diff --git a/.agents/skills/database-access/SKILL.md b/.agents/skills/database-access/SKILL.md new file mode 100644 index 00000000000..796dfafe4f6 --- /dev/null +++ b/.agents/skills/database-access/SKILL.md @@ -0,0 +1,52 @@ +--- +name: database-access +description: Add database queries, extract existing Prisma calls into repositories, or explicitly port queries to Rust and SQLx without expanding migration scope +--- + +# Database access + +## Adding new database access + +- Put Python database access behind an operation in `litellm/repositories` +- Give callers typed inputs and outputs, not Prisma clients, models, or query dictionaries +- Keep query execution and backend selection inside the repository +- Prisma is fine for the implementation, adding a query does not require a Rust port +- Native Rust callers use `litellm-rust/crates/db` directly + +## Asked to move existing access behind a repository + +- Identify the calls being moved and their transaction boundary +- Move the existing Prisma implementation into the relevant repository +- Replace those direct database calls with repository operations +- Preserve return values, errors, and transaction behavior, with focused regression tests +- Keep this an extraction, not a backend migration or unrelated cleanup + +## An equivalent Rust or SQLx query already exists + +- Leave it and the current backend selection unchanged unless integration is explicitly requested +- Its existence alone does not justify switching a Prisma caller to Rust +- Repository extraction can keep using Prisma even when the Rust query is available + +## Asked to port a Prisma query to Rust or SQLx + +- Identify the existing inputs, outputs, errors, and transaction boundary +- Check `litellm-rust/crates/db` for an equivalent query and reuse it if its behavior matches +- Otherwise follow `litellm-rust/crates/db/AGENTS.md` + - Put static SQL in `queries/` and compile-check it with SQLx + - Keep typed inputs and reusable row projections in `src/` + - Refresh SQLx query metadata after SQL changes +- Keep Python conversion in the Python bridge, not in `litellm-rust/crates/db` +- When caller integration is requested, expose the Rust operation through the bridge and call it from the repository + - A query-only port can land without switching callers +- Verify behavior against real PostgreSQL before switching callers + - Check relevant null handling, conflicts, ordering, errors, and transaction semantics +- Remove the old implementation only when no callers need it + +## Migration context and boundaries + +- Long-term direction is to centralize Python database access in repositories, then replace their Prisma implementations incrementally with Rust APIs +- Mixed Prisma and Rust implementations are expected during the transition, unrelated existing calls can stay as they are +- Both backends may have separate pools through PgBouncer, size them together and verify pooling-mode compatibility +- PgBouncer does not share transactions between Prisma and SQLx, keep each atomic unit of work on one backend and transaction +- Never retry a failed Rust write through Prisma when it may already have committed +- Prisma owns schema migrations today, eventual SQLx migration ownership and Prisma removal are separate planned steps, not part of a query port diff --git a/.github/scripts/auto_update_price_and_context_window_file.py b/.github/scripts/auto_update_price_and_context_window_file.py deleted file mode 100644 index 4c9a05bd4f0..00000000000 --- a/.github/scripts/auto_update_price_and_context_window_file.py +++ /dev/null @@ -1,319 +0,0 @@ -import asyncio -import aiohttp -import json -import math -from typing import Any - -# Asynchronously fetch data from a given URL -async def fetch_data(url): - try: - # Create an asynchronous session - async with aiohttp.ClientSession() as session: - # Send a GET request to the URL - async with session.get(url) as resp: - # Raise an error if the response status is not OK - resp.raise_for_status() - # Parse the response JSON - resp_json = await resp.json() - print("Fetch the data from URL.") - # Return the 'data' field from the JSON response - return resp_json['data'] - except Exception as e: - # Print an error message if fetching data fails - print("Error fetching data from URL:", e) - return None - - -FRIENDLI_API_URL = "https://api.friendli.ai/serverless/v1/models" -FRIENDLI_PROVIDER = "friendliai" - -INHERITABLE_BASE_KEYS = ( - "supports_pdf_input", - "supports_assistant_prefill", - "supports_adaptive_thinking", - "supports_output_config", -) - -REASONING_EFFORT_LEVEL_ORDER = ("none", "minimal", "low", "medium", "high", "xhigh", "max") - - -def _find_base_model_entry(base_model: str, local_data: dict) -> str | None: - if not base_model: - return None - bm_tail = base_model.split("/")[-1].lower() - if base_model in local_data: - return base_model - for key in local_data: - if key.startswith("sample_spec") or key == "fallback_generalizations": - continue - if key.split("/")[-1].lower() == bm_tail: - return key - return None - - -def _reasoning_effort_levels(reasoning_options: list) -> list: - offered = { - val - for opt in reasoning_options or [] - if opt.get("type") == "effort" - for val in opt.get("values", []) - } - return [level for level in REASONING_EFFORT_LEVEL_ORDER if level in offered] - - -def _valid_token_price(value: object) -> bool: - try: - price = float(value) # pyright: ignore[reportArgumentType] # non-numeric values are rejected via the except - except (TypeError, ValueError): - return False - return math.isfinite(price) and price >= 0 - - -def _has_valid_token_prices(pricing: dict | None) -> bool: - prices = pricing or {} - return _valid_token_price(prices.get("input")) and _valid_token_price(prices.get("output")) - - -def _pricing(pricing: dict) -> dict: - out: dict[str, Any] = {} - if not pricing: - return out - if "input" in pricing: - out["input_cost_per_token"] = float(pricing["input"]) - if "output" in pricing: - out["output_cost_per_token"] = float(pricing["output"]) - if "input_cache_read" in pricing and pricing["input_cache_read"] is not None: - out["cache_read_input_token_cost"] = float(pricing["input_cache_read"]) - return out - - -def _modality_flags(input_mods: list) -> dict: - mods = input_mods or [] - has_image = "image" in mods - return { - "supports_vision": has_image, - "supports_image_input": has_image, - "supports_video_input": "video" in mods, - } - - -def transform_friendli_data(data: list, local_data: dict) -> dict: - transformed: dict[str, dict] = {} - if not data: - return transformed - for model in data: - # An unpriced row must never wholesale-replace an already priced local entry: - # missing prices cost-calculate as zero, silently zeroing tracked spend - if not _has_valid_token_prices(model.get("pricing")): - continue - model_id = model["id"] - base_model = model.get("base_model") or "" - entry: dict[str, Any] = { - "litellm_provider": FRIENDLI_PROVIDER, - } - - base_key = _find_base_model_entry(base_model, local_data) - if base_key: - base_entry = local_data[base_key] - for k in INHERITABLE_BASE_KEYS: - if k in base_entry: - entry[k] = base_entry[k] - - ctx = model.get("context_length") - if ctx is not None: - entry["max_input_tokens"] = int(ctx) - max_out = model.get("max_completion_tokens") - if max_out is not None: - entry["max_output_tokens"] = int(max_out) - entry["max_tokens"] = int(max_out) - - pricing = _pricing(model.get("pricing", {})) - entry.update(pricing) - entry["supports_prompt_caching"] = "cache_read_input_token_cost" in pricing - - reasoning = model.get("reasoning") is True - entry["supports_reasoning"] = reasoning - if reasoning: - entry["reasoning_effort_levels"] = _reasoning_effort_levels( - model.get("reasoning_options", []) - ) - - func = model.get("functionality", {}) - entry["supports_function_calling"] = func.get("tool_call") is True - entry["supports_parallel_function_calling"] = func.get("parallel_tool_call") is True - is_struct = func.get("structured_output") is True - entry["supports_response_schema"] = is_struct - entry["supports_native_structured_output"] = is_struct - entry["supports_system_messages"] = func.get("system_messages") is True - entry["supports_tool_choice"] = func.get("tool_choice") is True - - entry.update(_modality_flags(model.get("input_modalities", []))) - - entry["mode"] = model.get("mode", "chat") - - desc = model.get("description") - if desc: - entry["comment"] = desc - - dep = model.get("deprecation_date") - if dep: - entry["deprecation_date"] = dep.split("T")[0] - - entry["source"] = FRIENDLI_API_URL - - transformed[f"{FRIENDLI_PROVIDER}/{model_id}"] = entry - return transformed - -# Synchronize local data with remote data -def sync_local_data_with_remote(local_data, remote_data, replace_keys=frozenset()): - # Update existing keys in local_data with values from remote_data - # (replace_keys entries are swapped wholesale so a field the remote catalog - # dropped, e.g. cache pricing, cannot survive as a stale value) - for key in (set(local_data) & set(remote_data)): - if key in replace_keys: - local_data[key] = remote_data[key] - else: - local_data[key].update(remote_data[key]) - - # Add new keys from remote_data to local_data - for key in (set(remote_data) - set(local_data)): - local_data[key] = remote_data[key] - -# Write data to the json file -def write_to_file(file_path, data): - try: - # Open the file in write mode - with open(file_path, "w") as file: - # Dump the data as JSON into the file - json.dump(data, file, indent=4) - print("Values updated successfully.") - except Exception as e: - # Print an error message if writing to file fails - print("Error updating JSON file:", e) - -# Update the existing models and add the missing models for OpenRouter -def transform_openrouter_data(data): - transformed = {} - if not data: - return transformed - for row in data: - # Add the fields 'max_tokens' and 'input_cost_per_token' - obj = { - "max_tokens": row["context_length"], - "input_cost_per_token": float(row["pricing"]["prompt"]), - } - - # Add 'max_output_tokens' as a field if it is not None - if "top_provider" in row and "max_completion_tokens" in row["top_provider"] and row["top_provider"]["max_completion_tokens"] is not None: - obj['max_output_tokens'] = int(row["top_provider"]["max_completion_tokens"]) - - # Add the field 'output_cost_per_token' - obj.update({ - "output_cost_per_token": float(row["pricing"]["completion"]), - }) - - # Add field 'input_cost_per_image' if it exists and is non-zero - if "pricing" in row and "image" in row["pricing"] and float(row["pricing"]["image"]) != 0.0: - obj['input_cost_per_image'] = float(row["pricing"]["image"]) - - # Add the fields 'litellm_provider' and 'mode' - obj.update({ - "litellm_provider": "openrouter", - "mode": "chat" - }) - - # Add the 'supports_vision' field if the modality is 'multimodal' - if row.get('architecture', {}).get('modality') == 'multimodal': - obj['supports_vision'] = True - - # Use a composite key to store the transformed object - transformed[f'openrouter/{row["id"]}'] = obj - - return transformed - -# Update the existing models and add the missing models for Vercel AI Gateway -def transform_vercel_ai_gateway_data(data): - transformed = {} - if not data: - return transformed - for row in data: - # Rows without token pricing or token limits (video/embedding models) previously KeyError'd the whole sync - if any(row.get(k) is None for k in ("context_window", "max_tokens")) or any( - row.get("pricing", {}).get(k) is None for k in ("input", "output") - ): - continue - obj = { - "max_tokens": row["context_window"], - "input_cost_per_token": float(row["pricing"]["input"]), - "output_cost_per_token": float(row["pricing"]["output"]), - 'max_output_tokens': row['max_tokens'], - 'max_input_tokens': row["context_window"], - } - - # Handle cache pricing if available - if "pricing" in row: - if "input_cache_read" in row["pricing"] and row["pricing"]["input_cache_read"] is not None: - obj['cache_read_input_token_cost'] = float(f"{float(row['pricing']['input_cache_read']):e}") - - if "input_cache_write" in row["pricing"] and row["pricing"]["input_cache_write"] is not None: - obj['cache_creation_input_token_cost'] = float(f"{float(row['pricing']['input_cache_write']):e}") - - mode = "embedding" if "embedding" in row["id"].lower() else "chat" - - obj.update({"litellm_provider": "vercel_ai_gateway", "mode": mode}) - - transformed[f'vercel_ai_gateway/{row["id"]}'] = obj - - return transformed - - -# Load local data from a specified file -def load_local_data(file_path): - try: - # Open the file in read mode - with open(file_path, "r") as file: - # Load and return the JSON data - return json.load(file) - except FileNotFoundError: - # Print an error message if the file is not found - print("File not found:", file_path) - return None - except json.JSONDecodeError as e: - # Print an error message if JSON decoding fails - print("Error decoding JSON:", e) - return None - -def main(): - local_file_path = "model_prices_and_context_window.json" # Path to the local data file - openrouter_url = "https://openrouter.ai/api/v1/models" # URL to fetch OpenRouter data - vercel_ai_gateway_url = "https://ai-gateway.vercel.sh/v1/models" # URL to fetch Vercel AI Gateway data - - # Load local data from file - local_data = load_local_data(local_file_path) - - # Fetch OpenRouter data - openrouter_data = asyncio.run(fetch_data(openrouter_url)) - # Transform the fetched OpenRouter data - openrouter_data = transform_openrouter_data(openrouter_data) - - # Fetch Vercel AI Gateway data - vercel_data = asyncio.run(fetch_data(vercel_ai_gateway_url)) - # Transform the fetched Vercel AI Gateway data - vercel_data = transform_vercel_ai_gateway_data(vercel_data) - - friendli_data = asyncio.run(fetch_data(FRIENDLI_API_URL)) - friendli_data = transform_friendli_data(friendli_data, local_data) - - # Combine both datasets - all_remote_data = {**openrouter_data, **vercel_data, **friendli_data} - - # If both local and openrouter data are available, synchronize and save - if local_data and all_remote_data: - sync_local_data_with_remote(local_data, all_remote_data, replace_keys=frozenset(friendli_data)) - write_to_file(local_file_path, local_data) - else: - print("Failed to fetch model data from either local file or URL.") - -# Entry point of the script -if __name__ == "__main__": - main() diff --git a/.github/workflows/auto_update_price_and_context_window.yml b/.github/workflows/auto_update_price_and_context_window.yml deleted file mode 100644 index 838ba35f831..00000000000 --- a/.github/workflows/auto_update_price_and_context_window.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Updates model_prices_and_context_window.json and Create Pull Request - -on: - schedule: - - cron: "0 0 * * 0" # Run every Sundays at midnight - #- cron: "0 0 * * *" # Run daily at midnight - -permissions: - contents: write - pull-requests: write - -jobs: - auto_update_price_and_context_window: - if: github.repository == 'BerriAI/litellm' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 - with: - persist-credentials: false - - name: Set up uv - uses: ./.github/actions/setup-uv-with-retries - with: - version: "0.10.9" - - name: Update JSON Data - run: | - uv run --frozen --with 'aiohttp==3.13.3' python ".github/scripts/auto_update_price_and_context_window_file.py" - - name: Create Pull Request - run: | - git add model_prices_and_context_window.json - git commit -m "Update model_prices_and_context_window.json file: $(date +'%Y-%m-%d')" - gh pr create --title "Update model_prices_and_context_window.json file" \ - --body "Automated update for model_prices_and_context_window.json" \ - --head auto-update-price-and-context-window-$(date +'%Y-%m-%d') \ - --base main - env: - GH_TOKEN: ${{ secrets.GH_TOKEN }} diff --git a/.github/workflows/spend-logs-guard.yml b/.github/workflows/spend-logs-guard.yml new file mode 100644 index 00000000000..80a503679ec --- /dev/null +++ b/.github/workflows/spend-logs-guard.yml @@ -0,0 +1,49 @@ +name: Spend logs guard + +on: # zizmor: ignore[dangerous-triggers] runs the base branch's code only; the PR's diff is read as data and never executed + pull_request_target: + branches: + - main + pull_request_review: + types: + - submitted + - dismissed + +permissions: + contents: read + pull-requests: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + spend-logs-guard: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 + with: + ref: ${{ github.event.pull_request.base.ref }} + persist-credentials: false + - name: Fetch the pull request head, its merge base and its reviews + id: revisions + env: + GH_TOKEN: ${{ github.token }} + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + merge_base="$(gh api "repos/${GITHUB_REPOSITORY}/compare/${BASE_SHA}...${HEAD_SHA}" --jq '.merge_base_commit.sha')" + git fetch --no-tags --depth=1 origin "$merge_base" "$HEAD_SHA" + gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/reviews" --paginate --slurp | jq 'add // []' > "$RUNNER_TEMP/reviews.json" + echo "merge_base=$merge_base" >> "$GITHUB_OUTPUT" + - name: Set up uv + uses: ./.github/actions/setup-uv-with-retries + with: + version: "0.10.9" + - name: Run the guard + env: + MERGE_BASE: ${{ steps.revisions.outputs.merge_base }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + uv run --frozen python ci_cd/spend_logs_guard.py --base "$MERGE_BASE" --head "$HEAD_SHA" --approver kerry-berri --reviews "$RUNNER_TEMP/reviews.json" diff --git a/.github/workflows/sync-together-ai-models.yml b/.github/workflows/sync-together-ai-models.yml deleted file mode 100644 index 5325510e45e..00000000000 --- a/.github/workflows/sync-together-ai-models.yml +++ /dev/null @@ -1,65 +0,0 @@ -name: Sync Together AI model registry - -on: - schedule: - - cron: "30 6 * * *" - workflow_dispatch: - -permissions: - contents: write - pull-requests: write - -jobs: - sync_together_ai_models: - if: github.repository == 'BerriAI/litellm' - runs-on: ubuntu-latest - env: - BASE_BRANCH: ${{ github.event.repository.default_branch }} - steps: - - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 - with: - ref: ${{ env.BASE_BRANCH }} - persist-credentials: false - - name: Set up uv - uses: ./.github/actions/setup-uv-with-retries - with: - version: "0.10.9" - - name: Look for an already-open sync PR - id: existing - run: | - open_pr="$(gh pr list --repo "$GITHUB_REPOSITORY" --state open --limit 1000 --json headRefName \ - --jq '[.[].headRefName | select(startswith("litellm_together_registry_sync_"))] | first // empty')" - echo "open_pr=$open_pr" >> "$GITHUB_OUTPUT" - if [ -n "$open_pr" ]; then - echo "An open sync PR already exists on branch $open_pr; skipping this run." - fi - env: - GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }} - - name: Run the sync - if: steps.existing.outputs.open_pr == '' - run: | - uv run --frozen python scripts/sync_together_ai_models.py --write --pr-body-file "$RUNNER_TEMP/pr_body.md" - env: - TOGETHER_API_KEY: ${{ secrets.TOGETHER_API_KEY }} - - name: Create a pull request when the registry changed - if: steps.existing.outputs.open_pr == '' - run: | - if git diff --quiet; then - echo "Registry already in sync; no PR needed." - exit 0 - fi - branch="litellm_together_registry_sync_$(date +'%Y-%m-%d')" - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git checkout -b "$branch" - git add model_prices_and_context_window.json \ - litellm/model_prices_and_context_window_backup.json - git commit -m "feat(models): sync together_ai model registry $(date +'%Y-%m-%d')" - gh auth setup-git - git push origin "$branch" - gh pr create --title "feat(models): sync together_ai model registry" \ - --body-file "$RUNNER_TEMP/pr_body.md" \ - --head "$branch" \ - --base "$BASE_BRANCH" - env: - GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }} diff --git a/.github/workflows/test-linting.yml b/.github/workflows/test-linting.yml index 3b9a2614725..b9f8d7e7dfb 100644 --- a/.github/workflows/test-linting.yml +++ b/.github/workflows/test-linting.yml @@ -524,6 +524,12 @@ jobs: - name: check_provider_folders_documented run: uv run --no-sync python ./tests/code_coverage_tests/check_provider_folders_documented.py + - name: check_provider_endpoints_support_generated + run: uv run --no-sync python scripts/generate_provider_endpoints_support.py --check + + - name: test_generate_provider_endpoints_support + run: uv run --no-sync pytest -q --noconftest -p no:cacheprovider -c /dev/null tests/code_coverage_tests/test_generate_provider_endpoints_support.py + - name: check_prisma_binary_cache run: uv run --no-sync python ./tests/code_coverage_tests/check_prisma_binary_cache.py diff --git a/.github/workflows/test-mcp-dependency-resolution.yml b/.github/workflows/test-mcp-dependency-resolution.yml index 3f0d1260e49..20efb351985 100644 --- a/.github/workflows/test-mcp-dependency-resolution.yml +++ b/.github/workflows/test-mcp-dependency-resolution.yml @@ -45,7 +45,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] + python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15"] steps: - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 @@ -132,7 +132,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] + python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15"] steps: - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 with: diff --git a/.github/workflows/test-merge-smoke.yml b/.github/workflows/test-merge-smoke.yml index 0d1cc6596de..f3f09523491 100644 --- a/.github/workflows/test-merge-smoke.yml +++ b/.github/workflows/test-merge-smoke.yml @@ -33,7 +33,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] + python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15"] env: LITELLM_LOCAL_MODEL_COST_MAP: "True" steps: @@ -76,6 +76,12 @@ jobs: - name: Import and CLI checks run: $IN_NETNS .venv/bin/python .github/scripts/run_merge_smoke.py cli + - name: Routing and UUID compatibility + run: >- + $IN_NETNS .venv/bin/python -m pytest + tests/unit/router_strategy/test_complexity_router.py::TestCustomDimensions + tests/unit/test_uuid_helper.py -q + - name: Proxy startup check run: $IN_NETNS .venv/bin/python .github/scripts/run_merge_smoke.py proxy-startup --diagnostics-dir "${RUNNER_TEMP}/smoke-diagnostics" diff --git a/.github/workflows/test-rust-db.yml b/.github/workflows/test-rust-db.yml new file mode 100644 index 00000000000..bb88b593d5b --- /dev/null +++ b/.github/workflows/test-rust-db.yml @@ -0,0 +1,106 @@ +name: LiteLLM Rust DB + +on: + push: + paths: + - "litellm-rust/crates/db/**" + - "litellm-rust/Cargo.toml" + - "litellm-rust/Cargo.lock" + - "litellm-rust/clippy.toml" + - "litellm-proxy-extras/litellm_proxy_extras/migrations/**" + - "**/schema.prisma" + - ".cargo/**" + - "rust-toolchain.toml" + - "pyproject.toml" + - "uv.lock" + - ".github/actions/setup-uv-with-retries/**" + - ".github/workflows/test-rust-db.yml" + pull_request: + branches: + - main + - "litellm_**" + paths: + - "litellm-rust/crates/db/**" + - "litellm-rust/Cargo.toml" + - "litellm-rust/Cargo.lock" + - "litellm-rust/clippy.toml" + - "litellm-proxy-extras/litellm_proxy_extras/migrations/**" + - "**/schema.prisma" + - ".cargo/**" + - "rust-toolchain.toml" + - "pyproject.toml" + - "uv.lock" + - ".github/actions/setup-uv-with-retries/**" + - ".github/workflows/test-rust-db.yml" + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +env: + CARGO_TERM_COLOR: always + +jobs: + db-queries: + runs-on: ubuntu-latest + timeout-minutes: 30 + services: + postgres: + image: postgres:16.6@sha256:557fea37a744d5f4c8faab304b0a90858b53ab119735a88c131fd19dab802f36 + env: + POSTGRES_DB: litellm + POSTGRES_PASSWORD: postgres + POSTGRES_USER: postgres + ports: + - 5432:5432 + options: >- + --health-cmd "pg_isready -U postgres -d litellm" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + env: + DATABASE_URL: postgresql://postgres:postgres@localhost:5432/litellm + SQLX_OFFLINE: "false" + defaults: + run: + working-directory: litellm-rust + steps: + - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 + with: + persist-credentials: false + + - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 + with: + python-version: "3.12" + + - uses: ./.github/actions/setup-uv-with-retries + with: + version: "0.10.9" + + - run: rustup toolchain install --no-self-update + + - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 + with: + workspaces: litellm-rust + cache-on-failure: true + + - name: Install Python dependencies + working-directory: . + run: uv sync --frozen --extra extra-proxy + + - name: Deploy Prisma migrations + working-directory: . + run: uv run --no-sync prisma migrate deploy --schema litellm-proxy-extras/litellm_proxy_extras/schema.prisma + + - name: Install SQLx CLI + run: cargo install sqlx-cli --version 0.9.0 --locked --no-default-features -F postgres + + - name: Check SQLx query metadata + working-directory: litellm-rust/crates/db + run: cargo sqlx prepare --check + + - name: Test database queries + run: cargo test -p litellm-db --locked -- --include-ignored diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml index 76af64c8ccd..4d47a882891 100644 --- a/.github/workflows/test-unit.yml +++ b/.github/workflows/test-unit.yml @@ -579,13 +579,13 @@ jobs: - shard: mcp-elicitation test-path: |- - tests/unit/experimental_mcp_client/test_mcp_client.py - tests/unit/proxy/_experimental/mcp_server/test_capabilities.py - tests/unit/proxy/_experimental/mcp_server/test_interactions.py - tests/unit/proxy/_experimental/mcp_server/test_mcp_elicitation_handler.py - tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py - tests/unit/proxy/_experimental/mcp_server/test_mcp_server_tool_calls_and_headers.py - tests/unit/proxy/_experimental/mcp_server/test_operations.py + tests/unit/mcp_client/test_mcp_client.py + tests/unit/proxy/mcp_server/test_capabilities.py + tests/unit/proxy/mcp_server/test_interactions.py + tests/unit/proxy/mcp_server/test_mcp_elicitation_handler.py + tests/unit/proxy/mcp_server/test_mcp_server_manager.py + tests/unit/proxy/mcp_server/test_mcp_server_tool_calls_and_headers.py + tests/unit/proxy/mcp_server/test_operations.py python-version: "3.12" workers: 4 reruns: 0 @@ -603,7 +603,7 @@ jobs: tests/unit/proxy/spend_tracking --ignore=tests/unit/proxy/spend_tracking/test_search_api_logging.py tests/unit/proxy/pass_through_endpoints - tests/unit/proxy/experimental + tests/unit/proxy/mcp_server/test_tool_registry.py tests/unit/proxy/common_utils --ignore=tests/unit/proxy/common_utils/test_cache_aware_routing.py --ignore=tests/unit/proxy/common_utils/test_check_batch_cost.py @@ -811,14 +811,14 @@ jobs: - shard: mcp-oauth test-path: |- - tests/unit/proxy/_experimental/mcp_server/test_discoverable_endpoints.py - tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py - tests/unit/proxy/_experimental/mcp_server/test_db_credentials.py - tests/unit/proxy/_experimental/mcp_server/test_gateway_dcr_flow.py - tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough_tools.py - tests/unit/proxy/_experimental/mcp_server/test_mcp_max_concurrent_requests.py - tests/unit/proxy/_experimental/mcp_server/faults/test_list_outcomes.py - tests/unit/proxy/_experimental/mcp_server/outbound_credentials + tests/unit/proxy/mcp_server/test_discoverable_endpoints.py + tests/unit/proxy/mcp_server/test_mcp_server_manager.py + tests/unit/proxy/mcp_server/test_db_credentials.py + tests/unit/proxy/mcp_server/test_gateway_dcr_flow.py + tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough_tools.py + tests/unit/proxy/mcp_server/test_mcp_max_concurrent_requests.py + tests/unit/proxy/mcp_server/faults/test_list_outcomes.py + tests/unit/proxy/mcp_server/outbound_credentials python-version: "3.12" workers: 4 reruns: 2 @@ -828,19 +828,21 @@ jobs: - shard: mcp-server test-path: |- + tests/unit/mcp_client tests/unit/experimental_mcp_client + tests/unit/proxy/mcp_server tests/unit/proxy/_experimental/mcp_server tests/unit/responses/mcp - --ignore=tests/unit/experimental_mcp_client/test_mcp_client.py - --ignore=tests/unit/proxy/_experimental/mcp_server/test_capabilities.py - --ignore=tests/unit/proxy/_experimental/mcp_server/test_interactions.py - --ignore=tests/unit/proxy/_experimental/mcp_server/test_mcp_elicitation_handler.py - --ignore=tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py - --ignore=tests/unit/proxy/_experimental/mcp_server/test_mcp_server_tool_calls_and_headers.py - --ignore=tests/unit/proxy/_experimental/mcp_server/test_operations.py - --ignore=tests/unit/proxy/_experimental/mcp_server/test_discoverable_endpoints.py - --ignore=tests/unit/proxy/_experimental/mcp_server/test_db_credentials.py - --ignore=tests/unit/proxy/_experimental/mcp_server/outbound_credentials + --ignore=tests/unit/mcp_client/test_mcp_client.py + --ignore=tests/unit/proxy/mcp_server/test_capabilities.py + --ignore=tests/unit/proxy/mcp_server/test_interactions.py + --ignore=tests/unit/proxy/mcp_server/test_mcp_elicitation_handler.py + --ignore=tests/unit/proxy/mcp_server/test_mcp_server_manager.py + --ignore=tests/unit/proxy/mcp_server/test_mcp_server_tool_calls_and_headers.py + --ignore=tests/unit/proxy/mcp_server/test_operations.py + --ignore=tests/unit/proxy/mcp_server/test_discoverable_endpoints.py + --ignore=tests/unit/proxy/mcp_server/test_db_credentials.py + --ignore=tests/unit/proxy/mcp_server/outbound_credentials python-version: "3.12" workers: 4 reruns: 0 @@ -950,7 +952,7 @@ jobs: dist: loadscope steps: - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 - timeout-minutes: 3 + timeout-minutes: ${{ matrix.shard == 'db-and-spend' && 10 || 3 }} with: persist-credentials: false fetch-depth: ${{ matrix.shard == 'db-and-spend' && '0' || '1' }} diff --git a/.gitignore b/.gitignore index 5ca20f02274..b08ee92d6af 100644 --- a/.gitignore +++ b/.gitignore @@ -105,7 +105,7 @@ litellm_config.yaml .cursor litellm/proxy/to_delete_loadtest_work/* update_model_cost_map.py -tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py +tests/unit/proxy/mcp_server/test_mcp_server_manager.py scripts/test_vertex_ai_search.py LAZY_LOADING_IMPROVEMENTS.md STABILIZATION_TODO.md diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 8e88c0ea15b..2177e483a1b 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -332,13 +332,13 @@ Each translation is isolated in its own file, making it easy to test and modify |--------------|----------|------------------| | `/v1/chat/completions` | Anthropic | `llms/anthropic/chat/transformation.py` | | `/v1/chat/completions` | Bedrock Converse | `llms/bedrock/chat/converse_transformation.py` | -| `/v1/chat/completions` | Bedrock Invoke | `llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.py` | +| `/v1/chat/completions` | Bedrock Invoke | `llms/bedrock/chat/invoke_transformations/anthropic_claude_transformation.py` | | `/v1/chat/completions` | Gemini | `llms/gemini/chat/transformation.py` | | `/v1/chat/completions` | Vertex AI | `llms/vertex_ai/gemini/transformation.py` | | `/v1/chat/completions` | OpenAI | `llms/openai/chat/gpt_transformation.py` | -| `/v1/messages` (passthrough) | Anthropic | `llms/anthropic/pass_through/messages/transformation.py` | -| `/v1/messages` (passthrough) | Bedrock | `llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py` | -| `/v1/messages` (passthrough) | Vertex AI | `llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/transformation.py` | +| `/v1/messages` (passthrough) | Anthropic | `llms/anthropic/messages/native/transformation.py` | +| `/v1/messages` (passthrough) | Bedrock | `llms/bedrock/messages/invoke_transformations/anthropic_claude_transformation.py` | +| `/v1/messages` (passthrough) | Vertex AI | `llms/vertex_ai/vertex_ai_partner_models/anthropic/messages/transformation.py` | | Passthrough endpoints | All | `proxy/pass_through_endpoints/llm_provider_handlers/` | ### Example: Debugging prompt caching @@ -346,7 +346,7 @@ Each translation is isolated in its own file, making it easy to test and modify If `/v1/messages` → Bedrock Converse prompt caching isn't working but Bedrock Invoke works: 1. **Bedrock Converse translation**: `llms/bedrock/chat/converse_transformation.py` -2. **Bedrock Invoke translation**: `llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.py` +2. **Bedrock Invoke translation**: `llms/bedrock/chat/invoke_transformations/anthropic_claude_transformation.py` 3. Compare how each handles `cache_control` in `transform_request()` ### How translations work diff --git a/Dockerfile b/Dockerfile index 713d7f8f5ab..4cef63c8d71 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ # syntax=docker/dockerfile:1.7 # Base image for building -ARG LITELLM_BUILD_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:81211e15a86ea1d5357f284482af45730c51de45eaf10ad9ce205d6bfc2df323 +ARG LITELLM_BUILD_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:360896efb0753a5701c48f860e17130c205eae5a264797aa3e7ea126ee2923a7 # Runtime image -ARG LITELLM_RUNTIME_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:81211e15a86ea1d5357f284482af45730c51de45eaf10ad9ce205d6bfc2df323 +ARG LITELLM_RUNTIME_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:360896efb0753a5701c48f860e17130c205eae5a264797aa3e7ea126ee2923a7 ARG UV_IMAGE=ghcr.io/astral-sh/uv:0.11.7@sha256:240fb85ab0f263ef12f492d8476aa3a2e4e1e333f7d67fbdd923d00a506a516a # Pinned by digest like the other base images; bump explicitly on Node upgrades. ARG UI_BUILD_IMAGE=node:24.19-alpine3.24@sha256:d32cdf619f63fe0471182d08996dd516c6275bb5fd31ae06e55a570bd9e1ad43 diff --git a/Makefile b/Makefile index dec853515b9..937873f8835 100644 --- a/Makefile +++ b/Makefile @@ -313,7 +313,7 @@ test-unit-proxy-core: install-test-deps $(UV_RUN) pytest tests/unit/proxy/auth tests/unit/proxy/client tests/unit/proxy/db tests/unit/proxy/hooks tests/unit/proxy/policy_engine --ignore=tests/unit/proxy/db/db_transaction_queue/test_e2e_pod_lock_manager.py --ignore=tests/unit/proxy/db/test_update_daily_tag_spend.py --tb=short -vv -n 4 --durations=20 test-unit-proxy-misc: install-test-deps - $(UV_RUN) pytest tests/unit/proxy/agent_endpoints tests/unit/proxy/anthropic_endpoints tests/unit/proxy/common_utils --ignore=tests/unit/proxy/common_utils/test_cache_aware_routing.py --ignore=tests/unit/proxy/common_utils/test_check_batch_cost.py --ignore=tests/unit/proxy/common_utils/test_check_responses_cost.py --ignore=tests/unit/proxy/common_utils/test_proxy_encrypt_decrypt.py --ignore=tests/unit/proxy/common_utils/test_realtime_cache.py tests/unit/proxy/discovery_endpoints tests/unit/proxy/experimental tests/unit/proxy/google_endpoints tests/unit/proxy/health_endpoints tests/unit/proxy/image_endpoints tests/unit/proxy/middleware --ignore=tests/unit/proxy/middleware/test_request_size_limit_middleware.py tests/unit/proxy/openai_files_endpoint tests/unit/proxy/pass_through_endpoints tests/unit/proxy/prompts tests/unit/proxy/public_endpoints tests/unit/proxy/response_api_endpoints tests/unit/proxy/shutdown tests/unit/proxy/spend_tracking --ignore=tests/unit/proxy/spend_tracking/test_search_api_logging.py tests/unit/proxy/ui_crud_endpoints tests/unit/proxy/vector_store_endpoints tests/unit/proxy/_experimental/mcp_server/test_mcp_server_tool_calls_and_headers.py --ignore=tests/unit/proxy/google_endpoints/test_gemini_agents_endpoints.py --ignore=tests/unit/proxy/google_endpoints/test_google_endpoint_routing.py --ignore=tests/unit/proxy/google_endpoints/test_google_gemini_proxy_request.py --ignore=tests/unit/proxy/public_endpoints/test_blog_posts_endpoint.py --tb=short -vv -n 4 --durations=20 + $(UV_RUN) pytest tests/unit/proxy/agent_endpoints tests/unit/proxy/anthropic_endpoints tests/unit/proxy/common_utils --ignore=tests/unit/proxy/common_utils/test_cache_aware_routing.py --ignore=tests/unit/proxy/common_utils/test_check_batch_cost.py --ignore=tests/unit/proxy/common_utils/test_check_responses_cost.py --ignore=tests/unit/proxy/common_utils/test_proxy_encrypt_decrypt.py --ignore=tests/unit/proxy/common_utils/test_realtime_cache.py tests/unit/proxy/discovery_endpoints tests/unit/proxy/mcp_server/test_tool_registry.py tests/unit/proxy/google_endpoints tests/unit/proxy/health_endpoints tests/unit/proxy/image_endpoints tests/unit/proxy/middleware --ignore=tests/unit/proxy/middleware/test_request_size_limit_middleware.py tests/unit/proxy/openai_files_endpoint tests/unit/proxy/pass_through_endpoints tests/unit/proxy/prompts tests/unit/proxy/public_endpoints tests/unit/proxy/response_api_endpoints tests/unit/proxy/shutdown tests/unit/proxy/spend_tracking --ignore=tests/unit/proxy/spend_tracking/test_search_api_logging.py tests/unit/proxy/ui_crud_endpoints tests/unit/proxy/vector_store_endpoints tests/unit/proxy/mcp_server/test_mcp_server_tool_calls_and_headers.py --ignore=tests/unit/proxy/google_endpoints/test_gemini_agents_endpoints.py --ignore=tests/unit/proxy/google_endpoints/test_google_endpoint_routing.py --ignore=tests/unit/proxy/google_endpoints/test_google_gemini_proxy_request.py --ignore=tests/unit/proxy/public_endpoints/test_blog_posts_endpoint.py --tb=short -vv -n 4 --durations=20 test-unit-proxy-root: install-test-deps $(UV_RUN) pytest tests/unit/proxy/test_*.py --ignore=tests/unit/proxy/test_aproxy_startup.py --ignore=tests/unit/proxy/test_credential_slot_registry.py --ignore=tests/unit/proxy/test_custom_callback_input.py --ignore=tests/unit/proxy/test_custom_logger_s3_gcs.py --ignore=tests/unit/proxy/test_custom_tokenizer_bug.py --ignore=tests/unit/proxy/test_db_schema_changes.py --ignore=tests/unit/proxy/test_deprecated_key_grace_period.py --ignore=tests/unit/proxy/test_get_favicon.py --ignore=tests/unit/proxy/test_get_image.py --ignore=tests/unit/proxy/test_prisma_client_backoff_retry.py --ignore=tests/unit/proxy/test_prompt_test_endpoint.py --ignore=tests/unit/proxy/test_proxy_config_unit_test.py --ignore=tests/unit/proxy/test_proxy_custom_auth.py --ignore=tests/unit/proxy/test_proxy_reject_logging.py --ignore=tests/unit/proxy/test_proxy_server.py --ignore=tests/unit/proxy/test_proxy_setting_guardrails.py --ignore=tests/unit/proxy/test_proxy_token_counter.py --ignore=tests/unit/proxy/test_proxy_utils.py --ignore=tests/unit/proxy/test_reducto_ocr_route.py --ignore=tests/unit/proxy/test_response_polling_pre_call_checks.py --ignore=tests/unit/proxy/test_server_root_path.py --ignore=tests/unit/proxy/test_ui_path_detection.py --ignore=tests/unit/proxy/test_unit_test_proxy_hooks.py --ignore=tests/unit/proxy/test_update_spend.py --ignore=tests/unit/proxy/test_zero_cost_model_budget_bypass.py --tb=short -vv -n 4 --durations=20 @@ -325,7 +325,7 @@ test-unit-core-utils: install-test-deps $(UV_RUN) pytest tests/unit/litellm_core_utils --tb=short -vv -n 2 --durations=20 test-unit-other: install-test-deps - $(UV_RUN) pytest tests/unit/caching tests/unit/responses tests/unit/secret_managers tests/unit/vector_stores tests/unit/a2a_protocol tests/unit/completion_extras tests/unit/containers tests/unit/enterprise tests/unit/experimental_mcp_client tests/unit/google_genai tests/unit/images tests/unit/interactions tests/unit/router_strategy tests/unit/router_utils tests/unit/types --tb=short -vv -n 4 --durations=20 + $(UV_RUN) pytest tests/unit/caching tests/unit/responses tests/unit/secret_managers tests/unit/vector_stores tests/unit/a2a_protocol tests/unit/completion_extras tests/unit/containers tests/unit/enterprise tests/unit/mcp_client tests/unit/google_genai tests/unit/images tests/unit/interactions tests/unit/router_strategy tests/unit/router_utils tests/unit/types --tb=short -vv -n 4 --durations=20 test-unit-root: install-test-deps $(UV_RUN) pytest tests/unit/test_*.py --tb=short -vv -n 4 --durations=20 diff --git a/README.md b/README.md index 4feb6e00ffa..5dfa8d01fc4 100644 --- a/README.md +++ b/README.md @@ -223,7 +223,7 @@ async with httpx.AsyncClient(headers=headers, timeout=60.0) as http_client: ```python from mcp import ClientSession, StdioServerParameters from mcp.client.stdio import stdio_client -from litellm import experimental_mcp_client +from litellm import mcp_client import litellm server_params = StdioServerParameters(command="python", args=["mcp_server.py"]) @@ -233,7 +233,7 @@ async with stdio_client(server_params) as (read, write): await session.initialize() # Load MCP tools in OpenAI format - tools = await experimental_mcp_client.load_mcp_tools(session=session, format="openai") + tools = await mcp_client.load_mcp_tools(session=session, format="openai") # Use with any LiteLLM model response = await litellm.acompletion( diff --git a/backend/Dockerfile b/backend/Dockerfile index 46d65c432bb..1c22f914100 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,5 +1,5 @@ -ARG LITELLM_BUILD_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:81211e15a86ea1d5357f284482af45730c51de45eaf10ad9ce205d6bfc2df323 -ARG LITELLM_RUNTIME_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:81211e15a86ea1d5357f284482af45730c51de45eaf10ad9ce205d6bfc2df323 +ARG LITELLM_BUILD_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:360896efb0753a5701c48f860e17130c205eae5a264797aa3e7ea126ee2923a7 +ARG LITELLM_RUNTIME_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:360896efb0753a5701c48f860e17130c205eae5a264797aa3e7ea126ee2923a7 ARG UV_IMAGE=ghcr.io/astral-sh/uv:0.11.7@sha256:240fb85ab0f263ef12f492d8476aa3a2e4e1e333f7d67fbdd923d00a506a516a FROM $UV_IMAGE AS uvbin @@ -124,7 +124,12 @@ ENV HOME=/home/nonroot \ PYTHONUNBUFFERED=1 \ PRISMA_BINARY_CACHE_DIR=/opt/prisma/binaries -COPY --from=builder --chown=nonroot:nonroot /app /app +COPY --from=builder --chown=nonroot:nonroot /app/.venv /app/.venv +COPY --from=builder --chown=nonroot:nonroot /app/litellm /app/litellm +COPY --from=builder --chown=nonroot:nonroot /app/enterprise /app/enterprise +COPY --from=builder --chown=nonroot:nonroot /app/backend /app/backend +COPY --from=builder --chown=nonroot:nonroot /app/docker/component_entrypoint.sh /app/docker/component_entrypoint.sh +COPY --from=builder --chown=nonroot:nonroot /app/schema.prisma /app/schema.prisma COPY --from=builder /opt/prisma /opt/prisma RUN find /app/.venv -type f -path "*/tornado/test/*" -delete && \ diff --git a/ci_cd/spend_logs_guard.py b/ci_cd/spend_logs_guard.py new file mode 100644 index 00000000000..a04999c47c0 --- /dev/null +++ b/ci_cd/spend_logs_guard.py @@ -0,0 +1,119 @@ +"""Required check: a pull request that touches LiteLLM_SpendLogs in schema.prisma or a migration +needs an approving review from the spend-log owner before it can merge. + +CODEOWNERS can only match file paths, and every schema change edits the same schema.prisma copies, +so a path rule would put every migration on the owner. This gate reads the diff instead: when no +added line in the watched files mentions the table it passes at once, otherwise it passes only once +the owner's latest review on the pull request is an approval. The workflow re-runs on every review. +""" + +from __future__ import annotations + +import argparse +import re +import subprocess +import sys +from collections.abc import Sequence +from pathlib import Path +from typing import Final + +from pydantic import BaseModel, ConfigDict, TypeAdapter + +WATCHED: Final = ( + "schema.prisma", + "litellm/proxy/schema.prisma", + "litellm-proxy-extras/litellm_proxy_extras/schema.prisma", +) +MIGRATIONS_PREFIX: Final = "litellm-proxy-extras/litellm_proxy_extras/migrations/" +TABLE: Final = re.compile(r"(? bool: + return path in WATCHED or (path.startswith(MIGRATIONS_PREFIX) and path.endswith("/migration.sql")) + + +def _added_lines(section: str) -> tuple[str, ...]: + body: Final = section.split("\n@@", 1) + return tuple(line[1:] for line in body[1].splitlines() if line.startswith("+")) if len(body) == 2 else () + + +def spend_log_hits(diff: str) -> tuple[str, ...]: + """`path: added line` for every added line in a watched file that names the table.""" + sections: Final = re.split(r"^diff --git [^\n]*\n", diff, flags=re.MULTILINE) + return tuple(f"{path}: {line.strip()}" for path, line in _watched_added_lines(sections) if TABLE.search(line)) + + +def _watched_added_lines(sections: Sequence[str]) -> tuple[tuple[str, str], ...]: + pairs: Final = tuple((_path_of(section), section) for section in sections) + return tuple( + (path, line) for path, section in pairs if watched(path) for line in _added_lines(section) + ) # comprehension-ok: path then its lines + + +def _path_of(section: str) -> str: + match: Final = re.search(r"^\+\+\+ b/(.+)$", section, flags=re.MULTILINE) + return match.group(1) if match else "" + + +def approved_by(reviews: Sequence[Review], login: str) -> bool: + """True when `login`'s most recent review on the pull request is an approval.""" + states: Final = tuple(review.state for review in reviews if review.user.login == login) + return bool(states) and states[-1] == "APPROVED" + + +def added_diff(base: str, head: str) -> str: + result: Final = subprocess.run( + ("git", "diff", "--unified=0", "--no-color", f"{base}..{head}", "--", *WATCHED, MIGRATIONS_PREFIX), + check=True, + capture_output=True, + text=True, + ) + return result.stdout + + +class Arguments(BaseModel): + model_config = ConfigDict(frozen=True) + base: str + head: str + approver: str + reviews: Path + + +def main(argv: Sequence[str]) -> int: + parser: Final = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--base", required=True, help="merge base of the pull request") + parser.add_argument("--head", required=True, help="head sha of the pull request") + parser.add_argument("--approver", required=True, help="GitHub login whose approval unlocks the merge") + parser.add_argument("--reviews", required=True, help="JSON file with the pull request's reviews") + args: Final = Arguments.model_validate(vars(parser.parse_args(argv))) + hits: Final = spend_log_hits(added_diff(args.base, args.head)) + if not hits: + sys.stdout.write("No added line in schema.prisma or a migration names LiteLLM_SpendLogs; nothing to review.\n") + return 0 + if approved_by(_REVIEWS.validate_json(args.reviews.read_bytes()), args.approver): + sys.stdout.write(f"LiteLLM_SpendLogs change approved by {args.approver}: {', '.join(hits)}\n") + return 0 + listed: Final = "".join(f" {hit}\n" for hit in hits) + sys.stdout.write( + f"This pull request changes LiteLLM_SpendLogs and needs an approving review from @{args.approver}:\n" + f"{listed}The check re-runs when a review is submitted.\n" + ) + return 1 + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) diff --git a/cookbook/ai_coding_tool_guides/chatgpt_subscription_passthrough.md b/cookbook/ai_coding_tool_guides/chatgpt_subscription_passthrough.md new file mode 100644 index 00000000000..c79632e9195 --- /dev/null +++ b/cookbook/ai_coding_tool_guides/chatgpt_subscription_passthrough.md @@ -0,0 +1,76 @@ +# Use your ChatGPT subscription through LiteLLM + +Sign into ChatGPT in Codex or Pi and send model requests through your existing LiteLLM proxy. The client keeps your login and refreshes it. Each request uses that client's ChatGPT account, while a separate LiteLLM virtual key controls gateway access and usage attribution. + +An administrator adds a `chatgpt/` model using the usual model configuration. No ChatGPT login needs to be added to the proxy. This uses the same separate-key convention as provider passthrough, including Claude Code subscription forwarding. + +## Add a model to the proxy + +Reuse your existing proxy. If you need one, follow the [proxy quickstart](https://docs.litellm.ai/docs/proxy/docker_quick_start). Merge this entry into its model list and restart the proxy: + +```yaml +model_list: + - model_name: gpt-6-luna + litellm_params: + model: chatgpt/gpt-6-luna + model_info: + mode: responses +``` + +Use a model available to the caller's subscription. The virtual key must allow the exposed model name. Leave saved ChatGPT logins and API credentials unset for a client-only deployment. Explicit cross-provider fallbacks can incur separate API charges; do not configure them for subscription-only traffic. + +## Configure Codex + +Use your existing LiteLLM URL and a virtual key assigned to your gateway user. Export that key as `LITELLM_API_KEY` in the environment that launches Codex. Keep the value out of committed configuration. + +Add this provider to `~/.codex/config.toml`, preserving your other settings: + +```toml +model = "gpt-6-luna" +model_provider = "litellm_subscription" + +[model_providers.litellm_subscription] +name = "LiteLLM subscription" +base_url = "https://litellm.example.com/v1" +wire_api = "responses" +supports_websockets = false +requires_openai_auth = true +env_http_headers = { "x-litellm-api-key" = "LITELLM_API_KEY" } +``` + +Replace `https://litellm.example.com` with your proxy URL. A local proxy normally uses `http://localhost:4000/v1`. Launch Codex, sign into ChatGPT if needed, and send a prompt with a model available to your subscription. The selected model must match the name exposed by the gateway. + +For a managed workspace rollout, use OpenAI's [gateway configuration guide](https://learn.chatgpt.com/docs/enterprise/sign-in-with-chatgpt-through-a-gateway). + +## Native compatibility and Pi + +For a native Codex model catalog and request format, change Codex's `base_url` to `https://litellm.example.com/backend-api/codex`. This route uses the same credentials but does not need a model deployment or resolve model aliases. Restricted keys must allow the upstream model name. + +### Configure Pi + +Sign into the built-in `openai-codex` provider in Pi. Merge this override into `~/.pi/agent/models.json` and export your LiteLLM virtual key as `LITELLM_API_KEY` before launching Pi: + +```json +{ + "providers": { + "openai-codex": { + "baseUrl": "https://litellm.example.com/backend-api/codex", + "headers": { + "x-litellm-api-key": "LITELLM_API_KEY" + } + } + } +} +``` + +Keep Pi's subscription login as the provider credential. The header value names an environment variable, not a key to paste into the file. + +## Verify account usage + +Send a prompt and check the completed request in LiteLLM's Logs page. Its gateway user/key and token counts should match the caller. Give each person their own LiteLLM virtual key for separate attribution. The gateway credential and ChatGPT login are independently authenticated; LiteLLM does not establish that both identities belong to the same person. + +The native routes are `GET /backend-api/codex/models` and `POST /backend-api/codex/responses`. Model requests use the upstream model name, so a restricted LiteLLM key must allow that name. OpenAI's model catalog is returned in its native format; seeing a model there does not override gateway permissions. + +The proxy forwards the ChatGPT bearer and account header to the fixed OpenAI Codex endpoint. It removes gateway credentials and cookies from the upstream request and redacts credential headers in logging callbacks. The client remains responsible for refresh and reauthentication. Native passthrough returns authentication and quota errors without switching subscriptions. Standard model routes retain the caller login across ChatGPT retries; explicitly configured cross-provider fallbacks use their own credentials. An explicit workspace header is preserved for OpenAI to validate. + +This flow does not connect accounts through the dashboard or pool subscription allowances. Use a Codex build that supports ChatGPT authentication with a custom model provider. The integration forwards HTTP and SSE requests; it does not add native WebSocket or other Codex backend routes. diff --git a/docker/Dockerfile.database b/docker/Dockerfile.database index 69d9c26b2a8..20f810686a3 100644 --- a/docker/Dockerfile.database +++ b/docker/Dockerfile.database @@ -1,10 +1,10 @@ # syntax=docker/dockerfile:1.7 # Base image for building -ARG LITELLM_BUILD_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:81211e15a86ea1d5357f284482af45730c51de45eaf10ad9ce205d6bfc2df323 +ARG LITELLM_BUILD_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:360896efb0753a5701c48f860e17130c205eae5a264797aa3e7ea126ee2923a7 # Runtime image -ARG LITELLM_RUNTIME_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:81211e15a86ea1d5357f284482af45730c51de45eaf10ad9ce205d6bfc2df323 +ARG LITELLM_RUNTIME_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:360896efb0753a5701c48f860e17130c205eae5a264797aa3e7ea126ee2923a7 ARG UV_IMAGE=ghcr.io/astral-sh/uv:0.11.7@sha256:240fb85ab0f263ef12f492d8476aa3a2e4e1e333f7d67fbdd923d00a506a516a # Pinned by digest like the other base images; bump explicitly on Node upgrades. ARG UI_BUILD_IMAGE=node:24.19-alpine3.24@sha256:d32cdf619f63fe0471182d08996dd516c6275bb5fd31ae06e55a570bd9e1ad43 diff --git a/docker/Dockerfile.non_root b/docker/Dockerfile.non_root index 54bf8c807aa..90bcc523d9e 100644 --- a/docker/Dockerfile.non_root +++ b/docker/Dockerfile.non_root @@ -1,8 +1,8 @@ # syntax=docker/dockerfile:1.7 # Base images -ARG LITELLM_BUILD_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:81211e15a86ea1d5357f284482af45730c51de45eaf10ad9ce205d6bfc2df323 -ARG LITELLM_RUNTIME_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:81211e15a86ea1d5357f284482af45730c51de45eaf10ad9ce205d6bfc2df323 +ARG LITELLM_BUILD_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:360896efb0753a5701c48f860e17130c205eae5a264797aa3e7ea126ee2923a7 +ARG LITELLM_RUNTIME_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:360896efb0753a5701c48f860e17130c205eae5a264797aa3e7ea126ee2923a7 ARG UV_IMAGE=ghcr.io/astral-sh/uv:0.11.7@sha256:240fb85ab0f263ef12f492d8476aa3a2e4e1e333f7d67fbdd923d00a506a516a # Pinned by digest like the other base images; bump explicitly on Node upgrades. ARG UI_BUILD_IMAGE=node:24.19-alpine3.24@sha256:d32cdf619f63fe0471182d08996dd516c6275bb5fd31ae06e55a570bd9e1ad43 diff --git a/enterprise/enterprise_hooks/aporia_ai.py b/enterprise/enterprise_hooks/aporia_ai.py index 28b49bfce21..1e840f8dcc5 100644 --- a/enterprise/enterprise_hooks/aporia_ai.py +++ b/enterprise/enterprise_hooks/aporia_ai.py @@ -15,9 +15,10 @@ sys.path.insert( ) # Adds the parent directory to the system path import json import sys -from typing import Any, List, Literal, Optional +from typing import Final, List, Literal, Optional from fastapi import HTTPException +from pydantic import TypeAdapter import litellm from litellm._logging import verbose_proxy_logger @@ -29,11 +30,13 @@ from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, httpxSpecialProvider, ) +from litellm.llms.openai.common_utils import decoded_json_object from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.guardrails.guardrail_helpers import should_proceed_based_on_metadata from litellm.types.guardrails import GuardrailEventHooks GUARDRAIL_NAME = "aporia" +_DECODED_JSON: Final = TypeAdapter(object) class AporiaGuardrail(CustomGuardrail): @@ -68,7 +71,7 @@ class AporiaGuardrail(CustomGuardrail): async def prepare_aporia_request( self, new_messages: List[dict], response_string: Optional[str] = None ) -> dict: - data: dict[str, Any] = {} + data: dict[str, object] = {} if new_messages is not None: data["messages"] = new_messages if response_string is not None: @@ -122,8 +125,10 @@ class AporiaGuardrail(CustomGuardrail): verbose_proxy_logger.debug("Aporia AI response: %s", response.text) if response.status_code == 200: # check if the response was flagged - _json_response = response.json() - action: str = _json_response.get( + _json_response: Final = decoded_json_object( + _DECODED_JSON.validate_python(response.json()) + ) + action: Final = _json_response.get( "action" ) # possible values are modify, passthrough, block, rephrase if action == "block": diff --git a/enterprise/enterprise_hooks/blocked_user_list.py b/enterprise/enterprise_hooks/blocked_user_list.py index f6998d58cd5..7e4d2514880 100644 --- a/enterprise/enterprise_hooks/blocked_user_list.py +++ b/enterprise/enterprise_hooks/blocked_user_list.py @@ -7,9 +7,10 @@ ## This accepts a list of user id's for whom calls will be rejected -from typing import Literal, Optional +from typing import Final, Literal, Optional from fastapi import HTTPException +from pydantic import TypeAdapter import litellm from litellm._internal_context import with_service_target @@ -19,6 +20,9 @@ from litellm.integrations.custom_logger import CustomLogger from litellm.proxy._types import LiteLLM_EndUserTable, UserAPIKeyAuth from litellm.proxy.common_utils.user_api_key_cache import AUTH_OBJECTS_TARGET from litellm.proxy.utils import PrismaClient +from litellm.repositories.table_repositories import EndUserRepository + +_REQUEST_BODY_VALUE: Final = TypeAdapter(object) class ENTERPRISE_BlockedUserList(CustomLogger): @@ -94,15 +98,14 @@ class ENTERPRISE_BlockedUserList(CustomLogger): ) if end_user_cache_obj is None and self.prisma_client is not None: # check db - end_user_obj = ( - await self.prisma_client.db.litellm_endusertable.find_unique( - where={"user_id": user} - ) - ) + end_user_id: Final = _REQUEST_BODY_VALUE.validate_python(user) + end_user_obj = await EndUserRepository( + self.prisma_client + ).table.find_unique(where={"user_id": end_user_id}) if end_user_obj is None: # user not in db - assume not blocked end_user_obj = LiteLLM_EndUserTable(user_id=user, blocked=False) cache.set_cache(key=cache_key, value=end_user_obj, ttl=60) - if end_user_obj is not None and end_user_obj.blocked is True: + if end_user_obj.blocked is True: raise HTTPException( status_code=400, detail={ diff --git a/enterprise/enterprise_hooks/google_text_moderation.py b/enterprise/enterprise_hooks/google_text_moderation.py index b3ef5a3d496..7dbbc9ed6ce 100644 --- a/enterprise/enterprise_hooks/google_text_moderation.py +++ b/enterprise/enterprise_hooks/google_text_moderation.py @@ -6,7 +6,10 @@ # +-----------------------------------------------+ # Thank you users! We ❤️ you! - Krrish & Ishaan +from typing import Final + from fastapi import HTTPException +from pydantic import TypeAdapter import litellm from litellm._logging import verbose_proxy_logger @@ -15,6 +18,8 @@ from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.guardrails._content_utils import iter_message_text from litellm.types.utils import CallTypesLiteral +_THRESHOLD_VALUE: Final = TypeAdapter(object) + class ENTERPRISE_GoogleTextModeration(CustomLogger): user_api_key_cache = None @@ -69,9 +74,11 @@ class ENTERPRISE_GoogleTextModeration(CustomLogger): f"{category}_confidence_threshold", default_confidence_threshold, ) - set_confidence_value = getattr( - self, - f"{category}_confidence_threshold", + set_confidence_value = _THRESHOLD_VALUE.validate_python( + getattr( + self, + f"{category}_confidence_threshold", + ) ) verbose_proxy_logger.info( f"Google Text Moderation: {category}_confidence_threshold: {set_confidence_value}" diff --git a/enterprise/litellm_enterprise/enterprise_callbacks/example_logging_api.py b/enterprise/litellm_enterprise/enterprise_callbacks/example_logging_api.py index 14d34f5d1e8..e0190ea8da0 100644 --- a/enterprise/litellm_enterprise/enterprise_callbacks/example_logging_api.py +++ b/enterprise/litellm_enterprise/enterprise_callbacks/example_logging_api.py @@ -1,15 +1,20 @@ # this is an example endpoint to receive data from litellm +from typing import Final + from fastapi import FastAPI, HTTPException, Request +from pydantic import TypeAdapter app = FastAPI() +_LOGGED_EVENT: Final = TypeAdapter(object) + @app.post("/log-event") async def log_event(request: Request): try: print("Received /log-event request") # noqa # Assuming the incoming request has JSON data - data = await request.json() + data: Final = _LOGGED_EVENT.validate_python(await request.json()) print("Received request data:") # noqa print(data) # noqa diff --git a/enterprise/litellm_enterprise/enterprise_callbacks/llm_guard.py b/enterprise/litellm_enterprise/enterprise_callbacks/llm_guard.py index 3422e8969b0..e12539eac53 100644 --- a/enterprise/litellm_enterprise/enterprise_callbacks/llm_guard.py +++ b/enterprise/litellm_enterprise/enterprise_callbacks/llm_guard.py @@ -8,25 +8,30 @@ ## This provides an LLM Guard Integration for content moderation on the proxy import asyncio -from typing import Final, Optional +from collections.abc import Mapping +from typing import Final import aiohttp from fastapi import HTTPException +from pydantic import TypeAdapter import litellm from litellm._logging import verbose_proxy_logger from litellm.integrations.custom_logger import CustomLogger +from litellm.llms.openai.common_utils import decoded_json_object from litellm.proxy._types import UserAPIKeyAuth from litellm.secret_managers.main import get_secret_str from litellm.types.utils import CallTypesLiteral +_DECODED_JSON: Final = TypeAdapter(object) + class _ENTERPRISE_LLMGuard(CustomLogger): # Class variables or attributes def __init__( self, mock_testing: bool = False, - mock_redacted_text: Optional[dict] = None, + mock_redacted_text: Mapping[str, object] | None = None, ): self.mock_redacted_text = mock_redacted_text self.llm_guard_mode = litellm.llm_guard_mode @@ -66,7 +71,9 @@ class _ENTERPRISE_LLMGuard(CustomLogger): async with session.post( analyze_url, json={"prompt": text} ) as response: - redacted_text = await response.json() + redacted_text = _DECODED_JSON.validate_python( + await response.json() + ) verbose_proxy_logger.debug( f"LLM Guard: Received response - {redacted_text}" ) @@ -77,12 +84,13 @@ class _ENTERPRISE_LLMGuard(CustomLogger): "error": f"Invalid content moderation response: {redacted_text}" }, ) - if redacted_text.get("is_valid", None) is False: + redacted_response: Final = decoded_json_object(redacted_text) + if redacted_response.get("is_valid", None) is False: raise HTTPException( status_code=400, detail={"error": "Violated content safety policy"}, ) - sanitized_prompt = redacted_text.get("sanitized_prompt") + sanitized_prompt: Final = redacted_response.get("sanitized_prompt") return sanitized_prompt if isinstance(sanitized_prompt, str) else text except Exception as e: verbose_proxy_logger.exception( diff --git a/enterprise/litellm_enterprise/proxy/auth/route_checks.py b/enterprise/litellm_enterprise/proxy/auth/route_checks.py index fc57292a8d2..479537c4a90 100644 --- a/enterprise/litellm_enterprise/proxy/auth/route_checks.py +++ b/enterprise/litellm_enterprise/proxy/auth/route_checks.py @@ -2,6 +2,8 @@ import os from fastapi import HTTPException, status +from litellm.proxy._types import MODEL_LIST_ROUTES + class EnterpriseRouteChecks: @staticmethod @@ -43,7 +45,7 @@ class EnterpriseRouteChecks: # Routes that should remain accessible even when LLM API endpoints are disabled. # These are read-only model listing routes needed by the Admin UI. - LLM_API_EXEMPT_ROUTES = ["/models", "/v1/models"] + LLM_API_EXEMPT_ROUTES = MODEL_LIST_ROUTES @staticmethod def should_call_route(route: str): diff --git a/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py b/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py index df1f263a947..f3b1240f733 100644 --- a/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py +++ b/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py @@ -1040,8 +1040,8 @@ class CheckBatchCost: from litellm.proxy.proxy_server import proxy_config from litellm.secret_managers.main import str_to_bool - api_key: Final = getattr(job, "api_key", None) - team_id: Final = getattr(job, "team_id", None) + api_key: Final = job.api_key if hasattr(job, "api_key") else None + team_id: Final = job.team_id if hasattr(job, "team_id") else None has_key_row: Final = api_key is not None and is_valid_sha256_hash(api_key) try: key_row: Final = ( diff --git a/enterprise/litellm_enterprise/proxy/hooks/managed_files.py b/enterprise/litellm_enterprise/proxy/hooks/managed_files.py index bc35c4a0aba..48cbc0ab8ff 100644 --- a/enterprise/litellm_enterprise/proxy/hooks/managed_files.py +++ b/enterprise/litellm_enterprise/proxy/hooks/managed_files.py @@ -44,6 +44,7 @@ from litellm.constants import ( ) from litellm.files.types import FileRetrieveCallOptions, FileRetrieveProvider from litellm.integrations.custom_logger import CustomLogger +from litellm.litellm_core_utils.core_helpers import require_attributes from litellm.litellm_core_utils.hidden_params import HIDDEN_PARAMS_ATTR from litellm.litellm_core_utils.internal_call_metadata import requests_background from litellm.litellm_core_utils.prompt_templates.common_utils import ( @@ -133,7 +134,7 @@ if TYPE_CHECKING: from litellm.proxy.utils import InternalUsageCache as _InternalUsageCache from litellm.proxy.utils import PrismaClient as _PrismaClient - Span = Union[_Span, Any] + Span = _Span InternalUsageCache = _InternalUsageCache PrismaClient = _PrismaClient else: @@ -490,6 +491,14 @@ _PROVIDER_FILE_ID_KEYS: Final = tuple(dict.fromkeys(chain.from_iterable(_PROVIDE _PROVIDER_FILE_RETRIEVE_RETRY_DELAYS_SECONDS: Final = (0.5, 1.0, 2.0) +class _SupportsKeyedGet(Protocol): + def get(self, key: str, default: object, /) -> object: ... + + +def _keyed_get(source: object, key: str, default: object = None) -> object: + return require_attributes(source, _SupportsKeyedGet, "get").get(key, default) + + class _PROXY_LiteLLMManagedFiles(CustomLogger, BaseFileEndpoints): # Class variables or attributes def __init__( @@ -1611,7 +1620,7 @@ class _PROXY_LiteLLMManagedFiles(CustomLogger, BaseFileEndpoints): return holders if holders or "input_file_id" in request else healthy_deployments async def async_pre_call_deployment_hook( - self, kwargs: Dict[str, Any], call_type: Optional[CallTypes] + self, kwargs: dict[str, object], call_type: Optional[CallTypes] ) -> Optional[dict]: """ Allow modifying the request just before it's sent to the deployment. @@ -1623,11 +1632,11 @@ class _PROXY_LiteLLMManagedFiles(CustomLogger, BaseFileEndpoints): model_file_id_mapping = cast(Optional[Dict[str, Dict[str, str]]], kwargs.get("model_file_id_mapping")) # model_info may be at top-level or nested under litellm_metadata # (batch/file operations use litellm_metadata) - model_id = cast(Optional[str], kwargs.get("model_info", {}).get("id", None)) + model_id = cast(Optional[str], _keyed_get(kwargs.get("model_info", {}), "id")) if model_id is None: model_id = cast( Optional[str], - kwargs.get("litellm_metadata", {}).get("model_info", {}).get("id", None), + _keyed_get(_keyed_get(kwargs.get("litellm_metadata", {}), "model_info", {}), "id"), ) for accessor_key in accessor_keys: input_file_id = cast(Optional[str], kwargs.get(accessor_key)) @@ -1824,7 +1833,7 @@ class _PROXY_LiteLLMManagedFiles(CustomLogger, BaseFileEndpoints): ), ) - async def get_model_file_id_mapping(self, file_ids: Sequence[str], litellm_parent_otel_span: Span) -> dict: + async def get_model_file_id_mapping(self, file_ids: Sequence[str], litellm_parent_otel_span: Span | None) -> dict: """ Get model-specific file IDs for a list of proxy file IDs. Returns a dictionary mapping litellm_proxy/ file_id -> model_id -> model_file_id @@ -1866,7 +1875,7 @@ class _PROXY_LiteLLMManagedFiles(CustomLogger, BaseFileEndpoints): llm_router: Optional[Router], _create_file_request: CreateFileRequest, target_model_names_list: List[str], - litellm_parent_otel_span: Span, + litellm_parent_otel_span: Span | None, ) -> List[OpenAIFileObject]: if llm_router is None: raise Exception("LLM Router not initialized. Ensure models added to proxy.") @@ -1882,7 +1891,7 @@ class _PROXY_LiteLLMManagedFiles(CustomLogger, BaseFileEndpoints): create_file_request: CreateFileRequest, llm_router: Router, target_model_names_list: List[str], - litellm_parent_otel_span: Span, + litellm_parent_otel_span: Span | None, user_api_key_dict: UserAPIKeyAuth, ) -> OpenAIFileObject: responses = await self.create_file_for_each_model( @@ -1949,7 +1958,7 @@ class _PROXY_LiteLLMManagedFiles(CustomLogger, BaseFileEndpoints): file_objects: List[OpenAIFileObject], create_file_request: CreateFileRequest, internal_usage_cache: InternalUsageCache, - litellm_parent_otel_span: Span, + litellm_parent_otel_span: Span | None, target_model_names_list: List[str], ) -> OpenAIFileObject: ## GET THE FILE TYPE FROM THE CREATE FILE REQUEST @@ -2652,7 +2661,7 @@ class _PROXY_LiteLLMManagedFiles(CustomLogger, BaseFileEndpoints): # Continue with other files even if one fails continue - def _get_content_type_from_file_object(self, file_object: Optional[Any]) -> str: + def _get_content_type_from_file_object(self, file_object: object) -> str: """ Determine content type from file object. diff --git a/enterprise/litellm_enterprise/proxy/hooks/managed_vector_stores.py b/enterprise/litellm_enterprise/proxy/hooks/managed_vector_stores.py index 0e9657aba96..fcaf58099b9 100644 --- a/enterprise/litellm_enterprise/proxy/hooks/managed_vector_stores.py +++ b/enterprise/litellm_enterprise/proxy/hooks/managed_vector_stores.py @@ -29,7 +29,7 @@ if TYPE_CHECKING: from litellm.proxy.utils import InternalUsageCache as _InternalUsageCache from litellm.proxy.utils import PrismaClient as _PrismaClient - Span = Union[_Span, Any] + Span = _Span InternalUsageCache = _InternalUsageCache PrismaClient = _PrismaClient else: @@ -107,7 +107,7 @@ class _PROXY_LiteLLMManagedVectorStores( llm_router: Router, model: str, request_data: dict[str, object] | VectorStoreCreateOptionalRequestParams, - litellm_parent_otel_span: Span, + litellm_parent_otel_span: Span | None, ) -> VectorStoreCreateResponse: """ Create a vector store for a specific model. @@ -134,7 +134,7 @@ class _PROXY_LiteLLMManagedVectorStores( create_request: VectorStoreCreateOptionalRequestParams, llm_router: Router, target_model_names_list: List[str], - litellm_parent_otel_span: Span, + litellm_parent_otel_span: Span | None, user_api_key_dict: UserAPIKeyAuth, ) -> VectorStoreCreateResponse: """ diff --git a/enterprise/litellm_enterprise/proxy/liteadmin.py b/enterprise/litellm_enterprise/proxy/liteadmin.py index e89bf11bd6e..bbf42829f47 100644 --- a/enterprise/litellm_enterprise/proxy/liteadmin.py +++ b/enterprise/litellm_enterprise/proxy/liteadmin.py @@ -18,8 +18,8 @@ from fastapi.responses import HTMLResponse, RedirectResponse, Response from pydantic import ConfigDict, Field, SecretStr, TypeAdapter, ValidationError from litellm.llms.custom_httpx.http_handler import get_async_httpx_client -from litellm.proxy._experimental.mcp_server.oauth_utils import get_request_base_url from litellm.proxy._types import LiteLLM_UserTable, LitellmUserRoles, UserAPIKeyAuth +from litellm.proxy.mcp_server.oauth_utils import get_request_base_url from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.auth.auth_checks import UserNotFoundError @@ -122,7 +122,7 @@ def _cookie_name(token: str) -> str: async def _session_user(request: Request) -> str | None: - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( get_authenticated_browser_user_id, ) diff --git a/enterprise/litellm_enterprise/proxy/management_endpoints/project_endpoints.py b/enterprise/litellm_enterprise/proxy/management_endpoints/project_endpoints.py index db419fde1e6..b91b4a970e8 100644 --- a/enterprise/litellm_enterprise/proxy/management_endpoints/project_endpoints.py +++ b/enterprise/litellm_enterprise/proxy/management_endpoints/project_endpoints.py @@ -36,6 +36,7 @@ from litellm.repositories.budget_repository import BudgetRepository from litellm.repositories.object_permission_repository import ObjectPermissionRepository from litellm.repositories.prisma_protocols import TableActions from litellm.repositories.project_repository import ProjectRepository +from litellm.repositories.table_repositories import PrismaTableRepository from litellm.repositories.team_repository import TeamRepository from litellm.repositories.user_repository import UserRepository from litellm.repositories.verification_token_repository import VerificationTokenRepository @@ -73,6 +74,16 @@ def _verification_token_table( return VerificationTokenRepository(prisma_client).table +class _WriterVerificationTokenRepository(PrismaTableRepository["prisma_models.LiteLLM_VerificationToken"]): + table_name = "litellm_verificationtoken" + + +def _writer_verification_token_table( + prisma_client: PrismaClient, +) -> TableActions["prisma_models.LiteLLM_VerificationToken"]: + return _WriterVerificationTokenRepository(prisma_client, use_writer=True).table + + def _budget_table(prisma_client: PrismaClient) -> TableActions["prisma_models.LiteLLM_BudgetTable"]: return BudgetRepository(prisma_client).table @@ -849,7 +860,7 @@ async def update_project( else None ) if current_project is not None and data.team_id != current_project.team_id: - mismatched_key_count: Final = await prisma_client.writer_db.litellm_verificationtoken.count( + mismatched_key_count: Final = await _writer_verification_token_table(prisma_client).count( where={ "project_id": data.project_id, "OR": [{"team_id": {"not": data.team_id}}, {"team_id": None}], diff --git a/enterprise/litellm_enterprise/proxy/vector_stores/endpoints.py b/enterprise/litellm_enterprise/proxy/vector_stores/endpoints.py index 9b87f4f1a7f..19d4988452b 100644 --- a/enterprise/litellm_enterprise/proxy/vector_stores/endpoints.py +++ b/enterprise/litellm_enterprise/proxy/vector_stores/endpoints.py @@ -14,6 +14,7 @@ from collections.abc import Mapping from typing import TYPE_CHECKING, Final, List, Optional, Protocol from fastapi import APIRouter, Depends, HTTPException +from pydantic import TypeAdapter import litellm from litellm._logging import verbose_proxy_logger @@ -37,6 +38,7 @@ if TYPE_CHECKING: from litellm.proxy.utils import PrismaClient router = APIRouter() +_DECODED_JSON: Final = TypeAdapter(object) class ManagedVectorStoreRow(Protocol): @@ -348,11 +350,11 @@ async def update_vector_store( raise HTTPException(status_code=500, detail="Database not connected") try: - update_data = data.model_dump(exclude_unset=True) - vector_store_id: Final[str] = update_data.pop("vector_store_id") + update_data = data.model_dump(exclude_unset=True, exclude={"vector_store_id"}) + vector_store_id: Final = data.vector_store_id if update_data.get("vector_store_metadata") is not None: update_data["vector_store_metadata"] = safe_dumps( - update_data["vector_store_metadata"] + _DECODED_JSON.validate_python(update_data["vector_store_metadata"]) ) updated = await managed_vector_store_table(prisma_client).update( diff --git a/gateway/Dockerfile b/gateway/Dockerfile index 390a5f5666f..69068cfc8a5 100644 --- a/gateway/Dockerfile +++ b/gateway/Dockerfile @@ -1,5 +1,5 @@ -ARG LITELLM_BUILD_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:81211e15a86ea1d5357f284482af45730c51de45eaf10ad9ce205d6bfc2df323 -ARG LITELLM_RUNTIME_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:81211e15a86ea1d5357f284482af45730c51de45eaf10ad9ce205d6bfc2df323 +ARG LITELLM_BUILD_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:360896efb0753a5701c48f860e17130c205eae5a264797aa3e7ea126ee2923a7 +ARG LITELLM_RUNTIME_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:360896efb0753a5701c48f860e17130c205eae5a264797aa3e7ea126ee2923a7 ARG UV_IMAGE=ghcr.io/astral-sh/uv:0.11.7@sha256:240fb85ab0f263ef12f492d8476aa3a2e4e1e333f7d67fbdd923d00a506a516a # Checksum from https://www.pgbouncer.org/downloads/ (the Wolfi repo only carries 1.24.x) ARG PGBOUNCER_VERSION=1.26.0 @@ -140,7 +140,12 @@ ENV HOME=/home/nonroot \ PYTHONUNBUFFERED=1 \ PRISMA_BINARY_CACHE_DIR=/opt/prisma/binaries -COPY --from=builder --chown=nonroot:nonroot /app /app +COPY --from=builder --chown=nonroot:nonroot /app/.venv /app/.venv +COPY --from=builder --chown=nonroot:nonroot /app/litellm /app/litellm +COPY --from=builder --chown=nonroot:nonroot /app/enterprise /app/enterprise +COPY --from=builder --chown=nonroot:nonroot /app/gateway /app/gateway +COPY --from=builder --chown=nonroot:nonroot /app/docker/component_entrypoint.sh /app/docker/component_entrypoint.sh +COPY --from=builder --chown=nonroot:nonroot /app/schema.prisma /app/schema.prisma COPY --from=builder /opt/prisma /opt/prisma COPY --from=pgbouncer-builder /usr/local/bin/pgbouncer /usr/local/bin/pgbouncer diff --git a/litellm-proxy-extras/litellm_proxy_extras/migration_data_checks.py b/litellm-proxy-extras/litellm_proxy_extras/migration_data_checks.py new file mode 100644 index 00000000000..a2d3728349a --- /dev/null +++ b/litellm-proxy-extras/litellm_proxy_extras/migration_data_checks.py @@ -0,0 +1,639 @@ +"""Read-only checks that the rows already in the database can take the pending schema +changes, run before `prisma migrate deploy` and before each request-log index build. + +Postgres has a short list of schema statements that fail because of existing rows: a +btree index whose entry for some row would not fit in a third of a page (2704 bytes on +the default 8 KB page, counting every indexed column), UNIQUE (duplicate values), SET NOT NULL and ADD COLUMN NOT NULL with no default (nulls, any row at all), +FOREIGN KEY (orphans) and CHECK (rows failing the expression). Each pending statement +of one of those kinds becomes one count query derived from the statement text and the +column types in the catalog. A count above zero names the table, the column, the +statement it blocks and the SQL that clears it, and the migration is refused before +anything is applied. Every other statement a migration can contain cannot fail on +existing data and gets no query. A statement the derivation cannot read gets none +either, so the migration keeps today's behavior for it. +""" + +import os +import re +from collections.abc import Callable, Iterator +from dataclasses import dataclass +from functools import reduce +from itertools import accumulate +from pathlib import Path +from types import MappingProxyType +from typing import TYPE_CHECKING, Final, Literal + +from litellm_proxy_extras._logging import logger + +if TYPE_CHECKING: + import psycopg + from psycopg import sql + +DEFAULT_BLOCK_SIZE: Final = 8192 +INDEX_TUPLE_HEADER_BYTES: Final = 8 +NULL_BITMAP_BYTES: Final = 8 +VARLENA_HEADER_BYTES: Final = 4 +SHORT_VARLENA_MAX_BYTES: Final = 126 +_PAGE_HEADER_WITH_THREE_LINE_POINTERS_BYTES: Final = 40 +_BTREE_PAGE_OPAQUE_BYTES: Final = 16 +_HEAP_TID_BYTES: Final = 8 +_ALIGNMENT: Final = MappingProxyType({"c": 1, "s": 2, "i": 4, "d": 8}) +_OCTET_LENGTH_TYPES: Final = frozenset({"text", "varchar", "bpchar", "bytea", "name"}) +MIGRATION_DATA_CHECK_TIMEOUT_ENV_VAR: Final = "LITELLM_MIGRATION_DATA_CHECK_TIMEOUT" +DEFAULT_MIGRATION_DATA_CHECK_TIMEOUT_SECONDS: Final = 600.0 +REFUSAL: Final = "Existing rows would make a pending schema change fail:" +LEGACY_SPEND_LOG_KEY_REMEDY: Final = ( + "Rows written before v1.99.0 hold the raw key. Hash them in place (one-way, idempotent):\n" + ' UPDATE "LiteLLM_SpendLogs" SET api_key = encode(sha256(convert_to(' + "regexp_replace(api_key, '^[Bb][Ee][Aa][Rr][Ee][Rr] ', ''), 'UTF8')), 'hex')\n" + " WHERE api_key <> '' AND api_key !~ '^[0-9a-fA-F]{64}$' AND api_key !~ '^hashed-jwt-[0-9A-Fa-f]{64}$';" +) + +Kind = Literal["too_long", "duplicates", "nulls", "any_row", "orphans", "check_violations"] + + +@dataclass(frozen=True, slots=True) +class Check: + kind: Kind + table: str + columns: tuple[str, ...] + statement: str + source: str + index: str | None = None + referenced_table: str | None = None + referenced_columns: tuple[str, ...] = () + expression: str | None = None + + +@dataclass(frozen=True, slots=True) +class BlockedChange: + check: Check + rows: int + detail: str + + +@dataclass(frozen=True, slots=True) +class CouldNotVerify: + check: Check + timeout_seconds: float + + +Finding = BlockedChange | CouldNotVerify + + +@dataclass(frozen=True, slots=True) +class ColumnType: + """One column as `pg_attribute` and `pg_type` describe it: `length` is `attlen` (-1 for a + variable-length value), `align` is `attalign` (c, s, i or d), `typmod` is `atttypmod`.""" + + type_name: str + length: int + align: str + typmod: int + + @property + def is_variable_length(self) -> bool: + return self.length == -1 + + @property + def can_overflow_btree(self) -> bool: + """Whether one value of this column alone can push a btree entry past the limit: a + variable-length type with no declared cap, or a cap of more bytes than the limit.""" + if not self.is_variable_length: + return False + return self.typmod == -1 or (self.typmod - VARLENA_HEADER_BYTES) * 4 > btree_max_entry_bytes(DEFAULT_BLOCK_SIZE) + + +ColumnTypeLookup = Callable[[str, str], ColumnType | None] + +_IDENT: Final = r'"?(\w+)"?' +_QUALIFIED: Final = r'(?:"?\w+"?\s*\.\s*)?"?(\w+)"?' +_CREATE_INDEX: Final = re.compile( + rf"^\s*CREATE\s+(UNIQUE\s+)?INDEX\s+(?:CONCURRENTLY\s+)?(?:IF\s+NOT\s+EXISTS\s+)?{_IDENT}\s+ON\s+(?:ONLY\s+)?" + rf"{_QUALIFIED}\s*(?:USING\s+(\w+)\s*)?\((.*?)\)", + re.IGNORECASE | re.DOTALL, +) +_ALTER_TABLE: Final = re.compile( + rf"^\s*ALTER\s+TABLE\s+(?:IF\s+EXISTS\s+)?(?:ONLY\s+)?{_QUALIFIED}\s+(.*)$", re.IGNORECASE | re.DOTALL +) +_SET_NOT_NULL: Final = re.compile(rf"^ALTER\s+(?:COLUMN\s+)?{_IDENT}\s+SET\s+NOT\s+NULL$", re.IGNORECASE) +_ADD_COLUMN: Final = re.compile( + rf"^ADD\s+(?:COLUMN\s+)?(?:IF\s+NOT\s+EXISTS\s+)?(?!(?:CONSTRAINT|FOREIGN|UNIQUE|CHECK|PRIMARY|EXCLUDE)\b){_IDENT}\s+(.*)$", + re.IGNORECASE | re.DOTALL, +) +_CONSTRAINT: Final = rf"^ADD\s+(?:CONSTRAINT\s+{_IDENT}\s+)?" +_ADD_FOREIGN_KEY: Final = re.compile( + rf"{_CONSTRAINT}FOREIGN\s+KEY\s*\(([^)]*)\)\s*REFERENCES\s+{_QUALIFIED}\s*\(([^)]*)\)(.*)$", + re.IGNORECASE | re.DOTALL, +) +_ADD_UNIQUE: Final = re.compile(rf"{_CONSTRAINT}UNIQUE\s*\(([^)]*)\)", re.IGNORECASE | re.DOTALL) +_ADD_CHECK: Final = re.compile(rf"{_CONSTRAINT}CHECK\s*\((.*)\)\s*(NOT\s+VALID)?\s*$", re.IGNORECASE | re.DOTALL) +_PLAIN_COLUMN: Final = re.compile(rf"^{_IDENT}(?:\s+(?:ASC|DESC|NULLS\s+(?:FIRST|LAST)))*$", re.IGNORECASE) +_COMMENT: Final = re.compile(r"--[^\n]*") +_NOT_NULL: Final = re.compile(r"\bNOT\s+NULL\b", re.IGNORECASE) +_HAS_DEFAULT: Final = re.compile(r"\bDEFAULT\b|\bGENERATED\b", re.IGNORECASE) + + +def migration_data_check_timeout_seconds() -> float: + """Seconds one count query may run before the preflight gives up on verifying it.""" + raw: Final = os.getenv(MIGRATION_DATA_CHECK_TIMEOUT_ENV_VAR) + if raw is None: + return DEFAULT_MIGRATION_DATA_CHECK_TIMEOUT_SECONDS + try: + return float(raw) + except ValueError: + logger.warning( + "%s=%r is not a number, using %s", + MIGRATION_DATA_CHECK_TIMEOUT_ENV_VAR, + raw, + DEFAULT_MIGRATION_DATA_CHECK_TIMEOUT_SECONDS, + ) + return DEFAULT_MIGRATION_DATA_CHECK_TIMEOUT_SECONDS + + +def statements(migration_sql: str) -> tuple[str, ...]: + """The statements of one migration file, comments stripped, empty ones dropped.""" + parts: Final = _COMMENT.sub("", migration_sql).split(";") + return tuple(part.strip() for part in parts if part.strip()) + + +def _split_top_level(text: str) -> tuple[str, ...]: + """Split on the commas outside parentheses.""" + depth: Final = accumulate((1 if char == "(" else -1 if char == ")" else 0) for char in text) + cuts: Final = tuple( + position for position, (char, level) in enumerate(zip(text, depth, strict=True)) if char == "," and level == 0 + ) + starts: Final = (0, *(cut + 1 for cut in cuts)) + stops: Final = (*cuts, len(text)) + pieces: Final = tuple(text[start:stop].strip() for start, stop in zip(starts, stops, strict=True)) + return tuple(piece for piece in pieces if piece) + + +def _plain_columns(column_list: str) -> tuple[str, ...] | None: + """The column names of an index or constraint column list, None when one entry is an + expression the derivation cannot turn into a count.""" + matches: Final = tuple(_PLAIN_COLUMN.match(entry) for entry in _split_top_level(column_list)) + if any(match is None for match in matches): + return None + return tuple(match.group(1) for match in matches if match is not None) + + +def _index_checks(match: "re.Match[str]", statement_text: str, source: str) -> Iterator[Check]: + unique, name, table, method, column_list = match.groups() + columns: Final = _plain_columns(column_list) + if columns is None: + return + label: Final = f'CREATE {"UNIQUE " if unique else ""}INDEX "{name}"' + if method is None or method.lower() == "btree": + yield Check("too_long", table, columns, label, source, index=name) + if unique: + yield Check("duplicates", table, columns, label, source, index=name) + + +def _alter_table_checks(table: str, action: str, source: str) -> Iterator[Check]: + if (set_not_null := _SET_NOT_NULL.match(action)) is not None: + yield Check("nulls", table, (set_not_null.group(1),), f'ALTER TABLE "{table}" {action}', source) + return + if (add_column := _ADD_COLUMN.match(action)) is not None: + column, body = add_column.groups() + if _NOT_NULL.search(body) is not None and _HAS_DEFAULT.search(body) is None: + yield Check( + "any_row", table, (column,), f'ALTER TABLE "{table}" ADD COLUMN "{column}" ... NOT NULL', source + ) + return + if (foreign_key := _ADD_FOREIGN_KEY.match(action)) is not None: + constraint, columns, referenced_table, referenced_columns, tail = foreign_key.groups() + own: Final = _plain_columns(columns) + theirs: Final = _plain_columns(referenced_columns) + if own is None or theirs is None or len(own) != len(theirs) or "NOT VALID" in tail.upper(): + return + yield Check( + "orphans", + table, + own, + _constraint_label(table, constraint, "FOREIGN KEY"), + source, + referenced_table=referenced_table, + referenced_columns=theirs, + ) + return + if (unique := _ADD_UNIQUE.match(action)) is not None: + constraint, columns = unique.groups() + unique_columns: Final = _plain_columns(columns) + if unique_columns is not None: + yield Check("duplicates", table, unique_columns, _constraint_label(table, constraint, "UNIQUE"), source) + return + if (check := _ADD_CHECK.match(action)) is not None: + constraint, expression, not_valid = check.groups() + if not_valid is None: + yield Check( + "check_violations", + table, + (), + _constraint_label(table, constraint, "CHECK"), + source, + expression=expression, + ) + + +def _constraint_label(table: str, constraint: str | None, kind: str) -> str: + named: Final = f'CONSTRAINT "{constraint}" ' if constraint else "" + return f'ALTER TABLE "{table}" ADD {named}{kind}' + + +def checks_for_statement(statement_text: str, source: str) -> tuple[Check, ...]: + """The count queries one SQL statement needs before it can be applied, empty for a + statement that cannot fail on existing rows or that the derivation cannot read.""" + if (index := _CREATE_INDEX.match(statement_text)) is not None: + return tuple(_index_checks(index, statement_text, source)) + if (alter := _ALTER_TABLE.match(statement_text)) is not None: + table, actions = alter.groups() + return tuple( + check for action in _split_top_level(actions) for check in _alter_table_checks(table, action, source) + ) # comprehension-ok: flattening the per-action checks of one statement + return () + + +def checks_for_migration(name: str, migration_sql: str) -> tuple[Check, ...]: + return tuple( + check + for statement_text in statements(migration_sql) + for check in checks_for_statement(statement_text, f"migration {name}") + ) # comprehension-ok: flattening the per-statement checks of one migration + + +def checks_for_index(table: str, name: str, columns: tuple[str, ...]) -> tuple[Check, ...]: + """The entry-size check a request-log index needs before `CREATE INDEX CONCURRENTLY`.""" + return (Check("too_long", table, columns, f'CREATE INDEX "{name}"', "request-log index", index=name),) + + +def _applied_migrations(connection: "psycopg.Connection[tuple[object, ...]]", schema: str) -> frozenset[str]: + import psycopg + from psycopg import sql + + try: + rows: Final = connection.execute( + sql.SQL("SELECT migration_name FROM {} WHERE finished_at IS NOT NULL AND rolled_back_at IS NULL").format( + sql.Identifier(schema, "_prisma_migrations") + ) + ).fetchall() + except psycopg.errors.UndefinedTable: + return frozenset() + return frozenset(str(row[0]) for row in rows) + + +def pending_migrations( + connection: "psycopg.Connection[tuple[object, ...]]", schema: str, migrations_dir: Path +) -> tuple[tuple[str, str], ...]: + """(name, sql) of every shipped migration the ledger has not finished, oldest first. + Without a ledger every migration is pending, and the checks skip tables that do not exist yet.""" + applied: Final = _applied_migrations(connection, schema) + folders: Final = tuple(folder for folder in sorted(migrations_dir.iterdir()) if folder.is_dir()) + return tuple( + (folder.name, (folder / "migration.sql").read_text()) + for folder in folders + if folder.name not in applied and (folder / "migration.sql").is_file() + ) + + +def _int(value: object, default: int) -> int: + return value if isinstance(value, int) else default + + +def column_type_lookup(connection: "psycopg.Connection[tuple[object, ...]]", schema: str) -> ColumnTypeLookup: + def lookup(table: str, column: str) -> ColumnType | None: + row: Final = connection.execute( + "SELECT t.typname, a.attlen, a.attalign, a.atttypmod FROM pg_attribute a " + "JOIN pg_class c ON c.oid = a.attrelid JOIN pg_namespace n ON n.oid = c.relnamespace " + "JOIN pg_type t ON t.oid = a.atttypid " + "WHERE n.nspname = %s AND c.relname = %s AND a.attname = %s AND a.attnum > 0 AND NOT a.attisdropped", + (schema, table, column), + ).fetchone() + if row is None: + return None + return ColumnType(str(row[0]), _int(row[1], -1), str(row[2]), _int(row[3], -1)) + + return lookup + + +def _column_types(check: Check, column_type: ColumnTypeLookup) -> tuple[ColumnType, ...] | None: + """The catalog types of the check's columns, None when one of them is not there yet.""" + types: Final = tuple(column_type(check.table, column) for column in check.columns) + if any(column is None for column in types): + return None + return tuple(column for column in types if column is not None) + + +def _table_exists(connection: "psycopg.Connection[tuple[object, ...]]", schema: str, table: str) -> bool: + row: Final = connection.execute( + "SELECT 1 FROM information_schema.tables WHERE table_schema = %s AND table_name = %s", (schema, table) + ).fetchone() + return row is not None + + +def _index_is_valid(connection: "psycopg.Connection[tuple[object, ...]]", schema: str, index: str) -> bool: + row: Final = connection.execute( + "SELECT x.indisvalid FROM pg_index x JOIN pg_class i ON i.oid = x.indexrelid " + "JOIN pg_namespace n ON n.oid = i.relnamespace WHERE n.nspname = %s AND i.relname = %s", + (schema, index), + ).fetchone() + return row is not None and bool(row[0]) + + +def btree_max_entry_bytes(block_size: int) -> int: + """`BTMaxItemSize` from nbtree.h for btree version 4: a third of the page left after the page + header, three line pointers and the btree opaque area, rounded down to 8, minus the heap TID a + pivot tuple carries. 2704 on the default 8 KB page, the number in Postgres's error.""" + usable: Final = block_size - _PAGE_HEADER_WITH_THREE_LINE_POINTERS_BYTES - _BTREE_PAGE_OPAQUE_BYTES + return (usable // 3) // 8 * 8 - _HEAP_TID_BYTES + + +def _value_bytes(column: ColumnType, identifier: "sql.Identifier") -> "sql.Composed": + from psycopg import sql + + if column.type_name in _OCTET_LENGTH_TYPES: + return sql.SQL("octet_length({})").format(identifier) + return sql.SQL("octet_length({}::text)").format(identifier) + + +def _aligned(offset: "sql.Composable", align: str) -> "sql.Composed": + from psycopg import sql + + unit: Final = _ALIGNMENT.get(align, 8) + return sql.SQL("(({off} + {pad}) / {unit}) * {unit}").format( + off=offset, pad=sql.Literal(unit - 1), unit=sql.Literal(unit) + ) + + +def _value_end(column: ColumnType, identifier: "sql.Identifier", offset: "sql.Composable") -> "sql.Composed": + """Where this column's value ends when laid down from `offset` the way `index_form_tuple` + does it: NULL takes no room, a fixed-length value is aligned to its type, a variable-length + value of up to 126 bytes gets a 1-byte header and no alignment, a longer one a 4-byte header.""" + from psycopg import sql + + length: Final = _value_bytes(column, identifier) + placed: Final = ( + sql.SQL("{} + {}").format(_aligned(offset, column.align), sql.Literal(column.length)) + if not column.is_variable_length + else sql.SQL("CASE WHEN {len} <= {short} THEN {off} + 1 + {len} ELSE {aligned} + {hdr} + {len} END").format( + len=length, + short=sql.Literal(SHORT_VARLENA_MAX_BYTES), + off=offset, + aligned=_aligned(offset, column.align), + hdr=sql.Literal(VARLENA_HEADER_BYTES), + ) + ) + return sql.SQL("CASE WHEN {col} IS NULL THEN {off} ELSE {placed} END").format( + col=identifier, off=offset, placed=placed + ) + + +def _entry_size_query(check: Check, schema: str, types: tuple[ColumnType, ...], limit_bytes: int) -> "sql.Composed": + """count(*) and the largest entry over the rows whose btree entry would not fit, plus the + longest value of each variable-length column: an 8-byte tuple header, 8 more for the null + bitmap when a column is NULL, each value laid down in index order, the total rounded up to 8.""" + from psycopg import sql + + identifiers: Final = tuple(sql.Identifier(column) for column in check.columns) + any_null: Final = sql.SQL(" OR ").join(sql.SQL("{} IS NULL").format(identifier) for identifier in identifiers) + header: Final = sql.SQL("{} + CASE WHEN {} THEN {} ELSE 0 END").format( + sql.Literal(INDEX_TUPLE_HEADER_BYTES), any_null, sql.Literal(NULL_BITMAP_BYTES) + ) + innermost: Final = sql.SQL("SELECT {cols}, {hdr} AS off0 FROM {t}").format( + cols=sql.SQL(", ").join(identifiers), hdr=header, t=sql.Identifier(schema, check.table) + ) + + def lay_down(inner: "sql.Composed", step: tuple[int, tuple[ColumnType, "sql.Identifier"]]) -> "sql.Composed": + position, (column, identifier) = step + return sql.SQL("SELECT *, {end} AS {next} FROM ({inner}) AS {alias}").format( + end=_value_end(column, identifier, sql.Identifier(f"off{position}")), + next=sql.Identifier(f"off{position + 1}"), + inner=inner, + alias=sql.Identifier(f"s{position}"), + ) + + laid_out: Final = reduce(lay_down, enumerate(zip(types, identifiers, strict=True)), innermost) + entry: Final = _aligned(sql.Identifier(f"off{len(types)}"), "d") + longest: Final = sql.SQL("").join( + sql.SQL(", max({})").format(_value_bytes(column, identifier)) + for column, identifier in zip(types, identifiers, strict=True) + if column.is_variable_length + ) + return sql.SQL("SELECT count(*), max({entry}){longest} FROM ({rows}) AS entries WHERE {entry} > {limit}").format( + entry=entry, longest=longest, rows=laid_out, limit=sql.Literal(limit_bytes) + ) + + +def _count_query(check: Check, schema: str, types: tuple[ColumnType, ...], limit_bytes: int) -> "sql.Composed": + from psycopg import sql + + table: Final = sql.Identifier(schema, check.table) + columns: Final = sql.SQL(", ").join(sql.Identifier(column) for column in check.columns) + match check.kind: + case "too_long": + return _entry_size_query(check, schema, types, limit_bytes) + case "duplicates": + not_null: Final = sql.SQL(" AND ").join( + sql.SQL("{} IS NOT NULL").format(sql.Identifier(column)) for column in check.columns + ) + return sql.SQL( + "SELECT count(*) FROM (SELECT 1 FROM {t} WHERE {nn} GROUP BY {cols} HAVING count(*) > 1) AS d" + ).format(t=table, nn=not_null, cols=columns) + case "nulls": + return sql.SQL("SELECT count(*) FROM {t} WHERE {col} IS NULL").format( + t=table, col=sql.Identifier(check.columns[0]) + ) + case "any_row": + return sql.SQL("SELECT count(*) FROM {t}").format(t=table) + case "orphans": + pairs: Final = sql.SQL(" AND ").join( + sql.SQL("parent.{} = child.{}").format(sql.Identifier(theirs), sql.Identifier(own)) + for own, theirs in zip(check.columns, check.referenced_columns, strict=True) + ) + present: Final = sql.SQL(" AND ").join( + sql.SQL("child.{} IS NOT NULL").format(sql.Identifier(column)) for column in check.columns + ) + return sql.SQL( + "SELECT count(*) FROM {t} AS child WHERE {present} AND NOT EXISTS (SELECT 1 FROM {ref} AS parent WHERE {pairs})" + ).format(t=table, present=present, ref=sql.Identifier(schema, check.referenced_table or ""), pairs=pairs) + case "check_violations": + return sql.SQL("SELECT count(*) FROM {t} WHERE NOT ({expr})").format( + t=table, + expr=sql.SQL(check.expression or "true"), # pyright: ignore[reportArgumentType] # copied from our own migration file + ) + + +def _applies( + connection: "psycopg.Connection[tuple[object, ...]]", + schema: str, + check: Check, + types: tuple[ColumnType, ...] | None, +) -> bool: + """False when the check has nothing to count yet: the table or a column is not there + (a pending migration adds it), the index is already valid, or no column can overflow.""" + if not _table_exists(connection, schema, check.table): + return False + if check.index is not None and _index_is_valid(connection, schema, check.index): + return False + if check.kind == "any_row": + return types is None + if types is None: + return False + if check.kind == "too_long": + return any(column.can_overflow_btree for column in types) + if check.kind == "orphans": + return check.referenced_table is not None and _table_exists(connection, schema, check.referenced_table) + return True + + +def _too_long_detail(check: Check, types: tuple[ColumnType, ...], values: tuple[object, ...], limit_bytes: int) -> str: + variable: Final = tuple( + column for column, column_type in zip(check.columns, types, strict=True) if column_type.is_variable_length + ) + longest: Final = ", ".join( + f"{column} up to {length} bytes" + for column, length in zip(variable, values[2:], strict=True) + if length is not None + ) + return f"with an index entry over {limit_bytes} bytes, largest {values[1]} bytes ({longest})" + + +def _run_check( + connection: "psycopg.Connection[tuple[object, ...]]", + schema: str, + check: Check, + types: tuple[ColumnType, ...], + limit_bytes: int, + timeout_seconds: float, +) -> Finding | None: + import psycopg + + try: + row: Final = connection.execute(_count_query(check, schema, types, limit_bytes)).fetchone() + except psycopg.errors.QueryCanceled: + return CouldNotVerify(check, timeout_seconds) + values: Final[tuple[object, ...]] = row if row is not None else () + rows: Final = _int(values[0], 0) if values else 0 + if rows == 0: + return None + match check.kind: + case "too_long": + return BlockedChange(check, rows, _too_long_detail(check, types, values, limit_bytes)) + case "duplicates": + return BlockedChange(check, rows, "duplicated value groups") + case "nulls": + return BlockedChange(check, rows, "NULL") + case "any_row": + return BlockedChange( + check, rows, "rows, and a NOT NULL column with no DEFAULT cannot be added to a table with rows" + ) + case "orphans": + return BlockedChange(check, rows, f'with no matching row in "{check.referenced_table}"') + case "check_violations": + return BlockedChange(check, rows, f"failing CHECK ({check.expression})") + + +def find_blockers( + connection: "psycopg.Connection[tuple[object, ...]]", + schema: str, + checks: tuple[Check, ...], + timeout_seconds: float = DEFAULT_MIGRATION_DATA_CHECK_TIMEOUT_SECONDS, +) -> tuple[Finding, ...]: + """Run every applicable check read-only, each under `timeout_seconds`. Never writes + and never takes a table lock; a check that times out is a finding, not a pass.""" + from psycopg import sql + + previous_timeout: Final = connection.execute("SHOW statement_timeout").fetchone() + previous_read_only: Final = connection.execute("SHOW default_transaction_read_only").fetchone() + block_size: Final = connection.execute("SHOW block_size").fetchone() + limit_bytes: Final = btree_max_entry_bytes(int(str(block_size[0])) if block_size else DEFAULT_BLOCK_SIZE) + connection.execute("SET default_transaction_read_only = on") + connection.execute(sql.SQL("SET statement_timeout = {}").format(sql.Literal(int(timeout_seconds * 1000)))) + column_type: Final = column_type_lookup(connection, schema) + typed: Final = tuple((check, _column_types(check, column_type)) for check in checks) + applicable: Final = tuple( + (check, types if types is not None else ()) + for check, types in typed + if _applies(connection, schema, check, types) + ) + results: Final = tuple( + _run_check(connection, schema, check, types, limit_bytes, timeout_seconds) for check, types in applicable + ) + connection.execute( + sql.SQL("SET statement_timeout = {}").format(sql.Literal(str(previous_timeout[0]) if previous_timeout else "0")) + ) + connection.execute( + sql.SQL("SET default_transaction_read_only = {}").format( + sql.Literal(str(previous_read_only[0]) if previous_read_only else "off") + ) + ) + return tuple(result for result in results if result is not None) + + +def _remedy(check: Check) -> str: + if check.kind == "too_long" and check.table == "LiteLLM_SpendLogs" and "api_key" in check.columns: + return LEGACY_SPEND_LOG_KEY_REMEDY + joined: Final = ", ".join(check.columns) + match check.kind: + case "too_long": + return f'Shorten or hash the long "{check.table}" ({joined}) values so every row\'s index entry fits.' + case "duplicates": + return f'Remove or merge the duplicate "{check.table}" ({joined}) values.' + case "nulls": + return f'Fill the NULL "{check.table}"."{joined}" values, or give the column a default first.' + case "any_row": + return "Give the new column a DEFAULT in the migration, or add it nullable and fill it afterwards." + case "orphans": + return f'Delete or repoint the "{check.table}" ({joined}) values with no "{check.referenced_table}" row.' + case "check_violations": + return f'Fix the "{check.table}" rows that fail the expression before adding the constraint.' + + +def _describe(finding: Finding) -> str: + check: Final = finding.check + where: Final = f'"{check.table}"' + (f".{', '.join(check.columns)}" if check.columns else "") + match finding: + case CouldNotVerify(timeout_seconds=seconds): + return ( + f" {where}: could not be checked within {seconds:g} s, refusing rather than guessing\n" + f" blocks: {check.statement} ({check.source})\n" + f" raise {MIGRATION_DATA_CHECK_TIMEOUT_ENV_VAR} to give the scan more time" + ) + case BlockedChange(rows=rows, detail=detail): + return ( + f" {where}: {rows} row(s) {detail}\n" + f" blocks: {check.statement} ({check.source})\n" + f" fix: {_remedy(check).replace(chr(10), chr(10) + ' ' * 8)}" + ) + + +def report(findings: tuple[Finding, ...]) -> str: + """The operator-facing refusal: one block per finding, then what to do next.""" + lines: Final = "\n".join(_describe(finding) for finding in findings) + return ( + f"{REFUSAL}\n{lines}\n" + "No schema change was made. Fix the rows and start again, or run `litellm --check_migrations_against_existing_data` with the new image to check again." + ) + + +def pending_change_checks( + connection: "psycopg.Connection[tuple[object, ...]]", + schema: str, + migrations_dir: Path | None, + indexes: tuple[tuple[str, str, tuple[str, ...]], ...], +) -> tuple[Check, ...]: + """Every check the pending migrations and the request-log indexes need. `migrations_dir` + is None when the schema is pushed rather than migrated, so only the indexes are checked.""" + migration_checks: Final = ( + tuple( + check + for name, migration_sql in pending_migrations(connection, schema, migrations_dir) + for check in checks_for_migration(name, migration_sql) + ) # comprehension-ok: flattening the per-migration checks + if migrations_dir is not None + else () + ) + index_checks: Final = tuple( + check for table, name, columns in indexes for check in checks_for_index(table, name, columns) + ) # comprehension-ok: flattening the per-index checks + return migration_checks + index_checks diff --git a/litellm-proxy-extras/litellm_proxy_extras/request_log_indexes.py b/litellm-proxy-extras/litellm_proxy_extras/request_log_indexes.py index 6c31e8364a9..4c856c741d3 100644 --- a/litellm-proxy-extras/litellm_proxy_extras/request_log_indexes.py +++ b/litellm-proxy-extras/litellm_proxy_extras/request_log_indexes.py @@ -18,6 +18,12 @@ from dataclasses import dataclass from typing import TYPE_CHECKING, Final from litellm_proxy_extras._logging import logger +from litellm_proxy_extras.migration_data_checks import ( + checks_for_index, + find_blockers, + migration_data_check_timeout_seconds, + report, +) from litellm_proxy_extras.migration_lock import held_migration_lock if TYPE_CHECKING: @@ -355,6 +361,12 @@ def _build_leaf_index( connection.execute(sql.SQL("DROP INDEX CONCURRENTLY {}").format(sql.Identifier(schema, name))) elif _adopt_equivalent_index(connection, schema, table, name, index): return True + blockers: Final = find_blockers( + connection, schema, checks_for_index(table, name, index.columns), migration_data_check_timeout_seconds() + ) + if blockers: + logger.warning("Not building index %s on %s. %s", name, table, report(blockers)) + return False logger.info("Building index %s on %s concurrently", name, table) prefix: Final = sql.SQL("CREATE INDEX CONCURRENTLY IF NOT EXISTS {} ON {} ").format( sql.Identifier(name), sql.Identifier(schema, table) diff --git a/litellm-proxy-extras/litellm_proxy_extras/utils.py b/litellm-proxy-extras/litellm_proxy_extras/utils.py index be785e2fd78..528bf7def20 100644 --- a/litellm-proxy-extras/litellm_proxy_extras/utils.py +++ b/litellm-proxy-extras/litellm_proxy_extras/utils.py @@ -16,6 +16,13 @@ from typing import TYPE_CHECKING, Final, Optional, Protocol, Union from litellm_proxy_extras import prisma_toolchain from litellm_proxy_extras._logging import logger from litellm_proxy_extras._redaction import _redact_credentials +from litellm_proxy_extras.migration_data_checks import ( + Finding, + find_blockers, + migration_data_check_timeout_seconds, + pending_change_checks, + report, +) from litellm_proxy_extras.migration_lock import held_migration_lock from litellm_proxy_extras.prisma_toolchain import ( PRISMA_COMMAND_TIMEOUT_ENV_VAR, @@ -28,7 +35,11 @@ from litellm_proxy_extras.replica_identity import ( REPLICA_IDENTITY_FULL_ENV_VAR, apply_replica_identity_full, ) -from litellm_proxy_extras.request_log_indexes import ensure_request_log_indexes, filter_request_log_index_diff +from litellm_proxy_extras.request_log_indexes import ( + REQUEST_LOG_INDEXES, + ensure_request_log_indexes, + filter_request_log_index_diff, +) if TYPE_CHECKING: import psycopg @@ -53,9 +64,7 @@ def _get_prisma_env() -> dict: if str_to_bool(os.getenv("PRISMA_OFFLINE_MODE")): # These env vars prevent Prisma from attempting downloads prisma_env["NPM_CONFIG_PREFER_OFFLINE"] = "true" - prisma_env["NPM_CONFIG_CACHE"] = os.getenv( - "NPM_CONFIG_CACHE", "/app/.cache/npm" - ) + prisma_env["NPM_CONFIG_CACHE"] = os.getenv("NPM_CONFIG_CACHE", "/app/.cache/npm") return prisma_env @@ -86,6 +95,7 @@ class _InvalidIndex: name: str table_size: str + MAX_MIGRATE_DEPLOY_ATTEMPTS = 4 LIBPQ_URL_PARAMS: Final = frozenset( { @@ -135,9 +145,7 @@ class _MigrateAttemptBudget: _SPEND_LOGS_ALTER_RE = re.compile(r'^ALTER\s+TABLE\s+"LiteLLM_SpendLogs"\s', re.IGNORECASE) -_SPEND_LOGS_ARTIFACT_DROP_RE = re.compile( - r'^DROP\s+TABLE\s+"LiteLLM_SpendLogs_[^"]*"', re.IGNORECASE -) +_SPEND_LOGS_ARTIFACT_DROP_RE = re.compile(r'^DROP\s+TABLE\s+"LiteLLM_SpendLogs_[^"]*"', re.IGNORECASE) _SPEND_LOGS_PK_CLAUSE_RE = re.compile( r'^(?:DROP\s+CONSTRAINT\s+"[^"]*_pkey"' r'|ADD\s+(?:CONSTRAINT\s+"[^"]*"\s+)?PRIMARY\s+KEY\s*\([^)]*\))$', @@ -146,9 +154,9 @@ _SPEND_LOGS_PK_CLAUSE_RE = re.compile( PARTITIONED_SPEND_LOGS_PUSH_ERROR = ( "LiteLLM_SpendLogs is a partitioned table (see db_scripts/partition_spend_logs.sql), " - "so its primary key must include the partition key (\"startTime\"). `prisma db push` " + 'so its primary key must include the partition key ("startTime"). `prisma db push` ' "reconciles the database against schema.prisma, which declares the unpartitioned " - "primary key (\"request_id\"), and Postgres rejects that rewrite with: unique " + 'primary key ("request_id"), and Postgres rejects that rewrite with: unique ' "constraint on partitioned table must include all partitioning columns. Start the " "proxy without --use_prisma_db_push so it uses `prisma migrate deploy`, which only " "applies shipped migrations and leaves the partitioned primary key alone." @@ -157,9 +165,7 @@ PARTITIONED_SPEND_LOGS_PUSH_ERROR = ( def _without_sql_comments(statement: str) -> str: return "\n".join( - line - for line in statement.splitlines() - if line.strip() and not line.strip().startswith("--") + line for line in statement.splitlines() if line.strip() and not line.strip().startswith("--") ).strip() @@ -169,7 +175,7 @@ def _without_spend_logs_pk_clauses(statement: str) -> Optional[str]: return statement kept = tuple( clause.strip() - for clause in statement[prefix_match.end():].split(",\n") + for clause in statement[prefix_match.end() :].split(",\n") if not _SPEND_LOGS_PK_CLAUSE_RE.match(clause.strip()) ) if not kept: @@ -243,8 +249,7 @@ def _get_prisma_command() -> str: # If not found, log warning and fall back logger.warning( - f"Prisma CLI not found at {default_cli_path}. " - "Falling back to Python wrapper (may attempt downloads)" + f"Prisma CLI not found at {default_cli_path}. Falling back to Python wrapper (may attempt downloads)" ) # Fall back to the Python wrapper (will work in online mode) @@ -331,9 +336,7 @@ class ProxyExtrasDBManager: return True except subprocess.TimeoutExpired: - logger.warning( - "Migration timed out - the database might be under heavy load." - ) + logger.warning("Migration timed out - the database might be under heavy load.") return False except subprocess.CalledProcessError as e: logger.warning( @@ -386,10 +389,12 @@ class ProxyExtrasDBManager: except ImportError: return None + from psycopg import sql + cleaned_url: Final = ProxyExtrasDBManager._strip_prisma_query_params(database_url) - ledger_table: Final = psycopg.sql.SQL("{}.{}").format( - psycopg.sql.Identifier(ProxyExtrasDBManager._prisma_schema_param(database_url) or "public"), - psycopg.sql.Identifier("_prisma_migrations"), + ledger_table: Final = sql.SQL("{}.{}").format( + sql.Identifier(ProxyExtrasDBManager._prisma_schema_param(database_url) or "public"), + sql.Identifier("_prisma_migrations"), ) try: with psycopg.connect(cleaned_url, connect_timeout=10, autocommit=True) as conn: @@ -500,9 +505,7 @@ class ProxyExtrasDBManager: return filter_partitioned_spend_logs_diff(without_indexes) @staticmethod - def _resolve_all_migrations( - migrations_dir: str, schema_path: str, mark_all_applied: bool = True - ): + def _resolve_all_migrations(migrations_dir: str, schema_path: str, mark_all_applied: bool = True): """ 1. Compare the current database state to schema.prisma and generate a migration for the diff. 2. Run prisma migrate deploy to apply any pending migrations. @@ -571,9 +574,7 @@ class ProxyExtrasDBManager: ) logger.info(f"Applied migration: {mig_file.parent.name}") except subprocess.CalledProcessError as e: - logger.warning( - f"Failed to apply migration {mig_file.parent.name}: {e.stderr}" - ) + logger.warning(f"Failed to apply migration {mig_file.parent.name}: {e.stderr}") except subprocess.TimeoutExpired: logger.warning(f"Migration {mig_file.parent.name} timed out.") return @@ -645,9 +646,7 @@ class ProxyExtrasDBManager: logger.debug(f"Resolved migration: {migration_name}") except subprocess.CalledProcessError as e: if "is already recorded as applied in the database." not in e.stderr: - logger.warning( - f"Failed to resolve migration {migration_name}: {e.stderr}" - ) + logger.warning(f"Failed to resolve migration {migration_name}: {e.stderr}") @staticmethod def raise_if_lens_rename_pending(connect: LensCheckConnect | None = None) -> None: @@ -707,9 +706,7 @@ class ProxyExtrasDBManager: cleaned_url = ProxyExtrasDBManager._strip_prisma_query_params(database_url) try: - with psycopg.connect( - cleaned_url, connect_timeout=10, autocommit=True - ) as conn: + with psycopg.connect(cleaned_url, connect_timeout=10, autocommit=True) as conn: row = conn.execute( "SELECT 1 " "FROM pg_partitioned_table pt " @@ -717,10 +714,7 @@ class ProxyExtrasDBManager: "JOIN pg_namespace n ON n.oid = c.relnamespace " "WHERE c.relname = 'LiteLLM_SpendLogs' " " AND n.nspname = %s", - ( - ProxyExtrasDBManager._prisma_schema_param(database_url) - or "public", - ), + (ProxyExtrasDBManager._prisma_schema_param(database_url) or "public",), ).fetchone() except (psycopg.OperationalError, psycopg.DatabaseError): return False @@ -815,9 +809,7 @@ class ProxyExtrasDBManager: # it, psycopg3's `with conn` calls COMMIT on clean exit — which # fails after `UndefinedTable` (fresh DB) leaves the transaction # in an aborted state. - with psycopg.connect( - cleaned_url, connect_timeout=10, autocommit=True - ) as conn: + with psycopg.connect(cleaned_url, connect_timeout=10, autocommit=True) as conn: try: rows = conn.execute( "SELECT migration_name FROM _prisma_migrations " @@ -838,9 +830,7 @@ class ProxyExtrasDBManager: return head_newest_ts = _max_migration_timestamp(known) - hostile = { - name for name in unknown if _migration_timestamp(name) > head_newest_ts - } + hostile = {name for name in unknown if _migration_timestamp(name) > head_newest_ts} if not hostile: return @@ -931,8 +921,7 @@ class ProxyExtrasDBManager: if not found: return True logger.warning( - "Found %d invalid index(es) left by an interrupted CREATE INDEX " - "CONCURRENTLY, rebuilding: %s", + "Found %d invalid index(es) left by an interrupted CREATE INDEX CONCURRENTLY, rebuilding: %s", len(found), ", ".join(f"{index.name} (table size {index.table_size})" for index in found), ) @@ -1403,8 +1392,7 @@ class ProxyExtrasDBManager: prisma_env = _get_prisma_env() except OSError as e: logger.error( - "Could not resolve the migrations directory for the REPLICA " - "IDENTITY FULL step, skipping it. Error: %s", + "Could not resolve the migrations directory for the REPLICA IDENTITY FULL step, skipping it. Error: %s", e, ) return False @@ -1435,18 +1423,57 @@ class ProxyExtrasDBManager: Returns: bool: True if setup was successful, False otherwise """ - ensure_prisma_toolchain( - prisma_command=_get_prisma_command(), prisma_env=_get_prisma_env() - ) - migrated = ProxyExtrasDBManager._run_migrations( - use_migrate=use_migrate, use_v2_resolver=use_v2_resolver - ) + ensure_prisma_toolchain(prisma_command=_get_prisma_command(), prisma_env=_get_prisma_env()) + ProxyExtrasDBManager.raise_if_rows_block_pending_changes(use_migrate=use_migrate) + migrated = ProxyExtrasDBManager._run_migrations(use_migrate=use_migrate, use_v2_resolver=use_v2_resolver) if not migrated: return False ProxyExtrasDBManager.repair_invalid_indexes() ProxyExtrasDBManager.apply_replica_identity_full_if_requested() return True + @staticmethod + def migration_data_check_findings(use_migrate: bool = True) -> tuple[Finding, ...]: + """What in the existing rows would make a pending migration or request-log index + fail, read with count queries only: no write, no table lock. Empty when nothing + blocks, when no database is configured, or when it cannot be reached, so the + migration step that follows reports the connection problem the way it does today.""" + import psycopg + + database_url: Final = os.environ.get("DATABASE_URL") + if not database_url: + return () + direct_url: Final = ProxyExtrasDBManager._strip_prisma_query_params( + os.environ.get("DIRECT_URL") or database_url + ) + schema: Final = ProxyExtrasDBManager._prisma_schema_param(database_url) or "public" + migrations_dir: Final = Path(ProxyExtrasDBManager._get_prisma_dir()) / "migrations" if use_migrate else None + indexes: Final = tuple((index.table, index.name, index.columns) for index in REQUEST_LOG_INDEXES) + try: + with psycopg.connect(direct_url, connect_timeout=10, autocommit=True) as connection: + checks: Final = pending_change_checks(connection, schema, migrations_dir, indexes) + return find_blockers(connection, schema, checks, migration_data_check_timeout_seconds()) + except psycopg.OperationalError as exc: + logger.warning( + "Could not reach the database for the pre-migration row check: %s", _redact_credentials(str(exc)) + ) + return () + + @staticmethod + def migration_data_check_report(use_migrate: bool = True) -> Optional[str]: + """The operator-facing refusal for `migration_data_check_findings`, None when nothing blocks.""" + findings: Final = ProxyExtrasDBManager.migration_data_check_findings(use_migrate=use_migrate) + return report(findings) if findings else None + + @staticmethod + def raise_if_rows_block_pending_changes(use_migrate: bool) -> None: + """Refuse to run migrations that the existing rows would make fail, before any is + applied. The RuntimeError carries the report and reaches the operator through the + proxy's "Database migration cannot proceed" exit.""" + refusal: Final = ProxyExtrasDBManager.migration_data_check_report(use_migrate=use_migrate) + if refusal is not None: + raise RuntimeError(refusal) + @staticmethod def build_request_log_indexes(build: Callable[[str, str], bool] = ensure_request_log_indexes) -> bool: """Build the indexes in `REQUEST_LOG_INDEXES` on the writer, in the schema the @@ -1513,9 +1540,7 @@ class ProxyExtrasDBManager: # Skip sanity check when deploy reports no pending migrations — # DB already matches schema, no drift to correct. if "No pending migrations to apply" in result.stdout: - logger.info( - "No pending migrations — skipping post-migration sanity check" - ) + logger.info("No pending migrations — skipping post-migration sanity check") return True # Run sanity check to ensure DB matches schema @@ -1530,9 +1555,7 @@ class ProxyExtrasDBManager: logger.info(f"prisma db error: {stderr}, e: {e.stdout}") if "P3009" in stderr: # Extract the failed migration name from the error message - migration_match = re.search( - r"`(\d+_.*)` migration", stderr - ) + migration_match = re.search(r"`(\d+_.*)` migration", stderr) if migration_match: failed_migration = migration_match.group(1) if ProxyExtrasDBManager._is_idempotent_error(stderr): @@ -1540,9 +1563,7 @@ class ProxyExtrasDBManager: f"Migration {failed_migration} failed due to idempotent error (e.g., column already exists), resolving as applied" ) try: - ProxyExtrasDBManager._roll_back_migration( - failed_migration - ) + ProxyExtrasDBManager._roll_back_migration(failed_migration) except ( subprocess.CalledProcessError, subprocess.TimeoutExpired, @@ -1552,9 +1573,7 @@ class ProxyExtrasDBManager: f"It may already be in a rolled-back state." ) try: - ProxyExtrasDBManager._resolve_specific_migration( - failed_migration - ) + ProxyExtrasDBManager._resolve_specific_migration(failed_migration) logger.info( f"✅ Migration {failed_migration} resolved, retrying to apply remaining migrations" ) @@ -1562,9 +1581,7 @@ class ProxyExtrasDBManager: subprocess.CalledProcessError, subprocess.TimeoutExpired, ) as resolve_err: - logger.warning( - f"Failed to resolve migration {failed_migration}: {resolve_err}" - ) + logger.warning(f"Failed to resolve migration {failed_migration}: {resolve_err}") # Apply any schema drift not covered by the marked-as-applied migration ProxyExtrasDBManager._resolve_all_migrations( migrations_dir, @@ -1572,9 +1589,7 @@ class ProxyExtrasDBManager: mark_all_applied=False, ) else: - logger.info( - f"Found failed migration: {failed_migration}, marking as rolled back" - ) + logger.info(f"Found failed migration: {failed_migration}, marking as rolled back") # Mark the failed migration as rolled back prisma_toolchain.run_prisma( [ @@ -1587,23 +1602,14 @@ class ProxyExtrasDBManager: timeout=prisma_command_timeout(), env=_get_prisma_env(), ) - logger.info( - f"✅ Migration {failed_migration} marked as rolled back... retrying" - ) - elif ( - "P3005" in stderr - and "database schema is not empty" in stderr - ): + logger.info(f"✅ Migration {failed_migration} marked as rolled back... retrying") + elif "P3005" in stderr and "database schema is not empty" in stderr: logger.info( "Database schema is not empty, creating baseline migration. In read-only file system, please set an environment variable `LITELLM_MIGRATION_DIR` to a writable directory to enable migrations. Learn more - https://docs.litellm.ai/docs/proxy/prod#read-only-file-system" ) ProxyExtrasDBManager._create_baseline_migration(schema_path) - logger.info( - "Baseline migration created, resolving all migrations" - ) - ProxyExtrasDBManager._resolve_all_migrations( - migrations_dir, schema_path - ) + logger.info("Baseline migration created, resolving all migrations") + ProxyExtrasDBManager._resolve_all_migrations(migrations_dir, schema_path) logger.info("✅ All migrations resolved.") return True elif "P3018" in stderr: @@ -1611,14 +1617,8 @@ class ProxyExtrasDBManager: if ProxyExtrasDBManager._is_permission_error(stderr): # Permission errors should NOT be marked as applied # Extract migration name for logging - migration_match = re.search( - r"Migration name: (\d+_.*)", stderr - ) - migration_name = ( - migration_match.group(1) - if migration_match - else "unknown" - ) + migration_match = re.search(r"Migration name: (\d+_.*)", stderr) + migration_name = migration_match.group(1) if migration_match else "unknown" logger.error( f"❌ Migration {migration_name} failed due to insufficient permissions. " @@ -1628,16 +1628,10 @@ class ProxyExtrasDBManager: # Mark as rolled back and exit with error if migration_match: try: - ProxyExtrasDBManager._roll_back_migration( - migration_name - ) - logger.info( - f"Migration {migration_name} marked as rolled back" - ) + ProxyExtrasDBManager._roll_back_migration(migration_name) + logger.info(f"Migration {migration_name} marked as rolled back") except Exception as rollback_error: - logger.warning( - f"Failed to mark migration as rolled back: {rollback_error}" - ) + logger.warning(f"Failed to mark migration as rolled back: {rollback_error}") # Re-raise the error to prevent silent failures raise RuntimeError( @@ -1652,18 +1646,12 @@ class ProxyExtrasDBManager: "resolving as applied" ) # Extract the migration name from the error message - migration_match = re.search( - r"Migration name: (\d+_.*)", stderr - ) + migration_match = re.search(r"Migration name: (\d+_.*)", stderr) if migration_match: migration_name = migration_match.group(1) try: - logger.info( - f"Rolling back migration {migration_name}" - ) - ProxyExtrasDBManager._roll_back_migration( - migration_name - ) + logger.info(f"Rolling back migration {migration_name}") + ProxyExtrasDBManager._roll_back_migration(migration_name) except ( subprocess.CalledProcessError, subprocess.TimeoutExpired, @@ -1677,9 +1665,7 @@ class ProxyExtrasDBManager: f"Resolving migration {migration_name} that failed " f"due to existing schema objects" ) - ProxyExtrasDBManager._resolve_specific_migration( - migration_name - ) + ProxyExtrasDBManager._resolve_specific_migration(migration_name) logger.info( f"✅ Migration {migration_name} resolved, " f"retrying to apply remaining migrations" @@ -1688,9 +1674,7 @@ class ProxyExtrasDBManager: subprocess.CalledProcessError, subprocess.TimeoutExpired, ) as resolve_err: - logger.warning( - f"Failed to resolve migration {migration_name}: {resolve_err}" - ) + logger.warning(f"Failed to resolve migration {migration_name}: {resolve_err}") # Apply any schema drift not covered by the marked-as-applied migration ProxyExtrasDBManager._resolve_all_migrations( migrations_dir, @@ -1732,14 +1716,8 @@ class ProxyExtrasDBManager: time.sleep(random.randrange(5, 15)) except subprocess.CalledProcessError as e: attempts_left = 3 - attempt - retry_msg = ( - f" Retrying... ({attempts_left} attempts left)" - if attempts_left > 0 - else "" - ) - stderr_detail: Final = ( - f" stderr: {_redact_credentials(str(e.stderr))}" if e.stderr else "" - ) + retry_msg = f" Retrying... ({attempts_left} attempts left)" if attempts_left > 0 else "" + stderr_detail: Final = f" stderr: {_redact_credentials(str(e.stderr))}" if e.stderr else "" logger.error( f"The process failed to execute. Details: {_redact_command_error(e)}.{stderr_detail}{retry_msg}" ) diff --git a/litellm-rust/Cargo.lock b/litellm-rust/Cargo.lock index c868d3e4b8a..63137949f38 100644 --- a/litellm-rust/Cargo.lock +++ b/litellm-rust/Cargo.lock @@ -876,6 +876,15 @@ dependencies = [ "time", ] +[[package]] +name = "backon" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cffb0e931875b666fc4fcb20fee52e9bbd1ef836fd9e9e04ec21555f9f85f7ef" +dependencies = [ + "fastrand", +] + [[package]] name = "base16ct" version = "0.2.0" @@ -1248,7 +1257,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfc320937d09e6de266b31b9afb480f197d7a861be86be7cb2ea7e5d1bfffc5e" dependencies = [ "bytes", + "futures-core", "memchr", + "pin-project-lite", + "tokio", + "tokio-util", ] [[package]] @@ -3642,6 +3655,14 @@ dependencies = [ "strum", ] +[[package]] +name = "litellm-circuit-breaker" +version = "0.1.0" +dependencies = [ + "proptest", + "rstest", +] + [[package]] name = "litellm-config" version = "0.1.0" @@ -3655,6 +3676,8 @@ dependencies = [ "strum", "tempfile", "thiserror 2.0.19", + "tracing", + "tracing-subscriber", ] [[package]] @@ -3695,8 +3718,15 @@ dependencies = [ name = "litellm-db" version = "0.1.0" dependencies = [ + "chrono", + "macro_rules_attribute", + "rstest", "serde", + "serde_json", "sqlx", + "strum", + "thiserror 2.0.19", + "tokio", ] [[package]] @@ -3736,6 +3766,7 @@ dependencies = [ "futures-util", "http-body-util", "litellm-auth-types", + "litellm-circuit-breaker", "litellm-config", "litellm-gateway-auth", "litellm-gateway-inference", @@ -3744,6 +3775,8 @@ dependencies = [ "litellm-http", "litellm-inference", "litellm-llms", + "litellm-redis-client", + "litellm-redis-testing", "litellm-secrets", "litellm-tracing", "rstest", @@ -4275,6 +4308,28 @@ dependencies = [ "thiserror 2.0.19", ] +[[package]] +name = "litellm-redis-client" +version = "0.1.0" +dependencies = [ + "futures-util", + "litellm-circuit-breaker", + "litellm-redis-testing", + "redis", + "rstest", + "thiserror 2.0.19", + "tokio", +] + +[[package]] +name = "litellm-redis-testing" +version = "0.1.0" +dependencies = [ + "testcontainers-modules", + "thiserror 2.0.19", + "tokio", +] + [[package]] name = "litellm-router" version = "0.1.0" @@ -5750,22 +5805,34 @@ dependencies = [ [[package]] name = "redis" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2acbc41a996f7652b2ddd9dfd98cc4ff602cfd742ae35382f07f608405ab50ed" +checksum = "7acd809e80afa754c63f586955699d8990efe1c4b6613183ee5f027a11fbc8b5" dependencies = [ + "arc-swap", "arcstr", + "async-lock", + "backon", + "bytes", + "cfg-if", "combine", "crc16", + "futures-channel", + "futures-util", "itoa", + "log", "num-bigint 0.5.1", "percent-encoding", + "pin-project-lite", "rand 0.10.2", "rustls 0.23.42", "rustls-native-certs", "ryu", "sha1_smol", "socket2 0.6.5", + "tokio", + "tokio-rustls 0.26.4", + "tokio-util", "url", "xxhash-rust", ] @@ -8202,18 +8269,18 @@ dependencies = [ [[package]] name = "webpki-root-certs" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58ec80e73fd8baf57bf0d9615554c75348bda990d6d5bbeab964dd068319fecb" +checksum = "e49d0e65abc00c142e8f9428da991da9f1a250c39be97459901eb12b9b49f62a" dependencies = [ "rustls-pki-types", ] [[package]] name = "webpki-roots" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c1c8e20c8a38fc7d65abfe74eb7280e4aa667e8eec8bc84996d2874810748d9" +checksum = "f5f280bbb2b287bc8e7de7e3852945a0ff50d1bbcb5ed42b6c7a568c546df171" dependencies = [ "rustls-pki-types", ] diff --git a/litellm-rust/Cargo.toml b/litellm-rust/Cargo.toml index 9e5e0a96b73..dd8d8704370 100644 --- a/litellm-rust/Cargo.toml +++ b/litellm-rust/Cargo.toml @@ -69,6 +69,9 @@ litellm-token-counter-huggingface = { path = "crates/token-counter-huggingface" litellm-token-counter-tiktoken = { path = "crates/token-counter-tiktoken" } litellm-host-python = { path = "crates/host-python" } litellm-python-compat = { path = "crates/python-compat" } +litellm-circuit-breaker = { path = "crates/circuit-breaker" } +litellm-redis-client = { path = "crates/redis-client" } +litellm-redis-testing = { path = "crates/redis-testing" } askama = { version = "0.16.1", default-features = false, features = ["derive", "std"] } tracing = "0.1" @@ -88,6 +91,9 @@ rand = "0.8" macro_rules_attribute = "0.2.3" schemars = "1" reqwest = { version = "0.12", default-features = false, features = ["json", "multipart", "rustls-tls", "http2", "stream"] } +redis = "1.8.0" +redis-test = "1.0.4" +testcontainers-modules = "0.15.0" qdrant-client = { version = "1.19.0", default-features = false } uuid = { version = "1", features = ["v4"] } rstest = "0.26.1" @@ -104,6 +110,7 @@ serde_with = { version = "=3.21.0", default-features = false, features = ["std", sha2 = "0.10" syn = { version = "2", default-features = false } sqlx = { version = "0.9.0", default-features = false, features = ["json", "macros", "postgres", "runtime-tokio", "chrono", "tls-rustls-ring-native-roots"] } +chrono = { version = "0.4.45", default-features = false, features = ["std"] } proc-macro2 = "1" quote = "1" subtle = "2" diff --git a/litellm-rust/crates/cache-redis-semantic/Cargo.toml b/litellm-rust/crates/cache-redis-semantic/Cargo.toml index fe5a317cec0..6a5c794bde7 100644 --- a/litellm-rust/crates/cache-redis-semantic/Cargo.toml +++ b/litellm-rust/crates/cache-redis-semantic/Cargo.toml @@ -8,12 +8,12 @@ repository.workspace = true [dependencies] litellm-cache.workspace = true litellm-cache-redis.workspace = true -redis = { version = "1.7.0", features = ["tls-rustls"] } +redis = { workspace = true, features = ["tls-rustls"] } sha2.workspace = true [dev-dependencies] litellm-cache-testing.workspace = true -redis-test = "1.0.4" +redis-test.workspace = true rstest.workspace = true serde_json.workspace = true tokio.workspace = true diff --git a/litellm-rust/crates/cache-redis/Cargo.toml b/litellm-rust/crates/cache-redis/Cargo.toml index a234286a338..bebfcafd98a 100644 --- a/litellm-rust/crates/cache-redis/Cargo.toml +++ b/litellm-rust/crates/cache-redis/Cargo.toml @@ -7,12 +7,12 @@ repository.workspace = true [dependencies] litellm-cache.workspace = true -redis = { version = "1.7.0", features = ["cluster", "tls-rustls"] } +redis = { workspace = true, features = ["cluster", "tls-rustls"] } r2d2 = "0.8.10" tokio.workspace = true [dev-dependencies] litellm-cache-testing.workspace = true -redis-test = "1.0.4" +redis-test.workspace = true rstest.workspace = true serde_json.workspace = true diff --git a/litellm-rust/crates/cache-response/Cargo.toml b/litellm-rust/crates/cache-response/Cargo.toml index 869c40a12ab..8f4570edc6f 100644 --- a/litellm-rust/crates/cache-response/Cargo.toml +++ b/litellm-rust/crates/cache-response/Cargo.toml @@ -17,8 +17,8 @@ litellm-cache-gcs.workspace = true litellm-http = { workspace = true, features = ["test-support"] } litellm-cache-memory.workspace = true litellm-cache-redis.workspace = true -redis = "1.7.0" -redis-test = "1.0.4" +redis.workspace = true +redis-test.workspace = true rstest.workspace = true tokio.workspace = true wiremock.workspace = true diff --git a/litellm-rust/crates/cache-valkey-semantic/Cargo.toml b/litellm-rust/crates/cache-valkey-semantic/Cargo.toml index da9bb60c853..ec755e61b8c 100644 --- a/litellm-rust/crates/cache-valkey-semantic/Cargo.toml +++ b/litellm-rust/crates/cache-valkey-semantic/Cargo.toml @@ -8,13 +8,13 @@ repository.workspace = true [dependencies] litellm-cache.workspace = true litellm-cache-redis.workspace = true -redis = { version = "1.7.0", features = ["tls-rustls"] } +redis = { workspace = true, features = ["tls-rustls"] } sha2.workspace = true uuid = { version = "1", features = ["v4"] } [dev-dependencies] litellm-cache-testing.workspace = true -redis-test = "1.0.4" +redis-test.workspace = true rstest.workspace = true serde_json.workspace = true tokio.workspace = true diff --git a/litellm-rust/crates/callbacks-legacy-python/src/mapping.rs b/litellm-rust/crates/callbacks-legacy-python/src/mapping.rs index a4aee4eb4da..cfa9e53aa7b 100644 --- a/litellm-rust/crates/callbacks-legacy-python/src/mapping.rs +++ b/litellm-rust/crates/callbacks-legacy-python/src/mapping.rs @@ -235,7 +235,7 @@ python_callbacks! { "async_log_stream_event", "async_post_mcp_tool_call_hook", ], - Dispatch::Python("litellm.llms.anthropic.pass_through.messages.handler") => [ + Dispatch::Python("litellm.llms.anthropic.messages.native.handler") => [ "async_pre_request_hook", ], Dispatch::Python("litellm.litellm_core_utils.streaming_handler") => [ diff --git a/litellm-rust/crates/circuit-breaker/AGENTS.md b/litellm-rust/crates/circuit-breaker/AGENTS.md new file mode 100644 index 00000000000..52ef0ca7435 --- /dev/null +++ b/litellm-rust/crates/circuit-breaker/AGENTS.md @@ -0,0 +1,14 @@ +- `fsm` is a generic state machine runtime and knows nothing about breakers. `breaker` is a generic circuit breaker and knows nothing about Redis. Deciding which errors count as failures belongs to the consumer +- `Machine::step` stays pure. `&self` is config and time comes in on the event, never read inside the machine. The only clock read is `Admission`'s drop, at the call-site boundary +- Transition rules are one `match (state, event)` per machine, with no macro DSL and no `_` arm that would hide a new state from the compiler +- `Shared` counts a transition, bumps the generation and calls the observer only when the state's enum variant changes, matching Python bumping `generation` only when `_state` changes. Data inside a variant (failure counters, `since`) changes without a transition +- The observer runs under the lock so transitions are seen in generation order. Keep it to logging or a metric +- A disabled breaker is `Option::None` at the consumer, not a flag inside the machine. `Config` comes in already resolved, reading `REDIS_CIRCUIT_BREAKER_*` env is the consumer's job + +## Parity with Python `RedisCircuitBreaker` (`litellm/caching/redis_cache.py`) +- The rstest table `matches_the_python_redis_circuit_breaker` was checked case by case against the Python breaker. A behavior change here needs the same check, by driving the Python class with the same steps +- Divergences, each on purpose + - monotonic `Instant` instead of `time.time()`, so a wall clock jump can't open or close the breaker + - a probe `Admission` dropped without an outcome records a hard failure and reopens. Python's probe that dies on `CancelledError` (a `BaseException`) records nothing and leaves the breaker HALF_OPEN for good, and a dropped Rust future is common + - `_failure_count` is dropped, it only fed a log line + - no `enabled` flag, see above diff --git a/litellm-rust/crates/circuit-breaker/Cargo.toml b/litellm-rust/crates/circuit-breaker/Cargo.toml new file mode 100644 index 00000000000..8eca448a2ac --- /dev/null +++ b/litellm-rust/crates/circuit-breaker/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "litellm-circuit-breaker" +version = "0.1.0" +edition.workspace = true +license.workspace = true +repository.workspace = true + +[dependencies] + +[dev-dependencies] +proptest.workspace = true +rstest.workspace = true diff --git a/litellm-rust/crates/circuit-breaker/src/breaker.rs b/litellm-rust/crates/circuit-breaker/src/breaker.rs new file mode 100644 index 00000000000..c9509561b37 --- /dev/null +++ b/litellm-rust/crates/circuit-breaker/src/breaker.rs @@ -0,0 +1,444 @@ +use std::{ + sync::Arc, + time::{Duration, Instant}, +}; + +use crate::{Machine, Observer, Shared}; + +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct Config { + pub failure_threshold: u32, + pub recovery_timeout: Duration, + pub timeout_min_duration: Duration, +} + +impl Default for Config { + fn default() -> Self { + Self { + failure_threshold: 5, + recovery_timeout: Duration::from_secs(60), + timeout_min_duration: Duration::from_secs(5), + } + } +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Failure { + Hard, + Timeout, +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum State { + Closed { + hard: u32, + timeouts: u32, + streak_started: Option, + }, + Open { + since: Instant, + }, + HalfOpen, +} + +impl State { + const CLOSED: Self = Self::Closed { + hard: 0, + timeouts: 0, + streak_started: None, + }; +} + +#[derive(Clone, Copy, Debug)] +pub enum Event { + Admit(Instant), + Succeeded, + Failed(Failure, Instant), +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Output { + Admitted, + Probe, + Rejected, + Recorded, +} + +impl Machine for Config { + type State = State; + type Event = Event; + type Output = Output; + + fn step(&self, state: &State, event: Event) -> (State, Output) { + match (state, event) { + (State::Closed { .. }, Event::Admit(_)) => (state.clone(), Output::Admitted), + (State::Open { since }, Event::Admit(now)) + if now.duration_since(*since) > self.recovery_timeout => + { + (State::HalfOpen, Output::Probe) + } + (State::Open { .. } | State::HalfOpen, Event::Admit(_)) => { + (state.clone(), Output::Rejected) + } + (State::Closed { .. } | State::HalfOpen, Event::Succeeded) => { + (State::CLOSED, Output::Recorded) + } + (State::Open { .. }, Event::Succeeded) => (state.clone(), Output::Recorded), + (State::Closed { hard, .. }, Event::Failed(Failure::Hard, now)) => { + let hard = hard + 1; + let next = match hard >= self.failure_threshold { + true => State::Open { since: now }, + false => State::Closed { + hard, + timeouts: 0, + streak_started: None, + }, + }; + (next, Output::Recorded) + } + ( + State::Closed { + hard, + timeouts, + streak_started, + }, + Event::Failed(Failure::Timeout, now), + ) => { + let timeouts = timeouts + 1; + let started = streak_started.unwrap_or(now); + let opens = timeouts >= self.failure_threshold + && now.duration_since(started) >= self.timeout_min_duration; + let next = match opens { + true => State::Open { since: now }, + false => State::Closed { + hard: *hard, + timeouts, + streak_started: Some(started), + }, + }; + (next, Output::Recorded) + } + (State::Open { .. } | State::HalfOpen, Event::Failed(_, now)) => { + (State::Open { since: now }, Output::Recorded) + } + } + } +} + +#[derive(Clone)] +pub struct Breaker(Arc>); + +#[derive(Debug, PartialEq, Eq)] +pub struct Rejected; + +pub struct Admission { + breaker: Breaker, + generation: u64, + probe: bool, + settled: bool, +} + +impl Breaker { + pub fn new(config: Config, observer: Observer) -> Self { + Self(Arc::new(Shared::new(config, State::CLOSED, observer))) + } + + pub fn admit(&self, now: Instant) -> Result { + let (output, generation) = self.0.fire(Event::Admit(now)); + let probe = match output { + Output::Admitted => false, + Output::Probe => true, + Output::Rejected | Output::Recorded => return Err(Rejected), + }; + Ok(Admission { + breaker: self.clone(), + generation, + probe, + settled: false, + }) + } + + pub fn failed(&self, failure: Failure, now: Instant) { + self.0.fire(Event::Failed(failure, now)); + } + + pub fn state(&self) -> State { + self.0.state() + } +} + +impl Admission { + pub fn probe(&self) -> bool { + self.probe + } + + pub fn succeeded(mut self) { + self.settled = true; + self.breaker.0.fire_if(self.generation, Event::Succeeded); + } + + pub fn failed(mut self, failure: Failure, now: Instant) { + self.settled = true; + self.breaker.failed(failure, now); + } +} + +impl Drop for Admission { + fn drop(&mut self) { + if self.probe && !self.settled { + self.breaker.0.fire_if( + self.generation, + Event::Failed(Failure::Hard, Instant::now()), + ); + } + } +} + +#[cfg(test)] +mod tests { + use std::{ + collections::HashMap, + sync::{Arc, Mutex}, + time::{Duration, Instant}, + }; + + use proptest::prelude::*; + use rstest::rstest; + + use super::{Admission, Breaker, Config, Failure, State}; + use crate::Transition; + + #[derive(Clone, Copy, Debug)] + enum Step { + Fail(f64, Failure), + Admit(f64, bool), + Succeed(usize), + } + + #[derive(Clone, Copy, Debug, PartialEq, Eq)] + enum Phase { + Closed, + Open, + HalfOpen, + } + + use Phase::{Closed as C, HalfOpen as H, Open as O}; + + #[rstest] + fn dropping_an_old_probe_does_not_undo_a_newer_recovery() { + let breaker = Breaker::new( + Config { + failure_threshold: 1, + recovery_timeout: Duration::from_secs(1), + ..Config::default() + }, + Box::new(|_| {}), + ); + let now = Instant::now(); + let pending = breaker.admit(now).unwrap(); + breaker.failed(Failure::Hard, now); + let old_probe = breaker.admit(now + Duration::from_secs(2)).unwrap(); + assert!(old_probe.probe()); + pending.failed(Failure::Hard, now + Duration::from_secs(2)); + let new_probe = breaker.admit(now + Duration::from_secs(4)).unwrap(); + assert!(new_probe.probe()); + new_probe.succeeded(); + assert_eq!(breaker.state(), State::CLOSED); + + drop(old_probe); + + assert_eq!(breaker.state(), State::CLOSED); + assert!(!breaker.admit(now + Duration::from_secs(4)).unwrap().probe()); + } + + fn hard(at: f64) -> Step { + Step::Fail(at, Failure::Hard) + } + + fn timeout(at: f64) -> Step { + Step::Fail(at, Failure::Timeout) + } + + fn five_hard_at_zero() -> Vec { + vec![hard(0.0); 5] + } + + fn phase(state: &State) -> Phase { + match state { + State::Closed { .. } => Phase::Closed, + State::Open { .. } => Phase::Open, + State::HalfOpen => Phase::HalfOpen, + } + } + + fn quiet() -> Breaker { + Breaker::new(Config::default(), Box::new(|_| {})) + } + + #[rstest] + #[case::five_hard_failures_open(vec![hard(0.0), hard(1.0), hard(2.0), hard(3.0), hard(4.0)], vec![C, C, C, C, O])] + #[case::a_success_resets_the_hard_failure_count( + vec![hard(0.0), hard(1.0), hard(2.0), hard(3.0), Step::Admit(4.0, true), Step::Succeed(4), hard(5.0), hard(6.0), hard(7.0), hard(8.0)], + vec![C; 10] + )] + #[case::a_timeout_streak_opens_only_after_the_min_duration( + vec![timeout(0.0), timeout(1.0), timeout(2.0), timeout(3.0), timeout(4.9), timeout(5.0)], + vec![C, C, C, C, C, O] + )] + #[case::a_hard_failure_restarts_the_timeout_streak( + vec![timeout(0.0), timeout(1.0), timeout(2.0), timeout(3.0), hard(4.0), timeout(5.0), timeout(6.0), timeout(7.0), timeout(8.0), timeout(9.9), timeout(10.0)], + vec![C, C, C, C, C, C, C, C, C, C, O] + )] + #[case::the_probe_waits_until_strictly_past_the_recovery_timeout( + [five_hard_at_zero(), vec![Step::Admit(60.0, false), Step::Admit(60.5, true)]].concat(), + vec![C, C, C, C, O, O, H] + )] + #[case::a_probe_success_closes( + [five_hard_at_zero(), vec![Step::Admit(61.0, true), Step::Succeed(5)]].concat(), + vec![C, C, C, C, O, H, C] + )] + #[case::a_probe_failure_reopens_with_a_fresh_timer( + [five_hard_at_zero(), vec![Step::Admit(61.0, true), hard(62.0), Step::Admit(122.0, false), Step::Admit(122.5, true)]].concat(), + vec![C, C, C, C, O, H, O, O, H] + )] + #[case::only_one_probe_at_a_time( + [five_hard_at_zero(), vec![Step::Admit(61.0, true), Step::Admit(61.5, false)]].concat(), + vec![C, C, C, C, O, H, H] + )] + #[case::a_late_failure_while_open_pushes_back_the_probe( + [five_hard_at_zero(), vec![hard(30.0), Step::Admit(61.0, false), Step::Admit(90.5, true)]].concat(), + vec![C, C, C, C, O, O, O, H] + )] + #[case::a_success_from_before_the_breaker_moved_is_ignored( + vec![Step::Admit(0.0, true), hard(1.0), hard(1.0), hard(1.0), hard(1.0), hard(1.0), Step::Admit(62.0, true), Step::Succeed(0), Step::Succeed(6)], + vec![C, C, C, C, C, O, H, H, C] + )] + fn matches_the_python_redis_circuit_breaker( + #[case] steps: Vec, + #[case] expected: Vec, + ) { + let breaker = quiet(); + let t0 = Instant::now(); + let mut admissions: HashMap = HashMap::new(); + + let phases: Vec = steps + .iter() + .enumerate() + .map(|(index, step)| { + match *step { + Step::Fail(at, failure) => { + breaker.failed(failure, t0 + Duration::from_secs_f64(at)) + } + Step::Admit(at, admitted) => { + let admission = breaker.admit(t0 + Duration::from_secs_f64(at)); + assert_eq!(admission.is_ok(), admitted, "step {index}"); + admissions.extend(admission.ok().map(|admission| (index, admission))); + } + Step::Succeed(admitted_at) => { + admissions.remove(&admitted_at).unwrap().succeeded() + } + } + phase(&breaker.state()) + }) + .collect(); + + assert_eq!(phases, expected); + } + + #[rstest] + fn a_dropped_probe_reopens_instead_of_wedging_half_open() { + let breaker = quiet(); + let t0 = Instant::now(); + (0..5).for_each(|_| breaker.failed(Failure::Hard, t0)); + let probe = breaker.admit(t0 + Duration::from_secs(61)).unwrap(); + assert!(probe.probe()); + + drop(probe); + + assert!(matches!(breaker.state(), State::Open { .. })); + } + + #[rstest] + fn a_dropped_regular_call_records_nothing() { + let breaker = quiet(); + let t0 = Instant::now(); + breaker.failed(Failure::Hard, t0); + + drop(breaker.admit(t0).unwrap()); + + assert_eq!( + breaker.state(), + State::Closed { + hard: 1, + timeouts: 0, + streak_started: None + } + ); + } + + #[derive(Clone, Copy, Debug)] + enum Action { + Admit, + SucceedOldest, + FailOldest(Failure), + Fail(Failure), + } + + fn action() -> impl Strategy { + let failure = prop_oneof![Just(Failure::Hard), Just(Failure::Timeout)]; + let action = prop_oneof![ + Just(Action::Admit), + Just(Action::SucceedOldest), + failure.clone().prop_map(Action::FailOldest), + failure.prop_map(Action::Fail), + ]; + (0u64..30_000, action) + } + + proptest! { + #[test] + fn open_never_closes_directly_and_each_half_open_visit_has_one_probe( + actions in prop::collection::vec(action(), 1..200) + ) { + let transitions: Arc>>> = Arc::default(); + let seen = Arc::clone(&transitions); + let config = Config { + failure_threshold: 3, + recovery_timeout: Duration::from_secs(10), + timeout_min_duration: Duration::from_secs(2), + }; + let breaker = Breaker::new(config, Box::new(move |t| seen.lock().unwrap().push(t.clone()))); + let t0 = Instant::now(); + let mut now = t0; + let mut pending: Vec = Vec::new(); + let mut probes_per_visit: Vec = Vec::new(); + + for (advance_ms, action) in actions { + now += Duration::from_millis(advance_ms); + match action { + Action::Admit => { + if let Ok(admission) = breaker.admit(now) { + if admission.probe() { + probes_per_visit.push(1); + } + pending.push(admission); + } + } + Action::SucceedOldest if !pending.is_empty() => pending.remove(0).succeeded(), + Action::FailOldest(failure) if !pending.is_empty() => pending.remove(0).failed(failure, now), + Action::SucceedOldest | Action::FailOldest(_) => {} + Action::Fail(failure) => breaker.failed(failure, now), + } + } + + let transitions = transitions.lock().unwrap(); + let open_to_closed = transitions + .iter() + .filter(|t| matches!((&t.from, &t.to), (State::Open { .. }, State::Closed { .. }))) + .count(); + let half_open_visits = transitions.iter().filter(|t| t.to == State::HalfOpen).count(); + prop_assert_eq!(open_to_closed, 0); + prop_assert_eq!(probes_per_visit.len(), half_open_visits); + } + } +} diff --git a/litellm-rust/crates/circuit-breaker/src/fsm.rs b/litellm-rust/crates/circuit-breaker/src/fsm.rs new file mode 100644 index 00000000000..1beb0f890c8 --- /dev/null +++ b/litellm-rust/crates/circuit-breaker/src/fsm.rs @@ -0,0 +1,174 @@ +use std::{ + fmt::Debug, + mem, + sync::{Mutex, PoisonError}, +}; + +pub trait Machine { + type State: Clone + Debug; + type Event; + type Output; + + fn step(&self, state: &Self::State, event: Self::Event) -> (Self::State, Self::Output); +} + +#[derive(Clone, Debug)] +pub struct Transition { + pub from: S, + pub to: S, + pub generation: u64, +} + +pub type Observer = Box) + Send + Sync>; + +pub struct Shared { + machine: M, + current: Mutex<(M::State, u64)>, + observer: Observer, +} + +impl Shared { + pub fn new(machine: M, initial: M::State, observer: Observer) -> Self { + Self { + machine, + current: Mutex::new((initial, 0)), + observer, + } + } + + pub fn fire(&self, event: M::Event) -> (M::Output, u64) { + let mut current = self.current.lock().unwrap_or_else(PoisonError::into_inner); + self.apply(&mut current, event) + } + + pub fn fire_if(&self, generation: u64, event: M::Event) -> Option { + let mut current = self.current.lock().unwrap_or_else(PoisonError::into_inner); + (current.1 == generation).then(|| self.apply(&mut current, event).0) + } + + pub fn state(&self) -> M::State { + self.current + .lock() + .unwrap_or_else(PoisonError::into_inner) + .0 + .clone() + } + + fn apply(&self, current: &mut (M::State, u64), event: M::Event) -> (M::Output, u64) { + let (to, output) = self.machine.step(¤t.0, event); + if mem::discriminant(&to) != mem::discriminant(¤t.0) { + let from = mem::replace(&mut current.0, to.clone()); + current.1 += 1; + (self.observer)(&Transition { + from, + to, + generation: current.1, + }); + } else { + current.0 = to; + } + (output, current.1) + } +} + +#[cfg(test)] +mod tests { + use std::sync::{Arc, Mutex}; + + use rstest::rstest; + + use super::{Machine, Shared, Transition}; + + struct Wrapping(u32); + + #[derive(Clone, Debug, PartialEq, Eq)] + enum Counter { + Low(u32), + High(u32), + } + + enum Tick { + Up, + Stay, + } + + impl Machine for Wrapping { + type State = Counter; + type Event = Tick; + type Output = (); + + fn step(&self, state: &Counter, event: Tick) -> (Counter, ()) { + let value = match (state, event) { + (Counter::Low(_) | Counter::High(_), Tick::Stay) => return (state.clone(), ()), + (Counter::Low(value) | Counter::High(value), Tick::Up) => (value + 1) % self.0, + }; + match value < self.0 / 2 { + true => (Counter::Low(value), ()), + false => (Counter::High(value), ()), + } + } + } + + type Seen = Arc>>>; + + fn recorded(wrap: u32) -> (Shared, Seen) { + let transitions: Seen = Arc::default(); + let seen = Arc::clone(&transitions); + let shared = Shared::new( + Wrapping(wrap), + Counter::Low(0), + Box::new(move |transition| seen.lock().unwrap().push(transition.clone())), + ); + (shared, transitions) + } + + #[rstest] + fn concurrent_events_are_all_applied_and_transitions_are_observed_in_generation_order() { + let (shared, transitions) = recorded(4); + + std::thread::scope(|scope| { + for _ in 0..64 { + scope.spawn(|| { + for _ in 0..100 { + shared.fire(Tick::Up); + } + }); + } + }); + + assert_eq!(shared.state(), Counter::Low(6400 % 4)); + let generations: Vec = transitions + .lock() + .unwrap() + .iter() + .map(|t| t.generation) + .collect(); + assert_eq!(generations, (1..=3200).collect::>()); + } + + #[rstest] + fn a_step_that_keeps_the_variant_neither_counts_nor_notifies() { + let (shared, transitions) = recorded(4); + + let (_, after_inner_change) = shared.fire(Tick::Up); + let (_, after_self_loop) = shared.fire(Tick::Stay); + + assert_eq!(shared.state(), Counter::Low(1)); + assert_eq!((after_inner_change, after_self_loop), (0, 0)); + assert!(transitions.lock().unwrap().is_empty()); + } + + #[rstest] + fn fire_if_skips_an_event_from_an_older_generation() { + let (shared, _) = recorded(4); + shared.fire(Tick::Up); + let (_, generation) = shared.fire(Tick::Up); + + let stale = shared.fire_if(generation - 1, Tick::Up); + let current = shared.fire_if(generation, Tick::Up); + + assert!(stale.is_none()); + assert!(current.is_some()); + assert_eq!(shared.state(), Counter::High(3)); + } +} diff --git a/litellm-rust/crates/circuit-breaker/src/lib.rs b/litellm-rust/crates/circuit-breaker/src/lib.rs new file mode 100644 index 00000000000..e76228122d1 --- /dev/null +++ b/litellm-rust/crates/circuit-breaker/src/lib.rs @@ -0,0 +1,5 @@ +mod breaker; +mod fsm; + +pub use breaker::{Admission, Breaker, Config, Event, Failure, Output, Rejected, State}; +pub use fsm::{Machine, Observer, Shared, Transition}; diff --git a/litellm-rust/crates/config/Cargo.toml b/litellm-rust/crates/config/Cargo.toml index 23d53923362..9746a002bb9 100644 --- a/litellm-rust/crates/config/Cargo.toml +++ b/litellm-rust/crates/config/Cargo.toml @@ -9,11 +9,13 @@ repository.workspace = true litellm-auth-types.workspace = true litellm-router-types.workspace = true serde.workspace = true +serde_json.workspace = true serde_yaml_ng = "0.10.0" strum.workspace = true thiserror.workspace = true +tracing.workspace = true [dev-dependencies] rstest.workspace = true -serde_json.workspace = true tempfile.workspace = true +tracing-subscriber = { version = "0.3", default-features = false, features = ["registry", "std"] } diff --git a/litellm-rust/crates/config/src/error.rs b/litellm-rust/crates/config/src/error.rs index 61d19491abc..95c33967cf0 100644 --- a/litellm-rust/crates/config/src/error.rs +++ b/litellm-rust/crates/config/src/error.rs @@ -4,4 +4,11 @@ pub enum Error { Read(#[from] std::io::Error), #[error("invalid YAML config")] Parse(#[from] serde_yaml_ng::Error), + #[error("Redis host does not yet support configured setting {0}")] + RedisSetting(String), + #[error("invalid Redis setting {setting}: {reason}")] + RedisInvalid { + setting: &'static str, + reason: &'static str, + }, } diff --git a/litellm-rust/crates/config/src/lib.rs b/litellm-rust/crates/config/src/lib.rs index 8603ef3279c..b8af6f11d2e 100644 --- a/litellm-rust/crates/config/src/lib.rs +++ b/litellm-rust/crates/config/src/lib.rs @@ -2,6 +2,7 @@ mod error; mod includes; mod mcp; mod model; +mod redis; mod settings; mod value; @@ -13,6 +14,10 @@ pub use error::Error; pub use litellm_router_types::{LitellmParams, Spelled}; pub use mcp::{McpAuth, McpServer, McpTransport}; pub use model::Model; +pub use redis::{ + CacheSettings, Lookup, RedisCluster, RedisEndpoint, RedisHost, RedisNode, RedisSettings, + ResolvedRedis, environment_has_target, +}; pub use settings::{ ClickHouseStoreSettings, GeneralSettings, LiteLlmSettings, RouterSettings, TracingSettings, TracingStoreSettings, diff --git a/litellm-rust/crates/config/src/redis.rs b/litellm-rust/crates/config/src/redis.rs new file mode 100644 index 00000000000..5674f993025 --- /dev/null +++ b/litellm-rust/crates/config/src/redis.rs @@ -0,0 +1,667 @@ +use std::{collections::BTreeMap, fmt, time::Duration}; + +use litellm_auth_types::SecretValue; +use litellm_router_types::Spelled; +use serde::{Deserialize, Deserializer, de::Error as _}; + +use crate::{AdditionalFields, Error, Object, Value}; + +pub type Lookup<'a> = &'a dyn Fn(&str) -> Option; + +const SUPPORTED: &[&str] = &[ + "url", + "host", + "port", + "username", + "password", + "ssl", + "db", + "socket_timeout", + "startup_nodes", + "namespace", +]; + +const IGNORED: &[&str] = &[ + "max_connections", + "single_connection_client", + "health_check_interval", + "socket_keepalive", + "socket_keepalive_options", + "decode_responses", + "encoding", + "encoding_errors", + "charset", + "errors", + "client_name", + "lib_name", + "lib_version", + "sentinel_password", + "gcp_ssl_ca_certs", + "azure_client_id", + "azure_tenant_id", + "azure_client_secret", + "aws_iam_user_name", + "aws_iam_cache_name", + "aws_iam_region", + "aws_iam_serverless", +]; + +const WARN_IGNORED: &[&str] = &[ + "max_connections", + "health_check_interval", + "socket_keepalive", + "socket_keepalive_options", +]; + +const REDIS_PY_KWARGS: &[&str] = &[ + "aws_iam_auth", + "aws_iam_cache_name", + "aws_iam_region", + "aws_iam_serverless", + "aws_iam_user_name", + "azure_client_id", + "azure_client_secret", + "azure_redis_ad_token", + "azure_tenant_id", + "cache", + "cache_config", + "charset", + "client_name", + "db", + "decode_responses", + "encoding", + "encoding_errors", + "errors", + "event_dispatcher", + "gcp_service_account", + "gcp_ssl_ca_certs", + "health_check_interval", + "host", + "lib_name", + "lib_version", + "max_connections", + "password", + "port", + "protocol", + "redis_connect_func", + "retry_on_error", + "retry_on_timeout", + "single_connection_client", + "socket_connect_timeout", + "socket_keepalive", + "socket_keepalive_options", + "socket_timeout", + "ssl", + "ssl_ca_certs", + "ssl_ca_data", + "ssl_ca_path", + "ssl_cert_reqs", + "ssl_certfile", + "ssl_check_hostname", + "ssl_ciphers", + "ssl_keyfile", + "ssl_min_version", + "ssl_ocsp_context", + "ssl_ocsp_expected_cert", + "ssl_password", + "ssl_validate_ocsp", + "ssl_validate_ocsp_stapled", + "unix_socket_path", + "url", + "username", +]; + +const UNSUPPORTED_EXTRA: &[&str] = &[ + "credential_provider", + "sentinel_nodes", + "retry", + "connection_pool", +]; + +const CACHE_ONLY: &[&str] = &[ + "type", + "mode", + "ttl", + "default_in_memory_ttl", + "default_in_redis_ttl", + "supported_call_types", + "similarity_threshold", + "max_messages", + "_backend", +]; + +#[derive(Clone, Default)] +pub struct RedisSettings { + pub url: Option, + pub host: Option>, + pub port: Option>, + pub username: Option, + pub password: Option, + pub ssl: Option>, + pub db: Option>, + pub socket_timeout: Option>, + pub startup_nodes: Option, + pub namespace: Option>, + pub additional_fields: AdditionalFields, + unparsed: DeferredInputs, +} + +impl<'de> Deserialize<'de> for RedisSettings { + fn deserialize>(deserializer: D) -> Result { + let fields = BTreeMap::::deserialize(deserializer)?; + let scalar = |key: &str| fields.get(key).and_then(as_text); + Ok(Self { + url: scalar("url").map(SecretValue::new), + host: scalar("host").map(Spelled::Value), + port: spelled(scalar("port")), + username: scalar("username").map(SecretValue::new), + password: scalar("password").map(SecretValue::new), + ssl: spelled(scalar("ssl")), + db: spelled(scalar("db")), + socket_timeout: spelled(scalar("socket_timeout")), + startup_nodes: fields + .get("startup_nodes") + .filter(|value| !value.is_null()) + .cloned(), + namespace: scalar("namespace").map(Spelled::Value), + additional_fields: cloned(&fields, |key, _| !SUPPORTED.contains(&key)), + unparsed: deferred_inputs(&fields), + }) + } +} + +impl fmt::Debug for RedisSettings { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { + formatter + .debug_struct("RedisSettings") + .field("url", &self.url) + .field("host", &self.host) + .field("port", &self.port) + .field("username", &self.username) + .field("password", &self.password) + .field("ssl", &self.ssl) + .field("db", &self.db) + .field("socket_timeout", &self.socket_timeout) + .field( + "startup_nodes", + &self.startup_nodes.as_ref().map(|_| ""), + ) + .field("namespace", &self.namespace) + .field("additional_fields", &self.additional_fields.keys()) + .field("unparsed", &self.unparsed.keys()) + .finish() + } +} + +#[derive(Clone, Debug)] +pub enum CacheSettings { + Redis(Box), + Other(Object), +} + +impl<'de> Deserialize<'de> for CacheSettings { + fn deserialize>(deserializer: D) -> Result { + let fields = BTreeMap::::deserialize(deserializer)?; + let is_redis = matches!(fields.get("type"), Some(Value::String(kind)) if kind == "redis"); + if !is_redis { + return Ok(Self::Other(Object::from_fields(fields))); + } + let mapping = fields + .into_iter() + .map(|(key, value)| (Value::String(key), value)) + .collect(); + serde_yaml_ng::from_value(Value::Mapping(mapping)) + .map(|settings| Self::Redis(Box::new(settings))) + .map_err(D::Error::custom) + } +} + +#[derive(Clone, PartialEq)] +pub struct ResolvedRedis { + pub endpoint: RedisEndpoint, + pub namespace: Option, + pub timeout: Option, +} + +impl fmt::Debug for ResolvedRedis { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { + formatter + .debug_struct("ResolvedRedis") + .field("endpoint", &self.endpoint) + .field("namespace", &self.namespace) + .field("timeout", &self.timeout) + .finish() + } +} + +#[derive(Clone, PartialEq)] +pub enum RedisEndpoint { + Url(SecretValue), + Host(RedisHost), + Cluster(RedisCluster), +} + +impl fmt::Debug for RedisEndpoint { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Url(_) => formatter.debug_tuple("Url").field(&"").finish(), + Self::Host(host) => host.fmt(formatter), + Self::Cluster(cluster) => cluster.fmt(formatter), + } + } +} + +#[derive(Clone, Debug, PartialEq)] +pub struct RedisHost { + pub host: String, + pub port: u16, + pub username: Option, + pub password: Option, + pub tls: bool, + pub db: i64, +} + +#[derive(Clone, Debug, PartialEq)] +pub struct RedisCluster { + pub nodes: Vec, + pub username: Option, + pub password: Option, + pub tls: bool, +} + +#[derive(Clone, Debug, PartialEq)] +pub struct RedisNode { + pub host: String, + pub port: u16, +} + +#[derive(Clone)] +struct Entry { + value: Value, + source: String, +} + +type Kwargs = BTreeMap; + +impl RedisSettings { + pub fn resolve(&self, lookup: Lookup<'_>) -> Result { + self.resolve_with(lookup, false) + } + + pub fn resolve_cache(&self, lookup: Lookup<'_>) -> Result { + self.resolve_with(lookup, true) + } + + fn resolve_with(&self, lookup: Lookup<'_>, cache: bool) -> Result { + let block = self.kwargs(cache); + let block: Kwargs = block + .into_iter() + .filter_map(|(key, entry)| { + let value = environment_reference(&entry.value, lookup)?; + Some((key, Entry { value, ..entry })) + }) + .collect(); + let environment = environment_kwargs(lookup); + let names_a_target = ["host", "startup_nodes", "sentinel_nodes"] + .iter() + .any(|key| block.contains_key(*key)); + let drop_environment_url = names_a_target && !block.contains_key("url"); + let merged: Kwargs = environment + .into_iter() + .filter(|(key, _)| !(key == "url" && drop_environment_url)) + .chain(block) + .collect(); + reject_unsupported(&merged, lookup)?; + warn_ignored(&merged); + + let startup_nodes = match merged.get("startup_nodes") { + Some(entry) => Some(cluster_nodes(&entry.value)?), + None => lookup("REDIS_CLUSTER_NODES") + .map(|nodes| cluster_nodes(&Value::String(nodes))) + .transpose()?, + }; + let username = secret_value(&merged, "username"); + let password = secret_value(&merged, "password"); + let tls = bool_value(&merged, "ssl"); + let endpoint = match (startup_nodes, text_value(&merged, "url")) { + (Some(nodes), _) if !nodes.is_empty() => RedisEndpoint::Cluster(RedisCluster { + nodes, + username, + password, + tls, + }), + (_, Some(url)) => RedisEndpoint::Url(SecretValue::new(url)), + _ => RedisEndpoint::Host(RedisHost { + host: text_value(&merged, "host").ok_or(Error::RedisInvalid { + setting: "host", + reason: "either host or url must be specified for redis", + })?, + port: integer(&merged, "port")?.unwrap_or(6379), + username, + password, + tls, + db: integer(&merged, "db")?.unwrap_or(0), + }), + }; + let timeout = merged + .get("socket_timeout") + .and_then(|entry| as_text(&entry.value)) + .map(|seconds| { + seconds + .parse::() + .ok() + .and_then(|seconds| Duration::try_from_secs_f64(seconds).ok()) + .ok_or(Error::RedisInvalid { + setting: "socket_timeout", + reason: "must be a non-negative number of seconds", + }) + }) + .transpose()?; + Ok(ResolvedRedis { + endpoint, + namespace: text_value(&merged, "namespace"), + timeout, + }) + } + + fn kwargs(&self, cache: bool) -> Kwargs { + let known = [ + ( + "url", + self.url.as_ref().map(|value| value.expose().to_owned()), + ), + ("host", spelled_text(self.host.as_ref())), + ("port", spelled_text(self.port.as_ref())), + ( + "username", + self.username + .as_ref() + .map(|value| value.expose().to_owned()), + ), + ( + "password", + self.password + .as_ref() + .map(|value| value.expose().to_owned()), + ), + ("ssl", spelled_text(self.ssl.as_ref())), + ("db", spelled_text(self.db.as_ref())), + ("socket_timeout", spelled_text(self.socket_timeout.as_ref())), + ("namespace", spelled_text(self.namespace.as_ref())), + ]; + let known = known.into_iter().filter_map(|(key, value)| { + value.map(|value| { + ( + key.to_owned(), + Entry { + value: Value::String(value), + source: key.to_owned(), + }, + ) + }) + }); + let startup_nodes = self.startup_nodes.clone().map(|value| { + ( + "startup_nodes".to_owned(), + Entry { + value, + source: "startup_nodes".to_owned(), + }, + ) + }); + let extras = self.additional_fields.iter().filter_map(|(key, value)| { + if cache && CACHE_ONLY.contains(&key.as_str()) { + return None; + } + let key = match (cache, key.as_str()) { + (true, "redis_startup_nodes") => "startup_nodes".to_owned(), + _ => key.clone(), + }; + Some(( + key.clone(), + Entry { + value: value.clone(), + source: key, + }, + )) + }); + let unparsed = self.unparsed.iter().map(|(key, value)| { + ( + key.clone(), + Entry { + value: value.0.clone(), + source: key.clone(), + }, + ) + }); + extras + .chain(unparsed) + .chain(known) + .chain(startup_nodes) + .collect() + } +} + +pub fn environment_has_target(lookup: Lookup<'_>) -> bool { + [ + "REDIS_HOST", + "REDIS_URL", + "REDIS_CLUSTER_NODES", + "REDIS_SENTINEL_NODES", + ] + .iter() + .any(|name| lookup(name).is_some()) +} + +fn reject_unsupported(merged: &Kwargs, lookup: Lookup<'_>) -> Result<(), Error> { + let active_auth = [ + merged + .get("gcp_service_account") + .map(|entry| entry.source.as_str()) + .or_else(|| lookup("REDIS_GCP_SERVICE_ACCOUNT").map(|_| "REDIS_GCP_SERVICE_ACCOUNT")), + text_value(merged, "azure_redis_ad_token") + .or_else(|| lookup("REDIS_AZURE_AD_TOKEN")) + .filter(|value| value.eq_ignore_ascii_case("true")) + .map(|_| { + merged + .get("azure_redis_ad_token") + .map_or("REDIS_AZURE_AD_TOKEN", |entry| entry.source.as_str()) + }), + bool_value(merged, "aws_iam_auth").then(|| merged["aws_iam_auth"].source.as_str()), + merged + .get("sentinel_nodes") + .map(|entry| entry.source.as_str()) + .or_else(|| lookup("REDIS_SENTINEL_NODES").map(|_| "REDIS_SENTINEL_NODES")), + ]; + if let Some(setting) = active_auth.into_iter().flatten().next() { + return Err(Error::RedisSetting(setting.to_owned())); + } + match merged + .iter() + .find(|(key, _)| is_unsupported(key)) + .map(|(_, entry)| entry.source.clone()) + { + Some(setting) => Err(Error::RedisSetting(setting)), + None => Ok(()), + } +} + +fn warn_ignored(merged: &Kwargs) { + for setting in WARN_IGNORED { + if merged.contains_key(*setting) { + tracing::warn!(setting, "Redis setting is accepted but ignored"); + } + } +} + +fn is_unsupported(key: &str) -> bool { + let known = REDIS_PY_KWARGS.contains(&key) || UNSUPPORTED_EXTRA.contains(&key); + let handled = SUPPORTED.contains(&key) + || IGNORED.contains(&key) + || matches!( + key, + "gcp_service_account" | "azure_redis_ad_token" | "aws_iam_auth" + ); + known && !handled +} + +fn environment_kwargs(lookup: Lookup<'_>) -> Kwargs { + REDIS_PY_KWARGS + .iter() + .filter_map(|key| { + let source = format!("REDIS_{}", key.to_ascii_uppercase()); + let value = lookup(&source)?; + Some(( + (*key).to_owned(), + Entry { + value: Value::String(value), + source, + }, + )) + }) + .collect() +} + +fn environment_reference(value: &Value, lookup: Lookup<'_>) -> Option { + match value { + Value::String(text) => match text.strip_prefix("os.environ/") { + Some(name) => lookup(name).map(Value::String), + None => Some(value.clone()), + }, + Value::Null => None, + _ => Some(value.clone()), + } +} + +fn as_text(value: &Value) -> Option { + match value { + Value::String(text) => Some(text.clone()), + Value::Number(number) => Some(number.to_string()), + Value::Bool(flag) => Some(flag.to_string()), + _ => None, + } +} + +fn text_value(kwargs: &Kwargs, key: &str) -> Option { + kwargs.get(key).and_then(|entry| as_text(&entry.value)) +} + +fn secret_value(kwargs: &Kwargs, key: &str) -> Option { + text_value(kwargs, key).map(SecretValue::new) +} + +fn bool_value(kwargs: &Kwargs, key: &str) -> bool { + match kwargs.get(key).map(|entry| &entry.value) { + Some(Value::Bool(flag)) => *flag, + Some(value) => as_text(value) + .is_some_and(|text| matches!(text.to_ascii_lowercase().as_str(), "true" | "1" | "yes")), + None => false, + } +} + +fn integer(kwargs: &Kwargs, key: &'static str) -> Result, Error> { + kwargs + .get(key) + .and_then(|entry| as_text(&entry.value)) + .map(|text| { + text.parse().map_err(|_| Error::RedisInvalid { + setting: key, + reason: "must be an integer", + }) + }) + .transpose() +} + +const INVALID_NODES: Error = Error::RedisInvalid { + setting: "startup_nodes", + reason: "must be a list of {host, port} objects", +}; + +fn cluster_nodes(value: &Value) -> Result, Error> { + match value { + Value::String(json) => { + let nodes: Vec> = + serde_json::from_str(json).map_err(|_| INVALID_NODES)?; + nodes + .iter() + .map(|node| { + cluster_node( + node.get("host").and_then(json_text), + node.get("port").and_then(json_text), + ) + }) + .collect() + } + Value::Sequence(nodes) => nodes + .iter() + .map(|node| { + cluster_node( + node.get("host").and_then(as_text), + node.get("port").and_then(as_text), + ) + }) + .collect(), + _ => Err(INVALID_NODES), + } +} + +fn cluster_node(host: Option, port: Option) -> Result { + match (host, port.and_then(|port| port.parse().ok())) { + (Some(host), Some(port)) => Ok(RedisNode { host, port }), + _ => Err(INVALID_NODES), + } +} + +fn json_text(value: &serde_json::Value) -> Option { + match value { + serde_json::Value::String(text) => Some(text.clone()), + serde_json::Value::Number(number) => Some(number.to_string()), + _ => None, + } +} + +fn spelled_text(value: Option<&Spelled>) -> Option { + value.map(|value| match value { + Spelled::Value(value) => value.to_string(), + Spelled::Text(value) => value.clone(), + }) +} + +fn spelled(text: Option) -> Option> { + text.map(|text| match text.parse() { + Ok(value) => Spelled::Value(value), + Err(_) => Spelled::Text(text), + }) +} + +fn cloned( + fields: &BTreeMap, + keep: impl Fn(&str, &Value) -> bool, +) -> AdditionalFields { + fields + .iter() + .filter(|(key, value)| keep(key, value)) + .map(|(key, value)| (key.clone(), value.clone())) + .collect() +} + +#[derive(Clone)] +struct DeferredInput(Value); + +type DeferredInputs = BTreeMap; + +fn deferred_inputs(fields: &BTreeMap) -> DeferredInputs { + fields + .iter() + .filter(|(key, value)| is_unparsed(key, value)) + .map(|(key, value)| (key.clone(), DeferredInput(value.clone()))) + .collect() +} + +fn is_unparsed(key: &str, value: &Value) -> bool { + SUPPORTED.contains(&key) + && match key { + "startup_nodes" => value.is_null(), + _ => as_text(value).is_none(), + } +} diff --git a/litellm-rust/crates/config/src/settings.rs b/litellm-rust/crates/config/src/settings.rs index 1094de1638e..9571c4fa5de 100644 --- a/litellm-rust/crates/config/src/settings.rs +++ b/litellm-rust/crates/config/src/settings.rs @@ -3,7 +3,9 @@ use std::fmt; use litellm_auth_types::SecretValue; use serde::Deserialize; -use crate::{AdditionalFields, Object, Spelled, Value, value::one_or_many}; +use crate::{ + AdditionalFields, CacheSettings, Object, RedisSettings, Spelled, Value, value::one_or_many, +}; #[derive(Clone, Debug, Deserialize)] #[serde(rename_all = "lowercase")] @@ -76,7 +78,7 @@ pub struct GeneralSettings { pub enable_public_model_hub: bool, pub dangerously_permit_weak_or_unset_master_key: Option, pub plugins: Option>, - pub coordination_redis: Option, + pub coordination_redis: Option, pub mcp_allowed_hosts: Option>, pub mcp_allowed_origins: Box<[String]>, #[serde(flatten)] @@ -220,7 +222,7 @@ pub struct LiteLlmSettings { pub request_timeout: Option>, pub num_retries: Option, pub cache: Option, - pub cache_params: Option, + pub cache_params: Option, #[serde(deserialize_with = "one_or_many")] pub callbacks: Option>, #[serde(deserialize_with = "one_or_many")] diff --git a/litellm-rust/crates/config/src/value.rs b/litellm-rust/crates/config/src/value.rs index 5becdc87b70..667a5afa130 100644 --- a/litellm-rust/crates/config/src/value.rs +++ b/litellm-rust/crates/config/src/value.rs @@ -10,6 +10,10 @@ pub type AdditionalFields = BTreeMap; pub struct Object(BTreeMap); impl Object { + pub(crate) fn from_fields(fields: BTreeMap) -> Self { + Self(fields) + } + pub fn get(&self, key: &str) -> Option<&Value> { self.0.get(key) } diff --git a/litellm-rust/crates/config/tests/redis.rs b/litellm-rust/crates/config/tests/redis.rs new file mode 100644 index 00000000000..ab409541c8e --- /dev/null +++ b/litellm-rust/crates/config/tests/redis.rs @@ -0,0 +1,405 @@ +use std::{ + collections::HashMap, + fmt::Write, + sync::{Arc, Mutex}, +}; + +use litellm_config::{CacheSettings, Config, Error, RedisEndpoint, RedisSettings, ResolvedRedis}; +use rstest::rstest; +use tracing::{Event, Subscriber, field::Visit}; +use tracing_subscriber::{Layer, layer::Context, prelude::*}; + +fn resolve( + yaml: &str, + environment: &[(&str, &str)], +) -> Result { + let environment: HashMap = environment + .iter() + .map(|(key, value)| ((*key).to_owned(), (*value).to_owned())) + .collect(); + let config = Config::from_yaml(yaml).unwrap(); + config + .general_settings + .coordination_redis + .as_ref() + .unwrap_or(&RedisSettings::default()) + .resolve(&|name| environment.get(name).cloned()) +} + +fn resolve_cache(yaml: &str) -> Result { + let config = Config::from_yaml(yaml).unwrap(); + match config.litellm_settings.cache_params.unwrap() { + CacheSettings::Redis(settings) => settings.resolve_cache(&|_| None), + CacheSettings::Other(_) => panic!("expected a Redis cache"), + } +} + +fn cluster_ports(resolved: &ResolvedRedis) -> Vec { + match &resolved.endpoint { + RedisEndpoint::Cluster(cluster) => cluster.nodes.iter().map(|node| node.port).collect(), + endpoint => panic!("expected a cluster, got {endpoint:?}"), + } +} + +#[rstest] +#[case::host( + "general_settings:\n coordination_redis:\n host: redis\n port: 6380\n db: 2\n ssl: true\n namespace: app\n socket_timeout: 1.5", + &[], + "host:redis:6380:2:true:app:1500" +)] +#[case::environment_url( + "model_list: []", + &[("REDIS_URL", "redis://environment:6379")], + "url:redis://environment:6379" +)] +#[case::explicit_host_drops_environment_url( + "general_settings:\n coordination_redis:\n host: configured", + &[("REDIS_URL", "redis://environment:6379")], + "host:configured:6379:0:false::none" +)] +#[case::yaml_cluster( + "general_settings:\n coordination_redis:\n startup_nodes:\n - host: node-a\n port: 7000\n - host: node-b\n port: \"7001\"", + &[], + "cluster:node-a:7000,node-b:7001" +)] +#[case::json_environment_cluster( + "model_list: []", + &[("REDIS_CLUSTER_NODES", r#"[{"host":"node-a","port":"7000"},{"host":"node-b","port":7001}]"#)], + "cluster:node-a:7000,node-b:7001" +)] +#[case::missing_reference_keeps_environment_fallback( + "general_settings:\n coordination_redis:\n host: os.environ/MISSING_HOST", + &[("REDIS_HOST", "environment")], + "host:environment:6379:0:false::none" +)] +#[case::configured_values_beat_the_same_environment_values( + "general_settings:\n coordination_redis:\n host: configured\n port: 6380\n db: 3", + &[("REDIS_HOST", "environment"), ("REDIS_PORT", "6390"), ("REDIS_DB", "9")], + "host:configured:6380:3:false::none" +)] +#[case::environment_url_beats_the_environment_host( + "model_list: []", + &[("REDIS_URL", "redis://environment:6379"), ("REDIS_HOST", "ignored")], + "url:redis://environment:6379" +)] +#[case::startup_nodes_beat_a_url( + "general_settings:\n coordination_redis:\n url: redis://single:6379\n startup_nodes:\n - host: node-a\n port: 7000", + &[], + "cluster:node-a:7000" +)] +#[case::environment_references_resolve_the_host_and_port( + "general_settings:\n coordination_redis:\n host: os.environ/COORD_HOST\n port: os.environ/COORD_PORT", + &[("COORD_HOST", "referenced"), ("COORD_PORT", "6400")], + "host:referenced:6400:0:false::none" +)] +#[case::a_null_host_falls_back_to_the_environment( + "general_settings:\n coordination_redis:\n host: null", + &[("REDIS_HOST", "environment")], + "host:environment:6379:0:false::none" +)] +fn resolves_redis_through_the_parsed_config( + #[case] yaml: &str, + #[case] environment: &[(&str, &str)], + #[case] expected: &str, +) { + let resolved = resolve(yaml, environment).unwrap(); + let description = match resolved.endpoint { + RedisEndpoint::Url(url) => format!("url:{}", url.expose()), + RedisEndpoint::Host(host) => format!( + "host:{}:{}:{}:{}:{}:{}", + host.host, + host.port, + host.db, + host.tls, + resolved.namespace.unwrap_or_default(), + resolved + .timeout + .map(|timeout| timeout.as_millis().to_string()) + .unwrap_or_else(|| "none".to_owned()) + ), + RedisEndpoint::Cluster(cluster) => format!( + "cluster:{}", + cluster + .nodes + .iter() + .map(|node| format!("{}:{}", node.host, node.port)) + .collect::>() + .join(",") + ), + }; + + assert_eq!(description, expected); +} + +#[rstest] +#[case::custom_tls_file( + "general_settings:\n coordination_redis:\n host: redis\n ssl_ca_certs: /ca.pem", + &[], + "ssl_ca_certs" +)] +#[case::gcp_auth_from_config( + "general_settings:\n coordination_redis:\n host: redis\n gcp_service_account: account", + &[], + "gcp_service_account" +)] +#[case::gcp_auth_from_environment( + "model_list: []", + &[("REDIS_HOST", "redis"), ("REDIS_GCP_SERVICE_ACCOUNT", "account")], + "REDIS_GCP_SERVICE_ACCOUNT" +)] +#[case::azure_auth_from_config( + "general_settings:\n coordination_redis:\n host: redis\n azure_redis_ad_token: true", + &[], + "azure_redis_ad_token" +)] +#[case::azure_auth_from_environment( + "model_list: []", + &[("REDIS_HOST", "redis"), ("REDIS_AZURE_AD_TOKEN", "true")], + "REDIS_AZURE_AD_TOKEN" +)] +#[case::aws_auth_from_config( + "general_settings:\n coordination_redis:\n host: redis\n aws_iam_auth: true", + &[], + "aws_iam_auth" +)] +#[case::aws_auth_from_environment( + "model_list: []", + &[("REDIS_HOST", "redis"), ("REDIS_AWS_IAM_AUTH", "true")], + "REDIS_AWS_IAM_AUTH" +)] +#[case::sentinel_from_config( + "general_settings:\n coordination_redis:\n sentinel_nodes: [[redis, 26379]]", + &[], + "sentinel_nodes" +)] +#[case::sentinel_from_environment( + "model_list: []", + &[("REDIS_SENTINEL_NODES", "[[\"redis\",26379]]")], + "REDIS_SENTINEL_NODES" +)] +fn rejected_settings_name_their_source( + #[case] yaml: &str, + #[case] environment: &[(&str, &str)], + #[case] expected: &str, +) { + let error = resolve(yaml, environment).unwrap_err(); + + assert!(matches!(error, Error::RedisSetting(setting) if setting == expected)); +} + +#[rstest] +fn an_explicit_host_keeps_environment_credentials() { + let resolved = resolve( + "general_settings:\n coordination_redis:\n host: configured", + &[ + ("REDIS_PASSWORD", "environment-secret"), + ("REDIS_SSL", "True"), + ], + ) + .unwrap(); + + let RedisEndpoint::Host(host) = resolved.endpoint else { + panic!("expected a host endpoint"); + }; + assert_eq!( + host.password.as_ref().map(|password| password.expose()), + Some("environment-secret") + ); + assert!(host.tls); +} + +#[rstest] +#[case::only_a_port("general_settings:\n coordination_redis:\n port: 6379", &[])] +#[case::a_structured_host_with_an_environment_target( + "general_settings:\n coordination_redis:\n host: []", + &[("REDIS_HOST", "environment"), ("REDIS_URL", "redis://environment:6379")] +)] +fn a_block_without_a_usable_target_fails(#[case] yaml: &str, #[case] environment: &[(&str, &str)]) { + let error = resolve(yaml, environment).unwrap_err(); + + assert!(matches!( + error, + Error::RedisInvalid { + setting: "host", + .. + } + )); +} + +#[rstest] +fn the_cache_alias_names_cluster_nodes() { + let resolved = resolve_cache( + "litellm_settings:\n cache_params:\n type: redis\n redis_startup_nodes:\n - host: node-a\n port: 7000", + ) + .unwrap(); + + assert_eq!(cluster_ports(&resolved), vec![7000]); +} + +#[rstest] +fn canonical_startup_nodes_beat_the_cache_alias() { + let resolved = resolve_cache( + "litellm_settings:\n cache_params:\n type: redis\n startup_nodes:\n - host: canonical\n port: 7000\n redis_startup_nodes:\n - host: alias\n port: 7100\n - host: alias\n port: 7101", + ) + .unwrap(); + + assert_eq!(cluster_ports(&resolved), vec![7000]); +} + +#[rstest] +fn a_null_canonical_startup_nodes_setting_shadows_the_cache_alias() { + let resolved = resolve_cache( + "litellm_settings:\n cache_params:\n type: redis\n host: cache\n startup_nodes: null\n redis_startup_nodes:\n - host: alias\n port: 7100", + ) + .unwrap(); + + assert!(matches!(resolved.endpoint, RedisEndpoint::Host(_))); +} + +#[rstest] +fn a_missing_canonical_startup_nodes_reference_shadows_the_cache_alias() { + let resolved = resolve_cache( + "litellm_settings:\n cache_params:\n type: redis\n host: cache\n startup_nodes: os.environ/MISSING_NODES\n redis_startup_nodes:\n - host: alias\n port: 7100", + ) + .unwrap(); + + assert!(matches!(resolved.endpoint, RedisEndpoint::Host(_))); +} + +#[rstest] +fn rejected_environment_settings_never_print_the_value() { + let error = resolve( + "model_list: []", + &[ + ("REDIS_HOST", "redis"), + ("REDIS_SSL_CERT_REQS", "private-option-value"), + ], + ) + .unwrap_err(); + let message = error.to_string(); + + assert!(message.contains("REDIS_SSL_CERT_REQS")); + assert!(!message.contains("private-option-value")); +} + +#[rstest] +#[case::negative("-1")] +#[case::not_a_number("slow")] +fn rejects_bad_socket_timeout(#[case] timeout: &str) { + let yaml = format!( + "general_settings:\n coordination_redis:\n host: redis\n socket_timeout: {timeout}" + ); + let error = resolve(&yaml, &[]).unwrap_err(); + + assert!(matches!( + error, + Error::RedisInvalid { + setting: "socket_timeout", + .. + } + )); +} + +#[rstest] +fn defaults_socket_timeout_for_the_gateway() { + let resolved = resolve( + "general_settings:\n coordination_redis:\n host: redis", + &[], + ) + .unwrap(); + + assert_eq!(resolved.timeout, None); +} + +#[rstest] +fn debug_redacts_redis_secrets_and_url() { + let config = Config::from_yaml( + "general_settings:\n coordination_redis:\n url: redis://user:password@redis:6379\n username: credential-user\n password: credential-password", + ) + .unwrap(); + let settings = config.general_settings.coordination_redis.unwrap(); + let resolved = settings.resolve(&|_| None).unwrap(); + let debug = format!("{settings:?} {resolved:?}"); + + assert!(!debug.contains("redis://user:password")); + assert!(!debug.contains("credential-user")); + assert!(!debug.contains("credential-password")); + assert!(debug.contains("redacted") || debug.contains("REDACTED")); +} + +#[rstest] +fn inactive_redis_cache_keeps_malformed_known_inputs_deferred() { + let config = Config::from_yaml( + "litellm_settings:\n cache: false\n cache_params:\n type: redis\n host: []\n port: invalid\n socket_timeout: invalid", + ) + .unwrap(); + + assert!(matches!( + config.litellm_settings.cache_params, + Some(litellm_config::CacheSettings::Redis(_)) + )); +} + +#[rstest] +fn non_redis_cache_settings_remain_opaque() { + let config = Config::from_yaml( + "litellm_settings:\n cache_params:\n type: local\n custom_option:\n nested: true", + ) + .unwrap(); + + assert!(matches!( + config.litellm_settings.cache_params, + Some(litellm_config::CacheSettings::Other(_)) + )); +} + +#[rstest] +fn legacy_unknown_settings_do_not_change_resolution() { + let resolved = resolve( + "general_settings:\n coordination_redis:\n host: redis\n redis_flush_size: 42\n service_name: primary", + &[], + ) + .unwrap(); + + assert!(matches!(resolved.endpoint, RedisEndpoint::Host(_))); +} + +struct WarningCapture(Arc>>); + +impl Layer for WarningCapture { + fn on_event(&self, event: &Event<'_>, _context: Context<'_, S>) { + let mut fields = Fields::default(); + event.record(&mut fields); + self.0.lock().unwrap().push(fields.0); + } +} + +#[derive(Default)] +struct Fields(String); + +impl Visit for Fields { + fn record_debug(&mut self, field: &tracing::field::Field, value: &dyn std::fmt::Debug) { + write!(self.0, "{}={value:?} ", field.name()).unwrap(); + } + + fn record_str(&mut self, field: &tracing::field::Field, value: &str) { + write!(self.0, "{}={value} ", field.name()).unwrap(); + } +} + +#[rstest] +fn ignored_setting_warning_names_the_setting_without_its_value() { + let events = Arc::new(Mutex::new(Vec::new())); + let subscriber = tracing_subscriber::registry().with(WarningCapture(events.clone())); + tracing::subscriber::with_default(subscriber, || { + resolve( + "general_settings:\n coordination_redis:\n host: redis\n max_connections: 47", + &[], + ) + .unwrap(); + }); + let warnings = events.lock().unwrap().join(" "); + + assert!(warnings.contains("max_connections")); + assert!(!warnings.contains("47")); +} diff --git a/litellm-rust/crates/core-utils/src/exception_mapping_utils/mod.rs b/litellm-rust/crates/core-utils/src/exception_mapping_utils/mod.rs index 162d325e4f4..8b63fadf5a6 100644 --- a/litellm-rust/crates/core-utils/src/exception_mapping_utils/mod.rs +++ b/litellm-rust/crates/core-utils/src/exception_mapping_utils/mod.rs @@ -51,7 +51,7 @@ mod rules; mod status; mod vertex_ai; -pub use original::{ExceptionFamily, OriginalException}; +pub use original::{ExceptionFamily, OriginalException, TimeoutPhase}; pub use public::{MappedFailure, PublicError, UpstreamResponse}; use rules::{Rule, contains_any, first_match}; @@ -67,7 +67,6 @@ const TIMEOUT_MARKERS: &[&str] = &[ pub struct ExceptionContext { pub model: String, pub custom_llm_provider: String, - pub asynchronous: bool, pub vertex_project: Option, pub vertex_location: Option, pub model_group: Option, @@ -105,11 +104,12 @@ pub fn exception_type( (None, message.clone(), None) } OriginalException::Timeout { + phase, timeout_seconds, elapsed_seconds, } => ( None, - timeout_message(context.asynchronous, *timeout_seconds, *elapsed_seconds), + timeout_message(*phase, *timeout_seconds, *elapsed_seconds), None, ), }; @@ -161,21 +161,16 @@ fn family_rules(family: ExceptionFamily) -> &'static [Rule] { } } -/// The text the Python HTTP handler's timeout carries: the sync and async handlers word it -/// differently. -fn timeout_message( - asynchronous: bool, +/// The text the Python HTTP handler's timeout carries: the phase that expired and the limit +/// httpx enforced for it, both rendered as Python would print them. +pub fn timeout_message( + phase: TimeoutPhase, timeout_seconds: Option, elapsed_seconds: Option, ) -> String { let timeout = python_float(timeout_seconds); - if asynchronous { - let elapsed = - python_float(elapsed_seconds.map(|seconds| (seconds * 1000.0).round() / 1000.0)); - format!("Connection timed out. Timeout passed={timeout}, time taken={elapsed} seconds") - } else { - format!("Connection timed out after {timeout} seconds.") - } + let elapsed = python_float(elapsed_seconds.map(|seconds| (seconds * 1000.0).round() / 1000.0)); + format!("{phase} timed out. Timeout passed={timeout}, time taken={elapsed} seconds") } fn python_float(value: Option) -> String { @@ -356,6 +351,7 @@ mod tests { #[test] fn a_handler_timeout_is_a_408_without_a_response() { let original = OriginalException::Timeout { + phase: TimeoutPhase::Read, timeout_seconds: Some(0.5), elapsed_seconds: Some(0.5031), }; @@ -363,7 +359,7 @@ mod tests { mapped("mistral", &original), MappedFailure { error: PublicError::Timeout { status: 408 }, - message: "MistralException - Connection timed out after 0.5 seconds.".into(), + message: "MistralException - Read timed out. Timeout passed=0.5, time taken=0.503 seconds".into(), upstream: None, debug_info: DEBUG.into(), } @@ -440,39 +436,44 @@ mod tests { } #[rstest::rstest] - #[case::sync( - false, + #[case::connect(TimeoutPhase::Connect, "Connection timed out.")] + #[case::read(TimeoutPhase::Read, "Read timed out.")] + #[case::write(TimeoutPhase::Write, "Write timed out.")] + #[case::pool(TimeoutPhase::Pool, "Connection pool timed out.")] + fn timeout_text_names_the_phase_that_expired( + #[case] phase: TimeoutPhase, + #[case] expected: &str, + ) { + assert_eq!( + timeout_message(phase, Some(0.5), Some(0.5031)), + format!("{expected} Timeout passed=0.5, time taken=0.503 seconds") + ); + } + + #[rstest::rstest] + #[case::rounds_the_elapsed_time( Some(0.5), Some(0.5031), - "Connection timed out after 0.5 seconds." - )] - #[case::async_rounds_the_elapsed_time( - true, - Some(0.5), - Some(0.5031), - "Connection timed out. Timeout passed=0.5, time taken=0.503 seconds" + "Timeout passed=0.5, time taken=0.503 seconds" )] #[case::whole_seconds_keep_a_decimal( - true, Some(600.0), Some(2.0), - "Connection timed out. Timeout passed=600.0, time taken=2.0 seconds" + "Timeout passed=600.0, time taken=2.0 seconds" )] #[case::unknown_values_render_as_none( - true, None, None, - "Connection timed out. Timeout passed=None, time taken=None seconds" + "Timeout passed=None, time taken=None seconds" )] - fn timeout_text_follows_the_delivery_mode( - #[case] asynchronous: bool, + fn timeout_text_renders_durations_as_python_floats( #[case] timeout_seconds: Option, #[case] elapsed_seconds: Option, #[case] expected: &str, ) { assert_eq!( - timeout_message(asynchronous, timeout_seconds, elapsed_seconds), - expected + timeout_message(TimeoutPhase::Read, timeout_seconds, elapsed_seconds), + format!("Read timed out. {expected}") ); } diff --git a/litellm-rust/crates/core-utils/src/exception_mapping_utils/original.rs b/litellm-rust/crates/core-utils/src/exception_mapping_utils/original.rs index 4de67e6e7b5..6517b093bbd 100644 --- a/litellm-rust/crates/core-utils/src/exception_mapping_utils/original.rs +++ b/litellm-rust/crates/core-utils/src/exception_mapping_utils/original.rs @@ -10,6 +10,7 @@ pub enum OriginalException { message: String, }, Timeout { + phase: TimeoutPhase, timeout_seconds: Option, elapsed_seconds: Option, }, @@ -20,6 +21,19 @@ pub enum OriginalException { }, } +/// The httpx timeout that expired, spelled the way the Python HTTP handler names it. +#[derive(Clone, Copy, Debug, PartialEq, Eq, strum::Display, strum::VariantArray)] +pub enum TimeoutPhase { + #[strum(serialize = "Connection")] + Connect, + #[strum(serialize = "Read")] + Read, + #[strum(serialize = "Write")] + Write, + #[strum(serialize = "Connection pool")] + Pool, +} + /// Which provider-specific text rules apply before the shared status table. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum ExceptionFamily { diff --git a/litellm-rust/crates/db-testing/Cargo.toml b/litellm-rust/crates/db-testing/Cargo.toml index 3ba71fbf644..457c0f2ad87 100644 --- a/litellm-rust/crates/db-testing/Cargo.toml +++ b/litellm-rust/crates/db-testing/Cargo.toml @@ -7,7 +7,7 @@ repository.workspace = true [dependencies] sqlx = { workspace = true, features = ["migrate"] } -testcontainers-modules = { version = "0.15.0", features = ["postgres"] } +testcontainers-modules = { workspace = true, features = ["postgres"] } thiserror.workspace = true tokio.workspace = true diff --git a/litellm-rust/crates/db/.sqlx/query-085edfb9af2a914466c75b447bc7bb2d97532a9cd461cc5d8da1e1090560ca1f.json b/litellm-rust/crates/db/.sqlx/query-085edfb9af2a914466c75b447bc7bb2d97532a9cd461cc5d8da1e1090560ca1f.json new file mode 100644 index 00000000000..a415666d0be --- /dev/null +++ b/litellm-rust/crates/db/.sqlx/query-085edfb9af2a914466c75b447bc7bb2d97532a9cd461cc5d8da1e1090560ca1f.json @@ -0,0 +1,23 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT pg_advisory_xact_lock(hashtext($1)) IS NULL AS \"locked!\"\n", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "locked!", + "type_info": "Bool", + "origin": "Expression" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + null + ] + }, + "hash": "085edfb9af2a914466c75b447bc7bb2d97532a9cd461cc5d8da1e1090560ca1f" +} diff --git a/litellm-rust/crates/db/.sqlx/query-32f3c07ced96324b535bbc703c1acf6d06eb22facdf478f88107c9dccdac326b.json b/litellm-rust/crates/db/.sqlx/query-32f3c07ced96324b535bbc703c1acf6d06eb22facdf478f88107c9dccdac326b.json new file mode 100644 index 00000000000..c4eb1737d85 --- /dev/null +++ b/litellm-rust/crates/db/.sqlx/query-32f3c07ced96324b535bbc703c1acf6d06eb22facdf478f88107c9dccdac326b.json @@ -0,0 +1,40 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO \"LiteLLM_SpendLogs\" (\n request_id, call_type, api_key, spend, total_tokens, prompt_tokens,\n completion_tokens, \"startTime\", \"endTime\", \"completionStartTime\",\n request_duration_ms, model, model_id, model_group, custom_llm_provider, api_base,\n \"user\", metadata, cache_hit, cache_key, request_tags, team_id, organization_id,\n end_user, requester_ip_address, messages, response, proxy_server_request,\n session_id, status, litellm_call_id\n)\nSELECT l.request_id, l.call_type, l.api_key, l.spend, l.total_tokens, l.prompt_tokens,\n l.completion_tokens, l.start_time::timestamp(3), l.end_time::timestamp(3),\n l.completion_start_time::timestamp(3), l.request_duration_ms, l.model,\n l.model_id, l.model_group, l.custom_llm_provider, l.api_base, l.user_id,\n l.metadata, l.cache_hit, l.cache_key, '[]'::jsonb, l.team_id,\n l.organization_id, l.end_user, l.requester_ip_address, '{}'::jsonb,\n '{}'::jsonb, '{}'::jsonb, l.session_id, l.status, l.litellm_call_id\nFROM UNNEST($1::text[], $2::text[], $3::text[], $4::float8[], $5::int4[], $6::int4[],\n $7::int4[], $8::timestamp[], $9::timestamp[], $10::timestamp[], $11::int4[], $12::text[],\n $13::text[], $14::text[], $15::text[], $16::text[], $17::text[],\n $18::jsonb[], $19::text[], $20::text[], $21::text[], $22::text[],\n $23::text[], $24::text[], $25::text[], $26::text[], $27::text[])\n AS l(request_id, call_type, api_key, spend, total_tokens, prompt_tokens,\n completion_tokens, start_time, end_time, completion_start_time,\n request_duration_ms, model, model_id, model_group, custom_llm_provider,\n api_base, user_id, metadata, cache_hit, cache_key, team_id, organization_id,\n end_user, requester_ip_address, session_id, status, litellm_call_id)\nON CONFLICT DO NOTHING\n", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "TextArray", + "TextArray", + "TextArray", + "Float8Array", + "Int4Array", + "Int4Array", + "Int4Array", + "TimestampArray", + "TimestampArray", + "TimestampArray", + "Int4Array", + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "JsonbArray", + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "TextArray" + ] + }, + "nullable": [] + }, + "hash": "32f3c07ced96324b535bbc703c1acf6d06eb22facdf478f88107c9dccdac326b" +} diff --git a/litellm-rust/crates/db/.sqlx/query-345c02595f55a7f0274ef7214b02288e0f2c1f12a2a79ed53f0002826724cd0a.json b/litellm-rust/crates/db/.sqlx/query-345c02595f55a7f0274ef7214b02288e0f2c1f12a2a79ed53f0002826724cd0a.json new file mode 100644 index 00000000000..123ff15ade2 --- /dev/null +++ b/litellm-rust/crates/db/.sqlx/query-345c02595f55a7f0274ef7214b02288e0f2c1f12a2a79ed53f0002826724cd0a.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO \"LiteLLM_EndUserTable\" (user_id, spend, blocked)\nSELECT id, SUM(cost), false FROM UNNEST($1::text[], $2::float8[]) AS a(id, cost)\nGROUP BY id\nORDER BY id\nON CONFLICT (user_id) DO UPDATE\nSET spend = \"LiteLLM_EndUserTable\".spend + EXCLUDED.spend\n", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "TextArray", + "Float8Array" + ] + }, + "nullable": [] + }, + "hash": "345c02595f55a7f0274ef7214b02288e0f2c1f12a2a79ed53f0002826724cd0a" +} diff --git a/litellm-rust/crates/db/.sqlx/query-377d063cd0fc3a265d07d01f5aa64311d25428fd393bac4250891f148597e92e.json b/litellm-rust/crates/db/.sqlx/query-377d063cd0fc3a265d07d01f5aa64311d25428fd393bac4250891f148597e92e.json new file mode 100644 index 00000000000..734935466ff --- /dev/null +++ b/litellm-rust/crates/db/.sqlx/query-377d063cd0fc3a265d07d01f5aa64311d25428fd393bac4250891f148597e92e.json @@ -0,0 +1,78 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT e.spend AS \"spend?\",\n e.blocked AS \"blocked?\",\n b.max_budget AS \"max_budget?\",\n b.rpm_limit AS \"rpm_limit?\",\n b.tpm_limit AS \"tpm_limit?\"\nFROM (SELECT 1) AS one\nLEFT JOIN \"LiteLLM_EndUserTable\" AS e ON e.user_id = $1\nLEFT JOIN \"LiteLLM_BudgetTable\" AS assigned ON assigned.budget_id = e.budget_id\nLEFT JOIN \"LiteLLM_BudgetTable\" AS key_budget ON key_budget.budget_id = $3\nLEFT JOIN \"LiteLLM_BudgetTable\" AS b ON b.budget_id = COALESCE(assigned.budget_id, key_budget.budget_id, $2)\n", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "spend?", + "type_info": "Float8", + "origin": { + "Table": { + "table": "\"LiteLLM_EndUserTable\"", + "name": "spend" + } + } + }, + { + "ordinal": 1, + "name": "blocked?", + "type_info": "Bool", + "origin": { + "Table": { + "table": "\"LiteLLM_EndUserTable\"", + "name": "blocked" + } + } + }, + { + "ordinal": 2, + "name": "max_budget?", + "type_info": "Float8", + "origin": { + "Table": { + "table": "\"LiteLLM_BudgetTable\"", + "name": "max_budget" + } + } + }, + { + "ordinal": 3, + "name": "rpm_limit?", + "type_info": "Int8", + "origin": { + "Table": { + "table": "\"LiteLLM_BudgetTable\"", + "name": "rpm_limit" + } + } + }, + { + "ordinal": 4, + "name": "tpm_limit?", + "type_info": "Int8", + "origin": { + "Table": { + "table": "\"LiteLLM_BudgetTable\"", + "name": "tpm_limit" + } + } + } + ], + "parameters": { + "Left": [ + "Text", + "Text", + "Text" + ] + }, + "nullable": [ + true, + true, + true, + true, + true + ] + }, + "hash": "377d063cd0fc3a265d07d01f5aa64311d25428fd393bac4250891f148597e92e" +} diff --git a/litellm-rust/crates/db/.sqlx/query-3829a383d0ae50578f0fd75da3910731a0cacc1ae5b92eec32967f539948f563.json b/litellm-rust/crates/db/.sqlx/query-3829a383d0ae50578f0fd75da3910731a0cacc1ae5b92eec32967f539948f563.json new file mode 100644 index 00000000000..e85c0986a60 --- /dev/null +++ b/litellm-rust/crates/db/.sqlx/query-3829a383d0ae50578f0fd75da3910731a0cacc1ae5b92eec32967f539948f563.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "WITH added AS (\n SELECT id, SUM(cost) AS cost\n FROM UNNEST($1::text[], $2::float8[]) AS a(id, cost)\n GROUP BY id\n), locked AS (\n SELECT t.token FROM \"LiteLLM_VerificationToken\" t\n WHERE t.token IN (SELECT id FROM added)\n ORDER BY t.token FOR UPDATE\n)\nUPDATE \"LiteLLM_VerificationToken\" t\nSET spend = t.spend + added.cost,\n total_spend = t.total_spend + added.cost,\n last_active = (clock_timestamp() AT TIME ZONE 'UTC'),\n updated_at = (clock_timestamp() AT TIME ZONE 'UTC')\nFROM added\nWHERE t.token = added.id AND t.token IN (SELECT token FROM locked)\n", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "TextArray", + "Float8Array" + ] + }, + "nullable": [] + }, + "hash": "3829a383d0ae50578f0fd75da3910731a0cacc1ae5b92eec32967f539948f563" +} diff --git a/litellm-rust/crates/db/.sqlx/query-43f2e12a3ffb1de29b5b031a1173b87a20a2664b0bef3616631d2c24487c1e54.json b/litellm-rust/crates/db/.sqlx/query-43f2e12a3ffb1de29b5b031a1173b87a20a2664b0bef3616631d2c24487c1e54.json new file mode 100644 index 00000000000..a758ae5126a --- /dev/null +++ b/litellm-rust/crates/db/.sqlx/query-43f2e12a3ffb1de29b5b031a1173b87a20a2664b0bef3616631d2c24487c1e54.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "WITH added AS (\n SELECT id, SUM(cost) AS cost\n FROM UNNEST($1::text[], $2::float8[]) AS a(id, cost)\n GROUP BY id\n), locked AS (\n SELECT u.user_id FROM \"LiteLLM_UserTable\" u\n WHERE u.user_id IN (SELECT id FROM added)\n ORDER BY u.user_id FOR UPDATE\n)\nUPDATE \"LiteLLM_UserTable\" u\nSET spend = u.spend + added.cost,\n updated_at = (NOW() AT TIME ZONE 'UTC')\nFROM added\nWHERE u.user_id = added.id AND u.user_id IN (SELECT user_id FROM locked)\n", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "TextArray", + "Float8Array" + ] + }, + "nullable": [] + }, + "hash": "43f2e12a3ffb1de29b5b031a1173b87a20a2664b0bef3616631d2c24487c1e54" +} diff --git a/litellm-rust/crates/db/.sqlx/query-5c74f47a2b84574133c520d235192bf33e16fea1dbb0c32cf89a376a874927f4.json b/litellm-rust/crates/db/.sqlx/query-5c74f47a2b84574133c520d235192bf33e16fea1dbb0c32cf89a376a874927f4.json new file mode 100644 index 00000000000..7eef5278cb5 --- /dev/null +++ b/litellm-rust/crates/db/.sqlx/query-5c74f47a2b84574133c520d235192bf33e16fea1dbb0c32cf89a376a874927f4.json @@ -0,0 +1,21 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT set_config('lock_timeout', '5000ms', true)", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "set_config", + "type_info": "Text", + "origin": "Expression" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + null + ] + }, + "hash": "5c74f47a2b84574133c520d235192bf33e16fea1dbb0c32cf89a376a874927f4" +} diff --git a/litellm-rust/crates/db/.sqlx/query-9c51401a8907f818e96da28050b74dca981ff954452b35ffbace3e022035b416.json b/litellm-rust/crates/db/.sqlx/query-9c51401a8907f818e96da28050b74dca981ff954452b35ffbace3e022035b416.json new file mode 100644 index 00000000000..9886a9505d8 --- /dev/null +++ b/litellm-rust/crates/db/.sqlx/query-9c51401a8907f818e96da28050b74dca981ff954452b35ffbace3e022035b416.json @@ -0,0 +1,31 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO \"LiteLLM_DailyTeamSpend\" (\n id, team_id, date, api_key, model, custom_llm_provider,\n mcp_namespaced_tool_name, endpoint, model_group, prompt_tokens,\n completion_tokens, api_requests, successful_requests, failed_requests,\n cache_read_input_tokens, cache_creation_input_tokens, total_response_time_ms,\n timed_requests, spend, updated_at\n)\nSELECT gen_random_uuid()::text, r.entity_id, r.date, r.api_key, r.model,\n r.custom_llm_provider, r.mcp_namespaced_tool_name, r.endpoint, r.model_group, r.prompt_tokens,\n r.completion_tokens, r.api_requests, r.successful_requests,\n r.failed_requests, r.cache_read, r.cache_creation, r.response_time,\n r.timed_requests, r.spend, (NOW() AT TIME ZONE 'UTC')\nFROM UNNEST(\n $1::text[], $2::text[], $3::text[], $4::text[], $5::text[],\n $6::text[], $7::text[], $8::int8[], $9::int8[], $10::int8[],\n $11::int8[], $12::int8[], $13::int8[], $14::int8[], $15::int8[],\n $16::int8[], $17::float8[], $18::text[]\n) AS r(\n entity_id, date, api_key, model, custom_llm_provider, endpoint,\n model_group, prompt_tokens, completion_tokens, api_requests,\n successful_requests, failed_requests, cache_read, cache_creation,\n response_time, timed_requests, spend, mcp_namespaced_tool_name\n)\nORDER BY r.date, r.entity_id, r.api_key, r.model, r.custom_llm_provider,\n r.mcp_namespaced_tool_name, r.endpoint\nON CONFLICT (\n team_id, date, api_key, model, custom_llm_provider,\n mcp_namespaced_tool_name, endpoint\n) DO UPDATE SET\n prompt_tokens = \"LiteLLM_DailyTeamSpend\".prompt_tokens + EXCLUDED.prompt_tokens,\n completion_tokens = \"LiteLLM_DailyTeamSpend\".completion_tokens + EXCLUDED.completion_tokens,\n api_requests = \"LiteLLM_DailyTeamSpend\".api_requests + EXCLUDED.api_requests,\n successful_requests = \"LiteLLM_DailyTeamSpend\".successful_requests + EXCLUDED.successful_requests,\n failed_requests = \"LiteLLM_DailyTeamSpend\".failed_requests + EXCLUDED.failed_requests,\n cache_read_input_tokens = \"LiteLLM_DailyTeamSpend\".cache_read_input_tokens + EXCLUDED.cache_read_input_tokens,\n cache_creation_input_tokens = \"LiteLLM_DailyTeamSpend\".cache_creation_input_tokens + EXCLUDED.cache_creation_input_tokens,\n total_response_time_ms = \"LiteLLM_DailyTeamSpend\".total_response_time_ms + EXCLUDED.total_response_time_ms,\n timed_requests = \"LiteLLM_DailyTeamSpend\".timed_requests + EXCLUDED.timed_requests,\n spend = \"LiteLLM_DailyTeamSpend\".spend + EXCLUDED.spend,\n updated_at = (NOW() AT TIME ZONE 'UTC')\n", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "Int8Array", + "Int8Array", + "Int8Array", + "Int8Array", + "Int8Array", + "Int8Array", + "Int8Array", + "Int8Array", + "Int8Array", + "Float8Array", + "TextArray" + ] + }, + "nullable": [] + }, + "hash": "9c51401a8907f818e96da28050b74dca981ff954452b35ffbace3e022035b416" +} diff --git a/litellm-rust/crates/db/.sqlx/query-b0eb48b795bdaf728c79e986d2027df60ff71d8fed05b53be4458b335af88147.json b/litellm-rust/crates/db/.sqlx/query-b0eb48b795bdaf728c79e986d2027df60ff71d8fed05b53be4458b335af88147.json new file mode 100644 index 00000000000..b333ec814a1 --- /dev/null +++ b/litellm-rust/crates/db/.sqlx/query-b0eb48b795bdaf728c79e986d2027df60ff71d8fed05b53be4458b335af88147.json @@ -0,0 +1,14 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO \"LiteLLM_TeamMembership\" (user_id, team_id, spend, total_spend)\nSELECT member.user_id, member.team_id, member.cost, member.cost\nFROM jsonb_to_recordset($1::jsonb) AS member(user_id text, team_id text, cost float8)\nWHERE EXISTS (\n SELECT 1 FROM \"LiteLLM_TeamTable\" t\n WHERE t.team_id = member.team_id\n AND t.members_with_roles @> jsonb_build_array(jsonb_build_object('user_id', member.user_id))\n)\n OR EXISTS (\n SELECT 1 FROM \"LiteLLM_TeamMembership\" m\n WHERE m.user_id = member.user_id AND m.team_id = member.team_id\n)\nON CONFLICT (user_id, team_id) DO UPDATE\nSET spend = \"LiteLLM_TeamMembership\".spend + EXCLUDED.spend,\n total_spend = \"LiteLLM_TeamMembership\".total_spend + EXCLUDED.total_spend\n", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Jsonb" + ] + }, + "nullable": [] + }, + "hash": "b0eb48b795bdaf728c79e986d2027df60ff71d8fed05b53be4458b335af88147" +} diff --git a/litellm-rust/crates/db/.sqlx/query-bec3b53762af021a118d63b841b8c2ebd7fc9fcbf19c1c25aa131a1053d96cfe.json b/litellm-rust/crates/db/.sqlx/query-bec3b53762af021a118d63b841b8c2ebd7fc9fcbf19c1c25aa131a1053d96cfe.json new file mode 100644 index 00000000000..6c56868e48e --- /dev/null +++ b/litellm-rust/crates/db/.sqlx/query-bec3b53762af021a118d63b841b8c2ebd7fc9fcbf19c1c25aa131a1053d96cfe.json @@ -0,0 +1,31 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO \"LiteLLM_DailyUserSpend\" (\n id, user_id, date, api_key, model, custom_llm_provider,\n mcp_namespaced_tool_name, endpoint, model_group, prompt_tokens,\n completion_tokens, api_requests, successful_requests, failed_requests,\n cache_read_input_tokens, cache_creation_input_tokens, total_response_time_ms,\n timed_requests, spend, updated_at\n)\nSELECT gen_random_uuid()::text, r.entity_id, r.date, r.api_key, r.model,\n r.custom_llm_provider, r.mcp_namespaced_tool_name, r.endpoint, r.model_group, r.prompt_tokens,\n r.completion_tokens, r.api_requests, r.successful_requests,\n r.failed_requests, r.cache_read, r.cache_creation, r.response_time,\n r.timed_requests, r.spend, (NOW() AT TIME ZONE 'UTC')\nFROM UNNEST(\n $1::text[], $2::text[], $3::text[], $4::text[], $5::text[],\n $6::text[], $7::text[], $8::int8[], $9::int8[], $10::int8[],\n $11::int8[], $12::int8[], $13::int8[], $14::int8[], $15::int8[],\n $16::int8[], $17::float8[], $18::text[]\n) AS r(\n entity_id, date, api_key, model, custom_llm_provider, endpoint,\n model_group, prompt_tokens, completion_tokens, api_requests,\n successful_requests, failed_requests, cache_read, cache_creation,\n response_time, timed_requests, spend, mcp_namespaced_tool_name\n)\nORDER BY r.date, r.entity_id, r.api_key, r.model, r.custom_llm_provider,\n r.mcp_namespaced_tool_name, r.endpoint\nON CONFLICT (\n user_id, date, api_key, model, custom_llm_provider,\n mcp_namespaced_tool_name, endpoint\n) DO UPDATE SET\n prompt_tokens = \"LiteLLM_DailyUserSpend\".prompt_tokens + EXCLUDED.prompt_tokens,\n completion_tokens = \"LiteLLM_DailyUserSpend\".completion_tokens + EXCLUDED.completion_tokens,\n api_requests = \"LiteLLM_DailyUserSpend\".api_requests + EXCLUDED.api_requests,\n successful_requests = \"LiteLLM_DailyUserSpend\".successful_requests + EXCLUDED.successful_requests,\n failed_requests = \"LiteLLM_DailyUserSpend\".failed_requests + EXCLUDED.failed_requests,\n cache_read_input_tokens = \"LiteLLM_DailyUserSpend\".cache_read_input_tokens + EXCLUDED.cache_read_input_tokens,\n cache_creation_input_tokens = \"LiteLLM_DailyUserSpend\".cache_creation_input_tokens + EXCLUDED.cache_creation_input_tokens,\n total_response_time_ms = \"LiteLLM_DailyUserSpend\".total_response_time_ms + EXCLUDED.total_response_time_ms,\n timed_requests = \"LiteLLM_DailyUserSpend\".timed_requests + EXCLUDED.timed_requests,\n spend = \"LiteLLM_DailyUserSpend\".spend + EXCLUDED.spend,\n updated_at = (NOW() AT TIME ZONE 'UTC')\n", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "Int8Array", + "Int8Array", + "Int8Array", + "Int8Array", + "Int8Array", + "Int8Array", + "Int8Array", + "Int8Array", + "Int8Array", + "Float8Array", + "TextArray" + ] + }, + "nullable": [] + }, + "hash": "bec3b53762af021a118d63b841b8c2ebd7fc9fcbf19c1c25aa131a1053d96cfe" +} diff --git a/litellm-rust/crates/db/.sqlx/query-c3e5542906e89995fae2a16eca1edd37a575d641bb68d91e61f5123173c275ce.json b/litellm-rust/crates/db/.sqlx/query-c3e5542906e89995fae2a16eca1edd37a575d641bb68d91e61f5123173c275ce.json new file mode 100644 index 00000000000..250971b053a --- /dev/null +++ b/litellm-rust/crates/db/.sqlx/query-c3e5542906e89995fae2a16eca1edd37a575d641bb68d91e61f5123173c275ce.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "WITH added AS (\n SELECT id, SUM(cost) AS cost\n FROM UNNEST($1::text[], $2::float8[]) AS a(id, cost)\n GROUP BY id\n),\nlocked AS (\n SELECT t.team_id FROM \"LiteLLM_TeamTable\" t\n WHERE t.team_id IN (SELECT id FROM added)\n ORDER BY t.team_id FOR UPDATE\n)\nUPDATE \"LiteLLM_TeamTable\" t\nSET spend = t.spend + added.cost,\n updated_at = (NOW() AT TIME ZONE 'UTC')\nFROM added\nWHERE t.team_id = added.id AND t.team_id IN (SELECT team_id FROM locked)\n", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "TextArray", + "Float8Array" + ] + }, + "nullable": [] + }, + "hash": "c3e5542906e89995fae2a16eca1edd37a575d641bb68d91e61f5123173c275ce" +} diff --git a/litellm-rust/crates/db/.sqlx/query-f207ff0f5310dea0833361d55993bcab69ff6ad3555a3926537586f5d81d933d.json b/litellm-rust/crates/db/.sqlx/query-f207ff0f5310dea0833361d55993bcab69ff6ad3555a3926537586f5d81d933d.json new file mode 100644 index 00000000000..b2635c549ac --- /dev/null +++ b/litellm-rust/crates/db/.sqlx/query-f207ff0f5310dea0833361d55993bcab69ff6ad3555a3926537586f5d81d933d.json @@ -0,0 +1,31 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO \"LiteLLM_DailyEndUserSpend\" (\n id, end_user_id, date, api_key, model, custom_llm_provider,\n mcp_namespaced_tool_name, endpoint, model_group, prompt_tokens,\n completion_tokens, api_requests, successful_requests, failed_requests,\n cache_read_input_tokens, cache_creation_input_tokens, total_response_time_ms,\n timed_requests, spend, updated_at\n)\nSELECT gen_random_uuid()::text, r.entity_id, r.date, r.api_key, r.model,\n r.custom_llm_provider, r.mcp_namespaced_tool_name, r.endpoint, r.model_group, r.prompt_tokens,\n r.completion_tokens, r.api_requests, r.successful_requests,\n r.failed_requests, r.cache_read, r.cache_creation, r.response_time,\n r.timed_requests, r.spend, (NOW() AT TIME ZONE 'UTC')\nFROM UNNEST(\n $1::text[], $2::text[], $3::text[], $4::text[], $5::text[],\n $6::text[], $7::text[], $8::int8[], $9::int8[], $10::int8[],\n $11::int8[], $12::int8[], $13::int8[], $14::int8[], $15::int8[],\n $16::int8[], $17::float8[], $18::text[]\n) AS r(\n entity_id, date, api_key, model, custom_llm_provider, endpoint,\n model_group, prompt_tokens, completion_tokens, api_requests,\n successful_requests, failed_requests, cache_read, cache_creation,\n response_time, timed_requests, spend, mcp_namespaced_tool_name\n)\nORDER BY r.date, r.entity_id, r.api_key, r.model, r.custom_llm_provider,\n r.mcp_namespaced_tool_name, r.endpoint\nON CONFLICT (\n end_user_id, date, api_key, model, custom_llm_provider,\n mcp_namespaced_tool_name, endpoint\n) DO UPDATE SET\n prompt_tokens = \"LiteLLM_DailyEndUserSpend\".prompt_tokens + EXCLUDED.prompt_tokens,\n completion_tokens = \"LiteLLM_DailyEndUserSpend\".completion_tokens + EXCLUDED.completion_tokens,\n api_requests = \"LiteLLM_DailyEndUserSpend\".api_requests + EXCLUDED.api_requests,\n successful_requests = \"LiteLLM_DailyEndUserSpend\".successful_requests + EXCLUDED.successful_requests,\n failed_requests = \"LiteLLM_DailyEndUserSpend\".failed_requests + EXCLUDED.failed_requests,\n cache_read_input_tokens = \"LiteLLM_DailyEndUserSpend\".cache_read_input_tokens + EXCLUDED.cache_read_input_tokens,\n cache_creation_input_tokens = \"LiteLLM_DailyEndUserSpend\".cache_creation_input_tokens + EXCLUDED.cache_creation_input_tokens,\n total_response_time_ms = \"LiteLLM_DailyEndUserSpend\".total_response_time_ms + EXCLUDED.total_response_time_ms,\n timed_requests = \"LiteLLM_DailyEndUserSpend\".timed_requests + EXCLUDED.timed_requests,\n spend = \"LiteLLM_DailyEndUserSpend\".spend + EXCLUDED.spend,\n updated_at = (NOW() AT TIME ZONE 'UTC')\n", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "TextArray", + "Int8Array", + "Int8Array", + "Int8Array", + "Int8Array", + "Int8Array", + "Int8Array", + "Int8Array", + "Int8Array", + "Int8Array", + "Float8Array", + "TextArray" + ] + }, + "nullable": [] + }, + "hash": "f207ff0f5310dea0833361d55993bcab69ff6ad3555a3926537586f5d81d933d" +} diff --git a/litellm-rust/crates/db/AGENTS.md b/litellm-rust/crates/db/AGENTS.md new file mode 100644 index 00000000000..1e08317230e --- /dev/null +++ b/litellm-rust/crates/db/AGENTS.md @@ -0,0 +1,25 @@ +# Database crate + +Keep each static query in `queries/` and call it through a typed SQLx query function. Rust does not create or migrate the database + +- Own reusable row projections in `src/` and export those consumed by other crates or integration tests +- Apply `#[macro_rules_attribute::apply(crate::db_row)]` to row types for shared derives, without adding serialization or schema derives automatically +- Apply `#[macro_rules_attribute::apply(crate::db_input)]` to write inputs, adding `Default` only where supported +- Keep function tests inline in their owning query module and reuse the strict database fixture in `test_support` +- Transaction-local setup in `begin` is the approved exception to static query files +- Keep write inputs separate from stored rows and keep test-only assertions out of public types +- `FromRow` supports runtime reads, but production static reads still use `query_file_as!` for compile-time checking + +Database integration tests are ignored by default, but still compile in workspace checks. Run them explicitly against a local database already migrated by Prisma. Missing or invalid database configuration must fail the selected tests: + +```sh +DATABASE_URL=postgresql://... cargo test -p litellm-db --locked -- --include-ignored +``` + +After changing a query, refresh the checked query metadata from this directory: + +```sh +SQLX_OFFLINE=false cargo sqlx prepare +``` + +Tests use transactions and leave them uncommitted so fixture rows roll back when each test finishes diff --git a/litellm-rust/crates/db/Cargo.toml b/litellm-rust/crates/db/Cargo.toml index ca9d6f555b0..4f8fe4e28e2 100644 --- a/litellm-rust/crates/db/Cargo.toml +++ b/litellm-rust/crates/db/Cargo.toml @@ -6,5 +6,14 @@ license.workspace = true repository.workspace = true [dependencies] +chrono.workspace = true +macro_rules_attribute.workspace = true serde.workspace = true +serde_json.workspace = true sqlx.workspace = true +strum.workspace = true +thiserror.workspace = true + +[dev-dependencies] +rstest.workspace = true +tokio.workspace = true diff --git a/litellm-rust/crates/db/queries/end_user/find_end_user.sql b/litellm-rust/crates/db/queries/end_user/find_end_user.sql new file mode 100644 index 00000000000..c10ef8b877d --- /dev/null +++ b/litellm-rust/crates/db/queries/end_user/find_end_user.sql @@ -0,0 +1,10 @@ +SELECT e.spend AS "spend?", + e.blocked AS "blocked?", + b.max_budget AS "max_budget?", + b.rpm_limit AS "rpm_limit?", + b.tpm_limit AS "tpm_limit?" +FROM (SELECT 1) AS one +LEFT JOIN "LiteLLM_EndUserTable" AS e ON e.user_id = $1 +LEFT JOIN "LiteLLM_BudgetTable" AS assigned ON assigned.budget_id = e.budget_id +LEFT JOIN "LiteLLM_BudgetTable" AS key_budget ON key_budget.budget_id = $3 +LEFT JOIN "LiteLLM_BudgetTable" AS b ON b.budget_id = COALESCE(assigned.budget_id, key_budget.budget_id, $2) diff --git a/litellm-rust/crates/db/queries/spend/add_end_user_spend.sql b/litellm-rust/crates/db/queries/spend/add_end_user_spend.sql new file mode 100644 index 00000000000..06a5b96d254 --- /dev/null +++ b/litellm-rust/crates/db/queries/spend/add_end_user_spend.sql @@ -0,0 +1,6 @@ +INSERT INTO "LiteLLM_EndUserTable" (user_id, spend, blocked) +SELECT id, SUM(cost), false FROM UNNEST($1::text[], $2::float8[]) AS a(id, cost) +GROUP BY id +ORDER BY id +ON CONFLICT (user_id) DO UPDATE +SET spend = "LiteLLM_EndUserTable".spend + EXCLUDED.spend diff --git a/litellm-rust/crates/db/queries/spend/add_key_spend.sql b/litellm-rust/crates/db/queries/spend/add_key_spend.sql new file mode 100644 index 00000000000..61850714acd --- /dev/null +++ b/litellm-rust/crates/db/queries/spend/add_key_spend.sql @@ -0,0 +1,16 @@ +WITH added AS ( + SELECT id, SUM(cost) AS cost + FROM UNNEST($1::text[], $2::float8[]) AS a(id, cost) + GROUP BY id +), locked AS ( + SELECT t.token FROM "LiteLLM_VerificationToken" t + WHERE t.token IN (SELECT id FROM added) + ORDER BY t.token FOR UPDATE +) +UPDATE "LiteLLM_VerificationToken" t +SET spend = t.spend + added.cost, + total_spend = t.total_spend + added.cost, + last_active = (clock_timestamp() AT TIME ZONE 'UTC'), + updated_at = (clock_timestamp() AT TIME ZONE 'UTC') +FROM added +WHERE t.token = added.id AND t.token IN (SELECT token FROM locked) diff --git a/litellm-rust/crates/db/queries/spend/add_team_spend.sql b/litellm-rust/crates/db/queries/spend/add_team_spend.sql new file mode 100644 index 00000000000..58b8e3d6ab9 --- /dev/null +++ b/litellm-rust/crates/db/queries/spend/add_team_spend.sql @@ -0,0 +1,15 @@ +WITH added AS ( + SELECT id, SUM(cost) AS cost + FROM UNNEST($1::text[], $2::float8[]) AS a(id, cost) + GROUP BY id +), +locked AS ( + SELECT t.team_id FROM "LiteLLM_TeamTable" t + WHERE t.team_id IN (SELECT id FROM added) + ORDER BY t.team_id FOR UPDATE +) +UPDATE "LiteLLM_TeamTable" t +SET spend = t.spend + added.cost, + updated_at = (NOW() AT TIME ZONE 'UTC') +FROM added +WHERE t.team_id = added.id AND t.team_id IN (SELECT team_id FROM locked) diff --git a/litellm-rust/crates/db/queries/spend/add_user_spend.sql b/litellm-rust/crates/db/queries/spend/add_user_spend.sql new file mode 100644 index 00000000000..27fc12e82f0 --- /dev/null +++ b/litellm-rust/crates/db/queries/spend/add_user_spend.sql @@ -0,0 +1,14 @@ +WITH added AS ( + SELECT id, SUM(cost) AS cost + FROM UNNEST($1::text[], $2::float8[]) AS a(id, cost) + GROUP BY id +), locked AS ( + SELECT u.user_id FROM "LiteLLM_UserTable" u + WHERE u.user_id IN (SELECT id FROM added) + ORDER BY u.user_id FOR UPDATE +) +UPDATE "LiteLLM_UserTable" u +SET spend = u.spend + added.cost, + updated_at = (NOW() AT TIME ZONE 'UTC') +FROM added +WHERE u.user_id = added.id AND u.user_id IN (SELECT user_id FROM locked) diff --git a/litellm-rust/crates/db/queries/spend/insert_spend_logs.sql b/litellm-rust/crates/db/queries/spend/insert_spend_logs.sql new file mode 100644 index 00000000000..fcffee181a1 --- /dev/null +++ b/litellm-rust/crates/db/queries/spend/insert_spend_logs.sql @@ -0,0 +1,26 @@ +INSERT INTO "LiteLLM_SpendLogs" ( + request_id, call_type, api_key, spend, total_tokens, prompt_tokens, + completion_tokens, "startTime", "endTime", "completionStartTime", + request_duration_ms, model, model_id, model_group, custom_llm_provider, api_base, + "user", metadata, cache_hit, cache_key, request_tags, team_id, organization_id, + end_user, requester_ip_address, messages, response, proxy_server_request, + session_id, status, litellm_call_id +) +SELECT l.request_id, l.call_type, l.api_key, l.spend, l.total_tokens, l.prompt_tokens, + l.completion_tokens, l.start_time::timestamp(3), l.end_time::timestamp(3), + l.completion_start_time::timestamp(3), l.request_duration_ms, l.model, + l.model_id, l.model_group, l.custom_llm_provider, l.api_base, l.user_id, + l.metadata, l.cache_hit, l.cache_key, '[]'::jsonb, l.team_id, + l.organization_id, l.end_user, l.requester_ip_address, '{}'::jsonb, + '{}'::jsonb, '{}'::jsonb, l.session_id, l.status, l.litellm_call_id +FROM UNNEST($1::text[], $2::text[], $3::text[], $4::float8[], $5::int4[], $6::int4[], + $7::int4[], $8::timestamp[], $9::timestamp[], $10::timestamp[], $11::int4[], $12::text[], + $13::text[], $14::text[], $15::text[], $16::text[], $17::text[], + $18::jsonb[], $19::text[], $20::text[], $21::text[], $22::text[], + $23::text[], $24::text[], $25::text[], $26::text[], $27::text[]) + AS l(request_id, call_type, api_key, spend, total_tokens, prompt_tokens, + completion_tokens, start_time, end_time, completion_start_time, + request_duration_ms, model, model_id, model_group, custom_llm_provider, + api_base, user_id, metadata, cache_hit, cache_key, team_id, organization_id, + end_user, requester_ip_address, session_id, status, litellm_call_id) +ON CONFLICT DO NOTHING diff --git a/litellm-rust/crates/db/queries/spend/lock_team.sql b/litellm-rust/crates/db/queries/spend/lock_team.sql new file mode 100644 index 00000000000..06cdb806ef0 --- /dev/null +++ b/litellm-rust/crates/db/queries/spend/lock_team.sql @@ -0,0 +1 @@ +SELECT pg_advisory_xact_lock(hashtext($1)) IS NULL AS "locked!" diff --git a/litellm-rust/crates/db/queries/spend/upsert_daily_end_user_spend.sql b/litellm-rust/crates/db/queries/spend/upsert_daily_end_user_spend.sql new file mode 100644 index 00000000000..8c4936e1a7a --- /dev/null +++ b/litellm-rust/crates/db/queries/spend/upsert_daily_end_user_spend.sql @@ -0,0 +1,40 @@ +INSERT INTO "LiteLLM_DailyEndUserSpend" ( + id, end_user_id, date, api_key, model, custom_llm_provider, + mcp_namespaced_tool_name, endpoint, model_group, prompt_tokens, + completion_tokens, api_requests, successful_requests, failed_requests, + cache_read_input_tokens, cache_creation_input_tokens, total_response_time_ms, + timed_requests, spend, updated_at +) +SELECT gen_random_uuid()::text, r.entity_id, r.date, r.api_key, r.model, + r.custom_llm_provider, r.mcp_namespaced_tool_name, r.endpoint, r.model_group, r.prompt_tokens, + r.completion_tokens, r.api_requests, r.successful_requests, + r.failed_requests, r.cache_read, r.cache_creation, r.response_time, + r.timed_requests, r.spend, (NOW() AT TIME ZONE 'UTC') +FROM UNNEST( + $1::text[], $2::text[], $3::text[], $4::text[], $5::text[], + $6::text[], $7::text[], $8::int8[], $9::int8[], $10::int8[], + $11::int8[], $12::int8[], $13::int8[], $14::int8[], $15::int8[], + $16::int8[], $17::float8[], $18::text[] +) AS r( + entity_id, date, api_key, model, custom_llm_provider, endpoint, + model_group, prompt_tokens, completion_tokens, api_requests, + successful_requests, failed_requests, cache_read, cache_creation, + response_time, timed_requests, spend, mcp_namespaced_tool_name +) +ORDER BY r.date, r.entity_id, r.api_key, r.model, r.custom_llm_provider, + r.mcp_namespaced_tool_name, r.endpoint +ON CONFLICT ( + end_user_id, date, api_key, model, custom_llm_provider, + mcp_namespaced_tool_name, endpoint +) DO UPDATE SET + prompt_tokens = "LiteLLM_DailyEndUserSpend".prompt_tokens + EXCLUDED.prompt_tokens, + completion_tokens = "LiteLLM_DailyEndUserSpend".completion_tokens + EXCLUDED.completion_tokens, + api_requests = "LiteLLM_DailyEndUserSpend".api_requests + EXCLUDED.api_requests, + successful_requests = "LiteLLM_DailyEndUserSpend".successful_requests + EXCLUDED.successful_requests, + failed_requests = "LiteLLM_DailyEndUserSpend".failed_requests + EXCLUDED.failed_requests, + cache_read_input_tokens = "LiteLLM_DailyEndUserSpend".cache_read_input_tokens + EXCLUDED.cache_read_input_tokens, + cache_creation_input_tokens = "LiteLLM_DailyEndUserSpend".cache_creation_input_tokens + EXCLUDED.cache_creation_input_tokens, + total_response_time_ms = "LiteLLM_DailyEndUserSpend".total_response_time_ms + EXCLUDED.total_response_time_ms, + timed_requests = "LiteLLM_DailyEndUserSpend".timed_requests + EXCLUDED.timed_requests, + spend = "LiteLLM_DailyEndUserSpend".spend + EXCLUDED.spend, + updated_at = (NOW() AT TIME ZONE 'UTC') diff --git a/litellm-rust/crates/db/queries/spend/upsert_daily_team_spend.sql b/litellm-rust/crates/db/queries/spend/upsert_daily_team_spend.sql new file mode 100644 index 00000000000..a9bdef34043 --- /dev/null +++ b/litellm-rust/crates/db/queries/spend/upsert_daily_team_spend.sql @@ -0,0 +1,40 @@ +INSERT INTO "LiteLLM_DailyTeamSpend" ( + id, team_id, date, api_key, model, custom_llm_provider, + mcp_namespaced_tool_name, endpoint, model_group, prompt_tokens, + completion_tokens, api_requests, successful_requests, failed_requests, + cache_read_input_tokens, cache_creation_input_tokens, total_response_time_ms, + timed_requests, spend, updated_at +) +SELECT gen_random_uuid()::text, r.entity_id, r.date, r.api_key, r.model, + r.custom_llm_provider, r.mcp_namespaced_tool_name, r.endpoint, r.model_group, r.prompt_tokens, + r.completion_tokens, r.api_requests, r.successful_requests, + r.failed_requests, r.cache_read, r.cache_creation, r.response_time, + r.timed_requests, r.spend, (NOW() AT TIME ZONE 'UTC') +FROM UNNEST( + $1::text[], $2::text[], $3::text[], $4::text[], $5::text[], + $6::text[], $7::text[], $8::int8[], $9::int8[], $10::int8[], + $11::int8[], $12::int8[], $13::int8[], $14::int8[], $15::int8[], + $16::int8[], $17::float8[], $18::text[] +) AS r( + entity_id, date, api_key, model, custom_llm_provider, endpoint, + model_group, prompt_tokens, completion_tokens, api_requests, + successful_requests, failed_requests, cache_read, cache_creation, + response_time, timed_requests, spend, mcp_namespaced_tool_name +) +ORDER BY r.date, r.entity_id, r.api_key, r.model, r.custom_llm_provider, + r.mcp_namespaced_tool_name, r.endpoint +ON CONFLICT ( + team_id, date, api_key, model, custom_llm_provider, + mcp_namespaced_tool_name, endpoint +) DO UPDATE SET + prompt_tokens = "LiteLLM_DailyTeamSpend".prompt_tokens + EXCLUDED.prompt_tokens, + completion_tokens = "LiteLLM_DailyTeamSpend".completion_tokens + EXCLUDED.completion_tokens, + api_requests = "LiteLLM_DailyTeamSpend".api_requests + EXCLUDED.api_requests, + successful_requests = "LiteLLM_DailyTeamSpend".successful_requests + EXCLUDED.successful_requests, + failed_requests = "LiteLLM_DailyTeamSpend".failed_requests + EXCLUDED.failed_requests, + cache_read_input_tokens = "LiteLLM_DailyTeamSpend".cache_read_input_tokens + EXCLUDED.cache_read_input_tokens, + cache_creation_input_tokens = "LiteLLM_DailyTeamSpend".cache_creation_input_tokens + EXCLUDED.cache_creation_input_tokens, + total_response_time_ms = "LiteLLM_DailyTeamSpend".total_response_time_ms + EXCLUDED.total_response_time_ms, + timed_requests = "LiteLLM_DailyTeamSpend".timed_requests + EXCLUDED.timed_requests, + spend = "LiteLLM_DailyTeamSpend".spend + EXCLUDED.spend, + updated_at = (NOW() AT TIME ZONE 'UTC') diff --git a/litellm-rust/crates/db/queries/spend/upsert_daily_user_spend.sql b/litellm-rust/crates/db/queries/spend/upsert_daily_user_spend.sql new file mode 100644 index 00000000000..4a5db90dee2 --- /dev/null +++ b/litellm-rust/crates/db/queries/spend/upsert_daily_user_spend.sql @@ -0,0 +1,40 @@ +INSERT INTO "LiteLLM_DailyUserSpend" ( + id, user_id, date, api_key, model, custom_llm_provider, + mcp_namespaced_tool_name, endpoint, model_group, prompt_tokens, + completion_tokens, api_requests, successful_requests, failed_requests, + cache_read_input_tokens, cache_creation_input_tokens, total_response_time_ms, + timed_requests, spend, updated_at +) +SELECT gen_random_uuid()::text, r.entity_id, r.date, r.api_key, r.model, + r.custom_llm_provider, r.mcp_namespaced_tool_name, r.endpoint, r.model_group, r.prompt_tokens, + r.completion_tokens, r.api_requests, r.successful_requests, + r.failed_requests, r.cache_read, r.cache_creation, r.response_time, + r.timed_requests, r.spend, (NOW() AT TIME ZONE 'UTC') +FROM UNNEST( + $1::text[], $2::text[], $3::text[], $4::text[], $5::text[], + $6::text[], $7::text[], $8::int8[], $9::int8[], $10::int8[], + $11::int8[], $12::int8[], $13::int8[], $14::int8[], $15::int8[], + $16::int8[], $17::float8[], $18::text[] +) AS r( + entity_id, date, api_key, model, custom_llm_provider, endpoint, + model_group, prompt_tokens, completion_tokens, api_requests, + successful_requests, failed_requests, cache_read, cache_creation, + response_time, timed_requests, spend, mcp_namespaced_tool_name +) +ORDER BY r.date, r.entity_id, r.api_key, r.model, r.custom_llm_provider, + r.mcp_namespaced_tool_name, r.endpoint +ON CONFLICT ( + user_id, date, api_key, model, custom_llm_provider, + mcp_namespaced_tool_name, endpoint +) DO UPDATE SET + prompt_tokens = "LiteLLM_DailyUserSpend".prompt_tokens + EXCLUDED.prompt_tokens, + completion_tokens = "LiteLLM_DailyUserSpend".completion_tokens + EXCLUDED.completion_tokens, + api_requests = "LiteLLM_DailyUserSpend".api_requests + EXCLUDED.api_requests, + successful_requests = "LiteLLM_DailyUserSpend".successful_requests + EXCLUDED.successful_requests, + failed_requests = "LiteLLM_DailyUserSpend".failed_requests + EXCLUDED.failed_requests, + cache_read_input_tokens = "LiteLLM_DailyUserSpend".cache_read_input_tokens + EXCLUDED.cache_read_input_tokens, + cache_creation_input_tokens = "LiteLLM_DailyUserSpend".cache_creation_input_tokens + EXCLUDED.cache_creation_input_tokens, + total_response_time_ms = "LiteLLM_DailyUserSpend".total_response_time_ms + EXCLUDED.total_response_time_ms, + timed_requests = "LiteLLM_DailyUserSpend".timed_requests + EXCLUDED.timed_requests, + spend = "LiteLLM_DailyUserSpend".spend + EXCLUDED.spend, + updated_at = (NOW() AT TIME ZONE 'UTC') diff --git a/litellm-rust/crates/db/queries/spend/upsert_team_member_spend.sql b/litellm-rust/crates/db/queries/spend/upsert_team_member_spend.sql new file mode 100644 index 00000000000..460c631cbbd --- /dev/null +++ b/litellm-rust/crates/db/queries/spend/upsert_team_member_spend.sql @@ -0,0 +1,15 @@ +INSERT INTO "LiteLLM_TeamMembership" (user_id, team_id, spend, total_spend) +SELECT member.user_id, member.team_id, member.cost, member.cost +FROM jsonb_to_recordset($1::jsonb) AS member(user_id text, team_id text, cost float8) +WHERE EXISTS ( + SELECT 1 FROM "LiteLLM_TeamTable" t + WHERE t.team_id = member.team_id + AND t.members_with_roles @> jsonb_build_array(jsonb_build_object('user_id', member.user_id)) +) + OR EXISTS ( + SELECT 1 FROM "LiteLLM_TeamMembership" m + WHERE m.user_id = member.user_id AND m.team_id = member.team_id +) +ON CONFLICT (user_id, team_id) DO UPDATE +SET spend = "LiteLLM_TeamMembership".spend + EXCLUDED.spend, + total_spend = "LiteLLM_TeamMembership".total_spend + EXCLUDED.total_spend diff --git a/litellm-rust/crates/db/src/daily_spend.rs b/litellm-rust/crates/db/src/daily_spend.rs new file mode 100644 index 00000000000..9db07514aab --- /dev/null +++ b/litellm-rust/crates/db/src/daily_spend.rs @@ -0,0 +1,76 @@ +use sqlx::types::chrono::NaiveDateTime; + +#[macro_rules_attribute::apply(crate::db_row)] +pub struct DailyUserRow { + pub id: String, + pub user_id: Option, + pub api_key: String, + pub model: Option, + pub custom_llm_provider: Option, + pub endpoint: Option, + pub model_group: Option, + pub mcp_namespaced_tool_name: Option, + pub prompt_tokens: i64, + pub completion_tokens: i64, + pub api_requests: i64, + pub successful_requests: i64, + pub failed_requests: i64, + pub cache_read_input_tokens: i64, + pub cache_creation_input_tokens: i64, + pub total_response_time_ms: i64, + pub timed_requests: i64, + pub spend: f64, + pub date: String, + pub created_at: NaiveDateTime, + pub updated_at: NaiveDateTime, +} + +#[macro_rules_attribute::apply(crate::db_row)] +pub struct DailyTeamRow { + pub id: String, + pub team_id: Option, + pub api_key: String, + pub model: Option, + pub custom_llm_provider: Option, + pub endpoint: Option, + pub model_group: Option, + pub mcp_namespaced_tool_name: Option, + pub prompt_tokens: i64, + pub completion_tokens: i64, + pub api_requests: i64, + pub successful_requests: i64, + pub failed_requests: i64, + pub cache_read_input_tokens: i64, + pub cache_creation_input_tokens: i64, + pub total_response_time_ms: i64, + pub timed_requests: i64, + pub spend: f64, + pub date: String, + pub created_at: NaiveDateTime, + pub updated_at: NaiveDateTime, +} + +#[macro_rules_attribute::apply(crate::db_row)] +pub struct DailyEndUserRow { + pub id: String, + pub end_user_id: Option, + pub api_key: String, + pub model: Option, + pub custom_llm_provider: Option, + pub endpoint: Option, + pub model_group: Option, + pub mcp_namespaced_tool_name: Option, + pub prompt_tokens: i64, + pub completion_tokens: i64, + pub api_requests: i64, + pub successful_requests: i64, + pub failed_requests: i64, + pub cache_read_input_tokens: i64, + pub cache_creation_input_tokens: i64, + pub total_response_time_ms: i64, + pub timed_requests: i64, + pub spend: f64, + pub date: String, + pub created_at: NaiveDateTime, + pub updated_at: NaiveDateTime, +} diff --git a/litellm-rust/crates/db/src/end_user.rs b/litellm-rust/crates/db/src/end_user.rs new file mode 100644 index 00000000000..66661b51640 --- /dev/null +++ b/litellm-rust/crates/db/src/end_user.rs @@ -0,0 +1,359 @@ +use sqlx::PgExecutor; + +use crate::Error; + +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] +pub struct RateLimits { + pub rpm: Option, + pub tpm: Option, +} + +#[derive(Clone, Debug, Default, PartialEq)] +pub struct EndUser { + pub spend: Option, + pub blocked: bool, + pub max_budget: Option, + pub limits: RateLimits, +} + +#[macro_rules_attribute::apply(crate::db_row)] +struct EndUserRow { + spend: Option, + blocked: Option, + max_budget: Option, + rpm_limit: Option, + tpm_limit: Option, +} + +pub async fn find_end_user( + executor: impl PgExecutor<'_>, + end_user_id: &str, + default_budget_id: Option<&str>, + key_budget_id: Option<&str>, +) -> Result { + let row = sqlx::query_file_as!( + EndUserRow, + "queries/end_user/find_end_user.sql", + end_user_id, + default_budget_id, + key_budget_id, + ) + .fetch_one(executor) + .await?; + Ok(EndUser { + spend: row.spend, + blocked: row.blocked.unwrap_or(false), + max_budget: row.max_budget, + limits: RateLimits { + rpm: row.rpm_limit, + tpm: row.tpm_limit, + }, + }) +} + +#[cfg(test)] +mod tests { + use std::error::Error as StdError; + + use super::{EndUser, RateLimits, find_end_user}; + use crate::test_support::database_pool; + use rstest::rstest; + use sqlx::{PgPool, Postgres, Transaction}; + + #[derive(Clone, Copy)] + struct BudgetFixture { + budget_id: &'static str, + max_budget: f64, + rpm_limit: i64, + tpm_limit: i64, + } + + async fn insert_budget( + tx: &mut Transaction<'_, Postgres>, + budget: BudgetFixture, + ) -> Result<(), sqlx::Error> { + #[expect( + clippy::disallowed_methods, + reason = "Fixture inserts are outside the compile-checked query set" + )] + let result = sqlx::query( + r#" + INSERT INTO "LiteLLM_BudgetTable" + (budget_id, max_budget, rpm_limit, tpm_limit, created_by, updated_by) + VALUES ($1, $2, $3, $4, 'db-query-test', 'db-query-test') + "#, + ) + .bind(budget.budget_id) + .bind(budget.max_budget) + .bind(budget.rpm_limit) + .bind(budget.tpm_limit) + .execute(&mut **tx) + .await; + result.map(|_| ()) + } + + async fn insert_end_user( + tx: &mut Transaction<'_, Postgres>, + user_id: &str, + spend: f64, + blocked: bool, + budget_id: Option<&str>, + ) -> Result<(), sqlx::Error> { + #[expect( + clippy::disallowed_methods, + reason = "Fixture inserts are outside the compile-checked query set" + )] + let result = sqlx::query( + r#" + INSERT INTO "LiteLLM_EndUserTable" (user_id, spend, blocked, budget_id) + VALUES ($1, $2, $3, $4) + "#, + ) + .bind(user_id) + .bind(spend) + .bind(blocked) + .bind(budget_id) + .execute(&mut **tx) + .await; + result.map(|_| ()) + } + + #[rstest] + #[case::without_default_budget(None)] + #[case::with_default_budget(Some(BudgetFixture { + budget_id: "missing-user-default-budget", + max_budget: 11.5, + rpm_limit: 12, + tpm_limit: 1300, + }))] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn missing_end_user_maps_to_defaults( + #[case] default_budget: Option, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + if let Some(budget) = default_budget { + insert_budget(&mut tx, budget).await?; + } + + let actual = find_end_user( + &mut *tx, + "missing-end-user", + default_budget.map(|budget| budget.budget_id), + None, + ) + .await?; + + assert_eq!( + actual, + EndUser { + spend: None, + blocked: false, + max_budget: default_budget.map(|budget| budget.max_budget), + limits: RateLimits { + rpm: default_budget.map(|budget| budget.rpm_limit), + tpm: default_budget.map(|budget| budget.tpm_limit), + }, + } + ); + Ok(()) + } + + #[rstest] + #[case::row_budget_precedes_default( + "row-budget-priority-user", + Some(BudgetFixture { + budget_id: "row-budget-priority-row", + max_budget: 10.0, + rpm_limit: 101, + tpm_limit: 1001, + }), + BudgetFixture { + budget_id: "row-budget-priority-default", + max_budget: 20.0, + rpm_limit: 201, + tpm_limit: 2001, + }, + None, + Some(BudgetFixture { + budget_id: "row-budget-priority-row", + max_budget: 10.0, + rpm_limit: 101, + tpm_limit: 1001, + }), + false + )] + #[case::default_applies_without_row_budget( + "default-budget-user", + None, + BudgetFixture { + budget_id: "default-budget-fallback", + max_budget: 30.0, + rpm_limit: 301, + tpm_limit: 3001, + }, + None, + Some(BudgetFixture { + budget_id: "default-budget-fallback", + max_budget: 30.0, + rpm_limit: 301, + tpm_limit: 3001, + }), + false + )] + #[case::assigned_budget_precedes_key_when_all_ids_differ( + "override-priority-user", + Some(BudgetFixture { + budget_id: "override-priority-row", + max_budget: 40.0, + rpm_limit: 401, + tpm_limit: 4001, + }), + BudgetFixture { + budget_id: "override-priority-default", + max_budget: 50.0, + rpm_limit: 501, + tpm_limit: 5001, + }, + Some(BudgetFixture { + budget_id: "override-priority-override", + max_budget: 60.0, + rpm_limit: 601, + tpm_limit: 6001, + }), + Some(BudgetFixture { + budget_id: "override-priority-row", + max_budget: 40.0, + rpm_limit: 401, + tpm_limit: 4001, + }), + true + )] + #[case::missing_key_budget_keeps_assigned_budget( + "dangling-override-user", + Some(BudgetFixture { + budget_id: "dangling-override-row", + max_budget: 70.0, + rpm_limit: 701, + tpm_limit: 7001, + }), + BudgetFixture { + budget_id: "dangling-override-default", + max_budget: 80.0, + rpm_limit: 801, + tpm_limit: 8001, + }, + Some(BudgetFixture { + budget_id: "dangling-override-missing", + max_budget: 90.0, + rpm_limit: 901, + tpm_limit: 9001, + }), + Some(BudgetFixture { + budget_id: "dangling-override-row", + max_budget: 70.0, + rpm_limit: 701, + tpm_limit: 7001, + }), + false + )] + #[case::key_budget_precedes_proxy_default( + "key-default-user", + None, + BudgetFixture { + budget_id: "key-default-proxy", + max_budget: 80.0, + rpm_limit: 801, + tpm_limit: 8001, + }, + Some(BudgetFixture { + budget_id: "key-default-key", + max_budget: 90.0, + rpm_limit: 901, + tpm_limit: 9001, + }), + Some(BudgetFixture { + budget_id: "key-default-key", + max_budget: 90.0, + rpm_limit: 901, + tpm_limit: 9001, + }), + true + )] + #[case::missing_key_budget_falls_back_to_proxy_default( + "missing-key-default-user", + None, + BudgetFixture { + budget_id: "missing-key-default-proxy", + max_budget: 80.0, + rpm_limit: 801, + tpm_limit: 8001, + }, + Some(BudgetFixture { + budget_id: "missing-key-default-key", + max_budget: 90.0, + rpm_limit: 901, + tpm_limit: 9001, + }), + Some(BudgetFixture { + budget_id: "missing-key-default-proxy", + max_budget: 80.0, + rpm_limit: 801, + tpm_limit: 8001, + }), + false + )] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn budget_resolution_matches_python_precedence( + #[case] user_id: &'static str, + #[case] user_budget: Option, + #[case] default_budget: BudgetFixture, + #[case] override_budget: Option, + #[case] expected_budget: Option, + #[case] insert_override_budget: bool, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + insert_budget(&mut tx, default_budget).await?; + if let Some(budget) = user_budget { + insert_budget(&mut tx, budget).await?; + } + if let (Some(budget), true) = (override_budget, insert_override_budget) { + insert_budget(&mut tx, budget).await?; + } + insert_end_user( + &mut tx, + user_id, + 7.5, + true, + user_budget.map(|budget| budget.budget_id), + ) + .await?; + + let actual = find_end_user( + &mut *tx, + user_id, + Some(default_budget.budget_id), + override_budget.map(|budget| budget.budget_id), + ) + .await?; + + assert_eq!( + actual, + EndUser { + spend: Some(7.5), + blocked: true, + max_budget: expected_budget.map(|budget| budget.max_budget), + limits: RateLimits { + rpm: expected_budget.map(|budget| budget.rpm_limit), + tpm: expected_budget.map(|budget| budget.tpm_limit), + }, + } + ); + Ok(()) + } +} diff --git a/litellm-rust/crates/db/src/error.rs b/litellm-rust/crates/db/src/error.rs new file mode 100644 index 00000000000..af0ee030896 --- /dev/null +++ b/litellm-rust/crates/db/src/error.rs @@ -0,0 +1,79 @@ +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error("database query failed")] + Query(#[from] sqlx::Error), + #[error("spend batch has {ids} ids and {costs} costs")] + InvalidSpendBatch { ids: usize, costs: usize }, + #[error("invalid spend timestamp")] + InvalidTimestamp(#[from] chrono::ParseError), +} + +impl Error { + pub fn is_retryable(&self) -> bool { + match self { + Self::Query(sqlx::Error::Database(error)) => { + matches!( + error.code().as_deref(), + Some("40P01" | "55P03" | "40001" | "53300") + ) + } + Self::Query(sqlx::Error::Io(_) | sqlx::Error::PoolTimedOut) => true, + _ => false, + } + } +} + +#[cfg(test)] +mod tests { + use std::error::Error as StdError; + + use rstest::rstest; + use sqlx::PgPool; + + use super::Error; + use crate::test_support::database_pool; + + #[rstest] + #[case::closed_pool(sqlx::Error::PoolClosed, false)] + #[case::pool_timeout(sqlx::Error::PoolTimedOut, true)] + #[case::io(sqlx::Error::Io(std::io::ErrorKind::ConnectionReset.into()), true)] + #[case::missing_row(sqlx::Error::RowNotFound, false)] + fn classifies_client_errors(#[case] error: sqlx::Error, #[case] retryable: bool) { + assert_eq!(Error::from(error).is_retryable(), retryable); + } + + #[rstest] + #[case::connection_capacity("53300", true)] + #[case::deadlock("40P01", true)] + #[case::lock_unavailable("55P03", true)] + #[case::serialization_failure("40001", true)] + #[case::unique_violation("23505", false)] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn classifies_server_errors( + #[case] code: &str, + #[case] retryable: bool, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + #[expect( + clippy::disallowed_methods, + reason = "Test query must raise the requested SQLSTATE" + )] + let error = sqlx::query(sqlx::AssertSqlSafe(format!( + "DO $$ BEGIN RAISE EXCEPTION USING ERRCODE = '{code}'; END $$" + ))) + .execute(&mut *tx) + .await + .expect_err("PostgreSQL must raise the requested error"); + + assert_eq!( + error.as_database_error().and_then(|error| error.code()), + Some(code.into()) + ); + assert_eq!(Error::from(error).is_retryable(), retryable); + tx.rollback().await?; + Ok(()) + } +} diff --git a/litellm-rust/crates/db/src/lib.rs b/litellm-rust/crates/db/src/lib.rs index b7ce211d906..541f97c7db9 100644 --- a/litellm-rust/crates/db/src/lib.rs +++ b/litellm-rust/crates/db/src/lib.rs @@ -1,3 +1,26 @@ -mod failure; +macro_rules_attribute::attribute_alias! { + #[apply(db_input)] = + #[derive(Clone, Debug, PartialEq)]; + #[apply(db_row)] = + #[derive(Clone, Debug, PartialEq, sqlx::FromRow)]; +} + +mod daily_spend; +mod end_user; +mod error; +mod failure; +mod spend; +#[cfg(test)] +mod test_support; + +pub use daily_spend::{DailyEndUserRow, DailyTeamRow, DailyUserRow}; +pub use end_user::{EndUser, RateLimits, find_end_user}; +pub use error::Error; pub use failure::DbFailure; +pub use spend::{ + DailySpend, DailyTable, EntitySpend, SpendLog, SpendLogRow, TeamMemberSpend, + add_end_user_spend, add_key_spend, add_team_member_spend, add_team_spend, add_user_spend, + begin, insert_spend_logs, lock_team, upsert_daily_end_user_spend, upsert_daily_spend, + upsert_daily_team_spend, upsert_daily_user_spend, +}; diff --git a/litellm-rust/crates/db/src/spend/daily_end_user_spend.rs b/litellm-rust/crates/db/src/spend/daily_end_user_spend.rs new file mode 100644 index 00000000000..6c88d47cdcc --- /dev/null +++ b/litellm-rust/crates/db/src/spend/daily_end_user_spend.rs @@ -0,0 +1,584 @@ +use sqlx::PgExecutor; + +use super::{DailySpend, upsert_daily_team_spend, upsert_daily_user_spend}; +use crate::Error; + +pub async fn upsert_daily_end_user_spend( + executor: impl PgExecutor<'_>, + rows: &[DailySpend], +) -> Result<(), Error> { + if rows.is_empty() { + return Ok(()); + } + macro_rules! column { + ($field:ident) => { + rows.iter() + .map(|row| row.$field.clone()) + .collect::>() + }; + } + sqlx::query_file!( + "queries/spend/upsert_daily_end_user_spend.sql", + &column!(entity_id), + &column!(date), + &column!(api_key), + &column!(model), + &column!(custom_llm_provider), + &column!(endpoint), + &column!(model_group) as &[Option], + &column!(prompt_tokens), + &column!(completion_tokens), + &column!(api_requests), + &column!(successful_requests), + &column!(failed_requests), + &column!(cache_read_input_tokens), + &column!(cache_creation_input_tokens), + &column!(total_response_time_ms), + &column!(timed_requests), + &column!(spend), + &column!(mcp_namespaced_tool_name), + ) + .execute(executor) + .await?; + Ok(()) +} + +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, strum::VariantArray)] +pub enum DailyTable { + User, + Team, + EndUser, +} + +pub async fn upsert_daily_spend( + executor: impl PgExecutor<'_>, + table: DailyTable, + rows: &[DailySpend], +) -> Result<(), Error> { + match table { + DailyTable::User => upsert_daily_user_spend(executor, rows).await, + DailyTable::Team => upsert_daily_team_spend(executor, rows).await, + DailyTable::EndUser => upsert_daily_end_user_spend(executor, rows).await, + } +} + +#[cfg(test)] +mod tests { + use std::error::Error as StdError; + + use super::{DailySpend, DailyTable, upsert_daily_end_user_spend, upsert_daily_spend}; + use crate::{DailyEndUserRow, test_support::database_pool}; + use rstest::rstest; + use sqlx::{PgPool, types::chrono::NaiveDateTime}; + + #[rstest] + #[case::full_keys( + "daily-end-user-base", + "daily-key-base", + "daily-model", + "daily-provider", + "/chat/completions", + Some("first-group") + )] + #[case::initial_model_group_none( + "daily-end-user-base", + "daily-key-base", + "daily-model", + "daily-provider", + "/chat/completions", + None + )] + #[case::empty_optional_keys("", "", "", "", "", Some(""))] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn daily_end_user_spend_upsert_preserves_keys_and_accumulates( + #[case] end_user_id: &'static str, + #[case] api_key: &'static str, + #[case] model: &'static str, + #[case] custom_llm_provider: &'static str, + #[case] endpoint: &'static str, + #[case] first_model_group: Option<&'static str>, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + + #[expect( + clippy::disallowed_methods, + reason = "The integration test exercises UTC timestamp behavior under a non-UTC session" + )] + sqlx::query("SET LOCAL TIME ZONE 'America/Los_Angeles'") + .execute(&mut *tx) + .await?; + + let first_batch = [ + DailySpend { + entity_id: end_user_id.to_owned(), + date: "2026-01-15".to_owned(), + api_key: api_key.to_owned(), + model: model.to_owned(), + custom_llm_provider: custom_llm_provider.to_owned(), + mcp_namespaced_tool_name: String::new(), + endpoint: endpoint.to_owned(), + model_group: first_model_group.map(str::to_owned), + prompt_tokens: 1, + completion_tokens: 2, + api_requests: 3, + successful_requests: 4, + failed_requests: 5, + cache_read_input_tokens: 6, + cache_creation_input_tokens: 7, + total_response_time_ms: 8, + timed_requests: 9, + spend: 0.125, + }, + DailySpend { + entity_id: end_user_id.to_owned(), + date: "2026-01-15".to_owned(), + api_key: api_key.to_owned(), + model: model.to_owned(), + custom_llm_provider: custom_llm_provider.to_owned(), + mcp_namespaced_tool_name: String::new(), + endpoint: "endpoint-sentinel".to_owned(), + model_group: Some("sentinel-endpoint-group".to_owned()), + prompt_tokens: 101, + completion_tokens: 102, + api_requests: 103, + successful_requests: 104, + failed_requests: 105, + cache_read_input_tokens: 106, + cache_creation_input_tokens: 107, + total_response_time_ms: 108, + timed_requests: 109, + spend: 1.25, + }, + DailySpend { + entity_id: end_user_id.to_owned(), + date: "2026-01-15".to_owned(), + api_key: "api-key-sentinel".to_owned(), + model: model.to_owned(), + custom_llm_provider: custom_llm_provider.to_owned(), + mcp_namespaced_tool_name: String::new(), + endpoint: endpoint.to_owned(), + model_group: Some("sentinel-key-group".to_owned()), + prompt_tokens: 201, + completion_tokens: 202, + api_requests: 203, + successful_requests: 204, + failed_requests: 205, + cache_read_input_tokens: 206, + cache_creation_input_tokens: 207, + total_response_time_ms: 208, + timed_requests: 209, + spend: 2.5, + }, + DailySpend { + entity_id: "entity-sentinel".to_owned(), + date: "2026-01-15".to_owned(), + api_key: api_key.to_owned(), + model: model.to_owned(), + custom_llm_provider: custom_llm_provider.to_owned(), + mcp_namespaced_tool_name: String::new(), + endpoint: endpoint.to_owned(), + model_group: Some("sentinel-entity-group".to_owned()), + prompt_tokens: 301, + completion_tokens: 302, + api_requests: 303, + successful_requests: 304, + failed_requests: 305, + cache_read_input_tokens: 306, + cache_creation_input_tokens: 307, + total_response_time_ms: 308, + timed_requests: 309, + spend: 3.75, + }, + ]; + upsert_daily_end_user_spend(&mut *tx, &first_batch).await?; + + #[expect( + clippy::disallowed_methods, + reason = "The integration test captures the inserted row identity before conflict handling" + )] + let (initial_id, initial_created_at): (String, NaiveDateTime) = sqlx::query_as( + r#"SELECT id, created_at + FROM "LiteLLM_DailyEndUserSpend" + WHERE end_user_id = $1 AND date = $2 AND api_key = $3 AND model = $4 + AND custom_llm_provider = $5 AND endpoint = $6"#, + ) + .bind(end_user_id) + .bind("2026-01-15") + .bind(api_key) + .bind(model) + .bind(custom_llm_provider) + .bind(endpoint) + .fetch_one(&mut *tx) + .await?; + assert!(!initial_id.is_empty()); + + #[expect( + clippy::disallowed_methods, + reason = "The integration test seeds updated_at before exercising the conflict update" + )] + let seeded_updated_at: NaiveDateTime = sqlx::query_scalar( + r#"UPDATE "LiteLLM_DailyEndUserSpend" + SET updated_at = TIMESTAMP '2000-01-01' + WHERE id = $1 + RETURNING updated_at"#, + ) + .bind(&initial_id) + .fetch_one(&mut *tx) + .await?; + + let increment = [DailySpend { + entity_id: end_user_id.to_owned(), + date: "2026-01-15".to_owned(), + api_key: api_key.to_owned(), + model: model.to_owned(), + custom_llm_provider: custom_llm_provider.to_owned(), + mcp_namespaced_tool_name: String::new(), + endpoint: endpoint.to_owned(), + model_group: Some("second-group".to_owned()), + prompt_tokens: 10, + completion_tokens: 20, + api_requests: 30, + successful_requests: 40, + failed_requests: 50, + cache_read_input_tokens: 60, + cache_creation_input_tokens: 70, + total_response_time_ms: 80, + timed_requests: 90, + spend: 0.625, + }]; + upsert_daily_end_user_spend(&mut *tx, &increment).await?; + upsert_daily_end_user_spend(&mut *tx, &[]).await?; + + #[expect( + clippy::disallowed_methods, + reason = "The integration test captures the transaction timestamp for assertions" + )] + let expected_updated_at: NaiveDateTime = + sqlx::query_scalar("SELECT (NOW() AT TIME ZONE 'UTC')::timestamp(3)") + .fetch_one(&mut *tx) + .await?; + + #[expect( + clippy::disallowed_methods, + reason = "The integration test reads all rows to verify attribution and accumulation" + )] + let rows: Vec = sqlx::query_as( + r#"SELECT id, end_user_id, api_key, model, custom_llm_provider, endpoint, + model_group, mcp_namespaced_tool_name, prompt_tokens, + completion_tokens, api_requests, successful_requests, + failed_requests, cache_read_input_tokens, + cache_creation_input_tokens, total_response_time_ms, + timed_requests, spend, date, created_at, updated_at + FROM "LiteLLM_DailyEndUserSpend" + WHERE date = $1 AND model = $2 AND custom_llm_provider = $3 + AND mcp_namespaced_tool_name = '' AND end_user_id = ANY($4) + ORDER BY CASE + WHEN end_user_id = $5 AND api_key = $6 AND endpoint = $7 THEN 0 + WHEN end_user_id = $5 AND api_key = $6 AND endpoint = $9 THEN 1 + WHEN end_user_id = $5 AND api_key = $8 AND endpoint = $7 THEN 2 + WHEN end_user_id = $10 AND api_key = $6 AND endpoint = $7 THEN 3 + ELSE 4 + END"#, + ) + .bind("2026-01-15") + .bind(model) + .bind(custom_llm_provider) + .bind(vec![end_user_id, "entity-sentinel"]) + .bind(end_user_id) + .bind(api_key) + .bind(endpoint) + .bind("api-key-sentinel") + .bind("endpoint-sentinel") + .bind("entity-sentinel") + .fetch_all(&mut *tx) + .await?; + + assert_eq!(rows.len(), 4); + assert_eq!(rows[0].id, initial_id); + assert_eq!(rows[0].end_user_id.as_deref(), Some(end_user_id)); + assert_eq!(rows[0].api_key, api_key); + assert_eq!(rows[0].model.as_deref(), Some(model)); + assert_eq!( + rows[0].custom_llm_provider.as_deref(), + Some(custom_llm_provider) + ); + assert_eq!(rows[0].endpoint.as_deref(), Some(endpoint)); + assert_eq!(rows[0].model_group.as_deref(), first_model_group); + assert_eq!(rows[0].mcp_namespaced_tool_name.as_deref(), Some("")); + assert_eq!( + ( + rows[0].prompt_tokens, + rows[0].completion_tokens, + rows[0].api_requests, + rows[0].successful_requests, + rows[0].failed_requests, + rows[0].cache_read_input_tokens, + rows[0].cache_creation_input_tokens, + rows[0].total_response_time_ms, + rows[0].timed_requests, + rows[0].spend + ), + (11, 22, 33, 44, 55, 66, 77, 88, 99, 0.75) + ); + assert_eq!(rows[0].date, "2026-01-15"); + assert_eq!(rows[0].created_at, initial_created_at); + assert!(rows[0].updated_at > seeded_updated_at); + assert_eq!(rows[0].updated_at, expected_updated_at); + + assert!(!rows[1].id.is_empty()); + assert_eq!(rows[1].end_user_id.as_deref(), Some(end_user_id)); + assert_eq!(rows[1].api_key, api_key); + assert_eq!(rows[1].model.as_deref(), Some(model)); + assert_eq!( + rows[1].custom_llm_provider.as_deref(), + Some(custom_llm_provider) + ); + assert_eq!(rows[1].endpoint.as_deref(), Some("endpoint-sentinel")); + assert_eq!( + rows[1].model_group.as_deref(), + Some("sentinel-endpoint-group") + ); + assert_eq!(rows[1].mcp_namespaced_tool_name.as_deref(), Some("")); + assert_eq!( + ( + rows[1].prompt_tokens, + rows[1].completion_tokens, + rows[1].api_requests, + rows[1].successful_requests, + rows[1].failed_requests, + rows[1].cache_read_input_tokens, + rows[1].cache_creation_input_tokens, + rows[1].total_response_time_ms, + rows[1].timed_requests, + rows[1].spend + ), + (101, 102, 103, 104, 105, 106, 107, 108, 109, 1.25) + ); + assert_eq!(rows[1].date, "2026-01-15"); + assert!(rows[1].updated_at > seeded_updated_at); + assert_eq!(rows[1].updated_at, expected_updated_at); + + assert!(!rows[2].id.is_empty()); + assert_eq!(rows[2].end_user_id.as_deref(), Some(end_user_id)); + assert_eq!(rows[2].api_key, "api-key-sentinel"); + assert_eq!(rows[2].model.as_deref(), Some(model)); + assert_eq!( + rows[2].custom_llm_provider.as_deref(), + Some(custom_llm_provider) + ); + assert_eq!(rows[2].endpoint.as_deref(), Some(endpoint)); + assert_eq!(rows[2].model_group.as_deref(), Some("sentinel-key-group")); + assert_eq!(rows[2].mcp_namespaced_tool_name.as_deref(), Some("")); + assert_eq!( + ( + rows[2].prompt_tokens, + rows[2].completion_tokens, + rows[2].api_requests, + rows[2].successful_requests, + rows[2].failed_requests, + rows[2].cache_read_input_tokens, + rows[2].cache_creation_input_tokens, + rows[2].total_response_time_ms, + rows[2].timed_requests, + rows[2].spend + ), + (201, 202, 203, 204, 205, 206, 207, 208, 209, 2.5) + ); + assert_eq!(rows[2].date, "2026-01-15"); + assert!(rows[2].updated_at > seeded_updated_at); + assert_eq!(rows[2].updated_at, expected_updated_at); + + assert!(!rows[3].id.is_empty()); + assert_eq!(rows[3].end_user_id.as_deref(), Some("entity-sentinel")); + assert_eq!(rows[3].api_key, api_key); + assert_eq!(rows[3].model.as_deref(), Some(model)); + assert_eq!( + rows[3].custom_llm_provider.as_deref(), + Some(custom_llm_provider) + ); + assert_eq!(rows[3].endpoint.as_deref(), Some(endpoint)); + assert_eq!( + rows[3].model_group.as_deref(), + Some("sentinel-entity-group") + ); + assert_eq!(rows[3].mcp_namespaced_tool_name.as_deref(), Some("")); + assert_eq!( + ( + rows[3].prompt_tokens, + rows[3].completion_tokens, + rows[3].api_requests, + rows[3].successful_requests, + rows[3].failed_requests, + rows[3].cache_read_input_tokens, + rows[3].cache_creation_input_tokens, + rows[3].total_response_time_ms, + rows[3].timed_requests, + rows[3].spend + ), + (301, 302, 303, 304, 305, 306, 307, 308, 309, 3.75) + ); + assert_eq!(rows[3].date, "2026-01-15"); + assert!(rows[3].updated_at > seeded_updated_at); + assert_eq!(rows[3].updated_at, expected_updated_at); + Ok(()) + } + + #[rstest] + #[case::distinct_tools("server/tool-a", "server/tool-b")] + #[case::empty_and_named_tool("", "server/tool-b")] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn daily_end_user_spend_preserves_tool_attribution( + #[case] first_tool: &str, + #[case] second_tool: &str, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + let first = DailySpend { + entity_id: "daily-end-user-tools".to_owned(), + date: "2026-02-21".to_owned(), + api_key: "tool-key".to_owned(), + model: "tool-model".to_owned(), + custom_llm_provider: "tool-provider".to_owned(), + endpoint: "/mcp".to_owned(), + mcp_namespaced_tool_name: first_tool.to_owned(), + prompt_tokens: 2, + spend: 0.25, + ..Default::default() + }; + let second = DailySpend { + mcp_namespaced_tool_name: second_tool.to_owned(), + prompt_tokens: 5, + spend: 0.5, + ..first.clone() + }; + upsert_daily_end_user_spend(&mut *tx, &[second, first.clone()]).await?; + upsert_daily_end_user_spend(&mut *tx, &[first]).await?; + + #[expect( + clippy::disallowed_methods, + reason = "The integration test reads stored tool attribution and counters" + )] + let rows: Vec = sqlx::query_as( + r#"SELECT * FROM "LiteLLM_DailyEndUserSpend" + WHERE end_user_id = $1 AND date = $2 AND api_key = $3 + ORDER BY mcp_namespaced_tool_name"#, + ) + .bind("daily-end-user-tools") + .bind("2026-02-21") + .bind("tool-key") + .fetch_all(&mut *tx) + .await?; + + assert_eq!(rows.len(), 2); + assert_eq!( + rows[0].mcp_namespaced_tool_name.as_deref(), + Some(first_tool) + ); + assert_eq!( + rows[1].mcp_namespaced_tool_name.as_deref(), + Some(second_tool) + ); + assert_eq!((rows[0].prompt_tokens, rows[0].spend), (4, 0.5)); + assert_eq!((rows[1].prompt_tokens, rows[1].spend), (5, 0.5)); + assert_ne!(rows[0].id, rows[1].id); + Ok(()) + } + + #[rstest] + #[case::user(DailyTable::User, "daily-dispatch-user")] + #[case::team(DailyTable::Team, "daily-dispatch-team")] + #[case::end_user(DailyTable::EndUser, "daily-dispatch-end-user")] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn daily_spend_dispatches_to_selected_table( + #[case] table: DailyTable, + #[case] entity_id: &'static str, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + let api_key = format!("{entity_id}-key"); + let rows = [DailySpend { + entity_id: entity_id.to_owned(), + date: "2026-02-20".to_owned(), + api_key: api_key.clone(), + model: "dispatcher-model".to_owned(), + custom_llm_provider: "dispatcher-provider".to_owned(), + mcp_namespaced_tool_name: String::new(), + endpoint: "/dispatcher".to_owned(), + model_group: Some("dispatcher-group".to_owned()), + prompt_tokens: 1, + completion_tokens: 2, + api_requests: 3, + successful_requests: 4, + failed_requests: 5, + cache_read_input_tokens: 6, + cache_creation_input_tokens: 7, + total_response_time_ms: 8, + timed_requests: 9, + spend: 0.125, + }]; + upsert_daily_spend(&mut *tx, table, &rows).await?; + + let count: i64 = match table { + DailyTable::User => + { + #[expect( + clippy::disallowed_methods, + reason = "The integration test checks the user-table dispatcher route" + )] + sqlx::query_scalar( + r#"SELECT COUNT(*) FROM "LiteLLM_DailyUserSpend" + WHERE user_id = $1 AND date = $2 AND api_key = $3 AND model = $4"#, + ) + .bind(entity_id) + .bind("2026-02-20") + .bind(&api_key) + .bind("dispatcher-model") + .fetch_one(&mut *tx) + .await? + } + DailyTable::Team => + { + #[expect( + clippy::disallowed_methods, + reason = "The integration test checks the team-table dispatcher route" + )] + sqlx::query_scalar( + r#"SELECT COUNT(*) FROM "LiteLLM_DailyTeamSpend" + WHERE team_id = $1 AND date = $2 AND api_key = $3 AND model = $4"#, + ) + .bind(entity_id) + .bind("2026-02-20") + .bind(&api_key) + .bind("dispatcher-model") + .fetch_one(&mut *tx) + .await? + } + DailyTable::EndUser => + { + #[expect( + clippy::disallowed_methods, + reason = "The integration test checks the end-user-table dispatcher route" + )] + sqlx::query_scalar( + r#"SELECT COUNT(*) FROM "LiteLLM_DailyEndUserSpend" + WHERE end_user_id = $1 AND date = $2 AND api_key = $3 AND model = $4"#, + ) + .bind(entity_id) + .bind("2026-02-20") + .bind(&api_key) + .bind("dispatcher-model") + .fetch_one(&mut *tx) + .await? + } + }; + assert_eq!(count, 1); + Ok(()) + } +} diff --git a/litellm-rust/crates/db/src/spend/daily_team_spend.rs b/litellm-rust/crates/db/src/spend/daily_team_spend.rs new file mode 100644 index 00000000000..f2acd23f468 --- /dev/null +++ b/litellm-rust/crates/db/src/spend/daily_team_spend.rs @@ -0,0 +1,485 @@ +use sqlx::PgExecutor; + +use super::DailySpend; +use crate::Error; + +pub async fn upsert_daily_team_spend( + executor: impl PgExecutor<'_>, + rows: &[DailySpend], +) -> Result<(), Error> { + if rows.is_empty() { + return Ok(()); + } + macro_rules! column { + ($field:ident) => { + rows.iter() + .map(|row| row.$field.clone()) + .collect::>() + }; + } + sqlx::query_file!( + "queries/spend/upsert_daily_team_spend.sql", + &column!(entity_id), + &column!(date), + &column!(api_key), + &column!(model), + &column!(custom_llm_provider), + &column!(endpoint), + &column!(model_group) as &[Option], + &column!(prompt_tokens), + &column!(completion_tokens), + &column!(api_requests), + &column!(successful_requests), + &column!(failed_requests), + &column!(cache_read_input_tokens), + &column!(cache_creation_input_tokens), + &column!(total_response_time_ms), + &column!(timed_requests), + &column!(spend), + &column!(mcp_namespaced_tool_name), + ) + .execute(executor) + .await?; + Ok(()) +} + +#[cfg(test)] +mod tests { + use std::error::Error as StdError; + + use super::{DailySpend, upsert_daily_team_spend}; + use crate::{DailyTeamRow, test_support::database_pool}; + use rstest::rstest; + use sqlx::{PgPool, types::chrono::NaiveDateTime}; + + #[rstest] + #[case::distinct_tools("server.fetch", "server.search")] + #[case::default_and_named_tool("", "server.search")] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn daily_team_spend_separates_tools_and_accumulates( + #[case] first_tool: &str, + #[case] second_tool: &str, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + let first = DailySpend { + entity_id: "daily-team-tools".to_owned(), + date: "2026-01-15".to_owned(), + api_key: "daily-key-tools".to_owned(), + model: "daily-model".to_owned(), + custom_llm_provider: "daily-provider".to_owned(), + endpoint: "/mcp".to_owned(), + mcp_namespaced_tool_name: first_tool.to_owned(), + api_requests: 1, + spend: 0.125, + ..Default::default() + }; + let second = DailySpend { + mcp_namespaced_tool_name: second_tool.to_owned(), + api_requests: 2, + spend: 0.25, + ..first.clone() + }; + upsert_daily_team_spend(&mut *tx, &[second.clone(), first.clone()]).await?; + upsert_daily_team_spend( + &mut *tx, + &[ + DailySpend { + api_requests: 3, + spend: 0.5, + ..first + }, + DailySpend { + api_requests: 5, + spend: 1.0, + ..second + }, + ], + ) + .await?; + + #[expect( + clippy::disallowed_methods, + reason = "The integration test reads stored tool attribution and counters" + )] + let rows = sqlx::query_as::<_, DailyTeamRow>( + r#"SELECT * FROM "LiteLLM_DailyTeamSpend" + WHERE team_id = $1 AND date = $2 + ORDER BY mcp_namespaced_tool_name"#, + ) + .bind("daily-team-tools") + .bind("2026-01-15") + .fetch_all(&mut *tx) + .await?; + + assert_eq!(rows.len(), 2); + assert_eq!( + rows[0].mcp_namespaced_tool_name.as_deref(), + Some(first_tool) + ); + assert_eq!( + rows[1].mcp_namespaced_tool_name.as_deref(), + Some(second_tool) + ); + assert_eq!((rows[0].api_requests, rows[0].spend), (4, 0.625)); + assert_eq!((rows[1].api_requests, rows[1].spend), (7, 1.25)); + Ok(()) + } + + #[rstest] + #[case::full_keys( + "daily-team-base", + "daily-key-base", + "daily-model", + "daily-provider", + "/chat/completions", + Some("first-group") + )] + #[case::initial_model_group_none( + "daily-team-base", + "daily-key-base", + "daily-model", + "daily-provider", + "/chat/completions", + None + )] + #[case::empty_optional_keys("", "", "", "", "", Some(""))] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn daily_team_spend_upsert_preserves_keys_and_accumulates( + #[case] team_id: &'static str, + #[case] api_key: &'static str, + #[case] model: &'static str, + #[case] custom_llm_provider: &'static str, + #[case] endpoint: &'static str, + #[case] first_model_group: Option<&'static str>, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + + #[expect( + clippy::disallowed_methods, + reason = "The integration test exercises UTC timestamp behavior under a non-UTC session" + )] + sqlx::query("SET LOCAL TIME ZONE 'America/Los_Angeles'") + .execute(&mut *tx) + .await?; + + let first_batch = [ + DailySpend { + entity_id: team_id.to_owned(), + date: "2026-01-15".to_owned(), + api_key: api_key.to_owned(), + model: model.to_owned(), + custom_llm_provider: custom_llm_provider.to_owned(), + mcp_namespaced_tool_name: String::new(), + endpoint: endpoint.to_owned(), + model_group: first_model_group.map(str::to_owned), + prompt_tokens: 1, + completion_tokens: 2, + api_requests: 3, + successful_requests: 4, + failed_requests: 5, + cache_read_input_tokens: 6, + cache_creation_input_tokens: 7, + total_response_time_ms: 8, + timed_requests: 9, + spend: 0.125, + }, + DailySpend { + entity_id: team_id.to_owned(), + date: "2026-01-15".to_owned(), + api_key: api_key.to_owned(), + model: model.to_owned(), + custom_llm_provider: custom_llm_provider.to_owned(), + mcp_namespaced_tool_name: String::new(), + endpoint: "endpoint-sentinel".to_owned(), + model_group: Some("sentinel-endpoint-group".to_owned()), + prompt_tokens: 101, + completion_tokens: 102, + api_requests: 103, + successful_requests: 104, + failed_requests: 105, + cache_read_input_tokens: 106, + cache_creation_input_tokens: 107, + total_response_time_ms: 108, + timed_requests: 109, + spend: 1.25, + }, + DailySpend { + entity_id: team_id.to_owned(), + date: "2026-01-15".to_owned(), + api_key: "api-key-sentinel".to_owned(), + model: model.to_owned(), + custom_llm_provider: custom_llm_provider.to_owned(), + mcp_namespaced_tool_name: String::new(), + endpoint: endpoint.to_owned(), + model_group: Some("sentinel-key-group".to_owned()), + prompt_tokens: 201, + completion_tokens: 202, + api_requests: 203, + successful_requests: 204, + failed_requests: 205, + cache_read_input_tokens: 206, + cache_creation_input_tokens: 207, + total_response_time_ms: 208, + timed_requests: 209, + spend: 2.5, + }, + DailySpend { + entity_id: "entity-sentinel".to_owned(), + date: "2026-01-15".to_owned(), + api_key: api_key.to_owned(), + model: model.to_owned(), + custom_llm_provider: custom_llm_provider.to_owned(), + mcp_namespaced_tool_name: String::new(), + endpoint: endpoint.to_owned(), + model_group: Some("sentinel-entity-group".to_owned()), + prompt_tokens: 301, + completion_tokens: 302, + api_requests: 303, + successful_requests: 304, + failed_requests: 305, + cache_read_input_tokens: 306, + cache_creation_input_tokens: 307, + total_response_time_ms: 308, + timed_requests: 309, + spend: 3.75, + }, + ]; + upsert_daily_team_spend(&mut *tx, &first_batch).await?; + + #[expect( + clippy::disallowed_methods, + reason = "The integration test captures the inserted row identity before conflict handling" + )] + let (initial_id, initial_created_at): (String, NaiveDateTime) = sqlx::query_as( + r#"SELECT id, created_at + FROM "LiteLLM_DailyTeamSpend" + WHERE team_id = $1 AND date = $2 AND api_key = $3 AND model = $4 + AND custom_llm_provider = $5 AND endpoint = $6"#, + ) + .bind(team_id) + .bind("2026-01-15") + .bind(api_key) + .bind(model) + .bind(custom_llm_provider) + .bind(endpoint) + .fetch_one(&mut *tx) + .await?; + assert!(!initial_id.is_empty()); + + #[expect( + clippy::disallowed_methods, + reason = "The integration test seeds updated_at before exercising the conflict update" + )] + let seeded_updated_at: NaiveDateTime = sqlx::query_scalar( + r#"UPDATE "LiteLLM_DailyTeamSpend" + SET updated_at = TIMESTAMP '2000-01-01' + WHERE id = $1 + RETURNING updated_at"#, + ) + .bind(&initial_id) + .fetch_one(&mut *tx) + .await?; + + let increment = [DailySpend { + entity_id: team_id.to_owned(), + date: "2026-01-15".to_owned(), + api_key: api_key.to_owned(), + model: model.to_owned(), + custom_llm_provider: custom_llm_provider.to_owned(), + mcp_namespaced_tool_name: String::new(), + endpoint: endpoint.to_owned(), + model_group: Some("second-group".to_owned()), + prompt_tokens: 10, + completion_tokens: 20, + api_requests: 30, + successful_requests: 40, + failed_requests: 50, + cache_read_input_tokens: 60, + cache_creation_input_tokens: 70, + total_response_time_ms: 80, + timed_requests: 90, + spend: 0.625, + }]; + upsert_daily_team_spend(&mut *tx, &increment).await?; + upsert_daily_team_spend(&mut *tx, &[]).await?; + + #[expect( + clippy::disallowed_methods, + reason = "The integration test captures the transaction timestamp for assertions" + )] + let expected_updated_at: NaiveDateTime = + sqlx::query_scalar("SELECT (NOW() AT TIME ZONE 'UTC')::timestamp(3)") + .fetch_one(&mut *tx) + .await?; + + #[expect( + clippy::disallowed_methods, + reason = "The integration test reads all rows to verify attribution and accumulation" + )] + let rows: Vec = sqlx::query_as( + r#"SELECT id, team_id, api_key, model, custom_llm_provider, endpoint, + model_group, mcp_namespaced_tool_name, prompt_tokens, + completion_tokens, api_requests, successful_requests, + failed_requests, cache_read_input_tokens, + cache_creation_input_tokens, total_response_time_ms, + timed_requests, spend, date, created_at, updated_at + FROM "LiteLLM_DailyTeamSpend" + WHERE date = $1 AND model = $2 AND custom_llm_provider = $3 + AND mcp_namespaced_tool_name = '' AND team_id = ANY($4) + ORDER BY CASE + WHEN team_id = $5 AND api_key = $6 AND endpoint = $7 THEN 0 + WHEN team_id = $5 AND api_key = $6 AND endpoint = $9 THEN 1 + WHEN team_id = $5 AND api_key = $8 AND endpoint = $7 THEN 2 + WHEN team_id = $10 AND api_key = $6 AND endpoint = $7 THEN 3 + ELSE 4 + END"#, + ) + .bind("2026-01-15") + .bind(model) + .bind(custom_llm_provider) + .bind(vec![team_id, "entity-sentinel"]) + .bind(team_id) + .bind(api_key) + .bind(endpoint) + .bind("api-key-sentinel") + .bind("endpoint-sentinel") + .bind("entity-sentinel") + .fetch_all(&mut *tx) + .await?; + + assert_eq!(rows.len(), 4); + assert_eq!(rows[0].id, initial_id); + assert_eq!(rows[0].team_id.as_deref(), Some(team_id)); + assert_eq!(rows[0].api_key, api_key); + assert_eq!(rows[0].model.as_deref(), Some(model)); + assert_eq!( + rows[0].custom_llm_provider.as_deref(), + Some(custom_llm_provider) + ); + assert_eq!(rows[0].endpoint.as_deref(), Some(endpoint)); + assert_eq!(rows[0].model_group.as_deref(), first_model_group); + assert_eq!(rows[0].mcp_namespaced_tool_name.as_deref(), Some("")); + assert_eq!( + ( + rows[0].prompt_tokens, + rows[0].completion_tokens, + rows[0].api_requests, + rows[0].successful_requests, + rows[0].failed_requests, + rows[0].cache_read_input_tokens, + rows[0].cache_creation_input_tokens, + rows[0].total_response_time_ms, + rows[0].timed_requests, + rows[0].spend + ), + (11, 22, 33, 44, 55, 66, 77, 88, 99, 0.75) + ); + assert_eq!(rows[0].date, "2026-01-15"); + assert_eq!(rows[0].created_at, initial_created_at); + assert!(rows[0].updated_at > seeded_updated_at); + assert_eq!(rows[0].updated_at, expected_updated_at); + + assert!(!rows[1].id.is_empty()); + assert_eq!(rows[1].team_id.as_deref(), Some(team_id)); + assert_eq!(rows[1].api_key, api_key); + assert_eq!(rows[1].model.as_deref(), Some(model)); + assert_eq!( + rows[1].custom_llm_provider.as_deref(), + Some(custom_llm_provider) + ); + assert_eq!(rows[1].endpoint.as_deref(), Some("endpoint-sentinel")); + assert_eq!( + rows[1].model_group.as_deref(), + Some("sentinel-endpoint-group") + ); + assert_eq!(rows[1].mcp_namespaced_tool_name.as_deref(), Some("")); + assert_eq!( + ( + rows[1].prompt_tokens, + rows[1].completion_tokens, + rows[1].api_requests, + rows[1].successful_requests, + rows[1].failed_requests, + rows[1].cache_read_input_tokens, + rows[1].cache_creation_input_tokens, + rows[1].total_response_time_ms, + rows[1].timed_requests, + rows[1].spend + ), + (101, 102, 103, 104, 105, 106, 107, 108, 109, 1.25) + ); + assert_eq!(rows[1].date, "2026-01-15"); + assert!(rows[1].updated_at > seeded_updated_at); + assert_eq!(rows[1].updated_at, expected_updated_at); + + assert!(!rows[2].id.is_empty()); + assert_eq!(rows[2].team_id.as_deref(), Some(team_id)); + assert_eq!(rows[2].api_key, "api-key-sentinel"); + assert_eq!(rows[2].model.as_deref(), Some(model)); + assert_eq!( + rows[2].custom_llm_provider.as_deref(), + Some(custom_llm_provider) + ); + assert_eq!(rows[2].endpoint.as_deref(), Some(endpoint)); + assert_eq!(rows[2].model_group.as_deref(), Some("sentinel-key-group")); + assert_eq!(rows[2].mcp_namespaced_tool_name.as_deref(), Some("")); + assert_eq!( + ( + rows[2].prompt_tokens, + rows[2].completion_tokens, + rows[2].api_requests, + rows[2].successful_requests, + rows[2].failed_requests, + rows[2].cache_read_input_tokens, + rows[2].cache_creation_input_tokens, + rows[2].total_response_time_ms, + rows[2].timed_requests, + rows[2].spend + ), + (201, 202, 203, 204, 205, 206, 207, 208, 209, 2.5) + ); + assert_eq!(rows[2].date, "2026-01-15"); + assert!(rows[2].updated_at > seeded_updated_at); + assert_eq!(rows[2].updated_at, expected_updated_at); + + assert!(!rows[3].id.is_empty()); + assert_eq!(rows[3].team_id.as_deref(), Some("entity-sentinel")); + assert_eq!(rows[3].api_key, api_key); + assert_eq!(rows[3].model.as_deref(), Some(model)); + assert_eq!( + rows[3].custom_llm_provider.as_deref(), + Some(custom_llm_provider) + ); + assert_eq!(rows[3].endpoint.as_deref(), Some(endpoint)); + assert_eq!( + rows[3].model_group.as_deref(), + Some("sentinel-entity-group") + ); + assert_eq!(rows[3].mcp_namespaced_tool_name.as_deref(), Some("")); + assert_eq!( + ( + rows[3].prompt_tokens, + rows[3].completion_tokens, + rows[3].api_requests, + rows[3].successful_requests, + rows[3].failed_requests, + rows[3].cache_read_input_tokens, + rows[3].cache_creation_input_tokens, + rows[3].total_response_time_ms, + rows[3].timed_requests, + rows[3].spend + ), + (301, 302, 303, 304, 305, 306, 307, 308, 309, 3.75) + ); + assert_eq!(rows[3].date, "2026-01-15"); + assert!(rows[3].updated_at > seeded_updated_at); + assert_eq!(rows[3].updated_at, expected_updated_at); + Ok(()) + } +} diff --git a/litellm-rust/crates/db/src/spend/daily_user_spend.rs b/litellm-rust/crates/db/src/spend/daily_user_spend.rs new file mode 100644 index 00000000000..3530eb245c5 --- /dev/null +++ b/litellm-rust/crates/db/src/spend/daily_user_spend.rs @@ -0,0 +1,500 @@ +use sqlx::PgExecutor; + +use crate::Error; + +#[macro_rules_attribute::apply(crate::db_input)] +#[derive(Default)] +pub struct DailySpend { + pub entity_id: String, + pub date: String, + pub api_key: String, + pub model: String, + pub custom_llm_provider: String, + pub mcp_namespaced_tool_name: String, + pub endpoint: String, + pub model_group: Option, + pub prompt_tokens: i64, + pub completion_tokens: i64, + pub api_requests: i64, + pub successful_requests: i64, + pub failed_requests: i64, + pub cache_read_input_tokens: i64, + pub cache_creation_input_tokens: i64, + pub total_response_time_ms: i64, + pub timed_requests: i64, + pub spend: f64, +} + +pub async fn upsert_daily_user_spend( + executor: impl PgExecutor<'_>, + rows: &[DailySpend], +) -> Result<(), Error> { + if rows.is_empty() { + return Ok(()); + } + macro_rules! column { + ($field:ident) => { + rows.iter() + .map(|row| row.$field.clone()) + .collect::>() + }; + } + sqlx::query_file!( + "queries/spend/upsert_daily_user_spend.sql", + &column!(entity_id), + &column!(date), + &column!(api_key), + &column!(model), + &column!(custom_llm_provider), + &column!(endpoint), + &column!(model_group) as &[Option], + &column!(prompt_tokens), + &column!(completion_tokens), + &column!(api_requests), + &column!(successful_requests), + &column!(failed_requests), + &column!(cache_read_input_tokens), + &column!(cache_creation_input_tokens), + &column!(total_response_time_ms), + &column!(timed_requests), + &column!(spend), + &column!(mcp_namespaced_tool_name), + ) + .execute(executor) + .await?; + Ok(()) +} + +#[cfg(test)] +mod tests { + use std::error::Error as StdError; + + use super::{DailySpend, upsert_daily_user_spend}; + use crate::{DailyUserRow, test_support::database_pool}; + use rstest::rstest; + use sqlx::{PgPool, types::chrono::NaiveDateTime}; + + #[rstest] + #[case::distinct_tools("server/search", "server/write")] + #[case::default_empty_tool("", "server/search")] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn daily_user_spend_separates_tools_and_accumulates( + #[case] first_tool: &str, + #[case] second_tool: &str, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + let first = DailySpend { + entity_id: format!("daily-user-tools-{first_tool}"), + date: "2026-01-15".to_owned(), + api_key: "tool-key".to_owned(), + model: "tool-model".to_owned(), + custom_llm_provider: "tool-provider".to_owned(), + endpoint: "/mcp".to_owned(), + model_group: Some("tool-group".to_owned()), + mcp_namespaced_tool_name: first_tool.to_owned(), + prompt_tokens: 3, + api_requests: 1, + spend: 0.25, + ..Default::default() + }; + let second = DailySpend { + mcp_namespaced_tool_name: second_tool.to_owned(), + prompt_tokens: 7, + api_requests: 2, + spend: 0.5, + ..first.clone() + }; + upsert_daily_user_spend(&mut *tx, &[second.clone(), first.clone()]).await?; + upsert_daily_user_spend(&mut *tx, &[first.clone(), second]).await?; + + #[expect( + clippy::disallowed_methods, + reason = "The integration test reads stored rows to verify tool attribution" + )] + let rows: Vec = sqlx::query_as( + r#"SELECT * FROM "LiteLLM_DailyUserSpend" + WHERE user_id = $1 + ORDER BY mcp_namespaced_tool_name, endpoint"#, + ) + .bind(&first.entity_id) + .fetch_all(&mut *tx) + .await?; + + assert_eq!(rows.len(), 2); + assert_eq!( + rows[0].mcp_namespaced_tool_name.as_deref(), + Some(first_tool) + ); + assert_eq!( + rows[1].mcp_namespaced_tool_name.as_deref(), + Some(second_tool) + ); + assert_eq!( + (rows[0].prompt_tokens, rows[0].api_requests, rows[0].spend), + (6, 2, 0.5) + ); + assert_eq!( + (rows[1].prompt_tokens, rows[1].api_requests, rows[1].spend), + (14, 4, 1.0) + ); + Ok(()) + } + + #[rstest] + #[case::full_keys( + "daily-user-base", + "daily-key-base", + "daily-model", + "daily-provider", + "/chat/completions", + Some("first-group") + )] + #[case::initial_model_group_none( + "daily-user-base", + "daily-key-base", + "daily-model", + "daily-provider", + "/chat/completions", + None + )] + #[case::empty_optional_keys("", "", "", "", "", Some(""))] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn daily_user_spend_upsert_preserves_keys_and_accumulates( + #[case] user_id: &'static str, + #[case] api_key: &'static str, + #[case] model: &'static str, + #[case] custom_llm_provider: &'static str, + #[case] endpoint: &'static str, + #[case] first_model_group: Option<&'static str>, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + + #[expect( + clippy::disallowed_methods, + reason = "The integration test exercises UTC timestamp behavior under a non-UTC session" + )] + sqlx::query("SET LOCAL TIME ZONE 'America/Los_Angeles'") + .execute(&mut *tx) + .await?; + + let first_batch = [ + DailySpend { + entity_id: user_id.to_owned(), + date: "2026-01-15".to_owned(), + api_key: api_key.to_owned(), + model: model.to_owned(), + custom_llm_provider: custom_llm_provider.to_owned(), + mcp_namespaced_tool_name: String::new(), + endpoint: endpoint.to_owned(), + model_group: first_model_group.map(str::to_owned), + prompt_tokens: 1, + completion_tokens: 2, + api_requests: 3, + successful_requests: 4, + failed_requests: 5, + cache_read_input_tokens: 6, + cache_creation_input_tokens: 7, + total_response_time_ms: 8, + timed_requests: 9, + spend: 0.125, + }, + DailySpend { + entity_id: user_id.to_owned(), + date: "2026-01-15".to_owned(), + api_key: api_key.to_owned(), + model: model.to_owned(), + custom_llm_provider: custom_llm_provider.to_owned(), + mcp_namespaced_tool_name: String::new(), + endpoint: "endpoint-sentinel".to_owned(), + model_group: Some("sentinel-endpoint-group".to_owned()), + prompt_tokens: 101, + completion_tokens: 102, + api_requests: 103, + successful_requests: 104, + failed_requests: 105, + cache_read_input_tokens: 106, + cache_creation_input_tokens: 107, + total_response_time_ms: 108, + timed_requests: 109, + spend: 1.25, + }, + DailySpend { + entity_id: user_id.to_owned(), + date: "2026-01-15".to_owned(), + api_key: "api-key-sentinel".to_owned(), + model: model.to_owned(), + custom_llm_provider: custom_llm_provider.to_owned(), + mcp_namespaced_tool_name: String::new(), + endpoint: endpoint.to_owned(), + model_group: Some("sentinel-key-group".to_owned()), + prompt_tokens: 201, + completion_tokens: 202, + api_requests: 203, + successful_requests: 204, + failed_requests: 205, + cache_read_input_tokens: 206, + cache_creation_input_tokens: 207, + total_response_time_ms: 208, + timed_requests: 209, + spend: 2.5, + }, + DailySpend { + entity_id: "entity-sentinel".to_owned(), + date: "2026-01-15".to_owned(), + api_key: api_key.to_owned(), + model: model.to_owned(), + custom_llm_provider: custom_llm_provider.to_owned(), + mcp_namespaced_tool_name: String::new(), + endpoint: endpoint.to_owned(), + model_group: Some("sentinel-entity-group".to_owned()), + prompt_tokens: 301, + completion_tokens: 302, + api_requests: 303, + successful_requests: 304, + failed_requests: 305, + cache_read_input_tokens: 306, + cache_creation_input_tokens: 307, + total_response_time_ms: 308, + timed_requests: 309, + spend: 3.75, + }, + ]; + upsert_daily_user_spend(&mut *tx, &first_batch).await?; + + #[expect( + clippy::disallowed_methods, + reason = "The integration test captures the inserted row identity before conflict handling" + )] + let (initial_id, initial_created_at): (String, NaiveDateTime) = sqlx::query_as( + r#"SELECT id, created_at + FROM "LiteLLM_DailyUserSpend" + WHERE user_id = $1 AND date = $2 AND api_key = $3 AND model = $4 + AND custom_llm_provider = $5 AND endpoint = $6"#, + ) + .bind(user_id) + .bind("2026-01-15") + .bind(api_key) + .bind(model) + .bind(custom_llm_provider) + .bind(endpoint) + .fetch_one(&mut *tx) + .await?; + assert!(!initial_id.is_empty()); + + #[expect( + clippy::disallowed_methods, + reason = "The integration test seeds updated_at before exercising the conflict update" + )] + let seeded_updated_at: NaiveDateTime = sqlx::query_scalar( + r#"UPDATE "LiteLLM_DailyUserSpend" + SET updated_at = TIMESTAMP '2000-01-01' + WHERE id = $1 + RETURNING updated_at"#, + ) + .bind(&initial_id) + .fetch_one(&mut *tx) + .await?; + + let increment = [DailySpend { + entity_id: user_id.to_owned(), + date: "2026-01-15".to_owned(), + api_key: api_key.to_owned(), + model: model.to_owned(), + custom_llm_provider: custom_llm_provider.to_owned(), + mcp_namespaced_tool_name: String::new(), + endpoint: endpoint.to_owned(), + model_group: Some("second-group".to_owned()), + prompt_tokens: 10, + completion_tokens: 20, + api_requests: 30, + successful_requests: 40, + failed_requests: 50, + cache_read_input_tokens: 60, + cache_creation_input_tokens: 70, + total_response_time_ms: 80, + timed_requests: 90, + spend: 0.625, + }]; + upsert_daily_user_spend(&mut *tx, &increment).await?; + upsert_daily_user_spend(&mut *tx, &[]).await?; + + #[expect( + clippy::disallowed_methods, + reason = "The integration test captures the transaction timestamp for assertions" + )] + let expected_updated_at: NaiveDateTime = + sqlx::query_scalar("SELECT (NOW() AT TIME ZONE 'UTC')::timestamp(3)") + .fetch_one(&mut *tx) + .await?; + + #[expect( + clippy::disallowed_methods, + reason = "The integration test reads all rows to verify attribution and accumulation" + )] + let rows: Vec = sqlx::query_as( + r#"SELECT id, user_id, api_key, model, custom_llm_provider, endpoint, + model_group, mcp_namespaced_tool_name, prompt_tokens, + completion_tokens, api_requests, successful_requests, + failed_requests, cache_read_input_tokens, + cache_creation_input_tokens, total_response_time_ms, + timed_requests, spend, date, created_at, updated_at + FROM "LiteLLM_DailyUserSpend" + WHERE date = $1 AND model = $2 AND custom_llm_provider = $3 + AND mcp_namespaced_tool_name = '' AND user_id = ANY($4) + ORDER BY CASE + WHEN user_id = $5 AND api_key = $6 AND endpoint = $7 THEN 0 + WHEN user_id = $5 AND api_key = $6 AND endpoint = $9 THEN 1 + WHEN user_id = $5 AND api_key = $8 AND endpoint = $7 THEN 2 + WHEN user_id = $10 AND api_key = $6 AND endpoint = $7 THEN 3 + ELSE 4 + END"#, + ) + .bind("2026-01-15") + .bind(model) + .bind(custom_llm_provider) + .bind(vec![user_id, "entity-sentinel"]) + .bind(user_id) + .bind(api_key) + .bind(endpoint) + .bind("api-key-sentinel") + .bind("endpoint-sentinel") + .bind("entity-sentinel") + .fetch_all(&mut *tx) + .await?; + + assert_eq!(rows.len(), 4); + assert_eq!(rows[0].id, initial_id); + assert_eq!(rows[0].user_id.as_deref(), Some(user_id)); + assert_eq!(rows[0].api_key, api_key); + assert_eq!(rows[0].model.as_deref(), Some(model)); + assert_eq!( + rows[0].custom_llm_provider.as_deref(), + Some(custom_llm_provider) + ); + assert_eq!(rows[0].endpoint.as_deref(), Some(endpoint)); + assert_eq!(rows[0].model_group.as_deref(), first_model_group); + assert_eq!(rows[0].mcp_namespaced_tool_name.as_deref(), Some("")); + assert_eq!( + ( + rows[0].prompt_tokens, + rows[0].completion_tokens, + rows[0].api_requests, + rows[0].successful_requests, + rows[0].failed_requests, + rows[0].cache_read_input_tokens, + rows[0].cache_creation_input_tokens, + rows[0].total_response_time_ms, + rows[0].timed_requests, + rows[0].spend + ), + (11, 22, 33, 44, 55, 66, 77, 88, 99, 0.75) + ); + assert_eq!(rows[0].date, "2026-01-15"); + assert_eq!(rows[0].created_at, initial_created_at); + assert!(rows[0].updated_at > seeded_updated_at); + assert_eq!(rows[0].updated_at, expected_updated_at); + + assert!(!rows[1].id.is_empty()); + assert_eq!(rows[1].user_id.as_deref(), Some(user_id)); + assert_eq!(rows[1].api_key, api_key); + assert_eq!(rows[1].model.as_deref(), Some(model)); + assert_eq!( + rows[1].custom_llm_provider.as_deref(), + Some(custom_llm_provider) + ); + assert_eq!(rows[1].endpoint.as_deref(), Some("endpoint-sentinel")); + assert_eq!( + rows[1].model_group.as_deref(), + Some("sentinel-endpoint-group") + ); + assert_eq!(rows[1].mcp_namespaced_tool_name.as_deref(), Some("")); + assert_eq!( + ( + rows[1].prompt_tokens, + rows[1].completion_tokens, + rows[1].api_requests, + rows[1].successful_requests, + rows[1].failed_requests, + rows[1].cache_read_input_tokens, + rows[1].cache_creation_input_tokens, + rows[1].total_response_time_ms, + rows[1].timed_requests, + rows[1].spend + ), + (101, 102, 103, 104, 105, 106, 107, 108, 109, 1.25) + ); + assert_eq!(rows[1].date, "2026-01-15"); + assert!(rows[1].updated_at > seeded_updated_at); + assert_eq!(rows[1].updated_at, expected_updated_at); + + assert!(!rows[2].id.is_empty()); + assert_eq!(rows[2].user_id.as_deref(), Some(user_id)); + assert_eq!(rows[2].api_key, "api-key-sentinel"); + assert_eq!(rows[2].model.as_deref(), Some(model)); + assert_eq!( + rows[2].custom_llm_provider.as_deref(), + Some(custom_llm_provider) + ); + assert_eq!(rows[2].endpoint.as_deref(), Some(endpoint)); + assert_eq!(rows[2].model_group.as_deref(), Some("sentinel-key-group")); + assert_eq!(rows[2].mcp_namespaced_tool_name.as_deref(), Some("")); + assert_eq!( + ( + rows[2].prompt_tokens, + rows[2].completion_tokens, + rows[2].api_requests, + rows[2].successful_requests, + rows[2].failed_requests, + rows[2].cache_read_input_tokens, + rows[2].cache_creation_input_tokens, + rows[2].total_response_time_ms, + rows[2].timed_requests, + rows[2].spend + ), + (201, 202, 203, 204, 205, 206, 207, 208, 209, 2.5) + ); + assert_eq!(rows[2].date, "2026-01-15"); + assert!(rows[2].updated_at > seeded_updated_at); + assert_eq!(rows[2].updated_at, expected_updated_at); + + assert!(!rows[3].id.is_empty()); + assert_eq!(rows[3].user_id.as_deref(), Some("entity-sentinel")); + assert_eq!(rows[3].api_key, api_key); + assert_eq!(rows[3].model.as_deref(), Some(model)); + assert_eq!( + rows[3].custom_llm_provider.as_deref(), + Some(custom_llm_provider) + ); + assert_eq!(rows[3].endpoint.as_deref(), Some(endpoint)); + assert_eq!( + rows[3].model_group.as_deref(), + Some("sentinel-entity-group") + ); + assert_eq!(rows[3].mcp_namespaced_tool_name.as_deref(), Some("")); + assert_eq!( + ( + rows[3].prompt_tokens, + rows[3].completion_tokens, + rows[3].api_requests, + rows[3].successful_requests, + rows[3].failed_requests, + rows[3].cache_read_input_tokens, + rows[3].cache_creation_input_tokens, + rows[3].total_response_time_ms, + rows[3].timed_requests, + rows[3].spend + ), + (301, 302, 303, 304, 305, 306, 307, 308, 309, 3.75) + ); + assert_eq!(rows[3].date, "2026-01-15"); + assert!(rows[3].updated_at > seeded_updated_at); + assert_eq!(rows[3].updated_at, expected_updated_at); + Ok(()) + } +} diff --git a/litellm-rust/crates/db/src/spend/end_user_spend.rs b/litellm-rust/crates/db/src/spend/end_user_spend.rs new file mode 100644 index 00000000000..ca327ac7e18 --- /dev/null +++ b/litellm-rust/crates/db/src/spend/end_user_spend.rs @@ -0,0 +1,197 @@ +use sqlx::PgExecutor; + +use super::EntitySpend; +use crate::Error; + +pub async fn add_end_user_spend( + executor: impl PgExecutor<'_>, + spend: &EntitySpend, +) -> Result<(), Error> { + spend.validate()?; + if spend.is_empty() { + return Ok(()); + } + sqlx::query_file!( + "queries/spend/add_end_user_spend.sql", + &spend.ids, + &spend.costs + ) + .execute(executor) + .await?; + Ok(()) +} + +#[cfg(test)] +mod tests { + use std::error::Error as StdError; + + use super::{EntitySpend, add_end_user_spend}; + use crate::test_support::database_pool; + use rstest::rstest; + use sqlx::PgPool; + + #[rstest] + #[case::fractional_costs(0.25, 0.75, false, 2.5, 1.5)] + #[case::zero_costs(0.0, 0.0, false, 2.0, 0.0)] + #[case::duplicate_ids(0.25, 0.75, true, 3.0, 3.0)] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn end_user_spend_matches_python_upsert( + #[case] existing_cost: f64, + #[case] new_cost: f64, + #[case] duplicate_ids: bool, + #[case] expected_existing_spend: f64, + #[case] expected_new_spend: f64, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + #[expect( + clippy::disallowed_methods, + reason = "Fixture writes are outside the compile-checked query set" + )] + let _budget = sqlx::query( + r#"INSERT INTO "LiteLLM_BudgetTable" (budget_id, created_by, updated_by) + VALUES ('end-user-spend-budget', 'db-query-test', 'db-query-test')"#, + ) + .execute(&mut *tx) + .await?; + #[expect( + clippy::disallowed_methods, + reason = "Fixture writes are outside the compile-checked query set" + )] + let _users = sqlx::query( + r#"INSERT INTO "LiteLLM_EndUserTable" (user_id, spend, blocked, budget_id) + VALUES ('end-user-spend-z', 2, true, 'end-user-spend-budget'), + ('end-user-spend-untouched', 100, true, NULL)"#, + ) + .execute(&mut *tx) + .await?; + let spend = if duplicate_ids { + EntitySpend { + ids: vec![ + "end-user-spend-z".into(), + "end-user-spend-a".into(), + "end-user-spend-z".into(), + "end-user-spend-a".into(), + ], + costs: vec![existing_cost, new_cost, existing_cost, new_cost], + } + } else { + EntitySpend { + ids: vec!["end-user-spend-z".into(), "end-user-spend-a".into()], + costs: vec![existing_cost, new_cost], + } + }; + add_end_user_spend(&mut *tx, &spend).await?; + add_end_user_spend(&mut *tx, &spend).await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let rows: Vec<(String, f64, bool, Option)> = sqlx::query_as( + r#"SELECT user_id, spend, blocked, budget_id FROM "LiteLLM_EndUserTable" + WHERE user_id = ANY($1) ORDER BY user_id"#, + ) + .bind(vec![ + "end-user-spend-a", + "end-user-spend-z", + "end-user-spend-untouched", + ]) + .fetch_all(&mut *tx) + .await?; + assert_eq!( + rows, + vec![ + ("end-user-spend-a".into(), expected_new_spend, false, None), + ("end-user-spend-untouched".into(), 100.0, true, None), + ( + "end-user-spend-z".into(), + expected_existing_spend, + true, + Some("end-user-spend-budget".into()), + ), + ] + ); + Ok(()) + } + + #[rstest] + #[case::missing_cost(vec!["end-user-invalid-existing".into(), "end-user-invalid-new".into()], vec![1.0])] + #[case::extra_cost(vec!["end-user-invalid-existing".into()], vec![1.0, 2.0])] + #[case::empty_ids(vec![], vec![1.0])] + #[case::empty_costs(vec!["end-user-invalid-existing".into()], vec![])] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn malformed_end_user_spend_is_rejected_before_writes( + #[case] ids: Vec, + #[case] costs: Vec, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + #[expect( + clippy::disallowed_methods, + reason = "Fixture writes are outside the compile-checked query set" + )] + let _user = sqlx::query( + r#"INSERT INTO "LiteLLM_EndUserTable" (user_id, spend, blocked) + VALUES ('end-user-invalid-existing', 8.5, true)"#, + ) + .execute(&mut *tx) + .await?; + let spend = EntitySpend { ids, costs }; + let result = add_end_user_spend(&mut *tx, &spend).await; + assert!(matches!( + result, + Err(crate::Error::InvalidSpendBatch { ids, costs }) + if ids == spend.ids.len() && costs == spend.costs.len() + )); + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let rows: Vec<(String, f64, bool)> = sqlx::query_as( + r#"SELECT user_id, spend, blocked FROM "LiteLLM_EndUserTable" + WHERE user_id IN ('end-user-invalid-existing', 'end-user-invalid-new')"#, + ) + .fetch_all(&mut *tx) + .await?; + assert_eq!(rows, vec![("end-user-invalid-existing".into(), 8.5, true)]); + Ok(()) + } + + #[rstest] + #[case::empty_batch()] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn empty_end_user_spend_is_a_noop( + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + #[expect( + clippy::disallowed_methods, + reason = "Fixture writes are outside the compile-checked query set" + )] + let _user = sqlx::query( + r#"INSERT INTO "LiteLLM_EndUserTable" (user_id, spend, blocked) + VALUES ('end-user-empty-spend', 8.5, true)"#, + ) + .execute(&mut *tx) + .await?; + add_end_user_spend(&mut *tx, &EntitySpend::default()).await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let row: (f64, bool, Option) = sqlx::query_as( + r#"SELECT spend, blocked, budget_id FROM "LiteLLM_EndUserTable" + WHERE user_id = 'end-user-empty-spend'"#, + ) + .fetch_one(&mut *tx) + .await?; + assert_eq!(row, (8.5, true, None)); + Ok(()) + } +} diff --git a/litellm-rust/crates/db/src/spend/key_spend.rs b/litellm-rust/crates/db/src/spend/key_spend.rs new file mode 100644 index 00000000000..5a6ba13307c --- /dev/null +++ b/litellm-rust/crates/db/src/spend/key_spend.rs @@ -0,0 +1,309 @@ +use sqlx::PgExecutor; +use std::collections::BTreeMap; + +use crate::Error; + +#[macro_rules_attribute::apply(crate::db_input)] +#[derive(Default)] +pub struct EntitySpend { + pub ids: Vec, + pub costs: Vec, +} + +impl EntitySpend { + pub(crate) fn validate(&self) -> Result<(), Error> { + if self.ids.len() != self.costs.len() { + return Err(Error::InvalidSpendBatch { + ids: self.ids.len(), + costs: self.costs.len(), + }); + } + Ok(()) + } + + pub fn is_empty(&self) -> bool { + self.ids.is_empty() + } +} + +impl FromIterator<(String, f64)> for EntitySpend { + fn from_iter>(entries: I) -> Self { + let entries = entries + .into_iter() + .fold(BTreeMap::new(), |mut sums, (id, cost)| { + *sums.entry(id).or_insert(0.0) += cost; + sums + }); + let (ids, costs) = entries.into_iter().unzip(); + Self { ids, costs } + } +} + +pub async fn add_key_spend( + executor: impl PgExecutor<'_>, + spend: &EntitySpend, +) -> Result<(), Error> { + spend.validate()?; + if spend.is_empty() { + return Ok(()); + } + sqlx::query_file!("queries/spend/add_key_spend.sql", &spend.ids, &spend.costs) + .execute(executor) + .await?; + Ok(()) +} + +#[cfg(test)] +mod tests { + use std::error::Error as StdError; + + use super::{EntitySpend, add_key_spend}; + use crate::{Error, test_support::database_pool}; + use rstest::rstest; + use sqlx::PgPool; + + #[rstest] + #[case::direct(false)] + #[case::collected(true)] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn duplicate_key_spend_accumulates( + #[case] collected: bool, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + #[expect( + clippy::disallowed_methods, + reason = "Fixture writes are outside the compile-checked query set" + )] + sqlx::query( + r#"INSERT INTO "LiteLLM_VerificationToken" (token, spend, total_spend, updated_at) + VALUES ('key-spend-duplicate', 2, 7, '2000-01-01')"#, + ) + .execute(&mut *tx) + .await?; + let spend = if collected { + [ + ("key-spend-duplicate".into(), 0.25), + ("key-spend-duplicate".into(), 0.75), + ] + .into_iter() + .collect() + } else { + EntitySpend { + ids: vec!["key-spend-duplicate".into(), "key-spend-duplicate".into()], + costs: vec![0.25, 0.75], + } + }; + add_key_spend(&mut *tx, &spend).await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let row: (f64, f64) = sqlx::query_as( + r#"SELECT spend, total_spend FROM "LiteLLM_VerificationToken" + WHERE token = 'key-spend-duplicate'"#, + ) + .fetch_one(&mut *tx) + .await?; + assert_eq!(row, (3.0, 8.0)); + Ok(()) + } + + #[rstest] + #[case::extra_id(vec!["key-spend-invalid".into(), "key-spend-invalid".into()], vec![0.25])] + #[case::extra_cost(vec!["key-spend-invalid".into()], vec![0.25, 0.75])] + #[case::empty_ids(vec![], vec![0.25])] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn malformed_key_spend_leaves_transaction_usable( + #[case] ids: Vec, + #[case] costs: Vec, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + #[expect( + clippy::disallowed_methods, + reason = "Fixture writes are outside the compile-checked query set" + )] + sqlx::query( + r#"INSERT INTO "LiteLLM_VerificationToken" + (token, spend, total_spend, last_active, updated_at) + VALUES ('key-spend-invalid', 2, 7, NULL, '2000-01-01')"#, + ) + .execute(&mut *tx) + .await?; + let spend = EntitySpend { ids, costs }; + let result = add_key_spend(&mut *tx, &spend).await; + assert!(matches!( + result, + Err(Error::InvalidSpendBatch { ids, costs }) + if ids == spend.ids.len() && costs == spend.costs.len() + )); + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let unchanged: (f64, f64, bool, bool) = sqlx::query_as( + r#"SELECT spend, total_spend, last_active IS NULL, + updated_at = TIMESTAMP '2000-01-01' + FROM "LiteLLM_VerificationToken" WHERE token = 'key-spend-invalid'"#, + ) + .fetch_one(&mut *tx) + .await?; + assert_eq!(unchanged, (2.0, 7.0, true, true)); + let valid = EntitySpend { + ids: vec!["key-spend-invalid".into()], + costs: vec![0.5], + }; + add_key_spend(&mut *tx, &valid).await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let updated: (f64, f64) = sqlx::query_as( + r#"SELECT spend, total_spend FROM "LiteLLM_VerificationToken" + WHERE token = 'key-spend-invalid'"#, + ) + .fetch_one(&mut *tx) + .await?; + assert_eq!(updated, (2.5, 7.5)); + Ok(()) + } + + #[rstest] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn key_activity_uses_update_time_in_old_transaction( + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + #[expect( + clippy::disallowed_methods, + reason = "Fixture writes are outside the compile-checked query set" + )] + sqlx::query( + r#"INSERT INTO "LiteLLM_VerificationToken" (token, spend, total_spend, updated_at) + VALUES ('key-spend-old-transaction', 2, 7, '2000-01-01')"#, + ) + .execute(&mut *tx) + .await?; + #[expect( + clippy::disallowed_methods, + reason = "Transaction timing setup is outside the compile-checked query set" + )] + sqlx::query("SELECT pg_sleep(0.02)") + .execute(&mut *tx) + .await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let boundary: chrono::NaiveDateTime = sqlx::query_scalar( + "SELECT date_trunc('milliseconds', clock_timestamp() AT TIME ZONE 'UTC')", + ) + .fetch_one(&mut *tx) + .await?; + let spend = EntitySpend { + ids: vec!["key-spend-old-transaction".into()], + costs: vec![0.25], + }; + add_key_spend(&mut *tx, &spend).await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let row: (chrono::NaiveDateTime, chrono::NaiveDateTime) = sqlx::query_as( + r#"SELECT last_active, updated_at FROM "LiteLLM_VerificationToken" + WHERE token = 'key-spend-old-transaction'"#, + ) + .fetch_one(&mut *tx) + .await?; + assert!(row.0 >= boundary, "last_active predates update boundary"); + assert!(row.1 >= boundary, "updated_at predates update boundary"); + Ok(()) + } + + #[rstest] + #[case::fractional_costs(0.25, 2.5, 7.5, 4.0, 12.0)] + #[case::zero_costs(0.0, 2.0, 7.0, 3.0, 11.0)] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn key_spend_matches_python_update_many( + #[case] cost: f64, + #[case] expected_a_spend: f64, + #[case] expected_a_total: f64, + #[case] expected_z_spend: f64, + #[case] expected_z_total: f64, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + #[expect( + clippy::disallowed_methods, + reason = "Fixture writes are outside the compile-checked query set" + )] + let _inserted = sqlx::query( + r#"INSERT INTO "LiteLLM_VerificationToken" + (token, spend, total_spend, last_active, updated_at) + VALUES ('key-spend-a', 2, 7, NULL, '2000-01-01'), + ('key-spend-z', 3, 11, NULL, '2000-01-01'), + ('key-spend-untouched', 100, 200, NULL, '2000-01-01')"#, + ) + .execute(&mut *tx) + .await?; + let spend = EntitySpend { + ids: vec![ + "key-spend-z".into(), + "key-spend-a".into(), + "key-spend-missing".into(), + ], + costs: vec![2.0 * cost, cost, 50.0], + }; + add_key_spend(&mut *tx, &EntitySpend::default()).await?; + add_key_spend(&mut *tx, &spend).await?; + add_key_spend(&mut *tx, &spend).await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let rows: Vec<(String, f64, f64, bool, bool)> = sqlx::query_as( + r#"SELECT token, spend, total_spend, last_active IS NOT NULL, + updated_at > TIMESTAMP '2000-01-01' + FROM "LiteLLM_VerificationToken" + WHERE token = ANY($1) ORDER BY token"#, + ) + .bind(vec![ + "key-spend-a", + "key-spend-z", + "key-spend-missing", + "key-spend-untouched", + ]) + .fetch_all(&mut *tx) + .await?; + assert_eq!( + rows, + vec![ + ( + "key-spend-a".into(), + expected_a_spend, + expected_a_total, + true, + true + ), + ("key-spend-untouched".into(), 100.0, 200.0, false, false), + ( + "key-spend-z".into(), + expected_z_spend, + expected_z_total, + true, + true + ), + ] + ); + Ok(()) + } +} diff --git a/litellm-rust/crates/db/src/spend/mod.rs b/litellm-rust/crates/db/src/spend/mod.rs new file mode 100644 index 00000000000..da255843547 --- /dev/null +++ b/litellm-rust/crates/db/src/spend/mod.rs @@ -0,0 +1,21 @@ +mod daily_end_user_spend; +mod daily_team_spend; +mod daily_user_spend; +mod end_user_spend; +mod key_spend; +mod spend_logs; +mod team_lock; +mod team_member_spend; +mod team_spend; +mod user_spend; + +pub use daily_end_user_spend::{DailyTable, upsert_daily_end_user_spend, upsert_daily_spend}; +pub use daily_team_spend::upsert_daily_team_spend; +pub use daily_user_spend::{DailySpend, upsert_daily_user_spend}; +pub use end_user_spend::add_end_user_spend; +pub use key_spend::{EntitySpend, add_key_spend}; +pub use spend_logs::{SpendLog, SpendLogRow, insert_spend_logs}; +pub use team_lock::{begin, lock_team}; +pub use team_member_spend::{TeamMemberSpend, add_team_member_spend}; +pub use team_spend::add_team_spend; +pub use user_spend::add_user_spend; diff --git a/litellm-rust/crates/db/src/spend/spend_logs.rs b/litellm-rust/crates/db/src/spend/spend_logs.rs new file mode 100644 index 00000000000..57a9ff85301 --- /dev/null +++ b/litellm-rust/crates/db/src/spend/spend_logs.rs @@ -0,0 +1,517 @@ +use chrono::{DateTime, NaiveDateTime}; +use sqlx::PgExecutor; + +use crate::Error; + +#[macro_rules_attribute::apply(crate::db_input)] +#[derive(Default)] +pub struct SpendLog { + pub request_id: String, + pub call_type: String, + pub api_key: String, + pub spend: f64, + pub total_tokens: i32, + pub prompt_tokens: i32, + pub completion_tokens: i32, + pub start_time: String, + pub end_time: String, + pub completion_start_time: Option, + pub request_duration_ms: Option, + pub model: String, + pub model_id: String, + pub model_group: String, + pub custom_llm_provider: String, + pub api_base: String, + pub user: String, + pub metadata: serde_json::Value, + pub cache_hit: String, + pub cache_key: String, + pub team_id: String, + pub organization_id: String, + pub end_user: String, + pub requester_ip_address: Option, + pub session_id: Option, + pub status: String, + pub litellm_call_id: Option, +} + +#[macro_rules_attribute::apply(crate::db_row)] +pub struct SpendLogRow { + pub request_id: String, + pub call_type: String, + pub api_key: String, + pub spend: f64, + pub total_tokens: i32, + pub prompt_tokens: i32, + pub completion_tokens: i32, + #[sqlx(rename = "startTime")] + pub start_time: NaiveDateTime, + #[sqlx(rename = "endTime")] + pub end_time: NaiveDateTime, + #[sqlx(rename = "completionStartTime")] + pub completion_start_time: Option, + pub request_duration_ms: Option, + pub model: String, + pub model_id: Option, + pub model_group: Option, + pub custom_llm_provider: Option, + pub api_base: Option, + pub user: Option, + pub metadata: Option, + pub cache_hit: Option, + pub cache_key: Option, + pub request_tags: Option, + pub team_id: Option, + pub organization_id: Option, + pub end_user: Option, + pub requester_ip_address: Option, + pub messages: Option, + pub response: Option, + pub proxy_server_request: Option, + pub session_id: Option, + pub status: Option, + pub litellm_call_id: Option, +} + +fn parse_timestamp(value: &str) -> Result { + DateTime::parse_from_rfc3339(value) + .map(|timestamp| timestamp.naive_utc()) + .or_else(|_| NaiveDateTime::parse_from_str(value, "%Y-%m-%dT%H:%M:%S%.f")) + .or_else(|_| NaiveDateTime::parse_from_str(value, "%Y-%m-%d %H:%M:%S%.f")) +} + +pub async fn insert_spend_logs( + executor: impl PgExecutor<'_>, + logs: &[SpendLog], +) -> Result<(), Error> { + if logs.is_empty() { + return Ok(()); + } + let start_times = logs + .iter() + .map(|log| parse_timestamp(&log.start_time)) + .collect::, _>>()?; + let end_times = logs + .iter() + .map(|log| parse_timestamp(&log.end_time)) + .collect::, _>>()?; + let completion_start_times = logs + .iter() + .map(|log| { + log.completion_start_time + .as_deref() + .map(parse_timestamp) + .transpose() + }) + .collect::, _>>()?; + macro_rules! column { + ($field:ident) => { + logs.iter() + .map(|log| log.$field.clone()) + .collect::>() + }; + } + sqlx::query_file!( + "queries/spend/insert_spend_logs.sql", + &column!(request_id), + &column!(call_type), + &column!(api_key), + &column!(spend), + &column!(total_tokens), + &column!(prompt_tokens), + &column!(completion_tokens), + &start_times, + &end_times, + &completion_start_times as &[Option], + &column!(request_duration_ms) as &[Option], + &column!(model), + &column!(model_id), + &column!(model_group), + &column!(custom_llm_provider), + &column!(api_base), + &column!(user), + &column!(metadata), + &column!(cache_hit), + &column!(cache_key), + &column!(team_id), + &column!(organization_id), + &column!(end_user), + &column!(requester_ip_address) as &[Option], + &column!(session_id) as &[Option], + &column!(status), + &column!(litellm_call_id) as &[Option], + ) + .execute(executor) + .await?; + Ok(()) +} + +#[cfg(test)] +mod tests { + use std::error::Error as StdError; + + use super::{SpendLog, SpendLogRow, insert_spend_logs}; + use crate::test_support::database_pool; + use rstest::{fixture, rstest}; + use serde_json::json; + use sqlx::{Acquire, Connection, PgExecutor, PgPool, types::chrono::NaiveDateTime}; + + #[fixture] + fn logs() -> [SpendLog; 2] { + [ + SpendLog { + request_id: "spend-logs-a".into(), + call_type: "acompletion".into(), + api_key: "key-a".into(), + spend: 0.125, + total_tokens: 17, + prompt_tokens: 11, + completion_tokens: 6, + start_time: "2026-01-02 03:04:05.123".into(), + end_time: "2026-01-02 03:04:06.789".into(), + completion_start_time: Some("2026-01-02 03:04:05.456".into()), + request_duration_ms: Some(1666), + model: "model-a".into(), + model_id: "deployment-a".into(), + model_group: "group-a".into(), + custom_llm_provider: "provider-a".into(), + api_base: "https://a.example.test".into(), + user: "user-a".into(), + metadata: json!({"tenant": "a", "nested": {"tokens": 11}, "flag": false}), + cache_hit: "False".into(), + cache_key: "cache-a".into(), + team_id: "team-a".into(), + organization_id: "org-a".into(), + end_user: "end-user-a".into(), + requester_ip_address: Some("192.0.2.1".into()), + session_id: Some("session-a".into()), + status: "success".into(), + litellm_call_id: Some("call-a".into()), + }, + SpendLog { + request_id: "spend-logs-b".into(), + call_type: "aembedding".into(), + api_key: "key-b".into(), + spend: 2.75, + total_tokens: 43, + prompt_tokens: 29, + completion_tokens: 14, + start_time: "2026-02-03 14:15:16.234".into(), + end_time: "2026-02-03 14:15:18.567".into(), + completion_start_time: None, + request_duration_ms: None, + model: "model-b".into(), + model_id: "deployment-b".into(), + model_group: "group-b".into(), + custom_llm_provider: "provider-b".into(), + api_base: "https://b.example.test".into(), + user: "user-b".into(), + metadata: json!({"tenant": "b", "tags": ["distinct", 7], "nullable": null}), + cache_hit: "True".into(), + cache_key: "cache-b".into(), + team_id: "team-b".into(), + organization_id: "org-b".into(), + end_user: "end-user-b".into(), + requester_ip_address: None, + session_id: None, + status: "failure".into(), + litellm_call_id: None, + }, + ] + } + + async fn read_log( + executor: impl PgExecutor<'_>, + request_id: &str, + ) -> Result { + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + sqlx::query_as::<_, SpendLogRow>( + r#"SELECT * FROM "LiteLLM_SpendLogs" WHERE request_id = $1"#, + ) + .bind(request_id) + .fetch_one(executor) + .await + } + + fn expected_log(log: &SpendLog) -> Result { + Ok(SpendLogRow { + request_id: log.request_id.clone(), + call_type: log.call_type.clone(), + api_key: log.api_key.clone(), + spend: log.spend, + total_tokens: log.total_tokens, + prompt_tokens: log.prompt_tokens, + completion_tokens: log.completion_tokens, + start_time: log.start_time.replace(' ', "T").parse()?, + end_time: log.end_time.replace(' ', "T").parse()?, + completion_start_time: log + .completion_start_time + .as_ref() + .map(|value| value.replace(' ', "T").parse()) + .transpose()?, + request_duration_ms: log.request_duration_ms, + model: log.model.clone(), + model_id: Some(log.model_id.clone()), + model_group: Some(log.model_group.clone()), + custom_llm_provider: Some(log.custom_llm_provider.clone()), + api_base: Some(log.api_base.clone()), + user: Some(log.user.clone()), + metadata: Some(log.metadata.clone()), + cache_hit: Some(log.cache_hit.clone()), + cache_key: Some(log.cache_key.clone()), + request_tags: Some(json!([])), + team_id: Some(log.team_id.clone()), + organization_id: Some(log.organization_id.clone()), + end_user: Some(log.end_user.clone()), + requester_ip_address: log.requester_ip_address.clone(), + messages: Some(json!({})), + response: Some(json!({})), + proxy_server_request: Some(json!({})), + session_id: log.session_id.clone(), + status: Some(log.status.clone()), + litellm_call_id: log.litellm_call_id.clone(), + }) + } + + #[rstest] + #[case::all_columns_and_duplicate()] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn inserts_distinct_rows_without_replacing_duplicates( + logs: [SpendLog; 2], + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + insert_spend_logs(&mut *tx, &logs).await?; + let replacement = SpendLog { + request_id: logs[0].request_id.clone(), + ..logs[1].clone() + }; + insert_spend_logs(&mut *tx, &[replacement]).await?; + assert_eq!( + read_log(&mut *tx, &logs[0].request_id).await?, + expected_log(&logs[0])? + ); + assert_eq!( + read_log(&mut *tx, &logs[1].request_id).await?, + expected_log(&logs[1])? + ); + tx.rollback().await?; + Ok(()) + } + + #[rstest] + #[case::partitioned_duplicate()] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn inserts_into_partitioned_logs_without_replacing_duplicates( + logs: [SpendLog; 2], + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + #[expect( + clippy::disallowed_methods, + reason = "The test creates a temporary partitioned table at runtime" + )] + sqlx::raw_sql( + r#"CREATE TEMP TABLE "LiteLLM_SpendLogs" ( + LIKE public."LiteLLM_SpendLogs" INCLUDING DEFAULTS INCLUDING GENERATED, + PRIMARY KEY (request_id, "startTime") + ) PARTITION BY RANGE ("startTime"); + CREATE TEMP TABLE spend_logs_default + PARTITION OF pg_temp."LiteLLM_SpendLogs" DEFAULT; + SET LOCAL search_path TO pg_temp, public;"#, + ) + .execute(&mut *tx) + .await?; + tx.clear_cached_statements().await?; + insert_spend_logs(&mut *tx, &logs).await?; + let replacement = SpendLog { + spend: 99.0, + ..logs[0].clone() + }; + insert_spend_logs(&mut *tx, &[replacement]).await?; + #[expect( + clippy::disallowed_methods, + reason = "The partitioned test fixture is created at runtime" + )] + let count: (i64,) = sqlx::query_as(r#"SELECT count(*) FROM pg_temp."LiteLLM_SpendLogs""#) + .fetch_one(&mut *tx) + .await?; + assert_eq!(count.0, 2); + assert_eq!( + read_log(&mut *tx, &logs[0].request_id).await?, + expected_log(&logs[0])? + ); + assert_eq!( + read_log(&mut *tx, &logs[1].request_id).await?, + expected_log(&logs[1])? + ); + let distinct_partition_key = SpendLog { + request_id: logs[0].request_id.clone(), + ..logs[1].clone() + }; + insert_spend_logs(&mut *tx, &[distinct_partition_key]).await?; + #[expect( + clippy::disallowed_methods, + reason = "The partitioned test fixture is created at runtime" + )] + let count: (i64,) = sqlx::query_as(r#"SELECT count(*) FROM pg_temp."LiteLLM_SpendLogs""#) + .fetch_one(&mut *tx) + .await?; + assert_eq!(count.0, 3); + tx.rollback().await?; + Ok(()) + } + + #[rstest] + #[case::positive_offset_across_midnight( + ["2026-01-02T00:04:05.1236+02:00", "2026-01-02T00:04:06.7894+02:00", "2026-01-02T00:04:05.4567+02:00"], + ["2026-01-01T22:04:05.124", "2026-01-01T22:04:06.789", "2026-01-01T22:04:05.457"] + )] + #[case::negative_offset_across_midnight( + ["2026-01-01T23:04:05-02:00", "2026-01-01T23:04:06-02:00", "2026-01-01T23:04:05.456-02:00"], + ["2026-01-02T01:04:05", "2026-01-02T01:04:06", "2026-01-02T01:04:05.456"] + )] + #[case::utc( + ["2026-01-02T03:04:05Z", "2026-01-02T03:04:06Z", "2026-01-02T03:04:05.456Z"], + ["2026-01-02T03:04:05", "2026-01-02T03:04:06", "2026-01-02T03:04:05.456"] + )] + #[case::naive_iso( + ["2026-01-02T03:04:05", "2026-01-02T03:04:06", "2026-01-02T03:04:05.456"], + ["2026-01-02T03:04:05", "2026-01-02T03:04:06", "2026-01-02T03:04:05.456"] + )] + #[case::naive_space( + ["2026-01-02 03:04:05", "2026-01-02 03:04:06", "2026-01-02 03:04:05.456"], + ["2026-01-02T03:04:05", "2026-01-02T03:04:06", "2026-01-02T03:04:05.456"] + )] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn stores_utc_timestamps( + #[case] input: [&str; 3], + #[case] expected: [&str; 3], + logs: [SpendLog; 2], + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + #[expect( + clippy::disallowed_methods, + reason = "The test sets a transaction-local timezone to verify timestamp handling" + )] + sqlx::raw_sql("SET LOCAL TIME ZONE 'America/Los_Angeles'") + .execute(&mut *tx) + .await?; + let log = SpendLog { + start_time: input[0].into(), + end_time: input[1].into(), + completion_start_time: Some(input[2].into()), + ..logs[0].clone() + }; + insert_spend_logs(&mut *tx, std::slice::from_ref(&log)).await?; + let row = read_log(&mut *tx, &log.request_id).await?; + assert_eq!(row.start_time, expected[0].parse::()?); + assert_eq!(row.end_time, expected[1].parse::()?); + assert_eq!( + row.completion_start_time, + Some(expected[2].parse::()?) + ); + tx.rollback().await?; + Ok(()) + } + + #[rstest] + #[case::empty_batch()] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn empty_input_leaves_rows_unchanged( + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let before: (i64,) = sqlx::query_as(r#"SELECT count(*) FROM "LiteLLM_SpendLogs""#) + .fetch_one(&mut *tx) + .await?; + insert_spend_logs(&mut *tx, &[]).await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let after: (i64,) = sqlx::query_as(r#"SELECT count(*) FROM "LiteLLM_SpendLogs""#) + .fetch_one(&mut *tx) + .await?; + assert_eq!(before, after); + tx.rollback().await?; + Ok(()) + } + + #[rstest] + #[case::invalid_timestamp("not-a-timestamp", "2026-01-02T03:04:06", None)] + #[case::invalid_end("2026-01-02T03:04:05", "not-a-timestamp", None)] + #[case::invalid_completion( + "2026-01-02T03:04:05", + "2026-01-02T03:04:06", + Some("not-a-timestamp") + )] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn invalid_timestamp_allows_caller_rollback( + #[case] start_time: &str, + #[case] end_time: &str, + #[case] completion_start_time: Option<&str>, + logs: [SpendLog; 2], + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut outer = pool.begin().await?; + let mut tx = outer.begin().await?; + let valid = SpendLog { + request_id: "spend-logs-rollback-valid".into(), + ..logs[0].clone() + }; + let invalid = SpendLog { + request_id: "spend-logs-rollback-invalid".into(), + start_time: start_time.into(), + end_time: end_time.into(), + completion_start_time: completion_start_time.map(str::to_owned), + ..logs[1].clone() + }; + insert_spend_logs(&mut *tx, std::slice::from_ref(&valid)).await?; + let result = insert_spend_logs(&mut *tx, &[logs[0].clone(), invalid]).await; + assert!(matches!(result, Err(crate::Error::InvalidTimestamp(_)))); + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let partial_batch: (i64,) = sqlx::query_as( + r#"SELECT count(*) FROM "LiteLLM_SpendLogs" WHERE request_id = ANY($1)"#, + ) + .bind([logs[0].request_id.as_str(), "spend-logs-rollback-invalid"].as_slice()) + .fetch_one(&mut *tx) + .await?; + assert_eq!(partial_batch.0, 0); + tx.rollback().await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let remaining: (i64,) = sqlx::query_as( + r#"SELECT count(*) FROM "LiteLLM_SpendLogs" WHERE request_id = ANY($1)"#, + ) + .bind([valid.request_id.as_str(), "spend-logs-rollback-invalid"].as_slice()) + .fetch_one(&mut *outer) + .await?; + assert_eq!(remaining.0, 0); + outer.rollback().await?; + Ok(()) + } +} diff --git a/litellm-rust/crates/db/src/spend/team_lock.rs b/litellm-rust/crates/db/src/spend/team_lock.rs new file mode 100644 index 00000000000..7a6b9c7f7d0 --- /dev/null +++ b/litellm-rust/crates/db/src/spend/team_lock.rs @@ -0,0 +1,98 @@ +use sqlx::{PgPool, Postgres, Transaction}; + +use crate::Error; + +pub async fn begin(pool: &PgPool) -> Result, Error> { + let mut transaction = pool.begin().await?; + sqlx::query!("SELECT set_config('lock_timeout', '5000ms', true)") + .fetch_one(&mut *transaction) + .await?; + Ok(transaction) +} + +pub async fn lock_team( + transaction: &mut Transaction<'_, Postgres>, + team_id: &str, +) -> Result<(), Error> { + sqlx::query_file!("queries/spend/lock_team.sql", team_id) + .fetch_one(&mut **transaction) + .await?; + Ok(()) +} + +#[cfg(test)] +mod tests { + use std::error::Error as StdError; + + use super::{begin, lock_team}; + use crate::test_support::database_pool; + use rstest::rstest; + use sqlx::{PgPool, postgres::PgPoolOptions}; + + #[rstest] + #[case::transaction_scoped("team-lock-scope")] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn team_lock_is_held_until_rollback( + #[case] team_id: &str, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let database_pool = database_pool?; + let pool = PgPoolOptions::new() + .max_connections(2) + .connect_with(database_pool.connect_options().as_ref().clone()) + .await?; + let mut first = begin(&pool).await?; + let mut second = pool.begin().await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let original_timeout: String = sqlx::query_scalar("SELECT current_setting('lock_timeout')") + .fetch_one(&mut *second) + .await?; + lock_team(&mut first, team_id).await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let (backend, timeout): (i32, String) = + sqlx::query_as("SELECT pg_backend_pid(), current_setting('lock_timeout')") + .fetch_one(&mut *first) + .await?; + assert_eq!(timeout, "5s"); + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let held: bool = sqlx::query_scalar("SELECT pg_try_advisory_xact_lock(hashtext($1))") + .bind(team_id) + .fetch_one(&mut *second) + .await?; + assert!(!held); + first.rollback().await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let released: bool = sqlx::query_scalar("SELECT pg_try_advisory_xact_lock(hashtext($1))") + .bind(team_id) + .fetch_one(&mut *second) + .await?; + assert!(released); + let mut next = pool.begin().await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let (next_backend, next_timeout): (i32, String) = + sqlx::query_as("SELECT pg_backend_pid(), current_setting('lock_timeout')") + .fetch_one(&mut *next) + .await?; + assert_eq!(next_backend, backend); + assert_eq!(next_timeout, original_timeout); + next.rollback().await?; + second.rollback().await?; + Ok(()) + } +} diff --git a/litellm-rust/crates/db/src/spend/team_member_spend.rs b/litellm-rust/crates/db/src/spend/team_member_spend.rs new file mode 100644 index 00000000000..965a39ada4f --- /dev/null +++ b/litellm-rust/crates/db/src/spend/team_member_spend.rs @@ -0,0 +1,162 @@ +use sqlx::{Postgres, Transaction}; + +use super::lock_team; +use crate::Error; + +#[macro_rules_attribute::apply(crate::db_input)] +pub struct TeamMemberSpend { + pub team_id: String, + pub user_id: String, + pub cost: f64, +} + +pub async fn add_team_member_spend( + transaction: &mut Transaction<'_, Postgres>, + members: &[TeamMemberSpend], +) -> Result<(), Error> { + if members.is_empty() { + return Ok(()); + } + let mut members = members.to_vec(); + members.sort_by(|left, right| { + (&left.team_id, &left.user_id).cmp(&(&right.team_id, &right.user_id)) + }); + let mut teams: Vec<&str> = members + .iter() + .map(|member| member.team_id.as_str()) + .collect(); + teams.dedup(); + for team in teams { + lock_team(transaction, team).await?; + } + let rows = serde_json::Value::Array( + members + .iter() + .map(|member| { + serde_json::json!({ + "user_id": member.user_id, + "team_id": member.team_id, + "cost": member.cost, + }) + }) + .collect(), + ); + sqlx::query_file!("queries/spend/upsert_team_member_spend.sql", rows) + .execute(&mut **transaction) + .await?; + Ok(()) +} + +#[cfg(test)] +mod tests { + use std::error::Error as StdError; + + use super::super::begin; + use super::{TeamMemberSpend, add_team_member_spend}; + use crate::test_support::database_pool; + use rstest::rstest; + use sqlx::PgPool; + + fn members(cost: f64) -> [TeamMemberSpend; 3] { + [ + TeamMemberSpend { + team_id: "member-spend-z".into(), + user_id: "off-roster-existing".into(), + cost: 2.0 * cost, + }, + TeamMemberSpend { + team_id: "member-spend-a".into(), + user_id: "on-roster-missing".into(), + cost, + }, + TeamMemberSpend { + team_id: "member-spend-a".into(), + user_id: "off-roster-missing".into(), + cost: 50.0 * cost, + }, + ] + } + + #[rstest] + #[case::zero_then_quarter(0.25, 0.5, 3.0, 8.0)] + #[case::zero_then_eighth(0.125, 0.25, 2.5, 7.5)] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn membership_spend_preserves_roster_guard_and_fractional_costs( + #[case] cost: f64, + #[case] expected_created: f64, + #[case] expected_spend: f64, + #[case] expected_total: f64, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = begin(&pool).await?; + #[expect( + clippy::disallowed_methods, + reason = "Fixture writes are outside the compile-checked query set" + )] + let _teams = sqlx::query( + r#"INSERT INTO "LiteLLM_TeamTable" (team_id, members_with_roles) + VALUES ('member-spend-a', '[{"user_id":"on-roster-missing","role":"user"}]'), + ('member-spend-z', '[]')"#, + ) + .execute(&mut *tx) + .await?; + #[expect( + clippy::disallowed_methods, + reason = "Fixture writes are outside the compile-checked query set" + )] + let _members = sqlx::query( + r#"INSERT INTO "LiteLLM_TeamMembership" (team_id, user_id, spend, total_spend) + VALUES ('member-spend-z', 'off-roster-existing', 2, 7), + ('member-spend-a', 'untouched', 100, 200)"#, + ) + .execute(&mut *tx) + .await?; + add_team_member_spend(&mut tx, &[]).await?; + add_team_member_spend(&mut tx, &members(0.0)).await?; + add_team_member_spend(&mut tx, &members(cost)).await?; + add_team_member_spend(&mut tx, &members(cost)).await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let rows: Vec<(String, String, f64, f64)> = sqlx::query_as( + r#"SELECT team_id, user_id, spend, total_spend FROM "LiteLLM_TeamMembership" + WHERE team_id IN ('member-spend-a', 'member-spend-z') ORDER BY team_id, user_id"#, + ) + .fetch_all(&mut *tx) + .await?; + assert_eq!( + rows, + vec![ + ( + "member-spend-a".into(), + "on-roster-missing".into(), + expected_created, + expected_created + ), + ("member-spend-a".into(), "untouched".into(), 100.0, 200.0), + ( + "member-spend-z".into(), + "off-roster-existing".into(), + expected_spend, + expected_total + ), + ] + ); + tx.rollback().await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let remaining: i64 = sqlx::query_scalar( + r#"SELECT COUNT(*) FROM "LiteLLM_TeamMembership" + WHERE team_id IN ('member-spend-a', 'member-spend-z')"#, + ) + .fetch_one(&pool) + .await?; + assert_eq!(remaining, 0); + Ok(()) + } +} diff --git a/litellm-rust/crates/db/src/spend/team_spend.rs b/litellm-rust/crates/db/src/spend/team_spend.rs new file mode 100644 index 00000000000..a105899bc2a --- /dev/null +++ b/litellm-rust/crates/db/src/spend/team_spend.rs @@ -0,0 +1,182 @@ +use sqlx::PgExecutor; + +use super::EntitySpend; +use crate::Error; + +pub async fn add_team_spend( + executor: impl PgExecutor<'_>, + spend: &EntitySpend, +) -> Result<(), Error> { + spend.validate()?; + if spend.is_empty() { + return Ok(()); + } + sqlx::query_file!("queries/spend/add_team_spend.sql", &spend.ids, &spend.costs) + .execute(executor) + .await?; + Ok(()) +} + +#[cfg(test)] +mod tests { + use std::error::Error as StdError; + + use super::{EntitySpend, add_team_spend}; + use crate::Error; + use crate::test_support::database_pool; + use rstest::rstest; + use sqlx::PgPool; + + #[rstest] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn duplicate_team_ids_add_every_cost( + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + #[expect( + clippy::disallowed_methods, + reason = "Fixture writes are outside the compile-checked query set" + )] + let _inserted = sqlx::query( + r#"INSERT INTO "LiteLLM_TeamTable" (team_id, spend, created_at, updated_at) + VALUES ('team-spend-duplicate-a', 2, '2000-01-01', '2000-01-01'), + ('team-spend-duplicate-z', 3, '2000-01-01', '2000-01-01')"#, + ) + .execute(&mut *tx) + .await?; + let spend = EntitySpend { + ids: vec![ + "team-spend-duplicate-z".into(), + "team-spend-duplicate-a".into(), + "team-spend-duplicate-z".into(), + "team-spend-duplicate-a".into(), + ], + costs: vec![0.5, 0.25, 1.0, 0.5], + }; + add_team_spend(&mut *tx, &spend).await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let rows: Vec<(String, f64)> = sqlx::query_as( + r#"SELECT team_id, spend FROM "LiteLLM_TeamTable" + WHERE team_id = ANY($1) ORDER BY team_id"#, + ) + .bind(&spend.ids) + .fetch_all(&mut *tx) + .await?; + assert_eq!( + rows, + vec![ + ("team-spend-duplicate-a".into(), 2.75), + ("team-spend-duplicate-z".into(), 4.5), + ] + ); + Ok(()) + } + + #[rstest] + #[case::missing_cost(vec!["team-spend-malformed".into()], vec![])] + #[case::extra_cost(vec!["team-spend-malformed".into()], vec![0.25, 0.5])] + #[case::empty_ids(vec![], vec![0.25])] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn malformed_team_batch_does_not_write( + #[case] ids: Vec, + #[case] costs: Vec, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + #[expect( + clippy::disallowed_methods, + reason = "Fixture writes are outside the compile-checked query set" + )] + let _inserted = sqlx::query( + r#"INSERT INTO "LiteLLM_TeamTable" (team_id, spend, created_at, updated_at) + VALUES ('team-spend-malformed', 2, '2000-01-01', '2000-01-01')"#, + ) + .execute(&mut *tx) + .await?; + let result = add_team_spend(&mut *tx, &EntitySpend { ids, costs }).await; + assert!(matches!(result, Err(Error::InvalidSpendBatch { .. }))); + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let row: (f64, bool) = sqlx::query_as( + r#"SELECT spend, updated_at = TIMESTAMP '2000-01-01' + FROM "LiteLLM_TeamTable" WHERE team_id = 'team-spend-malformed'"#, + ) + .fetch_one(&mut *tx) + .await?; + assert_eq!(row, (2.0, true)); + Ok(()) + } + + #[rstest] + #[case::fractional_costs(0.25, 2.5, 4.0)] + #[case::zero_costs(0.0, 2.0, 3.0)] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn team_spend_matches_python_update_many( + #[case] cost: f64, + #[case] expected_a_spend: f64, + #[case] expected_z_spend: f64, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + #[expect( + clippy::disallowed_methods, + reason = "Fixture writes are outside the compile-checked query set" + )] + let _inserted = sqlx::query( + r#"INSERT INTO "LiteLLM_TeamTable" (team_id, spend, created_at, updated_at) + VALUES ('team-spend-a', 2, '2000-01-01', '2000-01-01'), + ('team-spend-z', 3, '2000-01-01', '2000-01-01'), + ('team-spend-untouched', 100, '2000-01-01', '2000-01-01')"#, + ) + .execute(&mut *tx) + .await?; + let spend = EntitySpend { + ids: vec![ + "team-spend-z".into(), + "team-spend-a".into(), + "team-spend-missing".into(), + ], + costs: vec![2.0 * cost, cost, 50.0], + }; + add_team_spend(&mut *tx, &EntitySpend::default()).await?; + add_team_spend(&mut *tx, &spend).await?; + add_team_spend(&mut *tx, &spend).await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let rows: Vec<(String, f64, bool)> = sqlx::query_as( + r#"SELECT team_id, spend, updated_at > TIMESTAMP '2000-01-01' + FROM "LiteLLM_TeamTable" + WHERE team_id = ANY($1) ORDER BY team_id"#, + ) + .bind(vec![ + "team-spend-a", + "team-spend-z", + "team-spend-missing", + "team-spend-untouched", + ]) + .fetch_all(&mut *tx) + .await?; + assert_eq!( + rows, + vec![ + ("team-spend-a".into(), expected_a_spend, true), + ("team-spend-untouched".into(), 100.0, false), + ("team-spend-z".into(), expected_z_spend, true), + ] + ); + Ok(()) + } +} diff --git a/litellm-rust/crates/db/src/spend/user_spend.rs b/litellm-rust/crates/db/src/spend/user_spend.rs new file mode 100644 index 00000000000..2c89c04c1ef --- /dev/null +++ b/litellm-rust/crates/db/src/spend/user_spend.rs @@ -0,0 +1,173 @@ +use sqlx::PgExecutor; + +use super::EntitySpend; +use crate::Error; + +pub async fn add_user_spend( + executor: impl PgExecutor<'_>, + spend: &EntitySpend, +) -> Result<(), Error> { + spend.validate()?; + if spend.is_empty() { + return Ok(()); + } + sqlx::query_file!("queries/spend/add_user_spend.sql", &spend.ids, &spend.costs) + .execute(executor) + .await?; + Ok(()) +} + +#[cfg(test)] +mod tests { + use std::error::Error as StdError; + + use super::{EntitySpend, add_user_spend}; + use crate::{Error, test_support::database_pool}; + use rstest::rstest; + use sqlx::PgPool; + + #[rstest] + #[case::fractional_costs(0.25, 2.5, 4.0)] + #[case::zero_costs(0.0, 2.0, 3.0)] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn user_spend_matches_python_update_many( + #[case] cost: f64, + #[case] expected_a_spend: f64, + #[case] expected_z_spend: f64, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + #[expect( + clippy::disallowed_methods, + reason = "Fixture writes are outside the compile-checked query set" + )] + let _inserted = sqlx::query( + r#"INSERT INTO "LiteLLM_UserTable" (user_id, spend, updated_at) + VALUES ('user-spend-a', 2, '2000-01-01'), + ('user-spend-z', 3, '2000-01-01'), + ('user-spend-untouched', 100, '2000-01-01')"#, + ) + .execute(&mut *tx) + .await?; + let spend = EntitySpend { + ids: vec![ + "user-spend-z".into(), + "user-spend-a".into(), + "user-spend-missing".into(), + ], + costs: vec![2.0 * cost, cost, 50.0], + }; + add_user_spend(&mut *tx, &EntitySpend::default()).await?; + add_user_spend(&mut *tx, &spend).await?; + add_user_spend(&mut *tx, &spend).await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let rows: Vec<(String, f64, bool)> = sqlx::query_as( + r#"SELECT user_id, spend, updated_at > TIMESTAMP '2000-01-01' + FROM "LiteLLM_UserTable" + WHERE user_id = ANY($1) ORDER BY user_id"#, + ) + .bind(vec![ + "user-spend-a", + "user-spend-z", + "user-spend-missing", + "user-spend-untouched", + ]) + .fetch_all(&mut *tx) + .await?; + assert_eq!( + rows, + vec![ + ("user-spend-a".into(), expected_a_spend, true), + ("user-spend-untouched".into(), 100.0, false), + ("user-spend-z".into(), expected_z_spend, true), + ] + ); + Ok(()) + } + + #[rstest] + #[case::direct_duplicate_batch(vec![0.25, 0.75], 3.0)] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn user_spend_sums_duplicate_ids( + #[case] costs: Vec, + #[case] expected_spend: f64, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + #[expect( + clippy::disallowed_methods, + reason = "Fixture writes are outside the compile-checked query set" + )] + let _inserted = sqlx::query( + r#"INSERT INTO "LiteLLM_UserTable" (user_id, spend, updated_at) + VALUES ('user-spend-duplicate', 2, '2000-01-01')"#, + ) + .execute(&mut *tx) + .await?; + let spend = EntitySpend { + ids: vec!["user-spend-duplicate".into(), "user-spend-duplicate".into()], + costs, + }; + add_user_spend(&mut *tx, &spend).await?; + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let row: (f64, bool) = sqlx::query_as( + r#"SELECT spend, updated_at > TIMESTAMP '2000-01-01' + FROM "LiteLLM_UserTable" WHERE user_id = 'user-spend-duplicate'"#, + ) + .fetch_one(&mut *tx) + .await?; + assert_eq!(row, (expected_spend, true)); + Ok(()) + } + + #[rstest] + #[case::missing_cost(vec![])] + #[case::extra_cost(vec![0.25, 0.75])] + #[tokio::test] + #[ignore = "requires DATABASE_URL pointing to a Prisma-migrated PostgreSQL database"] + async fn user_spend_rejects_malformed_batch_without_writes( + #[case] costs: Vec, + #[future(awt)] database_pool: Result>, + ) -> Result<(), Box> { + let pool = database_pool?; + let mut tx = pool.begin().await?; + #[expect( + clippy::disallowed_methods, + reason = "Fixture writes are outside the compile-checked query set" + )] + let _inserted = sqlx::query( + r#"INSERT INTO "LiteLLM_UserTable" (user_id, spend, updated_at) + VALUES ('user-spend-malformed', 2, '2000-01-01')"#, + ) + .execute(&mut *tx) + .await?; + let spend = EntitySpend { + ids: vec!["user-spend-malformed".into()], + costs, + }; + let result = add_user_spend(&mut *tx, &spend).await; + assert!(matches!(result, Err(Error::InvalidSpendBatch { .. }))); + #[expect( + clippy::disallowed_methods, + reason = "Test assertions are outside the compile-checked query set" + )] + let row: (f64, bool) = sqlx::query_as( + r#"SELECT spend, updated_at = TIMESTAMP '2000-01-01' + FROM "LiteLLM_UserTable" WHERE user_id = 'user-spend-malformed'"#, + ) + .fetch_one(&mut *tx) + .await?; + assert_eq!(row, (2.0, true)); + Ok(()) + } +} diff --git a/litellm-rust/crates/db/src/test_support.rs b/litellm-rust/crates/db/src/test_support.rs new file mode 100644 index 00000000000..992be4a4447 --- /dev/null +++ b/litellm-rust/crates/db/src/test_support.rs @@ -0,0 +1,10 @@ +use std::error::Error as StdError; + +use rstest::fixture; +use sqlx::PgPool; + +#[fixture] +pub async fn database_pool() -> Result> { + let database_url = std::env::var("DATABASE_URL")?; + Ok(PgPool::connect(&database_url).await?) +} diff --git a/litellm-rust/crates/gateway/AGENTS.md b/litellm-rust/crates/gateway/AGENTS.md index d54fa062f2b..a33bd19cc80 100644 --- a/litellm-rust/crates/gateway/AGENTS.md +++ b/litellm-rust/crates/gateway/AGENTS.md @@ -3,3 +3,10 @@ - Endpoint paths, request handling, model resolution, and response encoding belong to the mounted crates. Provider execution belongs to the `inference-` crates and `llms` - Inject shared state and infrastructure. Avoid global runtimes, duplicate client pools, and abstractions for hypothetical endpoint groups - Test mounting and server lifecycle through public HTTP behavior. Test endpoint semantics in the owning crate + +## Redis +- `build_redis` builds the Redis clients once at boot (`src/redis.rs`). Components get a clone as a field, never a per-request extractor or a pool. redis-rs multiplexes one connection per node, so there is no connection pool and pool settings like `max_connections` are accepted and ignored +- Which Redis backs which role mirrors the proxy: coordination is `general_settings.coordination_redis`, else the `cache_params` Redis when `cache: true` and `type: redis`, else `REDIS_*` env. The transaction buffer reuses coordination, else env when `use_redis_transaction_buffer` is on. The response cache gets its own client so large values never queue in front of coordination commands +- `litellm-config` follows `litellm/_redis.py`'s merge of config blocks and `REDIS_*` env. A redis-py setting we can't honor (sentinel, IAM, custom TLS files, ...) fails boot with its name, never silently dropped +- Boot never waits for a configured Redis (clients connect lazily). Only the env-only coordination fallback is pinged, for 2s, and treated as absent when unreachable, as in Python +- `/health/readiness` never touches Redis, matching the proxy diff --git a/litellm-rust/crates/gateway/Cargo.toml b/litellm-rust/crates/gateway/Cargo.toml index 387bcd43231..b2a2f09bfc7 100644 --- a/litellm-rust/crates/gateway/Cargo.toml +++ b/litellm-rust/crates/gateway/Cargo.toml @@ -19,6 +19,8 @@ litellm-gateway-auth.workspace = true litellm-gateway-ui.workspace = true litellm-auth-types.workspace = true litellm-config.workspace = true +litellm-circuit-breaker.workspace = true +litellm-redis-client.workspace = true litellm-http = { workspace = true, features = ["mcp"] } litellm-llms.workspace = true litellm-secrets.workspace = true @@ -31,6 +33,7 @@ uuid.workspace = true tower-sessions-moka-store = "0.15.0" [dev-dependencies] +litellm-redis-testing.workspace = true base64.workspace = true rstest.workspace = true tempfile.workspace = true diff --git a/litellm-rust/crates/gateway/src/error.rs b/litellm-rust/crates/gateway/src/error.rs index 75dc04d179d..170a8284c18 100644 --- a/litellm-rust/crates/gateway/src/error.rs +++ b/litellm-rust/crates/gateway/src/error.rs @@ -8,6 +8,15 @@ pub enum Error { McpSetting(String), #[error(transparent)] Mcp(#[from] litellm_gateway_mcp::ConnectError), + #[error(transparent)] + Config(#[from] litellm_config::Error), + #[error("invalid Redis setting {setting}: {reason}")] + RedisInvalid { + setting: &'static str, + reason: &'static str, + }, + #[error(transparent)] + RedisConnect(#[from] litellm_redis_client::ConnectError), #[error("MCP requires a configured master key")] Auth(#[from] litellm_gateway_auth::Error), } diff --git a/litellm-rust/crates/gateway/src/lib.rs b/litellm-rust/crates/gateway/src/lib.rs index 0b3aba81181..2ed2fc80a51 100644 --- a/litellm-rust/crates/gateway/src/lib.rs +++ b/litellm-rust/crates/gateway/src/lib.rs @@ -1,7 +1,9 @@ mod auth; mod error; +mod redis; mod secrets; pub use error::Error; +pub use redis::RedisClients; use std::{sync::Arc, time::Instant}; @@ -70,6 +72,17 @@ pub fn build_inference(config: &Config) -> Result, Error> { )?)) } +pub async fn build_redis(config: &Config) -> Result { + let environment = secrets::environment_values(&config.environment_variables)?; + let lookup = |name: &str| { + environment + .get(name) + .map(|value| value.expose().to_owned()) + .or_else(|| std::env::var(name).ok()) + }; + redis::connect(config, &lookup).await +} + pub async fn build_mcp( config: &Config, secrets: Arc, @@ -128,12 +141,17 @@ pub fn router( litellm_gateway_auth::authenticate, )) .layer(axum::middleware::from_fn(log_request)); + let health = Router::new().route("/health/readiness", axum::routing::get(readiness)); match ui { - Some(ui) => inference.merge(ui), - None => inference, + Some(ui) => inference.merge(ui).merge(health), + None => inference.merge(health), } } +async fn readiness() -> axum::Json { + axum::Json(serde_json::json!({"status": "healthy", "db": "Not connected"})) +} + async fn log_request(request: Request, next: Next) -> Response { let request_id = Uuid::new_v4().to_string(); let log_body_chunks = tracing::enabled!(tracing::Level::DEBUG); diff --git a/litellm-rust/crates/gateway/src/main.rs b/litellm-rust/crates/gateway/src/main.rs index f8150e6e860..47c1fe83f50 100644 --- a/litellm-rust/crates/gateway/src/main.rs +++ b/litellm-rust/crates/gateway/src/main.rs @@ -46,6 +46,7 @@ async fn main() -> Result<(), Box> { Logger::new(StderrSink { level }).install_global()?; let config = Config::load(settings.litellm_config)?; let inference = litellm_gateway::build_inference(&config)?; + let _redis = litellm_gateway::build_redis(&config).await?; let ui = match std::env::var_os("LITELLM_UI_PATH") { Some(directory) => { let ui_settings: UiSettings = settings::from_iter(std::env::vars_os())?; diff --git a/litellm-rust/crates/gateway/src/redis.rs b/litellm-rust/crates/gateway/src/redis.rs new file mode 100644 index 00000000000..197f40e7988 --- /dev/null +++ b/litellm-rust/crates/gateway/src/redis.rs @@ -0,0 +1,577 @@ +use std::time::Duration; + +use litellm_circuit_breaker::{Breaker, Config as BreakerConfig, State}; +use litellm_config::{ + CacheSettings, Config, Lookup, RedisEndpoint, RedisSettings, ResolvedRedis, Value, + environment_has_target, +}; +use litellm_redis_client::{ + ClusterEndpoint, ClusterNode, DEFAULT_TIMEOUT, Endpoint, HostEndpoint, Namespace, RedisClient, + RedisConfig, +}; + +use crate::Error; + +const ENVIRONMENT_PING_TIMEOUT: Duration = Duration::from_secs(2); +type Params = ResolvedRedis; + +pub struct RedisClients { + pub coordination: Option, + pub transaction_buffer: Option, + pub response_cache: Option, +} + +#[derive(Debug, PartialEq)] +pub(crate) struct Plan { + coordination: Option, + transaction_buffer_fallback: Option, + response_cache: Option, +} + +#[derive(Debug, PartialEq)] +enum Target { + Configured(Params), + Environment(Params), +} + +pub(crate) fn plan(config: &Config, lookup: Lookup<'_>) -> Result { + let response_cache = redis_cache_params(config) + .map(|settings| settings.resolve_cache(lookup)) + .transpose()?; + let coordination = match &config.general_settings.coordination_redis { + Some(settings) => Some(Target::Configured(settings.resolve(lookup)?)), + None => match (&response_cache, config.litellm_settings.cache == Some(true)) { + (Some(cache), _) => Some(Target::Configured(cache.clone())), + (None, true) => environment(lookup)?.map(Target::Configured), + (None, false) => optional_environment(lookup).map(Target::Environment), + }, + }; + let transaction_buffer_fallback = match (&coordination, use_transaction_buffer(config)) { + (Some(Target::Configured(_)), _) | (_, false) => None, + (Some(Target::Environment(_)) | None, true) => environment(lookup)?, + }; + Ok(Plan { + coordination, + transaction_buffer_fallback, + response_cache, + }) +} + +pub async fn connect(config: &Config, lookup: Lookup<'_>) -> Result { + let plan = plan(config, lookup)?; + let breaker = breaker_config(lookup)?; + let coordination = match plan.coordination { + Some(Target::Configured(params)) => Some(client(params, breaker)?), + Some(Target::Environment(params)) => match client(params, breaker) { + Ok(client) => reachable(client).await, + Err(_) => { + tracing::warn!( + "REDIS_* environment variables did not form a valid Redis client, cross-pod coordination stays in memory" + ); + None + } + }, + None => None, + }; + let transaction_buffer = match (&coordination, plan.transaction_buffer_fallback) { + (Some(coordination), _) => Some(coordination.clone()), + (None, Some(params)) => Some(client(params, breaker)?), + (None, None) => None, + }; + let response_cache = plan + .response_cache + .map(|params| client(params, breaker)) + .transpose()?; + Ok(RedisClients { + coordination, + transaction_buffer, + response_cache, + }) +} + +fn redis_cache_params(config: &Config) -> Option<&RedisSettings> { + let settings = &config.litellm_settings; + let params = settings.cache_params.as_ref()?; + match (settings.cache, params) { + (Some(true), CacheSettings::Redis(redis)) => Some(redis), + _ => None, + } +} + +fn environment(lookup: Lookup<'_>) -> Result, Error> { + match environment_has_target(lookup) { + true => RedisSettings::default() + .resolve(lookup) + .map(Some) + .map_err(Into::into), + false => Ok(None), + } +} + +fn optional_environment(lookup: Lookup<'_>) -> Option { + match environment(lookup) { + Ok(params) => params, + Err(error) => { + tracing::warn!(error = %error, "REDIS_* environment variables are invalid, cross-pod coordination stays in memory"); + None + } + } +} + +fn use_transaction_buffer(config: &Config) -> bool { + match config + .general_settings + .additional_fields + .get("use_redis_transaction_buffer") + { + Some(Value::Bool(enabled)) => *enabled, + Some(Value::String(text)) => matches!( + text.to_ascii_lowercase().as_str(), + "true" | "1" | "yes" | "on" + ), + _ => false, + } +} + +async fn reachable(client: RedisClient) -> Option { + match tokio::time::timeout(ENVIRONMENT_PING_TIMEOUT, client.ping()).await { + Ok(Ok(())) => Some(client), + Ok(Err(error)) => { + tracing::warn!(%error, "REDIS_* environment variables named a Redis that is not reachable, cross-pod coordination stays in memory"); + None + } + Err(_) => { + tracing::warn!( + "REDIS_* environment variables named a Redis that did not answer PING in 2s, cross-pod coordination stays in memory" + ); + None + } + } +} + +fn client(params: Params, breaker: Option) -> Result { + tracing::info!(endpoint = ?params.endpoint, namespace = ?params.namespace, "redis client configured"); + let endpoint = match params.endpoint { + RedisEndpoint::Url(url) => Endpoint::Url(url.expose().to_owned()), + RedisEndpoint::Host(host) => Endpoint::Host(HostEndpoint { + host: host.host, + port: host.port, + username: host.username.map(|value| value.expose().to_owned()), + password: host.password.map(|value| value.expose().to_owned()), + tls: host.tls, + db: host.db, + }), + RedisEndpoint::Cluster(cluster) => Endpoint::Cluster(ClusterEndpoint { + nodes: cluster + .nodes + .into_iter() + .map(|node| ClusterNode { + host: node.host, + port: node.port, + }) + .collect(), + username: cluster.username.map(|value| value.expose().to_owned()), + password: cluster.password.map(|value| value.expose().to_owned()), + tls: cluster.tls, + }), + }; + Ok(RedisClient::new(RedisConfig { + endpoint, + namespace: params.namespace.map(Namespace::new).unwrap_or_default(), + timeout: params.timeout.unwrap_or(DEFAULT_TIMEOUT), + breaker: breaker.map(|config| Breaker::new(config, Box::new(log_transition))), + })?) +} + +fn log_transition(transition: &litellm_circuit_breaker::Transition) { + match transition.to { + State::Open { .. } => tracing::warn!( + generation = transition.generation, + "redis circuit breaker opened, fast-failing redis calls" + ), + State::HalfOpen => tracing::info!( + generation = transition.generation, + "redis circuit breaker half open, probing redis" + ), + State::Closed { .. } => tracing::info!( + generation = transition.generation, + "redis circuit breaker closed, redis recovered" + ), + } +} + +fn breaker_config(lookup: Lookup<'_>) -> Result, Error> { + let enabled = lookup("REDIS_CIRCUIT_BREAKER_ENABLED") + .is_none_or(|value| value.eq_ignore_ascii_case("true")); + if !enabled { + return Ok(None); + } + let defaults = BreakerConfig::default(); + let seconds = |name: &'static str, default: Duration| -> Result { + lookup(name) + .map(|value| { + value + .parse::() + .ok() + .and_then(|seconds| Duration::try_from_secs_f64(seconds).ok()) + .ok_or(Error::RedisInvalid { + setting: name, + reason: "must be a non-negative number of seconds", + }) + }) + .unwrap_or(Ok(default)) + }; + let failure_threshold = lookup("REDIS_CIRCUIT_BREAKER_FAILURE_THRESHOLD") + .map(|value| { + value.parse().map_err(|_| Error::RedisInvalid { + setting: "REDIS_CIRCUIT_BREAKER_FAILURE_THRESHOLD", + reason: "must be an integer", + }) + }) + .unwrap_or(Ok(defaults.failure_threshold))?; + Ok(Some(BreakerConfig { + failure_threshold, + recovery_timeout: seconds( + "REDIS_CIRCUIT_BREAKER_RECOVERY_TIMEOUT", + defaults.recovery_timeout, + )?, + timeout_min_duration: seconds( + "REDIS_CIRCUIT_BREAKER_TIMEOUT_MIN_DURATION", + defaults.timeout_min_duration, + )?, + })) +} + +#[cfg(test)] +mod tests { + use std::{collections::HashMap, time::Duration}; + + use litellm_config::{Config, RedisEndpoint, RedisHost}; + use litellm_redis_testing::RedisServer; + use rstest::rstest; + + use super::{Params, Plan, Target, connect, plan}; + use crate::Error; + + fn host(name: &str, port: u16) -> Params { + Params { + endpoint: RedisEndpoint::Host(RedisHost { + host: name.to_owned(), + port, + username: None, + password: None, + tls: false, + db: 0, + }), + namespace: None, + timeout: None, + } + } + + fn resolved(yaml: &str, environment: &[(&str, &str)]) -> Result { + let environment: HashMap = environment + .iter() + .map(|(key, value)| ((*key).to_owned(), (*value).to_owned())) + .collect(); + plan(&Config::from_yaml(yaml).unwrap(), &|name| { + environment.get(name).cloned() + }) + } + + fn configured(coordination: Params, response_cache: Option) -> Plan { + Plan { + coordination: Some(Target::Configured(coordination)), + transaction_buffer_fallback: None, + response_cache, + } + } + + const NO_REDIS: Plan = Plan { + coordination: None, + transaction_buffer_fallback: None, + response_cache: None, + }; + + #[rstest] + #[case::nothing_configured("model_list: []", &[], NO_REDIS)] + #[case::coordination_block_wins_over_the_cache_redis( + "general_settings:\n coordination_redis:\n host: coord\nlitellm_settings:\n cache: true\n cache_params:\n type: redis\n host: cache", + &[], + configured(host("coord", 6379), Some(host("cache", 6379))) + )] + #[case::cache_params_without_cache_true_are_unused( + "litellm_settings:\n cache_params:\n type: redis\n host: cache", + &[], + NO_REDIS + )] + #[case::non_redis_cache_takes_coordination_from_the_environment_without_a_ping( + "litellm_settings:\n cache: true\n cache_params:\n type: local", + &[("REDIS_HOST", "env")], + configured(host("env", 6379), None) + )] + #[case::environment_only_coordination_is_probed( + "model_list: []", + &[("REDIS_HOST", "env")], + Plan { coordination: Some(Target::Environment(host("env", 6379))), transaction_buffer_fallback: None, response_cache: None } + )] + #[case::the_transaction_buffer_falls_back_to_the_environment_only_when_enabled( + "general_settings:\n use_redis_transaction_buffer: \"true\"", + &[("REDIS_HOST", "env")], + Plan { coordination: Some(Target::Environment(host("env", 6379))), transaction_buffer_fallback: Some(host("env", 6379)), response_cache: None } + )] + fn resolves_each_redis_role_like_the_proxy( + #[case] yaml: &str, + #[case] environment: &[(&str, &str)], + #[case] expected: Plan, + ) { + assert_eq!(resolved(yaml, environment).unwrap(), expected); + } + + #[rstest] + fn redis_migration_regression_preserves_borrowed_cache_namespace() { + let yaml = "litellm_settings:\n cache: true\n cache_params:\n type: redis\n host: cache\n namespace: responses\n ttl: 600"; + let cache = Params { + namespace: Some("responses".to_owned()), + ..host("cache", 6379) + }; + + assert_eq!( + resolved(yaml, &[]).unwrap(), + configured(cache.clone(), Some(cache)) + ); + } + + #[rstest] + #[tokio::test] + async fn borrowed_coordination_and_transaction_buffer_share_the_cache_namespace() { + let server = RedisServer::start().await.unwrap(); + let config = Config::from_yaml(&format!( + "litellm_settings:\n cache: true\n cache_params:\n type: redis\n host: 127.0.0.1\n port: {}\n namespace: responses", + port_of(&server) + )) + .unwrap(); + let clients = connect(&config, &|_| None).await.unwrap(); + let coordination = clients.coordination.unwrap(); + let buffer = clients.transaction_buffer.unwrap(); + let cache = clients.response_cache.unwrap(); + let unnamespaced = connect(&coordination_config(&server), &|_| None) + .await + .unwrap() + .coordination + .unwrap(); + + coordination + .set("rate-limit", "1", Duration::from_secs(60)) + .await + .unwrap(); + buffer + .set("spend", "2", Duration::from_secs(60)) + .await + .unwrap(); + + assert_eq!( + cache.get::("rate-limit").await.unwrap().as_deref(), + Some("1") + ); + assert_eq!( + cache.get::("spend").await.unwrap().as_deref(), + Some("2") + ); + assert_eq!( + unnamespaced + .get::("responses:rate-limit") + .await + .unwrap() + .as_deref(), + Some("1") + ); + assert_eq!( + unnamespaced + .get::("responses:spend") + .await + .unwrap() + .as_deref(), + Some("2") + ); + assert!( + unnamespaced + .get::("rate-limit") + .await + .unwrap() + .is_none() + ); + assert!(unnamespaced.get::("spend").await.unwrap().is_none()); + } + + #[rstest] + #[case::malformed_port(&[("REDIS_HOST", "env"), ("REDIS_PORT", "not-a-port")])] + #[case::malformed_cluster_nodes(&[("REDIS_CLUSTER_NODES", "[{\"host\": ")])] + fn redis_migration_regression_malformed_optional_environment_is_absent( + #[case] environment: &[(&str, &str)], + ) { + assert_eq!(resolved("model_list: []", environment).unwrap(), NO_REDIS); + } + + #[rstest] + fn redis_migration_regression_explicit_malformed_setting_still_fails() { + let error = resolved( + "general_settings:\n coordination_redis:\n host: coord\n port: not-a-port", + &[], + ) + .unwrap_err(); + + assert!(matches!( + error, + Error::Config(litellm_config::Error::RedisInvalid { + setting: "port", + .. + }) + )); + } + + #[rstest] + fn redis_migration_regression_enabled_transaction_buffer_rejects_invalid_environment() { + let error = resolved( + "general_settings:\n use_redis_transaction_buffer: true", + &[("REDIS_HOST", "env"), ("REDIS_PORT", "not-a-port")], + ) + .unwrap_err(); + + assert!(matches!( + error, + Error::Config(litellm_config::Error::RedisInvalid { + setting: "port", + .. + }) + )); + } + + #[rstest] + fn redis_migration_regression_invalid_response_cache_still_fails() { + let error = resolved( + "litellm_settings:\n cache: true\n cache_params:\n type: redis\n host: cache\n port: not-a-port", + &[], + ) + .unwrap_err(); + + assert!(matches!( + error, + Error::Config(litellm_config::Error::RedisInvalid { + setting: "port", + .. + }) + )); + } + + #[rstest] + #[tokio::test] + async fn redis_migration_regression_invalid_optional_environment_url_is_absent() { + let config = Config::from_yaml("model_list: []").unwrap(); + + let clients = connect(&config, &|name| { + (name == "REDIS_URL").then(|| "not a redis URL".to_owned()) + }) + .await + .unwrap(); + + assert!(clients.coordination.is_none()); + } + + fn port_of(server: &RedisServer) -> String { + server.url().rsplit(':').next().unwrap().to_owned() + } + + fn coordination_config(server: &RedisServer) -> Config { + Config::from_yaml(&format!( + "general_settings:\n coordination_redis:\n host: 127.0.0.1\n port: {}\n socket_timeout: 0.5", + port_of(server) + )) + .unwrap() + } + + async fn eventually_pings(client: &litellm_redis_client::RedisClient) -> bool { + let deadline = tokio::time::Instant::now() + Duration::from_secs(30); + while tokio::time::Instant::now() < deadline { + if client.ping().await.is_ok() { + return true; + } + tokio::time::sleep(Duration::from_millis(200)).await; + } + false + } + + #[rstest] + #[tokio::test] + async fn boot_does_not_wait_for_a_configured_redis_that_is_down() { + let server = RedisServer::start().await.unwrap(); + server.stop().await.unwrap(); + + let clients = connect(&coordination_config(&server), &|_| None) + .await + .unwrap(); + let coordination = clients.coordination.unwrap(); + let while_down = coordination.ping().await; + server.resume().await.unwrap(); + + assert!(while_down.is_err()); + assert!(eventually_pings(&coordination).await); + } + + #[rstest] + #[tokio::test] + async fn the_coordination_client_survives_a_redis_restart_and_backs_the_transaction_buffer() { + let server = RedisServer::start().await.unwrap(); + let clients = connect(&coordination_config(&server), &|_| None) + .await + .unwrap(); + let coordination = clients.coordination.unwrap(); + coordination + .set("written", "1", Duration::from_secs(60)) + .await + .unwrap(); + + server.restart().await.unwrap(); + + assert!(eventually_pings(&coordination).await); + let buffer = clients.transaction_buffer.unwrap(); + assert!(buffer.ping().await.is_ok()); + } + + #[rstest] + #[tokio::test] + async fn an_unreachable_environment_only_redis_leaves_coordination_in_memory() { + let server = RedisServer::start().await.unwrap(); + let port = port_of(&server); + server.stop().await.unwrap(); + let config = Config::from_yaml("model_list: []").unwrap(); + + let clients = connect(&config, &|name| match name { + "REDIS_HOST" => Some("127.0.0.1".to_owned()), + "REDIS_PORT" => Some(port.clone()), + _ => None, + }) + .await + .unwrap(); + + assert!(clients.coordination.is_none()); + assert!(clients.transaction_buffer.is_none()); + } + + #[rstest] + #[tokio::test] + async fn a_reachable_environment_only_redis_becomes_coordination() { + let server = RedisServer::start().await.unwrap(); + let port = port_of(&server); + let config = Config::from_yaml("model_list: []").unwrap(); + + let clients = connect(&config, &|name| match name { + "REDIS_HOST" => Some("127.0.0.1".to_owned()), + "REDIS_PORT" => Some(port.clone()), + _ => None, + }) + .await + .unwrap(); + + assert!(clients.coordination.unwrap().ping().await.is_ok()); + } +} diff --git a/litellm-rust/crates/gateway/tests/server.rs b/litellm-rust/crates/gateway/tests/server.rs index 71edd3c3650..53a97e7098c 100644 --- a/litellm-rust/crates/gateway/tests/server.rs +++ b/litellm-rust/crates/gateway/tests/server.rs @@ -287,3 +287,33 @@ async fn ui_routes_are_absent_when_not_mounted( .unwrap(); assert_eq!(response.status().as_u16(), 404); } + +#[rstest] +#[case::with_master_key("model_list: []\ngeneral_settings:\n master_key: gateway-key\n")] +#[case::without_master_key("model_list: []\n")] +#[tokio::test] +async fn readiness_answers_without_credentials_like_the_proxy_with_no_database( + inference: Arc, + #[case] yaml: &str, +) { + let config = Config::from_yaml(yaml).unwrap(); + let app = litellm_gateway::router(inference, &config, None, None); + + let response = app + .oneshot( + Request::get("/health/readiness") + .body(Body::empty()) + .unwrap(), + ) + .await + .unwrap(); + + assert_eq!(response.status().as_u16(), 200); + let body = axum::body::to_bytes(response.into_body(), 1024) + .await + .unwrap(); + assert_eq!( + serde_json::from_slice::(&body).unwrap(), + json!({"status": "healthy", "db": "Not connected"}) + ); +} diff --git a/litellm-rust/crates/inference-messages/src/common_utils.rs b/litellm-rust/crates/inference-messages/src/common_utils.rs index 7394d7ae21e..9be7ee6ffc3 100644 --- a/litellm-rust/crates/inference-messages/src/common_utils.rs +++ b/litellm-rust/crates/inference-messages/src/common_utils.rs @@ -6,7 +6,7 @@ use litellm_llms::{ anthropic::messages::transformation::ANTHROPIC_MESSAGES_CONFIG, azure_ai::messages::transformation::AZURE_ANTHROPIC_MESSAGES_CONFIG, base_llm::messages::transformation::BaseMessagesConfig, - bedrock::messages::invoke_transformations::anthropic_claude3_transformation::BEDROCK_ANTHROPIC_MESSAGES_CONFIG, + bedrock::messages::invoke_transformations::anthropic_claude_transformation::BEDROCK_ANTHROPIC_MESSAGES_CONFIG, deepseek::messages::transformation::DEEPSEEK_ANTHROPIC_MESSAGES_CONFIG, edenai::messages::transformation::EDENAI_MESSAGES_CONFIG, minimax::messages::transformation::MINIMAX_MESSAGES_CONFIG, diff --git a/litellm-rust/crates/llms/src/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.rs b/litellm-rust/crates/llms/src/bedrock/messages/invoke_transformations/anthropic_claude_transformation.rs similarity index 100% rename from litellm-rust/crates/llms/src/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.rs rename to litellm-rust/crates/llms/src/bedrock/messages/invoke_transformations/anthropic_claude_transformation.rs diff --git a/litellm-rust/crates/llms/src/bedrock/messages/invoke_transformations/mod.rs b/litellm-rust/crates/llms/src/bedrock/messages/invoke_transformations/mod.rs index 4d67a0c0696..68ceaac3444 100644 --- a/litellm-rust/crates/llms/src/bedrock/messages/invoke_transformations/mod.rs +++ b/litellm-rust/crates/llms/src/bedrock/messages/invoke_transformations/mod.rs @@ -1 +1 @@ -pub mod anthropic_claude3_transformation; +pub mod anthropic_claude_transformation; diff --git a/litellm-rust/crates/python-bridge/Cargo.toml b/litellm-rust/crates/python-bridge/Cargo.toml index 6fc05c43146..8afde8362f6 100644 --- a/litellm-rust/crates/python-bridge/Cargo.toml +++ b/litellm-rust/crates/python-bridge/Cargo.toml @@ -53,7 +53,7 @@ pyo3.workspace = true prost.workspace = true pyo3-async-runtimes.workspace = true reqwest.workspace = true -redis = { version = "1.7.0", features = ["tls-rustls"] } +redis = { workspace = true, features = ["tls-rustls"] } serde_json.workspace = true strum.workspace = true veil.workspace = true diff --git a/litellm-rust/crates/python-bridge/src/secrets/provider.rs b/litellm-rust/crates/python-bridge/src/secrets/provider.rs index 568a0cd2228..5f4cd193fcf 100644 --- a/litellm-rust/crates/python-bridge/src/secrets/provider.rs +++ b/litellm-rust/crates/python-bridge/src/secrets/provider.rs @@ -88,20 +88,23 @@ fn aws_context( } fn read_timeout(value: Option<&Bound<'_, PyAny>>) -> PyResult> { - let Some(value) = value.filter(|value| !value.is_none()) else { - return Ok(None); - }; - let seconds = match value.extract::() { - Ok(value) => Some(value), - Err(_) => value.getattr("read")?.extract::>()?, - }; - seconds + read_timeout_seconds(value)? .map(|value| { Duration::try_from_secs_f64(value).map_err(|_| PyValueError::new_err("invalid timeout")) }) .transpose() } +pub(super) fn read_timeout_seconds(value: Option<&Bound<'_, PyAny>>) -> PyResult> { + let Some(value) = value.filter(|value| !value.is_none()) else { + return Ok(None); + }; + match value.extract::() { + Ok(value) => Ok(Some(value)), + Err(_) => value.getattr("read")?.extract::>(), + } +} + fn vault_context(params: Option<&Bound<'_, PyAny>>) -> PyResult { let params = params.and_then(|value| value.cast::().ok()); let nested = params diff --git a/litellm-rust/crates/python-bridge/src/secrets/vault.rs b/litellm-rust/crates/python-bridge/src/secrets/vault.rs index 46b29839fe4..79281662848 100644 --- a/litellm-rust/crates/python-bridge/src/secrets/vault.rs +++ b/litellm-rust/crates/python-bridge/src/secrets/vault.rs @@ -2,10 +2,12 @@ mod operation; pub(super) use operation::{Failure, FailureKind, FailureStage, delete, rotate, write}; +use litellm_core_utils::exception_mapping_utils::{TimeoutPhase, timeout_message}; use litellm_secrets::hashicorp::{Error, RawOperationError}; use pyo3::prelude::*; use super::mutation::{error_value, http_message, json_value}; +use super::provider::read_timeout_seconds; const HTTP_TRANSPORT_MODULE: &str = "litellm.rust_bridge.host.http_transport"; @@ -69,21 +71,17 @@ fn cause_message(py: Python<'_>, kind: FailureKind, context: &ErrorContext) -> P } FailureKind::Native(RawOperationError::Timeout { method, elapsed }) => { if method == "POST" { - let elapsed = py - .import("builtins")? - .call_method1("round", (elapsed.as_secs_f64(), 3))?; let kwargs = pyo3::types::PyDict::new(py); kwargs.set_item( "message", - format!( - "Connection timed out. Timeout passed={}, time taken={} seconds", - context.timeout.as_deref().unwrap_or("None"), - elapsed.str()? + timeout_message( + TimeoutPhase::Read, + context.timeout, + Some(elapsed.as_secs_f64()), ), )?; kwargs.set_item("model", "default-model-name")?; kwargs.set_item("llm_provider", "litellm-httpx-handler")?; - kwargs.set_item("headers", pyo3::types::PyDict::new(py))?; py.import("litellm.exceptions")? .getattr("Timeout")? .call((), Some(&kwargs))? @@ -159,7 +157,7 @@ fn response_text(py: Python<'_>, body: &[u8]) -> PyResult { #[derive(Default)] pub(super) struct ErrorContext { - timeout: Option, + timeout: Option, aiohttp: bool, } @@ -173,7 +171,7 @@ impl ErrorContext { return Ok(Self::default()); } Ok(Self { - timeout: timeout.map(|value| value.str()?.extract()).transpose()?, + timeout: read_timeout_seconds(timeout)?, aiohttp: py .import(HTTP_TRANSPORT_MODULE)? .getattr("uses_aiohttp_transport")? diff --git a/litellm-rust/crates/redis-client/AGENTS.md b/litellm-rust/crates/redis-client/AGENTS.md new file mode 100644 index 00000000000..c73a4ed8c4d --- /dev/null +++ b/litellm-rust/crates/redis-client/AGENTS.md @@ -0,0 +1,43 @@ +- The one async Redis client for the gateway and the Rust cache crates. It owns connecting, timeouts, error classes and the key namespace +- It knows nothing about domains, so key builders, TTL policy, value formats and fallback decisions stay in the crate that owns the state. Every write takes its TTL from the caller, and there is no default +- Async only. Build one `RedisClient` per Redis instance at the process boundary and clone it. Never add a pool, a sync API, `spawn_blocking`, or a client built inside a route +- Set every redis-rs timeout and retry explicitly. Its defaults (500ms response, 1s connect, 6 reconnect retries) are not the Python proxy's (5s socket timeout from `REDIS_SOCKET_TIMEOUT`) +- Resolving config from `config.yaml` / `REDIS_*` env the way `litellm/_redis.py` does belongs to the consumer that reads that config, not here. `RedisConfig` takes already-resolved values + +## Errors +- `Transport`, `Server`, `Decode`, each wrapping the redis-rs error as `#[source]`. `ConnectError` is separate because only `connect` returns it +- Classify in `From for Error` by `ErrorKind`. LOADING, CLUSTERDOWN, MASTERDOWN, TRYAGAIN and READONLY are typed server replies, but they mean the node can't serve right now, so they are `Transport`. Codes redis-rs doesn't type (WRONGTYPE) come back as `ErrorKind::Extension` and are `Server`. Each code gets its own rstest case built from a parsed RESP error +- A `Server` error never drops the connection +- `Transport` includes timeouts, where the command may still have applied. Callers of counters and locks treat it as an unknown outcome +- Never swallow an error or turn it into a miss. The caller picks the fallback +- Reads return `Option`: a missing key is `None`, and a value that doesn't decode to `T` (`"15.0"` as `i64`) is `Decode` + +## Circuit breaker +- The `litellm-circuit-breaker` `Breaker` is injected through `RedisConfig::breaker` and shared by every clone. `None` turns it off +- Every public call (each command, `eval`, one `run` of a pipeline) takes one admission through `guarded` / `admit` in `client.rs`. Never call the connection around it +- `Transport` counts as a failure (`Timeout` when `is_timeout()`, else `Hard`). `Server` and `Decode` count as nothing, since Redis answered and the request was bad. A probe that gets one still reopens, through the dropped-probe rule in `circuit-breaker`. A pipeline counts one failure if any op came back `Transport`, else one success +- An open breaker returns `Error::BreakerOpen` without touching the socket +- Python doesn't count MASTERDOWN, TRYAGAIN or READONLY as health failures. Here they are `Transport` and do count + +## Namespace +- Applied once, here, to every key. A key that already starts with `{namespace}:` is left alone, matching `RedisCache.check_and_fix_namespace` +- The rule never changes, because Python and Rust pods share keys in the same Redis + +## Commands +- One typed method per command, built with `redis::cmd`. Empty batches (MGET, DEL) return without a round trip, since Redis rejects an empty MGET +- On cluster, redis-rs splits MGET and DEL by slot and returns MGET values in input order. Other multi-key commands are not split, so a new one needs a cross-slot test +- TTLs are `Duration` and are sent in milliseconds (`PX`, `PEXPIRE`, `PTTL`) + +## Scripts and pipelines +- A `Script` declares every key it touches in KEYS. On cluster an undeclared key works or fails depending on which node owns its slot, so it can pass tests and break in production +- `eval` goes through redis-rs `invoke_async`, which loads the script on NOSCRIPT. Inside a pipeline nothing reloads, so a NOSCRIPT op reruns alone with `invoke_async` +- A pipeline is never atomic. Every op gets its own `Result`, from `.ignore_errors()`, so one rejected op leaves the others alone. A transport failure fails every op of that round trip +- redis-rs rejects an async cluster pipeline whose ops span slots. `Pipeline` groups ops by the slot of their first key, runs the groups concurrently and returns results in input order +- Pipeline ops take one key each. A multi-key op would span slots inside one group +- Command builders live in `commands.rs` and are shared by `RedisClient` and `Pipeline`, so a command is written once + +## Tests +- Against real Redis from `litellm-redis-testing`, never a mocked wire or asserted command bytes +- Every command test runs on each topology through `#[values(Topology::Standalone, Topology::Cluster)]`. A test is single-topology only when the behavior exists on one (a `db` number has no cluster meaning) +- Assert values and Redis state. Outages come from the container (`restart`, `freeze` / `thaw`), not `DEBUG`, which the official image disables +- Use a short client timeout in outage tests so they stay fast. Never sleep to wait for a state; poll with a deadline diff --git a/litellm-rust/crates/redis-client/Cargo.toml b/litellm-rust/crates/redis-client/Cargo.toml new file mode 100644 index 00000000000..eab57b36423 --- /dev/null +++ b/litellm-rust/crates/redis-client/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "litellm-redis-client" +version = "0.1.0" +edition.workspace = true +license.workspace = true +repository.workspace = true + +[dependencies] +litellm-circuit-breaker.workspace = true +futures-util.workspace = true +redis = { workspace = true, features = ["cluster-async", "connection-manager", "tokio-rustls-comp"] } +thiserror.workspace = true + +[dev-dependencies] +litellm-redis-testing.workspace = true +rstest.workspace = true +tokio.workspace = true diff --git a/litellm-rust/crates/redis-client/src/client.rs b/litellm-rust/crates/redis-client/src/client.rs new file mode 100644 index 00000000000..a02b0847663 --- /dev/null +++ b/litellm-rust/crates/redis-client/src/client.rs @@ -0,0 +1,647 @@ +use std::{ + future::Future, + time::{Duration, Instant}, +}; + +use litellm_circuit_breaker::{Admission, Breaker, Failure}; +use redis::{Cmd, FromRedisValue, IntoConnectionInfo, ToRedisArgs, ToSingleRedisArg, Value}; + +use crate::{ + ConnectError, Endpoint, Error, Namespace, Pipeline, RedisConfig, Script, commands, + connection::Connection, +}; + +#[derive(Clone)] +pub struct RedisClient { + pub(crate) connection: Connection, + namespace: Namespace, + breaker: Option, +} + +#[derive(Debug, PartialEq, Eq)] +pub enum Ttl { + Missing, + Persistent, + Expires(Duration), +} + +impl RedisClient { + pub fn new(config: RedisConfig) -> Result { + let connection = match &config.endpoint { + Endpoint::Url(url) => { + Connection::standalone(url.as_str().into_connection_info()?, config.timeout)? + } + Endpoint::Host(host) => { + Connection::standalone(host.connection_info()?, config.timeout)? + } + Endpoint::Cluster(cluster) => Connection::cluster(cluster, config.timeout)?, + }; + Ok(Self { + connection, + namespace: config.namespace, + breaker: config.breaker, + }) + } + + pub async fn ping(&self) -> Result<(), Error> { + self.query(&commands::ping()).await + } + + pub async fn get(&self, key: &str) -> Result, Error> { + self.query(&commands::get(self.key(key))).await + } + + pub async fn mget(&self, keys: &[&str]) -> Result>, Error> { + if keys.is_empty() { + return Ok(Vec::new()); + } + self.query(&commands::mget(self.keys(keys))).await + } + + pub async fn set( + &self, + key: &str, + value: impl ToSingleRedisArg, + ttl: Duration, + ) -> Result<(), Error> { + self.query(&commands::set(self.key(key), value, ttl)).await + } + + pub async fn set_nx( + &self, + key: &str, + value: impl ToSingleRedisArg, + ttl: Duration, + ) -> Result { + let reply: Option = self + .query(&commands::set_nx(self.key(key), value, ttl)) + .await?; + Ok(reply.is_some()) + } + + pub async fn del(&self, keys: &[&str]) -> Result { + if keys.is_empty() { + return Ok(0); + } + self.query(&commands::del(self.keys(keys))).await + } + + pub async fn expire(&self, key: &str, ttl: Duration) -> Result { + self.query(&commands::expire(self.key(key), ttl)).await + } + + pub async fn ttl(&self, key: &str) -> Result { + let reply: i64 = self.query(&commands::ttl(self.key(key))).await?; + Ok(match reply { + -2 => Ttl::Missing, + -1 => Ttl::Persistent, + millis => Ttl::Expires(Duration::from_millis(millis.unsigned_abs())), + }) + } + + pub async fn incr_by(&self, key: &str, delta: i64) -> Result { + self.query(&commands::incr_by(self.key(key), delta)).await + } + + pub async fn incr_by_float(&self, key: &str, delta: f64) -> Result { + self.query(&commands::incr_by_float(self.key(key), delta)) + .await + } + + pub async fn rpush(&self, key: &str, values: impl ToRedisArgs) -> Result { + self.query(&commands::rpush(self.key(key), values)).await + } + + pub async fn eval( + &self, + script: &Script, + keys: &[&str], + args: impl ToRedisArgs, + ) -> Result { + let keys = self.keys(keys); + let args = args.to_redis_args(); + self.guarded(async { + Ok(script + .invocation(&keys, &args) + .invoke_async(&mut self.connection.clone()) + .await?) + }) + .await + } + + pub fn pipeline(&self) -> Pipeline { + Pipeline::new(self.namespace.clone()) + } + + pub async fn run(&self, pipeline: &Pipeline) -> Vec> { + let admission = match self.admit() { + Ok(admission) => admission, + Err(_) => { + return (0..pipeline.len()) + .map(|_| Err(Error::BreakerOpen)) + .collect(); + } + }; + let results = pipeline.run(&self.connection).await; + let transport = results.iter().find_map(|result| { + result + .as_ref() + .err() + .filter(|error| matches!(error, Error::Transport(_))) + }); + settle(admission, transport); + results + } + + fn key(&self, key: &str) -> String { + self.namespace.apply(key) + } + + fn keys(&self, keys: &[&str]) -> Vec { + keys.iter().map(|key| self.key(key)).collect() + } + + async fn query(&self, command: &Cmd) -> Result { + self.guarded(async { Ok(command.query_async(&mut self.connection.clone()).await?) }) + .await + } + + async fn guarded(&self, call: impl Future>) -> Result { + let admission = self.admit()?; + let result = call.await; + settle(admission, result.as_ref().err()); + result + } + + fn admit(&self) -> Result, Error> { + self.breaker + .as_ref() + .map(|breaker| { + breaker + .admit(Instant::now()) + .map_err(|_| Error::BreakerOpen) + }) + .transpose() + } +} + +fn settle(admission: Option, error: Option<&Error>) { + let Some(admission) = admission else { + return; + }; + match error { + None => admission.succeeded(), + Some(Error::Transport(error)) if error.is_timeout() => { + admission.failed(Failure::Timeout, Instant::now()) + } + Some(Error::Transport(_)) => admission.failed(Failure::Hard, Instant::now()), + Some(Error::Server(_) | Error::Decode(_) | Error::BreakerOpen) => drop(admission), + } +} + +#[cfg(test)] +mod tests { + use std::time::{Duration, Instant}; + + use litellm_redis_testing::RedisServer; + use rstest::rstest; + + use litellm_circuit_breaker::{Breaker, Config, State}; + + use super::{RedisClient, Ttl}; + use crate::{ + DEFAULT_TIMEOUT, Endpoint, Error, HostEndpoint, Namespace, RedisConfig, + test_support::{Server, Topology, client_id}, + }; + + #[rstest] + #[tokio::test] + async fn namespaces_isolate_keys_on_the_server( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let a = server.client("a", DEFAULT_TIMEOUT).await; + let b = server.client("b", DEFAULT_TIMEOUT).await; + let bare = server.client("", DEFAULT_TIMEOUT).await; + + a.set("x", "1", Duration::from_secs(60)).await.unwrap(); + + assert_eq!(a.get::("x").await.unwrap().as_deref(), Some("1")); + assert_eq!(a.get::("a:x").await.unwrap().as_deref(), Some("1")); + assert_eq!( + bare.get::("a:x").await.unwrap().as_deref(), + Some("1") + ); + assert_eq!(b.get::("x").await.unwrap(), None); + } + + #[rstest] + #[tokio::test] + async fn a_rejected_command_keeps_the_connection( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let client = server.client("", DEFAULT_TIMEOUT).await; + client.rpush("list", "item").await.unwrap(); + let before = client_id(&client, "list").await; + + let rejected = client.incr_by("list", 1).await; + + assert!(matches!(rejected, Err(Error::Server(_))), "{rejected:?}"); + assert_eq!(client.rpush("list", "next").await.unwrap(), 2); + assert_eq!(client_id(&client, "list").await, before); + } + + #[rstest] + #[tokio::test] + async fn a_reply_of_another_type_is_a_decode_error_and_a_missing_key_is_none( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let client = server.client("", DEFAULT_TIMEOUT).await; + client + .set("float", "15.0", Duration::from_secs(60)) + .await + .unwrap(); + + let decoded = client.get::("float").await; + + assert!(matches!(decoded, Err(Error::Decode(_))), "{decoded:?}"); + assert_eq!(client.get::("missing").await.unwrap(), None); + } + + #[rstest] + #[tokio::test] + async fn a_timed_out_command_does_not_leak_its_reply_into_the_next_one( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let client = server.client("", Duration::from_millis(500)).await; + client + .set("first", "1", Duration::from_secs(60)) + .await + .unwrap(); + client + .set("second", "2", Duration::from_secs(60)) + .await + .unwrap(); + + server.freeze().await; + let timed_out = client.get::("first").await; + server.thaw().await; + + assert!( + matches!(timed_out, Err(Error::Transport(_))), + "{timed_out:?}" + ); + assert_eq!( + client.get::("second").await.unwrap().as_deref(), + Some("2") + ); + } + + #[rstest] + #[tokio::test] + async fn the_same_client_recovers_after_redis_restarts( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let client = server.client("", Duration::from_millis(500)).await; + + server.restart().await; + + let deadline = Instant::now() + Duration::from_secs(30); + let recovered = loop { + match client.incr_by("after_restart", 1).await { + Ok(value) => break Some(value), + Err(_) if Instant::now() < deadline => { + tokio::time::sleep(Duration::from_millis(200)).await + } + Err(_) => break None, + } + }; + assert_eq!(recovered, Some(1)); + } + + #[rstest] + #[tokio::test] + async fn a_client_created_while_redis_is_down_works_once_redis_is_up( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + server.stop().await; + + let client = server.client("", Duration::from_millis(500)).await; + let while_down = client.ping().await; + server.resume().await; + + assert!( + matches!(while_down, Err(Error::Transport(_))), + "{while_down:?}" + ); + let deadline = Instant::now() + Duration::from_secs(30); + let recovered = loop { + match client.ping().await { + Ok(()) => break true, + Err(_) if Instant::now() < deadline => { + tokio::time::sleep(Duration::from_millis(200)).await + } + Err(_) => break false, + } + }; + assert!(recovered); + } + + #[rstest] + #[tokio::test] + async fn empty_batches_succeed_without_asking_redis( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let client = server.client("", DEFAULT_TIMEOUT).await; + + assert_eq!( + client.mget::(&[]).await.unwrap(), + Vec::>::new() + ); + assert_eq!(client.del(&[]).await.unwrap(), 0); + } + + #[rstest] + #[tokio::test] + async fn mget_and_del_span_slots_in_input_order( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let client = server.client("", DEFAULT_TIMEOUT).await; + client.set("a", "1", Duration::from_secs(60)).await.unwrap(); + client.set("c", "3", Duration::from_secs(60)).await.unwrap(); + + let values = client.mget::(&["c", "b", "a"]).await.unwrap(); + let deleted = client.del(&["a", "b", "c"]).await.unwrap(); + + assert_eq!( + values, + vec![Some("3".to_owned()), None, Some("1".to_owned())] + ); + assert_eq!(deleted, 2); + assert_eq!( + client.mget::(&["a", "c"]).await.unwrap(), + vec![None, None] + ); + } + + #[rstest] + #[tokio::test] + async fn set_nx_only_writes_a_missing_key( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let client = server.client("", DEFAULT_TIMEOUT).await; + + let first = client + .set_nx("lock", "owner-1", Duration::from_secs(60)) + .await + .unwrap(); + let second = client + .set_nx("lock", "owner-2", Duration::from_secs(60)) + .await + .unwrap(); + + assert!(first); + assert!(!second); + assert_eq!( + client.get::("lock").await.unwrap().as_deref(), + Some("owner-1") + ); + } + + #[rstest] + #[tokio::test] + async fn ttl_reports_missing_persistent_and_remaining_time( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let client = server.client("", DEFAULT_TIMEOUT).await; + client.incr_by("persistent", 1).await.unwrap(); + client + .set("expiring", "1", Duration::from_secs(60)) + .await + .unwrap(); + client.incr_by_float("expired_later", 0.5).await.unwrap(); + assert!( + client + .expire("expired_later", Duration::from_secs(30)) + .await + .unwrap() + ); + + assert_eq!(client.ttl("missing").await.unwrap(), Ttl::Missing); + assert_eq!(client.ttl("persistent").await.unwrap(), Ttl::Persistent); + assert!(matches!( + client.ttl("expiring").await.unwrap(), + Ttl::Expires(left) if left > Duration::from_secs(50) && left <= Duration::from_secs(60) + )); + assert!(matches!( + client.ttl("expired_later").await.unwrap(), + Ttl::Expires(left) if left > Duration::from_secs(20) && left <= Duration::from_secs(30) + )); + assert!( + !client + .expire("missing", Duration::from_secs(30)) + .await + .unwrap() + ); + } + + #[rstest] + #[tokio::test] + async fn incr_by_float_accumulates_fractions( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let client = server.client("", DEFAULT_TIMEOUT).await; + + client.incr_by_float("spend", 0.25).await.unwrap(); + + assert_eq!(client.incr_by_float("spend", 0.5).await.unwrap(), 0.75); + } + + #[rstest] + #[tokio::test] + async fn concurrent_commands_on_one_cloned_client_all_apply( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let client = server.client("", DEFAULT_TIMEOUT).await; + + let tasks: Vec<_> = (0..100) + .map(|_| { + let client = client.clone(); + tokio::spawn(async move { + for _ in 0..10 { + client.incr_by("shared", 1).await.unwrap(); + } + }) + }) + .collect(); + for task in tasks { + task.await.unwrap(); + } + + assert_eq!(client.get::("shared").await.unwrap(), Some(1000)); + } + + fn breaker(failure_threshold: u32) -> Breaker { + Breaker::new( + Config { + failure_threshold, + recovery_timeout: Duration::from_millis(200), + timeout_min_duration: Duration::ZERO, + }, + Box::new(|_| {}), + ) + } + + #[rstest] + #[tokio::test] + async fn an_open_breaker_rejects_without_waiting_on_redis_and_a_probe_closes_it( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let breaker = breaker(2); + let client = server + .guarded_client("", Duration::from_millis(300), Some(breaker.clone())) + .await; + + server.freeze().await; + let first = client.get::("k").await; + let second = client.get::("k").await; + let started = Instant::now(); + let third = client.get::("k").await; + let rejected_in = started.elapsed(); + server.thaw().await; + + assert!(matches!(first, Err(Error::Transport(_))), "{first:?}"); + assert!(matches!(second, Err(Error::Transport(_))), "{second:?}"); + assert!(matches!(third, Err(Error::BreakerOpen)), "{third:?}"); + assert!(rejected_in < Duration::from_millis(50), "{rejected_in:?}"); + + let deadline = Instant::now() + Duration::from_secs(30); + let recovered = loop { + match client.get::("k").await { + Ok(value) => break Some(value), + Err(_) if Instant::now() < deadline => { + tokio::time::sleep(Duration::from_millis(50)).await + } + Err(_) => break None, + } + }; + assert_eq!(recovered, Some(None)); + assert!( + matches!(breaker.state(), State::Closed { .. }), + "{:?}", + breaker.state() + ); + } + + #[rstest] + #[tokio::test] + async fn rejected_commands_never_open_the_breaker( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let breaker = breaker(2); + let client = server + .guarded_client("", DEFAULT_TIMEOUT, Some(breaker.clone())) + .await; + client.rpush("list", "item").await.unwrap(); + + let rejected = [ + client.incr_by("list", 1).await, + client.incr_by("list", 1).await, + client.incr_by("list", 1).await, + ]; + + assert!( + matches!(rejected[2], Err(Error::Server(_))), + "{:?}", + rejected[2] + ); + assert!( + matches!(breaker.state(), State::Closed { hard: 0, .. }), + "{:?}", + breaker.state() + ); + } + + #[rstest] + #[tokio::test] + async fn an_open_breaker_fails_every_pipeline_op_without_sending( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let client = server + .guarded_client("", Duration::from_millis(300), Some(breaker(1))) + .await; + let pipeline = client.pipeline().incr_by("a", 1).incr_by("c", 1); + + server.freeze().await; + let failed = client.run(&pipeline).await; + let rejected = client.run(&pipeline).await; + server.thaw().await; + + assert!( + matches!(failed[0], Err(Error::Transport(_))), + "{:?}", + failed[0] + ); + assert!( + matches!(rejected[0], Err(Error::BreakerOpen)), + "{:?}", + rejected[0] + ); + assert!( + matches!(rejected[1], Err(Error::BreakerOpen)), + "{:?}", + rejected[1] + ); + } + + #[rstest] + #[tokio::test] + async fn a_host_endpoint_connects_to_its_database() { + let server = RedisServer::start().await.unwrap(); + let port = server.url().rsplit(':').next().unwrap().parse().unwrap(); + let connect = |endpoint| { + RedisClient::new(RedisConfig { + endpoint, + namespace: Namespace::default(), + timeout: DEFAULT_TIMEOUT, + breaker: None, + }) + }; + let in_db_3 = connect(Endpoint::Host(HostEndpoint { + host: "127.0.0.1".to_owned(), + port, + username: None, + password: None, + tls: false, + db: 3, + })) + .unwrap(); + let in_db_0 = connect(Endpoint::Url(server.url().to_owned())).unwrap(); + let via_url = connect(Endpoint::Url(format!("{}/3", server.url()))).unwrap(); + + in_db_3 + .set("k", "3", Duration::from_secs(60)) + .await + .unwrap(); + + assert_eq!(in_db_0.get::("k").await.unwrap(), None); + assert_eq!( + via_url.get::("k").await.unwrap().as_deref(), + Some("3") + ); + } +} diff --git a/litellm-rust/crates/redis-client/src/commands.rs b/litellm-rust/crates/redis-client/src/commands.rs new file mode 100644 index 00000000000..fb8a4a28c94 --- /dev/null +++ b/litellm-rust/crates/redis-client/src/commands.rs @@ -0,0 +1,62 @@ +use std::time::Duration; + +use redis::{Cmd, ToRedisArgs, ToSingleRedisArg}; + +pub(crate) fn ping() -> Cmd { + redis::cmd("PING") +} + +pub(crate) fn get(key: String) -> Cmd { + redis::cmd("GET").arg(key).to_owned() +} + +pub(crate) fn mget(keys: Vec) -> Cmd { + redis::cmd("MGET").arg(keys).to_owned() +} + +pub(crate) fn set(key: String, value: impl ToSingleRedisArg, ttl: Duration) -> Cmd { + redis::cmd("SET") + .arg(key) + .arg(value) + .arg("PX") + .arg(millis(ttl)) + .to_owned() +} + +pub(crate) fn set_nx(key: String, value: impl ToSingleRedisArg, ttl: Duration) -> Cmd { + redis::cmd("SET") + .arg(key) + .arg(value) + .arg("NX") + .arg("PX") + .arg(millis(ttl)) + .to_owned() +} + +pub(crate) fn del(keys: Vec) -> Cmd { + redis::cmd("DEL").arg(keys).to_owned() +} + +pub(crate) fn expire(key: String, ttl: Duration) -> Cmd { + redis::cmd("PEXPIRE").arg(key).arg(millis(ttl)).to_owned() +} + +pub(crate) fn ttl(key: String) -> Cmd { + redis::cmd("PTTL").arg(key).to_owned() +} + +pub(crate) fn incr_by(key: String, delta: i64) -> Cmd { + redis::cmd("INCRBY").arg(key).arg(delta).to_owned() +} + +pub(crate) fn incr_by_float(key: String, delta: f64) -> Cmd { + redis::cmd("INCRBYFLOAT").arg(key).arg(delta).to_owned() +} + +pub(crate) fn rpush(key: String, values: impl ToRedisArgs) -> Cmd { + redis::cmd("RPUSH").arg(key).arg(values).to_owned() +} + +fn millis(duration: Duration) -> u64 { + u64::try_from(duration.as_millis()).unwrap_or(u64::MAX) +} diff --git a/litellm-rust/crates/redis-client/src/config.rs b/litellm-rust/crates/redis-client/src/config.rs new file mode 100644 index 00000000000..64934c68891 --- /dev/null +++ b/litellm-rust/crates/redis-client/src/config.rs @@ -0,0 +1,152 @@ +use std::{fmt, time::Duration}; + +use redis::{ConnectionAddr, ConnectionInfo, IntoConnectionInfo, RedisConnectionInfo, RedisResult}; + +use litellm_circuit_breaker::Breaker; + +use crate::Namespace; + +pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(5); + +pub struct RedisConfig { + pub endpoint: Endpoint, + pub namespace: Namespace, + pub timeout: Duration, + pub breaker: Option, +} + +#[derive(Clone, PartialEq)] +pub enum Endpoint { + Url(String), + Host(HostEndpoint), + Cluster(ClusterEndpoint), +} + +#[derive(Clone, PartialEq)] +pub struct HostEndpoint { + pub host: String, + pub port: u16, + pub username: Option, + pub password: Option, + pub tls: bool, + pub db: i64, +} + +#[derive(Clone, PartialEq)] +pub struct ClusterEndpoint { + pub nodes: Vec, + pub username: Option, + pub password: Option, + pub tls: bool, +} + +#[derive(Clone, Debug, PartialEq)] +pub struct ClusterNode { + pub host: String, + pub port: u16, +} + +impl ClusterEndpoint { + pub(crate) fn addrs(&self) -> impl Iterator + '_ { + self.nodes + .iter() + .map(|node| addr(&node.host, node.port, self.tls)) + } +} + +impl HostEndpoint { + pub(crate) fn connection_info(&self) -> RedisResult { + let settings = RedisConnectionInfo::default().set_db(self.db); + let settings = match &self.username { + Some(username) => settings.set_username(username), + None => settings, + }; + let settings = match &self.password { + Some(password) => settings.set_password(password), + None => settings, + }; + Ok(addr(&self.host, self.port, self.tls) + .into_connection_info()? + .set_redis_settings(settings)) + } +} + +fn addr(host: &str, port: u16, tls: bool) -> ConnectionAddr { + match tls { + true => ConnectionAddr::TcpTls { + host: host.to_owned(), + port, + insecure: false, + tls_params: None, + }, + false => ConnectionAddr::Tcp(host.to_owned(), port), + } +} + +impl fmt::Debug for Endpoint { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Url(url) => formatter + .debug_tuple("Url") + .field(&redacted_url(url)) + .finish(), + Self::Host(host) => formatter + .debug_struct("Host") + .field("host", &host.host) + .field("port", &host.port) + .field("username", &host.username) + .field("password", &host.password.as_ref().map(|_| "")) + .field("tls", &host.tls) + .field("db", &host.db) + .finish(), + Self::Cluster(cluster) => formatter + .debug_struct("Cluster") + .field("nodes", &cluster.nodes) + .field("username", &cluster.username) + .field("password", &cluster.password.as_ref().map(|_| "")) + .field("tls", &cluster.tls) + .finish(), + } + } +} + +fn redacted_url(url: &str) -> String { + match url + .split_once("://") + .and_then(|(scheme, rest)| Some((scheme, rest.rsplit_once('@')?.1))) + { + Some((scheme, host)) => format!("{scheme}://@{host}"), + None => url.to_owned(), + } +} + +#[cfg(test)] +mod tests { + use rstest::rstest; + + use super::{Endpoint, HostEndpoint}; + + #[rstest] + #[case::url_with_password(Endpoint::Url("redis://user:secret@cache:6379/0".to_owned()), "redis://@cache:6379/0")] + #[case::url_with_at_in_password(Endpoint::Url("rediss://:p@ss@cache:6380".to_owned()), "rediss://@cache:6380")] + #[case::host_password( + Endpoint::Host(HostEndpoint { + host: "cache".to_owned(), + port: 6379, + username: None, + password: Some("secret".to_owned()), + tls: false, + db: 0, + }), + "" + )] + fn debug_output_never_shows_the_password(#[case] endpoint: Endpoint, #[case] shown: &str) { + let debug = format!("{endpoint:?}"); + + assert!( + !debug.contains("secret") && !debug.contains("p@ss"), + "{debug}" + ); + assert!(debug.contains(shown), "{debug}"); + } +} diff --git a/litellm-rust/crates/redis-client/src/connection.rs b/litellm-rust/crates/redis-client/src/connection.rs new file mode 100644 index 00000000000..aaf26f105da --- /dev/null +++ b/litellm-rust/crates/redis-client/src/connection.rs @@ -0,0 +1,80 @@ +use std::time::Duration; + +use redis::{ + Cmd, ConnectionInfo, Pipeline, RedisFuture, RedisResult, Value, + aio::{ConnectionLike, ConnectionManager, ConnectionManagerConfig}, + cluster::{ClusterClientBuilder, ClusterConfig}, + cluster_async::ClusterConnection, +}; + +use crate::ClusterEndpoint; + +const RETRIES: u32 = 3; + +#[derive(Clone)] +pub(crate) enum Connection { + Standalone(ConnectionManager), + Cluster(ClusterConnection), +} + +impl Connection { + pub(crate) fn standalone(info: ConnectionInfo, timeout: Duration) -> RedisResult { + let config = ConnectionManagerConfig::new() + .set_connection_timeout(Some(timeout)) + .set_response_timeout(Some(timeout)) + .set_number_of_retries(RETRIES as usize); + let manager = ConnectionManager::new_lazy_with_config(redis::Client::open(info)?, config)?; + Ok(Self::Standalone(manager)) + } + + pub(crate) fn cluster(endpoint: &ClusterEndpoint, timeout: Duration) -> RedisResult { + let builder = ClusterClientBuilder::new(endpoint.addrs()) + .connection_timeout(timeout) + .response_timeout(timeout) + .retries(RETRIES); + let builder = match &endpoint.username { + Some(username) => builder.username(username), + None => builder, + }; + let builder = match &endpoint.password { + Some(password) => builder.password(password), + None => builder, + }; + let config = ClusterConfig::new() + .set_connection_timeout(timeout) + .set_response_timeout(timeout); + Ok(Self::Cluster( + builder + .build()? + .get_pending_async_connection_with_config(config), + )) + } +} + +impl ConnectionLike for Connection { + fn req_packed_command<'a>(&'a mut self, cmd: &'a Cmd) -> RedisFuture<'a, Value> { + match self { + Self::Standalone(connection) => connection.req_packed_command(cmd), + Self::Cluster(connection) => connection.req_packed_command(cmd), + } + } + + fn req_packed_commands<'a>( + &'a mut self, + pipeline: &'a Pipeline, + offset: usize, + count: usize, + ) -> RedisFuture<'a, Vec> { + match self { + Self::Standalone(connection) => connection.req_packed_commands(pipeline, offset, count), + Self::Cluster(connection) => connection.req_packed_commands(pipeline, offset, count), + } + } + + fn get_db(&self) -> i64 { + match self { + Self::Standalone(connection) => connection.get_db(), + Self::Cluster(connection) => connection.get_db(), + } + } +} diff --git a/litellm-rust/crates/redis-client/src/error.rs b/litellm-rust/crates/redis-client/src/error.rs new file mode 100644 index 00000000000..ed3b2c74004 --- /dev/null +++ b/litellm-rust/crates/redis-client/src/error.rs @@ -0,0 +1,69 @@ +use redis::{ErrorKind, RedisError, ServerErrorKind}; + +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error("Redis did not answer, so the command may or may not have applied")] + Transport(#[source] RedisError), + #[error("Redis rejected the command")] + Server(#[source] RedisError), + #[error("Redis replied with a value of a different type")] + Decode(#[source] RedisError), + #[error("the Redis circuit breaker is open, so the command was not sent")] + BreakerOpen, +} + +#[derive(Debug, thiserror::Error)] +#[error("connecting to Redis")] +pub struct ConnectError(#[from] RedisError); + +impl From for Error { + fn from(error: RedisError) -> Self { + match error.kind() { + ErrorKind::Server( + ServerErrorKind::BusyLoading + | ServerErrorKind::ClusterDown + | ServerErrorKind::MasterDown + | ServerErrorKind::TryAgain + | ServerErrorKind::ReadOnly, + ) => Self::Transport(error), + ErrorKind::Server(_) | ErrorKind::Extension => Self::Server(error), + ErrorKind::Parse | ErrorKind::UnexpectedReturnType => Self::Decode(error), + _ => Self::Transport(error), + } + } +} + +#[cfg(test)] +mod tests { + use redis::{RedisError, Value}; + use rstest::rstest; + + use super::Error; + + fn reply(resp: &str) -> RedisError { + match redis::parse_redis_value(resp.as_bytes()).unwrap() { + Value::ServerError(error) => error.into(), + other => panic!("{resp:?} parsed as {other:?}"), + } + } + + #[rstest] + #[case::wrong_type("-WRONGTYPE Operation against a key holding the wrong kind of value\r\n")] + #[case::no_script("-NOSCRIPT No matching script\r\n")] + #[case::cross_slot("-CROSSSLOT Keys in request don't hash to the same slot\r\n")] + #[case::generic("-ERR value is not an integer or out of range\r\n")] + #[case::no_perm("-NOPERM this user has no permissions to access one of the keys\r\n")] + fn rejections_are_server_errors(#[case] resp: &str) { + assert!(matches!(Error::from(reply(resp)), Error::Server(_))); + } + + #[rstest] + #[case::loading("-LOADING Redis is loading the dataset in memory\r\n")] + #[case::cluster_down("-CLUSTERDOWN The cluster is down\r\n")] + #[case::master_down("-MASTERDOWN Link with MASTER is down\r\n")] + #[case::try_again("-TRYAGAIN Multiple keys request during rehashing of slot\r\n")] + #[case::read_only("-READONLY You can't write against a read only replica.\r\n")] + fn unavailable_nodes_are_transport_errors(#[case] resp: &str) { + assert!(matches!(Error::from(reply(resp)), Error::Transport(_))); + } +} diff --git a/litellm-rust/crates/redis-client/src/lib.rs b/litellm-rust/crates/redis-client/src/lib.rs new file mode 100644 index 00000000000..47ff8677e06 --- /dev/null +++ b/litellm-rust/crates/redis-client/src/lib.rs @@ -0,0 +1,20 @@ +mod client; +mod commands; +mod config; +mod connection; +mod error; +mod namespace; +mod pipeline; +mod script; +#[cfg(test)] +mod test_support; + +pub use client::{RedisClient, Ttl}; +pub use config::{ + ClusterEndpoint, ClusterNode, DEFAULT_TIMEOUT, Endpoint, HostEndpoint, RedisConfig, +}; +pub use error::{ConnectError, Error}; +pub use namespace::Namespace; +pub use pipeline::Pipeline; +pub use redis::Value; +pub use script::Script; diff --git a/litellm-rust/crates/redis-client/src/namespace.rs b/litellm-rust/crates/redis-client/src/namespace.rs new file mode 100644 index 00000000000..4db02b5b7bb --- /dev/null +++ b/litellm-rust/crates/redis-client/src/namespace.rs @@ -0,0 +1,57 @@ +#[derive(Clone, Debug, Default, PartialEq)] +pub struct Namespace(Option); + +impl Namespace { + pub fn new(namespace: impl Into) -> Self { + let namespace = namespace.into(); + Self((!namespace.is_empty()).then_some(namespace)) + } + + pub fn as_str(&self) -> Option<&str> { + self.0.as_deref() + } + + pub(crate) fn apply(&self, key: &str) -> String { + match &self.0 { + Some(namespace) if !is_prefixed(key, namespace) => { + format!("{namespace}:{key}") + } + _ => key.to_owned(), + } + } +} + +fn is_prefixed(key: &str, namespace: &str) -> bool { + key.strip_prefix(namespace) + .is_some_and(|rest| rest.starts_with(':')) +} + +#[cfg(test)] +mod tests { + use rstest::rstest; + + use super::Namespace; + + #[rstest] + #[case::plain(Namespace::new("litellm"), "spend:key:abc", "litellm:spend:key:abc")] + #[case::no_namespace(Namespace::default(), "spend:key:abc", "spend:key:abc")] + #[case::empty_namespace(Namespace::new(""), "spend:key:abc", "spend:key:abc")] + #[case::already_prefixed(Namespace::new("litellm"), "litellm:abc", "litellm:abc")] + #[case::shares_prefix_without_delimiter( + Namespace::new("litellm"), + "litellm_spend_update_buffer", + "litellm:litellm_spend_update_buffer" + )] + #[case::hash_tagged_key( + Namespace::new("litellm"), + "{api_key:sk-1}:requests", + "litellm:{api_key:sk-1}:requests" + )] + fn prefixes_keys_like_python_check_and_fix_namespace( + #[case] namespace: Namespace, + #[case] key: &str, + #[case] expected: &str, + ) { + assert_eq!(namespace.apply(key), expected); + } +} diff --git a/litellm-rust/crates/redis-client/src/pipeline.rs b/litellm-rust/crates/redis-client/src/pipeline.rs new file mode 100644 index 00000000000..e54c65e9605 --- /dev/null +++ b/litellm-rust/crates/redis-client/src/pipeline.rs @@ -0,0 +1,292 @@ +use std::{collections::HashMap, time::Duration}; + +use futures_util::future::join_all; +use redis::{ + Cmd, ErrorKind, RedisResult, ServerErrorKind, ToRedisArgs, ToSingleRedisArg, Value, + cluster_routing::Slot, +}; + +use crate::{Error, Namespace, Script, commands, connection::Connection}; + +pub struct Pipeline { + namespace: Namespace, + ops: Vec, +} + +struct Op { + command: Cmd, + key: String, + script: Option, +} + +struct ScriptCall { + script: Script, + keys: Vec, + args: Vec>, +} + +type Settled = (usize, Result); + +impl Pipeline { + pub(crate) fn new(namespace: Namespace) -> Self { + Self { + namespace, + ops: Vec::new(), + } + } + + pub fn get(self, key: &str) -> Self { + let key = self.namespace.apply(key); + self.command(commands::get(key.clone()), key) + } + + pub fn set(self, key: &str, value: impl ToSingleRedisArg, ttl: Duration) -> Self { + let key = self.namespace.apply(key); + self.command(commands::set(key.clone(), value, ttl), key) + } + + pub fn del(self, key: &str) -> Self { + let key = self.namespace.apply(key); + self.command(commands::del(vec![key.clone()]), key) + } + + pub fn expire(self, key: &str, ttl: Duration) -> Self { + let key = self.namespace.apply(key); + self.command(commands::expire(key.clone(), ttl), key) + } + + pub fn incr_by(self, key: &str, delta: i64) -> Self { + let key = self.namespace.apply(key); + self.command(commands::incr_by(key.clone(), delta), key) + } + + pub fn incr_by_float(self, key: &str, delta: f64) -> Self { + let key = self.namespace.apply(key); + self.command(commands::incr_by_float(key.clone(), delta), key) + } + + pub fn eval(self, script: &Script, keys: &[&str], args: impl ToRedisArgs) -> Self { + let keys: Vec = keys.iter().map(|key| self.namespace.apply(key)).collect(); + let args = args.to_redis_args(); + let op = Op { + command: script.evalsha(&keys, &args), + key: keys.first().cloned().unwrap_or_default(), + script: Some(ScriptCall { + script: script.clone(), + keys, + args, + }), + }; + self.push(op) + } + + fn command(self, command: Cmd, key: String) -> Self { + self.push(Op { + command, + key, + script: None, + }) + } + + fn push(mut self, op: Op) -> Self { + self.ops.push(op); + self + } + + pub(crate) fn len(&self) -> usize { + self.ops.len() + } + + pub(crate) async fn run(&self, connection: &Connection) -> Vec> { + let groups = self.groups(connection); + let settled = join_all( + groups + .iter() + .map(|group| self.run_group(connection.clone(), group)), + ) + .await; + let mut settled: Vec = settled.into_iter().flatten().collect(); + settled.sort_by_key(|(index, _)| *index); + settled.into_iter().map(|(_, result)| result).collect() + } + + fn groups(&self, connection: &Connection) -> Vec> { + match connection { + _ if self.ops.is_empty() => Vec::new(), + Connection::Standalone(_) => vec![(0..self.ops.len()).collect()], + Connection::Cluster(_) => { + let mut by_slot: HashMap> = HashMap::new(); + for (index, op) in self.ops.iter().enumerate() { + by_slot + .entry(Slot::for_key(&op.key)) + .or_default() + .push(index); + } + by_slot.into_values().collect() + } + } + } + + async fn run_group(&self, mut connection: Connection, indices: &[usize]) -> Vec { + let mut pipeline = redis::pipe(); + pipeline.ignore_errors(); + for &index in indices { + pipeline.add_command(self.ops[index].command.clone()); + } + let replies: RedisResult>> = + pipeline.query_async(&mut connection).await; + let replies = match replies { + Ok(replies) => replies, + Err(error) => { + return indices + .iter() + .map(|&index| (index, Err(Error::from(error.clone())))) + .collect(); + } + }; + let mut settled = Vec::with_capacity(indices.len()); + for (&index, reply) in indices.iter().zip(replies) { + settled.push((index, self.settle(&mut connection, index, reply).await)); + } + settled + } + + async fn settle( + &self, + connection: &mut Connection, + index: usize, + reply: RedisResult, + ) -> Result { + match (reply, &self.ops[index].script) { + (Err(error), Some(call)) + if error.kind() == ErrorKind::Server(ServerErrorKind::NoScript) => + { + Ok(call + .script + .invocation(&call.keys, &call.args) + .invoke_async(connection) + .await?) + } + (reply, _) => Ok(reply?), + } + } +} + +#[cfg(test)] +mod tests { + use std::time::{Duration, Instant}; + + use redis::Value; + use rstest::rstest; + + use crate::{ + DEFAULT_TIMEOUT, Error, Script, + test_support::{Server, Topology, flush_scripts}, + }; + + #[rstest] + #[tokio::test] + async fn each_op_settles_on_its_own_in_input_order( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let client = server.client("", DEFAULT_TIMEOUT).await; + client + .set("text", "not a number", Duration::from_secs(60)) + .await + .unwrap(); + let pipeline = client + .pipeline() + .incr_by("a", 1) + .incr_by("text", 1) + .incr_by("c", 5) + .set("b", "2", Duration::from_secs(60)) + .get("b") + .incr_by("a", 1) + .get("missing"); + + let results = client.run(&pipeline).await; + + assert_eq!(results.len(), 7); + assert_eq!(results[0].as_ref().unwrap(), &Value::Int(1)); + assert!( + matches!(results[1], Err(Error::Server(_))), + "{:?}", + results[1] + ); + assert_eq!(results[2].as_ref().unwrap(), &Value::Int(5)); + assert_eq!(results[3].as_ref().unwrap(), &Value::Okay); + assert_eq!( + results[4].as_ref().unwrap(), + &Value::BulkString(b"2".to_vec()) + ); + assert_eq!(results[5].as_ref().unwrap(), &Value::Int(2)); + assert_eq!(results[6].as_ref().unwrap(), &Value::Nil); + } + + #[rstest] + #[tokio::test] + async fn a_flushed_script_in_a_pipeline_reruns_alone( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let client = server.client("ns", DEFAULT_TIMEOUT).await; + let incr = Script::new("return redis.call('INCRBY', KEYS[1], ARGV[1])"); + client.eval::(&incr, &["counter"], 1).await.unwrap(); + flush_scripts(&client).await; + let pipeline = client + .pipeline() + .eval(&incr, &["counter"], 2) + .incr_by("other", 7); + + let results = client.run(&pipeline).await; + + assert_eq!(results[0].as_ref().unwrap(), &Value::Int(3)); + assert_eq!(results[1].as_ref().unwrap(), &Value::Int(7)); + assert_eq!(client.get::("counter").await.unwrap(), Some(3)); + } + + #[rstest] + #[tokio::test] + async fn an_unreachable_server_fails_every_op_as_transport( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let client = server.client("", Duration::from_millis(500)).await; + let pipeline = client.pipeline().incr_by("a", 1).incr_by("c", 1); + + server.freeze().await; + let results = client.run(&pipeline).await; + server.thaw().await; + + assert_eq!(results.len(), 2); + assert!( + matches!(results[0], Err(Error::Transport(_))), + "{:?}", + results[0] + ); + assert!( + matches!(results[1], Err(Error::Transport(_))), + "{:?}", + results[1] + ); + } + + #[rstest] + #[tokio::test] + async fn an_empty_pipeline_returns_without_asking_redis( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let client = server.client("", Duration::from_secs(2)).await; + + server.freeze().await; + let started = Instant::now(); + let results = client.run(&client.pipeline()).await; + let elapsed = started.elapsed(); + server.thaw().await; + + assert!(results.is_empty()); + assert!(elapsed < Duration::from_secs(1), "{elapsed:?}"); + } +} diff --git a/litellm-rust/crates/redis-client/src/script.rs b/litellm-rust/crates/redis-client/src/script.rs new file mode 100644 index 00000000000..c5d73133ecc --- /dev/null +++ b/litellm-rust/crates/redis-client/src/script.rs @@ -0,0 +1,88 @@ +use redis::{Cmd, ScriptInvocation}; + +#[derive(Clone)] +pub struct Script(redis::Script); + +impl Script { + pub fn new(source: &str) -> Self { + Self(redis::Script::new(source)) + } + + pub(crate) fn evalsha(&self, keys: &[String], args: &[Vec]) -> Cmd { + redis::cmd("EVALSHA") + .arg(self.0.get_hash()) + .arg(keys.len()) + .arg(keys) + .arg(args) + .to_owned() + } + + pub(crate) fn invocation(&self, keys: &[String], args: &[Vec]) -> ScriptInvocation<'_> { + let mut invocation = self.0.prepare_invoke(); + invocation.key(keys).arg(args); + invocation + } +} + +#[cfg(test)] +mod tests { + use std::time::Duration; + + use rstest::rstest; + + use super::Script; + use crate::{ + DEFAULT_TIMEOUT, Error, + test_support::{Server, Topology, flush_scripts}, + }; + + #[rstest] + #[tokio::test] + async fn script_keys_are_namespaced( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let client = server.client("a", DEFAULT_TIMEOUT).await; + let bare = server.client("", DEFAULT_TIMEOUT).await; + let read = Script::new("return redis.call('GET', KEYS[1])"); + bare.set("a:x", "1", Duration::from_secs(60)).await.unwrap(); + + let value: Option = client + .eval(&read, &["x"], Vec::::new()) + .await + .unwrap(); + + assert_eq!(value.as_deref(), Some("1")); + } + + #[rstest] + #[tokio::test] + async fn a_failing_script_is_a_server_error_and_keeps_the_connection( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let client = server.client("", DEFAULT_TIMEOUT).await; + let incr = Script::new("return redis.call('INCRBY', KEYS[1], ARGV[1])"); + client.rpush("list", "item").await.unwrap(); + + let failed = client.eval::(&incr, &["list"], 1).await; + + assert!(matches!(failed, Err(Error::Server(_))), "{failed:?}"); + assert_eq!(client.eval::(&incr, &["counter"], 3).await.unwrap(), 3); + } + + #[rstest] + #[tokio::test] + async fn a_flushed_script_is_loaded_again( + #[values(Topology::Standalone, Topology::Cluster)] topology: Topology, + ) { + let server = Server::start(topology).await; + let client = server.client("", DEFAULT_TIMEOUT).await; + let incr = Script::new("return redis.call('INCRBY', KEYS[1], ARGV[1])"); + client.eval::(&incr, &["counter"], 1).await.unwrap(); + + flush_scripts(&client).await; + + assert_eq!(client.eval::(&incr, &["counter"], 1).await.unwrap(), 2); + } +} diff --git a/litellm-rust/crates/redis-client/src/test_support.rs b/litellm-rust/crates/redis-client/src/test_support.rs new file mode 100644 index 00000000000..64a174b1543 --- /dev/null +++ b/litellm-rust/crates/redis-client/src/test_support.rs @@ -0,0 +1,125 @@ +use std::time::Duration; + +use litellm_circuit_breaker::Breaker; +use litellm_redis_testing::{RedisCluster, RedisServer}; +use redis::cluster_routing::{Route, RoutingInfo, SingleNodeRoutingInfo, SlotAddr}; + +use crate::{ + ClusterEndpoint, ClusterNode, Endpoint, Namespace, RedisClient, RedisConfig, + connection::Connection, +}; + +#[derive(Clone, Copy, Debug)] +pub(crate) enum Topology { + Standalone, + Cluster, +} + +pub(crate) enum Server { + Standalone(RedisServer), + Cluster(RedisCluster), +} + +impl Server { + pub(crate) async fn start(topology: Topology) -> Self { + match topology { + Topology::Standalone => Self::Standalone(RedisServer::start().await.unwrap()), + Topology::Cluster => Self::Cluster(RedisCluster::start().await.unwrap()), + } + } + + pub(crate) fn endpoint(&self) -> Endpoint { + match self { + Self::Standalone(server) => Endpoint::Url(server.url().to_owned()), + Self::Cluster(cluster) => Endpoint::Cluster(ClusterEndpoint { + nodes: cluster + .nodes() + .map(|(host, port)| ClusterNode { + host: host.to_owned(), + port, + }) + .collect(), + username: None, + password: None, + tls: false, + }), + } + } + + pub(crate) async fn client(&self, namespace: &str, timeout: Duration) -> RedisClient { + self.guarded_client(namespace, timeout, None).await + } + + pub(crate) async fn guarded_client( + &self, + namespace: &str, + timeout: Duration, + breaker: Option, + ) -> RedisClient { + RedisClient::new(RedisConfig { + endpoint: self.endpoint(), + namespace: Namespace::new(namespace), + timeout, + breaker, + }) + .unwrap() + } + + pub(crate) async fn restart(&self) { + match self { + Self::Standalone(server) => server.restart().await.unwrap(), + Self::Cluster(cluster) => cluster.restart().await.unwrap(), + } + } + + pub(crate) async fn stop(&self) { + match self { + Self::Standalone(server) => server.stop().await.unwrap(), + Self::Cluster(cluster) => cluster.stop().await.unwrap(), + } + } + + pub(crate) async fn resume(&self) { + match self { + Self::Standalone(server) => server.resume().await.unwrap(), + Self::Cluster(cluster) => cluster.resume().await.unwrap(), + } + } + + pub(crate) async fn freeze(&self) { + match self { + Self::Standalone(server) => server.freeze().await.unwrap(), + Self::Cluster(cluster) => cluster.freeze().await.unwrap(), + } + } + + pub(crate) async fn thaw(&self) { + match self { + Self::Standalone(server) => server.thaw().await.unwrap(), + Self::Cluster(cluster) => cluster.thaw().await.unwrap(), + } + } +} + +pub(crate) async fn client_id(client: &RedisClient, key: &str) -> i64 { + let command = redis::cmd("CLIENT").arg("ID").to_owned(); + match client.connection.clone() { + Connection::Standalone(mut connection) => { + command.query_async(&mut connection).await.unwrap() + } + Connection::Cluster(mut connection) => { + let node = Route::with_key(key, SlotAddr::Master); + let routing = RoutingInfo::SingleNode(SingleNodeRoutingInfo::SpecificNode(node)); + redis::from_redis_value(connection.route_command(command, routing).await.unwrap()) + .unwrap() + } + } +} + +pub(crate) async fn flush_scripts(client: &RedisClient) { + redis::cmd("SCRIPT") + .arg("FLUSH") + .query_async::<()>(&mut client.connection.clone()) + .await + .unwrap(); +} diff --git a/litellm-rust/crates/redis-testing/AGENTS.md b/litellm-rust/crates/redis-testing/AGENTS.md new file mode 100644 index 00000000000..fb7a4cd737a --- /dev/null +++ b/litellm-rust/crates/redis-testing/AGENTS.md @@ -0,0 +1,6 @@ +- Dev-only crate that starts real Redis for tests. Never a dependency outside `[dev-dependencies]` +- Same shape as `db-testing`: one container per test, a handle that removes it on drop +- The host port is fixed at start so `restart` keeps the same URL and a client can reconnect to it +- `RedisCluster` runs 3 masters in one container. Each node listens on the same port inside and outside and announces 127.0.0.1, so MOVED redirects work from the test process +- Outages come from the container (`restart`, `freeze` / `thaw`), never `DEBUG`, which the official image disables +- No env gate that makes a test pass without Redis. A test that can't start its container fails diff --git a/litellm-rust/crates/redis-testing/Cargo.toml b/litellm-rust/crates/redis-testing/Cargo.toml new file mode 100644 index 00000000000..c9bad227acc --- /dev/null +++ b/litellm-rust/crates/redis-testing/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "litellm-redis-testing" +version = "0.1.0" +edition.workspace = true +license.workspace = true +repository.workspace = true + +[dependencies] +testcontainers-modules = { workspace = true, features = ["redis"] } +thiserror.workspace = true +tokio = { workspace = true, features = ["io-util"] } diff --git a/litellm-rust/crates/redis-testing/src/cluster.rs b/litellm-rust/crates/redis-testing/src/cluster.rs new file mode 100644 index 00000000000..e61f7832b1c --- /dev/null +++ b/litellm-rust/crates/redis-testing/src/cluster.rs @@ -0,0 +1,93 @@ +use testcontainers_modules::testcontainers::{ + ContainerAsync, GenericImage, ImageExt, + core::{IntoContainerPort, WaitFor}, + runners::AsyncRunner, +}; + +use crate::{ + Error, + ports::{HOST, start_on_free_ports, wait_for_pong}, + standalone::REDIS_TAG, +}; + +const READY: &str = "redis-testing cluster ready"; + +const START_CLUSTER: &str = r#" +set -e +bus=17000 +for port in "$@"; do + mkdir -p "/data/$port" + redis-server --port "$port" --cluster-enabled yes --cluster-port "$bus" \ + --cluster-config-file "/data/$port/nodes.conf" --cluster-announce-ip 127.0.0.1 \ + --dir "/data/$port" --save '' --appendonly no --daemonize yes + bus=$((bus + 1)) +done +for port in "$@"; do + until redis-cli -p "$port" ping >/dev/null 2>&1; do sleep 0.1; done +done +if [ ! -f /data/created ]; then + redis-cli --cluster create $(for port in "$@"; do printf '127.0.0.1:%s ' "$port"; done) --cluster-yes >/dev/null + touch /data/created +fi +for port in "$@"; do + until redis-cli -p "$port" cluster info | grep -q cluster_state:ok; do sleep 0.1; done +done +echo "redis-testing cluster ready" +exec sleep infinity +"#; + +pub struct RedisCluster { + container: ContainerAsync, + ports: [u16; 3], +} + +impl RedisCluster { + pub async fn start() -> Result { + start_on_free_ports(Self::start_on).await + } + + async fn start_on(ports: [u16; 3]) -> Result { + let image = GenericImage::new("redis", REDIS_TAG) + .with_wait_for(WaitFor::message_on_stdout(READY)) + .with_entrypoint("sh"); + let request = ports.iter().fold( + image.with_cmd( + ["-c", START_CLUSTER, "sh"] + .into_iter() + .map(str::to_owned) + .chain(ports.iter().map(u16::to_string)), + ), + |request, &port| request.with_mapped_port(port, port.tcp()), + ); + let container = request.start().await?; + for port in ports { + wait_for_pong(port).await?; + } + Ok(Self { container, ports }) + } + + pub fn nodes(&self) -> impl Iterator + '_ { + self.ports.iter().map(|&port| (HOST, port)) + } + + pub async fn restart(&self) -> Result<(), Error> { + self.stop().await?; + self.resume().await + } + + pub async fn stop(&self) -> Result<(), Error> { + Ok(self.container.stop().await?) + } + + pub async fn resume(&self) -> Result<(), Error> { + Ok(self.container.start().await?) + } + + pub async fn freeze(&self) -> Result<(), Error> { + Ok(self.container.pause().await?) + } + + pub async fn thaw(&self) -> Result<(), Error> { + Ok(self.container.unpause().await?) + } +} diff --git a/litellm-rust/crates/redis-testing/src/error.rs b/litellm-rust/crates/redis-testing/src/error.rs new file mode 100644 index 00000000000..f21cc959812 --- /dev/null +++ b/litellm-rust/crates/redis-testing/src/error.rs @@ -0,0 +1,11 @@ +use std::io; + +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error("reserving a host port for the Redis container")] + Port(#[source] io::Error), + #[error("Redis on host port {port} did not answer PING")] + Unreachable { port: u16 }, + #[error("controlling the Redis container")] + Container(#[from] testcontainers_modules::testcontainers::TestcontainersError), +} diff --git a/litellm-rust/crates/redis-testing/src/lib.rs b/litellm-rust/crates/redis-testing/src/lib.rs new file mode 100644 index 00000000000..6c2afd7f275 --- /dev/null +++ b/litellm-rust/crates/redis-testing/src/lib.rs @@ -0,0 +1,8 @@ +mod cluster; +mod error; +mod ports; +mod standalone; + +pub use cluster::RedisCluster; +pub use error::Error; +pub use standalone::RedisServer; diff --git a/litellm-rust/crates/redis-testing/src/ports.rs b/litellm-rust/crates/redis-testing/src/ports.rs new file mode 100644 index 00000000000..e7b94988c10 --- /dev/null +++ b/litellm-rust/crates/redis-testing/src/ports.rs @@ -0,0 +1,66 @@ +use std::{ + future::Future, + io, + net::TcpListener, + time::{Duration, Instant}, +}; + +use tokio::{ + io::{AsyncReadExt, AsyncWriteExt}, + net::TcpStream, +}; + +use crate::Error; + +pub(crate) const HOST: &str = "127.0.0.1"; +const READY_TIMEOUT: Duration = Duration::from_secs(10); +const START_ATTEMPTS: usize = 3; + +fn free_ports() -> Result<[u16; N], Error> { + let listeners = (0..N) + .map(|_| TcpListener::bind((HOST, 0))) + .collect::>>() + .map_err(Error::Port)?; + let ports = listeners + .iter() + .map(|listener| listener.local_addr().map(|address| address.port())) + .collect::>>() + .map_err(Error::Port)?; + Ok(ports + .try_into() + .unwrap_or_else(|ports: Vec| unreachable!("{} ports", ports.len()))) +} + +pub(crate) async fn wait_for_pong(port: u16) -> Result<(), Error> { + let deadline = Instant::now() + READY_TIMEOUT; + while Instant::now() < deadline { + if ping(port).await.unwrap_or(false) { + return Ok(()); + } + tokio::time::sleep(Duration::from_millis(100)).await; + } + Err(Error::Unreachable { port }) +} + +async fn ping(port: u16) -> io::Result { + let mut stream = TcpStream::connect((HOST, port)).await?; + stream.write_all(b"PING\r\n").await?; + let mut reply = [0; 7]; + stream.read_exact(&mut reply).await?; + Ok(&reply == b"+PONG\r\n") +} + +pub(crate) async fn start_on_free_ports( + start: impl Fn([u16; N]) -> F, +) -> Result +where + F: Future>, +{ + let mut attempt = 1; + loop { + match start(free_ports()?).await { + Err(_) if attempt < START_ATTEMPTS => attempt += 1, + started => return started, + } + } +} diff --git a/litellm-rust/crates/redis-testing/src/standalone.rs b/litellm-rust/crates/redis-testing/src/standalone.rs new file mode 100644 index 00000000000..8060ccbf190 --- /dev/null +++ b/litellm-rust/crates/redis-testing/src/standalone.rs @@ -0,0 +1,62 @@ +use testcontainers_modules::{ + redis::{REDIS_PORT, Redis}, + testcontainers::core::IntoContainerPort, + testcontainers::{ContainerAsync, ImageExt, runners::AsyncRunner}, +}; + +use crate::{ + Error, + ports::{HOST, start_on_free_ports, wait_for_pong}, +}; + +pub(crate) const REDIS_TAG: &str = + "7.4@sha256:44960b3100c48159a66d28c18b0588c193492e25f7551d60e51dd464fc3eca5b"; + +pub struct RedisServer { + container: ContainerAsync, + url: String, +} + +impl RedisServer { + pub async fn start() -> Result { + start_on_free_ports(Self::start_on).await + } + + async fn start_on([host_port]: [u16; 1]) -> Result { + let container = Redis::default() + .with_tag(REDIS_TAG) + .with_mapped_port(host_port, REDIS_PORT.tcp()) + .start() + .await?; + wait_for_pong(host_port).await?; + Ok(Self { + container, + url: format!("redis://{HOST}:{host_port}"), + }) + } + + pub fn url(&self) -> &str { + &self.url + } + + pub async fn restart(&self) -> Result<(), Error> { + self.stop().await?; + self.resume().await + } + + pub async fn stop(&self) -> Result<(), Error> { + Ok(self.container.stop().await?) + } + + pub async fn resume(&self) -> Result<(), Error> { + Ok(self.container.start().await?) + } + + pub async fn freeze(&self) -> Result<(), Error> { + Ok(self.container.pause().await?) + } + + pub async fn thaw(&self) -> Result<(), Error> { + Ok(self.container.unpause().await?) + } +} diff --git a/litellm-rust/crates/spend-clickhouse/Cargo.toml b/litellm-rust/crates/spend-clickhouse/Cargo.toml index 661a75ac02e..893c5daded3 100644 --- a/litellm-rust/crates/spend-clickhouse/Cargo.toml +++ b/litellm-rust/crates/spend-clickhouse/Cargo.toml @@ -19,7 +19,7 @@ time = { workspace = true, features = ["formatting"] } [dev-dependencies] litellm-http = { workspace = true, features = ["test-support"] } rstest.workspace = true -testcontainers-modules = { version = "0.15.0", features = ["clickhouse"] } +testcontainers-modules = { workspace = true, features = ["clickhouse"] } tokio.workspace = true uuid.workspace = true wiremock.workspace = true diff --git a/litellm-rust/crates/storage-clickhouse/Cargo.toml b/litellm-rust/crates/storage-clickhouse/Cargo.toml index 4e72e823dc2..39d04f2de5d 100644 --- a/litellm-rust/crates/storage-clickhouse/Cargo.toml +++ b/litellm-rust/crates/storage-clickhouse/Cargo.toml @@ -19,6 +19,6 @@ url.workspace = true [dev-dependencies] litellm-http = { workspace = true, features = ["test-support"] } rstest.workspace = true -testcontainers-modules = { version = "0.15.0", features = ["clickhouse"] } +testcontainers-modules = { workspace = true, features = ["clickhouse"] } tokio.workspace = true wiremock.workspace = true diff --git a/litellm/__init__.py b/litellm/__init__.py index 1784deeb797..41e3fa34323 100644 --- a/litellm/__init__.py +++ b/litellm/__init__.py @@ -175,7 +175,7 @@ argilla_batch_size: Optional[int] = None datadog_use_v1: Optional[bool] = False # if you want to use v1 datadog logged payload. gcs_pub_sub_use_v1: Optional[bool] = False # if you want to use v1 gcs pubsub logged payload generic_api_use_v1: Optional[bool] = False # if you want to use v1 generic api logged payload -argilla_transformation_object: Optional[Dict[str, Any]] = None +argilla_transformation_object: Mapping[str, str] | None = None _async_input_callback: List[Union[str, Callable[..., object], "CustomLogger"]] = ( # CustomLogger is lazy-loaded [] ) # internal variable - async custom callbacks are routed here. @@ -234,6 +234,7 @@ bedrock_neutralize_orphaned_tool_blocks: bool = True use_chat_completions_url_for_anthropic_messages: bool = bool( os.getenv("LITELLM_USE_CHAT_COMPLETIONS_URL_FOR_ANTHROPIC_MESSAGES", False) ) # When True, routes OpenAI /v1/messages requests to chat/completions instead of the Responses API +anthropic_messages_estimate_initial_input_tokens: bool = False # When True, strip the OpenAI-flavored `usage.total_tokens` field that # LiteLLM injects into non-streaming /v1/messages responses, bringing the # wire response into line with the Anthropic spec (matches the streaming @@ -333,7 +334,7 @@ in_memory_llm_clients_cache: "LLMClientCache" safe_memory_mode: bool = False enable_azure_ad_token_refresh: Optional[bool] = False # Proxy Authentication - auto-obtain/refresh OAuth2/JWT tokens for LiteLLM Proxy -proxy_auth: Optional[Any] = None +proxy_auth: _ProxyAuthHandlerType | None = None ### DEFAULT AZURE API VERSION ### AZURE_DEFAULT_API_VERSION = "2025-02-01-preview" # this is updated to the latest ### DEFAULT WATSONX API VERSION ### @@ -503,7 +504,7 @@ skill_search_embedding_model: Optional[str] = None # Supports both old format (Dict[str, str]) and new format (Dict[str, Dict[str, Any]]) # New format: { "displayName": { "url": "...", "index": 0 } } # Old format: { "displayName": "url" } (for backward compatibility) -public_model_groups_links: Dict[str, Union[str, Dict[str, Any]]] = {} +public_model_groups_links: dict[str, str | dict[str, object]] = {} #### REQUEST PRIORITIZATION ####### priority_reservation: Optional[Dict[str, Union[float, "PriorityReservationDict"]]] = None # priority_reservation_settings is lazy-loaded via __getattr__ @@ -682,6 +683,7 @@ darkbloom_models: Set = set() openinfer_models: Final[Set[str]] = set() v0_models: Set = set() morph_models: Set = set() +opencode_go_models: Final[set[str]] = set() # mutable-ok: populated when the shared model catalog loads lambda_ai_models: Set = set() inception_models: Set = set() hyperbolic_models: Set = set() @@ -970,6 +972,8 @@ def _populate_provider_model_sets(model_cost_map: Mapping[str, Mapping[str, obje v0_models.add(key) elif value.get("litellm_provider") == "morph": morph_models.add(key) + elif value.get("litellm_provider") == "opencode_go": + opencode_go_models.add(key) elif value.get("litellm_provider") == "lambda_ai": lambda_ai_models.add(key) elif value.get("litellm_provider") == "inception": @@ -1137,6 +1141,7 @@ model_list = list( | openinfer_models | v0_models | morph_models + | opencode_go_models | lambda_ai_models | inception_models | black_forest_labs_models @@ -1254,6 +1259,7 @@ def _build_models_by_provider() -> dict: "openinfer": openinfer_models, "v0": v0_models, "morph": morph_models, + "opencode_go": opencode_go_models, "lambda_ai": lambda_ai_models, "inception": inception_models, "hyperbolic": hyperbolic_models, @@ -1724,6 +1730,9 @@ if TYPE_CHECKING: from .llms.hosted_vllm.decisions.transformation import ( HostedVLLMDecisionsConfig as HostedVLLMDecisionsConfig, ) + from .llms.lm_studio.decisions.transformation import ( + LMStudioDecisionsConfig as LMStudioDecisionsConfig, + ) from .llms.laya.decisions.transformation import ( LayaDecisionsConfig as LayaDecisionsConfig, ) @@ -1733,6 +1742,9 @@ if TYPE_CHECKING: from .llms.openai.decisions.transformation import ( OpenAIDecisionsConfig as OpenAIDecisionsConfig, ) + from .llms.azure.decisions.transformation import ( + AzureDecisionsConfig as AzureDecisionsConfig, + ) from .llms.azure_ai.decisions.transformation import ( AzureAIDecisionsConfig as AzureAIDecisionsConfig, ) @@ -1777,10 +1789,10 @@ if TYPE_CHECKING: SagemakerNovaConfig as SagemakerNovaConfig, ) from .llms.cohere.chat.transformation import CohereChatConfig as CohereChatConfig - from .llms.anthropic.pass_through.messages.transformation import ( + from .llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig as AnthropicMessagesConfig, ) - from .llms.bedrock.messages.invoke_transformations.anthropic_claude3_transformation import ( + from .llms.bedrock.messages.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeMessagesConfig as AmazonAnthropicClaudeMessagesConfig, ) from .llms.bedrock.messages.mantle_transformation import ( @@ -1803,7 +1815,7 @@ if TYPE_CHECKING: from .llms.vertex_ai.vertex_ai_partner_models.anthropic.transformation import ( VertexAIAnthropicConfig as VertexAIAnthropicConfig, ) - from .llms.vertex_ai.vertex_ai_partner_models.llama3.transformation import ( + from .llms.vertex_ai.vertex_ai_partner_models.llama.transformation import ( VertexAILlama3Config as VertexAILlama3Config, ) from .llms.vertex_ai.vertex_ai_partner_models.ai21.transformation import ( @@ -1830,10 +1842,10 @@ if TYPE_CHECKING: from .llms.bedrock.chat.invoke_transformations.amazon_qwen3_transformation import ( AmazonQwen3Config as AmazonQwen3Config, ) - from .llms.bedrock.chat.invoke_transformations.anthropic_claude2_transformation import ( + from .llms.bedrock.chat.invoke_transformations.anthropic_legacy_text_completions_transformation import ( AmazonAnthropicConfig as AmazonAnthropicConfig, ) - from .llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformation import ( + from .llms.bedrock.chat.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeConfig as AmazonAnthropicClaudeConfig, ) from .llms.bedrock.chat.invoke_transformations.amazon_cohere_transformation import ( @@ -1995,7 +2007,7 @@ if TYPE_CHECKING: GradientAIConfig as GradientAIConfig, ) from .llms.openai.chat.gpt_transformation import OpenAIGPTConfig as OpenAIGPTConfig - from .llms.openai.chat.gpt_5_transformation import ( + from .llms.openai.chat.gpt_reasoning_transformation import ( OpenAIGPT5Config as OpenAIGPT5Config, ) from .llms.openai.transcriptions.whisper_transformation import ( @@ -2136,7 +2148,7 @@ if TYPE_CHECKING: from .llms.azure.chat.gpt_transformation import ( AzureOpenAIConfig as AzureOpenAIConfig, ) - from .llms.azure.chat.gpt_5_transformation import ( + from .llms.azure.chat.gpt_reasoning_transformation import ( AzureOpenAIGPT5Config as AzureOpenAIGPT5Config, ) from .llms.azure.completion.transformation import ( @@ -2289,6 +2301,10 @@ if TYPE_CHECKING: LiteLLM_UpperboundKeyGenerateParams, ) from litellm.utils import ModelResponseListIterator as _ModelResponseListIterator + from collections.abc import Awaitable + from litellm.types.utils import ModelResponse as _ModelResponseType + from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapper as _CustomStreamWrapperType + from litellm.proxy_auth import ProxyAuthHandler as _ProxyAuthHandlerType # Cost calculator functions cost_per_token: Callable[..., Tuple[float, float]] @@ -2312,7 +2328,7 @@ if TYPE_CHECKING: supports_audio_output: Callable[..., bool] supports_system_messages: Callable[..., bool] supports_reasoning: Callable[..., bool] - acreate: Callable[..., Any] + acreate: Callable[..., Awaitable[_ModelResponseType | _CustomStreamWrapperType]] get_max_tokens: Callable[..., int] get_model_info: Callable[..., _ModelInfoType] register_prompt_template: Callable[..., None] @@ -2610,8 +2626,10 @@ def __getattr__(name: str) -> Any: cancel_run, delete_run, ) + from types import MappingProxyType - return locals()[name] + evals_exports: Final[Mapping[str, object]] = MappingProxyType(locals()) + return evals_exports[name] raise AttributeError(f"module {__name__!r} has no attribute {name!r}") diff --git a/litellm/_lazy_imports.py b/litellm/_lazy_imports.py index 46126c444a6..1a7dc343745 100644 --- a/litellm/_lazy_imports.py +++ b/litellm/_lazy_imports.py @@ -19,7 +19,7 @@ import importlib import sys from collections.abc import Callable, Mapping from types import ModuleType -from typing import TYPE_CHECKING, Any, Final, cast +from typing import TYPE_CHECKING, Any, Final from typing_extensions import ReadOnly, TypedDict @@ -456,7 +456,7 @@ def _lazy_import_http_handlers(name: str) -> object: params: Final = {"timeout": async_timeout, "client_alias": "module level aclient"} # Create the client instance - provider_id: Final = cast(Any, "litellm_module_level_client") + provider_id: Final = "litellm_module_level_client" async_client: Final = get_async_httpx_client( llm_provider=provider_id, params=params, diff --git a/litellm/_lazy_imports_registry.py b/litellm/_lazy_imports_registry.py index e0cb7c680bc..f43e369e092 100644 --- a/litellm/_lazy_imports_registry.py +++ b/litellm/_lazy_imports_registry.py @@ -170,9 +170,11 @@ LLM_CONFIG_NAMES: Final = ( "StrandsDeciderDecisionsConfig", "DatabricksDecisionsConfig", "HostedVLLMDecisionsConfig", + "LMStudioDecisionsConfig", "LayaDecisionsConfig", "BespokeDecisionsConfig", "OpenAIDecisionsConfig", + "AzureDecisionsConfig", "AzureAIDecisionsConfig", "NvidiaNimRerankConfig", "NvidiaNimRankingConfig", @@ -746,9 +748,11 @@ _LLM_CONFIGS_IMPORT_MAP: Final = { ".llms.hosted_vllm.decisions.transformation", "HostedVLLMDecisionsConfig", ), + "LMStudioDecisionsConfig": (".llms.lm_studio.decisions.transformation", "LMStudioDecisionsConfig"), "LayaDecisionsConfig": (".llms.laya.decisions.transformation", "LayaDecisionsConfig"), "BespokeDecisionsConfig": (".llms.bespoke.decisions.transformation", "BespokeDecisionsConfig"), "OpenAIDecisionsConfig": (".llms.openai.decisions.transformation", "OpenAIDecisionsConfig"), + "AzureDecisionsConfig": (".llms.azure.decisions.transformation", "AzureDecisionsConfig"), "AzureAIDecisionsConfig": (".llms.azure_ai.decisions.transformation", "AzureAIDecisionsConfig"), "NvidiaNimRerankConfig": ( ".llms.nvidia_nim.rerank.transformation", @@ -797,7 +801,7 @@ _LLM_CONFIGS_IMPORT_MAP: Final = { ), "CohereChatConfig": (".llms.cohere.chat.transformation", "CohereChatConfig"), "AnthropicMessagesConfig": ( - ".llms.anthropic.pass_through.messages.transformation", + ".llms.anthropic.messages.native.transformation", "AnthropicMessagesConfig", ), "BedrockClaudePlatformMessagesConfig": ( @@ -805,7 +809,7 @@ _LLM_CONFIGS_IMPORT_MAP: Final = { "BedrockClaudePlatformMessagesConfig", ), "AmazonAnthropicClaudeMessagesConfig": ( - ".llms.bedrock.messages.invoke_transformations.anthropic_claude3_transformation", + ".llms.bedrock.messages.invoke_transformations.anthropic_claude_transformation", "AmazonAnthropicClaudeMessagesConfig", ), "AmazonMantleMessagesConfig": ( @@ -835,7 +839,7 @@ _LLM_CONFIGS_IMPORT_MAP: Final = { "VertexAIAnthropicConfig", ), "VertexAILlama3Config": ( - ".llms.vertex_ai.vertex_ai_partner_models.llama3.transformation", + ".llms.vertex_ai.vertex_ai_partner_models.llama.transformation", "VertexAILlama3Config", ), "VertexAIAi21Config": ( @@ -880,11 +884,11 @@ _LLM_CONFIGS_IMPORT_MAP: Final = { "GoogleAIStudioGeminiConfig", ), # Alias "AmazonAnthropicConfig": ( - ".llms.bedrock.chat.invoke_transformations.anthropic_claude2_transformation", + ".llms.bedrock.chat.invoke_transformations.anthropic_legacy_text_completions_transformation", "AmazonAnthropicConfig", ), "AmazonAnthropicClaudeConfig": ( - ".llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformation", + ".llms.bedrock.chat.invoke_transformations.anthropic_claude_transformation", "AmazonAnthropicClaudeConfig", ), "AmazonCohereConfig": ( @@ -1101,7 +1105,7 @@ _LLM_CONFIGS_IMPORT_MAP: Final = { "OpenAIOSeriesConfig", ), # Alias "OpenAIGPTConfig": (".llms.openai.chat.gpt_transformation", "OpenAIGPTConfig"), - "OpenAIGPT5Config": (".llms.openai.chat.gpt_5_transformation", "OpenAIGPT5Config"), + "OpenAIGPT5Config": (".llms.openai.chat.gpt_reasoning_transformation", "OpenAIGPT5Config"), "OpenAIWhisperAudioTranscriptionConfig": ( ".llms.openai.transcriptions.whisper_transformation", "OpenAIWhisperAudioTranscriptionConfig", @@ -1175,7 +1179,7 @@ _LLM_CONFIGS_IMPORT_MAP: Final = { "CometAPIConfig": (".llms.cometapi.chat.transformation", "CometAPIConfig"), "AzureOpenAIConfig": (".llms.azure.chat.gpt_transformation", "AzureOpenAIConfig"), "AzureOpenAIGPT5Config": ( - ".llms.azure.chat.gpt_5_transformation", + ".llms.azure.chat.gpt_reasoning_transformation", "AzureOpenAIGPT5Config", ), "AzureOpenAITextConfig": ( diff --git a/litellm/_uuid.py b/litellm/_uuid.py index e9578b7287f..55df233b553 100644 --- a/litellm/_uuid.py +++ b/litellm/_uuid.py @@ -1,10 +1,14 @@ """ Internal unified UUID helper. -Always uses fastuuid for performance. +Uses fastuuid where supported and the standard library on Python 3.15+. """ -import fastuuid as _uuid +import sys +import uuid as _uuid + +if sys.version_info < (3, 15): + import fastuuid as _uuid # Expose a module-like alias so callers can use: uuid.uuid4() uuid = _uuid diff --git a/litellm/a2a_protocol/cost_calculator.py b/litellm/a2a_protocol/cost_calculator.py index 31ca81c44dd..9a1431d6457 100644 --- a/litellm/a2a_protocol/cost_calculator.py +++ b/litellm/a2a_protocol/cost_calculator.py @@ -5,7 +5,10 @@ Supports dynamic cost parameters that allow platform owners to define custom costs per agent query or per token. """ -from typing import TYPE_CHECKING, Any, Final +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, Final, SupportsFloat, SupportsIndex + +from typing_extensions import Buffer if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import ( @@ -15,6 +18,15 @@ else: LitellmLoggingObject = Any +def _custom_response_cost(model_call_details: Mapping[str, object]) -> float | None: + response_cost: Final = model_call_details.get("response_cost", None) + if response_cost is None: + return None + if isinstance(response_cost, (str, Buffer, SupportsFloat, SupportsIndex)): + return float(response_cost) + raise TypeError(f"float() argument must be a string or a real number, not {type(response_cost).__name__!r}") + + class A2ACostCalculator: @staticmethod def calculate_a2a_cost( @@ -45,9 +57,9 @@ class A2ACostCalculator: model_call_details: Final = litellm_logging_obj.model_call_details # Check if user set a custom response cost (backward compatibility) - response_cost: Final = model_call_details.get("response_cost", None) - if response_cost is not None: - return float(response_cost) + custom_response_cost: Final = _custom_response_cost(model_call_details) + if custom_response_cost is not None: + return custom_response_cost # Get litellm_params for cost parameters litellm_params: Final = model_call_details.get("litellm_params", {}) or {} diff --git a/litellm/a2a_protocol/providers/bedrock_agentcore/transformation.py b/litellm/a2a_protocol/providers/bedrock_agentcore/transformation.py index 404bcca712f..1cea0194715 100644 --- a/litellm/a2a_protocol/providers/bedrock_agentcore/transformation.py +++ b/litellm/a2a_protocol/providers/bedrock_agentcore/transformation.py @@ -84,14 +84,23 @@ def _filter_reserved_headers( return filtered or None +def _calling_key_hash(litellm_params: Mapping[str, object]) -> str | None: + principal: Final = litellm_params.get(A2A_USER_API_KEY_HASH_PARAM) + if principal is None or isinstance(principal, str): + return principal + if not principal: + return None + raise AttributeError(f"{type(principal).__name__!r} object has no attribute 'encode'", name="encode", obj=principal) + + def _request_scoped_runtime_session_id( params: Mapping[str, object], - litellm_params: Mapping[str, Any], + litellm_params: Mapping[str, object], ) -> str | None: context_id: Final = get_session_id_from_a2a_params(params) if not isinstance(context_id, str) or not context_id: return None - return scope_session_to_principal(context_id, litellm_params.get(A2A_USER_API_KEY_HASH_PARAM)) + return scope_session_to_principal(context_id, _calling_key_hash(litellm_params)) def _validate_runtime_session_id(session_id: str, model: str) -> str: @@ -109,6 +118,13 @@ def _validate_runtime_session_id(session_id: str, model: str) -> str: ) +def _agentcore_model_name(litellm_params: Mapping[str, object]) -> str: + model: Final = litellm_params.get("model", "") + if isinstance(model, str): + return model + raise AttributeError(f"{type(model).__name__!r} object has no attribute 'startswith'", name="startswith", obj=model) + + class BedrockAgentCoreA2ATransformation: """ Request/response transformation for Bedrock AgentCore A2A agents. @@ -152,11 +168,8 @@ class BedrockAgentCoreA2ATransformation: """ # Extract model and strip the "bedrock/" prefix # "bedrock/agentcore/arn:aws:..." → "agentcore/arn:aws:..." - model: Final = litellm_params.get("model", "") - if model.startswith("bedrock/"): - agentcore_model = model[len("bedrock/") :] - else: - agentcore_model = model + model: Final = _agentcore_model_name(litellm_params) + agentcore_model: Final = model.removeprefix("bedrock/") # Build optional_params from litellm_params (everything except model and custom_llm_provider) optional_params: Final = {k: v for k, v in litellm_params.items() if k not in ("model", "custom_llm_provider")} diff --git a/litellm/a2a_protocol/providers/watsonx_orchestrate/transformation.py b/litellm/a2a_protocol/providers/watsonx_orchestrate/transformation.py index 57c4a4677d0..c2d581321cd 100644 --- a/litellm/a2a_protocol/providers/watsonx_orchestrate/transformation.py +++ b/litellm/a2a_protocol/providers/watsonx_orchestrate/transformation.py @@ -8,11 +8,31 @@ WXO uses a REST API (not A2A/JSON-RPC) with an async-poll execution model: """ import asyncio -from collections.abc import AsyncIterator, Mapping -from typing import Any, Final +from collections.abc import AsyncIterator, Iterable, Mapping, Sequence +from itertools import chain +from typing import Final from uuid import uuid4 from litellm._logging import verbose_logger +from litellm.litellm_core_utils.core_helpers import as_str_mapping, iter_items +from litellm.llms.openai.common_utils import decoded_json_object + + +def _a2a_text_part(part: object) -> Sequence[object]: + part_fields: Final = as_str_mapping(part) + if not isinstance(part_fields, dict): + return () + if part_fields.get("kind") in (None, "", "text") and part_fields.get("text"): + return (part_fields["text"],) + return () + + +def _join_with_spaces(texts: Sequence[object]) -> str: + strings: Final = [text for text in texts if isinstance(text, str)] + if len(strings) == len(texts): + return " ".join(strings) + first_bad: Final = next(position for position, text in enumerate(texts) if not isinstance(text, str)) + raise TypeError(f"sequence item {first_bad}: expected str instance, {type(texts[first_bad]).__name__} found") class WatsonxOrchestrateTransformation: @@ -29,22 +49,16 @@ class WatsonxOrchestrateTransformation: return f"{cp4d_host.rstrip('/')}/orchestrate/cpd/instances/{instance_id}" @staticmethod - def extract_text_from_a2a_params(params: dict[str, Any]) -> str: + def extract_text_from_a2a_params(params: Mapping[str, object]) -> str: """ Extract user message text from A2A MessageSendParams. A2A format: params.message.parts[*] where part.kind == "text" """ - message: Final = params.get("message", {}) - parts: Final = message.get("parts", []) - texts: Final = [] - for part in parts: - if not isinstance(part, dict): - continue - kind = part.get("kind") - if kind in (None, "", "text") and part.get("text"): - texts.append(part["text"]) - return " ".join(texts) or "" + message: Final = decoded_json_object(params.get("message", {})) + parts: Final[Iterable[object]] = iter_items(message.get("parts", [])) + texts: Final = list(chain.from_iterable(map(_a2a_text_part, parts))) + return _join_with_spaces(texts) or "" @staticmethod def build_wxo_run_body( diff --git a/litellm/a2a_protocol/utils.py b/litellm/a2a_protocol/utils.py index 7400844bf28..17d1b86a609 100644 --- a/litellm/a2a_protocol/utils.py +++ b/litellm/a2a_protocol/utils.py @@ -4,15 +4,20 @@ Utility functions for A2A protocol. import hashlib from collections.abc import Mapping -from typing import TYPE_CHECKING, Any, Final +from typing import TYPE_CHECKING, Final, Protocol import litellm from litellm._logging import verbose_logger +from litellm.litellm_core_utils.core_helpers import has_attributes if TYPE_CHECKING: from a2a.types import SendMessageRequest, SendStreamingMessageRequest +class _SupportsModelDump(Protocol): + def model_dump(self, *, mode: str) -> object: ... + + class A2ARequestUtils: """Utility class for A2A request/response processing.""" @@ -74,7 +79,7 @@ class A2ARequestUtils: @staticmethod def get_input_message_from_request( request: "SendMessageRequest | SendStreamingMessageRequest", - ) -> Any: + ) -> object: """ Extract the input message from an A2A request. @@ -84,7 +89,7 @@ class A2ARequestUtils: Returns: The message object/dict or None """ - params: Final = getattr(request, "params", None) + params: Final[object] = getattr(request, "params", None) if params is None: return None return getattr(params, "message", None) @@ -127,10 +132,12 @@ class A2ARequestUtils: # the dict branch — request-side parts are a2a-sdk Part RootModels whose # kind/text live on part.root, which the object branch cannot read. This # mirrors how the response side already works (it operates on model_dump). - input_message = A2ARequestUtils.get_input_message_from_request(request) - if input_message is not None and hasattr(input_message, "model_dump"): - input_message = input_message.model_dump(mode="json") - input_text: Final = A2ARequestUtils.extract_text_from_message(input_message) + input_message: Final = A2ARequestUtils.get_input_message_from_request(request) + input_text: Final = A2ARequestUtils.extract_text_from_message( + input_message.model_dump(mode="json") + if has_attributes(input_message, _SupportsModelDump, "model_dump") + else input_message + ) prompt_tokens: Final = A2ARequestUtils.count_tokens(input_text) # Count output tokens diff --git a/litellm/anthropic_beta_headers_manager.py b/litellm/anthropic_beta_headers_manager.py index 61e36bd1e96..fec1d8e4465 100644 --- a/litellm/anthropic_beta_headers_manager.py +++ b/litellm/anthropic_beta_headers_manager.py @@ -45,6 +45,7 @@ _BETA_HEADERS_CONFIG_LOADER: Final = ThreadPoolExecutor(max_workers=1, thread_na BetaHeadersConfig: TypeAlias = Mapping[str, str | Mapping[str, str | None]] _BETA_HEADERS_CONFIG_ADAPTER: Final = TypeAdapter(BetaHeadersConfig) +_DECODED_JSON: Final = TypeAdapter(object) class GetAnthropicBetaHeadersConfig: @@ -76,7 +77,7 @@ class GetAnthropicBetaHeadersConfig: } @staticmethod - def _check_is_valid_dict(fetched_config: dict) -> bool: + def _check_is_valid_dict(fetched_config: object) -> bool: """Check if fetched config is a non-empty dict with expected structure.""" if not isinstance(fetched_config, dict): verbose_logger.warning( @@ -110,7 +111,7 @@ class GetAnthropicBetaHeadersConfig: return True @classmethod - def validate_beta_headers_config(cls, fetched_config: dict) -> bool: + def validate_beta_headers_config(cls, fetched_config: object) -> bool: """ Validate the integrity of a fetched beta headers config. @@ -119,7 +120,7 @@ class GetAnthropicBetaHeadersConfig: return cls._check_is_valid_dict(fetched_config) @staticmethod - def fetch_remote_beta_headers_config(url: str, timeout: int = 5) -> dict: + def fetch_remote_beta_headers_config(url: str, timeout: int = 5) -> object: """ Fetch the beta headers config from a remote URL. @@ -128,7 +129,7 @@ class GetAnthropicBetaHeadersConfig: """ response: Final = httpx.get(url, timeout=timeout) response.raise_for_status() - return response.json() + return _DECODED_JSON.validate_python(response.json()) def get_beta_headers_config(url: str) -> dict: @@ -161,7 +162,9 @@ def get_beta_headers_config(url: str) -> dict: return GetAnthropicBetaHeadersConfig.load_local_beta_headers_config() # Validate the fetched config - if not GetAnthropicBetaHeadersConfig.validate_beta_headers_config(fetched_config=content): + if not GetAnthropicBetaHeadersConfig.validate_beta_headers_config(fetched_config=content) or not isinstance( + content, dict + ): verbose_logger.warning( "LiteLLM: Fetched beta headers config failed integrity check. Using local backup instead. url=%s", url, diff --git a/litellm/anthropic_interface/exceptions/exception_mapping_utils.py b/litellm/anthropic_interface/exceptions/exception_mapping_utils.py index eb3ec8aaee2..d8198e41239 100644 --- a/litellm/anthropic_interface/exceptions/exception_mapping_utils.py +++ b/litellm/anthropic_interface/exceptions/exception_mapping_utils.py @@ -7,10 +7,14 @@ Similar to litellm/litellm_core_utils/exception_mapping_utils.py but for Anthrop import json from typing import Final +from pydantic import TypeAdapter + from litellm.litellm_core_utils.safe_json_loads import safe_json_loads from .exceptions import AnthropicErrorDetail, AnthropicErrorResponse, AnthropicErrorType +_PARSED_ERROR_BODY: Final = TypeAdapter(object) + # HTTP status code -> Anthropic error type # Source: https://docs.anthropic.com/en/api/errors ANTHROPIC_ERROR_TYPE_MAP: Final[dict[int, AnthropicErrorType]] = { @@ -79,7 +83,7 @@ class AnthropicExceptionMapping: - Generic: {"message": "..."} - Plain strings """ - parsed: Final = safe_json_loads(raw_message) + parsed: Final = _PARSED_ERROR_BODY.validate_python(safe_json_loads(raw_message)) if isinstance(parsed, dict): # Bedrock format if "detail" in parsed and isinstance(parsed["detail"], dict): @@ -145,9 +149,8 @@ class AnthropicExceptionMapping: AnthropicErrorResponse dict """ # Try to parse as JSON once - parsed: dict | None = safe_json_loads(raw_message) - if not isinstance(parsed, dict): - parsed = None + decoded: Final = _PARSED_ERROR_BODY.validate_python(safe_json_loads(raw_message)) + parsed: Final[dict[str, object] | None] = decoded if isinstance(decoded, dict) else None # If parsed and already in Anthropic format - passthrough if parsed is not None and AnthropicExceptionMapping._is_anthropic_error_dict(parsed): diff --git a/litellm/anthropic_interface/readme.md b/litellm/anthropic_interface/readme.md index a864e2572e6..99e18e17de0 100644 --- a/litellm/anthropic_interface/readme.md +++ b/litellm/anthropic_interface/readme.md @@ -57,6 +57,40 @@ async for chunk in response: print(chunk) ``` +### Optional opening token estimate + +When `/v1/messages` streams through the Chat Completions adapter, the opening +`message_start.usage.input_tokens` defaults to `0`. To show an estimated prompt +size while a response streams, enable `anthropic_messages_estimate_initial_input_tokens`. +This setting defaults to `false` and applies to all requests using this adapter + +For an existing proxy deployment, add the setting under `litellm_settings` in +`config.yaml` and restart the proxy. Use a YAML boolean, without quotes + +```yaml +litellm_settings: + anthropic_messages_estimate_initial_input_tokens: true +``` + +For the Python SDK, set the option before making streaming Messages requests + +```python +import litellm + +litellm.anthropic_messages_estimate_initial_input_tokens = True +``` + +Send a streaming Messages request to a Chat Completions-backed model, such as a +`hosted_vllm/` model. The opening `message_start` event includes the estimated +input count. If estimation fails, the count remains `0`. Set the option to +`false` in YAML or `False` in Python to disable estimation and skip token counting + +The opening count is approximate and is not suitable for billing or enforcing +exact context limits. Opening output and cache counts remain `0`. Final +`message_delta` usage still comes from the provider and takes precedence over the +opening estimate. Native Anthropic streams, the Responses adapter, and +non-streaming responses are unaffected. This setting does not select the adapter + ### LiteLLM Proxy Server @@ -113,4 +147,4 @@ curl -L -X POST 'http://0.0.0.0:4000/v1/messages' \ ], "max_tokens": 100 }' -``` \ No newline at end of file +``` diff --git a/litellm/assistants/main.py b/litellm/assistants/main.py index a3428261636..a5721c6f047 100644 --- a/litellm/assistants/main.py +++ b/litellm/assistants/main.py @@ -77,7 +77,7 @@ def get_assistants( api_base: str | None = None, api_version: str | None = None, **kwargs, -) -> SyncCursorPage[Assistant]: +) -> SyncCursorPage[Assistant] | Coroutine[None, None, AsyncCursorPage[Assistant]]: aget_assistants: Final[bool | None] = kwargs.pop("aget_assistants", None) if aget_assistants is not None and not isinstance(aget_assistants, bool): raise Exception("Invalid value passed in for aget_assistants. Only bool or None allowed") @@ -100,7 +100,7 @@ def get_assistants( elif timeout is None: timeout = 600.0 - response: SyncCursorPage[Assistant] | None = None + response: SyncCursorPage[Assistant] | Coroutine[None, None, AsyncCursorPage[Assistant]] | None = None if custom_llm_provider == "openai": api_base = ( optional_params.api_base # for deepinfra/perplexity/anyscale/groq we check in get_llm_provider and pass in the api base from there @@ -564,7 +564,7 @@ def create_thread( tool_resources: OpenAICreateThreadParamsToolResources | None = None, client: OpenAI | None = None, **kwargs, -) -> Thread: +) -> Thread | Coroutine[None, None, Thread]: """ - get the llm provider - if openai - route it there @@ -610,7 +610,7 @@ def create_thread( api_base: str | None = None api_key: str | None = None - response: Thread | None = None + response: Thread | Coroutine[None, None, Thread] | None = None if custom_llm_provider == "openai": api_base = ( optional_params.api_base # for deepinfra/perplexity/anyscale/groq we check in get_llm_provider and pass in the api base from there @@ -735,7 +735,7 @@ def get_thread( thread_id: str, client=None, **kwargs, -) -> Thread: +) -> Thread | Coroutine[None, None, Thread]: """Get the thread object, given a thread_id""" aget_thread: Final = kwargs.pop("aget_thread", None) optional_params: Final = GenericLiteLLMParams(**kwargs) @@ -757,7 +757,7 @@ def get_thread( timeout = 600.0 api_base: str | None = None api_key: str | None = None - response: Thread | None = None + response: Thread | Coroutine[None, None, Thread] | None = None if custom_llm_provider == "openai": api_base = ( optional_params.api_base # for deepinfra/perplexity/anyscale/groq we check in get_llm_provider and pass in the api base from there @@ -903,7 +903,7 @@ def add_message( metadata: dict | None = None, client=None, **kwargs, -) -> OpenAIMessage: +) -> OpenAIMessage | Coroutine[None, None, OpenAIMessage]: ### COMMON OBJECTS ### a_add_message: Final = kwargs.pop("a_add_message", None) _message_data: Final = MessageData(role=role, content=content, attachments=attachments, metadata=metadata) @@ -935,7 +935,7 @@ def add_message( timeout = 600.0 api_key: str | None = None api_base: str | None = None - response: OpenAIMessage | None = None + response: OpenAIMessage | Coroutine[None, None, OpenAIMessage] | None = None if custom_llm_provider == "openai": api_base = ( optional_params.api_base # for deepinfra/perplexity/anyscale/groq we check in get_llm_provider and pass in the api base from there @@ -1065,7 +1065,7 @@ def get_messages( thread_id: str, client: Any | None = None, **kwargs, -) -> SyncCursorPage[OpenAIMessage]: +) -> SyncCursorPage[OpenAIMessage] | Coroutine[None, None, AsyncCursorPage[OpenAIMessage]]: aget_messages: Final = kwargs.pop("aget_messages", None) optional_params: Final = GenericLiteLLMParams(**kwargs) litellm_params_dict: Final = get_litellm_params(**kwargs) @@ -1086,7 +1086,7 @@ def get_messages( elif timeout is None: timeout = 600.0 - response: SyncCursorPage[OpenAIMessage] | None = None + response: SyncCursorPage[OpenAIMessage] | Coroutine[None, None, AsyncCursorPage[OpenAIMessage]] | None = None api_key: str | None = None api_base: str | None = None if custom_llm_provider == "openai": @@ -1256,7 +1256,7 @@ def run_thread( client: object | None = None, event_handler: AssistantEventHandler | None = None, # for stream=True calls **kwargs, -) -> Run: +) -> Run | Coroutine[None, None, Run]: """Run a given thread + assistant.""" arun_thread: Final = kwargs.pop("arun_thread", None) optional_params: Final = GenericLiteLLMParams(**kwargs) @@ -1278,7 +1278,7 @@ def run_thread( elif timeout is None: timeout = 600.0 - response: Run | None = None + response: Run | Coroutine[None, None, Run] | None = None if custom_llm_provider == "openai": api_base = ( optional_params.api_base # for deepinfra/perplexity/anyscale/groq we check in get_llm_provider and pass in the api base from there diff --git a/litellm/caching/_embedding_router.py b/litellm/caching/_embedding_router.py index d82e58ecc91..0e7589d88ab 100644 --- a/litellm/caching/_embedding_router.py +++ b/litellm/caching/_embedding_router.py @@ -13,7 +13,7 @@ This module is dependency-injected: callers pass the proxy ``llm_router`` and from __future__ import annotations from collections.abc import Mapping, Sequence -from typing import TYPE_CHECKING, Any, Final +from typing import TYPE_CHECKING, Final import litellm from litellm.constants import SEMANTIC_CACHE_EMBEDDING_TIMEOUT_SECONDS @@ -25,12 +25,12 @@ if TYPE_CHECKING: def resolve_embedding_router( embedding_model: str, llm_router: Router | None, - llm_model_list: list[dict[str, Any]] | None, + llm_model_list: Sequence[Mapping[str, object]] | None, ) -> Router | None: """Return ``llm_router`` iff it serves ``embedding_model`` as a deployment.""" if llm_router is None: return None - router_model_names: Final[list[str]] = ( + router_model_names: Final[Sequence[object]] = ( [m["model_name"] for m in llm_model_list if "model_name" in m] if llm_model_list is not None else [] ) if embedding_model in router_model_names: diff --git a/litellm/caching/affinity_cache.py b/litellm/caching/affinity_cache.py index 2d27574b098..d9a40c44d2b 100644 --- a/litellm/caching/affinity_cache.py +++ b/litellm/caching/affinity_cache.py @@ -24,6 +24,16 @@ if current == false then end if ARGV[3] then local decoded, stored = pcall(cjson.decode, current) + if ARGV[4] then + local legacy = current + if decoded and type(stored) == 'string' then legacy = stored end + for _, eligible in ipairs(cjson.decode(ARGV[3])) do + if eligible['model_id'] == legacy then + redis.call('EXPIRE', KEYS[1], ARGV[2]) + return current + end + end + end if decoded and type(stored) == 'table' then for _, eligible in ipairs(cjson.decode(ARGV[3])) do local matches = true @@ -68,6 +78,7 @@ def claim_affinity_pin_in_memory( ttl_seconds: int, *, eligible_values: tuple[Mapping[str, str], ...] | None = None, + preserve_legacy_model_ids: bool = False, ) -> object: """No await between read and write, so same-loop claims agree during a Redis outage.""" existing: Final[object] = cache.in_memory_cache.get_cache(cache_key) @@ -75,7 +86,12 @@ def claim_affinity_pin_in_memory( if _legacy_pin_matches(existing, pin_value): set_local_affinity_pin(cache, cache_key, pin_value, ttl_seconds) return existing - winner: Final = existing if existing is not None and existing in (eligible_values or ()) else pin_value + eligible_existing: Final = existing in (eligible_values or ()) or ( + preserve_legacy_model_ids + and isinstance(existing, str) + and any("model_id" in value and _legacy_pin_matches(existing, value) for value in (eligible_values or ())) + ) + winner: Final = existing if existing is not None and eligible_existing else pin_value set_local_affinity_pin(cache, cache_key, winner, ttl_seconds) return winner @@ -94,6 +110,7 @@ async def claim_affinity_pin( ttl_seconds: int, *, eligible_values: tuple[Mapping[str, str], ...] | None = None, + preserve_legacy_model_ids: bool = False, ) -> object: """Return the authoritative first writer, replacing it only when it becomes ineligible. @@ -112,6 +129,7 @@ async def claim_affinity_pin( if eligible_values is not None else () ), + *(("1",) if preserve_legacy_model_ids and eligible_values is not None else ()), ) raw: Final = cast( # cast-ok: Redis scripts return heterogeneous values; only object is asserted here object, await claim_script(keys=(cache_key,), args=args) @@ -124,4 +142,11 @@ async def claim_affinity_pin( return winner except Exception as error: # noqa: BLE001 # Redis/Lua faults retain same-pod affinity through local claims verbose_router_logger.debug("Affinity cache: Redis claim failed, using pod-local claim. error=%s", error) - return claim_affinity_pin_in_memory(cache, cache_key, pin_value, ttl_seconds, eligible_values=eligible_values) + return claim_affinity_pin_in_memory( + cache, + cache_key, + pin_value, + ttl_seconds, + eligible_values=eligible_values, + preserve_legacy_model_ids=preserve_legacy_model_ids, + ) diff --git a/litellm/caching/azure_blob_cache.py b/litellm/caching/azure_blob_cache.py index bf0e15421bc..5b9071dc920 100644 --- a/litellm/caching/azure_blob_cache.py +++ b/litellm/caching/azure_blob_cache.py @@ -13,10 +13,14 @@ import json from contextlib import suppress from typing import Final +from pydantic import TypeAdapter + from litellm._logging import print_verbose, verbose_logger from .base_cache import BaseCache +_DECODED_BLOB: Final = TypeAdapter(object) + class AzureBlobCache(BaseCache): def __init__(self, account_url, container) -> None: @@ -65,7 +69,7 @@ class AzureBlobCache(BaseCache): print_verbose(f"Get Azure Blob Cache: key: {key}") as_bytes: Final = self.container_client.download_blob(key).readall() as_str: Final = as_bytes.decode("utf-8") - cached_response: Final[object] = json.loads(as_str) + cached_response: Final = _DECODED_BLOB.validate_python(json.loads(as_str)) verbose_logger.debug( "Got Azure Blob Cache: key: %s, cached_response %s. Type Response %s", @@ -86,7 +90,7 @@ class AzureBlobCache(BaseCache): blob: Final = await self.async_container_client.download_blob(key) as_bytes: Final = await blob.readall() as_str: Final = as_bytes.decode("utf-8") - cached_response: Final[object] = json.loads(as_str) + cached_response: Final = _DECODED_BLOB.validate_python(json.loads(as_str)) verbose_logger.debug( "Got Azure Blob Cache: key: %s, cached_response %s. Type Response %s", key, diff --git a/litellm/caching/base_cache.py b/litellm/caching/base_cache.py index 51c169ba796..4dc894a64ba 100644 --- a/litellm/caching/base_cache.py +++ b/litellm/caching/base_cache.py @@ -9,14 +9,7 @@ Has 4 methods: """ from abc import ABC, abstractmethod -from typing import TYPE_CHECKING, Any, Final - -if TYPE_CHECKING: - from opentelemetry.trace import Span as _Span - - Span = _Span | Any -else: - Span = Any +from typing import Final class BaseCache(ABC): diff --git a/litellm/caching/caching_handler.py b/litellm/caching/caching_handler.py index 7089ff78835..affabc6cc74 100644 --- a/litellm/caching/caching_handler.py +++ b/litellm/caching/caching_handler.py @@ -56,7 +56,7 @@ from litellm.types.utils import ( if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj - from litellm.llms.anthropic.pass_through.messages.response_cache import ( + from litellm.llms.anthropic.messages.native.response_cache import ( AnthropicMessagesStreamCacheWriter, ) from litellm.types.utils import PromptTokensDetailsWrapper @@ -182,7 +182,7 @@ def _should_defer_streaming_cache_hit_callbacks(*, cached_result: object) -> boo spend and callback records. A plain (non-stream) replay logs here, since nothing else will. """ - from litellm.llms.anthropic.pass_through.messages.response_cache import ( + from litellm.llms.anthropic.messages.native.response_cache import ( CachedAnthropicMessagesStreamIterator, ) from litellm.responses.streaming_iterator import BaseResponsesAPIStreamingIterator @@ -1040,7 +1040,7 @@ class LLMCachingHandler: elif ( call_type == CallTypes.anthropic_messages.value or call_type == CallTypes.aanthropic_messages.value ) and isinstance(cached_result, dict): - from litellm.llms.anthropic.pass_through.messages.response_cache import ( + from litellm.llms.anthropic.messages.native.response_cache import ( convert_cached_anthropic_messages_result, ) @@ -1270,7 +1270,7 @@ class LLMCachingHandler: return result if not isinstance(result, AsyncIterator): return result - from litellm.llms.anthropic.pass_through.messages.response_cache import ( + from litellm.llms.anthropic.messages.native.response_cache import ( AnthropicMessagesStreamCacheWriter, ) diff --git a/litellm/caching/disk_cache.py b/litellm/caching/disk_cache.py index 50939ad51ca..9470f23570a 100644 --- a/litellm/caching/disk_cache.py +++ b/litellm/caching/disk_cache.py @@ -1,15 +1,19 @@ import json from typing import TYPE_CHECKING, Any, Final +from pydantic import TypeAdapter + from .base_cache import BaseCache if TYPE_CHECKING: from opentelemetry.trace import Span as _Span - Span = _Span | Any + Span = _Span else: Span = Any +_DECODED_DISK_VALUE: Final = TypeAdapter(object) + class DiskCache(BaseCache): def __init__(self, disk_cache_dir: str | None = None): @@ -44,7 +48,7 @@ class DiskCache(BaseCache): original_cached_response: Final = self.disk_cache.get(key) if original_cached_response: try: - cached_response = json.loads(original_cached_response) + cached_response = _DECODED_DISK_VALUE.validate_python(json.loads(original_cached_response)) except Exception: cached_response = original_cached_response return cached_response diff --git a/litellm/caching/redis_cache.py b/litellm/caching/redis_cache.py index eb17facfb12..afe6f8a1eab 100644 --- a/litellm/caching/redis_cache.py +++ b/litellm/caching/redis_cache.py @@ -1738,7 +1738,9 @@ class RedisCache(BaseCache): return key_value_dict @_redis_circuit_breaker_guard - async def async_get_cache(self, key, parent_otel_span: Span | None = None, **kwargs): + async def async_get_cache( + self, key, parent_otel_span: Span | None = None, *, raise_on_error: bool = False, **kwargs + ): from redis.asyncio import Redis _redis_client: Final[Redis] = self.init_async_client() @@ -1781,6 +1783,8 @@ class RedisCache(BaseCache): ) ) print_verbose(f"litellm.caching.caching: async get() - Got exception from REDIS: {e}") + if raise_on_error: + raise _record_swallowed_redis_failure(self._circuit_breaker, e) @_redis_circuit_breaker_guard diff --git a/litellm/constants.py b/litellm/constants.py index c0fe0491775..2901b7d8948 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -480,6 +480,7 @@ REDIS_DAILY_END_USER_SPEND_UPDATE_BUFFER_KEY: Final = "litellm_daily_end_user_sp REDIS_DAILY_AGENT_SPEND_UPDATE_BUFFER_KEY: Final = "litellm_daily_agent_spend_update_buffer" REDIS_DAILY_TAG_SPEND_UPDATE_BUFFER_KEY: Final = "litellm_daily_tag_spend_update_buffer" REDIS_WINDOW_SPEND_UPDATE_BUFFER_KEY: Final = "litellm_window_spend_update_buffer" +REDIS_TOOL_DISCOVERY_BUFFER_KEY: Final = "litellm_tool_discovery_buffer" MAX_REDIS_BUFFER_DEQUEUE_COUNT: Final = get_env_int("MAX_REDIS_BUFFER_DEQUEUE_COUNT", 100) REDIS_SPEND_LOGS_BUFFER_KEY: Final = "litellm_spend_logs_buffer" REDIS_SPEND_LOGS_BUFFER_MAX_ROWS: Final = 100000 @@ -626,7 +627,7 @@ BEDROCK_MIN_THINKING_BUDGET_TOKENS: Final = get_env_int("BEDROCK_MIN_THINKING_BU # Anthropic's Messages API rejects thinking.budget_tokens < 1024. ANTHROPIC_MIN_THINKING_BUDGET_TOKENS: Final = 1024 REPLICATE_POLLING_DELAY_SECONDS: Final = get_env_float("REPLICATE_POLLING_DELAY_SECONDS", 0.5) -DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS: Final = get_env_int("DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS", 4096) +DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS: Final = get_env_int("DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS", 128000) DEFAULT_OCI_CHAT_MAX_TOKENS: Final = 4096 TOGETHER_AI_4_B: Final = get_env_int("TOGETHER_AI_4_B", 4) TOGETHER_AI_8_B: Final = get_env_int("TOGETHER_AI_8_B", 8) @@ -861,6 +862,7 @@ LITELLM_CHAT_PROVIDERS: Final = [ "heroku", "oci", "morph", + "opencode_go", "lambda_ai", "inception", "vercel_ai_gateway", @@ -1116,6 +1118,7 @@ openai_compatible_providers: Final[list[str]] = [ "v0", "helicone", "morph", + "opencode_go", "lambda_ai", "inception", "hyperbolic", @@ -1842,6 +1845,7 @@ LITELLM_UI_SESSION_DURATION: Final = os.getenv("LITELLM_UI_SESSION_DURATION", "2 ########################### DB CRON JOB NAMES ########################### DB_SPEND_UPDATE_JOB_NAME: Final = "db_spend_update_job" +TOOL_DISCOVERY_COMMIT_JOB_NAME: Final = "tool_discovery_commit_job" DB_DAILY_TAG_SPEND_UPDATE_JOB_NAME: Final = "db_daily_tag_spend_update_job" PROMETHEUS_EMIT_BUDGET_METRICS_JOB_NAME: Final = "prometheus_emit_budget_metrics" CLOUDZERO_EXPORT_USAGE_DATA_JOB_NAME: Final = "cloudzero_export_usage_data" diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py index 550bbfcde98..86b22069a39 100644 --- a/litellm/cost_calculator.py +++ b/litellm/cost_calculator.py @@ -37,6 +37,7 @@ from litellm.litellm_core_utils.llm_cost_calc.utils import ( _SERVICE_TIER_TO_COST_KEY_SUFFIX, BilledTokenRates, CostCalculatorUtils, + calculate_cache_writing_cost, calculate_cost_component, generic_cost_per_character, generic_cost_per_token, @@ -1200,12 +1201,16 @@ def get_usage_object( elif isinstance(usage_obj, dict): return Usage(**usage_obj) elif isinstance(usage_obj, BaseModel): - return Usage(**usage_obj.model_dump()) + return _usage_from_model(usage_obj) else: verbose_logger.debug("Unknown usage object type: %s, usage_obj: %s", type(usage_obj), usage_obj) return None +def _usage_from_model(usage_model: BaseModel) -> Usage: + return Usage(**usage_model.model_dump()) + + def _decisions_prompt_tokens_details(usage: DecisionsUsage | OpenAIDecisionUsage) -> PromptTokensDetailsWrapper: match usage: case DecisionsUsage(): @@ -1546,6 +1551,8 @@ def completion_cost( """ try: call_type = infer_call_type(call_type, completion_response) or "completion" + if isinstance(completion_response, DecisionsResponse) and completion_response.usage is None: + raise ValueError("Cannot calculate Decisions cost: provider did not report usage") if pricing_provider is not None: custom_llm_provider = pricing_provider # rebind-ok: model_info.pricing_provider overrides the routing provider for cost-map lookups @@ -1686,7 +1693,7 @@ def completion_cost( setattr( completion_response, "usage", - litellm.Usage(**_usage_for_dump.model_dump()), + _usage_from_model(_usage_for_dump), ) if isinstance(usage_obj, (DecisionsUsage, OpenAIDecisionUsage)): _usage = _decisions_usage(usage_obj).model_dump() @@ -1973,7 +1980,7 @@ def completion_cost( base_pricing_model=(selected_model if base_model is not None and not custom_pricing else None), ) elif call_type == _MCP_CALL_TYPE: - from litellm.proxy._experimental.mcp_server.cost_calculator import ( + from litellm.proxy.mcp_server.cost_calculator import ( MCPCostCalculator, ) @@ -2264,6 +2271,8 @@ def response_cost_calculator( ### VERTEX LOCATION ### vertex_location: str | None = None, # for Vertex AI regional-endpoint uplift (e.g. "us-east5", "global") region_name: str | None = None, + custom_cost_per_token: CostPerToken | None = None, + custom_cost_per_second: float | None = None, ) -> float: """ Returns @@ -2292,6 +2301,8 @@ def response_cost_calculator( optional_params=optional_params, custom_pricing=custom_pricing, base_model=base_model, + custom_cost_per_token=custom_cost_per_token, + custom_cost_per_second=custom_cost_per_second, prompt=prompt, standard_built_in_tools_params=standard_built_in_tools_params, litellm_model_name=litellm_model_name, @@ -2875,6 +2886,7 @@ def _batch_rate( model_info: ModelInfo, key: Literal[ "input_cost_per_audio_token_batches", + "cache_read_input_audio_token_cost_batches", "input_cost_per_image_token_batches", "input_cost_per_video_token_batches", ], @@ -2960,7 +2972,12 @@ def batch_cost_calculator( total_completion_cost = 0.0 if batch_rates.input is not None: total_prompt_cost = _batch_prompt_cost( - usage, model_info, batch_rates.input, batch_rates.cache_read, batch_rates.cache_creation + usage, + model_info, + batch_rates.input, + batch_rates.cache_read, + batch_rates.cache_creation, + batch_rates.cache_creation_rates_by_ttl, ) elif input_cost_per_token: details: Final = parse_prompt_tokens_details(usage) @@ -3005,10 +3022,13 @@ def _batch_prompt_cost( input_rate: float, cache_read_rate: float | None, cache_creation_rate: float | None, + cache_creation_rates_by_ttl: Mapping[str, float], ) -> float: details: Final = parse_prompt_tokens_details(usage) cached_tokens: Final = details["cache_hit_tokens"] if cache_read_rate is not None else 0 - written_tokens: Final = details["cache_creation_tokens"] if cache_creation_rate is not None else 0 + cached_audio_tokens: Final = details["cache_hit_audio_tokens"] if cache_read_rate is not None else 0 + bills_cache_writes: Final = cache_creation_rate is not None or bool(cache_creation_rates_by_ttl) + written_tokens: Final = details["cache_creation_tokens"] if bills_cache_writes else 0 audio_tokens, image_tokens, video_tokens = ( details["audio_tokens"], details["image_tokens"], @@ -3022,13 +3042,27 @@ def _batch_prompt_cost( + audio_tokens * _batch_rate(model_info, "input_cost_per_audio_token_batches", input_rate) + image_tokens * _batch_rate(model_info, "input_cost_per_image_token_batches", input_rate) + video_tokens * _batch_rate(model_info, "input_cost_per_video_token_batches", input_rate) - + cached_tokens * (cache_read_rate or 0.0) - + written_tokens * (cache_creation_rate or 0.0) + + (cached_tokens - cached_audio_tokens) * (cache_read_rate or 0.0) + + cached_audio_tokens + * _batch_rate(model_info, "cache_read_input_audio_token_cost_batches", cache_read_rate or 0.0) + + ( + calculate_cache_writing_cost( + written_tokens, + details["cache_creation_token_details"], + input_rate if cache_creation_rate is None else cache_creation_rate, + cache_creation_rates_by_ttl, + ) + if bills_cache_writes + else 0.0 + ) ) +_ATTRIBUTE_VALUE: Final = TypeAdapter(object) + + def _attribute_value(obj: object, name: str) -> object: - return getattr(obj, name) + return _ATTRIBUTE_VALUE.validate_python(getattr(obj, name)) def _summable_prompt_token_fields(prompt_tokens_details: BaseModel) -> list[str]: @@ -3663,7 +3697,26 @@ def _get_model_info_or_none(model: str, custom_llm_provider: str) -> ModelInfo | return None -def _declared_transcription_rate(info: ModelInfo | None, keys: tuple[str, ...]) -> float | None: +_TranscriptionRateKey: TypeAlias = Literal[ + "input_cost_per_second", "input_cost_per_audio_token", "input_cost_per_token", "output_cost_per_token" +] + + +def _model_info_rate(info: ModelInfo, key: _TranscriptionRateKey) -> float | None: + match key: + case "input_cost_per_second": + return info.get("input_cost_per_second") + case "input_cost_per_audio_token": + return info.get("input_cost_per_audio_token") + case "input_cost_per_token": + return info.get("input_cost_per_token") + case "output_cost_per_token": + return info.get("output_cost_per_token") + case _: + assert_never(key) + + +def _declared_transcription_rate(info: ModelInfo | None, keys: tuple[_TranscriptionRateKey, ...]) -> float | None: """First of ``keys`` this entry prices, read off the raw ``litellm.model_cost`` entry because ``get_model_info`` synthesizes zero token rates for entries that omit them.""" if info is None: @@ -3672,12 +3725,18 @@ def _declared_transcription_rate(info: ModelInfo | None, keys: tuple[str, ...]) if declared is None: return None return next( - (float(value) for key in keys if declared.get(key) is not None and (value := info.get(key)) is not None), + ( + float(value) + for key in keys + if declared.get(key) is not None and (value := _model_info_rate(info, key)) is not None + ), None, ) -def _transcription_rate(keys: tuple[str, ...], override: ModelInfo | None, base: ModelInfo | None) -> float: +def _transcription_rate( + keys: tuple[_TranscriptionRateKey, ...], override: ModelInfo | None, base: ModelInfo | None +) -> float: rates: Final = (_declared_transcription_rate(info, keys) for info in (override, base)) return next((rate for rate in rates if rate is not None), 0.0) diff --git a/litellm/decisions/call.py b/litellm/decisions/call.py index abbeccc10b3..3b73f65c917 100644 --- a/litellm/decisions/call.py +++ b/litellm/decisions/call.py @@ -456,10 +456,14 @@ def prepare_call( extra_headers: Mapping[str, str] | None, kwargs: Mapping[str, object], ) -> DecisionsCall: + base_url_alias: Final = kwargs.get("base_url") + call_api_base: Final = ( + base_url_alias if api_base is None and isinstance(base_url_alias, str) and base_url_alias else api_base + ) upstream_model, provider, dynamic_api_key, dynamic_api_base = litellm.get_llm_provider( model=model, custom_llm_provider=custom_llm_provider, - api_base=api_base, + api_base=call_api_base, api_key=api_key, ) provider_config: Final = _provider_config(upstream_model, provider) @@ -488,7 +492,7 @@ def prepare_call( try: resolved_api_base, static_api_key = provider_config.resolve_connection( - dynamic_api_base or api_base, dynamic_api_key or api_key + dynamic_api_base or call_api_base, dynamic_api_key or api_key ) except ValueError as error: raise litellm.BadRequestError(message=str(error), model=model, llm_provider=provider) from error diff --git a/litellm/exceptions.py b/litellm/exceptions.py index 733f1aa72d5..b8e933bf046 100644 --- a/litellm/exceptions.py +++ b/litellm/exceptions.py @@ -1273,7 +1273,7 @@ class MidStreamFallbackError(ServiceUnavailableError): self.message = _saved_message self.args = (_saved_message,) - original_headers: Final = getattr(original_exception, "litellm_response_headers", None) + original_headers: Final[object] = getattr(original_exception, "litellm_response_headers", None) if original_headers is not None: self.litellm_response_headers = original_headers diff --git a/litellm/experimental_mcp_client/__init__.py b/litellm/experimental_mcp_client/__init__.py index 7a3917a50ea..f2905c0f95c 100644 --- a/litellm/experimental_mcp_client/__init__.py +++ b/litellm/experimental_mcp_client/__init__.py @@ -1,8 +1,7 @@ -try: - from .tools import call_openai_tool, load_mcp_tools -except ModuleNotFoundError as exc: - if exc.name not in ("mcp", "httpx2"): - raise - raise ImportError("MCP client dependencies are missing. Install them with: pip install 'litellm[mcp]'") from exc +import litellm.mcp_client as _mcp_client +from litellm.litellm_core_utils.deprecated_package import alias_deprecated_package +from litellm.mcp_client import call_openai_tool, load_mcp_tools + +alias_deprecated_package(__name__, _mcp_client) __all__ = ["call_openai_tool", "load_mcp_tools"] diff --git a/litellm/files/main.py b/litellm/files/main.py index 16ff5b02f9c..c5172bc01ae 100644 --- a/litellm/files/main.py +++ b/litellm/files/main.py @@ -9,7 +9,7 @@ import asyncio import contextvars import time import uuid as uuid_module -from collections.abc import Coroutine +from collections.abc import Awaitable, Coroutine from functools import partial from typing import Final, Literal, cast @@ -293,6 +293,14 @@ def create_file( raise e +async def _await_retrieved_file(pending: Awaitable[FileObject | OpenAIFileObject]) -> FileObject | OpenAIFileObject: + return await pending + + +async def _await_deleted_file(pending: Awaitable[object]) -> object: + return await pending + + @client async def afile_retrieve( file_id: str, @@ -325,7 +333,7 @@ async def afile_retrieve( func_with_context: Final = partial(ctx.run, func) init_response: Final = await loop.run_in_executor(None, func_with_context) if asyncio.iscoroutine(init_response): - response = await init_response + response = await _await_retrieved_file(init_response) else: response = init_response @@ -505,7 +513,7 @@ async def afile_delete( func_with_context: Final = partial(ctx.run, func) init_response: Final = await loop.run_in_executor(None, func_with_context) if asyncio.iscoroutine(init_response): - response = await init_response + response = await _await_deleted_file(init_response) else: response = init_response diff --git a/litellm/files/streaming.py b/litellm/files/streaming.py index 460050872f4..e9a030e0e32 100644 --- a/litellm/files/streaming.py +++ b/litellm/files/streaming.py @@ -1,7 +1,7 @@ import datetime import traceback from collections.abc import AsyncIterator, Iterator -from typing import TYPE_CHECKING, Any, Final, Optional, cast +from typing import TYPE_CHECKING, Final, Optional, cast import anyio @@ -163,7 +163,7 @@ class FileContentStreamingResponse: merged_hidden_params: Final = cast( "StandardLoggingHiddenParams", { - **cast(dict[str, Any], payload.get("hidden_params") or {}), + **(payload.get("hidden_params") or {}), **self._hidden_params, }, ) diff --git a/litellm/harness/handlers/base.py b/litellm/harness/handlers/base.py index 18b7391e988..4721e9d6ff2 100644 --- a/litellm/harness/handlers/base.py +++ b/litellm/harness/handlers/base.py @@ -4,7 +4,6 @@ from __future__ import annotations from abc import ABC, abstractmethod from collections.abc import AsyncIterator -from typing import Any from litellm.harness.context import SessionContext from litellm.harness.errors import CapabilityUnsupported @@ -38,5 +37,5 @@ class BaseHarnessHandler(ABC): async def resume(self, ctx: SessionContext, native_session_id: str) -> None: """Continue the runtime's own session on the next turn.""" - async def history(self, ctx: SessionContext) -> list[dict[str, Any]]: # mutable-ok: public history() API shape + async def history(self, ctx: SessionContext) -> list[dict[str, object]]: # mutable-ok: public history() API shape raise CapabilityUnsupported(f"Harness.{self.config.harness.name} does not expose history") diff --git a/litellm/harness/handlers/cli_handler.py b/litellm/harness/handlers/cli_handler.py index 6320a877e6b..b01f449a67d 100644 --- a/litellm/harness/handlers/cli_handler.py +++ b/litellm/harness/handlers/cli_handler.py @@ -70,10 +70,10 @@ async def send_stdin(proc: Process, data: str) -> None: async def private_dir_for(sandbox: Sandbox) -> str: - tempdir = getattr(sandbox, "tempdir", None) + tempdir: Final = sandbox.tempdir if hasattr(sandbox, "tempdir") else None if tempdir is None: raise SandboxError(f"{type(sandbox).__name__} has no tempdir(); CLI harnesses need a private config dir") - path: str = await tempdir() + path: Final = await tempdir() return path diff --git a/litellm/harness/handlers/deepagents_handler.py b/litellm/harness/handlers/deepagents_handler.py index 4a36b1a08d1..f6785323292 100644 --- a/litellm/harness/handlers/deepagents_handler.py +++ b/litellm/harness/handlers/deepagents_handler.py @@ -161,7 +161,7 @@ class DeepAgentsHandler(BaseHarnessHandler): async def history( self, ctx: SessionContext - ) -> list[dict[str, Any]]: # mutable-ok: BaseHarnessHandler.history API returns OpenAI message dicts + ) -> list[dict[str, object]]: # mutable-ok: BaseHarnessHandler.history API returns OpenAI message dicts agent, deps = self._require_agent() snapshot = await agent.aget_state(self._run_config(ctx, None)) messages = (snapshot.values or MappingProxyType({})).get("messages") or () diff --git a/litellm/harness/runtime.py b/litellm/harness/runtime.py index dc24a1f0ef7..1d946521bfa 100644 --- a/litellm/harness/runtime.py +++ b/litellm/harness/runtime.py @@ -12,11 +12,10 @@ import inspect import logging import os import uuid -from collections.abc import AsyncIterator, Callable, Coroutine, Generator, Mapping, Sequence +from collections.abc import AsyncIterator, Awaitable, Callable, Coroutine, Generator, Mapping, Sequence from dataclasses import dataclass, field from types import MappingProxyType from typing import ( - Any, Final, get_args, ) @@ -331,11 +330,15 @@ async def _put_end(queue: asyncio.Queue[Event | _End], end: _End) -> None: queue.put_nowait(end) +async def _await_decision(pending: Awaitable[object]) -> object: + return await pending + + async def call_approval_handler(handler: ApprovalHandler, approval: Approval) -> None: """Run on_approval (sync in a worker thread, or async) and resolve approval.""" try: if inspect.iscoroutinefunction(handler): - decision: object = await handler(approval) + decision: object = await _await_decision(handler(approval)) else: decision = await asyncio.to_thread(handler, approval) if inspect.isawaitable(decision): @@ -749,7 +752,7 @@ class AsyncSession: async def history( self, - ) -> list[dict[str, Any]]: # mutable-ok: public API returns OpenAI-format message dicts from the handler + ) -> list[dict[str, object]]: # mutable-ok: public API returns OpenAI-format message dicts from the handler if not self.harness_config.capabilities.history: raise CapabilityUnsupported(f"Harness.{self.config.harness.name} does not expose history") await self._ensure_ready() diff --git a/litellm/images/main.py b/litellm/images/main.py index 7f94835d59b..9c88e737a40 100644 --- a/litellm/images/main.py +++ b/litellm/images/main.py @@ -1,9 +1,9 @@ import asyncio import contextvars import importlib -from collections.abc import Coroutine +from collections.abc import Coroutine, Mapping from functools import partial -from typing import TYPE_CHECKING, Final, Literal, Optional, cast, overload +from typing import TYPE_CHECKING, Final, Literal, cast, overload from pydantic import TypeAdapter, ValidationError @@ -70,20 +70,62 @@ from litellm.utils import ( _PROVIDER_ROUTING_HINTS: Final = TypeAdapter(ProviderRoutingHints) # Cache for ImageEditRequestUtils to avoid repeated __getattr__ calls -_ImageEditRequestUtils_cache: Optional["ImageEditRequestUtils"] = None +_ImageEditRequestUtils_cache: type["ImageEditRequestUtils"] | None = None -def _get_ImageEditRequestUtils() -> "ImageEditRequestUtils": +def _get_ImageEditRequestUtils() -> type["ImageEditRequestUtils"]: """Get ImageEditRequestUtils, loading it lazily if needed.""" global _ImageEditRequestUtils_cache if _ImageEditRequestUtils_cache is None: # Access via module to trigger __getattr__ if not cached - module: Final = importlib.import_module(__name__) - _ImageEditRequestUtils_cache = module.ImageEditRequestUtils + from litellm.images import main as images_main + + _ImageEditRequestUtils_cache = images_main.ImageEditRequestUtils assert _ImageEditRequestUtils_cache is not None # Type narrowing for type checker return _ImageEditRequestUtils_cache +def _chatgpt_image_params(kwargs: Mapping[str, object]) -> GenericLiteLLMParams: + from litellm.responses.utils import ResponsesAPIRequestUtils + + headers: Final = ResponsesAPIRequestUtils.merge_client_forwarded_headers( + TypeAdapter[dict[str, object] | None](dict[str, object] | None).validate_python(kwargs.get("extra_headers")), + TypeAdapter[dict[str, str] | None](dict[str, str] | None).validate_python(kwargs.get("headers")), + ) + return GenericLiteLLMParams.model_validate({**kwargs, "extra_headers": headers}) + + +def _chatgpt_image_headers(model: str, params: GenericLiteLLMParams, headers: Mapping[str, str]) -> Mapping[str, str]: + from litellm.llms.chatgpt.common_utils import get_chatgpt_request_credential + from litellm.llms.chatgpt.responses.transformation import ChatGPTResponsesAPIConfig + + credential: Final = get_chatgpt_request_credential(params) + credential_headers: Final = ( + { + "Authorization": f"Bearer {credential.access_token}", + **({"ChatGPT-Account-Id": credential.account_id} if credential.account_id else {}), + } + if credential is not None + else {} + ) + explicit_account_id: Final = next( + (value for name, value in headers.items() if name.lower() == "chatgpt-account-id"), None + ) + auth_headers: Final = ChatGPTResponsesAPIConfig().validate_environment( + headers=credential_headers, model=model, litellm_params=params + ) + return { + **{k: v for k, v in auth_headers.items() if k.lower() not in ("content-type", "accept")}, + **{ + k: v + for k, v in headers.items() + if k.lower() not in ("authorization", "chatgpt-account-id", "cookie", "x-litellm-api-key") + }, + **({"ChatGPT-Account-Id": explicit_account_id} if credential is None and explicit_account_id else {}), + "Accept": "application/json", + } + + ##### Image Generation ####################### @client async def aimage_generation(*args, **kwargs) -> ImageResponse: @@ -120,6 +162,12 @@ async def aimage_generation(*args, **kwargs) -> ImageResponse: model=model, custom_llm_provider=provider_hints.get("custom_llm_provider"), api_base=provider_hints.get("api_base"), + litellm_params=( + _chatgpt_image_params(TypeAdapter(dict[str, object]).validate_python(kwargs)) + if provider_hints.get("custom_llm_provider") == "chatgpt" + or (isinstance(model, str) and model.startswith("chatgpt/")) + else None + ), ) # Await normally @@ -239,12 +287,18 @@ def image_generation( if extra_headers is not None: headers.update(extra_headers) model_response: ImageResponse = litellm.utils.ImageResponse() + chatgpt_params: Final = ( + _chatgpt_image_params(TypeAdapter(dict[str, object]).validate_python({**kwargs, "api_key": api_key})) + if custom_llm_provider == "chatgpt" or (model is not None and model.startswith("chatgpt/")) + else None + ) dynamic_api_key: str | None = None if model is not None or custom_llm_provider is not None: model, custom_llm_provider, dynamic_api_key, api_base = get_llm_provider( model=model, custom_llm_provider=custom_llm_provider, api_base=api_base, + litellm_params=chatgpt_params, ) else: model = "dall-e-2" @@ -267,7 +321,10 @@ def image_generation( "size", "style", ] - non_default_params: Final = filter_out_litellm_params(kwargs, excluding=openai_params) + non_default_params: Final = filter_out_litellm_params( + kwargs, + excluding=[*openai_params, "extra_headers", "headers"] if chatgpt_params is not None else openai_params, + ) image_generation_config: BaseImageGenerationConfig | None = None if custom_llm_provider is not None and custom_llm_provider in LlmProviders._member_map_.values(): @@ -489,7 +546,7 @@ def image_generation( or custom_llm_provider == LlmProviders.LITELLM_PROXY.value or custom_llm_provider in litellm.openai_compatible_providers ): - if extra_headers is not None: + if extra_headers is not None and chatgpt_params is None: optional_params["extra_headers"] = extra_headers # Forward OpenAI organization if present (set by proxy pre-call utils) organization: Final[str | None] = kwargs.get("organization", None) @@ -505,7 +562,17 @@ def image_generation( organization=organization, aimg_generation=aimg_generation, client=client, - headers=headers, + headers=( + dict( + _chatgpt_image_headers( + model, + chatgpt_params.model_copy(update={"api_key": dynamic_api_key or api_key}), + TypeAdapter(dict[str, str]).validate_python(headers), + ) + ) + if chatgpt_params is not None + else headers + ), litellm_params=litellm_params_dict, ) elif custom_llm_provider == "bedrock": diff --git a/litellm/integrations/SlackAlerting/hanging_request_check.py b/litellm/integrations/SlackAlerting/hanging_request_check.py index 6f986144d4c..87baee91780 100644 --- a/litellm/integrations/SlackAlerting/hanging_request_check.py +++ b/litellm/integrations/SlackAlerting/hanging_request_check.py @@ -115,14 +115,16 @@ class AlertingHangingRequestCheck: if hanging_request_data.alerted: continue - request_status = await proxy_logging_obj.internal_usage_cache.async_get_cache( - key=f"request_status:{hanging_request_data.request_id}", - litellm_parent_otel_span=None, - local_only=True, - ) # this means the request status was either success or fail # and is not hanging - if request_status is not None: + if ( + await proxy_logging_obj.internal_usage_cache.async_get_cache( + key=f"request_status:{hanging_request_data.request_id}", + litellm_parent_otel_span=None, + local_only=True, + ) + is not None + ): # clear this request from hanging request cache since the request was either success or failed self.hanging_request_cache._remove_key( key=request_id, diff --git a/litellm/integrations/SlackAlerting/user_spend_alerts.py b/litellm/integrations/SlackAlerting/user_spend_alerts.py index 38794735c1b..08799a2f59f 100644 --- a/litellm/integrations/SlackAlerting/user_spend_alerts.py +++ b/litellm/integrations/SlackAlerting/user_spend_alerts.py @@ -56,8 +56,9 @@ async def fetch_user_spend_rows( today_str: Final = today.strftime("%Y-%m-%d") month_start_str: Final = today.replace(day=1).strftime("%Y-%m-%d") baseline_start_str: Final = (today - datetime.timedelta(days=max(baseline_days, 1))).strftime("%Y-%m-%d") - raw: Final = await prisma_client.db.query_raw(USER_SPEND_QUERY, today_str, month_start_str, baseline_start_str) - return USER_SPEND_ROWS_ADAPTER.validate_python(raw) + return USER_SPEND_ROWS_ADAPTER.validate_python( + await prisma_client.db.query_raw(USER_SPEND_QUERY, today_str, month_start_str, baseline_start_str) + ) def _daily_threshold_event(row: UserSpendRow, args: SlackAlertingArgs, today_str: str) -> UserSpendAlertEvent | None: diff --git a/litellm/integrations/agentops/agentops.py b/litellm/integrations/agentops/agentops.py index 9043ab1853a..3364520a8ae 100644 --- a/litellm/integrations/agentops/agentops.py +++ b/litellm/integrations/agentops/agentops.py @@ -4,11 +4,16 @@ AgentOps integration for LiteLLM - Provides OpenTelemetry tracing for LLM calls import os from dataclasses import dataclass -from typing import Any, Final +from typing import Final + +from pydantic import TypeAdapter from litellm.integrations.opentelemetry import OpenTelemetry, OpenTelemetryConfig +from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.llms.custom_httpx.http_handler import get_httpx_client +_DECODED_JSON: Final = TypeAdapter(object) + @dataclass class AgentOpsConfig: @@ -58,9 +63,10 @@ class AgentOps(OpenTelemetry): project_id = None if config.api_key: try: - response: Final = self._fetch_auth_token(config.api_key, config.auth_endpoint) - jwt_token = response.get("token") - project_id = response.get("project_id") + response: Final = as_str_mapping(self._fetch_auth_token(config.api_key, config.auth_endpoint)) + if response is not None: + jwt_token = response.get("token") + project_id = response.get("project_id") except Exception: pass @@ -78,12 +84,9 @@ class AgentOps(OpenTelemetry): "telemetry.sdk.name": "agentops", } - if project_id: - resource_attrs["project.id"] = project_id + self.resource_attributes = {**resource_attrs, "project.id": project_id} if project_id else resource_attrs - self.resource_attributes = resource_attrs - - def _fetch_auth_token(self, api_key: str, auth_endpoint: str) -> dict[str, Any]: + def _fetch_auth_token(self, api_key: str, auth_endpoint: str) -> object: """ Fetch JWT authentication token from AgentOps API @@ -111,6 +114,6 @@ class AgentOps(OpenTelemetry): if response.status_code != 200: raise Exception(f"Failed to fetch auth token: {response.text}") - return response.json() + return _DECODED_JSON.validate_python(response.json()) finally: client.close() diff --git a/litellm/integrations/arize/arize.py b/litellm/integrations/arize/arize.py index 24279b443aa..5a03b91d470 100644 --- a/litellm/integrations/arize/arize.py +++ b/litellm/integrations/arize/arize.py @@ -166,7 +166,7 @@ class ArizeLogger(OpenTelemetry): primary ``otel`` callback which handles proxy-level parent spans. """ - def set_attributes(self, span: Span, kwargs, response_obj: Any | None): + def set_attributes(self, span: Span, kwargs, response_obj: object): ArizeLogger.set_arize_attributes(span, kwargs, response_obj) @staticmethod diff --git a/litellm/integrations/braintrust_logging.py b/litellm/integrations/braintrust_logging.py index 501f5749ea4..f72b29a6ad8 100644 --- a/litellm/integrations/braintrust_logging.py +++ b/litellm/integrations/braintrust_logging.py @@ -3,9 +3,10 @@ import os from datetime import datetime -from typing import Final +from typing import Final, Protocol import httpx +from typing_extensions import ReadOnly, TypedDict import litellm from litellm import verbose_logger @@ -24,6 +25,18 @@ from litellm.utils import print_verbose API_BASE: Final = "https://api.braintrustdata.com/v1" +class _BraintrustProjectBody(TypedDict): + id: ReadOnly[str] + + +class _BraintrustProjectResponse(Protocol): + def json(self) -> _BraintrustProjectBody: ... + + +def _project_id(response: _BraintrustProjectResponse) -> str: + return response.json()["id"] + + def get_utc_datetime(): import datetime as dt @@ -80,8 +93,7 @@ class BraintrustLogger(CustomLogger): headers=self.headers, json={"name": project_name}, ) - project_dict: Final = response.json() - project_id: Final = project_dict["id"] + project_id: Final = _project_id(response) self._project_id_cache[project_name] = project_id return project_id except httpx.HTTPStatusError as e: @@ -100,8 +112,7 @@ class BraintrustLogger(CustomLogger): headers=self.headers, json={"name": project_name}, ) - project_dict: Final = response.json() - project_id: Final = project_dict["id"] + project_id: Final = _project_id(response) self._project_id_cache[project_name] = project_id return project_id except httpx.HTTPStatusError as e: @@ -112,18 +123,14 @@ class BraintrustLogger(CustomLogger): f"{self.api_base}/project", headers=self.headers, json={"name": "litellm"} ) - project_dict: Final = project.json() - - self.default_project_id = project_dict["id"] + self.default_project_id = _project_id(project) def create_sync_default_project_and_experiment(self): project: Final = self.global_braintrust_sync_http_handler.post( f"{self.api_base}/project", headers=self.headers, json={"name": "litellm"} ) - project_dict: Final = project.json() - - self.default_project_id = project_dict["id"] + self.default_project_id = _project_id(project) def log_success_event(self, kwargs, response_obj, start_time, end_time): verbose_logger.debug("REACHES BRAINTRUST SUCCESS") diff --git a/litellm/integrations/cloudzero/cz_stream_api.py b/litellm/integrations/cloudzero/cz_stream_api.py index 1e0413e8576..d0b25ea83e8 100644 --- a/litellm/integrations/cloudzero/cz_stream_api.py +++ b/litellm/integrations/cloudzero/cz_stream_api.py @@ -19,8 +19,9 @@ """Output modules for writing CBF data to various destinations.""" import zoneinfo +from collections.abc import Mapping from datetime import datetime, timezone -from typing import Any, Final +from typing import Final import httpx import polars as pl @@ -188,7 +189,7 @@ class CloudZeroStreamer: ) raise - def _prepare_batch_payload(self, batch_date: str, batch_data: pl.DataFrame, operation: str) -> dict[str, Any]: + def _prepare_batch_payload(self, batch_date: str, batch_data: pl.DataFrame, operation: str) -> Mapping[str, object]: """Prepare batch payload according to CloudZero AnyCost API format.""" # Convert batch_date to month for the API (YYYY-MM format) try: @@ -205,7 +206,7 @@ class CloudZeroStreamer: if record: data_records.append(record) - payload: Final = {"month": month_str, "operation": operation, "data": data_records} + payload: Final[Mapping[str, object]] = {"month": month_str, "operation": operation, "data": data_records} return payload diff --git a/litellm/integrations/custom_guardrail.py b/litellm/integrations/custom_guardrail.py index 1c12ac395c7..9e2dc902d55 100644 --- a/litellm/integrations/custom_guardrail.py +++ b/litellm/integrations/custom_guardrail.py @@ -352,7 +352,7 @@ class CustomGuardrail(CustomLogger): self, violation_message: str, request_data: dict[str, Any], - detection_info: dict[str, Any] | None = None, + detection_info: Mapping[str, object] | None = None, original_response: object = None, ) -> None: """ @@ -1368,7 +1368,10 @@ class CustomGuardrail(CustomLogger): if event_type is not None: guardrail_mode = event_type elif isinstance(self.event_hook, Mode): - guardrail_mode = GuardrailMode(**dict(self.event_hook.model_dump())) + guardrail_mode = GuardrailMode( + tags=copy.deepcopy(self.event_hook.tags), + default=copy.deepcopy(self.event_hook.default), + ) else: guardrail_mode = self.event_hook diff --git a/litellm/integrations/custom_secret_manager.py b/litellm/integrations/custom_secret_manager.py index e59842d409a..8fc5bc551c8 100644 --- a/litellm/integrations/custom_secret_manager.py +++ b/litellm/integrations/custom_secret_manager.py @@ -37,7 +37,6 @@ Usage: """ from abc import abstractmethod -from typing import Any import httpx @@ -154,7 +153,7 @@ class CustomSecretManager(BaseSecretManager): optional_params: dict | None = None, timeout: float | httpx.Timeout | None = None, tags: dict | list | None = None, - ) -> dict[str, Any]: + ) -> dict[str, object]: """ Asynchronously write a secret to your custom secret manager. diff --git a/litellm/integrations/dotprompt/__init__.py b/litellm/integrations/dotprompt/__init__.py index 4cf6c0de2df..0a2921db6c7 100644 --- a/litellm/integrations/dotprompt/__init__.py +++ b/litellm/integrations/dotprompt/__init__.py @@ -61,7 +61,9 @@ def prompt_initializer(litellm_params: "PromptLiteLLMParams", prompt_spec: "Prom prompt_file: Final = getattr(litellm_params, "prompt_file", None) # Handle dotprompt_content from database - dotprompt_content: Final = getattr(litellm_params, "dotprompt_content", None) + dotprompt_content: Final = ( + litellm_params.dotprompt_content if hasattr(litellm_params, "dotprompt_content") else None + ) if dotprompt_content and not prompt_data and not prompt_file: prompt_data = get_prompt_data_from_dotprompt_content(dotprompt_content) diff --git a/litellm/integrations/dotprompt/dotprompt_manager.py b/litellm/integrations/dotprompt/dotprompt_manager.py index c646dbf4e2e..77d70dd761c 100644 --- a/litellm/integrations/dotprompt/dotprompt_manager.py +++ b/litellm/integrations/dotprompt/dotprompt_manager.py @@ -7,6 +7,8 @@ import json from collections.abc import Mapping from typing import TYPE_CHECKING, Any, Final +from typing_extensions import ReadOnly, TypedDict + from litellm.integrations.custom_prompt_management import CustomPromptManagement from litellm.integrations.prompt_management_base import PromptManagementClient from litellm.types.llms.openai import AllMessageValues @@ -18,7 +20,12 @@ if TYPE_CHECKING: else: LiteLLMLoggingObj = Any -from .prompt_manager import PromptManager, PromptTemplate +from .prompt_manager import PromptJsonEntry, PromptManager, PromptTemplate + + +class _PromptJsonData(TypedDict, total=False): + content: ReadOnly[str] + metadata: ReadOnly[dict[str, object]] class DotpromptManager(CustomPromptManagement): @@ -342,17 +349,17 @@ class DotpromptManager(CustomPromptManagement): if self._prompt_manager: self._prompt_manager.reload_prompts() - def add_prompt_from_json(self, prompt_id: str, json_data: dict[str, Any]) -> None: + def add_prompt_from_json(self, prompt_id: str, json_data: _PromptJsonData) -> None: """Add a prompt from JSON data.""" content: Final = json_data.get("content", "") metadata: Final = json_data.get("metadata", {}) self.prompt_manager.add_prompt(prompt_id, content, metadata) - def load_prompts_from_json(self, prompts_data: dict[str, dict[str, object]]) -> None: + def load_prompts_from_json(self, prompts_data: Mapping[str, object]) -> None: """Load multiple prompts from JSON data.""" self.prompt_manager.load_prompts_from_json_data(prompts_data) - def get_prompts_as_json(self) -> dict[str, dict[str, object]]: + def get_prompts_as_json(self) -> dict[str, PromptJsonEntry]: """Get all prompts in JSON format.""" return self.prompt_manager.get_all_prompts_as_json() diff --git a/litellm/integrations/dotprompt/prompt_manager.py b/litellm/integrations/dotprompt/prompt_manager.py index 0eda266740c..0e52ca0b62f 100644 --- a/litellm/integrations/dotprompt/prompt_manager.py +++ b/litellm/integrations/dotprompt/prompt_manager.py @@ -12,6 +12,8 @@ from jinja2 import DictLoader, select_autoescape from jinja2.sandbox import ImmutableSandboxedEnvironment from typing_extensions import NotRequired, ReadOnly, TypedDict +from litellm.litellm_core_utils.core_helpers import as_str_mapping + class _PromptFileJson(TypedDict): """JSON form of a .prompt file: rendered template text plus its frontmatter.""" @@ -20,6 +22,11 @@ class _PromptFileJson(TypedDict): metadata: ReadOnly[NotRequired[dict[str, object]]] +class PromptJsonEntry(TypedDict): + content: ReadOnly[str] + metadata: ReadOnly[dict[str, object]] + + def strip_version_suffix(prompt_id: str) -> str | None: base, separator, version = prompt_id.rpartition(".v") if separator and base and version.isdigit(): @@ -358,20 +365,26 @@ class PromptManager: return f"---\n{frontmatter_yaml}---\n{content}" - def get_all_prompts_as_json(self) -> dict[str, dict[str, Any]]: + def get_all_prompts_as_json(self) -> dict[str, PromptJsonEntry]: """Get all loaded prompts in JSON format. Returns: Dictionary mapping prompt_id to prompt data """ - result: Final = {} - for prompt_id, template in self.prompts.items(): - result[prompt_id] = { + return { + prompt_id: { "content": template.content, "metadata": template.metadata, } - return result + for prompt_id, template in self.prompts.items() + } - def load_prompts_from_json_data(self, prompt_data: dict[str, dict[str, object]]) -> None: - """Load additional prompts from JSON data (merges with existing prompts).""" - self._load_prompts_from_json(prompt_data) + def load_prompts_from_json_data(self, prompt_data: Mapping[str, object]) -> None: + """Load additional prompts from JSON data (merges with existing prompts). Entries that are not + mappings are skipped, the same as a malformed entry inside the loader.""" + entries: Final = { + prompt_id: dict(entry) + for prompt_id, raw in prompt_data.items() + if (entry := as_str_mapping(raw)) is not None + } + self._load_prompts_from_json(entries) diff --git a/litellm/integrations/focus/destinations/factory.py b/litellm/integrations/focus/destinations/factory.py index 0ecf04326b3..cf871013265 100644 --- a/litellm/integrations/focus/destinations/factory.py +++ b/litellm/integrations/focus/destinations/factory.py @@ -3,6 +3,7 @@ from __future__ import annotations import os +from collections.abc import Mapping from typing import Any, Final from .base import FocusDestination @@ -20,7 +21,7 @@ class FocusDestinationFactory: *, provider: str, prefix: str, - config: dict[str, Any] | None = None, + config: Mapping[str, object] | None = None, ) -> FocusDestination: """Return a destination implementation for the requested provider.""" provider_lower: Final = provider.lower() @@ -39,7 +40,7 @@ class FocusDestinationFactory: def _resolve_config( *, provider: str, - overrides: dict[str, object], + overrides: Mapping[str, object], ) -> dict[str, Any]: if provider == "s3": resolved = { diff --git a/litellm/integrations/focus/export_engine.py b/litellm/integrations/focus/export_engine.py index 615aba72954..5c345630984 100644 --- a/litellm/integrations/focus/export_engine.py +++ b/litellm/integrations/focus/export_engine.py @@ -2,8 +2,8 @@ from __future__ import annotations -from collections.abc import Callable -from typing import Any, Final, SupportsFloat, SupportsIndex, SupportsInt, cast +from collections.abc import Callable, Mapping +from typing import Final, SupportsFloat, SupportsIndex, SupportsInt, cast import polars as pl @@ -24,7 +24,7 @@ class FocusExportEngine: provider: str, export_format: str, prefix: str, - destination_config: dict[str, Any] | None = None, + destination_config: Mapping[str, object] | None = None, ) -> None: self.provider = provider self.export_format = export_format @@ -77,7 +77,7 @@ class FocusExportEngine: return FocusParquetSerializer() raise NotImplementedError(f"Export format '{self.export_format}' not supported. Use 'parquet' or 'csv'.") - async def dry_run_export_usage_data(self, limit: int | None) -> dict[str, Any]: + async def dry_run_export_usage_data(self, limit: int | None) -> dict[str, object]: data: Final = await self.database.get_usage_data(limit=limit) normalized: Final = self.transformer.transform(data) diff --git a/litellm/integrations/focus/focus_logger.py b/litellm/integrations/focus/focus_logger.py index e961b53a240..71b61296cfc 100644 --- a/litellm/integrations/focus/focus_logger.py +++ b/litellm/integrations/focus/focus_logger.py @@ -6,6 +6,8 @@ import os from datetime import datetime, timedelta, timezone from typing import TYPE_CHECKING, Any, ClassVar, Final, cast +from typing_extensions import TypedDict, Unpack + import litellm from litellm._logging import verbose_logger from litellm.integrations.custom_logger import CustomLogger @@ -25,6 +27,10 @@ FOCUS_USAGE_DATA_JOB_NAME: Final = "focus_export_usage_data" DEFAULT_DRY_RUN_LIMIT: Final = 500 +class _CustomLoggerOptions(TypedDict, total=False, extra_items=object): + pass + + class FocusLogger(CustomLogger): """Coordinates Focus export jobs across transformer/serializer/destination layers.""" @@ -40,7 +46,7 @@ class FocusLogger(CustomLogger): interval_seconds: int | None = None, prefix: str | None = None, destination_config: dict[str, Any] | None = None, - **kwargs: Any, + **kwargs: Unpack[_CustomLoggerOptions], ) -> None: super().__init__(**kwargs) self.provider = (provider or os.getenv("FOCUS_PROVIDER") or "s3").lower() diff --git a/litellm/integrations/gcs_bucket/gcs_bucket.py b/litellm/integrations/gcs_bucket/gcs_bucket.py index 5bc7247e02a..99cd8b31b63 100644 --- a/litellm/integrations/gcs_bucket/gcs_bucket.py +++ b/litellm/integrations/gcs_bucket/gcs_bucket.py @@ -3,6 +3,7 @@ import hashlib import json import os import time +from collections.abc import Mapping from datetime import datetime, timedelta, timezone from typing import TYPE_CHECKING, Any, Final @@ -15,6 +16,7 @@ from litellm.integrations.gcs_bucket.gcs_bucket_base import GCSBucketBase from litellm.litellm_core_utils.cloud_storage_security import ( sanitize_cloud_object_component, ) +from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.types.integrations.base_health_check import IntegrationHealthCheckStatus from litellm.types.integrations.gcs_bucket import * from litellm.types.utils import StandardBatchLineItemsPayload, StandardLoggingPayload @@ -134,7 +136,7 @@ class GCSBucketLogger(GCSBucketBase, AdditionalLoggingUtils): """ return f"{date_str}/batch-{batch_id}.ndjson" - def _get_config_key(self, kwargs: dict[str, Any]) -> str: + def _get_config_key(self, kwargs: Mapping[str, object]) -> str: """ Extract a synchronous grouping key from kwargs to group items by GCS config. This allows us to batch items with the same bucket/credentials together. @@ -143,7 +145,9 @@ class GCSBucketLogger(GCSBucketBase, AdditionalLoggingUtils): This key may contain sensitive information (bucket names, paths) - use _sanitize_config_key() for logging purposes. """ - standard_callback_dynamic_params: Final = kwargs.get("standard_callback_dynamic_params", None) or {} + standard_callback_dynamic_params: Final = ( + as_str_mapping(kwargs.get("standard_callback_dynamic_params", None)) or {} + ) bucket_name = standard_callback_dynamic_params.get("gcs_bucket_name", None) or self.BUCKET_NAME or "default" path_service_account: Final = ( diff --git a/litellm/integrations/gcs_bucket/gcs_bucket_base.py b/litellm/integrations/gcs_bucket/gcs_bucket_base.py index 63c4fe92eca..092372b5d15 100644 --- a/litellm/integrations/gcs_bucket/gcs_bucket_base.py +++ b/litellm/integrations/gcs_bucket/gcs_bucket_base.py @@ -20,7 +20,7 @@ from litellm.llms.custom_httpx.http_handler import ( httpxSpecialProvider, ) from litellm.types.integrations.gcs_bucket import * -from litellm.types.utils import StandardCallbackDynamicParams, StandardLoggingPayload +from litellm.types.utils import StandardLoggingPayload if TYPE_CHECKING: from litellm.llms.vertex_ai.vertex_llm_base import VertexBase @@ -140,49 +140,16 @@ class GCSBucketBase(CustomBatchLogger): async def get_gcs_logging_config(self, kwargs: dict[str, Any] | None = {}) -> GCSLoggingConfig: """ - This function is used to get the GCS logging config for the GCS Bucket Logger. - It checks if the dynamic parameters are provided in the kwargs and uses them to get the GCS logging config. - If no dynamic parameters are provided, it uses the default values. + Returns the bucket and service account this logger was configured with. """ - if kwargs is None: - kwargs = {} - - standard_callback_dynamic_params: Final[StandardCallbackDynamicParams | None] = kwargs.get( - "standard_callback_dynamic_params", None - ) - - bucket_name: str - path_service_account: str | None - if standard_callback_dynamic_params is not None: - verbose_logger.debug("Using dynamic GCS logging") - verbose_logger.debug("standard_callback_dynamic_params: %s", standard_callback_dynamic_params) - - _bucket_name: str | None = standard_callback_dynamic_params.get("gcs_bucket_name", None) or self.BUCKET_NAME - _path_service_account: Final[str | None] = ( - standard_callback_dynamic_params.get("gcs_path_service_account", None) or self.path_service_account_json + if self.BUCKET_NAME is None: + raise ValueError( + "GCS_BUCKET_NAME is not set in the environment, but GCS Bucket is being used as a logging callback. Please set 'GCS_BUCKET_NAME' in the environment." ) - - if _bucket_name is None: - raise ValueError( - "GCS_BUCKET_NAME is not set in the environment, but GCS Bucket is being used as a logging callback. Please set 'GCS_BUCKET_NAME' in the environment." - ) - bucket_name = _bucket_name - path_service_account = _path_service_account - vertex_instance = await self.get_or_create_vertex_instance(credentials=path_service_account) - else: - # If no dynamic parameters, use the default instance - if self.BUCKET_NAME is None: - raise ValueError( - "GCS_BUCKET_NAME is not set in the environment, but GCS Bucket is being used as a logging callback. Please set 'GCS_BUCKET_NAME' in the environment." - ) - bucket_name = self.BUCKET_NAME - path_service_account = self.path_service_account_json - vertex_instance = await self.get_or_create_vertex_instance(credentials=path_service_account) - return GCSLoggingConfig( - bucket_name=bucket_name, - vertex_instance=vertex_instance, - path_service_account=path_service_account, + bucket_name=self.BUCKET_NAME, + vertex_instance=await self.get_or_create_vertex_instance(credentials=self.path_service_account_json), + path_service_account=self.path_service_account_json, ) async def get_or_create_vertex_instance(self, credentials: str | None) -> VertexBase: diff --git a/litellm/integrations/gcs_bucket/gcs_bucket_mock_client.py b/litellm/integrations/gcs_bucket/gcs_bucket_mock_client.py index 9dfd75e5559..3f8cf93e11c 100644 --- a/litellm/integrations/gcs_bucket/gcs_bucket_mock_client.py +++ b/litellm/integrations/gcs_bucket/gcs_bucket_mock_client.py @@ -9,6 +9,7 @@ Usage: """ import asyncio +import os from collections.abc import AsyncIterable, Iterable from typing import Final @@ -40,7 +41,7 @@ _mocks_initialized = False # Default mock latency in seconds (simulates network round-trip) # Typical GCS API calls take 100-300ms for uploads, 50-150ms for GET/DELETE -_MOCK_LATENCY_SECONDS: Final = float(__import__("os").getenv("GCS_MOCK_LATENCY_MS", "150")) / 1000.0 +_MOCK_LATENCY_SECONDS: Final = float(os.getenv("GCS_MOCK_LATENCY_MS", "150")) / 1000.0 async def _mock_async_handler_get(self, url, params=None, headers=None, follow_redirects=None): diff --git a/litellm/integrations/gcs_pubsub/pub_sub.py b/litellm/integrations/gcs_pubsub/pub_sub.py index c799245c215..cbf6898d978 100644 --- a/litellm/integrations/gcs_pubsub/pub_sub.py +++ b/litellm/integrations/gcs_pubsub/pub_sub.py @@ -12,6 +12,8 @@ import os import traceback from typing import TYPE_CHECKING, Any, Final +from pydantic import TypeAdapter + from litellm.types.utils import StandardLoggingPayload if TYPE_CHECKING: @@ -27,6 +29,8 @@ from litellm.llms.custom_httpx.http_handler import ( httpxSpecialProvider, ) +_DECODED_JSON: Final = TypeAdapter(object) + class GcsPubSubLogger(CustomBatchLogger): def __init__( @@ -152,7 +156,7 @@ class GcsPubSubLogger(CustomBatchLogger): finally: self.log_queue.clear() - async def publish_message(self, message: SpendLogsPayload | StandardLoggingPayload) -> dict[str, Any] | None: + async def publish_message(self, message: SpendLogsPayload | StandardLoggingPayload) -> object: """ Publish message to Google Cloud Pub/Sub using REST API @@ -188,7 +192,7 @@ class GcsPubSubLogger(CustomBatchLogger): raise Exception(f"Failed to publish message: {response.text}") verbose_logger.debug("Pub/Sub response: %s", response.text) - return response.json() + return _DECODED_JSON.validate_python(response.json()) except Exception as e: verbose_logger.error("Pub/Sub publish error: %s", str(e)) diff --git a/litellm/integrations/langfuse/langfuse.py b/litellm/integrations/langfuse/langfuse.py index 86f80047e52..b8c6e91d0d7 100644 --- a/litellm/integrations/langfuse/langfuse.py +++ b/litellm/integrations/langfuse/langfuse.py @@ -20,6 +20,7 @@ from litellm.integrations.langfuse.langfuse_mock_client import ( should_use_langfuse_mock, ) from litellm.litellm_core_utils.core_helpers import ( + as_str_mapping, filter_exceptions_from_params, reconstruct_model_name, safe_deep_copy, @@ -1268,11 +1269,11 @@ def log_provider_specific_information_as_span( *, tracing: "LangfuseTracing", parent: "LangfuseObservation", - enrichments: Mapping[str, Any], + enrichments: Mapping[str, object], ): """Logs provider-specific information as spans under the generation.""" - _hidden_params: Final[Mapping[str, object] | None] = enrichments.get("hidden_params", None) + _hidden_params: Final = as_str_mapping(enrichments.get("hidden_params", None)) if _hidden_params is None: return diff --git a/litellm/integrations/langfuse/langfuse_otel.py b/litellm/integrations/langfuse/langfuse_otel.py index f195cd97e3c..34d2c9fce0d 100644 --- a/litellm/integrations/langfuse/langfuse_otel.py +++ b/litellm/integrations/langfuse/langfuse_otel.py @@ -1,18 +1,32 @@ import base64 import json import os -from collections.abc import Mapping, Sequence +from collections.abc import Iterable, Mapping, Sequence from datetime import datetime -from typing import TYPE_CHECKING, Any, Final, Optional +from itertools import chain +from typing import TYPE_CHECKING, Any, Final, Optional, Protocol, runtime_checkable +from opentelemetry import trace + +import litellm from litellm._logging import verbose_logger +from litellm.constants import REDACTED_BY_LITELLM +from litellm.integrations._types.open_inference import ErrorAttributes from litellm.integrations.arize import _utils from litellm.integrations.langfuse.langfuse_otel_attributes import ( LangfuseLLMObsOTELAttributes, serialize_langfuse_datetime, ) -from litellm.integrations.opentelemetry import OpenTelemetry, OpenTelemetryConfig +from litellm.integrations.opentelemetry import ( + HTTP_RESPONSE_STATUS_CODE_ATTRIBUTE, + LITELLM_PROXY_REQUEST_SPAN_NAME, + OpenTelemetry, + OpenTelemetryConfig, +) +from litellm.litellm_core_utils.core_helpers import as_str_mapping +from litellm.litellm_core_utils.safe_json_dumps import safe_dumps from litellm.litellm_core_utils.safe_json_loads import safe_json_loads +from litellm.secret_managers.main import str_to_bool from litellm.types.integrations.langfuse_otel import ( LangfuseSpanAttributes, ) @@ -30,6 +44,86 @@ LANGFUSE_CLOUD_EU_ENDPOINT: Final = "https://cloud.langfuse.com/api/public/otel" LANGFUSE_CLOUD_US_ENDPOINT: Final = "https://us.cloud.langfuse.com/api/public/otel" LANGFUSE_INGESTION_VERSION_HEADER: Final = "x-langfuse-ingestion-version" LANGFUSE_INGESTION_VERSION: Final = "4" +_ERROR_ATTRIBUTES: Final = frozenset( + { + ErrorAttributes.ERROR_CODE, + HTTP_RESPONSE_STATUS_CODE_ATTRIBUTE, + ErrorAttributes.ERROR_TYPE, + ErrorAttributes.ERROR_MESSAGE, + ErrorAttributes.ERROR_LLM_PROVIDER, + ErrorAttributes.ERROR_STACK_TRACE, + } +) + + +@runtime_checkable +class _Gettable(Protocol): + def get(self, key: str, default: object = None) -> object: ... + + +def _as_gettable(value: object) -> _Gettable | None: + return value if isinstance(value, _Gettable) else None + + +def _attr(item: object, name: str, default: object = None) -> object: + return getattr(item, name, default) + + +def _preset_cache_key(kwargs: Mapping[str, object]) -> object: + if litellm.cache is None: + return None + return litellm.cache.get_preset_cache_key_from_kwargs(**kwargs) + + +def _mask_flag(value: object) -> bool: + parsed: Final = str_to_bool(value) if isinstance(value, str) else None + return bool(value) if parsed is None else parsed + + +def _caller_tag_list(value: object) -> tuple[str, ...]: + parsed: Final = ( + safe_json_loads(value, default=value) if isinstance(value, str) and value.strip().startswith("[") else value + ) + if isinstance(parsed, list): + return tuple(tag if isinstance(tag, str) else json.dumps(tag, default=str) for tag in parsed) + if isinstance(parsed, str) and parsed: + return tuple(tag.strip() for tag in parsed.split(",")) if "," in parsed else (parsed,) + return () + + +def _parent_of(span: object) -> trace.SpanContext | None: + parent: Final = getattr(span, "parent", None) + return parent if isinstance(parent, trace.SpanContext) else None + + +def _litellm_proxy_span(kwargs: Mapping[str, object]) -> trace.Span | None: + litellm_params: Final = _as_gettable(kwargs.get("litellm_params")) or {} + carried: Final = ( + (_as_gettable(litellm_params.get(key)) or {}).get("litellm_parent_otel_span") + for key in ("metadata", "litellm_metadata") + ) + return next( + ( + span + for span in carried + if isinstance(span, trace.Span) and getattr(span, "name", None) == LITELLM_PROXY_REQUEST_SPAN_NAME + ), + None, + ) + + +def _starts_its_own_trace(span: object, kwargs: Mapping[str, object]) -> bool: + if span is trace.get_current_span(): + return False + parent: Final = _parent_of(span) + if parent is None: + return True + proxy_span: Final = _litellm_proxy_span(kwargs) + return ( + proxy_span is not None + and _parent_of(proxy_span) is None + and proxy_span.get_span_context().span_id == parent.span_id + ) class LangfuseOtelLogger(OpenTelemetry): @@ -128,101 +222,45 @@ class LangfuseOtelLogger(OpenTelemetry): safe_set_attribute(span, enum_attr.value, value) @staticmethod - def _set_observation_output(span: Span, response_obj): - """Helper to set observation output attributes.""" - from litellm.integrations.arize._utils import safe_set_attribute - from litellm.litellm_core_utils.safe_json_dumps import safe_dumps - + def _observation_output(response_obj: _Gettable | None) -> str | None: if not response_obj or not hasattr(response_obj, "get"): - return - - choices: Final = response_obj.get("choices", []) - if choices: - first_choice: Final = choices[0] - message: Final = first_choice.get("message", {}) - tool_calls: Final = message.get("tool_calls") - if tool_calls: - transformed_tool_calls: Final = [] - for tool_call in tool_calls: - function = tool_call.get("function", {}) - arguments_str = function.get("arguments", "{}") - try: - arguments_obj = json.loads(arguments_str) if isinstance(arguments_str, str) else arguments_str - except json.JSONDecodeError: - arguments_obj = {} - langfuse_tool_call = { - "id": response_obj.get("id", ""), - "name": function.get("name", ""), - "call_id": tool_call.get("id", ""), - "type": "function_call", - "arguments": arguments_obj, - } - transformed_tool_calls.append(langfuse_tool_call) - safe_set_attribute( - span, - LangfuseSpanAttributes.OBSERVATION_OUTPUT.value, - safe_dumps(transformed_tool_calls), - ) - else: - output_data: Final = {} - if message.get("role"): - output_data["role"] = message.get("role") - if message.get("content") is not None: - output_data["content"] = message.get("content") - if output_data: - safe_set_attribute( - span, - LangfuseSpanAttributes.OBSERVATION_OUTPUT.value, - safe_dumps(output_data), - ) - - output: Final = response_obj.get("output", []) - if output: - output_items_data: Final[list[dict]] = [] - for item in output: - if hasattr(item, "type"): - item_type = item.type - if item_type == "reasoning" and hasattr(item, "summary"): - for summary in item.summary: - if hasattr(summary, "text"): - output_items_data.append( - { - "role": "reasoning_summary", - "content": summary.text, - } - ) - elif item_type == "message": - item_content: Sequence[object] = getattr(item, "content", [{}]) - output_items_data.append( - { - "role": getattr(item, "role", "assistant"), - "content": getattr(item_content[0], "text", ""), - } - ) - elif item_type == "function_call": - item_arguments: object = getattr(item, "arguments", "{}") - arguments_obj = ( - safe_json_loads(item_arguments, default={}) - if isinstance(item_arguments, str) - else item_arguments - ) - langfuse_tool_call = { - "id": getattr(item, "id", ""), - "name": getattr(item, "name", ""), - "call_id": getattr(item, "call_id", ""), - "type": "function_call", - "arguments": arguments_obj, - } - output_items_data.append(langfuse_tool_call) - if output_items_data: - safe_set_attribute( - span, - LangfuseSpanAttributes.OBSERVATION_OUTPUT.value, - safe_dumps(output_items_data), - ) + return None + return _extract_output_items(response_obj) or _extract_choices_output(response_obj) @staticmethod - def _set_langfuse_specific_attributes(span: Span, kwargs: Mapping[str, Any], response_obj): + def _trace_tags(kwargs: Mapping[str, object], metadata: Mapping[str, object]) -> tuple[str, ...]: + caller_tags: Final = metadata.get("tags") + request_tags: Final = (_as_gettable(kwargs.get("standard_logging_object")) or {}).get("request_tags") + default_tags: Final = litellm.langfuse_default_tags + + def _default_tag(key: str) -> str | None: + if key == "cache_hit": + return f"cache_hit:{kwargs.get('cache_hit', False)}" + if key == "cache_key": + hidden_params: Final = _as_gettable(metadata.get("hidden_params", {})) or {} + cache_key: Final = ( + hidden_params.get("cache_key") + if hidden_params.get("cache_key") is not None + else _preset_cache_key(kwargs) + ) + return f"cache_key:{cache_key}" + if key == "proxy_base_url": + proxy_base_url: Final = os.environ.get("PROXY_BASE_URL") + return f"proxy_base_url:{proxy_base_url}" if proxy_base_url is not None else None + if key in metadata and metadata[key] is not None: + return f"{key}:{metadata[key]}" + return None + + expanded: Final = tuple(_default_tag(key) for key in default_tags) if isinstance(default_tags, list) else () + candidates: Final = ( + _caller_tag_list(caller_tags) + + (tuple(tag for tag in request_tags if isinstance(tag, str)) if isinstance(request_tags, list) else ()) + + tuple(tag for tag in expanded if tag is not None) + ) + return tuple(dict.fromkeys(candidates)) + + @staticmethod + def _set_langfuse_specific_attributes(span: Span, kwargs: Mapping[str, object], response_obj): """ Sets Langfuse specific metadata attributes onto the OTEL span. @@ -234,7 +272,7 @@ class LangfuseOtelLogger(OpenTelemetry): from litellm.integrations.arize._utils import safe_set_attribute from litellm.litellm_core_utils.safe_json_dumps import safe_dumps - dynamic_params: Final = kwargs.get("standard_callback_dynamic_params") + dynamic_params: Final = as_str_mapping(kwargs.get("standard_callback_dynamic_params")) langfuse_environment: Final = ( dynamic_params.get("langfuse_environment") if dynamic_params else None ) or os.environ.get("LANGFUSE_TRACING_ENVIRONMENT") @@ -248,13 +286,12 @@ class LangfuseOtelLogger(OpenTelemetry): metadata: Final = LangfuseOtelLogger._extract_langfuse_metadata(kwargs) LangfuseOtelLogger._set_metadata_attributes(span=span, metadata=metadata) - messages: Final = kwargs.get("messages") - if messages: - safe_set_attribute( - span, - LangfuseSpanAttributes.OBSERVATION_INPUT.value, - safe_dumps(messages), - ) + joins_existing_trace: Final = metadata.get("existing_trace_id") is not None or not _starts_its_own_trace( + span, kwargs + ) + input_json: Final = safe_dumps(kwargs.get("messages")) if kwargs.get("messages") else None + if input_json is not None: + safe_set_attribute(span, LangfuseSpanAttributes.OBSERVATION_INPUT.value, input_json) completion_start_time: Final = kwargs.get("completion_start_time") if isinstance(completion_start_time, datetime): @@ -264,7 +301,64 @@ class LangfuseOtelLogger(OpenTelemetry): serialize_langfuse_datetime(completion_start_time), ) - LangfuseOtelLogger._set_observation_output(span=span, response_obj=response_obj) + output_json: Final = LangfuseOtelLogger._observation_output(response_obj) + if output_json is not None: + safe_set_attribute(span, LangfuseSpanAttributes.OBSERVATION_OUTPUT.value, output_json) + + if not joins_existing_trace: + LangfuseOtelLogger._set_trace_fields( + span=span, kwargs=kwargs, metadata=metadata, input_json=input_json, output_json=output_json + ) + + @staticmethod + def _set_trace_fields( + span: Span, + kwargs: Mapping[str, object], + metadata: Mapping[str, object], + input_json: str | None, + output_json: str | None, + ) -> None: + from litellm.integrations.otel.emitter import carried_keys, span_attribute_limit + + tags: Final = LangfuseOtelLogger._trace_tags(kwargs, metadata) + fields: Final = ( + *( + ((LangfuseSpanAttributes.TRACE_NAME.value, f"litellm-{kwargs.get('call_type') or 'completion'}"),) + if metadata.get("trace_name") is None + else () + ), + *(((LangfuseSpanAttributes.TAGS.value, json.dumps(list(tags))),) if tags else ()), + *( + ( + ( + LangfuseSpanAttributes.TRACE_INPUT.value, + REDACTED_BY_LITELLM if _mask_flag(metadata.get("mask_input")) else input_json, + ), + ) + if input_json is not None + else () + ), + *( + ( + ( + LangfuseSpanAttributes.TRACE_OUTPUT.value, + REDACTED_BY_LITELLM if _mask_flag(metadata.get("mask_output")) else output_json, + ), + ) + if output_json is not None + else () + ), + ) + limit: Final = span_attribute_limit(span) + carried: Final = carried_keys(span) + new_keys: Final = tuple(key for key, _value in fields if key not in carried) + room: Final = ( + len(new_keys) if limit is None else max(limit - len(carried) - len(_ERROR_ATTRIBUTES - carried), 0) + ) + written: Final = carried | frozenset(new_keys[:room]) + for key, value in fields: + if key in written: + _utils.safe_set_attribute(span, key, value) @staticmethod def _get_langfuse_otel_host() -> str | None: @@ -456,3 +550,101 @@ class LangfuseOtelLogger(OpenTelemetry): """ Langfuse should not receive service failure logs. """ + + +def _extract_choices_output(response_obj: _Gettable) -> str | None: + choices: Final = response_obj.get("choices", []) + if not isinstance(choices, list) or not choices: + return None + first_choice: Final = _as_gettable(choices[0]) + if first_choice is None: + return None + message: Final = _as_gettable(first_choice.get("message", {})) + if message is None: + return None + tool_calls: Final = message.get("tool_calls") + if isinstance(tool_calls, list) and tool_calls: + transformed_tool_calls: Final = [ + entry for tool_call in tool_calls if (entry := _transformed_tool_call(response_obj, tool_call)) is not None + ] + return safe_dumps(transformed_tool_calls) + output_data: Final = { + key: value + for key, value in ( + ("role", message.get("role") or None), + ("content", message.get("content")), + ) + if value is not None + } + return safe_dumps(output_data) if output_data else None + + +def _transformed_tool_call(response_obj: _Gettable, tool_call: object) -> dict[str, object] | None: + call: Final = _as_gettable(tool_call) + if call is None: + return None + function: Final = _as_gettable(call.get("function", {})) + if function is None: + return None + return { + "id": response_obj.get("id", ""), + "name": function.get("name", ""), + "call_id": call.get("id", ""), + "type": "function_call", + "arguments": _tool_call_arguments(function.get("arguments", "{}")), + } + + +def _tool_call_arguments(arguments: object) -> object: + if not isinstance(arguments, str): + return arguments + try: + return json.loads(arguments) + except json.JSONDecodeError: + return {} + + +def _extract_output_items(response_obj: _Gettable) -> str | None: + output: Final = response_obj.get("output", []) + if not isinstance(output, list) or not output: + return None + rendered: Final = tuple(chain.from_iterable(map(_output_items, output))) + return safe_dumps(list(rendered)) if rendered else None + + +def _output_items(item: object) -> tuple[dict[str, object], ...]: + item_type: Final = _attr(item, "type") + if item_type == "reasoning": + summaries: Final = _attr(item, "summary") + if not isinstance(summaries, Iterable): + return () + return tuple( + {"role": "reasoning_summary", "content": _attr(summary, "text")} + for summary in summaries + if hasattr(summary, "text") + ) + if item_type == "message": + content_items: Final = _attr(item, "content", [{}]) + first_content: Final = ( + content_items[0] + if isinstance(content_items, Sequence) and not isinstance(content_items, (str, bytes)) and content_items + else {} + ) + return ( + { + "role": _attr(item, "role", "assistant"), + "content": _attr(first_content, "text", ""), + }, + ) + if item_type == "function_call": + arguments: Final = _attr(item, "arguments", "{}") + return ( + { + "id": _attr(item, "id", ""), + "name": _attr(item, "name", ""), + "call_id": _attr(item, "call_id", ""), + "type": "function_call", + "arguments": safe_json_loads(arguments, default={}) if isinstance(arguments, str) else arguments, + }, + ) + return () diff --git a/litellm/integrations/langfuse/langfuse_prompt_management.py b/litellm/integrations/langfuse/langfuse_prompt_management.py index 3786087ba91..50ff7002068 100644 --- a/litellm/integrations/langfuse/langfuse_prompt_management.py +++ b/litellm/integrations/langfuse/langfuse_prompt_management.py @@ -2,6 +2,7 @@ Call Hook for LiteLLM Proxy which allows Langfuse prompt management. """ +from collections.abc import Mapping from functools import lru_cache from typing import TYPE_CHECKING, Any, Final, Literal, TypeAlias, cast @@ -110,6 +111,10 @@ def _remember_trace_id(litellm_call_id: object, logged: LangfuseLoggedEvent) -> in_memory_trace_id_cache.set_cache(litellm_call_id=litellm_call_id, service_name="langfuse", trace_id=trace_id) +def _params_without_model(config: Mapping[str, object]) -> Mapping[str, object]: + return {k: v for k, v in config.items() if k != "model"} + + class LangfusePromptManagement(LangFuseLogger, PromptManagementBase, CustomLogger): def __init__( self, @@ -182,12 +187,7 @@ class LangfusePromptManagement(LangFuseLogger, PromptManagementBase, CustomLogge return compiled_prompt def _get_optional_params_from_langfuse(self, langfuse_prompt_client: PROMPT_CLIENT) -> dict: - config: Final = langfuse_prompt_client.config - optional_params: Final = {} - for k, v in config.items(): - if k != "model": - optional_params[k] = v - return optional_params + return dict(_params_without_model(langfuse_prompt_client.config)) async def async_get_chat_completion_prompt( self, diff --git a/litellm/integrations/langsmith.py b/litellm/integrations/langsmith.py index 01812149498..ff1f3568685 100644 --- a/litellm/integrations/langsmith.py +++ b/litellm/integrations/langsmith.py @@ -7,10 +7,11 @@ import random import traceback import types from datetime import datetime, timezone -from typing import Any, Final +from typing import Final import httpx from pydantic import BaseModel, TypeAdapter +from typing_extensions import ReadOnly, TypedDict import litellm from litellm._logging import verbose_logger @@ -31,6 +32,10 @@ from litellm.types.utils import StandardCallbackDynamicParams, StandardLoggingPa _RUN_RESPONSE: Final = TypeAdapter(object) +class _DynamicParamsKwargs(TypedDict, total=False): + standard_callback_dynamic_params: ReadOnly[StandardCallbackDynamicParams | None] + + def is_serializable(value): non_serializable_types: Final = ( types.CoroutineType, @@ -474,7 +479,7 @@ class LangsmithLogger(CustomBatchLogger): return log_queue_by_credentials - def _get_sampling_rate_to_use_for_request(self, kwargs: dict[str, Any]) -> float: + def _get_sampling_rate_to_use_for_request(self, kwargs: _DynamicParamsKwargs) -> float: standard_callback_dynamic_params: Final[StandardCallbackDynamicParams | None] = kwargs.get( "standard_callback_dynamic_params", None ) @@ -485,7 +490,7 @@ class LangsmithLogger(CustomBatchLogger): sampling_rate = float(_sampling_rate) return sampling_rate - def _get_credentials_to_use_for_request(self, kwargs: dict[str, Any]) -> LangsmithCredentialsObject: + def _get_credentials_to_use_for_request(self, kwargs: _DynamicParamsKwargs) -> LangsmithCredentialsObject: """ Handles key/team based logging diff --git a/litellm/integrations/langtrace.py b/litellm/integrations/langtrace.py index eeff76e7063..ea411baee7e 100644 --- a/litellm/integrations/langtrace.py +++ b/litellm/integrations/langtrace.py @@ -6,7 +6,7 @@ from litellm.types.integrations.otel_span_attributes import SpanAttributes if TYPE_CHECKING: from opentelemetry.trace import Span as _Span - Span = _Span | Any + Span = _Span else: Span = Any diff --git a/litellm/integrations/levo/levo.py b/litellm/integrations/levo/levo.py index 4d2b4edf3cd..c1852e9bfe4 100644 --- a/litellm/integrations/levo/levo.py +++ b/litellm/integrations/levo/levo.py @@ -4,8 +4,6 @@ from typing import TYPE_CHECKING, Any, Final from litellm.integrations.opentelemetry import OpenTelemetry if TYPE_CHECKING: - from opentelemetry.trace import Span as _Span - from litellm.integrations.opentelemetry import ( OpenTelemetryConfig as _OpenTelemetryConfig, ) @@ -13,11 +11,9 @@ if TYPE_CHECKING: Protocol = _Protocol OpenTelemetryConfig = _OpenTelemetryConfig - Span = _Span | Any else: Protocol = Any OpenTelemetryConfig = Any - Span = Any class LevoConfig: diff --git a/litellm/integrations/logfire_logger.py b/litellm/integrations/logfire_logger.py index 848369a1cbb..862893fa883 100644 --- a/litellm/integrations/logfire_logger.py +++ b/litellm/integrations/logfire_logger.py @@ -3,8 +3,9 @@ import os import traceback +from collections.abc import Mapping from enum import Enum -from typing import Any, Final, NamedTuple +from typing import Final, NamedTuple from typing_extensions import LiteralString @@ -15,7 +16,7 @@ from litellm.litellm_core_utils.redact_messages import redact_user_api_key_info class SpanConfig(NamedTuple): message_template: LiteralString - span_data: dict[str, Any] + span_data: Mapping[str, object] class LogfireLevel(str, Enum): diff --git a/litellm/integrations/newrelic/newrelic.py b/litellm/integrations/newrelic/newrelic.py index 9829ef4e18f..3623335f599 100644 --- a/litellm/integrations/newrelic/newrelic.py +++ b/litellm/integrations/newrelic/newrelic.py @@ -49,11 +49,12 @@ import time import uuid from collections.abc import Mapping, Sequence from datetime import datetime -from typing import Any, Final +from typing import Final, Protocol import litellm from litellm._logging import verbose_logger from litellm.integrations.custom_logger import CustomLogger +from litellm.litellm_core_utils.core_helpers import has_attributes from litellm.litellm_core_utils.redact_messages import should_redact_message_logging from litellm.types.integrations.base_health_check import IntegrationHealthCheckStatus from litellm.types.integrations.newrelic import NewRelicInitParams @@ -65,6 +66,10 @@ except ImportError: _newrelic_agent = None +class _SupportsTimestamp(Protocol): + def timestamp(self) -> float: ... + + class NewRelicLogger(CustomLogger): """ New Relic logger for LiteLLM to send AI monitoring events. @@ -126,13 +131,13 @@ class NewRelicLogger(CustomLogger): verbose_logger.error("Failed to initialize New Relic agent: %s. Integration will be disabled.", e) self.enabled = False - def _get_newrelic_params(self) -> dict: + def _get_newrelic_params(self) -> Mapping[str, object]: """ Get the newrelic_params from litellm.newrelic_params These are params specific to initializing the NewRelicLogger e.g. turn_off_message_logging """ - dict_newrelic_params: dict = {} + dict_newrelic_params: Mapping[str, object] = {} if litellm.newrelic_params is not None: if isinstance(litellm.newrelic_params, NewRelicInitParams): dict_newrelic_params = litellm.newrelic_params.model_dump() @@ -401,9 +406,9 @@ class NewRelicLogger(CustomLogger): return choices[0].get("finish_reason") or "unknown" return "unknown" - def _to_epoch_ms(self, t: Any) -> float: + def _to_epoch_ms(self, t: datetime | float) -> float: """Convert a datetime or float timestamp to epoch milliseconds.""" - if hasattr(t, "timestamp"): + if has_attributes(t, _SupportsTimestamp, "timestamp"): return t.timestamp() * 1000.0 return float(t) * 1000.0 @@ -518,13 +523,13 @@ class NewRelicLogger(CustomLogger): sequence = 0 # Extract timestamps, preferring StandardLoggingPayload - start_time = None + start_time: datetime | float | None = None if standard_logging_object: start_time = standard_logging_object.get("startTime") if not start_time: start_time = kwargs.get("start_time") - end_time = None + end_time: datetime | float | None = None if standard_logging_object: end_time = standard_logging_object.get("endTime") if not end_time: diff --git a/litellm/integrations/newrelic/newrelic_metrics.py b/litellm/integrations/newrelic/newrelic_metrics.py index a2cedeba0f5..641d1d86188 100644 --- a/litellm/integrations/newrelic/newrelic_metrics.py +++ b/litellm/integrations/newrelic/newrelic_metrics.py @@ -254,7 +254,7 @@ class NewRelicMetricsLogger(CustomBatchLogger): if not self.log_queue: return if _pass < NEWRELIC_METRICS_MAX_DRAIN_PASSES - 1: - await asyncio.sleep(2**_pass) + await asyncio.sleep(1 << _pass) async with self.flush_lock: tried_ids: Final = frozenset(id(record) for record in attempted) survivors: Final = tuple(record for record in self.log_queue if id(record) not in tried_ids) diff --git a/litellm/integrations/opik/opik_payload_builder/payload_builders.py b/litellm/integrations/opik/opik_payload_builder/payload_builders.py index 3aaf5bfc162..2909ab9d63c 100644 --- a/litellm/integrations/opik/opik_payload_builder/payload_builders.py +++ b/litellm/integrations/opik/opik_payload_builder/payload_builders.py @@ -57,9 +57,7 @@ def build_span_payload( span_id: Final = utils.create_uuid7() model: Final[str] = response_obj.get("model", "unknown-model") - obj_type: Final[str] = response_obj.get("object", "unknown-object") - created: Final[int] = response_obj.get("created", 0) - span_name: Final = f"{model}_{obj_type}_{created}" + span_name: Final = f"{model}_{response_obj.get('object', 'unknown-object')}_{response_obj.get('created', 0)}" _logging.verbose_logger.debug("OpikLogger creating span with id %s for trace %s", span_id, trace_id) diff --git a/litellm/integrations/otel/langfuse_logger.py b/litellm/integrations/otel/langfuse_logger.py index c869474f532..15b0f3f0cc2 100644 --- a/litellm/integrations/otel/langfuse_logger.py +++ b/litellm/integrations/otel/langfuse_logger.py @@ -1,18 +1,25 @@ from collections.abc import AsyncGenerator, AsyncIterator, Callable, Mapping from typing import TYPE_CHECKING, Final +from opentelemetry.sdk.trace import ReadableSpan + from litellm._logging import verbose_logger from litellm.integrations.otel.logger import OpenTelemetryV2 from litellm.integrations.otel.mappers.langfuse import ( LANGFUSE_OBSERVATION_INPUT, LANGFUSE_OBSERVATION_OUTPUT, + LANGFUSE_TRACE_NAME, LangfuseMapper, ) +from litellm.integrations.otel.model.metadata import internal_call_origin from litellm.integrations.otel.model.request_io import request_input, response_output, stream_output from litellm.integrations.otel.model.trace_controls import caller_trace_controls +from litellm.integrations.otel.model.utils import as_str from litellm.integrations.otel.plumbing.context import request_root_span if TYPE_CHECKING: + from opentelemetry.trace import Span + from litellm.types.proxy.auth.user_api_key_auth import UserAPIKeyAuth from litellm.types.utils import ModelResponseStream @@ -24,9 +31,23 @@ class LangfuseOpenTelemetryV2(OpenTelemetryV2): def log_pre_api_call(self, model: str, messages: object, kwargs: Mapping[str, object]) -> None: root: Final = request_root_span() if root is not None and root.is_recording(): - root.set_attributes(LangfuseMapper.trace_attributes(caller_trace_controls(kwargs))) + root.set_attributes( + LangfuseMapper.trace_attributes( + caller_trace_controls(kwargs), + as_str(kwargs.get("call_type")) if self._derives_trace_name(root, kwargs) else None, + ) + ) super().log_pre_api_call(model, messages, kwargs) + def _derives_trace_name(self, root: "Span", kwargs: Mapping[str, object]) -> bool: + return ( + internal_call_origin(None, kwargs) is None + and isinstance(root, ReadableSpan) + and root.parent is None + and root.resource is self.tracer_provider.resource + and LANGFUSE_TRACE_NAME not in (root.attributes or {}) + ) + class LangfuseContentOpenTelemetryV2(LangfuseOpenTelemetryV2): """Stamps the request's input and output on the root observation while it is still recording. diff --git a/litellm/integrations/otel/mappers/langfuse.py b/litellm/integrations/otel/mappers/langfuse.py index e60ea539188..230a2e261fe 100644 --- a/litellm/integrations/otel/mappers/langfuse.py +++ b/litellm/integrations/otel/mappers/langfuse.py @@ -96,10 +96,10 @@ class LangfuseMapper: return {} @staticmethod - def trace_attributes(trace: TraceControls) -> AttributeMap: + def trace_attributes(trace: TraceControls, call_type: str | None = None) -> AttributeMap: return drop_none_pairs( ( - (LANGFUSE_TRACE_NAME, trace.name or None), + (LANGFUSE_TRACE_NAME, trace.name or (f"litellm-{call_type}" if call_type else None)), (LANGFUSE_TRACE_USER_ID, trace.user_id or None), (LANGFUSE_TRACE_SESSION_ID, trace.session_id or None), (LANGFUSE_TRACE_TAGS, trace.tags or None), diff --git a/litellm/integrations/otel/model/config.py b/litellm/integrations/otel/model/config.py index cca12b885c1..dd150082252 100644 --- a/litellm/integrations/otel/model/config.py +++ b/litellm/integrations/otel/model/config.py @@ -130,7 +130,8 @@ class _EnvWithoutBareExcludedServices(PydanticBaseSettingsSource): return self._env_settings.get_field_value(field, field_name) def __call__(self) -> dict[str, object]: - return {key: value for key, value in self._env_settings().items() if key != "excluded_services"} + settings: Final = self._env_settings() + return {key: settings[key] for key in settings if key != "excluded_services"} class OpenTelemetryV2Config(BaseSettings): diff --git a/litellm/integrations/otel/model/destination.py b/litellm/integrations/otel/model/destination.py index 4226b4361dd..e760ba3600b 100644 --- a/litellm/integrations/otel/model/destination.py +++ b/litellm/integrations/otel/model/destination.py @@ -42,7 +42,7 @@ class OtelDestination(LiteLLMBaseModel): success_sampling_rate: float | None = Field( default=None, description=( - "Share of the request trees forwarded, 0.0..1.0, drawn once per request when its root span ends; " + "Share of the request trees forwarded, 0.0..1.0, picked by a hash of the trace id; " "``None`` forwards every one." ), ) diff --git a/litellm/integrations/otel/model/metadata.py b/litellm/integrations/otel/model/metadata.py index 5d37894bb8f..a69c334a1fb 100644 --- a/litellm/integrations/otel/model/metadata.py +++ b/litellm/integrations/otel/model/metadata.py @@ -332,7 +332,7 @@ def caller_session_id(kwargs: Mapping[str, object], trace: TraceControls) -> str return (None if echoes_trace_id else explicit) or trace.session_id or None -def time_to_first_chunk_seconds(kwargs: Mapping[str, Any]) -> float | None: +def time_to_first_chunk_seconds(kwargs: Mapping[str, object]) -> float | None: """Seconds from the upstream request being issued (``api_call_start_time``) to the first streamed chunk (``completion_start_time``); ``None`` for non-streaming calls, where ``completion_start_time`` is backfilled with the @@ -340,8 +340,8 @@ def time_to_first_chunk_seconds(kwargs: Mapping[str, Any]) -> float | None: optional_params: Final = cast(Mapping[str, object], kwargs.get("optional_params") or {}) if not optional_params.get("stream"): return None - api_call_start: Final = to_seconds(kwargs.get("api_call_start_time")) - completion_start: Final = to_seconds(kwargs.get("completion_start_time")) + api_call_start: Final = _epoch_seconds(kwargs.get("api_call_start_time")) + completion_start: Final = _epoch_seconds(kwargs.get("completion_start_time")) if api_call_start is None or completion_start is None: return None return completion_start - api_call_start diff --git a/litellm/integrations/otel/model/payloads.py b/litellm/integrations/otel/model/payloads.py index d11505ce026..9c62c45e489 100644 --- a/litellm/integrations/otel/model/payloads.py +++ b/litellm/integrations/otel/model/payloads.py @@ -7,7 +7,7 @@ from collections.abc import Mapping, Sequence from dataclasses import dataclass, field from enum import Enum from types import MappingProxyType -from typing import TYPE_CHECKING, ClassVar, Final, Literal, cast +from typing import TYPE_CHECKING, ClassVar, Final, Literal, Protocol, cast from urllib.parse import urlsplit from typing_extensions import ReadOnly, TypedDict @@ -716,6 +716,15 @@ def _json_or_none(value: object) -> str | None: return None +class _EnumValue(Protocol): + @property + def value(self) -> object: ... + + +def _enum_value(item: _EnumValue) -> object: + return item.value + + def _guardrail_mode_str(value: object) -> str | None: """Normalize ``guardrail_mode`` to a stable string. @@ -732,12 +741,12 @@ def _guardrail_mode_str(value: object) -> str | None: for item in value: if item is None: continue - part = as_str(item.value) if isinstance(item, Enum) else as_str(item) + part = as_str(_enum_value(item)) if isinstance(item, Enum) else as_str(item) if part: parts.append(part) return ",".join(parts) or None if isinstance(value, Enum): - return as_str(value.value) + return as_str(_enum_value(value)) return as_str(value) diff --git a/litellm/integrations/otel/model/request_io.py b/litellm/integrations/otel/model/request_io.py index 287d28a0d17..82225531e23 100644 --- a/litellm/integrations/otel/model/request_io.py +++ b/litellm/integrations/otel/model/request_io.py @@ -6,7 +6,7 @@ from typing_extensions import ReadOnly, TypedDict import litellm from litellm.integrations.otel.mappers.utils import json_or_none -from litellm.llms.anthropic.pass_through.stream_assembly import assemble_anthropic_sse_stream, is_raw_sse_stream +from litellm.llms.anthropic.messages.stream_assembly import assemble_anthropic_sse_stream, is_raw_sse_stream from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import ResponseCompletedEvent, ResponsesAPIResponse from litellm.types.utils import ModelResponse, ModelResponseStream diff --git a/litellm/integrations/otel/plumbing/metrics.py b/litellm/integrations/otel/plumbing/metrics.py index 7ec3711ee65..72d51471ba2 100644 --- a/litellm/integrations/otel/plumbing/metrics.py +++ b/litellm/integrations/otel/plumbing/metrics.py @@ -173,6 +173,7 @@ class _MetricKwargs(TypedDict, total=False): response_cost: ReadOnly[float | None] completion_start_time: ReadOnly[datetime | float | str | None] api_call_start_time: ReadOnly[datetime | float | str | None] + end_time: ReadOnly[datetime | float | str | None] def resolve_error_type(kwargs: Mapping[str, Any]) -> str: @@ -414,15 +415,12 @@ class GenAIMetricRecorder: if generation_time > 0: self._metrics.time_per_output_token.record(generation_time / completion_tokens, attributes=common_attrs) - def _record_response_duration(self, kwargs: Mapping[str, Any], end_time: datetime, common_attrs: dict) -> None: + def _record_response_duration(self, kwargs: _MetricKwargs, end_time: datetime, common_attrs: dict) -> None: api_call_start_time: Final = kwargs.get("api_call_start_time") if api_call_start_time is None: return - _end_time = kwargs.get("end_time") or end_time - if _end_time is None: - _end_time = datetime.now() api_call_start: Final = to_seconds(api_call_start_time) - end_ts: Final = to_seconds(_end_time) + end_ts: Final = to_seconds(kwargs.get("end_time") or end_time) if api_call_start is None or end_ts is None: return duration: Final = end_ts - api_call_start diff --git a/litellm/integrations/otel/plumbing/providers.py b/litellm/integrations/otel/plumbing/providers.py index 898eab5715b..fc1e9b7099d 100644 --- a/litellm/integrations/otel/plumbing/providers.py +++ b/litellm/integrations/otel/plumbing/providers.py @@ -1,13 +1,14 @@ """Provider / exporter factory + the Baggage span processor.""" import queue -import random import threading import time +import weakref from collections import OrderedDict from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence +from hashlib import sha256 from types import MappingProxyType -from typing import TYPE_CHECKING, Final, Literal +from typing import TYPE_CHECKING, Final, Literal, TypeAlias from opentelemetry import _logs, baggage, metrics, trace from opentelemetry._logs import Logger, LoggerProvider, NoOpLoggerProvider @@ -486,15 +487,15 @@ def is_llm_call_span(span: ReadableSpan) -> bool: return GenAI.OPERATION_NAME in attributes and MCP.METHOD_NAME not in attributes -#: Request trees held back for a sampled destination until the last span of the trace +#: Request trees held back for a sampled destination until the last span of the request #: still open ends, the verdicts kept for the spans that start after that (a post-call -#: database write), and the spans in flight per trace. All bounded, so a span that never -#: ends, or a flood of requests, cannot hold spans for ever: the oldest tree is decided -#: on what it has. +#: database write), the spans in flight per request, and the request each open span +#: belongs to. All bounded, so a span that never ends, or a flood of requests, cannot +#: hold spans for ever: the oldest tree is decided on what it has. _MAX_PENDING_TREES: Final = 1024 _MAX_PENDING_SPANS_PER_TREE: Final = 512 _MAX_REMEMBERED_VERDICTS: Final = 4096 -_MAX_OPEN_TRACES: Final = 16384 +_MAX_OPEN_REQUESTS: Final = 16384 class _PendingTree: @@ -512,25 +513,35 @@ def _is_sampled(destination: "OtelDestination") -> bool: return destination.success_sampling_rate is not None or destination.error_sampling_rate is not None -#: A verdict is one request tree's draw for one destination at its rates: the exporter +#: A request is its trace id and the id of its root, the span of it whose parent is +#: remote or missing. Calls sharing a caller's trace are separate requests, each decided +#: on its own outcome. +_RequestKey: TypeAlias = tuple[int, int] + +#: A verdict is one request's keep or drop for one destination at its rates: the exporter #: ``cache_key`` leaves the rates out, so two destinations sharing an exporter with -#: different rates would otherwise share one draw. -_VerdictKey = tuple[int, object, float | None, float | None] +#: different rates would otherwise share one verdict. +_VerdictKey: TypeAlias = tuple[int, int, object, float | None, float | None] -def _verdict_key(trace_id: int, destination: "OtelDestination") -> _VerdictKey: - return (trace_id, destination.cache_key(), destination.success_sampling_rate, destination.error_sampling_rate) +def _verdict_key(request: _RequestKey, destination: "OtelDestination") -> _VerdictKey: + return (*request, destination.cache_key(), destination.success_sampling_rate, destination.error_sampling_rate) -def _keeps_tree(destination: "OtelDestination", failed: bool, draw: Callable[[], float]) -> bool: - """Whether one draw against the destination's rate keeps a request tree, read the - way the legacy Arize callback reads ``arize_success_sampling_rate`` / - ``arize_error_sampling_rate``: a tree with a failed span answers to the error - rate, an unset rate keeps everything and ``0.0`` keeps nothing.""" +def _keeps_tree(destination: "OtelDestination", failed: bool, trace_id: int) -> bool: + """Whether the destination's rate keeps a request tree of ``trace_id``: a tree with + a failed span answers to ``arize_error_sampling_rate``, the rest to + ``arize_success_sampling_rate``, an unset rate keeps everything and ``0.0`` keeps + nothing. + + The first eight bytes of a SHA-256 of the trace id are read against the rate, so + every process deciding a request of the trace with the same outcome reaches the same + verdict.""" rate: Final = destination.error_sampling_rate if failed else destination.success_sampling_rate if rate is None: return True - return rate > 0.0 and draw() <= rate + digest: Final = sha256(trace_id.to_bytes(16, "big")).digest() + return int.from_bytes(digest[:8], "big") < round(rate * 2**64) def _in_scope(span: ReadableSpan, scope: "OtelSpanScope") -> bool: @@ -667,10 +678,8 @@ class TenantFanOutSpanProcessor(SpanProcessor): default_capture_by_backend: Mapping[str, str] = MappingProxyType({}), pending_drains: int = _MAX_PENDING_DRAINS, drain_pool: _DrainPool | None = None, - sampling_draw: Callable[[], float] | None = None, ) -> None: self._operator_sinks: Final = operator_sinks - self._draw: Final = sampling_draw if sampling_draw is not None else random.random self._excluded_db_systems: Final = excluded_db_systems self._default_capture: Final = default_capture self._default_capture_by_backend: Final = default_capture_by_backend @@ -682,24 +691,32 @@ class TenantFanOutSpanProcessor(SpanProcessor): self._processors: OrderedDict[object, SpanProcessor] = OrderedDict() # mutable-ok: bounded LRU self._retired: OrderedDict[int, SpanProcessor] = OrderedDict() # mutable-ok: drains as exports finish self._exporting: dict[int, int] = {} # mutable-ok: per-processor in-flight export count - self._pending: OrderedDict[int, _PendingTree] = OrderedDict() # mutable-ok: bounded, by trace id - self._open: OrderedDict[int, int] = OrderedDict() # mutable-ok: bounded, spans in flight by trace id + self._pending: OrderedDict[_RequestKey, _PendingTree] = OrderedDict() # mutable-ok: bounded, by request + self._open: OrderedDict[_RequestKey, set[int]] = OrderedDict() # mutable-ok: bounded, open span ids by request + self._roots: dict[int, _RequestKey] = {} # mutable-ok: holds only the spans ``_open`` holds, request by span id + self._span_roots: weakref.WeakKeyDictionary[SDKSpan, int] = weakref.WeakKeyDictionary() self._verdicts: OrderedDict[_VerdictKey, bool] = OrderedDict() # mutable-ok: bounded LRU self._drain: Final = drain_pool if drain_pool is not None else _DrainPool(capacity=pending_drains) def on_start(self, span: SDKSpan, parent_context: Context | None = None) -> None: context: Final = span.context - trace_id: Final = context.trace_id if context is not None else 0 with self._lock: - self._open[trace_id] = self._open.get(trace_id, 0) + 1 - while len(self._open) > _MAX_OPEN_TRACES: - self._open.popitem(last=False) + request: Final = self._request_of(span, trace.get_current_span(parent_context)) + if context is not None: + self._span_roots[span] = request[1] + self._roots[context.span_id] = request + self._open.setdefault(request, set()).add(context.span_id) + while len(self._open) > _MAX_OPEN_REQUESTS: + for forgotten in self._open.popitem(last=False)[1]: + self._roots.pop(forgotten, None) def on_end(self, span: ReadableSpan) -> None: suppressed: Final = suppressed_backends() attributes: Final = span.attributes or _NO_ATTRIBUTES - context: Final = span.context - trace_id: Final = context.trace_id if context is not None else 0 + with self._lock: + request: Final = self._request_of(span) + if span.context is not None: + self._roots.pop(span.context.span_id, None) failed: Final = span.status.status_code is StatusCode.ERROR for destination in request_destinations(): if ( @@ -716,11 +733,32 @@ class TenantFanOutSpanProcessor(SpanProcessor): if not _is_sampled(destination): self._forward(span, destination) continue - for held_span, held_destination in self._route(trace_id, span, destination, failed): + for held_span, held_destination in self._route(request, span, destination, failed): self._forward(held_span, held_destination) - for held_span, held_destination in self._settle(trace_id, failed): + for held_span, held_destination in self._settle(request, span, failed): self._forward(held_span, held_destination) + def _request_of(self, span: ReadableSpan, parent_span: Span | None = None) -> _RequestKey: + """The request ``span`` belongs to, read under ``_lock``: the request recorded while + it is open, else the span itself when its parent is remote or missing, else its + parent's request, recorded while the parent is open or on ``parent_span`` for a + child starting under a parent that has ended, else the parent itself.""" + context: Final = span.context + if context is None: + return (0, 0) + recorded: Final = self._roots.get(context.span_id) + if recorded is not None: + return recorded + parent: Final = span.parent + if parent is None or parent.is_remote: + return (context.trace_id, context.span_id) + parent_request: Final = self._roots.get(parent.span_id) + if parent_request is not None: + return parent_request + if isinstance(parent_span, SDKSpan): + return (context.trace_id, self._span_roots.get(parent_span, parent.span_id)) + return (context.trace_id, parent.span_id) + def _default_capture_for(self, destination: "OtelDestination") -> str: backend: Final = destination.callback_name return ( @@ -743,14 +781,14 @@ class TenantFanOutSpanProcessor(SpanProcessor): self._release(processor) def _route( - self, trace_id: int, span: ReadableSpan, destination: "OtelDestination", failed: bool + self, request: _RequestKey, span: ReadableSpan, destination: "OtelDestination", failed: bool ) -> "tuple[tuple[ReadableSpan, OtelDestination], ...]": """The spans to forward now for ``span`` on a sampled ``destination``: the span itself when its tree's verdict is already known and keeps it, nothing while the - tree is held for the rest of its trace, or what the bounds made the fan-out decide + tree is held for the rest of its request, or what the bounds made the fan-out decide early (a tree that outgrew its cap is decided on what it has, and so is the oldest tree once too many are waiting, so a span that never ends holds nothing back for - ever). A failed span marks its tree before any such early draw. Once shutdown + ever). A failed span marks its tree before any such early decision. Once shutdown has started flushing, nothing is held: a span ending then is decided at once, since no later flush would reach it. @@ -758,58 +796,62 @@ class TenantFanOutSpanProcessor(SpanProcessor): another thread between the two would leave this span in a fresh tree. """ with self._lock: - verdict: Final = self._verdicts.get(_verdict_key(trace_id, destination)) + verdict: Final = self._verdicts.get(_verdict_key(request, destination)) if verdict is not None: return ((span, destination),) if verdict else () - tree: Final = self._pending.setdefault(trace_id, _PendingTree()) + tree: Final = self._pending.setdefault(request, _PendingTree()) tree.held.append((span, destination)) if failed: tree.failed = True if self._draining or len(tree.held) >= _MAX_PENDING_SPANS_PER_TREE: - return self._decide_locked(trace_id) + return self._decide_locked(request) if len(self._pending) > _MAX_PENDING_TREES: oldest: Final = next(iter(self._pending)) return self._decide_locked(oldest) return () - def _decide(self, trace_id: int) -> "tuple[tuple[ReadableSpan, OtelDestination], ...]": + def _decide(self, request: _RequestKey) -> "tuple[tuple[ReadableSpan, OtelDestination], ...]": with self._lock: - return self._decide_locked(trace_id) + return self._decide_locked(request) - def _settle(self, trace_id: int, failed: bool) -> "tuple[tuple[ReadableSpan, OtelDestination], ...]": - """What the trace's held tree exports once the span that just ended was the last - of its trace still open. The model-call span ends in the post-call callback, - after the server span, so a tree is decided when its trace goes quiet rather than + def _settle( + self, request: _RequestKey, span: ReadableSpan, failed: bool + ) -> "tuple[tuple[ReadableSpan, OtelDestination], ...]": + """What the request's held tree exports once the span that just ended was the last + of its request still open. The model-call span ends in the post-call callback, + after the server span, so a tree is decided when its request goes quiet rather than when its root ends, and a model call that fails late still answers to the error - rate. A trace whose starts this fan-out never saw (attached mid-flight, or forgotten - by the bound) is decided as each of its spans ends. + rate. A request whose starts this fan-out never saw (attached mid-flight, or + forgotten by the bound) is decided as each of its spans ends. """ with self._lock: - tree: Final = self._pending.get(trace_id) + tree: Final = self._pending.get(request) if tree is not None and failed: tree.failed = True - still_open: Final = self._open.pop(trace_id, 1) - 1 - if still_open > 0: - self._open[trace_id] = still_open + still_open: Final = self._open.pop(request, set()) + if span.context is not None: + still_open.discard(span.context.span_id) + if still_open: + self._open[request] = still_open return () - return self._decide_locked(trace_id) + return self._decide_locked(request) - def _decide_locked(self, trace_id: int) -> "tuple[tuple[ReadableSpan, OtelDestination], ...]": - """Draw once per destination for the held tree; the spans the draws keep, and a - verdict remembered for the spans of this trace that start later.""" - tree: Final = self._pending.pop(trace_id, None) + def _decide_locked(self, request: _RequestKey) -> "tuple[tuple[ReadableSpan, OtelDestination], ...]": + """Decide once per destination for the held tree; the spans the verdicts keep, and + a verdict remembered for the spans of this request that start later.""" + tree: Final = self._pending.pop(request, None) if tree is None: return () - verdicts: dict[_VerdictKey, bool] = {} # mutable-ok: one draw per destination of this tree + verdicts: dict[_VerdictKey, bool] = {} # mutable-ok: one verdict per destination of this tree for _, destination in tree.held: - key = _verdict_key(trace_id, destination) + key = _verdict_key(request, destination) if key not in verdicts: - verdicts[key] = _keeps_tree(destination, tree.failed, self._draw) + verdicts[key] = _keeps_tree(destination, tree.failed, request[0]) self._verdicts[key] = verdicts[key] while len(self._verdicts) > _MAX_REMEMBERED_VERDICTS: self._verdicts.popitem(last=False) return tuple( - (span, destination) for span, destination in tree.held if verdicts[_verdict_key(trace_id, destination)] + (span, destination) for span, destination in tree.held if verdicts[_verdict_key(request, destination)] ) def _operator_already_writes( @@ -850,8 +892,8 @@ class TenantFanOutSpanProcessor(SpanProcessor): with self._lock: self._draining = True undecided: Final = tuple(self._pending) - for trace_id in undecided: - for held_span, held_destination in self._decide(trace_id): + for request in undecided: + for held_span, held_destination in self._decide(request): self._forward(held_span, held_destination) deadline: Final = time.monotonic() + self._drain_seconds with self._lock: diff --git a/litellm/integrations/prometheus.py b/litellm/integrations/prometheus.py index 19d161b8aa4..bc8344fa686 100644 --- a/litellm/integrations/prometheus.py +++ b/litellm/integrations/prometheus.py @@ -14,6 +14,7 @@ from functools import partial from types import MappingProxyType from typing import TYPE_CHECKING, Annotated, Any, Final, Literal, Protocol, TypeAlias, TypeVar, cast +import openai from pydantic import BaseModel, Field, TypeAdapter, ValidationError from typing_extensions import ReadOnly, TypedDict, assert_never @@ -22,11 +23,13 @@ from litellm._internal_context import with_service_target from litellm._logging import print_verbose, verbose_logger from litellm.constants import ( AUTH_OBJECTS_TARGET, + LITELLM_LOGGING_NO_UPSTREAM_LLM_CALL, PROMETHEUS_OVERFLOW_SERIES_LABEL_VALUE, PROXY_LLM_PROVIDER_FALLBACK, PROXY_REJECTED_BEFORE_ROUTING_KEY, ) from litellm.exceptions import ( + CallerCredentialAuthenticationError, MalformedRequestFieldError, validate_rate_limit_category, validate_rate_limit_type, @@ -51,6 +54,7 @@ from litellm.litellm_core_utils.get_llm_provider_logic import is_registered_cust from litellm.litellm_core_utils.service_tier_utils import ( get_service_tier_from_standard_logging_payload, ) +from litellm.llms.github_copilot.per_user_auth import github_copilot_user_session_from from litellm.llms.openai_like.json_loader import JSONProviderRegistry from litellm.models.end_user import LiteLLM_EndUserTable from litellm.models.team import LiteLLM_TeamTable @@ -269,7 +273,10 @@ _NO_LOGGED_FIELDS: Final[Mapping[str, object]] = MappingProxyType({}) def _logged_fields(value: object) -> Mapping[str, object]: - return _LOGGED_FIELDS.validate_python(value) if isinstance(value, Mapping) else _NO_LOGGED_FIELDS + try: + return _LOGGED_FIELDS.validate_python(value) + except ValidationError: + return _NO_LOGGED_FIELDS def _is_llm_provider(name: str) -> bool: @@ -359,6 +366,87 @@ def _get_proxy_llm_router() -> Router | None: return llm_router +_CALLER_CREDENTIAL_FIELDS: Final = frozenset( + { + "aws_access_key_id", + "aws_secret_access_key", + "aws_session_token", + "aws_web_identity_token", + "azure_ad_token", + "azure_password", + "azure_scope", + "azure_username", + "client_id", + "client_secret", + "gigachat_access_token", + "litellm_credential_name", + "oci_fingerprint", + "oci_key", + "oci_key_file", + "oci_tenancy", + "oci_user", + "tenant_id", + "token", + "user_config", + "vertex_ai_credentials", + "vertex_credentials", + "watsonx_credentials", + "wx_credentials", + "zen_api_key", + } +) + + +_CALLER_ENDPOINT_FIELDS: Final = frozenset( + {"aws_bedrock_runtime_endpoint", "aws_sts_endpoint", "deployment_url", "s3_endpoint_url", "sagemaker_base_url"} +) + + +_CALLER_TRANSPORT_FIELDS: Final = frozenset( + {"api_key", "extra_headers", "headers", "organization", "provider_specific_header"} +) + + +def _sent_a_provider_credential_or_endpoint(caller_body: Mapping[str, object]) -> bool: + """True when the caller's request body, or its ``extra_body``, carries a provider credential field or a + provider endpoint field.""" + sent: Final = {*caller_body, *_logged_fields(caller_body.get("extra_body"))} + return not (_CALLER_CREDENTIAL_FIELDS.isdisjoint(sent) and _CALLER_ENDPOINT_FIELDS.isdisjoint(sent)) + + +def _used_a_caller_credential(logged_call: Mapping[str, object]) -> bool: + """True when the provider was called with a credential or at an endpoint that belongs to the caller rather than + the deployment: an api_key, header, OpenAI organization or other provider credential or endpoint field the caller + sent with the request, a stored credential the caller picked by name, the caller's own Anthropic OAuth token, the caller's own GitHub Copilot connection, or the + caller's identity token that a token-exchange deployment trades in on every call.""" + litellm_params: Final = _logged_fields(logged_call.get("litellm_params")) + proxy_server_request: Final = _logged_fields(litellm_params.get("proxy_server_request")) + caller_credential_fields: Final = proxy_server_request.get("caller_credential_fields") + logged_metadata: Final = _logged_fields(_logged_fields(logged_call.get("standard_logging_object")).get("metadata")) + return ( + ( + isinstance(caller_credential_fields, tuple) + and any(field in caller_credential_fields for field in _CALLER_TRANSPORT_FIELDS) + ) + or _sent_a_provider_credential_or_endpoint(_logged_fields(proxy_server_request.get("body"))) + or bool(litellm_params.get("token_exchange_endpoint")) + or logged_metadata.get("used_client_oauth_token") is True + or github_copilot_user_session_from(litellm_params) is not None + ) + + +def _is_deployment_failure(exception: openai.APIError, logged_call: Mapping[str, object]) -> bool: + """True for an error raised while calling the deployment with its own credential, on a request the proxy + did not reject itself. An error LiteLLM raises before it calls the provider, such as a missing deployment key, + is not one.""" + return not ( + isinstance(exception, CallerCredentialAuthenticationError) + or bool(logged_call.get(LITELLM_LOGGING_NO_UPSTREAM_LLM_CALL)) + or logged_call.get("api_call_start_time") is None + or _used_a_caller_credential(logged_call) + ) + + def _bounded_requested_model_label(requested_model: object, router_originated: bool = False) -> str | None: """ Bound ``requested_model`` label cardinality: names the router recognizes @@ -2817,6 +2905,8 @@ class PrometheusLogger(CustomLogger): information from various callback function signatures and determines if the request represents an invalid API key attempt that should be filtered from metrics. + An error raised while calling the deployment with its own credential is never skipped. + Args: kwargs: Dictionary potentially containing exception and other data user_api_key_dict: User API key authentication object (currently unused) @@ -2836,6 +2926,11 @@ class PrometheusLogger(CustomLogger): if exception is None and kwargs: exception = kwargs.get("exception") + if isinstance(exception, openai.APIError) and _is_deployment_failure( + exception, _LOGGED_FIELDS.validate_python(kwargs or {}) + ): + return False + if self._is_invalid_api_key_request(status_code, exception=exception): verbose_logger.debug( "Skipping Prometheus metrics for invalid API key request: status_code=%s, exception=%s", diff --git a/litellm/integrations/shadow_eval_logger.py b/litellm/integrations/shadow_eval_logger.py index d0ed30d40dd..3a2d7ee33bb 100644 --- a/litellm/integrations/shadow_eval_logger.py +++ b/litellm/integrations/shadow_eval_logger.py @@ -113,7 +113,7 @@ def _chat_request_from_anthropic_messages( because the logged optional_params switch dialect per provider path (the bridge's inner completion rewrites them to chat shape mid-flight); the adapter translates them alongside the messages, and sampling params copy through untranslated.""" - from litellm.llms.anthropic.pass_through.adapters.transformation import ( + from litellm.llms.anthropic.messages.adapters.transformation import ( LiteLLMAnthropicMessagesAdapter, ) diff --git a/litellm/integrations/sqs.py b/litellm/integrations/sqs.py index d787375ca3c..83f85232182 100644 --- a/litellm/integrations/sqs.py +++ b/litellm/integrations/sqs.py @@ -13,6 +13,8 @@ import re import traceback from typing import Final +from pydantic import TypeAdapter + import litellm from litellm._logging import print_verbose, verbose_logger from litellm.constants import ( @@ -32,6 +34,7 @@ from litellm.types.utils import StandardLoggingPayload from .custom_batch_logger import CustomBatchLogger +_DECODED_JSON: Final = TypeAdapter(object) _BASE64_INLINE_PATTERN: Final = re.compile( r"data:(?:application|image|audio|video)/[a-zA-Z0-9.+-]+;base64,[A-Za-z0-9+/=\s]+", re.MULTILINE, @@ -270,7 +273,7 @@ class SQSLogger(CustomBatchLogger, BaseAWSLLM): if self.sqs_queue_url is None: raise ValueError("sqs_queue_url not set") - json_data: Final = json.loads(safe_dumps(payload)) + json_data: Final = _DECODED_JSON.validate_python(json.loads(safe_dumps(payload))) if self.app_crypto: aad_bytes: Final = self.sqs_app_encryption_aad.encode("utf-8") if self.sqs_app_encryption_aad else None encrypted: Final = self.app_crypto.encrypt_json(json_data, aad=aad_bytes) diff --git a/litellm/integrations/websearch_interception/ARCHITECTURE.md b/litellm/integrations/websearch_interception/ARCHITECTURE.md index 255c1f1adb2..4ba8c2daa63 100644 --- a/litellm/integrations/websearch_interception/ARCHITECTURE.md +++ b/litellm/integrations/websearch_interception/ARCHITECTURE.md @@ -70,7 +70,7 @@ Claude Code (Anthropic's official CLI) sends web search requests using Anthropic Native tools are converted to LiteLLM standard format **before** sending to the provider: -1. **Conversion Point** (`litellm/llms/anthropic/pass_through/messages/handler.py`): +1. **Conversion Point** (`litellm/llms/anthropic/messages/native/handler.py`): - In `anthropic_messages()` function (lines 60-127) - Runs BEFORE the API request is made - Detects native web search tools using `is_web_search_tool()` diff --git a/litellm/interactions/background_cost_polling.py b/litellm/interactions/background_cost_polling.py index 275eb17787e..0b8c128286a 100644 --- a/litellm/interactions/background_cost_polling.py +++ b/litellm/interactions/background_cost_polling.py @@ -313,19 +313,35 @@ def _spend_metadata(logging_obj: "LiteLLMLoggingObj") -> Mapping[str, object]: } +def _sent_tags_are_a_list(litellm_params: Mapping[str, object]) -> bool: + """Whether the first non-empty ``tags`` in ``metadata`` then ``litellm_metadata`` is absent or a list.""" + buckets: Final = (litellm_params.get("metadata"), litellm_params.get("litellm_metadata")) + sent: Final = next( + ( + tags + for bucket in buckets + if isinstance(bucket, Mapping) and (tags := _OBJECT_MAPPING.validate_python(bucket).get("tags")) + ), + None, + ) + return sent is None or isinstance(sent, list) + + def _request_tags(litellm_params: Mapping[str, object]) -> Mapping[str, object]: from litellm.litellm_core_utils.litellm_logging import StandardLoggingPayloadSetup try: - return { - "tags": StandardLoggingPayloadSetup.get_request_tags( - litellm_params=_OBJECT_DICT.validate_python(litellm_params), - proxy_server_request=_OBJECT_DICT.validate_python(litellm_params.get("proxy_server_request") or {}), - ) - } + if _sent_tags_are_a_list(litellm_params): + return { + "tags": StandardLoggingPayloadSetup.get_request_tags( + litellm_params=_OBJECT_DICT.validate_python(litellm_params), + proxy_server_request=_OBJECT_DICT.validate_python(litellm_params.get("proxy_server_request") or {}), + ) + } except AttributeError: - verbose_logger.debug("Keeping a background interaction's request tags as sent: they are not a list") - return {} + pass + verbose_logger.debug("Keeping a background interaction's request tags as sent: they are not a list") + return {} def _create_context(logging_obj: "LiteLLMLoggingObj", custom_llm_provider: str) -> BackgroundInteractionCreateContext: diff --git a/litellm/interactions/litellm_responses_transformation/handler.py b/litellm/interactions/litellm_responses_transformation/handler.py index 8fee0fcd1b5..d84f0b5ffbd 100644 --- a/litellm/interactions/litellm_responses_transformation/handler.py +++ b/litellm/interactions/litellm_responses_transformation/handler.py @@ -116,10 +116,7 @@ class LiteLLMResponsesInteractionsHandler: """Async handler for interactions API requests.""" # Call litellm.aresponses() # Note: litellm.aresponses() returns Union[ResponsesAPIResponse, BaseResponsesAPIStreamingIterator] - aresponses_fn: Final[ - Callable[..., Coroutine[object, object, ResponsesAPIResponse | BaseResponsesAPIStreamingIterator]] - ] = vars(litellm)["aresponses"] - responses_response: Final = await aresponses_fn( + responses_response: Final = await litellm.aresponses( **responses_request, ) diff --git a/litellm/litellm_core_utils/app_crypto.py b/litellm/litellm_core_utils/app_crypto.py index 4ef3f34f3b8..da844620dce 100644 --- a/litellm/litellm_core_utils/app_crypto.py +++ b/litellm/litellm_core_utils/app_crypto.py @@ -4,6 +4,9 @@ import os from typing import Final from cryptography.hazmat.primitives.ciphers.aead import AESGCM +from pydantic import TypeAdapter + +_DECODED_JSON: Final = TypeAdapter(object) class AppCrypto: @@ -12,7 +15,7 @@ class AppCrypto: raise ValueError("Master key must be 32 bytes for AES-256-GCM") self.key = master_key - def encrypt_json(self, data: dict, aad: bytes | None = None) -> dict: + def encrypt_json(self, data: object, aad: bytes | None = None) -> dict: aes: Final = AESGCM(self.key) nonce: Final = os.urandom(12) plaintext: Final = json.dumps(data).encode("utf-8") @@ -24,10 +27,10 @@ class AppCrypto: "tag": base64.b64encode(tag).decode(), } - def decrypt_json(self, enc: dict, aad: bytes | None = None) -> dict: + def decrypt_json(self, enc: dict, aad: bytes | None = None) -> object: aes: Final = AESGCM(self.key) nonce: Final = base64.b64decode(enc["nonce"]) ct: Final = base64.b64decode(enc["ciphertext"]) tag: Final = base64.b64decode(enc["tag"]) data: Final = aes.decrypt(nonce, ct + tag, aad) - return json.loads(data.decode()) + return _DECODED_JSON.validate_python(json.loads(data.decode())) diff --git a/litellm/litellm_core_utils/cloud_storage_security.py b/litellm/litellm_core_utils/cloud_storage_security.py index e9689bd7d8a..8e949694881 100644 --- a/litellm/litellm_core_utils/cloud_storage_security.py +++ b/litellm/litellm_core_utils/cloud_storage_security.py @@ -3,10 +3,11 @@ import re from collections.abc import Mapping, Sequence from itertools import accumulate, repeat from types import MappingProxyType -from typing import Any, Final, cast +from typing import Final from urllib.parse import quote, unquote from litellm._uuid import uuid +from litellm.litellm_core_utils.core_helpers import as_str_mapping VERTEX_AI_MANAGED_GCS_PREFIX: Final = "litellm-vertex-files/" BEDROCK_MANAGED_S3_BATCH_PREFIX: Final = "litellm-bedrock-files-" @@ -141,7 +142,8 @@ def should_allow_legacy_cloud_file_ids( if isinstance(litellm_params, Mapping): trusted_model_credentials: Final = litellm_params.get("_litellm_internal_model_credentials") if isinstance(trusted_model_credentials, _MAPPING_PROXY_TYPE): - value = cast(Mapping[str, Any], trusted_model_credentials).get("allow_legacy_cloud_file_ids") + trusted_mapping: Final = as_str_mapping(trusted_model_credentials) + value = trusted_mapping.get("allow_legacy_cloud_file_ids") if trusted_mapping is not None else None if isinstance(value, bool): return value diff --git a/litellm/litellm_core_utils/core_helpers.py b/litellm/litellm_core_utils/core_helpers.py index 1d61ef8519a..00c6ce97e78 100644 --- a/litellm/litellm_core_utils/core_helpers.py +++ b/litellm/litellm_core_utils/core_helpers.py @@ -5,10 +5,11 @@ import logging import re from collections.abc import Collection, Iterable, Iterator, Mapping from types import MappingProxyType -from typing import TYPE_CHECKING, Any, Final, Literal, Protocol, cast, runtime_checkable +from typing import TYPE_CHECKING, Any, Final, Literal, Protocol, TypeVar, cast, runtime_checkable import httpx from pydantic import TypeAdapter, ValidationError +from typing_extensions import TypeIs # noqa: TID251 # narrows a duck-typed value to the Protocol its caller reads import litellm from litellm._logging import verbose_logger @@ -58,6 +59,13 @@ def as_str_mapping(value: object) -> Mapping[str, object] | None: return value if isinstance(value, Mapping) else None +def decoded_json_object(value: object) -> Mapping[str, object]: + mapping: Final = as_str_mapping(value) + if mapping is not None: + return mapping + raise AttributeError(f"{type(value).__name__!r} object has no attribute 'get'", name="get", obj=value) + + @runtime_checkable class _SupportsIter(Protocol): def __iter__(self) -> Iterator[object]: ... @@ -72,6 +80,24 @@ def attribute_or_none(source: object, name: str) -> object: return getattr(source, name, None) +_Shape: Final = TypeVar("_Shape") + + +def has_attributes( + value: object, + shape: type[_Shape], + *names: str, +) -> TypeIs[_Shape]: # guard-ok: hasattr sees what __getattr__ serves, which Protocol isinstance skips on 3.12+ + return all(hasattr(value, name) for name in names) + + +def require_attributes(value: object, shape: type[_Shape], *names: str) -> _Shape: + if has_attributes(value, shape, *names): + return value + missing: Final = next(name for name in names if not hasattr(value, name)) + raise AttributeError(f"'{type(value).__name__}' object has no attribute '{missing}'", name=missing, obj=value) + + def iter_items(value: object) -> Iterable[object]: if isinstance(value, _SupportsIter): return value @@ -634,11 +660,14 @@ def preserve_upstream_non_openai_attributes( for key in candidate_keys ) if all(value is None or isinstance(value, (str, int, float, bool)) for _, value in candidate_values): - for key, value in candidate_values: - setattr(model_response, key, value) + _assign_attributes(model_response, candidate_values) return - for key, value in original_chunk.model_dump(include=frozenset(candidate_keys)).items(): - setattr(model_response, key, value) + _assign_attributes(model_response, original_chunk.model_dump(include=frozenset(candidate_keys)).items()) + + +def _assign_attributes(target: object, values: Iterable[tuple[str, object]]) -> None: + for key, value in values: + setattr(target, key, value) def safe_deep_copy(data): @@ -764,6 +793,10 @@ def filter_exceptions_from_params(data: object, max_depth: int = 20) -> Any: Filtered data structure with Exception and callable objects removed, or None if the entire input was an Exception or callable """ + return _filter_exceptions_from_params(data, max_depth) + + +def _filter_exceptions_from_params(data: object, max_depth: int) -> object: if max_depth <= 0: return data @@ -785,7 +818,7 @@ def filter_exceptions_from_params(data: object, max_depth: int = 20) -> Any: if isinstance(v, Exception) or (callable(v) and not isinstance(v, type)): continue try: - filtered = filter_exceptions_from_params(v, max_depth - 1) + filtered = _filter_exceptions_from_params(v, max_depth - 1) if filtered is not None: result[k] = filtered except Exception: @@ -799,7 +832,7 @@ def filter_exceptions_from_params(data: object, max_depth: int = 20) -> Any: if isinstance(item, Exception) or (callable(item) and not isinstance(item, type)): continue try: - filtered = filter_exceptions_from_params(item, max_depth - 1) + filtered = _filter_exceptions_from_params(item, max_depth - 1) if filtered is not None: result_list.append(filtered) except Exception: @@ -895,6 +928,71 @@ class _CarriesHiddenParams(Protocol): def hidden_params(self, hidden_params: dict[str, object]) -> None: ... # mutable-ok: API requires mutation +_USAGE_BLOCK_ADAPTER: Final = TypeAdapter(Mapping[str, object]) + + +def _usage_field(usage: object, name: str) -> object: + if isinstance(usage, Mapping): + return _USAGE_BLOCK_ADAPTER.validate_python(usage).get(name) + return getattr(usage, name, None) + + +def _cost_number(value: object) -> float | None: + if isinstance(value, bool) or not isinstance(value, int | float): + return None + return float(value) + + +def _reported_cost_value(value: object) -> float | None: + """A reported cost is a number, or a breakdown whose total lives under ``total_cost``.""" + raw: Final[object] = value + if isinstance(value, Mapping): + return _cost_number(_usage_field(raw, "total_cost")) + return _cost_number(value) + + +def response_cost_in_hidden_params(response: _CarriesHiddenParams) -> float | None: + additional_headers: Final[object] = response.hidden_params.get("additional_headers") + if not isinstance(additional_headers, Mapping): + return None + return _cost_number(_USAGE_BLOCK_ADAPTER.validate_python(additional_headers).get(RESPONSE_COST_HEADER)) + + +def override_stamped_response_cost(response: _CarriesHiddenParams, cost: float) -> None: + """Replace the cost an earlier builder stamped so every reader of the hidden params agrees with the header.""" + set_response_cost_in_hidden_params(response, cost) + hidden_params: Final = response.hidden_params + hidden_params["response_cost"] = cost + + +def chunk_usage(chunk: object) -> object: + """Stream chunks reach the builders both as mappings and as ModelResponseStream objects.""" + if isinstance(chunk, Mapping): + return _USAGE_BLOCK_ADAPTER.validate_python(chunk).get("usage") + return getattr(chunk, "usage", None) + + +_MESSAGES_REPORTED_COST_PROVIDERS: Final = frozenset({"opencode_go"}) + + +def native_messages_reported_cost(usage: object, custom_llm_provider: object) -> float | None: + """Only a Messages upstream known to price its own responses is trusted, every other one keeps the price map.""" + if not isinstance(custom_llm_provider, str) or custom_llm_provider not in _MESSAGES_REPORTED_COST_PROVIDERS: + return None + return provider_reported_usage_cost(usage, custom_llm_provider) + + +def provider_reported_usage_cost(usage: object, custom_llm_provider: str | None) -> float | None: + """The request cost a provider states on its usage block, as a number or a breakdown with ``total_cost``. + + OpenCode Go reports the model's list price (peak hours and long-context tiers included) under + ``usage.opencode.list_cost``, while its ``usage.cost`` is what hit the prepaid balance, 0 inside the plan. + """ + if custom_llm_provider == "opencode_go": + return _reported_cost_value(_usage_field(_usage_field(usage, "opencode"), "list_cost")) + return _reported_cost_value(_usage_field(usage, "cost")) + + def set_response_cost_in_hidden_params(response: _CarriesHiddenParams, cost: float | None) -> None: """Record a provider-reported cost where the cost calculator looks before the price map.""" if cost is None: diff --git a/litellm/litellm_core_utils/cost_discount.py b/litellm/litellm_core_utils/cost_discount.py index a64ad0b20f7..bfcee7928fb 100644 --- a/litellm/litellm_core_utils/cost_discount.py +++ b/litellm/litellm_core_utils/cost_discount.py @@ -23,7 +23,7 @@ def parse_cost_discount_key(key: str) -> CostDiscountKey: def _literal_length(pattern: str) -> int: - return sum(1 for token in _GLOB_TOKEN.findall(pattern) if len(token) == 1 and token not in "*?") + return sum(1 for match in _GLOB_TOKEN.finditer(pattern) if len(match.group()) == 1 and match.group() not in "*?") def _model_names(model: str, provider_prefix: str) -> tuple[str, ...]: diff --git a/litellm/litellm_core_utils/default_encoding.py b/litellm/litellm_core_utils/default_encoding.py index c3b6a008411..970dd512a40 100644 --- a/litellm/litellm_core_utils/default_encoding.py +++ b/litellm/litellm_core_utils/default_encoding.py @@ -48,5 +48,5 @@ for attempt in range(_max_retries): # Last attempt, re-raise the exception raise # Exponential backoff with jitter to reduce collision probability - delay = _retry_delay * (2**attempt) + random.uniform(0, 0.1) + delay = _retry_delay * (2.0**attempt) + random.uniform(0, 0.1) time.sleep(delay) diff --git a/litellm/litellm_core_utils/deprecated_package.py b/litellm/litellm_core_utils/deprecated_package.py new file mode 100644 index 00000000000..f9915af4880 --- /dev/null +++ b/litellm/litellm_core_utils/deprecated_package.py @@ -0,0 +1,73 @@ +import importlib +import importlib.abc +import importlib.machinery +import importlib.util +import sys +import warnings +from collections.abc import Sequence +from dataclasses import dataclass +from functools import partial +from types import ModuleType +from typing import Final + + +@dataclass(frozen=True, slots=True) +class _AliasLoader(importlib.abc.Loader): + new_dotted: str + canonical_spec: importlib.machinery.ModuleSpec + old_dotted: str + + def create_module(self, spec: importlib.machinery.ModuleSpec) -> ModuleType: + return importlib.import_module(self.new_dotted) + + def exec_module(self, module: ModuleType) -> None: + module.__spec__ = self.canonical_spec # rebind-ok: [LIT011] restore import metadata overwritten by importlib + if self.canonical_spec.submodule_search_locations is not None: + _alias_attributes(self.old_dotted, self.new_dotted) + + +@dataclass(frozen=True, slots=True) +class _AliasFinder(importlib.abc.MetaPathFinder): + old_name: str + new_name: str + + def find_spec( + self, + fullname: str, + path: Sequence[str] | None = None, + target: ModuleType | None = None, + ) -> importlib.machinery.ModuleSpec | None: + if not fullname.startswith(f"{self.old_name}."): + return None + new_dotted: Final = f"{self.new_name}{fullname.removeprefix(self.old_name)}" + new_spec: Final = importlib.util.find_spec(new_dotted) + if new_spec is None: + return None + return importlib.util.spec_from_loader( + fullname, + _AliasLoader(new_dotted, new_spec, fullname), + is_package=new_spec.submodule_search_locations is not None, + ) + + +def _deprecated_attribute(old_name: str, new_name: str, name: str) -> ModuleType: + if importlib.util.find_spec(f"{new_name}.{name}") is None: + raise AttributeError(f"module {old_name!r} has no attribute {name!r}") + return importlib.import_module(f"{old_name}.{name}") + + +def _alias_attributes(old_name: str, new_name: str) -> None: + if "__getattr__" not in vars(sys.modules[old_name]): + sys.modules[old_name].__getattr__ = partial(_deprecated_attribute, old_name, new_name) + + +def alias_deprecated_package(old_name: str, new_package: ModuleType) -> None: + warnings.warn( + f"{old_name} is deprecated, import {new_package.__name__} instead", + DeprecationWarning, + stacklevel=3, + ) + finder: Final = _AliasFinder(old_name, new_package.__name__) + if finder not in sys.meta_path: + sys.meta_path.insert(0, finder) + _alias_attributes(old_name, new_package.__name__) diff --git a/litellm/litellm_core_utils/dot_notation_indexing.py b/litellm/litellm_core_utils/dot_notation_indexing.py index 1dac67ecbf6..818cf1b9695 100644 --- a/litellm/litellm_core_utils/dot_notation_indexing.py +++ b/litellm/litellm_core_utils/dot_notation_indexing.py @@ -181,7 +181,7 @@ def _delete_nested_value_custom( def delete_nested_value( - data: dict[str, Any], + data: Mapping[str, object], path: str, depth: int = 0, max_depth: int = 20, @@ -214,7 +214,7 @@ def delete_nested_value( """ import copy - result: Final = copy.deepcopy(data) + result: Final = copy.deepcopy(data if isinstance(data, dict) else dict(data)) try: # Parse path into segments diff --git a/litellm/litellm_core_utils/duration_parser.py b/litellm/litellm_core_utils/duration_parser.py index d52716951df..95bc77e3eba 100644 --- a/litellm/litellm_core_utils/duration_parser.py +++ b/litellm/litellm_core_utils/duration_parser.py @@ -22,7 +22,7 @@ _BUDGET_DURATION_WORD_ALIASES: Final[dict[str, str]] = { } -def _normalize_duration(duration: str) -> str: +def normalize_duration(duration: str) -> str: return _BUDGET_DURATION_WORD_ALIASES.get(duration.strip().lower(), duration) @@ -61,7 +61,7 @@ def duration_in_seconds(duration: str) -> int: Returns time in seconds till when budget needs to be reset """ - value, unit = _extract_from_regex(duration=_normalize_duration(duration)) + value, unit = _extract_from_regex(duration=normalize_duration(duration)) if unit == "s": return value @@ -89,7 +89,7 @@ def duration_in_seconds_from(start: datetime, duration: str) -> int: month of a different length needs its own start to know when it ends. Every other unit is a fixed length and ignores `start`. """ - value, unit = _extract_from_regex(duration=_normalize_duration(duration)) + value, unit = _extract_from_regex(duration=normalize_duration(duration)) if unit == "mo": return _months_in_seconds(start=start, months=value) return duration_in_seconds(duration) @@ -129,7 +129,7 @@ def get_next_standardized_reset_time( current_time, _ = _setup_timezone(current_time, timezone_str) # Parse duration - value, unit = _parse_duration(_normalize_duration(duration)) + value, unit = _parse_duration(normalize_duration(duration)) if value is None: verbose_logger.warning( "Unrecognized budget_duration %r; falling back to a next-midnight reset. " @@ -171,7 +171,7 @@ def get_budget_window_start(duration: str, reset_at: datetime) -> datetime: """Start of the budget period that ends at `reset_at`, under the same rules `get_next_standardized_reset_time` used to pick it: `30d` and `Nmo` span calendar months and a duration it does not recognize resets at the next midnight.""" - value, unit = _parse_duration(_normalize_duration(duration)) + value, unit = _parse_duration(normalize_duration(duration)) if value is None: return reset_at - timedelta(days=1) match unit: diff --git a/litellm/litellm_core_utils/exception_mapping_utils.py b/litellm/litellm_core_utils/exception_mapping_utils.py index e8da59cd33a..1c816b22ef1 100644 --- a/litellm/litellm_core_utils/exception_mapping_utils.py +++ b/litellm/litellm_core_utils/exception_mapping_utils.py @@ -16,7 +16,7 @@ from litellm.litellm_core_utils.bug_report import ( build_bug_report, should_report_bug, ) -from litellm.litellm_core_utils.core_helpers import as_str_mapping +from litellm.litellm_core_utils.core_helpers import as_str_mapping, attribute_or_none from litellm.litellm_core_utils.secret_redaction import redact_string as redact_secret_string from litellm.types.utils import LlmProviders @@ -169,7 +169,7 @@ def get_error_message(error_obj) -> str | None: return None if hasattr(error_obj, "body"): - _error_obj_body: Final = getattr(error_obj, "body") + _error_obj_body: Final = attribute_or_none(error_obj, "body") if isinstance(_error_obj_body, dict): # OpenAI-style: {"message": "...", "type": "...", ...} if _error_obj_body.get("message"): diff --git a/litellm/litellm_core_utils/get_litellm_params.py b/litellm/litellm_core_utils/get_litellm_params.py index 85557090ae9..ca8e2af18e6 100644 --- a/litellm/litellm_core_utils/get_litellm_params.py +++ b/litellm/litellm_core_utils/get_litellm_params.py @@ -76,6 +76,7 @@ OPTIONAL_KWARGS_KEYS: Final = ( "itpm", "otpm", "use_xai_oauth", + "chatgpt_auth_file", "github_copilot_auth_type", "github_copilot_host", "github_copilot_user_session", diff --git a/litellm/litellm_core_utils/get_llm_provider_logic.py b/litellm/litellm_core_utils/get_llm_provider_logic.py index 3130d49a5e2..19c1d5c414c 100644 --- a/litellm/litellm_core_utils/get_llm_provider_logic.py +++ b/litellm/litellm_core_utils/get_llm_provider_logic.py @@ -158,6 +158,14 @@ def declared_authenticating_provider(model: str | None, custom_llm_provider: str return declared if declared in PROVIDERS_THAT_AUTHENTICATE_ON_PROVIDER_INFO else None +def resolve_model_and_provider_for_metadata(model: str, custom_llm_provider: str | None = None) -> tuple[str, str]: + declared: Final = declared_authenticating_provider(model, custom_llm_provider) + if declared is not None: + return model.removeprefix(f"{declared}/"), declared + resolved_model, resolved_provider, _, _ = get_llm_provider(model=model, custom_llm_provider=custom_llm_provider) + return resolved_model, resolved_provider + + def inferred_provider(model: str | None) -> str | None: if not model: return None @@ -842,7 +850,9 @@ def _get_openai_compatible_provider_info( api_base, dynamic_api_key, custom_llm_provider, - ) = litellm.ChatGPTConfig().get_openai_compatible_provider_info(model, api_base, api_key, custom_llm_provider) + ) = litellm.ChatGPTConfig().get_openai_compatible_provider_info( + model, api_base, api_key, custom_llm_provider, litellm_params + ) elif custom_llm_provider == "novita": api_base = api_base or get_secret("NOVITA_API_BASE") or "https://api.novita.ai/v3/openai" dynamic_api_key = api_key or get_secret_str("NOVITA_API_KEY") @@ -902,6 +912,10 @@ def _get_openai_compatible_provider_info( api_base, dynamic_api_key, ) = litellm.MorphChatConfig().get_openai_compatible_provider_info(api_base, api_key) + elif custom_llm_provider == "opencode_go": + from litellm.llms.opencode.common_utils import go_api_base, go_api_key + + return model, custom_llm_provider, go_api_key(api_key), go_api_base(api_base, model) elif custom_llm_provider == "lambda_ai": ( api_base, diff --git a/litellm/litellm_core_utils/get_model_cost_map.py b/litellm/litellm_core_utils/get_model_cost_map.py index 1e2a511d439..7fc6eab6c60 100644 --- a/litellm/litellm_core_utils/get_model_cost_map.py +++ b/litellm/litellm_core_utils/get_model_cost_map.py @@ -43,6 +43,7 @@ from litellm.litellm_core_utils.offline_mode import is_offline_mode FALLBACK_GENERALIZATIONS_KEY: Final = "fallback_generalizations" _CATALOG_ADAPTER: Final = TypeAdapter(dict[str, dict[str, object]]) +_DECODED_JSON: Final = TypeAdapter(object) _BUNDLED_CATALOG_ADAPTER: Final = TypeAdapter(dict[str, object], config=ConfigDict(hide_input_in_errors=True)) _CLI_ENTRYPOINT_NAMES: Final = frozenset({"lite", "litellm-proxy"}) @@ -314,7 +315,7 @@ def _classify_fetch_error(error: httpx.HTTPError | httpx.InvalidURL, url: str) - def _classify_fetch_content(content: bytes, url: str, etag: str | None) -> _FetchAttemptOutcome: try: - parsed: Final[object] = json.loads(content) + parsed: Final = _DECODED_JSON.validate_python(json.loads(content)) except ValueError as e: return ModelCostMapReloadUnavailable(reason=f"invalid JSON from {url}: {e}") if not isinstance(parsed, dict): @@ -383,7 +384,8 @@ def _classify_fetch_response(response: httpx.Response, url: str) -> _FetchAttemp ) if response.is_error: return ModelCostMapReloadUnavailable(reason=f"HTTP {response.status_code} from {url}") - return _classify_fetch_content(response.content, url, response.headers.get("etag")) + etag_values: Final = response.headers.get_list("etag") + return _classify_fetch_content(response.content, url, ", ".join(etag_values) if etag_values else None) def _next_retry_wait( diff --git a/litellm/litellm_core_utils/get_provider_specific_headers.py b/litellm/litellm_core_utils/get_provider_specific_headers.py index bc325c3c702..62dfcb073e5 100644 --- a/litellm/litellm_core_utils/get_provider_specific_headers.py +++ b/litellm/litellm_core_utils/get_provider_specific_headers.py @@ -1,10 +1,23 @@ from collections.abc import Mapping, Sequence from typing import Final +from pydantic import TypeAdapter + from litellm.types.utils import ProviderSpecificHeader +_PROVIDER_HEADERS: Final[TypeAdapter[ProviderSpecificHeader | Sequence[ProviderSpecificHeader] | None]] = TypeAdapter( + ProviderSpecificHeader | Sequence[ProviderSpecificHeader] | None +) + class ProviderSpecificHeaderUtils: + @staticmethod + def forwarded_authorization(provider_specific_header: object, custom_llm_provider: str | None) -> str | None: + headers: Final = ProviderSpecificHeaderUtils.get_provider_specific_headers( + _PROVIDER_HEADERS.validate_python(provider_specific_header), custom_llm_provider + ) + return next((value for key, value in headers.items() if key.lower() == "authorization"), None) + @staticmethod def get_provider_specific_headers( provider_specific_header: ProviderSpecificHeader | Sequence[ProviderSpecificHeader] | None, diff --git a/litellm/litellm_core_utils/hidden_params.py b/litellm/litellm_core_utils/hidden_params.py index f8d44d44cdc..a74337d2549 100644 --- a/litellm/litellm_core_utils/hidden_params.py +++ b/litellm/litellm_core_utils/hidden_params.py @@ -1,4 +1,5 @@ from collections.abc import Iterator, Mapping, MutableMapping +from types import MappingProxyType from typing import Final, Protocol, cast from pydantic import BaseModel @@ -52,7 +53,7 @@ class HiddenParamsModelView(MutableMapping[str, object]): def stored_attribute(obj: object, name: str) -> object: if not isinstance(obj, BaseModel): return getattr(obj, name, None) - values: Final[Mapping[str, object]] = vars(obj) + values: Final[Mapping[str, object]] = MappingProxyType[str, object](vars(obj)) if name in values: return values[name] extras: Final[Mapping[str, object]] = obj.__pydantic_extra__ or {} diff --git a/litellm/litellm_core_utils/initialize_dynamic_callback_params.py b/litellm/litellm_core_utils/initialize_dynamic_callback_params.py index 5a533054f0b..c3769686e45 100644 --- a/litellm/litellm_core_utils/initialize_dynamic_callback_params.py +++ b/litellm/litellm_core_utils/initialize_dynamic_callback_params.py @@ -28,7 +28,7 @@ def inherit_message_logging_privacy(disabled: bool) -> Generator[None]: def iter_client_callback_metadata_dicts( - kwargs: dict[str, Any], + kwargs: Mapping[str, object], ) -> Iterator[tuple[str, dict[str, Any]]]: litellm_params: Final = kwargs.get("litellm_params") if isinstance(litellm_params, dict): diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index d75d35e4531..48e8a44b9a4 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -77,6 +77,8 @@ from litellm.litellm_core_utils.classifier_logging import ( from litellm.litellm_core_utils.core_helpers import ( get_provider_response_headers_from_hidden_params, is_expected_client_error, + native_messages_reported_cost, + provider_reported_usage_cost, proxy_stamped_kubernetes_pod_routing, proxy_stamped_used_client_oauth_token, reconstruct_model_name, @@ -95,8 +97,13 @@ from litellm.litellm_core_utils.internal_call_metadata import ( is_unbilled_non_inference_call, ) from litellm.litellm_core_utils.llm_cost_calc.guardrail_cost import ( + bedrock_guardrail_trace, cost_breakdown_with_guardrail, guardrail_information_cost, + is_str_keyed_dict, + native_bedrock_guardrail_information, + object_mapping, + with_guardrail_entry, ) from litellm.litellm_core_utils.llm_cost_calc.tool_call_cost_tracking import ( StandardBuiltInToolCostTracking, @@ -161,6 +168,7 @@ from litellm.types.utils import ( CachingDetails, CallTypes, CostBreakdown, + CostPerToken, CustomPricingLiteLLMParams, DynamicPromptManagementParamLiteral, EmbeddingResponse, @@ -555,6 +563,7 @@ def _resolve_mantle_region_for_cost( _PER_CALL_LITELLM_PARAM_DICTS: Final = frozenset({"metadata", "litellm_metadata"}) _LITELLM_PARAMS: Final = TypeAdapter(dict[str, object]) +_REDACTED_RESULT: Final = TypeAdapter(object) def _provider_response_id(source: object) -> str | None: @@ -621,6 +630,8 @@ class Logging(LiteLLMLoggingBaseClass): prometheusLogger, \ slack_app custom_pricing: bool = False + custom_cost_per_token: CostPerToken | None = None + custom_cost_per_second: float | None = None replaced_global_callback_keys: frozenset[str] = frozenset() stream_options = None litellm_request_debug: bool = False @@ -1168,7 +1179,7 @@ class Logging(LiteLLMLoggingBaseClass): automatically extracts metadata/litellm_metadata from kwargs, so callers don't need to manually plumb them into litellm_params. """ - base_litellm_params: Final[dict[str, Any]] = {} + base_litellm_params: Final[dict[str, object]] = {} if isinstance(kwargs.get("metadata"), dict): base_litellm_params["metadata"] = kwargs["metadata"].copy() @@ -1185,10 +1196,11 @@ class Logging(LiteLLMLoggingBaseClass): lp_metadata: Final = litellm_params.pop("metadata", None) base_litellm_params.update(litellm_params) if lp_metadata and isinstance(lp_metadata, dict): - base_litellm_params.setdefault("metadata", {}) - for k, v in lp_metadata.items(): - if k not in base_litellm_params["metadata"]: - base_litellm_params["metadata"][k] = v + merged_metadata: Final = base_litellm_params.setdefault("metadata", {}) + if isinstance(merged_metadata, dict): + for k, v in lp_metadata.items(): + if k not in merged_metadata: + merged_metadata[k] = v self.update_environment_variables( litellm_params=base_litellm_params, @@ -1790,7 +1802,7 @@ class Logging(LiteLLMLoggingBaseClass): verbose_logger.exception( "LiteLLM.LoggingError: [Non-Blocking] Exception occurred while logging %s", e ) - original_response = redact_message_input_output_from_logging( + redact_message_input_output_from_logging( model_call_details=(self.model_call_details if hasattr(self, "model_call_details") else {}), result=original_response, ) @@ -2020,10 +2032,9 @@ class Logging(LiteLLMLoggingBaseClass): self.model_call_details.pop("response_cost_failure_debug_information", None) - if cache_hit is None: - cache_hit = self.model_call_details.get("cache_hit", False) + resolved_cache_hit: Final = self.model_call_details.get("cache_hit", False) if cache_hit is None else cache_hit - if cache_hit is True: + if resolved_cache_hit is True: return 0.0 if is_unbilled_non_inference_call( @@ -2075,7 +2086,7 @@ class Logging(LiteLLMLoggingBaseClass): model_value: Final = litellm_model_name or self.model cost_cache_hit_value: Final = ( - self.model_call_details.get("cache_hit", False) if cache_hit is None else cache_hit + self.model_call_details.get("cache_hit", False) if resolved_cache_hit is None else resolved_cache_hit ) cost_cache_hit: Final[bool | None] = cast( # cast-ok: callback metadata is caller-provided bool | None, cost_cache_hit_value @@ -2096,6 +2107,8 @@ class Logging(LiteLLMLoggingBaseClass): "call_type": self.call_type, "optional_params": self.optional_params, "custom_pricing": custom_pricing, + "custom_cost_per_token": self.custom_cost_per_token if custom_pricing else None, + "custom_cost_per_second": self.custom_cost_per_second if custom_pricing else None, "prompt": prompt, "standard_built_in_tools_params": self.standard_built_in_tools_params, "router_model_id": router_model_id, @@ -2507,8 +2520,10 @@ class Logging(LiteLLMLoggingBaseClass): def carry_failed_attempt_usage(self) -> None: """Move what a failed earlier attempt stashed off the retry sharing this logging object, so the retry logs its own usage while the request's failure log still bills every attempt.""" - usage: Final = self.model_call_details.pop("combined_usage_object", None) - response_cost: Final = self.model_call_details.pop("response_cost", None) + usage: Final = self._model_call_details_view.get("combined_usage_object") + response_cost: Final = self._model_call_details_view.get("response_cost") + self.model_call_details.pop("combined_usage_object", None) + self.model_call_details.pop("response_cost", None) if isinstance(usage, Usage): self.model_call_details["current_attempt_api_call_start_time"] = None self.model_call_details["failed_attempts_usage"] = ( @@ -2715,6 +2730,31 @@ class Logging(LiteLLMLoggingBaseClass): return self.model_call_details["response_headers"] = headers + def record_native_bedrock_guardrail(self, result: object) -> None: + """Bill the guardrail trace a Bedrock response carries when the deployment's ``guardrailConfig`` ran it, by + recording it as guardrail information on this call, the same entry the proxy-side Bedrock guardrail writes. + A cache hit carries the original response's trace but made no Bedrock call, so it bills nothing.""" + trace: Final = bedrock_guardrail_trace(result) + if trace is None or served_from_cache(result) or self.model_call_details.get("cache_hit") is True: + return + optional_params: Final = object_mapping(getattr(self, "optional_params", None)) or {} + guardrail_config: Final = object_mapping(optional_params.get("guardrailConfig")) or {} + identifier: Final = guardrail_config.get("guardrailIdentifier") + litellm_params_in: Final = object_mapping(getattr(self, "litellm_params", None)) or {} + region: Final = optional_params.get("aws_region_name") or litellm_params_in.get("aws_region_name") + entry: Final = native_bedrock_guardrail_information( + trace, + aws_region_name=region if isinstance(region, str) else None, + guardrail_identifier=identifier if isinstance(identifier, str) else None, + ) + litellm_params: Final[object] = self.model_call_details.get("litellm_params") + if entry is None or not is_str_keyed_dict(litellm_params): + return + metadata: Final[object] = litellm_params.get("metadata") + bucket: Final = metadata if is_str_keyed_dict(metadata) else {} + litellm_params["metadata"] = bucket + with_guardrail_entry(bucket, entry) + def _merge_hidden_params_from_response_into_metadata(self, logging_result: object) -> None: """ Copy response._hidden_params into litellm_params.metadata['hidden_params']. @@ -3297,7 +3337,7 @@ class Logging(LiteLLMLoggingBaseClass): if callback_logging_payload is not None or shared_logging_payload is None else shared_logging_payload.copy() ) - call_details: dict[str, Any] # mutable-ok: legacy loggers take a plain dict + call_details: dict[str, object] # mutable-ok: legacy loggers take a plain dict call_details = ( # rebind-ok: logging hooks may return a new dict self.model_call_details if not for_async_request @@ -3318,9 +3358,11 @@ class Logging(LiteLLMLoggingBaseClass): ) ## REDACT MESSAGES ## - result = redact_message_input_output_from_logging( - model_call_details=call_details, - result=result, + result = _REDACTED_RESULT.validate_python( + redact_message_input_output_from_logging( + model_call_details=call_details, + result=result, + ) ) ## LOGGING HOOK ## hook_callbacks: Final = tuple(dict.fromkeys((*callbacks, *delivery_callbacks))) @@ -3586,7 +3628,7 @@ class Logging(LiteLLMLoggingBaseClass): print_verbose("S3Logger Logger: Got Stream Event - Completed Stream Response") s3Logger.log_event( kwargs=call_details, - response_obj=call_details["complete_streaming_response"], + response_obj=call_details_view["complete_streaming_response"], start_time=start_time, end_time=end_time, print_verbose=print_verbose, @@ -3909,9 +3951,11 @@ class Logging(LiteLLMLoggingBaseClass): self._get_completed_success_callbacks(asynchronous=True) if not self.stream else callbacks ) - result = redact_message_input_output_from_logging( - model_call_details=(self.model_call_details if hasattr(self, "model_call_details") else {}), - result=result, + result = _REDACTED_RESULT.validate_python( + redact_message_input_output_from_logging( + model_call_details=(self.model_call_details if hasattr(self, "model_call_details") else {}), + result=result, + ) ) ## LOGGING HOOK ## @@ -4256,9 +4300,11 @@ class Logging(LiteLLMLoggingBaseClass): result: object = None # result sent to all loggers, init this to None incase it's not created - result = redact_message_input_output_from_logging( - model_call_details=(self.model_call_details if hasattr(self, "model_call_details") else {}), - result=result, + result = _REDACTED_RESULT.validate_python( + redact_message_input_output_from_logging( + model_call_details=(self.model_call_details if hasattr(self, "model_call_details") else {}), + result=result, + ) ) self.mark_logging_complete(event_type="sync_failure") for callback in callbacks: @@ -4742,7 +4788,12 @@ class Logging(LiteLLMLoggingBaseClass): ): ## return unified Usage object if isinstance(result.response.usage, ResponseAPIUsage): - set_response_cost_in_hidden_params(result.response, result.response.usage.cost) + set_response_cost_in_hidden_params( + result.response, + provider_reported_usage_cost( + result.response.usage, self.model_call_details.get("custom_llm_provider") + ), + ) transformed_usage: Final = ResponseAPILoggingUtils.transform_response_api_usage_to_chat_usage( result.response.usage ) @@ -4808,8 +4859,11 @@ class Logging(LiteLLMLoggingBaseClass): bridge is replaced by the ModelResponse its spend row is built from, anything else is priced as is.""" served: Final[object] = result - if self.bridged_model_response is None or not isinstance(result, dict): - return result + call_type: Final[object] = getattr(self, "call_type", None) + if not isinstance(result, dict): + return served + if self.bridged_model_response is None and call_type != CallTypes.anthropic_messages.value: + return served return self._anthropic_messages_logged_response(result=served) def _anthropic_messages_logged_response(self, result: object) -> ModelResponse: @@ -4852,7 +4906,13 @@ class Logging(LiteLLMLoggingBaseClass): if isinstance(result, ResponsesAPIResponse): return self._translate_responses_api_response_to_model_response(result) - provider_response_id: Final = _provider_response_id(result) + raw_body: Final[object] = result + served_body: Final = _LITELLM_PARAMS.validate_python(raw_body) if isinstance(result, dict) else None + reported_cost: Final = native_messages_reported_cost( + served_body.get("usage") if served_body is not None else None, + self.model_call_details.get("custom_llm_provider"), + ) + provider_response_id: Final = _provider_response_id(raw_body) bridged: Final = self.bridged_model_response if bridged is not None and isinstance(result, dict): return bridged if provider_response_id is None else bridged.model_copy(update={"id": provider_response_id}) @@ -4877,7 +4937,7 @@ class Logging(LiteLLMLoggingBaseClass): else: from litellm.types.llms.anthropic import AnthropicResponse - pydantic_result: Final = AnthropicResponse.model_validate(result) + pydantic_result: Final = AnthropicResponse.model_validate({"stop_sequence": None, **(served_body or {})}) import httpx result = litellm.AnthropicConfig().transform_parsed_response( @@ -4890,6 +4950,7 @@ class Logging(LiteLLMLoggingBaseClass): json_mode=None, speed=self.optional_params.get("speed") if self.optional_params else None, ) + set_response_cost_in_hidden_params(result, reported_cost) return result def _translate_responses_api_response_to_model_response(self, result: ResponsesAPIResponse) -> ModelResponse: @@ -4947,7 +5008,7 @@ class Logging(LiteLLMLoggingBaseClass): """ import httpx - httpx_response: Final = self.model_call_details.get("httpx_response", None) + httpx_response: Final[Response | None] = self.model_call_details.get("httpx_response", None) if httpx_response is None: raise ValueError("Google GenAI Generate Content: httpx_response is None") dict_result: Final = httpx_response.json() @@ -4977,7 +5038,7 @@ class Logging(LiteLLMLoggingBaseClass): The response object with usage added if available """ # Get usage from model_call_details (set by asend_message) - usage: Final = self.model_call_details.get("usage") + usage: Final[Usage | None] = self.model_call_details.get("usage") if usage is None: return result @@ -5810,7 +5871,9 @@ def build_custom_logger_compatible_class( return callback # Get global BitBucket config - bitbucket_config: Final = getattr(litellm, "global_bitbucket_config", None) + bitbucket_config: Final = ( + litellm.global_bitbucket_config if hasattr(litellm, "global_bitbucket_config") else None + ) if bitbucket_config is None: raise ValueError("BitBucket configuration not found. Please set litellm.global_bitbucket_config first.") @@ -7078,12 +7141,12 @@ class StandardLoggingPayloadSetup: request_headers: Final = cast( # cast-ok: request headers are untyped framework data dict[str, str], headers ) - - header_tags: Final = [] - for header_name in extra_headers: - header_value = request_headers.get(header_name) - if header_value: - header_tags.append(f"{header_name}: {header_value}") + lowercase_request_headers: Final = {str(name).lower(): value for name, value in request_headers.items()} + header_tags: Final = [ + f"{header_name}: {header_value}" + for header_name in extra_headers + if (header_value := lowercase_request_headers.get(header_name.lower())) + ] return header_tags if header_tags else None @@ -7098,19 +7161,17 @@ class StandardLoggingPayloadSetup: litellm_metadata: Final = cast( # cast-ok: request metadata is caller-provided Mapping[str, object], litellm_params.get("litellm_metadata") or {} ) - if metadata.get("tags", []): - request_tags = cast(list[str], metadata.get("tags", [])).copy() # cast-ok: tags are caller-provided - elif litellm_metadata.get("tags", []): - request_tags = cast(list[str], litellm_metadata.get("tags", [])).copy() # cast-ok: tags are caller-provided - else: - request_tags = [] + request_tags: Final = next( + ( + cast(list[str], tags) # cast-ok: tags are caller-provided + for tags in (metadata.get("tags"), litellm_metadata.get("tags")) + if isinstance(tags, list) and tags + ), + (), + ) user_agent_tags: Final = StandardLoggingPayloadSetup._get_user_agent_tags(proxy_server_request) additional_header_tags: Final = StandardLoggingPayloadSetup._get_extra_header_tags(proxy_server_request) - if user_agent_tags is not None: - request_tags.extend(user_agent_tags) - if additional_header_tags is not None: - request_tags.extend(additional_header_tags) - return request_tags + return [*request_tags, *(user_agent_tags or ()), *(additional_header_tags or ())] _get_request_tags = get_request_tags diff --git a/litellm/litellm_core_utils/llm_cost_calc/guardrail_cost.py b/litellm/litellm_core_utils/llm_cost_calc/guardrail_cost.py index 61ec2fc39c1..e4ad36f50bc 100644 --- a/litellm/litellm_core_utils/llm_cost_calc/guardrail_cost.py +++ b/litellm/litellm_core_utils/llm_cost_calc/guardrail_cost.py @@ -1,15 +1,24 @@ import math -from collections.abc import Mapping +from collections.abc import Iterator, Mapping, Sequence +from functools import partial +from itertools import chain from typing import Annotated, Final -from pydantic import ConfigDict, Field, TypeAdapter, ValidationError +from pydantic import BaseModel, ConfigDict, Field, JsonValue, TypeAdapter, ValidationError +from typing_extensions import TypeIs # noqa: TID251 # TypeIs reaches typing only on 3.13 import litellm from litellm._logging import verbose_logger +from litellm.litellm_core_utils.core_helpers import ( + redact_nested_match_and_regex_keys, # pyright: ignore[reportUnknownVariableType] # signature uses bare dict +) +from litellm.types.guardrails import GuardrailEventHooks from litellm.types.llms.base import LiteLLMBaseModel -from litellm.types.utils import CostBreakdown +from litellm.types.utils import CostBreakdown, GuardrailStatus, StandardLoggingGuardrailInformation BEDROCK_GUARDRAIL_PRICING_KEY: Final = "bedrock/guardrails" +BEDROCK_TRACE_FIELDS: Final = ("trace", "amazon-bedrock-trace") +_INTERVENING_ACTIONS: Final = frozenset({"BLOCKED", "ANONYMIZED"}) class GuardrailPricing(LiteLLMBaseModel): @@ -96,6 +105,161 @@ def bedrock_guardrail_cost(usage_units: Mapping[str, int], aws_region_name: str return guardrail_cost_total(bedrock_guardrail_cost_by_unit(usage_units, aws_region_name)) +_OBJECT_MAPPING: Final = TypeAdapter(Mapping[str, object]) +_OBJECT_ITEMS: Final = TypeAdapter(tuple[object, ...]) + + +def object_mapping(value: object) -> Mapping[str, object] | None: + """``value`` as a str-keyed mapping, None for anything else. Vendor JSON arrives untyped, so this is the one place + that turns it into something the rest of the module can read without guessing.""" + try: + return _OBJECT_MAPPING.validate_python(value) + except ValidationError: + return None + + +def object_items(value: object) -> tuple[object, ...]: + if isinstance(value, (str, bytes, Mapping)): + return () + try: + return _OBJECT_ITEMS.validate_python(value) + except ValidationError: + return () + + +def is_str_keyed_dict( + value: object, +) -> TypeIs[dict[str, object]]: # guard-ok: JSON object keys are str # mutable-ok: the caller edits this dict in place + return isinstance(value, dict) + + +def _trace_field(response: object, field: str) -> Mapping[str, object] | None: + source: Final = object_mapping(response) + trace: Final = object_mapping(source.get(field) if source is not None else getattr(response, field, None)) + if trace is None or object_mapping(trace.get("guardrail")) is None: + return None + return trace + + +def bedrock_guardrail_trace(response: object) -> Mapping[str, object] | None: + """The guardrail trace a Bedrock response carries: Converse puts it under ``trace``, Invoke under + ``amazon-bedrock-trace``. Returned as is, or None when the response has no guardrail section.""" + traces: Final = map(partial(_trace_field, response), BEDROCK_TRACE_FIELDS) + return next((trace for trace in traces if trace is not None), None) + + +class _Assessment(BaseModel): + model_config = ConfigDict(frozen=True, extra="allow") + invocation_metrics: Mapping[str, JsonValue] = Field(default_factory=dict, alias="invocationMetrics") + + @property + def billable_usage(self) -> Mapping[str, int]: + usage: Final = self.invocation_metrics.get("usage") + if not isinstance(usage, dict): + return {} + return { + counter: units + for counter, units in usage.items() + if counter.endswith("Units") and isinstance(units, int) and not isinstance(units, bool) + } + + +class _GuardrailTrace(BaseModel): + """Both trace shapes: Converse ``inputAssessment`` {id: a} and ``outputAssessments`` {id: [a, ...]}, Invoke + ``input`` {id: a} and ``outputs`` [{id: a}, ...].""" + + model_config = ConfigDict(frozen=True, extra="allow") + input_assessment: Mapping[str, _Assessment] = Field(default_factory=dict, alias="inputAssessment") + input: Mapping[str, _Assessment] = Field(default_factory=dict) + output_assessments: Mapping[str, tuple[_Assessment, ...]] = Field(default_factory=dict, alias="outputAssessments") + outputs: tuple[Mapping[str, _Assessment], ...] = () + + @property + def assessments(self) -> tuple[tuple[str, _Assessment], ...]: + listed: Final = ( + (gid, a) for gid, items in self.output_assessments.items() for a in items + ) # comprehension-ok: id then its list + return ( + *self.input_assessment.items(), + *self.input.items(), + *listed, + *chain.from_iterable(by_id.items() for by_id in self.outputs), + ) + + +_JSON_OBJECT: Final = TypeAdapter(dict[str, JsonValue]) + + +def _summed_usage(usages: Sequence[Mapping[str, int]]) -> Mapping[str, int]: + counters: Final = tuple(dict.fromkeys(chain.from_iterable(usages))) + return {counter: sum(usage.get(counter, 0) for usage in usages) for counter in counters} + + +def _actions(node: JsonValue) -> Iterator[str]: + if isinstance(node, list): + yield from chain.from_iterable(map(_actions, node)) + return + if not isinstance(node, dict): + return + action: Final = node.get("action") + if isinstance(action, str): + yield action + yield from chain.from_iterable(map(_actions, node.values())) + + +def native_bedrock_guardrail_information( + trace: Mapping[str, object], aws_region_name: str | None, guardrail_identifier: str | None +) -> StandardLoggingGuardrailInformation | None: + """The guardrail entry for a trace Bedrock returned because the deployment's ``guardrailConfig`` ran with + ``trace: enabled``: every assessment's ``invocationMetrics.usage`` summed and priced like the proxy-side Bedrock + guardrail. None when the trace carries no usage, which is what ``trace: disabled`` leaves.""" + try: + guardrail: Final = _JSON_OBJECT.validate_python(trace.get("guardrail")) + pairs: Final = _GuardrailTrace.model_validate(guardrail).assessments + except ValidationError: + return None + usage: Final = _summed_usage(tuple(assessment.billable_usage for _, assessment in pairs)) + if not usage: + return None + cost_by_unit: Final = bedrock_guardrail_cost_by_unit(usage, aws_region_name) + name: Final = guardrail_identifier or pairs[0][0] + status: Final[GuardrailStatus] = ( + "guardrail_intervened" if any(action in _INTERVENING_ACTIONS for action in _actions(guardrail)) else "success" + ) + priced: Final[StandardLoggingGuardrailInformation] = ( + {"guardrail_cost_by_unit": cost_by_unit} if cost_by_unit is not None else {} + ) + return { + "guardrail_name": name, + "guardrail_id": name, + "guardrail_provider": "bedrock", + "guardrail_mode": GuardrailEventHooks.during_call, + "guardrail_response": redact_nested_match_and_regex_keys(guardrail), + "guardrail_status": status, + "guardrail_usage": usage, + "guardrail_cost": guardrail_cost_total(cost_by_unit), + **priced, + } + + +def guardrail_entries(raw: object) -> tuple[object, ...]: + """The entries under ``standard_logging_guardrail_information``, which older writers stored as one dict.""" + single: Final = object_mapping(raw) + return (single,) if single is not None else object_items(raw) + + +def with_guardrail_entry( + metadata: dict[str, object], # mutable-ok: the proxy's own request metadata, read later for headers and spend + entry: StandardLoggingGuardrailInformation, +) -> None: + """Append ``entry`` to the metadata's ``standard_logging_guardrail_information`` once, so the same trace recorded + from the response headers path and again from the success handler bills a single time.""" + existing: Final = guardrail_entries(metadata.get("standard_logging_guardrail_information")) + if entry in existing: + return + metadata["standard_logging_guardrail_information"] = [*existing, entry] # rebind-ok: appending here is the job + + AZURE_PROMPT_SHIELD_TEXT_RECORD_UNIT: Final = "text_records" diff --git a/litellm/litellm_core_utils/llm_cost_calc/tiered_pricing.py b/litellm/litellm_core_utils/llm_cost_calc/tiered_pricing.py index 9bcc2b1743c..3040e36ec5f 100644 --- a/litellm/litellm_core_utils/llm_cost_calc/tiered_pricing.py +++ b/litellm/litellm_core_utils/llm_cost_calc/tiered_pricing.py @@ -5,30 +5,42 @@ Shared by provider cost calculators (e.g. Dashscope) and the proxy budget reservation logic so neither has to depend on the other. """ -from typing import Final +from collections.abc import Mapping, Sequence +from typing import Final, SupportsFloat + +from pydantic import TypeAdapter, ValidationError + +_TIER_RANGE: Final = TypeAdapter(tuple[float, float]) -def _coerce_cost_per_token(value: float | str | None) -> float: +def _coerce_cost_per_token(value: object) -> float: """ Coerce a per-token cost into a float. Model cost values loaded from YAML config may arrive as strings (e.g. scientific notation like "4e-07"), which would break arithmetic. """ - if value is None: - return 0.0 if isinstance(value, str): try: return float(value) except ValueError: return 0.0 - return float(value) + if isinstance(value, SupportsFloat): + return float(value) + return 0.0 + + +def _tier_range(tier: Mapping[str, object]) -> tuple[float, float] | None: + try: + return _TIER_RANGE.validate_python(tier.get("range")) + except ValidationError: + return None def select_tier_for_input( - tiered_pricing: list[dict], + tiered_pricing: Sequence[Mapping[str, object]], input_tokens: int, -) -> dict | None: +) -> Mapping[str, object] | None: """ Select the pricing tier for a request based on its total input token count. @@ -44,19 +56,21 @@ def select_tier_for_input( if not tiered_pricing or input_tokens <= 0: return None - sorted_tiers: Final = sorted(tiered_pricing, key=lambda t: t.get("range", [0, 0])[0]) - valid_tiers: Final = [tier for tier in sorted_tiers if len(tier.get("range", [])) == 2] - if not valid_tiers: + ranged_tiers: Final = sorted( + ((bounds, tier) for tier in tiered_pricing if (bounds := _tier_range(tier)) is not None), + key=lambda ranged: ranged[0][0], + ) + if not ranged_tiers: return None - matching: Final = [tier for tier in valid_tiers if tier["range"][0] < input_tokens <= tier["range"][1]] + matching: Final = tuple(tier for (start, end), tier in ranged_tiers if start < input_tokens <= end) if matching: return matching[0] - return valid_tiers[-1] + return ranged_tiers[-1][1] def tier_rate( - tier: dict, + tier: Mapping[str, object], cost_key: str, fallback_cost_key: str | None = None, ) -> float: @@ -68,4 +82,6 @@ def tier_rate( primary: Final = tier.get(cost_key) if primary is not None: return _coerce_cost_per_token(primary) + if fallback_cost_key is None: + return 0.0 return _coerce_cost_per_token(tier.get(fallback_cost_key, 0)) diff --git a/litellm/litellm_core_utils/llm_cost_calc/tool_call_cost_tracking.py b/litellm/litellm_core_utils/llm_cost_calc/tool_call_cost_tracking.py index 04510c20db0..045869e4547 100644 --- a/litellm/litellm_core_utils/llm_cost_calc/tool_call_cost_tracking.py +++ b/litellm/litellm_core_utils/llm_cost_calc/tool_call_cost_tracking.py @@ -450,7 +450,7 @@ class StandardBuiltInToolCostTracking: def _get_code_interpreter_cost( model_info: ModelInfo | None, custom_llm_provider: str | None, - standard_built_in_tools_params: StandardBuiltInToolsParams, + standard_built_in_tools_params: Mapping[str, object], ) -> float: """Calculate code interpreter cost.""" code_interpreter_sessions: Final = standard_built_in_tools_params.get("code_interpreter_sessions", None) diff --git a/litellm/litellm_core_utils/llm_cost_calc/utils.py b/litellm/litellm_core_utils/llm_cost_calc/utils.py index a874459798d..3b49f239afe 100644 --- a/litellm/litellm_core_utils/llm_cost_calc/utils.py +++ b/litellm/litellm_core_utils/llm_cost_calc/utils.py @@ -3,7 +3,7 @@ import re from collections.abc import Mapping, Sequence -from dataclasses import dataclass +from dataclasses import dataclass, field, replace from datetime import datetime, timezone, tzinfo from types import MappingProxyType from typing import Final, Literal, TypedDict, cast @@ -52,6 +52,22 @@ _VALID_DATA_RESIDENCIES: Final = frozenset(r.value for r in DataResidency) _DEPLOYMENT_PRICING_KEYS: Final[frozenset[str]] = frozenset(CustomPricingLiteLLMParams.model_fields) +_BASE_CACHE_WRITE_RATE_KEY: Final = "cache_creation_input_token_cost" + +_CACHE_WRITE_RATE_KEYS: Final[Mapping[str, str]] = MappingProxyType( + { + "5m": _BASE_CACHE_WRITE_RATE_KEY, + "30m": _BASE_CACHE_WRITE_RATE_KEY, + "1hr": "cache_creation_input_token_cost_above_1hr", + "12hr": "cache_creation_input_token_cost_above_12hr", + } +) + +_TTL_PRICED_CACHE_WRITE_RATE_KEYS: Final[Mapping[str, str]] = MappingProxyType( + {ttl: key for ttl, key in _CACHE_WRITE_RATE_KEYS.items() if key != _BASE_CACHE_WRITE_RATE_KEY} +) + + _IMAGE_TOKEN_RATE_KEYS: Final[tuple[str, ...]] = ( "input_cost_per_token", "output_cost_per_token", @@ -88,7 +104,8 @@ _BATCH_RATE_PREFIXES: Final = ( "cache_read_input_token_cost", "cache_creation_input_token_cost", ) -_BATCH_TIER_KEY: Final = re.compile(rf"^({'|'.join(_BATCH_RATE_PREFIXES)})_above_(\d+k?)_tokens{_BATCH_KEY_SUFFIX}$") +_BATCH_TIER_PREFIXES: Final = (*_BATCH_RATE_PREFIXES, *_TTL_PRICED_CACHE_WRITE_RATE_KEYS.values()) +_BATCH_TIER_KEY: Final = re.compile(rf"^({'|'.join(_BATCH_TIER_PREFIXES)})_above_(\d+k?)_tokens{_BATCH_KEY_SUFFIX}$") _NON_STANDARD_THRESHOLD_SUFFIXES: Final = (*_SERVICE_TIER_SUFFIXES, _BATCH_KEY_SUFFIX) @@ -298,6 +315,7 @@ class BatchCostRates: output: float | None cache_read: float | None cache_creation: float | None + cache_creation_rates_by_ttl: Mapping[str, float] = field(default_factory=lambda: MappingProxyType({})) def _batch_rate(model_info: ModelInfo, key: str) -> float | None: @@ -353,10 +371,31 @@ def get_batch_cost_rates(model_info: ModelInfo, usage: Usage, custom_llm_provide output=_batch_rate_for_prefix(model_info, "output_cost_per_token", usage, inclusive), cache_read=_batch_rate_for_prefix(model_info, "cache_read_input_token_cost", usage, inclusive), cache_creation=_batch_rate_for_prefix(model_info, "cache_creation_input_token_cost", usage, inclusive), + cache_creation_rates_by_ttl=MappingProxyType( + { + ttl: rate + for ttl, key in _TTL_PRICED_CACHE_WRITE_RATE_KEYS.items() + if (rate := _batch_rate_for_prefix(model_info, key, usage, inclusive)) is not None + } + ), ) -def _select_priced_tier(model_info: ModelInfo, usage: Usage) -> dict[str, object] | None: +@dataclass(frozen=True, slots=True) +class TokenRates: + input_rate: float + output_rate: float + cache_read_rate: float + cache_creation_rate: float + reasoning_rate: float | None + cache_creation_rates_by_ttl: Mapping[str, float] = field(default_factory=lambda: MappingProxyType({})) + + @property + def billed_reasoning_rate(self) -> float: + return self.output_rate if self.reasoning_rate is None else self.reasoning_rate + + +def _select_priced_tier(model_info: ModelInfo, usage: Usage) -> Mapping[str, object] | None: tiered_pricing: Final = model_info.get("tiered_pricing") if not isinstance(tiered_pricing, list) or not tiered_pricing: return None @@ -376,7 +415,7 @@ def _get_tiered_reasoning_rate(model_info: ModelInfo, usage: Usage) -> float | N return tier_rate(tier, "output_cost_per_reasoning_token", "output_cost_per_token") -def _get_tiered_base_costs(model_info: ModelInfo, usage: Usage) -> tuple[float, float, float, float, float] | None: +def _get_tiered_base_costs(model_info: ModelInfo, usage: Usage) -> tuple[TokenRates, Mapping[str, object]] | None: """ Resolve the base rates from a model's ``tiered_pricing`` table, if it has one. @@ -391,22 +430,20 @@ def _get_tiered_base_costs(model_info: ModelInfo, usage: Usage) -> tuple[float, if tier is None: return None - cache_creation_cost: Final = tier_rate(tier, "cache_creation_input_token_cost", "input_cost_per_token") completion_cost: Final = ( tier_rate(tier, "output_cost_per_token") if "output_cost_per_token" in tier else get_cost_per_unit(model_info, "output_cost_per_token") or 0.0 ) - return ( - tier_rate(tier, "input_cost_per_token"), - completion_cost, - cache_creation_cost, - tier_rate(tier, "cache_creation_input_token_cost_above_1hr") - if "cache_creation_input_token_cost_above_1hr" in tier - and tier["cache_creation_input_token_cost_above_1hr"] is not None - else cache_creation_cost, - tier_rate(tier, "cache_read_input_token_cost", "input_cost_per_token"), + cache_creation_rate: Final = tier_rate(tier, "cache_creation_input_token_cost", "input_cost_per_token") + rates: Final = TokenRates( + input_rate=tier_rate(tier, "input_cost_per_token"), + output_rate=completion_cost, + cache_read_rate=tier_rate(tier, "cache_read_input_token_cost", "input_cost_per_token"), + cache_creation_rate=cache_creation_rate, + reasoning_rate=None, ) + return rates, tier def _is_within_off_peak_window(off_peak_hours_utc: str | Sequence[str], current_time: datetime | None = None) -> bool: @@ -532,19 +569,6 @@ def _is_off_peak(off_peak: Mapping[str, object], current_time: datetime | None = return False -@dataclass(frozen=True, slots=True) -class TokenRates: - input_rate: float - output_rate: float - cache_read_rate: float - cache_creation_rate: float - reasoning_rate: float | None - - @property - def billed_reasoning_rate(self) -> float: - return self.output_rate if self.reasoning_rate is None else self.reasoning_rate - - def resolve_explicit_cache_read_cost_rate( model_info: ModelInfo, usage: Usage, @@ -649,7 +673,8 @@ def apply_off_peak_pricing(model_info: ModelInfo, current_time: datetime | None, if off_peak is None: return rates off_peak_reasoning_rate: Final = _parse_off_peak_rate(off_peak.get("output_cost_per_reasoning_token")) - return TokenRates( + return replace( + rates, input_rate=_off_peak_rate(off_peak, "input_cost_per_token", rates.input_rate), output_rate=_off_peak_rate(off_peak, "output_cost_per_token", rates.output_rate), cache_read_rate=_off_peak_rate(off_peak, "cache_read_input_token_cost", rates.cache_read_rate), @@ -661,32 +686,28 @@ def apply_off_peak_pricing(model_info: ModelInfo, current_time: datetime | None, def _apply_off_peak_to_base_costs( model_info: ModelInfo, current_time: datetime | None, - base_costs: tuple[float, float, float, float | None, float], -) -> tuple[float, float, float, float, float]: - """Apply off-peak rates to an already-resolved set of base costs, whichever pricing path - produced them. off_peak_pricing has no field for the one-hour cache-creation rate, so a - present one passes through untouched and an absent one resolves to the applied - cache-creation rate. Reasoning is left to _resolve_billed_reasoning_rate. + base_rates: TokenRates, + tier: Mapping[str, object], +) -> TokenRates: + """Apply off-peak rates to the base costs resolved from a pricing tier. off_peak_pricing has no + field for the long-TTL cache-creation rates, so a tier that declares one keeps it, and a tier + that does not bills that TTL at the off-peak-adjusted write rate. Reasoning is left to + _resolve_billed_reasoning_rate. """ - prompt, completion, cache_creation, cache_creation_above_1hr, cache_read = base_costs - rates: Final = apply_off_peak_pricing( - model_info, - current_time, - TokenRates( - input_rate=prompt, - output_rate=completion, - cache_read_rate=cache_read, - cache_creation_rate=cache_creation, - reasoning_rate=None, + rates: Final = apply_off_peak_pricing(model_info, current_time, base_rates) + return replace( + rates, + cache_creation_rates_by_ttl=MappingProxyType( + { + ttl: rates.cache_creation_rate if tier.get(key) is None else tier_rate(tier, key) + for ttl, key in _TTL_PRICED_CACHE_WRITE_RATE_KEYS.items() + } ), ) - return ( - rates.input_rate, - rates.output_rate, - rates.cache_creation_rate, - rates.cache_creation_rate if cache_creation_above_1hr is None else cache_creation_above_1hr, - rates.cache_read_rate, - ) + + +def _first_present_key(model_info: ModelInfo, preferred_key: str, fallback_key: str) -> str: + return preferred_key if model_info.get(preferred_key) is not None else fallback_key def _get_token_base_cost( @@ -696,7 +717,7 @@ def _get_token_base_cost( current_time: datetime | None = None, *, threshold_is_inclusive: bool = False, -) -> tuple[float, float, float, float, float]: +) -> TokenRates: """ Return prompt cost, completion cost, and cache costs for a given model and usage. @@ -709,15 +730,12 @@ def _get_token_base_cost( An absent cache-creation or cache-read rate always resolves to the resolved input rate, the way the tiered table and custom deployment pricing already do, since a provider that publishes no cache price bills cached tokens as ordinary input. An - absent 1h write rate resolves to the cache-creation rate, off-peak included. An + absent long-TTL write rate resolves to the cache-creation rate, off-peak included. An explicit 0.0 stays a real price for all of them. - - Returns: - Tuple[float, float, float, float] - (prompt_cost, completion_cost, cache_creation_cost, cache_read_cost) """ tiered_base_costs: Final = _get_tiered_base_costs(model_info=model_info, usage=usage) if tiered_base_costs is not None: - return _apply_off_peak_to_base_costs(model_info, current_time, tiered_base_costs) + return _apply_off_peak_to_base_costs(model_info, current_time, *tiered_base_costs) # Get service tier aware cost keys input_cost_key: Final = get_service_tier_cost_key("input_cost_per_token", service_tier) @@ -734,13 +752,13 @@ def _get_token_base_cost( # For image generation models that don't have output_cost_per_token, # use output_cost_per_image_token as the base cost (all output tokens are image tokens) - if completion_base_cost == 0.0 or completion_base_cost is None: + if completion_base_cost == 0.0: output_image_cost: Final = get_cost_per_unit(model_info, "output_cost_per_image_token", None) if output_image_cost is not None: completion_base_cost = output_image_cost cache_creation_cost = get_cost_per_unit(model_info, cache_creation_cost_key, default_value=None) - cache_creation_cost_above_1hr = get_cost_per_unit( - model_info, "cache_creation_input_token_cost_above_1hr", default_value=None + cache_creation_keys_by_ttl: Mapping[str, str] = MappingProxyType( + {ttl: get_service_tier_cost_key(key, service_tier) for ttl, key in _TTL_PRICED_CACHE_WRITE_RATE_KEYS.items()} ) cache_read_cost = get_cost_per_unit(model_info, cache_read_cost_key, default_value=None) @@ -811,14 +829,6 @@ def _get_token_base_cost( if service_tier else f"cache_creation_input_token_cost_above_{threshold_str}_tokens" ) - cache_creation_1hr_tiered_key = ( - get_service_tier_cost_key( - f"cache_creation_input_token_cost_above_1hr_above_{threshold_str}_tokens", - service_tier, - ) - if service_tier - else f"cache_creation_input_token_cost_above_1hr_above_{threshold_str}_tokens" - ) cache_read_tiered_key = ( get_service_tier_cost_key( f"cache_read_input_token_cost_above_{threshold_str}_tokens", @@ -830,10 +840,19 @@ def _get_token_base_cost( cache_creation_cost = get_cost_per_unit(model_info, cache_creation_tiered_key, cache_creation_cost) - cache_creation_cost_above_1hr = get_cost_per_unit( - model_info, cache_creation_1hr_tiered_key, cache_creation_cost_above_1hr + cache_creation_keys_by_ttl = MappingProxyType( + { + ttl: _first_present_key( + model_info, + get_service_tier_cost_key( + f"{_TTL_PRICED_CACHE_WRITE_RATE_KEYS[ttl]}_above_{threshold_str}_tokens", + service_tier, + ), + key, + ) + for ttl, key in cache_creation_keys_by_ttl.items() + } ) - cache_read_cost = get_cost_per_unit(model_info, cache_read_tiered_key, cache_read_cost) except (IndexError, ValueError): continue @@ -849,16 +868,26 @@ def _get_token_base_cost( resolved_cache_creation_cost: Final = ( input_rate_for_missing_cache_rates if cache_creation_cost is None else cache_creation_cost ) - - return _apply_off_peak_to_base_costs( + base_rates: Final = apply_off_peak_pricing( model_info, current_time, - ( - prompt_base_cost, - completion_base_cost, - resolved_cache_creation_cost, - cache_creation_cost_above_1hr, - resolved_cache_read_cost, + TokenRates( + input_rate=prompt_base_cost, + output_rate=completion_base_cost, + cache_read_rate=resolved_cache_read_cost, + cache_creation_rate=resolved_cache_creation_cost, + reasoning_rate=None, + ), + ) + return replace( + base_rates, + cache_creation_rates_by_ttl=MappingProxyType( + { + ttl: base_rates.cache_creation_rate + if (rate := get_cost_per_unit(model_info, key, default_value=None)) is None + else rate + for ttl, key in cache_creation_keys_by_ttl.items() + } ), ) @@ -975,25 +1004,28 @@ def resolve_image_model_info(model: str, custom_llm_provider: str, model_info: M def calculate_cache_writing_cost( cache_creation_tokens: int, cache_creation_token_details: CacheCreationTokenDetails | None, - cache_creation_cost_above_1hr: float, cache_creation_cost: float, + cache_creation_cost_by_ttl: Mapping[str, float], ) -> float: """ - Adjust cost of cache creation tokens based on the cache creation token details. + Bill cache writes per lifetime: Anthropic reports 5m and 1h counts, OpenAI reports 30m and 12h counts. + Writes no lifetime count covers, such as a lifetime a provider adds later, bill at the base write rate. """ - total_cost: float = 0.0 - if cache_creation_token_details is not None: - # get the number of 5m and 1h cache creation tokens - cache_creation_tokens_5m: Final = cache_creation_token_details.ephemeral_5m_input_tokens - cache_creation_tokens_1h: Final = cache_creation_token_details.ephemeral_1h_input_tokens - # add the number of 5m and 1h cache creation tokens to the cache creation tokens - total_cost += cache_creation_tokens_5m * cache_creation_cost if cache_creation_tokens_5m is not None else 0.0 - total_cost += ( - cache_creation_tokens_1h * cache_creation_cost_above_1hr if cache_creation_tokens_1h is not None else 0.0 - ) - else: - total_cost += cache_creation_tokens * cache_creation_cost - return total_cost + if cache_creation_token_details is None: + return cache_creation_tokens * cache_creation_cost + tokens_by_ttl: Final[Mapping[str, int | None]] = MappingProxyType( + { + "5m": cache_creation_token_details.ephemeral_5m_input_tokens, + "30m": cache_creation_token_details.ephemeral_30m_input_tokens, + "1hr": cache_creation_token_details.ephemeral_1h_input_tokens, + "12hr": cache_creation_token_details.ephemeral_12h_input_tokens, + } + ) + unattributed_tokens: Final = max(cache_creation_tokens - sum(t or 0 for t in tokens_by_ttl.values()), 0) + return unattributed_tokens * cache_creation_cost + sum( + (tokens or 0) * cache_creation_cost_by_ttl.get(ttl, cache_creation_cost) + for ttl, tokens in tokens_by_ttl.items() + ) class PromptTokensDetailsResult(TypedDict): @@ -1178,7 +1210,7 @@ def _calculate_input_cost( prompt_base_cost: float, cache_read_cost: float, cache_creation_cost: float, - cache_creation_cost_above_1hr: float, + cache_creation_cost_by_ttl: Mapping[str, float], service_tier: str | None = None, ) -> float: """ @@ -1248,8 +1280,8 @@ def _calculate_input_cost( prompt_cost += calculate_cache_writing_cost( cache_creation_tokens=prompt_tokens_details["cache_creation_tokens"], cache_creation_token_details=prompt_tokens_details["cache_creation_token_details"], - cache_creation_cost_above_1hr=cache_creation_cost_above_1hr, cache_creation_cost=cache_creation_cost, + cache_creation_cost_by_ttl=cache_creation_cost_by_ttl, ) ### CHARACTER COST @@ -1510,34 +1542,31 @@ def generic_cost_per_token( ) billing_time: Final = current_time if current_time is not None else current_billing_time() - ( - prompt_base_cost, - completion_base_cost, - cache_creation_cost, - cache_creation_cost_above_1hr, - cache_read_cost, - ) = _get_token_base_cost( + base_costs: Final = _get_token_base_cost( model_info=resolved_model_info, usage=usage, service_tier=service_tier, current_time=billing_time, threshold_is_inclusive=_uses_inclusive_token_thresholds(custom_llm_provider), ) + completion_base_cost: Final = base_costs.output_rate resolved_cache_read_cost: Final = resolve_explicit_cache_read_cost_rate( model_info=resolved_model_info, usage=usage, current_time=billing_time, service_tier=service_tier, ) - effective_cache_read_cost: Final = cache_read_cost if resolved_cache_read_cost is None else resolved_cache_read_cost + effective_cache_read_cost: Final = ( + base_costs.cache_read_rate if resolved_cache_read_cost is None else resolved_cache_read_cost + ) prompt_cost = _calculate_input_cost( prompt_tokens_details=prompt_tokens_details, model_info=resolved_model_info, - prompt_base_cost=prompt_base_cost, + prompt_base_cost=base_costs.input_rate, cache_read_cost=effective_cache_read_cost, - cache_creation_cost=cache_creation_cost, - cache_creation_cost_above_1hr=cache_creation_cost_above_1hr, + cache_creation_cost=base_costs.cache_creation_rate, + cache_creation_cost_by_ttl=base_costs.cache_creation_rates_by_ttl, service_tier=service_tier, ) @@ -1640,7 +1669,7 @@ class BilledTokenRates: cache_read_input_token_cost: float cache_read_input_audio_token_cost: float cache_creation_input_token_cost: float - cache_creation_input_token_cost_above_1hr: float + cache_creation_input_token_cost_by_ttl: Mapping[str, float] output_cost_per_reasoning_token: float def scaled(self, multiplier: float) -> "BilledTokenRates": @@ -1652,7 +1681,9 @@ class BilledTokenRates: cache_read_input_token_cost=self.cache_read_input_token_cost * multiplier, cache_read_input_audio_token_cost=self.cache_read_input_audio_token_cost * multiplier, cache_creation_input_token_cost=self.cache_creation_input_token_cost * multiplier, - cache_creation_input_token_cost_above_1hr=self.cache_creation_input_token_cost_above_1hr * multiplier, + cache_creation_input_token_cost_by_ttl=MappingProxyType( + {ttl: rate * multiplier for ttl, rate in self.cache_creation_input_token_cost_by_ttl.items()} + ), output_cost_per_reasoning_token=self.output_cost_per_reasoning_token * multiplier, ) @@ -1702,7 +1733,7 @@ def _custom_pricing_rates(custom_cost_per_token: CostPerToken) -> BilledTokenRat cache_read_input_token_cost=cache_read_rate, cache_read_input_audio_token_cost=cache_read_rate, cache_creation_input_token_cost=cache_creation_rate, - cache_creation_input_token_cost_above_1hr=cache_creation_rate, + cache_creation_input_token_cost_by_ttl=MappingProxyType({}), output_cost_per_reasoning_token=output_rate, ) @@ -1717,13 +1748,7 @@ def _cost_map_billed_rates( current_time: datetime | None, ) -> BilledTokenRates: billing_time: Final = current_time if current_time is not None else current_billing_time() - ( - prompt_base_cost, - completion_base_cost, - cache_creation_cost_rate, - cache_creation_cost_above_1hr_rate, - cache_read_cost_rate, - ) = _get_token_base_cost( + base_costs: Final = _get_token_base_cost( model_info=model_info, usage=usage, service_tier=service_tier, @@ -1737,14 +1762,14 @@ def _cost_map_billed_rates( service_tier=service_tier, ) effective_cache_read_cost_rate: Final = ( - cache_read_cost_rate if provider_cache_read_cost_rate is None else provider_cache_read_cost_rate + base_costs.cache_read_rate if provider_cache_read_cost_rate is None else provider_cache_read_cost_rate ) reasoning_rate: Final = _resolve_billed_reasoning_rate( model_info=model_info, usage=usage, service_tier=service_tier, - completion_base_cost=completion_base_cost, + completion_base_cost=base_costs.output_rate, current_time=billing_time, ) audio_cache_read_rate: Final = get_cost_per_unit( @@ -1759,14 +1784,14 @@ def _cost_map_billed_rates( * get_provider_specific_speed_multiplier(model_info=model_info, usage=usage) ) return BilledTokenRates( - input_cost_per_token=prompt_base_cost, - output_cost_per_token=completion_base_cost, + input_cost_per_token=base_costs.input_rate, + output_cost_per_token=base_costs.output_rate, cache_read_input_token_cost=effective_cache_read_cost_rate, cache_read_input_audio_token_cost=( audio_cache_read_rate if audio_cache_read_rate is not None else effective_cache_read_cost_rate ), - cache_creation_input_token_cost=cache_creation_cost_rate, - cache_creation_input_token_cost_above_1hr=cache_creation_cost_above_1hr_rate, + cache_creation_input_token_cost=base_costs.cache_creation_rate, + cache_creation_input_token_cost_by_ttl=base_costs.cache_creation_rates_by_ttl, output_cost_per_reasoning_token=reasoning_rate, ).scaled(multiplier) @@ -1854,8 +1879,8 @@ def get_token_type_cost_breakdown( else calculate_cache_writing_cost( cache_creation_tokens=cache_creation_tokens, cache_creation_token_details=cache_creation_token_details, - cache_creation_cost_above_1hr=rates.cache_creation_input_token_cost_above_1hr, cache_creation_cost=rates.cache_creation_input_token_cost, + cache_creation_cost_by_ttl=rates.cache_creation_input_token_cost_by_ttl, ) ) return TokenTypeCostBreakdown( @@ -1886,7 +1911,7 @@ def calculate_prompt_caching_savings( biller saw them rather than at the later spend write. """ model_info_with_cache_read_default: Final = apply_provider_cache_read_default(model_info, custom_llm_provider) - prompt_base_cost, _, cache_creation_cost, cache_creation_cost_above_1hr, cache_read_cost = _get_token_base_cost( + base_costs: Final = _get_token_base_cost( model_info=model_info_with_cache_read_default, usage=usage, service_tier=service_tier, @@ -1899,9 +1924,11 @@ def calculate_prompt_caching_savings( current_time=billed_at, service_tier=service_tier, ) - effective_cache_read_cost: Final = cache_read_cost if provider_cache_read_cost is None else provider_cache_read_cost - write_rate: Final = cache_creation_cost or prompt_base_cost - write_rate_1h: Final = cache_creation_cost_above_1hr or write_rate + prompt_base_cost: Final = base_costs.input_rate + effective_cache_read_cost: Final = ( + base_costs.cache_read_rate if provider_cache_read_cost is None else provider_cache_read_cost + ) + write_rate: Final = base_costs.cache_creation_rate or prompt_base_cost prompt_tokens_details: Final = parse_prompt_tokens_details(usage) cache_read_tokens: Final = max(prompt_tokens_details["cache_hit_tokens"], 0) cache_creation_tokens: Final = max(prompt_tokens_details["cache_creation_tokens"], 0) @@ -1909,7 +1936,9 @@ def calculate_prompt_caching_savings( cache_creation_details: Final = ( CacheCreationTokenDetails( ephemeral_5m_input_tokens=max(details.ephemeral_5m_input_tokens or 0, 0), + ephemeral_30m_input_tokens=max(details.ephemeral_30m_input_tokens or 0, 0), ephemeral_1h_input_tokens=max(details.ephemeral_1h_input_tokens or 0, 0), + ephemeral_12h_input_tokens=max(details.ephemeral_12h_input_tokens or 0, 0), ) if details is not None else None @@ -1918,8 +1947,10 @@ def calculate_prompt_caching_savings( write_premium: Final = calculate_cache_writing_cost( cache_creation_tokens=cache_creation_tokens, cache_creation_token_details=cache_creation_details, - cache_creation_cost_above_1hr=write_rate_1h - prompt_base_cost, cache_creation_cost=write_rate - prompt_base_cost, + cache_creation_cost_by_ttl=MappingProxyType( + {ttl: rate - prompt_base_cost for ttl, rate in base_costs.cache_creation_rates_by_ttl.items()} + ), ) uplift: Final = get_regional_uplift_multiplier(model_info, data_residency) * get_vertex_regional_endpoint_uplift( model_info, vertex_location diff --git a/litellm/litellm_core_utils/llm_cost_calc/zero_cost_diagnostic.py b/litellm/litellm_core_utils/llm_cost_calc/zero_cost_diagnostic.py index 9688b511ea8..3ed598b5e97 100644 --- a/litellm/litellm_core_utils/llm_cost_calc/zero_cost_diagnostic.py +++ b/litellm/litellm_core_utils/llm_cost_calc/zero_cost_diagnostic.py @@ -5,6 +5,7 @@ from typing import Final from pydantic import TypeAdapter, ValidationError from typing_extensions import assert_never +from litellm.litellm_core_utils.llm_cost_calc.utils import parse_prompt_tokens_details from litellm.types.utils import ( CompletionTokensDetailsWrapper, PromptTokensDetailsWrapper, @@ -16,6 +17,8 @@ ZERO_COST_COUNTER_NAME: Final = "litellm_zero_cost_requests_total" _TEXT_INPUT_RATE: Final = "input_cost_per_token" _AUDIO_INPUT_RATE: Final = "input_cost_per_audio_token" +_CACHE_READ_INPUT_RATE: Final = "cache_read_input_token_cost" +_CACHE_READ_AUDIO_INPUT_RATE: Final = "cache_read_input_audio_token_cost" _TEXT_OUTPUT_RATE: Final = "output_cost_per_token" _AUDIO_OUTPUT_RATE: Final = "output_cost_per_audio_token" _RATE_KEY_MARKERS: Final = ("cost", "pricing") @@ -33,19 +36,38 @@ def _tokens(value: object) -> int: def used_pricing_keys(usage: Usage) -> tuple[str, ...]: - prompt_audio: Final = _audio_tokens(usage.prompt_tokens_details) + prompt_details: Final = parse_prompt_tokens_details(usage) + prompt_audio: Final = prompt_details["audio_tokens"] completion_audio: Final = _audio_tokens(usage.completion_tokens_details) - prompt_text: Final = _tokens(usage.prompt_tokens) - prompt_audio + prompt_text: Final = max( + _tokens(usage.prompt_tokens) + - prompt_details["cache_hit_tokens"] + - prompt_audio + - prompt_details["image_tokens"] + - prompt_details["video_tokens"], + 0, + ) + cached_text: Final = max(prompt_details["cache_hit_tokens"] - prompt_details["cache_hit_audio_tokens"], 0) completion_text: Final = _tokens(usage.completion_tokens) - completion_audio components: Final = ( (_TEXT_INPUT_RATE, prompt_text), (_AUDIO_INPUT_RATE, prompt_audio), + (_CACHE_READ_INPUT_RATE, cached_text), + (_CACHE_READ_AUDIO_INPUT_RATE, prompt_details["cache_hit_audio_tokens"]), (_TEXT_OUTPUT_RATE, completion_text), (_AUDIO_OUTPUT_RATE, completion_audio), ) return tuple(key for key, count in components if count > 0) +def _effective_pricing_key(key: str, pricing_entry: Mapping[str, object]) -> str: + if key == _CACHE_READ_AUDIO_INPUT_RATE and pricing_entry.get(key) is None: + return _CACHE_READ_INPUT_RATE if pricing_entry.get(_CACHE_READ_INPUT_RATE) is not None else _TEXT_INPUT_RATE + if key == _CACHE_READ_INPUT_RATE and pricing_entry.get(key) is None: + return _TEXT_INPUT_RATE + return key + + def _nested_pricing(value: object) -> Mapping[str, object] | tuple[object, ...] | None: try: return _NESTED_PRICING.validate_python(value) @@ -89,7 +111,8 @@ def diagnose_zero_cost( pricing_entry: Mapping[str, object], calculation_failed: bool, ) -> StandardLoggingZeroCostDiagnostic | None: - used_keys: Final = used_pricing_keys(usage) + effective_keys: Final = tuple(_effective_pricing_key(key, pricing_entry) for key in used_pricing_keys(usage)) + used_keys: Final = tuple(key for index, key in enumerate(effective_keys) if key not in effective_keys[:index]) if not used_keys: return None missing_keys: Final = tuple(key for key in used_keys if pricing_entry.get(key) is None) diff --git a/litellm/litellm_core_utils/llm_judge.py b/litellm/litellm_core_utils/llm_judge.py index 0c2d7767455..307e000119b 100644 --- a/litellm/litellm_core_utils/llm_judge.py +++ b/litellm/litellm_core_utils/llm_judge.py @@ -21,6 +21,7 @@ if TYPE_CHECKING: JSON_FENCE_RE: Final = re.compile(r"```(?:json)?\s*(.*?)\s*```", re.DOTALL | re.IGNORECASE) _OBJECT_MAPPING_ADAPTER: Final = TypeAdapter(Mapping[str, object]) +_DECODED_JSON: Final = TypeAdapter(object) def default_router_provider() -> Router | None: @@ -40,13 +41,13 @@ def parse_json_verdict(raw: str) -> dict[str, object]: # mutable-ok: plain pars text = fenced.group(1).strip() # rebind-ok: progressively narrowed to the JSON payload parsed: object try: - parsed = json.loads(text) + parsed = _DECODED_JSON.validate_python(json.loads(text)) except json.JSONDecodeError: start: Final = text.find("{") end: Final = text.rfind("}") if start == -1 or end <= start: raise - parsed = json.loads(text[start : end + 1]) + parsed = _DECODED_JSON.validate_python(json.loads(text[start : end + 1])) if not isinstance(parsed, dict): raise ValueError("judge response is not a JSON object") return {str(k): v for k, v in parsed.items()} diff --git a/litellm/litellm_core_utils/logging_callback_manager.py b/litellm/litellm_core_utils/logging_callback_manager.py index 307353d081b..56c6436eae6 100644 --- a/litellm/litellm_core_utils/logging_callback_manager.py +++ b/litellm/litellm_core_utils/logging_callback_manager.py @@ -1,5 +1,5 @@ import threading -from collections.abc import Callable, Iterable, Iterator +from collections.abc import Callable, Iterable, Iterator, Mapping from types import MethodType from typing import TYPE_CHECKING, Final @@ -20,6 +20,10 @@ _generic_api_logger_cache: Final[dict[str, GenericAPILogger]] = {} _callback_lists_lock: Final = threading.RLock() +def _instance_attributes(target: object) -> Mapping[str, object]: + return vars(target) + + class LoggingCallbackManager: """ A centralized class that allows easy add / remove callbacks for litellm. @@ -341,7 +345,7 @@ class LoggingCallbackManager: key_parts: Final = [type(custom_logger).__name__] # Add only fundamental type instance variables to the key - for attr_name, attr_value in vars(custom_logger).items(): + for attr_name, attr_value in _instance_attributes(custom_logger).items(): if not attr_name.startswith("_"): # Skip private attributes if isinstance(attr_value, (str, bool, int)): key_parts.append(f"{attr_name}={attr_value}") diff --git a/litellm/litellm_core_utils/prompt_templates/common_utils.py b/litellm/litellm_core_utils/prompt_templates/common_utils.py index 60be4d44706..59882dcbf2f 100644 --- a/litellm/litellm_core_utils/prompt_templates/common_utils.py +++ b/litellm/litellm_core_utils/prompt_templates/common_utils.py @@ -20,6 +20,7 @@ from pydantic import TypeAdapter import litellm from litellm import verbose_logger +from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.router_utils.batch_utils import InMemoryFile from litellm.types.llms.openai import ( AllMessageValues, @@ -1527,7 +1528,7 @@ def _grammar_branches(node: Mapping[str, object]) -> int: if properties is None: return 0 optional: Final = len(_optional_property_names(node)) - return 2**optional * (len(properties) - optional + 1) + return (1 << optional) * (len(properties) - optional + 1) def _optional_property_names(node: Mapping[str, object]) -> frozenset[str]: @@ -2839,7 +2840,7 @@ def split_concatenated_json_objects(raw: str) -> list[dict[str, object]]: break try: - obj, end_idx = decoder.raw_decode(raw, idx) + decoded = decoder.raw_decode(raw, idx) except json.JSONDecodeError as e: verbose_logger.warning( "split_concatenated_json_objects: discarding unparseable tool-call " @@ -2849,13 +2850,14 @@ def split_concatenated_json_objects(raw: str) -> list[dict[str, object]]: e, ) break - if isinstance(obj, dict): - results.append(obj) + obj = as_str_mapping(_DECODED_JSON.validate_python(decoded[0])) + if obj is not None: + results.append(dict(obj)) else: # Non-dict JSON value – wrap in empty dict (Bedrock requires # toolUse.input to be an object). results.append({}) - idx = end_idx + idx = decoded[1] return results @@ -2887,14 +2889,16 @@ def salvage_concatenated_tool_arguments(raw: str) -> tuple[dict[str, object], .. if idx >= length: break try: - obj, end_idx = decoder.raw_decode(stripped, idx) + decoded = decoder.raw_decode(stripped, idx) except json.JSONDecodeError: return () - if not isinstance(obj, dict): + decoded_object = as_str_mapping(_DECODED_JSON.validate_python(decoded[0])) + if decoded_object is None: return () - idx = end_idx + idx = decoded[1] if exceeded: continue + obj = dict(decoded_object) count += 1 if not kept: kept = (obj,) diff --git a/litellm/litellm_core_utils/prompt_templates/factory.py b/litellm/litellm_core_utils/prompt_templates/factory.py index 3d865bd1819..de8c6e6c4cc 100644 --- a/litellm/litellm_core_utils/prompt_templates/factory.py +++ b/litellm/litellm_core_utils/prompt_templates/factory.py @@ -21,6 +21,7 @@ import litellm.types.llms from litellm import verbose_logger from litellm._uuid import uuid from litellm.constants import REDACTED_BY_LITELLM +from litellm.litellm_core_utils.core_helpers import as_str_mapping, attribute_or_none from litellm.litellm_core_utils.prompt_templates.mid_conversation_system import ( anthropic_system_messages, find_anthropic_server_tool_result, @@ -1021,11 +1022,12 @@ def convert_to_anthropic_tool_invoke_xml(tool_calls: list) -> str: tool_function = get_attribute_or_key(tool, "function") tool_name = get_attribute_or_key(tool_function, "name") tool_arguments = get_attribute_or_key(tool_function, "arguments") - parsed_args = parse_tool_call_arguments( - tool_arguments, tool_name=tool_name, context="Anthropic XML tool invoke" + parsed_args = _DECODED_JSON.validate_python( + parse_tool_call_arguments(tool_arguments, tool_name=tool_name, context="Anthropic XML tool invoke") ) - if isinstance(parsed_args, dict): - parameters = "".join(f"<{param}>{val}\n" for param, val in parsed_args.items()) + parsed_mapping = as_str_mapping(parsed_args) + if parsed_mapping is not None: + parameters = "".join(f"<{param}>{val}\n" for param, val in parsed_mapping.items()) else: parameters = f"{parsed_args}\n" invokes += f"\n{tool_name}\n\n{parameters}\n\n" @@ -1488,6 +1490,7 @@ def convert_to_gemini_tool_call_result( message: ChatCompletionToolMessage | ChatCompletionFunctionMessage, last_message_with_tool_calls: dict | None, forward_function_call_id: bool = False, + supports_multimodal_function_responses: bool = True, ) -> VertexPartType | list[VertexPartType]: """ OpenAI message with a tool result looks like: @@ -1650,9 +1653,9 @@ def convert_to_gemini_tool_call_result( _part: Final[VertexPartType] = {"function_response": _function_response} - # For multimodal function responses, Gemini expects media parts nested - # inside functionResponse.parts instead of sibling content parts. if inline_data_list: + if not supports_multimodal_function_responses: + return [_part, *(VertexPartType(inline_data=inline_data) for inline_data in inline_data_list)] _function_response["parts"] = [{"inline_data": inline_data} for inline_data in inline_data_list] return [_part] @@ -2203,15 +2206,97 @@ def anthropic_process_openai_file_message( _EMPTY_TEXT_PLACEHOLDER: Final = "[System: Empty message content sanitised to satisfy protocol]" +def _dict_block(block: object) -> Mapping[str, object] | None: + if not isinstance(block, dict): + return None + return cast(Mapping[str, object], block) # cast-ok: narrowed by isinstance; the converters only read dict blocks + + +def _is_empty_text_block(block: object) -> bool: + match _dict_block(block): + case {"type": "text", "text": str() as text}: + return not text.strip() + case {"type": "text"}: + return True + case _: + return False + + +def _with_placeholder_text(block: object) -> object: + fields: Final = _dict_block(block) + if fields is None or not _is_empty_text_block(fields): + return block + return {**fields, "text": _EMPTY_TEXT_PLACEHOLDER} + + +def _survives_assistant_conversion(block: object) -> bool: + """Whether ``anthropic_messages_pt`` keeps this list-content block of an assistant turn. + + Mirrors the assistant converter: a ``thinking`` / ``redacted_thinking`` block is kept + unless it is unsignable (a signed block is kept even with empty text), and + ``server_tool_use`` and ``*_tool_result`` blocks pass through. A redacted block with + blank data is dropped under ``drop_params``, which is not known here, so it never counts. + """ + fields: Final = _dict_block(block) + if fields is None: + return False + if (thinking_block := _as_thinking_block(fields)) is not None: + return not (is_unsignable_thinking_block(thinking_block) or has_blank_redacted_data(thinking_block)) + match fields: + case {"type": "server_tool_use"}: + return True + case {"type": str() as block_type}: + return block_type.endswith("_tool_result") + case _: + return False + + +def _tool_call_survives_conversion(tool_call: object) -> bool: + """Whether ``convert_to_anthropic_tool_invoke`` can emit a block for this tool call. + + Non-function calls are skipped there, and a tool search call is dropped when its + result is not replayed, which depends on the rest of the conversation, so neither counts. + """ + if message_field(tool_call, "type") != "function": + return False + match message_field(tool_call, "id"), message_field(message_field(tool_call, "function"), "name"): + case (str() as tool_id, str() as tool_name): + return not is_anthropic_tool_search_use(tool_id, tool_name) + case _: + return True + + +def _carries_non_text_content(message: AllMessageValues) -> bool: + if any(_tool_call_survives_conversion(tool_call) for tool_call in parts_of(message_field(message, "tool_calls"))): + return True + content: Final = message_field(message, "content") + blocks: Final = parts_of(content) + return isinstance(content, list) and any(_survives_assistant_conversion(block) for block in blocks) + + +def _with_content(message: AllMessageValues, content: object, action: str) -> AllMessageValues: + sanitized: Final = cast(AllMessageValues, {**message, "content": content}) + verbose_logger.debug("_sanitize_empty_text_content: %s in %s message", action, message_field(message, "role")) + return sanitized + + def _sanitize_empty_text_content( message: AllMessageValues, ) -> AllMessageValues: """ Case C: Sanitize empty text content - - Replace empty or whitespace-only text content with a placeholder message. - - Handles both string content and list-of-blocks content (rewriting only - the empty text blocks in place; non-text blocks like images are left - untouched). + + Anthropic rejects empty text blocks, so empty or whitespace-only text must never be + forwarded verbatim. What replaces it depends on what else the turn carries. + + Assistant turns that already carry substantive content (``tool_calls``, or non-text + blocks such as ``server_tool_use``) get the empty text dropped. Anthropic accepts an + assistant turn whose content is just ``tool_use``, so there is nothing to substitute, and + substituting anyway leaks a protocol diagnostic into the conversation as though the + assistant had said it, which the model then echoes on later turns. + + Every other empty turn would otherwise end up with no content at all, which Anthropic + also rejects, so the placeholder is still substituted there. Returns: The message with sanitized content if needed, otherwise the original message @@ -2219,42 +2304,26 @@ def _sanitize_empty_text_content( if message.get("role") not in ["user", "assistant"]: return message - content: Final = message.get("content") + content: Final = message_field(message, "content") + drop_empty_text: Final = message_field(message, "role") == "assistant" and _carries_non_text_content(message) if isinstance(content, str): - if not content or not content.strip(): - message = cast(AllMessageValues, dict(message)) # Make a copy - message["content"] = _EMPTY_TEXT_PLACEHOLDER - verbose_logger.debug( - "_sanitize_empty_text_content: Replaced empty text content in %s message", message.get("role") - ) + if content.strip(): + return message + if drop_empty_text: + return _with_content(message, None, "Dropped empty text content") + return _with_content(message, _EMPTY_TEXT_PLACEHOLDER, "Replaced empty text content") + + blocks: Final = parts_of(content) + if not isinstance(content, list) or not any(_is_empty_text_block(block) for block in blocks): return message - if isinstance(content, list): - # Walk the blocks and rewrite any empty text blocks. We rewrite (rather - # than drop) so callers don't end up with an entirely empty content - # list, which Anthropic also rejects. - new_blocks: Final[list[Any]] = [] - rewrote_any = False - for block in content: - if isinstance(block, dict) and block.get("type") == "text": - text = block.get("text") - if not isinstance(text, str) or not text or not text.strip(): - new_block = dict(block) - new_block["text"] = _EMPTY_TEXT_PLACEHOLDER - new_blocks.append(new_block) - rewrote_any = True - continue - new_blocks.append(block) + if drop_empty_text: + kept: Final = [block for block in blocks if not _is_empty_text_block(block)] + return _with_content(message, kept, "Dropped empty text block(s)") - if rewrote_any: - message = cast(AllMessageValues, dict(message)) # Make a copy - message["content"] = new_blocks - verbose_logger.debug( - "_sanitize_empty_text_content: Replaced empty text block(s) in %s message", message.get("role") - ) - - return message + rewritten: Final = [_with_placeholder_text(block) for block in blocks] + return _with_content(message, rewritten, "Replaced empty text block(s)") def _add_missing_tool_results( @@ -2342,7 +2411,7 @@ def _add_missing_tool_results( else: tool_name = getattr(function, "name", "unknown_tool") else: - function = getattr(tool_call, "function", None) + function = attribute_or_none(tool_call, "function") if function: tool_name = getattr(function, "name", "unknown_tool") break @@ -3184,10 +3253,14 @@ def anthropic_messages_pt( def extract_between_tags(tag: str, string: str, strip: bool = False) -> list[str]: ext_list = re.findall(f"<{tag}>(.+?)", string, re.DOTALL) if strip: - ext_list = [e.strip() for e in ext_list] + ext_list = list(_stripped(ext_list)) return ext_list +def _stripped(values: Iterable[str]) -> Iterator[str]: + return (value.strip() for value in values) + + def contains_tag(tag: str, string: str) -> bool: return bool(re.search(f"<{tag}>(.+?)", string, re.DOTALL)) @@ -4061,13 +4134,15 @@ def _convert_to_bedrock_tool_call_invoke( arguments_dict = {} else: try: - arguments_dict = json.loads(arguments) + decoded_arguments = as_str_mapping(_DECODED_JSON.validate_python(json.loads(arguments))) # Ensure arguments_dict is always a dict # (Bedrock requires toolUse.input to be an object). # Some providers return arguments: '""' which # json.loads decodes to a bare string. - if not isinstance(arguments_dict, dict): + if decoded_arguments is None: arguments_dict = {} + else: + arguments_dict = dict(decoded_arguments) except json.JSONDecodeError: # The model may return multiple JSON objects # concatenated in a single arguments string, e.g. @@ -6028,7 +6103,11 @@ def _parse_tool_call_arguments(raw: object, tool_name: str | None, context: str) return ({},) normalized_raw: Final = "{}" if raw == REDACTED_BY_LITELLM else raw try: - parsed: Final = parse_tool_call_arguments(normalized_raw, tool_name=tool_name, context=context) + parsed: Final = as_str_mapping( + _DECODED_JSON.validate_python( + parse_tool_call_arguments(normalized_raw, tool_name=tool_name, context=context) + ) + ) except ValueError as e: salvaged: Final = salvage_concatenated_tool_arguments(normalized_raw) if salvaged: @@ -6041,7 +6120,7 @@ def _parse_tool_call_arguments(raw: object, tool_name: str | None, context: str) return salvaged verbose_logger.warning("Failed to parse tool call arguments: %s", e) return ({},) - return (parsed,) if isinstance(parsed, dict) else ({},) + return (dict(parsed),) if parsed is not None else ({},) def _choice_tool_calls(choice: object) -> tuple[object, ...]: @@ -6275,7 +6354,7 @@ def is_flat_responses_tool(tool: Mapping[str, object]) -> bool: def chat_completion_tools_for(tool: Mapping[str, object]) -> tuple[Mapping[str, object], ...]: - from litellm.llms.anthropic.pass_through.adapters.transformation import LiteLLMAnthropicMessagesAdapter + from litellm.llms.anthropic.messages.adapters.transformation import LiteLLMAnthropicMessagesAdapter from litellm.responses.litellm_completion_transformation.transformation import ( LiteLLMCompletionResponsesConfig, ) diff --git a/litellm/litellm_core_utils/prompt_templates/mid_conversation_system.py b/litellm/litellm_core_utils/prompt_templates/mid_conversation_system.py index ecf419695d0..eb3400aee8b 100644 --- a/litellm/litellm_core_utils/prompt_templates/mid_conversation_system.py +++ b/litellm/litellm_core_utils/prompt_templates/mid_conversation_system.py @@ -482,7 +482,7 @@ def _runs_by_anchor( ) -> Mapping[int, tuple[tuple[int, ...], ...]]: anchored: Final = tuple(sorted(((anchor, run) for run, anchor in anchors if anchor is not None), key=itemgetter(0))) return MappingProxyType( - {anchor: tuple(run for _, run in group) for anchor, group in groupby(anchored, key=itemgetter(0))} + {anchor: tuple(run for _, run in group) for anchor, group in groupby(anchored, key=lambda entry: entry[0])} ) diff --git a/litellm/litellm_core_utils/redact_messages.py b/litellm/litellm_core_utils/redact_messages.py index 7f8a38cc8ec..548d088d833 100644 --- a/litellm/litellm_core_utils/redact_messages.py +++ b/litellm/litellm_core_utils/redact_messages.py @@ -14,7 +14,7 @@ from collections.abc import Mapping, Sequence from dataclasses import replace from typing import TYPE_CHECKING, Any, Final -from pydantic import TypeAdapter +from pydantic import JsonValue, TypeAdapter, ValidationError import litellm from litellm.constants import REDACTED_BY_LITELLM @@ -120,11 +120,55 @@ def _redacted_streaming_response_copy(streaming_response: object) -> object: return _redact_streaming_response(redacted_response) +BEDROCK_GUARDRAIL_TRACE_FIELDS: Final = ("trace", "amazon-bedrock-trace") +_MATCHED_TEXT_KEYS: Final = frozenset({"match", "regex"}) +_JSON_OBJECT: Final = TypeAdapter(dict[str, JsonValue]) + + +def _without_matched_text(trace: Mapping[str, JsonValue]) -> Mapping[str, JsonValue]: + redacted: Final = dict(copy.deepcopy(trace)) + stack: Final[list[JsonValue]] = [redacted] # mutable-ok: iterative walk, recursive_detector bans recursion here + while stack: + node = stack.pop() + if isinstance(node, dict): + for key in _MATCHED_TEXT_KEYS & node.keys(): + node[key] = "[REDACTED]" + stack.extend(node.values()) + elif isinstance(node, list): + stack.extend(node) + return redacted + + +def _redacted_bedrock_trace(trace: object) -> object: + try: + return _without_matched_text(_JSON_OBJECT.validate_python(trace)) + except ValidationError: + return trace + + +def _redact_bedrock_guardrail_trace(response: object) -> None: + """A Bedrock guardrail trace echoes the matched text of its sensitive-information and word findings back.""" + mapping: Final = _as_mapping(response) + if isinstance(response, dict): + traces: Final = { + field: _redacted_bedrock_trace(value) + for field, value in (mapping or {}).items() + if field in BEDROCK_GUARDRAIL_TRACE_FIELDS + } + response.update(traces) + return + for field, value in ((name, getattr(response, name, None)) for name in BEDROCK_GUARDRAIL_TRACE_FIELDS): + if value is not None: + setattr(response, field, _redacted_bedrock_trace(value)) + + def _redact_streaming_response(streaming_response): if hasattr(streaming_response, "choices"): for choice in streaming_response.choices: _redact_choice_content(choice) redact_vertex_ai_metadata_from_logged_object(streaming_response) + if isinstance(streaming_response, litellm.ModelResponse): + _redact_bedrock_guardrail_trace(streaming_response) elif isinstance(streaming_response, litellm.ResponsesAPIResponse): return perform_redaction({}, streaming_response) elif hasattr(streaming_response, "output"): @@ -351,6 +395,7 @@ def _redact_standard_logging_object( if isinstance(response.get("choices"), list): _redact_model_response_dict_choices(response["choices"], redacted_str) redact_vertex_ai_metadata_from_logged_object(response) + _redact_bedrock_guardrail_trace(response) elif isinstance(response, str): standard_logging_object["response"] = redacted_str else: @@ -523,11 +568,13 @@ def perform_redaction(model_call_details: dict, result, redact_streaming_respons for choice in _result.choices: _redact_choice_content(choice) redact_vertex_ai_metadata_from_logged_object(_result) + _redact_bedrock_guardrail_trace(_result) elif isinstance(_result, dict) and "choices" in _result: # Handle dict representation of ModelResponse (e.g., from model_dump()) if _result.get("choices") is not None: _redact_model_response_dict_choices(_result["choices"], REDACTED_BY_LITELLM) redact_vertex_ai_metadata_from_logged_object(_result) + _redact_bedrock_guardrail_trace(_result) elif isinstance(_result, dict) and "output" in _result: return _redacted_responses_api_response(_result, redact_instructions=redact_streaming_responses) elif isinstance(_result, litellm.ResponsesAPIResponse): diff --git a/litellm/litellm_core_utils/renamed_package_shim.py b/litellm/litellm_core_utils/renamed_package_shim.py new file mode 100644 index 00000000000..7f7f39a351a --- /dev/null +++ b/litellm/litellm_core_utils/renamed_package_shim.py @@ -0,0 +1,87 @@ +import importlib +import sys +import warnings +from collections.abc import Callable, Sequence +from importlib.abc import Loader, MetaPathFinder +from importlib.machinery import ModuleSpec +from importlib.util import spec_from_loader +from types import ModuleType +from typing import Final + + +class _AliasLoader(Loader): + """Hand the import system the module already loaded under its new name instead of executing a copy.""" + + def __init__(self, target: ModuleType) -> None: + self._target: Final = target + self._spec: Final = target.__spec__ + + def create_module(self, spec: ModuleSpec) -> ModuleType: + return self._target + + def exec_module(self, module: ModuleType) -> None: + module.__spec__ = self._spec # rebind-ok: the loader restores the spec the import system replaced + + +class _RenamedPackageFinder(MetaPathFinder): + def __init__(self, old_name: str, renames: tuple[tuple[str, str], ...]) -> None: + self._prefix: Final = old_name + "." + self._renames: Final = renames + + def new_name_for(self, old_module_name: str) -> str | None: + if not old_module_name.startswith(self._prefix): + return None + for old_prefix, new_prefix in self._renames: + if old_module_name == old_prefix or old_module_name.startswith(old_prefix + "."): + return new_prefix + old_module_name[len(old_prefix) :] + return None + + def find_spec( + self, + fullname: str, + path: Sequence[str] | None = None, + target: ModuleType | None = None, + ) -> ModuleSpec | None: + new_name: Final = self.new_name_for(fullname) + if new_name is None: + return None + module: Final = importlib.import_module(new_name) + spec: Final = spec_from_loader(fullname, _AliasLoader(module), is_package=hasattr(module, "__path__")) + if spec is not None and spec.submodule_search_locations is not None: + spec.submodule_search_locations = list(module.__path__) # pyright: ignore[reportAny] # module attributes are untyped + return spec + + +def alias_renamed_package( + old_name: str, + new_name: str, + *, + nested_renames: tuple[tuple[str, str], ...] = (), +) -> Callable[[str], ModuleType]: + """Make every module of the package now at ``new_name`` importable under its old dotted name. + + Nothing is imported up front: a meta path finder resolves ``old_name.x.y`` to the module object at + ``new_name.x.y`` the moment something imports it, so a deep import of the old path is the very same object + as the new path and importing one old module loads no more than importing its new counterpart would. + ``nested_renames`` lists (old, new) dotted prefixes for sub-packages that changed name inside the move, + longest first. The returned function is the shim package's module ``__getattr__``, so attribute access on + the old package reaches the renamed sub-packages too. + """ + warnings.warn( + f"{old_name} moved to {new_name}; update imports, the old path will be removed in a future release", + DeprecationWarning, + stacklevel=3, + ) + finder: Final = _RenamedPackageFinder(old_name, (*nested_renames, (old_name, new_name))) + if not any( + isinstance(entry, _RenamedPackageFinder) and entry.new_name_for(old_name + ".x") for entry in sys.meta_path + ): + sys.meta_path.insert(0, finder) + + def getattr_(name: str) -> ModuleType: + try: + return importlib.import_module(f"{old_name}.{name}") + except ModuleNotFoundError as error: + raise AttributeError(f"module {old_name!r} has no attribute {name!r}") from error + + return getattr_ diff --git a/litellm/litellm_core_utils/sensitive_data_masker.py b/litellm/litellm_core_utils/sensitive_data_masker.py index 52758e617d8..8c402fe9b44 100644 --- a/litellm/litellm_core_utils/sensitive_data_masker.py +++ b/litellm/litellm_core_utils/sensitive_data_masker.py @@ -1,4 +1,4 @@ -from collections.abc import Mapping, Sequence +from collections.abc import ItemsView, Mapping, Sequence from collections.abc import Set as AbstractSet from dataclasses import dataclass, field from typing import Any, Final @@ -30,6 +30,10 @@ _DEFAULT_SENSITIVE_PATTERNS: Final = frozenset( ) +def _object_items(data: Mapping[str, object]) -> ItemsView[str, object]: + return data.items() + + class SensitiveDataMasker: def __init__( self, @@ -127,7 +131,7 @@ class SensitiveDataMasker: return data masked_data: Final[dict[str, object]] = {} - for k, v in data.items(): + for k, v in _object_items(data): try: key_is_sensitive = self.is_sensitive_key(k, excluded_keys) if isinstance(v, Mapping): diff --git a/litellm/litellm_core_utils/served_output_texts.py b/litellm/litellm_core_utils/served_output_texts.py index e23db5200a3..854785f304b 100644 --- a/litellm/litellm_core_utils/served_output_texts.py +++ b/litellm/litellm_core_utils/served_output_texts.py @@ -110,7 +110,7 @@ def served_output_texts(response: object) -> ServedTexts | None: def served_stream_output_texts(chunks: Sequence[object]) -> ServedTexts | None: if chunks and all(isinstance(chunk, ModelResponseStream) for chunk in chunks): return _chat_stream_texts(tuple(chunk for chunk in chunks if isinstance(chunk, ModelResponseStream))) - from litellm.llms.anthropic.pass_through.stream_assembly import ( + from litellm.llms.anthropic.messages.stream_assembly import ( assemble_anthropic_sse_stream, is_anthropic_sse_stream, ) diff --git a/litellm/litellm_core_utils/streaming_chunk_builder_utils.py b/litellm/litellm_core_utils/streaming_chunk_builder_utils.py index 39f675099d7..8d243e572fa 100644 --- a/litellm/litellm_core_utils/streaming_chunk_builder_utils.py +++ b/litellm/litellm_core_utils/streaming_chunk_builder_utils.py @@ -12,7 +12,9 @@ from typing_extensions import ReadOnly, Required import litellm from litellm._logging import verbose_logger +from litellm.litellm_core_utils.core_helpers import chunk_usage, provider_reported_usage_cost from litellm.litellm_core_utils.hidden_params import HIDDEN_PARAMS_ATTR, set_hidden_params +from litellm.litellm_core_utils.llm_cost_calc.guardrail_cost import BEDROCK_TRACE_FIELDS, object_items, object_mapping from litellm.litellm_core_utils.prompt_templates.common_utils import ( get_content_from_model_response, # pyright: ignore[reportUnknownVariableType] # response param accepts an untyped dict ) @@ -425,7 +427,7 @@ class ChunkProcessor: if hasattr(chunk["choices"][0], "finish_reason"): chunk_finish_reason = chunk["choices"][0].finish_reason elif "finish_reason" in chunk["choices"][0]: - chunk_finish_reason = chunk["choices"][0]["finish_reason"] + chunk_finish_reason = _CHOICE_FIELD_VALUE.validate_python(chunk["choices"][0]["finish_reason"]) if chunk_finish_reason is not None: finish_reason = chunk_finish_reason @@ -1226,6 +1228,7 @@ def concatenate_base64_list(base64_strings: Sequence[str]) -> str: _CHOICE_DICTS: Final = TypeAdapter(list[dict[str, object]]) +_CHOICE_FIELD_VALUE: Final = TypeAdapter(object) def _text_completion_chunk_from_mapping(chunk: Mapping[str, object]) -> TextCompletionResponse: @@ -1351,14 +1354,27 @@ def stream_chunk_builder_text_completion( _CALCULATOR_PRICED_REPORTED_COST_PROVIDERS: Final = frozenset({LlmProviders.XAI.value}) -def _reported_cost_is_priced_by_calculator(logging_obj: Optional["Logging"]) -> bool: +def _logged_provider(logging_obj: Optional["Logging"]) -> object: if logging_obj is None: - return False + return None provider: Final[object] = logging_obj.model_call_details.get("custom_llm_provider") - return provider in _CALCULATOR_PRICED_REPORTED_COST_PROVIDERS + return provider -def _stream_builder_response_cost(response: ModelResponse, logging_obj: Optional["Logging"]) -> float | None: +def _reported_cost_is_priced_by_calculator(logging_obj: Optional["Logging"]) -> bool: + return _logged_provider(logging_obj) in _CALCULATOR_PRICED_REPORTED_COST_PROVIDERS + + +def _stream_builder_response_cost( + response: ModelResponse, logging_obj: Optional["Logging"], chunks: Sequence[object] +) -> float | None: + if _logged_provider(logging_obj) == LlmProviders.OPENCODE_GO.value: + # usage.opencode only survives on the chunks, the assembled Usage keeps declared fields + reported: Final = ( + provider_reported_usage_cost(chunk_usage(chunk), LlmProviders.OPENCODE_GO.value) + for chunk in reversed(chunks) + ) + return next((cost for cost in reported if cost is not None), None) usage_cost: Final = getattr(getattr(response, "usage", None), "cost", None) if isinstance(usage_cost, (int, float)) and not _reported_cost_is_priced_by_calculator(logging_obj): return float(usage_cost) @@ -1396,8 +1412,10 @@ def _set_hidden_response_cost(response: ModelResponse, response_cost: float) -> hidden_params["response_cost"] = response_cost -def _set_stream_builder_response_cost(response: ModelResponse, logging_obj: Optional["Logging"]) -> None: - response_cost: Final = _stream_builder_response_cost(response, logging_obj) +def _set_stream_builder_response_cost( + response: ModelResponse, logging_obj: Optional["Logging"], chunks: Sequence[object] +) -> None: + response_cost: Final = _stream_builder_response_cost(response, logging_obj, chunks) if response_cost is None: return _set_hidden_response_cost(response, response_cost) @@ -1467,6 +1485,35 @@ def _simple_text_part(choices: Sequence[object]) -> str | None: return content if isinstance(content, str) else "" +_NO_TRACE_FIELDS: Final[Mapping[str, object]] = MappingProxyType({}) + + +def _carry_bedrock_guardrail_trace(chunks: Sequence[object], response: ModelResponse) -> None: + """Bedrock reports a guardrail trace once per stream, on the final metadata chunk, so the built response carries it + under the same field as the non-streaming response (``trace`` on Converse, ``amazon-bedrock-trace`` on Invoke).""" + traced: Final = map(_bedrock_trace_fields, reversed(chunks)) + carried: Final = next((fields for fields in traced if fields), _NO_TRACE_FIELDS) + for field, trace in carried.items(): + setattr(response, field, trace) + + +def _record_bedrock_guardrail_trace( + chunks: Sequence[object], response: ModelResponse, logging_obj: Optional["Logging"] +) -> None: + _carry_bedrock_guardrail_trace(chunks, response) + if logging_obj is not None: + logging_obj.record_native_bedrock_guardrail(response) + + +def _bedrock_trace_fields(chunk: object) -> Mapping[str, object]: + as_mapping: Final = object_mapping(chunk) + raw: Final = ( + as_mapping.get("provider_specific_fields") if as_mapping else getattr(chunk, "provider_specific_fields", None) + ) + fields: Final[Mapping[str, object]] = object_mapping(raw) or {} + return {field: fields[field] for field in BEDROCK_TRACE_FIELDS if field in fields} + + def stream_chunk_builder( chunks: list, messages: Sequence | None = None, @@ -1548,8 +1595,17 @@ def stream_chunk_builder( ) break + _record_bedrock_guardrail_trace( + object_items(chunks), # pyright: ignore[reportUnknownArgumentType] # chunks is an untyped list param + response, + logging_obj, + ) _stamp_streaming_usage_cost(usage, response, logging_obj) - _set_stream_builder_response_cost(response, logging_obj) + _set_stream_builder_response_cost( + response, + logging_obj, + chunks, # pyright: ignore[reportUnknownArgumentType] # legacy chunk list is untyped + ) processor.apply_provider_assembled_streaming_metadata(response, chunks, logging_obj) return response @@ -1733,8 +1789,17 @@ def stream_chunk_builder( break _stamp_streaming_usage_cost(usage, response, logging_obj) - _set_stream_builder_response_cost(response, logging_obj) + _set_stream_builder_response_cost( + response, + logging_obj, + chunks, # pyright: ignore[reportUnknownArgumentType] # legacy chunk list is untyped + ) + _record_bedrock_guardrail_trace( + object_items(chunks), # pyright: ignore[reportUnknownArgumentType] # chunks is an untyped list param + response, + logging_obj, + ) processor.apply_provider_assembled_streaming_metadata(response, chunks, logging_obj) return response except Exception as e: diff --git a/litellm/litellm_core_utils/streaming_handler.py b/litellm/litellm_core_utils/streaming_handler.py index f994baa52b1..8fb602ebeb0 100644 --- a/litellm/litellm_core_utils/streaming_handler.py +++ b/litellm/litellm_core_utils/streaming_handler.py @@ -24,6 +24,7 @@ import litellm from litellm import verbose_logger from litellm._uuid import uuid from litellm.litellm_core_utils.asyncify import asyncify +from litellm.litellm_core_utils.core_helpers import chunk_usage, provider_reported_usage_cost from litellm.litellm_core_utils.hidden_params import ( HIDDEN_PARAMS_ATTR, get_hidden_params, @@ -37,7 +38,6 @@ from litellm.litellm_core_utils.redact_messages import LiteLLMLoggingObject from litellm.litellm_core_utils.thread_pool_executor import executor from litellm.llms.ollama.common_utils import OllamaResponseIdNormalizer from litellm.types.llms.base import LiteLLMBaseModel -from litellm.types.llms.openai import OpenAIChatCompletionChunk from litellm.types.router import GenericLiteLLMParams from litellm.types.utils import ( CacheCreationTokenDetails, @@ -73,7 +73,9 @@ _SYNC_ITER_EXHAUSTED: Final = object() _GCHUNK_FIELDS: Final[frozenset] = frozenset(GChunk.__annotations__) _CompleteStreamingResponse = ModelResponse | TextCompletionResponse | ModelResponseStream | None -_USAGE_COST_HEADER_PROVIDERS: Final[frozenset[str]] = frozenset({LlmProviders.OPENROUTER.value}) +_USAGE_COST_HEADER_PROVIDERS: Final[frozenset[str]] = frozenset( + {LlmProviders.OPENROUTER.value, LlmProviders.OPENCODE_GO.value} +) def _next_sync_or_exhausted(it: Iterator[object]) -> object: @@ -111,14 +113,15 @@ def _prepend_upstream_choice_extras( choice.__pydantic_fields_set__.update(upstream_extras) -def _holds_only_scalars(model: BaseModel) -> bool: - fields: Final[Iterator[tuple[str, object]]] = iter(model) +def _holds_only_scalars(fields: Iterable[tuple[str, object]]) -> bool: return all(value is None or isinstance(value, (str, int, float, bool)) for _, value in fields) -def _delta_from_upstream(upstream_delta: BaseModel | None) -> Delta | None: +def _delta_from_upstream(upstream_delta: "BaseModel | _UpstreamDeltaLike | None") -> Delta | None: if upstream_delta is None: return Delta() + if not isinstance(upstream_delta, BaseModel): + return None try: return Delta(**dict(iter(upstream_delta))) except Exception: @@ -189,6 +192,33 @@ class _DeltaDumpDict(TypedDict): tool_calls: NotRequired[Sequence[Mapping[str, object]]] +class _UpstreamFunctionCallLike(Protocol): + arguments: str | None + + +class _UpstreamToolCallLike(Protocol): + function: _UpstreamFunctionCallLike + + +class _UpstreamDeltaLike(Protocol): + function_call: _UpstreamFunctionCallLike | None + tool_calls: Sequence[_UpstreamToolCallLike] | None + + def __iter__(self) -> Iterator[tuple[str, object]]: ... + + def model_dump(self) -> _DeltaDumpDict: ... + + +class _UpstreamChoiceLike(Protocol): + delta: _UpstreamDeltaLike | None + + +class _UpstreamChunkLike(Protocol): + id: str + choices: Sequence[_UpstreamChoiceLike] + system_fingerprint: str | None + + class _TextCompletionChoiceLike(Protocol): text: str finish_reason: str | None @@ -920,7 +950,7 @@ class CustomStreamWrapper: def copy_model_response_level_provider_specific_fields( self, - original_chunk: ModelResponseStream | OpenAIChatCompletionChunk, + original_chunk: object, model_response: ModelResponseStream, ) -> ModelResponseStream: """ @@ -949,8 +979,8 @@ class CustomStreamWrapper: or ("function_call" in completion_obj and completion_obj["function_call"] is not None) or ( "tool_calls" in model_response.choices[0].delta - and model_response.choices[0].delta["tool_calls"] is not None - and len(model_response.choices[0].delta["tool_calls"]) > 0 + and model_response.choices[0].delta.tool_calls is not None + and len(model_response.choices[0].delta.tool_calls) > 0 ) or ( "function_call" in model_response.choices[0].delta @@ -1115,7 +1145,8 @@ class CustomStreamWrapper: ## check if openai/azure chunk original_chunk: Final = response_obj.get("original_chunk", None) if original_chunk: - if len(original_chunk.choices) > 0: + upstream_chunk: Final[_UpstreamChunkLike] = original_chunk + if len(upstream_chunk.choices) > 0: original_chunk_for_reuse: Final[object] = cast( # cast-ok: runtime type-check before access object, original_chunk, @@ -1151,7 +1182,7 @@ class CustomStreamWrapper: ) else: choices: Final = [] - for choice in original_chunk.choices: + for choice in upstream_chunk.choices: try: if isinstance(choice, BaseModel): choice_json = choice.model_dump() @@ -1164,11 +1195,11 @@ class CustomStreamWrapper: setattr(model_response, "choices", choices) else: return - model_response.system_fingerprint = original_chunk.system_fingerprint + model_response.system_fingerprint = upstream_chunk.system_fingerprint setattr( model_response, "citations", - stored_attribute(original_chunk, "citations"), + stored_attribute(upstream_chunk, "citations"), ) preserve_upstream_non_openai_attributes( model_response=model_response, @@ -1579,6 +1610,8 @@ class CustomStreamWrapper: return _ProviderChunkParsed(response_obj) def chunk_creator(self, chunk: Any): + if isinstance(chunk, ModelResponseStream) and chunk.provider_specific_fields: + self.logging_obj.record_native_bedrock_guardrail(chunk.provider_specific_fields) if self.custom_llm_provider != "cached_response" and isinstance( chunk, (ChatCompletionChunk, ModelResponseStream) ): @@ -1611,7 +1644,9 @@ class CustomStreamWrapper: model_response.model = self.model ## FUNCTION CALL PARSING - original_chunk: Final = response_obj.get("original_chunk") if response_obj is not None else None + original_chunk: Final[_UpstreamChunkLike | None] = ( + response_obj.get("original_chunk") if response_obj is not None else None + ) if ( original_chunk is not None ): # function / tool calling branch - only set for openai/azure compatible endpoints @@ -1623,31 +1658,19 @@ class CustomStreamWrapper: original_chunk, model_response ) if original_chunk.choices and len(original_chunk.choices) > 0: - delta = original_chunk.choices[0].delta + delta: Final = original_chunk.choices[0].delta if delta is not None and (delta.function_call is not None or delta.tool_calls is not None): try: model_response.system_fingerprint = original_chunk.system_fingerprint ## AZURE - check if arguments is not None - if original_chunk.choices[0].delta.function_call is not None: - if ( - getattr( - original_chunk.choices[0].delta.function_call, - "arguments", - ) - is None - ): - original_chunk.choices[0].delta.function_call.arguments = "" - elif original_chunk.choices[0].delta.tool_calls is not None: - if isinstance(original_chunk.choices[0].delta.tool_calls, list): - for t in original_chunk.choices[0].delta.tool_calls: - if hasattr(t, "functions") and hasattr(t.functions, "arguments"): - if ( - getattr( - t.function, - "arguments", - ) - is None - ): + if delta.function_call is not None: + if delta.function_call.arguments is None: + delta.function_call.arguments = "" + elif delta.tool_calls is not None: + if isinstance(delta.tool_calls, list): + for t in delta.tool_calls: + if hasattr(t, "functions") and hasattr(getattr(t, "functions"), "arguments"): + if t.function.arguments is None: t.function.arguments = "" _json_delta: Final[_DeltaDumpDict] = delta.model_dump() if "role" not in _json_delta or _json_delta["role"] is None: @@ -1696,6 +1719,8 @@ class CustomStreamWrapper: model_response.usage = Usage(**chunk_usage.model_dump()) ## RETURN ARG + if isinstance(chunk, ModelResponseStream) and chunk.provider_specific_fields: + self.copy_model_response_level_provider_specific_fields(chunk, model_response) result: Final = self.return_processed_chunk_logic( completion_obj=completion_obj, model_response=model_response, @@ -1886,7 +1911,7 @@ class CustomStreamWrapper: else: asyncio.run(self.logging_obj.async_success_handler(processed_chunk, None, None, cache_hit)) ## SYNC LOGGING — only for sync SDK entrypoints; async proxy paths export via async_success_handler - litellm_params: Final = self.logging_obj.model_call_details.get("litellm_params", {}) + litellm_params: Final[Mapping[str, object]] = self.logging_obj.model_call_details.get("litellm_params", {}) if self.logging_obj.is_sync_litellm_request(litellm_params): self.logging_obj.success_handler(processed_chunk, None, None, cache_hit) @@ -1935,11 +1960,17 @@ class CustomStreamWrapper: def _propagate_usage_cost_to_hidden_params( response: "ModelResponse", custom_llm_provider: str | None, + chunks: Sequence[object] = (), ) -> None: + """The builder's usage only keeps declared fields, so provider blocks like usage.opencode are read off the chunks.""" if custom_llm_provider not in _USAGE_COST_HEADER_PROVIDERS: return - _usage: Final[Usage | None] = getattr(response, "usage", None) - _cost: Final = CustomStreamWrapper._resolve_provider_reported_cost(getattr(_usage, "cost", None)) + usages: Final = ( + getattr(response, "usage", None), + *(chunk_usage(chunk) for chunk in reversed(chunks)), + ) + costs: Final = (provider_reported_usage_cost(usage, custom_llm_provider) for usage in usages) + _cost: Final = next((cost for cost in costs if cost is not None), None) if _cost is not None: if "additional_headers" not in response.hidden_params: response.hidden_params["additional_headers"] = {} @@ -2081,7 +2112,9 @@ class CustomStreamWrapper: complete_streaming_response: Final = self._build_complete_streaming_response() response = self._new_usage_chunk() if complete_streaming_response is not None: - self._propagate_usage_cost_to_hidden_params(complete_streaming_response, self.custom_llm_provider) + self._propagate_usage_cost_to_hidden_params( + complete_streaming_response, self.custom_llm_provider, self.chunks + ) setattr( response, @@ -2300,7 +2333,9 @@ class CustomStreamWrapper: complete_streaming_response: Final = await self._async_build_complete_streaming_response() response: Final = self._new_usage_chunk() if complete_streaming_response is not None: - self._propagate_usage_cost_to_hidden_params(complete_streaming_response, self.custom_llm_provider) + self._propagate_usage_cost_to_hidden_params( + complete_streaming_response, self.custom_llm_provider, self.chunks + ) setattr( response, diff --git a/litellm/litellm_core_utils/token_counter.py b/litellm/litellm_core_utils/token_counter.py index 8aded69aed2..edb5ecf0f8d 100644 --- a/litellm/litellm_core_utils/token_counter.py +++ b/litellm/litellm_core_utils/token_counter.py @@ -44,7 +44,7 @@ from litellm.litellm_core_utils.tokenizer import HuggingFaceTokenizer, OpenAIEnc if TYPE_CHECKING: from litellm.litellm_core_utils.tokenizer import Encoding, HuggingFace from litellm.litellm_core_utils.url_utils import safe_get -from litellm.llms.custom_httpx.http_handler import get_httpx_client +from litellm.llms.custom_httpx.http_handler import get_httpx_client, header_value from litellm.rust_bridge.tokenizer import get_encoding from litellm.types.llms.anthropic import ( AnthropicContentParamSource, @@ -59,7 +59,6 @@ from litellm.types.llms.anthropic import ( from litellm.types.llms.openai import ( AllMessageValues, ChatCompletionDocumentObject, - ChatCompletionNamedToolChoiceParam, ChatCompletionRedactedThinkingBlock, ChatCompletionThinkingBlock, ChatCompletionToolParam, @@ -247,7 +246,7 @@ def get_image_dimensions( client: Final = get_httpx_client() response: Final[httpx.Response] = safe_get(client, data) max_bytes: Final = int(MAX_IMAGE_URL_DOWNLOAD_SIZE_MB * 1024 * 1024) - content_length: Final[str | None] = response.headers.get("Content-Length") + content_length: Final[str | None] = header_value(response.headers, "Content-Length") if content_length is not None and int(content_length) > max_bytes: pass # skip download; img_data stays None else: @@ -261,6 +260,10 @@ def get_image_dimensions( _header, encoded = data.split(",", 1) img_data = base64.b64decode(encoded) + return _image_dimensions_from_bytes(img_data) + + +def _image_dimensions_from_bytes(img_data: bytes) -> tuple[int, int]: img_type: Final = get_image_type(img_data) if img_type == "png": @@ -307,8 +310,37 @@ def get_image_dimensions( return DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT +def _auto_image_dimensions(data: str) -> tuple[int, int] | None: + """Read bounded inline image data without fetching caller-supplied URLs.""" + if not data.startswith("data:image/"): + return None + max_bytes: Final = int(MAX_IMAGE_URL_DOWNLOAD_SIZE_MB * 1024 * 1024) + max_encoded_length: Final = 4 * ((max_bytes + 2) // 3) + # Bound allocations before splitting or decoding the data URL, including its header. + if max_bytes <= 0 or len(data) > max_encoded_length + 128: + return None + header, separator, encoded = data.partition(",") + if not separator or len(header) > 128 or not header.endswith(";base64") or len(encoded) > max_encoded_length: + return None + try: + image_data: Final = base64.b64decode(encoded, validate=True) + if len(image_data) > max_bytes or get_image_type(image_data) not in ( + "png", + "gif", + "jpeg", + "webp", + ): + return None + width, height = _image_dimensions_from_bytes(image_data) + except (ValueError, TypeError, struct.error): + return None + if width <= 0 or height <= 0: + return None + return width, height + + def calculate_img_tokens( - data, + data: str, mode: Literal["low", "high", "auto"] = "auto", base_tokens: int = 85, # openai default - https://openai.com/pricing use_default_image_token_count: bool = False, @@ -318,7 +350,8 @@ def calculate_img_tokens( Args: data (str): The URL or base64 encoded string of the image. - mode (Literal["low", "high", "auto"]): The mode to use for calculating the number of tokens. + mode (Literal["low", "high", "auto"]): Auto uses high-detail tiles for readable inline images; + URLs and unreadable images keep the base estimate without network I/O. base_tokens (int): The base number of tokens for an image. use_default_image_token_count (bool): When True, will NOT make a GET request to the image URL and instead return the default image dimensions. @@ -328,18 +361,19 @@ def calculate_img_tokens( if use_default_image_token_count: verbose_logger.debug("Using default image token count: %s", DEFAULT_IMAGE_TOKEN_COUNT) return DEFAULT_IMAGE_TOKEN_COUNT - if mode == "low" or mode == "auto": + if mode == "low": return base_tokens - elif mode == "high": - # Run the async function using the helper - width, height = get_image_dimensions( - data=data, - ) - resized_width, resized_height = resize_image_high_res(width=width, height=height) - tiles_needed_high_res = calculate_tiles_needed(resized_width=resized_width, resized_height=resized_height) - tile_tokens: Final = (base_tokens * 2) * tiles_needed_high_res - total_tokens: Final = base_tokens + tile_tokens - return total_tokens + if mode not in ("auto", "high"): + return None + dimensions: Final = _auto_image_dimensions(data) if mode == "auto" else get_image_dimensions(data=data) + if dimensions is None: + return base_tokens + width, height = dimensions + resized_width, resized_height = resize_image_high_res(width=width, height=height) + tiles_needed_high_res = calculate_tiles_needed(resized_width=resized_width, resized_height=resized_height) + tile_tokens: Final = (base_tokens * 2) * tiles_needed_high_res + total_tokens: Final = base_tokens + tile_tokens + return total_tokens TokenCounterFunction = Callable[[str], int] @@ -421,7 +455,7 @@ def token_counter( messages: Sequence[AllMessageValues | Message] | None = None, count_response_tokens: bool | None = False, tools: list[ChatCompletionToolParam] | None = None, - tool_choice: ChatCompletionNamedToolChoiceParam | None = None, + tool_choice: str | Mapping[str, object] | None = None, use_default_image_token_count: bool | None = False, default_token_count: int | None = None, ) -> int: @@ -601,7 +635,7 @@ def _count_messages( def _count_extra( count_function: TokenCounterFunction, tools: list[ChatCompletionToolParam] | None, - tool_choice: ChatCompletionNamedToolChoiceParam | None, + tool_choice: str | Mapping[str, object] | None, includes_system_message: bool, tool_section: ChatTemplateToolSection | None, ) -> int: @@ -638,13 +672,19 @@ def _count_tool_definitions( def _count_tool_choice( count_function: TokenCounterFunction, - tool_choice: ChatCompletionNamedToolChoiceParam | None, + tool_choice: str | Mapping[str, object] | None, ) -> int: - if tool_choice == "none": - return 1 - if isinstance(tool_choice, dict): - return 7 + count_function(str(tool_choice["function"]["name"])) - return 0 + match tool_choice: + case "none": + return 1 + case {"function": {"name": str() as name}}: + return 7 + count_function(name) + case {"type": "none"}: + return 1 + case {"name": str() as name}: + return 7 + count_function(name) + case _: + return 0 def _count_chat_template_tools( diff --git a/litellm/litellm_core_utils/url_utils.py b/litellm/litellm_core_utils/url_utils.py index 4a1eaa87d3a..0db6a41b503 100644 --- a/litellm/litellm_core_utils/url_utils.py +++ b/litellm/litellm_core_utils/url_utils.py @@ -22,11 +22,11 @@ Admins can opt out via two ``litellm`` globals (wired from proxy config): import asyncio import socket from ipaddress import ip_address, ip_network -from typing import Any, Final, Protocol +from typing import Final, Protocol from urllib.parse import quote, urlparse, urlsplit, urlunparse import httpx -from typing_extensions import ReadOnly, TypedDict +from typing_extensions import ReadOnly, TypedDict, Unpack import litellm @@ -50,6 +50,7 @@ class _UrlFetcher(Protocol): *, headers: dict[str, str] | None = None, follow_redirects: bool = False, + timeout: float | httpx.Timeout | None = None, ) -> httpx.Response: ... @@ -62,6 +63,8 @@ class _AsyncUrlFetcher(Protocol): *, headers: dict[str, str] | None = None, follow_redirects: bool = False, + timeout: float | httpx.Timeout | None = None, + max_response_bytes: int | None = None, ) -> httpx.Response: ... @@ -73,8 +76,14 @@ class _AsyncFetcherView(TypedDict): fetcher: ReadOnly[_AsyncUrlFetcher] -class _CallerHeadersView(TypedDict): +class _FetchOptions(TypedDict, total=False): headers: ReadOnly[dict[str, str]] + follow_redirects: ReadOnly[bool] + timeout: ReadOnly[float | httpx.Timeout | None] + + +class _AsyncFetchOptions(_FetchOptions, total=False): + max_response_bytes: ReadOnly[int | None] # Cloud-internal IPs that ``ip.is_global`` can report as public. Everything @@ -440,7 +449,7 @@ def _extract_redirect_url(response: httpx.Response, request_url: str) -> str: return str(httpx.URL(request_url).join(location)) -def safe_get(client: _UrlFetcher, url: str, **kwargs: Any) -> httpx.Response: +def safe_get(client: _UrlFetcher, url: str, **kwargs: Unpack[_FetchOptions]) -> httpx.Response: """ Fetch a user-supplied URL with SSRF protection on every redirect hop. @@ -460,21 +469,23 @@ def safe_get(client: _UrlFetcher, url: str, **kwargs: Any) -> httpx.Response: The final httpx.Response. """ if not getattr(litellm, "user_url_validation", True): - kwargs.setdefault("follow_redirects", True) - unvalidated: Final[_ResponseView] = {"response": client.get(url, **kwargs)} + unvalidated_options: Final[_FetchOptions] = { + **kwargs, + "follow_redirects": kwargs.get("follow_redirects", True), + } + unvalidated: Final[_ResponseView] = {"response": client.get(url, **unvalidated_options)} return unvalidated["response"] fetcher_view: Final[_FetcherView] = {"fetcher": client} fetcher: Final = fetcher_view["fetcher"] - kwargs.pop("follow_redirects", None) - headers_view: Final[_CallerHeadersView] = {"headers": kwargs.pop("headers", {})} + caller_headers: Final = kwargs.get("headers", {}) for _ in range(_MAX_REDIRECTS): validated_url, original_host = validate_url(url) - response = fetcher.get( - validated_url, - headers={**headers_view["headers"], "Host": original_host}, - follow_redirects=False, + hop_options: _FetchOptions = { **kwargs, - ) + "headers": {**caller_headers, "Host": original_host}, + "follow_redirects": False, + } + response = fetcher.get(validated_url, **hop_options) if not response.is_redirect: return response # Resolve the next hop against the ORIGINAL (pre-rewrite) URL so @@ -483,24 +494,26 @@ def safe_get(client: _UrlFetcher, url: str, **kwargs: Any) -> httpx.Response: raise SSRFError("Too many redirects") -async def async_safe_get(client: _AsyncUrlFetcher, url: str, **kwargs: Any) -> httpx.Response: +async def async_safe_get(client: _AsyncUrlFetcher, url: str, **kwargs: Unpack[_AsyncFetchOptions]) -> httpx.Response: """Async version of safe_get.""" if not getattr(litellm, "user_url_validation", True): - kwargs.setdefault("follow_redirects", True) - unvalidated: Final[_ResponseView] = {"response": await client.get(url, **kwargs)} + unvalidated_options: Final[_AsyncFetchOptions] = { + **kwargs, + "follow_redirects": kwargs.get("follow_redirects", True), + } + unvalidated: Final[_ResponseView] = {"response": await client.get(url, **unvalidated_options)} return unvalidated["response"] fetcher_view: Final[_AsyncFetcherView] = {"fetcher": client} fetcher: Final = fetcher_view["fetcher"] - kwargs.pop("follow_redirects", None) - headers_view: Final[_CallerHeadersView] = {"headers": kwargs.pop("headers", {})} + caller_headers: Final = kwargs.get("headers", {}) for _ in range(_MAX_REDIRECTS): validated_url, original_host = await asyncio.to_thread(validate_url, url) - response = await fetcher.get( - validated_url, - headers={**headers_view["headers"], "Host": original_host}, - follow_redirects=False, + hop_options: _AsyncFetchOptions = { **kwargs, - ) + "headers": {**caller_headers, "Host": original_host}, + "follow_redirects": False, + } + response = await fetcher.get(validated_url, **hop_options) if not response.is_redirect: return response # Resolve the next hop against the ORIGINAL (pre-rewrite) URL so diff --git a/litellm/llms/__init__.py b/litellm/llms/__init__.py index 7452a4a20ef..c18ce8cea68 100644 --- a/litellm/llms/__init__.py +++ b/litellm/llms/__init__.py @@ -3,6 +3,7 @@ import os from typing import TYPE_CHECKING, Final from litellm._logging import verbose_logger +from litellm.litellm_core_utils.core_helpers import attribute_or_none from litellm.types.utils import CallTypes from . import * @@ -128,7 +129,7 @@ def discover_guardrail_translation_mappings() -> dict[CallTypes, type["BaseTrans # Check for guardrail_translation_mappings dictionary if hasattr(module, "guardrail_translation_mappings"): - mappings = getattr(module, "guardrail_translation_mappings") + mappings = attribute_or_none(module, "guardrail_translation_mappings") if isinstance(mappings, dict): discovered_mappings.update(mappings) verbose_logger.debug( @@ -143,7 +144,7 @@ def discover_guardrail_translation_mappings() -> dict[CallTypes, type["BaseTrans continue try: - from litellm.proxy._experimental.mcp_server.guardrail_translation import ( + from litellm.proxy.mcp_server.guardrail_translation import ( guardrail_translation_mappings as mcp_guardrail_translation_mappings, ) diff --git a/litellm/llms/a2a/common_utils.py b/litellm/llms/a2a/common_utils.py index 1818b406823..633ea73bb16 100644 --- a/litellm/llms/a2a/common_utils.py +++ b/litellm/llms/a2a/common_utils.py @@ -31,6 +31,10 @@ class A2AError(BaseLLMException): ) +def _message_role(message: Mapping[str, object]) -> object: + return message.get("role", "user") + + def convert_messages_to_prompt(messages: list[AllMessageValues]) -> str: """ Convert OpenAI messages to a single prompt string for A2A agent. @@ -51,7 +55,7 @@ def convert_messages_to_prompt(messages: list[AllMessageValues]) -> str: # Get role if isinstance(msg, BaseModel): - role = msg.model_dump().get("role", "user") + role = _message_role(msg.model_dump()) elif isinstance(msg, dict): role = msg.get("role", "user") else: diff --git a/litellm/llms/ai21/chat/transformation.py b/litellm/llms/ai21/chat/transformation.py index 2b8c36d0085..e78cc77c0fc 100644 --- a/litellm/llms/ai21/chat/transformation.py +++ b/litellm/llms/ai21/chat/transformation.py @@ -4,6 +4,8 @@ AI21 Chat Completions API this is OpenAI compatible - no translation needed / occurs """ +from collections.abc import Mapping +from types import MappingProxyType from typing import Final from ...openai_like.chat.transformation import OpenAILikeChatConfig @@ -41,7 +43,7 @@ class AI21ChatConfig(OpenAILikeChatConfig): tool_choice: str | None = None, user: str | None = None, ) -> None: - locals_: Final = locals().copy() + locals_: Final[Mapping[str, object]] = MappingProxyType(locals().copy()) for key, value in locals_.items(): if key != "self" and value is not None: setattr(self.__class__, key, value) diff --git a/litellm/llms/amazon_nova/chat/transformation.py b/litellm/llms/amazon_nova/chat/transformation.py index a93fbf1e933..4ef729bc76d 100644 --- a/litellm/llms/amazon_nova/chat/transformation.py +++ b/litellm/llms/amazon_nova/chat/transformation.py @@ -2,6 +2,8 @@ Translate from OpenAI's `/v1/chat/completions` to Amazon Nova's `/v1/chat/completions` """ +from collections.abc import Mapping +from types import MappingProxyType from typing import TYPE_CHECKING, Final import httpx @@ -38,7 +40,7 @@ class AmazonNovaChatConfig(OpenAILikeChatConfig): tools: list | None = None, reasoning_effort: list | None = None, ) -> None: - locals_: Final = locals().copy() + locals_: Final[Mapping[str, object]] = MappingProxyType(locals().copy()) for key, value in locals_.items(): if key != "self" and value is not None: setattr(self.__class__, key, value) diff --git a/litellm/llms/anthropic/batches/handler.py b/litellm/llms/anthropic/batches/handler.py index 3f3716e0de6..a9d9f930b9e 100644 --- a/litellm/llms/anthropic/batches/handler.py +++ b/litellm/llms/anthropic/batches/handler.py @@ -132,7 +132,7 @@ class AnthropicBatchesHandler: max_retries: int | None, logging_obj: LiteLLMLoggingObj | None = None, litellm_params: dict | None = None, # mutable-ok: handed straight to validate_environment - ) -> LiteLLMBatch | Coroutine[Any, Any, LiteLLMBatch]: + ) -> LiteLLMBatch | Coroutine[object, object, LiteLLMBatch]: """ Retrieve a batch from Anthropic. diff --git a/litellm/llms/anthropic/chat/guardrail_translation/handler.py b/litellm/llms/anthropic/chat/guardrail_translation/handler.py index 4c6bded68ea..d371aab4581 100644 --- a/litellm/llms/anthropic/chat/guardrail_translation/handler.py +++ b/litellm/llms/anthropic/chat/guardrail_translation/handler.py @@ -26,18 +26,18 @@ from typing_extensions import ReadOnly, TypedDict, assert_never from litellm._logging import verbose_proxy_logger from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.llms.anthropic.chat.transformation import AnthropicConfig -from litellm.llms.anthropic.pass_through.adapters.transformation import ( +from litellm.llms.anthropic.messages.adapters.transformation import ( OPENAI_MAX_TOOL_NAME_LENGTH, LiteLLMAnthropicMessagesAdapter, is_provider_native_tool_dict, truncate_tool_name, ) -from litellm.llms.anthropic.pass_through.convertible_blocks import ( +from litellm.llms.anthropic.messages.convertible_blocks import ( keep_non_string_tool_result_texts, scannable_tool_result_request, ) -from litellm.llms.anthropic.pass_through.messages.utils import filtered_safeguard_results, redacted_stop_details -from litellm.llms.anthropic.pass_through.stream_assembly import ( +from litellm.llms.anthropic.messages.native.utils import filtered_safeguard_results, redacted_stop_details +from litellm.llms.anthropic.messages.stream_assembly import ( build_complete_streaming_response, build_usage_only_response_from_chunks, ) @@ -435,7 +435,7 @@ class AnthropicMessagesHandler(BaseTranslation): def _standalone_block_chunks(self, exc: "ModifyResponseException") -> list[bytes]: import uuid - from litellm.llms.anthropic.pass_through.messages.fake_stream_iterator import ( + from litellm.llms.anthropic.messages.native.fake_stream_iterator import ( FakeAnthropicMessagesStreamIterator, ) from litellm.llms.base_llm.guardrail_translation.utils import ( @@ -1697,14 +1697,13 @@ class AnthropicMessagesHandler(BaseTranslation): if not line.startswith("data:"): return line try: - data: Final[str | int | float | bool | None | Sequence[object] | Mapping[str, object]] = json.loads( - line[len("data:") :].strip() - ) + data: Final = _DECODED_SSE_DATA.validate_python(json.loads(line[len("data:") :].strip())) except json.JSONDecodeError: return line - if not isinstance(data, dict): + event: Final = as_str_mapping(data) + if not isinstance(event, dict): return line - rewritten: Final = _rewritten_event(_as_str_mapping(data), rewrite_event) + rewritten: Final = _rewritten_event(event, rewrite_event) return line if rewritten is data else "data: " + json.dumps(rewritten) def get_streaming_scan_key(self, responses_so_far: Sequence[object]) -> StreamingScanKey | None: diff --git a/litellm/llms/anthropic/chat/transformation.py b/litellm/llms/anthropic/chat/transformation.py index 9a63afd5cc0..92e7c84031c 100644 --- a/litellm/llms/anthropic/chat/transformation.py +++ b/litellm/llms/anthropic/chat/transformation.py @@ -831,6 +831,7 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig): "else": "conditional (else): {}", "not": "must not match: {}", } + schema_fields: Final[Mapping[str, object]] = MappingProxyType(schema) min_items: Final = schema.get("minItems") enforced_min_items: Final = ( isinstance(min_items, int) and not isinstance(min_items, bool) and min_items in (0, 1) @@ -845,7 +846,7 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig): for field, label in constraint_labels.items(): if field not in schema or field not in unsupported_fields: continue - value = schema[field] + value = schema_fields[field] # A falsy boolean constraint (e.g. ``uniqueItems: false``) imposes no # real requirement, so don't add a misleading advisory note for it. if isinstance(value, bool) and not value: @@ -869,7 +870,7 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig): drops_conflicting_type: Final = _enum_conflicts_with_declared_type(schema) - for key, value in schema.items(): + for key, value in schema_fields.items(): if key in unsupported_fields: continue if key == "type" and drops_conflicting_type: @@ -2385,7 +2386,7 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig): optional_params["tools"] = tools ## Load Config - config: Final = litellm.AnthropicConfig.get_config(model=model) + config: Final[Mapping[str, object]] = MappingProxyType(litellm.AnthropicConfig.get_config(model=model)) for k, v in config.items(): if ( k not in optional_params diff --git a/litellm/llms/anthropic/completion/transformation.py b/litellm/llms/anthropic/completion/transformation.py index 73e94e85f04..5cc4e955d00 100644 --- a/litellm/llms/anthropic/completion/transformation.py +++ b/litellm/llms/anthropic/completion/transformation.py @@ -7,6 +7,7 @@ Litellm provider slug: `anthropic_text/` import json import time from collections.abc import AsyncIterator, Iterator, Mapping +from types import MappingProxyType from typing import TYPE_CHECKING, Final import httpx @@ -112,7 +113,7 @@ class AnthropicTextConfig(BaseConfig): ) -> dict: prompt: Final = self._get_anthropic_text_prompt_from_messages(messages=messages, model=model) ## Load Config - config: Final = litellm.AnthropicTextConfig.get_config() + config: Final[Mapping[str, object]] = MappingProxyType(litellm.AnthropicTextConfig.get_config()) for k, v in config.items(): if ( k not in optional_params diff --git a/litellm/llms/anthropic/count_tokens/transformation.py b/litellm/llms/anthropic/count_tokens/transformation.py index c2d87c641be..eb8e595c849 100644 --- a/litellm/llms/anthropic/count_tokens/transformation.py +++ b/litellm/llms/anthropic/count_tokens/transformation.py @@ -162,7 +162,7 @@ def _has_non_chat_user_block(message: Mapping[str, object]) -> bool: def _gets_placeholder_name(tool: Mapping[str, object]) -> bool: - from litellm.llms.anthropic.pass_through.adapters.transformation import is_provider_native_tool_dict + from litellm.llms.anthropic.messages.adapters.transformation import is_provider_native_tool_dict name: Final = tool.get("name") return not (_is_chat_tool(tool) or is_provider_native_tool_dict(tool) or (isinstance(name, str) and name.strip())) diff --git a/litellm/llms/anthropic/files/handler.py b/litellm/llms/anthropic/files/handler.py index 1a793e32317..279fb92cf6c 100644 --- a/litellm/llms/anthropic/files/handler.py +++ b/litellm/llms/anthropic/files/handler.py @@ -5,6 +5,7 @@ from collections.abc import Coroutine, Mapping from typing import Final import httpx +from pydantic import TypeAdapter import litellm from litellm._logging import verbose_logger @@ -24,6 +25,8 @@ from litellm.types.utils import CallTypes, LlmProviders, ModelResponse from ..chat.transformation import AnthropicConfig from ..common_utils import ANTHROPIC_ERROR_STATUS_CODE_MAP, AnthropicModelInfo +_DECODED_JSON: Final = TypeAdapter(object) + class AnthropicFilesHandler: """ @@ -194,7 +197,7 @@ class AnthropicFilesHandler: if not line.strip(): continue - anthropic_result: object = json.loads(line) + anthropic_result: object = _DECODED_JSON.validate_python(json.loads(line)) if not isinstance(anthropic_result, dict): raise TypeError( f"Anthropic batch result line is not a JSON object: {type(anthropic_result).__name__}" diff --git a/litellm/llms/anthropic/pass_through/adapters/__init__.py b/litellm/llms/anthropic/messages/adapters/__init__.py similarity index 100% rename from litellm/llms/anthropic/pass_through/adapters/__init__.py rename to litellm/llms/anthropic/messages/adapters/__init__.py diff --git a/litellm/llms/anthropic/pass_through/adapters/handler.py b/litellm/llms/anthropic/messages/adapters/handler.py similarity index 98% rename from litellm/llms/anthropic/pass_through/adapters/handler.py rename to litellm/llms/anthropic/messages/adapters/handler.py index 01e781485a0..71ccfbaf915 100644 --- a/litellm/llms/anthropic/pass_through/adapters/handler.py +++ b/litellm/llms/anthropic/messages/adapters/handler.py @@ -15,23 +15,23 @@ from litellm._logging import verbose_logger from litellm.litellm_core_utils.asyncify import run_async_function from litellm.litellm_core_utils.core_helpers import drops_unsupported_params from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObject -from litellm.llms.anthropic.pass_through.adapters.transformation import ( +from litellm.llms.anthropic.messages.adapters.transformation import ( AnthropicAdapter, ) -from litellm.llms.anthropic.pass_through.context_management import ( +from litellm.llms.anthropic.messages.context_management import ( AnthropicContextManagementError, PolyfillResult, apply_context_management, ) -from litellm.llms.anthropic.pass_through.convertible_blocks import reject_malformed_tool_result_text -from litellm.llms.anthropic.pass_through.safeguards import ( +from litellm.llms.anthropic.messages.convertible_blocks import reject_malformed_tool_result_text +from litellm.llms.anthropic.messages.safeguards import ( SafeguardsEvaluator, build_safeguards_evaluator, read_classifier_model_setting, requested_dangerous_tool_use, with_safeguard_results, ) -from litellm.llms.anthropic.pass_through.utils import ( +from litellm.llms.anthropic.messages.utils import ( ProxySubCallLoggingKwargs, is_reasoning_auto_summary_enabled, litellm_logging_obj_from_kwargs, @@ -158,7 +158,7 @@ async def prepare_context_managed_request( drop_invalid_edits: bool = False, ) -> PolyfillResult | None: """Apply client compaction history, then optional context_management polyfill.""" - from litellm.llms.anthropic.pass_through.context_management.editors.compact import ( + from litellm.llms.anthropic.messages.context_management.editors.compact import ( apply_client_compaction_block_history, ) @@ -239,7 +239,7 @@ def _polyfill_will_run( if edits is None: return False - from litellm.llms.anthropic.pass_through.context_management.constants import ( + from litellm.llms.anthropic.messages.context_management.constants import ( COMPACT_EDIT_TYPE, ) @@ -265,7 +265,7 @@ def _spec_has_non_compact_edits( if edits is None: return False - from litellm.llms.anthropic.pass_through.context_management.constants import ( + from litellm.llms.anthropic.messages.context_management.constants import ( COMPACT_EDIT_TYPE, ) @@ -298,7 +298,7 @@ def _normalize_spec_edits( if context_management_explicitly_dropped(additional_drop_params): return None - from litellm.llms.anthropic.pass_through.context_management.dispatcher import ( + from litellm.llms.anthropic.messages.context_management.dispatcher import ( normalize_spec, ) @@ -543,7 +543,7 @@ class LiteLLMMessagesToCompletionTransformationHandler: Handles both string ("max") and dict ({"effort": "max", "summary": ...}) formats. Uses model registry to check supports_xhigh/supports_minimal. """ - from litellm.llms.anthropic.pass_through.utils import ( + from litellm.llms.anthropic.messages.utils import ( normalize_reasoning_effort_value, ) @@ -806,6 +806,7 @@ class LiteLLMMessagesToCompletionTransformationHandler: tool_name_mapping=tool_name_mapping, polyfill_result=polyfill_result, is_async=True, + completion_request=completion_kwargs, litellm_logging_obj=logging_obj, safeguards_evaluator=safeguards_evaluator, ) @@ -952,6 +953,7 @@ class LiteLLMMessagesToCompletionTransformationHandler: tool_name_mapping=tool_name_mapping, polyfill_result=polyfill_result, is_async=False, + completion_request=completion_kwargs, litellm_logging_obj=logging_obj, ) if transformed_stream is not None: diff --git a/litellm/llms/anthropic/pass_through/adapters/streaming_iterator.py b/litellm/llms/anthropic/messages/adapters/streaming_iterator.py similarity index 95% rename from litellm/llms/anthropic/pass_through/adapters/streaming_iterator.py rename to litellm/llms/anthropic/messages/adapters/streaming_iterator.py index e9fd77ef441..62a1e5f0a97 100644 --- a/litellm/llms/anthropic/pass_through/adapters/streaming_iterator.py +++ b/litellm/llms/anthropic/messages/adapters/streaming_iterator.py @@ -22,13 +22,14 @@ from typing import ( from pydantic import TypeAdapter from typing_extensions import assert_never +import litellm from litellm._logging import verbose_logger from litellm._uuid import uuid from litellm.exceptions import ContextWindowExceededError, MidStreamFallbackError -from litellm.litellm_core_utils.core_helpers import as_str_mapping +from litellm.litellm_core_utils.core_helpers import as_str_mapping, attribute_items from litellm.litellm_core_utils.hidden_params import set_hidden_params -from litellm.llms.anthropic.pass_through.safeguards import StreamedSafeguardResults -from litellm.llms.anthropic.pass_through.utils import anthropic_sse_frame +from litellm.llms.anthropic.messages.safeguards import StreamedSafeguardResults +from litellm.llms.anthropic.messages.utils import anthropic_sse_frame from litellm.llms.base_llm.chat.transformation import BaseLLMException from litellm.types.llms.anthropic import ( AppliedEdit, @@ -41,19 +42,25 @@ from litellm.types.llms.anthropic import ( UsageDelta, UsageIteration, ) -from litellm.types.llms.openai import ChatCompletionRedactedThinkingBlock, ChatCompletionThinkingBlock +from litellm.types.llms.openai import ( + AllMessageValues, + ChatCompletionRedactedThinkingBlock, + ChatCompletionThinkingBlock, + ChatCompletionToolParam, +) from litellm.types.utils import AdapterCompletionStreamWrapper, ChatCompletionDeltaToolCall, Delta, Function if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObject - from litellm.llms.anthropic.pass_through.safeguards import SafeguardsEvaluator - from litellm.types.llms.openai import AllMessageValues + from litellm.llms.anthropic.messages.safeguards import SafeguardsEvaluator from litellm.types.utils import ModelResponseStream _STREAMING_DELTA_TYPES: Final = frozenset(get_args(StreamingContentBlockDeltaType)) _SSE_EVENT: Final = TypeAdapter(Mapping[str, object]) _THINKING_BLOCK: Final = TypeAdapter(ChatCompletionThinkingBlock | ChatCompletionRedactedThinkingBlock) +_PROMPT_MESSAGES: Final = TypeAdapter(list[AllMessageValues]) +_PROMPT_TOOLS: Final = TypeAdapter(list[ChatCompletionToolParam]) class _UsageDeltaWithIterations(UsageDelta, total=False): @@ -66,6 +73,11 @@ class _ChunkStream(Protocol): def __aiter__(self) -> "AsyncIterator[ModelResponseStream]": ... +@runtime_checkable +class _AsyncCloseable(Protocol): + async def aclose(self) -> None: ... + + @runtime_checkable class _FailureLoggingWaiter(Protocol): @property @@ -197,6 +209,14 @@ class _CombinedChunkSplitter: self._buffer: deque[ModelResponseStream] = deque() self._held_calls: Mapping[int, tuple[ModelResponseStream, _ToolCallPart]] = MappingProxyType({}) self._live_call_index: int | None = None + self._closed = False + + async def aclose(self) -> None: + if self._closed: + return + self._closed = True + if isinstance(self._stream, _AsyncCloseable): + await self._stream.aclose() @property def has_dispatched_failure_logging(self) -> bool: @@ -221,7 +241,7 @@ class _CombinedChunkSplitter: @staticmethod def _is_combined(chunk: "ModelResponseStream") -> bool: """True if ``chunk`` carries response content AND a finish_reason.""" - from litellm.llms.anthropic.pass_through.messages.utils import ( + from litellm.llms.anthropic.messages.native.utils import ( openai_chat_refusal_text, ) @@ -535,6 +555,7 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): iterations_usage: list[UsageIteration] | None = None, litellm_logging_obj: "LiteLLMLoggingObject | None" = None, safeguards_evaluator: "SafeguardsEvaluator | None" = None, + completion_request: Mapping[str, object] | None = None, ): # Wrap the upstream stream so chunks that carry both content and a # finish_reason (fake-streamed providers) are split into two — see @@ -543,6 +564,7 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): super().__init__(combined_chunk_splitter) self._combined_chunk_splitter: Final = combined_chunk_splitter self.model = model + self.completion_request: Final = completion_request self._message_id: str = f"msg_{uuid.uuid4()}" if litellm_logging_obj is not None: litellm_logging_obj.record_streamed_anthropic_message_id(self._message_id) @@ -739,25 +761,42 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): def _create_initial_usage_delta(self) -> UsageDelta: """ - Create the initial UsageDelta for the message_start event. + Optionally estimate prompt tokens without consuming upstream chunks. - Initializes cache token fields (cache_creation_input_tokens, cache_read_input_tokens) - to 0 to indicate to clients (like Claude Code) that prompt caching is supported. - - The actual cache token values will be provided in the message_delta event at the - end of the stream, since Bedrock Converse API only returns usage data in the final - response chunk. - - Returns: - UsageDelta with all token counts initialized to 0. + Output and cache counts start at zero. Provider usage in message_delta + remains authoritative. Failed estimates fall back to zero. """ return UsageDelta( - input_tokens=0, + input_tokens=( + self._estimate_initial_input_tokens() + if litellm.anthropic_messages_estimate_initial_input_tokens is True + else 0 + ), output_tokens=0, cache_creation_input_tokens=0, cache_read_input_tokens=0, ) + def _estimate_initial_input_tokens(self) -> int: + try: + request: Final = self.completion_request or {} + messages: Final = _PROMPT_MESSAGES.validate_python(request.get("messages", self.messages)) + if not messages: + return 0 + materialized_messages: Final = cast( # cast-ok: JSON-mode serialization preserves validated message types and materializes iterable content + list[AllMessageValues], _PROMPT_MESSAGES.dump_python(messages, mode="json") + ) + model: Final = request.get("model", self.model) + tools: Final = request.get("tools") + return litellm.token_counter( # pyright: ignore[reportUnknownMemberType] # token_counter's public signature is partially untyped + model=model if isinstance(model, str) else self.model, + messages=materialized_messages, + tools=_PROMPT_TOOLS.validate_python(tools) if tools is not None else None, + use_default_image_token_count=True, + ) + except Exception: # noqa: BLE001 # prompt estimation must not interrupt the stream + return 0 + def __next__(self): from .transformation import LiteLLMAnthropicMessagesAdapter @@ -1239,6 +1278,9 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): # For non-dict chunks, forward the original value unchanged yield chunk + async def aclose(self) -> None: + await self._combined_chunk_splitter.aclose() + async def async_anthropic_sse_wrapper(self) -> AsyncIterator[bytes]: """ Async version of anthropic_sse_wrapper. @@ -1292,7 +1334,7 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): delta: Final = processed_chunk["delta"] if delta.get("stop_reason") == "max_tokens": return processed_chunk - from litellm.llms.anthropic.pass_through.messages.utils import ( + from litellm.llms.anthropic.messages.native.utils import ( refusal_stop_details, ) @@ -1347,7 +1389,7 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): @staticmethod def _is_blank_delta(chunk: "ModelResponseStream") -> bool: from litellm.llms.anthropic.common_utils import is_empty_unsigned_thinking_block - from litellm.llms.anthropic.pass_through.messages.utils import ( + from litellm.llms.anthropic.messages.native.utils import ( openai_chat_refusal_text, ) @@ -1367,9 +1409,9 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): # open a block: the emitted {"type": "thinking", "thinking": ""} gets # replayed as history and Anthropic rejects it (LIT-6357). A signed # entry opens the block so the client receives the replay signature. - thinking_blocks: Final = getattr(delta, "thinking_blocks", None) - if thinking_blocks and any( - isinstance(b, dict) and not is_empty_unsigned_thinking_block(b) for b in thinking_blocks + if any( + isinstance(b, dict) and not is_empty_unsigned_thinking_block(b) + for b in attribute_items(delta, "thinking_blocks") ): return False return True @@ -1384,7 +1426,7 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): - Different content types in the response - Specific markers in the content """ - from litellm.llms.anthropic.pass_through.messages.utils import ( + from litellm.llms.anthropic.messages.native.utils import ( openai_chat_refusal_text, ) @@ -1481,4 +1523,7 @@ class AnthropicSSEStream(AsyncIterator[bytes]): return await self._byte_stream.__anext__() async def aclose(self) -> None: - await self._byte_stream.aclose() + try: + await self._byte_stream.aclose() + finally: + await self._anthropic_wrapper.aclose() diff --git a/litellm/llms/anthropic/pass_through/adapters/transformation.py b/litellm/llms/anthropic/messages/adapters/transformation.py similarity index 99% rename from litellm/llms/anthropic/pass_through/adapters/transformation.py rename to litellm/llms/anthropic/messages/adapters/transformation.py index 9b1297dbd75..1ed552d46e3 100644 --- a/litellm/llms/anthropic/pass_through/adapters/transformation.py +++ b/litellm/llms/anthropic/messages/adapters/transformation.py @@ -10,8 +10,8 @@ from pydantic import JsonValue, TypeAdapter import litellm from litellm.litellm_core_utils.core_helpers import normalize_drop_params from litellm.litellm_core_utils.hidden_params import get_hidden_params -from litellm.llms.anthropic.pass_through.convertible_blocks import tool_result_text_part -from litellm.llms.anthropic.pass_through.utils import ( +from litellm.llms.anthropic.messages.convertible_blocks import tool_result_text_part +from litellm.llms.anthropic.messages.utils import ( is_reasoning_auto_summary_enabled, json_copy_or_original, prompt_cache_key_from_user_id, @@ -139,14 +139,14 @@ from litellm.llms.anthropic.common_utils import ( normalize_anthropic_tool_use_id, strip_encrypted_reasoning_blocks_from_anthropic_messages, ) -from litellm.llms.anthropic.pass_through.context_management import ( +from litellm.llms.anthropic.messages.context_management import ( PolyfillResult, ) -from litellm.llms.anthropic.pass_through.messages.mid_conversation_system import ( +from litellm.llms.anthropic.messages.native.mid_conversation_system import ( convert_mid_conversation_system_turns, is_system_role_message, ) -from litellm.llms.anthropic.pass_through.messages.utils import ( +from litellm.llms.anthropic.messages.native.utils import ( openai_chat_refusal_text, refusal_stop_details, ) @@ -210,7 +210,7 @@ from .streaming_iterator import AnthropicSSEStream, AnthropicStreamWrapper if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObject - from litellm.llms.anthropic.pass_through.safeguards import SafeguardsEvaluator + from litellm.llms.anthropic.messages.safeguards import SafeguardsEvaluator from litellm.types.llms.anthropic import ContentBlockContentBlockDict ToolResultContent: TypeAlias = str | list[ToolMessageContentPart] @@ -322,6 +322,7 @@ class AnthropicAdapter: is_async: bool = True, litellm_logging_obj: "LiteLLMLoggingObject | None" = None, safeguards_evaluator: "SafeguardsEvaluator | None" = None, + completion_request: Mapping[str, object] | None = None, ) -> AsyncIterator[bytes] | Iterator[bytes] | None: """ Translate OpenAI streaming response to Anthropic format. @@ -350,6 +351,7 @@ class AnthropicAdapter: iterations_usage=iterations_usage, litellm_logging_obj=litellm_logging_obj, safeguards_evaluator=safeguards_evaluator, + completion_request=completion_request, ) # Return the SSE-wrapped version for proper event formatting. if is_async: diff --git a/litellm/llms/anthropic/pass_through/architecture.md b/litellm/llms/anthropic/messages/architecture.md similarity index 100% rename from litellm/llms/anthropic/pass_through/architecture.md rename to litellm/llms/anthropic/messages/architecture.md diff --git a/litellm/llms/anthropic/pass_through/caller_model_checks.py b/litellm/llms/anthropic/messages/caller_model_checks.py similarity index 100% rename from litellm/llms/anthropic/pass_through/caller_model_checks.py rename to litellm/llms/anthropic/messages/caller_model_checks.py diff --git a/litellm/llms/anthropic/pass_through/context_management/__init__.py b/litellm/llms/anthropic/messages/context_management/__init__.py similarity index 100% rename from litellm/llms/anthropic/pass_through/context_management/__init__.py rename to litellm/llms/anthropic/messages/context_management/__init__.py diff --git a/litellm/llms/anthropic/pass_through/context_management/constants.py b/litellm/llms/anthropic/messages/context_management/constants.py similarity index 100% rename from litellm/llms/anthropic/pass_through/context_management/constants.py rename to litellm/llms/anthropic/messages/context_management/constants.py diff --git a/litellm/llms/anthropic/pass_through/context_management/dispatcher.py b/litellm/llms/anthropic/messages/context_management/dispatcher.py similarity index 98% rename from litellm/llms/anthropic/pass_through/context_management/dispatcher.py rename to litellm/llms/anthropic/messages/context_management/dispatcher.py index bce653df6d1..1557cf206ac 100644 --- a/litellm/llms/anthropic/pass_through/context_management/dispatcher.py +++ b/litellm/llms/anthropic/messages/context_management/dispatcher.py @@ -18,7 +18,7 @@ from .editors import ( from .result import PolyfillResult if TYPE_CHECKING: - from litellm.llms.anthropic.pass_through.utils import ProxySubCallLoggingKwargs + from litellm.llms.anthropic.messages.utils import ProxySubCallLoggingKwargs from litellm.router import Router from litellm.types.proxy.auth.user_api_key_auth import UserAPIKeyAuth diff --git a/litellm/llms/anthropic/pass_through/context_management/editors/__init__.py b/litellm/llms/anthropic/messages/context_management/editors/__init__.py similarity index 100% rename from litellm/llms/anthropic/pass_through/context_management/editors/__init__.py rename to litellm/llms/anthropic/messages/context_management/editors/__init__.py diff --git a/litellm/llms/anthropic/pass_through/context_management/editors/clear_tool_uses.py b/litellm/llms/anthropic/messages/context_management/editors/clear_tool_uses.py similarity index 96% rename from litellm/llms/anthropic/pass_through/context_management/editors/clear_tool_uses.py rename to litellm/llms/anthropic/messages/context_management/editors/clear_tool_uses.py index 935ce77ef87..d4430ca5ab9 100644 --- a/litellm/llms/anthropic/pass_through/context_management/editors/clear_tool_uses.py +++ b/litellm/llms/anthropic/messages/context_management/editors/clear_tool_uses.py @@ -15,7 +15,7 @@ from dataclasses import dataclass from functools import reduce from itertools import chain from types import MappingProxyType -from typing import Annotated, Any, Final, Literal, TypeVar, cast +from typing import TYPE_CHECKING, Annotated, Final, Literal, TypeVar, cast from pydantic import BaseModel, ConfigDict, Field, StrictInt, TypeAdapter, ValidationError from typing_extensions import ReadOnly, TypedDict @@ -32,6 +32,9 @@ from ..constants import ( from ..errors import AnthropicContextManagementError from ..placeholders import build_cleared_tool_result_content +if TYPE_CHECKING: + from litellm.types.llms.openai import ChatCompletionToolParam + T = TypeVar("T") # api.anthropic.com, measured 2026-10-19: text results of 1 to 46 bytes are never cleared or counted toward keep _TINY_RESULT_BYTES: Final = 46 @@ -216,7 +219,7 @@ def _trigger_met( current_tokens: Final = litellm.token_counter( model=model, messages=messages, - tools=cast(Any, tools), + tools=cast("list[ChatCompletionToolParam] | None", tools), ) verbose_logger.debug("context_management polyfill: current_tokens: %s", current_tokens) verbose_logger.debug("context_management polyfill: threshold: %s", threshold) @@ -366,9 +369,13 @@ def apply_clear_tool_uses_20250919( tokens_before: Final = ( counted_tokens if counted_tokens is not None - else litellm.token_counter(model=model, messages=messages, tools=cast(Any, tools)) + else litellm.token_counter( + model=model, messages=messages, tools=cast("list[ChatCompletionToolParam] | None", tools) + ) + ) + tokens_after: Final = litellm.token_counter( + model=model, messages=final_messages, tools=cast("list[ChatCompletionToolParam] | None", tools) ) - tokens_after: Final = litellm.token_counter(model=model, messages=final_messages, tools=cast(Any, tools)) cleared_input_tokens: Final = max(tokens_before - tokens_after, 0) return final_messages, { diff --git a/litellm/llms/anthropic/pass_through/context_management/editors/compact.py b/litellm/llms/anthropic/messages/context_management/editors/compact.py similarity index 99% rename from litellm/llms/anthropic/pass_through/context_management/editors/compact.py rename to litellm/llms/anthropic/messages/context_management/editors/compact.py index 5eb2863a241..254d1c4c058 100644 --- a/litellm/llms/anthropic/pass_through/context_management/editors/compact.py +++ b/litellm/llms/anthropic/messages/context_management/editors/compact.py @@ -21,12 +21,12 @@ from typing_extensions import NotRequired, ReadOnly, TypedDict, Unpack import litellm from litellm._logging import verbose_logger from litellm.litellm_core_utils.asyncify import asyncify -from litellm.llms.anthropic.pass_through.caller_model_checks import ( +from litellm.llms.anthropic.messages.caller_model_checks import ( caller_can_call_model, caller_within_model_budget, caller_within_model_rate_limit, ) -from litellm.llms.anthropic.pass_through.utils import ( +from litellm.llms.anthropic.messages.utils import ( ProxySubCallLoggingKwargs, proxy_general_settings, proxy_sub_call_metadata, @@ -269,7 +269,7 @@ def _count_effective_tokens( threshold check matches the downstream ``input_tokens`` metric. """ # Local import to avoid pulling the adapter at module load time. - from litellm.llms.anthropic.pass_through.adapters.transformation import ( + from litellm.llms.anthropic.messages.adapters.transformation import ( LiteLLMAnthropicMessagesAdapter, ) @@ -426,7 +426,7 @@ def _build_summary_messages( system prompt); the conversation history is translated to OpenAI shape; the summarization prompt is appended as a final user turn. """ - from litellm.llms.anthropic.pass_through.adapters.transformation import ( + from litellm.llms.anthropic.messages.adapters.transformation import ( LiteLLMAnthropicMessagesAdapter, ) diff --git a/litellm/llms/anthropic/pass_through/context_management/errors.py b/litellm/llms/anthropic/messages/context_management/errors.py similarity index 100% rename from litellm/llms/anthropic/pass_through/context_management/errors.py rename to litellm/llms/anthropic/messages/context_management/errors.py diff --git a/litellm/llms/anthropic/pass_through/context_management/placeholders.py b/litellm/llms/anthropic/messages/context_management/placeholders.py similarity index 89% rename from litellm/llms/anthropic/pass_through/context_management/placeholders.py rename to litellm/llms/anthropic/messages/context_management/placeholders.py index b3d3529f105..8a0eb6d48e1 100644 --- a/litellm/llms/anthropic/pass_through/context_management/placeholders.py +++ b/litellm/llms/anthropic/messages/context_management/placeholders.py @@ -1,12 +1,10 @@ """Placeholder content for cleared ``tool_result`` blocks (string or block list).""" -from typing import Any - from .constants import CLEARED_TOOL_RESULT_PLACEHOLDER def build_cleared_tool_result_content( - original_content: Any, + original_content: object, ) -> str | list[dict]: """Return a string or single text block list, matching ``original_content`` shape.""" if isinstance(original_content, list): diff --git a/litellm/llms/anthropic/pass_through/context_management/result.py b/litellm/llms/anthropic/messages/context_management/result.py similarity index 94% rename from litellm/llms/anthropic/pass_through/context_management/result.py rename to litellm/llms/anthropic/messages/context_management/result.py index 5b88fe30871..4713b8d79c7 100644 --- a/litellm/llms/anthropic/pass_through/context_management/result.py +++ b/litellm/llms/anthropic/messages/context_management/result.py @@ -6,7 +6,7 @@ attach ``iterations`` to ``usage``. """ from dataclasses import dataclass, field -from typing import Any, Final +from typing import Final from litellm.types.llms.anthropic import ( AppliedEdit, @@ -19,8 +19,8 @@ from .constants import COMPACT_EDIT_TYPE @dataclass class PolyfillResult: - messages: list[dict[str, Any]] - system: str | list[dict[str, Any]] | None + messages: list[dict[str, object]] + system: str | list[dict[str, object]] | None applied_edits: list[AppliedEdit] = field(default_factory=list) compaction_block: CompactionBlock | None = None iterations_usage: list[UsageIteration] | None = None diff --git a/litellm/llms/anthropic/pass_through/convertible_blocks.py b/litellm/llms/anthropic/messages/convertible_blocks.py similarity index 96% rename from litellm/llms/anthropic/pass_through/convertible_blocks.py rename to litellm/llms/anthropic/messages/convertible_blocks.py index fb17910fb97..09d662da543 100644 --- a/litellm/llms/anthropic/pass_through/convertible_blocks.py +++ b/litellm/llms/anthropic/messages/convertible_blocks.py @@ -3,7 +3,6 @@ from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence from dataclasses import dataclass from functools import partial from itertools import chain, groupby -from operator import itemgetter from types import MappingProxyType from typing import Final, TypeAlias @@ -13,7 +12,7 @@ from typing_extensions import assert_never import litellm from litellm.litellm_core_utils.core_helpers import as_str_mapping, drops_unsupported_params from litellm.litellm_core_utils.prompt_templates.factory import sanitize_anthropic_tool_use_id -from litellm.llms.anthropic.pass_through.messages.utils import normalize_native_messages +from litellm.llms.anthropic.messages.native.utils import normalize_native_messages from litellm.types.utils import TokenCountMessagesFormat _CONVERTIBLE_BLOCK_TYPES: Final = MappingProxyType( @@ -279,6 +278,14 @@ def _with_kept_parts(block: object, tool_result: Mapping[str, object], parts: _K return {**tool_result, "content": [_restored_part(part, parts.get(index)) for index, part in enumerate(blocks)]} +def _entry_tool_use_id(entry: tuple[str, _KeptParts]) -> str: + return entry[0] + + +def _entry_kept_parts(entry: tuple[str, _KeptParts]) -> _KeptParts: + return entry[1] + + def _restored_block(block: object, kept: Mapping[str, Iterator[_KeptParts]]) -> object: match as_str_mapping(block): case {"type": "tool_result", "tool_use_id": str(tool_use_id)} as tool_result if ( @@ -293,13 +300,15 @@ def _restored_block(block: object, kept: Mapping[str, Iterator[_KeptParts]]) -> def keep_non_string_tool_result_texts(rewritten: Sequence[object], original: object) -> Sequence[object]: blocks: Final = chain.from_iterable(map(_user_content_blocks, _list_items(original))) - by_id: Final = tuple(sorted(chain.from_iterable(map(_tool_result_non_string_texts, blocks)), key=itemgetter(0))) + by_id: Final = tuple( + sorted(chain.from_iterable(map(_tool_result_non_string_texts, blocks)), key=_entry_tool_use_id) + ) if not any(parts for _, parts in by_id): return rewritten kept_in_order: Final = MappingProxyType( { - tool_use_id: iter(tuple(map(itemgetter(1), group))) - for tool_use_id, group in groupby(by_id, key=itemgetter(0)) + tool_use_id: iter(tuple(map(_entry_kept_parts, group))) + for tool_use_id, group in groupby(by_id, key=_entry_tool_use_id) } ) return [_with_user_blocks(message, partial(_restored_block, kept=kept_in_order)) for message in rewritten] diff --git a/litellm/llms/anthropic/pass_through/messages/agentic_streaming_iterator.py b/litellm/llms/anthropic/messages/native/agentic_streaming_iterator.py similarity index 98% rename from litellm/llms/anthropic/pass_through/messages/agentic_streaming_iterator.py rename to litellm/llms/anthropic/messages/native/agentic_streaming_iterator.py index 922a6e21bae..25d4d7b3ce1 100644 --- a/litellm/llms/anthropic/pass_through/messages/agentic_streaming_iterator.py +++ b/litellm/llms/anthropic/messages/native/agentic_streaming_iterator.py @@ -336,7 +336,7 @@ class AgenticAnthropicStreamingIterator: await task async def aclose(self) -> None: - from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( + from litellm.llms.anthropic.messages.native.streaming_iterator import ( aclose_if_supported, ) @@ -379,7 +379,7 @@ class AgenticAnthropicStreamingIterator: if hasattr(result, "__aiter__"): self._follow_up_iterator = result.__aiter__() elif isinstance(result, dict): - from litellm.llms.anthropic.pass_through.messages.fake_stream_iterator import ( + from litellm.llms.anthropic.messages.native.fake_stream_iterator import ( FakeAnthropicMessagesStreamIterator, ) from litellm.types.llms.anthropic_messages.anthropic_response import ( diff --git a/litellm/llms/anthropic/pass_through/messages/fake_stream_iterator.py b/litellm/llms/anthropic/messages/native/fake_stream_iterator.py similarity index 94% rename from litellm/llms/anthropic/pass_through/messages/fake_stream_iterator.py rename to litellm/llms/anthropic/messages/native/fake_stream_iterator.py index 8d1b358c8f1..39bdfbbc53a 100644 --- a/litellm/llms/anthropic/pass_through/messages/fake_stream_iterator.py +++ b/litellm/llms/anthropic/messages/native/fake_stream_iterator.py @@ -9,10 +9,10 @@ the LLM doesn't make a tool call, and we need to return a stream to the user. """ import json -from collections.abc import Mapping -from typing import Any, Final, cast +from collections.abc import Mapping, Sequence +from typing import Final, cast -from litellm.llms.anthropic.pass_through.messages.utils import anthropic_message_delta +from litellm.llms.anthropic.messages.native.utils import anthropic_message_delta from litellm.types.llms.anthropic_messages.anthropic_response import ( AnthropicMessagesResponse, ) @@ -136,8 +136,7 @@ class FakeAnthropicMessagesStreamIterator: """Convert the non-streaming response to streaming chunks""" chunks: Final = [] - # Cast response to dict for easier access - response_dict: Final = cast(dict[str, Any], self.response) + response_dict: Final[Mapping[str, object]] = self.response # 1. message_start event usage: Final = self.response.get("usage") @@ -160,9 +159,8 @@ class FakeAnthropicMessagesStreamIterator: chunks.append(f"event: message_start\ndata: {json.dumps(message_start)}\n\n".encode()) # 2-4. For each content block, send start/delta/stop events - content_blocks: Final = response_dict.get("content", []) - for index, block in enumerate(content_blocks): - block_dict = cast(dict[str, Any], block) + content_blocks: Final = cast(Sequence[Mapping[str, object]], response_dict.get("content", [])) + for index, block_dict in enumerate(content_blocks): chunks.extend(self._create_content_block_chunks(block_dict, index)) # 5. message_delta event (with final usage and stop_reason) diff --git a/litellm/llms/anthropic/pass_through/messages/handler.py b/litellm/llms/anthropic/messages/native/handler.py similarity index 99% rename from litellm/llms/anthropic/pass_through/messages/handler.py rename to litellm/llms/anthropic/messages/native/handler.py index a93e9106fb4..6f97a019a96 100644 --- a/litellm/llms/anthropic/pass_through/messages/handler.py +++ b/litellm/llms/anthropic/messages/native/handler.py @@ -99,6 +99,7 @@ def _should_route_to_responses_api( requested_model: str | None = None, resolved_model: str | None = None, deployment_model_info: object = None, + stop_sequences: Sequence[str] | None = None, ) -> bool: """Return True when the request should use the Responses API path. @@ -107,6 +108,8 @@ def _should_route_to_responses_api( """ if litellm.use_chat_completions_url_for_anthropic_messages: return False + if stop_sequences: + return False if custom_llm_provider in _RESPONSES_API_PROVIDERS: return True if custom_llm_provider is None or requested_model is None or resolved_model is None: @@ -362,7 +365,7 @@ async def _try_websearch_short_circuit( ), ) if stream: - from litellm.llms.anthropic.pass_through.messages.fake_stream_iterator import ( + from litellm.llms.anthropic.messages.native.fake_stream_iterator import ( FakeAnthropicMessagesStreamIterator, ) @@ -656,7 +659,7 @@ def anthropic_messages_handler( # reference the provider cannot resolve. Popped from kwargs so it never reaches the provider. skip_mcp_handler: Final = kwargs.pop("_skip_mcp_handler", False) if not skip_mcp_handler and tools and may_name_litellm_mcp_gateway(tools): # pyright: ignore[reportUnknownArgumentType] # untyped tools list - from litellm.llms.anthropic.pass_through.messages.mcp_handler import ( + from litellm.llms.anthropic.messages.native.mcp_handler import ( anthropic_messages_with_mcp, ) @@ -690,7 +693,7 @@ def anthropic_messages_handler( if anthropic_messages_provider_config is None: # Route to Responses API for OpenAI / Azure, chat/completions for everything else. if kwargs.get("compaction") is None and _should_route_to_responses_api( - custom_llm_provider, original_model, model, kwargs.get("model_info") + custom_llm_provider, original_model, model, kwargs.get("model_info"), stop_sequences=stop_sequences ): return LiteLLMMessagesToResponsesAPIHandler.anthropic_messages_handler( max_tokens=max_tokens, diff --git a/litellm/llms/anthropic/pass_through/messages/interceptors/README.md b/litellm/llms/anthropic/messages/native/interceptors/README.md similarity index 100% rename from litellm/llms/anthropic/pass_through/messages/interceptors/README.md rename to litellm/llms/anthropic/messages/native/interceptors/README.md diff --git a/litellm/llms/anthropic/pass_through/messages/interceptors/__init__.py b/litellm/llms/anthropic/messages/native/interceptors/__init__.py similarity index 100% rename from litellm/llms/anthropic/pass_through/messages/interceptors/__init__.py rename to litellm/llms/anthropic/messages/native/interceptors/__init__.py diff --git a/litellm/llms/anthropic/pass_through/messages/interceptors/advisor.py b/litellm/llms/anthropic/messages/native/interceptors/advisor.py similarity index 99% rename from litellm/llms/anthropic/pass_through/messages/interceptors/advisor.py rename to litellm/llms/anthropic/messages/native/interceptors/advisor.py index 85d76de5402..f69d9820ef9 100644 --- a/litellm/llms/anthropic/pass_through/messages/interceptors/advisor.py +++ b/litellm/llms/anthropic/messages/native/interceptors/advisor.py @@ -68,7 +68,7 @@ class AdvisorOrchestrationHandler(MessagesInterceptor): custom_llm_provider: str | None, **kwargs, ) -> AnthropicMessagesResponse | AsyncIterator: - from litellm.llms.anthropic.pass_through.messages.fake_stream_iterator import ( + from litellm.llms.anthropic.messages.native.fake_stream_iterator import ( FakeAnthropicMessagesStreamIterator, ) diff --git a/litellm/llms/anthropic/pass_through/messages/interceptors/base.py b/litellm/llms/anthropic/messages/native/interceptors/base.py similarity index 100% rename from litellm/llms/anthropic/pass_through/messages/interceptors/base.py rename to litellm/llms/anthropic/messages/native/interceptors/base.py diff --git a/litellm/llms/anthropic/pass_through/messages/mcp_handler.py b/litellm/llms/anthropic/messages/native/mcp_handler.py similarity index 94% rename from litellm/llms/anthropic/pass_through/messages/mcp_handler.py rename to litellm/llms/anthropic/messages/native/mcp_handler.py index f369e10f22c..8fe18d79f24 100644 --- a/litellm/llms/anthropic/pass_through/messages/mcp_handler.py +++ b/litellm/llms/anthropic/messages/native/mcp_handler.py @@ -76,12 +76,12 @@ async def anthropic_messages_with_mcp( upstream provider as a url it cannot reach. """ import litellm - from litellm.experimental_mcp_client.tools import ( + from litellm.llms.anthropic.messages.adapters.handler import request_safeguards_evaluator + from litellm.llms.anthropic.messages.native.handler import proxy_classifies_tool_uses + from litellm.llms.anthropic.messages.safeguards import with_safeguard_results + from litellm.mcp_client.tools import ( transform_mcp_tool_to_anthropic_tool, ) - from litellm.llms.anthropic.pass_through.adapters.handler import request_safeguards_evaluator - from litellm.llms.anthropic.pass_through.messages.handler import proxy_classifies_tool_uses - from litellm.llms.anthropic.pass_through.safeguards import with_safeguard_results from litellm.responses.mcp.litellm_proxy_mcp_handler import ( LiteLLM_Proxy_MCP_Handler, ) @@ -198,7 +198,7 @@ async def anthropic_messages_with_mcp( else response ) if stream: - from litellm.llms.anthropic.pass_through.messages.fake_stream_iterator import ( + from litellm.llms.anthropic.messages.native.fake_stream_iterator import ( FakeAnthropicMessagesStreamIterator, ) diff --git a/litellm/llms/anthropic/pass_through/messages/mid_conversation_system.py b/litellm/llms/anthropic/messages/native/mid_conversation_system.py similarity index 100% rename from litellm/llms/anthropic/pass_through/messages/mid_conversation_system.py rename to litellm/llms/anthropic/messages/native/mid_conversation_system.py diff --git a/litellm/llms/anthropic/pass_through/messages/response_cache.py b/litellm/llms/anthropic/messages/native/response_cache.py similarity index 98% rename from litellm/llms/anthropic/pass_through/messages/response_cache.py rename to litellm/llms/anthropic/messages/native/response_cache.py index 81d01f1437e..d2425c3f484 100644 --- a/litellm/llms/anthropic/pass_through/messages/response_cache.py +++ b/litellm/llms/anthropic/messages/native/response_cache.py @@ -7,7 +7,7 @@ from typing import TYPE_CHECKING, Final, cast import litellm from litellm._logging import verbose_logger from litellm.caching.caching_handler import create_cache_write_task, is_response_without_output -from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( +from litellm.llms.anthropic.messages.native.streaming_iterator import ( AnthropicMessagesStreamingResponse, BaseAnthropicMessagesStreamingIterator, aclose_if_supported, diff --git a/litellm/llms/anthropic/pass_through/messages/streaming_iterator.py b/litellm/llms/anthropic/messages/native/streaming_iterator.py similarity index 99% rename from litellm/llms/anthropic/pass_through/messages/streaming_iterator.py rename to litellm/llms/anthropic/messages/native/streaming_iterator.py index bfa309fad83..52b3f1042f8 100644 --- a/litellm/llms/anthropic/pass_through/messages/streaming_iterator.py +++ b/litellm/llms/anthropic/messages/native/streaming_iterator.py @@ -18,13 +18,13 @@ from litellm.litellm_core_utils.core_helpers import process_response_headers from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER from litellm.llms.anthropic.common_utils import ANTHROPIC_ERROR_STATUS_CODE_MAP -from litellm.llms.anthropic.pass_through.messages.utils import ( +from litellm.llms.anthropic.messages.native.utils import ( INCOMPLETE_STREAM_ERROR_MESSAGE, MESSAGE_DELTA_OPTIONAL_KEYS, anthropic_message_delta, ) -from litellm.llms.anthropic.pass_through.safeguards import StreamedSafeguardResults -from litellm.llms.anthropic.pass_through.utils import anthropic_sse_frame +from litellm.llms.anthropic.messages.safeguards import StreamedSafeguardResults +from litellm.llms.anthropic.messages.utils import anthropic_sse_frame from litellm.proxy.pass_through_endpoints.success_handler import ( PassThroughEndpointLogging, ) @@ -33,7 +33,7 @@ from litellm.types.passthrough_endpoints.pass_through_endpoints import EndpointT from litellm.types.utils import GenericStreamingChunk, ModelResponseStream if TYPE_CHECKING: - from litellm.llms.anthropic.pass_through.safeguards import SafeguardsEvaluator + from litellm.llms.anthropic.messages.safeguards import SafeguardsEvaluator GLOBAL_PASS_THROUGH_SUCCESS_HANDLER_OBJ: Final = PassThroughEndpointLogging() diff --git a/litellm/llms/anthropic/pass_through/messages/transformation.py b/litellm/llms/anthropic/messages/native/transformation.py similarity index 99% rename from litellm/llms/anthropic/pass_through/messages/transformation.py rename to litellm/llms/anthropic/messages/native/transformation.py index dfe0788e50a..cc53858f842 100644 --- a/litellm/llms/anthropic/pass_through/messages/transformation.py +++ b/litellm/llms/anthropic/messages/native/transformation.py @@ -10,8 +10,8 @@ from litellm.exceptions import AuthenticationError from litellm.litellm_core_utils.core_helpers import drops_unsupported_params from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj from litellm.litellm_core_utils.url_utils import ensure_api_route -from litellm.llms.anthropic.pass_through.convertible_blocks import drop_non_string_tool_result_texts -from litellm.llms.anthropic.pass_through.safeguards import proxy_serves_safeguards +from litellm.llms.anthropic.messages.convertible_blocks import drop_non_string_tool_result_texts +from litellm.llms.anthropic.messages.safeguards import proxy_serves_safeguards from litellm.llms.base_llm.anthropic_messages.transformation import ( BaseAnthropicMessagesConfig, ) @@ -722,7 +722,7 @@ class AnthropicMessagesConfig(BaseAnthropicMessagesConfig): logging_obj: LiteLLMLoggingObj, ) -> AnthropicMessagesResponse: try: - raw_response_json: Final = raw_response.json() + raw_response_json: Final[AnthropicMessagesResponse] = raw_response.json() except Exception: raise AnthropicError(message=raw_response.text, status_code=raw_response.status_code) response: Final = AnthropicMessagesResponse(**raw_response_json) @@ -736,7 +736,7 @@ class AnthropicMessagesConfig(BaseAnthropicMessagesConfig): litellm_logging_obj: LiteLLMLoggingObj, ) -> AsyncIterator[bytes]: """Helper function to handle Anthropic streaming responses using the existing logging handlers""" - from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( + from litellm.llms.anthropic.messages.native.streaming_iterator import ( BaseAnthropicMessagesStreamingIterator, ) diff --git a/litellm/llms/anthropic/pass_through/messages/utils.py b/litellm/llms/anthropic/messages/native/utils.py similarity index 99% rename from litellm/llms/anthropic/pass_through/messages/utils.py rename to litellm/llms/anthropic/messages/native/utils.py index d91a5e2fb5c..29bbd8178ba 100644 --- a/litellm/llms/anthropic/pass_through/messages/utils.py +++ b/litellm/llms/anthropic/messages/native/utils.py @@ -11,7 +11,7 @@ from litellm.llms.anthropic.common_utils import ( sanitize_tool_use_ids_in_anthropic_messages, strip_empty_content_blocks_from_anthropic_messages, ) -from litellm.llms.anthropic.pass_through.utils import is_reasoning_auto_summary_enabled +from litellm.llms.anthropic.messages.utils import is_reasoning_auto_summary_enabled from litellm.types.llms.anthropic import ( AnthropicMessagesRequestOptionalParams, AnthropicStopDetails, diff --git a/litellm/llms/anthropic/pass_through/responses_adapters/__init__.py b/litellm/llms/anthropic/messages/responses_adapters/__init__.py similarity index 100% rename from litellm/llms/anthropic/pass_through/responses_adapters/__init__.py rename to litellm/llms/anthropic/messages/responses_adapters/__init__.py diff --git a/litellm/llms/anthropic/pass_through/responses_adapters/handler.py b/litellm/llms/anthropic/messages/responses_adapters/handler.py similarity index 99% rename from litellm/llms/anthropic/pass_through/responses_adapters/handler.py rename to litellm/llms/anthropic/messages/responses_adapters/handler.py index b1347b0c79e..99a07a1e9bf 100644 --- a/litellm/llms/anthropic/pass_through/responses_adapters/handler.py +++ b/litellm/llms/anthropic/messages/responses_adapters/handler.py @@ -201,7 +201,7 @@ def _build_responses_kwargs( if isinstance(reasoning, dict): effort: Final[object] = reasoning.get("effort") if isinstance(effort, str): - from litellm.llms.anthropic.pass_through.utils import ( + from litellm.llms.anthropic.messages.utils import ( normalize_reasoning_effort_value, ) diff --git a/litellm/llms/anthropic/pass_through/responses_adapters/streaming_iterator.py b/litellm/llms/anthropic/messages/responses_adapters/streaming_iterator.py similarity index 98% rename from litellm/llms/anthropic/pass_through/responses_adapters/streaming_iterator.py rename to litellm/llms/anthropic/messages/responses_adapters/streaming_iterator.py index e628a30fdd6..614a7c96848 100644 --- a/litellm/llms/anthropic/pass_through/responses_adapters/streaming_iterator.py +++ b/litellm/llms/anthropic/messages/responses_adapters/streaming_iterator.py @@ -14,13 +14,13 @@ from litellm.exceptions import MidStreamFallbackError from litellm.litellm_core_utils.prompt_templates.common_utils import ( encrypted_reasoning_signature, ) -from litellm.llms.anthropic.pass_through.messages.utils import ( +from litellm.llms.anthropic.messages.native.utils import ( INCOMPLETE_STREAM_ERROR_MESSAGE, refusal_stop_details, responses_output_refusal_text, ) -from litellm.llms.anthropic.pass_through.safeguards import StreamedSafeguardResults -from litellm.llms.anthropic.pass_through.utils import anthropic_sse_frame +from litellm.llms.anthropic.messages.safeguards import StreamedSafeguardResults +from litellm.llms.anthropic.messages.utils import anthropic_sse_frame from litellm.responses.streaming_iterator import ( partial_responses_incomplete_event_on_disconnect, stream_error_status_and_message, @@ -35,7 +35,7 @@ from .transformation import ( if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObject - from litellm.llms.anthropic.pass_through.safeguards import SafeguardsEvaluator + from litellm.llms.anthropic.messages.safeguards import SafeguardsEvaluator from litellm.types.llms.openai import ResponseIncompleteEvent diff --git a/litellm/llms/anthropic/pass_through/responses_adapters/transformation.py b/litellm/llms/anthropic/messages/responses_adapters/transformation.py similarity index 98% rename from litellm/llms/anthropic/pass_through/responses_adapters/transformation.py rename to litellm/llms/anthropic/messages/responses_adapters/transformation.py index bd0f57c3ed9..1dd07c1739b 100644 --- a/litellm/llms/anthropic/pass_through/responses_adapters/transformation.py +++ b/litellm/llms/anthropic/messages/responses_adapters/transformation.py @@ -20,12 +20,12 @@ from litellm.litellm_core_utils.prompt_templates.common_utils import ( from litellm.litellm_core_utils.reasoning_effort_utils import ( reasoning_effort_from_thinking, ) -from litellm.llms.anthropic.pass_through.convertible_blocks import tool_result_text_parts -from litellm.llms.anthropic.pass_through.messages.utils import ( +from litellm.llms.anthropic.messages.convertible_blocks import tool_result_text_parts +from litellm.llms.anthropic.messages.native.utils import ( refusal_stop_details, responses_output_refusal_text, ) -from litellm.llms.anthropic.pass_through.utils import ( +from litellm.llms.anthropic.messages.utils import ( is_reasoning_auto_summary_enabled, json_copy_or_original, prompt_cache_key_from_user_id, @@ -71,7 +71,7 @@ class LiteLLMAnthropicToResponsesAPIAdapter: if raw_usage is None: return AnthropicUsage(input_tokens=0, output_tokens=0) - from litellm.llms.anthropic.pass_through.adapters.transformation import ( + from litellm.llms.anthropic.messages.adapters.transformation import ( LiteLLMAnthropicMessagesAdapter, ) from litellm.responses.utils import ResponseAPILoggingUtils @@ -242,7 +242,7 @@ class LiteLLMAnthropicToResponsesAPIAdapter: @staticmethod def _summary_part_text(part: object) -> str: if isinstance(part, Mapping): - mapping: Final = cast(Mapping[str, Any], part) # cast-ok: summary parts are untyped provider json + mapping: Final = cast(Mapping[str, object], part) # cast-ok: summary parts are untyped provider json return str(mapping.get("text") or "") return str(getattr(part, "text", None) or "") @@ -673,7 +673,7 @@ class LiteLLMAnthropicToResponsesAPIAdapter: output_config = anthropic_request.get("output_config") reasoning: Final = self.translate_thinking_to_reasoning( thinking, - output_config=cast(dict[str, Any] | None, output_config), + output_config=cast(dict[str, object] | None, output_config), auto_summary_level=auto_summary_level, drop_params=drop_params, ) diff --git a/litellm/llms/anthropic/pass_through/safeguards.py b/litellm/llms/anthropic/messages/safeguards.py similarity index 99% rename from litellm/llms/anthropic/pass_through/safeguards.py rename to litellm/llms/anthropic/messages/safeguards.py index eededde7e92..22627a454b3 100644 --- a/litellm/llms/anthropic/pass_through/safeguards.py +++ b/litellm/llms/anthropic/messages/safeguards.py @@ -11,8 +11,8 @@ from typing_extensions import NotRequired, ReadOnly, Unpack, assert_never import litellm from litellm._logging import verbose_logger -from litellm.llms.anthropic.pass_through.caller_model_checks import CallerModelVerdict, caller_model_verdict -from litellm.llms.anthropic.pass_through.utils import ( +from litellm.llms.anthropic.messages.caller_model_checks import CallerModelVerdict, caller_model_verdict +from litellm.llms.anthropic.messages.utils import ( ProxySubCallLoggingKwargs, proxy_general_settings, proxy_sub_call_metadata, diff --git a/litellm/llms/anthropic/pass_through/stream_assembly.py b/litellm/llms/anthropic/messages/stream_assembly.py similarity index 99% rename from litellm/llms/anthropic/pass_through/stream_assembly.py rename to litellm/llms/anthropic/messages/stream_assembly.py index 90cb9f4c335..90bdad8f4bc 100644 --- a/litellm/llms/anthropic/pass_through/stream_assembly.py +++ b/litellm/llms/anthropic/messages/stream_assembly.py @@ -12,7 +12,7 @@ from litellm.llms.anthropic.chat.handler import ( ModelResponseIterator as AnthropicModelResponseIterator, ) from litellm.llms.anthropic.chat.transformation import AnthropicConfig -from litellm.llms.anthropic.pass_through.messages.utils import MESSAGE_DELTA_OPTIONAL_KEYS +from litellm.llms.anthropic.messages.native.utils import MESSAGE_DELTA_OPTIONAL_KEYS from litellm.types.utils import ( Choices, Message, diff --git a/litellm/llms/anthropic/pass_through/utils.py b/litellm/llms/anthropic/messages/utils.py similarity index 100% rename from litellm/llms/anthropic/pass_through/utils.py rename to litellm/llms/anthropic/messages/utils.py diff --git a/litellm/llms/anthropic/pass_through/__init__.py b/litellm/llms/anthropic/pass_through/__init__.py new file mode 100644 index 00000000000..c29255c09c2 --- /dev/null +++ b/litellm/llms/anthropic/pass_through/__init__.py @@ -0,0 +1,7 @@ +from litellm.litellm_core_utils.renamed_package_shim import alias_renamed_package + +__getattr__ = alias_renamed_package( + __name__, + "litellm.llms.anthropic.messages", + nested_renames=((f"{__name__}.messages", "litellm.llms.anthropic.messages.native"),), +) diff --git a/litellm/llms/anthropic/prompt_cache_prediction.py b/litellm/llms/anthropic/prompt_cache_prediction.py index 4c363dba860..7a4c707860d 100644 --- a/litellm/llms/anthropic/prompt_cache_prediction.py +++ b/litellm/llms/anthropic/prompt_cache_prediction.py @@ -24,11 +24,11 @@ from litellm.llms.anthropic.common_utils import ( ) from litellm.llms.anthropic.count_tokens.handler import AnthropicCountTokensHandler from litellm.llms.anthropic.count_tokens.transformation import COUNT_TOKEN_OPTION_NAMES -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( DEFAULT_ANTHROPIC_API_VERSION, AnthropicMessagesConfig, ) -from litellm.llms.anthropic.pass_through.messages.utils import AnthropicMessagesRequestUtils, prepare_native_messages +from litellm.llms.anthropic.messages.native.utils import AnthropicMessagesRequestUtils, prepare_native_messages from litellm.router_utils.baseline_request import ( BASELINE_PARAMETERS, capture_baseline_parameters, diff --git a/litellm/llms/azure/audio_transcriptions.py b/litellm/llms/azure/audio_transcriptions.py index 99ebd2875a7..df8a0614665 100644 --- a/litellm/llms/azure/audio_transcriptions.py +++ b/litellm/llms/azure/audio_transcriptions.py @@ -1,5 +1,5 @@ from collections.abc import Coroutine -from typing import TYPE_CHECKING, Any, Final +from typing import TYPE_CHECKING, Final from openai import AsyncAzureOpenAI, AzureOpenAI from pydantic import BaseModel @@ -38,7 +38,7 @@ class AzureAudioTranscription(AzureChatCompletion): atranscription: bool = False, litellm_params: dict | None = None, custom_llm_provider: str = "azure", - ) -> TranscriptionResponse | Coroutine[Any, Any, TranscriptionResponse]: + ) -> TranscriptionResponse | Coroutine[object, object, TranscriptionResponse]: data: Final = {"model": model, "file": audio_file, **optional_params} if atranscription is True: diff --git a/litellm/llms/azure/azure.py b/litellm/llms/azure/azure.py index 67b25bf7d12..02f1ba3472a 100644 --- a/litellm/llms/azure/azure.py +++ b/litellm/llms/azure/azure.py @@ -13,7 +13,7 @@ from openai import ( BadRequestError, OpenAI, ) -from pydantic import BaseModel +from pydantic import BaseModel, TypeAdapter import litellm from litellm.constants import AZURE_OPERATION_POLLING_TIMEOUT, DEFAULT_MAX_RETRIES @@ -59,6 +59,8 @@ from .image_generation import ( ) from .image_generation.http_utils import azure_deployment_image_generation_json_body +_DECODED_JSON: Final = TypeAdapter(object) + class AzureOpenAIAssistantsAPIConfig: """ @@ -961,7 +963,7 @@ class AzureChatCompletion(BaseAzureLLM, BaseLLM): body=error_data, ) - result: Final = response.json()["result"] + result: Final = _DECODED_JSON.validate_python(response.json()["result"]) return httpx.Response( status_code=200, headers=response.headers, @@ -1078,7 +1080,7 @@ class AzureChatCompletion(BaseAzureLLM, BaseLLM): body=error_data, ) - result: Final = response.json()["result"] + result: Final = _DECODED_JSON.validate_python(response.json()["result"]) return httpx.Response( status_code=200, headers=response.headers, @@ -1358,7 +1360,7 @@ class AzureChatCompletion(BaseAzureLLM, BaseLLM): except AzureOpenAIError as e: raise e except Exception as e: - error_code: Final = getattr(e, "status_code", None) + error_code: Final[object] = getattr(e, "status_code", None) if error_code is not None: raise AzureOpenAIError(status_code=error_code, message=str(e)) else: diff --git a/litellm/llms/azure/chat/gpt_5_transformation.py b/litellm/llms/azure/chat/gpt_reasoning_transformation.py similarity index 98% rename from litellm/llms/azure/chat/gpt_5_transformation.py rename to litellm/llms/azure/chat/gpt_reasoning_transformation.py index 4bec335064e..5bd03f511c5 100644 --- a/litellm/llms/azure/chat/gpt_5_transformation.py +++ b/litellm/llms/azure/chat/gpt_reasoning_transformation.py @@ -4,7 +4,7 @@ from collections.abc import Collection from typing import ClassVar, Final import litellm -from litellm.llms.openai.chat.gpt_5_transformation import ( +from litellm.llms.openai.chat.gpt_reasoning_transformation import ( OpenAIGPT5Config, is_gpt_reasoning_series_name, ) diff --git a/litellm/llms/azure/chat/gpt_transformation.py b/litellm/llms/azure/chat/gpt_transformation.py index 03fe27437a5..26ae30635d4 100644 --- a/litellm/llms/azure/chat/gpt_transformation.py +++ b/litellm/llms/azure/chat/gpt_transformation.py @@ -16,7 +16,7 @@ from litellm.litellm_core_utils.prompt_templates.factory import ( convert_to_azure_openai_messages, ) from litellm.llms.base_llm.chat.transformation import BaseLLMException -from litellm.llms.openai.chat.gpt_5_transformation import GPT_REASONING_SERIES_MARKERS +from litellm.llms.openai.chat.gpt_reasoning_transformation import GPT_REASONING_SERIES_MARKERS from litellm.types.llms.azure import ( API_VERSION_MONTH_SUPPORTED_RESPONSE_FORMAT, API_VERSION_YEAR_SUPPORTED_RESPONSE_FORMAT, diff --git a/litellm/llms/azure/decisions/transformation.py b/litellm/llms/azure/decisions/transformation.py new file mode 100644 index 00000000000..3fb40e39702 --- /dev/null +++ b/litellm/llms/azure/decisions/transformation.py @@ -0,0 +1,77 @@ +import asyncio +from collections.abc import Mapping +from typing import Final + +from pydantic import ValidationError + +import litellm +from litellm.llms.azure.common_utils import ( + BaseAzureLLM, + cached_azure_ad_token_refresh_provider, +) +from litellm.llms.openai.decisions.transformation import OpenAIDecisionsConfig +from litellm.secret_managers.main import get_secret_str +from litellm.types.router import GenericLiteLLMParams + + +class AzureDecisionsConfig(OpenAIDecisionsConfig): + """Azure OpenAI Decisions, with the Azure deployment name in the request body.""" + + api_key_required = False + + def resolve_api_base(self, api_base: str | None) -> str | None: + return BaseAzureLLM.resolve_azure_api_base(api_base) + + def resolve_api_key(self, api_key: str | None) -> str | None: + return api_key + + def resolve_credential( + self, api_key: str | None, api_base: str, litellm_params: Mapping[str, object] + ) -> str | None: + return api_key + + def validate_environment( + self, + headers: Mapping[str, str], + model: str, + api_key: str | None, + litellm_params: Mapping[str, object], + ) -> Mapping[str, str]: + try: + params: Final = GenericLiteLLMParams.model_validate({**litellm_params, "api_key": api_key}) + except ValidationError as error: + raise litellm.BadRequestError( + message="Invalid Azure Decisions credential parameters", + model=model, + llm_provider="azure", + ) from error + clean_headers: Final = super().validate_environment( + {name: value for name, value in headers.items() if name.lower() != "api-key"}, + model, + None, + litellm_params, + ) + azure_headers: Final = BaseAzureLLM.base_validate_azure_environment( + headers=dict(clean_headers), litellm_params=params + ) + if "api-key" in azure_headers: + return azure_headers + if "Authorization" in azure_headers: + return azure_headers + scope: Final = ( + params.azure_scope or get_secret_str("AZURE_SCOPE") or "https://cognitiveservices.azure.com/.default" + ) + azure_headers["Authorization"] = f"Bearer {cached_azure_ad_token_refresh_provider(scope)()}" + return azure_headers + + async def avalidate_environment( + self, + headers: Mapping[str, str], + model: str, + api_key: str | None, + litellm_params: Mapping[str, object], + ) -> Mapping[str, str]: + return await asyncio.to_thread(self.validate_environment, headers, model, api_key, litellm_params) + + def get_complete_url(self, api_base: str, model: str) -> str: + return BaseAzureLLM.get_base_azure_url(api_base, None, route="/openai/v1/decisions") diff --git a/litellm/llms/azure/exception_mapping.py b/litellm/llms/azure/exception_mapping.py index dcc3601cd8e..f7146a36384 100644 --- a/litellm/llms/azure/exception_mapping.py +++ b/litellm/llms/azure/exception_mapping.py @@ -1,4 +1,4 @@ -from typing import Any, Final +from typing import Final from litellm.exceptions import ContentPolicyViolationError @@ -54,7 +54,7 @@ class AzureOpenAIExceptionMapping: @staticmethod def _extract_azure_error( original_exception: Exception, - ) -> tuple[dict[str, object], dict | None]: + ) -> tuple[dict[str, object], object]: """Extract Azure OpenAI error payload and inner error details. Azure error formats can vary by endpoint/version. Common shapes: @@ -67,13 +67,13 @@ class AzureOpenAIExceptionMapping: return {}, None # Some SDKs place the payload under "error". - azure_error: dict[str, Any] + azure_error: dict[str, object] if isinstance(body_dict.get("error"), dict): azure_error = body_dict.get("error", {}) else: azure_error = body_dict - inner_error: Final = ( + inner_error: Final[object] = ( azure_error.get("inner_error") or azure_error.get("innererror") or body_dict.get("innererror") diff --git a/litellm/llms/azure/responses/transformation.py b/litellm/llms/azure/responses/transformation.py index 8cae4bf284b..647ad97e02c 100644 --- a/litellm/llms/azure/responses/transformation.py +++ b/litellm/llms/azure/responses/transformation.py @@ -12,7 +12,7 @@ from pydantic import TypeAdapter from litellm._logging import verbose_logger from litellm.constants import AZURE_DEFAULT_RESPONSES_API_VERSION from litellm.litellm_core_utils.url_utils import encode_url_path_segment -from litellm.llms.azure.chat.gpt_5_transformation import AzureOpenAIGPT5Config +from litellm.llms.azure.chat.gpt_reasoning_transformation import AzureOpenAIGPT5Config from litellm.llms.azure.common_utils import BaseAzureLLM from litellm.llms.openai.responses.transformation import OpenAIResponsesAPIConfig from litellm.types.llms.openai import * @@ -95,7 +95,7 @@ class AzureOpenAIResponsesAPIConfig(OpenAIResponsesAPIConfig): def get_stripped_model_name(self, model: str) -> str: return model.replace("responses/", "").replace("o_series/", "").replace("azure_ai/", "") - def _handle_reasoning_item(self, item: dict[str, Any]) -> dict[str, Any]: + def _handle_reasoning_item(self, item: dict[str, Any]) -> Mapping[str, object]: """ Handle reasoning items to filter out the status field. Issue: https://github.com/BerriAI/litellm/issues/13484 diff --git a/litellm/llms/azure/vector_stores/transformation.py b/litellm/llms/azure/vector_stores/transformation.py index 9510c021c7d..5a2961cd550 100644 --- a/litellm/llms/azure/vector_stores/transformation.py +++ b/litellm/llms/azure/vector_stores/transformation.py @@ -1,3 +1,5 @@ +from typing import Final + from litellm.llms.azure.common_utils import BaseAzureLLM from litellm.llms.openai.vector_stores.transformation import OpenAIVectorStoreConfig from litellm.types.router import GenericLiteLLMParams @@ -15,5 +17,10 @@ class AzureOpenAIVectorStoreConfig(OpenAIVectorStoreConfig): route="/openai/vector_stores", ) + def get_vector_store_url(self, api_base: str, encoded_vector_store_id: str) -> str: + path, _, query = api_base.partition("?") + url: Final = f"{path}/{encoded_vector_store_id}" + return f"{url}?{query}" if query else url + def validate_environment(self, headers: dict, litellm_params: GenericLiteLLMParams | None) -> dict: return BaseAzureLLM.base_validate_azure_environment(headers=headers, litellm_params=litellm_params) diff --git a/litellm/llms/azure_ai/anthropic/messages_transformation.py b/litellm/llms/azure_ai/anthropic/messages_transformation.py index 2aacc5771d0..6b2da96de23 100644 --- a/litellm/llms/azure_ai/anthropic/messages_transformation.py +++ b/litellm/llms/azure_ai/anthropic/messages_transformation.py @@ -5,7 +5,7 @@ Azure Anthropic messages transformation config - extends AnthropicMessagesConfig from collections.abc import Sequence from typing import Any, Final -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) from litellm.llms.azure.common_utils import BaseAzureLLM diff --git a/litellm/llms/azure_ai/chat/transformation.py b/litellm/llms/azure_ai/chat/transformation.py index 83d00a621b4..6aed7eb3c54 100644 --- a/litellm/llms/azure_ai/chat/transformation.py +++ b/litellm/llms/azure_ai/chat/transformation.py @@ -21,7 +21,7 @@ from litellm.llms.azure_ai.common_utils import ( is_foundry_model_inference_base, ) from litellm.llms.base_llm.chat.transformation import LiteLLMLoggingObj -from litellm.llms.openai.chat.gpt_5_transformation import OpenAIGPT5Config +from litellm.llms.openai.chat.gpt_reasoning_transformation import OpenAIGPT5Config from litellm.llms.openai.common_utils import drop_params_from_unprocessable_entity_error from litellm.llms.openai.openai import OpenAIChatCompletionResponseIterator, OpenAIConfig from litellm.llms.xai.chat.transformation import XAIChatConfig @@ -397,7 +397,7 @@ class AzureAIStudioConfig(OpenAIConfig): return data def _drop_tool_level_extra_fields(self, request_data: dict, error_text: str) -> dict: - fields_to_drop: Final = set(re.findall(r"tools\[\d+\]\.([\w-]+)", error_text)) + fields_to_drop: Final[Collection[str]] = set(re.findall(r"tools\[\d+\]\.([\w-]+)", error_text)) tools: Final = request_data.get("tools") if fields_to_drop and isinstance(tools, list): for tool in tools: diff --git a/litellm/llms/azure_ai/common_utils.py b/litellm/llms/azure_ai/common_utils.py index cffe9049de6..65d73363b30 100644 --- a/litellm/llms/azure_ai/common_utils.py +++ b/litellm/llms/azure_ai/common_utils.py @@ -6,7 +6,7 @@ from urllib.parse import urlparse import litellm from litellm.llms.base_llm.base_utils import BaseLLMModelInfo, BaseTokenCounter -from litellm.llms.openai.chat.gpt_5_transformation import OpenAIGPT5Config +from litellm.llms.openai.chat.gpt_reasoning_transformation import OpenAIGPT5Config from litellm.secret_managers.main import get_secret_str from litellm.types.llms.openai import AllMessageValues from litellm.types.router import GenericLiteLLMParams diff --git a/litellm/llms/base_llm/chat/transformation.py b/litellm/llms/base_llm/chat/transformation.py index b2eb4cde5ce..207a4705c92 100644 --- a/litellm/llms/base_llm/chat/transformation.py +++ b/litellm/llms/base_llm/chat/transformation.py @@ -94,9 +94,10 @@ class BaseConfig(ABC): @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("_") and not isinstance( v, @@ -437,6 +438,7 @@ class BaseConfig(ABC): sync_stream: bool, json_mode: bool | None, optional_params: Mapping[str, object], + logging_obj: LiteLLMLoggingObj | None = None, ) -> object: if sync_stream: return self.get_model_response_iterator( @@ -513,7 +515,7 @@ class BaseConfig(ABC): def apply_assembled_streaming_response_metadata( self, response: "ModelResponse", - chunks: list[Any], + chunks: list[object], ) -> None: """Hook for providers to merge chunk metadata into assembled streaming responses.""" return diff --git a/litellm/llms/base_llm/decisions/transformation.py b/litellm/llms/base_llm/decisions/transformation.py index a122aeb3033..b3df4654a6b 100644 --- a/litellm/llms/base_llm/decisions/transformation.py +++ b/litellm/llms/base_llm/decisions/transformation.py @@ -351,9 +351,10 @@ def _ir_score_answer(question: DecisionsIRScoreQuestion, answer: ScoreAnswer) -> DecisionsIRScoreProbability( value=index, label=answer.legend.get(str(index), level.label), - probability=answer.probabilities.get(str(index), 0.0), + probability=answer.probabilities[str(index)], ) for index, level in enumerate(question.levels) + if str(index) in answer.probabilities ), extra=MappingProxyType(answer.model_extra or {}), ) @@ -376,12 +377,14 @@ def _ir_answer(question: DecisionsIRQuestion, answer: DecisionAnswer | None) -> def systemone_response_to_ir(response: DecisionsResponse, request: DecisionsIRRequest) -> DecisionsIRResponse: - usage: Final = response.usage or DecisionsUsage() + usage: Final = response.usage keyed_questions: Final = zip(systemone_keys(request.questions), request.questions, strict=True) return DecisionsIRResponse( model=response.model, answers=tuple(_ir_answer(question, response.answers.get(key)) for key, question in keyed_questions), - usage=DecisionsIRUsage( + usage=None + if usage is None + else DecisionsIRUsage( input_tokens=usage.input_tokens, output_tokens=usage.output_tokens, cached_tokens=usage.cached_tokens, @@ -485,7 +488,9 @@ def ir_to_systemone_response(response: DecisionsIRResponse, request: DecisionsIR **response.extra, "model": response.model, "answers": {key: answer for key, answer in keyed_answers if answer is not None}, - "usage": DecisionsUsage.model_validate( + "usage": None + if response.usage is None + else DecisionsUsage.model_validate( { **response.usage.extra, "input_tokens": response.usage.input_tokens, diff --git a/litellm/llms/base_llm/guardrail_translation/base_translation.py b/litellm/llms/base_llm/guardrail_translation/base_translation.py index 5fe81a7f1b7..6399ded9555 100644 --- a/litellm/llms/base_llm/guardrail_translation/base_translation.py +++ b/litellm/llms/base_llm/guardrail_translation/base_translation.py @@ -121,7 +121,7 @@ class BaseTranslation(ABC): @staticmethod def merge_user_api_key_metadata_into_request( - request_data: dict[str, Any], # mutable-ok: proxy hooks share and mutate the request payload dict in place + request_data: dict[str, object], # mutable-ok: proxy hooks share and mutate the request payload dict in place user_api_key_dict: Optional["UserAPIKeyAuth"], ) -> None: """ diff --git a/litellm/llms/base_llm/guardrail_translation/utils.py b/litellm/llms/base_llm/guardrail_translation/utils.py index 55a4b3da0b3..725146fe894 100644 --- a/litellm/llms/base_llm/guardrail_translation/utils.py +++ b/litellm/llms/base_llm/guardrail_translation/utils.py @@ -9,6 +9,8 @@ from pydantic import BaseModel, ConfigDict, TypeAdapter, ValidationError from litellm.types.llms.anthropic_messages.anthropic_response import AnthropicUsage from litellm.types.llms.openai import AllMessageValues, ResponseAPIUsage +_DECODED_JSON: Final = TypeAdapter(object) + def _anthropic_stream_chunk_events(item: object) -> list[dict]: if isinstance(item, dict): @@ -30,7 +32,7 @@ def _anthropic_stream_chunk_events(item: object) -> list[dict]: if not payload or payload == "[DONE]": continue try: - parsed = json.loads(payload) + parsed = _DECODED_JSON.validate_python(json.loads(payload)) except json.JSONDecodeError: continue if isinstance(parsed, dict): diff --git a/litellm/llms/base_llm/image_edit/transformation.py b/litellm/llms/base_llm/image_edit/transformation.py index 4faf0aaaf30..35b4bb90025 100644 --- a/litellm/llms/base_llm/image_edit/transformation.py +++ b/litellm/llms/base_llm/image_edit/transformation.py @@ -1,7 +1,7 @@ import types from abc import ABC, abstractmethod from collections.abc import Mapping -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING, Any, Final import httpx from httpx._types import RequestFiles @@ -32,9 +32,10 @@ class BaseImageEditConfig(ABC): @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not k.startswith("_abc") and not isinstance( diff --git a/litellm/llms/base_llm/interactions/transformation.py b/litellm/llms/base_llm/interactions/transformation.py index b7bbf7bde73..39ca1d8f7d7 100644 --- a/litellm/llms/base_llm/interactions/transformation.py +++ b/litellm/llms/base_llm/interactions/transformation.py @@ -11,7 +11,8 @@ Per OpenAPI spec (https://ai.google.dev/static/api/interactions.openapi.json): import types from abc import ABC, abstractmethod -from typing import TYPE_CHECKING, Any +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, Final import httpx @@ -60,9 +61,10 @@ class BaseInteractionsAPIConfig(ABC): @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not k.startswith("_abc") and not isinstance( diff --git a/litellm/llms/base_llm/managed_resources/base_managed_resource.py b/litellm/llms/base_llm/managed_resources/base_managed_resource.py index d3b05716452..2663a3c42e7 100644 --- a/litellm/llms/base_llm/managed_resources/base_managed_resource.py +++ b/litellm/llms/base_llm/managed_resources/base_managed_resource.py @@ -141,7 +141,7 @@ class BaseManagedResource(ABC, Generic[ResourceObjectType]): self, llm_router: Router, model: str, - request_data: dict[str, Any], + request_data: dict[str, object], litellm_parent_otel_span: Span, ) -> ResourceObjectType: """ @@ -399,7 +399,7 @@ class BaseManagedResource(ABC, Generic[ResourceObjectType]): async def create_resource_for_each_model( self, llm_router: Router, - request_data: dict[str, Any], + request_data: dict[str, object], target_model_names_list: list[str], litellm_parent_otel_span: Span, ) -> list[ResourceObjectType]: diff --git a/litellm/llms/base_llm/passthrough/transformation.py b/litellm/llms/base_llm/passthrough/transformation.py index ac5032c08f1..7e58cc6e71b 100644 --- a/litellm/llms/base_llm/passthrough/transformation.py +++ b/litellm/llms/base_llm/passthrough/transformation.py @@ -28,6 +28,7 @@ if TYPE_CHECKING: RELAYED_JSON_OBJECT: Final = TypeAdapter(Mapping[str, object]) +_DECODED_JSON: Final = TypeAdapter(object) class PassthroughMetadata(LiteLLMBaseModel): @@ -71,7 +72,7 @@ def relayed_json_object(httpx_response: Response) -> Mapping[str, object] | None def relayed_body(httpx_response: Response) -> str | dict: try: - body: Final[object] = httpx_response.json() + body: Final = _DECODED_JSON.validate_python(httpx_response.json()) except ValueError: return httpx_response.text return body if isinstance(body, dict) else httpx_response.text diff --git a/litellm/llms/base_llm/rerank/transformation.py b/litellm/llms/base_llm/rerank/transformation.py index 5d2f92b5e82..7f246bf33da 100644 --- a/litellm/llms/base_llm/rerank/transformation.py +++ b/litellm/llms/base_llm/rerank/transformation.py @@ -80,7 +80,7 @@ class BaseRerankConfig(ABC): model: str, drop_params: bool, query: str, - documents: list[str | dict[str, Any]], + documents: list[str | dict[str, object]], custom_llm_provider: str | None = None, top_n: int | None = None, rank_fields: list[str] | None = None, diff --git a/litellm/llms/base_llm/text_to_speech/transformation.py b/litellm/llms/base_llm/text_to_speech/transformation.py index fb85cdb7687..be49098b62b 100644 --- a/litellm/llms/base_llm/text_to_speech/transformation.py +++ b/litellm/llms/base_llm/text_to_speech/transformation.py @@ -1,6 +1,7 @@ import types from abc import ABC, abstractmethod -from typing import TYPE_CHECKING, Any, TypedDict +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, Final, TypedDict import httpx @@ -40,9 +41,10 @@ class BaseTextToSpeechConfig(ABC): @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not k.startswith("_abc") and not isinstance( diff --git a/litellm/llms/base_llm/vector_store/transformation.py b/litellm/llms/base_llm/vector_store/transformation.py index 28f6348e4d9..6885183aeba 100644 --- a/litellm/llms/base_llm/vector_store/transformation.py +++ b/litellm/llms/base_llm/vector_store/transformation.py @@ -152,7 +152,7 @@ class BaseVectorStoreConfig: api_base: str, litellm_logging_obj: LiteLLMLoggingObj, litellm_params: dict, - extra_body: dict[str, Any] | None = None, + extra_body: dict[str, object] | None = None, ) -> tuple[str, dict]: pass @@ -164,7 +164,7 @@ class BaseVectorStoreConfig: api_base: str, litellm_logging_obj: LiteLLMLoggingObj, litellm_params: dict, - extra_body: dict[str, Any] | None = None, + extra_body: dict[str, object] | None = None, ) -> tuple[str, dict]: """ Optional async version of transform_search_vector_store_request. @@ -221,6 +221,11 @@ class BaseVectorStoreConfig: raise ValueError("api_base is required") return api_base + def get_vector_store_url(self, api_base: str, encoded_vector_store_id: str) -> str: + """Url of one vector store for retrieve, update and delete. Providers whose + ``get_complete_url`` adds a query string, like Azure, override this.""" + return f"{api_base}/{encoded_vector_store_id}" + def get_error_class(self, error_message: str, status_code: int, headers: dict | httpx.Headers) -> BaseLLMException: from ..chat.transformation import BaseLLMException diff --git a/litellm/llms/baseten/chat.py b/litellm/llms/baseten/chat.py index 381d487c36d..c165831b90a 100644 --- a/litellm/llms/baseten/chat.py +++ b/litellm/llms/baseten/chat.py @@ -1,3 +1,4 @@ +from collections.abc import Mapping from typing import Final import litellm @@ -42,7 +43,7 @@ class BasetenConfig(OpenAIGPTConfig): frequency_penalty: int | None = None, stream_options: dict | None = None, ) -> None: - locals_: Final = locals().copy() + locals_: Final[Mapping[str, object]] = dict(locals()) for key, value in locals_.items(): if key != "self" and value is not None: setattr(self.__class__, key, value) diff --git a/litellm/llms/bedrock/batches/handler.py b/litellm/llms/bedrock/batches/handler.py index 48e79d39b8e..f37abacc883 100644 --- a/litellm/llms/bedrock/batches/handler.py +++ b/litellm/llms/bedrock/batches/handler.py @@ -174,12 +174,13 @@ class BedrockBatchesHandler: ) def job_status() -> "LiteLLMBatch": + auth_kwargs: Final[Mapping[str, object]] = dict(auth_params.model_dump()) return BedrockBatchesHandler.handle_model_invocation_job_status( batch_id=batch_id, aws_region_name=region, logging_obj=logging_obj, aws_bedrock_control_plane_endpoint=control_plane_endpoint, - **auth_params.model_dump(), + **auth_kwargs, ) try: diff --git a/litellm/llms/bedrock/chat/agentcore/transformation.py b/litellm/llms/bedrock/chat/agentcore/transformation.py index bb5bb246a93..18212b7390f 100644 --- a/litellm/llms/bedrock/chat/agentcore/transformation.py +++ b/litellm/llms/bedrock/chat/agentcore/transformation.py @@ -10,6 +10,7 @@ from typing import TYPE_CHECKING, Any, Final, Optional, Union from urllib.parse import quote import httpx +from pydantic import TypeAdapter from litellm._logging import verbose_logger from litellm._uuid import uuid @@ -51,6 +52,8 @@ else: HTTPHandler = Any AsyncHTTPHandler = Any +_DECODED_JSON: Final = TypeAdapter(object) + class AmazonAgentCoreConfig(BaseConfig, BaseAWSLLM): def __init__(self, **kwargs): @@ -314,7 +317,7 @@ class AmazonAgentCoreConfig(BaseConfig, BaseAWSLLM): return None try: - data: Final[object] = json.loads(json_str) + data: Final = _DECODED_JSON.validate_python(json.loads(json_str)) # Skip non-dict data (some lines contain JSON strings) return data if isinstance(data, dict) else None except json.JSONDecodeError: @@ -482,7 +485,7 @@ class AmazonAgentCoreConfig(BaseConfig, BaseAWSLLM): if "application/json" in content_type: # Direct JSON response verbose_logger.debug("Parsing JSON response") - response_json: Final[object] = raw_response.json() + response_json: Final = _DECODED_JSON.validate_python(raw_response.json()) verbose_logger.debug("Response JSON: %s", response_json) return self._parse_json_response(response_json) else: @@ -566,7 +569,7 @@ class AmazonAgentCoreConfig(BaseConfig, BaseAWSLLM): continue try: - data_obj = json.loads(json_str) + data_obj = _DECODED_JSON.validate_python(json.loads(json_str)) if not isinstance(data_obj, dict): continue @@ -706,7 +709,7 @@ class AmazonAgentCoreConfig(BaseConfig, BaseAWSLLM): ) try: body: Final = response.read() - response_json: Final[object] = json.loads(body) + response_json: Final = _DECODED_JSON.validate_python(json.loads(body)) except (json.JSONDecodeError, Exception) as e: raise BedrockError( status_code=response.status_code, @@ -788,7 +791,7 @@ class AmazonAgentCoreConfig(BaseConfig, BaseAWSLLM): continue try: - data_obj = json.loads(json_str) + data_obj = _DECODED_JSON.validate_python(json.loads(json_str)) if not isinstance(data_obj, dict): continue @@ -928,7 +931,7 @@ class AmazonAgentCoreConfig(BaseConfig, BaseAWSLLM): ) try: body: Final = await response.aread() - response_json: Final[object] = json.loads(body) + response_json: Final = _DECODED_JSON.validate_python(json.loads(body)) except (json.JSONDecodeError, Exception) as e: raise BedrockError( status_code=response.status_code, diff --git a/litellm/llms/bedrock/chat/converse_transformation.py b/litellm/llms/bedrock/chat/converse_transformation.py index cd3727401ef..f54c352fd6e 100644 --- a/litellm/llms/bedrock/chat/converse_transformation.py +++ b/litellm/llms/bedrock/chat/converse_transformation.py @@ -12,7 +12,8 @@ from itertools import chain from typing import TYPE_CHECKING, Final, Literal, cast, overload import httpx -from pydantic import TypeAdapter, ValidationError +from pydantic import ConfigDict, TypeAdapter, ValidationError, with_config +from typing_extensions import ReadOnly, TypedDict import litellm from litellm._logging import verbose_logger @@ -21,6 +22,7 @@ from litellm.constants import ( RESPONSE_FORMAT_TOOL_NAME, ) from litellm.litellm_core_utils.core_helpers import ( + as_str_mapping, filter_exceptions_from_params, filter_internal_params, map_finish_reason, @@ -160,6 +162,14 @@ _TOOLS_AS_SENT: Final = TypeAdapter(tuple[Mapping[str, object], ...]) _JSON_VALUE: Final = TypeAdapter(object) _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object]) _TOOLS_AS_RECEIVED: Final = TypeAdapter(list[object]) + + +@with_config(ConfigDict(extra="allow", strict=True)) +class _ToolCallInContent(TypedDict): + name: ReadOnly[str] + + +_TOOL_CALL_IN_CONTENT: Final = TypeAdapter(_ToolCallInContent) CLAUDE_ON_BEDROCK_INVOKE_REMEDY: Final = " This model runs tool search on Bedrock through `bedrock/invoke/`." _DEPLOYMENT_PARAMS: Final = TypeAdapter(Mapping[str, object]) @@ -1945,7 +1955,7 @@ class AmazonConverseConfig(BaseConfig): anthropic_beta_list: list, ) -> None: """Keep only compact_20260112 edits for Bedrock; add beta header or drop field.""" - from litellm.llms.anthropic.pass_through.context_management.constants import ( + from litellm.llms.anthropic.messages.context_management.constants import ( COMPACT_EDIT_TYPE, ) from litellm.types.llms.anthropic import ANTHROPIC_BETA_HEADER_VALUES @@ -2453,9 +2463,17 @@ class AmazonConverseConfig(BaseConfig): if message.content is not None: try: tool_call_names: Final = self.get_tool_call_names(tools) - json_content: Final = json.loads(message.content) - if json_content.get("type") == "function" and json_content.get("name") in tool_call_names: - tool_calls: Final = [ChatCompletionMessageToolCall(function=Function(**json_content))] + json_content: Final = as_str_mapping(_JSON_VALUE.validate_python(json.loads(message.content))) + if ( + json_content is not None + and json_content.get("type") == "function" + and json_content.get("name") in tool_call_names + ): + tool_calls: Final = [ + ChatCompletionMessageToolCall( + function=Function(**_TOOL_CALL_IN_CONTENT.validate_python(json_content)) + ) + ] message.tool_calls = tool_calls message.content = None @@ -2841,6 +2859,8 @@ class AmazonConverseConfig(BaseConfig): # Add "trace" from Bedrock guardrails - if user has opted in to returning it if "trace" in completion_response: setattr(model_response, "trace", completion_response["trace"]) + if logging_obj is not None: + logging_obj.record_native_bedrock_guardrail(model_response) # Add service_tier if present in Bedrock response # Map Bedrock serviceTier (object) to OpenAI service_tier (string) diff --git a/litellm/llms/bedrock/chat/invoke_handler.py b/litellm/llms/bedrock/chat/invoke_handler.py index 3d4821fcaa2..a6b34010297 100644 --- a/litellm/llms/bedrock/chat/invoke_handler.py +++ b/litellm/llms/bedrock/chat/invoke_handler.py @@ -13,6 +13,7 @@ from litellm.caching.caching import InMemoryCache from litellm.constants import RESPONSE_FORMAT_TOOL_NAME from litellm.litellm_core_utils.core_helpers import map_finish_reason from litellm.litellm_core_utils.litellm_logging import Logging +from litellm.litellm_core_utils.llm_cost_calc.guardrail_cost import object_mapping from litellm.litellm_core_utils.llm_response_utils.get_headers import provider_request_id_headers from litellm.litellm_core_utils.optional_imports import ensure_optional_import from litellm.litellm_core_utils.prompt_templates.common_utils import native_redacted_thinking_data @@ -22,6 +23,7 @@ from litellm.llms.anthropic.chat.handler import ( from litellm.llms.anthropic.chat.transformation import JsonModeRequest from litellm.llms.base_llm import base_model_iterator from litellm.llms.base_llm.base_utils import ResponseFormatSchema +from litellm.llms.bedrock.common_utils import BEDROCK_INVOKE_TRACE_FIELD from litellm.llms.custom_httpx.http_handler import ( AsyncHTTPHandler, HTTPHandler, @@ -962,8 +964,19 @@ class AmazonAnthropicClaudeStreamDecoder(AWSEventStreamDecoder): response_format_schema=response_format_schema, ) - def _chunk_parser(self, chunk_data: dict) -> ModelResponseStream: - return self.anthropic_model_response_iterator.chunk_parser(chunk=chunk_data) + def _chunk_parser(self, chunk_data: dict[str, object]) -> ModelResponseStream: + parsed: Final = self.anthropic_model_response_iterator.chunk_parser(chunk=chunk_data) + trace: Final = object_mapping(chunk_data.get(BEDROCK_INVOKE_TRACE_FIELD)) + if trace is None: + return parsed + return parsed.model_copy( + update={ + "provider_specific_fields": { + **(parsed.provider_specific_fields or {}), + BEDROCK_INVOKE_TRACE_FIELD: trace, + } + } + ) def _stream_end_chunk(self) -> ModelResponseStream | None: return self.anthropic_model_response_iterator.cut_stream_chunk() diff --git a/litellm/llms/bedrock/chat/invoke_transformations/amazon_ai21_transformation.py b/litellm/llms/bedrock/chat/invoke_transformations/amazon_ai21_transformation.py index 3005bc82299..777237b4f18 100644 --- a/litellm/llms/bedrock/chat/invoke_transformations/amazon_ai21_transformation.py +++ b/litellm/llms/bedrock/chat/invoke_transformations/amazon_ai21_transformation.py @@ -56,9 +56,10 @@ class AmazonAI21Config(AmazonInvokeConfig, BaseConfig): @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not k.startswith("_abc") and not isinstance( diff --git a/litellm/llms/bedrock/chat/invoke_transformations/amazon_cohere_transformation.py b/litellm/llms/bedrock/chat/invoke_transformations/amazon_cohere_transformation.py index 00c2eaf0f8f..2118d183b22 100644 --- a/litellm/llms/bedrock/chat/invoke_transformations/amazon_cohere_transformation.py +++ b/litellm/llms/bedrock/chat/invoke_transformations/amazon_cohere_transformation.py @@ -37,9 +37,10 @@ class AmazonCohereConfig(AmazonInvokeConfig, CohereChatConfig): @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not k.startswith("_abc") and not isinstance( diff --git a/litellm/llms/bedrock/chat/invoke_transformations/amazon_llama_transformation.py b/litellm/llms/bedrock/chat/invoke_transformations/amazon_llama_transformation.py index d2eb6eef9ef..cb867a09f8f 100644 --- a/litellm/llms/bedrock/chat/invoke_transformations/amazon_llama_transformation.py +++ b/litellm/llms/bedrock/chat/invoke_transformations/amazon_llama_transformation.py @@ -37,9 +37,10 @@ class AmazonLlamaConfig(AmazonInvokeConfig, BaseConfig): @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not k.startswith("_abc") and not isinstance( diff --git a/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py b/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py index 44511eeaa3e..4420bb3a418 100644 --- a/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py +++ b/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py @@ -47,9 +47,10 @@ class AmazonMistralConfig(AmazonInvokeConfig, BaseConfig): @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not k.startswith("_abc") and not isinstance( diff --git a/litellm/llms/bedrock/chat/invoke_transformations/amazon_titan_transformation.py b/litellm/llms/bedrock/chat/invoke_transformations/amazon_titan_transformation.py index a18e97c63a6..736b3ea3cd2 100644 --- a/litellm/llms/bedrock/chat/invoke_transformations/amazon_titan_transformation.py +++ b/litellm/llms/bedrock/chat/invoke_transformations/amazon_titan_transformation.py @@ -43,9 +43,10 @@ class AmazonTitanConfig(AmazonInvokeConfig, BaseConfig): @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not k.startswith("_abc") and not isinstance( diff --git a/litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.py b/litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude_transformation.py similarity index 97% rename from litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.py rename to litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude_transformation.py index 240a85ce327..eb6ed5c75e3 100644 --- a/litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.py +++ b/litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude_transformation.py @@ -5,6 +5,7 @@ import httpx from pydantic import TypeAdapter from litellm.anthropic_beta_headers_manager import filter_and_transform_beta_headers +from litellm.litellm_core_utils.llm_cost_calc.guardrail_cost import object_mapping from litellm.litellm_core_utils.prompt_templates.factory import ( convert_to_anthropic_image_obj, ) @@ -22,6 +23,7 @@ from litellm.llms.bedrock.chat.invoke_transformations.base_invoke_transformation AmazonInvokeConfig, ) from litellm.llms.bedrock.common_utils import ( + BEDROCK_INVOKE_TRACE_FIELD, apply_bedrock_invoke_structured_output, bedrock_chat_uses_native_structured_output, bedrock_cleaned_output_schema, @@ -406,7 +408,7 @@ class AmazonAnthropicClaudeConfig(AmazonInvokeConfig, AnthropicConfig): api_key: str | None = None, json_mode: bool | None = None, ) -> ModelResponse: - return AnthropicConfig.transform_response( + response: Final = AnthropicConfig.transform_response( self, model=model, raw_response=raw_response, @@ -420,3 +422,9 @@ class AmazonAnthropicClaudeConfig(AmazonInvokeConfig, AnthropicConfig): api_key=api_key, json_mode=json_mode, ) + body: Final = object_mapping(raw_response.json()) or {} + trace: Final = object_mapping(body.get(BEDROCK_INVOKE_TRACE_FIELD)) + if trace is not None: + setattr(response, BEDROCK_INVOKE_TRACE_FIELD, trace) + logging_obj.record_native_bedrock_guardrail(response) + return response diff --git a/litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude2_transformation.py b/litellm/llms/bedrock/chat/invoke_transformations/anthropic_legacy_text_completions_transformation.py similarity index 95% rename from litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude2_transformation.py rename to litellm/llms/bedrock/chat/invoke_transformations/anthropic_legacy_text_completions_transformation.py index b29ddf01d1e..2655c13be44 100644 --- a/litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude2_transformation.py +++ b/litellm/llms/bedrock/chat/invoke_transformations/anthropic_legacy_text_completions_transformation.py @@ -44,9 +44,10 @@ class AmazonAnthropicConfig(AmazonInvokeConfig): @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not isinstance( v, diff --git a/litellm/llms/bedrock/chat/mantle/transformation.py b/litellm/llms/bedrock/chat/mantle/transformation.py index e48196946cd..b5a352bab48 100644 --- a/litellm/llms/bedrock/chat/mantle/transformation.py +++ b/litellm/llms/bedrock/chat/mantle/transformation.py @@ -12,7 +12,7 @@ from typing import TYPE_CHECKING, Any, Final from litellm.litellm_core_utils.prompt_templates.image_handling import async_inline_remote_media from litellm.llms.anthropic.chat.transformation import JsonModeRequest -from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformation import ( +from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeConfig, ) from litellm.llms.bedrock.common_utils import build_mantle_messages_url @@ -21,6 +21,7 @@ from litellm.types.utils import ModelResponse if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import Logging as _LiteLLMLoggingObj + from litellm.llms.anthropic.chat.handler import ModelResponseIterator LiteLLMLoggingObj = _LiteLLMLoggingObj else: @@ -134,7 +135,7 @@ class AmazonMantleConfig(AmazonAnthropicClaudeConfig): streaming_response: Iterator[str] | AsyncIterator[str] | ModelResponse, sync_stream: bool, json_mode: bool | None = False, - ) -> Any: + ) -> "ModelResponseIterator": return self.get_model_response_iterator_for_request( streaming_response=streaming_response, sync_stream=sync_stream, json_mode=json_mode, optional_params={} ) @@ -145,7 +146,8 @@ class AmazonMantleConfig(AmazonAnthropicClaudeConfig): sync_stream: bool, json_mode: bool | None, optional_params: Mapping[str, object], - ) -> object: + logging_obj: LiteLLMLoggingObj | None = None, + ) -> "ModelResponseIterator": from litellm.llms.anthropic.chat.handler import ModelResponseIterator return ModelResponseIterator( diff --git a/litellm/llms/bedrock/claude_platform/messages_transformation.py b/litellm/llms/bedrock/claude_platform/messages_transformation.py index 57ebaa0ca71..06308cde124 100644 --- a/litellm/llms/bedrock/claude_platform/messages_transformation.py +++ b/litellm/llms/bedrock/claude_platform/messages_transformation.py @@ -1,7 +1,7 @@ from typing import Final import litellm -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( DEFAULT_ANTHROPIC_API_VERSION, AnthropicMessagesConfig, ) diff --git a/litellm/llms/bedrock/claude_platform/transformation.py b/litellm/llms/bedrock/claude_platform/transformation.py index cea1140bf65..0194f1c7e45 100644 --- a/litellm/llms/bedrock/claude_platform/transformation.py +++ b/litellm/llms/bedrock/claude_platform/transformation.py @@ -14,6 +14,7 @@ from .common_utils import ( ) if TYPE_CHECKING: + from litellm.litellm_core_utils.litellm_logging import Logging from litellm.llms.anthropic.chat.handler import ModelResponseIterator @@ -110,6 +111,7 @@ class BedrockClaudePlatformConfig(BedrockClaudePlatformMixin, AnthropicConfig): sync_stream: bool, json_mode: bool | None, optional_params: Mapping[str, object], + logging_obj: "Logging | None" = None, ) -> "ModelResponseIterator": from litellm.llms.anthropic.chat.handler import ModelResponseIterator diff --git a/litellm/llms/bedrock/common_utils.py b/litellm/llms/bedrock/common_utils.py index 4954e646f58..28888f1a23a 100644 --- a/litellm/llms/bedrock/common_utils.py +++ b/litellm/llms/bedrock/common_utils.py @@ -45,6 +45,8 @@ if TYPE_CHECKING: from litellm.llms.custom_httpx.http_handler import HTTPHandler from litellm.types.llms.openai import AllMessageValues +BEDROCK_INVOKE_TRACE_FIELD: Final = "amazon-bedrock-trace" + _ERROR_REQUEST_URL: Final = "https://docs.litellm.ai/docs" _OPENAI_FAMILY_MODEL_RE: Final = re.compile(r"(^|[./])openai\.") @@ -2021,8 +2023,13 @@ def get_bedrock_response_stream_shape(): _BEDROCK_STREAM_OUTPUT_SHAPES: Final = ("ConverseStreamOutput", "ResponseStream") +class _ModeledErrorMetadata(TypedDict, total=False): + httpStatusCode: ReadOnly[int] + + def _modeled_error_status(member: Shape) -> int | None: - status: Final = (member.metadata or {}).get("error", {}).get("httpStatusCode") + error: Final[_ModeledErrorMetadata] = (member.metadata or {}).get("error", {}) + status: Final = error.get("httpStatusCode") return None if status is None else int(status) diff --git a/litellm/llms/bedrock/cost_calculation.py b/litellm/llms/bedrock/cost_calculation.py index 0a2e39ab972..1b45531dda4 100644 --- a/litellm/llms/bedrock/cost_calculation.py +++ b/litellm/llms/bedrock/cost_calculation.py @@ -3,9 +3,13 @@ Helper util for handling bedrock-specific cost calculation - e.g.: prompt caching """ -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Final -from litellm.litellm_core_utils.llm_cost_calc.utils import generic_cost_per_token +import litellm +from litellm.litellm_core_utils.llm_cost_calc.utils import ( + generic_cost_per_token, + get_provider_specific_geo_multiplier, +) if TYPE_CHECKING: from litellm.types.utils import Usage @@ -17,9 +21,13 @@ def cost_per_token(model: str, usage: "Usage", service_tier: str | None = None) Follows the same logic as Anthropic's cost per token calculation. """ - return generic_cost_per_token( + model_info: Final = litellm.get_model_info(model=model, custom_llm_provider="bedrock") + prompt_cost, completion_cost = generic_cost_per_token( model=model, usage=usage, custom_llm_provider="bedrock", service_tier=service_tier, + model_info=model_info, ) + geo_multiplier: Final = get_provider_specific_geo_multiplier(model_info=model_info, usage=usage) + return prompt_cost * geo_multiplier, completion_cost * geo_multiplier diff --git a/litellm/llms/bedrock/count_tokens/kimi_k3.py b/litellm/llms/bedrock/count_tokens/kimi_k3.py index 4f8b4624cd8..5eb46944f9a 100644 --- a/litellm/llms/bedrock/count_tokens/kimi_k3.py +++ b/litellm/llms/bedrock/count_tokens/kimi_k3.py @@ -32,7 +32,7 @@ from litellm.litellm_core_utils.prompt_templates.factory import ( chat_completion_tools_for, is_flat_responses_tool, ) -from litellm.llms.anthropic.pass_through.adapters.transformation import LiteLLMAnthropicMessagesAdapter +from litellm.llms.anthropic.messages.adapters.transformation import LiteLLMAnthropicMessagesAdapter from litellm.types.llms.openai import AllMessageValues, ChatCompletionToolParam KIMI_K3_REPO: Final = "moonshotai/Kimi-K3" diff --git a/litellm/llms/bedrock/embed/amazon_titan_g1_transformation.py b/litellm/llms/bedrock/embed/amazon_titan_g1_transformation.py index 581b89369f7..fba2673b5aa 100644 --- a/litellm/llms/bedrock/embed/amazon_titan_g1_transformation.py +++ b/litellm/llms/bedrock/embed/amazon_titan_g1_transformation.py @@ -35,9 +35,10 @@ class AmazonTitanG1Config: @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not isinstance( v, diff --git a/litellm/llms/bedrock/embed/amazon_titan_v2_transformation.py b/litellm/llms/bedrock/embed/amazon_titan_v2_transformation.py index 3b594662a9b..7d319ca6b06 100644 --- a/litellm/llms/bedrock/embed/amazon_titan_v2_transformation.py +++ b/litellm/llms/bedrock/embed/amazon_titan_v2_transformation.py @@ -39,9 +39,10 @@ class AmazonTitanV2Config: @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not isinstance( v, diff --git a/litellm/llms/bedrock/files/handler.py b/litellm/llms/bedrock/files/handler.py index 3d23b69f846..37f95ff7b9b 100644 --- a/litellm/llms/bedrock/files/handler.py +++ b/litellm/llms/bedrock/files/handler.py @@ -1,6 +1,6 @@ import asyncio from collections.abc import Coroutine, Mapping -from typing import Any, Final +from typing import Final import httpx @@ -139,7 +139,7 @@ class BedrockFilesHandler(BaseAWSLLM): optional_params: dict, timeout: float | httpx.Timeout, max_retries: int | None, - ) -> HttpxBinaryResponseContent | Coroutine[Any, Any, HttpxBinaryResponseContent]: + ) -> HttpxBinaryResponseContent | Coroutine[object, object, HttpxBinaryResponseContent]: """ Download file content from S3 bucket for Bedrock files. Supports both sync and async operations. diff --git a/litellm/llms/bedrock/files/transformation.py b/litellm/llms/bedrock/files/transformation.py index cb10c2384cd..8c4702bcf99 100644 --- a/litellm/llms/bedrock/files/transformation.py +++ b/litellm/llms/bedrock/files/transformation.py @@ -1052,7 +1052,7 @@ class BedrockFilesConfig(BaseAWSLLM, BaseFilesConfig): # --- Anthropic: use existing AmazonAnthropicClaudeConfig --- if provider == LlmProviders.ANTHROPIC: - from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformation import ( + from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeConfig, ) diff --git a/litellm/llms/bedrock/image_edit/handler.py b/litellm/llms/bedrock/image_edit/handler.py index 466993de9d1..bdfe6f5a8d2 100644 --- a/litellm/llms/bedrock/image_edit/handler.py +++ b/litellm/llms/bedrock/image_edit/handler.py @@ -10,6 +10,7 @@ import json from typing import TYPE_CHECKING, Any, Final import httpx +from pydantic import TypeAdapter import litellm from litellm._logging import verbose_logger @@ -39,6 +40,8 @@ if TYPE_CHECKING: else: AWSPreparedRequest = Any +_DECODED_JSON: Final = TypeAdapter(object) + class BedrockImageEditPreparedRequest(LiteLLMBaseModel): """ @@ -317,7 +320,7 @@ class BedrockImageEdit(BaseAWSLLM): additional_args={"complete_input_dict": data}, ) verbose_logger.debug("raw model_response: %s", response.text) - response_dict: Final = response.json() + response_dict: Final = _DECODED_JSON.validate_python(response.json()) if response_dict is None: raise ValueError("Error in response object format, got None") diff --git a/litellm/llms/bedrock/image_generation/amazon_stability3_transformation.py b/litellm/llms/bedrock/image_generation/amazon_stability3_transformation.py index acc847e0e3c..e5c5edba750 100644 --- a/litellm/llms/bedrock/image_generation/amazon_stability3_transformation.py +++ b/litellm/llms/bedrock/image_generation/amazon_stability3_transformation.py @@ -1,4 +1,5 @@ import types +from collections.abc import Mapping from typing import Final from openai.types.image import Image @@ -20,9 +21,10 @@ class AmazonStability3Config: @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not isinstance( v, diff --git a/litellm/llms/bedrock/image_generation/amazon_titan_transformation.py b/litellm/llms/bedrock/image_generation/amazon_titan_transformation.py index 145e6a0781f..5731541da56 100644 --- a/litellm/llms/bedrock/image_generation/amazon_titan_transformation.py +++ b/litellm/llms/bedrock/image_generation/amazon_titan_transformation.py @@ -3,6 +3,7 @@ Transformation logic for Amazon Titan Image Generation. """ import types +from collections.abc import Mapping from typing import Final from openai.types.image import Image @@ -35,16 +36,17 @@ class AmazonTitanImageGenerationConfig: width: int | None = None, height: int | None = None, ) -> None: - locals_: Final = locals().copy() + locals_: Final[Mapping[str, object]] = types.MappingProxyType(locals().copy()) for key, value in locals_.items(): if key != "self" and value is not None: setattr(self.__class__, key, value) @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not isinstance( v, diff --git a/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py b/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude_transformation.py similarity index 97% rename from litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py rename to litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude_transformation.py index 12421aa94fd..e1e15861a90 100644 --- a/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py +++ b/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude_transformation.py @@ -1,4 +1,4 @@ -from collections.abc import AsyncIterator, Mapping +from collections.abc import AsyncIterator, Mapping, Sequence from types import MappingProxyType from typing import TYPE_CHECKING, Any, Final, cast @@ -24,7 +24,7 @@ from litellm.llms.anthropic.common_utils import ( carried_thinking_keys, validated_object_mapping, ) -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) from litellm.llms.base_llm.anthropic_messages.transformation import ( @@ -33,6 +33,7 @@ from litellm.llms.base_llm.anthropic_messages.transformation import ( from litellm.llms.bedrock.chat.invoke_handler import AWSEventStreamDecoder from litellm.llms.bedrock.chat.invoke_transformations.base_invoke_transformation import ( AmazonInvokeConfig, + bedrock_invoke_guardrail_headers, ) from litellm.llms.bedrock.common_utils import ( BedrockError, @@ -145,14 +146,20 @@ class AmazonAnthropicClaudeMessagesConfig( self, headers: dict, model: str, - messages: list[object], + messages: Sequence[object], optional_params: dict, litellm_params: dict, api_key: str | None = None, api_base: str | None = None, ) -> tuple[dict, str | None]: + raw_guardrail_config: Final = litellm_params.get("guardrailConfig") # pyright: ignore[reportUnknownVariableType, reportUnknownMemberType] # litellm_params is an untyped dict param + guardrail_headers: Final = ( + () + if raw_guardrail_config is None + else tuple(bedrock_invoke_guardrail_headers(raw_guardrail_config).items()) # pyright: ignore[reportUnknownArgumentType] # read from the untyped dict param + ) owned_names, metadata_headers = bedrock_request_metadata_headers(litellm_params) - return merge_bedrock_invoke_headers(headers, (), metadata_headers, owned_names), api_base + return merge_bedrock_invoke_headers(headers, guardrail_headers, metadata_headers, owned_names), api_base # pyright: ignore[reportUnknownArgumentType] # headers is an untyped dict param def sign_request( self, @@ -878,7 +885,7 @@ class AmazonAnthropicClaudeMessagesConfig( merge them from ``message_start`` so logging/cost sees a consistent usage object (fixes negative input costs: LIT-2411). """ - from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( + from litellm.llms.anthropic.messages.native.streaming_iterator import ( BaseAnthropicMessagesStreamingIterator, ) diff --git a/litellm/llms/bedrock/messages/mantle_transformation.py b/litellm/llms/bedrock/messages/mantle_transformation.py index c71721d800e..89f4cc4dd8b 100644 --- a/litellm/llms/bedrock/messages/mantle_transformation.py +++ b/litellm/llms/bedrock/messages/mantle_transformation.py @@ -7,19 +7,19 @@ stripping, and the anthropic-version / anthropic-beta placement (headers, never the body) that are specific to the bedrock-mantle endpoint. """ -from collections.abc import AsyncIterator, Mapping +from collections.abc import AsyncIterator, Mapping, Sequence from types import MappingProxyType from typing import TYPE_CHECKING, Any, Final import httpx from pydantic import TypeAdapter -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( DEFAULT_ANTHROPIC_API_VERSION, AnthropicMessagesConfig, ) from litellm.llms.bedrock.common_utils import build_mantle_messages_url -from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude3_transformation import ( +from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeMessagesConfig, ) from litellm.types.llms.anthropic_messages.anthropic_response import ( @@ -90,7 +90,7 @@ class AmazonMantleMessagesConfig(AmazonAnthropicClaudeMessagesConfig): self, headers: dict, model: str, - messages: list[Any], + messages: Sequence[object], optional_params: dict, litellm_params: dict, api_key: str | None = None, diff --git a/litellm/llms/bedrock/model_listing.py b/litellm/llms/bedrock/model_listing.py index 99ff48f9400..409bf2c7b97 100644 --- a/litellm/llms/bedrock/model_listing.py +++ b/litellm/llms/bedrock/model_listing.py @@ -4,7 +4,7 @@ from typing import Final, TypeAlias from urllib.parse import quote, urlencode import httpx -from pydantic import BaseModel, ConfigDict, Field +from pydantic import BaseModel, ConfigDict, Field, TypeAdapter from litellm.litellm_core_utils.aws_partition import get_aws_dns_suffix from litellm.llms.bedrock.base_aws_llm import BaseAWSLLM, bedrock_bearer_token @@ -15,6 +15,7 @@ from litellm.types.llms.bedrock import AwsAuthParams LIST_MODELS_TIMEOUT: Final = 10.0 INFERENCE_PROFILES_PAGE_SIZE: Final = 1000 INFERENCE_PROFILES_PAGE_CAP: Final = 20 +_DECODED_JSON: Final = TypeAdapter(object) QueryPairs: TypeAlias = tuple[tuple[str, str], ...] @@ -103,7 +104,7 @@ class BedrockModelLister(BaseAWSLLM): f"Status code: {response.status_code}, Response: {response.text}" ), ) - return response.json() + return _DECODED_JSON.validate_python(response.json()) def _auth_headers(self, url: str) -> Mapping[str, str]: if self._bearer_token is not None: diff --git a/litellm/llms/bedrock/passthrough/guardrail_translation/handler.py b/litellm/llms/bedrock/passthrough/guardrail_translation/handler.py index a90b4829634..1b01b0ec6d0 100644 --- a/litellm/llms/bedrock/passthrough/guardrail_translation/handler.py +++ b/litellm/llms/bedrock/passthrough/guardrail_translation/handler.py @@ -544,7 +544,7 @@ class _StreamFrame(TypedDict): def _unpack_uint32(buffer: bytes) -> int: - return struct.unpack("!I", buffer)[0] + return int.from_bytes(buffer, "big") def _collect_stream_delta_text_holders(delta: object) -> list[_DeltaHolder]: @@ -1255,7 +1255,9 @@ class BedrockPassthroughGuardrailHandler(BaseTranslation): headers_bytes = frame_raw[12 : 12 + orig_hdrs_len] try: - payload_dict = json.loads(frame_raw[12 + orig_hdrs_len : orig_total - 4]) + payload_dict = _BODY_BY_REFERENCE.validate_python( + json.loads(frame_raw[12 + orig_hdrs_len : orig_total - 4]) + ) for local_idx, (_, container, key) in enumerate( _collect_stream_delta_text_holders(payload_dict.get("delta")) ): diff --git a/litellm/llms/bedrock_mantle/chat/transformation.py b/litellm/llms/bedrock_mantle/chat/transformation.py index 61c7d51a889..9e168f14401 100644 --- a/litellm/llms/bedrock_mantle/chat/transformation.py +++ b/litellm/llms/bedrock_mantle/chat/transformation.py @@ -24,7 +24,7 @@ from litellm.llms.bedrock_mantle.common_utils import ( BEDROCK_MANTLE_DEFAULT_REGION, BedrockMantleAuthMixin, ) -from litellm.llms.openai.chat.gpt_5_transformation import get_effort_level, is_gpt_reasoning_series_name +from litellm.llms.openai.chat.gpt_reasoning_transformation import get_effort_level, is_gpt_reasoning_series_name from litellm.secret_managers.main import get_secret_str from litellm.types.llms.openai import AllMessageValues from litellm.types.router import GenericLiteLLMParams diff --git a/litellm/llms/black_forest_labs/image_edit/transformation.py b/litellm/llms/black_forest_labs/image_edit/transformation.py index 7cfb0daf334..38bcbb0d905 100644 --- a/litellm/llms/black_forest_labs/image_edit/transformation.py +++ b/litellm/llms/black_forest_labs/image_edit/transformation.py @@ -51,6 +51,7 @@ class _BflPolledResult(TypedDict): _BFL_POLLED_RESULT_ADAPTER: Final = TypeAdapter(_BflPolledResult) +_DECODED_JSON: Final = TypeAdapter(object) _BFL_REQUEST_PARAMS: Final = ( @@ -316,7 +317,7 @@ class BlackForestLabsImageEditConfig(BaseImageEditConfig): The response contains: {"status": "Ready", "result": {"sample": "https://..."}} """ try: - raw_response_data: Final[object] = raw_response.json() + raw_response_data: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception as e: raise BlackForestLabsError( status_code=raw_response.status_code, diff --git a/litellm/llms/black_forest_labs/image_generation/transformation.py b/litellm/llms/black_forest_labs/image_generation/transformation.py index 928af314506..52f2c9a7c50 100644 --- a/litellm/llms/black_forest_labs/image_generation/transformation.py +++ b/litellm/llms/black_forest_labs/image_generation/transformation.py @@ -40,6 +40,7 @@ else: LiteLLMLoggingObj = Any _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_input_in_errors=True)) +_DECODED_JSON: Final = TypeAdapter(object) class BlackForestLabsImageGenerationConfig(BaseImageGenerationConfig): @@ -272,7 +273,7 @@ class BlackForestLabsImageGenerationConfig(BaseImageGenerationConfig): The response contains: {"status": "Ready", "result": {"sample": "https://..."}} """ try: - response_data: Final = raw_response.json() + response_data: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception as e: raise BlackForestLabsError( status_code=raw_response.status_code, diff --git a/litellm/llms/cerebras/chat.py b/litellm/llms/cerebras/chat.py index c3aa26ade35..9fc99500fc5 100644 --- a/litellm/llms/cerebras/chat.py +++ b/litellm/llms/cerebras/chat.py @@ -4,6 +4,7 @@ Cerebras Chat Completions API this is OpenAI compatible - no translation needed / occurs """ +from collections.abc import Mapping from typing import Final from litellm.llms.openai.chat.gpt_transformation import OpenAIGPTConfig @@ -41,7 +42,7 @@ class CerebrasConfig(OpenAIGPTConfig): user: str | None = None, reasoning_effort: str | None = None, ) -> None: - locals_: Final = locals().copy() + locals_: Final[Mapping[str, object]] = dict(locals()) for key, value in locals_.items(): if key != "self" and value is not None: setattr(self.__class__, key, value) diff --git a/litellm/llms/chatgpt/authenticator.py b/litellm/llms/chatgpt/authenticator.py index ff9c6476cba..a5fb1c9c6b9 100644 --- a/litellm/llms/chatgpt/authenticator.py +++ b/litellm/llms/chatgpt/authenticator.py @@ -1,9 +1,9 @@ -import base64 import json import os import time from collections.abc import Mapping -from typing import Final, TypeAlias +from functools import lru_cache +from typing import TYPE_CHECKING, Final import httpx from pydantic import JsonValue, TypeAdapter, ValidationError @@ -24,19 +24,21 @@ from .common_utils import ( CHATGPT_OAUTH_TOKEN_URL, GetAccessTokenError, GetDeviceCodeError, + JsonObject, RefreshAccessTokenError, + decode_jwt_claims, + extract_chatgpt_account_id, ) +if TYPE_CHECKING: + from litellm.types.router import GenericLiteLLMParams + TOKEN_EXPIRY_SKEW_SECONDS: Final = 60 TOKEN_REFRESH_TIMEOUT_SECONDS: Final = 30 DEVICE_CODE_TIMEOUT_SECONDS: Final = 15 * 60 DEVICE_CODE_COOLDOWN_SECONDS: Final = 5 * 60 DEVICE_CODE_POLL_SLEEP_SECONDS: Final = 5 -OPENAI_AUTH_CLAIM_KEY: Final = "https://api.openai.com/auth" - -JsonObject: TypeAlias = Mapping[str, JsonValue] - _JSON_OBJECT_ADAPTER: Final = TypeAdapter(JsonObject) @@ -44,6 +46,26 @@ def _optional_str(value: JsonValue | None) -> str | None: return value if isinstance(value, str) else None +def get_chatgpt_auth_file( + litellm_params: "Mapping[str, object] | GenericLiteLLMParams | None", +) -> str | None: + if litellm_params is None: + return None + value: Final = ( + litellm_params.get("chatgpt_auth_file") + if isinstance(litellm_params, Mapping) + else litellm_params.chatgpt_auth_file + ) + if not isinstance(value, str) or not value: + return None + return os.path.abspath(os.path.expanduser(value)) + + +@lru_cache(maxsize=128) +def get_cached_authenticator(auth_file: str) -> "Authenticator": + return Authenticator(auth_file=auth_file) + + def _token_refresh_timeout() -> httpx.Timeout: configured: Final = get_configured_request_timeout() seconds: Final = ( @@ -53,13 +75,13 @@ def _token_refresh_timeout() -> httpx.Timeout: class Authenticator: - def __init__(self) -> None: - self.token_dir = os.getenv( - "CHATGPT_TOKEN_DIR", - os.path.expanduser("~/.config/litellm/chatgpt"), + def __init__(self, auth_file: str | None = None) -> None: + default_auth_file: Final = os.path.join( + os.getenv("CHATGPT_TOKEN_DIR", os.path.expanduser("~/.config/litellm/chatgpt")), + os.getenv("CHATGPT_AUTH_FILE", "auth.json"), ) - self.auth_file = os.path.join(self.token_dir, os.getenv("CHATGPT_AUTH_FILE", "auth.json")) - self._ensure_token_dir() + self.auth_file = os.path.abspath(os.path.expanduser(auth_file or default_auth_file)) + self.token_dir = os.path.dirname(self.auth_file) def get_api_base(self) -> str: return os.getenv("CHATGPT_API_BASE") or os.getenv("OPENAI_CHATGPT_API_BASE") or CHATGPT_API_BASE @@ -99,16 +121,18 @@ class Authenticator: tokens: Final = self._login_device_code() return tokens["access_token"] - def get_account_id(self) -> str | None: + def get_account_id(self, access_token: str | None = None) -> str | None: auth_data: Final = self._read_auth_file() + if access_token and (not auth_data or auth_data.get("access_token") != access_token): + return extract_chatgpt_account_id(access_token) if not auth_data: return None account_id: Final = _optional_str(auth_data.get("account_id")) if account_id: return account_id id_token: Final = auth_data.get("id_token") - access_token: Final = auth_data.get("access_token") - derived: Final = self._extract_account_id(_optional_str(id_token or access_token)) + saved_access_token: Final = auth_data.get("access_token") + derived: Final = extract_chatgpt_account_id(_optional_str(id_token or saved_access_token)) if derived: self._write_auth_file({**auth_data, "account_id": derived}) return derived @@ -129,6 +153,7 @@ class Authenticator: def _write_auth_file(self, data: JsonObject) -> None: try: + self._ensure_token_dir() with open(self.auth_file, "w") as f: json.dump(data, f) except OSError as exc: @@ -146,34 +171,11 @@ class Authenticator: return time.time() >= float(derived_expires_at) - TOKEN_EXPIRY_SKEW_SECONDS def _get_expires_at(self, token: str) -> int | None: - claims: Final = self._decode_jwt_claims(token) - exp: Final = claims.get("exp") + exp: Final = decode_jwt_claims(token).get("exp") if isinstance(exp, (int, float)): return int(exp) return None - def _decode_jwt_claims(self, token: str) -> JsonObject: - try: - parts: Final = token.split(".") - if len(parts) < 2: - return {} - payload_b64: Final = parts[1] + "=" * (-len(parts[1]) % 4) - payload_bytes: Final = base64.urlsafe_b64decode(payload_b64) - return _JSON_OBJECT_ADAPTER.validate_python(json.loads(payload_bytes.decode("utf-8"))) - except Exception: - return {} - - def _extract_account_id(self, token: str | None) -> str | None: - if not token: - return None - claims: Final = self._decode_jwt_claims(token) - auth_claims: Final = claims.get(OPENAI_AUTH_CLAIM_KEY) - if isinstance(auth_claims, dict): - account_id: Final = auth_claims.get("chatgpt_account_id") - if isinstance(account_id, str) and account_id: - return account_id - return None - def _login_device_code(self) -> dict[str, str]: cooldown_remaining: Final = self._get_device_code_cooldown_remaining(self._read_auth_file()) if cooldown_remaining > 0: @@ -361,15 +363,16 @@ class Authenticator: "refresh_token": _optional_str(data.get("refresh_token")) or refresh_token, "id_token": id_token, } + account_id: Final = self.get_account_id() auth_data: Final = self._build_auth_record(refreshed) - self._write_auth_file(auth_data) + self._write_auth_file({**auth_data, "account_id": account_id} if account_id else auth_data) return refreshed def _build_auth_record(self, tokens: dict[str, str]) -> JsonObject: access_token: Final = tokens.get("access_token") id_token: Final = tokens.get("id_token") expires_at: Final = self._get_expires_at(access_token) if access_token else None - account_id: Final = self._extract_account_id(id_token or access_token) + account_id: Final = extract_chatgpt_account_id(id_token or access_token) return { "access_token": access_token, "refresh_token": tokens.get("refresh_token"), diff --git a/litellm/llms/chatgpt/chat/streaming_utils.py b/litellm/llms/chatgpt/chat/streaming_utils.py index ee3120bacea..49be583f6d1 100644 --- a/litellm/llms/chatgpt/chat/streaming_utils.py +++ b/litellm/llms/chatgpt/chat/streaming_utils.py @@ -7,6 +7,8 @@ Normalizes non-spec-compliant tool_call chunks from the ChatGPT backend API. from collections.abc import Awaitable from typing import Final, Protocol +from pydantic import TypeAdapter + from litellm.types.utils import ( ChatCompletionDeltaCustomToolCall, ChatCompletionDeltaToolCall, @@ -23,6 +25,9 @@ class ChatGPTChunkStream(Protocol): def __anext__(self) -> Awaitable[ModelResponseStream]: ... +_DELEGATED_ATTRIBUTE: Final = TypeAdapter(object) + + def _first_choice_delta(chunk: ModelResponseStream) -> Delta | None: return chunk.choices[0].delta @@ -47,7 +52,7 @@ class ChatGPTToolCallNormalizer: self._last_id: str | None = None # tracks which tool call the next delta belongs to def __getattr__(self, name: str) -> object: - return getattr(self._stream, name) + return _DELEGATED_ATTRIBUTE.validate_python(getattr(self._stream, name)) def __iter__(self) -> "ChatGPTToolCallNormalizer": return self diff --git a/litellm/llms/chatgpt/chat/transformation.py b/litellm/llms/chatgpt/chat/transformation.py index a1aac7f315b..9005185931f 100644 --- a/litellm/llms/chatgpt/chat/transformation.py +++ b/litellm/llms/chatgpt/chat/transformation.py @@ -1,14 +1,20 @@ +from collections.abc import Mapping from typing import Any, Final from litellm.exceptions import AuthenticationError from litellm.llms.openai.openai import OpenAIConfig from litellm.types.llms.openai import AllMessageValues +from litellm.types.router import GenericLiteLLMParams -from ..authenticator import Authenticator +from ..authenticator import Authenticator, get_cached_authenticator, get_chatgpt_auth_file from ..common_utils import ( GetAccessTokenError, + chatgpt_client_api_base, ensure_chatgpt_session_id, + get_chatgpt_client_credential, get_chatgpt_default_headers, + get_chatgpt_request_credential, + strip_chatgpt_client_credential_headers, ) from .streaming_utils import ChatGPTToolCallNormalizer @@ -19,9 +25,27 @@ class ChatGPTConfig(OpenAIConfig): api_key: str | None = None, api_base: str | None = None, custom_llm_provider: str = "openai", + authenticator: Authenticator | None = None, ) -> None: super().__init__() - self.authenticator = Authenticator() + self.authenticator = authenticator if authenticator is not None else Authenticator() + + def _resolve_authenticator( + self, litellm_params: Mapping[str, object] | GenericLiteLLMParams | None + ) -> Authenticator: + auth_file: Final = get_chatgpt_auth_file(litellm_params) + return get_cached_authenticator(auth_file) if auth_file else self.authenticator + + @staticmethod + def _get_access_token_or_raise(authenticator: Authenticator, model: str, llm_provider: str) -> str: + try: + return authenticator.get_access_token() + except GetAccessTokenError as e: + raise AuthenticationError( + model=model, + llm_provider=llm_provider, + message=str(e), + ) def api_base_without_login(self) -> str: return self.authenticator.get_api_base() @@ -32,16 +56,16 @@ class ChatGPTConfig(OpenAIConfig): api_base: str | None, api_key: str | None, custom_llm_provider: str, + litellm_params: Mapping[str, object] | GenericLiteLLMParams | None = None, ) -> tuple[str | None, str | None, str]: - dynamic_api_base: Final = self.api_base_without_login() - try: - dynamic_api_key: Final = self.authenticator.get_access_token() - except GetAccessTokenError as e: - raise AuthenticationError( - model=model, - llm_provider=custom_llm_provider, - message=str(e), - ) + client_credential: Final = get_chatgpt_request_credential(litellm_params) + if client_credential is not None: + return chatgpt_client_api_base(api_base), client_credential.access_token, custom_llm_provider + if api_key: + return api_base or self.api_base_without_login(), api_key, custom_llm_provider + authenticator: Final = self._resolve_authenticator(litellm_params) + dynamic_api_base: Final = authenticator.get_api_base() + dynamic_api_key: Final = self._get_access_token_or_raise(authenticator, model, custom_llm_provider) return dynamic_api_base, dynamic_api_key, custom_llm_provider def get_openai_compatible_provider_info( @@ -50,26 +74,49 @@ class ChatGPTConfig(OpenAIConfig): api_base: str | None, api_key: str | None, custom_llm_provider: str, + litellm_params: Mapping[str, object] | GenericLiteLLMParams | None = None, ) -> tuple[str | None, str | None, str]: - return self._get_openai_compatible_provider_info(model, api_base, api_key, custom_llm_provider) + return self._get_openai_compatible_provider_info(model, api_base, api_key, custom_llm_provider, litellm_params) def validate_environment( self, - headers: dict, + headers: dict[str, str], model: str, messages: list[AllMessageValues], optional_params: dict, - litellm_params: dict, + litellm_params: dict[str, object], api_key: str | None = None, api_base: str | None = None, - ) -> dict: + ) -> dict[str, str]: + client_credential: Final = get_chatgpt_client_credential(headers) + if client_credential is not None: + return dict( + get_chatgpt_default_headers( + client_credential.access_token, + client_credential.account_id, + ensure_chatgpt_session_id(litellm_params), + ), + **strip_chatgpt_client_credential_headers(headers), + ) + authenticator: Final = self._resolve_authenticator(litellm_params) + resolved_api_key: Final = ( + self._get_access_token_or_raise(authenticator, model, "chatgpt") + if get_chatgpt_auth_file(litellm_params) + else api_key + ) validated_headers: Final = super().validate_environment( - headers, model, messages, optional_params, litellm_params, api_key, api_base + dict(strip_chatgpt_client_credential_headers(headers)), + model, + messages, + optional_params, + litellm_params, + resolved_api_key, + api_base, ) - account_id: Final = self.authenticator.get_account_id() + account_id: Final = authenticator.get_account_id(resolved_api_key) session_id: Final = ensure_chatgpt_session_id(litellm_params) - default_headers: Final = get_chatgpt_default_headers(api_key or "", account_id, session_id) + default_headers: Final = get_chatgpt_default_headers(resolved_api_key or "", account_id, session_id) return {**default_headers, **validated_headers} def post_stream_processing(self, stream: Any) -> ChatGPTToolCallNormalizer: diff --git a/litellm/llms/chatgpt/common_utils.py b/litellm/llms/chatgpt/common_utils.py index fe33219f110..ec7fbfa92da 100644 --- a/litellm/llms/chatgpt/common_utils.py +++ b/litellm/llms/chatgpt/common_utils.py @@ -2,14 +2,32 @@ Constants and helpers for ChatGPT subscription OAuth. """ +import base64 +import json import os import platform -from typing import Any, Final +from collections.abc import Mapping, Sequence +from dataclasses import dataclass +from types import MappingProxyType +from typing import TYPE_CHECKING, Final, TypeAlias +from urllib.parse import urlsplit from uuid import uuid4 import httpx +from pydantic import JsonValue, TypeAdapter +from litellm.litellm_core_utils.get_provider_specific_headers import ProviderSpecificHeaderUtils from litellm.llms.base_llm.chat.transformation import BaseLLMException +from litellm.types.utils import ProviderSpecificHeader + +if TYPE_CHECKING: + from litellm.types.router import GenericLiteLLMParams + +_SCOPED_HEADERS: Final[TypeAdapter[ProviderSpecificHeader | Sequence[ProviderSpecificHeader] | None]] = TypeAdapter( + ProviderSpecificHeader | Sequence[ProviderSpecificHeader] | None +) +_STRING_HEADERS: Final = TypeAdapter(Mapping[str, str]) +_PARAMS: Final = TypeAdapter(Mapping[str, object]) # OAuth + API constants (derived from openai/codex) CHATGPT_AUTH_BASE: Final = "https://auth.openai.com" @@ -19,6 +37,12 @@ CHATGPT_OAUTH_TOKEN_URL: Final = f"{CHATGPT_AUTH_BASE}/oauth/token" CHATGPT_DEVICE_VERIFY_URL: Final = f"{CHATGPT_AUTH_BASE}/codex/device" CHATGPT_API_BASE: Final = "https://chatgpt.com/backend-api/codex" CHATGPT_CLIENT_ID: Final = "app_EMoamEEZ73f0CkXaXp7hrann" +CHATGPT_ACCOUNT_ID_HEADER: Final = "ChatGPT-Account-Id" +OPENAI_AUTH_CLAIM_KEY: Final = "https://api.openai.com/auth" + +JsonObject: TypeAlias = Mapping[str, JsonValue] +_JSON_OBJECT_ADAPTER: Final = TypeAdapter(JsonObject) +_EMPTY_CLAIMS: Final[JsonObject] = MappingProxyType({}) DEFAULT_ORIGINATOR: Final = "codex_cli_rs" DEFAULT_USER_AGENT: Final = "codex_cli_rs/0.0.0 (Unknown 0; unknown) unknown" @@ -229,7 +253,7 @@ def get_chatgpt_default_headers( access_token: str, account_id: str | None, session_id: str | None = None, -) -> dict: +) -> dict[str, str]: originator: Final = get_chatgpt_originator() user_agent: Final = get_chatgpt_user_agent(originator) headers: Final = { @@ -242,30 +266,133 @@ def get_chatgpt_default_headers( if session_id: headers["session_id"] = session_id if account_id: - headers["ChatGPT-Account-Id"] = account_id + headers[CHATGPT_ACCOUNT_ID_HEADER] = account_id return headers +def decode_jwt_claims(token: str) -> JsonObject: + try: + parts: Final = token.split(".") + if len(parts) < 2: + return _EMPTY_CLAIMS + payload_b64: Final = parts[1] + "=" * (-len(parts[1]) % 4) + payload_bytes: Final = base64.urlsafe_b64decode(payload_b64) + return _JSON_OBJECT_ADAPTER.validate_python(json.loads(payload_bytes.decode("utf-8"))) + except Exception: + return _EMPTY_CLAIMS + + +def extract_chatgpt_account_id(token: str | None) -> str | None: + if not token: + return None + auth_claims: Final = decode_jwt_claims(token).get(OPENAI_AUTH_CLAIM_KEY) + if not isinstance(auth_claims, dict): + return None + account_id: Final = auth_claims.get("chatgpt_account_id") + return account_id if isinstance(account_id, str) and account_id else None + + +def _bearer_token(value: str) -> str: + scheme, separator, token = value.strip().partition(" ") + if not separator: + return scheme + return token.strip() if scheme.lower() == "bearer" else "" + + +def is_chatgpt_oauth_key(value: str | None) -> bool: + if value is None: + return False + return OPENAI_AUTH_CLAIM_KEY in decode_jwt_claims(_bearer_token(value)) + + +@dataclass(frozen=True, slots=True) +class ChatGPTClientCredential: + access_token: str + account_id: str | None + + +def _header_value(headers: Mapping[str, str], name: str) -> str | None: + return next((value for key, value in headers.items() if key.lower() == name), None) + + +def get_chatgpt_client_credential(headers: Mapping[str, str]) -> ChatGPTClientCredential | None: + auth_header: Final = _header_value(headers, "authorization") + if auth_header is None or not is_chatgpt_oauth_key(auth_header): + return None + access_token: Final = _bearer_token(auth_header) + account_id: Final = _header_value(headers, CHATGPT_ACCOUNT_ID_HEADER.lower()) or extract_chatgpt_account_id( + access_token + ) + return ChatGPTClientCredential(access_token=access_token, account_id=account_id) + + +def select_chatgpt_client_credential_headers(headers: Mapping[str, str]) -> Mapping[str, str]: + if get_chatgpt_client_credential(headers) is None: + return MappingProxyType({}) + return MappingProxyType( + { + key: value + for key, value in headers.items() + if (key.lower() == "authorization" and is_chatgpt_oauth_key(value)) + or key.lower() == CHATGPT_ACCOUNT_ID_HEADER.lower() + } + ) + + +def strip_chatgpt_client_credential_headers(headers: Mapping[str, str]) -> Mapping[str, str]: + return MappingProxyType( + { + key: value + for key, value in headers.items() + if key.lower() not in ("authorization", CHATGPT_ACCOUNT_ID_HEADER.lower()) + } + ) + + +def get_chatgpt_request_credential( + params: "Mapping[str, object] | GenericLiteLLMParams | None", +) -> ChatGPTClientCredential | None: + normalized: Final = _normalize_litellm_params(params) + scoped: Final = normalized.get("provider_specific_header") + extra: Final = normalized.get("extra_headers") + headers: Final = ProviderSpecificHeaderUtils.get_provider_specific_headers( + provider_specific_header=_SCOPED_HEADERS.validate_python(scoped), custom_llm_provider="chatgpt" + ) + return get_chatgpt_client_credential(headers) or get_chatgpt_client_credential( + _STRING_HEADERS.validate_python(extra) if extra is not None else MappingProxyType({}) + ) + + +def chatgpt_client_api_base(api_base: str | None) -> str: + base: Final = api_base or CHATGPT_API_BASE + parsed: Final = urlsplit(base) + if ( + parsed.scheme != "https" + or parsed.hostname != "chatgpt.com" + or parsed.port not in (None, 443) + or parsed.username + or parsed.password + ): + raise ChatGPTAuthError( + status_code=400, message="Client ChatGPT credentials require the official HTTPS ChatGPT endpoint" + ) + return base + + def get_chatgpt_default_instructions() -> str: return os.getenv("CHATGPT_DEFAULT_INSTRUCTIONS") or CHATGPT_DEFAULT_INSTRUCTIONS -def _normalize_litellm_params(litellm_params: Any | None) -> dict: - if litellm_params is None: - return {} - if isinstance(litellm_params, dict): - return litellm_params - if hasattr(litellm_params, "model_dump"): - try: - return litellm_params.model_dump() - except Exception: - return {} - if hasattr(litellm_params, "dict"): - try: - return litellm_params.dict() - except Exception: - return {} - return {} +def _normalize_litellm_params(litellm_params: object) -> Mapping[str, object]: + if isinstance(litellm_params, Mapping): + return _PARAMS.validate_python(litellm_params) + serializer: Final = getattr(litellm_params, "model_dump", None) or getattr(litellm_params, "dict", None) + if not callable(serializer): + return MappingProxyType({}) + try: + return _PARAMS.validate_python(serializer()) + except Exception: + return MappingProxyType({}) def get_chatgpt_session_id(litellm_params: object) -> str | None: @@ -274,8 +401,8 @@ def get_chatgpt_session_id(litellm_params: object) -> str | None: value = params.get(key) if value: return str(value) - metadata: Final = params.get("metadata") - if isinstance(metadata, dict): + metadata: Final = _normalize_litellm_params(params.get("metadata")) + if metadata: value = metadata.get("session_id") if value: return str(value) diff --git a/litellm/llms/chatgpt/responses/transformation.py b/litellm/llms/chatgpt/responses/transformation.py index 34953a79c60..2352de35b5b 100644 --- a/litellm/llms/chatgpt/responses/transformation.py +++ b/litellm/llms/chatgpt/responses/transformation.py @@ -25,13 +25,15 @@ from litellm.types.llms.openai import ( from litellm.types.router import GenericLiteLLMParams from litellm.types.utils import LlmProviders -from ..authenticator import Authenticator +from ..authenticator import Authenticator, get_cached_authenticator, get_chatgpt_auth_file from ..common_utils import ( CHATGPT_API_BASE, GetAccessTokenError, ensure_chatgpt_session_id, + get_chatgpt_client_credential, get_chatgpt_default_headers, get_chatgpt_default_instructions, + strip_chatgpt_client_credential_headers, ) if TYPE_CHECKING: @@ -49,14 +51,35 @@ class ChatGPTResponsesAPIConfig(OpenAIResponsesAPIConfig): def custom_llm_provider(self) -> LlmProviders: return LlmProviders.CHATGPT + def _resolve_authenticator(self, litellm_params: GenericLiteLLMParams | None) -> Authenticator: + auth_file: Final = get_chatgpt_auth_file(litellm_params) + return get_cached_authenticator(auth_file) if auth_file else self.authenticator + def validate_environment( self, - headers: dict, + headers: dict[str, str], model: str, litellm_params: GenericLiteLLMParams | None, - ) -> dict: + ) -> dict[str, str]: + session_id: Final = ensure_chatgpt_session_id(litellm_params) + client_credential: Final = get_chatgpt_client_credential(headers) + if client_credential is not None: + return { + **get_chatgpt_default_headers(client_credential.access_token, client_credential.account_id, session_id), + **strip_chatgpt_client_credential_headers(headers), + } + authenticator: Final = self._resolve_authenticator(litellm_params) + safe_headers: Final = strip_chatgpt_client_credential_headers(headers) + configured_api_key: Final = litellm_params.api_key if litellm_params is not None else None + if configured_api_key and not get_chatgpt_auth_file(litellm_params): + return { + **get_chatgpt_default_headers( + configured_api_key, authenticator.get_account_id(configured_api_key), session_id + ), + **safe_headers, + } try: - access_token: Final = self.authenticator.get_access_token() + access_token: Final = authenticator.get_access_token() except GetAccessTokenError as e: raise AuthenticationError( model=model, @@ -64,10 +87,9 @@ class ChatGPTResponsesAPIConfig(OpenAIResponsesAPIConfig): message=str(e), ) - account_id: Final = self.authenticator.get_account_id() - session_id: Final = ensure_chatgpt_session_id(litellm_params) + account_id: Final = authenticator.get_account_id() default_headers: Final = get_chatgpt_default_headers(access_token, account_id, session_id) - return {**default_headers, **headers} + return {**default_headers, **safe_headers} def transform_responses_api_request( self, @@ -79,7 +101,7 @@ class ChatGPTResponsesAPIConfig(OpenAIResponsesAPIConfig): ) -> dict: request: Final = super().transform_responses_api_request( model, - input, + [{"role": "user", "content": input}] if isinstance(input, str) else input, response_api_optional_request_params, litellm_params, headers, diff --git a/litellm/llms/clarifai/chat/transformation.py b/litellm/llms/clarifai/chat/transformation.py index 8c2fd9e0aff..d07ae5e4215 100644 --- a/litellm/llms/clarifai/chat/transformation.py +++ b/litellm/llms/clarifai/chat/transformation.py @@ -23,6 +23,7 @@ else: LiteLLMLoggingObj = Any _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(strict=True, hide_input_in_errors=True)) +_DECODED_JSON: Final = TypeAdapter(object) class ClarifaiConfig(OpenAIGPTConfig): @@ -114,7 +115,7 @@ class ClarifaiConfig(OpenAIGPTConfig): ) ## Reponse try: - completion_response: Final = raw_response.json() + completion_response: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception as e: raise OpenAIError( status_code=raw_response.status_code, diff --git a/litellm/llms/claude_code/harness/transformation.py b/litellm/llms/claude_code/harness/transformation.py index f75d86c7e63..8252d2dd461 100644 --- a/litellm/llms/claude_code/harness/transformation.py +++ b/litellm/llms/claude_code/harness/transformation.py @@ -30,6 +30,7 @@ from litellm.harness.types import ( ToolCall, ToolResult, ) +from litellm.litellm_core_utils.core_helpers import iter_items from litellm.llms.base_llm.harness.transformation import ( BaseCLIHarnessConfig, HarnessSessionSetup, @@ -231,12 +232,12 @@ def _system_events(event: Mapping[str, object], state: ClaudeCodeStreamState) -> return event_list() -def _record_result(event: Mapping[str, Any], state: ClaudeCodeStreamState) -> Sequence[Event]: +def _record_result(event: Mapping[str, object], state: ClaudeCodeStreamState) -> Sequence[Event]: state.result_seen = True state.is_error = bool(event.get("is_error", False)) result = event.get("result") state.result_text = result if isinstance(result, str) else None - state.errors = [str(e) for e in event.get("errors") or ()] # mutable-ok: mirrors the JSON errors array + state.errors = [str(e) for e in iter_items(event.get("errors") or ())] # mutable-ok: mirrors the JSON errors array state.structured_output = event.get("structured_output") if event.get("session_id"): state.session_id = str(event["session_id"]) diff --git a/litellm/llms/cloudflare/chat/transformation.py b/litellm/llms/cloudflare/chat/transformation.py index 0a76588f767..2bbfd2010cc 100644 --- a/litellm/llms/cloudflare/chat/transformation.py +++ b/litellm/llms/cloudflare/chat/transformation.py @@ -58,7 +58,7 @@ class CloudflareChatConfig(OpenAIGPTConfig): trimmed: Final = api_base.rstrip("/") if trimmed.endswith("/ai/run"): verbose_logger.warning( - "Cloudflare api_base ending in '/ai/run' is the legacy Workers AI path and no longer serves OpenAI-compatible requests; rewriting to the '/ai/v1' endpoint" + "Cloudflare chat completions require the OpenAI-compatible '/ai/v1' endpoint; rewriting api_base ending in '/ai/run' to '/ai/v1'. Decision models continue to use the native Workers AI '/ai/run/{model}' endpoint." ) return join_api_base(trimmed[: -len("/ai/run")], "ai/v1") return api_base diff --git a/litellm/llms/cloudflare/decisions/transformation.py b/litellm/llms/cloudflare/decisions/transformation.py index 7c776367886..7575e8bce21 100644 --- a/litellm/llms/cloudflare/decisions/transformation.py +++ b/litellm/llms/cloudflare/decisions/transformation.py @@ -20,6 +20,8 @@ class CloudflareDecisionsConfig(BaseDecisionsConfig): inlines_remote_images = True def get_default_api_base(self) -> str | None: + # Decision models (Clef) require native /ai/run/{model} requests with + # state and questions; /ai/v1/chat/completions only accepts chat requests. return workers_ai_default_api_base() def missing_api_base_message(self, custom_llm_provider: str) -> str: diff --git a/litellm/llms/codestral/completion/handler.py b/litellm/llms/codestral/completion/handler.py index 08799c3a0a5..6bebfe2d444 100644 --- a/litellm/llms/codestral/completion/handler.py +++ b/litellm/llms/codestral/completion/handler.py @@ -2,7 +2,7 @@ ## handler file for TextCompletionCodestral Integration - https://codestral.com/ import json -from collections.abc import Callable +from collections.abc import Callable, Mapping from functools import partial from typing import Final, Protocol @@ -268,7 +268,7 @@ class CodestralTextCompletion: prompt = prompt_factory(model=model, messages=messages) ## Load Config - config: Final = litellm.CodestralTextCompletionConfig.get_config() + config: Final[Mapping[str, object]] = litellm.CodestralTextCompletionConfig.get_config() for k, v in config.items(): if ( k not in optional_params diff --git a/litellm/llms/codex/harness/transformation.py b/litellm/llms/codex/harness/transformation.py index 4512e39189e..d7388bd23fc 100644 --- a/litellm/llms/codex/harness/transformation.py +++ b/litellm/llms/codex/harness/transformation.py @@ -15,7 +15,7 @@ import re from collections.abc import Iterator, Mapping, Sequence from dataclasses import dataclass, field from types import MappingProxyType -from typing import TYPE_CHECKING, Any, Final +from typing import TYPE_CHECKING, Final from pydantic import ConfigDict, TypeAdapter @@ -31,6 +31,7 @@ from litellm.harness.types import ( ToolCall, ToolResult, ) +from litellm.litellm_core_utils.core_helpers import iter_items from litellm.llms.base_llm.harness.transformation import ( BaseCLIHarnessConfig, HarnessSessionSetup, @@ -77,13 +78,13 @@ class CodexStreamState: started: set[str] = field(default_factory=set) # mutable-ok: parser records announced tool items -def _tool_input(item: Mapping[str, Any]) -> tuple[str, str, Mapping[str, object], bool]: +def _tool_input(item: Mapping[str, object]) -> tuple[str, str, Mapping[str, object], bool]: """(normalized name, native name, input, builtin) for a tool-like item.""" item_type = item.get("type") if item_type == "command_execution": return "bash", "command_execution", MappingProxyType({"command": item.get("command", "")}), True if item_type == "file_change": - changes: Final = list(item.get("changes") or ()) # mutable-ok: JSON array, as codex reports it + changes: Final = list(iter_items(item.get("changes") or ())) # mutable-ok: JSON array, as codex reports it return "edit", "apply_patch", MappingProxyType({"changes": changes}), True if item_type == "web_search": return "web_search", "web_search", MappingProxyType({"query": item.get("query", "")}), True diff --git a/litellm/llms/cohere/chat/transformation.py b/litellm/llms/cohere/chat/transformation.py index fdf44d5333e..e7fadd7f375 100644 --- a/litellm/llms/cohere/chat/transformation.py +++ b/litellm/llms/cohere/chat/transformation.py @@ -1,6 +1,6 @@ import json import time -from collections.abc import AsyncIterator, Iterator, Sequence +from collections.abc import AsyncIterator, Iterator, Mapping, Sequence from typing import TYPE_CHECKING, Any, Final import httpx @@ -221,7 +221,8 @@ class CohereChatConfig(BaseConfig): headers: dict, ) -> dict: ## Load Config - for k, v in litellm.CohereChatConfig.get_config().items(): + config: Final[Mapping[str, object]] = litellm.CohereChatConfig.get_config() + for k, v in config.items(): if ( k not in optional_params ): # completion(top_k=3) > cohere_config(top_k=3) <- allows for dynamic variables to be passed in diff --git a/litellm/llms/cohere/rerank/transformation.py b/litellm/llms/cohere/rerank/transformation.py index 8b641c24e9b..7d9c8de7a07 100644 --- a/litellm/llms/cohere/rerank/transformation.py +++ b/litellm/llms/cohere/rerank/transformation.py @@ -15,6 +15,7 @@ from litellm.types.rerank import OptionalRerankParams, RerankRequest, RerankResp from ..common_utils import CohereError _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_input_in_errors=True)) +_DECODED_JSON: Final = TypeAdapter(object) class CohereRerankConfig(BaseRerankConfig): @@ -144,7 +145,7 @@ class CohereRerankConfig(BaseRerankConfig): No transformation required, litellm follows cohere API response format """ try: - raw_response_json: Final = raw_response.json() + raw_response_json: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception: raise CohereError(message=raw_response.text, status_code=raw_response.status_code) diff --git a/litellm/llms/cohere/rerank_v2/transformation.py b/litellm/llms/cohere/rerank_v2/transformation.py index 009a220534c..83596f90d1f 100644 --- a/litellm/llms/cohere/rerank_v2/transformation.py +++ b/litellm/llms/cohere/rerank_v2/transformation.py @@ -1,4 +1,4 @@ -from typing import Any, Final +from typing import Final from litellm.litellm_core_utils.url_utils import ensure_api_route from litellm.llms.cohere.rerank.transformation import CohereRerankConfig @@ -39,7 +39,7 @@ class CohereRerankV2Config(CohereRerankConfig): model: str, drop_params: bool, query: str, - documents: list[str | dict[str, Any]], + documents: list[str | dict[str, object]], custom_llm_provider: str | None = None, top_n: int | None = None, rank_fields: list[str] | None = None, diff --git a/litellm/llms/cometapi/chat/transformation.py b/litellm/llms/cometapi/chat/transformation.py index 2bf119a0a4a..ae04889bc97 100644 --- a/litellm/llms/cometapi/chat/transformation.py +++ b/litellm/llms/cometapi/chat/transformation.py @@ -6,7 +6,7 @@ Documentation: [CometAPI Documentation Link] """ from collections.abc import AsyncIterator, Iterator -from typing import Any, Final +from typing import Final import httpx @@ -137,7 +137,7 @@ class CometAPIConfig(OpenAIGPTConfig): streaming_response: Iterator[str] | AsyncIterator[str] | ModelResponse, sync_stream: bool, json_mode: bool | None = False, - ) -> Any: + ) -> "CometAPIChatCompletionStreamingHandler": """ Get model response iterator for streaming responses """ diff --git a/litellm/llms/compactifai/chat/transformation.py b/litellm/llms/compactifai/chat/transformation.py index a02db2338d8..87fc61985e6 100644 --- a/litellm/llms/compactifai/chat/transformation.py +++ b/litellm/llms/compactifai/chat/transformation.py @@ -3,10 +3,10 @@ CompactifAI chat completion transformation """ from collections.abc import Mapping, Sequence -from typing import TYPE_CHECKING, Any, Final +from typing import TYPE_CHECKING, Any, Final, Protocol, cast import httpx -from typing_extensions import ReadOnly, TypedDict +from typing_extensions import ReadOnly, Required, TypedDict from litellm.llms.base_llm.chat.transformation import BaseLLMException from litellm.llms.openai.common_utils import OpenAIError @@ -25,11 +25,32 @@ else: LiteLLMLoggingObj = Any +class _JsonResponse(Protocol): + def json(self) -> object: ... + + +def _json_body(response: _JsonResponse) -> object: + return response.json() + + +class _CompactifAIToolCall(TypedDict): + function: ReadOnly[Mapping[str, str]] + + +class _CompactifAIMessage(TypedDict, total=False): + content: str | None # writable-ok: json mode moves a lone tool call's arguments into the content in place + tool_calls: Sequence[_CompactifAIToolCall] | None # writable-ok: json mode clears the tool call it moved + + +class _CompactifAIChoice(TypedDict, total=False): + message: ReadOnly[_CompactifAIMessage] + + class CompactifAIResponseFields(TypedDict, total=False): """The chat completion fields of a CompactifAI response body.""" id: ReadOnly[str] - choices: ReadOnly[Sequence[Mapping[str, object]]] + choices: ReadOnly[Required[Sequence[_CompactifAIChoice]]] created: ReadOnly[int] model: ReadOnly[str] system_fingerprint: ReadOnly[str | None] @@ -82,22 +103,19 @@ class CompactifAIChatConfig(OpenAIGPTConfig): ) ## RESPONSE OBJECT - response_json: Final = raw_response.json() + response_json: Final = cast( # cast-ok: the body passes through unvalidated, as before it was typed + CompactifAIResponseFields, _json_body(raw_response) + ) # Handle JSON mode if needed if json_mode: for choice in response_json["choices"]: message = choice.get("message") - if message and message.get("tool_calls"): - # Convert tool calls to content for JSON mode - tool_calls = message.get("tool_calls", []) - if len(tool_calls) == 1: - message["content"] = tool_calls[0]["function"].get("arguments", "") - message["tool_calls"] = None + if message and (tool_calls := message.get("tool_calls")) and len(tool_calls) == 1: + message["content"] = tool_calls[0]["function"].get("arguments", "") + message["tool_calls"] = None - response_fields: Final[CompactifAIResponseFields] = response_json - - returned_response: Final = ModelResponse(**response_fields) + returned_response: Final = ModelResponse(**response_json) # Set model name with provider prefix returned_response.model = f"compactifai/{model}" diff --git a/litellm/llms/custom_httpx/aiohttp_transport.py b/litellm/llms/custom_httpx/aiohttp_transport.py index b8cb183c02f..0e4d97fd770 100644 --- a/litellm/llms/custom_httpx/aiohttp_transport.py +++ b/litellm/llms/custom_httpx/aiohttp_transport.py @@ -289,6 +289,13 @@ class LiteLLMAiohttpTransport(AiohttpTransport): cls._background_close_tasks.add(task) task.add_done_callback(cls._on_close_task_done) + def __del__(self) -> None: + session: Final = getattr(self, "client", None) + if not getattr(self, "_owns_session", False) or not isinstance(session, ClientSession): + return + with contextlib.suppress(Exception): + self._close_recycled_session(session) + def get_valid_client_session(self) -> ClientSession: """ Helper to get a valid ClientSession for the current event loop. diff --git a/litellm/llms/custom_httpx/async_client_cleanup.py b/litellm/llms/custom_httpx/async_client_cleanup.py index 6ef61b6f58f..3c0cc90f30f 100644 --- a/litellm/llms/custom_httpx/async_client_cleanup.py +++ b/litellm/llms/custom_httpx/async_client_cleanup.py @@ -20,7 +20,7 @@ async def close_litellm_async_clients(): cache_dict: Final = getattr(litellm.in_memory_llm_clients_cache, "cache_dict", {}) - for key, handler in cache_dict.items(): + for handler in cache_dict.values(): # Handle BaseLLMAIOHTTPHandler instances (aiohttp_openai provider) if isinstance(handler, BaseLLMAIOHTTPHandler) and hasattr(handler, "close"): try: diff --git a/litellm/llms/custom_httpx/http_handler.py b/litellm/llms/custom_httpx/http_handler.py index cffeb44f12c..0b64885df45 100644 --- a/litellm/llms/custom_httpx/http_handler.py +++ b/litellm/llms/custom_httpx/http_handler.py @@ -20,6 +20,7 @@ from aiohttp import ClientSession, DummyCookieJar, TCPConnector from httpx import USE_CLIENT_DEFAULT, AsyncHTTPTransport, HTTPTransport from httpx._types import CertTypes, RequestFiles from httpx._utils import get_environment_proxies +from pydantic import TypeAdapter import litellm from litellm._logging import verbose_logger @@ -566,6 +567,34 @@ async def _raise_masked_async_error(e: httpx.HTTPStatusError, stream: bool) -> N raise MaskedHTTPStatusError(e, message=_text, text=_text) from None +_TIMEOUT_PHASES: Final[Mapping[type[httpx.TimeoutException], tuple[str, str]]] = MappingProxyType( + { + httpx.ConnectTimeout: ("Connection", "connect"), + httpx.ReadTimeout: ("Read", "read"), + httpx.WriteTimeout: ("Write", "write"), + httpx.PoolTimeout: ("Connection pool", "pool"), + } +) +_UNKNOWN_TIMEOUT_PHASE: Final = ("Request", "read") +_TIMEOUT_EXTENSION: Final = TypeAdapter(dict[str, float | None]) + + +def _timeout_phase_seconds(error: httpx.TimeoutException, phase: str) -> float | None: + """The limit httpx enforced for ``phase`` on the request that raised ``error``, from the request itself.""" + return _TIMEOUT_EXTENSION.validate_python(error.request.extensions["timeout"]).get(phase) + + +def _raise_timeout(error: httpx.TimeoutException, started_at: float) -> NoReturn: + label, phase = _TIMEOUT_PHASES.get(type(error), _UNKNOWN_TIMEOUT_PHASE) + seconds: Final = _timeout_phase_seconds(error, phase) + time_taken: Final = round(time.time() - started_at, 3) + raise litellm.Timeout( + message=f"{label} timed out. Timeout passed={seconds}, time taken={time_taken} seconds", + model="default-model-name", + llm_provider="litellm-httpx-handler", + ) + + class HTTPResponseLimitError(ValueError): pass @@ -870,20 +899,7 @@ class AsyncHTTPHandler: finally: await new_client.aclose() except httpx.TimeoutException as e: - end_time: Final = time.time() - time_delta: Final = round(end_time - start_time, 3) - headers = {} - error_response: Final[httpx.Response | None] = getattr(e, "response", None) - if error_response is not None: - for key, value in error_response.headers.items(): - headers[f"response_headers-{key}"] = value - - raise litellm.Timeout( - message=f"Connection timed out. Timeout passed={timeout}, time taken={time_delta} seconds", - model="default-model-name", - llm_provider="litellm-httpx-handler", - headers=headers, - ) + _raise_timeout(e, start_time) except httpx.HTTPStatusError as e: await _raise_masked_async_error(e, stream) except Exception as e: @@ -902,6 +918,7 @@ class AsyncHTTPHandler: follow_redirects: bool | None = None, ): _follow_redirects: Final = follow_redirects if follow_redirects is not None else USE_CLIENT_DEFAULT + start_time: Final = time.time() try: if timeout is None: timeout = self.timeout @@ -946,18 +963,7 @@ class AsyncHTTPHandler: finally: await new_client.aclose() except httpx.TimeoutException as e: - headers = {} - error_response: Final[httpx.Response | None] = getattr(e, "response", None) - if error_response is not None: - for key, value in error_response.headers.items(): - headers[f"response_headers-{key}"] = value - - raise litellm.Timeout( - message=f"Connection timed out after {timeout} seconds.", - model="default-model-name", - llm_provider="litellm-httpx-handler", - headers=headers, - ) + _raise_timeout(e, start_time) except httpx.HTTPStatusError as e: await _raise_masked_async_error(e, stream) except Exception as e: @@ -974,6 +980,7 @@ class AsyncHTTPHandler: stream: bool = False, content: _RequestContent | None = None, ): + start_time: Final = time.time() try: if timeout is None: timeout = self.timeout @@ -1012,18 +1019,7 @@ class AsyncHTTPHandler: finally: await new_client.aclose() except httpx.TimeoutException as e: - headers = {} - error_response: Final[httpx.Response | None] = getattr(e, "response", None) - if error_response is not None: - for key, value in error_response.headers.items(): - headers[f"response_headers-{key}"] = value - - raise litellm.Timeout( - message=f"Connection timed out after {timeout} seconds.", - model="default-model-name", - llm_provider="litellm-httpx-handler", - headers=headers, - ) + _raise_timeout(e, start_time) except httpx.HTTPStatusError as e: await _raise_masked_async_error(e, stream) except Exception as e: @@ -1514,6 +1510,7 @@ class HTTPHandler: content: _RequestContent | None = None, logging_obj: LiteLLMLoggingObject | None = None, ): + start_time: Final = time.time() try: # Prepare data/content parameters to prevent httpx DeprecationWarning (memory leak fix) request_data, request_content = _prepare_request_data_and_content(data, content) @@ -1546,12 +1543,8 @@ class HTTPHandler: _anchor_handler_to(response, self) response.raise_for_status() return response - except httpx.TimeoutException: - raise litellm.Timeout( - message=f"Connection timed out after {timeout} seconds.", - model="default-model-name", - llm_provider="litellm-httpx-handler", - ) + except httpx.TimeoutException as e: + _raise_timeout(e, start_time) except httpx.HTTPStatusError as e: _raise_masked_sync_error(e, stream) except Exception as e: @@ -1568,6 +1561,7 @@ class HTTPHandler: timeout: float | httpx.Timeout | None = None, content: _RequestContent | None = None, ): + start_time: Final = time.time() try: # Prepare data/content parameters to prevent httpx DeprecationWarning (memory leak fix) request_data, request_content = _prepare_request_data_and_content(data, content) @@ -1598,12 +1592,8 @@ class HTTPHandler: _anchor_handler_to(response, self) response.raise_for_status() return response - except httpx.TimeoutException: - raise litellm.Timeout( - message=f"Connection timed out after {timeout} seconds.", - model="default-model-name", - llm_provider="litellm-httpx-handler", - ) + except httpx.TimeoutException as e: + _raise_timeout(e, start_time) except httpx.HTTPStatusError as e: _raise_masked_sync_error(e, stream) except Exception as e: @@ -1620,6 +1610,7 @@ class HTTPHandler: timeout: float | httpx.Timeout | None = None, content: _RequestContent | None = None, ): + start_time: Final = time.time() try: # Prepare data/content parameters to prevent httpx DeprecationWarning (memory leak fix) request_data, request_content = _prepare_request_data_and_content(data, content) @@ -1649,12 +1640,8 @@ class HTTPHandler: if stream: _anchor_handler_to(response, self) return response - except httpx.TimeoutException: - raise litellm.Timeout( - message=f"Connection timed out after {timeout} seconds.", - model="default-model-name", - llm_provider="litellm-httpx-handler", - ) + except httpx.TimeoutException as e: + _raise_timeout(e, start_time) except httpx.HTTPStatusError as e: _raise_masked_sync_error(e, stream) except Exception as e: @@ -1671,6 +1658,7 @@ class HTTPHandler: stream: bool = False, content: _RequestContent | None = None, ): + start_time: Final = time.time() try: # Prepare data/content parameters to prevent httpx DeprecationWarning (memory leak fix) request_data, request_content = _prepare_request_data_and_content(data, content) @@ -1701,12 +1689,8 @@ class HTTPHandler: _anchor_handler_to(response, self) response.raise_for_status() return response - except httpx.TimeoutException: - raise litellm.Timeout( - message=f"Connection timed out after {timeout} seconds.", - model="default-model-name", - llm_provider="litellm-httpx-handler", - ) + except httpx.TimeoutException as e: + _raise_timeout(e, start_time) except httpx.HTTPStatusError as e: _raise_masked_sync_error(e, stream) except Exception as e: diff --git a/litellm/llms/custom_httpx/llm_http_handler.py b/litellm/llms/custom_httpx/llm_http_handler.py index a692f3f964e..ef009e70137 100644 --- a/litellm/llms/custom_httpx/llm_http_handler.py +++ b/litellm/llms/custom_httpx/llm_http_handler.py @@ -49,7 +49,7 @@ from litellm.litellm_core_utils.audio_utils.subtitle_utils import ( SUBTITLE_RESPONSE_FORMATS, synthesize_subtitle_document, ) -from litellm.litellm_core_utils.core_helpers import set_provider_response_headers_in_hidden_params +from litellm.litellm_core_utils.core_helpers import as_str_mapping, set_provider_response_headers_in_hidden_params from litellm.litellm_core_utils.dot_notation_indexing import delete_nested_value from litellm.litellm_core_utils.get_litellm_params import AWS_CREDENTIAL_KWARGS_KEYS from litellm.litellm_core_utils.get_llm_provider_logic import get_provider_affinity_header @@ -198,6 +198,26 @@ from litellm.utils import ( ) +def _merge_headers_case_insensitive( + headers: Mapping[str, object], extra_headers: Mapping[str, object] | None +) -> dict[str, str]: # mutable-ok: legacy HTTP handler methods require a dict of headers + overridden: Final = frozenset(name.lower() for name in extra_headers or {}) + return { + **{name: str(value) for name, value in headers.items() if name.lower() not in overridden}, + **{name: str(value) for name, value in (extra_headers or {}).items()}, + } + + +def _client_request_headers( + response_api_optional_request_params: Mapping[str, object], + extra_headers: Mapping[str, object] | None, +) -> dict[str, str]: # mutable-ok: provider validate_environment methods require a dict + from litellm.litellm_core_utils.core_helpers import as_str_mapping + + optional_headers: Final = as_str_mapping(response_api_optional_request_params.get("extra_headers")) + return _merge_headers_case_insensitive(optional_headers or {}, extra_headers) + + def _rust_responses_websocket_enabled( custom_llm_provider: str | None, ) -> bool: @@ -218,7 +238,7 @@ if TYPE_CHECKING: from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.litellm_logging import Logging as _LiteLLMLoggingObj from litellm.litellm_core_utils.tokenizer import Encoding as Tokenizer - from litellm.llms.anthropic.pass_through.messages.fake_stream_iterator import ( + from litellm.llms.anthropic.messages.native.fake_stream_iterator import ( FakeAnthropicMessagesStreamIterator, ) from litellm.llms.base_llm.passthrough.transformation import BasePassthroughConfig @@ -412,6 +432,27 @@ def _has_pre_call_deployment_hook(logging_obj: LiteLLMLoggingObj) -> bool: return False +def _run_responses_deployment_hook( + *, + model: str, + request_input: str | ResponseInputParam, + custom_llm_provider: str, + optional_params: Mapping[str, object], + litellm_params: GenericLiteLLMParams, +) -> Mapping[str, object]: + return run_async_function( + async_pre_call_deployment_hook, + { + **dict(litellm_params), + **optional_params, + "model": model, + "input": request_input, + "custom_llm_provider": custom_llm_provider, + }, + CallTypes.responses.value, + ) + + def _mask_presigned_request_headers(transformed_request: bytes | str | dict) -> bytes | str | dict: """A pre-signed request carries its auth inside its own ``headers`` key, which logging treats as request body (only the top-level headers channel gets masked), @@ -477,6 +518,7 @@ _DECODED_BODY_STALE_HEADERS: Final[frozenset[str]] = frozenset({"content-encodin _OPTIONAL_PARAMS: Final = TypeAdapter(Mapping[str, object]) _JSON_OBJECT: Final = TypeAdapter(dict[str, object]) _JSON_OBJECTS: Final = TypeAdapter(list[dict[str, object]]) +_DECODED_JSON: Final = TypeAdapter(object) def _decoded_body_headers(response: httpx.Response) -> httpx.Headers: @@ -977,7 +1019,7 @@ class BaseLLMHTTPHandler: original_data: dict, model: str, messages: list, - logging_obj, + logging_obj: LiteLLMLoggingObj, optional_params: dict, litellm_params: dict, timeout: float | httpx.Timeout, @@ -1031,6 +1073,7 @@ class BaseLLMHTTPHandler: sync_stream=True, json_mode=json_mode, optional_params=_OPTIONAL_PARAMS.validate_python(optional_params), + logging_obj=logging_obj, ) if isinstance(completion_stream, BaseModelResponseIterator): completion_stream.http_response = response @@ -1173,6 +1216,7 @@ class BaseLLMHTTPHandler: sync_stream=False, json_mode=json_mode, optional_params=_OPTIONAL_PARAMS.validate_python(optional_params), + logging_obj=logging_obj, ) if isinstance(completion_stream, BaseModelResponseIterator): completion_stream.http_response = response @@ -2606,7 +2650,7 @@ class BaseLLMHTTPHandler: initial_response: AsyncIterator | AnthropicMessagesResponse if stream: - from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( + from litellm.llms.anthropic.messages.native.streaming_iterator import ( AnthropicMessagesStreamingResponse, anthropic_messages_stream_hidden_params, ) @@ -2630,7 +2674,7 @@ class BaseLLMHTTPHandler: hidden_params=stream_hidden_params, ) - from litellm.llms.anthropic.pass_through.messages.agentic_streaming_iterator import ( + from litellm.llms.anthropic.messages.native.agentic_streaming_iterator import ( AgenticAnthropicStreamingIterator, ) @@ -2661,6 +2705,7 @@ class BaseLLMHTTPHandler: raw_response=response, logging_obj=logging_obj, ) + logging_obj.record_native_bedrock_guardrail(initial_response) return await self._finalize_anthropic_messages_response( initial_response=initial_response, @@ -2765,16 +2810,12 @@ class BaseLLMHTTPHandler: litellm_params, ) - modified_kwargs: Final = run_async_function( - async_pre_call_deployment_hook, - { - **dict(litellm_params), - **response_api_optional_request_params, - "model": model, - "input": input, - "custom_llm_provider": custom_llm_provider, - }, - CallTypes.responses.value, + modified_kwargs: Final = _run_responses_deployment_hook( + model=model, + request_input=input, + custom_llm_provider=custom_llm_provider, + optional_params=response_api_optional_request_params, + litellm_params=litellm_params, ) if modified_kwargs is None: return ( @@ -2886,14 +2927,18 @@ class BaseLLMHTTPHandler: else: sync_httpx_client = client - headers = responses_api_provider_config.validate_environment( - headers=response_api_optional_request_params.get("extra_headers", {}) or {}, - model=model, - litellm_params=litellm_params, - ) - - if extra_headers: - headers.update(extra_headers) + headers = { # rebind-ok: validation replaces the method's incoming headers + **responses_api_provider_config.validate_environment( + headers=( + _client_request_headers(response_api_optional_request_params, extra_headers) + if custom_llm_provider == "chatgpt" + else response_api_optional_request_params.get("extra_headers", {}) or {} + ), + model=model, + litellm_params=litellm_params, + ), + **((extra_headers or {}) if custom_llm_provider != "chatgpt" else {}), + } # Check if streaming is requested stream = response_api_optional_request_params.get("stream", False) @@ -3084,11 +3129,15 @@ class BaseLLMHTTPHandler: validated_headers: Final = { **await asyncio.to_thread( responses_api_provider_config.validate_environment, - headers=response_api_optional_request_params.get("extra_headers", {}) or {}, + headers=( + _client_request_headers(response_api_optional_request_params, extra_headers) + if custom_llm_provider == "chatgpt" + else response_api_optional_request_params.get("extra_headers", {}) or {} + ), model=model, litellm_params=litellm_params, ), - **(extra_headers or {}), + **((extra_headers or {}) if custom_llm_provider != "chatgpt" else {}), } # Check if streaming is requested @@ -3753,7 +3802,7 @@ class BaseLLMHTTPHandler: response: httpx.Response, upload_url_location: str, upload_url_key: str = "upload_url", - ) -> tuple[str | None, dict | None]: + ) -> tuple[object, Mapping[str, object] | None]: """ Extract upload URL from initial file creation response. @@ -3773,8 +3822,10 @@ class BaseLLMHTTPHandler: else: # Response body style (e.g., Manus, S3 presigned URLs) try: - response_data: Final = response.json() - upload_url = response_data.get(upload_url_key) + response_data: Final = as_str_mapping(_DECODED_JSON.validate_python(response.json())) + if response_data is None: + return None, None + upload_url: Final = response_data.get(upload_url_key) return upload_url, response_data if upload_url else None except Exception: return None, None @@ -3940,7 +3991,7 @@ class BaseLLMHTTPHandler: elif isinstance(transformed_request, dict) and "file" in transformed_request: # Handle multipart form-data uploads (e.g., Anthropic Files API) # The dict contains tuples suitable for httpx's `files` parameter - file_request: Final = cast(dict[str, Any], transformed_request) + file_request: Final = cast(dict[str, object], transformed_request) upload_response = sync_httpx_client.post( url=api_base, headers=headers, @@ -6187,7 +6238,7 @@ class BaseLLMHTTPHandler: from typing import cast from litellm._logging import verbose_logger - from litellm.llms.anthropic.pass_through.messages.fake_stream_iterator import ( + from litellm.llms.anthropic.messages.native.fake_stream_iterator import ( FakeAnthropicMessagesStreamIterator, ) from litellm.types.llms.anthropic_messages.anthropic_response import ( @@ -10869,7 +10920,7 @@ class BaseLLMHTTPHandler: ) encoded_vector_store_id: Final = encode_url_path_segment(vector_store_id, field_name="vector_store_id") - url: Final = f"{api_base}/{encoded_vector_store_id}" + url: Final = vector_store_provider_config.get_vector_store_url(api_base, encoded_vector_store_id) logging_obj.pre_call( input="", @@ -10934,7 +10985,7 @@ class BaseLLMHTTPHandler: ) encoded_vector_store_id: Final = encode_url_path_segment(vector_store_id, field_name="vector_store_id") - url: Final = f"{api_base}/{encoded_vector_store_id}" + url: Final = vector_store_provider_config.get_vector_store_url(api_base, encoded_vector_store_id) logging_obj.pre_call( input="", @@ -11137,7 +11188,7 @@ class BaseLLMHTTPHandler: ) encoded_vector_store_id: Final = encode_url_path_segment(vector_store_id, field_name="vector_store_id") - url: Final = f"{api_base}/{encoded_vector_store_id}" + url: Final = vector_store_provider_config.get_vector_store_url(api_base, encoded_vector_store_id) request_body: Final[dict[str, object]] = dict(vector_store_update_optional_params) metadata: Final = vector_store_update_optional_params.get("metadata") @@ -11216,7 +11267,7 @@ class BaseLLMHTTPHandler: ) encoded_vector_store_id: Final = encode_url_path_segment(vector_store_id, field_name="vector_store_id") - url: Final = f"{api_base}/{encoded_vector_store_id}" + url: Final = vector_store_provider_config.get_vector_store_url(api_base, encoded_vector_store_id) request_body: Final[dict[str, object]] = dict(vector_store_update_optional_params) metadata: Final = vector_store_update_optional_params.get("metadata") @@ -11284,7 +11335,7 @@ class BaseLLMHTTPHandler: ) encoded_vector_store_id: Final = encode_url_path_segment(vector_store_id, field_name="vector_store_id") - url: Final = f"{api_base}/{encoded_vector_store_id}" + url: Final = vector_store_provider_config.get_vector_store_url(api_base, encoded_vector_store_id) logging_obj.pre_call( input="", @@ -11346,7 +11397,7 @@ class BaseLLMHTTPHandler: ) encoded_vector_store_id: Final = encode_url_path_segment(vector_store_id, field_name="vector_store_id") - url: Final = f"{api_base}/{encoded_vector_store_id}" + url: Final = vector_store_provider_config.get_vector_store_url(api_base, encoded_vector_store_id) logging_obj.pre_call( input="", diff --git a/litellm/llms/custom_httpx/mock_transport.py b/litellm/llms/custom_httpx/mock_transport.py index 0322cceec0f..6acadb8e98a 100644 --- a/litellm/llms/custom_httpx/mock_transport.py +++ b/litellm/llms/custom_httpx/mock_transport.py @@ -12,6 +12,9 @@ import uuid from typing import Final import httpx +from pydantic import TypeAdapter + +from litellm.litellm_core_utils.core_helpers import decoded_json_object # --------------------------------------------------------------------------- # Pre-built response templates @@ -22,7 +25,7 @@ def _mock_id() -> str: return f"chatcmpl-mock-{uuid.uuid4().hex[:8]}" -def _chat_completion_json(model: str) -> dict: +def _chat_completion_json(model: object) -> dict: """Return a minimal valid ChatCompletion object.""" return { "id": _mock_id(), @@ -55,6 +58,8 @@ _JSON_HEADERS: Final = { "content-type": "application/json", } +_DECODED_JSON: Final = TypeAdapter(object) + class MockOpenAITransport(httpx.AsyncBaseTransport, httpx.BaseTransport): """ @@ -64,13 +69,13 @@ class MockOpenAITransport(httpx.AsyncBaseTransport, httpx.BaseTransport): """ @staticmethod - def _parse_request(request: httpx.Request) -> tuple[str, bool]: + def _parse_request(request: httpx.Request) -> tuple[object, bool]: """Extract model from the request body.""" try: - body: Final = json.loads(request.content) + body: Final = _DECODED_JSON.validate_python(json.loads(request.content)) except (json.JSONDecodeError, ValueError): return ("mock-model", False) - model: Final = body.get("model", "mock-model") + model: Final = decoded_json_object(body).get("model", "mock-model") return (model, False) async def handle_async_request(self, request: httpx.Request) -> httpx.Response: diff --git a/litellm/llms/dashscope/cost_calculator.py b/litellm/llms/dashscope/cost_calculator.py index 98504f54533..55d6fb1a0e2 100644 --- a/litellm/llms/dashscope/cost_calculator.py +++ b/litellm/llms/dashscope/cost_calculator.py @@ -7,6 +7,7 @@ cached, cache-creation, output, reasoning) is billed at that one tier's rate. See https://help.aliyun.com/zh/model-studio/billing-for-model-studio """ +from collections.abc import Mapping from dataclasses import dataclass, replace from datetime import datetime from typing import Final @@ -54,10 +55,9 @@ def _extract_token_breakdown(usage: Usage) -> TokenBreakdown: ) -def _flat_rate(model_info: ModelInfo, cost_key: str, fallback_cost_key: str) -> float: - value: Final = model_info.get(cost_key) +def _flat_rate(value: float | None, fallback_value: float | None) -> float: if value is None: - return float(model_info.get(fallback_cost_key) or 0.0) + return float(fallback_value or 0.0) return float(value) @@ -65,14 +65,18 @@ def _flat_rates(model_info: ModelInfo) -> TokenRates: reasoning_rate: Final = model_info.get("output_cost_per_reasoning_token") return TokenRates( input_rate=float(model_info.get("input_cost_per_token") or 0.0), - cache_read_rate=_flat_rate(model_info, "cache_read_input_token_cost", "input_cost_per_token"), - cache_creation_rate=_flat_rate(model_info, "cache_creation_input_token_cost", "input_cost_per_token"), + cache_read_rate=_flat_rate( + model_info.get("cache_read_input_token_cost"), model_info.get("input_cost_per_token") + ), + cache_creation_rate=_flat_rate( + model_info.get("cache_creation_input_token_cost"), model_info.get("input_cost_per_token") + ), output_rate=float(model_info.get("output_cost_per_token") or 0.0), reasoning_rate=None if reasoning_rate is None else float(reasoning_rate), ) -def _tier_rates(model_info: ModelInfo, tier: dict) -> TokenRates: +def _tier_rates(model_info: ModelInfo, tier: Mapping[str, object]) -> TokenRates: # A tier that declares output rates keeps the request on them, all-or-nothing. A tier table # spelling out only input rates would serve every completion for free, so there the model's # own output rates stand in diff --git a/litellm/llms/dashscope/image_generation/transformation.py b/litellm/llms/dashscope/image_generation/transformation.py index 6a172e1e074..d1faa6c6cd0 100644 --- a/litellm/llms/dashscope/image_generation/transformation.py +++ b/litellm/llms/dashscope/image_generation/transformation.py @@ -49,6 +49,7 @@ else: _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_input_in_errors=True)) _JSON_OBJECTS: Final = TypeAdapter(Iterable[Mapping[str, object]], config=ConfigDict(hide_input_in_errors=True)) +_DECODED_JSON: Final = TypeAdapter(object) DEFAULT_API_BASE: Final = "https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation" @@ -187,7 +188,7 @@ class DashScopeImageGenerationConfig(BaseImageGenerationConfig): ) try: - response_data: Final = raw_response.json() + response_data: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception as e: raise self.get_error_class( error_message=f"Failed to parse DashScope image generation response: {e}", diff --git a/litellm/llms/databricks/agent/transformation.py b/litellm/llms/databricks/agent/transformation.py index fb0fdd22132..7747837a68b 100644 --- a/litellm/llms/databricks/agent/transformation.py +++ b/litellm/llms/databricks/agent/transformation.py @@ -5,16 +5,14 @@ Model Serving, unified: POST {workspace}/serving-endpoints/responses with the en Databricks Apps: POST {app}/responses """ -import hashlib from collections.abc import AsyncIterator, Iterator, Mapping, Sequence -from typing import TYPE_CHECKING, Final, Protocol +from typing import TYPE_CHECKING, Final from urllib.parse import quote, urlsplit import httpx from pydantic import BaseModel, ConfigDict, StrictStr, TypeAdapter, ValidationError import litellm -from litellm.caching.in_memory_cache import InMemoryCache from litellm.litellm_core_utils.prompt_templates.common_utils import ( convert_content_list_to_str, ) @@ -41,20 +39,6 @@ _ENDPOINT_URL_SUFFIXES: Final = (_INVOCATIONS_SUFFIX, _APP_RESPONSES_SUFFIX) _SERVING_ENDPOINTS_SEGMENT: Final = "/serving-endpoints/" _UNIFIED_RESPONSES_SUFFIX: Final = "/serving-endpoints/responses" _APP_HOST_SUFFIX: Final = ".databricksapps.com" -_TOKEN_EXPIRY_BUFFER_SECONDS: Final = 60 - - -class _TokenCache(Protocol): - def get_cache(self, key: str) -> object: ... - - def set_cache(self, key: str, value: str, *, ttl: int) -> None: ... - - -def _new_token_cache() -> _TokenCache: - return InMemoryCache(max_size_in_memory=64) - - -_ENV_M2M_TOKENS: Final = _new_token_cache() _INPUT_ROLES: Final = frozenset({"system", "developer", "user", "assistant"}) _BODY_PARAMS: Final = ( "max_output_tokens", @@ -220,20 +204,7 @@ def _env_oauth_m2m_token(api_base: str | None) -> str | None: "set DATABRICKS_HOST to the workspace URL (a Databricks App URL is not a workspace)" ), ) - return _cached_m2m_token(workspace, client_id, client_secret) - - -def _cached_m2m_token(workspace: str, client_id: str, client_secret: str) -> str: - secret_digest: Final = hashlib.sha256(client_secret.encode()).hexdigest()[:16] - cache_key: Final = f"{workspace}|{client_id}|{secret_digest}" - cached: Final[object] = _ENV_M2M_TOKENS.get_cache(cache_key) - if isinstance(cached, str): - return cached - token: Final = DatabricksBase().get_oauth_m2m_token_and_lifetime(workspace, client_id, client_secret) - ttl: Final = token.expires_in - _TOKEN_EXPIRY_BUFFER_SECONDS - if ttl > 0: - _ENV_M2M_TOKENS.set_cache(cache_key, token.access_token, ttl=ttl) - return token.access_token + return DatabricksBase().get_cached_oauth_m2m_token(workspace, client_id, client_secret) def _resolved_env_reference(value: str | None) -> str | None: diff --git a/litellm/llms/databricks/chat/transformation.py b/litellm/llms/databricks/chat/transformation.py index 61b41c2a173..48118c23ed7 100644 --- a/litellm/llms/databricks/chat/transformation.py +++ b/litellm/llms/databricks/chat/transformation.py @@ -822,6 +822,7 @@ class DatabricksConfig(DatabricksBase, OpenAILikeChatConfig, AnthropicConfig): sync_stream: bool, json_mode: bool | None, optional_params: Mapping[str, object], + logging_obj: LiteLLMLoggingObj | None = None, ) -> "DatabricksChatResponseIterator": return self.get_model_response_iterator( streaming_response=streaming_response, sync_stream=sync_stream, json_mode=json_mode diff --git a/litellm/llms/databricks/common_utils.py b/litellm/llms/databricks/common_utils.py index cd9432ac36f..b1562bef6b8 100644 --- a/litellm/llms/databricks/common_utils.py +++ b/litellm/llms/databricks/common_utils.py @@ -10,21 +10,33 @@ Authentication priority: 3. Databricks SDK automatic auth - Fallback (uses unified auth) """ +import hashlib import os import re from collections.abc import Mapping from types import MappingProxyType -from typing import Final, Literal +from typing import Final, Literal, Protocol from urllib.parse import urlsplit, urlunsplit from pydantic import BaseModel, ConfigDict import litellm +from litellm.caching.in_memory_cache import InMemoryCache from litellm.litellm_core_utils.url_utils import join_api_base from litellm.llms.base_llm.chat.transformation import BaseLLMException from litellm.secret_managers.main import get_secret_str _DEFAULT_M2M_TOKEN_LIFETIME_SECONDS: Final = 3600 +_TOKEN_EXPIRY_BUFFER_SECONDS: Final = 60 + + +class _TokenCache(Protocol): + def get_cache(self, key: str) -> object: ... + + def set_cache(self, key: str, value: str, *, ttl: int) -> None: ... + + +_OAUTH_TOKENS: Final[_TokenCache] = InMemoryCache(max_size_in_memory=64) class DatabricksException(BaseLLMException): @@ -293,6 +305,26 @@ class DatabricksBase: ) -> str: return self.get_oauth_m2m_token_and_lifetime(api_base, client_id, client_secret).access_token + def get_cached_oauth_m2m_token( + self, + api_base: str, + client_id: str, + client_secret: str, + *, + token_cache: _TokenCache = _OAUTH_TOKENS, + ) -> str: + workspace: Final = self.workspace_root(api_base) + secret_digest: Final = hashlib.sha256(client_secret.encode()).hexdigest() + cache_key: Final = f"{workspace}|{client_id}|{secret_digest}" + cached: Final = token_cache.get_cache(cache_key) + if isinstance(cached, str): + return cached + token: Final = self.get_oauth_m2m_token_and_lifetime(workspace, client_id, client_secret) + ttl: Final = token.expires_in - _TOKEN_EXPIRY_BUFFER_SECONDS + if ttl > 0: + token_cache.set_cache(cache_key, token.access_token, ttl=ttl) + return token.access_token + def get_oauth_m2m_token_and_lifetime( self, api_base: str, diff --git a/litellm/llms/databricks/decisions/transformation.py b/litellm/llms/databricks/decisions/transformation.py index d1698fdf5e2..2b0524da2f9 100644 --- a/litellm/llms/databricks/decisions/transformation.py +++ b/litellm/llms/databricks/decisions/transformation.py @@ -8,6 +8,8 @@ from pydantic import TypeAdapter, ValidationError from litellm.litellm_core_utils.url_utils import join_api_base from litellm.llms.base_llm.decisions.transformation import BaseDecisionsConfig +from litellm.llms.databricks.common_utils import DatabricksBase +from litellm.secret_managers.main import get_secret_str from litellm.types.decisions import DecisionsIRRequest, UnsupportedDecisionsRequest DATABRICKS_AI_DECIDE_MODEL: Final = "ai_decide" @@ -74,6 +76,17 @@ class DatabricksDecisionsConfig(BaseDecisionsConfig): api_key_env = ("DATABRICKS_API_KEY", "DATABRICKS_TOKEN") api_base_env = ("DATABRICKS_API_BASE",) + def resolve_credential( + self, api_key: str | None, api_base: str, litellm_params: Mapping[str, object] + ) -> str | None: + if api_key: + return api_key + client_id: Final = get_secret_str("DATABRICKS_CLIENT_ID") + client_secret: Final = get_secret_str("DATABRICKS_CLIENT_SECRET") + if not client_id or not client_secret: + return None + return DatabricksBase().get_cached_oauth_m2m_token(api_base, client_id, client_secret) + def missing_api_base_message(self, custom_llm_provider: str) -> str: return ( f"api_base is required for Decisions provider '{custom_llm_provider}': set DATABRICKS_API_BASE to " diff --git a/litellm/llms/databricks/embed/transformation.py b/litellm/llms/databricks/embed/transformation.py index ddaf2bbb621..0feb2aea5a0 100644 --- a/litellm/llms/databricks/embed/transformation.py +++ b/litellm/llms/databricks/embed/transformation.py @@ -3,6 +3,7 @@ Translates from OpenAI's `/v1/embeddings` to Databricks' `/embeddings` """ import types +from collections.abc import Mapping from typing import Final @@ -16,16 +17,17 @@ class DatabricksEmbeddingConfig: ) def __init__(self, instruction: str | None = None) -> None: - locals_: Final = locals().copy() + locals_: Final[Mapping[str, object]] = types.MappingProxyType(locals().copy()) for key, value in locals_.items(): if key != "self" and value is not None: setattr(self.__class__, key, value) @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not isinstance( v, diff --git a/litellm/llms/databricks/messages/transformation.py b/litellm/llms/databricks/messages/transformation.py index cb8d2b652a2..e22ad85b5f9 100644 --- a/litellm/llms/databricks/messages/transformation.py +++ b/litellm/llms/databricks/messages/transformation.py @@ -3,11 +3,12 @@ from collections.abc import AsyncIterator, Mapping from typing import Final import httpx +from pydantic import TypeAdapter import litellm from litellm.litellm_core_utils.core_helpers import as_str_mapping, iter_items from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) from litellm.llms.databricks.common_utils import ( @@ -25,6 +26,7 @@ DROP_CONTAINER_WARNING: Final = ( "and the chat completions bridge it replaces never forwarded it." ) BEDROCK_INVOCATION_METRICS_FIELD: Final = "amazon-bedrock-invocationMetrics" +_DECODED_JSON: Final = TypeAdapter(object) def _is_unsupported_server_tool(tool: object) -> bool: @@ -57,7 +59,7 @@ def _without_unsupported_server_tools(params: Mapping[str, object]) -> dict[str, def _without_invocation_metrics(sse_line: bytes) -> bytes: if not sse_line.startswith(b"data:") or BEDROCK_INVOCATION_METRICS_FIELD.encode() not in sse_line: return sse_line - event: Final = as_str_mapping(json.loads(sse_line.removeprefix(b"data:"))) + event: Final = as_str_mapping(_DECODED_JSON.validate_python(json.loads(sse_line.removeprefix(b"data:")))) if event is None: return sse_line kept_fields: Final = {key: value for key, value in event.items() if key != BEDROCK_INVOCATION_METRICS_FIELD} diff --git a/litellm/llms/deepagents/harness/sandbox_backend.py b/litellm/llms/deepagents/harness/sandbox_backend.py index d39690ccdd1..8ad90faa2b4 100644 --- a/litellm/llms/deepagents/harness/sandbox_backend.py +++ b/litellm/llms/deepagents/harness/sandbox_backend.py @@ -22,7 +22,7 @@ import shlex import uuid from collections.abc import Awaitable, Callable, Coroutine, Iterator, Mapping, Sequence from types import MappingProxyType -from typing import Any, Final, TypeVar +from typing import Final, TypeVar from deepagents.backends.protocol import ( DeleteResult, @@ -171,7 +171,7 @@ class SandboxBackend(SandboxBackendProtocol): # pyright: ignore[reportUntypedBa # -- sync bridge (deepagents only calls these outside the event loop) --- - def _sync(self, coro: Coroutine[Any, Any, T]) -> T: + def _sync(self, coro: Coroutine[object, object, T]) -> T: try: running = asyncio.get_running_loop() except RuntimeError: diff --git a/litellm/llms/deepagents/harness/transformation.py b/litellm/llms/deepagents/harness/transformation.py index cb80e3e12f7..54a6a5573ac 100644 --- a/litellm/llms/deepagents/harness/transformation.py +++ b/litellm/llms/deepagents/harness/transformation.py @@ -11,11 +11,13 @@ from __future__ import annotations import itertools import json -from collections.abc import Iterator, Mapping, Sequence +from collections.abc import Iterable, Iterator, Mapping, Sequence from dataclasses import dataclass from types import MappingProxyType from typing import TYPE_CHECKING, Any, Final, Protocol +from pydantic import TypeAdapter + from litellm.harness.options import DeepAgentsOptions from litellm.harness.types import ( Capabilities, @@ -41,6 +43,7 @@ DEEPAGENTS_DEFAULT_RECURSION_LIMIT: Final = 1000 _MODEL_NODE: Final = "model" # Only these graph nodes produce new messages; middleware hooks may re-emit history. _EVENT_NODES: Final = frozenset({"model", "tools"}) +_TOOL_CALLS: Final = TypeAdapter(Iterable[Mapping[str, object]]) NORMALIZED_TO_NATIVE: Final[Mapping[str, str]] = MappingProxyType( { @@ -208,7 +211,7 @@ def update_events( def _message_events(message: object, skip_tools: frozenset[str]) -> tuple[Event, ...]: kind = getattr(message, "type", None) if kind == "ai": - calls = getattr(message, "tool_calls", None) or () + calls: Final = _TOOL_CALLS.validate_python(getattr(message, "tool_calls", None) or ()) return tuple(tool_call_event(call) for call in calls if call.get("name") not in skip_tools) if kind == "tool" and getattr(message, "name", None) not in skip_tools: status: Final[object] = getattr(message, "status", None) diff --git a/litellm/llms/deepgram/audio_transcription/transformation.py b/litellm/llms/deepgram/audio_transcription/transformation.py index a1c3021c9f5..1c8a056116f 100644 --- a/litellm/llms/deepgram/audio_transcription/transformation.py +++ b/litellm/llms/deepgram/audio_transcription/transformation.py @@ -2,12 +2,13 @@ Translates from OpenAI's `/v1/audio/transcriptions` to Deepgram's `/v1/listen` """ -from collections.abc import Iterable, Mapping -from typing import Final +from collections.abc import Iterable, Mapping, Sequence +from typing import Final, Protocol, cast from urllib.parse import urlencode from httpx import Headers, Response -from pydantic import ConfigDict, TypeAdapter +from pydantic import ConfigDict, InstanceOf, TypeAdapter +from typing_extensions import NotRequired, ReadOnly, TypedDict from litellm.litellm_core_utils.audio_utils.utils import process_audio_file from litellm.litellm_core_utils.url_utils import join_api_base @@ -27,6 +28,31 @@ from ..common_utils import DeepgramException _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_input_in_errors=True)) _JSON_OBJECTS: Final = TypeAdapter(Iterable[Mapping[str, object]], config=ConfigDict(hide_input_in_errors=True)) +_RESPONSE_BODY: Final = TypeAdapter(InstanceOf[dict[str, object]], config=ConfigDict(hide_input_in_errors=True)) +_WORD_LIST: Final = TypeAdapter(InstanceOf[list[object]], config=ConfigDict(hide_input_in_errors=True)) + + +class _JsonResponse(Protocol): + def json(self) -> object: ... + + +def _json_body(response: _JsonResponse) -> object: + return response.json() + + +class _DeepgramAlternative(TypedDict): + transcript: ReadOnly[str] + words: ReadOnly[Sequence[Mapping[str, object]]] + paragraphs: ReadOnly[NotRequired[Mapping[str, str]]] + + +class _DeepgramChannel(TypedDict): + alternatives: ReadOnly[Sequence[_DeepgramAlternative]] + + +class _DeepgramResponse(TypedDict): + results: ReadOnly[Mapping[str, Sequence[_DeepgramChannel]]] + metadata: ReadOnly[Mapping[str, float]] class DeepgramAudioTranscriptionConfig(BaseAudioTranscriptionConfig): @@ -82,7 +108,10 @@ class DeepgramAudioTranscriptionConfig(BaseAudioTranscriptionConfig): Transforms the raw response from Deepgram to the TranscriptionResponse format """ try: - response_json: Final = raw_response.json() + body: Final = _json_body(raw_response) + response_json: Final = cast( # cast-ok: the body passes through unvalidated, as before it was typed + _DeepgramResponse, body + ) # Get the first alternative from the first channel first_channel: Final = response_json["results"]["channels"][0] @@ -102,7 +131,7 @@ class DeepgramAudioTranscriptionConfig(BaseAudioTranscriptionConfig): text = first_alternative["paragraphs"]["transcript"] else: # Diarization without paragraphs: reconstruct from words - text = self._reconstruct_diarized_transcript(first_alternative["words"]) + text = self._reconstruct_diarized_transcript(_WORD_LIST.validate_python(first_alternative["words"])) # Create TranscriptionResponse object response: Final = TranscriptionResponse(text=text) @@ -124,7 +153,7 @@ class DeepgramAudioTranscriptionConfig(BaseAudioTranscriptionConfig): ] # Store full response in hidden params - response.hidden_params = response_json + response.hidden_params = _RESPONSE_BODY.validate_python(body) return response diff --git a/litellm/llms/deepinfra/rerank/transformation.py b/litellm/llms/deepinfra/rerank/transformation.py index 5196c44d504..62a780396a1 100644 --- a/litellm/llms/deepinfra/rerank/transformation.py +++ b/litellm/llms/deepinfra/rerank/transformation.py @@ -6,6 +6,7 @@ from collections.abc import Mapping, Sequence from typing import Final, Protocol import httpx +from pydantic import TypeAdapter from typing_extensions import ReadOnly, TypedDict from litellm._uuid import uuid @@ -24,6 +25,8 @@ from litellm.types.rerank import ( RerankTokens, ) +_DECODED_JSON: Final = TypeAdapter(object) + class _DeepinfraInferenceStatus(TypedDict, total=False): """The ``inference_status`` block of a DeepInfra rerank response.""" @@ -251,7 +254,7 @@ class DeepinfraRerankConfig(BaseRerankConfig): try: error_data = error_message if isinstance(error_message, str): - error_data = json.loads(error_message) + error_data = _DECODED_JSON.validate_python(json.loads(error_message)) if isinstance(error_data, dict): # Check for {"detail": {"error": "..."}} detail: Final = error_data.get("detail") diff --git a/litellm/llms/deepseek/chat/transformation.py b/litellm/llms/deepseek/chat/transformation.py index a9a20101bb1..ecaa0a2ef16 100644 --- a/litellm/llms/deepseek/chat/transformation.py +++ b/litellm/llms/deepseek/chat/transformation.py @@ -17,6 +17,8 @@ from litellm.utils import supports_reasoning, supports_vision from ...openai.chat.gpt_transformation import OpenAIGPTConfig +SUPPORTED_REASONING_EFFORTS: Final = ("minimal", "low", "medium", "high", "xhigh", "max", "ultra") + class DeepSeekChatConfig(OpenAIGPTConfig): def get_supported_openai_params(self, model: str) -> list: @@ -33,7 +35,7 @@ class DeepSeekChatConfig(OpenAIGPTConfig): optional_params: dict, model: str, drop_params: bool, - ) -> dict: + ) -> dict[str, object]: """ Map OpenAI params to DeepSeek params. @@ -60,6 +62,13 @@ class DeepSeekChatConfig(OpenAIGPTConfig): elif reasoning_effort is not None: optional_params["thinking"] = {"type": "disabled" if reasoning_effort == "none" else "enabled"} + if ( + isinstance(reasoning_effort, str) + and reasoning_effort in SUPPORTED_REASONING_EFFORTS + and optional_params["thinking"] == {"type": "enabled"} + ): + return {**optional_params, "reasoning_effort": reasoning_effort} + return optional_params def _fill_reasoning_content(self, messages: list[AllMessageValues]) -> list[AllMessageValues]: diff --git a/litellm/llms/deepseek/messages/transformation.py b/litellm/llms/deepseek/messages/transformation.py index 6ddee99aea3..3b2076b0085 100644 --- a/litellm/llms/deepseek/messages/transformation.py +++ b/litellm/llms/deepseek/messages/transformation.py @@ -2,17 +2,37 @@ DeepSeek Anthropic-compatible messages transformation config. """ -from collections.abc import Sequence -from typing import Any, Final +from collections.abc import Mapping, Sequence +from typing import Final + +from pydantic import TypeAdapter import litellm from litellm.litellm_core_utils.url_utils import join_api_base -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) from litellm.secret_managers.main import get_secret_str from litellm.types.router import GenericLiteLLMParams +_TOOL_LIST: Final = TypeAdapter(list[object]) +_TOOL_FIELDS: Final = TypeAdapter(dict[object, object]) + + +def _custom_tool_without_type(tool: object) -> Mapping[object, object] | None: + if not isinstance(tool, dict): + return None + fields: Final = _TOOL_FIELDS.validate_python(tool) + if fields.get("type") == "custom": + fields.pop("type", None) + return fields + return None + + +def _sanitized_tool(tool: object) -> object: + stripped: Final = _custom_tool_without_type(tool) + return tool if stripped is None else stripped + class DeepSeekAnthropicMessagesConfig(AnthropicMessagesConfig): """ @@ -96,19 +116,11 @@ class DeepSeekAnthropicMessagesConfig(AnthropicMessagesConfig): return join_api_base(base_url, "v1/messages") @staticmethod - def _sanitize_tools_for_deepseek(tools: Any) -> object: + def _sanitize_tools_for_deepseek(tools: object) -> object: if not isinstance(tools, list): return tools - sanitized_tools: Final = [] - for tool in tools: - if isinstance(tool, dict) and tool.get("type") == "custom": - sanitized_tool = dict(tool) - sanitized_tool.pop("type", None) - sanitized_tools.append(sanitized_tool) - else: - sanitized_tools.append(tool) - return sanitized_tools + return [_sanitized_tool(tool) for tool in _TOOL_LIST.validate_python(tools)] def transform_anthropic_messages_request( self, diff --git a/litellm/llms/deprecated_providers/palm.py b/litellm/llms/deprecated_providers/palm.py index 785cffa48ea..b4a32630c42 100644 --- a/litellm/llms/deprecated_providers/palm.py +++ b/litellm/llms/deprecated_providers/palm.py @@ -1,4 +1,5 @@ import types +from collections.abc import Mapping from typing import Final @@ -41,16 +42,17 @@ class PalmConfig: top_p: float | None = None, max_output_tokens: int | None = None, ) -> None: - locals_: Final = locals().copy() + locals_: Final[Mapping[str, object]] = types.MappingProxyType(locals().copy()) for key, value in locals_.items(): if key != "self" and value is not None: setattr(self.__class__, key, value) @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not isinstance( v, diff --git a/litellm/llms/edenai/embedding/transformation.py b/litellm/llms/edenai/embedding/transformation.py index c79a6839434..13fa7142916 100644 --- a/litellm/llms/edenai/embedding/transformation.py +++ b/litellm/llms/edenai/embedding/transformation.py @@ -5,7 +5,7 @@ per-request cost at the top level of the body. Docs: https://www.edenai.co/docs/v3/llms/embeddings """ -from typing import TYPE_CHECKING, Final +from typing import TYPE_CHECKING, Final, Protocol, cast import httpx @@ -24,6 +24,14 @@ if TYPE_CHECKING: _SUPPORTED_PARAMS: Final = ("dimensions", "encoding_format", "user") +class _JsonResponse(Protocol): + def json(self) -> object: ... + + +def _json_body(response: _JsonResponse) -> object: + return response.json() + + class EdenAIEmbeddingConfig(BaseEmbeddingConfig): def get_supported_openai_params(self, model: str) -> list[str]: # mutable-ok: inherited contract return list(_SUPPORTED_PARAMS) @@ -80,10 +88,14 @@ class EdenAIEmbeddingConfig(BaseEmbeddingConfig): optional_params: dict[str, object], # mutable-ok: inherited contract litellm_params: dict[str, object], # mutable-ok: inherited contract ) -> EmbeddingResponse: - body: Final = raw_response.json() + body: Final = _json_body(raw_response) logging_obj.post_call(original_response=body) response: Final[EmbeddingResponse] = convert_to_model_response_object( - response_object=body, model_response_object=model_response, response_type="embedding" + response_object=cast( # cast-ok: the body passes through unvalidated, as before it was typed + dict[str, object], body + ), + model_response_object=model_response, + response_type="embedding", ) set_response_cost_in_hidden_params(response, reported_cost(body)) return response diff --git a/litellm/llms/edenai/image_generation/transformation.py b/litellm/llms/edenai/image_generation/transformation.py index e2a0b8684f6..a0c4e1b0458 100644 --- a/litellm/llms/edenai/image_generation/transformation.py +++ b/litellm/llms/edenai/image_generation/transformation.py @@ -5,7 +5,7 @@ for every image model in the catalog with the real per-request cost at the top l Docs: https://www.edenai.co/docs/v3/llms/image-generation """ -from typing import TYPE_CHECKING, Final +from typing import TYPE_CHECKING, Final, Protocol, cast import httpx @@ -36,6 +36,14 @@ _SUPPORTED_PARAMS: Final[tuple[OpenAIImageGenerationOptionalParams, ...]] = ( ) +class _JsonResponse(Protocol): + def json(self) -> object: ... + + +def _json_body(response: _JsonResponse) -> object: + return response.json() + + class EdenAIImageGenerationConfig(BaseImageGenerationConfig): def get_supported_openai_params( self, model: str @@ -97,10 +105,14 @@ class EdenAIImageGenerationConfig(BaseImageGenerationConfig): api_key: str | None = None, json_mode: bool | None = None, ) -> ImageResponse: - body: Final = raw_response.json() + body: Final = _json_body(raw_response) logging_obj.post_call(original_response=body) response: Final[ImageResponse] = convert_to_model_response_object( - response_object=body, model_response_object=model_response, response_type="image_generation" + response_object=cast( # cast-ok: the body passes through unvalidated, as before it was typed + dict[str, object], body + ), + model_response_object=model_response, + response_type="image_generation", ) set_response_cost_in_hidden_params(response, reported_cost(body)) return response diff --git a/litellm/llms/elevenlabs/audio_transcription/transformation.py b/litellm/llms/elevenlabs/audio_transcription/transformation.py index 5a673b5ac41..3dc42f35d3c 100644 --- a/litellm/llms/elevenlabs/audio_transcription/transformation.py +++ b/litellm/llms/elevenlabs/audio_transcription/transformation.py @@ -3,7 +3,7 @@ Translates from OpenAI's `/v1/audio/transcriptions` to ElevenLabs's `/v1/speech- """ from collections.abc import Iterable, Mapping -from typing import Final +from typing import Final, Protocol from httpx import Headers, Response from pydantic import ConfigDict, TypeAdapter @@ -27,6 +27,15 @@ from ..common_utils import ElevenLabsException _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_input_in_errors=True)) _JSON_OBJECTS: Final = TypeAdapter(Iterable[Mapping[str, object]], config=ConfigDict(hide_input_in_errors=True)) +_HIDDEN_PARAMS: Final = TypeAdapter(dict[str, object]) + + +class _JsonResponse(Protocol): + def json(self) -> object: ... + + +def _json_body(response: _JsonResponse) -> object: + return response.json() class ElevenLabsAudioTranscriptionConfig(BaseAudioTranscriptionConfig): @@ -120,7 +129,7 @@ class ElevenLabsAudioTranscriptionConfig(BaseAudioTranscriptionConfig): Transforms the raw response from ElevenLabs to the TranscriptionResponse format """ try: - response_json: Final = raw_response.json() + response_json: Final = _json_body(raw_response) response_object: Final = _JSON_OBJECT.validate_python(response_json) # Extract the main transcript text @@ -135,20 +144,18 @@ class ElevenLabsAudioTranscriptionConfig(BaseAudioTranscriptionConfig): # Map ElevenLabs words to OpenAI format if "words" in response_object: - response["words"] = [] - for word_data in _JSON_OBJECTS.validate_python(response_object["words"]): - # Only include actual words, skip spacing and audio events - if word_data.get("type") == "word": - response["words"].append( - { - "word": word_data.get("text", ""), - "start": word_data.get("start", 0), - "end": word_data.get("end", 0), - } - ) + response["words"] = [ + { + "word": word_data.get("text", ""), + "start": word_data.get("start", 0), + "end": word_data.get("end", 0), + } + for word_data in _JSON_OBJECTS.validate_python(response_object["words"]) + if word_data.get("type") == "word" + ] # Store full response in hidden params - response.hidden_params = response_json + response.hidden_params = _HIDDEN_PARAMS.validate_python(response_json) return response diff --git a/litellm/llms/elevenlabs/text_to_speech/transformation.py b/litellm/llms/elevenlabs/text_to_speech/transformation.py index f910ef8c057..23ccf41c9da 100644 --- a/litellm/llms/elevenlabs/text_to_speech/transformation.py +++ b/litellm/llms/elevenlabs/text_to_speech/transformation.py @@ -56,9 +56,9 @@ class ElevenLabsTextToSpeechConfig(BaseTextToSpeechConfig): # Response format mappings from OpenAI to ElevenLabs FORMAT_MAPPINGS = { "mp3": "mp3_44100_128", - "pcm": "pcm_44100", + "pcm": "pcm_24000", "opus": "opus_48000_128", - # ElevenLabs does not support WAV, AAC, or FLAC formats. + "wav": "wav_24000", } ELEVENLABS_QUERY_PARAMS_KEY = "__elevenlabs_query_params__" diff --git a/litellm/llms/fal_ai/image_generation/flux_pro_v11_ultra_transformation.py b/litellm/llms/fal_ai/image_generation/flux_pro_v11_ultra_transformation.py index 0fdd89aec91..fc215e3d94e 100644 --- a/litellm/llms/fal_ai/image_generation/flux_pro_v11_ultra_transformation.py +++ b/litellm/llms/fal_ai/image_generation/flux_pro_v11_ultra_transformation.py @@ -19,6 +19,7 @@ else: LiteLLMLoggingObj = Any _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_input_in_errors=True)) +_DECODED_JSON: Final = TypeAdapter(object) class FalAIFluxProV11UltraConfig(FalAIBaseConfig): @@ -222,7 +223,7 @@ class FalAIFluxProV11UltraConfig(FalAIBaseConfig): } """ try: - response_data: Final = raw_response.json() + response_data: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception as e: raise self.get_error_class( error_message=f"Error transforming image generation response: {e}", diff --git a/litellm/llms/fal_ai/image_generation/recraft_v3_transformation.py b/litellm/llms/fal_ai/image_generation/recraft_v3_transformation.py index 038a06c5749..26b257f5c89 100644 --- a/litellm/llms/fal_ai/image_generation/recraft_v3_transformation.py +++ b/litellm/llms/fal_ai/image_generation/recraft_v3_transformation.py @@ -18,6 +18,7 @@ else: LiteLLMLoggingObj = Any _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_input_in_errors=True)) +_DECODED_JSON: Final = TypeAdapter(object) class FalAIRecraftV3Config(FalAIBaseConfig): @@ -195,7 +196,7 @@ class FalAIRecraftV3Config(FalAIBaseConfig): } """ try: - response_data: Final = raw_response.json() + response_data: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception as e: raise self.get_error_class( error_message=f"Error transforming image generation response: {e}", diff --git a/litellm/llms/fal_ai/image_generation/stable_diffusion_transformation.py b/litellm/llms/fal_ai/image_generation/stable_diffusion_transformation.py index 30d51cc8084..fdd552efd73 100644 --- a/litellm/llms/fal_ai/image_generation/stable_diffusion_transformation.py +++ b/litellm/llms/fal_ai/image_generation/stable_diffusion_transformation.py @@ -19,6 +19,7 @@ else: LiteLLMLoggingObj = Any _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_input_in_errors=True)) +_DECODED_JSON: Final = TypeAdapter(object) class FalAIStableDiffusionConfig(FalAIBaseConfig): @@ -236,7 +237,7 @@ class FalAIStableDiffusionConfig(FalAIBaseConfig): } """ try: - response_data: Final = raw_response.json() + response_data: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception as e: raise self.get_error_class( error_message=f"Error transforming image generation response: {e}", diff --git a/litellm/llms/featherless_ai/chat/transformation.py b/litellm/llms/featherless_ai/chat/transformation.py index a68261c58e9..4bf0486f723 100644 --- a/litellm/llms/featherless_ai/chat/transformation.py +++ b/litellm/llms/featherless_ai/chat/transformation.py @@ -1,3 +1,5 @@ +from collections.abc import Mapping +from types import MappingProxyType from typing import Final import litellm @@ -42,7 +44,7 @@ class FeatherlessAIConfig(OpenAIGPTConfig): tool_choice: str | None = None, tools: list | None = None, ) -> None: - locals_: Final = locals().copy() + locals_: Final[Mapping[str, object]] = MappingProxyType(locals().copy()) for key, value in locals_.items(): if key != "self" and value is not None: setattr(self.__class__, key, value) diff --git a/litellm/llms/fireworks_ai/decisions/transformation.py b/litellm/llms/fireworks_ai/decisions/transformation.py index 87d402902be..bba4835060b 100644 --- a/litellm/llms/fireworks_ai/decisions/transformation.py +++ b/litellm/llms/fireworks_ai/decisions/transformation.py @@ -14,6 +14,8 @@ class FireworksAIDecisionsConfig(BaseDecisionsConfig): def parse_response(self, payload: object, request: DecisionsIRRequest) -> DecisionsIRResponse: response: Final = parse_systemone_response(self.unwrap_response(payload), request) + if response.usage is None: + return response cached: Final = response.usage.extra.get("cached_input_tokens") if isinstance(cached, bool) or not isinstance(cached, int): return response diff --git a/litellm/llms/fireworks_ai/rerank/transformation.py b/litellm/llms/fireworks_ai/rerank/transformation.py index 964f85c821e..84c93974cd7 100644 --- a/litellm/llms/fireworks_ai/rerank/transformation.py +++ b/litellm/llms/fireworks_ai/rerank/transformation.py @@ -44,6 +44,7 @@ class _FireworksAIResultFields(LiteLLMBaseModel): _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_input_in_errors=True)) _JSON_OBJECTS: Final = TypeAdapter(Iterable[Mapping[str, object]], config=ConfigDict(hide_input_in_errors=True)) _STR: Final = TypeAdapter(str) +_DECODED_JSON: Final = TypeAdapter(object) class FireworksAIRerankConfig(FireworksAIMixin, BaseRerankConfig): @@ -200,7 +201,7 @@ class FireworksAIRerankConfig(FireworksAIMixin, BaseRerankConfig): Transform Fireworks AI rerank response to LiteLLM RerankResponse format """ try: - raw_response_json: Final = raw_response.json() + raw_response_json: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception as e: raise self.get_error_class( error_message=f"Failed to parse response: {e}", diff --git a/litellm/llms/gdc/chat/transformation.py b/litellm/llms/gdc/chat/transformation.py index cd9ffe9e03e..680db52b283 100644 --- a/litellm/llms/gdc/chat/transformation.py +++ b/litellm/llms/gdc/chat/transformation.py @@ -10,13 +10,17 @@ from collections.abc import Callable from typing import Final, Protocol from urllib.parse import urlsplit +from pydantic import TypeAdapter from typing_extensions import ReadOnly, TypedDict, Unpack import litellm +from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.litellm_core_utils.url_utils import join_api_base from litellm.llms.openai_like.chat.transformation import OpenAILikeChatConfig from litellm.types.llms.openai import AllMessageValues +_DECODED_JSON: Final = TypeAdapter(object) + class _OpenAIGPTConfigOptions(TypedDict, total=False): """The sampling defaults ``OpenAIGPTConfig.__init__`` accepts and stashes on the class.""" @@ -203,10 +207,10 @@ class GDCGeminiConfig(OpenAILikeChatConfig): import google.auth try: - json_obj: Final = json.loads(api_key) + json_obj: Final = as_str_mapping(_DECODED_JSON.validate_python(json.loads(api_key))) except json.JSONDecodeError: return None, False - if not isinstance(json_obj, dict) or json_obj.get("type") != self._GDCH_CREDENTIAL_TYPE: + if json_obj is None or json_obj.get("type") != self._GDCH_CREDENTIAL_TYPE: raise ValueError( "GDC only accepts a GDCH service account credential as a JSON api_key " '(expected "type": "gdch_service_account"). Other Google credential types are ' diff --git a/litellm/llms/gemini/agents/transformation.py b/litellm/llms/gemini/agents/transformation.py index c19bd9ce87c..f7352da5fb6 100644 --- a/litellm/llms/gemini/agents/transformation.py +++ b/litellm/llms/gemini/agents/transformation.py @@ -10,11 +10,12 @@ Proxies the Gemini v1beta Agents API: """ from collections.abc import Mapping -from typing import Any, Final +from typing import Any, Final, Protocol import httpx from litellm._logging import verbose_logger +from litellm.litellm_core_utils.core_helpers import decoded_json_object from litellm.litellm_core_utils.url_utils import join_api_base from litellm.llms.base_llm.agents.transformation import BaseAgentsAPIConfig from litellm.llms.gemini.common_utils import GeminiError, GeminiModelInfo @@ -29,6 +30,15 @@ from litellm.types.agents import ( # create-agent body verbatim. _GEMINI_AGENT_BODY_KEYS: Final = ("base_agent", "instructions", "base_environment") + +class _JsonResponse(Protocol): + def json(self) -> object: ... + + +def _json_body(response: _JsonResponse) -> object: + return response.json() + + # LiteLLM-internal keys that must never be forwarded to Gemini. _LITELLM_INTERNAL_KEYS: Final = frozenset( { @@ -156,18 +166,19 @@ class GeminiAgentsConfig(BaseAgentsAPIConfig): """ self._raise_for_status(raw_response) try: - data: dict[str, Any] = raw_response.json() + decoded: object = _json_body(raw_response) except Exception: verbose_logger.warning( "GeminiAgentsConfig: non-JSON create response (status=%d).", raw_response.status_code, ) - data = {"id": name} + decoded = {"id": name} + data: Final = dict(decoded_json_object(decoded)) # Gemini uses "id" as the identifier; normalise to both fields. data.setdefault("id", name) data.setdefault("name", data["id"]) verbose_logger.debug("GeminiAgentsConfig create response: %s", data) - return AgentCreateResponse(**data) + return AgentCreateResponse.model_validate(data) # ------------------------------------------------------------------ # # LIST # @@ -192,13 +203,16 @@ class GeminiAgentsConfig(BaseAgentsAPIConfig): ) -> AgentListResponse: self._raise_for_status(raw_response) try: - data = raw_response.json() + decoded: object = _json_body(raw_response) except Exception: - data = {} + decoded = {} + data: Final = decoded_json_object(decoded) verbose_logger.debug("GeminiAgentsConfig list response: %s", data) - return AgentListResponse( - agents=data.get("agents", []), - next_page_token=data.get("nextPageToken"), + return AgentListResponse.model_validate( + { + "agents": data.get("agents", []), + "next_page_token": data.get("nextPageToken"), + } ) # ------------------------------------------------------------------ # @@ -222,13 +236,14 @@ class GeminiAgentsConfig(BaseAgentsAPIConfig): """Same shape as create response — Gemini returns "id" as identifier.""" self._raise_for_status(raw_response) try: - data = raw_response.json() + decoded: object = _json_body(raw_response) except Exception: - data = {"id": name} + decoded = {"id": name} + data: Final = dict(decoded_json_object(decoded)) data.setdefault("id", name) data.setdefault("name", data["id"]) verbose_logger.debug("GeminiAgentsConfig get response: %s", data) - return AgentCreateResponse(**data) + return AgentCreateResponse.model_validate(data) # ------------------------------------------------------------------ # # DELETE # @@ -285,11 +300,14 @@ class GeminiAgentsConfig(BaseAgentsAPIConfig): """ self._raise_for_status(raw_response) try: - data = raw_response.json() + decoded: object = _json_body(raw_response) except Exception: - data = {} + decoded = {} + data: Final = decoded_json_object(decoded) verbose_logger.debug("GeminiAgentsConfig list_versions response for '%s': %s", name, data) - return AgentVersionsResponse( - agent_versions=data.get("agentVersions", []), - next_page_token=data.get("nextPageToken"), + return AgentVersionsResponse.model_validate( + { + "agent_versions": data.get("agentVersions", []), + "next_page_token": data.get("nextPageToken"), + } ) diff --git a/litellm/llms/gemini/audio_transcription/transformation.py b/litellm/llms/gemini/audio_transcription/transformation.py index ea116a7e9de..3457b22faa4 100644 --- a/litellm/llms/gemini/audio_transcription/transformation.py +++ b/litellm/llms/gemini/audio_transcription/transformation.py @@ -3,6 +3,7 @@ from collections.abc import Mapping, Sequence from typing import Final from httpx import Headers, Response +from pydantic import TypeAdapter from litellm.litellm_core_utils.audio_utils.subtitle_utils import SUBTITLE_RESPONSE_FORMATS from litellm.litellm_core_utils.audio_utils.utils import ( @@ -36,6 +37,7 @@ from litellm.types.utils import ( INTERACTIONS_API_REVISION: Final = "2026-05-20" WORD_INFO_ANNOTATION_TYPE: Final = "word_info" +_DECODED_JSON: Final = TypeAdapter(object) class GeminiAudioTranscriptionConfig(BaseAudioTranscriptionConfig): @@ -132,7 +134,7 @@ class GeminiAudioTranscriptionConfig(BaseAudioTranscriptionConfig): raw_response: Response, ) -> TranscriptionResponse: try: - response_json: Final = raw_response.json() + response_json: Final = _DECODED_JSON.validate_python(raw_response.json()) except ValueError: raise GeminiError( status_code=raw_response.status_code, diff --git a/litellm/llms/gemini/common_utils.py b/litellm/llms/gemini/common_utils.py index 13df3921d13..9634c580858 100644 --- a/litellm/llms/gemini/common_utils.py +++ b/litellm/llms/gemini/common_utils.py @@ -2,9 +2,9 @@ import base64 import datetime import json import math -from collections.abc import Mapping, Sequence +from collections.abc import Iterable, Mapping, Sequence from types import MappingProxyType -from typing import Any, Final +from typing import Any, Final, cast import httpx from pydantic import JsonValue, TypeAdapter @@ -389,7 +389,7 @@ class GeminiModelInfo(BaseLLMModelInfo): def get_base_model(model: str) -> str | None: return model.replace("gemini/", "") - def process_model_name(self, models: list[dict[str, str]]) -> list[str]: + def process_model_name(self, models: Iterable[Mapping[str, str]]) -> list[str]: litellm_model_names: Final = [] for model in models: stripped_model_name = model["name"].replace("models/", "") @@ -416,9 +416,11 @@ class GeminiModelInfo(BaseLLMModelInfo): f"Failed to fetch models from Gemini. Status code: {response.status_code}, Response: {response.json()}" ) - models: Final[list[dict[str, str]]] = response.json()["models"] + listing: Final = cast( # cast-ok: the body passes through unvalidated, as before it was typed + Mapping[str, Iterable[Mapping[str, str]]], _JSON_VALUE.validate_python(response.json()) + ) - litellm_model_names: Final = self.process_model_name(models) + litellm_model_names: Final = self.process_model_name(listing["models"]) return litellm_model_names def get_error_class(self, error_message: str, status_code: int, headers: dict | httpx.Headers) -> BaseLLMException: diff --git a/litellm/llms/gemini/google_genai/guardrail_translation/handler.py b/litellm/llms/gemini/google_genai/guardrail_translation/handler.py index 44cdac11325..34007bc8fd4 100644 --- a/litellm/llms/gemini/google_genai/guardrail_translation/handler.py +++ b/litellm/llms/gemini/google_genai/guardrail_translation/handler.py @@ -15,7 +15,10 @@ from collections.abc import Mapping, Sequence from types import MappingProxyType from typing import TYPE_CHECKING, Final, Optional +from pydantic import TypeAdapter + from litellm._logging import verbose_proxy_logger +from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.llms.base_llm.guardrail_translation.base_translation import ( BaseTranslation, StreamTransformSink, @@ -28,6 +31,7 @@ if TYPE_CHECKING: from litellm.types.proxy.auth.user_api_key_auth import UserAPIKeyAuth _EMPTY_REQUEST_DATA: Final[Mapping[str, object]] = MappingProxyType({}) +_DECODED_JSON: Final = TypeAdapter(object) def _field(container: object, name: str) -> object | None: @@ -108,12 +112,10 @@ def _write_back_texts(text_parts: Sequence[object], guardrailed_texts: Sequence[ def _parse_json_dict_or_none(payload: str) -> Mapping[str, object] | None: try: - parsed: Final = json.loads(payload) + parsed: Final = _DECODED_JSON.validate_python(json.loads(payload)) except json.JSONDecodeError: return None - if isinstance(parsed, dict): - return parsed - return None + return as_str_mapping(parsed) def _sse_payload_texts(sse_text: str) -> tuple[str, ...]: diff --git a/litellm/llms/gemini/google_genai/transformation.py b/litellm/llms/gemini/google_genai/transformation.py index bc3180a2129..0e29df36e80 100644 --- a/litellm/llms/gemini/google_genai/transformation.py +++ b/litellm/llms/gemini/google_genai/transformation.py @@ -3,7 +3,7 @@ Transformation for Calling Google models in their native format. """ from copy import deepcopy -from typing import TYPE_CHECKING, Any, Final, Literal, cast +from typing import TYPE_CHECKING, Any, Final, Literal, Protocol, cast import httpx @@ -36,6 +36,14 @@ else: from ..common_utils import get_api_key_from_env +class _JsonResponse(Protocol): + def json(self) -> object: ... + + +def _json_body(response: _JsonResponse) -> object: + return response.json() + + class GoogleGenAIConfig(BaseGoogleGenAIGenerateContentConfig, VertexLLM): """ Configuration for calling Google models in their native format. @@ -382,7 +390,7 @@ class GoogleGenAIConfig(BaseGoogleGenAIGenerateContentConfig, VertexLLM): from litellm.types.google_genai.main import GenerateContentResponse try: - response = raw_response.json() + decoded: Final = _json_body(raw_response) except Exception as e: raise self.get_error_class( error_message=f"Error transforming generate content response: {e}", @@ -391,7 +399,9 @@ class GoogleGenAIConfig(BaseGoogleGenAIGenerateContentConfig, VertexLLM): ) logging_obj.model_call_details["httpx_response"] = raw_response - response = self.convert_citation_sources_to_citations(response) + response: Final = self.convert_citation_sources_to_citations( + cast(dict[str, object], decoded) # cast-ok: the body passes through unvalidated, as before it was typed + ) return GenerateContentResponse(**response) diff --git a/litellm/llms/gemini/image_edit/transformation.py b/litellm/llms/gemini/image_edit/transformation.py index 450c38a2206..d48a66f1f93 100644 --- a/litellm/llms/gemini/image_edit/transformation.py +++ b/litellm/llms/gemini/image_edit/transformation.py @@ -1,12 +1,13 @@ import base64 from collections.abc import Mapping from io import BufferedReader, BytesIO -from typing import TYPE_CHECKING, Any, Final, cast +from typing import TYPE_CHECKING, Any, Final, Protocol, cast import httpx from httpx._types import RequestFiles from litellm.images.utils import ImageEditRequestUtils +from litellm.litellm_core_utils.core_helpers import decoded_json_object from litellm.litellm_core_utils.url_utils import join_api_base from litellm.llms.base_llm.image_edit.transformation import BaseImageEditConfig from litellm.llms.gemini.common_utils import ( @@ -18,6 +19,7 @@ from litellm.llms.gemini.image_usage_transformation import ( ) from litellm.secret_managers.main import get_secret_str from litellm.types.images.main import ImageEditOptionalRequestParams +from litellm.types.llms.vertex_ai import GenerateContentResponseBody from litellm.types.router import GenericLiteLLMParams from litellm.types.utils import ( FileTypes, @@ -34,6 +36,14 @@ else: LiteLLMLoggingObj = Any +class _JsonResponse(Protocol): + def json(self) -> object: ... + + +def _json_body(response: _JsonResponse) -> object: + return response.json() + + class GeminiImageEditConfig(BaseImageEditConfig): DEFAULT_BASE_URL: str = "https://generativelanguage.googleapis.com/v1beta" SUPPORTED_PARAMS: list[str] = ["n", "size", "imageConfig"] @@ -125,7 +135,7 @@ class GeminiImageEditConfig(BaseImageEditConfig): ) -> ImageResponse: model_response: Final = ImageResponse() try: - response_json: Final = raw_response.json() + response_json: Final = _json_body(raw_response) except Exception as exc: raise self.get_error_class( error_message=f"Error transforming image edit response: {exc}", @@ -133,7 +143,10 @@ class GeminiImageEditConfig(BaseImageEditConfig): headers=raw_response.headers, ) - candidates: Final = response_json.get("candidates", []) + payload: Final = cast( # cast-ok: the body passes through unvalidated, as before it was typed + GenerateContentResponseBody, response_json + ) + candidates: Final = payload.get("candidates", []) data_list: Final[list[ImageObject]] = [] for candidate in candidates: @@ -141,17 +154,18 @@ class GeminiImageEditConfig(BaseImageEditConfig): parts = content.get("parts", []) for part in parts: inline_data = part.get("inlineData") - if inline_data and inline_data.get("data"): + image_data = inline_data.get("data") if inline_data else None + if image_data: data_list.append( ImageObject( - b64_json=inline_data["data"], + b64_json=image_data, url=None, ) ) model_response.data = cast(list[OpenAIImage], data_list) - if "usageMetadata" in response_json: - model_response.usage = transform_gemini_image_usage(response_json["usageMetadata"]) + if "usageMetadata" in payload: + model_response.usage = transform_gemini_image_usage(dict(decoded_json_object(payload["usageMetadata"]))) return model_response def _prepare_inline_image_parts(self, image: FileTypes | list[FileTypes]) -> list[dict[str, object]]: diff --git a/litellm/llms/gemini/image_generation/transformation.py b/litellm/llms/gemini/image_generation/transformation.py index 1aa3d074b1a..1f986b11af2 100644 --- a/litellm/llms/gemini/image_generation/transformation.py +++ b/litellm/llms/gemini/image_generation/transformation.py @@ -37,6 +37,7 @@ else: _JSON_OBJECTS: Final = TypeAdapter(Iterable[Mapping[str, object]], config=ConfigDict(hide_input_in_errors=True)) _JSON_DICT: Final = TypeAdapter(dict[str, object], config=ConfigDict(hide_input_in_errors=True)) _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_input_in_errors=True)) +_DECODED_JSON: Final = TypeAdapter(object) _JSON_CONTAINER: Final[TypeAdapter[Mapping[str, object] | str | Sequence[object]]] = TypeAdapter( Mapping[str, object] | str | Sequence[object], config=ConfigDict(hide_input_in_errors=True) ) @@ -188,7 +189,7 @@ class GoogleImageGenConfig(BaseImageGenerationConfig): Transform Google AI Imagen response to litellm ImageResponse format """ try: - response_data: Final = raw_response.json() + response_data: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception as e: raise self.get_error_class( error_message=f"Error transforming image generation response: {e}", @@ -226,9 +227,9 @@ class GoogleImageGenConfig(BaseImageGenerationConfig): ) # Extract usage metadata for Gemini models - if "usageMetadata" in response_data: + if "usageMetadata" in response_object: model_response.usage = transform_gemini_image_usage( - _JSON_DICT.validate_python(response_data["usageMetadata"]) + _JSON_DICT.validate_python(response_object["usageMetadata"]) ) web_search_requests: Final = get_gemini_image_web_search_requests(response_object) if web_search_requests and model_response.usage is not None: diff --git a/litellm/llms/gemini/realtime/transformation.py b/litellm/llms/gemini/realtime/transformation.py index 9af7edeac86..6f778ab2761 100644 --- a/litellm/llms/gemini/realtime/transformation.py +++ b/litellm/llms/gemini/realtime/transformation.py @@ -5,13 +5,14 @@ This file contains the transformation logic for the Gemini realtime API. import json from collections import OrderedDict from collections.abc import Mapping, Sequence -from typing import Any, Final, cast +from typing import Final, cast from typing_extensions import ReadOnly, Required, TypedDict import litellm from litellm import verbose_logger from litellm._uuid import uuid +from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj from litellm.litellm_core_utils.url_utils import join_api_base from litellm.llms.base_llm.realtime.transformation import BaseRealtimeConfig @@ -167,16 +168,17 @@ class GeminiRealtimeConfig(BaseRealtimeConfig): return True @staticmethod - def _usage_detail_alias(details: Mapping[str, int | None] | None, defaults: dict[str, int]) -> dict[str, int]: - if not isinstance(details, dict): + def _usage_detail_alias(details: object, defaults: dict[str, int]) -> dict[str, object]: + detail_mapping: Final = as_str_mapping(details) + if detail_mapping is None or not isinstance(details, dict): return dict(defaults) return { **defaults, - **{key: value for key, value in details.items() if value is not None}, + **{key: value for key, value in detail_mapping.items() if value is not None}, } @staticmethod - def _add_pipecat_usage_detail_aliases(usage_dict: dict[str, Any]) -> dict[str, object]: + def _add_pipecat_usage_detail_aliases(usage_dict: dict[str, object]) -> dict[str, object]: usage_dict.setdefault( "input_token_details", GeminiRealtimeConfig._usage_detail_alias( diff --git a/litellm/llms/gemini/videos/transformation.py b/litellm/llms/gemini/videos/transformation.py index 0656095927c..3f6b900fd01 100644 --- a/litellm/llms/gemini/videos/transformation.py +++ b/litellm/llms/gemini/videos/transformation.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Any, Final import httpx from httpx._types import RequestFiles +from pydantic import TypeAdapter import litellm from litellm.constants import DEFAULT_GOOGLE_VIDEO_DURATION_SECONDS @@ -37,6 +38,8 @@ else: LiteLLMLoggingObj = Any BaseLLMException = Any +_DECODED_JSON: Final = TypeAdapter(object) + def _convert_image_to_gemini_format(image_file) -> dict[str, str]: """ @@ -60,7 +63,7 @@ def _convert_image_to_gemini_format(image_file) -> dict[str, str]: def _json_payload(raw_response: httpx.Response) -> object: """Read an HTTP response body as an opaque JSON payload.""" - return raw_response.json() + return _DECODED_JSON.validate_python(raw_response.json()) def _usage_video_resolution_from_parameters( diff --git a/litellm/llms/gigachat/chat/transformation.py b/litellm/llms/gigachat/chat/transformation.py index 936e6339865..65921b628fb 100644 --- a/litellm/llms/gigachat/chat/transformation.py +++ b/litellm/llms/gigachat/chat/transformation.py @@ -273,7 +273,7 @@ class GigaChatConfig(BaseConfig): # Default to None (don't set function_call) return None - def _upload_image(self, image_url: str) -> str | None: + def _upload_image(self, image_url: str) -> object: """ Upload image to GigaChat and return file_id. @@ -293,7 +293,7 @@ class GigaChatConfig(BaseConfig): verbose_logger.error("Failed to upload image: %s", e) return None - def _transform_list_content(self, content: Sequence) -> tuple[str, Sequence[str]]: + def _transform_list_content(self, content: Sequence) -> tuple[str, Sequence[object]]: """ Extract text and image attachments from a multimodal message content list. @@ -304,7 +304,7 @@ class GigaChatConfig(BaseConfig): Tuple of (combined text, list of attachment file ids) """ texts: Final[list[str]] = [] # mutable-ok: accumulator - attachments: Final[list[str]] = [] # mutable-ok: accumulator + attachments: Final[list[object]] = [] # mutable-ok: accumulator for part in content: if isinstance(part, dict): if part.get("type") == "text": diff --git a/litellm/llms/gigachat/file_handler.py b/litellm/llms/gigachat/file_handler.py index aff0465d1ec..d53ae3af334 100644 --- a/litellm/llms/gigachat/file_handler.py +++ b/litellm/llms/gigachat/file_handler.py @@ -12,6 +12,8 @@ import uuid from collections.abc import Mapping from typing import Final +from pydantic import TypeAdapter + from litellm._logging import verbose_logger from litellm.litellm_core_utils.url_utils import join_api_base from litellm.llms.custom_httpx.http_handler import ( @@ -19,12 +21,14 @@ from litellm.llms.custom_httpx.http_handler import ( get_httpx_client, ) from litellm.llms.gigachat.utils import get_api_base +from litellm.llms.openai.common_utils import decoded_json_object from litellm.types.utils import LlmProviders from .authenticator import get_access_token, get_access_token_async # Simple in-memory cache for file IDs -_file_cache: Final[dict[str, str]] = {} +_file_cache: Final[dict[str, object]] = {} +_DECODED_JSON: Final = TypeAdapter(object) def _get_url_hash(url: str) -> str: @@ -91,7 +95,7 @@ def upload_file_sync( credentials: str | None = None, api_base: str | None = None, litellm_params: Mapping[str, object] | None = None, -) -> str | None: +) -> object: """ Upload file to GigaChat and return file_id (sync). @@ -137,9 +141,9 @@ def upload_file_sync( timeout=60, ) response.raise_for_status() - result: Final = response.json() + result: Final = _DECODED_JSON.validate_python(response.json()) - file_id: Final = result.get("id") + file_id: Final = decoded_json_object(result).get("id") if file_id: _file_cache[url_hash] = file_id verbose_logger.debug("File uploaded successfully, file_id: %s", file_id) @@ -156,7 +160,7 @@ async def upload_file_async( credentials: str | None = None, api_base: str | None = None, litellm_params: Mapping[str, object] | None = None, -) -> str | None: +) -> object: """ Upload file to GigaChat and return file_id (async). @@ -205,9 +209,9 @@ async def upload_file_async( timeout=60, ) response.raise_for_status() - result: Final = response.json() + result: Final = _DECODED_JSON.validate_python(response.json()) - file_id: Final = result.get("id") + file_id: Final = decoded_json_object(result).get("id") if file_id: _file_cache[url_hash] = file_id verbose_logger.debug("File uploaded successfully, file_id: %s", file_id) diff --git a/litellm/llms/gigachat/passthrough/transformation.py b/litellm/llms/gigachat/passthrough/transformation.py index 872eee6dbf9..27f75eece50 100644 --- a/litellm/llms/gigachat/passthrough/transformation.py +++ b/litellm/llms/gigachat/passthrough/transformation.py @@ -5,11 +5,13 @@ from collections.abc import Mapping, Sequence from typing import TYPE_CHECKING, Final import httpx +from pydantic import TypeAdapter from litellm.llms.base_llm.passthrough.transformation import BasePassthroughConfig from litellm.llms.gigachat.authenticator import get_access_token from litellm.llms.gigachat.chat.streaming import GigaChatModelResponseIterator from litellm.llms.gigachat.utils import GIGACHAT_BASE_URL +from litellm.llms.openai.common_utils import decoded_json_object from litellm.secret_managers.main import get_secret_str from litellm.types.llms.openai import AllMessageValues from litellm.types.utils import EmbeddingResponse @@ -20,6 +22,8 @@ if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj from litellm.types.utils import CostResponseTypes +_DECODED_JSON: Final = TypeAdapter(object) + class GigaChatPassthroughConfig(BasePassthroughConfig): def is_streaming_request(self, endpoint: str, request_data: Mapping[str, object]) -> bool: @@ -161,7 +165,7 @@ class GigaChatPassthroughConfig(BasePassthroughConfig): continue chunk = chunk.removeprefix("data: ") try: - message = json.loads(chunk) + message = _DECODED_JSON.validate_python(json.loads(chunk)) except json.JSONDecodeError: continue @@ -169,7 +173,7 @@ class GigaChatPassthroughConfig(BasePassthroughConfig): streaming_response=None, sync_stream=False, ) - translated_chunk = gigachat_iterator.chunk_parser(chunk=message) + translated_chunk = gigachat_iterator.chunk_parser(chunk=decoded_json_object(message)) if isinstance(translated_chunk, dict) and generic_chunk_has_all_required_fields( # pyright: ignore[reportUnnecessaryIsInstance] # runtime guard for patched chunk_parser dict(translated_chunk) diff --git a/litellm/llms/github_copilot/chat/transformation.py b/litellm/llms/github_copilot/chat/transformation.py index 9553327db97..83bc8df23a6 100644 --- a/litellm/llms/github_copilot/chat/transformation.py +++ b/litellm/llms/github_copilot/chat/transformation.py @@ -4,9 +4,11 @@ from collections.abc import Mapping, Sequence from typing import TYPE_CHECKING, Final, cast # noqa: TID251 # spread dict loses the role literal without a cast import httpx +from pydantic import TypeAdapter from litellm.exceptions import AuthenticationError from litellm.llms.anthropic.chat.transformation import AnthropicConfig +from litellm.llms.openai.common_utils import decoded_json_object from litellm.llms.openai.openai import OpenAIConfig from litellm.types.llms.openai import AllMessageValues, ChatCompletionToolCallChunk from litellm.types.utils import ModelResponse @@ -23,6 +25,8 @@ if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj from litellm.litellm_core_utils.tokenizer import Encoding +_DECODED_JSON: Final = TypeAdapter(object) + class GithubCopilotConfig(OpenAIConfig): def __init__( @@ -309,7 +313,7 @@ class GithubCopilotConfig(OpenAIConfig): json_mode: bool | None = None, ) -> "ModelResponse": try: - response_json = raw_response.json() + decoded_response: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception: return super().transform_response( model=model, @@ -325,12 +329,13 @@ class GithubCopilotConfig(OpenAIConfig): json_mode=json_mode, ) + response_json: Final = decoded_json_object(decoded_response) if not response_json.get("choices"): - response_json = self._synthesize_choices_for_anthropic_native(response_json) + synthesized: Final = self._synthesize_choices_for_anthropic_native(dict(response_json)) raw_response = httpx.Response( status_code=raw_response.status_code, headers=raw_response.headers, - content=json.dumps(response_json).encode(), + content=json.dumps(synthesized).encode(), ) return super().transform_response( diff --git a/litellm/llms/github_copilot/messages/transformation.py b/litellm/llms/github_copilot/messages/transformation.py index 56c3693a02c..bc2b68cd02b 100644 --- a/litellm/llms/github_copilot/messages/transformation.py +++ b/litellm/llms/github_copilot/messages/transformation.py @@ -1,8 +1,9 @@ -from typing import Any, Final, cast # noqa: TID251 # narrows untyped request dicts at the session boundary +from collections.abc import Sequence +from typing import Final, cast # noqa: TID251 # narrows untyped request dicts at the session boundary from litellm.exceptions import AuthenticationError from litellm.litellm_core_utils.url_utils import ensure_api_route -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) @@ -54,7 +55,7 @@ class GithubCopilotAnthropicMessagesConfig(AnthropicMessagesConfig): self, headers: dict, model: str, - messages: list[Any], + messages: Sequence[object], optional_params: dict, litellm_params: dict, api_key: str | None = None, diff --git a/litellm/llms/github_copilot/responses/transformation.py b/litellm/llms/github_copilot/responses/transformation.py index bf0b8c79068..b055d388dd5 100644 --- a/litellm/llms/github_copilot/responses/transformation.py +++ b/litellm/llms/github_copilot/responses/transformation.py @@ -9,6 +9,7 @@ https://github.com/caozhiyuan/copilot-api """ import os +from collections.abc import Mapping from typing import ( TYPE_CHECKING, Any, @@ -16,6 +17,8 @@ from typing import ( cast, # noqa: TID251 # narrows untyped request dicts at the session boundary ) +from pydantic import TypeAdapter + import litellm from litellm._logging import verbose_logger from litellm.constants import DEFAULT_MAX_RECURSE_DEPTH @@ -47,6 +50,9 @@ if TYPE_CHECKING: else: LiteLLMLoggingObj = Any +_OBJECT_LIST: Final = TypeAdapter(list[object]) +_OBJECT_MAPPING: Final = TypeAdapter(Mapping[object, object]) + def github_copilot_supports_responses_api(model: str) -> bool: """ @@ -387,7 +393,9 @@ class GithubCopilotResponsesAPIConfig(OpenAIResponsesAPIConfig): """ return self._contains_vision_content(input_param) - def _contains_vision_content(self, value: Any, depth: int = 0, max_depth: int = DEFAULT_MAX_RECURSE_DEPTH) -> bool: + def _contains_vision_content( + self, value: object, depth: int = 0, max_depth: int = DEFAULT_MAX_RECURSE_DEPTH + ) -> bool: """ Recursively check if a value contains vision content. @@ -404,22 +412,28 @@ class GithubCopilotResponsesAPIConfig(OpenAIResponsesAPIConfig): # Check arrays if isinstance(value, list): - return any(self._contains_vision_content(item, depth=depth + 1, max_depth=max_depth) for item in value) + items: Final = _OBJECT_LIST.validate_python(value) + return any(self._contains_vision_content(item, depth=depth + 1, max_depth=max_depth) for item in items) # Only check dict/object types if not isinstance(value, dict): return False + fields: Final = _OBJECT_MAPPING.validate_python(value) + # Check if this item is an input_image - item_type: Final = value.get("type") + item_type: Final = fields.get("type") if isinstance(item_type, str) and item_type.lower() == "input_image": return True # Check content field recursively - if "content" in value and isinstance(value["content"], list): - return any( - self._contains_vision_content(item, depth=depth + 1, max_depth=max_depth) for item in value["content"] - ) + if "content" in fields: + content: Final = fields["content"] + if isinstance(content, list): + content_items: Final = _OBJECT_LIST.validate_python(content) + return any( + self._contains_vision_content(item, depth=depth + 1, max_depth=max_depth) for item in content_items + ) return False diff --git a/litellm/llms/gradient_ai/chat/transformation.py b/litellm/llms/gradient_ai/chat/transformation.py index 0ba5ca45c2a..2a2368ad8de 100644 --- a/litellm/llms/gradient_ai/chat/transformation.py +++ b/litellm/llms/gradient_ai/chat/transformation.py @@ -1,3 +1,5 @@ +from collections.abc import Mapping +from types import MappingProxyType from typing import Final, Literal from litellm.litellm_core_utils.url_utils import join_api_base @@ -43,7 +45,7 @@ class GradientAIConfig(OpenAILikeChatConfig): include_guardrails_info: bool | None = None, provide_citations: bool | None = None, ) -> None: - locals_: Final = locals().copy() + locals_: Final[Mapping[str, object]] = MappingProxyType(locals().copy()) for key, value in locals_.items(): if key != "self" and value is not None: setattr(self.__class__, key, value) diff --git a/litellm/llms/groq/chat/transformation.py b/litellm/llms/groq/chat/transformation.py index 8c269cb5dfd..23f68335ea9 100644 --- a/litellm/llms/groq/chat/transformation.py +++ b/litellm/llms/groq/chat/transformation.py @@ -11,7 +11,7 @@ from pydantic import BaseModel, TypeAdapter, ValidationError import litellm from litellm._logging import verbose_logger from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj -from litellm.litellm_core_utils.prompt_templates.common_utils import strip_litellm_response_only_fields +from litellm.litellm_core_utils.prompt_templates.common_utils import strip_litellm_internal_message_fields from litellm.llms.openai.chat.gpt_transformation import ( OpenAIChatCompletionStreamingHandler, ) @@ -40,6 +40,7 @@ class GroqExecutedToolIdentity(LiteLLMBaseModel): _EXECUTED_TOOLS_ADAPTER: Final = TypeAdapter(tuple[GroqExecutedToolIdentity, ...]) +_ATTRIBUTE_VALUE: Final = TypeAdapter(object) class GroqChatConfig(OpenAILikeChatConfig): @@ -153,7 +154,7 @@ class GroqChatConfig(OpenAILikeChatConfig): for k, v in _message.items(): if v is not None: new_message[k] = v - messages[idx] = strip_litellm_response_only_fields(new_message) + messages[idx] = strip_litellm_internal_message_fields(new_message) if is_async: return super()._transform_messages(messages=messages, model=model, is_async=True) @@ -324,7 +325,7 @@ class GroqChatConfig(OpenAILikeChatConfig): json_mode=json_mode, ) - original_service_tier: Final[object] = getattr(model_response, "service_tier") + original_service_tier: Final = _ATTRIBUTE_VALUE.validate_python(getattr(model_response, "service_tier")) mapped_service_tier: Final[Literal["auto", "default", "flex"]] = self._map_groq_service_tier( original_service_tier=original_service_tier ) diff --git a/litellm/llms/groq/cost_calculator.py b/litellm/llms/groq/cost_calculator.py index bcebb347aea..7f75a607410 100644 --- a/litellm/llms/groq/cost_calculator.py +++ b/litellm/llms/groq/cost_calculator.py @@ -19,7 +19,10 @@ if TYPE_CHECKING: def cost_per_web_search_request(usage: Usage, model_info: "ModelInfo") -> float: search_costs: Final = model_info.get("search_context_cost_per_query") cost_per_search: Final = search_costs.get("search_context_size_medium", 0.0) if search_costs else 0.0 - server_tool_use: Final = getattr(usage, "server_tool_use", None) + try: + server_tool_use: Final = usage.server_tool_use + except AttributeError: + return 0.0 if server_tool_use is None: return 0.0 searches: Final = server_tool_use.web_search_requests or 0 diff --git a/litellm/llms/groq/stt/transformation.py b/litellm/llms/groq/stt/transformation.py index 93d36dd7b0f..33e01ab7c0e 100644 --- a/litellm/llms/groq/stt/transformation.py +++ b/litellm/llms/groq/stt/transformation.py @@ -3,6 +3,7 @@ Translate from OpenAI's `/v1/audio/transcriptions` to Groq's `/v1/audio/transcri """ import types +from collections.abc import Mapping from typing import Final import litellm @@ -39,16 +40,17 @@ class GroqSTTConfig: tools: list | None = None, tool_choice: str | dict | None = None, ) -> None: - locals_: Final = locals().copy() + locals_: Final[Mapping[str, object]] = types.MappingProxyType(locals().copy()) for key, value in locals_.items(): if key != "self" and value is not None: setattr(self.__class__, key, value) @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not isinstance( v, diff --git a/litellm/llms/hosted_vllm/decisions/transformation.py b/litellm/llms/hosted_vllm/decisions/transformation.py index ef99f2de173..fab07d2e7db 100644 --- a/litellm/llms/hosted_vllm/decisions/transformation.py +++ b/litellm/llms/hosted_vllm/decisions/transformation.py @@ -9,6 +9,8 @@ class HostedVLLMDecisionsConfig(BaseDecisionsConfig): api_key_env = ("HOSTED_VLLM_API_KEY",) api_base_env = ("HOSTED_VLLM_API_BASE",) api_key_required = False + supports_images = True + inlines_remote_images = True health_check_questions = MappingProxyType( { "reachable": MappingProxyType( diff --git a/litellm/llms/hosted_vllm/rerank/transformation.py b/litellm/llms/hosted_vllm/rerank/transformation.py index 4a5729945b4..0b77a04c69a 100644 --- a/litellm/llms/hosted_vllm/rerank/transformation.py +++ b/litellm/llms/hosted_vllm/rerank/transformation.py @@ -7,7 +7,7 @@ from types import MappingProxyType from typing import Final import httpx -from pydantic import ValidationError +from pydantic import TypeAdapter, ValidationError from litellm._uuid import uuid from litellm.exceptions import UnsupportedParamsError @@ -15,6 +15,7 @@ from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLogging from litellm.litellm_core_utils.url_utils import join_api_base from litellm.llms.base_llm.chat.transformation import BaseLLMException from litellm.llms.base_llm.rerank.transformation import BaseRerankConfig +from litellm.llms.openai.common_utils import decoded_json_object from litellm.secret_managers.main import get_secret_str from litellm.types.rerank import ( HostedVLLMRerankTruncationParams, @@ -28,6 +29,8 @@ from litellm.types.rerank import ( RerankTokens, ) +_DECODED_JSON: Final = TypeAdapter(object) + class HostedVLLMRerankError(BaseLLMException): def __init__( @@ -193,11 +196,11 @@ class HostedVLLMRerankConfig(BaseRerankConfig): Process response from Hosted VLLM rerank API """ try: - raw_response_json: Final = raw_response.json() + raw_response_json: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception: raise ValueError(f"Error parsing response: {raw_response.text}, status_code={raw_response.status_code}") - return self._transform_response(raw_response_json) + return self._transform_response(dict(decoded_json_object(raw_response_json))) def get_error_class(self, error_message: str, status_code: int, headers: dict | httpx.Headers) -> BaseLLMException: return HostedVLLMRerankError(message=error_message, status_code=status_code, headers=headers) diff --git a/litellm/llms/hosted_vllm/videos/transformation.py b/litellm/llms/hosted_vllm/videos/transformation.py index 30ae6835263..2045d2c8988 100644 --- a/litellm/llms/hosted_vllm/videos/transformation.py +++ b/litellm/llms/hosted_vllm/videos/transformation.py @@ -8,6 +8,7 @@ from typing import Final from urllib.parse import urlparse from httpx._types import FileTypes, RequestFiles +from pydantic import TypeAdapter from litellm.images.utils import ImageEditRequestUtils from litellm.litellm_core_utils.url_utils import SSRFError, join_api_base, validate_url @@ -16,6 +17,7 @@ from litellm.secret_managers.main import get_secret_str from litellm.types.router import GenericLiteLLMParams from litellm.types.videos.main import VideoCreateOptionalRequestParams +_DECODED_JSON: Final = TypeAdapter(object) _EXCLUDED_FORM_KEYS: Final = frozenset( { "model", @@ -82,7 +84,7 @@ def _maybe_json(value: object) -> object: stripped: Final = value.strip() if not stripped or stripped[0] not in "{[": return value - return json.loads(stripped) + return _DECODED_JSON.validate_python(json.loads(stripped)) def _reject_unsafe_media_url(url: str) -> None: diff --git a/litellm/llms/huggingface/embedding/handler.py b/litellm/llms/huggingface/embedding/handler.py index 60917c68221..a1d1a3f6a19 100644 --- a/litellm/llms/huggingface/embedding/handler.py +++ b/litellm/llms/huggingface/embedding/handler.py @@ -3,6 +3,7 @@ import os from typing import Final, Literal, Protocol, get_args import httpx +from pydantic import TypeAdapter import litellm from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj @@ -11,6 +12,7 @@ from litellm.llms.custom_httpx.http_handler import ( HTTPHandler, get_async_httpx_client, ) +from litellm.llms.openai.common_utils import decoded_json_object from litellm.types.utils import EmbeddingResponse from ...base import BaseLLM @@ -21,6 +23,8 @@ config: Final = HuggingFaceEmbeddingConfig() HF_HUB_URL: Final = "https://huggingface.co" +_DECODED_JSON: Final = TypeAdapter(object) + hf_tasks_embeddings: Final = ( Literal[ # pipeline tags + hf tei endpoints - https://huggingface.github.io/text-embeddings-inference/#/ "sentence-similarity", "feature-extraction", "rerank", "embed", "similarity" @@ -34,7 +38,7 @@ class _SupportsTokenEncode(Protocol): def encode(self, text: str) -> list[int]: ... -def get_hf_task_embedding_for_model(model: str, task_type: str | None, api_base: str) -> str | None: +def get_hf_task_embedding_for_model(model: str, task_type: str | None, api_base: str) -> object: if task_type is not None: if task_type in get_args(hf_tasks_embeddings): return task_type @@ -44,14 +48,14 @@ def get_hf_task_embedding_for_model(model: str, task_type: str | None, api_base: model_info: Final = http_client.get(url=f"{api_base}/api/models/{model}") - model_info_dict: Final = model_info.json() + model_info_dict: Final = decoded_json_object(_DECODED_JSON.validate_python(model_info.json())) - pipeline_tag: Final[str | None] = model_info_dict.get("pipeline_tag", None) + pipeline_tag: Final = model_info_dict.get("pipeline_tag", None) return pipeline_tag -async def async_get_hf_task_embedding_for_model(model: str, task_type: str | None, api_base: str) -> str | None: +async def async_get_hf_task_embedding_for_model(model: str, task_type: str | None, api_base: str) -> object: if task_type is not None: if task_type in get_args(hf_tasks_embeddings): return task_type @@ -63,9 +67,9 @@ async def async_get_hf_task_embedding_for_model(model: str, task_type: str | Non model_info: Final = await http_client.get(url=f"{api_base}/api/models/{model}") - model_info_dict: Final = model_info.json() + model_info_dict: Final = decoded_json_object(_DECODED_JSON.validate_python(model_info.json())) - pipeline_tag: Final[str | None] = model_info_dict.get("pipeline_tag", None) + pipeline_tag: Final = model_info_dict.get("pipeline_tag", None) return pipeline_tag @@ -77,7 +81,7 @@ class HuggingFaceEmbedding(BaseLLM): def __init__(self) -> None: super().__init__() - def _transform_input_on_pipeline_tag(self, input: list, pipeline_tag: str | None) -> dict: + def _transform_input_on_pipeline_tag(self, input: list, pipeline_tag: object) -> dict: if pipeline_tag is None: return {"inputs": input} if pipeline_tag == "sentence-similarity" or pipeline_tag == "similarity": diff --git a/litellm/llms/huggingface/embedding/transformation.py b/litellm/llms/huggingface/embedding/transformation.py index 0883a9a8077..1b7d6483739 100644 --- a/litellm/llms/huggingface/embedding/transformation.py +++ b/litellm/llms/huggingface/embedding/transformation.py @@ -447,14 +447,13 @@ class HuggingFaceEmbeddingConfig(BaseConfig): except Exception: # this should remain non blocking we should not block a response returning if calculating usage fails pass - output_text: Final = model_response["choices"][0]["message"].get("content", "") + first_message: Final = model_response.choices[0].message + output_text: Final = first_message.content if output_text is not None and len(output_text) > 0: completion_tokens = 0 try: if encoding is not None: - completion_tokens = len( - encoding.encode(model_response["choices"][0]["message"].get("content", "")) - ) ##[TODO] use the llama2 tokenizer here + completion_tokens = len(encoding.encode(output_text)) ##[TODO] use the llama2 tokenizer here except Exception: # this should remain non blocking we should not block a response returning if calculating usage fails pass diff --git a/litellm/llms/huggingface/rerank/transformation.py b/litellm/llms/huggingface/rerank/transformation.py index 1217a2540d4..1f130f84283 100644 --- a/litellm/llms/huggingface/rerank/transformation.py +++ b/litellm/llms/huggingface/rerank/transformation.py @@ -86,7 +86,7 @@ class HuggingFaceRerankConfig(BaseRerankConfig): model: str, drop_params: bool, query: str, - documents: list[str | dict[str, Any]], + documents: list[str | dict[str, object]], custom_llm_provider: str | None = None, top_n: int | None = None, rank_fields: list[str] | None = None, diff --git a/litellm/llms/langflow/chat/transformation.py b/litellm/llms/langflow/chat/transformation.py index 0938cc0d07b..3807be562cf 100644 --- a/litellm/llms/langflow/chat/transformation.py +++ b/litellm/llms/langflow/chat/transformation.py @@ -1,9 +1,11 @@ """LangFlow run API: POST {api_base}/api/v1/run/{flow_id}""" +from collections.abc import Mapping from typing import TYPE_CHECKING, Any, Final from urllib.parse import quote import httpx +from pydantic import TypeAdapter from litellm._logging import verbose_logger from litellm.litellm_core_utils.prompt_templates.common_utils import ( @@ -11,6 +13,7 @@ from litellm.litellm_core_utils.prompt_templates.common_utils import ( ) from litellm.litellm_core_utils.url_utils import join_api_base from litellm.llms.base_llm.chat.transformation import BaseConfig, BaseLLMException +from litellm.llms.openai.common_utils import decoded_json_object from litellm.types.llms.openai import AllMessageValues from litellm.types.utils import Choices, Message, ModelResponse, Usage @@ -27,6 +30,8 @@ else: AsyncHTTPHandler = Any CustomStreamWrapper = Any +_DECODED_JSON: Final = TypeAdapter(object) + class LangFlowError(BaseLLMException): """Exception class for LangFlow API errors.""" @@ -179,7 +184,7 @@ class LangFlowConfig(BaseConfig): verbose_logger.debug("LangFlow request payload: %s", payload) return payload - def _extract_content_from_response(self, response_json: dict) -> str | None: + def _extract_content_from_response(self, response_json: Mapping[str, object]) -> str | None: """ Extract the assistant text from a LangFlow run response. @@ -236,7 +241,7 @@ class LangFlowConfig(BaseConfig): json_mode: bool | None = None, ) -> ModelResponse: try: - response_json: Final = raw_response.json() + response_json: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception as e: raise LangFlowError( message=f"LangFlow returned a non-JSON response: {e}", @@ -245,7 +250,7 @@ class LangFlowConfig(BaseConfig): verbose_logger.debug("LangFlow response: %s", response_json) - content: Final = self._extract_content_from_response(response_json) + content: Final = self._extract_content_from_response(decoded_json_object(response_json)) if content is None: raise LangFlowError( message=( diff --git a/litellm/llms/langgraph/chat/sse_iterator.py b/litellm/llms/langgraph/chat/sse_iterator.py index 499cbab3b7b..575820bceee 100644 --- a/litellm/llms/langgraph/chat/sse_iterator.py +++ b/litellm/llms/langgraph/chat/sse_iterator.py @@ -9,10 +9,13 @@ import uuid from typing import Final import httpx +from pydantic import TypeAdapter from litellm._logging import verbose_logger from litellm.types.utils import Delta, ModelResponseStream, StreamingChoices +_DECODED_JSON: Final = TypeAdapter(object) + class LangGraphSSEStreamIterator: """ @@ -60,7 +63,7 @@ class LangGraphSSEStreamIterator: return None try: - data: Final = json.loads(json_str) + data: Final = _DECODED_JSON.validate_python(json.loads(json_str)) return self._process_data(data) except json.JSONDecodeError: verbose_logger.debug("Skipping non-JSON SSE line: %s", line[:100]) diff --git a/litellm/llms/langgraph/chat/transformation.py b/litellm/llms/langgraph/chat/transformation.py index ce624eecc0e..603d5a07292 100644 --- a/litellm/llms/langgraph/chat/transformation.py +++ b/litellm/llms/langgraph/chat/transformation.py @@ -13,6 +13,7 @@ from collections.abc import Mapping from typing import TYPE_CHECKING, Any, Final, Optional, Union import httpx +from pydantic import TypeAdapter from litellm._logging import verbose_logger from litellm.litellm_core_utils.prompt_templates.common_utils import ( @@ -21,6 +22,7 @@ from litellm.litellm_core_utils.prompt_templates.common_utils import ( from litellm.litellm_core_utils.url_utils import join_api_base from litellm.llms.base_llm.chat.transformation import BaseConfig, BaseLLMException from litellm.llms.langgraph.chat.sse_iterator import LangGraphSSEStreamIterator +from litellm.llms.openai.common_utils import decoded_json_object from litellm.types.llms.openai import AllMessageValues from litellm.types.utils import Choices, Message, ModelResponse, Usage @@ -37,6 +39,8 @@ else: AsyncHTTPHandler = Any CustomStreamWrapper = Any +_DECODED_JSON: Final = TypeAdapter(object) + class LangGraphError(BaseLLMException): """Exception class for LangGraph API errors.""" @@ -233,7 +237,7 @@ class LangGraphConfig(BaseConfig): verbose_logger.debug("LangGraph request payload: %s", payload) return payload - def _extract_content_from_response(self, response_json: dict) -> str: + def _extract_content_from_response(self, response_json: Mapping[str, object]) -> str: """ Extract content from LangGraph non-streaming response. @@ -434,10 +438,10 @@ class LangGraphConfig(BaseConfig): Transform the LangGraph response to LiteLLM ModelResponse format. """ try: - response_json: Final = raw_response.json() + response_json: Final = _DECODED_JSON.validate_python(raw_response.json()) verbose_logger.debug("LangGraph response: %s", response_json) - content: Final = self._extract_content_from_response(response_json) + content: Final = self._extract_content_from_response(decoded_json_object(response_json)) # Create the message message: Final = Message(content=content, role="assistant") diff --git a/litellm/llms/lemonade/chat/transformation.py b/litellm/llms/lemonade/chat/transformation.py index 01fdc0b8bf8..42bd63b0160 100644 --- a/litellm/llms/lemonade/chat/transformation.py +++ b/litellm/llms/lemonade/chat/transformation.py @@ -3,7 +3,7 @@ Translate from OpenAI's `/v1/chat/completions` to Lemonade's `/v1/chat/completio """ from collections.abc import Iterable, Mapping -from typing import TYPE_CHECKING, Any, Final, Protocol +from typing import TYPE_CHECKING, Final, Protocol from urllib.parse import quote import httpx @@ -27,6 +27,7 @@ if TYPE_CHECKING: _JSON_DICT: Final = TypeAdapter(dict[str, object], config=ConfigDict(hide_input_in_errors=True)) _JSON_OBJECTS: Final = TypeAdapter(Iterable[Mapping[str, object]], config=ConfigDict(hide_input_in_errors=True)) _STR: Final = TypeAdapter(str) +_OPAQUE_VALUE: Final = TypeAdapter(object) class _JsonResponse(Protocol): @@ -123,7 +124,7 @@ class LemonadeChatConfig(OpenAILikeChatConfig): return ["lemonade/" + _STR.validate_python(model["id"]) for model in model_list] @staticmethod - def _get_positive_int(value: Any) -> int | None: + def _get_positive_int(value: object) -> int | None: if isinstance(value, bool): return None if isinstance(value, int) and value > 0: @@ -163,7 +164,7 @@ class LemonadeChatConfig(OpenAILikeChatConfig): provider_specific_entry.get("context_window"), provider_specific_entry.get("max_context_window"), ): - parsed = self._get_positive_int(value) + parsed = self._get_positive_int(_OPAQUE_VALUE.validate_python(value)) if parsed is not None: return parsed return None diff --git a/litellm/llms/litellm_proxy/skills/prompt_injection.py b/litellm/llms/litellm_proxy/skills/prompt_injection.py index 3377338a03e..e8e1c68a112 100644 --- a/litellm/llms/litellm_proxy/skills/prompt_injection.py +++ b/litellm/llms/litellm_proxy/skills/prompt_injection.py @@ -9,9 +9,10 @@ import posixpath import zipfile from collections.abc import Mapping from io import BytesIO -from typing import Any, Final +from typing import Final from litellm._logging import verbose_logger +from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.models.skills import LiteLLM_SkillsTable @@ -251,27 +252,30 @@ class SkillPromptInjectionHandler: if len(description) > max_desc_length: description = description[: max_desc_length - 3] + "..." - tool: Final[dict[str, Any]] = { + params: Final = ( + as_str_mapping(skill.metadata.get("parameters")) + if skill.metadata and isinstance(skill.metadata, dict) + else None + ) + parameters: Final[Mapping[str, object]] = ( + params + if params and isinstance(params, dict) + else { + "type": "object", + "properties": {}, + "required": [], + } + ) + + return { "type": "function", "function": { "name": func_name, "description": description, - "parameters": { - "type": "object", - "properties": {}, - "required": [], - }, + "parameters": parameters, }, } - # If skill has metadata with parameter definitions, use them - if skill.metadata and isinstance(skill.metadata, dict): - params: Final = skill.metadata.get("parameters") - if params and isinstance(params, dict): - tool["function"]["parameters"] = params - - return tool - def convert_skill_to_anthropic_tool(self, skill: LiteLLM_SkillsTable) -> Mapping[str, object]: """ Convert a LiteLLM skill to an Anthropic-style tool (messages API format). diff --git a/litellm/llms/litellm_proxy/skills/sandbox_executor.py b/litellm/llms/litellm_proxy/skills/sandbox_executor.py index 3e38dd81905..8e5c9effa17 100644 --- a/litellm/llms/litellm_proxy/skills/sandbox_executor.py +++ b/litellm/llms/litellm_proxy/skills/sandbox_executor.py @@ -7,7 +7,8 @@ Supports Docker, Podman, and Kubernetes backends. import base64 import os -from typing import Any, Final, Protocol, TypedDict +from collections.abc import Sequence +from typing import Final, Protocol, TypedDict from typing_extensions import ReadOnly @@ -41,6 +42,13 @@ class _GeneratedFile(TypedDict): mime_type: ReadOnly[str] +class _SandboxExecution(TypedDict): + success: ReadOnly[bool] + output: ReadOnly[str] + error: ReadOnly[str] + files: ReadOnly[Sequence[_GeneratedFile]] + + class SkillsSandboxExecutor: """ Executes skill code in llm-sandbox Docker container. @@ -76,7 +84,7 @@ class SkillsSandboxExecutor: code: str, skill_files: dict[str, bytes], requirements: str | None = None, - ) -> dict[str, Any]: + ) -> _SandboxExecution: """ Execute code with skill files in sandbox. diff --git a/litellm/llms/lm_studio/decisions/transformation.py b/litellm/llms/lm_studio/decisions/transformation.py new file mode 100644 index 00000000000..84e5ff14443 --- /dev/null +++ b/litellm/llms/lm_studio/decisions/transformation.py @@ -0,0 +1,16 @@ +from typing import Final + +from litellm.constants import PLACEHOLDER_API_KEY +from litellm.llms.base_llm.decisions.transformation import BaseDecisionsConfig + + +class LMStudioDecisionsConfig(BaseDecisionsConfig): + api_key_env = ("LM_STUDIO_API_KEY",) + api_base_env = ("LM_STUDIO_API_BASE",) + api_key_required = False + supports_images = True + inlines_remote_images = True + + def resolve_api_key(self, api_key: str | None) -> str | None: + resolved: Final = super().resolve_api_key(api_key) + return None if resolved == PLACEHOLDER_API_KEY else resolved diff --git a/litellm/llms/lm_studio/embed/transformation.py b/litellm/llms/lm_studio/embed/transformation.py index 66b2dbb534d..d6264ceb6e0 100644 --- a/litellm/llms/lm_studio/embed/transformation.py +++ b/litellm/llms/lm_studio/embed/transformation.py @@ -7,6 +7,7 @@ Docs - https://lmstudio.ai/docs/basics/server """ import types +from collections.abc import Mapping from typing import Final @@ -18,16 +19,17 @@ class LmStudioEmbeddingConfig: def __init__( self, ) -> None: - locals_: Final = locals().copy() + locals_: Final[Mapping[str, object]] = types.MappingProxyType(locals().copy()) for key, value in locals_.items(): if key != "self" and value is not None: setattr(self.__class__, key, value) @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not isinstance( v, diff --git a/litellm/llms/maritalk.py b/litellm/llms/maritalk.py index 094dee4cee1..36bde5847fb 100644 --- a/litellm/llms/maritalk.py +++ b/litellm/llms/maritalk.py @@ -1,3 +1,4 @@ +from collections.abc import Mapping from typing import Final from httpx._models import Headers @@ -32,7 +33,7 @@ class MaritalkConfig(OpenAIGPTConfig): tools: list[dict] | None = None, tool_choice: str | dict | None = None, ) -> None: - locals_: Final = locals().copy() + locals_: Final[Mapping[str, object]] = dict(locals()) for key, value in locals_.items(): if key != "self" and value is not None: setattr(self.__class__, key, value) diff --git a/litellm/llms/milvus/vector_stores/transformation.py b/litellm/llms/milvus/vector_stores/transformation.py index 67de3a06af8..14470922e57 100644 --- a/litellm/llms/milvus/vector_stores/transformation.py +++ b/litellm/llms/milvus/vector_stores/transformation.py @@ -4,12 +4,14 @@ from collections.abc import Mapping, Sequence from typing import TYPE_CHECKING, Any, Final import httpx +from pydantic import TypeAdapter from litellm.litellm_core_utils.url_utils import join_api_base from litellm.llms.base_llm.vector_store.transformation import ( BaseQueryEmbeddingVectorStoreConfig, VectorStoreEmbeddingExecutor, ) +from litellm.llms.openai.common_utils import decoded_json_object from litellm.secret_managers.main import get_secret_str from litellm.types.router import GenericLiteLLMParams from litellm.types.vector_stores import ( @@ -30,6 +32,8 @@ if TYPE_CHECKING: else: LiteLLMLoggingObj = Any +_DECODED_JSON: Final = TypeAdapter(object) + MILVUS_OPTIONAL_PARAMS: Final = { "annsField", "limit", @@ -218,15 +222,17 @@ class MilvusVectorStoreConfig(BaseQueryEmbeddingVectorStoreConfig): results: Final = response_json.get("data", []) # Try to get text_field from optional_params first, then litellm_params - optional_params: Final = litellm_logging_obj.model_call_details.get("optional_params", {}) + optional_params: Final = decoded_json_object( + _DECODED_JSON.validate_python(litellm_logging_obj.model_call_details.get("optional_params", {})) + ) text_field = optional_params.get("milvus_text_field", "") # Fallback to litellm_params if not in optional_params if not text_field: - text_field = litellm_logging_obj.model_call_details.get("litellm_params", {}).get( - "milvus_text_field", "" - ) + text_field = decoded_json_object( + _DECODED_JSON.validate_python(litellm_logging_obj.model_call_details.get("litellm_params", {})) + ).get("milvus_text_field", "") # Transform results to standard format search_results: Final[list[VectorStoreSearchResult]] = [] diff --git a/litellm/llms/minimax/messages/transformation.py b/litellm/llms/minimax/messages/transformation.py index f9f3502237c..f546d2d3a16 100644 --- a/litellm/llms/minimax/messages/transformation.py +++ b/litellm/llms/minimax/messages/transformation.py @@ -2,11 +2,9 @@ MiniMax Anthropic transformation config - extends AnthropicConfig for MiniMax's Anthropic-compatible API """ -from typing import Any # noqa: TID251 # override below must mirror the legacy base signature - import litellm from litellm.litellm_core_utils.url_utils import ensure_api_route -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) from litellm.secret_managers.main import get_secret_str @@ -54,7 +52,7 @@ class MinimaxMessagesConfig(AnthropicMessagesConfig): self, headers: dict, # mutable-ok: mirrors the legacy base override signature model: str, - messages: list[Any], # mutable-ok: mirrors the legacy base override signature + messages: list[object], # mutable-ok: mirrors the legacy base override signature optional_params: dict, # mutable-ok: mirrors the legacy base override signature litellm_params: dict, # mutable-ok: mirrors the legacy base override signature api_key: str | None = None, diff --git a/litellm/llms/modelscope/image_generation/transformation.py b/litellm/llms/modelscope/image_generation/transformation.py index 36c8705f256..c308de92d1d 100644 --- a/litellm/llms/modelscope/image_generation/transformation.py +++ b/litellm/llms/modelscope/image_generation/transformation.py @@ -33,6 +33,7 @@ else: LiteLLMLoggingObj = object _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_input_in_errors=True)) +_DECODED_JSON: Final = TypeAdapter(object) _JSON_OBJECTS: Final = TypeAdapter(Iterable[Mapping[str, object]], config=ConfigDict(hide_input_in_errors=True)) @@ -173,7 +174,7 @@ class ModelScopeImageGenerationConfig(BaseImageGenerationConfig): {"created": timestamp, "data": [{"url": "..."}]} """ try: - response_data: Final = raw_response.json() + response_data: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception as e: raise self.get_error_class( error_message=f"Error parsing ModelScope response: {e}", diff --git a/litellm/llms/nadir/chat/transformation.py b/litellm/llms/nadir/chat/transformation.py index d22b1a51bab..c8bde7d9fad 100644 --- a/litellm/llms/nadir/chat/transformation.py +++ b/litellm/llms/nadir/chat/transformation.py @@ -2,8 +2,9 @@ import math from typing import Final import httpx +from pydantic import TypeAdapter -from litellm.litellm_core_utils.core_helpers import set_response_cost_in_hidden_params +from litellm.litellm_core_utils.core_helpers import as_str_mapping, set_response_cost_in_hidden_params from litellm.llms.openai.chat.gpt_transformation import OpenAIGPTConfig from litellm.types.llms.openai import AllMessageValues from litellm.types.utils import ModelResponse @@ -19,13 +20,17 @@ _SUPPORTED_OPENAI_PARAMS: Final = ( "temperature", "top_p", ) +_DECODED_JSON: Final = TypeAdapter(object) def _reported_cost_usd(raw_response: httpx.Response) -> float | None: try: - cost: Final = raw_response.json()["nadir_metadata"]["cost"]["total_cost_usd"] + body: Final = as_str_mapping(_DECODED_JSON.validate_python(raw_response.json())) except (ValueError, KeyError, TypeError): return None + metadata: Final = as_str_mapping(body.get("nadir_metadata")) if body is not None else None + cost_block: Final = as_str_mapping(metadata.get("cost")) if metadata is not None else None + cost: Final = cost_block.get("total_cost_usd") if cost_block is not None else None if isinstance(cost, bool) or not isinstance(cost, (int, float)): return None if not math.isfinite(cost) or cost < 0: diff --git a/litellm/llms/nvidia_nim/embed.py b/litellm/llms/nvidia_nim/embed.py index 5a0105a3776..d2ef446299e 100644 --- a/litellm/llms/nvidia_nim/embed.py +++ b/litellm/llms/nvidia_nim/embed.py @@ -9,6 +9,7 @@ API calling is done using the OpenAI SDK with an api_base """ import types +from collections.abc import Mapping from typing import Final @@ -32,16 +33,17 @@ class NvidiaNimEmbeddingConfig: input_type: str | None = None, truncate: str | None = None, ) -> None: - locals_: Final = locals().copy() + locals_: Final[Mapping[str, object]] = types.MappingProxyType(locals().copy()) for key, value in locals_.items(): if key != "self" and value is not None: setattr(self.__class__, key, value) @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not isinstance( v, diff --git a/litellm/llms/nvidia_riva/audio_transcription/handler.py b/litellm/llms/nvidia_riva/audio_transcription/handler.py index 748203b22d9..cafeece0a4e 100644 --- a/litellm/llms/nvidia_riva/audio_transcription/handler.py +++ b/litellm/llms/nvidia_riva/audio_transcription/handler.py @@ -28,7 +28,7 @@ without the optional STT extras installed. import asyncio import inspect -from collections.abc import Callable, Iterable, Mapping +from collections.abc import Callable, Iterable, Mapping, Sequence from types import MappingProxyType from typing import TYPE_CHECKING, Any, Final, Protocol @@ -48,6 +48,8 @@ from litellm.llms.nvidia_riva.audio_transcription.transformation import ( RIVA_TARGET_NUM_CHANNELS, RIVA_TARGET_SAMPLE_RATE_HZ, NvidiaRivaAudioTranscriptionConfig, + RivaFinalResult, + RivaWordTiming, ) from litellm.llms.nvidia_riva.common_utils import ( NvidiaRivaException, @@ -535,14 +537,14 @@ class NvidiaRivaAudioTranscription: yield chunk @staticmethod - def _collect_final_results(stream: Iterable[object], require_final: bool = True) -> list[dict[str, object]]: + def _collect_final_results(stream: Iterable[object], require_final: bool = True) -> Sequence[RivaFinalResult]: """ Walk the gRPC responses, ignore empty / non-final chunks, and return a list of normalized final-result dicts. Matching the user's note: the ``id`` blocks with no ``results`` are streaming heartbeats and must be skipped. """ - final_results: Final[list[dict[str, object]]] = [] + final_results: Final[list[RivaFinalResult]] = [] for response in stream: results = getattr(response, "results", None) or [] for result in results: @@ -554,16 +556,19 @@ class NvidiaRivaAudioTranscription: top = alternatives[0] transcript = getattr(top, "transcript", "") or "" words_proto = getattr(top, "words", None) or [] - words = [] - for word in words_proto: - words.append( - { - "word": getattr(word, "word", ""), - "start_time_ms": int(getattr(word, "start_time", 0) or 0), - "end_time_ms": int(getattr(word, "end_time", 0) or 0), - } - ) - final_results.append({"transcript": transcript, "words": words}) + final_results.append( + { + "transcript": transcript, + "words": [ + RivaWordTiming( + word=getattr(word, "word", ""), + start_time_ms=int(getattr(word, "start_time", 0) or 0), + end_time_ms=int(getattr(word, "end_time", 0) or 0), + ) + for word in words_proto + ], + } + ) return final_results diff --git a/litellm/llms/nvidia_riva/audio_transcription/transformation.py b/litellm/llms/nvidia_riva/audio_transcription/transformation.py index 262dfb7bd78..5862a5d10b1 100644 --- a/litellm/llms/nvidia_riva/audio_transcription/transformation.py +++ b/litellm/llms/nvidia_riva/audio_transcription/transformation.py @@ -11,9 +11,11 @@ dict at call time. Reference: https://docs.nvidia.com/deeplearning/riva/user-guide/docs/asr/asr-overview.html """ -from typing import Any, Final +from collections.abc import Sequence +from typing import Final, TypedDict from httpx import Headers, Response +from typing_extensions import ReadOnly from litellm.llms.base_llm.chat.transformation import BaseLLMException from litellm.types.llms.openai import ( @@ -34,6 +36,17 @@ RIVA_TARGET_NUM_CHANNELS: Final = 1 RIVA_TARGET_ENCODING: Final = "LINEAR_PCM" +class RivaWordTiming(TypedDict): + word: ReadOnly[str] + start_time_ms: ReadOnly[int] + end_time_ms: ReadOnly[int] + + +class RivaFinalResult(TypedDict): + transcript: ReadOnly[str] + words: ReadOnly[Sequence[RivaWordTiming]] + + class NvidiaRivaAudioTranscriptionConfig(BaseAudioTranscriptionConfig): """ Config for NVIDIA Riva ASR (gRPC). @@ -219,7 +232,7 @@ class NvidiaRivaAudioTranscriptionConfig(BaseAudioTranscriptionConfig): @staticmethod def build_transcription_response( - final_results: list[dict[str, Any]], + final_results: Sequence[RivaFinalResult], response_format: str, duration_seconds: float | None, timestamp_granularities: list[str] | None, diff --git a/litellm/llms/oci/chat/transformation.py b/litellm/llms/oci/chat/transformation.py index 8e1502b2610..e8d37f857e6 100644 --- a/litellm/llms/oci/chat/transformation.py +++ b/litellm/llms/oci/chat/transformation.py @@ -189,6 +189,7 @@ def _normalize_tool_choice(selected_params: dict) -> None: _TOOL_CHOICE_MODES: Final = frozenset({"auto", "none", "required", "any"}) _TOOLS_ADAPTER: Final = TypeAdapter(list[dict[str, object]]) _JSON_OBJECT_ADAPTER: Final = TypeAdapter(dict[str, object]) +_DECODED_JSON: Final = TypeAdapter(object) def _as_json_object(value: object) -> Mapping[str, object] | None: @@ -701,7 +702,7 @@ class OCIChatConfig(BaseConfig): api_key: str | None = None, json_mode: bool | None = None, ) -> ModelResponse: - response_json: Final = raw_response.json() + response_json: Final = _DECODED_JSON.validate_python(raw_response.json()) if not isinstance(response_json, dict): raise OCIError( diff --git a/litellm/llms/oci/embed/transformation.py b/litellm/llms/oci/embed/transformation.py index ffcb156bb16..6dee64bf19a 100644 --- a/litellm/llms/oci/embed/transformation.py +++ b/litellm/llms/oci/embed/transformation.py @@ -56,6 +56,7 @@ else: LiteLLMLoggingObj = Any _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_input_in_errors=True)) +_DECODED_JSON: Final = TypeAdapter(object) # OCI sends up to 96 texts per embedText request (Cohere limit). OCI_EMBED_BATCH_LIMIT: Final = 96 @@ -272,7 +273,7 @@ class OCIEmbedConfig(BaseEmbeddingConfig): ) try: - json_response: Final = raw_response.json() + json_response: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception as e: raise OCIError( status_code=raw_response.status_code, diff --git a/litellm/llms/ollama/common_utils.py b/litellm/llms/ollama/common_utils.py index 7894904c870..f313c62f026 100644 --- a/litellm/llms/ollama/common_utils.py +++ b/litellm/llms/ollama/common_utils.py @@ -13,6 +13,7 @@ from litellm.llms.base_llm.chat.transformation import BaseLLMException from litellm.types.utils import ModelResponse, ModelResponseStream _PROVIDER_FIELDS: Final = TypeAdapter(dict[str, object]) +_DECODED_JSON: Final = TypeAdapter(object) class OllamaResponseIdNormalizer: @@ -152,7 +153,7 @@ class OllamaModelInfo(BaseLLMModelInfo): try: resp: Final = httpx.get(join_api_base(base, "api/tags"), headers=headers) resp.raise_for_status() - data: Final = resp.json() + data: Final = _DECODED_JSON.validate_python(resp.json()) # Expecting a dict with a 'models' list models_list = [] if isinstance(data, dict) and "models" in data and isinstance(data["models"], list): diff --git a/litellm/llms/ollama/completion/transformation.py b/litellm/llms/ollama/completion/transformation.py index 30de22b17ff..239b4e32645 100644 --- a/litellm/llms/ollama/completion/transformation.py +++ b/litellm/llms/ollama/completion/transformation.py @@ -547,7 +547,7 @@ class OllamaTextCompletionResponseIterator(BaseModelResponseIterator): held: Final = self.held_content self.held_content = "" try: - parsed: Final[object] = json.loads(_strip_json_code_fence(held)) + parsed: Final = _JSON_VALUE.validate_python(json.loads(_strip_json_code_fence(held))) except json.JSONDecodeError: return GenericStreamingChunk(text=held, is_finished=True, finish_reason="stop", usage=usage) if isinstance(parsed, dict) and "name" in parsed and "arguments" in parsed: diff --git a/litellm/llms/openai/chat/gpt_5_transformation.py b/litellm/llms/openai/chat/gpt_reasoning_transformation.py similarity index 100% rename from litellm/llms/openai/chat/gpt_5_transformation.py rename to litellm/llms/openai/chat/gpt_reasoning_transformation.py diff --git a/litellm/llms/openai/common_utils.py b/litellm/llms/openai/common_utils.py index e472661efb9..12ead582975 100644 --- a/litellm/llms/openai/common_utils.py +++ b/litellm/llms/openai/common_utils.py @@ -23,13 +23,14 @@ from openai.types.chat.chat_completion import Choice from openai.types.chat.chat_completion_chunk import Choice as ChunkChoice from openai.types.chat.chat_completion_chunk import ChoiceDelta from openai.types.completion_usage import CompletionUsage -from pydantic import BaseModel +from pydantic import BaseModel, TypeAdapter if TYPE_CHECKING: from aiohttp import ClientSession import litellm from litellm.litellm_core_utils.completion_timeout import CompletionTimeout +from litellm.litellm_core_utils.core_helpers import as_str_mapping, decoded_json_object from litellm.litellm_core_utils.token_counter import token_counter from litellm.llms.base_llm.chat.transformation import BaseLLMException from litellm.llms.custom_httpx.http_handler import ( @@ -134,6 +135,9 @@ class OpenAIError(BaseLLMException): ) +_DECODED_JSON: Final = TypeAdapter(object) + + ####### Error Handling Utils for OpenAI API ####################### ################################################################### def drop_params_from_unprocessable_entity_error( @@ -152,19 +156,20 @@ def drop_params_from_unprocessable_entity_error( """ invalid_params: Final[list[str]] = [] if isinstance(e, httpx.HTTPStatusError): - error_json: Final = e.response.json() + error_json: Final = decoded_json_object(_DECODED_JSON.validate_python(e.response.json())) error_message: Final = error_json.get("error", {}) error_body = error_message else: error_body = e.body - if error_body is not None and isinstance(error_body, dict) and error_body.get("message"): - message = error_body.get("message", {}) + error_mapping: Final = as_str_mapping(error_body) + if isinstance(error_mapping, dict) and error_mapping.get("message"): + message = error_mapping.get("message", {}) if isinstance(message, str): try: - message = json.loads(message) + message = _DECODED_JSON.validate_python(json.loads(message)) except json.JSONDecodeError: message = {"detail": message} - detail: Final = message.get("detail") + detail: Final = decoded_json_object(message).get("detail") if isinstance(detail, list) and len(detail) > 0 and isinstance(detail[0], dict): for error_dict in detail: diff --git a/litellm/llms/openai/decisions/transformation.py b/litellm/llms/openai/decisions/transformation.py index 56f348881de..4518fe6a77e 100644 --- a/litellm/llms/openai/decisions/transformation.py +++ b/litellm/llms/openai/decisions/transformation.py @@ -270,10 +270,9 @@ def _openai_choice_answer(question: DecisionsIRChoiceQuestion, answer: Decisions name=question.name, choice=answer.choice, probabilities=tuple( - OpenAIChoiceProbability( - value=option.value, probability=probabilities.get(systemone_choice_key(option.value), 0.0) - ) + OpenAIChoiceProbability(value=option.value, probability=probabilities[systemone_choice_key(option.value)]) for option in question.choices + if systemone_choice_key(option.value) in probabilities ), confidence=answer.confidence, ) @@ -285,10 +284,9 @@ def _openai_score_answer(question: DecisionsIRScoreQuestion, answer: DecisionsIR name=question.name, score=answer.score, probabilities=tuple( - OpenAIScoreProbability( - value=index, label=decisions_text(level.label), probability=probabilities.get(index, 0.0) - ) + OpenAIScoreProbability(value=index, label=decisions_text(level.label), probability=probabilities[index]) for index, level in enumerate(question.levels) + if index in probabilities ), confidence=answer.confidence, ) @@ -311,6 +309,7 @@ def _openai_answer(question: DecisionsIRQuestion, answer: DecisionsIRAnswer) -> def ir_to_openai_response( response: DecisionsIRResponse, request: DecisionsIRRequest, requested_model: str ) -> OpenAIDecisionResponse: + usage: Final = response.usage or DecisionsIRUsage() return OpenAIDecisionResponse( model=response.model or requested_model, answers=tuple( @@ -318,14 +317,14 @@ def ir_to_openai_response( for question, answer in zip(request.questions, response.answers, strict=True) ), usage=OpenAIDecisionUsage( - input_tokens=response.usage.input_tokens, + input_tokens=usage.input_tokens, input_tokens_details=OpenAIDecisionInputTokensDetails( - cached_tokens=response.usage.cached_tokens, - cache_write_tokens=response.usage.cache_write_tokens, + cached_tokens=usage.cached_tokens, + cache_write_tokens=usage.cache_write_tokens, ), - output_tokens=response.usage.output_tokens, - output_tokens_details=OpenAIDecisionOutputTokensDetails(reasoning_tokens=response.usage.reasoning_tokens), - total_tokens=response.usage.input_tokens + response.usage.output_tokens, + output_tokens=usage.output_tokens, + output_tokens_details=OpenAIDecisionOutputTokensDetails(reasoning_tokens=usage.reasoning_tokens), + total_tokens=usage.input_tokens + usage.output_tokens, ), ) diff --git a/litellm/llms/openai/evals/transformation.py b/litellm/llms/openai/evals/transformation.py index 581e5e8ad87..73d211e1613 100644 --- a/litellm/llms/openai/evals/transformation.py +++ b/litellm/llms/openai/evals/transformation.py @@ -2,10 +2,10 @@ OpenAI Evals API configuration and transformations """ -from collections.abc import Mapping from typing import Final import httpx +from pydantic import TypeAdapter from litellm._logging import verbose_logger from litellm.litellm_core_utils.url_utils import encode_url_path_segment, join_api_base @@ -32,9 +32,11 @@ from litellm.types.llms.openai_evals import ( from litellm.types.router import GenericLiteLLMParams from litellm.types.utils import LlmProviders +_DECODED_JSON: Final = TypeAdapter(object) -def _parsed_response_json(raw_response: httpx.Response) -> Mapping[str, object]: - return raw_response.json() + +def _parsed_response_json(raw_response: httpx.Response) -> object: + return _DECODED_JSON.validate_python(raw_response.json()) class OpenAIEvalsConfig(BaseEvalsAPIConfig): diff --git a/litellm/llms/openai/openai.py b/litellm/llms/openai/openai.py index 73f40f5e0e4..9d4df354a30 100644 --- a/litellm/llms/openai/openai.py +++ b/litellm/llms/openai/openai.py @@ -48,7 +48,7 @@ from litellm.utils import ( from ...types.llms.openai import * from ..base import BaseLLM -from .chat.gpt_5_transformation import OpenAIGPT5Config +from .chat.gpt_reasoning_transformation import OpenAIGPT5Config from .chat.gpt_transformation import OpenAIGPTConfig, OpenAIUnknownModelConfig from .chat.o_series_transformation import OpenAIOSeriesConfig from .common_utils import ( diff --git a/litellm/llms/openai/responses/count_tokens/token_counter.py b/litellm/llms/openai/responses/count_tokens/token_counter.py index 437f19a4dc6..6ae61e15953 100644 --- a/litellm/llms/openai/responses/count_tokens/token_counter.py +++ b/litellm/llms/openai/responses/count_tokens/token_counter.py @@ -15,12 +15,12 @@ from litellm._logging import verbose_logger from litellm.litellm_core_utils.asyncify import asyncify from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.litellm_core_utils.tool_fields import DropPolicy -from litellm.llms.anthropic.pass_through.convertible_blocks import deployment_drops_params, unconvertible_blocks_error -from litellm.llms.anthropic.pass_through.responses_adapters.transformation import ( +from litellm.llms.anthropic.messages.convertible_blocks import deployment_drops_params, unconvertible_blocks_error +from litellm.llms.anthropic.messages.responses_adapters.transformation import ( LiteLLMAnthropicToResponsesAPIAdapter, ) from litellm.llms.base_llm.base_utils import BaseTokenCounter -from litellm.llms.openai.common_utils import OpenAIError, get_openai_credentials +from litellm.llms.openai.common_utils import OpenAIError, decoded_json_object, get_openai_credentials from litellm.llms.openai.responses.count_tokens.handler import ( OpenAICountTokensHandler, ) @@ -244,7 +244,7 @@ class OpenAITokenCounter(BaseTokenCounter): if result is not None: return TokenCountResponse.model_validate( { - "total_tokens": result.get("input_tokens", 0), + "total_tokens": decoded_json_object(result).get("input_tokens", 0), "request_model": request_model, "model_used": model_to_use, "tokenizer_type": "openai_api", diff --git a/litellm/llms/openai/responses/count_tokens/transformation.py b/litellm/llms/openai/responses/count_tokens/transformation.py index c1ee42444c5..b4e152ff406 100644 --- a/litellm/llms/openai/responses/count_tokens/transformation.py +++ b/litellm/llms/openai/responses/count_tokens/transformation.py @@ -6,17 +6,18 @@ This module handles the transformation of requests to OpenAI's /v1/responses/inp import copy from collections.abc import Mapping, Sequence -from typing import Any, Final, Literal, TypeAlias +from typing import Final, Literal, Protocol, TypeAlias from openai.types.responses.input_token_count_params import InputTokenCountParams from pydantic import JsonValue, TypeAdapter, ValidationError from typing_extensions import ReadOnly, TypedDict +from litellm.litellm_core_utils.core_helpers import iter_items, require_attributes from litellm.litellm_core_utils.tool_fields import DropPolicy from litellm.litellm_core_utils.url_utils import join_api_base -from litellm.llms.anthropic.pass_through.convertible_blocks import malformed_tool_result_text_error -from litellm.llms.anthropic.pass_through.messages.utils import normalize_native_messages -from litellm.llms.anthropic.pass_through.responses_adapters.transformation import ( +from litellm.llms.anthropic.messages.convertible_blocks import malformed_tool_result_text_error +from litellm.llms.anthropic.messages.native.utils import normalize_native_messages +from litellm.llms.anthropic.messages.responses_adapters.transformation import ( LiteLLMAnthropicToResponsesAPIAdapter, ) from litellm.responses.utils import ResponsesAPIRequestUtils @@ -61,6 +62,26 @@ class _AnthropicCountMessage(TypedDict): _ANTHROPIC_COUNT_MESSAGES: Final = TypeAdapter(tuple[_AnthropicCountMessage, ...]) + + +class _FieldReader(Protocol): + def get(self, key: str, default: object = None, /) -> object: ... + + +class _FunctionFields(_FieldReader, Protocol): + def __contains__(self, key: object, /) -> bool: ... + + def __getitem__(self, key: str, /) -> object: ... + + +def _field_reader(value: object) -> _FieldReader: + return require_attributes(value, _FieldReader, "get") + + +def _function_fields(value: object) -> _FunctionFields: + return require_attributes(value, _FunctionFields, "get", "__contains__", "__getitem__") + + _ANTHROPIC_OUTPUT_SCHEMA: Final = TypeAdapter(AnthropicOutputSchema) @@ -196,7 +217,7 @@ class OpenAICountTokensConfig: @staticmethod def _transform_tools_for_responses_api( - tools: list[dict[str, Any]], + tools: list[dict[str, object]], ) -> list[dict[str, object]]: """ Transform OpenAI chat and Anthropic tools to Responses API tools format. @@ -208,7 +229,7 @@ class OpenAICountTokensConfig: transformed: Final[list[dict[str, object]]] = [] for tool in tools: if tool.get("type") == "function" and "function" in tool: - func = tool["function"] + func = _function_fields(tool["function"]) item: dict[str, object] = { "type": "function", "name": func.get("name", ""), @@ -235,7 +256,7 @@ class OpenAICountTokensConfig: @staticmethod def messages_to_responses_input( - messages: list[dict[str, Any]], + messages: Sequence[Mapping[str, object]], ) -> tuple[list[dict[str, object]], str | None]: """ Convert standard chat messages format to OpenAI Responses API input format. @@ -276,14 +297,17 @@ class OpenAICountTokensConfig: if content: input_items.append({"role": "assistant", "content": content}) if tool_calls: - for tc in tool_calls: - func = tc.get("function", {}) + for tc in iter_items(tool_calls): + tool_call = _field_reader(tc) + function = tool_call.get("function", {}) + call_id = tool_call.get("id", "") + function_fields = _field_reader(function) input_items.append( { "type": "function_call", - "call_id": tc.get("id", ""), - "name": func.get("name", ""), - "arguments": func.get("arguments", ""), + "call_id": call_id, + "name": function_fields.get("name", ""), + "arguments": function_fields.get("arguments", ""), } ) elif not content: diff --git a/litellm/llms/openai/responses/guardrail_translation/handler.py b/litellm/llms/openai/responses/guardrail_translation/handler.py index 3ea126c5a2a..d37a12a91d6 100644 --- a/litellm/llms/openai/responses/guardrail_translation/handler.py +++ b/litellm/llms/openai/responses/guardrail_translation/handler.py @@ -36,7 +36,7 @@ from collections.abc import Mapping, MutableSequence, Sequence from dataclasses import dataclass from itertools import accumulate, chain, repeat from types import MappingProxyType -from typing import TYPE_CHECKING, Any, Final, NamedTuple, Union, cast +from typing import TYPE_CHECKING, Any, Final, NamedTuple, Protocol, Union, cast from pydantic import BaseModel, ConfigDict, TypeAdapter, ValidationError from typing_extensions import ReadOnly, TypedDict @@ -47,6 +47,7 @@ from litellm.completion_extras.litellm_responses_transformation.transformation i OpenAiResponsesToChatCompletionStreamIterator, tool_call_dict_from_output_item, ) +from litellm.litellm_core_utils.core_helpers import has_attributes from litellm.llms.base_llm.guardrail_translation.base_translation import ( BaseTranslation, StreamingScanKey, @@ -237,6 +238,10 @@ class ResponsesStreamChunk(TypedDict, total=False): content_index: ReadOnly[int] +class _StreamEventFields(Protocol): + def get(self, key: str, /) -> object: ... + + _TERMINAL_ENVELOPE_EVENT_TYPES: Final = frozenset( { ResponsesAPIStreamEvents.RESPONSE_COMPLETED.value, @@ -1264,7 +1269,7 @@ class OpenAIResponsesHandler(BaseTranslation): def _sync_stream_events_with_rewrites( self, - stream_events: Sequence[Any], + stream_events: Sequence[object], rewrites_by_position: Mapping[tuple[int, int], str], ) -> None: """Sync pre-completion stream events with the rewritten completed @@ -1278,7 +1283,7 @@ class OpenAIResponsesHandler(BaseTranslation): {position: chain((rewritten,), repeat("")) for position, rewritten in rewrites_by_position.items()} ) for event in stream_events: - if not (isinstance(event, dict) or hasattr(event, "get")): + if not has_attributes(event, _StreamEventFields, "get"): continue event_type = event.get("type") output_index = event.get("output_index") diff --git a/litellm/llms/openai/responses/transformation.py b/litellm/llms/openai/responses/transformation.py index b90f6aa01da..07822bb17b3 100644 --- a/litellm/llms/openai/responses/transformation.py +++ b/litellm/llms/openai/responses/transformation.py @@ -25,7 +25,7 @@ from litellm.litellm_core_utils.prompt_templates.common_utils import ( from litellm.litellm_core_utils.safe_json_loads import safe_json_loads from litellm.litellm_core_utils.url_utils import encode_url_path_segment, join_api_base from litellm.llms.base_llm.responses.transformation import BaseResponsesAPIConfig -from litellm.llms.openai.chat.gpt_5_transformation import ( +from litellm.llms.openai.chat.gpt_reasoning_transformation import ( is_gpt_reasoning_series_name, unsupported_reasoning_effort_message, ) @@ -291,7 +291,7 @@ class OpenAIResponsesAPIConfig(BaseResponsesAPIConfig): level the row cannot gate because the same model takes it here and refuses it on chat. Azure overrides this so a bare deployment name reads the azure/ entry. """ - from litellm.llms.openai.chat.gpt_5_transformation import OpenAIGPT5Config + from litellm.llms.openai.chat.gpt_reasoning_transformation import OpenAIGPT5Config return OpenAIGPT5Config.row_disables_reasoning_effort_level(model, level) @@ -305,7 +305,7 @@ class OpenAIResponsesAPIConfig(BaseResponsesAPIConfig): copy of the rule here is what let this surface keep forwarding temperature after the chat surface stopped. """ - from litellm.llms.openai.chat.gpt_5_transformation import OpenAIGPT5Config + from litellm.llms.openai.chat.gpt_reasoning_transformation import OpenAIGPT5Config return OpenAIGPT5Config.effort_resolves_to_none(model, effort) diff --git a/litellm/llms/openai_like/messages/transformation.py b/litellm/llms/openai_like/messages/transformation.py index 12c8b1da166..8daae2a8e6a 100644 --- a/litellm/llms/openai_like/messages/transformation.py +++ b/litellm/llms/openai_like/messages/transformation.py @@ -1,9 +1,9 @@ -from typing import Any, Final +from typing import Final import litellm from litellm.litellm_core_utils.url_utils import join_api_base from litellm.llms.anthropic.common_utils import normalize_cache_control_in_anthropic_payload -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) from litellm.llms.openai_like.json_loader import SimpleProviderConfig @@ -41,7 +41,7 @@ class OpenAILikeAnthropicMessagesConfig(AnthropicMessagesConfig): self, headers: dict[str, str], model: str, - messages: list[Any], + messages: list[object], optional_params: dict, litellm_params: dict, api_key: str | None = None, @@ -151,7 +151,7 @@ class JSONProviderAnthropicMessagesConfig(OpenAILikeAnthropicMessagesConfig): self, headers: dict[str, str], model: str, - messages: list[Any], + messages: list[object], optional_params: dict, litellm_params: dict, api_key: str | None = None, diff --git a/litellm/llms/openai_like/providers.json b/litellm/llms/openai_like/providers.json index 36337fddbdc..115d914d3ac 100644 --- a/litellm/llms/openai_like/providers.json +++ b/litellm/llms/openai_like/providers.json @@ -249,5 +249,13 @@ "/v1/responses", "/v1/messages" ] + }, + "refuseless": { + "base_url": "https://api.refuseless.com/v1", + "api_key_env": "REFUSELESS_API_KEY", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/responses" + ] } } diff --git a/tests/unit/llms/anthropic/pass_through/adapters/__init__.py b/litellm/llms/opencode/chat/__init__.py similarity index 100% rename from tests/unit/llms/anthropic/pass_through/adapters/__init__.py rename to litellm/llms/opencode/chat/__init__.py diff --git a/litellm/llms/opencode/chat/transformation.py b/litellm/llms/opencode/chat/transformation.py new file mode 100644 index 00000000000..dcb30b5835c --- /dev/null +++ b/litellm/llms/opencode/chat/transformation.py @@ -0,0 +1,248 @@ +from collections.abc import AsyncIterator, Iterator, Mapping, Sequence +from typing import TYPE_CHECKING, Final + +import httpx +from pydantic import TypeAdapter + +import litellm +from litellm.litellm_core_utils.url_utils import ensure_api_route +from litellm.llms.anthropic.chat.transformation import AnthropicConfig +from litellm.llms.base_llm.chat.transformation import BaseConfig +from litellm.llms.gemini.chat.transformation import GoogleAIStudioGeminiConfig +from litellm.llms.openai_like.chat.transformation import OpenAILikeChatConfig +from litellm.llms.opencode.common_utils import ( + attach_go_reported_cost, + go_api_base, + go_api_key, + go_endpoint, + go_headers, + go_model_info, +) +from litellm.secret_managers.main import get_secret_str +from litellm.types.llms.openai import AllMessageValues +from litellm.types.utils import ModelResponse + +if TYPE_CHECKING: + from litellm.litellm_core_utils.litellm_logging import Logging + + +class _GoReportedCostMixin: + """Record usage.opencode.list_cost so response_cost reflects OpenCode's price, not the static rows.""" + + go_usage_key: str = "usage" + + def transform_response( + self, + model: str, + raw_response: httpx.Response, + model_response: ModelResponse, + logging_obj: "Logging", + request_data: Mapping[str, object], + messages: Sequence[AllMessageValues], + optional_params: Mapping[str, object], + litellm_params: Mapping[str, object], + encoding: object, + api_key: str | None = None, + json_mode: bool | None = None, + ) -> ModelResponse: + response: Final = super().transform_response( # pyright: ignore[reportAttributeAccessIssue, reportUnknownMemberType, reportUnknownVariableType] # mixin precedes a BaseConfig subclass + model=model, + raw_response=raw_response, + model_response=model_response, + logging_obj=logging_obj, + request_data=dict(request_data), + messages=list(messages), + optional_params=dict(optional_params), + litellm_params=dict(litellm_params), + encoding=encoding, + api_key=api_key, + json_mode=json_mode, + ) + priced: Final = TypeAdapter(ModelResponse).validate_python(response) + attach_go_reported_cost( + priced, TypeAdapter(dict[str, object]).validate_json(raw_response.content).get(self.go_usage_key) + ) + return priced + + +class OpenCodeGoChatConfig(_GoReportedCostMixin, OpenAILikeChatConfig): + @property + def custom_llm_provider(self) -> str: + return "opencode_go" + + def _get_openai_compatible_provider_info( + self, + api_base: str | None, + api_key: str | None, + ) -> tuple[str, str | None]: + return go_api_base(api_base), go_api_key(api_key) + + def validate_environment( + self, + headers: Mapping[str, object], + model: str, + messages: Sequence[AllMessageValues], + optional_params: Mapping[str, object], + litellm_params: Mapping[str, object], + api_key: str | None = None, + api_base: str | None = None, + ) -> dict[str, object]: # mutable-ok: protocol handlers mutate the returned request and headers + return go_headers(headers, litellm_params, api_key, model) + + def get_models( + self, api_key: str | None = None, api_base: str | None = None + ) -> list[str]: # mutable-ok: provider discovery requires a list + response: Final = litellm.module_level_client.get( # pyright: ignore[reportUnknownMemberType] # legacy HTTP wrapper has untyped query parameters + url=ensure_api_route( + (api_base or get_secret_str("OPENCODE_GO_API_BASE") or "https://opencode.ai/inference/go") + .rstrip("/") + .removesuffix("/v1"), + "v1/models", + ), + headers={"Authorization": f"Bearer {go_api_key(api_key)}"} if go_api_key(api_key) else {}, + ) + response.raise_for_status() + data: Final = TypeAdapter(dict[str, object]).validate_json(response.content) + models: Final = TypeAdapter(tuple[Mapping[str, object], ...]).validate_python(data["data"]) + return [f"opencode_go/{entry['id']}" for entry in models if isinstance(entry.get("id"), str)] + + +class OpenCodeGoMessagesChatConfig(_GoReportedCostMixin, AnthropicConfig): + @property + def custom_llm_provider(self) -> str: + return "opencode_go" + + def get_complete_url( + self, + api_base: str | None, + api_key: str | None, + model: str, + optional_params: Mapping[str, object], + litellm_params: Mapping[str, object], + stream: bool | None = None, + ) -> str: + return ensure_api_route(go_api_base(api_base, model).rstrip("/").removesuffix("/v1"), "v1/messages") + + def validate_environment( + self, + headers: Mapping[str, object], + model: str, + messages: Sequence[AllMessageValues], + optional_params: Mapping[str, object], + litellm_params: Mapping[str, object], + api_key: str | None = None, + api_base: str | None = None, + ) -> dict[str, object]: # mutable-ok: protocol handlers mutate the returned request and headers + return go_headers({"anthropic-version": "2023-06-01", **headers}, litellm_params, api_key, model) + + def transform_request( + self, + model: str, + messages: Sequence[AllMessageValues], + optional_params: Mapping[str, object], + litellm_params: Mapping[str, object], + headers: Mapping[str, object], + ) -> dict[str, object]: # mutable-ok: protocol handlers mutate the returned request and headers + max_output: Final[int | None] = TypeAdapter[int | None](int | None).validate_python( + go_model_info(model).get("max_output_tokens") + ) + defaults: Final = {"max_tokens": max_output} if max_output else {} + raw: Final[object] = super().transform_request( # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] # legacy Anthropic transformer accepts untyped mappings + model, + list(messages), + {**defaults, **optional_params}, + dict(litellm_params), + dict(headers), + ) + return TypeAdapter(dict[str, object]).validate_python(raw) + + +class OpenCodeGoGeminiChatConfig(_GoReportedCostMixin, GoogleAIStudioGeminiConfig): + go_usage_key: str = "usageMetadata" + + @property + def supports_stream_param_in_request_body(self) -> bool: + return False + + def get_model_response_iterator_for_request( + self, + streaming_response: Iterator[str] | AsyncIterator[str] | ModelResponse, + sync_stream: bool, + json_mode: bool | None, + optional_params: Mapping[str, object], + logging_obj: "Logging | None" = None, + ) -> object: + from litellm.llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini import ModelResponseIterator + + if logging_obj is None: + raise ValueError("OpenCode Go Gemini streaming requires the request logging context") + iterator: Final = ModelResponseIterator( + streaming_response=streaming_response, sync_stream=sync_stream, logging_obj=logging_obj + ) + return iter(iterator) if sync_stream else iterator + + @property + def custom_llm_provider(self) -> str: + return "opencode_go" + + def get_complete_url( + self, + api_base: str | None, + api_key: str | None, + model: str, + optional_params: Mapping[str, object], + litellm_params: Mapping[str, object], + stream: bool | None = None, + ) -> str: + base: Final = ensure_api_route( + go_api_base(api_base, model).rstrip("/").removesuffix("/v1beta"), "v1beta/models" + ) + action: Final = "streamGenerateContent?alt=sse" if stream else "generateContent" + return f"{base}/{model}:{action}" + + def validate_environment( + self, + headers: Mapping[str, object] | None, + model: str, + messages: Sequence[AllMessageValues], + optional_params: Mapping[str, object], + litellm_params: Mapping[str, object], + api_key: str | Mapping[str, object] | None = None, + api_base: str | None = None, + ) -> dict[str, str]: # mutable-ok: Gemini handler requires mutable string headers + return TypeAdapter(dict[str, str]).validate_python( + go_headers(headers or {}, litellm_params, api_key if isinstance(api_key, str) else None, model) + ) + + def transform_request( + self, + model: str, + messages: Sequence[AllMessageValues], + optional_params: Mapping[str, object], + litellm_params: Mapping[str, object], + headers: Mapping[str, object], + ) -> dict[str, object]: # mutable-ok: protocol handlers mutate the returned request and headers + from litellm.llms.vertex_ai.gemini.transformation import ( + _transform_request_body, # pyright: ignore[reportPrivateUsage, reportUnknownVariableType] # shared legacy Gemini wire-format builder + ) + + cached_content: Final = optional_params.get("cached_content") + body: Final = _transform_request_body( + messages=list(messages), + model=model, + optional_params=dict(optional_params), + custom_llm_provider="gemini", + litellm_params=dict(litellm_params), + cached_content=cached_content if isinstance(cached_content, str) else None, + ) + return TypeAdapter(dict[str, object]).validate_python(body) + + +def go_chat_config(model: str) -> BaseConfig: + match go_endpoint(model): + case "/v1/messages": + return OpenCodeGoMessagesChatConfig() + case "/v1beta/models": + return OpenCodeGoGeminiChatConfig() + case _: + return OpenCodeGoChatConfig() diff --git a/litellm/llms/opencode/common_utils.py b/litellm/llms/opencode/common_utils.py index 65a96411e52..82cd957d23c 100644 --- a/litellm/llms/opencode/common_utils.py +++ b/litellm/llms/opencode/common_utils.py @@ -1,4 +1,14 @@ import re +from collections.abc import Mapping +from typing import Final + +from pydantic import TypeAdapter + +from litellm.litellm_core_utils.core_helpers import provider_reported_usage_cost, set_response_cost_in_hidden_params +from litellm.litellm_core_utils.provider_affinity import add_provider_affinity_header +from litellm.secret_managers.main import get_secret_str +from litellm.types.llms.openai import ResponsesAPIResponse +from litellm.types.utils import ModelResponse def is_opencode_api_base(api_base: str | None) -> bool: @@ -8,3 +18,63 @@ def is_opencode_api_base(api_base: str | None) -> bool: r"https://opencode\.ai/(?:zen(?:/go)?|inference/(?:go/)?(?:openai|anthropic))(?:/v1)?/?", api_base ) ) + + +def go_model_info(model: str) -> Mapping[str, object]: + import litellm + + raw: Final[object] = litellm.model_cost.get( # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] # legacy mutable catalog, validated below + f"opencode_go/{model.removeprefix('opencode_go/')}", {} + ) + return TypeAdapter(Mapping[str, object]).validate_python(raw) + + +def go_endpoint(model: str) -> str: + endpoints: Final = TypeAdapter(tuple[str, ...]).validate_python( + go_model_info(model).get("supported_endpoints") or () + ) + return next(iter(endpoints), "/v1/chat/completions") + + +def go_api_base(api_base: str | None, model: str = "") -> str: + endpoint: Final = go_endpoint(model) + family: Final = ( + "anthropic/v1" + if endpoint == "/v1/messages" + else ("google/v1beta" if endpoint == "/v1beta/models" else "openai/v1") + ) + return api_base or get_secret_str("OPENCODE_GO_API_BASE") or f"https://opencode.ai/inference/go/{family}" + + +def go_api_key(api_key: str | None) -> str | None: + return api_key or get_secret_str("OPENCODE_GO_API_KEY") or get_secret_str("OPENCODE_API_KEY") + + +def go_headers( + headers: Mapping[str, object], + params: object, + api_key: str | None, + model: str, +) -> dict[str, object]: # mutable-ok: protocol handlers mutate the returned request and headers + import litellm + + resolved_key: Final = go_api_key(api_key) + if not resolved_key: + raise litellm.AuthenticationError( + message="Set OPENCODE_API_KEY or pass api_key for OpenCode Go.", + llm_provider="opencode_go", + model=model, + ) + return add_provider_affinity_header( + {"Content-Type": "application/json", **headers, "Authorization": f"Bearer {resolved_key}"}, + params, + "x-opencode-session", + ) + + +def go_reported_cost(usage: object) -> float | None: + return provider_reported_usage_cost(usage, "opencode_go") + + +def attach_go_reported_cost(response: ModelResponse | ResponsesAPIResponse, usage: object) -> None: + set_response_cost_in_hidden_params(response, go_reported_cost(usage)) diff --git a/litellm/llms/opencode/harness/transformation.py b/litellm/llms/opencode/harness/transformation.py index 46e8b750ca5..e801b66c448 100644 --- a/litellm/llms/opencode/harness/transformation.py +++ b/litellm/llms/opencode/harness/transformation.py @@ -26,10 +26,10 @@ import itertools import json import secrets import string -from collections.abc import Iterator, Mapping, Sequence +from collections.abc import Iterable, Iterator, Mapping, Sequence from dataclasses import dataclass from types import MappingProxyType -from typing import TYPE_CHECKING, Any, Final +from typing import TYPE_CHECKING, Final from pydantic import BaseModel, ConfigDict, JsonValue, TypeAdapter, ValidationError @@ -45,6 +45,7 @@ from litellm.harness.types import ( ToolCall, ToolResult, ) +from litellm.litellm_core_utils.core_helpers import iter_items from litellm.llms.base_llm.harness.transformation import ( BaseCLIHarnessConfig, HarnessSessionCopy, @@ -269,10 +270,17 @@ def session_copy(exported: str, path: str, workdir: str) -> HarnessSessionCopy | ) -def _as_dict(value: object) -> Mapping[str, Any]: +def _as_dict(value: object) -> Mapping[str, object]: return value if isinstance(value, dict) else MappingProxyType({}) +def _spread_items(value: object) -> Iterable[object]: + try: + return iter_items(value) + except TypeError: + raise TypeError(f"Value after * must be an iterable, not {type(value).__name__}") from None + + def _tool_events(part: Mapping[str, object]) -> Sequence[Event]: native = str(part.get("tool") or "") call_id = str(part.get("callID") or part.get("id") or "") @@ -346,7 +354,7 @@ def build_opencode_config( token_path: str, permissions: PermissionMode, disable_tools: Sequence[str] = (), - user_config: Mapping[str, Any] | None = None, + user_config: Mapping[str, object] | None = None, instructions_path: str | None = None, skills_path: str | None = None, ) -> Mapping[str, object]: @@ -355,10 +363,16 @@ def build_opencode_config( validate_user_config(user) qualified = f"{OPENCODE_PROVIDER_ID}/{model}" extra_instructions: Final = (instructions_path,) if instructions_path else () - instructions: Final = [*(user.get("instructions") or ()), *extra_instructions] # mutable-ok: opencode config JSON + instructions: Final = [ + *_spread_items(user.get("instructions") or ()), + *extra_instructions, + ] # mutable-ok: opencode config JSON user_skills = _as_dict(user.get("skills")) extra_skills: Final = (skills_path,) if skills_path else () - skill_paths: Final = [*(user_skills.get("paths") or ()), *extra_skills] # mutable-ok: opencode config JSON + skill_paths: Final = [ + *_spread_items(user_skills.get("paths") or ()), + *extra_skills, + ] # mutable-ok: opencode config JSON options: Final = {"baseURL": base_url, "apiKey": "{file:" + token_path + "}"} # mutable-ok: opencode config JSON models: Final[dict[str, Mapping[str, object]]] = {model: {}} # mutable-ok: opencode config JSON provider: Final = { # mutable-ok: opencode config JSON diff --git a/tests/unit/llms/anthropic/pass_through/context_management/__init__.py b/litellm/llms/opencode/messages/__init__.py similarity index 100% rename from tests/unit/llms/anthropic/pass_through/context_management/__init__.py rename to litellm/llms/opencode/messages/__init__.py diff --git a/litellm/llms/opencode/messages/transformation.py b/litellm/llms/opencode/messages/transformation.py new file mode 100644 index 00000000000..16953a33329 --- /dev/null +++ b/litellm/llms/opencode/messages/transformation.py @@ -0,0 +1,47 @@ +from collections.abc import Mapping, Sequence + +from pydantic import TypeAdapter + +from litellm.litellm_core_utils.url_utils import ensure_api_route +from litellm.llms.anthropic.messages.native.transformation import AnthropicMessagesConfig +from litellm.llms.opencode.common_utils import go_api_base, go_headers + + +class OpenCodeGoMessagesConfig(AnthropicMessagesConfig): + @property + def custom_llm_provider(self) -> str: + return "opencode_go" + + def should_strip_billing_metadata(self) -> bool: + return True + + def validate_anthropic_messages_environment( + self, + headers: Mapping[str, object], + model: str, + messages: Sequence[object], + optional_params: Mapping[str, object], + litellm_params: Mapping[str, object], + api_key: str | None = None, + api_base: str | None = None, + ) -> tuple[dict[str, object], str | None]: # mutable-ok: native Messages handler mutates validated headers + headers_out, base = super().validate_anthropic_messages_environment( # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] # validate legacy headers before returning them + headers=go_headers(headers, litellm_params, api_key, model), + model=model, + messages=list(messages), + optional_params=dict(optional_params), + litellm_params=dict(litellm_params), + api_base=go_api_base(api_base, model), + ) + return TypeAdapter(dict[str, object]).validate_python(headers_out), base + + def get_complete_url( + self, + api_base: str | None, + api_key: str | None, + model: str, + optional_params: Mapping[str, object], + litellm_params: Mapping[str, object], + stream: bool | None = None, + ) -> str: + return ensure_api_route(go_api_base(api_base, model).rstrip("/").removesuffix("/v1"), "v1/messages") diff --git a/tests/unit/llms/anthropic/pass_through/messages/__init__.py b/litellm/llms/opencode/responses/__init__.py similarity index 100% rename from tests/unit/llms/anthropic/pass_through/messages/__init__.py rename to litellm/llms/opencode/responses/__init__.py diff --git a/litellm/llms/opencode/responses/transformation.py b/litellm/llms/opencode/responses/transformation.py new file mode 100644 index 00000000000..615ca60b45b --- /dev/null +++ b/litellm/llms/opencode/responses/transformation.py @@ -0,0 +1,65 @@ +from collections.abc import Mapping +from typing import TYPE_CHECKING, Final + +import httpx + +from litellm.litellm_core_utils.url_utils import ensure_api_route +from litellm.llms.openai.responses.transformation import OpenAIResponsesAPIConfig +from litellm.llms.opencode.common_utils import attach_go_reported_cost, go_api_base, go_headers +from litellm.types.llms.openai import ( + ResponseCompletedEvent, + ResponseFailedEvent, + ResponseIncompleteEvent, + ResponsesAPIResponse, + ResponsesAPIStreamingResponse, +) +from litellm.types.router import GenericLiteLLMParams +from litellm.types.utils import LlmProviders + +if TYPE_CHECKING: + from litellm.litellm_core_utils.litellm_logging import Logging + + +class OpenCodeGoResponsesConfig(OpenAIResponsesAPIConfig): + @property + def custom_llm_provider(self) -> LlmProviders: + return LlmProviders.OPENCODE_GO + + def supports_native_websocket(self) -> bool: + return False + + def get_complete_url(self, api_base: str | None, litellm_params: Mapping[str, object]) -> str: + return ensure_api_route(go_api_base(api_base).rstrip("/").removesuffix("/v1"), "v1/responses") + + def validate_environment( + self, + headers: Mapping[str, object], + model: str, + litellm_params: GenericLiteLLMParams | None, + ) -> dict[str, object]: # mutable-ok: protocol handlers mutate the returned request and headers + return go_headers(headers, litellm_params, litellm_params.api_key if litellm_params else None, model) + + def transform_response_api_response( + self, + model: str, + raw_response: httpx.Response, + logging_obj: "Logging", + ) -> ResponsesAPIResponse: + response: Final = super().transform_response_api_response( + model=model, raw_response=raw_response, logging_obj=logging_obj + ) + attach_go_reported_cost(response, response.usage) + return response + + def transform_streaming_response( + self, + model: str, + parsed_chunk: Mapping[str, object], + logging_obj: "Logging", + ) -> ResponsesAPIStreamingResponse: + event: Final = super().transform_streaming_response( # pyright: ignore[reportUnknownMemberType] # base takes an untyped dict + model=model, parsed_chunk=dict(parsed_chunk), logging_obj=logging_obj + ) + if isinstance(event, ResponseCompletedEvent | ResponseFailedEvent | ResponseIncompleteEvent): + attach_go_reported_cost(event.response, event.response.usage) + return event diff --git a/litellm/llms/openrouter/decisions/transformation.py b/litellm/llms/openrouter/decisions/transformation.py index 0fa5c7ca7cb..30d33f09efd 100644 --- a/litellm/llms/openrouter/decisions/transformation.py +++ b/litellm/llms/openrouter/decisions/transformation.py @@ -13,7 +13,7 @@ class OpenRouterDecisionsConfig(BaseDecisionsConfig): return "https://openrouter.ai/api" def provider_reported_cost(self, response: DecisionsIRResponse) -> float | None: - cost: Final = response.usage.extra.get("cost") + cost: Final = response.usage.extra.get("cost") if response.usage is not None else None if not isinstance(cost, (int, float)): return None return float(cost) diff --git a/litellm/llms/openrouter/image_edit/transformation.py b/litellm/llms/openrouter/image_edit/transformation.py index 9644ee3f280..c2d8398aead 100644 --- a/litellm/llms/openrouter/image_edit/transformation.py +++ b/litellm/llms/openrouter/image_edit/transformation.py @@ -47,7 +47,7 @@ from typing import TYPE_CHECKING, Any, Final, cast import httpx from httpx._types import RequestFiles -from pydantic import ConfigDict, RootModel, with_config +from pydantic import ConfigDict, RootModel, TypeAdapter, with_config from typing_extensions import NotRequired, ReadOnly, TypedDict import litellm @@ -74,6 +74,8 @@ if TYPE_CHECKING: else: LiteLLMLoggingObj = Any +_DECODED_JSON: Final = TypeAdapter(object) + @with_config(ConfigDict(extra="allow", strict=True, hide_input_in_errors=True)) class _ImageUrl(TypedDict): @@ -248,7 +250,7 @@ class OpenRouterImageEditConfig(BaseImageEditConfig): logging_obj: LiteLLMLoggingObj, ) -> ImageResponse: try: - response_json: Final[object] = raw_response.json() + response_json: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception as e: raise OpenRouterException( message=f"Error parsing OpenRouter response: {e}", diff --git a/litellm/llms/openrouter/image_generation/transformation.py b/litellm/llms/openrouter/image_generation/transformation.py index ce6e62aaa88..a9e07555d6a 100644 --- a/litellm/llms/openrouter/image_generation/transformation.py +++ b/litellm/llms/openrouter/image_generation/transformation.py @@ -59,6 +59,7 @@ if TYPE_CHECKING: else: LiteLLMLoggingObj = Any +_DECODED_JSON: Final = TypeAdapter(object) _JSON_DICT: Final = TypeAdapter(dict[str, object], config=ConfigDict(hide_input_in_errors=True)) _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_input_in_errors=True)) _JSON_OBJECTS: Final = TypeAdapter(Iterable[Mapping[str, object]], config=ConfigDict(hide_input_in_errors=True)) @@ -359,7 +360,7 @@ class OpenRouterImageGenerationConfig(BaseImageGenerationConfig): ImageResponse: Populated image response """ try: - response_json: Final = raw_response.json() + response_json: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception as e: raise OpenRouterException( message=f"Error parsing OpenRouter response: {e}", diff --git a/litellm/llms/opensandbox/sandbox/transformation.py b/litellm/llms/opensandbox/sandbox/transformation.py index 574fbfa9e5b..d30a9ff534e 100644 --- a/litellm/llms/opensandbox/sandbox/transformation.py +++ b/litellm/llms/opensandbox/sandbox/transformation.py @@ -20,6 +20,7 @@ from litellm.constants import ( OPEN_SANDBOX_POLL_INTERVAL, OPEN_SANDBOX_READY_TIMEOUT, ) +from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.litellm_core_utils.hidden_params import HIDDEN_PARAMS_ATTR, set_hidden_params from litellm.litellm_core_utils.url_utils import join_api_base from litellm.llms.base_llm.sandbox.transformation import ( @@ -44,6 +45,13 @@ _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_i _JSON_VALUE: Final = TypeAdapter(object) +def _decoded_json_object(value: object) -> Mapping[str, object]: + mapping: Final = as_str_mapping(value) + if mapping is not None: + return mapping + raise AttributeError(f"{type(value).__name__!r} object has no attribute 'get'", name="get", obj=value) + + class OpenSandboxSandboxConfig(BaseSandboxConfig): def _http(self, client: AsyncHTTPHandler | None) -> AsyncHTTPHandler: if client is not None: @@ -321,7 +329,7 @@ class OpenSandboxSandboxConfig(BaseSandboxConfig): headers=headers, params={"use_server_proxy": use_server_proxy}, ) - data: Final = response.json() + data: Final = _decoded_json_object(_JSON_VALUE.validate_python(response.json())) endpoint: Final = data.get("endpoint") if not endpoint: raise ValueError(f"OpenSandbox did not return an execd endpoint for {sandbox_id}") @@ -492,7 +500,7 @@ class OpenSandboxSandboxConfig(BaseSandboxConfig): if not data: return None try: - parsed: Final = json.loads(data) + parsed: Final = _JSON_VALUE.validate_python(json.loads(data)) except json.JSONDecodeError: return None if not isinstance(parsed, dict): diff --git a/litellm/llms/pass_through/guardrail_translation/handler.py b/litellm/llms/pass_through/guardrail_translation/handler.py index 885fc98ffea..dea8bcb73a4 100644 --- a/litellm/llms/pass_through/guardrail_translation/handler.py +++ b/litellm/llms/pass_through/guardrail_translation/handler.py @@ -6,11 +6,14 @@ It uses the field targeting configuration from litellm_logging_obj to extract specific fields for guardrail processing. """ -from collections.abc import AsyncIterable, AsyncIterator, Callable, Mapping, Sequence +from collections.abc import AsyncIterable, AsyncIterator, Awaitable, Callable, Mapping, Sequence from typing import TYPE_CHECKING, Final, Optional, Protocol, runtime_checkable +from pydantic import TypeAdapter + from litellm._logging import verbose_proxy_logger from litellm.integrations.custom_guardrail import without_server_streaming_classification +from litellm.litellm_core_utils.core_helpers import has_attributes from litellm.llms.base_llm.guardrail_translation.base_translation import ( BaseTranslation, StreamingScanKey, @@ -87,7 +90,7 @@ class PassThroughEndpointHandler(BaseTranslation): payload_to_check: Final = { k: v for k, v in without_server_streaming_classification(data).items() - if not k.startswith("_") and k not in ("metadata", "litellm_logging_obj") + if not k.startswith("_") and k not in ("metadata", "litellm_metadata", "litellm_logging_obj") } verbose_proxy_logger.debug("PassThroughEndpointHandler: Using full payload for guardrail") return safe_dumps(payload_to_check) @@ -215,6 +218,19 @@ class _EventStreamEndpointChecker(Protocol): def event_stream_endpoint_is_de_anonymizable(self, endpoint: str, model: str, body: object) -> bool: ... +class _EventStreamDeAnonymizer(Protocol): + async def de_anonymize_event_stream( + self, + body_bytes: bytes, + proxy_logging_obj: "ProxyLogging", + user_api_key_dict: "UserAPIKeyAuth", + data: Mapping[str, object], + ) -> bytes: ... + + +_TRANSLATION_RESULT: Final = TypeAdapter(object) + + _PROVIDER_HANDLERS: dict[str, type[BaseTranslation]] = {} @@ -260,10 +276,12 @@ class LlmPassthroughRouteHandler(BaseTranslation): provider, ) return data - return await handler_cls().process_input_messages( - data=data, - guardrail_to_apply=guardrail_to_apply, - litellm_logging_obj=litellm_logging_obj, + return _TRANSLATION_RESULT.validate_python( + await handler_cls().process_input_messages( + data=data, + guardrail_to_apply=guardrail_to_apply, + litellm_logging_obj=litellm_logging_obj, + ) ) async def process_output_response( @@ -282,12 +300,14 @@ class LlmPassthroughRouteHandler(BaseTranslation): provider, ) return response - return await handler_cls().process_output_response( - response=response, - guardrail_to_apply=guardrail_to_apply, - litellm_logging_obj=litellm_logging_obj, - user_api_key_dict=user_api_key_dict, - request_data=request_data, + return _TRANSLATION_RESULT.validate_python( + await handler_cls().process_output_response( + response=response, + guardrail_to_apply=guardrail_to_apply, + litellm_logging_obj=litellm_logging_obj, + user_api_key_dict=user_api_key_dict, + request_data=request_data, + ) ) @staticmethod @@ -399,9 +419,11 @@ class LlmPassthroughRouteHandler(BaseTranslation): return handler_cls.event_stream_media_type() @staticmethod - def _resolve_event_stream_de_anonymizer(provider: str | None): + def _resolve_event_stream_de_anonymizer(provider: str | None) -> Callable[..., Awaitable[bytes]] | None: handler_cls: Final = _get_provider_handlers().get(provider or "") - return getattr(handler_cls, "de_anonymize_event_stream", None) + if not has_attributes(handler_cls, _EventStreamDeAnonymizer, "de_anonymize_event_stream"): + return None + return handler_cls.de_anonymize_event_stream @staticmethod def supports_event_stream_relay(provider: object, endpoint: object, model: object, body: object) -> bool: diff --git a/litellm/llms/perplexity/responses/transformation.py b/litellm/llms/perplexity/responses/transformation.py index a2b7eceea40..77817a5e5bb 100644 --- a/litellm/llms/perplexity/responses/transformation.py +++ b/litellm/llms/perplexity/responses/transformation.py @@ -12,6 +12,7 @@ Ref: https://docs.perplexity.ai/api-reference/responses-post from typing import Any, Final import httpx +from pydantic import TypeAdapter from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj from litellm.litellm_core_utils.url_utils import join_api_base @@ -22,6 +23,8 @@ from litellm.types.llms.openai import ResponseInputParam, ResponsesAPIResponse from litellm.types.router import GenericLiteLLMParams from litellm.types.utils import LlmProviders +_DECODED_JSON: Final = TypeAdapter(object) + class PerplexityResponsesConfig(OpenAIResponsesAPIConfig): def get_supported_openai_params(self, model: str) -> list: @@ -104,7 +107,7 @@ class PerplexityResponsesConfig(OpenAIResponsesAPIConfig): ) -> ResponsesAPIResponse: """Check for Perplexity's status:'failed' on HTTP 200 before delegating to base.""" try: - raw_response_json = raw_response.json() + raw_response_json = _DECODED_JSON.validate_python(raw_response.json()) except Exception: raw_response_json = None diff --git a/litellm/llms/petals/completion/transformation.py b/litellm/llms/petals/completion/transformation.py index ee20c2b12d5..a875992448a 100644 --- a/litellm/llms/petals/completion/transformation.py +++ b/litellm/llms/petals/completion/transformation.py @@ -1,3 +1,5 @@ +from collections.abc import Mapping +from types import MappingProxyType from typing import TYPE_CHECKING, Final from httpx import Headers, Response @@ -57,7 +59,7 @@ class PetalsConfig(BaseConfig): top_p: float | None = None, repetition_penalty: float | None = None, ) -> None: - locals_: Final = locals().copy() + locals_: Final[Mapping[str, object]] = MappingProxyType(locals().copy()) for key, value in locals_.items(): if key != "self" and value is not None: setattr(self.__class__, key, value) diff --git a/litellm/llms/pg_vector/vector_stores/transformation.py b/litellm/llms/pg_vector/vector_stores/transformation.py index eeecd02653d..89851f60d76 100644 --- a/litellm/llms/pg_vector/vector_stores/transformation.py +++ b/litellm/llms/pg_vector/vector_stores/transformation.py @@ -76,7 +76,7 @@ class PGVectorStoreConfig(OpenAIVectorStoreConfig): api_base: str, litellm_logging_obj: LiteLLMLoggingObj, litellm_params: dict, - extra_body: dict[str, Any] | None = None, + extra_body: dict[str, object] | None = None, ) -> tuple[str, dict]: encoded_vector_store_id: Final = encode_url_path_segment(vector_store_id, field_name="vector_store_id") url: Final = join_api_base(api_base, f"{encoded_vector_store_id}/search") diff --git a/litellm/llms/recraft/image_generation/transformation.py b/litellm/llms/recraft/image_generation/transformation.py index 7b1a7714ec6..49a2938e1c0 100644 --- a/litellm/llms/recraft/image_generation/transformation.py +++ b/litellm/llms/recraft/image_generation/transformation.py @@ -26,6 +26,7 @@ else: _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_input_in_errors=True)) _JSON_OBJECTS: Final = TypeAdapter(Iterable[Mapping[str, object]], config=ConfigDict(hide_input_in_errors=True)) +_DECODED_JSON: Final = TypeAdapter(object) class RecraftImageGenerationConfig(BaseImageGenerationConfig): @@ -134,7 +135,7 @@ class RecraftImageGenerationConfig(BaseImageGenerationConfig): https://www.recraft.ai/docs#generate-image """ try: - response_data: Final = raw_response.json() + response_data: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception as e: raise self.get_error_class( error_message=f"Error transforming image generation response: {e}", diff --git a/litellm/llms/runwayml/image_generation/transformation.py b/litellm/llms/runwayml/image_generation/transformation.py index e721ac678a1..23c8c86e7ca 100644 --- a/litellm/llms/runwayml/image_generation/transformation.py +++ b/litellm/llms/runwayml/image_generation/transformation.py @@ -1,9 +1,10 @@ import asyncio import time from collections.abc import Mapping, Sequence -from typing import TYPE_CHECKING, Any, Final +from typing import TYPE_CHECKING, Any, Final, cast import httpx +from pydantic import TypeAdapter from typing_extensions import ReadOnly, TypedDict from litellm._logging import verbose_logger @@ -11,6 +12,7 @@ from litellm.constants import ( RUNWAYML_DEFAULT_API_VERSION, RUNWAYML_POLLING_TIMEOUT, ) +from litellm.litellm_core_utils.core_helpers import decoded_json_object from litellm.litellm_core_utils.url_utils import join_api_base from litellm.llms.base_llm.image_generation.transformation import ( BaseImageGenerationConfig, @@ -36,9 +38,25 @@ class _RunwayMLTask(TypedDict, total=False): id: ReadOnly[str] status: ReadOnly[str] - output: ReadOnly[Sequence[str | Mapping[str, str]]] - failure: ReadOnly[str] - failureCode: ReadOnly[str] + output: ReadOnly[Sequence[str | Mapping[str, str | None]] | None] + failure: ReadOnly[str | None] + failureCode: ReadOnly[str | None] + + +_JSON_VALUE: Final = TypeAdapter(object) + + +def _decoded_json(response: httpx.Response) -> object: + return _JSON_VALUE.validate_python(response.json()) + + +def _runway_task(decoded: object) -> _RunwayMLTask: + task: Final = decoded_json_object(decoded) + return cast(_RunwayMLTask, task) # cast-ok: the payload passes through unvalidated, as before it was typed + + +def _parse_runway_task(response: httpx.Response) -> _RunwayMLTask: + return _runway_task(_decoded_json(response)) class RunwayMLImageGenerationConfig(BaseImageGenerationConfig): @@ -234,7 +252,7 @@ class RunwayMLImageGenerationConfig(BaseImageGenerationConfig): response = client.get(url=task_url, headers=headers) response.raise_for_status() - response_data: _RunwayMLTask = response.json() + response_data: _RunwayMLTask = _parse_runway_task(response) # Check task status status = self._check_task_status(response_data=response_data) @@ -282,7 +300,7 @@ class RunwayMLImageGenerationConfig(BaseImageGenerationConfig): response = await client.get(url=task_url, headers=headers) response.raise_for_status() - response_data: _RunwayMLTask = response.json() + response_data: _RunwayMLTask = _parse_runway_task(response) # Check task status status = self._check_task_status(response_data=response_data) @@ -328,13 +346,14 @@ class RunwayMLImageGenerationConfig(BaseImageGenerationConfig): } """ try: - response_data: _RunwayMLTask = raw_response.json() + decoded: Final = _decoded_json(raw_response) except Exception as e: raise self.get_error_class( error_message=f"Error transforming image generation response: {e}", status_code=raw_response.status_code, headers=raw_response.headers, ) + response_data: _RunwayMLTask = _runway_task(decoded) verbose_logger.debug("RunwayML starting polling...") @@ -358,7 +377,7 @@ class RunwayMLImageGenerationConfig(BaseImageGenerationConfig): ) # Update response_data with polled result - response_data = raw_response.json() + response_data = _parse_runway_task(raw_response) verbose_logger.debug("RunwayML polling complete, transforming to OpenAI format") @@ -388,13 +407,14 @@ class RunwayMLImageGenerationConfig(BaseImageGenerationConfig): We need to poll the task until it completes (status SUCCEEDED) using async polling. """ try: - response_data: _RunwayMLTask = raw_response.json() + decoded: Final = _decoded_json(raw_response) except Exception as e: raise self.get_error_class( error_message=f"Error transforming image generation response: {e}", status_code=raw_response.status_code, headers=raw_response.headers, ) + response_data: _RunwayMLTask = _runway_task(decoded) verbose_logger.debug("RunwayML starting polling (async)...") @@ -418,7 +438,7 @@ class RunwayMLImageGenerationConfig(BaseImageGenerationConfig): ) # Update response_data with polled result - response_data = raw_response.json() + response_data = _parse_runway_task(raw_response) verbose_logger.debug("RunwayML polling complete (async), transforming to OpenAI format") diff --git a/litellm/llms/runwayml/text_to_speech/transformation.py b/litellm/llms/runwayml/text_to_speech/transformation.py index 1f052648f13..ce1ec1714f1 100644 --- a/litellm/llms/runwayml/text_to_speech/transformation.py +++ b/litellm/llms/runwayml/text_to_speech/transformation.py @@ -41,6 +41,11 @@ class _RunwayTtsTaskResponse(TypedDict, total=False): failureCode: ReadOnly[str] +def _parse_runway_tts_task(response: httpx.Response) -> _RunwayTtsTaskResponse: + task: Final[_RunwayTtsTaskResponse] = response.json() + return task + + class RunwayMLTextToSpeechConfig(BaseTextToSpeechConfig): """ Configuration for RunwayML Text-to-Speech @@ -321,7 +326,7 @@ class RunwayMLTextToSpeechConfig(BaseTextToSpeechConfig): response = client.get(url=task_url, headers=headers) response.raise_for_status() - response_data: _RunwayTtsTaskResponse = response.json() + response_data: _RunwayTtsTaskResponse = _parse_runway_tts_task(response) # Check task status status = self._check_task_status(response_data=response_data) @@ -368,7 +373,7 @@ class RunwayMLTextToSpeechConfig(BaseTextToSpeechConfig): response = await client.get(url=task_url, headers=headers) response.raise_for_status() - response_data: _RunwayTtsTaskResponse = response.json() + response_data: _RunwayTtsTaskResponse = _parse_runway_tts_task(response) # Check task status status = self._check_task_status(response_data=response_data) @@ -459,7 +464,7 @@ class RunwayMLTextToSpeechConfig(BaseTextToSpeechConfig): from litellm.types.llms.openai import HttpxBinaryResponseContent try: - response_data: Final[_RunwayTtsTaskResponse] = raw_response.json() + response_data: Final[_RunwayTtsTaskResponse] = _parse_runway_tts_task(raw_response) except Exception as e: raise self.get_error_class( error_message=f"Error parsing RunwayML TTS response: {e}", @@ -489,7 +494,7 @@ class RunwayMLTextToSpeechConfig(BaseTextToSpeechConfig): ) # Get the completed task data - task_data: Final[_RunwayTtsTaskResponse] = polled_response.json() + task_data: Final[_RunwayTtsTaskResponse] = _parse_runway_tts_task(polled_response) verbose_logger.debug("RunwayML TTS polling complete, downloading audio") @@ -528,7 +533,7 @@ class RunwayMLTextToSpeechConfig(BaseTextToSpeechConfig): from litellm.types.llms.openai import HttpxBinaryResponseContent try: - response_data: Final[_RunwayTtsTaskResponse] = raw_response.json() + response_data: Final[_RunwayTtsTaskResponse] = _parse_runway_tts_task(raw_response) except Exception as e: raise self.get_error_class( error_message=f"Error parsing RunwayML TTS response: {e}", @@ -558,7 +563,7 @@ class RunwayMLTextToSpeechConfig(BaseTextToSpeechConfig): ) # Get the completed task data - task_data: Final[_RunwayTtsTaskResponse] = polled_response.json() + task_data: Final[_RunwayTtsTaskResponse] = _parse_runway_tts_task(polled_response) verbose_logger.debug("RunwayML TTS polling complete (async), downloading audio") diff --git a/litellm/llms/runwayml/videos/transformation.py b/litellm/llms/runwayml/videos/transformation.py index 106567f6fba..ad8a24c1535 100644 --- a/litellm/llms/runwayml/videos/transformation.py +++ b/litellm/llms/runwayml/videos/transformation.py @@ -119,7 +119,7 @@ class RunwayMLVideoConfig(BaseVideoConfig): @staticmethod def _parse_task_response(raw_response: httpx.Response) -> _RunwayTaskResponse: - return raw_response.json() + return _parse_runway_task_response(raw_response) def get_supported_openai_params(self, model: str) -> list: """ diff --git a/litellm/llms/sagemaker/common_utils.py b/litellm/llms/sagemaker/common_utils.py index 14f0e3ead62..eaa805e7769 100644 --- a/litellm/llms/sagemaker/common_utils.py +++ b/litellm/llms/sagemaker/common_utils.py @@ -1,3 +1,4 @@ +import builtins import codecs import functools import json @@ -34,6 +35,14 @@ class _SageMakerMessagesChunkData(TypedDict, total=False): choices: ReadOnly[Required[list[Mapping[str, object]]]] +class _SageMakerPayloadPart(TypedDict, total=False): + bytes: ReadOnly[builtins.bytes] + + +class _SageMakerStreamEvent(TypedDict, total=False): + chunk: ReadOnly[_SageMakerPayloadPart] + + class _SageMakerChunkDataRoot(RootModel[_SageMakerChunkData]): model_config = ConfigDict(frozen=True, hide_input_in_errors=True) @@ -345,7 +354,7 @@ class AWSEventStreamDecoder: ), ) response_dict: Final = event.to_response_dict() - parsed_response: Final = self.parser.parse(response_dict, response_stream_shape) + parsed_response: Final[_SageMakerStreamEvent] = self.parser.parse(response_dict, response_stream_shape) body: Final = response_dict.get("body") if response_dict["status_code"] != 200: diff --git a/litellm/llms/sagemaker/embedding/cohere_transformation.py b/litellm/llms/sagemaker/embedding/cohere_transformation.py index 35352f65dda..8c0f4437edf 100644 --- a/litellm/llms/sagemaker/embedding/cohere_transformation.py +++ b/litellm/llms/sagemaker/embedding/cohere_transformation.py @@ -10,7 +10,8 @@ be of type Object`. Reference: https://docs.cohere.com/v2/reference/embed """ -from typing import TYPE_CHECKING, Any, cast +from collections.abc import Sequence +from typing import TYPE_CHECKING, cast if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj @@ -25,6 +26,7 @@ from litellm.llms.bedrock.embed.cohere_transformation import ( BedrockCohereEmbeddingConfig, ) from litellm.llms.cohere.embed.v1_transformation import CohereEmbeddingConfig +from litellm.types.llms.openai import AllMessageValues from litellm.types.utils import EmbeddingResponse from ..common_utils import SagemakerError @@ -123,7 +125,7 @@ class SagemakerCohereEmbeddingConfig(BaseEmbeddingConfig): self, headers: dict, model: str, - messages: list[Any], + messages: Sequence[AllMessageValues], optional_params: dict, litellm_params: dict, api_key: str | None = None, diff --git a/litellm/llms/sagemaker/embedding/openai_transformation.py b/litellm/llms/sagemaker/embedding/openai_transformation.py index a3f0ebfbf59..1222c697832 100644 --- a/litellm/llms/sagemaker/embedding/openai_transformation.py +++ b/litellm/llms/sagemaker/embedding/openai_transformation.py @@ -15,7 +15,7 @@ if TYPE_CHECKING: from litellm.types.llms.openai import AllEmbeddingInputValues from httpx._models import Headers, Response -from pydantic import BaseModel, ConfigDict, ValidationError +from pydantic import BaseModel, ConfigDict, TypeAdapter, ValidationError from litellm.llms.base_llm.chat.transformation import BaseLLMException from litellm.llms.base_llm.embedding.transformation import BaseEmbeddingConfig @@ -25,6 +25,7 @@ from litellm.types.utils import EmbeddingResponse, Usage from ..common_utils import STR_KEYED_MAPPING, SagemakerError SUPPORTED_OPENAI_PARAMS: Final = ("dimensions", "encoding_format", "user") +_DECODED_JSON: Final = TypeAdapter(object) class OpenAIEmbeddingUsage(BaseModel): @@ -94,7 +95,7 @@ class SagemakerOpenAIEmbeddingConfig(BaseEmbeddingConfig): litellm_params: Mapping[str, object] | None = None, ) -> "EmbeddingResponse": try: - response_data: Final = raw_response.json() + response_data: Final = _DECODED_JSON.validate_python(raw_response.json()) except ValueError as e: raise SagemakerError( message=f"Failed to parse response: {e}", diff --git a/litellm/llms/sagemaker/embedding/transformation.py b/litellm/llms/sagemaker/embedding/transformation.py index 1395f9b98ec..2cd02683167 100644 --- a/litellm/llms/sagemaker/embedding/transformation.py +++ b/litellm/llms/sagemaker/embedding/transformation.py @@ -4,7 +4,8 @@ Translate from OpenAI's `/v1/embeddings` to Sagemaker's `/invoke` In the Huggingface TGI format. """ -from typing import TYPE_CHECKING, Any, Final +from collections.abc import Sequence +from typing import TYPE_CHECKING, Final if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj @@ -15,6 +16,7 @@ from httpx._models import Headers, Response from litellm.llms.base_llm.chat.transformation import BaseLLMException from litellm.llms.base_llm.embedding.transformation import BaseEmbeddingConfig from litellm.llms.voyage.embedding.transformation import VoyageEmbeddingConfig +from litellm.types.llms.openai import AllMessageValues from litellm.types.utils import EmbeddingResponse, Usage from ..common_utils import SagemakerError @@ -158,7 +160,7 @@ class SagemakerEmbeddingConfig(BaseEmbeddingConfig): self, headers: dict, model: str, - messages: list[Any], + messages: Sequence[AllMessageValues], optional_params: dict, litellm_params: dict, api_key: str | None = None, diff --git a/litellm/llms/sap/chat/transformation.py b/litellm/llms/sap/chat/transformation.py index 8a7baf18e8f..622c28f3c90 100755 --- a/litellm/llms/sap/chat/transformation.py +++ b/litellm/llms/sap/chat/transformation.py @@ -25,7 +25,7 @@ if TYPE_CHECKING: else: LiteLLMLoggingObj = Any -from ..credentials import get_token_creator +from ..credentials import AICoreConfiguration, AICoreDeploymentList, get_token_creator from .handler import ( AsyncSAPStreamIterator, GenAIHubOrchestrationError, @@ -186,11 +186,13 @@ class GenAIHubOrchestrationConfig(OpenAIGPTConfig): # Keep a short, tight client lifecycle here to avoid fd leaks client: Final = litellm.module_level_client # with httpx.Client(timeout=30) as client: - deployments: Final = client.get(join_api_base(self.base_url, "lm/deployments"), headers=self.headers).json() + deployments: Final[AICoreDeploymentList] = client.get( + join_api_base(self.base_url, "lm/deployments"), headers=self.headers + ).json() valid: Final[list[tuple[str, str]]] = [] for dep in deployments.get("resources", []): if dep.get("scenarioId") == "orchestration": - cfg = client.get( + cfg: AICoreConfiguration = client.get( join_api_base(self.base_url, f"lm/configurations/{dep['configurationId']}"), headers=self.headers, ).json() diff --git a/litellm/llms/sap/credentials.py b/litellm/llms/sap/credentials.py index 2622d0fa9b6..74d065956cc 100644 --- a/litellm/llms/sap/credentials.py +++ b/litellm/llms/sap/credentials.py @@ -8,7 +8,7 @@ from dataclasses import dataclass from datetime import datetime, timedelta, timezone from pathlib import Path from threading import Lock -from typing import Any, Final, Protocol +from typing import Final, Protocol import httpx from pydantic import TypeAdapter @@ -34,6 +34,21 @@ DEFAULT_HOME_PATH: Final = os.path.join(os.path.expanduser("~"), ".aicore") _DECODED_JSON: Final = TypeAdapter(object) +class AICoreDeployment(TypedDict): + configurationId: ReadOnly[str] + scenarioId: ReadOnly[str] + deploymentUrl: ReadOnly[str] + createdAt: ReadOnly[str] + + +class AICoreDeploymentList(TypedDict, total=False): + resources: ReadOnly[Sequence[AICoreDeployment]] + + +class AICoreConfiguration(TypedDict): + executableId: ReadOnly[str] + + def _get_home() -> str: return os.getenv(HOME_PATH_ENV_VAR, DEFAULT_HOME_PATH) @@ -59,7 +74,7 @@ def _get_nested(d: object, path: Sequence[str]) -> object: return cur -def _load_json_env(var_name: str) -> dict[str, object] | None: +def _load_json_env(var_name: str) -> Mapping[str, Sequence[Mapping[str, object]]] | None: raw: Final = os.environ.get(var_name) if not raw: return None @@ -76,7 +91,7 @@ def _str_or_none(value: object) -> str | None: return None -def _load_vcap() -> dict[str, Any]: +def _load_vcap() -> Mapping[str, Sequence[Mapping[str, object]]]: return _load_json_env(VCAP_SERVICES_ENV_VAR) or {} @@ -196,7 +211,7 @@ def resolve_resource_group(sources: list[Source]) -> str | None: def _parse_service_key_once( service_key: str | dict | None, -) -> dict[str, object] | None: +) -> object: """ Pre-parse service_key if it's a string to avoid repeated JSON parsing. @@ -208,7 +223,7 @@ def _parse_service_key_once( return service_key if isinstance(service_key, str): try: - return json.loads(service_key) + return _DECODED_JSON.validate_python(json.loads(service_key)) except json.JSONDecodeError: verbose_logger.warning("SAP service key is a string but not valid JSON. Skipping this source.") return None @@ -218,7 +233,7 @@ def _parse_service_key_once( return None -def _resolve_credential_from_service_key(service_key: str | dict | None, cv: CredentialsValue) -> str | None: +def _resolve_credential_from_service_key(service_key: object, cv: CredentialsValue) -> str | None: if service_key is None: return None val: Final = _str_or_none(_get_nested(service_key, (("credentials",) + cv.vcap_key) if cv.vcap_key else (cv.name,))) @@ -253,14 +268,16 @@ def fetch_credentials( """ config: Final = init_conf(profile) - service_key = _parse_service_key_once(service_key or litellm.sap_service_key or os.environ.get(SERVICE_KEY_ENV_VAR)) + parsed_service_key: Final = _parse_service_key_once( + service_key or litellm.sap_service_key or os.environ.get(SERVICE_KEY_ENV_VAR) + ) vcap_service: Final = _get_vcap_service(VCAP_AICORE_SERVICE_NAME) sources: Final = [ Source("kwargs", lambda cv: _str_or_none(kwargs.get(cv.name))), Source( "service key", - lambda cv: _resolve_credential_from_service_key(service_key, cv), + lambda cv: _resolve_credential_from_service_key(parsed_service_key, cv), ), Source( "environment variables", diff --git a/litellm/llms/sap/embed/transformation.py b/litellm/llms/sap/embed/transformation.py index 107fef0b355..a59b7e1e00d 100644 --- a/litellm/llms/sap/embed/transformation.py +++ b/litellm/llms/sap/embed/transformation.py @@ -19,7 +19,7 @@ from litellm.types.llms.openai import AllEmbeddingInputValues from litellm.types.utils import EmbeddingResponse from ..chat.handler import GenAIHubOrchestrationError -from ..credentials import get_token_creator +from ..credentials import AICoreConfiguration, AICoreDeploymentList, get_token_creator class Usage(LiteLLMBaseModel): @@ -102,10 +102,12 @@ class GenAIHubEmbeddingConfig(BaseEmbeddingConfig): def deployment_url(self) -> str: with httpx.Client(timeout=30) as client: valid_deployments: Final = [] - deployments: Final = client.get(join_api_base(self.base_url, "lm/deployments"), headers=self.headers).json() + deployments: Final[AICoreDeploymentList] = client.get( + join_api_base(self.base_url, "lm/deployments"), headers=self.headers + ).json() for deployment in deployments.get("resources", []): if deployment["scenarioId"] == "orchestration": - config_details = client.get( + config_details: AICoreConfiguration = client.get( join_api_base(self.base_url, f"lm/configurations/{deployment['configurationId']}"), headers=self.headers, ).json() diff --git a/litellm/llms/stability/image_edit/transformations.py b/litellm/llms/stability/image_edit/transformations.py index 5d5fad6128e..974996c5e48 100644 --- a/litellm/llms/stability/image_edit/transformations.py +++ b/litellm/llms/stability/image_edit/transformations.py @@ -6,10 +6,12 @@ Handles transformation between OpenAI-compatible format and Stability AI API for API Reference: https://platform.stability.ai/docs/api-reference """ +from collections.abc import Sequence from typing import TYPE_CHECKING, Any, Final, cast import httpx from httpx._types import RequestFiles +from typing_extensions import ReadOnly, TypedDict from litellm.llms.base_llm.image_edit.transformation import BaseImageEditConfig from litellm.secret_managers.main import get_secret_str @@ -30,6 +32,13 @@ else: LiteLLMLoggingObj = Any +class _StabilityImageEditResponse(TypedDict, total=False): + image: ReadOnly[str] + finish_reason: ReadOnly[str] + seed: ReadOnly[int] + errors: ReadOnly[Sequence[str]] + + class StabilityImageEditConfig(BaseImageEditConfig): """ Configuration for Stability AI image edit. @@ -259,7 +268,7 @@ class StabilityImageEditConfig(BaseImageEditConfig): OpenAI expects: {"data": [{"b64_json": "base64..."}], "created": timestamp} """ try: - response_data: Final = raw_response.json() + response_data: Final[_StabilityImageEditResponse] = raw_response.json() except Exception as e: raise self.get_error_class( error_message=f"Error parsing Stability AI response: {e}", diff --git a/litellm/llms/tencent/messages/transformation.py b/litellm/llms/tencent/messages/transformation.py index 1e52bc37d47..cfc9e9ed6aa 100644 --- a/litellm/llms/tencent/messages/transformation.py +++ b/litellm/llms/tencent/messages/transformation.py @@ -5,11 +5,9 @@ Tencent TokenHub exposes an Anthropic-compatible Messages API endpoint alongside its standard OpenAI-compatible chat completions endpoint. """ -from typing import Any - import litellm from litellm.litellm_core_utils.url_utils import join_api_base -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) from litellm.secret_managers.main import get_secret_str @@ -48,7 +46,7 @@ class TencentAnthropicMessagesConfig(AnthropicMessagesConfig): self, headers: dict, model: str, - messages: list[Any], + messages: list[object], optional_params: dict, litellm_params: dict, api_key: str | None = None, diff --git a/litellm/llms/triton/completion/transformation.py b/litellm/llms/triton/completion/transformation.py index b37bbd78f2b..fe0f96cb805 100644 --- a/litellm/llms/triton/completion/transformation.py +++ b/litellm/llms/triton/completion/transformation.py @@ -7,6 +7,7 @@ from collections.abc import AsyncIterator, Iterator from typing import TYPE_CHECKING, Final, Literal from httpx import Headers, Response +from typing_extensions import ReadOnly, TypedDict from litellm.constants import DEFAULT_MAX_TOKENS_FOR_TRITON from litellm.litellm_core_utils.prompt_templates.factory import prompt_factory @@ -32,6 +33,10 @@ if TYPE_CHECKING: from litellm.litellm_core_utils.tokenizer import Encoding as Tokenizer +class _TritonGenerateResponse(TypedDict): + text_output: ReadOnly[str] + + class TritonConfig(BaseConfig): """ Base class for Triton configurations. @@ -220,7 +225,7 @@ class TritonGenerateConfig(TritonConfig): json_mode: bool | None = None, ) -> ModelResponse: try: - raw_response_json: Final = raw_response.json() + raw_response_json: Final[_TritonGenerateResponse] = raw_response.json() except Exception: raise TritonError(message=raw_response.text, status_code=raw_response.status_code) model_response.choices = [Choices(index=0, message=Message(content=raw_response_json["text_output"]))] diff --git a/litellm/llms/triton/embedding/transformation.py b/litellm/llms/triton/embedding/transformation.py index 8c6e0b832fc..3a735f741fd 100644 --- a/litellm/llms/triton/embedding/transformation.py +++ b/litellm/llms/triton/embedding/transformation.py @@ -1,6 +1,8 @@ +from collections.abc import Sequence from typing import Final import httpx +from typing_extensions import NotRequired, ReadOnly, TypedDict from litellm.llms.base_llm.chat.transformation import AllMessageValues, BaseLLMException from litellm.llms.base_llm.embedding.transformation import ( @@ -14,6 +16,16 @@ from litellm.utils import token_counter from ..common_utils import TritonError +class _TritonEmbeddingOutput(TypedDict): + shape: ReadOnly[Sequence[int]] + data: ReadOnly[Sequence[float]] + + +class _TritonEmbeddingResponse(TypedDict): + outputs: ReadOnly[Sequence[_TritonEmbeddingOutput]] + model_name: NotRequired[ReadOnly[str]] + + class TritonEmbeddingConfig(BaseEmbeddingConfig): """ Transformations for triton /embeddings endpoint (This is a trtllm model) @@ -79,7 +91,7 @@ class TritonEmbeddingConfig(BaseEmbeddingConfig): litellm_params: dict = {}, ) -> EmbeddingResponse: try: - raw_response_json: Final = raw_response.json() + raw_response_json: Final[_TritonEmbeddingResponse] = raw_response.json() except Exception: raise TritonError(message=raw_response.text, status_code=raw_response.status_code) @@ -134,7 +146,7 @@ class TritonEmbeddingConfig(BaseEmbeddingConfig): return TritonError(message=error_message, status_code=status_code, headers=headers) @staticmethod - def split_embedding_by_shape(data: list[float], shape: list[int]) -> list[list[float]]: + def split_embedding_by_shape(data: Sequence[float], shape: Sequence[int]) -> list[Sequence[float]]: if len(shape) != 2: raise ValueError("Shape must be of length 2.") embedding_size: Final = shape[1] diff --git a/litellm/llms/vercel_ai_gateway/chat/transformation.py b/litellm/llms/vercel_ai_gateway/chat/transformation.py index 3fc74b6acc1..cf633358a41 100644 --- a/litellm/llms/vercel_ai_gateway/chat/transformation.py +++ b/litellm/llms/vercel_ai_gateway/chat/transformation.py @@ -6,9 +6,11 @@ Calls done in OpenAI/openai.py as Vercel AI Gateway is openai-compatible. Docs: https://vercel.com/docs/ai-gateway """ +from collections.abc import Sequence from typing import Final import httpx +from typing_extensions import ReadOnly, TypedDict import litellm from litellm.litellm_core_utils.url_utils import join_api_base @@ -20,6 +22,14 @@ from ...openai.chat.gpt_transformation import OpenAIGPTConfig from ..common_utils import VercelAIGatewayException +class _VercelAIGatewayModel(TypedDict): + id: ReadOnly[str] + + +class _VercelAIGatewayModelList(TypedDict): + data: ReadOnly[Sequence[_VercelAIGatewayModel]] + + class VercelAIGatewayConfig(OpenAIGPTConfig): @property def custom_llm_provider(self) -> str | None: @@ -99,5 +109,5 @@ class VercelAIGatewayConfig(OpenAIGPTConfig): if response.status_code != 200: raise Exception(f"Failed to get models: {response.text}") - models: Final = response.json()["data"] - return [model["id"] for model in models] + models: Final[_VercelAIGatewayModelList] = response.json() + return [model["id"] for model in models["data"]] diff --git a/litellm/llms/vertex_ai/audio_transcription/gemini_transcribe_transformation.py b/litellm/llms/vertex_ai/audio_transcription/gemini_transcribe_transformation.py index 39d2e9b4c49..26de755d5ca 100644 --- a/litellm/llms/vertex_ai/audio_transcription/gemini_transcribe_transformation.py +++ b/litellm/llms/vertex_ai/audio_transcription/gemini_transcribe_transformation.py @@ -3,6 +3,7 @@ from collections.abc import Mapping, Sequence from typing import Final from httpx import Headers, Response +from pydantic import TypeAdapter import litellm from litellm.exceptions import UnsupportedParamsError @@ -45,6 +46,7 @@ from litellm.types.utils import ( DEFAULT_GEMINI_TRANSCRIBE_LOCATION: Final = "global" AUDIO_MODALITY: Final = "AUDIO" +_DECODED_JSON: Final = TypeAdapter(object) class VertexGeminiAudioTranscriptionConfig(BaseAudioTranscriptionConfig, VertexBase): @@ -177,7 +179,7 @@ class VertexGeminiAudioTranscriptionConfig(BaseAudioTranscriptionConfig, VertexB raw_response: Response, ) -> TranscriptionResponse: try: - response_json: Final = raw_response.json() + response_json: Final = _DECODED_JSON.validate_python(raw_response.json()) except ValueError: raise VertexAIError( status_code=raw_response.status_code, diff --git a/litellm/llms/vertex_ai/batches/transformation.py b/litellm/llms/vertex_ai/batches/transformation.py index a8d02045740..99ef750b5fc 100644 --- a/litellm/llms/vertex_ai/batches/transformation.py +++ b/litellm/llms/vertex_ai/batches/transformation.py @@ -202,7 +202,7 @@ class VertexAIBatchTransformation: @classmethod def transform_vertex_ai_batch_list_response_to_openai_list_response( cls, response: dict[str, Any] - ) -> dict[str, Any]: + ) -> Mapping[str, object]: """ Transforms Vertex AI batch list response into OpenAI-compatible list response. """ diff --git a/litellm/llms/vertex_ai/count_tokens/context.py b/litellm/llms/vertex_ai/count_tokens/context.py index 2579e857bd9..fc7d6545624 100644 --- a/litellm/llms/vertex_ai/count_tokens/context.py +++ b/litellm/llms/vertex_ai/count_tokens/context.py @@ -134,7 +134,7 @@ def vertex_gemini_count_context( def unconvertible_messages_error( messages: Sequence[Mapping[str, object]] | None, messages_format: TokenCountMessagesFormat ) -> VertexGeminiCountContextError | None: - from litellm.llms.anthropic.pass_through.convertible_blocks import unconvertible_blocks_error + from litellm.llms.anthropic.messages.convertible_blocks import unconvertible_blocks_error error_message: Final = unconvertible_blocks_error(messages, messages_format) return None if error_message is None else VertexGeminiCountContextError(error_message=error_message) @@ -145,7 +145,7 @@ def malformed_tool_result_text_count_error( messages_format: TokenCountMessagesFormat, deployment: Mapping[str, object] | None, ) -> VertexGeminiCountContextError | None: - from litellm.llms.anthropic.pass_through.convertible_blocks import malformed_tool_result_count_error + from litellm.llms.anthropic.messages.convertible_blocks import malformed_tool_result_count_error error_message: Final = malformed_tool_result_count_error(messages, messages_format, deployment) return None if error_message is None else VertexGeminiCountContextError(error_message=error_message) @@ -235,7 +235,7 @@ def _view_without_edits( system: object | None, typed_system: str | Sequence[Mapping[str, object]] | None, ) -> InferenceRequestView: - from litellm.llms.anthropic.pass_through.context_management.editors.compact import ( + from litellm.llms.anthropic.messages.context_management.editors.compact import ( apply_client_compaction_block_history, ) @@ -253,9 +253,9 @@ def _view_without_edits( async def _anthropic_inference_view( messages: Sequence[Mapping[str, object]], system: object | None, edits: CountContextEdits ) -> InferenceRequestView | VertexGeminiCountContextError: - from litellm.llms.anthropic.pass_through.adapters.handler import prepare_context_managed_request - from litellm.llms.anthropic.pass_through.context_management import AnthropicContextManagementError - from litellm.llms.anthropic.pass_through.messages.utils import normalize_native_messages + from litellm.llms.anthropic.messages.adapters.handler import prepare_context_managed_request + from litellm.llms.anthropic.messages.context_management import AnthropicContextManagementError + from litellm.llms.anthropic.messages.native.utils import normalize_native_messages typed_system: Final = _typed_system(system) if isinstance(typed_system, VertexGeminiCountContextError): @@ -308,7 +308,7 @@ def _chat_messages( model: str, custom_llm_provider: Literal["vertex_ai", "gemini"], ) -> Sequence[AllMessageValues]: - from litellm.llms.anthropic.pass_through.adapters.transformation import LiteLLMAnthropicMessagesAdapter + from litellm.llms.anthropic.messages.adapters.transformation import LiteLLMAnthropicMessagesAdapter match messages_format: case "anthropic": diff --git a/litellm/llms/vertex_ai/files/handler.py b/litellm/llms/vertex_ai/files/handler.py index f2da04a7db7..54c0fa97550 100644 --- a/litellm/llms/vertex_ai/files/handler.py +++ b/litellm/llms/vertex_ai/files/handler.py @@ -3,7 +3,7 @@ import json import os import time from collections.abc import Coroutine, Mapping -from typing import Any, Final +from typing import Final from urllib.parse import unquote import httpx @@ -197,7 +197,7 @@ class VertexAIFilesHandler(GCSBucketBase): timeout: float | httpx.Timeout, max_retries: int | None, litellm_params: dict | None = None, - ) -> HttpxBinaryResponseContent | Coroutine[Any, Any, HttpxBinaryResponseContent]: + ) -> HttpxBinaryResponseContent | Coroutine[object, object, HttpxBinaryResponseContent]: """ Download file content from GCS bucket for VertexAI files. Supports both sync and async operations. diff --git a/litellm/llms/vertex_ai/files/transformation.py b/litellm/llms/vertex_ai/files/transformation.py index e36aba00293..410f29ef88a 100644 --- a/litellm/llms/vertex_ai/files/transformation.py +++ b/litellm/llms/vertex_ai/files/transformation.py @@ -5,7 +5,7 @@ import json import os import re import time -from collections.abc import AsyncGenerator, Callable, Iterable, Iterator, Mapping +from collections.abc import AsyncGenerator, Callable, Iterable, Iterator, Mapping, Sequence from contextlib import aclosing from dataclasses import dataclass from functools import partial @@ -16,6 +16,7 @@ from urllib.parse import quote, unquote import httpx from httpx import Headers, Response from openai.types.file_deleted import FileDeleted +from pydantic import TypeAdapter from typing_extensions import ReadOnly, Required import litellm @@ -31,7 +32,7 @@ from litellm.litellm_core_utils.cloud_storage_security import ( split_configured_cloud_bucket_name, validate_managed_cloud_file_id, ) -from litellm.litellm_core_utils.core_helpers import drops_unsupported_params +from litellm.litellm_core_utils.core_helpers import as_str_mapping, drops_unsupported_params from litellm.litellm_core_utils.litellm_logging import Logging from litellm.litellm_core_utils.prompt_templates.common_utils import ( extract_file_data, @@ -96,6 +97,7 @@ _JSONL_NEWLINE: Final = b"\n" _BATCH_OUTPUT_FIRST_ROW_PEEK_LIMIT_BYTES: Final = 32 * 1024 * 1024 _PASSTHROUGH_MANAGED_GCS_PREFIX: Final = f"{VERTEX_AI_MANAGED_GCS_PREFIX}passthrough/" _RAW_UPLOAD_CHUNK_BYTES: Final = 1024 * 1024 +_DECODED_JSON: Final = TypeAdapter(object) class _GcsObjectMetadataJson(TypedDict, total=False): @@ -827,7 +829,7 @@ def _iter_openai_jsonl_entries( def _load_openai_jsonl_row(lineno: int, line: str) -> object: try: - return json.loads(line) + return _DECODED_JSON.validate_python(json.loads(line)) except json.JSONDecodeError as e: raise VertexAIError( status_code=400, @@ -967,7 +969,7 @@ class VertexAIFilesConfig(VertexBase, BaseFilesConfig): def _get_gcs_object_name_from_batch_jsonl( self, - openai_jsonl_content: list[dict[str, Any]], + openai_jsonl_content: Sequence[Mapping[str, object]], deployment_model: str | None = None, ) -> str: """ @@ -985,8 +987,9 @@ class VertexAIFilesConfig(VertexBase, BaseFilesConfig): `projects/../locations/../endpoints/` batch job model instead of a nonexistent publisher model. """ - first_entry: Final = openai_jsonl_content[0] - body_model: Final = first_entry["body"].get("model") if isinstance(first_entry.get("body"), dict) else None + body: Final = openai_jsonl_content[0].get("body") + body_fields: Final = as_str_mapping(body) + body_model: Final = body_fields.get("model") if body_fields is not None and isinstance(body, dict) else None jsonl_model: Final = body_model if isinstance(body_model, str) else "" raw_model: Final = deployment_model.removeprefix("vertex_ai/") if deployment_model else jsonl_model return _managed_batch_object_name(raw_model, passthrough=False) diff --git a/litellm/llms/vertex_ai/fine_tuning/handler.py b/litellm/llms/vertex_ai/fine_tuning/handler.py index 40564d536a7..7cb52281a6a 100644 --- a/litellm/llms/vertex_ai/fine_tuning/handler.py +++ b/litellm/llms/vertex_ai/fine_tuning/handler.py @@ -27,6 +27,11 @@ from litellm.types.utils import LiteLLMFineTuningJob _JSON_VALUE: Final = TypeAdapter(object) +def _response_tuning_job(response: httpx.Response) -> ResponseTuningJob: + tuning_job: Final[ResponseTuningJob] = response.json() + return ResponseTuningJob(**tuning_job) + + class VertexFineTuningAPI(VertexLLM): """ Vertex methods to support for batches @@ -187,9 +192,7 @@ class VertexFineTuningAPI(VertexLLM): "got response from creating fine tuning job: %s", _JSON_VALUE.validate_python(response.json()) ) - vertex_response: Final = ResponseTuningJob( - **response.json(), - ) + vertex_response: Final = _response_tuning_job(response) verbose_logger.debug("vertex_response %s", vertex_response) open_ai_response: Final = self.convert_vertex_response_to_open_ai_response(vertex_response) @@ -272,9 +275,7 @@ class VertexFineTuningAPI(VertexLLM): verbose_logger.debug( "got response from creating fine tuning job: %s", _JSON_VALUE.validate_python(response.json()) ) - vertex_response: Final = ResponseTuningJob( - **response.json(), - ) + vertex_response: Final = _response_tuning_job(response) verbose_logger.debug("vertex_response %s", vertex_response) open_ai_response: Final = self.convert_vertex_response_to_open_ai_response(vertex_response) diff --git a/litellm/llms/vertex_ai/gemini/long_decode.py b/litellm/llms/vertex_ai/gemini/long_decode.py index 571fa94d4a5..25aae70a853 100644 --- a/litellm/llms/vertex_ai/gemini/long_decode.py +++ b/litellm/llms/vertex_ai/gemini/long_decode.py @@ -332,7 +332,8 @@ def with_initial_prompt_tokens(usage: Usage, initial_prompt_tokens: int | None) def parse_body(response: httpx.Response) -> GenerateContentResponseBody: try: - return GenerateContentResponseBody(**response.json()) + body: Final[GenerateContentResponseBody] = response.json() + return GenerateContentResponseBody(**body) except Exception as e: raise VertexAIError( message=( diff --git a/litellm/llms/vertex_ai/gemini/transformation.py b/litellm/llms/vertex_ai/gemini/transformation.py index 71bb05ee155..ed86934db63 100644 --- a/litellm/llms/vertex_ai/gemini/transformation.py +++ b/litellm/llms/vertex_ai/gemini/transformation.py @@ -726,6 +726,9 @@ def gemini_convert_messages_with_history( from .vertex_and_google_ai_studio_gemini import VertexGeminiConfig forward_function_call_id: Final = VertexGeminiConfig.forward_gemini_function_call_id(model or "") + supports_multimodal_function_responses: Final = model is None or ( + VertexGeminiConfig.supports_multimodal_function_responses(model) + ) try: while msg_i < len(messages): @@ -1029,6 +1032,7 @@ def gemini_convert_messages_with_history( messages[msg_i], last_message_with_tool_calls, forward_function_call_id=forward_function_call_id, + supports_multimodal_function_responses=supports_multimodal_function_responses, ) msg_i += 1 # Handle both single part and list of parts (for Computer Use with images) diff --git a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py index ce632bc0eef..9acbc9c459c 100644 --- a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py +++ b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py @@ -42,6 +42,7 @@ from litellm.llms.custom_httpx.http_handler import ( get_httpx_client, ) from litellm.types.llms.anthropic import AnthropicThinkingParam +from litellm.types.llms.base import CachedTokensDetails from litellm.types.llms.gemini import BidiGenerateContentServerMessage from litellm.types.llms.openai import ( AllMessageValues, @@ -688,6 +689,10 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig): ) -> bool: return cls._forward_gemini_function_call_id(model) + @classmethod + def supports_multimodal_function_responses(cls, model: str) -> bool: + return cls.is_gemini_3_or_newer(model) + def _supports_penalty_parameters(self, model: str) -> bool: # Gemini 3 models do not support penalty parameters if VertexGeminiConfig._is_gemini_3_or_newer(model): @@ -2364,26 +2369,13 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig): elif modality == "DOCUMENT": cached_text_tokens = (cached_text_tokens or 0) + token_count - ## Calculate non-cached tokens by subtracting cached from total (per modality) - ## This is necessary because promptTokensDetails includes both cached and non-cached tokens - ## See: https://github.com/BerriAI/litellm/issues/18750 - if cached_text_tokens is not None and prompt_text_tokens is not None: - # Explicit caching: subtract cached tokens per modality from cacheTokensDetails - prompt_text_tokens = prompt_text_tokens - cached_text_tokens - elif ( + if ( cached_tokens is not None and prompt_text_tokens is not None and cached_text_tokens is None and "cacheTokensDetails" not in usage_metadata ): - # Implicit caching: only cachedContentTokenCount is provided (no cacheTokensDetails) - # Subtract from text tokens since implicit caching is primarily for text content - # See: https://github.com/BerriAI/litellm/issues/16341 prompt_text_tokens = prompt_text_tokens - cached_tokens - if cached_audio_tokens is not None and prompt_audio_tokens is not None: - prompt_audio_tokens = prompt_audio_tokens - cached_audio_tokens - if cached_image_tokens is not None and prompt_image_tokens is not None: - prompt_image_tokens = prompt_image_tokens - cached_image_tokens if cached_video_tokens is not None and prompt_video_tokens is not None: prompt_video_tokens = prompt_video_tokens - cached_video_tokens @@ -2404,9 +2396,24 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig): billable_text_tokens: Final = ( prompt_text_tokens if prompt_text_tokens is None else prompt_text_tokens + billable_tool_use_prompt_tokens ) + cached_tokens_details_fields: Final = MappingProxyType( + { + key: token_count + for key, token_count in ( + ("text_tokens", cached_text_tokens), + ("audio_tokens", cached_audio_tokens), + ("image_tokens", cached_image_tokens), + ) + if token_count is not None + } + ) + cached_tokens_details: Final = ( + CachedTokensDetails.model_validate(cached_tokens_details_fields) if cached_tokens_details_fields else None + ) prompt_tokens_details = PromptTokensDetailsWrapper( cached_tokens=cached_tokens, + cached_tokens_details=cached_tokens_details, audio_tokens=prompt_audio_tokens, text_tokens=billable_text_tokens, image_tokens=prompt_image_tokens, diff --git a/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_handler.py b/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_handler.py index 0a800497de1..f15c6393cb2 100644 --- a/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_handler.py +++ b/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_handler.py @@ -6,6 +6,7 @@ import json from typing import TYPE_CHECKING, Final, Literal import httpx +from typing_extensions import ReadOnly, TypedDict import litellm from litellm.llms.custom_httpx.http_handler import ( @@ -35,6 +36,11 @@ if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj +class _GeminiFileResource(TypedDict, total=False): + mimeType: ReadOnly[str] + uri: ReadOnly[str] + + class GoogleBatchEmbeddings(VertexLLM): @staticmethod def _flatten_and_detect_file_refs( @@ -74,7 +80,7 @@ class GoogleBatchEmbeddings(VertexLLM): if response.status_code != 200: raise Exception(f"Error fetching file {element}: {response.status_code} {response.text}") - file_data = response.json() + file_data: _GeminiFileResource = response.json() resolved_files[element] = { "mime_type": file_data.get("mimeType", ""), "uri": file_data.get("uri", element), @@ -111,7 +117,7 @@ class GoogleBatchEmbeddings(VertexLLM): if response.status_code != 200: raise Exception(f"Error fetching file {element}: {response.status_code} {response.text}") - file_data = response.json() + file_data: _GeminiFileResource = response.json() resolved_files[element] = { "mime_type": file_data.get("mimeType", ""), "uri": file_data.get("uri", element), diff --git a/litellm/llms/vertex_ai/image_edit/vertex_gemini_transformation.py b/litellm/llms/vertex_ai/image_edit/vertex_gemini_transformation.py index 725a7f39917..6d071363823 100644 --- a/litellm/llms/vertex_ai/image_edit/vertex_gemini_transformation.py +++ b/litellm/llms/vertex_ai/image_edit/vertex_gemini_transformation.py @@ -190,7 +190,7 @@ class VertexAIGeminiImageEditConfig(BaseImageEditConfig, VertexLLM): payload: Final = json.dumps(request_body) empty_files: Final = cast(RequestFiles, []) - return cast(tuple[dict[str, Any], RequestFiles | None], (payload, empty_files)) + return cast(tuple[dict[str, object], RequestFiles | None], (payload, empty_files)) def transform_image_edit_response( self, diff --git a/litellm/llms/vertex_ai/image_edit/vertex_imagen_transformation.py b/litellm/llms/vertex_ai/image_edit/vertex_imagen_transformation.py index 085ff715c30..deaa32f7308 100644 --- a/litellm/llms/vertex_ai/image_edit/vertex_imagen_transformation.py +++ b/litellm/llms/vertex_ai/image_edit/vertex_imagen_transformation.py @@ -9,6 +9,7 @@ from typing import TYPE_CHECKING, Any, Final, cast import httpx from httpx._types import RequestFiles from pydantic import ConfigDict, TypeAdapter +from typing_extensions import ReadOnly, TypedDict import litellm from litellm.constants import DEFAULT_MAX_RECURSE_DEPTH @@ -34,6 +35,10 @@ _JSON_CONTAINER: Final[TypeAdapter[Mapping[str, object] | str | Sequence[object] ) +class _VertexImagenPredictResponse(TypedDict, total=False): + predictions: ReadOnly[Sequence[object]] + + class VertexAIImagenImageEditConfig(BaseImageEditConfig, VertexLLM): """ Vertex AI Imagen Image Edit Configuration @@ -207,7 +212,7 @@ class VertexAIImagenImageEditConfig(BaseImageEditConfig, VertexLLM): ) -> ImageResponse: model_response: Final = ImageResponse() try: - response_json: Final = raw_response.json() + response_json: Final[_VertexImagenPredictResponse] = raw_response.json() except Exception as exc: raise self.get_error_class( error_message=f"Error transforming image edit response: {exc}", diff --git a/litellm/llms/vertex_ai/image_generation/image_generation_handler.py b/litellm/llms/vertex_ai/image_generation/image_generation_handler.py index 7ba7b060991..ec915e10fcd 100644 --- a/litellm/llms/vertex_ai/image_generation/image_generation_handler.py +++ b/litellm/llms/vertex_ai/image_generation/image_generation_handler.py @@ -168,7 +168,7 @@ class VertexImageGeneration(VertexLLM): if response.status_code != 200: raise Exception(f"Error: {response.status_code} {response.text}") - json_response: Final = response.json() + json_response: Final[Mapping[str, object]] = response.json() return self.process_image_generation_response(json_response, model_response, model) async def aimage_generation( @@ -272,7 +272,7 @@ class VertexImageGeneration(VertexLLM): if response.status_code != 200: raise Exception(f"Error: {response.status_code} {response.text}") - json_response: Final = response.json() + json_response: Final[Mapping[str, object]] = response.json() return self.process_image_generation_response(json_response, model_response, model) def is_image_generation_response(self, json_response: dict[str, Any]) -> bool: diff --git a/litellm/llms/vertex_ai/image_generation/vertex_gemini_transformation.py b/litellm/llms/vertex_ai/image_generation/vertex_gemini_transformation.py index 916e25a027e..f6df772dd56 100644 --- a/litellm/llms/vertex_ai/image_generation/vertex_gemini_transformation.py +++ b/litellm/llms/vertex_ai/image_generation/vertex_gemini_transformation.py @@ -33,6 +33,7 @@ if TYPE_CHECKING: else: LiteLLMLoggingObj = Any +_DECODED_JSON: Final = TypeAdapter(object) _JSON_DICT: Final = TypeAdapter(dict[str, object], config=ConfigDict(hide_input_in_errors=True)) _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_input_in_errors=True)) _JSON_CONTAINER: Final[TypeAdapter[Mapping[str, object] | str | Sequence[object]]] = TypeAdapter( @@ -299,7 +300,7 @@ class VertexAIGeminiImageGenerationConfig(BaseImageGenerationConfig, VertexLLM): Transform Gemini image generation response to litellm ImageResponse format """ try: - response_data: Final = raw_response.json() + response_data: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception as e: raise self.get_error_class( error_message=f"Error transforming image generation response: {e}", diff --git a/litellm/llms/vertex_ai/multimodal_embeddings/transformation.py b/litellm/llms/vertex_ai/multimodal_embeddings/transformation.py index da77fa338db..c282ae22ea6 100644 --- a/litellm/llms/vertex_ai/multimodal_embeddings/transformation.py +++ b/litellm/llms/vertex_ai/multimodal_embeddings/transformation.py @@ -208,7 +208,7 @@ class VertexAIMultimodalEmbeddingConfig(BaseEmbeddingConfig): if raw_response.status_code != 200: raise Exception(f"Error: {raw_response.status_code} {raw_response.text}") - _json_response: Final = raw_response.json() + _json_response: Final[MultimodalPredictions] = raw_response.json() if "predictions" not in _json_response: raise InternalServerError( message=f"embedding response does not contain 'predictions', got {_json_response}", diff --git a/litellm/llms/vertex_ai/rag_engine/transformation.py b/litellm/llms/vertex_ai/rag_engine/transformation.py index a34ef519578..61cb083fa4c 100644 --- a/litellm/llms/vertex_ai/rag_engine/transformation.py +++ b/litellm/llms/vertex_ai/rag_engine/transformation.py @@ -4,7 +4,10 @@ Transformation utilities for Vertex AI RAG Engine. Handles transforming LiteLLM's unified formats to Vertex AI RAG Engine API format. """ -from typing import Any, Final +from collections.abc import Mapping +from typing import Final + +from typing_extensions import ReadOnly, TypedDict from litellm._logging import verbose_logger from litellm.constants import DEFAULT_CHUNK_OVERLAP, DEFAULT_CHUNK_SIZE @@ -13,6 +16,15 @@ from litellm.llms.vertex_ai.vertex_llm_base import VertexBase from litellm.types.rag import RAGChunkingStrategy +class VertexRAGChunkingConfig(TypedDict): + chunk_size: ReadOnly[int] + chunk_overlap: ReadOnly[int] + + +class VertexRAGTransformationConfig(TypedDict): + chunking_config: ReadOnly[VertexRAGChunkingConfig] + + class VertexAIRAGTransformation(VertexBase): """ Transformation class for Vertex AI RAG Engine API. @@ -55,7 +67,7 @@ class VertexAIRAGTransformation(VertexBase): def transform_chunking_strategy_to_vertex_format( self, chunking_strategy: RAGChunkingStrategy | None, - ) -> dict[str, Any]: + ) -> VertexRAGTransformationConfig: """ Transform LiteLLM's unified chunking_strategy to Vertex AI RAG format. @@ -105,7 +117,7 @@ class VertexAIRAGTransformation(VertexBase): self, gcs_uri: str, chunking_strategy: RAGChunkingStrategy | None = None, - ) -> dict[str, Any]: + ) -> Mapping[str, object]: """ Build the request payload for importing RAG files. diff --git a/litellm/llms/vertex_ai/rerank/transformation.py b/litellm/llms/vertex_ai/rerank/transformation.py index dce4d2f2a87..398471a7c9b 100644 --- a/litellm/llms/vertex_ai/rerank/transformation.py +++ b/litellm/llms/vertex_ai/rerank/transformation.py @@ -6,10 +6,11 @@ Why separate file? Make it easy to see how transformation works import math import uuid -from collections.abc import Mapping +from collections.abc import Mapping, Sequence from typing import Final import httpx +from typing_extensions import NotRequired, ReadOnly, TypedDict import litellm from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj @@ -27,6 +28,17 @@ from litellm.types.rerank import ( ) +class _VertexRankedRecord(TypedDict): + id: ReadOnly[str] + score: NotRequired[ReadOnly[float]] + title: NotRequired[ReadOnly[str]] + content: NotRequired[ReadOnly[str]] + + +class _VertexRankResponse(TypedDict, total=False): + records: ReadOnly[Sequence[_VertexRankedRecord]] + + class VertexAIRerankConfig(BaseRerankConfig, VertexBase): """ Configuration for Vertex AI Discovery Engine Rerank API @@ -172,7 +184,7 @@ class VertexAIRerankConfig(BaseRerankConfig, VertexBase): Transform Vertex AI Discovery Engine response to Cohere format """ try: - raw_response_json: Final = raw_response.json() + raw_response_json: Final[_VertexRankResponse] = raw_response.json() except Exception as e: raise ValueError(f"Failed to parse response: {e}") diff --git a/litellm/llms/vertex_ai/vertex_ai_partner_models/__init__.py b/litellm/llms/vertex_ai/vertex_ai_partner_models/__init__.py index a9c1e5819f2..991d7e8f1bc 100644 --- a/litellm/llms/vertex_ai/vertex_ai_partner_models/__init__.py +++ b/litellm/llms/vertex_ai/vertex_ai_partner_models/__init__.py @@ -12,7 +12,7 @@ def get_vertex_ai_partner_model_config(model: str, vertex_publisher_or_api_spec: return VertexAIAi21Config() elif vertex_publisher_or_api_spec == "openapi" or vertex_publisher_or_api_spec == "mistralai": - from .llama3.transformation import VertexAILlama3Config + from .llama.transformation import VertexAILlama3Config return VertexAILlama3Config() else: diff --git a/litellm/llms/vertex_ai/vertex_ai_partner_models/ai21/transformation.py b/litellm/llms/vertex_ai/vertex_ai_partner_models/ai21/transformation.py index 45cc5320401..3873a4be0b5 100644 --- a/litellm/llms/vertex_ai/vertex_ai_partner_models/ai21/transformation.py +++ b/litellm/llms/vertex_ai/vertex_ai_partner_models/ai21/transformation.py @@ -1,4 +1,5 @@ import types +from collections.abc import Mapping from typing import Final import litellm @@ -18,16 +19,17 @@ class VertexAIAi21Config(OpenAIGPTConfig): self, max_tokens: int | None = None, ) -> None: - locals_: Final = locals().copy() + locals_: Final[Mapping[str, object]] = types.MappingProxyType(locals().copy()) for key, value in locals_.items(): if key != "self" and value is not None: setattr(self.__class__, key, value) @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not isinstance( v, diff --git a/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/__init__.py b/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/__init__.py new file mode 100644 index 00000000000..9756aa4ec5a --- /dev/null +++ b/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/__init__.py @@ -0,0 +1,3 @@ +from litellm.litellm_core_utils.renamed_package_shim import alias_renamed_package + +__getattr__ = alias_renamed_package(__name__, "litellm.llms.vertex_ai.vertex_ai_partner_models.anthropic.messages") diff --git a/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/transformation.py b/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/messages/transformation.py similarity index 61% rename from litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/transformation.py rename to litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/messages/transformation.py index 5d748ad6e74..6d8eb228786 100644 --- a/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/transformation.py +++ b/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/messages/transformation.py @@ -1,7 +1,8 @@ -from typing import Any, Final +from collections.abc import Mapping, Sequence +from typing import Final from litellm.llms.anthropic.common_utils import AnthropicModelInfo -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, messages_carry_output_config, ) @@ -25,34 +26,92 @@ class VertexAIPartnerModelsAnthropicMessagesConfig(AnthropicMessagesConfig, Vert def should_strip_billing_metadata(self) -> bool: return True + @staticmethod + def _vertex_auth_parameters( + litellm_params: dict[str, object], # mutable-ok: delegates to the existing Vertex parameter readers + ) -> tuple[str | None, str | None, str | None]: + return ( + VertexBase.safe_get_vertex_ai_project(litellm_params), + VertexBase.safe_get_vertex_ai_location(litellm_params), + VertexBase.safe_get_vertex_ai_credentials(litellm_params), + ) + def validate_anthropic_messages_environment( self, - headers: dict, + headers: dict[str, str], model: str, - messages: list[Any], - optional_params: dict, - litellm_params: dict, + messages: Sequence[object], + optional_params: dict[str, object], + litellm_params: dict[str, object], api_key: str | None = None, api_base: str | None = None, - ) -> tuple[dict, str | None]: + ) -> tuple[dict[str, str], str | None]: """ OPTIONAL Validate the environment for the request """ - # Work on a local copy — router shallow-copies litellm_params so the caller's - # headers dict may be the shared deployment extra_headers object. - headers = dict(headers) - vertex_ai_project: Final = VertexBase.safe_get_vertex_ai_project(litellm_params) - vertex_ai_location: Final = VertexBase.safe_get_vertex_ai_location(litellm_params) - - vertex_credentials: Final = VertexBase.safe_get_vertex_ai_credentials(litellm_params) + vertex_ai_project, vertex_ai_location, vertex_credentials = self._vertex_auth_parameters(litellm_params) access_token, project_id = self._ensure_access_token( credentials=vertex_credentials, project_id=vertex_ai_project, custom_llm_provider="vertex_ai", ) - headers["Authorization"] = f"Bearer {access_token}" + return self._finalize_vertex_messages_environment( + headers, + model, + messages, + optional_params, + api_base, + access_token, + project_id, + vertex_ai_project, + vertex_ai_location, + ) + + async def avalidate_anthropic_messages_environment( + self, + headers: dict[str, str], # mutable-ok: mirrors the provider validation contract + model: str, + messages: Sequence[object], + optional_params: dict[str, object], # mutable-ok: mirrors the provider validation contract + litellm_params: dict[str, object], # mutable-ok: mirrors the provider validation contract + api_key: str | None = None, + api_base: str | None = None, + ) -> tuple[dict[str, str], str | None]: # mutable-ok: the caller consumes request headers + vertex_ai_project, vertex_ai_location, vertex_credentials = self._vertex_auth_parameters(litellm_params) + access_token, project_id = await self._ensure_access_token_async( + credentials=vertex_credentials, + project_id=vertex_ai_project, + custom_llm_provider="vertex_ai", + ) + return self._finalize_vertex_messages_environment( + headers, + model, + messages, + optional_params, + api_base, + access_token, + project_id, + vertex_ai_project, + vertex_ai_location, + ) + + def _finalize_vertex_messages_environment( + self, + headers: Mapping[str, str], + model: str, + messages: Sequence[object], + optional_params: dict, # mutable-ok: preserves the existing provider optional-parameter contract + api_base: str | None, + access_token: str, + project_id: str, + vertex_ai_project: str | None, + vertex_ai_location: str | None, + ) -> tuple[dict[str, str], str | None]: # mutable-ok: the caller consumes request headers + # Router shallow-copies litellm_params, so headers may be shared between requests. + request_headers: Final = dict(headers) + request_headers["Authorization"] = f"Bearer {access_token}" api_base = self.get_complete_vertex_url( custom_api_base=api_base, @@ -64,14 +123,14 @@ class VertexAIPartnerModelsAnthropicMessagesConfig(AnthropicMessagesConfig, Vert model=model, ) - headers["content-type"] = "application/json" + request_headers["content-type"] = "application/json" # Add beta headers for Vertex AI tools: Final = optional_params.get("tools", []) beta_values: Final[set[str]] = set() # Get existing beta headers if any - existing_beta: Final = headers.get("anthropic-beta") + existing_beta: Final = request_headers.get("anthropic-beta") if existing_beta: beta_values.update(b.strip() for b in existing_beta.split(",")) @@ -116,9 +175,9 @@ class VertexAIPartnerModelsAnthropicMessagesConfig(AnthropicMessagesConfig, Vert beta_values.add(ANTHROPIC_BETA_HEADER_VALUES.PER_TURN_CONTROL_2026_07_01.value) if beta_values: - headers["anthropic-beta"] = ",".join(beta_values) + request_headers["anthropic-beta"] = ",".join(beta_values) - return headers, api_base + return request_headers, api_base def get_complete_url( self, diff --git a/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/output_params_utils.py b/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/output_params_utils.py index db27427a5be..00c28a728e0 100644 --- a/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/output_params_utils.py +++ b/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/output_params_utils.py @@ -2,7 +2,7 @@ Shared sanitization for ``output_config`` / ``output_format`` on Vertex AI Claude. Lives in its own module so both the chat-completion transformation (``transformation.py``) and the Messages pass-through transformation -(``experimental_pass_through/transformation.py``) can import it without +(``messages/transformation.py``) can import it without forming a cycle through the parent module's heavier imports. CodeQL flagged the ``..transformation`` import path as a potential cyclic diff --git a/litellm/llms/vertex_ai/vertex_ai_partner_models/llama3/transformation.py b/litellm/llms/vertex_ai/vertex_ai_partner_models/llama/transformation.py similarity index 100% rename from litellm/llms/vertex_ai/vertex_ai_partner_models/llama3/transformation.py rename to litellm/llms/vertex_ai/vertex_ai_partner_models/llama/transformation.py diff --git a/litellm/llms/vertex_ai/vertex_embeddings/transformation.py b/litellm/llms/vertex_ai/vertex_embeddings/transformation.py index ddc83bc53a5..96fccf007a5 100644 --- a/litellm/llms/vertex_ai/vertex_embeddings/transformation.py +++ b/litellm/llms/vertex_ai/vertex_embeddings/transformation.py @@ -1,4 +1,5 @@ import types +from collections.abc import Mapping from typing import Final, Literal from pydantic import TypeAdapter @@ -70,16 +71,17 @@ class VertexAITextEmbeddingConfig(LiteLLMBaseModel): | None = None, title: str | None = None, ) -> None: - locals_: Final = locals().copy() + locals_: Final[Mapping[str, object]] = types.MappingProxyType(locals().copy()) for key, value in locals_.items(): if key != "self" and value is not None: setattr(self.__class__, key, value) @classmethod def get_config(cls): + class_attributes: Final[Mapping[str, object]] = types.MappingProxyType(cls.__dict__) return { k: v - for k, v in cls.__dict__.items() + for k, v in class_attributes.items() if not k.startswith("__") and not isinstance( v, diff --git a/litellm/llms/vertex_ai/vertex_llm_base.py b/litellm/llms/vertex_ai/vertex_llm_base.py index 6cff9729189..0cdd92bb071 100644 --- a/litellm/llms/vertex_ai/vertex_llm_base.py +++ b/litellm/llms/vertex_ai/vertex_llm_base.py @@ -7,12 +7,14 @@ Handles Authentication and generating request urls for Vertex AI and Google AI S import asyncio import json import threading +from collections import OrderedDict from collections.abc import Mapping from typing import TYPE_CHECKING, Any, Final, Literal, Protocol from urllib.parse import urlparse import litellm from litellm._logging import verbose_logger +from litellm.constants import DEFAULT_MAX_LRU_CACHE_SIZE from litellm.litellm_core_utils.asyncify import asyncify from litellm.litellm_core_utils.url_utils import join_api_base from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler @@ -70,16 +72,20 @@ class _VertexCredentialsObject(Protocol): def refresh(self, request: object) -> None: ... +_VertexCredentialCacheKey = tuple[str | None, str | None] + + class VertexBase: def __init__(self) -> None: super().__init__() self.access_token: str | None = None self.refresh_token: str | None = None self._credentials: GoogleCredentialsObject | None = None - self._credentials_project_mapping: dict[ - tuple[VERTEX_CREDENTIALS_TYPES | None, str | None], + self._credentials_project_mapping: OrderedDict[ + _VertexCredentialCacheKey, tuple[_VertexCredentialsObject, str | None], - ] = {} + ] = OrderedDict() + self._credentials_cache_lock = threading.RLock() self.project_id: str | None = None self.async_handler: AsyncHTTPHandler | None = None # Per-credential-key asyncio.Lock for single-flight async refresh. @@ -91,10 +97,10 @@ class VertexBase: # each lock; the entry is pruned when the count reaches zero, so the # dict stays bounded even in long-running high-cardinality deployments # without depending on any private asyncio internals. - self._async_refresh_locks: dict[tuple, asyncio.Lock] = {} - self._async_refresh_lock_refcounts: dict[tuple, int] = {} + self._async_refresh_locks: dict[_VertexCredentialCacheKey, asyncio.Lock] = {} + self._async_refresh_lock_refcounts: dict[_VertexCredentialCacheKey, int] = {} # Tracks in-flight background refresh tasks to avoid duplicate refreshes. - self._background_refresh_tasks: dict[tuple, asyncio.Task] = {} + self._background_refresh_tasks: dict[_VertexCredentialCacheKey, asyncio.Task] = {} # Protects the sync get_access_token refresh path. # Use RLock so that the reauthentication retry path (which calls # back into get_access_token while still holding the lock) can @@ -378,7 +384,7 @@ class VertexBase: with self._sync_refresh_lock: credentials.refresh(Request()) - def _acquire_async_refresh_lock(self, credential_cache_key: tuple) -> asyncio.Lock: + def _acquire_async_refresh_lock(self, credential_cache_key: _VertexCredentialCacheKey) -> asyncio.Lock: """Increment the refcount and return the lock for ``credential_cache_key``. Every call must be paired with ``_release_async_refresh_lock`` once the @@ -391,7 +397,7 @@ class VertexBase: ) return lock - def _release_async_refresh_lock(self, credential_cache_key: tuple, lock: asyncio.Lock) -> None: + def _release_async_refresh_lock(self, credential_cache_key: _VertexCredentialCacheKey, lock: asyncio.Lock) -> None: """Decrement the refcount and drop the lock entry when it reaches zero. Must be called only after the caller has released ``lock`` (i.e. once @@ -409,7 +415,7 @@ class VertexBase: def _try_get_cached_token( self, - credential_cache_key: tuple, + credential_cache_key: _VertexCredentialCacheKey, project_id: str | None, ) -> tuple[str, str] | None: """ @@ -432,7 +438,7 @@ class VertexBase: def _try_get_usable_cached_token( self, - credential_cache_key: tuple, + credential_cache_key: _VertexCredentialCacheKey, project_id: str | None, ) -> tuple[str, str, "TokenState", _VertexCredentialsObject, str | None] | None: """ @@ -458,19 +464,37 @@ class VertexBase: return creds.token, resolved_project, token_state, creds, cached_project_id def _unpack_cached_credentials( - self, credential_cache_key: tuple + self, credential_cache_key: _VertexCredentialCacheKey ) -> tuple[_VertexCredentialsObject | None, str | None]: """ Return (credentials, project_id) from the cache, or (None, None) if not cached. Handles both tuple and legacy cache formats. """ - if credential_cache_key not in self._credentials_project_mapping: - return None, None - cached_entry: Final = self._credentials_project_mapping[credential_cache_key] + with self._credentials_cache_lock: + cached_entry: Final = self._credentials_project_mapping.get(credential_cache_key) + if cached_entry is None: + return None, None + self._credentials_project_mapping.move_to_end(credential_cache_key) if isinstance(cached_entry, tuple): return cached_entry return cached_entry, cached_entry.quota_project_id or getattr(cached_entry, "project_id", None) + def _cache_credentials( + self, + credential_cache_key: _VertexCredentialCacheKey, + credentials: _VertexCredentialsObject, + project_id: str | None, + *, + replace: bool = True, + ) -> None: + with self._credentials_cache_lock: + if not replace and credential_cache_key in self._credentials_project_mapping: + return + self._credentials_project_mapping[credential_cache_key] = (credentials, project_id) + self._credentials_project_mapping.move_to_end(credential_cache_key) + while len(self._credentials_project_mapping) > max(0, DEFAULT_MAX_LRU_CACHE_SIZE): + self._credentials_project_mapping.popitem(last=False) + def _get_token_state(self, credentials: _VertexCredentialsObject) -> "TokenState": """ Return the token state using google-auth's TokenState enum. @@ -494,7 +518,7 @@ class VertexBase: self, credentials: VERTEX_CREDENTIALS_TYPES | None, project_id: str | None, - credential_cache_key: tuple, + credential_cache_key: _VertexCredentialCacheKey, ) -> tuple[_VertexCredentialsObject, str | None]: """Load credentials via load_auth (in thread) and cache the result.""" try: @@ -507,17 +531,12 @@ class VertexBase: raise if _credentials is None: raise ValueError("Could not resolve credentials") - self._credentials_project_mapping[credential_cache_key] = ( - _credentials, - credential_project_id, - ) + self._cache_credentials(credential_cache_key, _credentials, credential_project_id) return _credentials, credential_project_id async def _background_refresh_credentials( self, credentials: _VertexCredentialsObject, - credential_cache_key: tuple, - credential_project_id: str | None, ) -> None: """ Refresh credentials in the background without blocking the calling request. @@ -528,25 +547,13 @@ class VertexBase: try: verbose_logger.debug("Background proactive credential refresh") await asyncify(self.refresh_auth)(credentials) - # Only update the cache if it still points at the credentials - # object we just refreshed. The per-key async lock is not held - # here, so a concurrent INVALID path may have already replaced - # this entry (e.g. via _handle_reauthentication_async, which - # creates a fresh credentials object). In that case our write - # would clobber the newer entry with a stale reference. - cached_creds, _ = self._unpack_cached_credentials(credential_cache_key) - if cached_creds is credentials: - self._credentials_project_mapping[credential_cache_key] = ( - credentials, - credential_project_id, - ) except Exception: verbose_logger.debug( "Background credential refresh failed, will retry on next request", exc_info=True, ) - async def _await_in_flight_background_refresh(self, credential_cache_key: tuple) -> None: + async def _await_in_flight_background_refresh(self, credential_cache_key: _VertexCredentialCacheKey) -> None: """Wait for an in-flight background refresh to finish, if any. google-auth's ``Credentials.refresh()`` is not safe to invoke @@ -568,8 +575,7 @@ class VertexBase: def _schedule_background_refresh( self, credentials: _VertexCredentialsObject, - credential_cache_key: tuple, - credential_project_id: str | None, + credential_cache_key: _VertexCredentialCacheKey, ) -> None: """Kick off a single background refresh for ``credential_cache_key``. @@ -581,9 +587,7 @@ class VertexBase: if existing is not None and not existing.done(): return self._background_refresh_tasks.pop(credential_cache_key, None) - task: Final = asyncio.create_task( - self._background_refresh_credentials(credentials, credential_cache_key, credential_project_id) - ) + task: Final = asyncio.create_task(self._background_refresh_credentials(credentials)) def _drop_background_refresh_task(_fut: asyncio.Future[None]) -> None: if self._background_refresh_tasks.get(credential_cache_key) is _fut: @@ -796,7 +800,7 @@ class VertexBase: self, credentials: VERTEX_CREDENTIALS_TYPES | None, project_id: str | None, - credential_cache_key: tuple, + credential_cache_key: _VertexCredentialCacheKey, error: Exception, ) -> tuple[str, str]: """ @@ -822,8 +826,8 @@ class VertexBase: ) # Clear the cached credentials - if credential_cache_key in self._credentials_project_mapping: - del self._credentials_project_mapping[credential_cache_key] + with self._credentials_cache_lock: + self._credentials_project_mapping.pop(credential_cache_key, None) # Retry once with _retry_reauth=True to prevent infinite recursion try: @@ -846,7 +850,7 @@ class VertexBase: self, credentials: VERTEX_CREDENTIALS_TYPES | None, project_id: str | None, - credential_cache_key: tuple, + credential_cache_key: _VertexCredentialCacheKey, error: Exception, ) -> tuple[str, str]: """ @@ -856,7 +860,8 @@ class VertexBase: "Handling async reauthentication for project_id: %s. Clearing cache and retrying once.", project_id ) - self._credentials_project_mapping.pop(credential_cache_key, None) + with self._credentials_cache_lock: + self._credentials_project_mapping.pop(credential_cache_key, None) try: ( @@ -875,10 +880,7 @@ class VertexBase: # references the OLD credentials object we just replaced, and # leaving it would force the next request to do a redundant # refresh/reauth before realizing the cached creds are stale. - self._credentials_project_mapping[resolved_cache_key] = ( - _credentials, - credential_project_id, - ) + self._cache_credentials(resolved_cache_key, _credentials, credential_project_id) if _credentials.token is None or not isinstance(_credentials.token, str): raise ValueError( @@ -924,21 +926,11 @@ class VertexBase: # Convert dict credentials to string for caching cache_credentials: Final = json.dumps(credentials) if isinstance(credentials, dict) else credentials credential_cache_key: Final = (cache_credentials, project_id) - _credentials: _VertexCredentialsObject | None = None - verbose_logger.debug("Checking cached credentials for project_id: %s", project_id) - if credential_cache_key in self._credentials_project_mapping: + _credentials, credential_project_id = self._unpack_cached_credentials(credential_cache_key) + if _credentials is not None: verbose_logger.debug("Cached credentials found for project_id: %s.", project_id) - # Retrieve both credentials and cached project_id - cached_entry: Final = self._credentials_project_mapping[credential_cache_key] - verbose_logger.debug("cached_entry: %s", cached_entry) - if isinstance(cached_entry, tuple): - _credentials, credential_project_id = cached_entry - else: - # Backward compatibility with old cache format - _credentials = cached_entry - credential_project_id = _credentials.quota_project_id or getattr(_credentials, "project_id", None) verbose_logger.debug( "Using cached credentials for project_id: %s", credential_project_id, @@ -963,10 +955,7 @@ class VertexBase: f"Could not resolve credentials - either dynamically or from environment, for project_id: {project_id}" ) # Cache the project_id and credentials from load_auth result (resolved project_id) - self._credentials_project_mapping[credential_cache_key] = ( - _credentials, - credential_project_id, - ) + self._cache_credentials(credential_cache_key, _credentials, credential_project_id) ## VALIDATE CREDENTIALS verbose_logger.debug("Validating credentials") @@ -974,11 +963,7 @@ class VertexBase: project_id = credential_project_id # Update cache with resolved project_id for future lookups resolved_cache_key: Final = (cache_credentials, project_id) - if resolved_cache_key not in self._credentials_project_mapping: - self._credentials_project_mapping[resolved_cache_key] = ( - _credentials, - credential_project_id, - ) + self._cache_credentials(resolved_cache_key, _credentials, credential_project_id, replace=False) # Check if credentials are None before accessing attributes if _credentials is None: @@ -991,10 +976,6 @@ class VertexBase: try: verbose_logger.debug("Credentials expired, refreshing") self.refresh_auth(_credentials) - self._credentials_project_mapping[credential_cache_key] = ( - _credentials, - credential_project_id, - ) except Exception as e: # if refresh fails, it's possible the user has re-authenticated via `gcloud auth application-default login` # in this case, we should try to reload the credentials by clearing the cache and retrying @@ -1043,9 +1024,9 @@ class VertexBase: # callers on the lock just to schedule that refresh. usable: Final = self._try_get_usable_cached_token(credential_cache_key, project_id) if usable is not None: - cached_token, resolved_project, token_state, creds, cached_project_id = usable + cached_token, resolved_project, token_state, creds, _cached_project_id = usable if token_state == TokenState.STALE: - self._schedule_background_refresh(creds, credential_cache_key, cached_project_id) + self._schedule_background_refresh(creds, credential_cache_key) return cached_token, resolved_project # === SLOW PATH (per-key lock) === @@ -1075,10 +1056,7 @@ class VertexBase: # reauth that only repopulated the unresolved key), which # would force the next request through an unnecessary # refresh/reauth cycle. - self._credentials_project_mapping[resolved_cache_key] = ( - _credentials, - credential_project_id, - ) + self._cache_credentials(resolved_cache_key, _credentials, credential_project_id) # Use google-auth's token_state to decide refresh strategy: # - STALE: token is usable but within REFRESH_THRESHOLD (3:45) of @@ -1098,7 +1076,6 @@ class VertexBase: self._schedule_background_refresh( _credentials, credential_cache_key, - credential_project_id, ) return current_token, project_id @@ -1117,10 +1094,6 @@ class VertexBase: try: verbose_logger.debug("Credentials expired, refreshing") await asyncify(self.refresh_auth)(_credentials) - self._credentials_project_mapping[credential_cache_key] = ( - _credentials, - credential_project_id, - ) except Exception as e: if "Reauthentication is needed" in str(e): verbose_logger.debug("Reauthentication needed, clearing cache and retrying") diff --git a/litellm/llms/volcengine/chat/transformation.py b/litellm/llms/volcengine/chat/transformation.py index 52b3242c186..4ccab38e761 100644 --- a/litellm/llms/volcengine/chat/transformation.py +++ b/litellm/llms/volcengine/chat/transformation.py @@ -1,3 +1,4 @@ +from collections.abc import Mapping from typing import Final from litellm.llms.openai_like.chat.transformation import OpenAILikeChatConfig @@ -34,7 +35,7 @@ class VolcEngineChatConfig(OpenAILikeChatConfig): top_p: int | None = None, response_format: dict | None = None, ) -> None: - locals_: Final = locals().copy() + locals_: Final[Mapping[str, object]] = dict(locals()) for key, value in locals_.items(): if key != "self" and value is not None: setattr(self.__class__, key, value) diff --git a/litellm/llms/volcengine/responses/transformation.py b/litellm/llms/volcengine/responses/transformation.py index 74f6182bd89..747ea21e4fb 100644 --- a/litellm/llms/volcengine/responses/transformation.py +++ b/litellm/llms/volcengine/responses/transformation.py @@ -45,6 +45,11 @@ class _EventModelClass(Protocol): def model_validate(self, obj: Mapping[str, object]) -> ResponsesAPIStreamingResponse: ... +class _FieldDefaultCarrier(Protocol): + @property + def default(self) -> object: ... + + class VolcEngineResponsesAPIConfig(OpenAIResponsesAPIConfig): _SUPPORTED_OPTIONAL_PARAMS: list[str] = [ # Doc-listed knobs @@ -430,6 +435,10 @@ class VolcEngineResponsesAPIConfig(OpenAIResponsesAPIConfig): annotation: Final[object] = field.annotation return annotation + @staticmethod + def _field_default(field: _FieldDefaultCarrier) -> object: + return field.default + @staticmethod def _fill_missing_fields(chunk: Mapping[str, object], event_model: object | None) -> Mapping[str, object]: """ @@ -451,7 +460,7 @@ class VolcEngineResponsesAPIConfig(OpenAIResponsesAPIConfig): continue # Explicit default or factory - field_default: object = field.default + field_default: object = VolcEngineResponsesAPIConfig._field_default(field) if field_default is not pyd_fields.PydanticUndefined and field_default is not None: patched[name] = field_default continue diff --git a/litellm/llms/voyage/rerank/transformation.py b/litellm/llms/voyage/rerank/transformation.py index 7fe643870d5..21c6e6a82b9 100644 --- a/litellm/llms/voyage/rerank/transformation.py +++ b/litellm/llms/voyage/rerank/transformation.py @@ -29,6 +29,7 @@ _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_i _JSON_OBJECTS: Final = TypeAdapter(Iterable[Mapping[str, object]], config=ConfigDict(hide_input_in_errors=True)) _OPTIONAL_INT: Final[TypeAdapter[int | None]] = TypeAdapter(int | None) _STR: Final = TypeAdapter(str) +_DECODED_JSON: Final = TypeAdapter(object) class VoyageRerankConfig(BaseRerankConfig): @@ -112,7 +113,7 @@ class VoyageRerankConfig(BaseRerankConfig): logging_obj.post_call(original_response=raw_response.text) try: - _json_response: Final = raw_response.json() + _json_response: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception: raise VoyageError( message=f"Failed to parse response: {raw_response.text}", diff --git a/litellm/llms/watsonx/audio_transcription/transformation.py b/litellm/llms/watsonx/audio_transcription/transformation.py index e5da7dd412f..35fda05c028 100644 --- a/litellm/llms/watsonx/audio_transcription/transformation.py +++ b/litellm/llms/watsonx/audio_transcription/transformation.py @@ -29,6 +29,7 @@ from ...openai.transcriptions.whisper_transformation import ( from ..common_utils import IBMWatsonXMixin _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_input_in_errors=True)) +_DECODED_JSON: Final = TypeAdapter(object) class IBMWatsonXAudioTranscriptionConfig(IBMWatsonXMixin, OpenAIWhisperAudioTranscriptionConfig): @@ -172,7 +173,7 @@ class IBMWatsonXAudioTranscriptionConfig(IBMWatsonXMixin, OpenAIWhisperAudioTran removed before creating the TranscriptionResponse object. """ try: - raw_response_json: Final = raw_response.json() + raw_response_json: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception as e: raise ValueError(f"Error transforming response to json: {e}\nResponse: {raw_response.text}") diff --git a/litellm/llms/watsonx/rerank/transformation.py b/litellm/llms/watsonx/rerank/transformation.py index 591ddda3cbd..87f30483196 100644 --- a/litellm/llms/watsonx/rerank/transformation.py +++ b/litellm/llms/watsonx/rerank/transformation.py @@ -30,6 +30,7 @@ _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_i _JSON_OBJECTS: Final = TypeAdapter(Iterable[Mapping[str, object]], config=ConfigDict(hide_input_in_errors=True)) _OPTIONAL_INT: Final[TypeAdapter[int | None]] = TypeAdapter(int | None) _STR: Final = TypeAdapter(str) +_DECODED_JSON: Final = TypeAdapter(object) class IBMWatsonXRerankConfig(IBMWatsonXMixin, BaseRerankConfig): @@ -170,7 +171,7 @@ class IBMWatsonXRerankConfig(IBMWatsonXMixin, BaseRerankConfig): Transform IBM watsonx.ai rerank response to LiteLLM RerankResponse format """ try: - raw_response_json: Final = raw_response.json() + raw_response_json: Final = _DECODED_JSON.validate_python(raw_response.json()) except Exception as e: raise self.get_error_class( error_message=f"Failed to parse response: {e}", diff --git a/litellm/llms/xai/chat/transformation.py b/litellm/llms/xai/chat/transformation.py index 984b62eeb59..2b943fa4107 100644 --- a/litellm/llms/xai/chat/transformation.py +++ b/litellm/llms/xai/chat/transformation.py @@ -32,6 +32,7 @@ from ...openai.chat.gpt_transformation import ( ) _RESPONSE_BODY: Final = TypeAdapter(dict[object, object], config=ConfigDict(hide_input_in_errors=True)) +_FILTERED_TOOL: Final = TypeAdapter(object) def _usage_restated_from_xai_ticks(usage: Usage | None) -> Usage | None: @@ -204,11 +205,13 @@ class XAIChatConfig(OpenAIGPTConfig): if param == "max_completion_tokens": optional_params["max_tokens"] = value elif param == "tools" and value is not None: - tools = [] - for tool in value: - tool = filter_value_from_dict(tool, "strict") - if tool is not None: - tools.append(tool) + tools = [ + filtered_tool + for filtered_tool in ( + _FILTERED_TOOL.validate_python(filter_value_from_dict(tool, "strict")) for tool in value + ) + if filtered_tool is not None + ] if len(tools) > 0: optional_params["tools"] = tools elif param in supported_openai_params: diff --git a/litellm/llms/xai/cost_calculator.py b/litellm/llms/xai/cost_calculator.py index de2cbf5f9e3..aec535c2086 100644 --- a/litellm/llms/xai/cost_calculator.py +++ b/litellm/llms/xai/cost_calculator.py @@ -120,12 +120,11 @@ def _web_search_cost_per_call_from_model_info(model_info: "ModelInfo") -> float: search_costs: Final = model_info.get("search_context_cost_per_query") if not isinstance(search_costs, Mapping): return _DEFAULT_WEB_SEARCH_COST_PER_CALL - for key in ( - "search_context_size_medium", - "search_context_size_low", - "search_context_size_high", + for value in ( + search_costs.get("search_context_size_medium"), + search_costs.get("search_context_size_low"), + search_costs.get("search_context_size_high"), ): - value = search_costs.get(key) if value is None: continue try: diff --git a/litellm/main.py b/litellm/main.py index 327a7a1c4b5..7775922ea44 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -130,7 +130,7 @@ from litellm.llms.bedrock.common_utils import ( from litellm.llms.bedrock_mantle.chat.claude_transformation import bedrock_mantle_chat_config from litellm.llms.cohere.common_utils import CohereModelInfo from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler, http2_enabled -from litellm.llms.openai.chat.gpt_5_transformation import OpenAIGPT5Config +from litellm.llms.openai.chat.gpt_reasoning_transformation import OpenAIGPT5Config from litellm.llms.openai.common_utils import get_openai_credentials from litellm.llms.openai_like.json_loader import JSONProviderRegistry from litellm.llms.vertex_ai.common_utils import ( @@ -237,7 +237,7 @@ from .llms.azure_ai.anthropic.transformation import azure_anthropic_messages_url from .llms.azure_ai.embed import AzureAIEmbedding from .llms.bedrock.chat import BedrockConverseLLM from .llms.bedrock.chat.converse_transformation import AmazonConverseConfig -from .llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformation import AmazonAnthropicClaudeConfig +from .llms.bedrock.chat.invoke_transformations.anthropic_claude_transformation import AmazonAnthropicClaudeConfig from .llms.bedrock.chat.native_output_fallback import NativeOutputAttemptResult, call_with_native_output_fallback from .llms.bedrock.embed.embedding import BedrockEmbedding from .llms.bedrock.image_edit.handler import BedrockImageEdit @@ -677,7 +677,11 @@ async def acompletion( } if custom_llm_provider is None: _supplemental: Final = cast( # cast-ok: kwargs values are request-scoped objects - "dict[str, object]", {k: kwargs[k] for k in OPTIONAL_KWARGS_KEYS if k in kwargs} + "dict[str, object]", + { + **{k: kwargs[k] for k in OPTIONAL_KWARGS_KEYS | {"provider_specific_header"} if k in kwargs}, + "extra_headers": extra_headers, + }, ) _, custom_llm_provider, _, _ = get_llm_provider( model=model, @@ -802,6 +806,11 @@ def _transcription_response_from_cached_dict(cached_response_dict: Mapping[str, return TranscriptionResponse(**cached_response_dict) +def _text_completion_response_from_cached_dict(cached_response_dict: Mapping[str, object]) -> TextCompletionResponse: + fields: Final = {key: value for key, value in cached_response_dict.items() if key != "stream"} + return TextCompletionResponse(stream=bool(cached_response_dict.get("stream", False)), **fields) + + async def _async_streaming(response, model, custom_llm_provider, args): try: print_verbose(f"received response in _async_streaming: {response}") @@ -2192,6 +2201,27 @@ def _complete_groq(ctx: CompletionDispatchContext) -> _CompletionDispatchResult: ) +def _complete_opencode_go(ctx: CompletionDispatchContext) -> _CompletionDispatchResult: + return base_llm_http_handler.completion( # pyright: ignore[reportUnknownMemberType] # shared legacy handler has untyped request mappings + model=ctx.model, + stream=ctx.stream, + messages=ctx.messages, # pyright: ignore[reportUnknownMemberType, reportUnknownArgumentType] # existing dispatch context carries validated messages + acompletion=ctx.acompletion, + api_base=ctx.api_base, + model_response=ctx.model_response, + optional_params=ctx.optional_params, # pyright: ignore[reportUnknownMemberType] # existing dispatch context carries the mapped provider parameters + litellm_params=ctx.litellm_params, + shared_session=ctx.shared_session, + custom_llm_provider=ctx.custom_llm_provider, + timeout=ctx.timeout, # pyright: ignore[reportArgumentType] # completion normalizes timeout before constructing this context + headers=ctx.headers, # pyright: ignore[reportUnknownMemberType, reportUnknownArgumentType] # legacy context retains caller headers + encoding=_get_encoding(), + api_key=ctx.api_key, + logging_obj=ctx.logging, + client=_dispatch_client_http(ctx), + ) + + def _complete_bedrock_mantle( ctx: CompletionDispatchContext, ) -> _CompletionDispatchResult: @@ -3560,7 +3590,7 @@ def _complete_nadir(ctx: CompletionDispatchContext) -> _CompletionDispatchResult encoding=_get_encoding(), api_key=api_key, logging_obj=ctx.logging, - client=ctx.client, + client=_dispatch_client_http(ctx), ) ctx.logging.post_call(input=ctx.messages, api_key=api_key, original_response=response) @@ -4197,6 +4227,7 @@ _REQUEST_KWARGS_ADAPTER: Final = TypeAdapter(Mapping[str, object]) _MODEL_INFO_ADAPTER: Final = TypeAdapter(Mapping[str, object]) _PROVIDER_ROUTING_HINTS: Final = TypeAdapter(ProviderRoutingHints) _BASE_URL_HINT: Final = TypeAdapter(BaseUrlRoutingHint) +_OPAQUE_VALUE_ADAPTER: Final = TypeAdapter(object) _AWS_BEDROCK_CLIENT_CREDENTIAL_KEYS: Final = ( @@ -4741,7 +4772,7 @@ def _complete_petals(ctx: CompletionDispatchContext) -> _CompletionDispatchResul ) if stream is True: ## [BETA] # Fake streaming for petals - resp_string: Final = model_response["choices"][0]["message"]["content"] + resp_string: Final = _OPAQUE_VALUE_ADAPTER.validate_python(model_response["choices"][0]["message"]["content"]) return CustomStreamWrapper( resp_string, model, @@ -5651,7 +5682,10 @@ def completion( if deployment_id is not None: # azure llms model = deployment_id custom_llm_provider = "azure" - _supplemental_provider_params: Final = {k: kwargs[k] for k in OPTIONAL_KWARGS_KEYS if k in kwargs} + _supplemental_provider_params: Final = { + **{k: kwargs[k] for k in OPTIONAL_KWARGS_KEYS | {"provider_specific_header"} if k in kwargs}, + "extra_headers": extra_headers, + } model, custom_llm_provider, dynamic_api_key, api_base = get_llm_provider( model=model, custom_llm_provider=custom_llm_provider, @@ -5971,6 +6005,7 @@ def completion( tpm=kwargs.get("tpm"), rpm=kwargs.get("rpm"), use_xai_oauth=kwargs.get("use_xai_oauth", False), + chatgpt_auth_file=routing_kwargs.get("chatgpt_auth_file"), gigachat_scope=kwargs.get("gigachat_scope"), gigachat_auth_url=kwargs.get("gigachat_auth_url"), gigachat_access_token=kwargs.get("gigachat_access_token"), @@ -6192,6 +6227,10 @@ def completion( response = _complete_xai(_dispatch_ctx) elif custom_llm_provider == "groq": response = _complete_groq(_dispatch_ctx) + elif custom_llm_provider == "opencode_go": + response = _complete_opencode_go( # rebind-ok: common dispatcher finalizes the selected provider result + _dispatch_ctx + ) elif custom_llm_provider == "bedrock_mantle": response = _complete_bedrock_mantle(_dispatch_ctx) elif custom_llm_provider == "a2a": @@ -6287,7 +6326,7 @@ def completion( response = _complete_vercel_ai_gateway(_dispatch_ctx) elif custom_llm_provider == "palm": raise ValueError( - "Palm was decommisioned on October 2024. Please use the `gemini/` route for Gemini Google AI Studio Models. Announcement: https://ai.google.dev/palm_docs/palm?hl=en" + "Palm was decommissioned on October 2024. Please use the `gemini/` route for Gemini Google AI Studio Models. Announcement: https://ai.google.dev/palm_docs/palm?hl=en" ) elif custom_llm_provider == "vertex_ai_beta" or custom_llm_provider == "gemini": response = _complete_vertex_ai_beta(_dispatch_ctx) @@ -7719,7 +7758,7 @@ async def atext_completion(*args, **kwargs) -> TextCompletionResponse | TextComp init_response: Final = await loop.run_in_executor(None, func_with_context) if isinstance(init_response, dict) or isinstance(init_response, TextCompletionResponse): ## CACHING SCENARIO if isinstance(init_response, dict): - response = TextCompletionResponse(**init_response) + response = _text_completion_response_from_cached_dict(init_response) else: response = init_response elif asyncio.iscoroutine(init_response): @@ -7899,7 +7938,6 @@ def text_completion( tokenizer: Final = get_encoding("p50k_base") ## if it's a 2d list - each element in the list is a text_completion() request if len(prompt) > 0 and isinstance(prompt[0], list): - responses: Final = [None for x in prompt] # init responses def process_prompt(i, individual_prompt): decoded_prompt: Final = tokenizer.decode(individual_prompt) @@ -7916,16 +7954,16 @@ def text_completion( text_completion_response["object"] = "text_completion" text_completion_response["created"] = response.get("created", None) text_completion_response["model"] = response.get("model", None) - return response["choices"][0] + return response.choices[0] with concurrent.futures.ThreadPoolExecutor() as executor: completed_futures: Final = [ executor.submit(process_prompt, i, individual_prompt) for i, individual_prompt in enumerate(prompt) ] - for i, future in enumerate(concurrent.futures.as_completed(completed_futures)): - responses[i] = future.result() - text_completion_response.choices = responses + text_completion_response.choices = [ + future.result() for future in concurrent.futures.as_completed(completed_futures) + ] return text_completion_response # else: @@ -9110,6 +9148,7 @@ async def ahealth_check( custom_llm_provider=custom_llm_provider_from_params, api_base=api_base_from_params, api_key=api_key_from_params, + litellm_params=GenericLiteLLMParams(**model_params), ) model_params["cache"] = {"no-cache": True} # don't used cached responses for making health check calls diff --git a/litellm/experimental_mcp_client/Readme.md b/litellm/mcp_client/Readme.md similarity index 89% rename from litellm/experimental_mcp_client/Readme.md rename to litellm/mcp_client/Readme.md index 3385a37cf69..b6008591dd7 100644 --- a/litellm/experimental_mcp_client/Readme.md +++ b/litellm/mcp_client/Readme.md @@ -5,13 +5,13 @@ LiteLLM MCP Client allows you to use MCP tools with LiteLLM Install the optional dependencies with `pip install 'litellm[mcp]'`, then use the existing public imports: ```python -from litellm.experimental_mcp_client import call_openai_tool, load_mcp_tools -from litellm.experimental_mcp_client.client import MCPClient +from litellm.mcp_client import call_openai_tool, load_mcp_tools +from litellm.mcp_client.client import MCPClient client = MCPClient(server_url="https://mcp.example.com/mcp") ``` -Core `import litellm` works without the MCP extra. Importing the experimental MCP client without its MCP or HTTPX2 dependency raises an error with this installation command +`litellm.experimental_mcp_client` is a deprecated alias of `litellm.mcp_client` that warns on import. Core `import litellm` works without the MCP extra. Importing the MCP client without its MCP or HTTPX2 dependency raises an error with this installation command ## MCP Python SDK compatibility diff --git a/litellm/mcp_client/__init__.py b/litellm/mcp_client/__init__.py new file mode 100644 index 00000000000..7a3917a50ea --- /dev/null +++ b/litellm/mcp_client/__init__.py @@ -0,0 +1,8 @@ +try: + from .tools import call_openai_tool, load_mcp_tools +except ModuleNotFoundError as exc: + if exc.name not in ("mcp", "httpx2"): + raise + raise ImportError("MCP client dependencies are missing. Install them with: pip install 'litellm[mcp]'") from exc + +__all__ = ["call_openai_tool", "load_mcp_tools"] diff --git a/litellm/experimental_mcp_client/client.py b/litellm/mcp_client/client.py similarity index 98% rename from litellm/experimental_mcp_client/client.py rename to litellm/mcp_client/client.py index 79887e4ab99..107b7155303 100644 --- a/litellm/experimental_mcp_client/client.py +++ b/litellm/mcp_client/client.py @@ -100,11 +100,11 @@ from litellm.constants import ( MCP_TOOL_LISTING_MAX_PAGES, MCP_TOOL_LISTING_TIMEOUT, ) -from litellm.experimental_mcp_client.tools import list_tools_with_pagination from litellm.llms.custom_httpx.http_handler import get_ssl_configuration -from litellm.proxy._experimental.mcp_server.mcp_context import get_active_mcp_request_ctx -from litellm.proxy._experimental.mcp_server.mcp_debug import capture_upstream_error_response -from litellm.proxy._experimental.mcp_server.result_conversion import ( +from litellm.mcp_client.tools import list_tools_with_pagination +from litellm.proxy.mcp_server.mcp_context import get_active_mcp_request_ctx +from litellm.proxy.mcp_server.mcp_debug import capture_upstream_error_response +from litellm.proxy.mcp_server.result_conversion import ( age_freshness, aggregate_freshness, error_text_result, @@ -125,14 +125,14 @@ from litellm.types.mcp import ( ) if TYPE_CHECKING: - from litellm.proxy._experimental.mcp_server.contracts import CatalogListRequest, CatalogListResult - from litellm.proxy._experimental.mcp_server.legacy_callbacks import ElicitationCallback + from litellm.proxy.mcp_server.contracts import CatalogListRequest, CatalogListResult + from litellm.proxy.mcp_server.legacy_callbacks import ElicitationCallback def _mcp_response_hooks() -> tuple[Callable[[httpx2.Response], Awaitable[None]], ...]: if get_active_mcp_request_ctx() is None: return (capture_upstream_error_response,) - from litellm.proxy._experimental.mcp_server.legacy_callbacks import ( + from litellm.proxy.mcp_server.legacy_callbacks import ( get_scope_response, record_upstream_tool_authorization, ) @@ -564,7 +564,7 @@ class MCPClient: return self._hash_discovery_auth(await self.prepare_request_auth(), self._aws_identity()) async def subscription_auth_fingerprint(self) -> str: - from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.client_credentials import ( ClientCredentialsBearerAuth, ) @@ -1125,8 +1125,8 @@ class MCPClient: request_state: str | None, allow_input_required: bool, ) -> TSessionResult | InputRequiredResult: - from litellm.proxy._experimental.mcp_server.contracts import ClientInteraction - from litellm.proxy._experimental.mcp_server.interactions import LegacyClientInteraction, ModernClientInteraction + from litellm.proxy.mcp_server.contracts import ClientInteraction + from litellm.proxy.mcp_server.interactions import LegacyClientInteraction, ModernClientInteraction with anyio.fail_after(self.timeout): first: Final = await request(input_responses, request_state) diff --git a/litellm/experimental_mcp_client/tools.py b/litellm/mcp_client/tools.py similarity index 94% rename from litellm/experimental_mcp_client/tools.py rename to litellm/mcp_client/tools.py index 8015b065899..4f204b3629e 100644 --- a/litellm/experimental_mcp_client/tools.py +++ b/litellm/mcp_client/tools.py @@ -10,6 +10,7 @@ from mcp.types import Tool as MCPTool from openai.types.chat import ChatCompletionToolParam from openai.types.responses.function_tool_param import FunctionToolParam from openai.types.shared_params.function_definition import FunctionDefinition +from pydantic import TypeAdapter from litellm._logging import verbose_logger from litellm.constants import ( @@ -20,6 +21,8 @@ from litellm.constants import ( from litellm.types.llms.anthropic import AnthropicMessagesTool from litellm.types.utils import ChatCompletionMessageToolCall +_DECODED_JSON: Final = TypeAdapter(object) + ######################################################## # List MCP Tool functions @@ -200,15 +203,18 @@ async def call_mcp_tool( return tool_result +def _decode_json_arguments(arguments: str) -> object: + try: + return _DECODED_JSON.validate_python(json.loads(arguments)) + except json.JSONDecodeError: + return {} + + def _get_function_arguments(function: FunctionDefinition) -> dict: """Helper to safely get and parse function arguments.""" - arguments = function.get("arguments", {}) - if isinstance(arguments, str): - try: - arguments = json.loads(arguments) - except json.JSONDecodeError: - arguments = {} - return arguments if isinstance(arguments, dict) else {} + arguments: Final = function.get("arguments", {}) + decoded: Final = _decode_json_arguments(arguments) if isinstance(arguments, str) else arguments + return decoded if isinstance(decoded, dict) else {} def transform_openai_tool_call_request_to_mcp_tool_call_request( diff --git a/litellm/messages/dispatch.py b/litellm/messages/dispatch.py index 2e9d6a77a62..0e2fc2e3dcb 100644 --- a/litellm/messages/dispatch.py +++ b/litellm/messages/dispatch.py @@ -5,7 +5,7 @@ from typing import Final, TypeAlias, cast # noqa: TID251 # native binding sele from litellm.exceptions import BadRequestError from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider -from litellm.llms.anthropic.pass_through.messages import handler as main +from litellm.llms.anthropic.messages.native import handler as main from litellm.rust_bridge import detectors from litellm.rust_bridge.catalog import Feature, Route, RouteContext, Target from litellm.rust_bridge.dispatch import PublicDispatch diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index 3edb30b4218..39500330096 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -9,9 +9,8 @@ "input_cost_per_audio_token": 0.0, "input_cost_per_token": 0.0, "litellm_provider": "one of https://docs.litellm.ai/docs/providers", - "max_input_tokens": "max input tokens, if the provider specifies it. if not default to max_tokens", - "max_output_tokens": "max output tokens, if the provider specifies it. if not default to max_tokens", - "max_tokens": "LEGACY parameter. set to max_output_tokens if provider specifies it. IF not set to max_input_tokens, if provider specifies it.", + "max_input_tokens": "max input tokens, if the provider specifies it", + "max_output_tokens": "max output tokens, if the provider specifies it", "mode": "one of: chat, embedding, completion, image_generation, audio_transcription, audio_speech, image_generation, moderation, rerank, search", "output_cost_per_reasoning_token": 0.0, "output_cost_per_token": 0.0, @@ -49,37 +48,132 @@ "1024-x-1024/50-steps/stability.stable-diffusion-xl-v1": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.04 }, "1024-x-1024/max-steps/stability.stable-diffusion-xl-v1": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.08 }, "512-x-512/50-steps/stability.stable-diffusion-xl-v0": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.018 }, "512-x-512/max-steps/stability.stable-diffusion-xl-v0": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.036 }, + "abliteration/abliterated-model": { + "cache_read_input_token_cost": 1e-07, + "input_cost_per_token": 1e-06, + "litellm_provider": "abliteration", + "max_input_tokens": 262144, + "max_output_tokens": 262134, + "mode": "chat", + "output_cost_per_token": 3e-06, + "source": "https://abliteration.ai/pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": true, + "reasoning_effort_levels": [ + "none", + "minimal", + "low", + "medium", + "high", + "xhigh", + "max" + ] + }, + "abliteration/abliterated-model-large": { + "cache_read_input_token_cost": 3e-07, + "input_cost_per_token": 3e-06, + "litellm_provider": "abliteration", + "max_input_tokens": 1000000, + "max_output_tokens": 999990, + "mode": "chat", + "output_cost_per_token": 5e-06, + "source": "https://abliteration.ai/pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false, + "reasoning_effort_levels": [ + "none", + "minimal", + "low", + "medium", + "high", + "xhigh", + "max" + ] + }, + "abliteration/abliterated-model-large-v2": { + "cache_read_input_token_cost": 3e-07, + "input_cost_per_token": 3e-06, + "litellm_provider": "abliteration", + "max_input_tokens": 1000000, + "max_output_tokens": 999990, + "mode": "chat", + "output_cost_per_token": 5e-06, + "source": "https://abliteration.ai/pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_none_reasoning_effort": false, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false, + "reasoning_effort_levels": [ + "minimal", + "low", + "medium", + "high", + "xhigh", + "max" + ] + }, + "abliteration/abliterated-model-large-flash": { + "cache_read_input_token_cost": 1e-07, + "input_cost_per_token": 1e-06, + "litellm_provider": "abliteration", + "max_input_tokens": 1048576, + "max_output_tokens": 262144, + "mode": "chat", + "output_cost_per_token": 2e-06, + "source": "https://abliteration.ai/pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": true, + "reasoning_effort_levels": [ + "none", + "minimal", + "low", + "medium", + "high", + "xhigh", + "max" + ] + }, "ai21.j2-mid-v1": { "input_cost_per_token": 1.25e-05, "litellm_provider": "bedrock", "max_input_tokens": 8191, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 1.25e-05, "source": "https://aws.amazon.com/bedrock/pricing/" @@ -89,7 +183,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8191, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 1.88e-05, "source": "https://aws.amazon.com/bedrock/pricing/" @@ -100,7 +193,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 256000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-ai21-labs-jamba-1-5-large.md" @@ -111,7 +203,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 256000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-ai21-labs-jamba-1-5-mini.md" @@ -121,7 +212,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 70000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7e-07, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -298,7 +388,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-writer-palmyra-x4.md", @@ -311,7 +400,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-writer-palmyra-x5.md", @@ -324,7 +412,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-writer-palmyra-x4.md", @@ -337,7 +424,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-writer-palmyra-x5.md", @@ -352,7 +438,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -368,7 +453,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 2.4e-07, "output_cost_per_token_batches": 1.2e-07, @@ -389,7 +473,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 1.25e-06, @@ -414,7 +497,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -435,7 +517,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 3.311e-06, "supports_function_calling": true, @@ -455,7 +536,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.1e-05, "source": "https://aws.amazon.com/nova/pricing/", @@ -474,7 +554,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 3.597e-06, "supports_function_calling": true, @@ -494,7 +573,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.1e-05, "source": "https://aws.amazon.com/nova/pricing/", @@ -518,7 +596,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.75e-06, "output_cost_per_token_batches": 1.375e-06, @@ -544,7 +621,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_batches": 5.5e-06, @@ -562,7 +638,6 @@ "amazon.nova-2-multimodal-embeddings-v1:0": { "litellm_provider": "bedrock", "max_input_tokens": 8172, - "max_tokens": 8172, "mode": "embedding", "input_cost_per_token": 1.35e-07, "input_cost_per_image": 6e-05, @@ -583,7 +658,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 1.4e-07, "output_cost_per_token_batches": 7e-08, @@ -602,7 +676,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 1.25e-05, "output_cost_per_token_batches": 6.25e-06, @@ -626,7 +699,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 3.2e-06, "output_cost_per_token_batches": 1.6e-06, @@ -644,9 +716,12 @@ "input_cost_per_audio_token": 3e-06, "input_cost_per_token": 3.3e-07, "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 64000, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2.75e-06, + "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-amazon-nova-2-sonic.md", "supports_audio_input": true, "supports_audio_output": true }, @@ -656,7 +731,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "rerank", "output_cost_per_token": 0.0 }, @@ -665,7 +739,6 @@ "input_cost_per_token": 8e-07, "litellm_provider": "bedrock", "max_input_tokens": 128, - "max_tokens": 128, "metadata": { "notes": "'supports_image_input' is a deprecated field. Use 'supports_embedding_image_input' instead." }, @@ -680,7 +753,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "bedrock", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536 @@ -689,7 +761,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "bedrock", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536 @@ -698,7 +769,6 @@ "input_cost_per_token": 2e-08, "litellm_provider": "bedrock", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -736,7 +806,6 @@ "input_cost_per_image": 0.0001, "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -751,7 +820,6 @@ "input_cost_per_image": 0.0001, "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -766,7 +834,6 @@ "input_cost_per_image": 0.0001, "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -780,7 +847,6 @@ "input_cost_per_image": 0.0001, "litellm_provider": "bedrock", "max_input_tokens": 500, - "max_tokens": 500, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 512, @@ -794,7 +860,6 @@ "input_cost_per_image": 0.0001, "litellm_provider": "bedrock", "max_input_tokens": 500, - "max_tokens": 500, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 512, @@ -808,7 +873,6 @@ "input_cost_per_image": 0.0001, "litellm_provider": "bedrock", "max_input_tokens": 500, - "max_tokens": 500, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 512, @@ -856,7 +920,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 42000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 6e-07 }, @@ -865,7 +928,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 42000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 2e-07 }, @@ -874,7 +936,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 42000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.5e-06 }, @@ -885,7 +946,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4e-06, "supports_assistant_prefill": true, @@ -905,7 +965,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "source": "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonBedrockFoundationModels/current/index.json", @@ -937,7 +996,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "source": "https://aws.amazon.com/about-aws/whats-new/2025/10/claude-4-5-haiku-anthropic-amazon-bedrock", @@ -960,7 +1018,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -978,7 +1035,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -997,7 +1053,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.8e-05, "supports_assistant_prefill": true, @@ -1017,7 +1072,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -1035,7 +1089,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_function_calling": true, @@ -1050,7 +1103,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-06, "supports_tool_choice": true @@ -1063,7 +1115,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "search_context_cost_per_query": { @@ -1093,7 +1144,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "search_context_cost_per_query": { @@ -1121,7 +1171,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -1160,7 +1209,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -1200,7 +1248,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -1240,7 +1287,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -1280,7 +1326,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -1320,7 +1365,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -1360,7 +1404,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -1401,7 +1444,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "thinking_always_on": true, "supports_function_calling": true, @@ -1423,7 +1465,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -1466,7 +1507,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -1509,7 +1549,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -1552,7 +1591,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -1592,7 +1630,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "search_context_cost_per_query": { @@ -1635,7 +1672,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "search_context_cost_per_query": { @@ -1674,7 +1710,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "search_context_cost_per_query": { @@ -1717,7 +1752,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "search_context_cost_per_query": { @@ -1756,7 +1790,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-05, "search_context_cost_per_query": { @@ -1799,7 +1832,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-05, "search_context_cost_per_query": { @@ -1838,7 +1870,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-05, "search_context_cost_per_query": { @@ -1876,7 +1907,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-05, "search_context_cost_per_query": { @@ -1918,7 +1948,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -1961,7 +1990,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "search_context_cost_per_query": { @@ -2006,7 +2034,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -2049,7 +2076,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "search_context_cost_per_query": { @@ -2094,7 +2120,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -2137,7 +2162,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-05, "search_context_cost_per_query": { @@ -2182,7 +2206,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -2225,7 +2248,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-05, "search_context_cost_per_query": { @@ -2265,7 +2287,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -2308,7 +2329,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-05, "search_context_cost_per_query": { @@ -2353,7 +2373,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -2391,7 +2410,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-05, "search_context_cost_per_query": { @@ -2431,7 +2449,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -2476,7 +2493,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -2521,7 +2537,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -2566,7 +2581,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -2611,7 +2625,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -2656,7 +2669,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -2699,7 +2711,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -2741,7 +2752,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "search_context_cost_per_query": { @@ -2786,7 +2796,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "search_context_cost_per_query": { @@ -2831,7 +2840,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "search_context_cost_per_query": { @@ -2876,7 +2884,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "search_context_cost_per_query": { @@ -2921,7 +2928,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "search_context_cost_per_query": { @@ -2966,7 +2972,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "search_context_cost_per_query": { @@ -3007,7 +3012,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -3046,7 +3050,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -3085,7 +3088,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.65e-05, "search_context_cost_per_query": { @@ -3124,7 +3126,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.65e-05, "search_context_cost_per_query": { @@ -3163,7 +3164,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.65e-05, "search_context_cost_per_query": { @@ -3202,7 +3202,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.65e-05, "search_context_cost_per_query": { @@ -3242,7 +3241,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -3282,7 +3280,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -3315,7 +3312,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05 }, @@ -3324,7 +3320,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_tool_choice": true @@ -3334,7 +3329,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-07 }, @@ -3343,7 +3337,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1e-06 }, @@ -3352,7 +3345,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1e-06, "source": "https://docs.anyscale.com/preview/endpoints/text-generation/supported-models/codellama-CodeLlama-70b-Instruct-hf" @@ -3362,7 +3354,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://docs.anyscale.com/preview/endpoints/text-generation/supported-models/google-gemma-7b-it" @@ -3372,7 +3363,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.5e-07 }, @@ -3381,7 +3371,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1e-06 }, @@ -3390,7 +3379,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-07 }, @@ -3399,7 +3387,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1e-06, "source": "https://docs.anyscale.com/preview/endpoints/text-generation/supported-models/meta-llama-Meta-Llama-3-70B-Instruct" @@ -3409,7 +3396,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://docs.anyscale.com/preview/endpoints/text-generation/supported-models/meta-llama-Meta-Llama-3-8B-Instruct" @@ -3419,7 +3405,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://docs.anyscale.com/preview/endpoints/text-generation/supported-models/mistralai-Mistral-7B-Instruct-v0.1", @@ -3430,7 +3415,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 65536, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://docs.anyscale.com/preview/endpoints/text-generation/supported-models/mistralai-Mixtral-8x22B-Instruct-v0.1", @@ -3441,7 +3425,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://docs.anyscale.com/preview/endpoints/text-generation/supported-models/mistralai-Mixtral-8x7B-Instruct-v0.1", @@ -3453,7 +3436,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 2.52e-07, "supports_function_calling": true, @@ -3469,7 +3451,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 1.48e-07, "supports_function_calling": true, @@ -3485,7 +3466,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 3.36e-06, "output_cost_per_token_flex": 1.68e-06, @@ -3504,7 +3484,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5.5e-06, "source": "https://aws.amazon.com/about-aws/whats-new/2025/10/claude-4-5-haiku-anthropic-amazon-bedrock", @@ -3539,7 +3518,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -3591,7 +3569,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.65e-05, "search_context_cost_per_query": { @@ -3624,7 +3601,6 @@ "input_cost_per_token": 1.1e-07, "litellm_provider": "azure", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/" @@ -3636,7 +3612,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 6e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -3666,7 +3641,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -3681,7 +3655,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "supports_assistant_prefill": true, @@ -3705,7 +3678,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "supports_assistant_prefill": true, @@ -3730,7 +3702,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -3761,7 +3732,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -3793,7 +3763,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -3826,7 +3795,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -3864,7 +3832,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -3895,7 +3862,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -3934,7 +3900,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -3967,7 +3932,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -3992,7 +3956,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "search_context_cost_per_query": { @@ -4026,7 +3989,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": false, @@ -4048,7 +4010,6 @@ "litellm_provider": "azure", "max_input_tokens": 8192, "max_output_tokens": 1024, - "max_tokens": 1024, "mode": "chat", "output_cost_per_token": 1.2e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -4083,7 +4044,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", "supports_function_calling": true, @@ -4101,7 +4061,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_above_272k_tokens": 7.5e-05, @@ -4150,7 +4109,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_above_272k_tokens": 7.5e-07, @@ -4199,7 +4157,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -4248,7 +4205,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -4300,7 +4256,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "output_cost_per_token_above_272k_tokens": 4.5e-05, @@ -4339,9 +4294,8 @@ "deprecation_date": "2027-05-18", "input_cost_per_token": 5e-06, "litellm_provider": "azure_ai", - "max_input_tokens": 272000, + "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "source": "https://azure.microsoft.com/en-us/pricing/details/cognitive-services/openai-service/", @@ -4391,7 +4345,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 6e-06, "source": "https://azure.microsoft.com/en-us/pricing/details/cognitive-services/openai-service/", @@ -4435,7 +4388,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "output_cost_per_token_above_272k_tokens": 4.5e-05, @@ -4482,7 +4434,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "output_cost_per_token_above_272k_tokens": 4.5e-05, @@ -4529,7 +4480,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_above_272k_tokens": 2.25e-05, @@ -4577,7 +4527,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_above_272k_tokens": 2.25e-05, @@ -4625,7 +4574,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -4671,7 +4619,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -4713,7 +4660,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.5e-06, "output_cost_per_token_priority": 9e-06, @@ -4755,7 +4701,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.5e-06, "output_cost_per_token_priority": 9e-06, @@ -4797,7 +4742,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.25e-06, "output_cost_per_token_priority": 2.5e-06, @@ -4839,7 +4783,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.25e-06, "output_cost_per_token_priority": 2.5e-06, @@ -4879,7 +4822,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 200000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://azure.microsoft.com/en-us/pricing/details/ai-foundry-models/aoai/", "comment": "Flat cost of $0.14 per M input tokens for Azure AI Foundry Model Router infrastructure. Use pattern: azure_ai/model_router/ where deployment-name is your Azure deployment (e.g., azure-model-router)" @@ -4891,7 +4833,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 200000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://azure.microsoft.com/en-us/pricing/details/ai-foundry-models/aoai/", "comment": "Catalog-name twin of azure_ai/model_router: the flat $0.14 per M input tokens is the router's own fee, the routed model is priced on top of it" @@ -4904,7 +4845,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_batches": 5.5e-06, @@ -4925,7 +4865,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_batches": 5.5e-06, @@ -4945,7 +4884,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_batches": 5.5e-06, @@ -4964,7 +4902,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6.6e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -4983,7 +4920,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6.6e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -5002,7 +4938,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 2.2e-05, "output_cost_per_token": 2.64e-06, @@ -5022,7 +4957,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 0.00022, "output_cost_per_token": 2.2e-05, @@ -5042,7 +4976,6 @@ "litellm_provider": "azure", "max_input_tokens": 16000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 8.8e-05, "output_cost_per_token": 2.2e-05, @@ -5072,7 +5005,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_batches": 5.5e-06, @@ -5112,7 +5044,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-06, "output_cost_per_token_batches": 1.1e-06, @@ -5151,7 +5082,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "supported_endpoints": [ @@ -5192,7 +5122,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -5224,7 +5153,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 2.2e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -5257,7 +5185,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.4e-07, "output_cost_per_token_batches": 2.2e-07, @@ -5294,7 +5221,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6.6e-05, "output_cost_per_token_batches": 3.3e-05, @@ -5313,7 +5239,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6.6e-05, "output_cost_per_token_batches": 3.3e-05, @@ -5331,7 +5256,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -5349,7 +5273,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -5367,7 +5290,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -5385,7 +5307,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -5405,7 +5326,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -5422,7 +5342,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -5439,7 +5358,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -5459,7 +5377,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -5480,7 +5397,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "supported_endpoints": [ @@ -5521,7 +5437,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -5553,7 +5468,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 2e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -5583,7 +5497,6 @@ "litellm_provider": "azure", "max_input_tokens": 4097, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-06, "supports_function_calling": true, @@ -5593,7 +5506,7 @@ "input_cost_per_token": 1.65e-06, "litellm_provider": "azure_text", "max_input_tokens": 4097, - "max_tokens": 4097, + "max_output_tokens": 4097, "mode": "completion", "output_cost_per_token": 2.2e-06, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/" @@ -5603,7 +5516,6 @@ "litellm_provider": "azure", "max_input_tokens": 4097, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-06, "supports_function_calling": true, @@ -5615,7 +5527,6 @@ "litellm_provider": "azure", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/legacy-models", @@ -5627,7 +5538,6 @@ "litellm_provider": "azure", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/legacy-models", @@ -5638,7 +5548,7 @@ "input_cost_per_token": 1.65e-06, "litellm_provider": "azure_text", "max_input_tokens": 4097, - "max_tokens": 4097, + "max_output_tokens": 4097, "mode": "completion", "output_cost_per_token": 2.2e-06, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/" @@ -5647,7 +5557,7 @@ "input_cost_per_token": 1.65e-06, "litellm_provider": "azure_text", "max_input_tokens": 4097, - "max_tokens": 4097, + "max_output_tokens": 4097, "mode": "completion", "output_cost_per_token": 2.2e-06, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/" @@ -5658,7 +5568,6 @@ "litellm_provider": "azure", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-05, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -5670,7 +5579,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3e-05, "supports_function_calling": true, @@ -5683,7 +5591,6 @@ "litellm_provider": "azure", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-05, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/legacy-models", @@ -5695,7 +5602,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3e-05, "supports_function_calling": true, @@ -5708,7 +5614,6 @@ "litellm_provider": "azure", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.00012, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/legacy-models", @@ -5720,7 +5625,6 @@ "litellm_provider": "azure", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.00012, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/legacy-models", @@ -5731,7 +5635,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3.3e-05, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/", @@ -5744,7 +5647,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3.3e-05, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/", @@ -5758,7 +5660,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3.3e-05, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/", @@ -5775,7 +5676,6 @@ "litellm_provider": "azure", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "output_cost_per_token_batches": 4e-06, @@ -5813,7 +5713,6 @@ "litellm_provider": "azure", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "output_cost_per_token_batches": 4e-06, @@ -5851,7 +5750,6 @@ "litellm_provider": "azure", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.6e-06, "output_cost_per_token_batches": 8e-07, @@ -5889,7 +5787,6 @@ "litellm_provider": "azure", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.6e-06, "output_cost_per_token_batches": 8e-07, @@ -5925,7 +5822,6 @@ "litellm_provider": "azure", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-07, "output_cost_per_token_batches": 2e-07, @@ -5959,7 +5855,6 @@ "litellm_provider": "azure", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-07, "output_cost_per_token_batches": 2e-07, @@ -5993,7 +5888,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 0.00015, "output_cost_per_token_batches": 7.5e-05, @@ -6013,7 +5907,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "supports_function_calling": true, @@ -6030,7 +5923,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 7.5e-06, @@ -6049,7 +5941,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -6069,7 +5960,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -6088,7 +5978,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 8e-05, "output_cost_per_token": 1e-05, @@ -6121,7 +6010,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 8e-05, "output_cost_per_token": 1e-05, @@ -6153,7 +6041,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1e-05, @@ -6186,7 +6073,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1e-05, @@ -6202,6 +6088,8 @@ "text", "audio" ], + "supports_audio_input": true, + "supports_audio_output": true, "supports_function_calling": true, "supports_native_streaming": true, "supports_parallel_function_calling": true, @@ -6219,7 +6107,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -6251,7 +6138,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -6266,6 +6152,8 @@ "text", "audio" ], + "supports_audio_input": true, + "supports_audio_output": true, "supports_function_calling": true, "supports_native_streaming": true, "supports_parallel_function_calling": true, @@ -6282,7 +6170,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 8e-05, "output_cost_per_token": 1e-05, @@ -6314,7 +6201,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -6332,7 +6218,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -6350,7 +6235,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 6e-07, @@ -6384,7 +6268,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -6406,7 +6289,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1.6e-05, @@ -6441,7 +6323,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1.6e-05, @@ -6475,7 +6356,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1.6e-05, @@ -6510,7 +6390,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1.6e-05, @@ -6544,7 +6423,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 2.4e-05, @@ -6579,7 +6457,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -6614,7 +6491,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -6648,7 +6524,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -6712,7 +6587,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 0.0002, "output_cost_per_token": 2e-05, @@ -6731,7 +6605,6 @@ "litellm_provider": "azure", "max_input_tokens": 16000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 8e-05, "output_cost_per_token": 2e-05, @@ -6785,7 +6658,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "audio_transcription", "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/gpt-realtime-whisper", "supported_endpoints": [ @@ -6809,7 +6681,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_priority": 2e-05, @@ -6852,7 +6723,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "output_cost_per_token_priority": 2e-05, @@ -6887,7 +6757,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 2e-06, "output_cost_per_token_priority": 3.6e-06, @@ -6924,7 +6793,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -6963,7 +6831,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -7000,7 +6867,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7036,7 +6902,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-06, "output_cost_per_token_batches": 1e-06, @@ -7075,7 +6940,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-06, "output_cost_per_token_batches": 1e-06, @@ -7114,7 +6978,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4e-07, "output_cost_per_token_batches": 2e-07, @@ -7150,7 +7013,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4e-07, "output_cost_per_token_batches": 2e-07, @@ -7186,7 +7048,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00012, "output_cost_per_token_batches": 6e-05, @@ -7220,7 +7081,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "supported_endpoints": [ @@ -7261,7 +7121,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7286,7 +7145,6 @@ "litellm_provider": "azure", "max_input_tokens": 111616, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7308,7 +7166,6 @@ "litellm_provider": "azure", "max_input_tokens": 111616, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.4e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7329,7 +7186,6 @@ "litellm_provider": "azure", "max_input_tokens": 111616, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.4e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7350,7 +7206,6 @@ "litellm_provider": "azure", "max_input_tokens": 111616, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7372,7 +7227,6 @@ "litellm_provider": "azure", "max_input_tokens": 111616, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.54e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7393,7 +7247,6 @@ "litellm_provider": "azure", "max_input_tokens": 111616, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.54e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7414,7 +7267,6 @@ "litellm_provider": "azure", "max_input_tokens": 111616, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7436,7 +7288,6 @@ "litellm_provider": "azure", "max_input_tokens": 111616, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.54e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7457,7 +7308,6 @@ "litellm_provider": "azure", "max_input_tokens": 111616, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.54e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7478,7 +7328,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 6.6e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7494,7 +7343,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 6.6e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7510,7 +7358,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7542,7 +7389,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7574,7 +7420,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 2e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7610,7 +7455,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.4e-05, "output_cost_per_token_batches": 7e-06, @@ -7650,7 +7494,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.4e-05, "output_cost_per_token_batches": 7e-06, @@ -7688,7 +7531,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.4e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7722,7 +7564,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.4e-05, "output_cost_per_token_priority": 2.8e-05, @@ -7754,7 +7595,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.000168, "output_cost_per_token_batches": 8.4e-05, @@ -7793,7 +7633,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.000168, "output_cost_per_token_batches": 8.4e-05, @@ -7842,7 +7681,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_above_272k_tokens": 2.25e-05, @@ -7898,7 +7736,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions", @@ -7948,7 +7785,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions", @@ -7998,7 +7834,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_above_272k_tokens": 2.25e-05, @@ -8054,7 +7889,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions", @@ -8104,7 +7938,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions", @@ -8155,7 +7988,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -8204,7 +8036,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -8258,7 +8089,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "output_cost_per_token_above_272k_tokens": 3e-05, @@ -8319,7 +8149,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "output_cost_per_token_above_272k_tokens": 3e-05, @@ -8383,7 +8212,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "output_cost_per_token_above_272k_tokens": 3e-05, @@ -8447,7 +8275,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_272k_tokens": 1.8e-05, @@ -8511,7 +8338,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_272k_tokens": 1.8e-05, @@ -8575,7 +8401,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_above_272k_tokens": 1.8e-06, @@ -8639,7 +8464,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_above_272k_tokens": 1.8e-06, @@ -8691,7 +8515,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_above_272k_tokens": 7.5e-05, @@ -8740,7 +8563,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_above_272k_tokens": 7.5e-05, @@ -8789,7 +8611,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_above_272k_tokens": 7.5e-07, @@ -8838,7 +8659,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_above_272k_tokens": 7.5e-07, @@ -8893,7 +8713,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -8946,7 +8765,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -8993,7 +8811,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -9042,7 +8859,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -9091,7 +8907,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_above_272k_tokens": 1.65e-05, @@ -9140,7 +8955,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_272k_tokens": 1.8e-05, @@ -9189,7 +9003,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_272k_tokens": 1.8e-05, @@ -9232,9 +9045,8 @@ "deprecation_date": "2027-05-18", "input_cost_per_token": 5e-06, "litellm_provider": "azure", - "max_input_tokens": 272000, + "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "reasoning_effort_levels": [ @@ -9271,7 +9083,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "reasoning_effort_levels": [ @@ -9317,7 +9128,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-05, "output_cost_per_token_above_272k_tokens": 3.3e-05, @@ -9372,7 +9182,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-05, "output_cost_per_token_above_272k_tokens": 3.3e-05, @@ -9428,7 +9237,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.32e-05, "output_cost_per_token_above_272k_tokens": 1.98e-05, @@ -9484,7 +9292,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.32e-06, "output_cost_per_token_above_272k_tokens": 1.98e-06, @@ -9534,7 +9341,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-05, "output_cost_per_token_above_272k_tokens": 8.25e-05, @@ -9583,7 +9389,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-07, "output_cost_per_token_above_272k_tokens": 8.25e-07, @@ -9638,7 +9443,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_above_272k_tokens": 1.65e-05, @@ -9679,9 +9483,8 @@ "deprecation_date": "2027-05-18", "input_cost_per_token": 5.5e-06, "litellm_provider": "azure", - "max_input_tokens": 272000, + "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3.3e-05, "reasoning_effort_levels": [ @@ -9727,7 +9530,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-05, "output_cost_per_token_above_272k_tokens": 3.3e-05, @@ -9782,7 +9584,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-05, "output_cost_per_token_above_272k_tokens": 3.3e-05, @@ -9838,7 +9639,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.32e-05, "output_cost_per_token_above_272k_tokens": 1.98e-05, @@ -9894,7 +9694,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.32e-06, "output_cost_per_token_above_272k_tokens": 1.98e-06, @@ -9953,7 +9752,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "output_cost_per_token_above_272k_tokens": 4.5e-05, @@ -10012,7 +9810,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token_above_272k_tokens_batches": 2.475e-05, "output_cost_per_token_batches": 1.65e-05, @@ -10067,7 +9864,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token_above_272k_tokens_batches": 2.475e-05, "output_cost_per_token_batches": 1.65e-05, @@ -10119,7 +9915,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "output_cost_per_token_above_272k_tokens": 4.5e-05, @@ -10179,7 +9974,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "output_cost_per_token_batches": 1.5e-05, @@ -10238,7 +10032,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -10291,7 +10084,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -10345,7 +10137,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -10398,7 +10189,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -10445,7 +10235,6 @@ "litellm_provider": "azure", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -10489,7 +10278,6 @@ "litellm_provider": "azure", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -10531,7 +10319,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.5e-06, "search_context_cost_per_query": { @@ -10582,7 +10369,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.5e-06, "search_context_cost_per_query": { @@ -10634,7 +10420,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.25e-06, "search_context_cost_per_query": { @@ -10682,7 +10467,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.25e-06, "search_context_cost_per_query": { @@ -11058,7 +10842,7 @@ "input_cost_per_token": 8e-06, "litellm_provider": "azure", "max_input_tokens": 32000, - "max_tokens": 32000, + "max_output_tokens": 32000, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_function_calling": true @@ -11067,7 +10851,7 @@ "input_cost_per_token": 8e-06, "litellm_provider": "azure", "max_input_tokens": 32000, - "max_tokens": 32000, + "max_output_tokens": 32000, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_function_calling": true @@ -11079,7 +10863,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6e-05, "supports_function_calling": true, @@ -11097,7 +10880,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6e-05, "output_cost_per_token_batches": 3e-05, @@ -11116,7 +10898,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_batches": 2.2e-06, @@ -11134,7 +10915,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_batches": 2.2e-06, @@ -11152,7 +10932,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8e-06, "supported_endpoints": [ @@ -11183,7 +10962,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8e-06, "output_cost_per_token_batches": 4e-06, @@ -11215,7 +10993,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 4e-05, "search_context_cost_per_query": { @@ -11253,7 +11030,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "supports_prompt_caching": true, @@ -11270,7 +11046,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_batches": 2.2e-06, @@ -11287,7 +11062,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 8e-05, "output_cost_per_token_batches": 4e-05, @@ -11318,7 +11092,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 8e-05, "output_cost_per_token_batches": 4e-05, @@ -11349,7 +11122,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "supported_endpoints": [ @@ -11380,7 +11152,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_batches": 2.2e-06, @@ -11425,7 +11196,6 @@ "input_cost_per_token": 1.43e-07, "litellm_provider": "azure", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/" @@ -11435,7 +11205,6 @@ "input_cost_per_token": 2.2e-08, "litellm_provider": "azure", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/" @@ -11445,7 +11214,6 @@ "input_cost_per_token": 1.1e-07, "litellm_provider": "azure", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/" @@ -11496,7 +11264,6 @@ "litellm_provider": "azure", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8.8e-06, "output_cost_per_token_batches": 4.4e-06, @@ -11534,7 +11301,6 @@ "litellm_provider": "azure", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.76e-06, "output_cost_per_token_batches": 8.8e-07, @@ -11570,7 +11336,6 @@ "litellm_provider": "azure", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4.4e-07, "output_cost_per_token_batches": 2.2e-07, @@ -11604,7 +11369,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_batches": 5.5e-06, @@ -11625,7 +11389,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_batches": 5.5e-06, @@ -11645,7 +11408,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_batches": 5.5e-06, @@ -11664,7 +11426,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6.6e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -11683,7 +11444,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6.6e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -11702,7 +11462,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 2.2e-05, "output_cost_per_token": 2.64e-06, @@ -11722,7 +11481,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 0.00022, "output_cost_per_token": 2.2e-05, @@ -11742,7 +11500,6 @@ "litellm_provider": "azure", "max_input_tokens": 16000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 8.8e-05, "output_cost_per_token": 2.2e-05, @@ -11772,7 +11529,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_batches": 5.5e-06, @@ -11812,7 +11568,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-06, "output_cost_per_token_batches": 1.1e-06, @@ -11850,7 +11605,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.4e-07, "output_cost_per_token_batches": 2.2e-07, @@ -11888,7 +11642,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "supported_endpoints": [ @@ -11929,7 +11682,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -11961,7 +11713,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 2.2e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -11994,7 +11745,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6.6e-05, "output_cost_per_token_batches": 3.3e-05, @@ -12013,7 +11763,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6.6e-05, "output_cost_per_token_batches": 3.3e-05, @@ -12031,7 +11780,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -12049,7 +11797,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8.8e-06, "output_cost_per_token_batches": 4.4e-06, @@ -12082,7 +11829,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8.8e-06, "output_cost_per_token_batches": 4.4e-06, @@ -12115,7 +11861,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -12133,7 +11878,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -12151,7 +11895,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -12172,7 +11915,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -12196,7 +11938,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "azure_ai", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -12207,7 +11948,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "azure_ai", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -12219,7 +11959,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 256000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12237,7 +11976,6 @@ "azure_ai/FLUX-1.1-pro": { "litellm_provider": "azure_ai", "max_input_tokens": 5000, - "max_tokens": 5000, "mode": "image_generation", "output_cost_per_image": 0.04, "source": "https://techcommunity.microsoft.com/blog/azure-ai-foundry-blog/black-forest-labs-flux-1-kontext-pro-and-flux1-1-pro-now-available-in-azure-ai-f/4434659", @@ -12248,7 +11986,6 @@ "azure_ai/FLUX.1-Kontext-pro": { "litellm_provider": "azure_ai", "max_input_tokens": 5000, - "max_tokens": 5000, "mode": "image_generation", "output_cost_per_image": 0.04, "source": "https://azure.microsoft.com/en-us/pricing/details/ai-foundry-models/black-forest-labs/", @@ -12259,7 +11996,6 @@ "azure_ai/flux.2-pro": { "litellm_provider": "azure_ai", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "image_generation", "output_cost_per_image": 0.04, "source": "https://learn.microsoft.com/en-us/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure", @@ -12271,7 +12007,6 @@ "input_cost_per_pixel": 5e-08, "litellm_provider": "azure_ai", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "image_generation", "source": "https://azure.microsoft.com/en-us/pricing/details/ai-foundry-models/black-forest-labs/", "supported_endpoints": [ @@ -12293,7 +12028,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "mode": "chat", "output_cost_per_token": 1.85e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12308,7 +12042,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 3.828e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12324,7 +12057,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3.52e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12340,7 +12072,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 202800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.84e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12355,7 +12086,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.84e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12370,7 +12100,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 7.26e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12385,7 +12114,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_token": 4.46e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12407,7 +12135,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 3.3e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12430,7 +12157,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12453,7 +12179,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12476,7 +12201,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-05, "reasoning_effort_levels": [ @@ -12505,7 +12229,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 1.32e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12520,7 +12243,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 512000, "max_output_tokens": 512000, - "max_tokens": 512000, "mode": "chat", "output_cost_per_token": 1.32e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12563,7 +12285,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 2.64e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12629,7 +12350,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 256000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12652,7 +12372,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.1e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure", @@ -12664,7 +12383,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 1e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12677,7 +12395,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 10000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 7.8e-07, "source": "https://azure.microsoft.com/en-us/blog/introducing-the-llama-4-herd-in-azure-ai-foundry-and-azure-databricks/", @@ -12691,7 +12408,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 8192, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 3.7e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12703,7 +12419,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 3.54e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12715,7 +12430,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6.8e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12728,7 +12442,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6.8e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12741,7 +12454,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 5.2e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12754,7 +12466,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 5.2e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12767,7 +12478,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12780,7 +12490,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12793,7 +12502,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6.4e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12806,7 +12514,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 5.2e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12819,7 +12526,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 5.2e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12832,7 +12538,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12846,7 +12551,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 131072, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12859,7 +12563,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 131072, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3.2e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12873,7 +12576,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 131072, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12885,7 +12587,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12927,7 +12628,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 131072, "max_output_tokens": 8182, - "max_tokens": 8182, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12967,7 +12667,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 5.4e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12981,7 +12680,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models" @@ -12993,7 +12691,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models" @@ -13004,7 +12701,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://techcommunity.microsoft.com/blog/azure-ai-foundry-blog/introducing-cohere-rerank-4-0-in-microsoft-foundry/4477076" @@ -13015,7 +12711,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://techcommunity.microsoft.com/blog/azure-ai-foundry-blog/introducing-cohere-rerank-4-0-in-microsoft-foundry/4477076" @@ -13025,7 +12720,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.68e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure", @@ -13040,7 +12734,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.68e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure", @@ -13056,7 +12749,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4.56e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -13068,7 +12760,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 3.48e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -13084,7 +12775,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 5.1e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -13101,7 +12791,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 1.32e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure", @@ -13114,7 +12803,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "azure_ai", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 3072, @@ -13134,7 +12822,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://learn.microsoft.com/en-us/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure", @@ -13151,7 +12838,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -13172,7 +12858,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -13192,7 +12877,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -13211,7 +12895,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -13228,7 +12911,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", "supports_function_calling": true, @@ -13242,7 +12924,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", "supports_function_calling": true, @@ -13256,7 +12937,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 256000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure", @@ -13271,7 +12951,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.00971, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models" @@ -13282,7 +12961,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 70000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -13294,7 +12972,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -13311,7 +12988,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -13335,7 +13011,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 4e-08, "source": "https://marketplace.microsoft.com/en/marketplace/apps/000-000.ministral-3b-2410-offer?tab=Overview", @@ -13348,7 +13023,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 32000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 1.2e-05, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -13361,7 +13035,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -13373,7 +13046,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://marketplace.microsoft.com/en/marketplace/apps/000-000.mistral-ai-large-2407-offer?tab=Overview", @@ -13385,7 +13057,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 256000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -13399,7 +13070,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 131072, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2e-06, "supports_assistant_prefill": true, @@ -13412,7 +13082,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 131072, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -13424,7 +13093,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 32000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -13437,7 +13105,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -13451,7 +13118,6 @@ "litellm_provider": "text-completion-openai", "max_input_tokens": 16384, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 4e-07, "output_cost_per_token_batches": 2e-07, @@ -13463,7 +13129,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_tool_choice": true }, @@ -13473,7 +13138,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_tool_choice": true }, @@ -13483,7 +13147,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_tool_choice": true }, @@ -13493,7 +13156,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_tool_choice": true }, @@ -13518,7 +13180,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -13528,7 +13189,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat" }, "bedrock/ap-northeast-1/1-month-commitment/anthropic.claude-v2:1": { @@ -13537,7 +13197,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -13547,7 +13206,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -13557,7 +13215,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat" }, "bedrock/ap-northeast-1/6-month-commitment/anthropic.claude-v2:1": { @@ -13566,7 +13223,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -13575,7 +13231,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 7.55e-06, "supports_tool_choice": true @@ -13585,7 +13240,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_tool_choice": true @@ -13595,7 +13249,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_tool_choice": true @@ -13606,7 +13259,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 163840, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2.22e-06, "output_cost_per_token_flex": 1.11e-06, @@ -13626,7 +13278,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -13644,7 +13295,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -13664,7 +13314,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3.03e-06, "output_cost_per_token_flex": 1.52e-06, @@ -13678,7 +13327,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3.6e-06, "output_cost_per_token_flex": 1.8e-06, @@ -13696,7 +13344,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -13715,7 +13362,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_flex": 1.25e-06, @@ -13729,7 +13375,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3e-06, "output_cost_per_token_flex": 1.5e-06, @@ -13749,7 +13394,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4.2e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-70b-instruct.md" @@ -13760,7 +13404,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-8b-instruct.md" @@ -13771,7 +13414,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 163840, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2.22e-06, "output_cost_per_token_flex": 1.11e-06, @@ -13791,7 +13433,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -13809,7 +13450,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -13829,7 +13469,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 2.94e-06, "output_cost_per_token_flex": 1.47e-06, @@ -13843,7 +13482,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3.6e-06, "output_cost_per_token_flex": 1.8e-06, @@ -13861,7 +13499,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -13879,7 +13516,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -13898,7 +13534,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 163840, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2.22e-06, "output_cost_per_token_flex": 1.11e-06, @@ -13918,7 +13553,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -13936,7 +13570,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -13955,7 +13588,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3.6e-06, "output_cost_per_token_flex": 1.8e-06, @@ -13973,7 +13605,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -13991,7 +13622,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4.03e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-70b-instruct.md" @@ -14002,7 +13632,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6.9e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-8b-instruct.md" @@ -14013,7 +13642,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 163840, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2.22e-06, "output_cost_per_token_flex": 1.11e-06, @@ -14033,7 +13661,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -14051,7 +13678,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -14070,7 +13696,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3.6e-06, "output_cost_per_token_flex": 1.8e-06, @@ -14088,7 +13713,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -14098,7 +13722,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat" }, "bedrock/eu-central-1/1-month-commitment/anthropic.claude-v2:1": { @@ -14107,7 +13730,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -14117,7 +13739,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -14127,7 +13748,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat" }, "bedrock/eu-central-1/6-month-commitment/anthropic.claude-v2:1": { @@ -14136,7 +13756,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -14145,7 +13764,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 8.38e-06, "supports_tool_choice": true @@ -14155,7 +13773,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05 }, @@ -14164,7 +13781,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_tool_choice": true @@ -14176,7 +13792,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -14194,7 +13809,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -14213,7 +13827,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -14231,7 +13844,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 3.78e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-70b-instruct.md" @@ -14242,7 +13854,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6.5e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-8b-instruct.md" @@ -14254,7 +13865,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -14272,7 +13882,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -14291,7 +13900,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -14309,7 +13917,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4.55e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-70b-instruct.md" @@ -14320,7 +13927,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.8e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-8b-instruct.md" @@ -14332,7 +13938,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.86e-06, "output_cost_per_token_flex": 9.3e-07, @@ -14350,7 +13955,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -14369,7 +13973,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 256000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.01e-06, "output_cost_per_token_flex": 5.05e-07, @@ -14388,7 +13991,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.86e-06, "output_cost_per_token_flex": 9.3e-07, @@ -14406,7 +14008,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.6e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mistral-7b-instruct.md", @@ -14417,7 +14018,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.56e-05, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mistral-large.md", @@ -14429,7 +14029,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 9.1e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mixtral-8x7b-instruct.md", @@ -14442,7 +14041,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -14460,7 +14058,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -14479,7 +14076,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -14496,7 +14092,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "metadata": { "notes": "Anthropic via Invoke route does not currently support pdf input." }, @@ -14515,7 +14110,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 5.88e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-70b-instruct.md" @@ -14526,7 +14120,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.01e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-8b-instruct.md" @@ -14537,7 +14130,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 163840, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2.22e-06, "output_cost_per_token_flex": 1.11e-06, @@ -14557,7 +14149,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -14575,7 +14166,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -14595,7 +14185,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3.03e-06, "output_cost_per_token_flex": 1.52e-06, @@ -14609,7 +14198,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3.6e-06, "output_cost_per_token_flex": 1.8e-06, @@ -14627,7 +14215,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -14645,7 +14232,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -14655,7 +14241,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat" }, "bedrock/us-east-1/1-month-commitment/anthropic.claude-v2:1": { @@ -14664,7 +14249,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -14674,7 +14258,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -14684,7 +14267,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat" }, "bedrock/us-east-1/6-month-commitment/anthropic.claude-v2:1": { @@ -14693,7 +14275,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -14702,7 +14283,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-06, "supports_tool_choice": true @@ -14712,7 +14292,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_tool_choice": true @@ -14722,7 +14301,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_tool_choice": true @@ -14733,7 +14311,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 3.5e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-70b-instruct.md" @@ -14744,7 +14321,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-8b-instruct.md" @@ -14755,7 +14331,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mistral-7b-instruct.md", @@ -14766,7 +14341,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.2e-05, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mistral-large.md", @@ -14778,7 +14352,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mixtral-8x7b-instruct.md", @@ -14790,7 +14363,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 163840, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.85e-06, "output_cost_per_token_flex": 9.25e-07, @@ -14810,7 +14382,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_flex": 6e-07, @@ -14830,7 +14401,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "supports_function_calling": true, "supports_system_messages": true, @@ -14847,7 +14417,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_flex": 1.25e-06, @@ -14861,7 +14430,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3e-06, "output_cost_per_token_flex": 1.5e-06, @@ -14879,7 +14447,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_flex": 6e-07, @@ -14897,7 +14464,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 163840, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.85e-06, "output_cost_per_token_flex": 9.25e-07, @@ -14917,7 +14483,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_flex": 6e-07, @@ -14935,7 +14500,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -14955,7 +14519,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_flex": 1.25e-06, @@ -14969,7 +14532,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3e-06, "output_cost_per_token_flex": 1.5e-06, @@ -14987,7 +14549,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_flex": 6e-07, @@ -15005,7 +14566,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 3.84e-06, "supports_function_calling": true, @@ -15019,7 +14579,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "bedrock", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536 @@ -15028,7 +14587,6 @@ "input_cost_per_token": 2e-07, "litellm_provider": "bedrock", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024 @@ -15038,7 +14596,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 42000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.7e-06 }, @@ -15047,7 +14604,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 42000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 4e-07 }, @@ -15056,7 +14612,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 42000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.5e-06 }, @@ -15069,7 +14624,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.8e-05, "supports_assistant_prefill": true, @@ -15098,7 +14652,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.8e-05, "supports_assistant_prefill": true, @@ -15119,7 +14672,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8000, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 3.5e-06, "supports_pdf_input": true @@ -15129,7 +14681,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8000, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 2.65e-06, "supports_pdf_input": true @@ -15137,7 +14688,6 @@ "bedrock/us-gov-west-1/amazon.nova-2-multimodal-embeddings-v1:0": { "litellm_provider": "bedrock", "max_input_tokens": 8172, - "max_tokens": 8172, "mode": "embedding", "input_cost_per_token": 1.62e-07, "input_cost_per_image": 7.2e-05, @@ -15156,7 +14706,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 2.88e-07, "supports_function_calling": true, @@ -15172,7 +14721,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 1.68e-07, "supports_function_calling": true, @@ -15186,7 +14734,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 3.84e-06, "supports_function_calling": true, @@ -15200,7 +14747,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "bedrock", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536 @@ -15209,7 +14755,6 @@ "input_cost_per_token": 1.1e-07, "litellm_provider": "bedrock", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024 @@ -15219,7 +14764,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 42000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.6e-06 }, @@ -15228,7 +14772,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 42000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 4e-07 }, @@ -15237,7 +14780,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 42000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.5e-06 }, @@ -15250,7 +14792,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.8e-05, "supports_assistant_prefill": true, @@ -15279,7 +14820,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.8e-05, "supports_assistant_prefill": true, @@ -15300,7 +14840,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8000, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 3.5e-06, "supports_pdf_input": true @@ -15310,7 +14849,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8000, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 6e-07, "supports_pdf_input": true @@ -15321,7 +14859,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 3.5e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-70b-instruct.md" @@ -15332,7 +14869,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-8b-instruct.md" @@ -15343,7 +14879,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -15353,7 +14888,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat" }, "bedrock/us-west-2/1-month-commitment/anthropic.claude-v2:1": { @@ -15362,7 +14896,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -15372,7 +14905,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -15382,7 +14914,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat" }, "bedrock/us-west-2/6-month-commitment/anthropic.claude-v2:1": { @@ -15391,7 +14922,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -15400,7 +14930,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-06, "supports_tool_choice": true @@ -15410,7 +14939,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_tool_choice": true @@ -15420,7 +14948,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_tool_choice": true @@ -15431,7 +14958,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mistral-7b-instruct.md", @@ -15442,7 +14968,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.2e-05, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mistral-large.md", @@ -15454,7 +14979,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mixtral-8x7b-instruct.md", @@ -15466,7 +14990,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 163840, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.85e-06, "output_cost_per_token_flex": 9.25e-07, @@ -15486,7 +15009,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_flex": 6e-07, @@ -15506,7 +15028,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "supports_function_calling": true, "supports_system_messages": true, @@ -15523,7 +15044,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_flex": 1.25e-06, @@ -15537,7 +15057,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3e-06, "output_cost_per_token_flex": 1.5e-06, @@ -15555,7 +15074,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_flex": 6e-07, @@ -15574,7 +15092,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4e-06, "supports_assistant_prefill": true, @@ -15659,12 +15176,31 @@ "/v1/images/generations" ] }, + "cerebras/llama-3.1-70b": { + "input_cost_per_token": 6e-07, + "litellm_provider": "cerebras", + "max_input_tokens": 128000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 6e-07, + "supports_function_calling": true, + "supports_tool_choice": true + }, + "cerebras/llama-3.1-8b": { + "input_cost_per_token": 1e-07, + "litellm_provider": "cerebras", + "max_input_tokens": 128000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 1e-07, + "supports_function_calling": true, + "supports_tool_choice": true + }, "cerebras/llama-3.3-70b": { "input_cost_per_token": 8.5e-07, "litellm_provider": "cerebras", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-06, "supports_function_calling": true, @@ -15675,7 +15211,6 @@ "litellm_provider": "cerebras", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -15686,7 +15221,6 @@ "litellm_provider": "cerebras", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-07, "supports_function_calling": true, @@ -15697,7 +15231,6 @@ "litellm_provider": "cerebras", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 7.5e-07, "source": "https://www.cerebras.ai/blog/openai-gpt-oss-120b-runs-fastest-on-cerebras", @@ -15712,7 +15245,6 @@ "litellm_provider": "cerebras", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 8e-07, "source": "https://inference-docs.cerebras.ai/support/pricing", @@ -15725,7 +15257,6 @@ "litellm_provider": "cerebras", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.49e-06, "source": "https://api.cerebras.ai/public/v1/models/qwen-3.8-27b", @@ -15741,7 +15272,6 @@ "litellm_provider": "nlp_cloud", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 5e-07 }, @@ -15772,7 +15302,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "output_cost_per_token_batches": 2.5e-06, @@ -15799,7 +15328,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "output_cost_per_token_batches": 2.5e-06, @@ -15828,7 +15356,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 7.5e-06, @@ -15862,7 +15389,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 7.5e-06, @@ -15898,7 +15424,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -15942,7 +15467,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -15989,7 +15513,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 7.5e-06, @@ -16033,7 +15556,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -16062,7 +15584,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -16096,7 +15617,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -16133,7 +15653,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -16176,7 +15695,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -16219,7 +15737,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -16263,7 +15780,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -16307,7 +15823,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_batches": 2.5e-05, @@ -16352,7 +15867,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_batches": 2.5e-05, @@ -16398,7 +15912,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "output_cost_per_token_batches": 1e-05, @@ -16444,7 +15957,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -16492,7 +16004,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -16608,7 +16119,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 3072, "max_output_tokens": 3072, - "max_tokens": 3072, "mode": "chat", "output_cost_per_token": 1.923e-06, "rpm": 300 @@ -16618,7 +16128,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 2048, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 1.923e-06, "rpm": 300 @@ -16628,7 +16137,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.923e-06, "rpm": 300 @@ -16638,7 +16146,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.923e-06, "rpm": 300 @@ -16648,7 +16155,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 7.5e-07, "rpm": 300, @@ -16660,7 +16166,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "rpm": 300 @@ -16670,7 +16175,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 80000, "max_output_tokens": 80000, - "max_tokens": 80000, "mode": "chat", "output_cost_per_token": 3.35e-07, "rpm": 300 @@ -16680,7 +16184,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3e-08, "rpm": 300 @@ -16690,7 +16193,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 15000, "max_output_tokens": 15000, - "max_tokens": 15000, "mode": "chat", "output_cost_per_token": 0.0, "rpm": 300 @@ -16701,7 +16203,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4e-06, "rpm": 20, @@ -16713,7 +16214,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 80000, "max_output_tokens": 80000, - "max_tokens": 80000, "mode": "chat", "output_cost_per_token": 4.881e-06, "rpm": 300, @@ -16724,7 +16224,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 2.87e-07, "rpm": 300 @@ -16734,7 +16233,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 60000, "max_output_tokens": 60000, - "max_tokens": 60000, "mode": "chat", "output_cost_per_token": 2.01e-07, "rpm": 300 @@ -16745,7 +16243,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4e-06, "rpm": 20, @@ -16757,7 +16254,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4e-07, "rpm": 300, @@ -16769,7 +16265,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "rpm": 300 @@ -16779,7 +16274,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 24000, "max_output_tokens": 24000, - "max_tokens": 24000, "mode": "chat", "output_cost_per_token": 2.253e-06, "rpm": 300, @@ -16790,7 +16284,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 131000, "max_output_tokens": 131000, - "max_tokens": 131000, "mode": "chat", "output_cost_per_token": 1.12e-07, "rpm": 300, @@ -16801,7 +16294,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1e-06, "rpm": 300 @@ -16812,7 +16304,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4.4e-06, "rpm": 20, @@ -16824,7 +16315,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 1.5e-06, "rpm": 300, @@ -16836,7 +16326,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.55e-07, "rpm": 300 @@ -16846,7 +16335,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3.35e-07, "rpm": 300, @@ -16858,7 +16346,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 3500, "max_output_tokens": 3500, - "max_tokens": 3500, "mode": "chat", "output_cost_per_token": 0.0, "rpm": 300 @@ -16868,7 +16355,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 3e-07, "rpm": 300, @@ -16880,7 +16366,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.55e-07, "rpm": 300, @@ -16891,7 +16376,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6.76e-07, "rpm": 300, @@ -16902,7 +16386,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-07, "rpm": 300, @@ -16914,7 +16397,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 131000, "max_output_tokens": 131000, - "max_tokens": 131000, "mode": "chat", "output_cost_per_token": 8.5e-07, "rpm": 300, @@ -16925,7 +16407,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 24000, "max_output_tokens": 24000, - "max_tokens": 24000, "mode": "chat", "output_cost_per_token": 1e-06, "rpm": 300, @@ -16936,7 +16417,6 @@ "litellm_provider": "codestral", "max_input_tokens": 32000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://docs.mistral.ai/capabilities/code_generation/", @@ -16948,7 +16428,6 @@ "litellm_provider": "codestral", "max_input_tokens": 32000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://docs.mistral.ai/capabilities/code_generation/", @@ -16960,7 +16439,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -16971,7 +16449,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -16981,7 +16458,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "bedrock", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -16991,7 +16467,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "bedrock", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -17001,7 +16476,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "bedrock", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536, @@ -17012,7 +16486,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "bedrock", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536, @@ -17023,7 +16496,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "bedrock", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536, @@ -17034,7 +16506,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "cohere", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536, @@ -17046,7 +16517,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "cohere", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 2048, @@ -17057,7 +16527,6 @@ "input_cost_per_token": 8e-08, "litellm_provider": "cohere", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 2048, @@ -17079,7 +16548,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-cohere-rerank-3-5.md" @@ -17089,7 +16557,6 @@ "litellm_provider": "cohere_chat", "max_input_tokens": 256000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1e-05, "supports_function_calling": true, @@ -17101,7 +16568,6 @@ "litellm_provider": "cohere_chat", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "source": "https://docs.cohere.com/docs/models" }, @@ -17110,7 +16576,6 @@ "litellm_provider": "cohere_chat", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://docs.cohere.com/docs/command-a-plus", @@ -17125,7 +16590,6 @@ "litellm_provider": "cohere", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 2e-06 }, @@ -17134,7 +16598,6 @@ "litellm_provider": "cohere_chat", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -17145,7 +16608,6 @@ "litellm_provider": "cohere_chat", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1e-05, "supports_function_calling": true, @@ -17156,7 +16618,6 @@ "litellm_provider": "cohere_chat", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://docs.cohere.com/v2/docs/command-r7b", @@ -17169,7 +16630,7 @@ "input_cost_per_token": 1.12e-06, "litellm_provider": "coralbricks", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.coralbricks.ai/pricing", @@ -17192,7 +16653,7 @@ "input_cost_per_token": 1.12e-06, "litellm_provider": "coralbricks", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.coralbricks.ai/pricing", @@ -17215,7 +16676,7 @@ "input_cost_per_token": 1.12e-06, "litellm_provider": "coralbricks", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.coralbricks.ai/pricing", @@ -17238,7 +16699,7 @@ "input_cost_per_token": 1e-08, "litellm_provider": "coralbricks", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.coralbricks.ai/pricing", @@ -17261,7 +16722,7 @@ "input_cost_per_token": 1e-08, "litellm_provider": "coralbricks", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.coralbricks.ai/pricing", @@ -17284,7 +16745,7 @@ "input_cost_per_token": 1e-08, "litellm_provider": "coralbricks", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.coralbricks.ai/pricing", @@ -17307,7 +16768,6 @@ "litellm_provider": "openai", "max_input_tokens": 8192, "max_output_tokens": 1024, - "max_tokens": 1024, "mode": "chat", "output_cost_per_token": 1.2e-05, "supported_endpoints": [ @@ -17337,7 +16797,6 @@ "litellm_provider": "openai", "max_input_tokens": 8192, "max_output_tokens": 1024, - "max_tokens": 1024, "mode": "chat", "output_cost_per_token": 1.2e-05, "supported_endpoints": [ @@ -17368,7 +16827,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4.2e-07, "source": "https://api-docs.deepseek.com/quick_start/pricing", @@ -17390,7 +16848,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 4.2e-07, "source": "https://api-docs.deepseek.com/quick_start/pricing", @@ -17412,7 +16869,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17428,7 +16884,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17444,7 +16899,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 4.8e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17460,7 +16914,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 202745, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17476,7 +16929,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17492,7 +16944,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 229376, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17508,7 +16959,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 1000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17520,7 +16970,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17549,7 +16998,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17579,7 +17027,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 30720, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6.4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17592,7 +17039,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17605,7 +17051,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 129024, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17618,7 +17063,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 4e-06, "output_cost_per_token": 1.2e-06, @@ -17632,7 +17076,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 4e-06, "output_cost_per_token": 1.2e-06, @@ -17645,7 +17088,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17676,7 +17118,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17707,7 +17148,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17739,7 +17179,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 5e-07, "output_cost_per_token": 2e-07, @@ -17753,7 +17192,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 1000000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17766,7 +17204,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 1000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 5e-07, "output_cost_per_token": 2e-07, @@ -17780,7 +17217,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 1000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 5e-07, "output_cost_per_token": 2e-07, @@ -17793,7 +17229,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17804,7 +17239,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17853,7 +17287,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17898,7 +17331,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17947,7 +17379,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17992,7 +17423,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 258048, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -18029,7 +17459,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 258048, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -18066,7 +17495,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 258048, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -18104,7 +17532,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -18116,7 +17543,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -18129,7 +17555,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.6e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -18142,7 +17567,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -18156,7 +17580,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 6.4e-07, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -18169,7 +17592,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2.87e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -18182,7 +17604,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 260096, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -18220,7 +17641,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 991808, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -18254,7 +17674,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 991808, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 7.5e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -18268,7 +17687,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 991808, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -18304,7 +17722,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 991808, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -18322,7 +17739,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 991808, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.7e-07, "source": "https://docs.modelstudio.console.alibabacloud.com/en/model-studio/model-pricing", @@ -18341,7 +17757,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 991808, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.7e-07, "source": "https://docs.modelstudio.console.alibabacloud.com/en/model-studio/model-pricing", @@ -18360,7 +17775,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 98304, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -18681,7 +18095,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://www.qwencloud.com/models", @@ -18697,7 +18110,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://www.qwencloud.com/models", @@ -18713,7 +18125,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 4.8e-06, "source": "https://www.qwencloud.com/models", @@ -18729,7 +18140,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 202745, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.qwencloud.com/models", @@ -18745,7 +18155,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.qwencloud.com/models", @@ -18761,7 +18170,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 229376, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://www.qwencloud.com/models", @@ -18777,7 +18185,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 1000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://www.qwencloud.com/models", @@ -18789,7 +18196,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -18818,7 +18224,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -18848,7 +18253,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 30720, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6.4e-06, "source": "https://www.qwencloud.com/models", @@ -18861,7 +18265,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.qwencloud.com/models", @@ -18874,7 +18277,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 129024, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.qwencloud.com/models", @@ -18887,7 +18289,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 4e-06, "output_cost_per_token": 1.2e-06, @@ -18901,7 +18302,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 4e-06, "output_cost_per_token": 1.2e-06, @@ -18914,7 +18314,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -18945,7 +18344,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -18976,7 +18374,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19008,7 +18405,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 5e-07, "output_cost_per_token": 2e-07, @@ -19022,7 +18418,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 1000000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://www.qwencloud.com/models", @@ -19035,7 +18430,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 1000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 5e-07, "output_cost_per_token": 2e-07, @@ -19049,7 +18443,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 1000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 5e-07, "output_cost_per_token": 2e-07, @@ -19062,7 +18455,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19073,7 +18465,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19122,7 +18513,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19167,7 +18557,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19216,7 +18605,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19261,7 +18649,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 258048, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19298,7 +18685,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 258048, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19335,7 +18721,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 258048, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19373,7 +18758,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.qwencloud.com/models", @@ -19385,7 +18769,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.qwencloud.com/models", @@ -19398,7 +18781,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.6e-06, "source": "https://www.qwencloud.com/models", @@ -19411,7 +18793,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://www.qwencloud.com/models", @@ -19425,7 +18806,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 6.4e-07, "source": "https://www.qwencloud.com/models", @@ -19438,7 +18818,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2.87e-06, "source": "https://www.qwencloud.com/models", @@ -19451,7 +18830,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 260096, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19489,7 +18867,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 991808, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19523,7 +18900,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 991808, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 7.5e-06, "source": "https://www.qwencloud.com/models", @@ -19537,7 +18913,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 991808, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19573,7 +18948,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 991808, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://www.qwencloud.com/models", @@ -19589,7 +18963,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 98304, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://www.qwencloud.com/models", @@ -19910,7 +19283,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -19926,7 +19298,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -19942,7 +19313,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 4.8e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -19958,7 +19328,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 202745, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -19974,7 +19343,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -19990,7 +19358,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 229376, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -20006,7 +19373,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 1000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -20018,7 +19384,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20047,7 +19412,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20077,7 +19441,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 30720, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6.4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -20090,7 +19453,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -20103,7 +19465,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 129024, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -20116,7 +19477,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 4e-06, "output_cost_per_token": 1.2e-06, @@ -20130,7 +19490,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 4e-06, "output_cost_per_token": 1.2e-06, @@ -20143,7 +19502,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20174,7 +19532,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20205,7 +19562,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20237,7 +19593,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 5e-07, "output_cost_per_token": 2e-07, @@ -20251,7 +19606,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 1000000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -20264,7 +19618,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 1000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 5e-07, "output_cost_per_token": 2e-07, @@ -20278,7 +19631,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 1000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 5e-07, "output_cost_per_token": 2e-07, @@ -20291,7 +19643,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20302,7 +19653,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20351,7 +19701,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20396,7 +19745,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20445,7 +19793,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20490,7 +19837,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 258048, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20527,7 +19873,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 258048, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20564,7 +19909,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 258048, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20602,7 +19946,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -20614,7 +19957,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -20627,7 +19969,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.6e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -20640,7 +19981,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -20654,7 +19994,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 6.4e-07, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -20667,7 +20006,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2.87e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -20680,7 +20018,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 260096, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20718,7 +20055,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 991808, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20752,7 +20088,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 991808, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 7.5e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -20766,7 +20101,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 991808, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20802,7 +20136,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 991808, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -20820,7 +20153,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 991808, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.7e-07, "source": "https://docs.modelstudio.console.alibabacloud.com/en/model-studio/model-pricing", @@ -20839,7 +20171,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 991808, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.7e-07, "source": "https://docs.modelstudio.console.alibabacloud.com/en/model-studio/model-pricing", @@ -20858,7 +20189,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 98304, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -21180,7 +20510,6 @@ "input_dbu_cost_per_token": 1.429e-06, "litellm_provider": "databricks", "max_input_tokens": 512, - "max_tokens": 512, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070, based on databricks Llama 3.1 70B conversion. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21198,7 +20527,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -21227,7 +20555,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -21257,7 +20584,6 @@ "litellm_provider": "databricks", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21281,7 +20607,6 @@ "litellm_provider": "databricks", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21305,7 +20630,6 @@ "litellm_provider": "databricks", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21329,7 +20653,6 @@ "litellm_provider": "databricks", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21354,7 +20677,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21379,7 +20701,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -21406,7 +20727,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -21434,7 +20754,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -21463,7 +20782,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -21498,7 +20816,6 @@ "litellm_provider": "databricks", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21522,7 +20839,6 @@ "litellm_provider": "databricks", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21545,7 +20861,6 @@ "litellm_provider": "databricks", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21569,7 +20884,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21594,7 +20908,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields. Introductory launch rates of 28.571 input / 142.857 output / 35.714 cache write / 2.857 cache read DBU run through 2026-08-31; the standard rates are listed here because entries carry no expiry date." }, @@ -21623,7 +20936,6 @@ "token_count_framing": 97, "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Billing reads the per-token dollar fields; the '*_dbu_cost_per_token' fields are the published Databricks rates, kept for reference. Context/max output are the DeepSeek-published model limits (1M context, 384K max output)." }, @@ -21656,7 +20968,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Billing reads the per-token dollar fields; the '*_dbu_cost_per_token' fields are the published Databricks rates, kept for reference. Context/max output are the DeepSeek-published model limits (1M context, 384K max output)." }, @@ -21685,7 +20996,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21719,7 +21029,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21754,7 +21063,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21782,7 +21090,6 @@ "litellm_provider": "databricks", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "metadata": { "notes": "Databricks DBU rates not yet published for this model; endpoint metadata only." }, @@ -21803,7 +21110,6 @@ "litellm_provider": "databricks", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "metadata": { "notes": "Databricks DBU rates not yet published for this model; endpoint metadata only." }, @@ -21828,7 +21134,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21861,7 +21166,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21893,7 +21197,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21909,7 +21212,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Databricks DBU rates not yet published for this model; endpoint metadata only." }, @@ -21934,7 +21236,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Databricks DBU rates not yet published for this model; endpoint metadata only." }, @@ -21963,7 +21264,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -21995,7 +21295,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22026,7 +21325,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22059,7 +21357,6 @@ "litellm_provider": "databricks", "max_input_tokens": 128000, "max_output_tokens": 32000, - "max_tokens": 32000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22076,7 +21373,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Billing reads the per-token dollar fields; the '*_dbu_cost_per_token' fields are the published Databricks rates, kept for reference." }, @@ -22104,7 +21400,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22135,7 +21430,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22165,7 +21459,6 @@ "litellm_provider": "databricks", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22185,7 +21478,6 @@ "litellm_provider": "databricks", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22205,7 +21497,6 @@ "litellm_provider": "databricks", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22225,7 +21516,6 @@ "litellm_provider": "databricks", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22245,7 +21535,6 @@ "litellm_provider": "databricks", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22274,7 +21563,6 @@ "litellm_provider": "databricks", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22303,7 +21591,6 @@ "litellm_provider": "databricks", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22332,7 +21619,6 @@ "litellm_provider": "databricks", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields. Rates reflect OpenAI's promotional pricing in effect through November 21, 2026; afterwards input, cache and Batch rates are 25% higher and output rates 50% higher." }, @@ -22361,7 +21647,6 @@ "litellm_provider": "databricks", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22390,7 +21675,6 @@ "litellm_provider": "databricks", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22419,7 +21703,6 @@ "litellm_provider": "databricks", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22448,7 +21731,6 @@ "litellm_provider": "databricks", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22477,7 +21759,6 @@ "litellm_provider": "databricks", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22497,7 +21778,6 @@ "litellm_provider": "databricks", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22517,7 +21797,6 @@ "litellm_provider": "databricks", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22534,7 +21813,6 @@ "litellm_provider": "databricks", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22576,7 +21854,6 @@ "input_dbu_cost_per_token": 1.857e-06, "litellm_provider": "databricks", "max_input_tokens": 8192, - "max_tokens": 8192, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070, based on databricks Llama 3.1 70B conversion. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22623,7 +21900,6 @@ "token_count_framing": 100, "max_input_tokens": 1000000, "max_output_tokens": 1048576, - "max_tokens": 1048576, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Billing reads the per-token dollar fields; the '*_dbu_cost_per_token' fields are the published Databricks rates, kept for reference." }, @@ -22657,7 +21933,6 @@ "litellm_provider": "databricks", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Databricks documentation now provides both DBU costs (_dbu_cost_per_token) and dollar costs(_cost_per_token)." }, @@ -22675,7 +21950,6 @@ "litellm_provider": "databricks", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22692,7 +21966,6 @@ "litellm_provider": "databricks", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070, based on databricks Llama 3.1 70B conversion. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22710,7 +21983,6 @@ "litellm_provider": "databricks", "max_input_tokens": 262144, "max_output_tokens": 25000, - "max_tokens": 25000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22760,7 +22032,6 @@ "input_dbu_cost_per_token": 2.86e-07, "litellm_provider": "databricks", "max_input_tokens": 32768, - "max_tokens": 32768, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22806,7 +22077,6 @@ "litellm_provider": "text-completion-openai", "max_input_tokens": 16384, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 2e-06, "output_cost_per_token_batches": 1e-06, @@ -23401,7 +22671,6 @@ ] }, "deepinfra/Gryphe/MythoMax-L2-13b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 4e-07, @@ -23413,7 +22682,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/NousResearch/Hermes-3-Llama-3.1-405B": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-06, @@ -23424,7 +22692,6 @@ "supports_function_calling": true }, "deepinfra/NousResearch/Hermes-3-Llama-3.1-70B": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 7e-07, @@ -23435,7 +22702,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/QwQ-32B": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.5e-07, @@ -23446,7 +22712,6 @@ "supports_function_calling": true }, "deepinfra/Qwen/Qwen2.5-72B-Instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 3.6e-07, @@ -23458,7 +22723,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen2.5-7B-Instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 4e-08, @@ -23468,7 +22732,6 @@ "supports_tool_choice": false }, "deepinfra/Qwen/Qwen2.5-VL-32B-Instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2e-07, @@ -23480,7 +22743,6 @@ "supports_function_calling": true }, "deepinfra/Qwen/Qwen3-14B": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 1.2e-07, @@ -23492,7 +22754,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-235B-A22B": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 1.8e-07, @@ -23503,7 +22764,6 @@ "supports_function_calling": true }, "deepinfra/Qwen/Qwen3-235B-A22B-Instruct-2507": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 9e-08, @@ -23515,7 +22775,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-235B-A22B-Thinking-2507": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 3e-07, @@ -23526,7 +22785,6 @@ "supports_function_calling": true }, "deepinfra/Qwen/Qwen3-30B-A3B": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 1.2e-07, @@ -23538,7 +22796,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-32B": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 8e-08, @@ -23550,7 +22807,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-Coder-480B-A35B-Instruct": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 4e-07, @@ -23561,7 +22817,6 @@ "supports_function_calling": true }, "deepinfra/Qwen/Qwen3-Coder-480B-A35B-Instruct-Turbo": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 3e-07, @@ -23575,7 +22830,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-Next-80B-A3B-Instruct": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 9e-08, @@ -23587,7 +22841,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-Next-80B-A3B-Thinking": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.4e-07, @@ -23598,7 +22851,6 @@ "supports_function_calling": true }, "deepinfra/Sao10K/L3-8B-Lunaris-v1-Turbo": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 4e-08, @@ -23608,7 +22860,6 @@ "supports_tool_choice": false }, "deepinfra/Sao10K/L3.1-70B-Euryale-v2.2": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 8.5e-07, @@ -23619,7 +22870,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Sao10K/L3.3-70B-Euryale-v2.3": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 6.5e-07, @@ -23629,7 +22879,6 @@ "supports_tool_choice": false }, "deepinfra/allenai/olmOCR-7B-0725-FP8": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2.7e-07, @@ -23639,7 +22888,6 @@ "supports_tool_choice": false }, "deepinfra/anthropic/claude-3-7-sonnet-latest": { - "max_tokens": 200000, "max_input_tokens": 200000, "max_output_tokens": 200000, "input_cost_per_token": 3.3e-06, @@ -23651,7 +22899,6 @@ "supports_function_calling": true }, "deepinfra/anthropic/claude-4-opus": { - "max_tokens": 200000, "max_input_tokens": 200000, "max_output_tokens": 200000, "input_cost_per_token": 1.65e-05, @@ -23662,7 +22909,6 @@ "supports_function_calling": true }, "deepinfra/anthropic/claude-4-sonnet": { - "max_tokens": 200000, "max_input_tokens": 200000, "max_output_tokens": 200000, "input_cost_per_token": 3.3e-06, @@ -23673,7 +22919,6 @@ "supports_function_calling": true }, "deepinfra/deepseek-ai/DeepSeek-R1": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 7e-07, @@ -23684,7 +22929,6 @@ "supports_function_calling": true }, "deepinfra/deepseek-ai/DeepSeek-R1-0528": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 5e-07, @@ -23696,7 +22940,6 @@ "supports_function_calling": true }, "deepinfra/deepseek-ai/DeepSeek-R1-0528-Turbo": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-06, @@ -23707,7 +22950,6 @@ "supports_function_calling": true }, "deepinfra/deepseek-ai/DeepSeek-R1-Distill-Llama-70B": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -23717,7 +22959,6 @@ "supports_tool_choice": false }, "deepinfra/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2.7e-07, @@ -23728,7 +22969,6 @@ "supports_function_calling": true }, "deepinfra/deepseek-ai/DeepSeek-R1-Turbo": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 1e-06, @@ -23739,7 +22979,6 @@ "supports_function_calling": true }, "deepinfra/deepseek-ai/DeepSeek-V3": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 3.2e-07, @@ -23751,7 +22990,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/deepseek-ai/DeepSeek-V3-0324": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 2.4e-07, @@ -23765,7 +23003,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/deepseek-ai/DeepSeek-V3.1": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 2.5e-07, @@ -23779,7 +23016,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/deepseek-ai/DeepSeek-V3.1-Terminus": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 2.7e-07, @@ -23791,7 +23027,6 @@ "supports_function_calling": true }, "deepinfra/google/gemini-2.5-flash": { - "max_tokens": 1000000, "max_input_tokens": 1000000, "max_output_tokens": 1000000, "input_cost_per_token": 3e-07, @@ -23807,7 +23042,6 @@ "supports_audio_input": true }, "deepinfra/google/gemini-2.5-pro": { - "max_tokens": 1000000, "max_input_tokens": 1000000, "max_output_tokens": 1000000, "input_cost_per_token": 1.25e-06, @@ -23822,7 +23056,6 @@ "supports_audio_input": true }, "deepinfra/google/gemma-3-12b-it": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 5e-08, @@ -23834,7 +23067,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemma-3-27b-it": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 8e-08, @@ -23846,7 +23078,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemma-3-4b-it": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 5e-08, @@ -23858,7 +23089,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/meta-llama/Llama-3.2-11B-Vision-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 4.9e-08, @@ -23868,7 +23098,6 @@ "supports_tool_choice": false }, "deepinfra/meta-llama/Llama-3.2-3B-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-08, @@ -23879,7 +23108,6 @@ "supports_function_calling": true }, "deepinfra/meta-llama/Llama-3.3-70B-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2.3e-07, @@ -23890,7 +23118,6 @@ "supports_function_calling": true }, "deepinfra/meta-llama/Llama-3.3-70B-Instruct-Turbo": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -23902,7 +23129,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 2e-07, @@ -23914,7 +23140,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/meta-llama/Llama-4-Scout-17B-16E-Instruct": { - "max_tokens": 327680, "max_input_tokens": 327680, "max_output_tokens": 327680, "input_cost_per_token": 1e-07, @@ -23926,7 +23151,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/meta-llama/Llama-Guard-3-8B": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 5.5e-08, @@ -23936,7 +23160,6 @@ "supports_tool_choice": false }, "deepinfra/meta-llama/Llama-Guard-4-12B": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 1.8e-07, @@ -23946,7 +23169,6 @@ "supports_tool_choice": false }, "deepinfra/meta-llama/Meta-Llama-3-8B-Instruct": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 3e-08, @@ -23957,7 +23179,6 @@ "supports_function_calling": true }, "deepinfra/meta-llama/Meta-Llama-3.1-70B-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 4e-07, @@ -23968,7 +23189,6 @@ "supports_function_calling": true }, "deepinfra/meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 4e-07, @@ -23980,7 +23200,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/meta-llama/Meta-Llama-3.1-8B-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 3e-08, @@ -23991,7 +23210,6 @@ "supports_function_calling": true }, "deepinfra/meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-08, @@ -24003,7 +23221,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/microsoft/WizardLM-2-8x22B": { - "max_tokens": 65536, "max_input_tokens": 65536, "max_output_tokens": 65536, "input_cost_per_token": 4.8e-07, @@ -24013,7 +23230,6 @@ "supports_tool_choice": false }, "deepinfra/microsoft/phi-4": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 7e-08, @@ -24024,7 +23240,6 @@ "supports_function_calling": true }, "deepinfra/mistralai/Mistral-Nemo-Instruct-2407": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.9e-08, @@ -24036,7 +23251,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/mistralai/Mistral-Small-24B-Instruct-2501": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 5e-08, @@ -24047,7 +23261,6 @@ "supports_function_calling": true }, "deepinfra/mistralai/Mistral-Small-3.2-24B-Instruct-2506": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 7.5e-08, @@ -24058,7 +23271,6 @@ "supports_function_calling": true }, "deepinfra/mistralai/Mixtral-8x7B-Instruct-v0.1": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 4e-07, @@ -24069,7 +23281,6 @@ "supports_function_calling": true }, "deepinfra/moonshotai/Kimi-K2-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 5e-07, @@ -24080,7 +23291,6 @@ "supports_function_calling": true }, "deepinfra/moonshotai/Kimi-K2-Instruct-0905": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 5e-07, @@ -24092,7 +23302,6 @@ "supports_function_calling": true }, "deepinfra/nvidia/Llama-3.1-Nemotron-70B-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 6e-07, @@ -24103,7 +23312,6 @@ "supports_function_calling": true }, "deepinfra/nvidia/Llama-3.3-Nemotron-Super-49B-v1.5": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -24127,7 +23335,6 @@ "supports_prompt_caching": true }, "deepinfra/nvidia/NVIDIA-Nemotron-Nano-9B-v2": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 4e-08, @@ -24138,7 +23345,6 @@ "supports_function_calling": true }, "deepinfra/openai/gpt-oss-120b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 3.7e-08, @@ -24150,7 +23356,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/openai/gpt-oss-20b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 3e-08, @@ -24162,7 +23367,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/zai-org/GLM-4.5": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 4e-07, @@ -24181,7 +23385,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4.2e-07, "source": "https://api-docs.deepseek.com/quick_start/pricing", @@ -24204,7 +23407,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.8e-07, "supports_assistant_prefill": true, @@ -24219,7 +23421,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 65536, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.19e-06, "supports_assistant_prefill": true, @@ -24236,7 +23437,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 4.2e-07, "source": "https://api-docs.deepseek.com/quick_start/pricing", @@ -24261,7 +23461,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 65536, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.1e-06, "supports_assistant_prefill": true, @@ -24276,7 +23475,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "mode": "chat", "output_cost_per_token": 4e-07, "supports_assistant_prefill": true, @@ -24291,7 +23489,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.68e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-deepseek-deepseek-v3-1.html", @@ -24308,7 +23505,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 164000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.85e-06, "output_cost_per_token_batches": 9.25e-07, @@ -24328,7 +23524,6 @@ "litellm_provider": "nlp_cloud", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "completion", "output_cost_per_token": 5e-07 }, @@ -24337,7 +23532,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 98304, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 0.0, "supports_assistant_prefill": true, @@ -24351,7 +23545,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 0.0, "supports_assistant_prefill": true, @@ -24365,7 +23558,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 229376, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 0.0, "supports_assistant_prefill": true, @@ -24378,7 +23570,6 @@ "input_cost_per_token": 0.0, "litellm_provider": "volcengine", "max_input_tokens": 4096, - "max_tokens": 4096, "metadata": { "notes": "Volcengine Doubao embedding model - standard version with 2560 dimensions" }, @@ -24390,7 +23581,6 @@ "input_cost_per_token": 0.0, "litellm_provider": "volcengine", "max_input_tokens": 4096, - "max_tokens": 4096, "metadata": { "notes": "Volcengine Doubao embedding model - large version with 2048 dimensions" }, @@ -24402,7 +23592,6 @@ "input_cost_per_token": 0.0, "litellm_provider": "volcengine", "max_input_tokens": 4096, - "max_tokens": 4096, "metadata": { "notes": "Volcengine Doubao embedding model - text-240915 version with 4096 dimensions" }, @@ -24414,7 +23603,6 @@ "input_cost_per_token": 0.0, "litellm_provider": "volcengine", "max_input_tokens": 4096, - "max_tokens": 4096, "metadata": { "notes": "Volcengine Doubao embedding model - text-250515 version with 2048 dimensions" }, @@ -24426,7 +23614,6 @@ "input_cost_per_token": 0.0, "litellm_provider": "volcengine", "max_input_tokens": 4096, - "max_tokens": 4096, "metadata": { "notes": "Volcengine Doubao embedding model - text-240715 version with 2560 dimensions" }, @@ -24539,7 +23726,6 @@ "mode": "search" }, "sail/moonshotai/Kimi-K3": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 2.5e-06, @@ -24561,7 +23747,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/zai-org/GLM-5.3": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 9.8e-07, @@ -24583,7 +23768,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/zai-org/GLM-5.3-Flash": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 1.1e-07, @@ -24605,7 +23789,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/deepseek-ai/DeepSeek-V4-Pro-0813": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 9.2e-07, @@ -24627,7 +23810,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/deepseek-ai/DeepSeek-V4-Flash-0731": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 9e-08, @@ -24649,7 +23831,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/deepseek-ai/DeepSeek-V4.1-Flash": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 9e-08, @@ -24671,7 +23852,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/moonshotai/Kimi-K2.6": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1e-06, @@ -24694,7 +23874,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/google/gemma-4-31B-it": { - "max_tokens": 256000, "max_input_tokens": 256000, "max_output_tokens": 256000, "input_cost_per_token": 4e-07, @@ -24717,7 +23896,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/nvidia/Gemma-4-31B-IT-NVFP4": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.4e-07, @@ -24740,7 +23918,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/google/gemma-4-12B-it": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 3e-07, @@ -24762,7 +23939,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/openai/gpt-oss-120b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 6e-08, @@ -24778,7 +23954,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/Qwen/Qwen3.6-35B-A3B": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 5e-08, @@ -25017,7 +24192,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "cohere", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -25026,7 +24200,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "cohere", "max_input_tokens": 512, - "max_tokens": 512, "metadata": { "notes": "'supports_image_input' is a deprecated field. Use 'supports_embedding_image_input' instead." }, @@ -25039,7 +24212,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "cohere", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "supports_embedding_image_input": true @@ -25048,7 +24220,6 @@ "input_cost_per_token": 0.0001, "litellm_provider": "cohere", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "supports_embedding_image_input": true @@ -25059,7 +24230,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 3.12e-07, "supports_function_calling": true, @@ -25075,7 +24245,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 1.84e-07, "supports_function_calling": true, @@ -25091,7 +24260,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 4.2e-06, "output_cost_per_token_flex": 2.1e-06, @@ -25108,7 +24276,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4e-06, "supports_assistant_prefill": true, @@ -25131,7 +24298,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5.5e-06, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -25159,7 +24325,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -25175,7 +24340,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -25194,7 +24358,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -25214,7 +24377,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_function_calling": true, @@ -25231,7 +24393,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "search_context_cost_per_query": { @@ -25262,7 +24423,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "search_context_cost_per_query": { @@ -25293,7 +24453,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -25333,7 +24492,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.65e-05, "search_context_cost_per_query": { @@ -25367,7 +24525,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.3e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-2-1b-instruct.md", @@ -25380,7 +24537,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.9e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-2-3b-instruct.md", @@ -25392,7 +24548,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-pixtral-large.md", @@ -27658,14 +26813,12 @@ "litellm_provider": "featherless_ai", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat" }, "featherless_ai/featherless-ai/Qwerky-QwQ-32B": { "litellm_provider": "featherless_ai", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat" }, "fireworks-ai-4.1b-to-16b": { @@ -27713,7 +26866,6 @@ "input_cost_per_token": 1.6e-08, "litellm_provider": "fireworks_ai-embedding-models", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://fireworks.ai/pricing" @@ -27723,7 +26875,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 65536, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://fireworks.ai/pricing", @@ -27736,7 +26887,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 163840, "max_output_tokens": 20480, - "max_tokens": 20480, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://fireworks.ai/pricing", @@ -27748,7 +26898,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 163840, "max_output_tokens": 160000, - "max_tokens": 160000, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://fireworks.ai/pricing", @@ -27760,7 +26909,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 163840, "max_output_tokens": 20480, - "max_tokens": 20480, "mode": "chat", "output_cost_per_token": 2.19e-06, "source": "https://fireworks.ai/pricing", @@ -27772,7 +26920,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://fireworks.ai/pricing", @@ -27784,7 +26931,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://fireworks.ai/models/fireworks/deepseek-v3-0324", @@ -27796,7 +26942,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.68e-06, "source": "https://fireworks.ai/pricing", @@ -27809,7 +26954,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.68e-06, "source": "https://fireworks.ai/pricing", @@ -27822,7 +26966,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "mode": "chat", "output_cost_per_token": 1.68e-06, "source": "https://fireworks.ai/models/fireworks/deepseek-v3p2", @@ -27837,7 +26980,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 2.8e-07, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -27856,7 +26998,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3.96e-06, "output_cost_per_token_priority": 4.95e-06, @@ -27876,7 +27017,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3.96e-06, "output_cost_per_token_priority": 4.95e-06, @@ -27892,7 +27032,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://fireworks.ai/pricing", @@ -27905,7 +27044,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 96000, - "max_tokens": 96000, "mode": "chat", "output_cost_per_token": 2.19e-06, "source": "https://fireworks.ai/models/fireworks/glm-4p5", @@ -27919,7 +27057,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 96000, - "max_tokens": 96000, "mode": "chat", "output_cost_per_token": 8.8e-07, "source": "https://artificialanalysis.ai/models/glm-4-5-air", @@ -27934,7 +27071,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 202752, "max_output_tokens": 202800, - "max_tokens": 202800, "mode": "chat", "source": "https://fireworks.ai/pricing", "supports_function_calling": true, @@ -27948,7 +27084,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 202752, "max_output_tokens": 202800, - "max_tokens": 202800, "mode": "chat", "output_cost_per_token": 2.2e-06, "source": "https://fireworks.ai/models/fireworks/glm-4p7", @@ -27963,7 +27098,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 202752, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -27982,7 +27116,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_priority": 5.5e-06, @@ -28002,7 +27135,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_priority": 7.2e-07, @@ -28019,7 +27151,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -28034,7 +27165,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://fireworks.ai/models/fireworks/kimi-k2-instruct", @@ -28047,7 +27177,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://app.fireworks.ai/models/fireworks/kimi-k2-instruct-0905", @@ -28060,7 +27189,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://fireworks.ai/pricing", @@ -28075,7 +27203,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://fireworks.ai/pricing", @@ -28092,7 +27219,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-06, "output_cost_per_token_priority": 6e-06, @@ -28112,7 +27238,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-06, "output_cost_per_token_priority": 6e-06, @@ -28128,7 +27253,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://fireworks.ai/pricing", @@ -28141,7 +27265,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://fireworks.ai/pricing", @@ -28154,7 +27277,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://fireworks.ai/pricing", @@ -28168,7 +27290,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://fireworks.ai/pricing", @@ -28181,7 +27302,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://fireworks.ai/pricing", @@ -28194,7 +27314,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://fireworks.ai/pricing", @@ -28207,7 +27326,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 8.8e-07, "source": "https://fireworks.ai/pricing", @@ -28219,7 +27337,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://fireworks.ai/pricing", @@ -28232,7 +27349,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 196608, "max_output_tokens": 204800, - "max_tokens": 204800, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://fireworks.ai/models/fireworks/minimax-m2p1", @@ -28248,7 +27364,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 512000, "max_output_tokens": 512000, - "max_tokens": 512000, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_priority": 1.8e-06, @@ -28264,7 +27379,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 65536, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://fireworks.ai/pricing", @@ -28277,7 +27391,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://fireworks.ai/pricing", @@ -28290,7 +27403,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://fireworks.ai/pricing", @@ -28303,7 +27415,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://fireworks.ai/pricing", @@ -28317,7 +27428,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 2.8e-07, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -28333,7 +27443,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 202752, "max_output_tokens": 202800, - "max_tokens": 202800, "mode": "chat", "output_cost_per_token": 2.2e-06, "source": "https://fireworks.ai/models/fireworks/glm-4p7", @@ -28348,7 +27457,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 202752, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -28364,7 +27472,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 202800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 8.8e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -28383,7 +27490,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_priority": 5.5e-06, @@ -28403,7 +27509,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_priority": 7.2e-07, @@ -28420,7 +27525,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -28436,7 +27540,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://fireworks.ai/pricing", @@ -28453,7 +27556,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-06, "output_cost_per_token_priority": 6e-06, @@ -28471,7 +27573,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -28490,7 +27591,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-06, "output_cost_per_token_priority": 6e-06, @@ -28508,7 +27608,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -28524,7 +27623,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 196608, "max_output_tokens": 204800, - "max_tokens": 204800, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://fireworks.ai/models/fireworks/minimax-m2p1", @@ -28540,7 +27638,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 512000, "max_output_tokens": 512000, - "max_tokens": 512000, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_priority": 1.8e-06, @@ -28557,7 +27654,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.6e-06, "source": "https://api.fireworks.ai/v1/serverless/models", @@ -28571,7 +27667,6 @@ "input_cost_per_token": 8e-09, "litellm_provider": "fireworks_ai-embedding-models", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://fireworks.ai/pricing" @@ -28580,7 +27675,6 @@ "input_cost_per_token": 8e-09, "litellm_provider": "fireworks_ai-embedding-models", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://fireworks.ai/pricing" @@ -28589,7 +27683,6 @@ "input_cost_per_token": 8e-09, "litellm_provider": "fireworks_ai-embedding-models", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://fireworks.ai/pricing" @@ -28598,7 +27691,6 @@ "input_cost_per_token": 1.6e-08, "litellm_provider": "fireworks_ai-embedding-models", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://fireworks.ai/pricing" @@ -28607,7 +27699,6 @@ "litellm_provider": "friendliai", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "input_cost_per_token": 1.5e-07, "output_cost_per_token": 5e-07, "cache_read_input_token_cost": 3e-08, @@ -28635,7 +27726,6 @@ "litellm_provider": "friendliai", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "input_cost_per_token": 1.26e-06, "output_cost_per_token": 3.96e-06, "cache_read_input_token_cost": 2.34e-07, @@ -28663,7 +27753,6 @@ "litellm_provider": "friendliai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "input_cost_per_token": 1.4e-07, "output_cost_per_token": 4e-07, "supports_prompt_caching": false, @@ -28686,7 +27775,6 @@ "litellm_provider": "friendliai", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "input_cost_per_token": 1.4e-06, "output_cost_per_token": 4.4e-06, "cache_read_input_token_cost": 2.6e-07, @@ -28713,7 +27801,6 @@ "litellm_provider": "friendliai", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "input_cost_per_token": 5e-07, "output_cost_per_token": 1.5e-06, "cache_read_input_token_cost": 2.5e-07, @@ -28737,7 +27824,6 @@ "litellm_provider": "friendliai", "max_input_tokens": 196608, "max_output_tokens": 196608, - "max_tokens": 196608, "input_cost_per_token": 3e-07, "output_cost_per_token": 1.2e-06, "cache_read_input_token_cost": 6e-08, @@ -28761,7 +27847,6 @@ "litellm_provider": "friendliai", "max_input_tokens": 202752, "max_output_tokens": 202752, - "max_tokens": 202752, "input_cost_per_token": 1.4e-06, "output_cost_per_token": 4.4e-06, "cache_read_input_token_cost": 2.6e-07, @@ -28788,7 +27873,6 @@ "litellm_provider": "text-completion-openai", "max_input_tokens": 16384, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 1.6e-06, "output_cost_per_token_batches": 9e-07, @@ -28801,7 +27885,6 @@ "litellm_provider": "text-completion-openai", "max_input_tokens": 16384, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 1.2e-05, "output_cost_per_token_batches": 6e-06, @@ -28814,7 +27897,6 @@ "litellm_provider": "openai", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_batches": 3e-06, @@ -28828,7 +27910,6 @@ "litellm_provider": "openai", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-06, "supports_system_messages": true, @@ -28840,7 +27921,6 @@ "litellm_provider": "openai", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-06, "supports_system_messages": true, @@ -28852,7 +27932,6 @@ "litellm_provider": "openai", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-06, "supports_system_messages": true, @@ -28864,7 +27943,6 @@ "litellm_provider": "openai", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-05, "source": "OpenAI needs to add pricing for this ft model, will be updated when added by OpenAI. Defaulting to base model pricing", @@ -28881,7 +27959,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -28902,7 +27979,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -28922,7 +27998,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_batches": 6e-07, @@ -28944,7 +28019,6 @@ "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_batches": 6e-06, @@ -28965,7 +28039,6 @@ "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3.2e-06, "output_cost_per_token_batches": 1.6e-06, @@ -28986,7 +28059,6 @@ "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-07, "output_cost_per_token_batches": 4e-07, @@ -29007,7 +28079,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 1.6e-05, "output_cost_per_token_batches": 8e-06, @@ -29030,7 +28101,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_reasoning_token": 2.5e-06, "output_cost_per_token": 2.5e-06, @@ -29087,7 +28157,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.039, "output_cost_per_image_token": 3e-05, @@ -29145,7 +28214,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.134, "output_cost_per_image_token": 0.00012, @@ -29199,7 +28267,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.134, "output_cost_per_image_token": 0.00012, @@ -29251,7 +28318,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.0672, "output_cost_per_image_token": 6e-05, @@ -29297,7 +28363,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.0672, "output_cost_per_image_token": 6e-05, @@ -29337,7 +28402,6 @@ "cache_read_input_token_cost_batches": 1.25e-08, "cache_read_input_token_cost_flex": 1.25e-08, "cache_read_input_token_cost_priority": 4.5e-08, - "deprecation_date": "2027-06-28", "input_cost_per_image": 0.00028, "input_cost_per_token": 2.5e-07, "input_cost_per_token_batches": 1.25e-07, @@ -29346,7 +28410,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "image_generation", "output_cost_per_image": 0.0336, "output_cost_per_image_token": 3e-05, @@ -29386,7 +28449,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 1.5e-06, "output_cost_per_token": 1.5e-06, @@ -29445,7 +28507,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 1.5e-06, "output_cost_per_token": 1.5e-06, @@ -29505,7 +28566,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 2.5e-06, "output_cost_per_token": 2.5e-06, @@ -29561,7 +28621,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_image": 0.134, "output_cost_per_image_token": 0.00012, @@ -29599,7 +28658,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_reasoning_token": 4e-07, "output_cost_per_token": 4e-07, @@ -29654,7 +28712,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_reasoning_token": 4e-07, "output_cost_per_token": 4e-07, @@ -29701,7 +28758,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_reasoning_token": 2.5e-06, "output_cost_per_token": 2.5e-06, @@ -29748,7 +28804,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2e-06, @@ -29794,7 +28849,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2e-06, @@ -29838,7 +28892,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2e-06, @@ -29890,7 +28943,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_200k_tokens": 1.5e-05, @@ -29952,7 +29004,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_image": 0.00012, "output_cost_per_token": 1.2e-05, @@ -30005,7 +29056,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_200k_tokens": 1.8e-05, @@ -30058,7 +29108,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_200k_tokens": 1.8e-05, @@ -30119,7 +29168,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_token": 3e-06, "output_cost_per_token_batches": 1.5e-06, @@ -30166,7 +29214,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_reasoning_token": 9e-06, "output_cost_per_token": 9e-06, @@ -30229,7 +29276,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -30290,7 +29336,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -30354,7 +29399,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -30410,7 +29454,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 7.5e-06, "output_cost_per_token": 7.5e-06, @@ -30458,7 +29501,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 4.5e-06, @@ -30501,7 +29543,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_image": 0.00012, "output_cost_per_token": 1.2e-05, @@ -30554,7 +29595,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_200k_tokens": 1.8e-05, @@ -30611,7 +29651,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2e-05, @@ -30644,7 +29683,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_reasoning_token": 2.5e-06, @@ -30682,7 +29720,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 5e-06, "output_cost_per_token": 5e-06, @@ -30729,7 +29766,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_200k_tokens": 1.5e-05, @@ -30753,7 +29789,6 @@ "input_cost_per_token_batches": 1.2e-07, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 2048, - "max_tokens": 2048, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -30770,7 +29805,6 @@ "input_cost_per_video_token_batches": 6e-06, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -30788,7 +29822,6 @@ "input_cost_per_video_token_batches": 6e-06, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -30807,7 +29840,6 @@ "input_cost_per_video_token_batches": 6e-06, "litellm_provider": "vertex_ai", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -30826,7 +29858,6 @@ "input_cost_per_video_token_batches": 6e-06, "litellm_provider": "vertex_ai", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -30840,7 +29871,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1000000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -30852,7 +29882,6 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "gemini", "max_input_tokens": 2048, - "max_tokens": 2048, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -30871,7 +29900,6 @@ "input_cost_per_video_token_batches": 6e-06, "litellm_provider": "gemini", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -30892,7 +29920,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.134, "output_cost_per_image_token": 0.00012, @@ -30938,7 +29965,6 @@ "litellm_provider": "gemini", "max_input_tokens": 65536, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "image_generation", "output_cost_per_image": 0.045, "output_cost_per_image_token": 6e-05, @@ -30990,7 +30016,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 1.5e-06, "output_cost_per_token": 1.5e-06, @@ -31050,7 +30075,6 @@ "input_cost_per_video_token_batches": 6e-06, "litellm_provider": "gemini", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -31067,7 +30091,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "rpm": 1000, @@ -31104,7 +30127,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "rpm": 1000, @@ -31137,16 +30159,19 @@ }, "gemini/gemini-2.5-flash": { "cache_read_input_audio_token_cost": 1e-07, + "cache_read_input_audio_token_cost_batches": 1e-07, + "cache_read_input_audio_token_cost_flex": 1e-07, + "cache_read_input_audio_token_cost_priority": 1.8e-07, "cache_read_input_token_cost": 3e-08, "cache_read_input_token_cost_batches": 3e-08, "cache_read_input_token_cost_flex": 3e-08, "cache_read_input_token_cost_priority": 5.4e-08, "input_cost_per_audio_token": 1e-06, + "input_cost_per_audio_token_flex": 5e-07, "input_cost_per_token": 3e-07, "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 2.5e-06, "output_cost_per_token": 2.5e-06, @@ -31209,7 +30234,6 @@ "supports_reasoning": false, "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.039, "output_cost_per_image_token": 3e-05, @@ -31261,7 +30285,6 @@ "litellm_provider": "gemini", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.134, "output_cost_per_image_token": 0.00012, @@ -31310,7 +30333,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.134, "output_cost_per_image_token": 0.00012, @@ -31353,7 +30375,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.045, "output_cost_per_image_token": 6e-05, @@ -31395,7 +30416,6 @@ "litellm_provider": "gemini", "max_input_tokens": 65536, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "image_generation", "output_cost_per_image": 0.0336, "output_cost_per_image_token": 3e-05, @@ -31434,7 +30454,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_batches": 6e-06, @@ -31466,16 +30485,19 @@ }, "gemini/gemini-2.5-flash-lite": { "cache_read_input_audio_token_cost": 3e-08, + "cache_read_input_audio_token_cost_batches": 3e-08, + "cache_read_input_audio_token_cost_flex": 3e-08, + "cache_read_input_audio_token_cost_priority": 5.4e-08, "cache_read_input_token_cost": 1e-08, "cache_read_input_token_cost_batches": 1e-08, "cache_read_input_token_cost_flex": 1e-08, "cache_read_input_token_cost_priority": 1.8e-08, "input_cost_per_audio_token": 3e-07, + "input_cost_per_audio_token_flex": 1.5e-07, "input_cost_per_token": 1e-07, "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 4e-07, "output_cost_per_token": 4e-07, @@ -31532,7 +30554,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -31591,7 +30612,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 2.5e-06, "output_cost_per_token": 2.5e-06, @@ -31650,7 +30670,6 @@ "litellm_provider": "gemini", "max_input_tokens": 8192, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "audio_speech", "output_cost_per_audio_token": 1e-05, "output_cost_per_token": 1e-05, @@ -31680,7 +30699,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_200k_tokens": 1.5e-05, @@ -31734,7 +30752,6 @@ "litellm_provider": "gemini", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_200k_tokens": 1.5e-05, @@ -31760,12 +30777,16 @@ }, "gemini/gemini-3.1-flash-lite": { "cache_read_input_audio_token_cost": 5e-08, + "cache_read_input_audio_token_cost_batches": 2.5e-08, + "cache_read_input_audio_token_cost_flex": 2.5e-08, + "cache_read_input_audio_token_cost_priority": 9e-08, "cache_read_input_token_cost": 2.5e-08, "cache_read_input_token_cost_batches": 1.25e-08, "cache_read_input_token_cost_flex": 1.25e-08, "cache_read_input_token_cost_priority": 4.5e-08, "deprecation_date": "2027-05-07", "input_cost_per_audio_token": 5e-07, + "input_cost_per_audio_token_flex": 2.5e-07, "input_cost_per_token": 2.5e-07, "input_cost_per_token_batches": 1.25e-07, "input_cost_per_token_flex": 1.25e-07, @@ -31773,7 +30794,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 1.5e-06, "output_cost_per_token": 1.5e-06, @@ -31835,7 +30855,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 2.5e-06, "output_cost_per_token": 2.5e-06, @@ -31886,15 +30905,18 @@ }, "gemini/gemini-3-flash-preview": { "cache_read_input_audio_token_cost": 1e-07, + "cache_read_input_audio_token_cost_batches": 1e-07, + "cache_read_input_audio_token_cost_flex": 1e-07, + "cache_read_input_audio_token_cost_priority": 1.8e-07, "cache_read_input_token_cost": 5e-08, "cache_read_input_token_cost_batches": 5e-08, "cache_read_input_token_cost_flex": 5e-08, "input_cost_per_audio_token": 1e-06, + "input_cost_per_audio_token_flex": 5e-07, "input_cost_per_token": 5e-07, "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3e-06, "output_cost_per_token": 3e-06, @@ -31956,7 +30978,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 9e-06, "output_cost_per_token": 9e-06, @@ -32021,7 +31042,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -32083,7 +31103,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -32146,7 +31165,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -32204,7 +31222,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 9e-06, "output_cost_per_token": 9e-06, @@ -32242,7 +31259,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_200k_tokens": 1.8e-05, @@ -32306,7 +31322,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_200k_tokens": 1.8e-05, @@ -32375,7 +31390,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_reasoning_token": 3e-06, "output_cost_per_token": 3e-06, @@ -32420,7 +31434,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_reasoning_token": 9e-06, "output_cost_per_token": 9e-06, @@ -32455,7 +31468,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_reasoning_token": 9e-06, "output_cost_per_token": 9e-06, @@ -32518,7 +31530,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -32579,7 +31590,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -32643,7 +31653,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -32699,7 +31708,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 7.5e-06, "output_cost_per_token": 7.5e-06, @@ -32746,7 +31754,6 @@ "litellm_provider": "gemini", "max_input_tokens": 8192, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2e-05, @@ -32781,7 +31788,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 8192, - "max_tokens": 8192, "metadata": { "notes": "Rate limits not documented for gemini-exp-1114. Assuming same as gemini-1.5-pro.", "supports_tool_choice": true @@ -32804,7 +31810,6 @@ "litellm_provider": "gemini", "max_input_tokens": 2097152, "max_output_tokens": 8192, - "max_tokens": 8192, "metadata": { "notes": "Rate limits not documented for gemini-exp-1206. Assuming same as gemini-1.5-pro.", "supports_tool_choice": true @@ -32825,7 +31830,7 @@ "input_cost_per_token": 3.5e-07, "litellm_provider": "gemini", "max_output_tokens": 8192, - "max_tokens": 8192, + "max_input_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.05e-06, "source": "https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models#foundation_models", @@ -32839,7 +31844,7 @@ "input_cost_per_token": 3.5e-07, "litellm_provider": "gemini", "max_output_tokens": 8192, - "max_tokens": 8192, + "max_input_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.05e-06, "source": "https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models#foundation_models", @@ -32863,7 +31868,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_character": 0, "output_cost_per_character_above_128k_tokens": 0, @@ -32883,7 +31887,6 @@ "litellm_provider": "gemini", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "supports_function_calling": true, "supports_reasoning": true, @@ -32899,7 +31902,6 @@ "litellm_provider": "gemini", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "supports_function_calling": true, "supports_reasoning": true, @@ -32935,7 +31937,6 @@ "litellm_provider": "gemini", "max_input_tokens": 32767, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_character": 0, "output_cost_per_character_above_128k_tokens": 0, @@ -32954,7 +31955,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_image": 0.04, "output_cost_per_token": 0, @@ -32979,7 +31979,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0, "source": "https://ai.google.dev/gemini-api/docs/pricing", @@ -33003,7 +32002,6 @@ "deprecation_date": "2026-10-22", "litellm_provider": "gemini", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.1, "output_cost_per_second_1080p": 0.12, @@ -33020,7 +32018,6 @@ "deprecation_date": "2026-10-22", "litellm_provider": "gemini", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.4, "output_cost_per_second_4k": 0.6, @@ -33036,7 +32033,6 @@ "deprecation_date": "2026-10-22", "litellm_provider": "gemini", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.05, "output_cost_per_second_1080p": 0.08, @@ -33051,7 +32047,6 @@ "gemini/veo-3.1-fast-generate-001": { "litellm_provider": "gemini", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.1, "output_cost_per_second_1080p": 0.12, @@ -33067,7 +32062,6 @@ "gemini/veo-3.1-generate-001": { "litellm_provider": "gemini", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.4, "output_cost_per_second_4k": 0.6, @@ -33086,7 +32080,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33109,7 +32102,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33132,7 +32124,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 128000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 5e-06, "supported_endpoints": [ @@ -33153,7 +32144,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 128000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_above_100k_tokens": 2.5e-06, @@ -33178,7 +32168,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33196,11 +32185,11 @@ "github_copilot/claude-opus-4.8-fast": { "cache_creation_input_token_cost": 1.25e-05, "cache_read_input_token_cost": 1e-06, + "deprecation_date": "2026-11-16", "input_cost_per_token": 1e-05, "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33223,7 +32212,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33245,7 +32233,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33268,7 +32255,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33290,7 +32276,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33313,7 +32298,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 3.75e-06, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33332,7 +32316,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3.75e-06, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33349,7 +32332,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 16384, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_function_calling": true }, @@ -33357,7 +32339,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 16384, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_function_calling": true }, @@ -33365,7 +32346,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_function_calling": true }, @@ -33373,7 +32353,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_function_calling": true }, @@ -33381,7 +32360,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 64000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_function_calling": true, "supports_parallel_function_calling": true @@ -33391,7 +32369,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/model-deprecation-history.yml", "supports_function_calling": true, @@ -33404,7 +32381,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/model-deprecation-history.yml", "supports_function_calling": true, @@ -33420,7 +32396,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 64000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_function_calling": true, "supports_parallel_function_calling": true, @@ -33430,7 +32405,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 64000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_function_calling": true, "supports_parallel_function_calling": true, @@ -33440,7 +32414,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 64000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "supports_function_calling": true, "supports_parallel_function_calling": true @@ -33449,7 +32422,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 64000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "supports_function_calling": true, "supports_parallel_function_calling": true, @@ -33459,7 +32431,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 64000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_function_calling": true, "supports_parallel_function_calling": true @@ -33468,7 +32439,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 64000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_function_calling": true, "supports_parallel_function_calling": true @@ -33480,7 +32450,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://github.blog/changelog/2026-10-19-github-copilot-models-deprecated-on-october-19-2026", @@ -33495,7 +32464,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.4e-05, "supported_endpoints": [ @@ -33516,7 +32484,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_above_272k_tokens": 2.25e-05, @@ -33538,7 +32505,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 4.5e-06, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33560,7 +32526,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 3e-05, "output_cost_per_token_above_272k_tokens": 4.5e-05, @@ -33584,7 +32549,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.2e-06, "output_cost_per_token_above_200k_tokens": 1.8e-06, @@ -33608,7 +32572,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 2e-05, "output_cost_per_token_above_272k_tokens": 3e-05, @@ -33633,7 +32596,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_272k_tokens": 1.8e-05, @@ -33655,9 +32617,8 @@ "input_cost_per_token": 1e-05, "input_cost_per_token_above_272k_tokens": 2e-05, "litellm_provider": "github_copilot", - "max_input_tokens": 272000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 5e-05, "output_cost_per_token_above_272k_tokens": 7.5e-05, @@ -33679,9 +32640,8 @@ "input_cost_per_token": 1e-07, "input_cost_per_token_above_272k_tokens": 2e-07, "litellm_provider": "github_copilot", - "max_input_tokens": 272000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 5e-07, "output_cost_per_token_above_272k_tokens": 7.5e-07, @@ -33703,9 +32663,8 @@ "input_cost_per_token": 2e-06, "input_cost_per_token_above_272k_tokens": 4e-06, "litellm_provider": "github_copilot", - "max_input_tokens": 272000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -33727,9 +32686,8 @@ "input_cost_per_token": 2e-06, "input_cost_per_token_above_272k_tokens": 4e-06, "litellm_provider": "github_copilot", - "max_input_tokens": 272000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -33749,7 +32707,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 917504, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33767,7 +32724,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.2e-06, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33782,19 +32738,16 @@ "github_copilot/text-embedding-3-small": { "litellm_provider": "github_copilot", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding" }, "github_copilot/text-embedding-3-small-inference": { "litellm_provider": "github_copilot", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding" }, "github_copilot/text-embedding-ada-002": { "litellm_provider": "github_copilot", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding" }, "chatgpt/gpt-6-sol": { @@ -33806,7 +32759,6 @@ ], "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "source": "https://developers.openai.com/api/docs/pricing", "supports_function_calling": true, "supports_max_reasoning_effort": true, @@ -33827,7 +32779,6 @@ ], "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "source": "https://developers.openai.com/api/docs/pricing", "supports_function_calling": true, "supports_max_reasoning_effort": true, @@ -33848,7 +32799,6 @@ ], "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "source": "https://developers.openai.com/api/docs/pricing", "supports_function_calling": true, "supports_max_reasoning_effort": true, @@ -33869,7 +32819,6 @@ ], "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "source": "https://developers.openai.com/api/docs/pricing", "supports_function_calling": true, "supports_max_reasoning_effort": true, @@ -33886,7 +32835,6 @@ "source": "https://platform.openai.com/docs/models/gpt-5.5", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/chat/completions", @@ -33906,7 +32854,6 @@ "source": "https://platform.openai.com/docs/models/gpt-5.6-luna", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/chat/completions", @@ -33926,7 +32873,6 @@ "source": "https://platform.openai.com/docs/models/gpt-5.6-sol", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/chat/completions", @@ -33946,7 +32892,6 @@ "source": "https://platform.openai.com/docs/models/gpt-5.6-terra", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/chat/completions", @@ -33965,7 +32910,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/chat/completions", @@ -33985,7 +32929,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/responses" @@ -34003,7 +32946,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/responses" @@ -34021,7 +32963,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/responses" @@ -34035,7 +32976,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "responses", "supported_endpoints": [ "/v1/chat/completions", @@ -34050,7 +32990,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "responses", "supported_endpoints": [ "/v1/chat/completions", @@ -34066,7 +33005,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/responses" @@ -34081,7 +33019,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "responses", "supported_endpoints": [ "/v1/chat/completions", @@ -34101,7 +33038,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/responses" @@ -34116,7 +33052,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "responses", "supported_endpoints": [ "/v1/responses" @@ -34132,7 +33067,6 @@ "litellm_provider": "gigachat", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true, @@ -34143,7 +33077,6 @@ "litellm_provider": "gigachat", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true, @@ -34155,7 +33088,6 @@ "litellm_provider": "gigachat", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true, @@ -34166,7 +33098,6 @@ "input_cost_per_token": 0.0, "litellm_provider": "gigachat", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024 @@ -34175,7 +33106,6 @@ "input_cost_per_token": 0.0, "litellm_provider": "gigachat", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024 @@ -34184,7 +33114,6 @@ "input_cost_per_token": 0.0, "litellm_provider": "gigachat", "max_input_tokens": 4096, - "max_tokens": 4096, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 2560 @@ -34193,7 +33122,6 @@ "input_cost_per_token": 0.0, "litellm_provider": "gigachat", "max_input_tokens": 4096, - "max_tokens": 4096, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 2048 @@ -34203,7 +33131,6 @@ "litellm_provider": "gmi", "max_input_tokens": 409600, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 2.5e-05, "supports_function_calling": true, @@ -34215,7 +33142,6 @@ "litellm_provider": "gmi", "max_input_tokens": 409600, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -34226,7 +33152,6 @@ "litellm_provider": "gmi", "max_input_tokens": 409600, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -34237,7 +33162,6 @@ "litellm_provider": "gmi", "max_input_tokens": 409600, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_function_calling": true, @@ -34248,7 +33172,6 @@ "litellm_provider": "gmi", "max_input_tokens": 409600, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.4e-05, "supports_function_calling": true @@ -34258,7 +33181,6 @@ "litellm_provider": "gmi", "max_input_tokens": 409600, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1e-05, "supports_function_calling": true @@ -34268,7 +33190,6 @@ "litellm_provider": "gmi", "max_input_tokens": 409600, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1e-05, "supports_function_calling": true @@ -34278,7 +33199,6 @@ "litellm_provider": "gmi", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "supports_function_calling": true, @@ -34289,7 +33209,6 @@ "litellm_provider": "gmi", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -34300,7 +33219,6 @@ "litellm_provider": "gmi", "max_input_tokens": 163840, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 4e-07, "supports_function_calling": true @@ -34310,7 +33228,6 @@ "litellm_provider": "gmi", "max_input_tokens": 163840, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 8.8e-07, "supports_function_calling": true @@ -34320,7 +33237,6 @@ "litellm_provider": "gmi", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3e-06, "supports_function_calling": true, @@ -34332,7 +33248,6 @@ "litellm_provider": "gmi", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06 }, @@ -34341,7 +33256,6 @@ "litellm_provider": "gmi", "max_input_tokens": 196608, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06 }, @@ -34373,7 +33287,6 @@ "litellm_provider": "baseten", "max_input_tokens": 200000, "max_output_tokens": 200000, - "max_tokens": 200000, "mode": "chat", "output_cost_per_token": 2.2e-06, "source": "https://inference.baseten.co/v1/models", @@ -34418,7 +33331,6 @@ "litellm_provider": "baseten", "max_input_tokens": 128072, "max_output_tokens": 128072, - "max_tokens": 128072, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inference.baseten.co/v1/models", @@ -34448,7 +33360,6 @@ "litellm_provider": "gmi", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.4e-06, "supports_vision": true @@ -34458,7 +33369,6 @@ "litellm_provider": "gmi", "max_input_tokens": 202752, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 2e-06 }, @@ -34471,7 +33381,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2.9e-07, "output_cost_per_token_batches": 1.5e-07, @@ -34493,7 +33402,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 3.8e-07, "output_cost_per_token_batches": 1.9e-07, @@ -34515,7 +33423,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 8e-08, "output_cost_per_token_batches": 4e-08, @@ -34547,7 +33454,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -34587,7 +33493,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -34621,7 +33526,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -34653,7 +33557,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 1.25e-06, @@ -34674,7 +33577,6 @@ "litellm_provider": "openai", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://developers.openai.com/api/docs/pricing", @@ -34690,7 +33592,6 @@ "litellm_provider": "openai", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-06, "output_cost_per_token_batches": 7.5e-07, @@ -34708,7 +33609,6 @@ "litellm_provider": "openai", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2e-06, "output_cost_per_token_batches": 2e-06, @@ -34725,7 +33625,6 @@ "litellm_provider": "openai", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 4e-06, "supports_prompt_caching": true, @@ -34738,7 +33637,6 @@ "litellm_provider": "text-completion-openai", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 2e-06, "source": "https://developers.openai.com/api/docs/pricing" @@ -34748,7 +33646,6 @@ "litellm_provider": "text-completion-openai", "max_input_tokens": 8192, "max_output_tokens": 4097, - "max_tokens": 4097, "mode": "completion", "output_cost_per_token": 2e-06 }, @@ -34758,7 +33655,6 @@ "litellm_provider": "openai", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-05, "supports_function_calling": true, @@ -34773,7 +33669,6 @@ "litellm_provider": "openai", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-05, "output_cost_per_token_batches": 3e-05, @@ -34789,7 +33684,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3e-05, "supports_function_calling": true, @@ -34804,7 +33698,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3e-05, "supports_function_calling": true, @@ -34822,7 +33715,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3e-05, "output_cost_per_token_batches": 1.5e-05, @@ -34844,7 +33736,6 @@ "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "output_cost_per_token_batches": 4e-06, @@ -34888,7 +33779,6 @@ "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "output_cost_per_token_priority": 1.4e-05, @@ -34931,7 +33821,6 @@ "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.6e-06, "output_cost_per_token_batches": 8e-07, @@ -34975,7 +33864,6 @@ "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.6e-06, "output_cost_per_token_priority": 2.8e-06, @@ -35019,7 +33907,6 @@ "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-07, "output_cost_per_token_batches": 2e-07, @@ -35057,7 +33944,6 @@ "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-07, "output_cost_per_token_priority": 8e-07, @@ -35094,7 +33980,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -35117,7 +34002,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 7.5e-06, @@ -35141,7 +34025,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_priority": 1.7e-05, @@ -35166,7 +34049,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_priority": 1.7e-05, @@ -35188,7 +34070,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 8e-05, "output_cost_per_token": 1e-05, @@ -35206,7 +34087,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 8e-05, "output_cost_per_token": 1e-05, @@ -35224,7 +34104,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1e-05, @@ -35261,7 +34140,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1e-05, @@ -35296,7 +34174,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1e-05, @@ -35334,7 +34211,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -35372,7 +34248,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -35409,7 +34284,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -35450,7 +34324,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -35480,7 +34353,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_priority": 1e-06, @@ -35507,7 +34379,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 6e-07, @@ -35527,7 +34398,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -35545,7 +34415,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -35572,7 +34441,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -35653,7 +34521,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -35680,7 +34547,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -36234,7 +35100,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -36280,7 +35145,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "source": "https://developers.openai.com/api/docs/models/gpt-5-codex", @@ -36315,7 +35179,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_priority": 2e-05, @@ -36365,7 +35228,6 @@ "litellm_provider": "openai", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 2e-06, "source": "https://developers.openai.com/api/docs/models/gpt-5.1-codex-mini", @@ -36396,7 +35258,6 @@ "litellm_provider": "openai", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "source": "https://developers.openai.com/api/docs/models/gpt-5.1-codex-max", @@ -36428,7 +35289,6 @@ "litellm_provider": "openai", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "source": "https://developers.openai.com/api/docs/models/gpt-5.1-codex", @@ -36460,7 +35320,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://developers.openai.com/api/docs/models/gpt-5.1-chat-latest", @@ -36495,7 +35354,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_priority": 2e-05, @@ -36547,7 +35405,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.4e-05, "output_cost_per_token_priority": 2.8e-05, @@ -36598,7 +35455,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.4e-05, "source": "https://developers.openai.com/api/docs/models/gpt-5.2-codex", @@ -36630,7 +35486,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.4e-05, "source": "https://developers.openai.com/api/docs/models/gpt-5.2-chat-latest", @@ -36665,7 +35520,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.4e-05, "output_cost_per_token_priority": 2.8e-05, @@ -36715,7 +35569,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.000168, "output_cost_per_token_batches": 8.4e-05, @@ -36757,7 +35610,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.000168, "output_cost_per_token_batches": 8.4e-05, @@ -36795,6 +35647,16 @@ }, "gpt-6-astra": { "cache_creation_input_token_cost": 1.25e-05, + "cache_creation_input_token_cost_above_12hr": 2.5e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 5e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches": 2.5e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": 2.5e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": 0.0001, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_ultrafast": 0.0003, + "cache_creation_input_token_cost_above_12hr_batches": 1.25e-05, + "cache_creation_input_token_cost_above_12hr_flex": 1.25e-05, + "cache_creation_input_token_cost_above_12hr_priority": 5e-05, + "cache_creation_input_token_cost_above_12hr_ultrafast": 0.00015, "cache_creation_input_token_cost_above_272k_tokens": 2.5e-05, "cache_creation_input_token_cost_above_272k_tokens_flex": 1.25e-05, "cache_creation_input_token_cost_above_272k_tokens_priority": 5e-05, @@ -36827,7 +35689,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_above_272k_tokens": 7.5e-05, @@ -36880,6 +35741,14 @@ }, "gpt-6-sol": { "cache_creation_input_token_cost": 2.5e-06, + "cache_creation_input_token_cost_above_12hr": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 1e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": 2e-05, + "cache_creation_input_token_cost_above_12hr_batches": 2.5e-06, + "cache_creation_input_token_cost_above_12hr_flex": 2.5e-06, + "cache_creation_input_token_cost_above_12hr_priority": 1e-05, "cache_creation_input_token_cost_above_272k_tokens": 5e-06, "cache_creation_input_token_cost_above_272k_tokens_flex": 2.5e-06, "cache_creation_input_token_cost_above_272k_tokens_priority": 1e-05, @@ -36906,7 +35775,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -36957,6 +35825,14 @@ }, "gpt-6-luna": { "cache_creation_input_token_cost": 1.25e-07, + "cache_creation_input_token_cost_above_12hr": 2.5e-07, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 5e-07, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches": 2.5e-07, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": 2.5e-07, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": 1e-06, + "cache_creation_input_token_cost_above_12hr_batches": 1.25e-07, + "cache_creation_input_token_cost_above_12hr_flex": 1.25e-07, + "cache_creation_input_token_cost_above_12hr_priority": 5e-07, "cache_creation_input_token_cost_decisions": 1.25e-07, "cache_creation_input_token_cost_above_272k_tokens": 2.5e-07, "cache_creation_input_token_cost_above_272k_tokens_decisions": 2.5e-07, @@ -36989,7 +35865,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_decisions": 0.0, @@ -37043,6 +35918,12 @@ }, "gpt-5.6": { "cache_creation_input_token_cost": 5e-06, + "cache_creation_input_token_cost_above_12hr": 1e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 2e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": 1e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": 4e-05, + "cache_creation_input_token_cost_above_12hr_flex": 5e-06, + "cache_creation_input_token_cost_above_12hr_priority": 2e-05, "cache_creation_input_token_cost_above_272k_tokens": 1e-05, "cache_creation_input_token_cost_above_272k_tokens_flex": 5e-06, "cache_creation_input_token_cost_above_272k_tokens_priority": 2e-05, @@ -37069,7 +35950,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "output_cost_per_token_above_272k_tokens": 3e-05, @@ -37117,6 +35997,14 @@ }, "gpt-5.6-sol": { "cache_creation_input_token_cost": 5e-06, + "cache_creation_input_token_cost_above_12hr": 1e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 2e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches": 1e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": 1e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": 4e-05, + "cache_creation_input_token_cost_above_12hr_batches": 5e-06, + "cache_creation_input_token_cost_above_12hr_flex": 5e-06, + "cache_creation_input_token_cost_above_12hr_priority": 2e-05, "cache_creation_input_token_cost_above_272k_tokens": 1e-05, "cache_creation_input_token_cost_above_272k_tokens_flex": 5e-06, "cache_creation_input_token_cost_above_272k_tokens_priority": 2e-05, @@ -37143,7 +36031,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "output_cost_per_token_above_272k_tokens": 3e-05, @@ -37193,6 +36080,14 @@ }, "gpt-5.6-terra": { "cache_creation_input_token_cost": 2.5e-06, + "cache_creation_input_token_cost_above_12hr": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 1e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": 2e-05, + "cache_creation_input_token_cost_above_12hr_batches": 2.5e-06, + "cache_creation_input_token_cost_above_12hr_flex": 2.5e-06, + "cache_creation_input_token_cost_above_12hr_priority": 1e-05, "cache_creation_input_token_cost_above_272k_tokens": 5e-06, "cache_creation_input_token_cost_above_272k_tokens_flex": 2.5e-06, "cache_creation_input_token_cost_above_272k_tokens_priority": 1e-05, @@ -37219,7 +36114,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_272k_tokens": 1.8e-05, @@ -37268,6 +36162,14 @@ }, "gpt-5.6-luna": { "cache_creation_input_token_cost": 2.5e-07, + "cache_creation_input_token_cost_above_12hr": 5e-07, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 1e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches": 5e-07, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": 5e-07, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": 2e-06, + "cache_creation_input_token_cost_above_12hr_batches": 2.5e-07, + "cache_creation_input_token_cost_above_12hr_flex": 2.5e-07, + "cache_creation_input_token_cost_above_12hr_priority": 1e-06, "cache_creation_input_token_cost_above_272k_tokens": 5e-07, "cache_creation_input_token_cost_above_272k_tokens_flex": 2.5e-07, "cache_creation_input_token_cost_above_272k_tokens_priority": 1e-06, @@ -37294,7 +36196,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_above_272k_tokens": 1.8e-06, @@ -37343,6 +36244,7 @@ }, "gpt-5.6-cyber": { "cache_creation_input_token_cost": 1.5625e-05, + "cache_creation_input_token_cost_above_12hr": 3.125e-05, "cache_creation_input_token_cost_above_272k_tokens": 3.125e-05, "cache_read_input_token_cost": 1.25e-06, "cache_read_input_token_cost_above_272k_tokens": 2.5e-06, @@ -37351,7 +36253,6 @@ "litellm_provider": "openai", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 7.5e-05, "output_cost_per_token_above_272k_tokens": 0.0001125, @@ -37390,7 +36291,6 @@ "litellm_provider": "openai", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 7.5e-05, "output_cost_per_token_above_272k_tokens": 0.0001125, @@ -37429,7 +36329,6 @@ "litellm_provider": "openai", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 7.5e-05, "output_cost_per_token_above_272k_tokens": 0.0001125, @@ -37467,7 +36366,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "output_cost_per_token_above_272k_tokens": 3e-05, @@ -37506,7 +36404,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 2e-05, "output_cost_per_token_above_272k_tokens": 3e-05, @@ -37540,7 +36437,6 @@ "litellm_provider": "openai", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "reasoning_effort_levels": [ @@ -37586,7 +36482,6 @@ "litellm_provider": "openai", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "output_cost_per_token_above_272k_tokens": 4.5e-05, @@ -37649,7 +36544,6 @@ "litellm_provider": "openai", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "output_cost_per_token_above_272k_tokens": 4.5e-05, @@ -37705,7 +36599,6 @@ "litellm_provider": "openai", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -37757,7 +36650,6 @@ "litellm_provider": "openai", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -37816,7 +36708,6 @@ "litellm_provider": "openai", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_above_272k_tokens": 2.25e-05, @@ -37874,7 +36765,6 @@ "litellm_provider": "openai", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_above_272k_tokens": 2.25e-05, @@ -37925,7 +36815,6 @@ "litellm_provider": "openai", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -37978,7 +36867,6 @@ "litellm_provider": "openai", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -38034,7 +36922,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.5e-06, "output_cost_per_token_flex": 2.25e-06, @@ -38089,7 +36976,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.5e-06, "output_cost_per_token_flex": 2.25e-06, @@ -38142,7 +37028,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.25e-06, "output_cost_per_token_flex": 6.25e-07, @@ -38194,7 +37079,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.25e-06, "output_cost_per_token_flex": 6.25e-07, @@ -38241,7 +37125,6 @@ "litellm_provider": "openai", "max_input_tokens": 400000, "max_output_tokens": 272000, - "max_tokens": 272000, "mode": "responses", "output_cost_per_token": 0.00012, "output_cost_per_token_batches": 6e-05, @@ -38284,7 +37167,6 @@ "litellm_provider": "openai", "max_input_tokens": 400000, "max_output_tokens": 272000, - "max_tokens": 272000, "mode": "responses", "output_cost_per_token": 0.00012, "output_cost_per_token_batches": 6e-05, @@ -38333,7 +37215,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -38379,7 +37260,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "supported_endpoints": [ @@ -38415,7 +37295,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://developers.openai.com/api/docs/models/gpt-5-chat-latest", @@ -38448,7 +37327,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.4e-05, "output_cost_per_token_priority": 2.8e-05, @@ -38492,7 +37370,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.4e-05, "source": "https://developers.openai.com/api/docs/models/gpt-5.3-chat-latest", @@ -38529,7 +37406,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-06, "output_cost_per_token_batches": 1e-06, @@ -38581,7 +37457,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-06, "output_cost_per_token_batches": 1e-06, @@ -38631,7 +37506,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4e-07, "output_cost_per_token_batches": 2e-07, @@ -38681,7 +37555,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4e-07, "output_cost_per_token_batches": 2e-07, @@ -38767,7 +37640,6 @@ "litellm_provider": "openai", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1.6e-05, @@ -38802,7 +37674,6 @@ "litellm_provider": "openai", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1.6e-05, @@ -38837,7 +37708,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 2.4e-05, @@ -38872,7 +37742,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 2.4e-05, @@ -38909,7 +37778,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "realtime", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -38947,7 +37815,6 @@ "litellm_provider": "openai", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -38983,7 +37850,6 @@ "litellm_provider": "openai", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1.6e-05, @@ -39009,7 +37875,6 @@ }, "gradient_ai/alibaba-qwen3-32b": { "litellm_provider": "gradient_ai", - "max_tokens": 40960, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions" @@ -39024,7 +37889,6 @@ "gradient_ai/anthropic-claude-3-opus": { "input_cost_per_token": 1.5e-05, "litellm_provider": "gradient_ai", - "max_tokens": 1024, "mode": "chat", "output_cost_per_token": 7.5e-05, "supported_endpoints": [ @@ -39040,7 +37904,6 @@ "gradient_ai/anthropic-claude-3.5-haiku": { "input_cost_per_token": 8e-07, "litellm_provider": "gradient_ai", - "max_tokens": 1024, "mode": "chat", "output_cost_per_token": 4e-06, "supported_endpoints": [ @@ -39056,7 +37919,6 @@ "gradient_ai/anthropic-claude-3.5-sonnet": { "input_cost_per_token": 3e-06, "litellm_provider": "gradient_ai", - "max_tokens": 1024, "mode": "chat", "output_cost_per_token": 1.5e-05, "supported_endpoints": [ @@ -39072,7 +37934,6 @@ "gradient_ai/anthropic-claude-3.7-sonnet": { "input_cost_per_token": 3e-06, "litellm_provider": "gradient_ai", - "max_tokens": 1024, "mode": "chat", "output_cost_per_token": 1.5e-05, "supported_endpoints": [ @@ -39088,7 +37949,6 @@ "gradient_ai/deepseek-r1-distill-llama-70b": { "input_cost_per_token": 9.9e-07, "litellm_provider": "gradient_ai", - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 9.9e-07, "supported_endpoints": [ @@ -39104,7 +37964,6 @@ "gradient_ai/llama3-8b-instruct": { "input_cost_per_token": 2e-07, "litellm_provider": "gradient_ai", - "max_tokens": 512, "mode": "chat", "output_cost_per_token": 2e-07, "supported_endpoints": [ @@ -39120,7 +37979,6 @@ "gradient_ai/llama3.3-70b-instruct": { "input_cost_per_token": 6.5e-07, "litellm_provider": "gradient_ai", - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 6.5e-07, "supported_endpoints": [ @@ -39136,7 +37994,6 @@ "gradient_ai/mistral-nemo-instruct-2407": { "input_cost_per_token": 3e-07, "litellm_provider": "gradient_ai", - "max_tokens": 512, "mode": "chat", "output_cost_per_token": 3e-07, "supported_endpoints": [ @@ -39151,7 +38008,6 @@ }, "gradient_ai/openai-gpt-4o": { "litellm_provider": "gradient_ai", - "max_tokens": 16384, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions" @@ -39165,7 +38021,6 @@ }, "gradient_ai/openai-gpt-4o-mini": { "litellm_provider": "gradient_ai", - "max_tokens": 16384, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions" @@ -39180,7 +38035,6 @@ "gradient_ai/openai-o3": { "input_cost_per_token": 2e-06, "litellm_provider": "gradient_ai", - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8e-06, "supported_endpoints": [ @@ -39196,7 +38050,6 @@ "gradient_ai/openai-o3-mini": { "input_cost_per_token": 1.1e-06, "litellm_provider": "gradient_ai", - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "supported_endpoints": [ @@ -39212,7 +38065,6 @@ "lemonade/Qwen3-Coder-30B-A3B-Instruct-GGUF": { "input_cost_per_token": 0, "litellm_provider": "lemonade", - "max_tokens": 32768, "max_input_tokens": 262144, "max_output_tokens": 32768, "mode": "chat", @@ -39224,7 +38076,6 @@ "lemonade/gpt-oss-20b-mxfp4-GGUF": { "input_cost_per_token": 0, "litellm_provider": "lemonade", - "max_tokens": 32768, "max_input_tokens": 131072, "max_output_tokens": 32768, "mode": "chat", @@ -39236,7 +38087,6 @@ "lemonade/gpt-oss-120b-mxfp-GGUF": { "input_cost_per_token": 0, "litellm_provider": "lemonade", - "max_tokens": 32768, "max_input_tokens": 131072, "max_output_tokens": 32768, "mode": "chat", @@ -39248,7 +38098,6 @@ "lemonade/Gemma-3-4b-it-GGUF": { "input_cost_per_token": 0, "litellm_provider": "lemonade", - "max_tokens": 8192, "max_input_tokens": 128000, "max_output_tokens": 8192, "mode": "chat", @@ -39260,7 +38109,6 @@ "lemonade/Qwen3-4B-Instruct-2507-GGUF": { "input_cost_per_token": 0, "litellm_provider": "lemonade", - "max_tokens": 32768, "max_input_tokens": 262144, "max_output_tokens": 32768, "mode": "chat", @@ -39274,7 +38122,6 @@ "litellm_provider": "amazon_nova", "max_input_tokens": 128000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 1.4e-07, "supports_function_calling": true, @@ -39286,7 +38133,6 @@ "litellm_provider": "amazon_nova", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 2.4e-07, "supports_function_calling": true, @@ -39300,7 +38146,6 @@ "litellm_provider": "amazon_nova", "max_input_tokens": 1000000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 1.25e-05, "supports_function_calling": true, @@ -39314,7 +38159,6 @@ "litellm_provider": "amazon_nova", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 3.2e-06, "supports_function_calling": true, @@ -39328,7 +38172,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "groq", "max_input_tokens": 8192, - "max_tokens": 8192, + "max_output_tokens": 8192, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://console.groq.com/docs/model/llama-guard-3-8b" @@ -39338,7 +38182,6 @@ "litellm_provider": "groq", "max_input_tokens": 512, "max_output_tokens": 512, - "max_tokens": 512, "mode": "chat", "output_cost_per_token": 3e-08, "source": "https://console.groq.com/docs/models" @@ -39348,7 +38191,6 @@ "litellm_provider": "groq", "max_input_tokens": 512, "max_output_tokens": 512, - "max_tokens": 512, "mode": "chat", "output_cost_per_token": 4e-08, "source": "https://console.groq.com/docs/model/meta-llama/llama-prompt-guard-2-86m" @@ -39359,7 +38201,6 @@ "litellm_provider": "groq", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 6e-07, "search_context_cost_per_query": { @@ -39380,7 +38221,6 @@ "litellm_provider": "groq", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3e-07, "search_context_cost_per_query": { @@ -39401,7 +38241,6 @@ "litellm_provider": "groq", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3e-07, "search_context_cost_per_query": { @@ -39420,7 +38259,6 @@ "litellm_provider": "groq", "max_input_tokens": 4000, "max_output_tokens": 50000, - "max_tokens": 50000, "mode": "audio_speech", "source": "https://console.groq.com/docs/model/canopylabs/orpheus-v1-english" }, @@ -39429,7 +38267,6 @@ "litellm_provider": "groq", "max_input_tokens": 4000, "max_output_tokens": 50000, - "max_tokens": 50000, "mode": "audio_speech", "source": "https://console.groq.com/docs/models" }, @@ -39447,7 +38284,6 @@ }, "heroku/claude-3-5-haiku": { "litellm_provider": "heroku", - "max_tokens": 8192, "mode": "chat", "supports_function_calling": true, "supports_system_messages": true, @@ -39457,7 +38293,6 @@ }, "heroku/claude-3-5-sonnet-latest": { "litellm_provider": "heroku", - "max_tokens": 8192, "mode": "chat", "supports_function_calling": true, "supports_system_messages": true, @@ -39467,7 +38302,6 @@ }, "heroku/claude-3-7-sonnet": { "litellm_provider": "heroku", - "max_tokens": 8192, "mode": "chat", "supports_function_calling": true, "supports_system_messages": true, @@ -39477,7 +38311,6 @@ }, "heroku/claude-4-sonnet": { "litellm_provider": "heroku", - "max_tokens": 8192, "mode": "chat", "supports_function_calling": true, "supports_system_messages": true, @@ -39523,7 +38356,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -39536,7 +38368,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-07, "supports_function_calling": true, @@ -39549,7 +38380,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -39562,7 +38392,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -39575,7 +38404,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-06, "supports_function_calling": true, @@ -39588,7 +38416,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-07, "supports_function_calling": true, @@ -39601,7 +38428,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.5e-07, "supports_function_calling": true, @@ -39614,7 +38440,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2e-07, "supports_function_calling": true, @@ -39627,7 +38452,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-07, "supports_function_calling": true, @@ -39640,7 +38464,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -39653,7 +38476,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -39666,7 +38488,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -39679,7 +38500,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -39692,7 +38512,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -39705,7 +38524,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -39718,7 +38536,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-06, "supports_function_calling": true, @@ -39731,7 +38548,6 @@ "litellm_provider": "ai21", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "completion", "output_cost_per_token": 3e-06 }, @@ -39740,7 +38556,6 @@ "litellm_provider": "ai21", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "completion", "output_cost_per_token": 1e-05 }, @@ -39749,7 +38564,6 @@ "litellm_provider": "ai21", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "completion", "output_cost_per_token": 1.5e-05 }, @@ -39758,7 +38572,6 @@ "litellm_provider": "ai21", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4e-07, "supports_tool_choice": true @@ -39768,7 +38581,6 @@ "litellm_provider": "ai21", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 8e-06, "supports_tool_choice": true @@ -39778,7 +38590,6 @@ "litellm_provider": "ai21", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 8e-06, "supports_tool_choice": true @@ -39788,7 +38599,6 @@ "litellm_provider": "ai21", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4e-07, "supports_tool_choice": true @@ -39798,7 +38608,6 @@ "litellm_provider": "ai21", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4e-07, "supports_tool_choice": true @@ -39808,7 +38617,6 @@ "litellm_provider": "ai21", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 8e-06, "supports_tool_choice": true @@ -39818,7 +38626,6 @@ "litellm_provider": "ai21", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 8e-06, "supports_tool_choice": true @@ -39828,7 +38635,6 @@ "litellm_provider": "ai21", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4e-07, "supports_tool_choice": true @@ -39838,7 +38644,6 @@ "litellm_provider": "ai21", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4e-07, "supports_tool_choice": true @@ -39848,7 +38653,6 @@ "litellm_provider": "jina_ai", "max_input_tokens": 1024, "max_output_tokens": 1024, - "max_tokens": 1024, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://api.jina.ai/v1/models" @@ -39868,7 +38672,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.65e-05, "search_context_cost_per_query": { @@ -39905,7 +38708,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5.5e-06, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -39933,7 +38735,6 @@ "litellm_provider": "crusoe", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "mode": "chat", "output_cost_per_token": 7e-06, "supports_function_calling": false, @@ -39946,7 +38747,6 @@ "litellm_provider": "crusoe", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "mode": "chat", "output_cost_per_token": 1.5e-06, "supports_function_calling": true, @@ -39959,7 +38759,6 @@ "litellm_provider": "crusoe", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1e-07, "supports_function_calling": true, @@ -39973,7 +38772,6 @@ "litellm_provider": "crusoe", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-07, "supports_function_calling": true, @@ -39986,7 +38784,6 @@ "litellm_provider": "crusoe", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 2.5e-06, "supports_function_calling": false, @@ -39999,7 +38796,6 @@ "litellm_provider": "crusoe", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 8e-07, "supports_function_calling": true, @@ -40012,7 +38808,6 @@ "litellm_provider": "crusoe", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 3e-06, "supports_function_calling": true, @@ -40026,7 +38821,6 @@ "litellm_provider": "inception", "max_input_tokens": 128000, "max_output_tokens": 50000, - "max_tokens": 50000, "mode": "chat", "output_cost_per_token": 7.5e-07, "supports_function_calling": true, @@ -40041,7 +38835,6 @@ "litellm_provider": "inception", "max_input_tokens": 260000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 7.5e-07, "source": "https://docs.inceptionlabs.ai/get-started/models", @@ -40056,7 +38849,7 @@ "input_cost_per_token": 1.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 3.8e-07, "source": "https://inferenceapis.com/pricing", @@ -40077,7 +38870,7 @@ "input_cost_per_token": 1.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 3.8e-07, "source": "https://inferenceapis.com/pricing", @@ -40098,7 +38891,7 @@ "input_cost_per_token": 1.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 3.8e-07, "source": "https://inferenceapis.com/pricing", @@ -40119,7 +38912,7 @@ "input_cost_per_token": 1.72e-06, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 5.15e-06, "source": "https://inferenceapis.com/pricing", @@ -40140,7 +38933,7 @@ "input_cost_per_token": 1.72e-06, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 5.15e-06, "source": "https://inferenceapis.com/pricing", @@ -40161,7 +38954,7 @@ "input_cost_per_token": 4e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.6e-06, "source": "https://inferenceapis.com/pricing", @@ -40182,7 +38975,7 @@ "input_cost_per_token": 1.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 3.8e-07, "source": "https://inferenceapis.com/pricing", @@ -40203,7 +38996,7 @@ "input_cost_per_token": 4e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.6e-06, "source": "https://inferenceapis.com/pricing", @@ -40224,7 +39017,7 @@ "input_cost_per_token": 1.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 3.8e-07, "source": "https://inferenceapis.com/pricing", @@ -40245,7 +39038,7 @@ "input_cost_per_token": 1.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 3.8e-07, "source": "https://inferenceapis.com/pricing", @@ -40266,7 +39059,7 @@ "input_cost_per_token": 1.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 3.8e-07, "source": "https://inferenceapis.com/pricing", @@ -40287,7 +39080,7 @@ "input_cost_per_token": 1.72e-06, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 5.15e-06, "source": "https://inferenceapis.com/pricing", @@ -40308,7 +39101,7 @@ "input_cost_per_token": 4e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.6e-06, "source": "https://inferenceapis.com/pricing", @@ -40329,7 +39122,7 @@ "input_cost_per_token": 1.82e-06, "litellm_provider": "inferenceapis", "max_input_tokens": 1048575, - "max_tokens": 1048575, + "max_output_tokens": 1048575, "mode": "chat", "output_cost_per_token": 5.72e-06, "source": "https://inferenceapis.com/pricing", @@ -40350,7 +39143,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048575, - "max_tokens": 1048575, + "max_output_tokens": 1048575, "mode": "chat", "output_cost_per_token": 6.6e-07, "source": "https://inferenceapis.com/pricing", @@ -40370,7 +39163,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 8e-07, "source": "https://inferenceapis.com/pricing", @@ -40389,7 +39182,7 @@ "input_cost_per_token": 4e-08, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.9e-07, "source": "https://inferenceapis.com/pricing", @@ -40409,7 +39202,7 @@ "input_cost_per_token": 8.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 4.42e-06, "source": "https://inferenceapis.com/pricing", @@ -40429,7 +39222,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inferenceapis.com/pricing", @@ -40448,7 +39241,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inferenceapis.com/pricing", @@ -40467,7 +39260,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inferenceapis.com/pricing", @@ -40486,7 +39279,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inferenceapis.com/pricing", @@ -40505,7 +39298,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inferenceapis.com/pricing", @@ -40524,7 +39317,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inferenceapis.com/pricing", @@ -40544,7 +39337,7 @@ "input_cost_per_token": 3.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 524288, - "max_tokens": 524288, + "max_output_tokens": 524288, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://inferenceapis.com/pricing", @@ -40565,7 +39358,7 @@ "input_cost_per_token": 3.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 524288, - "max_tokens": 524288, + "max_output_tokens": 524288, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://inferenceapis.com/pricing", @@ -40586,7 +39379,7 @@ "input_cost_per_token": 8.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 4.42e-06, "source": "https://inferenceapis.com/pricing", @@ -40606,7 +39399,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 8e-07, "source": "https://inferenceapis.com/pricing", @@ -40625,7 +39418,7 @@ "input_cost_per_token": 4e-08, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.9e-07, "source": "https://inferenceapis.com/pricing", @@ -40644,7 +39437,7 @@ "input_cost_per_token": 2.6e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.15e-06, "source": "https://inferenceapis.com/pricing", @@ -40664,7 +39457,7 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inferenceapis.com/pricing", @@ -40684,7 +39477,7 @@ "input_cost_per_token": 2.6e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.15e-06, "source": "https://inferenceapis.com/pricing", @@ -40703,7 +39496,7 @@ "input_cost_per_token": 2.6e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.15e-06, "source": "https://inferenceapis.com/pricing", @@ -40723,7 +39516,7 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inferenceapis.com/pricing", @@ -40744,7 +39537,7 @@ "input_cost_per_token": 1.82e-06, "litellm_provider": "inferenceapis", "max_input_tokens": 1048575, - "max_tokens": 1048575, + "max_output_tokens": 1048575, "mode": "chat", "output_cost_per_token": 5.72e-06, "source": "https://inferenceapis.com/pricing", @@ -40765,7 +39558,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048575, - "max_tokens": 1048575, + "max_output_tokens": 1048575, "mode": "chat", "output_cost_per_token": 6.6e-07, "source": "https://inferenceapis.com/pricing", @@ -40787,7 +39580,6 @@ "litellm_provider": "text-completion-inception", "max_input_tokens": 32000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "completion", "output_cost_per_token": 7.5e-07 }, @@ -40796,7 +39588,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -40810,7 +39601,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -40824,7 +39614,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 8e-07, "supports_function_calling": true, @@ -40838,7 +39627,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -40851,7 +39639,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 8e-07, "supports_function_calling": true, @@ -40864,7 +39651,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -40877,7 +39663,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4e-08, "supports_function_calling": true, @@ -40890,7 +39675,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-07, "supports_function_calling": true, @@ -40903,7 +39687,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4e-08, "supports_function_calling": true, @@ -40916,7 +39699,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1e-07, "supports_function_calling": true, @@ -40929,7 +39711,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 16384, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1e-07, "supports_function_calling": true, @@ -40942,7 +39723,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 8e-07, "supports_function_calling": true, @@ -40955,7 +39735,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -40968,7 +39747,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4e-08, "supports_function_calling": true, @@ -40981,7 +39759,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -40994,7 +39771,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.5e-08, "supports_function_calling": true, @@ -41008,7 +39784,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.5e-08, "supports_function_calling": true, @@ -41021,7 +39796,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -41034,7 +39808,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1e-07, "supports_function_calling": true, @@ -41047,7 +39820,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1e-07, "supports_function_calling": true, @@ -41092,14 +39864,12 @@ "max-x-max/50-steps/stability.stable-diffusion-xl-v0": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.036 }, "max-x-max/max-steps/stability.stable-diffusion-xl-v0": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.072 }, @@ -41195,7 +39965,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 8192, "max_output_tokens": 1024, - "max_tokens": 1024, "mode": "chat", "output_cost_per_character": 1.5e-05, "source": "https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models#foundation_models", @@ -41206,7 +39975,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 32768, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_character": 1e-06, "source": "https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models#foundation_models", @@ -41217,7 +39985,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1e-06, "source": "https://aws.amazon.com/bedrock/pricing/" @@ -41227,7 +39994,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.56e-06, "source": "https://aws.amazon.com/bedrock/pricing/" @@ -41238,7 +40004,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/bedrock/USD/current/bedrock.json", @@ -41252,7 +40017,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.2e-07, "output_cost_per_token_batches": 3.6e-07, @@ -41267,7 +40031,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.2e-07, "output_cost_per_token_batches": 1.1e-07, @@ -41281,7 +40044,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.6e-07, "source": "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/bedrock/USD/current/bedrock.json", @@ -41295,7 +40057,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-2-1b-instruct.md", @@ -41308,7 +40069,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-2-3b-instruct.md", @@ -41321,7 +40081,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/bedrock/USD/current/bedrock.json", @@ -41336,7 +40095,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.2e-07, "output_cost_per_token_batches": 3.6e-07, @@ -41350,7 +40108,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 3.5e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-70b-instruct.md" @@ -41361,7 +40118,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-8b-instruct.md" @@ -41373,7 +40129,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 9.7e-07, "output_cost_per_token_batches": 4.85e-07, @@ -41396,7 +40151,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 10000000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6.6e-07, "output_cost_per_token_batches": 3.3e-07, @@ -41418,7 +40172,6 @@ "litellm_provider": "meta", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.25e-06, "search_context_cost_per_query": { @@ -41459,7 +40212,6 @@ "litellm_provider": "meta", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.25e-06, "search_context_cost_per_query": { @@ -41500,7 +40252,6 @@ "litellm_provider": "meta", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-07, "search_context_cost_per_query": { @@ -41541,7 +40292,6 @@ "litellm_provider": "meta", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.25e-06, "search_context_cost_per_query": { @@ -41582,7 +40332,6 @@ "litellm_provider": "meta", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-07, "search_context_cost_per_query": { @@ -41639,7 +40388,6 @@ "litellm_provider": "meta", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-05, "search_context_cost_per_query": { @@ -41680,7 +40428,6 @@ "litellm_provider": "meta_llama", "max_input_tokens": 128000, "max_output_tokens": 4028, - "max_tokens": 4028, "mode": "chat", "source": "https://ai.developer.meta.com/docs/models", "supported_modalities": [ @@ -41696,7 +40443,6 @@ "litellm_provider": "meta_llama", "max_input_tokens": 128000, "max_output_tokens": 4028, - "max_tokens": 4028, "mode": "chat", "source": "https://ai.developer.meta.com/docs/models", "supported_modalities": [ @@ -41712,7 +40458,6 @@ "litellm_provider": "meta_llama", "max_input_tokens": 1000000, "max_output_tokens": 4028, - "max_tokens": 4028, "mode": "chat", "source": "https://ai.developer.meta.com/docs/models", "supported_modalities": [ @@ -41729,7 +40474,6 @@ "litellm_provider": "meta_llama", "max_input_tokens": 10000000, "max_output_tokens": 4028, - "max_tokens": 4028, "mode": "chat", "source": "https://ai.developer.meta.com/docs/models", "supported_modalities": [ @@ -41751,7 +40495,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_batches": 6e-07, @@ -41774,7 +40517,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 196000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_batches": 6e-07, @@ -41798,7 +40540,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 196000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token_batches": 6e-07, "output_cost_per_token_priority": 2.1e-06, @@ -41996,7 +40737,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 2e-06, "output_cost_per_token_batches": 1e-06, @@ -42018,7 +40758,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 40000, - "max_tokens": 40000, "mode": "chat", "output_cost_per_token": 1.5e-06, "output_cost_per_token_batches": 7.5e-07, @@ -42040,7 +40779,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2e-07, "output_cost_per_token_batches": 1e-07, @@ -42062,7 +40800,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1e-07, "output_cost_per_token_batches": 5e-08, @@ -42084,7 +40821,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.5e-07, "output_cost_per_token_batches": 7e-08, @@ -42104,7 +40840,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mistral-7b-instruct.md", @@ -42115,7 +40850,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.2e-05, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mistral-large.md", @@ -42126,7 +40860,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/bedrock/USD/current/bedrock.json", @@ -42141,7 +40874,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.5e-06, "output_cost_per_token_batches": 7.5e-07, @@ -42161,7 +40893,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3e-06, "output_cost_per_token_batches": 1.5e-06, @@ -42174,7 +40905,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mixtral-8x7b-instruct.md", @@ -42189,7 +40919,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 32768, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4e-08, "output_cost_per_token_batches": 2e-08, @@ -42209,7 +40938,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 32768, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 3e-07, "output_cost_per_token_batches": 1.5e-07, @@ -42226,7 +40954,6 @@ "litellm_provider": "mistral", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://docs.mistral.ai/models/model-cards/codestral-25-08", @@ -42241,7 +40968,6 @@ "litellm_provider": "mistral", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://docs.mistral.ai/models/model-cards/codestral-25-08", @@ -42256,7 +40982,6 @@ "litellm_provider": "mistral", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2.5e-07, "source": "https://mistral.ai/technology/", @@ -42269,7 +40994,6 @@ "litellm_provider": "mistral", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://docs.mistral.ai/models/devstral-small-2-25-12", @@ -42284,7 +41008,6 @@ "litellm_provider": "mistral", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://mistral.ai/news/devstral-2-vibe-cli", @@ -42299,7 +41022,6 @@ "litellm_provider": "mistral", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://mistral.ai/news/devstral-2-vibe-cli", @@ -42313,7 +41035,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://docs.mistral.ai/models/ministral-3-14b-25-12", @@ -42329,7 +41050,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://docs.mistral.ai/models/ministral-3-14b-25-12", @@ -42345,7 +41065,6 @@ "litellm_provider": "mistral", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://docs.mistral.ai/models/ministral-3-3b-25-12", @@ -42361,7 +41080,6 @@ "litellm_provider": "mistral", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://docs.mistral.ai/models/ministral-3-3b-25-12", @@ -42376,7 +41094,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "mistral", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "source": "https://docs.mistral.ai/models/mistral-embed-23-12" }, @@ -42386,7 +41103,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 7.5e-06, "reasoning_effort_levels": [ @@ -42567,7 +41283,6 @@ "litellm_provider": "mistral", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://docs.mistral.ai/models/voxtral-small-25-07", @@ -42582,7 +41297,6 @@ "litellm_provider": "mistral", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://docs.mistral.ai/models/voxtral-small-25-07", @@ -42598,7 +41312,6 @@ "litellm_provider": "mistral", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "reasoning_effort_levels": [ @@ -42624,7 +41337,6 @@ "litellm_provider": "mistral", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "reasoning_effort_levels": [ @@ -42640,13 +41352,34 @@ "supports_response_schema": true, "supports_tool_choice": true }, + "mistral/zai-glm-5-3-flash": { + "cache_read_input_token_cost": 3e-08, + "input_cost_per_token": 1.5e-07, + "litellm_provider": "mistral", + "max_input_tokens": 1048576, + "max_output_tokens": 131072, + "mode": "chat", + "output_cost_per_token": 5e-07, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ], + "source": "https://docs.mistral.ai/models/zai-glm-5-3-flash", + "supports_assistant_prefill": true, + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": true + }, "mistral/zai-glm-5": { "cache_read_input_token_cost": 1.4e-07, "input_cost_per_token": 1.4e-06, "litellm_provider": "mistral", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "reasoning_effort_levels": [ @@ -42668,7 +41401,6 @@ "litellm_provider": "mistral", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "reasoning_effort_levels": [ @@ -42690,7 +41422,6 @@ "litellm_provider": "mistral", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "reasoning_effort_levels": [ @@ -42769,7 +41500,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 7.5e-06, "source": "https://docs.mistral.ai/models/model-cards/mistral-medium-3-5-26-04", @@ -42786,7 +41516,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://docs.mistral.ai/models/model-cards/mistral-small-4-0-26-03", @@ -42801,7 +41530,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "mistral", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding" }, "mistral/codestral-embed": { @@ -42809,7 +41537,6 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "mistral", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding" }, "mistral/codestral-embed-2505": { @@ -42817,7 +41544,6 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "mistral", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding" }, "mistral/mistral-large-4": { @@ -42825,7 +41551,7 @@ "input_cost_per_token": 6.8e-07, "litellm_provider": "mistral", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 2.09e-06, "reasoning_effort_levels": [ @@ -42846,7 +41572,7 @@ "input_cost_per_token": 6.8e-07, "litellm_provider": "mistral", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 2.09e-06, "reasoning_effort_levels": [ @@ -42868,7 +41594,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://docs.mistral.ai/models/mistral-large-3-25-12", @@ -42884,7 +41609,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://docs.mistral.ai/models/mistral-large-3-25-12", @@ -42900,7 +41624,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://docs.mistral.ai/models/mistral-large-3-25-12", @@ -42916,7 +41639,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 7.5e-06, "reasoning_effort_levels": [ @@ -42937,7 +41659,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 7.5e-06, "reasoning_effort_levels": [ @@ -42958,7 +41679,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 7.5e-06, "reasoning_effort_levels": [ @@ -42979,7 +41699,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 7.5e-06, "reasoning_effort_levels": [ @@ -43000,7 +41719,6 @@ "litellm_provider": "mistral", "max_input_tokens": 32000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 3e-07, "supports_assistant_prefill": true, @@ -43014,7 +41732,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 6e-07, "reasoning_effort_levels": [ @@ -43035,7 +41752,6 @@ "litellm_provider": "mistral", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://mistral.ai/pricing", @@ -43051,7 +41767,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://mistral.ai/pricing", @@ -43067,7 +41782,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://mistral.ai/pricing", @@ -43083,7 +41797,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://mistral.ai/pricing", @@ -43099,7 +41812,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://mistral.ai/pricing", @@ -43115,7 +41827,6 @@ "litellm_provider": "mistral", "max_input_tokens": 32000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.5e-07, "supports_assistant_prefill": true, @@ -43128,7 +41839,6 @@ "litellm_provider": "mistral", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://mistral.ai/technology/", @@ -43142,7 +41852,6 @@ "litellm_provider": "mistral", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-06, "supports_assistant_prefill": true, @@ -43159,7 +41868,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 1.25e-06, @@ -43181,7 +41889,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3e-06, "output_cost_per_token_batches": 1.5e-06, @@ -43201,7 +41908,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://platform.kimi.ai/docs/pricing/chat-k27-code", @@ -43219,7 +41925,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://platform.moonshot.ai/docs/guide/kimi-k2-5-quickstart", @@ -43236,7 +41941,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://platform.kimi.ai/docs/pricing/chat-k26", @@ -43253,7 +41957,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.5e-05, "reasoning_effort_levels": [ @@ -43274,7 +41977,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-06, "source": "https://platform.moonshot.ai/docs/pricing", @@ -43287,7 +41989,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-06, "source": "https://platform.moonshot.ai/docs/pricing", @@ -43301,7 +42002,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://platform.moonshot.ai/docs/pricing", @@ -43314,7 +42014,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://platform.moonshot.ai/docs/pricing", @@ -43328,7 +42027,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://platform.moonshot.ai/docs/pricing", @@ -43341,7 +42039,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://platform.moonshot.ai/docs/pricing", @@ -43355,7 +42052,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-06, "source": "https://platform.moonshot.ai/docs/pricing", @@ -43368,7 +42064,6 @@ "litellm_provider": "morph", "max_input_tokens": 16000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 1.2e-06, "supports_function_calling": false, @@ -43382,7 +42077,6 @@ "litellm_provider": "morph", "max_input_tokens": 16000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 1.9e-06, "supports_function_calling": false, @@ -43400,7 +42094,6 @@ "input_cost_per_video_per_second_above_8s_interval": 0.001, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 2048, - "max_tokens": 2048, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 768, @@ -43424,7 +42117,6 @@ "input_cost_per_video_per_second_above_8s_interval": 0.001, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 2048, - "max_tokens": 2048, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 768, @@ -43584,7 +42276,6 @@ ] }, "nebius/deepseek-ai/DeepSeek-R1": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 8e-07, @@ -43596,7 +42287,6 @@ "source": "https://nebius.com/prices" }, "nebius/deepseek-ai/DeepSeek-R1-0528": { - "max_tokens": 164000, "max_input_tokens": 164000, "max_output_tokens": 164000, "input_cost_per_token": 8e-07, @@ -43608,7 +42298,6 @@ "source": "https://nebius.com/prices" }, "nebius/deepseek-ai/DeepSeek-R1-Distill-Llama-70B": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2.5e-07, @@ -43619,7 +42308,6 @@ "source": "https://nebius.com/prices" }, "nebius/deepseek-ai/DeepSeek-V3": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 5e-07, @@ -43630,7 +42318,6 @@ "source": "https://nebius.com/prices" }, "nebius/deepseek-ai/DeepSeek-V3-0324": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 5e-07, @@ -43641,7 +42328,6 @@ "source": "https://nebius.com/prices" }, "nebius/google/gemma-3-27b-it": { - "max_tokens": 110000, "max_input_tokens": 110000, "max_output_tokens": 110000, "input_cost_per_token": 1e-07, @@ -43653,7 +42339,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/google%2Fgemma-3-27b-it" }, "nebius/meta-llama/Llama-3.3-70B-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.3e-07, @@ -43664,7 +42349,6 @@ "source": "https://nebius.com/prices" }, "nebius/meta-llama/Llama-Guard-3-8B": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2e-08, @@ -43674,7 +42358,6 @@ "source": "https://nebius.com/prices" }, "nebius/meta-llama/Meta-Llama-3.1-8B-Instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2e-08, @@ -43685,7 +42368,6 @@ "source": "https://nebius.com/prices" }, "nebius/meta-llama/Meta-Llama-3.1-70B-Instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 1.3e-07, @@ -43696,7 +42378,6 @@ "source": "https://nebius.com/prices" }, "nebius/meta-llama/Meta-Llama-3.1-405B-Instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 1e-06, @@ -43707,7 +42388,6 @@ "source": "https://nebius.com/prices" }, "nebius/mistralai/Mistral-Nemo-Instruct-2407": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 4e-08, @@ -43718,7 +42398,6 @@ "source": "https://nebius.com/prices" }, "nebius/NousResearch/Hermes-3-Llama-3.1-405B": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 1e-06, @@ -43729,7 +42408,6 @@ "source": "https://nebius.com/prices" }, "nebius/nvidia/Llama-3.1-Nemotron-Ultra-253B-v1": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 6e-07, @@ -43740,7 +42418,6 @@ "source": "https://nebius.com/prices" }, "nebius/nvidia/Llama-3.3-Nemotron-Super-49B-v1": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -43751,7 +42428,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen3-235B-A22B": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 2e-07, @@ -43762,7 +42438,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen3-32B": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 1e-07, @@ -43773,7 +42448,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/Qwen%2FQwen3-32B" }, "nebius/Qwen/Qwen3-30B-A3B": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -43784,7 +42458,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen3-14B": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 8e-08, @@ -43795,7 +42468,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen3-4B": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 8e-08, @@ -43806,7 +42478,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/QwQ-32B": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1.5e-07, @@ -43818,7 +42489,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen2.5-72B-Instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 1.3e-07, @@ -43829,7 +42499,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen2.5-32B-Instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 6e-08, @@ -43840,7 +42509,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen2.5-Coder-7B": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-08, @@ -43851,7 +42519,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen2.5-VL-72B-Instruct": { - "max_tokens": 32000, "max_input_tokens": 32000, "max_output_tokens": 32000, "input_cost_per_token": 2.5e-07, @@ -43863,7 +42530,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/image2text/Qwen%2FQwen2.5-VL-72B-Instruct" }, "nebius/Qwen/Qwen2-VL-72B-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.3e-07, @@ -43875,7 +42541,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen2-VL-7B-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-08, @@ -43886,7 +42551,6 @@ "source": "https://nebius.com/prices" }, "nebius/deepseek-ai/DeepSeek-V4-Flash": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 1.4e-07, @@ -43898,7 +42562,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/deepseek-ai%2FDeepSeek-V4-Flash" }, "nebius/deepseek-ai/DeepSeek-V4-Flash-0731": { - "max_tokens": 1024000, "max_input_tokens": 1024000, "max_output_tokens": 1024000, "input_cost_per_token": 1.4e-07, @@ -43910,7 +42573,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/deepseek-ai%2FDeepSeek-V4-Flash-0731" }, "nebius/deepseek-ai/DeepSeek-V4-Pro": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 1.75e-06, @@ -43936,7 +42598,6 @@ "litellm_provider": "nebius", "max_input_tokens": 1048000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://tokenfactory.nebius.com/endpoints?modals=endpoint-details&model-id=deepseek-ai/DeepSeek-V4.1-Flash", @@ -43945,7 +42606,6 @@ "supports_vision": true }, "nebius/MiniMaxAI/MiniMax-M2.5": { - "max_tokens": 196608, "max_input_tokens": 196608, "max_output_tokens": 196608, "input_cost_per_token": 3e-07, @@ -43957,7 +42617,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/MiniMaxAI%2FMiniMax-M2.5" }, "nebius/MiniMaxAI/MiniMax-M3": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 3e-07, @@ -43970,7 +42629,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/MiniMaxAI%2FMiniMax-M3" }, "nebius/moonshotai/Kimi-K2.6": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 9.5e-07, @@ -43983,7 +42641,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/image2text/moonshotai%2FKimi-K2.6" }, "nebius/moonshotai/Kimi-K2.7-Code": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 9.5e-07, @@ -43996,7 +42653,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/moonshotai%2FKimi-K2.7-Code" }, "nebius/moonshotai/Kimi-K3": { - "max_tokens": 1024000, "max_input_tokens": 1024000, "max_output_tokens": 1024000, "input_cost_per_token": 3e-06, @@ -44009,7 +42665,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/image2text/moonshotai%2FKimi-K3" }, "nebius/NousResearch/Hermes-4-405B": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-06, @@ -44021,7 +42676,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/NousResearch%2FHermes-4-405B" }, "nebius/NousResearch/Hermes-4-70B": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.3e-07, @@ -44033,7 +42687,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/NousResearch%2FHermes-4-70B" }, "nebius/nvidia/Cosmos3-Super-Reasoner": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1e-07, @@ -44046,7 +42699,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/image2text/nvidia%2FCosmos3-Super-Reasoner" }, "nebius/nvidia/Llama-3_1-Nemotron-Ultra-253B-v1": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 6e-07, @@ -44057,7 +42709,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/nvidia%2FLlama-3_1-Nemotron-Ultra-253B-v1" }, "nebius/nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 6e-08, @@ -44069,7 +42720,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/nvidia%2FNVIDIA-Nemotron-3-Nano-30B-A3B" }, "nebius/nvidia/Nemotron-3-Nano-Omni": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 6e-08, @@ -44082,7 +42732,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/nvidia%2FNemotron-3-Nano-Omni" }, "nebius/nvidia/nemotron-3-super-120b-a12b": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 3e-07, @@ -44094,7 +42743,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/nvidia%2Fnemotron-3-super-120b-a12b" }, "nebius/nvidia/Nemotron-3-Ultra-550b-a55b": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 1e-06, @@ -44106,7 +42754,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/nvidia%2FNemotron-3-Ultra-550b-a55b" }, "nebius/nvidia/Nemotron-3_5-Lightning": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 6e-08, @@ -44118,7 +42765,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/nvidia%2FNemotron-3_5-Lightning" }, "nebius/openai/gpt-oss-120b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.5e-07, @@ -44130,7 +42776,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/openai%2Fgpt-oss-120b" }, "nebius/openbmb/MiniCPM-V-4_5": { - "max_tokens": 32000, "max_input_tokens": 32000, "max_output_tokens": 32000, "input_cost_per_token": 6.58e-07, @@ -44141,7 +42786,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/image2text/openbmb%2FMiniCPM-V-4_5" }, "nebius/Qwen/Qwen3-235B-A22B-Instruct-2507": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 2e-07, @@ -44152,7 +42796,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/Qwen%2FQwen3-235B-A22B-Instruct-2507" }, "nebius/Qwen/Qwen3-30B-A3B-Instruct-2507": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1e-07, @@ -44163,7 +42806,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/Qwen%2FQwen3-30B-A3B-Instruct-2507" }, "nebius/Qwen/Qwen3-Next-80B-A3B-Thinking": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 1.5e-07, @@ -44175,7 +42817,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/Qwen%2FQwen3-Next-80B-A3B-Thinking" }, "nebius/Qwen/Qwen3.5-397B-A17B": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 6e-07, @@ -44197,7 +42838,6 @@ "supports_reasoning": true }, "nebius/zai-org/GLM-5.1": { - "max_tokens": 202752, "max_input_tokens": 202752, "max_output_tokens": 202752, "input_cost_per_token": 1.4e-06, @@ -44209,7 +42849,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/zai-org%2FGLM-5.1" }, "nebius/zai-org/GLM-5.2": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 1.4e-06, @@ -44224,7 +42863,7 @@ "input_cost_per_token": 1.4e-06, "litellm_provider": "nebius", "max_input_tokens": 1024000, - "max_tokens": 1024000, + "max_output_tokens": 1024000, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://tokenfactory.nebius.com/models/catalog/text2text/zai-org%2FGLM-5.3", @@ -44232,7 +42871,6 @@ "supports_reasoning": true }, "nebius/zai-org/GLM-5.3-Flash": { - "max_tokens": 1024000, "max_input_tokens": 1024000, "max_output_tokens": 1024000, "input_cost_per_token": 1.5e-07, @@ -44245,7 +42883,6 @@ "supports_vision": true }, "nebius/BAAI/bge-en-icl": { - "max_tokens": 32768, "max_input_tokens": 32768, "input_cost_per_token": 1e-08, "output_cost_per_token": 0.0, @@ -44254,7 +42891,6 @@ "source": "https://nebius.com/prices" }, "nebius/BAAI/bge-multilingual-gemma2": { - "max_tokens": 8192, "max_input_tokens": 8192, "input_cost_per_token": 1e-08, "output_cost_per_token": 0.0, @@ -44263,7 +42899,6 @@ "source": "https://nebius.com/prices" }, "nebius/intfloat/e5-mistral-7b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "input_cost_per_token": 1e-08, "output_cost_per_token": 0.0, @@ -44272,7 +42907,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen3-Embedding-8B": { - "max_tokens": 40960, "max_input_tokens": 40960, "input_cost_per_token": 1e-08, "output_cost_per_token": 0.0, @@ -44289,7 +42923,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -44311,7 +42944,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2.3e-07, "output_cost_per_token_batches": 1.2e-07, @@ -44332,7 +42964,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2.4e-07, "output_cost_per_token_batches": 1.2e-07, @@ -44355,7 +42986,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 6.5e-07, "output_cost_per_token_batches": 3.25e-07, @@ -44378,7 +43008,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6e-05, "output_cost_per_token_batches": 3e-05, @@ -44401,7 +43030,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6e-05, "output_cost_per_token_batches": 3e-05, @@ -44423,7 +43051,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 0.0006, "output_cost_per_token_batches": 0.0003, @@ -44457,7 +43084,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 0.0006, "output_cost_per_token_batches": 0.0003, @@ -44495,7 +43121,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8e-06, "output_cost_per_token_batches": 4e-06, @@ -44536,7 +43161,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 4e-05, "source": "https://developers.openai.com/api/docs/models/o3-deep-research", @@ -44569,7 +43193,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 4e-05, "source": "https://developers.openai.com/api/docs/models/o3-deep-research", @@ -44606,7 +43229,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8e-06, "output_cost_per_token_batches": 4e-06, @@ -44649,7 +43271,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_batches": 2.2e-06, @@ -44670,7 +43291,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_batches": 2.2e-06, @@ -44689,7 +43309,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 8e-05, "output_cost_per_token_batches": 4e-05, @@ -44727,7 +43346,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 8e-05, "output_cost_per_token_batches": 4e-05, @@ -44770,7 +43388,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_batches": 2.2e-06, @@ -44798,7 +43415,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 8e-06, "source": "https://developers.openai.com/api/docs/models/o4-mini-deep-research", @@ -44831,7 +43447,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 8e-06, "source": "https://developers.openai.com/api/docs/models/o4-mini-deep-research", @@ -44868,7 +43483,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_batches": 2.2e-06, @@ -44895,7 +43509,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -44908,7 +43521,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -44921,7 +43533,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1.068e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -44934,7 +43545,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -44948,7 +43558,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -44961,7 +43570,6 @@ "litellm_provider": "oci", "max_input_tokens": 1048576, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -44975,7 +43583,6 @@ "litellm_provider": "oci", "max_input_tokens": 10485760, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -44988,7 +43595,6 @@ "litellm_provider": "oci", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45001,7 +43607,6 @@ "litellm_provider": "oci", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.5e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45014,7 +43619,6 @@ "litellm_provider": "oci", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45027,7 +43631,6 @@ "litellm_provider": "oci", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45040,7 +43643,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45053,7 +43655,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://www.oracle.com/artificial-intelligence/enterprise-ai/cost-estimator/", @@ -45066,7 +43667,6 @@ "litellm_provider": "oci", "max_input_tokens": 256000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://www.oracle.com/artificial-intelligence/enterprise-ai/cost-estimator/", @@ -45079,7 +43679,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://www.oracle.com/artificial-intelligence/enterprise-ai/cost-estimator/", @@ -45092,7 +43691,6 @@ "litellm_provider": "oci", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45112,7 +43710,6 @@ "litellm_provider": "oci", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45131,7 +43728,6 @@ "litellm_provider": "oci", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45151,7 +43747,6 @@ "litellm_provider": "oci", "max_input_tokens": 256000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://www.oracle.com/artificial-intelligence/enterprise-ai/cost-estimator/", @@ -45165,7 +43760,6 @@ "litellm_provider": "oci", "max_input_tokens": 256000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://www.oracle.com/artificial-intelligence/enterprise-ai/cost-estimator/", @@ -45187,7 +43781,6 @@ "litellm_provider": "oci", "max_input_tokens": 256000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45199,7 +43792,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45212,7 +43804,6 @@ "litellm_provider": "oci", "max_input_tokens": 256000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 9e-08, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45224,7 +43815,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45236,7 +43826,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45248,7 +43837,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45261,7 +43849,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45273,7 +43860,6 @@ "litellm_provider": "oci", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.5e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45285,7 +43871,6 @@ "litellm_provider": "oci", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.5e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45297,7 +43882,6 @@ "litellm_provider": "oci", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-05, "reasoning_effort_levels": [], @@ -45310,7 +43894,6 @@ "litellm_provider": "oci", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45325,7 +43908,6 @@ "litellm_provider": "oci", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -45341,7 +43923,6 @@ "litellm_provider": "oci", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -45358,7 +43939,6 @@ "litellm_provider": "oci", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -45374,7 +43954,6 @@ "litellm_provider": "oci", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -45388,7 +43967,6 @@ "litellm_provider": "oci", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.5e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45400,7 +43978,6 @@ "litellm_provider": "oci", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45415,7 +43992,6 @@ "litellm_provider": "oci", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45430,7 +44006,6 @@ "litellm_provider": "oci", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45445,7 +44020,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45458,7 +44032,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45470,7 +44043,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "oci", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -45480,7 +44052,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "oci", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 384, @@ -45490,7 +44061,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "oci", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -45500,7 +44070,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "oci", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 384, @@ -45510,7 +44079,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "oci", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -45521,7 +44089,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "oci", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 384, @@ -45532,7 +44099,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "oci", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 384, @@ -45543,7 +44109,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "oci", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536, @@ -45555,7 +44120,6 @@ "litellm_provider": "ollama", "max_input_tokens": 32768, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": false @@ -45565,7 +44129,6 @@ "litellm_provider": "ollama", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "completion", "output_cost_per_token": 0.0 }, @@ -45574,7 +44137,6 @@ "litellm_provider": "ollama", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 0.0 }, @@ -45583,7 +44145,6 @@ "litellm_provider": "ollama", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "completion", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45593,7 +44154,6 @@ "litellm_provider": "ollama", "max_input_tokens": 32768, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45603,7 +44163,6 @@ "litellm_provider": "ollama", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "completion", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45613,7 +44172,6 @@ "litellm_provider": "ollama", "max_input_tokens": 32768, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45623,7 +44181,6 @@ "litellm_provider": "ollama", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45633,7 +44190,6 @@ "litellm_provider": "ollama", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45643,7 +44199,6 @@ "litellm_provider": "ollama", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45653,7 +44208,6 @@ "litellm_provider": "ollama", "max_input_tokens": 32768, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45663,7 +44217,6 @@ "litellm_provider": "ollama", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -45672,7 +44225,6 @@ "litellm_provider": "ollama", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 0.0 }, @@ -45681,7 +44233,6 @@ "litellm_provider": "ollama", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -45690,7 +44241,6 @@ "litellm_provider": "ollama", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -45699,7 +44249,6 @@ "litellm_provider": "ollama", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -45708,7 +44257,6 @@ "litellm_provider": "ollama", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -45717,7 +44265,6 @@ "litellm_provider": "ollama", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45727,7 +44274,6 @@ "litellm_provider": "ollama", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -45736,7 +44282,6 @@ "litellm_provider": "ollama", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -45745,7 +44290,6 @@ "litellm_provider": "ollama", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "completion", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45755,7 +44299,6 @@ "litellm_provider": "ollama", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45765,7 +44308,6 @@ "litellm_provider": "ollama", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45775,7 +44317,6 @@ "litellm_provider": "ollama", "max_input_tokens": 65536, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45785,7 +44326,6 @@ "litellm_provider": "ollama", "max_input_tokens": 65536, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45795,7 +44335,6 @@ "litellm_provider": "ollama", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45805,7 +44344,6 @@ "litellm_provider": "ollama", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 0.0 }, @@ -45814,7 +44352,6 @@ "litellm_provider": "ollama", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45824,7 +44361,6 @@ "litellm_provider": "ollama", "max_input_tokens": 2048, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "completion", "output_cost_per_token": 0.0 }, @@ -45833,7 +44369,6 @@ "litellm_provider": "openai", "max_input_tokens": 32768, "max_output_tokens": 0, - "max_tokens": 0, "mode": "moderation", "output_cost_per_token": 0.0 }, @@ -45842,11 +44377,11 @@ "litellm_provider": "openai", "max_input_tokens": 32768, "max_output_tokens": 0, - "max_tokens": 0, "mode": "moderation", "output_cost_per_token": 0.0 }, "openai.gpt-oss-120b-1:0": { + "supports_vision": false, "supported_endpoints": [ "/v1/chat/completions" ], @@ -45859,7 +44394,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -45872,6 +44406,7 @@ "supports_tool_choice": true }, "openai.gpt-oss-20b-1:0": { + "supports_vision": false, "supported_endpoints": [ "/v1/chat/completions" ], @@ -45884,7 +44419,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 3e-07, "output_cost_per_token_batches": 1.5e-07, @@ -45904,7 +44438,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -45926,7 +44459,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 2e-07, "output_cost_per_token_batches": 1e-07, @@ -45945,7 +44477,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 131000, "max_output_tokens": 131000, - "max_tokens": 131000, "mode": "chat", "output_cost_per_token": 6.7e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -45959,7 +44490,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 131000, "max_output_tokens": 131000, - "max_tokens": 131000, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -45972,7 +44502,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 131000, "max_output_tokens": 131000, - "max_tokens": 131000, "mode": "chat", "output_cost_per_token": 6.7e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -45985,7 +44514,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 131000, "max_output_tokens": 131000, - "max_tokens": 131000, "mode": "chat", "output_cost_per_token": 6.7e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -45998,7 +44526,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 127000, "max_output_tokens": 127000, - "max_tokens": 127000, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46011,7 +44538,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 118000, "max_output_tokens": 118000, - "max_tokens": 118000, "mode": "chat", "output_cost_per_token": 1.3e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46024,7 +44550,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.8e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46038,7 +44563,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 6.3e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46051,7 +44575,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 8.7e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46064,7 +44587,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 9.1e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46078,7 +44600,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 2.3e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46092,7 +44613,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 131000, "max_output_tokens": 131000, - "max_tokens": 131000, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46106,7 +44626,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 131000, "max_output_tokens": 131000, - "max_tokens": 131000, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46120,7 +44639,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 2.9e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46134,7 +44652,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 1.9e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46167,7 +44684,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.4e-06 }, @@ -46176,7 +44692,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 2.8e-06 }, @@ -46185,7 +44700,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.8e-06 }, @@ -46194,7 +44708,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1e-06 }, @@ -46203,7 +44716,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-07 }, @@ -46212,7 +44724,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.8e-07 }, @@ -46221,7 +44732,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.8e-07 }, @@ -46230,7 +44740,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.8e-06 }, @@ -46240,7 +44749,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.8e-06 }, @@ -46249,7 +44757,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.8e-07 }, @@ -46259,7 +44766,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.8e-07 }, @@ -46315,7 +44821,7 @@ "input_cost_per_token": 1e-06, "litellm_provider": "perplexity", "max_input_tokens": 128000, - "max_tokens": 128000, + "max_output_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-06, "search_context_cost_per_query": { @@ -46330,7 +44836,7 @@ "input_cost_per_token": 2e-06, "litellm_provider": "perplexity", "max_input_tokens": 128000, - "max_tokens": 128000, + "max_output_tokens": 128000, "mode": "chat", "output_cost_per_reasoning_token": 3e-06, "output_cost_per_token": 8e-06, @@ -46347,7 +44853,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.8e-06 }, @@ -46357,7 +44862,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 12000, "max_output_tokens": 12000, - "max_tokens": 12000, "mode": "chat", "output_cost_per_token": 1.8e-06 }, @@ -46366,7 +44870,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 200000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -46380,7 +44883,7 @@ "input_cost_per_token": 1e-06, "litellm_provider": "perplexity", "max_input_tokens": 128000, - "max_tokens": 128000, + "max_output_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-06, "search_context_cost_per_query": { @@ -46395,7 +44898,7 @@ "input_cost_per_token": 2e-06, "litellm_provider": "perplexity", "max_input_tokens": 128000, - "max_tokens": 128000, + "max_output_tokens": 128000, "mode": "chat", "output_cost_per_token": 8e-06, "search_context_cost_per_query": { @@ -46411,7 +44914,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 2.8e-07 }, @@ -46421,7 +44923,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 12000, "max_output_tokens": 12000, - "max_tokens": 12000, "mode": "chat", "output_cost_per_token": 2.8e-07 }, @@ -46430,7 +44931,6 @@ "litellm_provider": "publicai", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://platform.publicai.co/docs", @@ -46442,7 +44942,6 @@ "litellm_provider": "publicai", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://platform.publicai.co/docs", @@ -46454,7 +44953,6 @@ "litellm_provider": "publicai", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://platform.publicai.co/docs", @@ -46466,7 +44964,6 @@ "litellm_provider": "publicai", "max_input_tokens": 16384, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://platform.publicai.co/docs", @@ -46478,7 +44975,6 @@ "litellm_provider": "publicai", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://platform.publicai.co/docs", @@ -46490,7 +44986,6 @@ "litellm_provider": "publicai", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://platform.publicai.co/docs", @@ -46730,7 +45225,6 @@ "input_cost_per_token": 4e-09, "litellm_provider": "perplexity", "max_input_tokens": 32768, - "max_tokens": 32768, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -46740,7 +45234,6 @@ "input_cost_per_token": 3e-08, "litellm_provider": "perplexity", "max_input_tokens": 32768, - "max_tokens": 32768, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 2560, @@ -46751,7 +45244,6 @@ "litellm_provider": "publicai", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://platform.publicai.co/docs", @@ -46763,7 +45255,6 @@ "litellm_provider": "publicai", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://platform.publicai.co/docs", @@ -46776,7 +45267,6 @@ "litellm_provider": "publicai", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://platform.publicai.co/docs", @@ -46790,7 +45280,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.8e-06, "supports_function_calling": true, @@ -46805,7 +45294,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 8.8e-07, "output_cost_per_token_flex": 4.4e-07, @@ -46825,7 +45313,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -46844,7 +45331,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 32768, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -46861,7 +45347,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -46877,7 +45362,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.45e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-qwen-qwen3-next-80b-a3b.html", @@ -46893,7 +45377,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.41e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-qwen-qwen3-next-80b-a3b.html", @@ -46909,7 +45392,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.236e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-qwen-qwen3-next-80b-a3b.html", @@ -46925,7 +45407,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.41e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-qwen-qwen3-next-80b-a3b.html", @@ -46941,7 +45422,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.86e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-qwen-qwen3-next-80b-a3b.html", @@ -46957,7 +45437,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.45e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-qwen-qwen3-next-80b-a3b.html", @@ -46975,7 +45454,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2.66e-06, "output_cost_per_token_batches": 1.33e-06, @@ -46996,7 +45474,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_batches": 6e-07, @@ -47051,7 +45528,6 @@ "litellm_provider": "replicate", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 5e-07, "supports_tool_choice": true @@ -47061,7 +45537,6 @@ "litellm_provider": "replicate", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 5e-07, "supports_tool_choice": true @@ -47071,7 +45546,6 @@ "litellm_provider": "replicate", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.75e-06, "supports_tool_choice": true @@ -47081,7 +45555,6 @@ "litellm_provider": "replicate", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.75e-06, "supports_tool_choice": true @@ -47091,7 +45564,6 @@ "litellm_provider": "replicate", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.5e-07, "supports_tool_choice": true @@ -47101,7 +45573,6 @@ "litellm_provider": "replicate", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.5e-07, "supports_tool_choice": true @@ -47111,7 +45582,6 @@ "litellm_provider": "replicate", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.75e-06, "supports_tool_choice": true @@ -47121,7 +45591,6 @@ "litellm_provider": "replicate", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.75e-06, "supports_tool_choice": true @@ -47131,7 +45600,6 @@ "litellm_provider": "replicate", "max_input_tokens": 8086, "max_output_tokens": 8086, - "max_tokens": 8086, "mode": "chat", "output_cost_per_token": 2.5e-07, "supports_tool_choice": true @@ -47141,7 +45609,6 @@ "litellm_provider": "replicate", "max_input_tokens": 8086, "max_output_tokens": 8086, - "max_tokens": 8086, "mode": "chat", "output_cost_per_token": 2.5e-07, "supports_tool_choice": true @@ -47151,7 +45618,6 @@ "litellm_provider": "replicate", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.5e-07, "supports_tool_choice": true @@ -47161,7 +45627,6 @@ "litellm_provider": "replicate", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.5e-07, "supports_tool_choice": true @@ -47171,7 +45636,6 @@ "litellm_provider": "replicate", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1e-06, "supports_tool_choice": true @@ -47300,7 +45764,6 @@ "mode": "chat", "max_input_tokens": 65536, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_function_calling": true, "supports_system_messages": true }, @@ -47455,7 +45918,6 @@ "mode": "chat", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "supports_function_calling": true, "supports_reasoning": true, "supports_system_messages": true @@ -47476,7 +45938,6 @@ "mode": "chat", "max_input_tokens": 65536, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_reasoning": true, "supports_system_messages": true }, @@ -47486,7 +45947,6 @@ "litellm_provider": "cohere", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "rerank", "output_cost_per_token": 0.0 }, @@ -47496,7 +45956,6 @@ "litellm_provider": "cohere", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "rerank", "output_cost_per_token": 0.0 }, @@ -47506,7 +45965,6 @@ "litellm_provider": "cohere", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "rerank", "output_cost_per_token": 0.0 }, @@ -47516,7 +45974,6 @@ "litellm_provider": "cohere", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://cohere.com/pricing" @@ -47527,7 +45984,6 @@ "litellm_provider": "cohere", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://cohere.com/pricing" @@ -47558,7 +46014,6 @@ "litellm_provider": "sagemaker", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 0.0 }, @@ -47567,7 +46022,6 @@ "litellm_provider": "sagemaker", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -47576,7 +46030,6 @@ "litellm_provider": "sagemaker", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 0.0 }, @@ -47585,7 +46038,6 @@ "litellm_provider": "sagemaker", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -47594,7 +46046,6 @@ "litellm_provider": "sagemaker", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 0.0 }, @@ -47603,7 +46054,6 @@ "litellm_provider": "sagemaker", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -47612,7 +46062,6 @@ "litellm_provider": "sambanova", "max_input_tokens": 196608, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://cloud.sambanova.ai/plans/pricing", @@ -47625,7 +46074,6 @@ "litellm_provider": "sambanova", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 7e-06, "source": "https://cloud.sambanova.ai/plans/pricing" @@ -47635,7 +46083,6 @@ "litellm_provider": "sambanova", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "metadata": { "notes": "For vision models, images are converted to 6432 input tokens and are billed at that amount" }, @@ -47652,7 +46099,6 @@ "litellm_provider": "sambanova", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://cloud.sambanova.ai/plans/pricing", @@ -47661,7 +46107,6 @@ "supports_tool_choice": true }, "sambanova/DeepSeek-V3.1": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 3e-06, @@ -47674,7 +46119,6 @@ "source": "https://cloud.sambanova.ai/plans/pricing" }, "sambanova/gpt-oss-120b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2.2e-07, @@ -47687,7 +46131,6 @@ "source": "https://cloud.sambanova.ai/plans/pricing" }, "sambanova/DeepSeek-V3.2": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 3e-06, @@ -47699,7 +46142,6 @@ "source": "https://cloud.sambanova.ai/plans/pricing" }, "sambanova/gemma-4-31B-it": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 3.8e-07, @@ -47715,7 +46157,6 @@ "litellm_provider": "scx-ai", "max_input_tokens": 1000000, "max_output_tokens": 375000, - "max_tokens": 375000, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://scx.ai/models/deepseek-v4-1-flash", @@ -47730,7 +46171,6 @@ "litellm_provider": "scx-ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3.08e-06, "source": "https://scx.ai/models/glm-5-3", @@ -47746,7 +46186,6 @@ "litellm_provider": "scx-ai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 1.413e-05, "source": "https://scx.ai/models/kimi-k3", @@ -47762,7 +46201,6 @@ "litellm_provider": "scx-ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.98e-06, "source": "https://scx.ai/pricing", @@ -47779,7 +46217,6 @@ "litellm_provider": "scx-ai", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.99e-06, "source": "https://scx.ai/pricing", @@ -47794,7 +46231,6 @@ "litellm_provider": "snowflake", "max_input_tokens": 200000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "input_cost_per_token": 3e-06, "output_cost_per_token": 1.5e-05, @@ -47810,7 +46246,6 @@ "litellm_provider": "snowflake", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "input_cost_per_token": 1.35e-06, "output_cost_per_token": 5.4e-06, @@ -47821,56 +46256,48 @@ "litellm_provider": "snowflake", "max_input_tokens": 8000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/jamba-1.5-large": { "litellm_provider": "snowflake", "max_input_tokens": 256000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/jamba-1.5-mini": { "litellm_provider": "snowflake", "max_input_tokens": 256000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/jamba-instruct": { "litellm_provider": "snowflake", "max_input_tokens": 256000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/llama2-70b-chat": { "litellm_provider": "snowflake", "max_input_tokens": 4096, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/llama3-70b": { "litellm_provider": "snowflake", "max_input_tokens": 8000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/llama3-8b": { "litellm_provider": "snowflake", "max_input_tokens": 8000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/llama3.1-405b": { "litellm_provider": "snowflake", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "input_cost_per_token": 1.2e-06, "output_cost_per_token": 1.2e-06, @@ -47881,7 +46308,6 @@ "litellm_provider": "snowflake", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "input_cost_per_token": 7.2e-07, "output_cost_per_token": 7.2e-07, @@ -47892,7 +46318,6 @@ "litellm_provider": "snowflake", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "input_cost_per_token": 2.4e-07, "output_cost_per_token": 2.4e-07, @@ -47902,18 +46327,15 @@ "litellm_provider": "snowflake", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/llama3.2-3b": { "litellm_provider": "snowflake", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/llama3.3-70b": { - "max_tokens": 16384, "max_input_tokens": 128000, "max_output_tokens": 16384, "input_cost_per_token": 7.2e-07, @@ -47927,21 +46349,18 @@ "litellm_provider": "snowflake", "max_input_tokens": 32000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/mistral-large": { "litellm_provider": "snowflake", "max_input_tokens": 32000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/mistral-large2": { "litellm_provider": "snowflake", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "input_cost_per_token": 2e-06, "output_cost_per_token": 6e-06, @@ -47953,39 +46372,33 @@ "litellm_provider": "snowflake", "max_input_tokens": 32000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/reka-core": { "litellm_provider": "snowflake", "max_input_tokens": 32000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/reka-flash": { "litellm_provider": "snowflake", "max_input_tokens": 100000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/snowflake-arctic": { "litellm_provider": "snowflake", "max_input_tokens": 4096, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/snowflake-llama-3.1-405b": { "litellm_provider": "snowflake", "max_input_tokens": 8000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/snowflake-llama-3.3-70b": { - "max_tokens": 16384, "max_input_tokens": 128000, "max_output_tokens": 16384, "input_cost_per_token": 7.2e-07, @@ -48182,21 +46595,18 @@ "stability.sd3-5-large-v1:0": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.08 }, "stability.sd3-large-v1:0": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.08 }, "stability.stable-image-core-v1:0": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.04 }, @@ -48372,21 +46782,18 @@ "stability.stable-image-core-v1:1": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.04 }, "stability.stable-image-ultra-v1:0": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.14 }, "stability.stable-image-ultra-v1:1": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.14 }, @@ -48420,7 +46827,6 @@ "litellm_provider": "text-completion-codestral", "max_input_tokens": 32000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "completion", "output_cost_per_token": 0.0, "source": "https://docs.mistral.ai/capabilities/code_generation/" @@ -48430,7 +46836,6 @@ "litellm_provider": "text-completion-codestral", "max_input_tokens": 32000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "completion", "output_cost_per_token": 0.0, "source": "https://docs.mistral.ai/capabilities/code_generation/" @@ -48441,7 +46846,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 2048, - "max_tokens": 2048, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 768, @@ -48453,7 +46857,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 2048, - "max_tokens": 2048, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 768, @@ -48464,7 +46867,6 @@ "input_cost_per_token_batches": 6.5e-08, "litellm_provider": "openai", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding", "output_cost_per_token": 0.0, "output_cost_per_token_batches": 0.0, @@ -48476,7 +46878,6 @@ "input_cost_per_token_batches": 1e-08, "litellm_provider": "openai", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding", "output_cost_per_token": 0.0, "output_cost_per_token_batches": 0.0, @@ -48487,7 +46888,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "openai", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536, @@ -48498,7 +46898,6 @@ "input_cost_per_token_batches": 5e-08, "litellm_provider": "openai", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding", "output_cost_per_token": 0.0, "output_cost_per_token_batches": 0.0 @@ -48508,7 +46907,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -48518,7 +46916,6 @@ "input_cost_per_token": 6.25e-09, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 3072, - "max_tokens": 3072, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 768, @@ -48530,7 +46927,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 2048, - "max_tokens": 2048, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 768, @@ -48541,7 +46937,6 @@ "litellm_provider": "vertex_ai-text-models", "max_input_tokens": 8192, "max_output_tokens": 1024, - "max_tokens": 1024, "mode": "completion", "output_cost_per_token": 2.8e-05, "source": "https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models#foundation_models" @@ -48551,7 +46946,6 @@ "litellm_provider": "vertex_ai-text-models", "max_input_tokens": 8192, "max_output_tokens": 1024, - "max_tokens": 1024, "mode": "completion", "output_cost_per_token": 2.8e-05, "source": "https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models#foundation_models" @@ -48577,7 +46971,8 @@ "together-ai-8.1b-21b": { "input_cost_per_token": 3e-07, "litellm_provider": "together_ai", - "max_tokens": 1000, + "max_output_tokens": 1000, + "max_input_tokens": 1000, "mode": "chat", "output_cost_per_token": 3e-07 }, @@ -48630,7 +47025,6 @@ "litellm_provider": "together_ai", "max_input_tokens": 65536, "max_output_tokens": 8192, - "max_tokens": 8192, "metadata": { "successor": "together_ai/deepseek-ai/DeepSeek-V4-Pro-0813" }, @@ -48646,7 +47040,7 @@ "input_cost_per_token": 1.04e-06, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.04e-06, "source": "https://api.together.ai/v1/models", @@ -48673,7 +47067,7 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://api.together.ai/v1/models", @@ -48694,7 +47088,7 @@ "input_cost_per_token": 6e-07, "litellm_provider": "together_ai", "max_input_tokens": 202752, - "max_tokens": 202752, + "max_output_tokens": 202752, "metadata": { "successor": "together_ai/zai-org/GLM-5.2" }, @@ -48708,10 +47102,11 @@ }, "together_ai/MiniMaxAI/MiniMax-M3": { "cache_read_input_token_cost": 6e-08, + "deprecation_date": "2026-11-06", "input_cost_per_token": 3e-07, "litellm_provider": "together_ai", "max_input_tokens": 524288, - "max_tokens": 524288, + "max_output_tokens": 524288, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://api.together.ai/v1/models", @@ -48728,7 +47123,7 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "together_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://www.together.ai/pricing", @@ -48738,7 +47133,7 @@ "input_cost_per_token": 0.0, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://docs.together.ai/docs/serverless-models" @@ -48747,7 +47142,7 @@ "input_cost_per_token": 1.7e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 2.5e-07, "source": "https://api.together.ai/v1/models", @@ -48762,7 +47157,7 @@ "input_cost_per_token": 5e-07, "litellm_provider": "together_ai", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://api.together.ai/v1/models", @@ -48773,7 +47168,7 @@ "input_cost_per_token": 1.5e-06, "litellm_provider": "together_ai", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 4.5e-06, "source": "https://www.together.ai/pricing", @@ -48783,7 +47178,7 @@ "input_cost_per_token": 3.2e-07, "litellm_provider": "together_ai", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 1.28e-06, "source": "https://api.together.ai/v1/models" @@ -48793,7 +47188,7 @@ "input_cost_per_token": 2e-06, "litellm_provider": "together_ai", "max_input_tokens": 1010000, - "max_tokens": 1010000, + "max_output_tokens": 1010000, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://api.together.ai/v1/models", @@ -48803,7 +47198,7 @@ "input_cost_per_token": 1e-07, "litellm_provider": "together_ai", "max_input_tokens": 32768, - "max_tokens": 32768, + "max_output_tokens": 32768, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://api.together.ai/v1/models" @@ -48814,7 +47209,7 @@ "input_cost_per_token": 1.4e-07, "litellm_provider": "together_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 2.8e-07, "source": "https://api.together.ai/v1/models", @@ -48829,7 +47224,7 @@ "input_cost_per_token": 3e-07, "litellm_provider": "together_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://api.together.ai/v1/models", @@ -48843,7 +47238,7 @@ "input_cost_per_token": 1.32e-06, "litellm_provider": "together_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 3.96e-06, "source": "https://api.together.ai/v1/models", @@ -48858,7 +47253,7 @@ "input_cost_per_token": 3.5e-07, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://api.together.ai/v1/models", @@ -48869,7 +47264,7 @@ "input_cost_per_token": 1.25e-06, "litellm_provider": "together_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 4.25e-06, "source": "https://docs.together.ai/docs/serverless-models", @@ -48882,7 +47277,7 @@ "input_cost_per_token": 3e-06, "litellm_provider": "together_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.5e-05, "reasoning_effort_levels": [ @@ -48901,10 +47296,11 @@ }, "together_ai/thinkingmachines/Inkling": { "cache_read_input_token_cost": 1.7e-07, + "deprecation_date": "2026-11-06", "input_cost_per_token": 1e-06, "litellm_provider": "together_ai", "max_input_tokens": 524288, - "max_tokens": 524288, + "max_output_tokens": 524288, "mode": "chat", "output_cost_per_token": 4.05e-06, "source": "https://api.together.ai/v1/models", @@ -48920,7 +47316,6 @@ "litellm_provider": "together_ai", "max_input_tokens": 1048575, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://api.together.ai/v1/models", @@ -48937,7 +47332,6 @@ "litellm_provider": "together_ai", "max_input_tokens": 1048575, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://api.together.ai/v1/models", @@ -48954,7 +47348,6 @@ "litellm_provider": "together_ai", "max_input_tokens": 1048575, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://api.together.ai/v1/models", @@ -49039,7 +47432,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 2.4e-07, "output_cost_per_token_batches": 1.2e-07, @@ -49058,7 +47450,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 1.4e-07, "output_cost_per_token_batches": 7e-08, @@ -49079,7 +47470,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 3.2e-06, "output_cost_per_token_batches": 1.6e-06, @@ -49100,7 +47490,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4e-06, "supports_assistant_prefill": true, @@ -49120,7 +47509,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5.5e-06, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -49148,7 +47536,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -49166,7 +47553,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -49185,7 +47571,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -49203,7 +47588,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_function_calling": true, @@ -49221,7 +47605,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "search_context_cost_per_query": { @@ -49260,7 +47643,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.65e-05, "search_context_cost_per_query": { @@ -49302,7 +47684,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.8e-05, "supports_assistant_prefill": true, @@ -49334,7 +47715,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "prompt_cache_min_tokens": 1024, @@ -49374,7 +47754,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "prompt_cache_min_tokens": 1024, @@ -49413,7 +47792,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "prompt_cache_min_tokens": 512, @@ -49451,7 +47829,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.4e-05, "prompt_cache_min_tokens": 512, @@ -49489,7 +47866,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-05, "supports_adaptive_thinking": true, @@ -49525,7 +47901,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.88e-07, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -49543,7 +47918,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-nvidia-nvidia-nemotron-nano-12b-v2-vl-bf16.html", @@ -49559,7 +47933,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.76e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-nvidia-nvidia-nemotron-nano-9b-v2.html", @@ -49574,7 +47947,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 7.8e-07, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -49587,11 +47959,11 @@ "supports_vision": false }, "us-gov.openai.gpt-oss-20b-1:0": { + "supports_vision": false, "input_cost_per_token": 8.4e-08, "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 3.6e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-20b.html", @@ -49606,11 +47978,11 @@ "supports_tool_choice": true }, "us-gov.openai.gpt-oss-120b-1:0": { + "supports_vision": false, "input_cost_per_token": 1.8e-07, "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-120b.html", @@ -49637,7 +48009,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "supports_function_calling": true, "supports_prompt_caching": false, @@ -49654,7 +48025,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5.5e-06, "supports_assistant_prefill": true, @@ -49684,7 +48054,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "search_context_cost_per_query": { @@ -49712,7 +48081,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -49749,7 +48117,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -49786,7 +48153,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -49826,7 +48192,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -49857,7 +48222,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 5.4e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-deepseek-deepseek-r1.html", @@ -49873,7 +48237,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "mode": "chat", "output_cost_per_token": 1.85e-06, "output_cost_per_token_batches": 9.25e-07, @@ -49894,7 +48257,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "mode": "chat", "output_cost_per_token": 2.22e-06, "output_cost_per_token_flex": 1.11e-06, @@ -49912,7 +48274,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/bedrock/USD/current/bedrock.json", @@ -49926,7 +48287,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.2e-07, "output_cost_per_token_batches": 3.6e-07, @@ -49941,7 +48301,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.2e-07, "output_cost_per_token_batches": 1.1e-07, @@ -49955,7 +48314,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.6e-07, "source": "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/bedrock/USD/current/bedrock.json", @@ -49969,7 +48327,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-2-1b-instruct.md", @@ -49982,7 +48339,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-2-3b-instruct.md", @@ -49995,7 +48351,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/bedrock/USD/current/bedrock.json", @@ -50010,7 +48365,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.2e-07, "output_cost_per_token_batches": 3.6e-07, @@ -50025,7 +48379,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 9.7e-07, "output_cost_per_token_batches": 4.85e-07, @@ -50048,7 +48401,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 10000000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6.6e-07, "output_cost_per_token_batches": 3.3e-07, @@ -50069,7 +48421,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-pixtral-large.md", @@ -50081,7 +48432,6 @@ "litellm_provider": "v0", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -50095,7 +48445,6 @@ "litellm_provider": "v0", "max_input_tokens": 512000, "max_output_tokens": 512000, - "max_tokens": 512000, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_function_calling": true, @@ -50109,7 +48458,6 @@ "litellm_provider": "v0", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -50123,7 +48471,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 40960, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 2.4e-07 }, @@ -50132,7 +48479,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 40960, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07 }, @@ -50141,7 +48487,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 40960, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 3e-07 }, @@ -50150,7 +48495,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 40960, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -50161,7 +48505,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 262144, "max_output_tokens": 66536, - "max_tokens": 66536, "mode": "chat", "output_cost_per_token": 1.6e-06, "supports_function_calling": true, @@ -50172,7 +48515,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 300000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.4e-07, "supports_vision": true, @@ -50184,7 +48526,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.4e-07, "supports_function_calling": true, @@ -50195,7 +48536,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 300000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 3.2e-06, "supports_vision": true, @@ -50207,7 +48547,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -50218,7 +48557,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.25e-06, "supports_vision": true, @@ -50233,7 +48571,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_vision": true, @@ -50248,7 +48585,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4e-06, "supports_vision": true, @@ -50263,7 +48599,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_vision": true, @@ -50278,7 +48613,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_vision": true, @@ -50293,7 +48627,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_vision": true, @@ -50308,7 +48641,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -50321,7 +48653,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -50339,7 +48670,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -50357,7 +48687,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -50376,7 +48705,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "supports_assistant_prefill": true, @@ -50396,7 +48724,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_assistant_prefill": true, @@ -50416,7 +48743,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_assistant_prefill": true, @@ -50436,7 +48762,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "supports_assistant_prefill": true, @@ -50459,7 +48784,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "supports_assistant_prefill": false, @@ -50480,7 +48804,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -50500,7 +48823,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -50517,7 +48839,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 256000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1e-05, "supports_function_calling": true, @@ -50529,7 +48850,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -50540,7 +48860,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1e-05, "supports_function_calling": true, @@ -50551,7 +48870,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -50560,7 +48878,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.19e-06, "supports_tool_choice": true @@ -50570,7 +48887,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 9.9e-07, "supports_function_calling": true, @@ -50582,7 +48898,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 9e-07, "supports_tool_choice": true @@ -50592,7 +48907,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 1000000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 2.5e-06, "supports_vision": true, @@ -50611,7 +48925,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1e-05, "supports_vision": true, @@ -50632,7 +48945,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -50641,7 +48953,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2e-07, "supports_vision": true, @@ -50653,7 +48964,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -50662,7 +48972,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -50671,7 +48980,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 32000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-06 }, @@ -50680,7 +48988,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.9e-07, "supports_tool_choice": true @@ -50690,7 +48997,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 8e-08, "supports_tool_choice": true @@ -50700,7 +49006,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "supports_tool_choice": true @@ -50710,7 +49015,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 8e-08, "supports_function_calling": true, @@ -50721,7 +49025,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.6e-07, "supports_vision": true, @@ -50733,7 +49036,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1e-07 }, @@ -50742,7 +49044,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-07, "supports_function_calling": true, @@ -50753,7 +49054,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "supports_vision": true, @@ -50765,7 +49065,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "supports_function_calling": true, @@ -50776,7 +49075,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6e-07, "supports_tool_choice": true @@ -50786,7 +49084,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 3e-07, "supports_vision": true, @@ -50798,7 +49095,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 256000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 9e-07, "supports_function_calling": true, @@ -50809,7 +49105,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -50818,7 +49113,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.8e-07, "supports_function_calling": true, @@ -50830,7 +49124,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "supports_function_calling": true, @@ -50842,7 +49135,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-06, "supports_function_calling": true @@ -50852,7 +49144,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 4e-08, "supports_function_calling": true, @@ -50863,7 +49154,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1e-07, "supports_vision": true, @@ -50875,7 +49165,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -50884,7 +49173,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 32000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 6e-06, "supports_function_calling": true, @@ -50895,7 +49183,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 7.9e-07 }, @@ -50904,7 +49191,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 32000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -50916,7 +49202,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 65536, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 1.2e-06, "supports_function_calling": true @@ -50926,7 +49211,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1.5e-07, "supports_vision": true, @@ -50939,7 +49223,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 6e-06, "supports_vision": true, @@ -50952,7 +49235,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 2.2e-06, "supports_function_calling": true, @@ -50963,7 +49245,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 32768, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06 }, @@ -50972,7 +49253,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 32768, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.9e-06 }, @@ -50981,7 +49261,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-06, "supports_function_calling": true, @@ -50992,7 +49271,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2e-06 }, @@ -51001,7 +49279,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3e-05, "supports_vision": true, @@ -51015,7 +49292,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "supports_vision": true, @@ -51030,7 +49306,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.6e-06, "supports_vision": true, @@ -51045,7 +49320,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-07, "supports_vision": true, @@ -51060,7 +49334,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "supports_vision": true, @@ -51075,7 +49348,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "supports_vision": true, @@ -51090,7 +49362,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6e-05, "supports_vision": true, @@ -51105,7 +49376,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8e-06, "supports_vision": true, @@ -51120,7 +49390,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "supports_function_calling": true, @@ -51134,7 +49403,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "supports_vision": true, @@ -51147,7 +49415,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -51156,7 +49423,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -51165,7 +49431,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -51174,7 +49439,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 127000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1e-06 }, @@ -51183,7 +49447,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.5e-05 }, @@ -51192,7 +49455,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 127000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 5e-06 }, @@ -51201,7 +49463,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 127000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 8e-06 }, @@ -51210,7 +49471,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_vision": true, @@ -51222,7 +49482,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_vision": true, @@ -51234,7 +49493,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1e-05, "supports_function_calling": true, @@ -51245,7 +49503,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1e-05, "supports_vision": true, @@ -51257,7 +49514,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -51268,7 +49524,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.5e-05, "supports_function_calling": true @@ -51278,7 +49533,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-07, "supports_function_calling": true, @@ -51289,7 +49543,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4e-06, "supports_function_calling": true, @@ -51300,7 +49553,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -51311,7 +49563,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.2e-06, "supports_function_calling": true, @@ -51322,7 +49573,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 96000, - "max_tokens": 96000, "mode": "chat", "output_cost_per_token": 1.1e-06, "supports_function_calling": true, @@ -51334,7 +49584,6 @@ "input_cost_per_token": 4.5e-07, "max_input_tokens": 200000, "max_output_tokens": 200000, - "max_tokens": 200000, "mode": "chat", "output_cost_per_token": 1.8e-06, "source": "https://vercel.com/ai-gateway/models/glm-4.6", @@ -51385,7 +49634,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 5e-06, "supports_assistant_prefill": true, @@ -51399,7 +49647,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 5e-06, "supports_assistant_prefill": true, @@ -51419,7 +49666,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "output_cost_per_token_batches": 2.5e-06, @@ -51448,7 +49694,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "output_cost_per_token_batches": 2.5e-06, @@ -51471,7 +49716,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -51487,7 +49731,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -51502,7 +49745,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.25e-06, "supports_assistant_prefill": true, @@ -51516,7 +49758,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.25e-06, "supports_assistant_prefill": true, @@ -51530,7 +49771,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_assistant_prefill": true, @@ -51544,7 +49784,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_assistant_prefill": true, @@ -51557,7 +49796,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -51570,7 +49808,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -51590,7 +49827,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -51625,7 +49861,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -51664,7 +49899,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -51702,7 +49936,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -51739,7 +49972,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -51777,7 +50009,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -51815,7 +50046,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_batches": 2.5e-05, @@ -51853,7 +50083,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "search_context_cost_per_query": { @@ -51897,7 +50126,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_batches": 2.5e-05, @@ -51935,7 +50163,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "search_context_cost_per_query": { @@ -51980,7 +50207,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -52019,7 +50245,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -52056,7 +50281,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "output_cost_per_token_batches": 1.25e-05, @@ -52097,7 +50321,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "output_cost_per_token_batches": 1.25e-05, @@ -52140,7 +50363,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -52179,7 +50401,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -52219,7 +50440,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 7.5e-06, @@ -52249,7 +50469,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -52288,7 +50507,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 7.5e-06, @@ -52327,7 +50545,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 7.5e-06, @@ -52351,7 +50568,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -52363,7 +50579,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -52375,7 +50590,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -52387,7 +50601,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -52399,7 +50612,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -52410,7 +50622,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -52421,7 +50632,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -52435,7 +50645,6 @@ "litellm_provider": "vertex_ai-deepseek_models", "max_input_tokens": 163840, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.7e-06, "output_cost_per_token_batches": 8.5e-07, @@ -52457,7 +50666,6 @@ "litellm_provider": "vertex_ai-deepseek_models", "max_input_tokens": 163840, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.68e-06, "output_cost_per_token_batches": 8.4e-07, @@ -52478,7 +50686,6 @@ "litellm_provider": "vertex_ai-deepseek_models", "max_input_tokens": 65336, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 5.4e-06, "output_cost_per_token_batches": 2.7e-06, @@ -52501,7 +50708,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.039, "output_cost_per_image_token": 3e-05, @@ -52560,7 +50766,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.134, "output_cost_per_image_token": 0.00012, @@ -52595,7 +50800,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.134, "output_cost_per_image_token": 0.00012, @@ -52628,7 +50832,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.0672, "output_cost_per_image_token": 6e-05, @@ -52656,7 +50859,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.0672, "output_cost_per_image_token": 6e-05, @@ -52677,7 +50879,6 @@ "cache_read_input_token_cost_batches": 1.25e-08, "cache_read_input_token_cost_flex": 1.25e-08, "cache_read_input_token_cost_priority": 4.5e-08, - "deprecation_date": "2027-06-28", "input_cost_per_image": 0.00028, "input_cost_per_token": 2.5e-07, "input_cost_per_token_batches": 1.25e-07, @@ -52686,7 +50887,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "image_generation", "output_cost_per_image": 0.0336, "output_cost_per_image_token": 3e-05, @@ -52726,7 +50926,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 1.5e-06, "output_cost_per_token": 1.5e-06, @@ -52785,7 +50984,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 1.5e-06, "output_cost_per_token": 1.5e-06, @@ -52846,7 +51044,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 2.5e-06, "output_cost_per_token": 2.5e-06, @@ -52903,7 +51100,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_image": 0.134, "output_cost_per_image_token": 0.00012, @@ -52917,7 +51113,6 @@ "litellm_provider": "vertex_ai-ai21_models", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4e-07, "supports_tool_choice": true @@ -52928,7 +51123,6 @@ "litellm_provider": "vertex_ai-ai21_models", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 8e-06, "supports_tool_choice": true @@ -52939,7 +51133,6 @@ "litellm_provider": "vertex_ai-ai21_models", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 8e-06, "supports_tool_choice": true @@ -52950,7 +51143,6 @@ "litellm_provider": "vertex_ai-ai21_models", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4e-07, "supports_tool_choice": true @@ -52961,7 +51153,6 @@ "litellm_provider": "vertex_ai-ai21_models", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4e-07, "supports_tool_choice": true @@ -52991,7 +51182,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "audio_speech", "output_cost_per_image": 0.04, "output_cost_per_token": 0, @@ -53027,7 +51217,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "audio_speech", "output_cost_per_image": 0.08, "output_cost_per_token": 0, @@ -53064,7 +51253,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 128000, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 1.6e-05, "source": "https://console.cloud.google.com/vertex-ai/publishers/meta/model-garden/llama-3.2-90b-vision-instruct-maas", @@ -53077,7 +51265,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 128000, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://console.cloud.google.com/vertex-ai/publishers/meta/model-garden/llama-3.2-90b-vision-instruct-maas", @@ -53090,7 +51277,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 128000, "max_output_tokens": 2048, - "max_tokens": 2048, "metadata": { "notes": "VertexAI states that The Llama 3.1 API service for llama-3.1-70b-instruct-maas and llama-3.1-8b-instruct-maas are in public preview and at no cost." }, @@ -53106,7 +51292,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 128000, "max_output_tokens": 2048, - "max_tokens": 2048, "metadata": { "notes": "VertexAI states that The Llama 3.2 API service is at no cost during public preview, and will be priced as per dollar-per-1M-tokens at GA." }, @@ -53123,7 +51308,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 1.15e-06, "output_cost_per_token_batches": 5.75e-07, @@ -53145,7 +51329,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 1.15e-06, "output_cost_per_token_batches": 5.75e-07, @@ -53167,7 +51350,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 10000000, "max_output_tokens": 10000000, - "max_tokens": 10000000, "mode": "chat", "output_cost_per_token": 7e-07, "output_cost_per_token_batches": 3.5e-07, @@ -53189,7 +51371,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 10000000, "max_output_tokens": 10000000, - "max_tokens": 10000000, "mode": "chat", "output_cost_per_token": 7e-07, "output_cost_per_token_batches": 3.5e-07, @@ -53210,7 +51391,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://cloud.google.com/vertex-ai/generative-ai/pricing#partner-models", @@ -53221,7 +51401,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://cloud.google.com/vertex-ai/generative-ai/pricing#partner-models", @@ -53232,7 +51411,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://cloud.google.com/vertex-ai/generative-ai/pricing#partner-models", @@ -53245,7 +51423,6 @@ "litellm_provider": "vertex_ai-minimax_models", "max_input_tokens": 196608, "max_output_tokens": 196608, - "max_tokens": 196608, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53259,7 +51436,6 @@ "litellm_provider": "vertex_ai-moonshot_models", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53274,7 +51450,6 @@ "litellm_provider": "vertex_ai-zai_models", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53292,7 +51467,6 @@ "litellm_provider": "vertex_ai-zai_models", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3.2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53309,7 +51483,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53321,7 +51494,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53333,7 +51505,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53345,7 +51516,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53357,7 +51527,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 6e-06, "supports_function_calling": true, @@ -53368,7 +51537,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 6e-06, "supports_function_calling": true, @@ -53379,7 +51547,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 6e-06, "supports_function_calling": true, @@ -53390,7 +51557,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 6e-06, "supports_function_calling": true, @@ -53401,7 +51567,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-06, "supports_function_calling": true, @@ -53412,7 +51577,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-07, "supports_function_calling": true, @@ -53423,7 +51587,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -53436,7 +51599,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 32000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -53470,7 +51632,6 @@ "litellm_provider": "vertex_ai-openai_models", "max_input_tokens": 262144, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://cloud.google.com/vertex-ai/generative-ai/docs/maas/google/gemma-4-26b-a4b-it", @@ -53487,7 +51648,6 @@ "litellm_provider": "vertex_ai-openai_models", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3.6e-07, "output_cost_per_token_batches": 1.8e-07, @@ -53500,7 +51660,6 @@ "litellm_provider": "vertex_ai-openai_models", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2.5e-07, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53515,7 +51674,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53532,7 +51690,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53552,7 +51709,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 2000000, "max_output_tokens": 2000000, - "max_tokens": 2000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -53572,7 +51728,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 2000000, "max_output_tokens": 2000000, - "max_tokens": 2000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -53593,7 +51748,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 200000, "max_output_tokens": 200000, - "max_tokens": 200000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -53613,7 +51767,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 524288, "max_output_tokens": 524288, - "max_tokens": 524288, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -53632,7 +51785,6 @@ "litellm_provider": "vertex_ai-qwen_models", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 8.8e-07, "output_cost_per_token_batches": 4.4e-07, @@ -53652,7 +51804,6 @@ "litellm_provider": "vertex_ai-qwen_models", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.8e-06, "output_cost_per_token_batches": 9e-07, @@ -53669,7 +51820,6 @@ "litellm_provider": "vertex_ai-qwen_models", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53685,7 +51835,6 @@ "litellm_provider": "vertex_ai-qwen_models", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53698,7 +51847,6 @@ "vertex_ai/veo-3.1-generate-preview": { "litellm_provider": "vertex_ai-video-models", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.4, "output_cost_per_second_4k": 0.6, @@ -53713,7 +51861,6 @@ "vertex_ai/veo-3.1-fast-generate-preview": { "litellm_provider": "vertex_ai-video-models", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.1, "output_cost_per_second_1080p": 0.12, @@ -53730,7 +51877,6 @@ "deprecation_date": "2026-11-17", "litellm_provider": "vertex_ai-video-models", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.4, "output_cost_per_second_4k": 0.6, @@ -53746,7 +51892,6 @@ "deprecation_date": "2026-11-17", "litellm_provider": "vertex_ai-video-models", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.1, "output_cost_per_second_1080p": 0.12, @@ -53762,7 +51907,6 @@ "vertex_ai/veo-3.1-lite-generate-001": { "litellm_provider": "vertex_ai-video-models", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.05, "output_cost_per_second_1080p": 0.08, @@ -53780,7 +51924,6 @@ "litellm_provider": "voyage", "max_input_tokens": 16000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "rerank", "output_cost_per_token": 0.0 }, @@ -53789,7 +51932,6 @@ "litellm_provider": "voyage", "max_input_tokens": 8000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "rerank", "output_cost_per_token": 0.0 }, @@ -53798,7 +51940,6 @@ "litellm_provider": "voyage", "max_input_tokens": 8000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://docs.voyageai.com/docs/pricing" @@ -53808,7 +51949,6 @@ "litellm_provider": "voyage", "max_input_tokens": 4000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://docs.voyageai.com/docs/pricing" @@ -53818,7 +51958,6 @@ "litellm_provider": "voyage", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "rerank", "output_cost_per_token": 0.0 }, @@ -53827,7 +51966,6 @@ "litellm_provider": "voyage", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "rerank", "output_cost_per_token": 0.0 }, @@ -53836,7 +51974,6 @@ "litellm_provider": "voyage", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://docs.voyageai.com/docs/pricing" @@ -53846,7 +51983,6 @@ "litellm_provider": "voyage", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://docs.voyageai.com/docs/pricing" @@ -53855,7 +51991,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "voyage", "max_input_tokens": 4000, - "max_tokens": 4000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53863,7 +51998,6 @@ "input_cost_per_token": 6e-08, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53871,7 +52005,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -53881,7 +52014,6 @@ "input_cost_per_token": 1.8e-07, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53889,7 +52021,6 @@ "input_cost_per_token": 2e-08, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53897,7 +52028,6 @@ "input_cost_per_token": 6e-08, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53905,7 +52035,6 @@ "input_cost_per_token": 2e-08, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53913,7 +52042,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 16000, - "max_tokens": 16000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53921,7 +52049,6 @@ "input_cost_per_token": 1.8e-07, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53929,7 +52056,6 @@ "input_cost_per_token": 1.8e-07, "litellm_provider": "voyage", "max_input_tokens": 120000, - "max_tokens": 120000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53937,7 +52063,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53945,7 +52070,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 16000, - "max_tokens": 16000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53953,7 +52077,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 16000, - "max_tokens": 16000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -53963,7 +52086,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 16000, - "max_tokens": 16000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53971,7 +52093,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "voyage", "max_input_tokens": 4096, - "max_tokens": 4096, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53979,7 +52100,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "voyage", "max_input_tokens": 4000, - "max_tokens": 4000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53987,13 +52107,11 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0 }, "wandb/openai/gpt-oss-120b": { "supports_reasoning": true, - "max_tokens": 131072, "max_input_tokens": 131000, "max_output_tokens": 131072, "input_cost_per_token": 3e-08, @@ -54004,7 +52122,6 @@ }, "wandb/openai/gpt-oss-20b": { "supports_reasoning": true, - "max_tokens": 131072, "max_input_tokens": 131000, "max_output_tokens": 131072, "input_cost_per_token": 3e-08, @@ -54014,7 +52131,6 @@ "source": "https://wandb.ai/site/pricing/tokens/" }, "wandb/moonshotai/Kimi-K2.5": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "cache_read_input_token_cost": 1e-07, @@ -54029,7 +52145,6 @@ "supports_vision": true }, "wandb/meta-llama/Llama-3.1-8B-Instruct": { - "max_tokens": 128000, "max_input_tokens": 131000, "max_output_tokens": 128000, "input_cost_per_token": 2.2e-07, @@ -54040,7 +52155,6 @@ }, "wandb/deepseek-ai/DeepSeek-V3.1": { "supports_reasoning": true, - "max_tokens": 128000, "max_input_tokens": 161000, "max_output_tokens": 128000, "input_cost_per_token": 5.5e-07, @@ -54050,7 +52164,6 @@ "source": "https://wandb.ai/site/pricing/tokens/" }, "wandb/meta-llama/Llama-3.3-70B-Instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 7.1e-07, @@ -54064,7 +52177,6 @@ "litellm_provider": "watsonx", "max_input_tokens": 8192, "max_output_tokens": 1024, - "max_tokens": 1024, "mode": "chat", "output_cost_per_token": 2e-07, "supports_audio_input": false, @@ -54082,7 +52194,6 @@ "litellm_provider": "watsonx", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "supports_audio_input": false, @@ -54096,7 +52207,6 @@ "supports_vision": false }, "watsonx/bigscience/mt0-xxl-13b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1.908e-06, @@ -54109,7 +52219,6 @@ "source": "https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-models.html?context=wx" }, "watsonx/bigscience/mt0-xxl": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1.908e-06, @@ -54122,7 +52231,6 @@ "source": "https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-models.html?context=wx" }, "watsonx/core42/jais-13b-chat": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 0.0005, @@ -54134,7 +52242,6 @@ "supports_vision": false }, "watsonx/google/flan-t5-xl-3b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 6e-07, @@ -54146,7 +52253,6 @@ "supports_vision": false }, "watsonx/ibm/granite-13b-chat-v2": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 6e-07, @@ -54158,7 +52264,6 @@ "supports_vision": false }, "watsonx/ibm/granite-13b-instruct-v2": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 6e-07, @@ -54170,7 +52275,6 @@ "supports_vision": false }, "watsonx/ibm/granite-3-3-8b-instruct": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -54182,7 +52286,6 @@ "supports_vision": false }, "watsonx/ibm/granite-4-h-small": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 6.36e-08, @@ -54195,7 +52298,6 @@ "source": "https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-models.html?context=wx" }, "watsonx/ibm/granite-guardian-3-2-2b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 1e-07, @@ -54207,7 +52309,6 @@ "supports_vision": false }, "watsonx/ibm/granite-guardian-3-3-8b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -54219,7 +52320,6 @@ "supports_vision": false }, "watsonx/ibm/granite-ttm-1024-96-r2": { - "max_tokens": 512, "max_input_tokens": 512, "max_output_tokens": 512, "input_cost_per_token": 3.8e-07, @@ -54231,7 +52331,6 @@ "supports_vision": false }, "watsonx/ibm/granite-ttm-1536-96-r2": { - "max_tokens": 512, "max_input_tokens": 512, "max_output_tokens": 512, "input_cost_per_token": 3.8e-07, @@ -54243,7 +52342,6 @@ "supports_vision": false }, "watsonx/ibm/granite-ttm-512-96-r2": { - "max_tokens": 512, "max_input_tokens": 512, "max_output_tokens": 512, "input_cost_per_token": 3.8e-07, @@ -54255,7 +52353,6 @@ "supports_vision": false }, "watsonx/ibm/granite-vision-3-2-2b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 1e-07, @@ -54267,7 +52364,6 @@ "supports_vision": true }, "watsonx/meta-llama/llama-3-2-11b-vision-instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 3.5e-07, @@ -54279,7 +52375,6 @@ "supports_vision": true }, "watsonx/meta-llama/llama-3-2-1b-instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 1e-07, @@ -54291,7 +52386,6 @@ "supports_vision": false }, "watsonx/meta-llama/llama-3-2-3b-instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 1.5e-07, @@ -54303,7 +52397,6 @@ "supports_vision": false }, "watsonx/meta-llama/llama-3-2-90b-vision-instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2e-06, @@ -54315,7 +52408,6 @@ "supports_vision": true }, "watsonx/meta-llama/llama-3-3-70b-instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 7.526e-07, @@ -54328,7 +52420,6 @@ "source": "https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-models.html?context=wx" }, "watsonx/meta-llama/llama-4-maverick-17b": { - "max_tokens": 8192, "max_input_tokens": 131072, "max_output_tokens": 8192, "input_cost_per_token": 3.71e-07, @@ -54341,7 +52432,6 @@ "source": "https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-models.html?context=wx" }, "watsonx/meta-llama/llama-4-maverick-17b-128e-instruct-fp8": { - "max_tokens": 8192, "max_input_tokens": 131072, "max_output_tokens": 8192, "input_cost_per_token": 3.71e-07, @@ -54354,7 +52444,6 @@ "source": "https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-models.html?context=wx" }, "watsonx/meta-llama/llama-guard-3-11b-vision": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 3.5e-07, @@ -54366,7 +52455,6 @@ "supports_vision": true }, "watsonx/mistralai/mistral-medium-2505": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 3e-06, @@ -54378,7 +52466,6 @@ "supports_vision": false }, "watsonx/mistralai/mistral-small-2503": { - "max_tokens": 32000, "max_input_tokens": 32000, "max_output_tokens": 32000, "input_cost_per_token": 1e-07, @@ -54390,7 +52477,6 @@ "supports_vision": false }, "watsonx/mistralai/mistral-small-3-1-24b-instruct-2503": { - "max_tokens": 16384, "max_input_tokens": 131072, "max_output_tokens": 16384, "input_cost_per_token": 1.06e-07, @@ -54403,7 +52489,6 @@ "source": "https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-models.html?context=wx" }, "watsonx/mistralai/pixtral-12b-2409": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 3.5e-07, @@ -54415,7 +52500,6 @@ "supports_vision": true }, "watsonx/openai/gpt-oss-120b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.59e-07, @@ -54428,7 +52512,6 @@ "source": "https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-models.html?context=wx" }, "watsonx/sdaia/allam-1-13b-instruct": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 1.8e-06, @@ -54465,7 +52548,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "responses", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -54490,7 +52572,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -54514,7 +52595,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -54540,7 +52620,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -54568,7 +52647,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -54596,7 +52674,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -54620,7 +52697,6 @@ "litellm_provider": "xai", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -54642,7 +52718,6 @@ "litellm_provider": "xai", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -54664,7 +52739,6 @@ "litellm_provider": "xai", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -54686,7 +52760,6 @@ "litellm_provider": "xai", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -54708,7 +52781,6 @@ "litellm_provider": "xai", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -54730,7 +52802,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 203000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-06, "output_cost_per_token_batches": 1.1e-06, @@ -54753,7 +52824,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token_batches": 1.6e-06, "output_cost_per_token_priority": 5.6e-06, @@ -54776,7 +52846,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 203000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4e-07, "output_cost_per_token_batches": 2e-07, @@ -55374,7 +53443,6 @@ } }, "fireworks_ai/accounts/fireworks/models/qwen3-coder-480b-a35b-instruct": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 4.5e-07, @@ -55384,7 +53452,6 @@ "supports_reasoning": true }, "fireworks_ai/accounts/fireworks/models/flux-kontext-pro": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 4e-08, @@ -55393,7 +53460,6 @@ "mode": "image_generation" }, "fireworks_ai/accounts/fireworks/models/SSD-1B": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1.3e-10, @@ -55402,7 +53468,6 @@ "mode": "image_generation" }, "fireworks_ai/accounts/fireworks/models/chronos-hermes-13b-v2": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -55411,7 +53476,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-13b": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2e-07, @@ -55420,7 +53484,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-13b-instruct": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2e-07, @@ -55429,7 +53492,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-13b-python": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2e-07, @@ -55438,7 +53500,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-34b": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 9e-07, @@ -55447,7 +53508,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-34b-instruct": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 9e-07, @@ -55456,7 +53516,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-34b-python": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 9e-07, @@ -55465,7 +53524,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-70b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -55474,7 +53532,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-70b-instruct": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -55483,7 +53540,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-70b-python": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -55492,7 +53548,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-7b": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2e-07, @@ -55501,7 +53556,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-7b-instruct": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2e-07, @@ -55510,7 +53564,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-7b-python": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2e-07, @@ -55519,7 +53572,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-qwen-1p5-7b": { - "max_tokens": 65536, "max_input_tokens": 65536, "max_output_tokens": 65536, "input_cost_per_token": 2e-07, @@ -55528,7 +53580,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/codegemma-2b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 1e-07, @@ -55537,7 +53588,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/codegemma-7b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -55546,7 +53596,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/cogito-671b-v2-p1": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 1.2e-06, @@ -55555,7 +53604,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/cogito-v1-preview-llama-3b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -55564,7 +53612,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/cogito-v1-preview-llama-70b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -55573,7 +53620,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/cogito-v1-preview-llama-8b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -55582,7 +53628,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/cogito-v1-preview-qwen-14b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -55591,7 +53636,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/cogito-v1-preview-qwen-32b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -55600,7 +53644,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/flux-kontext-max": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 8e-08, @@ -55609,7 +53652,6 @@ "mode": "image_generation" }, "fireworks_ai/accounts/fireworks/models/dbrx-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1.2e-06, @@ -55618,7 +53660,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-coder-1b-base": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 1e-07, @@ -55627,7 +53668,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-coder-33b-instruct": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 9e-07, @@ -55636,7 +53676,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-coder-7b-base": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -55645,7 +53684,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-coder-7b-base-v1p5": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -55654,7 +53692,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-coder-7b-instruct-v1p5": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -55663,7 +53700,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-coder-v2-lite-base": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 5e-07, @@ -55672,7 +53708,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-coder-v2-lite-instruct": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 5e-07, @@ -55681,7 +53716,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-prover-v2": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 1.2e-06, @@ -55690,7 +53724,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-r1-0528-distill-qwen3-8b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -55699,7 +53732,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-r1-distill-llama-70b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -55708,7 +53740,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-r1-distill-llama-8b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -55717,7 +53748,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-r1-distill-qwen-14b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -55726,7 +53756,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-r1-distill-qwen-1p5b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -55735,7 +53764,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-r1-distill-qwen-32b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -55744,7 +53772,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-r1-distill-qwen-7b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -55753,7 +53780,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-v2-lite-chat": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 5e-07, @@ -55762,7 +53788,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-v2p5": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1.2e-06, @@ -55771,7 +53796,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/devstral-small-2505": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -55780,7 +53804,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/dobby-mini-unhinged-plus-llama-3-1-8b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -55789,7 +53812,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/dobby-unhinged-llama-3-3-70b-new": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -55798,7 +53820,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/dolphin-2-9-2-qwen2-72b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -55807,7 +53828,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/dolphin-2p6-mixtral-8x7b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 5e-07, @@ -55816,7 +53836,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/ernie-4p5-21b-a3b-pt": { - "max_tokens": 4096, "max_input_tokens": 131072, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -55825,7 +53844,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/ernie-4p5-300b-a47b-pt": { - "max_tokens": 4096, "max_input_tokens": 131072, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -55834,7 +53852,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/fare-20b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -55843,7 +53860,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/firefunction-v1": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 5e-07, @@ -55852,7 +53868,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/firellava-13b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -55861,7 +53876,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/firesearch-ocr-v6": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -55870,7 +53884,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/fireworks-asr-large": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 0.0, @@ -55879,7 +53892,6 @@ "mode": "audio_transcription" }, "fireworks_ai/accounts/fireworks/models/fireworks-asr-v2": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 0.0, @@ -55888,7 +53900,6 @@ "mode": "audio_transcription" }, "fireworks_ai/accounts/fireworks/models/flux-1-dev": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -55897,7 +53908,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/flux-1-dev-controlnet-union": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1e-09, @@ -55906,7 +53916,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/flux-1-dev-fp8": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 5e-10, @@ -55915,7 +53924,6 @@ "mode": "image_generation" }, "fireworks_ai/accounts/fireworks/models/flux-1-schnell": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -55924,7 +53932,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/flux-1-schnell-fp8": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 3.5e-10, @@ -55933,7 +53940,6 @@ "mode": "image_generation" }, "fireworks_ai/accounts/fireworks/models/gemma-2b-it": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 1e-07, @@ -55942,7 +53948,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/gemma-3-27b-it": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -55951,7 +53956,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/gemma-7b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -55960,7 +53964,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/gemma-7b-it": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -55969,7 +53972,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/gemma2-9b-it": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -55978,7 +53980,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/glm-4p5v": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.2e-06, @@ -55988,7 +53989,6 @@ "supports_reasoning": true }, "fireworks_ai/accounts/fireworks/models/gpt-oss-safeguard-120b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.2e-06, @@ -55997,7 +53997,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/gpt-oss-safeguard-20b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 5e-07, @@ -56006,7 +54005,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/hermes-2-pro-mistral-7b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56015,7 +54013,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/internvl3-38b": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 9e-07, @@ -56024,7 +54021,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/internvl3-78b": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 9e-07, @@ -56033,7 +54029,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/internvl3-8b": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2e-07, @@ -56042,7 +54037,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/japanese-stable-diffusion-xl": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1.3e-10, @@ -56051,7 +54045,6 @@ "mode": "image_generation" }, "fireworks_ai/accounts/fireworks/models/kat-coder": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 9e-07, @@ -56060,7 +54053,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/kat-dev-32b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -56069,7 +54061,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/kat-dev-72b-exp": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -56078,7 +54069,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-guard-2-8b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -56087,7 +54077,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-guard-3-1b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -56096,7 +54085,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-guard-3-8b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -56105,7 +54093,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v2-13b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -56114,7 +54101,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v2-13b-chat": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -56123,7 +54109,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v2-70b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -56132,7 +54117,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v2-70b-chat": { - "max_tokens": 2048, "max_input_tokens": 2048, "max_output_tokens": 2048, "input_cost_per_token": 9e-07, @@ -56141,7 +54125,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v2-7b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -56150,7 +54133,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v2-7b-chat": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -56159,7 +54141,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3-70b-instruct": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 9e-07, @@ -56168,7 +54149,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3-70b-instruct-hf": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 9e-07, @@ -56177,7 +54157,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3-8b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -56186,7 +54165,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3-8b-instruct-hf": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -56195,7 +54173,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3p1-405b-instruct-long": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -56204,7 +54181,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3p1-70b-instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -56213,7 +54189,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3p1-70b-instruct-1b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -56222,7 +54197,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3p1-nemotron-70b-instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -56231,7 +54205,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3p2-1b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -56240,7 +54213,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3p2-3b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -56249,7 +54221,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3p3-70b-instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -56258,7 +54229,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llamaguard-7b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -56267,7 +54237,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llava-yi-34b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -56276,7 +54245,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/minimax-m1-80k": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -56285,7 +54253,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/minimax-m2": { - "max_tokens": 4096, "max_input_tokens": 196608, "max_output_tokens": 4096, "input_cost_per_token": 3e-07, @@ -56294,7 +54261,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/ministral-3-14b-instruct-2512": { - "max_tokens": 256000, "max_input_tokens": 256000, "max_output_tokens": 256000, "input_cost_per_token": 2e-07, @@ -56303,7 +54269,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/ministral-3-3b-instruct-2512": { - "max_tokens": 256000, "max_input_tokens": 256000, "max_output_tokens": 256000, "input_cost_per_token": 1e-07, @@ -56312,7 +54277,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/ministral-3-8b-instruct-2512": { - "max_tokens": 256000, "max_input_tokens": 256000, "max_output_tokens": 256000, "input_cost_per_token": 2e-07, @@ -56321,7 +54285,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mistral-7b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56330,7 +54293,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mistral-7b-instruct-4k": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56339,7 +54301,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mistral-7b-instruct-v0p2": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56348,7 +54309,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mistral-7b-instruct-v3": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56357,7 +54317,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mistral-7b-v0p2": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56366,7 +54325,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mistral-large-3-fp8": { - "max_tokens": 256000, "max_input_tokens": 256000, "max_output_tokens": 256000, "input_cost_per_token": 1.2e-06, @@ -56375,7 +54333,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mistral-nemo-base-2407": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2e-07, @@ -56384,7 +54341,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mistral-nemo-instruct-2407": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2e-07, @@ -56393,7 +54349,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mistral-small-24b-instruct-2501": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 9e-07, @@ -56402,7 +54357,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mixtral-8x22b": { - "max_tokens": 65536, "max_input_tokens": 65536, "max_output_tokens": 65536, "input_cost_per_token": 1.2e-06, @@ -56411,7 +54365,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mixtral-8x22b-instruct": { - "max_tokens": 65536, "max_input_tokens": 65536, "max_output_tokens": 65536, "input_cost_per_token": 1.2e-06, @@ -56420,7 +54373,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mixtral-8x7b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 5e-07, @@ -56429,7 +54381,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mixtral-8x7b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 5e-07, @@ -56438,7 +54389,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mixtral-8x7b-instruct-hf": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 5e-07, @@ -56447,7 +54397,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mythomax-l2-13b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -56456,7 +54405,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/nemotron-nano-v2-12b-vl": { - "max_tokens": 4096, "max_input_tokens": 131072, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -56465,7 +54413,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/nous-capybara-7b-v1p9": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56474,7 +54421,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/nous-hermes-2-mixtral-8x7b-dpo": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 5e-07, @@ -56483,7 +54429,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/nous-hermes-2-yi-34b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -56492,7 +54437,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/nous-hermes-llama2-13b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -56501,7 +54445,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/nous-hermes-llama2-70b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -56510,7 +54453,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/nous-hermes-llama2-7b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -56519,7 +54461,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/nvidia-nemotron-nano-12b-v2": { - "max_tokens": 131072, "max_input_tokens": 128000, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -56528,7 +54469,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/nvidia-nemotron-nano-9b-v2": { - "max_tokens": 131072, "max_input_tokens": 128000, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -56537,7 +54477,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/openchat-3p5-0106-7b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -56546,7 +54485,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/openhermes-2-mistral-7b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56555,7 +54493,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/openhermes-2p5-mistral-7b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56564,7 +54501,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/openorca-7b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56573,7 +54509,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/phi-2-3b": { - "max_tokens": 2048, "max_input_tokens": 2048, "max_output_tokens": 2048, "input_cost_per_token": 1e-07, @@ -56582,7 +54517,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/phi-3-mini-128k-instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -56591,7 +54525,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/phi-3-vision-128k-instruct": { - "max_tokens": 32064, "max_input_tokens": 32064, "max_output_tokens": 32064, "input_cost_per_token": 2e-07, @@ -56600,7 +54533,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/phind-code-llama-34b-python-v1": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 9e-07, @@ -56609,7 +54541,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/phind-code-llama-34b-v1": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 9e-07, @@ -56618,7 +54549,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/phind-code-llama-34b-v2": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 9e-07, @@ -56627,7 +54557,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/playground-v2-1024px-aesthetic": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1.3e-10, @@ -56636,7 +54565,6 @@ "mode": "image_generation" }, "fireworks_ai/accounts/fireworks/models/playground-v2-5-1024px-aesthetic": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1.3e-10, @@ -56645,7 +54573,6 @@ "mode": "image_generation" }, "fireworks_ai/accounts/fireworks/models/pythia-12b": { - "max_tokens": 2048, "max_input_tokens": 2048, "max_output_tokens": 2048, "input_cost_per_token": 2e-07, @@ -56654,7 +54581,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen-qwq-32b-preview": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 9e-07, @@ -56663,7 +54589,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen-v2p5-14b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56672,7 +54597,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen-v2p5-7b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -56681,7 +54605,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen1p5-72b-chat": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 9e-07, @@ -56690,7 +54613,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2-7b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56699,7 +54621,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2-vl-2b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -56708,7 +54629,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2-vl-72b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 9e-07, @@ -56717,7 +54637,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2-vl-7b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56726,7 +54645,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-0p5b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -56735,7 +54653,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-14b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -56744,7 +54661,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-1p5b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -56753,7 +54669,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-32b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -56762,7 +54677,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-32b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 9e-07, @@ -56771,7 +54685,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-72b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -56780,7 +54693,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-72b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 9e-07, @@ -56789,7 +54701,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-7b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56798,7 +54709,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-0p5b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -56807,7 +54717,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-0p5b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -56816,7 +54725,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-14b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56825,7 +54733,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-14b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56834,7 +54741,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-1p5b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -56843,7 +54749,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-1p5b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -56852,7 +54757,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-32b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 9e-07, @@ -56861,7 +54765,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-32b-instruct-128k": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -56870,7 +54773,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-32b-instruct-32k-rope": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 9e-07, @@ -56879,7 +54781,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-32b-instruct-64k": { - "max_tokens": 65536, "max_input_tokens": 65536, "max_output_tokens": 65536, "input_cost_per_token": 9e-07, @@ -56888,7 +54789,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-3b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -56897,7 +54797,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-3b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -56906,7 +54805,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-7b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56915,7 +54813,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-7b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56924,7 +54821,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-math-72b-instruct": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -56933,7 +54829,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-vl-32b-instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 9e-07, @@ -56942,7 +54837,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-vl-3b-instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2e-07, @@ -56951,7 +54845,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-vl-72b-instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 9e-07, @@ -56960,7 +54853,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-vl-7b-instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2e-07, @@ -56969,7 +54861,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-0p6b": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 1e-07, @@ -56978,7 +54869,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-14b": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 2e-07, @@ -56987,7 +54877,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-1p7b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -56996,7 +54885,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-1p7b-fp8-draft": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1e-07, @@ -57005,7 +54893,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-1p7b-fp8-draft-131072": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -57014,7 +54901,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-1p7b-fp8-draft-40960": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 1e-07, @@ -57023,7 +54909,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-235b-a22b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2.2e-07, @@ -57032,7 +54917,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-235b-a22b-instruct-2507": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 2.2e-07, @@ -57041,7 +54925,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-235b-a22b-thinking-2507": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 2.2e-07, @@ -57050,7 +54933,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-30b-a3b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.5e-07, @@ -57059,7 +54941,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-30b-a3b-instruct-2507": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 5e-07, @@ -57068,7 +54949,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-30b-a3b-thinking-2507": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 9e-07, @@ -57077,7 +54957,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-32b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -57087,7 +54966,6 @@ "supports_reasoning": true }, "fireworks_ai/accounts/fireworks/models/qwen3-4b": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 2e-07, @@ -57096,7 +54974,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-4b-instruct-2507": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 2e-07, @@ -57105,7 +54982,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-8b": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 2e-07, @@ -57115,7 +54991,6 @@ "supports_reasoning": true }, "fireworks_ai/accounts/fireworks/models/qwen3-coder-30b-a3b-instruct": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.5e-07, @@ -57124,7 +54999,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-coder-480b-instruct-bf16": { - "max_tokens": 4096, "max_input_tokens": 262144, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -57133,7 +55007,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-embedding-0p6b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 0.0, @@ -57142,7 +55015,6 @@ "mode": "embedding" }, "fireworks_ai/accounts/fireworks/models/qwen3-embedding-4b": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 0.0, @@ -57151,7 +55023,6 @@ "mode": "embedding" }, "fireworks_ai/accounts/fireworks/models/qwen3-next-80b-a3b-instruct": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -57160,7 +55031,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-next-80b-a3b-thinking": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -57169,7 +55039,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-reranker-0p6b": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 0.0, @@ -57178,7 +55047,6 @@ "mode": "rerank" }, "fireworks_ai/accounts/fireworks/models/qwen3-reranker-4b": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 0.0, @@ -57187,7 +55055,6 @@ "mode": "rerank" }, "fireworks_ai/accounts/fireworks/models/qwen3-reranker-8b": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 2e-07, @@ -57197,7 +55064,6 @@ "source": "https://api.fireworks.ai/v1/serverless/models" }, "fireworks_ai/accounts/fireworks/models/qwen3-vl-235b-a22b-instruct": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 2.2e-07, @@ -57206,7 +55072,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-vl-235b-a22b-thinking": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 2.2e-07, @@ -57215,7 +55080,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-vl-30b-a3b-instruct": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.5e-07, @@ -57224,7 +55088,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-vl-30b-a3b-thinking": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.5e-07, @@ -57233,7 +55096,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-vl-32b-instruct": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -57242,7 +55104,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-vl-8b-instruct": { - "max_tokens": 4096, "max_input_tokens": 262144, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -57256,7 +55117,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.6e-06, "source": "https://api.fireworks.ai/v1/serverless/models", @@ -57267,7 +55127,6 @@ "supports_vision": true }, "fireworks_ai/accounts/fireworks/models/qwq-32b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -57276,7 +55135,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/rolm-ocr": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2e-07, @@ -57285,7 +55143,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/snorkel-mistral-7b-pairrm-dpo": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -57294,7 +55151,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/stable-diffusion-xl-1024-v1-0": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1.3e-10, @@ -57303,7 +55159,6 @@ "mode": "image_generation" }, "fireworks_ai/accounts/fireworks/models/stablecode-3b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -57312,7 +55167,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/starcoder-16b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -57321,7 +55175,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/starcoder-7b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -57330,7 +55183,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/starcoder2-15b": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2e-07, @@ -57339,7 +55191,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/starcoder2-3b": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 1e-07, @@ -57348,7 +55199,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/starcoder2-7b": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2e-07, @@ -57357,7 +55207,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/toppy-m-7b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -57366,7 +55215,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/yi-34b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -57375,7 +55223,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/yi-34b-200k-capybara": { - "max_tokens": 200000, "max_input_tokens": 200000, "max_output_tokens": 200000, "input_cost_per_token": 9e-07, @@ -57384,7 +55231,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/yi-34b-chat": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -57393,7 +55239,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/yi-6b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -57402,7 +55247,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/zephyr-7b-beta": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -57416,7 +55260,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 202800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 8.8e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -57433,7 +55276,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -57450,7 +55292,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -57465,7 +55306,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 256000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 3.6e-06, "supports_function_calling": true, @@ -57477,7 +55317,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 256000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-06, "supports_function_calling": true, @@ -57489,7 +55328,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 256000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 2.25e-06, "supports_function_calling": true @@ -57505,7 +55343,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 128000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-07, "supports_function_calling": true, @@ -57516,7 +55353,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 128000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true @@ -57532,7 +55368,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 256000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 5e-07, "supports_function_calling": true, @@ -57544,7 +55379,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 256000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 7.5e-06, "supports_reasoning": true, @@ -57557,7 +55391,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 128000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3.5e-07, "supports_function_calling": true, @@ -57568,7 +55401,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2e-07, "supports_vision": true, @@ -57586,7 +55418,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 9e-07, "supports_function_calling": true @@ -57598,7 +55429,6 @@ "output_cost_per_token": 4e-07, "max_input_tokens": 163840, "max_output_tokens": 65536, - "max_tokens": 65536, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57615,7 +55445,6 @@ "output_cost_per_token": 1.2e-06, "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57631,7 +55460,6 @@ "output_cost_per_token": 2.2e-06, "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57648,7 +55476,6 @@ "output_cost_per_token": 3.3e-07, "max_input_tokens": 262144, "max_output_tokens": 32000, - "max_tokens": 32000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57665,7 +55492,6 @@ "output_cost_per_token": 1.38e-07, "max_input_tokens": 65536, "max_output_tokens": 65536, - "max_tokens": 65536, "supports_vision": true, "supports_system_messages": true }, @@ -57676,7 +55502,6 @@ "output_cost_per_token": 2.5e-06, "max_input_tokens": 262144, "max_output_tokens": 100352, - "max_tokens": 100352, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57693,7 +55518,6 @@ "output_cost_per_token": 1.2e-06, "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57710,7 +55534,6 @@ "output_cost_per_token": 2e-08, "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "supports_vision": true, "supports_system_messages": true }, @@ -57721,7 +55544,6 @@ "output_cost_per_token": 4.1e-07, "max_input_tokens": 163840, "max_output_tokens": 65536, - "max_tokens": 65536, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57736,7 +55558,6 @@ "output_cost_per_token": 3.95e-06, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_vision": true, "supports_system_messages": true, "supports_reasoning": true, @@ -57750,7 +55571,6 @@ "output_cost_per_token": 9e-07, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57768,7 +55588,6 @@ "output_cost_per_token": 2.2e-06, "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57785,7 +55604,6 @@ "output_cost_per_token": 1.2e-06, "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57801,7 +55619,6 @@ "output_cost_per_token": 1.5e-06, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57816,7 +55633,6 @@ "output_cost_per_token": 1.5e-06, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57831,7 +55647,6 @@ "output_cost_per_token": 3e-08, "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_tool_choice": true, "supports_vision": true, "supports_system_messages": true, @@ -57844,7 +55659,6 @@ "output_cost_per_token": 1e-06, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57861,7 +55675,6 @@ "output_cost_per_token": 1.5e-06, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57876,7 +55689,6 @@ "output_cost_per_token": 8.45e-06, "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57890,7 +55702,6 @@ "output_cost_per_token": 6e-07, "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "supports_tool_choice": true, "supports_vision": true, "supports_system_messages": true, @@ -57903,7 +55714,6 @@ "output_cost_per_token": 1e-06, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57920,7 +55730,6 @@ "output_cost_per_token": 2.5e-06, "max_input_tokens": 262144, "max_output_tokens": 100352, - "max_tokens": 100352, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57934,7 +55743,6 @@ "output_cost_per_token": 1.55e-06, "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57948,7 +55756,6 @@ "output_cost_per_token": 2.7e-07, "max_input_tokens": 160000, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57962,7 +55769,6 @@ "output_cost_per_token": 2.5e-07, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57978,7 +55784,6 @@ "output_cost_per_token": 2.3e-06, "max_input_tokens": 131072, "max_output_tokens": 100352, - "max_tokens": 100352, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57992,7 +55797,6 @@ "output_cost_per_token": 1.12e-06, "max_input_tokens": 163840, "max_output_tokens": 65536, - "max_tokens": 65536, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58008,7 +55812,6 @@ "output_cost_per_token": 2.2e-06, "max_input_tokens": 131072, "max_output_tokens": 98304, - "max_tokens": 98304, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58024,7 +55827,6 @@ "output_cost_per_token": 3e-06, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58038,7 +55840,6 @@ "output_cost_per_token": 5e-08, "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "supports_system_messages": true, "supports_response_schema": true }, @@ -58049,7 +55850,6 @@ "output_cost_per_token": 1e-07, "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_tool_choice": true, "supports_vision": true, "supports_system_messages": true, @@ -58062,7 +55862,6 @@ "output_cost_per_token": 1.8e-06, "max_input_tokens": 65536, "max_output_tokens": 16384, - "max_tokens": 16384, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58080,7 +55879,6 @@ "output_cost_per_token": 1.5e-07, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_tool_choice": true, "supports_vision": false, "supports_system_messages": true, @@ -58094,7 +55892,6 @@ "output_cost_per_token": 5.8e-07, "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58108,7 +55905,6 @@ "output_cost_per_token": 1.5e-07, "max_input_tokens": 32768, "max_output_tokens": 16384, - "max_tokens": 16384, "supports_tool_choice": true, "supports_system_messages": true, "supports_response_schema": true, @@ -58121,7 +55917,6 @@ "output_cost_per_token": 4e-07, "max_input_tokens": 12288, "max_output_tokens": 12288, - "max_tokens": 12288, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58135,7 +55930,6 @@ "output_cost_per_token": 4e-07, "max_input_tokens": 32000, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58149,7 +55943,6 @@ "output_cost_per_token": 1.7e-07, "max_input_tokens": 60288, "max_output_tokens": 16000, - "max_tokens": 16000, "supports_tool_choice": true, "supports_system_messages": true, "supports_response_schema": true @@ -58161,7 +55954,6 @@ "output_cost_per_token": 2.2e-06, "max_input_tokens": 1000000, "max_output_tokens": 40000, - "max_tokens": 40000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58176,7 +55968,6 @@ "output_cost_per_token": 2.5e-06, "max_input_tokens": 163840, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58193,7 +55984,6 @@ "output_cost_per_token": 3e-07, "max_input_tokens": 64000, "max_output_tokens": 32000, - "max_tokens": 32000, "supports_tool_choice": true, "supports_system_messages": true, "supports_response_schema": true, @@ -58206,7 +55996,6 @@ "output_cost_per_token": 4e-08, "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_system_messages": true, "supports_response_schema": true }, @@ -58217,7 +56006,6 @@ "output_cost_per_token": 6.2e-07, "max_input_tokens": 65535, "max_output_tokens": 8000, - "max_tokens": 8000, "supports_system_messages": true, "supports_response_schema": true }, @@ -58228,7 +56016,6 @@ "output_cost_per_token": 9e-08, "max_input_tokens": 128000, "max_output_tokens": 32000, - "max_tokens": 32000, "supports_system_messages": true, "supports_reasoning": true }, @@ -58239,7 +56026,6 @@ "output_cost_per_token": 8e-07, "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_tool_choice": true, "supports_system_messages": true, "supports_response_schema": true, @@ -58252,7 +56038,6 @@ "output_cost_per_token": 7.4e-07, "max_input_tokens": 8192, "max_output_tokens": 8000, - "max_tokens": 8000, "supports_tool_choice": true, "supports_system_messages": true, "supports_response_schema": true @@ -58264,7 +56049,6 @@ "output_cost_per_token": 8e-07, "max_input_tokens": 40960, "max_output_tokens": 20000, - "max_tokens": 20000, "supports_system_messages": true, "supports_reasoning": true, "supports_response_schema": true @@ -58276,7 +56060,6 @@ "output_cost_per_token": 8.5e-07, "max_input_tokens": 1048576, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_vision": true, "supports_system_messages": true, "supports_response_schema": true @@ -58288,7 +56071,6 @@ "output_cost_per_token": 5.9e-07, "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "supports_vision": true, "supports_system_messages": true }, @@ -58299,7 +56081,6 @@ "output_cost_per_token": 1.4e-07, "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_tool_choice": true, "supports_system_messages": true, "supports_response_schema": true @@ -58311,7 +56092,6 @@ "output_cost_per_token": 8e-07, "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_vision": true, "supports_system_messages": true }, @@ -58322,7 +56102,6 @@ "output_cost_per_token": 1.48e-06, "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58335,7 +56114,6 @@ "output_cost_per_token": 2.8e-07, "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "supports_system_messages": true, "supports_reasoning": true }, @@ -58346,7 +56124,6 @@ "output_cost_per_token": 5e-08, "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_tool_choice": true, "supports_system_messages": true, "supports_response_schema": true @@ -58358,7 +56135,6 @@ "output_cost_per_token": 7e-08, "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "supports_system_messages": true }, "novita/baidu/ernie-4.5-vl-424b-a47b": { @@ -58368,7 +56144,6 @@ "output_cost_per_token": 1.25e-06, "max_input_tokens": 123000, "max_output_tokens": 16000, - "max_tokens": 16000, "supports_vision": true, "supports_system_messages": true, "supports_reasoning": true @@ -58380,7 +56155,6 @@ "output_cost_per_token": 1.1e-06, "max_input_tokens": 123000, "max_output_tokens": 12000, - "max_tokens": 12000, "supports_tool_choice": true, "supports_system_messages": true, "supports_response_schema": true @@ -58392,7 +56166,6 @@ "output_cost_per_token": 2.5e-06, "max_input_tokens": 160000, "max_output_tokens": 160000, - "max_tokens": 160000, "supports_system_messages": true }, "novita/qwen/qwen3-32b-fp8": { @@ -58402,7 +56175,6 @@ "output_cost_per_token": 4.5e-07, "max_input_tokens": 40960, "max_output_tokens": 20000, - "max_tokens": 20000, "supports_system_messages": true, "supports_reasoning": true }, @@ -58413,7 +56185,6 @@ "output_cost_per_token": 4.5e-07, "max_input_tokens": 40960, "max_output_tokens": 20000, - "max_tokens": 20000, "supports_system_messages": true, "supports_reasoning": true, "supports_function_calling": true, @@ -58426,7 +56197,6 @@ "output_cost_per_token": 2e-07, "max_input_tokens": 98304, "max_output_tokens": 16384, - "max_tokens": 16384, "supports_vision": true, "supports_system_messages": true }, @@ -58437,7 +56207,6 @@ "output_cost_per_token": 1.3e-06, "max_input_tokens": 64000, "max_output_tokens": 16000, - "max_tokens": 16000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58450,7 +56219,6 @@ "output_cost_per_token": 2.5e-06, "max_input_tokens": 64000, "max_output_tokens": 16000, - "max_tokens": 16000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58465,7 +56233,6 @@ "output_cost_per_token": 5e-08, "max_input_tokens": 8192, "max_output_tokens": 32000, - "max_tokens": 32000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58478,7 +56245,6 @@ "output_cost_per_token": 9e-08, "max_input_tokens": 4096, "max_output_tokens": 3200, - "max_tokens": 3200, "supports_system_messages": true }, "novita/baidu/ernie-4.5-vl-28b-a3b-thinking": { @@ -58488,7 +56254,6 @@ "output_cost_per_token": 3.9e-07, "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58504,7 +56269,6 @@ "output_cost_per_token": 5e-07, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58519,7 +56283,6 @@ "output_cost_per_token": 8.5e-07, "max_input_tokens": 131072, "max_output_tokens": 98304, - "max_tokens": 98304, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58535,7 +56298,6 @@ "output_cost_per_token": 7e-07, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58550,7 +56312,6 @@ "output_cost_per_token": 1e-06, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58565,7 +56326,6 @@ "output_cost_per_token": 9.7e-07, "max_input_tokens": 65536, "max_output_tokens": 16384, - "max_tokens": 16384, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58582,7 +56342,6 @@ "output_cost_per_token": 9.7e-07, "max_input_tokens": 65536, "max_output_tokens": 16384, - "max_tokens": 16384, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58599,7 +56358,6 @@ "output_cost_per_token": 7.5e-07, "max_input_tokens": 16384, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_system_messages": true }, "novita/baidu/ernie-4.5-vl-28b-a3b": { @@ -58609,7 +56367,6 @@ "output_cost_per_token": 5.6e-07, "max_input_tokens": 30000, "max_output_tokens": 8000, - "max_tokens": 8000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58624,7 +56381,6 @@ "output_cost_per_token": 2.8e-07, "max_input_tokens": 120000, "max_output_tokens": 8000, - "max_tokens": 8000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58637,7 +56393,6 @@ "output_cost_per_token": 1.38e-07, "max_input_tokens": 128000, "max_output_tokens": 20000, - "max_tokens": 20000, "supports_system_messages": true, "supports_reasoning": true }, @@ -58648,7 +56403,6 @@ "output_cost_per_token": 3e-08, "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_system_messages": true, "supports_reasoning": true, "supports_function_calling": true, @@ -58661,7 +56415,6 @@ "output_cost_per_token": 7e-08, "max_input_tokens": 32000, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58675,7 +56428,6 @@ "output_cost_per_token": 5e-08, "max_input_tokens": 32768, "max_output_tokens": 32000, - "max_tokens": 32000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58688,7 +56440,6 @@ "output_cost_per_token": 1.48e-06, "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58700,8 +56451,7 @@ "input_cost_per_token": 7e-08, "output_cost_per_token": 0, "max_input_tokens": 32768, - "max_output_tokens": 32768, - "max_tokens": 32768 + "max_output_tokens": 32768 }, "novita/qwen/qwen3-embedding-8b": { "litellm_provider": "novita", @@ -58709,8 +56459,7 @@ "input_cost_per_token": 7e-08, "output_cost_per_token": 0, "max_input_tokens": 32768, - "max_output_tokens": 4096, - "max_tokens": 4096 + "max_output_tokens": 4096 }, "novita/baai/bge-m3": { "litellm_provider": "novita", @@ -58718,8 +56467,7 @@ "input_cost_per_token": 1e-08, "output_cost_per_token": 1e-08, "max_input_tokens": 8192, - "max_output_tokens": 96000, - "max_tokens": 96000 + "max_output_tokens": 96000 }, "novita/qwen/qwen3-reranker-8b": { "litellm_provider": "novita", @@ -58727,8 +56475,7 @@ "input_cost_per_token": 5e-08, "output_cost_per_token": 5e-08, "max_input_tokens": 32768, - "max_output_tokens": 4096, - "max_tokens": 4096 + "max_output_tokens": 4096 }, "novita/baai/bge-reranker-v2-m3": { "litellm_provider": "novita", @@ -58736,11 +56483,9 @@ "input_cost_per_token": 1e-08, "output_cost_per_token": 1e-08, "max_input_tokens": 8000, - "max_output_tokens": 8000, - "max_tokens": 8000 + "max_output_tokens": 8000 }, "llamagate/llama-3.1-8b": { - "max_tokens": 8192, "max_input_tokens": 131072, "max_output_tokens": 8192, "input_cost_per_token": 3e-08, @@ -58751,7 +56496,6 @@ "supports_response_schema": true }, "llamagate/llama-3.2-3b": { - "max_tokens": 8192, "max_input_tokens": 131072, "max_output_tokens": 8192, "input_cost_per_token": 4e-08, @@ -58762,7 +56506,6 @@ "supports_response_schema": true }, "llamagate/mistral-7b-v0.3": { - "max_tokens": 8192, "max_input_tokens": 32768, "max_output_tokens": 8192, "input_cost_per_token": 1e-07, @@ -58773,7 +56516,6 @@ "supports_response_schema": true }, "llamagate/qwen3-8b": { - "max_tokens": 8192, "max_input_tokens": 32768, "max_output_tokens": 8192, "input_cost_per_token": 4e-08, @@ -58784,7 +56526,6 @@ "supports_response_schema": true }, "llamagate/dolphin3-8b": { - "max_tokens": 8192, "max_input_tokens": 128000, "max_output_tokens": 8192, "input_cost_per_token": 8e-08, @@ -58795,7 +56536,6 @@ "supports_response_schema": true }, "llamagate/deepseek-r1-8b": { - "max_tokens": 16384, "max_input_tokens": 65536, "max_output_tokens": 16384, "input_cost_per_token": 1e-07, @@ -58807,7 +56547,6 @@ "supports_reasoning": true }, "llamagate/deepseek-r1-7b-qwen": { - "max_tokens": 16384, "max_input_tokens": 131072, "max_output_tokens": 16384, "input_cost_per_token": 8e-08, @@ -58819,7 +56558,6 @@ "supports_reasoning": true }, "llamagate/openthinker-7b": { - "max_tokens": 8192, "max_input_tokens": 32768, "max_output_tokens": 8192, "input_cost_per_token": 8e-08, @@ -58831,7 +56569,6 @@ "supports_reasoning": true }, "llamagate/qwen2.5-coder-7b": { - "max_tokens": 8192, "max_input_tokens": 32768, "max_output_tokens": 8192, "input_cost_per_token": 6e-08, @@ -58842,7 +56579,6 @@ "supports_response_schema": true }, "llamagate/deepseek-coder-6.7b": { - "max_tokens": 4096, "max_input_tokens": 16384, "max_output_tokens": 4096, "input_cost_per_token": 6e-08, @@ -58853,7 +56589,6 @@ "supports_response_schema": true }, "llamagate/codellama-7b": { - "max_tokens": 4096, "max_input_tokens": 16384, "max_output_tokens": 4096, "input_cost_per_token": 6e-08, @@ -58864,7 +56599,6 @@ "supports_response_schema": true }, "llamagate/qwen3-vl-8b": { - "max_tokens": 8192, "max_input_tokens": 32768, "max_output_tokens": 8192, "input_cost_per_token": 1.5e-07, @@ -58876,7 +56610,6 @@ "supports_vision": true }, "llamagate/llava-7b": { - "max_tokens": 2048, "max_input_tokens": 4096, "max_output_tokens": 2048, "input_cost_per_token": 1e-07, @@ -58887,7 +56620,6 @@ "supports_vision": true }, "llamagate/gemma3-4b": { - "max_tokens": 8192, "max_input_tokens": 128000, "max_output_tokens": 8192, "input_cost_per_token": 3e-08, @@ -58899,7 +56631,6 @@ "supports_vision": true }, "llamagate/nomic-embed-text": { - "max_tokens": 8192, "max_input_tokens": 8192, "input_cost_per_token": 2e-08, "output_cost_per_token": 0, @@ -58907,7 +56638,6 @@ "mode": "embedding" }, "llamagate/qwen3-embedding-8b": { - "max_tokens": 40960, "max_input_tokens": 40960, "input_cost_per_token": 2e-08, "output_cost_per_token": 0, @@ -58915,7 +56645,6 @@ "mode": "embedding" }, "libertai/hermes-3-8b-tee": { - "max_tokens": 16000, "max_input_tokens": 16000, "max_output_tokens": 16000, "input_cost_per_token": 1.5e-07, @@ -58929,7 +56658,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/gemma-4-31b-it": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.5e-07, @@ -58943,7 +56671,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/gemma-4-31b-it-thinking": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.5e-07, @@ -58958,7 +56685,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/qwen3.6-27b": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.5e-07, @@ -58972,7 +56698,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/qwen3.6-27b-thinking": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.5e-07, @@ -58987,7 +56712,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/qwen3.6-35b-a3b": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.5e-07, @@ -59001,7 +56725,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/qwen3.6-35b-a3b-thinking": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.5e-07, @@ -59016,7 +56739,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/qwen3.5-122b-a10b": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 2.5e-07, @@ -59030,7 +56752,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/qwen3.5-122b-a10b-thinking": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 2.5e-07, @@ -59045,7 +56766,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/deepseek-v4-flash": { - "max_tokens": 200000, "max_input_tokens": 200000, "max_output_tokens": 200000, "input_cost_per_token": 2.5e-07, @@ -59059,7 +56779,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/deepseek-v4-flash-thinking": { - "max_tokens": 200000, "max_input_tokens": 200000, "max_output_tokens": 200000, "input_cost_per_token": 2.5e-07, @@ -59074,7 +56793,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/bge-m3": { - "max_tokens": 8192, "max_input_tokens": 8192, "input_cost_per_token": 1e-08, "output_cost_per_token": 0.0, @@ -59090,7 +56808,6 @@ "litellm_provider": "sarvam", "max_input_tokens": 8192, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 0, "supports_reasoning": true @@ -59166,7 +56883,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "search_context_cost_per_query": { @@ -59194,7 +56910,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "search_context_cost_per_query": { @@ -59226,7 +56941,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -59336,7 +57050,6 @@ "litellm_provider": "gemini", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.039, "output_cost_per_token": 0.0, @@ -59357,7 +57070,6 @@ "litellm_provider": "gemini", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.039, "output_cost_per_token": 0.0, @@ -59380,7 +57092,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2e-06, @@ -59406,7 +57117,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2e-06, @@ -59433,7 +57143,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2e-06, @@ -59452,6 +57161,7 @@ "supports_audio_input": true, "supports_audio_output": true, "gemini_native_audio": true, + "input_cost_per_video_token": 3e-06, "supports_function_calling": true, "supports_response_schema": false, "supports_vision": true, @@ -59467,7 +57177,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 4.5e-06, @@ -59502,7 +57211,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 4.5e-06, @@ -59536,7 +57244,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 4.5e-06, @@ -59569,7 +57276,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2e-06, @@ -59597,7 +57303,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2e-06, @@ -59626,7 +57331,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2e-06, @@ -59647,6 +57351,7 @@ "tpm": 250000, "rpm": 10, "gemini_native_audio": true, + "input_cost_per_video_token": 3e-06, "supports_function_calling": true, "supports_response_schema": false, "supports_vision": true, @@ -59663,7 +57368,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 4.5e-06, @@ -59700,7 +57404,6 @@ "litellm_provider": "gemini", "max_input_tokens": 8192, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "audio_speech", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2e-05, @@ -59727,7 +57430,6 @@ "litellm_provider": "gemini", "max_input_tokens": 8192, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "audio_speech", "output_cost_per_audio_token": 9e-06, "output_cost_per_token": 9e-06, @@ -59752,7 +57454,6 @@ "litellm_provider": "gemini", "max_input_tokens": 8192, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "audio_speech", "output_cost_per_audio_token": 6e-06, "output_cost_per_token": 6e-06, @@ -59772,7 +57473,6 @@ "litellm_provider": "gemini", "max_input_tokens": 8192, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "audio_speech", "output_cost_per_audio_token": 1e-05, "output_cost_per_token": 1e-05, @@ -59792,7 +57492,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -59851,7 +57550,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 2.5e-06, "output_cost_per_token": 2.5e-06, @@ -59911,7 +57609,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_200k_tokens": 1.8e-05, @@ -59973,7 +57670,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_200k_tokens": 1.8e-05, @@ -60034,7 +57730,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_reasoning_token": 2.5e-06, "output_cost_per_token": 2.5e-06, @@ -60085,7 +57780,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -60124,7 +57818,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 7.5e-06, @@ -60156,6 +57849,7 @@ } }, "bedrock_mantle/openai.gpt-oss-120b": { + "supports_vision": false, "input_cost_per_token": 1.5e-07, "input_cost_per_token_batches": 7.5e-08, "input_cost_per_token_flex": 7.5e-08, @@ -60165,7 +57859,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token_batches": 3e-07, "output_cost_per_token_priority": 1.05e-06, @@ -60181,6 +57874,7 @@ "supports_tool_choice": true }, "bedrock_mantle/openai.gpt-oss-20b": { + "supports_vision": false, "input_cost_per_token": 7e-08, "input_cost_per_token_batches": 3.5e-08, "input_cost_per_token_flex": 3.5e-08, @@ -60190,7 +57884,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token_batches": 1.5e-07, "output_cost_per_token_priority": 5.25e-07, @@ -60206,6 +57899,7 @@ "supports_tool_choice": true }, "bedrock_mantle/openai.gpt-oss-safeguard-120b": { + "supports_vision": false, "input_cost_per_token": 1.5e-07, "input_cost_per_token_batches": 7e-08, "input_cost_per_token_flex": 7e-08, @@ -60215,7 +57909,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 131072, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token_batches": 3e-07, "output_cost_per_token_priority": 1.05e-06, @@ -60229,6 +57922,7 @@ "supports_tool_choice": true }, "bedrock_mantle/openai.gpt-oss-safeguard-20b": { + "supports_vision": false, "input_cost_per_token": 7e-08, "input_cost_per_token_batches": 3e-08, "input_cost_per_token_flex": 3e-08, @@ -60238,7 +57932,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 131072, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token_batches": 1e-07, "output_cost_per_token_priority": 3.5e-07, @@ -60266,9 +57959,8 @@ "search_context_size_medium": 0.012 }, "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -60310,9 +58002,8 @@ "search_context_size_medium": 0.012 }, "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -60347,7 +58038,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-56-cyber.html", "use_openai_responses_path": true, @@ -60383,7 +58073,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -60421,9 +58110,8 @@ "search_context_size_medium": 0.012 }, "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -60462,9 +58150,8 @@ "output_cost_per_token_above_272k_tokens": 3.3e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-56-sol.html", "supported_modalities": [ @@ -60499,9 +58186,8 @@ "output_cost_per_token_above_272k_tokens": 3e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-56-sol.html", "supported_modalities": [ @@ -60536,9 +58222,8 @@ "output_cost_per_token_above_272k_tokens": 1.98e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-56-terra.html", "supported_modalities": [ @@ -60573,9 +58258,8 @@ "output_cost_per_token_above_272k_tokens": 1.8e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-56-terra.html", "supported_modalities": [ @@ -60610,9 +58294,8 @@ "output_cost_per_token_above_272k_tokens": 1.98e-06, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-56-luna.html", "supported_modalities": [ @@ -60644,9 +58327,8 @@ "output_cost_per_token_above_272k_tokens": 2.475e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-54.html", "supported_modalities": [ @@ -60676,9 +58358,8 @@ "output_cost_per_token_above_272k_tokens": 2.25e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-54.html", "supported_modalities": [ @@ -60708,9 +58389,8 @@ "output_cost_per_token_above_272k_tokens": 4.95e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-55.html", "supported_modalities": [ @@ -60740,9 +58420,8 @@ "output_cost_per_token_above_272k_tokens": 4.5e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-55.html", "supported_modalities": [ @@ -60775,9 +58454,8 @@ "output_cost_per_token_above_272k_tokens": 1.8e-06, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-56-luna.html", "supported_modalities": [ @@ -60816,9 +58494,8 @@ "output_cost_per_token": 5.5e-05, "output_cost_per_token_above_272k_tokens": 8.25e-05, "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token_above_272k_tokens_ultrafast": 0.000495, "output_cost_per_token_ultrafast": 0.00033, @@ -60857,9 +58534,8 @@ "output_cost_per_token": 1.1e-05, "output_cost_per_token_above_272k_tokens": 1.65e-05, "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -60896,9 +58572,8 @@ "output_cost_per_token": 5.5e-07, "output_cost_per_token_above_272k_tokens": 8.25e-07, "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -60943,9 +58618,8 @@ "output_cost_per_token_above_272k_tokens": 8.25e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token_above_272k_tokens_ultrafast": 0.000495, "output_cost_per_token_ultrafast": 0.00033, @@ -60984,9 +58658,8 @@ "output_cost_per_token_above_272k_tokens": 1.65e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_modalities": [ "text", @@ -61023,9 +58696,8 @@ "output_cost_per_token_above_272k_tokens": 8.25e-07, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_modalities": [ "text", @@ -61068,9 +58740,8 @@ "output_cost_per_token_above_272k_tokens": 7.5e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token_above_272k_tokens_ultrafast": 0.00045, "output_cost_per_token_ultrafast": 0.0003, @@ -61108,9 +58779,8 @@ "output_cost_per_token_above_272k_tokens": 1.5e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_modalities": [ "text", @@ -61143,9 +58813,8 @@ "output_cost_per_token_above_272k_tokens": 1.5e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_modalities": [ "text", @@ -61181,9 +58850,8 @@ "output_cost_per_token_above_272k_tokens": 7.5e-07, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_modalities": [ "text", @@ -61216,9 +58884,8 @@ "output_cost_per_token_above_272k_tokens": 7.5e-07, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_modalities": [ "text", @@ -61256,9 +58923,8 @@ "search_context_size_medium": 0.012 }, "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -61296,9 +58962,8 @@ "search_context_size_medium": 0.012 }, "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -61333,7 +58998,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token_batches": 2e-07, "output_cost_per_token_priority": 7e-07, @@ -61359,7 +59023,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token_batches": 2e-07, "output_cost_per_token_priority": 7e-07, @@ -61385,7 +59048,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token_batches": 4e-08, "output_cost_per_token_priority": 1.4e-07, @@ -61415,7 +59077,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 1048576, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token_batches": 1.25e-06, "output_cost_per_token_flex": 1.25e-06, @@ -61443,7 +59104,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token_flex": 3.3e-06, "output_cost_per_token_priority": 1.155e-05, @@ -61468,7 +59128,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "source": "https://aws.amazon.com/about-aws/whats-new/2025/10/claude-4-5-haiku-anthropic-amazon-bedrock", @@ -61499,7 +59158,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-05, "search_context_cost_per_query": { @@ -61525,7 +59183,8 @@ "prompt_cache_min_tokens": 512, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-anthropic-claude-opus-5-5.html", "thinking_always_on": true, - "supports_forced_tool_use": false + "supports_forced_tool_use": false, + "token_count_model": {"model":"anthropic.claude-opus-5-5","litellm_provider":"bedrock_mantle","region":"us-east-1"} }, "bedrock_mantle/anthropic.claude-sonnet-5-5": { "bedrock_converse_supports_strict_tools": false, @@ -61537,7 +59196,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "search_context_cost_per_query": { @@ -61585,7 +59243,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token_flex": 3.3e-06, "output_cost_per_token_priority": 1.155e-05, @@ -61613,7 +59270,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token_flex": 3e-06, "output_cost_per_token_priority": 1.05e-05, @@ -61628,7 +59284,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.volcengine.com/docs/82379/1330310", "supports_function_calling": true, @@ -61668,7 +59323,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4.3125e-06, "source": "https://www.volcengine.com/docs/82379/1544106", @@ -61684,7 +59338,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 1024000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4.3125e-06, "source": "https://www.volcengine.com/docs/82379/1544106", @@ -61702,7 +59355,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 1024000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 3.88126e-07, "source": "https://www.volcengine.com/docs/82379/1544106", @@ -61719,7 +59371,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2.15625e-06, "source": "https://www.volcengine.com/docs/82379/1544106", @@ -61733,7 +59384,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.volcengine.com/docs/82379/1330310", "supports_function_calling": true, @@ -61771,7 +59421,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.volcengine.com/docs/82379/1330310", "supports_function_calling": true, @@ -61809,7 +59458,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.volcengine.com/docs/82379/1330310", "supports_function_calling": true, @@ -61904,7 +59552,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_function_calling": true, "supports_reasoning": true, @@ -61922,7 +59569,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_function_calling": true, "supports_reasoning": true, @@ -61943,7 +59589,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://aws.amazon.com/about-aws/whats-new/2025/10/claude-4-5-haiku-anthropic-amazon-bedrock", @@ -61973,7 +59618,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://aws.amazon.com/about-aws/whats-new/2025/10/claude-4-5-haiku-anthropic-amazon-bedrock", @@ -61995,7 +59639,6 @@ } }, "snowflake/claude-sonnet-4-5": { - "max_tokens": 16384, "max_input_tokens": 200000, "max_output_tokens": 16384, "input_cost_per_token": 3e-06, @@ -62013,7 +59656,6 @@ "snowflake/claude-sonnet-4-6": { "supports_adaptive_thinking": true, "supports_legacy_thinking": true, - "max_tokens": 16384, "max_input_tokens": 200000, "max_output_tokens": 16384, "input_cost_per_token": 3e-06, @@ -62029,7 +59671,6 @@ "prompt_cache_min_tokens": 1024 }, "snowflake/claude-4-sonnet": { - "max_tokens": 16384, "max_input_tokens": 200000, "max_output_tokens": 16384, "input_cost_per_token": 3e-06, @@ -62045,7 +59686,6 @@ "prompt_cache_min_tokens": 1024 }, "snowflake/claude-4-opus": { - "max_tokens": 16384, "max_input_tokens": 200000, "max_output_tokens": 16384, "input_cost_per_token": 5e-06, @@ -62062,7 +59702,6 @@ "prompt_cache_min_tokens": 1024 }, "snowflake/claude-haiku-4-5": { - "max_tokens": 16384, "max_input_tokens": 200000, "max_output_tokens": 16384, "input_cost_per_token": 1e-06, @@ -62078,7 +59717,6 @@ "prompt_cache_min_tokens": 4096 }, "snowflake/claude-3-7-sonnet": { - "max_tokens": 16384, "max_input_tokens": 200000, "max_output_tokens": 16384, "input_cost_per_token": 3e-06, @@ -62094,7 +59732,6 @@ "supports_response_schema": true }, "snowflake/openai-gpt-4.1": { - "max_tokens": 16384, "max_input_tokens": 300000, "max_output_tokens": 16384, "input_cost_per_token": 2e-06, @@ -62109,7 +59746,6 @@ "supports_response_schema": true }, "snowflake/openai-gpt-5": { - "max_tokens": 16384, "max_input_tokens": 300000, "max_output_tokens": 16384, "input_cost_per_token": 1.25e-06, @@ -62125,7 +59761,6 @@ "supports_response_schema": true }, "snowflake/openai-gpt-5-mini": { - "max_tokens": 16384, "max_input_tokens": 1000000, "max_output_tokens": 16384, "input_cost_per_token": 3e-07, @@ -62137,7 +59772,6 @@ "supports_response_schema": true }, "snowflake/openai-gpt-5-nano": { - "max_tokens": 16384, "max_input_tokens": 5000000, "max_output_tokens": 16384, "input_cost_per_token": 1.5e-07, @@ -62149,7 +59783,6 @@ "supports_response_schema": true }, "snowflake/llama4-maverick": { - "max_tokens": 16384, "max_input_tokens": 128000, "max_output_tokens": 16384, "input_cost_per_token": 2.4e-07, @@ -62160,7 +59793,6 @@ "supports_system_messages": true }, "snowflake/snowflake-arctic-embed-l-v2.0": { - "max_tokens": 8192, "max_input_tokens": 8192, "input_cost_per_token": 7e-08, "output_cost_per_token": 0.0, @@ -62168,7 +59800,6 @@ "mode": "embedding" }, "snowflake/snowflake-arctic-embed-m-v2.0": { - "max_tokens": 8192, "max_input_tokens": 8192, "input_cost_per_token": 7e-08, "output_cost_per_token": 0.0, @@ -62178,7 +59809,7 @@ "soniox/stt-async-v4": { "litellm_provider": "soniox", "max_output_tokens": 8000, - "max_tokens": 8000, + "max_input_tokens": 8000, "input_cost_per_second": 0.0, "output_cost_per_second": 2.77778e-05, "mode": "audio_transcription", @@ -62191,7 +59822,7 @@ "soniox/stt-async-v5": { "litellm_provider": "soniox", "max_output_tokens": 8000, - "max_tokens": 8000, + "max_input_tokens": 8000, "input_cost_per_second": 0.0, "output_cost_per_second": 2.77778e-05, "mode": "audio_transcription", @@ -62368,7 +59999,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 3e-09, @@ -62422,7 +60052,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 3e-09, @@ -62476,7 +60105,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 3e-09, @@ -62530,7 +60158,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 2.2e-08, @@ -62584,7 +60211,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 3e-09, @@ -62638,7 +60264,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 3e-09, @@ -62692,7 +60317,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 3e-09, @@ -62746,7 +60370,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 2.2e-08, @@ -62800,7 +60423,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 3.48e-06, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -62826,7 +60448,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 2.8e-07, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -62852,7 +60473,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 2.2e-08, @@ -62907,7 +60527,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 3e-09, @@ -62962,7 +60581,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.25e-06, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -62987,7 +60605,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -63012,7 +60629,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -63036,7 +60652,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -63060,7 +60675,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -63084,7 +60698,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -63108,7 +60721,6 @@ "litellm_provider": "tencent", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -63132,7 +60744,6 @@ "litellm_provider": "tencent", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -63199,7 +60810,6 @@ "source": "https://docs.devin.ai/desktop/models" }, "pinstripes/ps/glm-4.5-air": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 1.25e-07, @@ -63212,7 +60822,6 @@ "source": "https://pinstripes.io/" }, "pinstripes/ps/qwen3.6-35b-a3b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.4e-07, @@ -63225,7 +60834,6 @@ "source": "https://pinstripes.io/" }, "pinstripes/ps/qwen3-30b-a3b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-08, @@ -63238,7 +60846,6 @@ "source": "https://pinstripes.io/" }, "pinstripes/ps/qwen3-coder-30b-a3b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 3e-07, @@ -63251,7 +60858,6 @@ "source": "https://pinstripes.io/" }, "pinstripes/ps/deepseek-v4-flash": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 1e-07, @@ -63264,7 +60870,6 @@ "source": "https://pinstripes.io/" }, "pinstripes/ps/minimax-m2.7": { - "max_tokens": 1000192, "max_input_tokens": 1000192, "max_output_tokens": 1000192, "input_cost_per_token": 2.55e-07, @@ -63281,7 +60886,6 @@ "litellm_provider": "darkbloom", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.65e-07, "source": "https://www.darkbloom.dev/", @@ -63298,7 +60902,6 @@ "litellm_provider": "darkbloom", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 7e-08, "source": "https://www.darkbloom.dev/", @@ -63318,7 +60921,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -63345,7 +60947,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "responses", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -63374,7 +60975,6 @@ "litellm_provider": "xai", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://api.x.ai/v1/language-models", @@ -63447,7 +61047,6 @@ "litellm_provider": "openai", "max_input_tokens": 16000, "max_output_tokens": 2000, - "max_tokens": 2000, "mode": "realtime", "source": "https://developers.openai.com/api/docs/pricing", "supported_modalities": [ @@ -63472,7 +61071,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_batches": 2.5e-05, @@ -63516,7 +61114,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_batches": 2.5e-05, @@ -63559,7 +61156,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "prompt_cache_min_tokens": 512, @@ -63595,7 +61191,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 5e-06, "search_context_cost_per_query": { @@ -63630,7 +61225,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 6e-07, "reasoning_effort_levels": [ @@ -63651,7 +61245,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://docs.mistral.ai/models/model-cards/leanstral-1-5", @@ -63741,7 +61334,6 @@ "mode": "chat", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_vision": true, @@ -63840,7 +61432,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "realtime", "output_cost_per_audio_token": 2.1e-05, "output_cost_per_token": 2.1e-05, @@ -63869,7 +61460,6 @@ "litellm_provider": "gemini", "max_input_tokens": 98304, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "audio_transcription", "output_cost_per_token": 1.2e-05, "source": "https://ai.google.dev/gemini-api/docs/pricing", @@ -63894,7 +61484,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "audio_transcription", "output_cost_per_token": 2.1e-05, "source": "https://ai.google.dev/gemini-api/docs/pricing", @@ -63975,7 +61564,6 @@ "input_cost_per_token": 8e-09, "litellm_provider": "perplexity", "max_input_tokens": 32768, - "max_tokens": 32768, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -63985,7 +61573,6 @@ "input_cost_per_token": 5e-08, "litellm_provider": "perplexity", "max_input_tokens": 32768, - "max_tokens": 32768, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 2560, @@ -63995,7 +61582,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -64005,7 +61591,6 @@ "input_cost_per_token": 6e-08, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -64015,7 +61600,6 @@ "input_cost_per_token": 2e-08, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -64025,7 +61609,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -64035,7 +61618,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 120000, - "max_tokens": 120000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -64045,7 +61627,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -64061,7 +61642,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6.6e-07, "output_cost_per_token_priority": 8.25e-07, @@ -64080,7 +61660,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_priority": 1.5e-06, @@ -64100,7 +61679,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 1.8e-06, "output_cost_per_token_priority": 2.25e-06, @@ -64120,7 +61698,7 @@ "input_cost_per_token_priority": 2.75e-07, "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 6.6e-07, "output_cost_per_token_priority": 8.25e-07, @@ -64138,7 +61716,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_priority": 1.875e-05, @@ -64163,7 +61740,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6.6e-07, "output_cost_per_token_priority": 8.25e-07, @@ -64182,7 +61758,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_priority": 1.5e-06, @@ -64202,7 +61777,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 1.8e-06, "output_cost_per_token_priority": 2.25e-06, @@ -64222,7 +61796,7 @@ "input_cost_per_token_priority": 2.75e-07, "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 6.6e-07, "output_cost_per_token_priority": 8.25e-07, @@ -64239,7 +61813,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6.6e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -64256,7 +61829,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6.6e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -64274,7 +61846,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_priority": 1.875e-05, @@ -64296,7 +61867,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.25e-05, "reasoning_effort_levels": [ @@ -64319,7 +61889,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.25e-05, "output_cost_per_token_priority": 2.8125e-05, @@ -64361,7 +61930,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-06, "output_cost_per_token_priority": 2.25e-06, @@ -64381,7 +61949,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2e-07, "output_cost_per_token_priority": 2.5e-07, @@ -64401,7 +61968,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2.4e-06, "output_cost_per_token_priority": 3e-06, @@ -64421,7 +61987,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-06, "output_cost_per_token_priority": 2.25e-06, @@ -64456,7 +62021,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2e-07, "output_cost_per_token_priority": 2.5e-07, @@ -64476,7 +62040,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2.4e-06, "output_cost_per_token_priority": 3e-06, @@ -64511,7 +62074,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6.6e-06, "source": "https://api.fireworks.ai/v1/serverless/models", @@ -64528,7 +62090,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6.6e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -64544,7 +62105,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.25e-05, "reasoning_effort_levels": [ @@ -64567,7 +62127,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.25e-05, "output_cost_per_token_priority": 2.8125e-05, @@ -64589,7 +62148,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://api.novita.ai/v3/openai/models", @@ -64606,7 +62164,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 3.96e-06, "source": "https://novita.ai/pricing", @@ -64623,7 +62180,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://novita.ai/pricing", @@ -64640,7 +62196,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 5.8e-07, "source": "https://novita.ai/pricing", @@ -64657,7 +62212,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://novita.ai/pricing", @@ -64674,7 +62228,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://novita.ai/pricing", @@ -64691,7 +62244,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 1.32e-06, "source": "https://api.novita.ai/v3/openai/models", @@ -64708,7 +62260,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 1.32e-06, "source": "https://novita.ai/pricing", @@ -64725,7 +62276,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.5e-06, "source": "https://novita.ai/pricing", @@ -64741,7 +62291,6 @@ "litellm_provider": "novita", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://novita.ai/pricing", @@ -64758,7 +62307,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 2.8e-07, "source": "https://novita.ai/pricing", @@ -64775,7 +62323,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 3.2000000000000003e-06, "source": "https://novita.ai/pricing", @@ -64792,7 +62339,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.8e-07, "source": "https://novita.ai/pricing", @@ -64808,7 +62354,6 @@ "litellm_provider": "novita", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://novita.ai/pricing", @@ -64825,7 +62370,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.8e-07, "source": "https://novita.ai/pricing", @@ -64841,7 +62385,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2.6e-06, "source": "https://novita.ai/pricing", @@ -64857,7 +62400,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 1.15e-06, "source": "https://novita.ai/pricing", @@ -64873,7 +62415,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2.0000000000000002e-07, "source": "https://novita.ai/pricing", @@ -64889,7 +62430,6 @@ "litellm_provider": "novita", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.13e-06, "source": "https://novita.ai/pricing", @@ -64905,7 +62445,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3.3600000000000004e-07, "source": "https://novita.ai/pricing", @@ -64922,7 +62461,6 @@ "litellm_provider": "novita", "max_input_tokens": 1000000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3.75e-06, "source": "https://novita.ai/pricing", @@ -64939,7 +62477,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.044e-06, "source": "https://novita.ai/pricing", @@ -64955,7 +62492,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3.6000000000000003e-06, "source": "https://novita.ai/pricing", @@ -64971,7 +62507,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 3.4e-06, "source": "https://novita.ai/pricing", @@ -64988,7 +62523,6 @@ "litellm_provider": "novita", "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://novita.ai/pricing", @@ -65005,7 +62539,6 @@ "litellm_provider": "novita", "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://api.novita.ai/v3/openai/models", @@ -65022,7 +62555,6 @@ "litellm_provider": "novita", "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://api.novita.ai/v3/openai/models", @@ -65038,7 +62570,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.0000000000000003e-07, "source": "https://novita.ai/pricing", @@ -65053,7 +62584,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.0000000000000003e-07, "source": "https://novita.ai/pricing", @@ -65069,7 +62599,6 @@ "litellm_provider": "novita", "max_input_tokens": 202800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://api.novita.ai/v3/openai/models", @@ -65086,7 +62615,6 @@ "litellm_provider": "novita", "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://novita.ai/pricing", @@ -65103,7 +62631,6 @@ "litellm_provider": "novita", "max_input_tokens": 204800, "max_output_tokens": 131100, - "max_tokens": 131100, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://novita.ai/pricing", @@ -65119,7 +62646,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://novita.ai/pricing", @@ -65134,7 +62660,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3.2000000000000003e-06, "source": "https://novita.ai/pricing", @@ -65149,7 +62674,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://novita.ai/pricing", @@ -65164,7 +62688,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3.6000000000000003e-06, "source": "https://novita.ai/pricing", @@ -65180,7 +62703,6 @@ "litellm_provider": "novita", "max_input_tokens": 204800, "max_output_tokens": 131100, - "max_tokens": 131100, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://novita.ai/pricing", @@ -65197,7 +62719,6 @@ "litellm_provider": "novita", "max_input_tokens": 202800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3.2000000000000003e-06, "source": "https://novita.ai/pricing", @@ -65213,7 +62734,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://novita.ai/pricing", @@ -65227,7 +62747,6 @@ "litellm_provider": "novita", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 3e-08, "source": "https://novita.ai/pricing", @@ -65239,7 +62758,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://novita.ai/pricing", @@ -65256,7 +62774,6 @@ "litellm_provider": "novita", "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.2e-06, "source": "https://api.novita.ai/v3/openai/models", @@ -65273,7 +62790,6 @@ "litellm_provider": "novita", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.0000000000000003e-07, "source": "https://novita.ai/pricing", @@ -65289,7 +62805,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.4850000000000002e-06, "source": "https://novita.ai/pricing", @@ -65304,7 +62819,6 @@ "litellm_provider": "novita", "max_input_tokens": 64000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 8.900000000000001e-07, "source": "https://api.novita.ai/v3/openai/models", @@ -65317,7 +62831,6 @@ "litellm_provider": "novita", "max_input_tokens": 64000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://api.novita.ai/v3/openai/models", @@ -65331,7 +62844,6 @@ "litellm_provider": "novita", "max_input_tokens": 64000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 8.900000000000001e-07, "source": "https://api.novita.ai/v3/openai/models", @@ -65344,7 +62856,6 @@ "litellm_provider": "novita", "max_input_tokens": 64000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://api.novita.ai/v3/openai/models", @@ -65358,7 +62869,6 @@ "litellm_provider": "novita", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.66e-06, "source": "https://api.novita.ai/v3/openai/models", @@ -65372,7 +62882,6 @@ "litellm_provider": "novita", "max_input_tokens": 131000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 2e-08, "source": "https://api.novita.ai/v3/openai/models", @@ -65381,7 +62890,7 @@ }, "wandb/deepseek-ai/DeepSeek-V4-Flash": { "supports_reasoning": true, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "max_input_tokens": 1049000, "input_cost_per_token": 1.4e-07, "output_cost_per_token": 2.8e-07, @@ -65395,7 +62904,7 @@ }, "wandb/deepseek-ai/DeepSeek-V4-Flash-0731": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 1.3e-07, "output_cost_per_token": 2.8e-07, @@ -65408,7 +62917,7 @@ }, "wandb/deepseek-ai/DeepSeek-V4-Pro": { "supports_reasoning": true, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "max_input_tokens": 1049000, "input_cost_per_token": 1.15e-06, "output_cost_per_token": 2.55e-06, @@ -65422,7 +62931,7 @@ }, "wandb/google/gemma-4-31B-it": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 1e-07, "output_cost_per_token": 3.4e-07, @@ -65433,7 +62942,7 @@ }, "wandb/ibm-granite/granite-4.1-8b": { "deprecation_date": "2026-10-05", - "max_tokens": 131072, + "max_output_tokens": 131072, "max_input_tokens": 131000, "input_cost_per_token": 5e-08, "output_cost_per_token": 1e-07, @@ -65444,7 +62953,7 @@ }, "wandb/JetBrains/Mellum2-12B-A2.5B-Instruct": { "deprecation_date": "2026-10-05", - "max_tokens": 131072, + "max_output_tokens": 131072, "max_input_tokens": 131000, "input_cost_per_token": 5e-08, "output_cost_per_token": 1e-07, @@ -65455,7 +62964,7 @@ }, "wandb/meta-llama/Llama-3.1-70B-Instruct": { "deprecation_date": "2026-10-05", - "max_tokens": 128000, + "max_output_tokens": 128000, "max_input_tokens": 131000, "input_cost_per_token": 8e-07, "output_cost_per_token": 8e-07, @@ -65466,7 +62975,7 @@ }, "wandb/MiniMaxAI/MiniMax-M3": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 2.3e-07, "output_cost_per_token": 9.6e-07, @@ -65479,7 +62988,7 @@ }, "wandb/moonshotai/Kimi-K2.7-Code": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 7.1e-07, "output_cost_per_token": 3.5e-06, @@ -65492,7 +63001,7 @@ }, "wandb/moonshotai/Kimi-K2.6": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 6.5e-07, "output_cost_per_token": 3.41e-06, @@ -65505,7 +63014,7 @@ }, "wandb/nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 7e-08, "output_cost_per_token": 2e-07, @@ -65518,7 +63027,7 @@ }, "wandb/nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 5e-07, "output_cost_per_token": 2.15e-06, @@ -65531,7 +63040,7 @@ }, "wandb/OpenPipe/Qwen3-14B-Instruct": { "deprecation_date": "2026-10-05", - "max_tokens": 32768, + "max_output_tokens": 32768, "max_input_tokens": 32800, "input_cost_per_token": 5e-08, "output_cost_per_token": 2.2e-07, @@ -65542,7 +63051,7 @@ }, "wandb/Qwen/Qwen3.8-27B": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 4e-07, "output_cost_per_token": 3e-06, @@ -65555,7 +63064,7 @@ }, "wandb/Qwen/Qwen3.6-35B-A3B": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 2.5e-07, "output_cost_per_token": 1.25e-06, @@ -65566,7 +63075,7 @@ }, "wandb/Qwen/Qwen3.6-27B": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 6e-07, "output_cost_per_token": 3.6e-06, @@ -65581,7 +63090,7 @@ "wandb/Qwen/Qwen3.5-35B-A3B": { "deprecation_date": "2026-10-05", "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 2.5e-07, "output_cost_per_token": 1.25e-06, @@ -65592,7 +63101,7 @@ }, "wandb/Qwen/Qwen3-30B-A3B-Instruct-2507": { "deprecation_date": "2026-10-05", - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 1e-07, "output_cost_per_token": 3e-07, @@ -65625,7 +63134,7 @@ }, "wandb/zai-org/GLM-5.2": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 1049000, "input_cost_per_token": 7.6e-07, "output_cost_per_token": 2.42e-06, @@ -65637,7 +63146,7 @@ "source": "https://wandb.ai/site/pricing/tokens/" }, "deepinfra/openai/gpt-oss-120b-Turbo": { - "max_tokens": 131072, + "max_output_tokens": 131072, "max_input_tokens": 131072, "input_cost_per_token": 1.5e-07, "output_cost_per_token": 6e-07, @@ -65651,7 +63160,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/MiniMaxAI/MiniMax-M2.7": { - "max_tokens": 196608, + "max_output_tokens": 196608, "max_input_tokens": 196608, "input_cost_per_token": 2.5e-07, "output_cost_per_token": 1e-06, @@ -65667,7 +63176,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3.8-27B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 4e-07, "output_cost_per_token": 3e-06, @@ -65683,7 +63192,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemma-4-31B-it-Ultra": { - "max_tokens": 131072, + "max_output_tokens": 131072, "max_input_tokens": 131072, "input_cost_per_token": 2.7e-07, "output_cost_per_token": 7.6e-07, @@ -65697,7 +63206,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/moonshotai/Kimi-K2.5": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 4.5e-07, "output_cost_per_token": 2.25e-06, @@ -65713,7 +63222,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/zai-org/GLM-4.7-Flash": { - "max_tokens": 202752, + "max_output_tokens": 202752, "max_input_tokens": 202752, "input_cost_per_token": 6e-08, "output_cost_per_token": 4e-07, @@ -65729,7 +63238,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/zai-org/GLM-4.6": { - "max_tokens": 202752, + "max_output_tokens": 202752, "max_input_tokens": 202752, "input_cost_per_token": 5e-07, "output_cost_per_token": 2e-06, @@ -65748,7 +63257,7 @@ "input_cost_per_token": 5e-06, "litellm_provider": "deepinfra", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-05, "prompt_cache_min_tokens": 1024, @@ -65762,7 +63271,7 @@ "supports_vision": true }, "deepinfra/anthropic/claude-sonnet-4-6": { - "max_tokens": 1000000, + "max_output_tokens": 1000000, "max_input_tokens": 1000000, "input_cost_per_token": 3e-06, "output_cost_per_token": 1.5e-05, @@ -65778,7 +63287,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemini-3.5-flash": { - "max_tokens": 1000000, + "max_output_tokens": 1000000, "max_input_tokens": 1000000, "input_cost_per_token": 1.5e-06, "output_cost_per_token": 9e-06, @@ -65793,7 +63302,7 @@ "supports_audio_input": true }, "deepinfra/XiaomiMiMo/MiMo-V2.5": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 4e-07, "output_cost_per_token": 2e-06, @@ -65809,7 +63318,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-Max": { - "max_tokens": 256000, + "max_output_tokens": 256000, "max_input_tokens": 256000, "input_cost_per_token": 1.2e-06, "output_cost_per_token": 6e-06, @@ -65824,7 +63333,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemma-4-31B-it-turbo": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 9e-08, "output_cost_per_token": 3.4e-07, @@ -65839,7 +63348,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/thinkingmachines/Inkling-Small": { - "max_tokens": 524288, + "max_output_tokens": 524288, "max_input_tokens": 524288, "input_cost_per_token": 4.5e-07, "output_cost_per_token": 1.2e-06, @@ -65855,7 +63364,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/meta-models/Muse-Glimmer-30B": { - "max_tokens": 131072, + "max_output_tokens": 131072, "max_input_tokens": 131072, "input_cost_per_token": 3e-07, "output_cost_per_token": 1.2e-06, @@ -65871,7 +63380,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-Max-Thinking": { - "max_tokens": 256000, + "max_output_tokens": 256000, "max_input_tokens": 256000, "input_cost_per_token": 1.2e-06, "output_cost_per_token": 6e-06, @@ -65886,7 +63395,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-VL-235B-A22B-Instruct": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 2e-07, "output_cost_per_token": 8.8e-07, @@ -65901,7 +63410,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-VL-30B-A3B-Instruct": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 1.5e-07, "output_cost_per_token": 6e-07, @@ -65914,7 +63423,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3.5-27B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 2.6e-07, "output_cost_per_token": 2.6e-06, @@ -65928,7 +63437,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3.6-35B-A3B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 1e-07, "output_cost_per_token": 9.5e-07, @@ -65942,7 +63451,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/nvidia/Nemotron-Content-Safety-3.5": { - "max_tokens": 131072, + "max_output_tokens": 131072, "max_input_tokens": 131072, "input_cost_per_token": 2e-07, "output_cost_per_token": 2e-07, @@ -65955,7 +63464,7 @@ "input_cost_per_token": 5e-06, "litellm_provider": "deepinfra", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-05, "prompt_cache_min_tokens": 512, @@ -65969,7 +63478,7 @@ "supports_vision": true }, "deepinfra/thinkingmachines/Inkling": { - "max_tokens": 524288, + "max_output_tokens": 524288, "max_input_tokens": 524288, "input_cost_per_token": 9.5e-07, "output_cost_per_token": 4.05e-06, @@ -65985,7 +63494,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/moonshotai/Kimi-K2.6": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 7.5e-07, "output_cost_per_token": 3.5e-06, @@ -66001,7 +63510,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/deepseek-ai/DeepSeek-V4-Pro-0813": { - "max_tokens": 1048576, + "max_output_tokens": 1048576, "max_input_tokens": 1048576, "input_cost_per_token": 1.3e-06, "output_cost_per_token": 2.6e-06, @@ -66016,7 +63525,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3.7-Max": { - "max_tokens": 256000, + "max_output_tokens": 256000, "max_input_tokens": 256000, "input_cost_per_token": 2.5e-06, "output_cost_per_token": 7.5e-06, @@ -66031,7 +63540,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/ByteDance/Seed-2.0-mini": { - "max_tokens": 256000, + "max_output_tokens": 256000, "max_input_tokens": 256000, "input_cost_per_token": 1e-07, "output_cost_per_token": 4e-07, @@ -66047,7 +63556,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3.8-2.4T-A95B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 2e-06, "output_cost_per_token": 6e-06, @@ -66063,7 +63572,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/MiniMaxAI/MiniMax-M3": { - "max_tokens": 524288, + "max_output_tokens": 524288, "max_input_tokens": 524288, "input_cost_per_token": 2.8e-07, "output_cost_per_token": 1.1e-06, @@ -66079,7 +63588,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemini-3.1-flash-lite": { - "max_tokens": 1000000, + "max_output_tokens": 1000000, "max_input_tokens": 1000000, "input_cost_per_token": 2.5e-07, "output_cost_per_token": 1.5e-06, @@ -66094,7 +63603,7 @@ "supports_audio_input": true }, "deepinfra/google/gemini-3.7-flash": { - "max_tokens": 1000000, + "max_output_tokens": 1000000, "max_input_tokens": 1000000, "input_cost_per_token": 7.5e-07, "output_cost_per_token": 3.75e-06, @@ -66110,7 +63619,7 @@ "supports_audio_input": true }, "deepinfra/inclusionAI/Ling-3.0-flash": { - "max_tokens": 131072, + "max_output_tokens": 131072, "max_input_tokens": 131072, "input_cost_per_token": 6e-08, "output_cost_per_token": 1.8e-07, @@ -66126,7 +63635,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/stepfun-ai/Step-3.7-Flash": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 2e-07, "output_cost_per_token": 1.15e-06, @@ -66140,7 +63649,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3.5-35B-A3B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 1.4e-07, "output_cost_per_token": 1e-06, @@ -66156,7 +63665,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/ByteDance/Seed-1.8": { - "max_tokens": 256000, + "max_output_tokens": 256000, "max_input_tokens": 256000, "input_cost_per_token": 2.5e-07, "output_cost_per_token": 2e-06, @@ -66172,7 +63681,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/tencent/Hy3": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 1.4e-07, "output_cost_per_token": 5.8e-07, @@ -66188,7 +63697,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/ByteDance/Seed-2.0-code": { - "max_tokens": 256000, + "max_output_tokens": 256000, "max_input_tokens": 256000, "input_cost_per_token": 5e-07, "output_cost_per_token": 3e-06, @@ -66204,7 +63713,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/ByteDance/Seed-2.0-pro": { - "max_tokens": 256000, + "max_output_tokens": 256000, "max_input_tokens": 256000, "input_cost_per_token": 5e-07, "output_cost_per_token": 3e-06, @@ -66220,7 +63729,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/zai-org/GLM-5": { - "max_tokens": 202752, + "max_output_tokens": 202752, "max_input_tokens": 202752, "input_cost_per_token": 6e-07, "output_cost_per_token": 2.08e-06, @@ -66236,7 +63745,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/nvidia/Nemotron-3-Nano-30B-A3B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 5e-08, "output_cost_per_token": 2e-07, @@ -66251,7 +63760,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/moonshotai/Kimi-K2.7-Code": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 6.8e-07, "output_cost_per_token": 3.4e-06, @@ -66270,7 +63779,7 @@ "input_cost_per_token": 2e-06, "litellm_provider": "deepinfra", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 1e-05, "prompt_cache_min_tokens": 1024, @@ -66284,7 +63793,7 @@ "supports_vision": true }, "deepinfra/Qwen/Qwen3.5-397B-A17B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 4.5e-07, "output_cost_per_token": 3e-06, @@ -66300,7 +63809,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/deepseek-ai/DeepSeek-V4-Flash-0731": { - "max_tokens": 1048576, + "max_output_tokens": 1048576, "max_input_tokens": 1048576, "input_cost_per_token": 8e-08, "output_cost_per_token": 1.8e-07, @@ -66316,7 +63825,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemma-4-E4B-it": { - "max_tokens": 131072, + "max_output_tokens": 131072, "max_input_tokens": 131072, "input_cost_per_token": 2e-08, "output_cost_per_token": 1e-07, @@ -66329,7 +63838,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/deepseek-ai/DeepSeek-V3.2": { - "max_tokens": 163840, + "max_output_tokens": 163840, "max_input_tokens": 163840, "input_cost_per_token": 2.6e-07, "output_cost_per_token": 3.8e-07, @@ -66344,7 +63853,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3.8-Max": { - "max_tokens": 256000, + "max_output_tokens": 256000, "max_input_tokens": 256000, "input_cost_per_token": 1.65e-06, "output_cost_per_token": 4.951e-06, @@ -66362,7 +63871,7 @@ "input_cost_per_token": 1e-05, "litellm_provider": "deepinfra", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 5e-05, "prompt_cache_min_tokens": 512, @@ -66377,7 +63886,7 @@ "thinking_always_on": true }, "deepinfra/nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 5e-07, "output_cost_per_token": 2.2e-06, @@ -66393,7 +63902,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3.5-122B-A10B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 2.9e-07, "output_cost_per_token": 2.4e-06, @@ -66407,7 +63916,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/zai-org/GLM-5.1": { - "max_tokens": 202752, + "max_output_tokens": 202752, "max_input_tokens": 202752, "input_cost_per_token": 1.05e-06, "output_cost_per_token": 3.5e-06, @@ -66423,7 +63932,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/deepseek-ai/DeepSeek-V4-Pro": { - "max_tokens": 1048576, + "max_output_tokens": 1048576, "max_input_tokens": 1048576, "input_cost_per_token": 1.3e-06, "output_cost_per_token": 2.6e-06, @@ -66438,7 +63947,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/nvidia/NVIDIA-Nemotron-3-Super-120B-A12B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 8.5e-08, "output_cost_per_token": 4e-07, @@ -66452,7 +63961,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/zai-org/GLM-5.2": { - "max_tokens": 1048576, + "max_output_tokens": 1048576, "max_input_tokens": 1048576, "input_cost_per_token": 7.5e-07, "output_cost_per_token": 2.4e-06, @@ -66468,7 +63977,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/moonshotai/Kimi-K3": { - "max_tokens": 1048576, + "max_output_tokens": 1048576, "max_input_tokens": 1048576, "input_cost_per_token": 2.85e-06, "output_cost_per_token": 1.425e-05, @@ -66486,7 +63995,7 @@ "input_cost_per_token": 5e-06, "litellm_provider": "deepinfra", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-05, "prompt_cache_min_tokens": 2048, @@ -66500,7 +64009,7 @@ "supports_vision": true }, "deepinfra/Qwen/Qwen3.6-27B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 3.2e-07, "output_cost_per_token": 3.2e-06, @@ -66514,7 +64023,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemma-4-26B-A4B-it": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 7e-08, "output_cost_per_token": 3.4e-07, @@ -66528,7 +64037,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemini-3.1-pro": { - "max_tokens": 1000000, + "max_output_tokens": 1000000, "max_input_tokens": 1000000, "input_cost_per_token": 2e-06, "output_cost_per_token": 1.2e-05, @@ -66543,7 +64052,7 @@ "supports_audio_input": true }, "deepinfra/XiaomiMiMo/MiMo-V2.5-Pro": { - "max_tokens": 1048576, + "max_output_tokens": 1048576, "max_input_tokens": 1048576, "input_cost_per_token": 1e-06, "output_cost_per_token": 3e-06, @@ -66559,7 +64068,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/anthropic/claude-haiku-4-5": { - "max_tokens": 200000, + "max_output_tokens": 200000, "max_input_tokens": 200000, "input_cost_per_token": 1e-06, "output_cost_per_token": 5e-06, @@ -66574,7 +64083,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/deepseek-ai/DeepSeek-V4-Flash": { - "max_tokens": 1048576, + "max_output_tokens": 1048576, "max_input_tokens": 1048576, "input_cost_per_token": 9e-08, "output_cost_per_token": 1.8e-07, @@ -66590,7 +64099,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/deepseek-ai/DeepSeek-V4.1-Flash": { - "max_tokens": 131072, "max_input_tokens": 1048576, "max_output_tokens": 131072, "input_cost_per_token": 1.4e-07, @@ -66607,7 +64115,6 @@ "source": "https://deepinfra.com/deepseek-ai/DeepSeek-V4.1-Flash" }, "deepinfra/deepseek-ai/DeepSeek-V4.1-Flash-1017": { - "max_tokens": 131072, "max_input_tokens": 1048576, "max_output_tokens": 131072, "input_cost_per_token": 1.4e-07, @@ -66624,7 +64131,7 @@ "source": "https://deepinfra.com/deepseek-ai/DeepSeek-V4.1-Flash-1017" }, "deepinfra/openai/gpt-oss-120b-Ultra": { - "max_tokens": 131072, + "max_output_tokens": 131072, "max_input_tokens": 131072, "input_cost_per_token": 2e-07, "output_cost_per_token": 9.5e-07, @@ -66638,7 +64145,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3.5-9B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 1e-07, "output_cost_per_token": 1.5e-07, @@ -66651,7 +64158,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/MiniMaxAI/MiniMax-M2.7-Turbo": { - "max_tokens": 196608, + "max_output_tokens": 196608, "max_input_tokens": 196608, "input_cost_per_token": 3.8e-07, "output_cost_per_token": 1.7e-06, @@ -66667,7 +64174,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/zai-org/GLM-4.7": { - "max_tokens": 202752, + "max_output_tokens": 202752, "max_input_tokens": 202752, "input_cost_per_token": 4e-07, "output_cost_per_token": 1.75e-06, @@ -66683,7 +64190,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemma-4-31B-it": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 1.3e-07, "output_cost_per_token": 3.8e-07, @@ -66702,7 +64209,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 9e-06, "output_cost_per_token": 9e-06, @@ -66737,7 +64243,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -66765,7 +64270,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -66793,7 +64297,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -67069,7 +64572,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -67096,7 +64598,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -67123,7 +64624,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "responses", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -67154,7 +64654,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "responses", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -67182,7 +64681,6 @@ "litellm_provider": "groq", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://console.groq.com/docs/model/qwen/qwen3.8-27b", @@ -67198,7 +64696,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 7.5e-06, "reasoning_effort_levels": [ @@ -67219,7 +64716,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 7.5e-06, "reasoning_effort_levels": [ @@ -67240,7 +64736,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 7.5e-06, "reasoning_effort_levels": [ @@ -67261,7 +64756,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 6e-07, "reasoning_effort_levels": [ @@ -67282,7 +64776,6 @@ "litellm_provider": "mistral", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://docs.mistral.ai/models/model-cards/codestral-25-08", @@ -67297,7 +64790,6 @@ "litellm_provider": "mistral", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://docs.mistral.ai/models/model-cards/codestral-25-08", @@ -67312,7 +64804,6 @@ "litellm_provider": "mistral", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://mistral.ai/news/devstral-2-vibe-cli", @@ -67413,7 +64904,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://docs.mistral.ai/models/model-cards/leanstral-1-5", @@ -67429,7 +64919,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_priority": 5.5e-06, @@ -67448,7 +64937,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6.6e-06, "output_cost_per_token_priority": 8.25e-06, @@ -67467,7 +64955,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_priority": 5.5e-06, @@ -67486,7 +64973,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6.6e-06, "output_cost_per_token_priority": 8.25e-06, @@ -67502,7 +64988,7 @@ "input_cost_per_token": 2.1e-06, "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 6.6e-06, "source": "https://api.fireworks.ai/v1/serverless/models", @@ -67544,7 +65030,7 @@ "input_cost_per_token": 2.1e-06, "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 6.6e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -67561,7 +65047,7 @@ "input_cost_per_token_priority": 1.875e-07, "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_priority": 6.25e-07, @@ -67579,7 +65065,7 @@ "input_cost_per_token_priority": 2.8125e-07, "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 7.5e-07, "output_cost_per_token_priority": 9.375e-07, @@ -67596,7 +65082,7 @@ "input_cost_per_token_priority": 1.875e-07, "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_priority": 6.25e-07, @@ -67614,7 +65100,7 @@ "input_cost_per_token_priority": 2.8125e-07, "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 7.5e-07, "output_cost_per_token_priority": 9.375e-07, @@ -67632,7 +65118,7 @@ "input_cost_per_token_priority": 1e-06, "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 4.05e-06, "output_cost_per_token_priority": 4.05e-06, @@ -67648,7 +65134,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 40960, "max_output_tokens": 40960, - "max_tokens": 40960, "mode": "embedding", "source": "https://api.fireworks.ai/v1/serverless/models" }, @@ -67671,7 +65156,7 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "together_ai", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 4.7e-07, "source": "https://api.together.ai/v1/models" @@ -67731,7 +65216,6 @@ "litellm_provider": "cerebras", "max_input_tokens": 131072, "max_output_tokens": 40960, - "max_tokens": 40960, "mode": "chat", "output_cost_per_token": 1.49e-06, "source": "https://api.cerebras.ai/public/v1/models/gemma-4-31b", @@ -67757,7 +65241,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 256000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 5.5e-06, "source": "https://www.scaleway.com/en/pricing/model-as-a-service/", @@ -67771,7 +65254,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 256000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-07, "source": "https://www.scaleway.com/en/pricing/model-as-a-service/", @@ -67787,7 +65269,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -67810,7 +65291,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 1.2e-06, "supports_function_calling": true, @@ -67852,7 +65332,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -67867,7 +65346,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 3.1e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -67882,7 +65360,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 5.5e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -67897,7 +65374,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6.25e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -67913,7 +65389,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6.6e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -67930,7 +65405,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 3.2e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -67943,7 +65417,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 7.5e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -68018,7 +65491,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.88e-07, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -68036,7 +65508,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-nvidia-nvidia-nemotron-nano-12b-v2-vl-bf16.html", @@ -68052,7 +65523,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.76e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-nvidia-nvidia-nemotron-nano-9b-v2.html", @@ -68067,7 +65537,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 256000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 7.8e-07, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -68080,11 +65549,11 @@ "supports_vision": false }, "bedrock/us-gov-west-1/openai.gpt-oss-20b-1:0": { + "supports_vision": false, "input_cost_per_token": 8.4e-08, "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 3.6e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-20b.html", @@ -68099,11 +65568,11 @@ "supports_tool_choice": true }, "bedrock/us-gov-west-1/openai.gpt-oss-120b-1:0": { + "supports_vision": false, "input_cost_per_token": 1.8e-07, "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-120b.html", @@ -68128,7 +65597,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "prompt_cache_min_tokens": 1024, @@ -68167,7 +65635,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "prompt_cache_min_tokens": 1024, @@ -68205,7 +65672,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "prompt_cache_min_tokens": 512, @@ -68242,7 +65708,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.4e-05, "prompt_cache_min_tokens": 512, @@ -68280,7 +65745,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-05, "supports_adaptive_thinking": true, @@ -68315,7 +65779,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.88e-07, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -68333,7 +65796,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-nvidia-nvidia-nemotron-nano-12b-v2-vl-bf16.html", @@ -68349,7 +65811,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.76e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-nvidia-nvidia-nemotron-nano-9b-v2.html", @@ -68364,7 +65825,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 256000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 7.8e-07, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -68377,11 +65837,11 @@ "supports_vision": false }, "bedrock/us-gov-east-1/openai.gpt-oss-20b-1:0": { + "supports_vision": false, "input_cost_per_token": 8.4e-08, "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 3.6e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-20b.html", @@ -68396,11 +65856,11 @@ "supports_tool_choice": true }, "bedrock/us-gov-east-1/openai.gpt-oss-120b-1:0": { + "supports_vision": false, "input_cost_per_token": 1.8e-07, "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-120b.html", @@ -68425,7 +65885,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "prompt_cache_min_tokens": 1024, @@ -68459,7 +65918,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "prompt_cache_min_tokens": 1024, @@ -68492,7 +65950,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "prompt_cache_min_tokens": 512, @@ -68524,7 +65981,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.4e-05, "prompt_cache_min_tokens": 512, @@ -68557,7 +66013,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-05, "supports_adaptive_thinking": true, @@ -68584,9 +66039,8 @@ }, "bedrock_mantle/us-gov-west-1/openai.gpt-5.6-terra": { "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -68620,9 +66074,8 @@ }, "bedrock_mantle/us-gov-west-1/openai.gpt-5.6-luna": { "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -68656,9 +66109,8 @@ }, "bedrock_mantle/us-gov-west-1/openai.gpt-5.4": { "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -68689,7 +66141,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 1048576, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions", @@ -68713,7 +66164,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions", @@ -68732,7 +66182,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "use_openai_responses_path": true, "supported_endpoints": [ @@ -68751,7 +66200,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "use_openai_responses_path": true, "supported_endpoints": [ @@ -68770,7 +66218,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "use_openai_responses_path": true, "supported_endpoints": [ @@ -68784,12 +66231,12 @@ "supports_vision": true }, "bedrock_mantle/us-gov-west-1/openai.gpt-oss-20b": { + "supports_vision": false, "input_cost_per_token": 8.4e-08, "output_cost_per_token": 3.6e-07, "litellm_provider": "bedrock_mantle", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-20b.html", "supported_endpoints": [ @@ -68803,12 +66250,12 @@ "supports_tool_choice": true }, "bedrock_mantle/us-gov-west-1/openai.gpt-oss-120b": { + "supports_vision": false, "input_cost_per_token": 1.8e-07, "output_cost_per_token": 7.2e-07, "litellm_provider": "bedrock_mantle", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-120b.html", "supported_endpoints": [ @@ -68831,7 +66278,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.4e-05, "prompt_cache_min_tokens": 512, @@ -68854,7 +66300,8 @@ "supports_xhigh_reasoning_effort": true, "thinking_always_on": true, "supports_forced_tool_use": false, - "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-anthropic-claude-opus-5-5.html" + "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-anthropic-claude-opus-5-5.html", + "token_count_model": {"model":"anthropic.claude-opus-5-5","litellm_provider":"bedrock_mantle","region":"us-gov-west-1"} }, "bedrock_mantle/us-gov-west-1/anthropic.claude-sonnet-5-5": { "bedrock_converse_supports_strict_tools": false, @@ -68867,7 +66314,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "supports_forced_tool_use": false, @@ -68894,9 +66340,8 @@ }, "bedrock_mantle/us-gov-east-1/openai.gpt-5.4": { "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -68919,7 +66364,8 @@ "supports_vision": true, "input_cost_per_token": 3.3e-06, "cache_read_input_token_cost": 3.3e-07, - "output_cost_per_token": 1.98e-05 + "output_cost_per_token": 1.98e-05, + "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-54.md" }, "bedrock_mantle/us-gov-east-1/xai.grok-4.6": { "use_openai_responses_path": true, @@ -68929,7 +66375,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions", @@ -68943,12 +66388,12 @@ "supports_vision": true }, "bedrock_mantle/us-gov-east-1/openai.gpt-oss-20b": { + "supports_vision": false, "input_cost_per_token": 8.4e-08, "output_cost_per_token": 3.6e-07, "litellm_provider": "bedrock_mantle", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-20b.html", "supported_endpoints": [ @@ -68962,12 +66407,12 @@ "supports_tool_choice": true }, "bedrock_mantle/us-gov-east-1/openai.gpt-oss-120b": { + "supports_vision": false, "input_cost_per_token": 1.8e-07, "output_cost_per_token": 7.2e-07, "litellm_provider": "bedrock_mantle", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-120b.html", "supported_endpoints": [ @@ -68991,7 +66436,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token_batches": 8.4e-07, "output_cost_per_token_priority": 2.94e-06, @@ -69013,7 +66457,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 256000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token_batches": 1.25e-06, "output_cost_per_token_priority": 4.38e-06, @@ -69035,7 +66478,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 256000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token_batches": 4.4e-07, "output_cost_per_token_priority": 1.54e-06, @@ -69057,7 +66499,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 32000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token_batches": 3e-07, "output_cost_per_token_priority": 1.05e-06, @@ -69080,7 +66521,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 256000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token_batches": 3e-07, "output_cost_per_token_priority": 1.05e-06, @@ -69102,7 +66542,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token_batches": 9e-07, "output_cost_per_token_priority": 3.15e-06, @@ -69123,7 +66562,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 256000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token_batches": 6e-07, "output_cost_per_token_priority": 2.1e-06, @@ -69145,7 +66583,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 256000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token_batches": 1.33e-06, "output_cost_per_token_priority": 4.66e-06, @@ -69164,7 +66601,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.375e-05, "supported_endpoints": [ @@ -69198,7 +66634,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6.05e-06, "supports_prompt_caching": true, @@ -69211,7 +66646,6 @@ "input_cost_per_token": 1.63e-07, "litellm_provider": "azure", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -69219,7 +66653,6 @@ "input_cost_per_token": 2.5e-08, "litellm_provider": "azure", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -69250,7 +66683,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_image": 0.04, "output_cost_per_token": 0, @@ -69275,7 +66707,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0, "source": "https://ai.google.dev/gemini-api/docs/pricing", @@ -69300,7 +66731,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 0, "source": "https://ai.google.dev/gemini-api/docs/pricing", @@ -69325,7 +66755,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 0, "source": "https://ai.google.dev/gemini-api/docs/models/lyria-realtime-exp", @@ -69698,7 +67127,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://inference.baseten.co/v1/models", @@ -69722,7 +67150,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 6.6e-06, "source": "https://inference.baseten.co/v1/models", @@ -69747,7 +67174,7 @@ "output_cost_per_token": 1.5e-07, "source": "https://api.together.ai/v1/models", "max_input_tokens": 128000, - "max_tokens": 128000 + "max_output_tokens": 128000 }, "vertex_ai/gemini-2.5-flash-native-audio": { "deprecation_date": "2026-12-13", @@ -69808,7 +67235,7 @@ "input_cost_per_token": 1.5e-06, "litellm_provider": "vertex_ai", "max_output_tokens": 57920, - "max_tokens": 57920, + "max_input_tokens": 57920, "mode": "chat", "output_cost_per_reasoning_token": 9e-06, "output_cost_per_token": 9e-06, @@ -69871,7 +67298,7 @@ "output_cost_per_token": 3.5e-06, "source": "https://api.together.ai/v1/models", "max_input_tokens": 4096, - "max_tokens": 4096 + "max_output_tokens": 4096 }, "together_ai/meta-llama/Llama-3.2-1B-Instruct": { "input_cost_per_token": 6e-08, @@ -69880,7 +67307,7 @@ "output_cost_per_token": 6e-08, "source": "https://api.together.ai/v1/models", "max_input_tokens": 131072, - "max_tokens": 131072 + "max_output_tokens": 131072 }, "together_ai/meta-llama/Llama-3.2-3B-Instruct": { "input_cost_per_token": 6e-08, @@ -69889,7 +67316,7 @@ "output_cost_per_token": 6e-08, "source": "https://api.together.ai/v1/models", "max_input_tokens": 131072, - "max_tokens": 131072 + "max_output_tokens": 131072 }, "together_ai/Qwen/Qwen2-1.5B-Instruct": { "input_cost_per_token": 2e-08, @@ -69898,7 +67325,7 @@ "output_cost_per_token": 2e-08, "source": "https://api.together.ai/v1/models", "max_input_tokens": 32768, - "max_tokens": 32768 + "max_output_tokens": 32768 }, "together_ai/Qwen/Qwen2.5-14B-Instruct": { "input_cost_per_token": 8e-07, @@ -69907,7 +67334,7 @@ "output_cost_per_token": 8e-07, "source": "https://api.together.ai/v1/models", "max_input_tokens": 32768, - "max_tokens": 32768 + "max_output_tokens": 32768 }, "together_ai/Qwen/Qwen2.5-72B-Instruct": { "input_cost_per_token": 1.2e-06, @@ -69916,14 +67343,13 @@ "output_cost_per_token": 1.2e-06, "source": "https://api.together.ai/v1/models", "max_input_tokens": 32768, - "max_tokens": 32768 + "max_output_tokens": 32768 }, "together_ai/Salesforce/Llama-Rank-V1": { "deprecation_date": "2026-02-06", "input_cost_per_token": 1e-07, "litellm_provider": "together_ai", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://api.together.ai/v1/models" @@ -69932,7 +67358,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "together_ai", "max_input_tokens": 16384, - "max_tokens": 16384, + "max_output_tokens": 16384, "mode": "completion", "output_cost_per_token": 2e-07, "source": "https://api.together.xyz/v1/models" @@ -69950,7 +67376,7 @@ "input_cost_per_token": 6e-07, "litellm_provider": "together_ai", "max_input_tokens": 32768, - "max_tokens": 32768, + "max_output_tokens": 32768, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://api.together.ai/v1/models" @@ -69960,7 +67386,7 @@ "input_cost_per_token": 1.2e-06, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://api.together.ai/v1/models" @@ -69970,7 +67396,7 @@ "input_cost_per_token": 9e-07, "litellm_provider": "together_ai", "max_input_tokens": 32768, - "max_tokens": 32768, + "max_output_tokens": 32768, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://api.together.ai/v1/models" @@ -69980,7 +67406,7 @@ "input_cost_per_token": 1.2e-06, "litellm_provider": "together_ai", "max_input_tokens": 32768, - "max_tokens": 32768, + "max_output_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://api.together.ai/v1/models" @@ -69990,7 +67416,7 @@ "input_cost_per_token": 1.2e-06, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://api.together.ai/v1/models" @@ -70000,7 +67426,7 @@ "input_cost_per_token": 8e-07, "litellm_provider": "together_ai", "max_input_tokens": 16384, - "max_tokens": 16384, + "max_output_tokens": 16384, "mode": "chat", "output_cost_per_token": 8e-07, "source": "https://api.together.ai/v1/models" @@ -70010,7 +67436,7 @@ "input_cost_per_token": 1.95e-06, "litellm_provider": "together_ai", "max_input_tokens": 32768, - "max_tokens": 32768, + "max_output_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://api.together.ai/v1/models" @@ -70020,7 +67446,7 @@ "input_cost_per_token": 2e-06, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://api.together.ai/v1/models" @@ -70030,7 +67456,7 @@ "input_cost_per_token": 5e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://api.together.ai/v1/models" @@ -70040,7 +67466,7 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://api.together.ai/v1/models" @@ -70050,7 +67476,7 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://api.together.ai/v1/models" @@ -70060,7 +67486,7 @@ "input_cost_per_token": 5e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://api.together.ai/v1/models" @@ -70070,7 +67496,7 @@ "input_cost_per_token": 1.8e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 6.8e-07, "source": "https://api.together.ai/v1/models" @@ -70081,7 +67507,7 @@ "input_cost_per_token": 6e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 3.6e-06, "source": "https://api.together.ai/v1/models" @@ -70091,7 +67517,7 @@ "input_cost_per_token": 2e-06, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://api.together.ai/v1/models" @@ -70101,7 +67527,7 @@ "input_cost_per_token": 1.8e-07, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.8e-07, "source": "https://api.together.ai/v1/models" @@ -70111,7 +67537,7 @@ "input_cost_per_token": 1.6e-06, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.6e-06, "source": "https://api.together.ai/v1/models" @@ -70121,7 +67547,7 @@ "input_cost_per_token": 6e-07, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.7e-06, "source": "https://api.together.ai/v1/models" @@ -70131,7 +67557,7 @@ "input_cost_per_token": 8e-07, "litellm_provider": "together_ai", "max_input_tokens": 16384, - "max_tokens": 16384, + "max_output_tokens": 16384, "mode": "chat", "output_cost_per_token": 8e-07, "source": "https://api.together.ai/v1/models" @@ -70141,7 +67567,7 @@ "input_cost_per_token": 8e-07, "litellm_provider": "together_ai", "max_input_tokens": 8192, - "max_tokens": 8192, + "max_output_tokens": 8192, "mode": "chat", "output_cost_per_token": 8e-07, "source": "https://api.together.ai/v1/models" @@ -70151,7 +67577,7 @@ "input_cost_per_token": 3.9e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 9.7e-07, "source": "https://api.together.ai/v1/models" @@ -70161,7 +67587,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "together_ai", "max_input_tokens": 8192, - "max_tokens": 8192, + "max_output_tokens": 8192, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://api.together.ai/v1/models" @@ -70171,7 +67597,7 @@ "input_cost_per_token": 1.8e-07, "litellm_provider": "together_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 5.9e-07, "source": "https://api.together.ai/v1/models" @@ -70181,7 +67607,7 @@ "input_cost_per_token": 8.8e-07, "litellm_provider": "together_ai", "max_input_tokens": 8192, - "max_tokens": 8192, + "max_output_tokens": 8192, "mode": "chat", "output_cost_per_token": 8.8e-07, "source": "https://api.together.ai/v1/models" @@ -70191,7 +67617,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "together_ai", "max_input_tokens": 8192, - "max_tokens": 8192, + "max_output_tokens": 8192, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://api.together.ai/v1/models" @@ -70201,7 +67627,7 @@ "input_cost_per_token": 8.8e-07, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 8.8e-07, "source": "https://api.together.ai/v1/models" @@ -70211,7 +67637,7 @@ "input_cost_per_token": 1.8e-07, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.8e-07, "source": "https://api.together.ai/v1/models" @@ -70221,7 +67647,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "together_ai", "max_input_tokens": 32768, - "max_tokens": 32768, + "max_output_tokens": 32768, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://api.together.ai/v1/models" @@ -70231,7 +67657,7 @@ "input_cost_per_token": 1e-07, "litellm_provider": "together_ai", "max_input_tokens": 32768, - "max_tokens": 32768, + "max_output_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://api.together.ai/v1/models" @@ -70241,7 +67667,7 @@ "input_cost_per_token": 6e-07, "litellm_provider": "together_ai", "max_input_tokens": 32768, - "max_tokens": 32768, + "max_output_tokens": 32768, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://api.together.ai/v1/models" @@ -70252,7 +67678,7 @@ "input_cost_per_token": 1.2e-06, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 4.5e-06, "source": "https://api.together.ai/v1/models" @@ -70263,7 +67689,7 @@ "input_cost_per_token": 9.5e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://api.together.ai/v1/models" @@ -70273,7 +67699,7 @@ "input_cost_per_token": 8.8e-07, "litellm_provider": "together_ai", "max_input_tokens": 32768, - "max_tokens": 32768, + "max_output_tokens": 32768, "mode": "chat", "output_cost_per_token": 8.8e-07, "source": "https://api.together.ai/v1/models" @@ -70284,7 +67710,7 @@ "input_cost_per_token": 6e-07, "litellm_provider": "together_ai", "max_input_tokens": 512288, - "max_tokens": 512288, + "max_output_tokens": 512288, "mode": "chat", "output_cost_per_token": 3.6e-06, "source": "https://api.together.ai/v1/models" @@ -70294,7 +67720,7 @@ "input_cost_per_token": 5e-08, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://api.together.ai/v1/models" @@ -70304,7 +67730,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.1e-06, "source": "https://api.together.ai/v1/models" @@ -70314,7 +67740,7 @@ "input_cost_per_token": 4.5e-07, "litellm_provider": "together_ai", "max_input_tokens": 202752, - "max_tokens": 202752, + "max_output_tokens": 202752, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://api.together.ai/v1/models" @@ -70324,7 +67750,7 @@ "input_cost_per_token": 1e-06, "litellm_provider": "together_ai", "max_input_tokens": 202752, - "max_tokens": 202752, + "max_output_tokens": 202752, "mode": "chat", "output_cost_per_token": 3.2e-06, "source": "https://api.together.ai/v1/models" @@ -70335,7 +67761,7 @@ "input_cost_per_token": 1.4e-06, "litellm_provider": "together_ai", "max_input_tokens": 202752, - "max_tokens": 202752, + "max_output_tokens": 202752, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://api.together.ai/v1/models" @@ -70402,7 +67828,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.65e-05, "output_cost_per_token_batches": 8.25e-06, @@ -70575,7 +68000,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-05, "output_cost_per_token_above_272k_tokens": 9e-05, @@ -70619,7 +68043,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_above_272k_tokens": 9e-07, @@ -70668,7 +68091,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_272k_tokens": 1.8e-05, @@ -70724,7 +68146,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8.8e-06, "output_cost_per_token_batches": 4.4e-06, @@ -70738,7 +68159,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8.8e-06, "output_cost_per_token_batches": 4.4e-06, @@ -70761,7 +68181,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -70775,7 +68194,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -70810,7 +68228,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 4.5e-06, @@ -70832,7 +68249,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 4.5e-06, @@ -70908,7 +68324,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.65e-05, "output_cost_per_token_batches": 8.25e-06, @@ -71121,7 +68536,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 2.4e-05, @@ -71169,7 +68583,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "audio_transcription", "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", "supported_endpoints": [ @@ -71210,7 +68623,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", "supported_modalities": [ @@ -71228,7 +68640,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 512000, "max_output_tokens": 65500, - "max_tokens": 65500, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71241,7 +68652,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71254,7 +68664,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 200000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.2e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71269,7 +68678,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71290,7 +68698,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5.5e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71308,7 +68715,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71328,7 +68734,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71349,7 +68754,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71368,7 +68772,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.2e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71383,7 +68786,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.61333e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71412,7 +68814,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.6e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71428,7 +68829,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71442,7 +68842,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71457,7 +68856,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 2.84e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71472,7 +68870,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 3.38e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71487,7 +68884,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.411e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71503,7 +68899,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.4246e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71520,7 +68915,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3.0136e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71537,7 +68931,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.411e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71554,7 +68947,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2.32375e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71571,7 +68963,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 119000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 2.5353e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71584,7 +68975,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71601,7 +68991,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71618,7 +69007,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71635,7 +69023,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71652,7 +69039,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 2.499999e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71670,7 +69056,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3.75e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71687,7 +69072,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 131100, - "max_tokens": 131100, "mode": "chat", "output_cost_per_token": 3.9998e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71699,7 +69083,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 131100, - "max_tokens": 131100, "mode": "chat", "output_cost_per_token": 3.9998e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71712,7 +69095,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 7.889e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71727,7 +69109,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3.9438e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71742,7 +69123,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3.9438e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71758,7 +69138,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 200000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3.09848e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71772,7 +69151,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.4e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71788,7 +69166,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71805,7 +69182,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71822,7 +69198,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.5e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71839,7 +69214,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.25e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71856,7 +69230,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71872,7 +69245,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 0.00018, "source": "https://aihubmix.com/api/v1/models", @@ -71889,7 +69261,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71906,7 +69277,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71923,7 +69293,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71939,7 +69308,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71984,7 +69352,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72000,7 +69367,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72016,7 +69382,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6.248e-07, "source": "https://aihubmix.com/api/v1/models", @@ -72032,7 +69397,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.535e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72048,7 +69412,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3.9995e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72064,7 +69427,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 7.999e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72080,7 +69442,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://aihubmix.com/api/v1/models", @@ -72096,7 +69457,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3.0984e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72109,7 +69469,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 256000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72145,7 +69504,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 204800, "max_output_tokens": 204800, - "max_tokens": 204800, "mode": "chat", "output_cost_per_token": 1.1832e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72159,7 +69517,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 524288, - "max_tokens": 524288, "mode": "chat", "output_cost_per_token": 1.152e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72184,7 +69541,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 5.48e-07, "source": "https://aihubmix.com/api/v1/models", @@ -72196,7 +69552,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 9.008e-07, "source": "https://aihubmix.com/api/v1/models", @@ -72211,7 +69566,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 9.864e-07, "source": "https://aihubmix.com/api/v1/models", @@ -72226,7 +69580,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 2.532e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72241,7 +69594,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.524e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72258,7 +69610,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 7.608e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72275,7 +69626,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.128e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72292,7 +69642,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72309,7 +69658,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3.80025e-07, "source": "https://aihubmix.com/api/v1/models", @@ -72327,7 +69675,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 5.07e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72512,7 +69859,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "wandb", "max_input_tokens": 1049000, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 6.5e-07, "source": "https://wandb.ai/site/pricing/tokens/", @@ -72525,7 +69872,7 @@ "input_cost_per_token": 1e-07, "litellm_provider": "wandb", "max_input_tokens": 262000, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://wandb.ai/site/pricing/tokens/", @@ -72566,7 +69913,6 @@ "token_count_tokenizer": "kimi_k3", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.65e-05, "output_cost_per_token_flex": 8.25e-06, @@ -72598,7 +69944,6 @@ "token_count_tokenizer": "kimi_k3", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_flex": 7.5e-06, @@ -72630,7 +69975,6 @@ "token_count_tokenizer": "kimi_k3", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.65e-05, "output_cost_per_token_flex": 8.25e-06, @@ -72652,7 +69996,6 @@ "litellm_provider": "xiaomi_mimo", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 8.7e-07, "source": "https://platform.xiaomimimo.com/static/docs/price/pay-as-you-go.md", @@ -72675,7 +70018,6 @@ "litellm_provider": "xiaomi_mimo", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.8e-07, "source": "https://platform.xiaomimimo.com/static/docs/price/pay-as-you-go.md", @@ -72700,7 +70042,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -72726,7 +70067,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72748,7 +70088,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72770,7 +70109,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72792,7 +70130,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72813,7 +70150,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72835,7 +70171,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72856,7 +70191,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72878,7 +70212,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72900,7 +70233,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72921,7 +70253,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72943,7 +70274,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72965,7 +70295,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72986,7 +70315,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -73008,7 +70336,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "responses", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -73033,7 +70360,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "responses", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -73058,7 +70384,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "responses", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -73083,7 +70408,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -73104,7 +70428,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -73126,7 +70449,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://inference.baseten.co/v1/models", @@ -73144,7 +70466,6 @@ "litellm_provider": "baseten", "max_input_tokens": 262000, "max_output_tokens": 262000, - "max_tokens": 262000, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://inference.baseten.co/v1/models", @@ -73162,7 +70483,6 @@ "litellm_provider": "baseten", "max_input_tokens": 262000, "max_output_tokens": 262000, - "max_tokens": 262000, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://inference.baseten.co/v1/models", @@ -73179,7 +70499,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://inference.baseten.co/v1/models", @@ -73196,7 +70515,6 @@ "litellm_provider": "baseten", "max_input_tokens": 202800, "max_output_tokens": 202800, - "max_tokens": 202800, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://inference.baseten.co/v1/models", @@ -73214,7 +70532,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4.05e-06, "source": "https://inference.baseten.co/v1/models", @@ -73232,7 +70549,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://inference.baseten.co/v1/models", @@ -73249,7 +70565,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://inference.baseten.co/v1/models", @@ -73266,7 +70581,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inference.baseten.co/v1/models", @@ -73283,7 +70597,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 2.6e-07, "source": "https://inference.baseten.co/v1/models", @@ -73301,7 +70614,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 3.48e-06, "source": "https://inference.baseten.co/v1/models", @@ -73318,7 +70630,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 3.96e-06, "source": "https://inference.baseten.co/v1/models", @@ -73335,7 +70646,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 6.6e-06, "source": "https://inference.baseten.co/v1/models", @@ -73355,7 +70665,6 @@ "litellm_provider": "xai", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2e-06, "output_cost_per_token_above_200k_tokens": 4e-06, @@ -73376,7 +70685,6 @@ "litellm_provider": "xai", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2e-06, "output_cost_per_token_above_200k_tokens": 4e-06, @@ -73397,7 +70705,6 @@ "litellm_provider": "xai", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2e-06, "output_cost_per_token_above_200k_tokens": 4e-06, @@ -73418,7 +70725,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_priority": 1.2e-06, @@ -73436,7 +70742,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 196608, "max_output_tokens": 196608, - "max_tokens": 196608, "mode": "chat", "output_cost_per_token_priority": 1.2e-06, "source": "https://api.fireworks.ai/v1/serverless/models", @@ -73502,7 +70807,6 @@ "litellm_provider": "vertex_ai-zai_models", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -73520,7 +70824,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "output_cost_per_token_batches": 3.6e-07, @@ -73539,7 +70842,6 @@ "deprecation_date": "2026-06-30", "litellm_provider": "vertex_ai-video-models", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.4, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing#veo", @@ -73555,7 +70857,6 @@ "deprecation_date": "2026-06-30", "litellm_provider": "vertex_ai-video-models", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.1, "output_cost_per_second_1080p": 0.12, @@ -73572,7 +70873,6 @@ "deprecation_date": "2026-06-30", "litellm_provider": "vertex_ai-video-models", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.5, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing#veo", @@ -73619,7 +70919,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_adaptive_thinking": true, "thinking_always_on": true, @@ -73652,7 +70951,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_adaptive_thinking": true, "thinking_always_on": true, @@ -73685,7 +70983,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_adaptive_thinking": true, "thinking_always_on": true, @@ -73718,7 +71015,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_adaptive_thinking": true, "thinking_always_on": true, @@ -73756,7 +71052,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_adaptive_thinking": true, "thinking_always_on": true, @@ -73789,7 +71084,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_adaptive_thinking": true, "thinking_always_on": true, @@ -73825,7 +71119,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_assistant_prefill": false, "supports_computer_use": true, @@ -73864,7 +71157,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_assistant_prefill": false, "supports_computer_use": true, @@ -73904,7 +71196,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_assistant_prefill": false, "supports_computer_use": true, @@ -73942,7 +71233,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_assistant_prefill": false, "supports_computer_use": true, @@ -73981,7 +71271,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "supports_assistant_prefill": false, "supports_computer_use": true, @@ -74014,7 +71303,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_adaptive_thinking": true, "supports_mid_conversation_system": true, @@ -74052,7 +71340,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "thinking_always_on": true, "supports_function_calling": true, @@ -74072,7 +71359,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "thinking_always_on": true, "supports_function_calling": true, @@ -74092,7 +71378,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "thinking_always_on": true, "supports_function_calling": true, @@ -74114,7 +71399,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 5.4e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-deepseek-deepseek-r1.html", @@ -74127,7 +71411,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -74140,7 +71423,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 256000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 3.5e-06, "source": "https://azure.microsoft.com/en-us/pricing/details/ai-foundry-models/microsoft/", @@ -74176,7 +71458,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "search_context_cost_per_query": { @@ -74214,7 +71495,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_adaptive_thinking": true, "supports_mid_conversation_system": true, @@ -74260,7 +71540,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "search_context_cost_per_query": { @@ -74302,7 +71581,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "search_context_cost_per_query": { @@ -74339,7 +71617,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "supports_forced_tool_use": false, @@ -74376,7 +71653,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "supports_forced_tool_use": false, @@ -74417,7 +71693,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "search_context_cost_per_query": { @@ -74464,7 +71739,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "search_context_cost_per_query": { @@ -74506,7 +71780,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "search_context_cost_per_query": { @@ -74638,7 +71911,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "supports_forced_tool_use": false, @@ -74684,7 +71956,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "search_context_cost_per_query": { @@ -74729,7 +72000,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -74769,7 +72039,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -74802,7 +72071,6 @@ "litellm_provider": "prism", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 6.3e-07, "source": "https://prisminference.com/pricing", @@ -74827,7 +72095,6 @@ "litellm_provider": "prism", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 2.1e-07, "source": "https://prisminference.com/pricing", @@ -74860,7 +72127,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 524288, "max_output_tokens": 524288, - "max_tokens": 524288, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_flex": 3e-06, @@ -74886,7 +72152,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 524288, "max_output_tokens": 524288, - "max_tokens": 524288, "mode": "chat", "output_cost_per_token": 6.6e-06, "output_cost_per_token_flex": 3.3e-06, @@ -74904,7 +72169,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://inference.baseten.co/v1/models", @@ -74917,6 +72181,16 @@ }, "gpt-6.1-sol": { "cache_creation_input_token_cost": 2.5e-06, + "cache_creation_input_token_cost_above_12hr": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 1e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": 2e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_ultrafast": 6e-05, + "cache_creation_input_token_cost_above_12hr_batches": 2.5e-06, + "cache_creation_input_token_cost_above_12hr_flex": 2.5e-06, + "cache_creation_input_token_cost_above_12hr_priority": 1e-05, + "cache_creation_input_token_cost_above_12hr_ultrafast": 3e-05, "cache_creation_input_token_cost_above_272k_tokens": 5e-06, "cache_creation_input_token_cost_above_272k_tokens_batches": 2.5e-06, "cache_creation_input_token_cost_above_272k_tokens_flex": 2.5e-06, @@ -74949,7 +72223,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -75017,7 +72290,6 @@ "supports_bedrock_converse_tool_result_images": false, "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -75063,7 +72335,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "responses", "output_cost_per_token": 1.1e-05, "output_cost_per_token_above_272k_tokens": 1.65e-05, @@ -75111,7 +72382,6 @@ "supports_bedrock_converse_tool_result_images": false, "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_above_272k_tokens": 1.65e-05, @@ -75146,7 +72416,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 8192, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "audio_speech", "output_cost_per_audio_token": 9e-06, "output_cost_per_token": 9e-06, @@ -75160,7 +72429,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 8192, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "audio_speech", "output_cost_per_audio_token": 6e-06, "output_cost_per_token": 6e-06, @@ -75177,7 +72445,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 524288, "max_output_tokens": 524288, - "max_tokens": 524288, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -75195,7 +72462,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://azure.microsoft.com/en-us/pricing/details/ai-foundry-models/kimi/", @@ -75228,7 +72494,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.28e-06, "output_cost_per_token_batches": 2.64e-06, @@ -75261,7 +72526,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.808e-06, "output_cost_per_token_batches": 2.904e-06, @@ -75282,10 +72546,12 @@ "input_cost_per_audio_token": 3e-06, "input_cost_per_token": 3.3e-07, "litellm_provider": "bedrock", + "max_input_tokens": 256000, + "max_output_tokens": 64000, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2.75e-06, - "source": "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonBedrockFoundationModels/current/index.json", + "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-amazon-nova-2-5-sonic.md", "supports_audio_input": true, "supports_audio_output": true }, @@ -75296,7 +72562,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://azure.microsoft.com/en-us/pricing/details/ai-foundry-models/model-router/", @@ -75316,7 +72581,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.0336, "output_cost_per_image_token": 3e-05, @@ -75361,7 +72625,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.0336, "output_cost_per_image_token": 3e-05, @@ -75407,7 +72670,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.0336, "output_cost_per_image_token": 3e-05, @@ -75451,7 +72713,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -75479,7 +72740,6 @@ "token_count_tokenizer": "kimi_k3", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.65e-05, "output_cost_per_token_flex": 8.25e-06, @@ -75512,7 +72772,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_batches": 2.5e-07, @@ -75566,7 +72825,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-07, "search_context_cost_per_query": { @@ -75613,7 +72871,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "supports_forced_tool_use": true, @@ -75658,7 +72915,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "search_context_cost_per_query": { @@ -75701,7 +72957,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_adaptive_thinking": true, "supports_mid_conversation_system": true, @@ -75752,7 +73007,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-07, "search_context_cost_per_query": { @@ -75799,7 +73053,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "search_context_cost_per_query": { @@ -75841,7 +73094,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "supports_forced_tool_use": true, @@ -75883,7 +73135,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "supports_forced_tool_use": true, @@ -75929,7 +73180,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-07, "search_context_cost_per_query": { @@ -75981,7 +73231,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "search_context_cost_per_query": { @@ -76028,7 +73277,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-07, "search_context_cost_per_query": { @@ -76087,7 +73335,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "supports_forced_tool_use": true, @@ -76138,7 +73385,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-07, "search_context_cost_per_query": { @@ -76188,7 +73434,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_batches": 2.5e-07, @@ -76233,7 +73478,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_batches": 2.5e-07, @@ -76272,7 +73516,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 261120, "max_output_tokens": 98304, - "max_tokens": 98304, "mode": "chat", "output_cost_per_token": 7.5e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-twelvelabs-pegasus-v1-5.html", @@ -76283,7 +73526,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 261120, "max_output_tokens": 98304, - "max_tokens": 98304, "mode": "chat", "output_cost_per_token": 7.5e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-twelvelabs-pegasus-v1-5.html", @@ -76294,7 +73536,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 261120, "max_output_tokens": 98304, - "max_tokens": 98304, "mode": "chat", "output_cost_per_token": 7.5e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-twelvelabs-pegasus-v1-5.html", @@ -76303,9 +73544,10 @@ "azure_ai/Microsoft-Decision-1": { "input_cost_per_token": 4.2e-08, "litellm_provider": "azure_ai", + "max_input_tokens": 32768, "mode": "evaluation", "output_cost_per_token": 0.0, - "source": "https://prices.azure.com/api/retail/prices?$filter=productName eq 'Microsoft Decision Models'" + "source": "https://learn.microsoft.com/en-us/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure" }, "gpt-rosalind-discovery": { "cache_read_input_token_cost": 5e-07, @@ -76329,7 +73571,6 @@ "input_cost_per_token": 8e-08, "litellm_provider": "azure_ai", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 2048.0, @@ -76349,7 +73590,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "azure_ai", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 2048.0, @@ -76418,7 +73658,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 5e-06, "output_cost_per_token": 5e-06, @@ -76464,7 +73703,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 5e-06, "output_cost_per_token": 5e-06, @@ -76514,7 +73752,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_reasoning_token": 1e-05, "output_cost_per_token": 1e-05, @@ -76573,7 +73810,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_reasoning_token": 1e-05, "output_cost_per_token": 1e-05, @@ -76631,7 +73867,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_reasoning_token": 2e-05, "output_cost_per_token": 2e-05, @@ -76679,7 +73914,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -76692,7 +73926,6 @@ "supports_vision": true }, "openinfer/@oi/GLM-5.3-Flash": { - "max_tokens": 393216, "max_input_tokens": 393216, "max_output_tokens": 393216, "input_cost_per_token": 1.95e-07, @@ -76704,7 +73937,6 @@ "source": "https://api.openinfer.ai/v1/models" }, "openinfer/@oi/Qwen3.5-27B": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1.95e-07, @@ -76716,7 +73948,6 @@ "source": "https://api.openinfer.ai/v1/models" }, "openinfer/@oi/Qwen3.5-9B": { - "max_tokens": 100000, "max_input_tokens": 100000, "max_output_tokens": 100000, "input_cost_per_token": 5e-06, @@ -76795,7 +74026,7 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://api.together.ai/v1/models", @@ -76818,7 +74049,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 3.311e-06, "output_cost_per_token_batches": 1.6555e-06, @@ -76840,7 +74070,6 @@ "litellm_provider": "vertex_ai-deepseek_models", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -76864,7 +74093,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4e-05, "prompt_cache_min_tokens": 512.0, @@ -76894,7 +74122,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_token": 4.25e-06, "source": "https://inference.baseten.co/v1/models", @@ -76912,7 +74139,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inference.baseten.co/v1/models", @@ -76928,7 +74154,7 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "wandb", "max_input_tokens": 1049000, - "max_tokens": 943718, + "max_output_tokens": 943718, "mode": "chat", "output_cost_per_token": 7.5e-07, "source": "https://openrouter.ai/api/v1/models/nvidia/nemotron-3.5-super-vl/endpoints", @@ -76944,7 +74170,7 @@ "input_cost_per_token": 4e-07, "litellm_provider": "together_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://api.together.ai/v1/models", @@ -76958,7 +74184,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://inference.baseten.co/v1/models", @@ -76972,7 +74197,7 @@ "input_cost_per_token": 2.5e-07, "litellm_provider": "nebius", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1e-06, "source": "https://tokenfactory.nebius.com/models/catalog/text2text/reflection%2Fbeam", @@ -76985,7 +74210,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://inference.baseten.co/v1/models", @@ -77002,7 +74226,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://inference.baseten.co/v1/models", @@ -77021,7 +74244,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_priority": 1.5e-06, @@ -77041,7 +74263,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -77063,7 +74284,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.25e-06, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -77085,7 +74305,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -77107,7 +74326,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -77129,7 +74347,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -77148,7 +74365,7 @@ "input_cost_per_token": 3e-07, "litellm_provider": "together_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://api.together.ai/v1/models", @@ -77185,7 +74402,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_priority": 9e-07, @@ -77221,7 +74437,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 1.8e-06, "output_cost_per_token_priority": 2.25e-06, @@ -77270,7 +74485,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 256000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -77290,5 +74504,1547 @@ "supports_reasoning": true, "supports_tool_choice": true, "supports_vision": true + }, + "opencode_go/grok-4.7": { + "litellm_provider": "opencode_go", + "mode": "responses", + "supported_endpoints": [ + "/v1/responses" + ], + "input_cost_per_token": 2e-06, + "output_cost_per_token": 6e-06, + "cache_read_input_token_cost": 5e-07, + "max_output_tokens": 500000, + "max_input_tokens": 500000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "tiered_pricing": [ + { + "range": [ + 0, + 200000 + ], + "input_cost_per_token": 2e-06, + "output_cost_per_token": 6e-06, + "cache_read_input_token_cost": 5e-07 + }, + { + "range": [ + 200000, + 500000 + ], + "input_cost_per_token": 4e-06, + "output_cost_per_token": 1.2e-05, + "cache_read_input_token_cost": 1e-06 + } + ], + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/gpt-6-luna": { + "litellm_provider": "opencode_go", + "mode": "responses", + "supported_endpoints": [ + "/v1/responses" + ], + "input_cost_per_token": 1.0000000000000001e-07, + "output_cost_per_token": 5e-07, + "cache_read_input_token_cost": 1e-08, + "cache_creation_input_token_cost": 1.25e-07, + "max_output_tokens": 128000, + "max_input_tokens": 922000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "tiered_pricing": [ + { + "range": [ + 0, + 272000 + ], + "input_cost_per_token": 1.0000000000000001e-07, + "output_cost_per_token": 5e-07, + "cache_read_input_token_cost": 1e-08, + "cache_creation_input_token_cost": 1.25e-07 + }, + { + "range": [ + 272000, + 1050000 + ], + "input_cost_per_token": 2.0000000000000002e-07, + "output_cost_per_token": 7.5e-07, + "cache_read_input_token_cost": 2e-08, + "cache_creation_input_token_cost": 2.5e-07 + } + ], + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/gpt-5.6-luna": { + "litellm_provider": "opencode_go", + "mode": "responses", + "supported_endpoints": [ + "/v1/responses" + ], + "input_cost_per_token": 2.0000000000000002e-07, + "output_cost_per_token": 1.2e-06, + "cache_read_input_token_cost": 2e-08, + "cache_creation_input_token_cost": 2.5e-07, + "max_output_tokens": 128000, + "max_input_tokens": 922000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "tiered_pricing": [ + { + "range": [ + 0, + 272000 + ], + "input_cost_per_token": 2.0000000000000002e-07, + "output_cost_per_token": 1.2e-06, + "cache_read_input_token_cost": 2e-08, + "cache_creation_input_token_cost": 2.5e-07 + }, + { + "range": [ + 272000, + 1050000 + ], + "input_cost_per_token": 4.0000000000000003e-07, + "output_cost_per_token": 1.8000000000000001e-06, + "cache_read_input_token_cost": 4e-08, + "cache_creation_input_token_cost": 5e-07 + } + ], + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/claude-haiku-5-5": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/messages" + ], + "input_cost_per_token": 1.0000000000000001e-07, + "output_cost_per_token": 5e-07, + "cache_read_input_token_cost": 1e-08, + "cache_creation_input_token_cost": 1.25e-07, + "max_output_tokens": 128000, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "tiered_pricing": [ + { + "range": [ + 0, + 100000 + ], + "input_cost_per_token": 1.0000000000000001e-07, + "output_cost_per_token": 5e-07, + "cache_read_input_token_cost": 1e-08, + "cache_creation_input_token_cost": 1.25e-07 + }, + { + "range": [ + 100000, + 1000000 + ], + "input_cost_per_token": 5e-07, + "output_cost_per_token": 2.5e-06, + "cache_read_input_token_cost": 5.0000000000000004e-08, + "cache_creation_input_token_cost": 6.25e-07 + } + ], + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/gemini-4-argon": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1beta/models" + ], + "input_cost_per_token": 2e-06, + "output_cost_per_token": 1e-05, + "cache_read_input_token_cost": 1e-07, + "max_output_tokens": 65536, + "max_input_tokens": 1048576, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/glm-5.3-flash": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 1.5e-07, + "output_cost_per_token": 5e-07, + "cache_read_input_token_cost": 3e-08, + "max_output_tokens": 131072, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/glm-5.3": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 1.4e-06, + "output_cost_per_token": 4.4e-06, + "cache_read_input_token_cost": 2.6e-07, + "max_output_tokens": 131072, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": false, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/glm-5.2": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 1.4e-06, + "output_cost_per_token": 4.4e-06, + "cache_read_input_token_cost": 2.6e-07, + "max_output_tokens": 131072, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": false, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/kimi-k3.1-pro": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 2e-06, + "output_cost_per_token": 1e-05, + "cache_read_input_token_cost": 2.0000000000000002e-07, + "cache_creation_input_token_cost": 2e-06, + "max_output_tokens": 131072, + "max_input_tokens": 1048576, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/kimi-k3": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 3e-06, + "output_cost_per_token": 1.5e-05, + "cache_read_input_token_cost": 3e-07, + "cache_creation_input_token_cost": 3e-06, + "max_output_tokens": 131072, + "max_input_tokens": 1048576, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/kimi-k2.7-code": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 9.499999999999999e-07, + "output_cost_per_token": 4e-06, + "cache_read_input_token_cost": 1.9e-07, + "max_output_tokens": 262144, + "max_input_tokens": 262144, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/longcat-2.0": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 3e-07, + "output_cost_per_token": 1.2e-06, + "cache_read_input_token_cost": 6e-09, + "max_output_tokens": 131072, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": false, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/deepseek-v4.1-flash": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 3e-07, + "output_cost_per_token": 1.2e-06, + "cache_read_input_token_cost": 6e-09, + "max_output_tokens": 384000, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/deepseek-v4-pro": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 1.32e-06, + "output_cost_per_token": 3.96e-06, + "cache_read_input_token_cost": 4.4e-08, + "max_output_tokens": 384000, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": false, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/mimo-v2.6-flash": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 1.4e-07, + "output_cost_per_token": 2.8e-07, + "cache_read_input_token_cost": 2.8e-09, + "max_output_tokens": 131072, + "max_input_tokens": 1048576, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/mimo-v2.6-pro": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 4.35e-07, + "output_cost_per_token": 8.7e-07, + "cache_read_input_token_cost": 3.625e-09, + "max_output_tokens": 131072, + "max_input_tokens": 1048576, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/mimo-v2.5": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 1.4e-07, + "output_cost_per_token": 2.8e-07, + "cache_read_input_token_cost": 2.8e-09, + "max_output_tokens": 128000, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/mimo-v2.5-pro": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 4.35e-07, + "output_cost_per_token": 8.7e-07, + "cache_read_input_token_cost": 3.625e-09, + "max_output_tokens": 128000, + "max_input_tokens": 1048576, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": false, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/minimax-m3.1-flash": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 1.5e-07, + "output_cost_per_token": 6e-07, + "cache_read_input_token_cost": 1.5e-08, + "max_output_tokens": 512000, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/minimax-m3": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/messages" + ], + "input_cost_per_token": 3e-07, + "output_cost_per_token": 1.2e-06, + "cache_read_input_token_cost": 6e-08, + "max_output_tokens": 131072, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/muse-spark-1.3-contributor": { + "litellm_provider": "opencode_go", + "mode": "responses", + "supported_endpoints": [ + "/v1/responses" + ], + "input_cost_per_token": 1.0000000000000001e-07, + "output_cost_per_token": 2.0000000000000002e-07, + "cache_read_input_token_cost": 2e-09, + "max_output_tokens": 131072, + "max_input_tokens": 1048576, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/muse-spark-1.2-contributor": { + "litellm_provider": "opencode_go", + "mode": "responses", + "supported_endpoints": [ + "/v1/responses" + ], + "input_cost_per_token": 1.0000000000000001e-07, + "output_cost_per_token": 2.0000000000000002e-07, + "cache_read_input_token_cost": 2e-09, + "max_output_tokens": 131072, + "max_input_tokens": 1048576, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/qwen3.8-max": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/messages" + ], + "input_cost_per_token": 2e-06, + "output_cost_per_token": 6e-06, + "cache_read_input_token_cost": 2.5e-07, + "cache_creation_input_token_cost": 2.5e-06, + "max_output_tokens": 131072, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/qwen3.8-flash": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/messages" + ], + "input_cost_per_token": 1.5e-07, + "output_cost_per_token": 4.6999999999999995e-07, + "cache_read_input_token_cost": 1.6e-08, + "cache_creation_input_token_cost": 2.0000000000000002e-07, + "max_output_tokens": 131072, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/qwen3.7-plus": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/messages" + ], + "input_cost_per_token": 4.0000000000000003e-07, + "output_cost_per_token": 1.6000000000000001e-06, + "cache_read_input_token_cost": 4e-08, + "cache_creation_input_token_cost": 5e-07, + "max_output_tokens": 65536, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "tiered_pricing": [ + { + "range": [ + 0, + 256000 + ], + "input_cost_per_token": 4.0000000000000003e-07, + "output_cost_per_token": 1.6000000000000001e-06, + "cache_read_input_token_cost": 4e-08, + "cache_creation_input_token_cost": 5e-07 + }, + { + "range": [ + 256000, + 1000000 + ], + "input_cost_per_token": 1.2e-06, + "output_cost_per_token": 4.8e-06, + "cache_read_input_token_cost": 1.2e-07, + "cache_creation_input_token_cost": 1.5e-06 + } + ], + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/hy4-preview": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 8.34e-07, + "output_cost_per_token": 2.501e-06, + "cache_read_input_token_cost": 4.2000000000000006e-08, + "max_output_tokens": 64000, + "max_input_tokens": 1024000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": false, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/hy3": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 1.4e-07, + "output_cost_per_token": 5.8e-07, + "cache_read_input_token_cost": 3.5e-08, + "max_output_tokens": 128000, + "max_input_tokens": 192000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": false, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/longcat-2.5-preview-free": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 0, + "output_cost_per_token": 0, + "cache_read_input_token_cost": 0, + "max_output_tokens": 131072, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/step-5-preview": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 1e-06, + "output_cost_per_token": 2.7e-06, + "cache_read_input_token_cost": 1.0000000000000001e-07, + "max_output_tokens": 65536, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/beam-free": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 0, + "output_cost_per_token": 0, + "cache_read_input_token_cost": 0, + "max_output_tokens": 131072, + "max_input_tokens": 1048576, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": false, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "bedrock/claude_platform/claude-fable-5": { + "supports_web_search": true, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 1.25e-05, + "cache_creation_input_token_cost_above_1hr": 2e-05, + "cache_creation_input_token_cost_batches": 6.25e-06, + "cache_read_input_token_cost": 1e-06, + "cache_read_input_token_cost_batches": 5e-07, + "input_cost_per_token": 1e-05, + "input_cost_per_token_batches": 5e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 5e-05, + "output_cost_per_token_batches": 2.5e-05, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "thinking_always_on": true, + "supports_mid_conversation_system": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "supports_max_reasoning_effort": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "prompt_cache_min_tokens": 512, + "supports_native_structured_output": true, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-fable-5-1": { + "supports_web_search": true, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 1.25e-05, + "cache_creation_input_token_cost_above_1hr": 2e-05, + "cache_creation_input_token_cost_batches": 6.25e-06, + "cache_read_input_token_cost": 2.5e-07, + "cache_read_input_token_cost_batches": 1.25e-07, + "input_cost_per_token": 1e-05, + "input_cost_per_token_batches": 5e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 5e-05, + "output_cost_per_token_batches": 2.5e-05, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "thinking_always_on": true, + "supports_mid_conversation_system": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_forced_tool_use": false, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "supports_max_reasoning_effort": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "prompt_cache_min_tokens": 512, + "supports_native_structured_output": true, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-haiku-4-5": { + "cache_creation_input_token_cost": 1.25e-06, + "cache_creation_input_token_cost_above_1hr": 2e-06, + "cache_creation_input_token_cost_batches": 6.25e-07, + "cache_read_input_token_cost": 1e-07, + "cache_read_input_token_cost_batches": 5e-08, + "input_cost_per_token": 1e-06, + "input_cost_per_token_batches": 5e-07, + "litellm_provider": "bedrock", + "max_input_tokens": 200000, + "max_output_tokens": 64000, + "mode": "chat", + "output_cost_per_token": 5e-06, + "output_cost_per_token_batches": 2.5e-06, + "supports_assistant_prefill": true, + "supports_function_calling": true, + "supports_native_structured_output": true, + "supports_computer_use": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": true, + "prompt_cache_min_tokens": 4096, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-haiku-5-5": { + "input_cost_per_token_above_100k_tokens_batches": 2.5e-07, + "output_cost_per_token_above_100k_tokens_batches": 1.25e-06, + "cache_creation_input_token_cost_above_100k_tokens_batches": 3.125e-07, + "cache_read_input_token_cost_above_100k_tokens_batches": 2.5e-08, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 1.25e-07, + "cache_creation_input_token_cost_above_1hr": 2e-07, + "cache_creation_input_token_cost_batches": 6.25e-08, + "cache_read_input_token_cost": 1e-08, + "cache_read_input_token_cost_batches": 5e-09, + "input_cost_per_token": 1e-07, + "input_cost_per_token_batches": 5e-08, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 5e-07, + "output_cost_per_token_batches": 2.5e-07, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "supports_mid_conversation_system": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_native_structured_output": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "supports_max_reasoning_effort": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "supports_forced_tool_use": true, + "thinking_always_on": false, + "prompt_cache_min_tokens": 512, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing", + "supports_web_search": true, + "input_cost_per_token_above_100k_tokens": 5e-07, + "output_cost_per_token_above_100k_tokens": 2.5e-06, + "cache_creation_input_token_cost_above_100k_tokens": 6.25e-07, + "cache_creation_input_token_cost_above_1hr_above_100k_tokens": 1e-06, + "cache_read_input_token_cost_above_100k_tokens": 5e-08 + }, + "bedrock/claude_platform/claude-opus-4-5": { + "cache_creation_input_token_cost": 6.25e-06, + "cache_creation_input_token_cost_above_1hr": 1e-05, + "cache_creation_input_token_cost_batches": 3.125e-06, + "cache_read_input_token_cost": 5e-07, + "cache_read_input_token_cost_batches": 2.5e-07, + "input_cost_per_token": 5e-06, + "input_cost_per_token_batches": 2.5e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 200000, + "max_output_tokens": 64000, + "mode": "chat", + "output_cost_per_token": 2.5e-05, + "output_cost_per_token_batches": 1.25e-05, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_assistant_prefill": true, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_thinking_cache_preservation": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_native_structured_output": true, + "supports_tool_choice": true, + "supports_vision": true, + "supports_output_config": true, + "prompt_cache_min_tokens": 4096, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-opus-4-6": { + "supports_web_search": true, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 6.25e-06, + "cache_creation_input_token_cost_above_1hr": 1e-05, + "cache_creation_input_token_cost_batches": 3.125e-06, + "cache_read_input_token_cost": 5e-07, + "cache_read_input_token_cost_batches": 2.5e-07, + "input_cost_per_token": 5e-06, + "input_cost_per_token_batches": 2.5e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 2.5e-05, + "output_cost_per_token_batches": 1.25e-05, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "supports_legacy_thinking": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_thinking_cache_preservation": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_native_structured_output": true, + "supports_tool_choice": true, + "supports_vision": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "supports_max_reasoning_effort": true, + "prompt_cache_min_tokens": 4096, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-opus-4-7": { + "supports_web_search": true, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 6.25e-06, + "cache_creation_input_token_cost_above_1hr": 1e-05, + "cache_creation_input_token_cost_batches": 3.125e-06, + "cache_read_input_token_cost": 5e-07, + "cache_read_input_token_cost_batches": 2.5e-07, + "input_cost_per_token": 5e-06, + "input_cost_per_token_batches": 2.5e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 2.5e-05, + "output_cost_per_token_batches": 1.25e-05, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_thinking_cache_preservation": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_native_structured_output": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "supports_max_reasoning_effort": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "prompt_cache_min_tokens": 2048, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-opus-4-8": { + "supports_web_search": true, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 6.25e-06, + "cache_creation_input_token_cost_above_1hr": 1e-05, + "cache_creation_input_token_cost_batches": 3.125e-06, + "cache_read_input_token_cost": 5e-07, + "cache_read_input_token_cost_batches": 2.5e-07, + "input_cost_per_token": 5e-06, + "input_cost_per_token_batches": 2.5e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 2.5e-05, + "output_cost_per_token_batches": 1.25e-05, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "supports_mid_conversation_system": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_thinking_cache_preservation": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_native_structured_output": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "supports_max_reasoning_effort": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "prompt_cache_min_tokens": 1024, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-opus-5": { + "supports_web_search": true, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 6.25e-06, + "cache_creation_input_token_cost_above_1hr": 1e-05, + "cache_creation_input_token_cost_batches": 3.125e-06, + "cache_read_input_token_cost": 5e-07, + "cache_read_input_token_cost_batches": 2.5e-07, + "input_cost_per_token": 5e-06, + "input_cost_per_token_batches": 2.5e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 2.5e-05, + "output_cost_per_token_batches": 1.25e-05, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "supports_mid_conversation_system": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_thinking_cache_preservation": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_native_structured_output": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "supports_max_reasoning_effort": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "prompt_cache_min_tokens": 512, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-opus-5-5": { + "supports_web_search": true, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 5e-06, + "cache_creation_input_token_cost_above_1hr": 8e-06, + "cache_creation_input_token_cost_batches": 2.5e-06, + "cache_read_input_token_cost": 2e-07, + "cache_read_input_token_cost_batches": 1e-07, + "input_cost_per_token": 4e-06, + "input_cost_per_token_batches": 2e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 2e-05, + "output_cost_per_token_batches": 1e-05, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "thinking_always_on": true, + "supports_mid_conversation_system": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_forced_tool_use": false, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_native_structured_output": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "supports_max_reasoning_effort": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "prompt_cache_min_tokens": 512, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-sonnet-4-5": { + "cache_creation_input_token_cost": 3.75e-06, + "cache_creation_input_token_cost_above_1hr": 6e-06, + "cache_read_input_token_cost": 3e-07, + "input_cost_per_token": 3e-06, + "cache_creation_input_token_cost_batches": 1.875e-06, + "cache_read_input_token_cost_batches": 1.5e-07, + "deprecation_date": "2026-11-30", + "input_cost_per_token_batches": 1.5e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 200000, + "max_output_tokens": 64000, + "mode": "chat", + "output_cost_per_token": 1.5e-05, + "output_cost_per_token_batches": 7.5e-06, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_assistant_prefill": true, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_native_structured_output": true, + "supports_tool_choice": true, + "supports_vision": true, + "prompt_cache_min_tokens": 1024, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-sonnet-4-6": { + "supports_web_search": true, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 3.75e-06, + "cache_creation_input_token_cost_above_1hr": 6e-06, + "cache_creation_input_token_cost_batches": 1.875e-06, + "cache_read_input_token_cost": 3e-07, + "cache_read_input_token_cost_batches": 1.5e-07, + "input_cost_per_token": 3e-06, + "input_cost_per_token_batches": 1.5e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 1.5e-05, + "output_cost_per_token_batches": 7.5e-06, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "supports_legacy_thinking": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_thinking_cache_preservation": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_native_structured_output": true, + "supports_max_reasoning_effort": true, + "supports_tool_choice": true, + "supports_vision": true, + "supports_output_config": true, + "prompt_cache_min_tokens": 1024, + "provider_specific_entry": { + "us": 1.1 + }, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-sonnet-5": { + "supports_web_search": true, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 2.5e-06, + "cache_creation_input_token_cost_above_1hr": 4e-06, + "cache_creation_input_token_cost_batches": 1.25e-06, + "cache_read_input_token_cost": 2e-07, + "cache_read_input_token_cost_batches": 1e-07, + "input_cost_per_token": 2e-06, + "input_cost_per_token_batches": 1e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 1e-05, + "output_cost_per_token_batches": 5e-06, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "supports_mid_conversation_system": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_native_structured_output": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_thinking_cache_preservation": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "supports_max_reasoning_effort": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "prompt_cache_min_tokens": 1024, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-sonnet-5-5": { + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 2.5e-06, + "cache_creation_input_token_cost_above_1hr": 4e-06, + "cache_creation_input_token_cost_batches": 1.25e-06, + "cache_read_input_token_cost": 1e-07, + "cache_read_input_token_cost_batches": 5e-08, + "input_cost_per_token": 2e-06, + "input_cost_per_token_batches": 1e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 1e-05, + "output_cost_per_token_batches": 5e-06, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "supports_mid_conversation_system": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_native_structured_output": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "supports_max_reasoning_effort": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "supports_forced_tool_use": false, + "thinking_always_on": true, + "prompt_cache_min_tokens": 512, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing", + "supports_web_search": true + }, + "gpt-6.1-terra": { + "cache_creation_input_token_cost": 1.25e-06, + "cache_creation_input_token_cost_above_12hr": 2.5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches": 2.5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": 2.5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": 1e-05, + "cache_creation_input_token_cost_above_12hr_batches": 1.25e-06, + "cache_creation_input_token_cost_above_12hr_flex": 1.25e-06, + "cache_creation_input_token_cost_above_12hr_priority": 5e-06, + "cache_creation_input_token_cost_above_272k_tokens": 2.5e-06, + "cache_creation_input_token_cost_above_272k_tokens_batches": 1.25e-06, + "cache_creation_input_token_cost_above_272k_tokens_flex": 1.25e-06, + "cache_creation_input_token_cost_above_272k_tokens_priority": 5e-06, + "cache_creation_input_token_cost_batches": 6.25e-07, + "cache_creation_input_token_cost_flex": 6.25e-07, + "cache_creation_input_token_cost_priority": 2.5e-06, + "cache_read_input_token_cost": 5e-08, + "cache_read_input_token_cost_above_272k_tokens": 1e-07, + "cache_read_input_token_cost_above_272k_tokens_batches": 5e-08, + "cache_read_input_token_cost_above_272k_tokens_flex": 5e-08, + "cache_read_input_token_cost_above_272k_tokens_priority": 2e-07, + "cache_read_input_token_cost_batches": 2.5e-08, + "cache_read_input_token_cost_flex": 2.5e-08, + "cache_read_input_token_cost_priority": 1e-07, + "input_cost_per_token": 1e-06, + "input_cost_per_token_above_272k_tokens": 2e-06, + "input_cost_per_token_above_272k_tokens_batches": 1e-06, + "input_cost_per_token_above_272k_tokens_flex": 1e-06, + "input_cost_per_token_above_272k_tokens_priority": 4e-06, + "input_cost_per_token_batches": 5e-07, + "input_cost_per_token_flex": 5e-07, + "input_cost_per_token_priority": 2e-06, + "litellm_provider": "openai", + "max_input_tokens": 922000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 5e-06, + "output_cost_per_token_above_272k_tokens": 7.5e-06, + "output_cost_per_token_above_272k_tokens_batches": 3.75e-06, + "output_cost_per_token_above_272k_tokens_flex": 3.75e-06, + "output_cost_per_token_above_272k_tokens_priority": 1.5e-05, + "output_cost_per_token_batches": 2.5e-06, + "output_cost_per_token_flex": 2.5e-06, + "output_cost_per_token_priority": 1e-05, + "regional_processing_uplift_multiplier_eu": 1.1, + "regional_processing_uplift_multiplier_us": 1.1, + "search_context_cost_per_query": {"search_context_size_high":0.01,"search_context_size_low":0.01,"search_context_size_medium":0.01}, + "source": "https://developers.openai.com/api/docs/pricing", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/batch", + "/v1/responses" + ], + "supported_modalities": [ + "text", + "image" + ], + "supported_output_modalities": [ + "text" + ], + "supports_computer_use": true, + "supports_function_calling": true, + "supports_max_reasoning_effort": true, + "supports_minimal_reasoning_effort": false, + "supports_native_streaming": true, + "supports_none_reasoning_effort": true, + "supports_parallel_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_cache_breakpoint": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_tool_search": true, + "supports_vision": true, + "supports_web_search": true, + "supports_xhigh_reasoning_effort": true + }, + "chatgpt/gpt-6.1-terra": { + "litellm_provider": "chatgpt", + "max_input_tokens": 922000, + "max_output_tokens": 128000, + "mode": "responses", + "source": "https://developers.openai.com/api/docs/pricing", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/responses" + ], + "supports_function_calling": true, + "supports_max_reasoning_effort": true, + "supports_minimal_reasoning_effort": false, + "supports_none_reasoning_effort": true, + "supports_parallel_function_calling": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true + }, + "global.openai.gpt-6.1-terra": { + "cache_creation_input_token_cost": 1.25e-06, + "cache_creation_input_token_cost_above_272k_tokens": 2.5e-06, + "cache_read_input_token_cost": 5e-08, + "cache_read_input_token_cost_above_272k_tokens": 1e-07, + "input_cost_per_token": 1e-06, + "input_cost_per_token_above_272k_tokens": 2e-06, + "litellm_provider": "bedrock_converse", + "max_input_tokens": 922000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 5e-06, + "output_cost_per_token_above_272k_tokens": 7.5e-06, + "source": "https://developers.openai.com/api/docs/models/gpt-6.1-terra", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/responses" + ], + "supported_modalities": [ + "text", + "image" + ], + "supported_output_modalities": [ + "text" + ], + "supports_bedrock_converse_tool_result_images": false, + "supports_bedrock_runtime_chat_completions_response_format": true, + "supports_function_calling": true, + "supports_max_reasoning_effort": true, + "supports_minimal_reasoning_effort": false, + "supports_none_reasoning_effort": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true + }, + "us.openai.gpt-6.1-terra": { + "cache_creation_input_token_cost": 1.375e-06, + "cache_creation_input_token_cost_above_272k_tokens": 2.75e-06, + "cache_read_input_token_cost": 5.5e-08, + "cache_read_input_token_cost_above_272k_tokens": 1.1e-07, + "input_cost_per_token": 1.1e-06, + "input_cost_per_token_above_272k_tokens": 2.2e-06, + "litellm_provider": "bedrock_converse", + "max_input_tokens": 922000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 5.5e-06, + "output_cost_per_token_above_272k_tokens": 8.25e-06, + "source": "https://developers.openai.com/api/docs/models/gpt-6.1-terra", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/responses" + ], + "supported_modalities": [ + "text", + "image" + ], + "supported_output_modalities": [ + "text" + ], + "supports_bedrock_converse_tool_result_images": false, + "supports_bedrock_runtime_chat_completions_response_format": true, + "supports_function_calling": true, + "supports_max_reasoning_effort": true, + "supports_minimal_reasoning_effort": false, + "supports_none_reasoning_effort": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true + }, + "baseten/decision-models/baseten-elephant-9b-latest": { + "input_cost_per_token": 0.0, + "litellm_provider": "baseten", + "max_input_tokens": 16384, + "mode": "decisions", + "output_cost_per_token": 0.0, + "source": "https://inference.baseten.co/v1/models", + "supports_vision": true + }, + "baseten/decision-models/baseten-mammoth-27b-latest": { + "input_cost_per_token": 0.0, + "litellm_provider": "baseten", + "max_input_tokens": 16384, + "mode": "decisions", + "output_cost_per_token": 0.0, + "source": "https://inference.baseten.co/v1/models", + "supports_vision": true + }, + "github_copilot/gpt-6.1-terra": { + "cache_creation_input_token_cost": 1.25e-06, + "cache_creation_input_token_cost_above_272k_tokens": 2.5e-06, + "cache_read_input_token_cost": 5e-08, + "cache_read_input_token_cost_above_272k_tokens": 1e-07, + "input_cost_per_token": 1e-06, + "input_cost_per_token_above_272k_tokens": 2e-06, + "litellm_provider": "github_copilot", + "max_input_tokens": 922000, + "max_output_tokens": 128000, + "mode": "responses", + "output_cost_per_token": 5e-06, + "output_cost_per_token_above_272k_tokens": 7.5e-06, + "source": "https://github.blog/changelog/2026-10-26-gpt-6-1-terra-in-github-copilot", + "supported_endpoints": [ + "/v1/responses" + ], + "supports_function_calling": true, + "supports_parallel_function_calling": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_vision": true + }, + "refuseless/glm-5.3-abliterated": { + "cache_read_input_token_cost": 2.5e-07, + "input_cost_per_token": 1.25e-06, + "litellm_provider": "refuseless", + "max_input_tokens": 1048576, + "max_output_tokens": 131072, + "mode": "chat", + "output_cost_per_token": 2.25e-06, + "source": "https://refuseless.com/pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ] + }, + "refuseless/glm-5.3-flash-abliterated": { + "cache_read_input_token_cost": 1.5e-07, + "input_cost_per_token": 2.5e-07, + "litellm_provider": "refuseless", + "max_input_tokens": 1048576, + "max_output_tokens": 131072, + "mode": "chat", + "output_cost_per_token": 8e-07, + "source": "https://refuseless.com/pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ] + }, + "refuseless/deepseek-v4.1-flash-abliterated": { + "cache_read_input_token_cost": 4.5e-08, + "input_cost_per_token": 2.2e-07, + "litellm_provider": "refuseless", + "max_input_tokens": 1048576, + "max_output_tokens": 130000, + "mode": "chat", + "output_cost_per_token": 7.5e-07, + "source": "https://refuseless.com/pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ] + }, + "refuseless/deepseek-v4.1-flash-fast": { + "cache_read_input_token_cost": 3e-09, + "input_cost_per_token": 5e-08, + "litellm_provider": "refuseless", + "max_input_tokens": 1048576, + "max_output_tokens": 262144, + "mode": "chat", + "output_cost_per_token": 1.5e-07, + "source": "https://refuseless.com/pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ] + }, + "refuseless/minimax-m3.1-flash": { + "cache_read_input_token_cost": 2e-09, + "input_cost_per_token": 5e-08, + "litellm_provider": "refuseless", + "max_input_tokens": 1048576, + "max_output_tokens": 512000, + "mode": "chat", + "output_cost_per_token": 2.5e-07, + "source": "https://refuseless.com/pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ] + }, + "bedrock_mantle/openai.gpt-6.1-terra": { + "cache_creation_input_token_cost": 1.375e-06, + "cache_creation_input_token_cost_above_272k_tokens": 2.75e-06, + "cache_read_input_token_cost": 5.5e-08, + "cache_read_input_token_cost_above_272k_tokens": 1.1e-07, + "input_cost_per_token": 1.1e-06, + "input_cost_per_token_above_272k_tokens": 2.2e-06, + "litellm_provider": "bedrock_mantle", + "max_input_tokens": 922000, + "max_output_tokens": 128000, + "mode": "responses", + "output_cost_per_token": 5.5e-06, + "output_cost_per_token_above_272k_tokens": 8.25e-06, + "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-6-1-terra.html", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/responses" + ], + "supported_modalities": [ + "text", + "image" + ], + "supported_output_modalities": [ + "text" + ], + "supports_function_calling": true, + "supports_max_reasoning_effort": true, + "supports_minimal_reasoning_effort": false, + "supports_none_reasoning_effort": true, + "supports_prompt_cache_breakpoint": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "use_openai_responses_path": true } } diff --git a/litellm/models/organization_membership.py b/litellm/models/organization_membership.py index 6a0d22cb63b..f3abbc2e93d 100644 --- a/litellm/models/organization_membership.py +++ b/litellm/models/organization_membership.py @@ -6,6 +6,7 @@ Canonical definition for ``litellm_organizationmembership``. Re-exported from """ from datetime import datetime +from typing import Final from pydantic import ConfigDict, model_validator @@ -31,9 +32,10 @@ class LiteLLM_OrganizationMembershipTable(LiteLLMPydanticObjectBase): @model_validator(mode="after") def populate_user_email(self) -> "LiteLLM_OrganizationMembershipTable": - if self.user_email is None and self.user is not None: - if isinstance(self.user, dict): - self.user_email = self.user.get("user_email") + user: Final[object] = self.user + if self.user_email is None and user is not None: + if isinstance(user, dict): + self.user_email = user.get("user_email") else: - self.user_email = getattr(self.user, "user_email", None) + self.user_email = getattr(user, "user_email", None) return self diff --git a/litellm/provider_endpoints_support_backup.json b/litellm/provider_endpoints_support_backup.json index f95b553c2b4..9ba6ed342ea 100644 --- a/litellm/provider_endpoints_support_backup.json +++ b/litellm/provider_endpoints_support_backup.json @@ -6,6 +6,7 @@ "url": "Link to provider documentation", "endpoints": { "chat_completions": "Supports /chat/completions endpoint", + "systemone": "Supports native System One typed decisions", "messages": "Supports /messages endpoint (Anthropic format)", "responses": "Supports /responses endpoint (OpenAI/Anthropic unified)", "embeddings": "Supports /embeddings endpoint", @@ -19,9 +20,9 @@ "search": "Supports /search endpoint", "skills": "Supports /skills endpoint", "interactions": "Supports /interactions endpoint (Google AI Interactions API)", - "a2a": "Supports /a2a/{agent}/message/send endpoint (A2A Protocol)", + "a2a_(Agent Gateway)": "Supports /a2a/{agent}/message/send endpoint (A2A Protocol)", "container": "Supports OpenAI's /containers endpoint", - "container_files": "Supports OpenAI's /containers/{id}/files endpoint", + "container_file": "Supports OpenAI's /containers/{id}/files endpoint", "compact": "Supports /responses/compact endpoint", "files": "Supports /files endpoint for file operations", "image_edits": "Supports /images/edits endpoint for image editing", @@ -32,21 +33,56 @@ } }, "providers": { + "refuseless": { + "display_name": "Refuseless (`refuseless`)", + "url": "https://docs.litellm.ai/docs/providers/refuseless", + "endpoints": { + "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true + } + }, "a2a": { "display_name": "A2A (Agent-to-Agent) (`a2a`)", "url": "https://docs.litellm.ai/docs/providers/a2a", "endpoints": { - "chat_completions": true, - "messages": false, + "chat_completions": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "abliteration": { @@ -54,34 +90,51 @@ "url": "https://docs.litellm.ai/docs/providers/abliteration", "endpoints": { "chat_completions": true, - "messages": false, - "responses": false, + "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "aiml": { "display_name": "AI/ML API (`aiml`)", "url": "https://docs.litellm.ai/docs/providers/aiml", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": true, + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, "image_generations": true, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "ai21": { @@ -89,35 +142,51 @@ "url": "https://docs.litellm.ai/docs/providers/ai21", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "ai21_chat": { "display_name": "AI21 Chat (`ai21_chat`)", "url": "https://docs.litellm.ai/docs/providers/ai21", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "amazon_nova": { @@ -125,17 +194,25 @@ "url": "https://docs.litellm.ai/docs/providers/amazon_nova", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "anthropic": { @@ -143,18 +220,26 @@ "url": "https://docs.litellm.ai/docs/providers/anthropic", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": true, "rerank": false, - "skills": true, - "a2a": true, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true, + "skills": true, "count_tokens": true } }, @@ -162,71 +247,130 @@ "display_name": "Anthropic Text (`anthropic_text`)", "url": "https://docs.litellm.ai/docs/providers/anthropic", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": true, "rerank": false, - "skills": true, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, + "skills": true } }, "apertis": { "display_name": "Apertis (`apertis`)", "endpoints": { - "chat_completions": true, - "messages": false, + "chat_completions": false, "responses": false, - "embeddings": true, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "aihubmix": { + "display_name": "AIHubMix (`aihubmix`)", + "url": "https://docs.litellm.ai/docs/providers/aihubmix", + "endpoints": { + "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "assemblyai": { "display_name": "AssemblyAI (`assemblyai`)", "url": "https://docs.litellm.ai/docs/pass_through/assembly_ai", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": true, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "auto_router": { "display_name": "Auto Router (`auto_router`)", "url": "https://docs.litellm.ai/docs/proxy/auto_routing", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "bedrock": { @@ -234,17 +378,25 @@ "url": "https://docs.litellm.ai/docs/providers/bedrock", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": true, - "image_generations": false, + "image_generations": true, + "image_edits": true, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": true, - "a2a": true, + "ocr": false, + "search": false, + "moderations": false, + "realtime": true, + "video_generations": false, + "batches": false, + "messages": true, "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true, "bedrock_invoke": true, "bedrock_converse": true, "vector_stores_search": true, @@ -258,17 +410,25 @@ "url": "https://docs.litellm.ai/docs/providers/s3_vectors", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, "vector_stores_create": true, "vector_stores_search": true } @@ -278,17 +438,25 @@ "url": "https://docs.litellm.ai/docs/providers/aws_sagemaker", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": true, + "text_completion": true, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "aws_polly": { @@ -296,15 +464,25 @@ "url": "https://docs.litellm.ai/docs/providers/aws_polly", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": true, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "azure": { @@ -312,21 +490,28 @@ "url": "https://docs.litellm.ai/docs/providers/azure", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": true, "image_generations": true, + "image_edits": true, "audio_transcriptions": true, "audio_speech": true, - "moderations": true, - "batches": true, "rerank": false, - "a2a": true, + "ocr": false, + "search": false, + "moderations": false, + "realtime": true, + "video_generations": true, + "batches": true, + "messages": true, "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true, "vector_stores_search": true, "assistants": true, - "fine_tuning": true, - "text_completion": true + "fine_tuning": true } }, "azure_ai": { @@ -334,19 +519,25 @@ "url": "https://docs.litellm.ai/docs/providers/azure_ai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": true, "image_generations": true, "image_edits": true, "audio_transcriptions": true, - "audio_speech": true, - "moderations": true, - "batches": true, - "rerank": false, + "audio_speech": false, + "rerank": true, "ocr": true, - "a2a": true, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": true, + "messages": true, "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true, "vector_stores_create": true, "vector_stores_search": true } @@ -356,52 +547,77 @@ "url": "https://docs.litellm.ai/docs/providers/azure_document_intelligence", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "ocr": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "azure_ai/agents": { "display_name": "Azure AI Foundry Agents (`azure_ai/agents`)", "url": "https://docs.litellm.ai/docs/providers/azure_ai_agents", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "azure_text": { "display_name": "Azure Text (`azure_text`)", "url": "https://docs.litellm.ai/docs/providers/azure", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": true, "embeddings": false, "image_generations": false, - "audio_transcriptions": true, - "audio_speech": true, - "moderations": true, - "batches": true, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "baseten": { @@ -409,35 +625,77 @@ "url": "https://docs.litellm.ai/docs/providers/baseten", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "bytez": { "display_name": "Bytez (`bytez`)", "url": "https://docs.litellm.ai/docs/providers/bytez", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "nadir": { + "display_name": "Nadir (`nadir`)", + "url": "https://docs.litellm.ai/docs/providers/nadir", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "cerebras": { @@ -445,51 +703,102 @@ "url": "https://docs.litellm.ai/docs/providers/cerebras", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true + } + }, + "charity_engine": { + "display_name": "Charity Engine (`charity_engine`)", + "url": "https://docs.litellm.ai/docs/providers/charity_engine", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "chutes": { "display_name": "Chutes (`chutes`)", "endpoints": { - "chat_completions": true, - "messages": false, + "chat_completions": false, "responses": false, - "embeddings": true, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "clarifai": { "display_name": "Clarifai (`clarifai`)", "url": "https://docs.litellm.ai/docs/providers/clarifai", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "cloudflare": { @@ -497,17 +806,25 @@ "url": "https://docs.litellm.ai/docs/providers/cloudflare_workers", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, - "audio_transcriptions": false, + "image_edits": false, + "audio_transcriptions": true, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "codestral": { @@ -515,17 +832,25 @@ "url": "https://docs.litellm.ai/docs/providers/codestral", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "cognition": { @@ -533,35 +858,51 @@ "url": "https://docs.litellm.ai/docs/providers/cognition", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "cohere": { "display_name": "Cohere (`cohere`)", "url": "https://docs.litellm.ai/docs/providers/cohere", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": true, "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": true, "ocr": true, - "a2a": true, - "interactions": true + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "cohere_chat": { @@ -569,53 +910,77 @@ "url": "https://docs.litellm.ai/docs/providers/cohere", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "cometapi": { "display_name": "CometAPI (`cometapi`)", "url": "https://docs.litellm.ai/docs/providers/cometapi", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": true, + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "compactifai": { "display_name": "CompactifAI (`compactifai`)", "url": "https://docs.litellm.ai/docs/providers/compactifai", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "coralbricks": { @@ -623,71 +988,129 @@ "url": "https://docs.litellm.ai/docs/providers/coralbricks", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false, - "interactions": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "cortecs": { "display_name": "Cortecs (`cortecs`)", "url": "https://docs.litellm.ai/docs/providers/cortecs", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, "a2a": false, - "interactions": false + "generateContent": false + } + }, + "crusoe": { + "display_name": "Crusoe (`crusoe`)", + "url": "https://docs.litellm.ai/docs/providers/crusoe", + "endpoints": { + "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "custom": { "display_name": "Custom (`custom`)", "url": "https://docs.litellm.ai/docs/providers/custom_llm_server", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "custom_openai": { "display_name": "Custom OpenAI (`custom_openai`)", "url": "https://docs.litellm.ai/docs/providers/openai_compatible", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, - "audio_transcriptions": true, - "audio_speech": true, - "moderations": true, - "batches": true, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "dashscope": { @@ -695,17 +1118,25 @@ "url": "https://docs.litellm.ai/docs/providers/dashscope", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, - "image_generations": false, + "image_generations": true, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": true, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "qwencloud": { @@ -713,17 +1144,25 @@ "url": "https://docs.litellm.ai/docs/providers/qwencloud", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": true, + "text_completion": true, + "embeddings": false, "image_generations": true, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": true, "batches": false, - "rerank": true, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "qwen_ai_platform": { @@ -731,17 +1170,25 @@ "url": "https://docs.litellm.ai/docs/providers/qwencloud", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": true, + "text_completion": true, + "embeddings": false, "image_generations": true, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": true, "batches": false, - "rerank": true, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "databricks": { @@ -749,17 +1196,25 @@ "url": "https://docs.litellm.ai/docs/providers/databricks", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "dataforseo": { @@ -767,52 +1222,77 @@ "url": "https://docs.litellm.ai/docs/search/dataforseo", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "search": true + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "datarobot": { "display_name": "DataRobot (`datarobot`)", "url": "https://docs.litellm.ai/docs/providers/datarobot", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "deepgram": { "display_name": "Deepgram (`deepgram`)", "url": "https://docs.litellm.ai/docs/providers/deepgram", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": true, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "deepinfra": { @@ -820,17 +1300,25 @@ "url": "https://docs.litellm.ai/docs/providers/deepinfra", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "deepseek": { @@ -838,35 +1326,51 @@ "url": "https://docs.litellm.ai/docs/providers/deepseek", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "edenai": { "display_name": "Eden AI (`edenai`)", "url": "https://docs.litellm.ai/docs/providers/edenai", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": true, - "image_generations": true, - "audio_transcriptions": true, - "audio_speech": true, - "moderations": false, - "batches": false, + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, "interactions": false, - "video_generations": true + "systemone": false, + "a2a": false, + "generateContent": false } }, "duckduckgo": { @@ -874,34 +1378,78 @@ "url": "https://docs.litellm.ai/docs/search/duckduckgo", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "search": true + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "e2b": { + "display_name": "E2B (`e2b`)", + "url": "https://docs.litellm.ai/docs/providers/e2b", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, + "sandbox": true } }, "elevenlabs": { "display_name": "ElevenLabs (`elevenlabs`)", "url": "https://docs.litellm.ai/docs/providers/elevenlabs", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, - "audio_transcriptions": false, + "image_edits": false, + "audio_transcriptions": true, "audio_speech": true, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "exa_ai": { @@ -909,16 +1457,25 @@ "url": "https://docs.litellm.ai/docs/search/exa_ai", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "search": true + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "brave": { @@ -926,34 +1483,51 @@ "url": "https://docs.litellm.ai/docs/search/brave", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "search": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "empower": { "display_name": "Empower (`empower`)", "url": "https://docs.litellm.ai/docs/providers/empower", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "fal_ai": { @@ -961,17 +1535,25 @@ "url": "https://docs.litellm.ai/docs/providers/fal_ai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": true, + "image_edits": true, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": true, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "featherless_ai": { @@ -979,17 +1561,25 @@ "url": "https://docs.litellm.ai/docs/providers/featherless_ai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "fireworks_ai": { @@ -997,17 +1587,25 @@ "url": "https://docs.litellm.ai/docs/providers/fireworks_ai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, - "image_generations": false, - "audio_transcriptions": false, + "text_completion": true, + "embeddings": true, + "image_generations": true, + "image_edits": false, + "audio_transcriptions": true, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": true, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "firecrawl": { @@ -1015,16 +1613,51 @@ "url": "https://docs.litellm.ai/docs/search/firecrawl", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "search": true + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "fastcrw": { + "display_name": "fastCRW (`fastcrw`)", + "url": "https://docs.litellm.ai/docs/search/fastcrw", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "linkup": { @@ -1032,16 +1665,25 @@ "url": "https://docs.litellm.ai/docs/search/linkup", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "search": true + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "friendliai": { @@ -1049,35 +1691,77 @@ "url": "https://docs.litellm.ai/docs/providers/friendliai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "galadriel": { "display_name": "Galadriel (`galadriel`)", "url": "https://docs.litellm.ai/docs/providers/galadriel", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "gdc": { + "display_name": "Google Distributed Cloud (GDC)", + "url": "https://docs.litellm.ai/docs/providers/gdc", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "github_copilot": { @@ -1085,17 +1769,25 @@ "url": "https://docs.litellm.ai/docs/providers/github_copilot", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "chatgpt": { @@ -1103,35 +1795,51 @@ "url": "https://docs.litellm.ai/docs/providers/chatgpt", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false, - "interactions": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "github": { "display_name": "GitHub Models (`github`)", "url": "https://docs.litellm.ai/docs/providers/github", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "gmi": { @@ -1139,17 +1847,25 @@ "url": "https://docs.litellm.ai/docs/providers/gmi_cloud", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "vertex_ai": { @@ -1157,25 +1873,30 @@ "url": "https://docs.litellm.ai/docs/providers/vertex", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": true, "image_generations": true, - "audio_transcriptions": false, + "image_edits": true, + "audio_transcriptions": true, "audio_speech": true, - "moderations": false, - "batches": false, - "rerank": false, + "rerank": true, "ocr": true, - "a2a": true, + "search": false, + "moderations": false, + "realtime": true, + "video_generations": true, + "batches": true, + "messages": true, "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true, "vector_stores_search": true, "count_tokens": true, "fine_tuning": true, "rag_ingest": true, - "rag_query": true, - "generateContent": true, - "realtime": true + "rag_query": true } }, "gemini": { @@ -1183,22 +1904,28 @@ "url": "https://docs.litellm.ai/docs/providers/gemini", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, - "image_generations": false, - "audio_transcriptions": false, - "audio_speech": false, - "moderations": false, - "batches": false, + "text_completion": true, + "embeddings": true, + "image_generations": true, + "image_edits": true, + "audio_transcriptions": true, + "audio_speech": true, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": true, + "video_generations": true, + "batches": true, + "messages": true, "interactions": true, + "systemone": false, "a2a": true, + "generateContent": true, "vector_stores_search": true, "count_tokens": true, - "rag_ingest": true, - "realtime": true, - "generateContent": true + "rag_ingest": true } }, "gradient_ai": { @@ -1206,17 +1933,25 @@ "url": "https://docs.litellm.ai/docs/providers/gradient_ai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "groq": { @@ -1224,17 +1959,25 @@ "url": "https://docs.litellm.ai/docs/providers/groq", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, - "audio_transcriptions": false, - "audio_speech": false, - "moderations": false, - "batches": false, + "image_edits": false, + "audio_transcriptions": true, + "audio_speech": true, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "heroku": { @@ -1242,55 +1985,78 @@ "url": "https://docs.litellm.ai/docs/providers/heroku", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "hosted_vllm": { "display_name": "Hosted VLLM (`hosted_vllm`)", "url": "https://docs.litellm.ai/docs/providers/vllm", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": true, + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, - "batches": true, - "files": true, - "rerank": true, - "a2a": true, - "interactions": true, - "video_generations": true + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, + "files": true } }, "huggingface": { "display_name": "Huggingface (`huggingface`)", "url": "https://docs.litellm.ai/docs/providers/huggingface", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": true, + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": true, - "a2a": true, - "interactions": true + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "hyperbolic": { @@ -1298,17 +2064,25 @@ "url": "https://docs.litellm.ai/docs/providers/hyperbolic", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "watsonx": { @@ -1316,17 +2090,51 @@ "url": "https://docs.litellm.ai/docs/providers/watsonx", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": true, + "text_completion": true, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": true, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true + } + }, + "inception": { + "display_name": "Inception (`inception`)", + "url": "https://docs.litellm.ai/docs/providers/inception", + "endpoints": { + "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "infinity": { @@ -1334,15 +2142,25 @@ "url": "https://docs.litellm.ai/docs/providers/infinity", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, - "embeddings": true, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "jina_ai": { @@ -1350,15 +2168,77 @@ "url": "https://docs.litellm.ai/docs/providers/jina_ai", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, - "embeddings": true, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": true, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "bespoke": { + "display_name": "Bespoke Nimble (`bespoke`)", + "url": "https://docs.litellm.ai/docs/auto_router/decision_classifiers", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": true, + "a2a": false, + "generateContent": false + } + }, + "laya": { + "display_name": "Laya (`laya`)", + "url": "https://docs.litellm.ai/docs/auto_router/decision_classifiers", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": true, + "a2a": false, + "generateContent": false } }, "lambda_ai": { @@ -1366,17 +2246,25 @@ "url": "https://docs.litellm.ai/docs/providers/lambda_ai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "lemonade": { @@ -1384,17 +2272,25 @@ "url": "https://docs.litellm.ai/docs/providers/lemonade", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "libertai": { @@ -1402,88 +2298,129 @@ "url": "https://docs.litellm.ai/docs/providers/libertai", "endpoints": { "chat_completions": true, - "messages": true, - "responses": false, - "embeddings": false, + "responses": true, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "litellm_proxy": { "display_name": "LiteLLM Proxy (`litellm_proxy`)", "url": "https://docs.litellm.ai/docs/providers/litellm_proxy", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": true, - "image_generations": true, + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "llamafile": { "display_name": "Llamafile (`llamafile`)", "url": "https://docs.litellm.ai/docs/providers/llamafile", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "lm_studio": { "display_name": "LM Studio (`lm_studio`)", "url": "https://docs.litellm.ai/docs/providers/lm_studio", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "maritalk": { "display_name": "Maritalk (`maritalk`)", "url": "https://docs.litellm.ai/docs/providers/maritalk", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "meta_llama": { @@ -1491,17 +2428,25 @@ "url": "https://docs.litellm.ai/docs/providers/meta_llama", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "mistral": { @@ -1509,18 +2454,51 @@ "url": "https://docs.litellm.ai/docs/providers/mistral", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": true, "image_generations": false, - "audio_transcriptions": false, - "audio_speech": false, - "moderations": false, - "batches": true, + "image_edits": false, + "audio_transcriptions": true, + "audio_speech": true, "rerank": false, "ocr": true, + "search": false, + "moderations": true, + "realtime": false, + "video_generations": false, + "batches": true, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true + } + }, + "modelscope": { + "display_name": "ModelScope (`modelscope`)", + "url": "https://docs.litellm.ai/docs/providers/modelscope", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "moonshot": { @@ -1528,35 +2506,51 @@ "url": "https://docs.litellm.ai/docs/providers/moonshot", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "docker_model_runner": { "display_name": "Docker Model Runner (`docker_model_runner`)", "url": "https://docs.litellm.ai/docs/providers/docker_model_runner", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "morph": { @@ -1564,33 +2558,50 @@ "url": "https://docs.litellm.ai/docs/providers/morph", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "nanogpt": { "display_name": "NanoGPT (`nanogpt`)", "endpoints": { - "chat_completions": true, - "messages": false, + "chat_completions": false, "responses": false, - "embeddings": true, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "nebius": { @@ -1598,17 +2609,51 @@ "url": "https://docs.litellm.ai/docs/providers/nebius", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true + } + }, + "neosantara": { + "display_name": "Neosantara (`neosantara`)", + "url": "https://docs.litellm.ai/docs/providers/neosantara", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "nlp_cloud": { @@ -1616,17 +2661,25 @@ "url": "https://docs.litellm.ai/docs/providers/nlp_cloud", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "novita": { @@ -1634,17 +2687,25 @@ "url": "https://novita.ai/models/llm?utm_source=github_litellm&utm_medium=github_readme&utm_campaign=github_link", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": true, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "nscale": { @@ -1652,52 +2713,77 @@ "url": "https://docs.litellm.ai/docs/providers/nscale", "endpoints": { "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": true, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, "messages": true, - "responses": true, - "embeddings": false, - "image_generations": false, - "audio_transcriptions": false, - "audio_speech": false, - "moderations": false, - "batches": false, - "rerank": false, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true - } - }, - "neosantara": { - "display_name": "Neosantara (`neosantara`)", - "url": "https://docs.litellm.ai/docs/providers/neosantara", - "endpoints": { - "chat_completions": true, - "messages": false, - "responses": true, - "embeddings": false, - "image_generations": false, - "audio_transcriptions": false, - "audio_speech": false, - "moderations": false, - "batches": false, - "rerank": false, - "a2a": false + "generateContent": true } }, "nvidia_nim": { "display_name": "Nvidia NIM (`nvidia_nim`)", "url": "https://docs.litellm.ai/docs/providers/nvidia_nim", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": true, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "nvidia_riva": { + "display_name": "Nvidia Riva (`nvidia_riva`)", + "url": "https://docs.litellm.ai/docs/providers/nvidia_riva", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "oci": { @@ -1705,17 +2791,25 @@ "url": "https://docs.litellm.ai/docs/providers/oci", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "ollama": { @@ -1723,53 +2817,77 @@ "url": "https://docs.litellm.ai/docs/providers/ollama", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": true, + "text_completion": true, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "ollama_chat": { "display_name": "Ollama Chat (`ollama_chat`)", "url": "https://docs.litellm.ai/docs/providers/ollama", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "oobabooga": { "display_name": "Oobabooga (`oobabooga`)", "url": "https://docs.litellm.ai/docs/providers/openai_compatible", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, - "audio_transcriptions": true, - "audio_speech": true, - "moderations": true, - "batches": true, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "openai": { @@ -1777,19 +2895,27 @@ "url": "https://docs.litellm.ai/docs/providers/openai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": true, "image_generations": true, + "image_edits": true, "audio_transcriptions": true, "audio_speech": true, - "moderations": true, - "batches": true, "rerank": false, + "ocr": false, + "search": false, + "moderations": true, + "realtime": true, + "video_generations": true, + "batches": true, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true, "container": true, "compact": true, - "a2a": true, - "interactions": true, "vector_store_files": true, "vector_stores_create": true, "vector_stores_search": true, @@ -1798,9 +2924,34 @@ "fine_tuning": true, "image_variations": true, "rag_ingest": true, - "rag_query": true, - "realtime": true, - "text_completion": true + "rag_query": true + } + }, + "opensandbox": { + "display_name": "OpenSandbox (`opensandbox`)", + "url": "https://open-sandbox.ai/api/", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, + "sandbox": true } }, "openai_like": { @@ -1808,15 +2959,25 @@ "url": "https://docs.litellm.ai/docs/providers/openai_compatible", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, - "embeddings": true, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, "assistants": true } }, @@ -1824,18 +2985,26 @@ "display_name": "OpenRouter (`openrouter`)", "url": "https://docs.litellm.ai/docs/providers/openrouter", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": true, + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "ovhcloud": { @@ -1843,17 +3012,25 @@ "url": "https://docs.litellm.ai/docs/providers/ovhcloud", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, - "audio_transcriptions": true, + "image_edits": false, + "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "parallel_ai": { @@ -1861,16 +3038,51 @@ "url": "https://docs.litellm.ai/docs/search/parallel_ai", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "search": true + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "parasail": { + "display_name": "Parasail (`parasail`)", + "url": "https://docs.litellm.ai/docs/providers/parasail", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "perplexity": { @@ -1878,52 +3090,154 @@ "url": "https://docs.litellm.ai/docs/providers/perplexity", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "petals": { "display_name": "Petals (`petals`)", "url": "https://docs.litellm.ai/docs/providers/petals", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "sail": { + "display_name": "Sail (`sail`)", + "url": "https://docs.litellm.ai/docs/providers/sail", + "endpoints": { + "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true + } + }, + "meta": { + "display_name": "Meta Model API (`meta`)", + "url": "https://docs.litellm.ai/docs/providers/meta", + "endpoints": { + "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": true, + "image_edits": true, + "audio_transcriptions": true, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": true, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true + } + }, + "pinstripes": { + "display_name": "Pinstripes (`pinstripes`)", + "url": "https://docs.litellm.ai/docs/providers/pinstripes", + "endpoints": { + "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "poe": { "display_name": "Poe (`poe`)", "endpoints": { - "chat_completions": true, - "messages": false, + "chat_completions": false, "responses": false, - "embeddings": true, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "publicai": { @@ -1931,17 +3245,25 @@ "url": "https://docs.litellm.ai/docs/providers/publicai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "darkbloom": { @@ -1949,34 +3271,51 @@ "url": "https://docs.litellm.ai/docs/providers/darkbloom", "endpoints": { "chat_completions": true, - "messages": false, - "responses": false, + "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "predibase": { "display_name": "Predibase (`predibase`)", "url": "https://docs.litellm.ai/docs/providers/predibase", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "prism": { @@ -1984,16 +3323,25 @@ "url": "https://docs.litellm.ai/docs/providers/prism", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "recraft": { @@ -2001,15 +3349,51 @@ "url": "https://docs.litellm.ai/docs/providers/recraft", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": true, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "reducto": { + "display_name": "Reducto (`reducto`)", + "url": "https://docs.litellm.ai/docs/providers/reducto", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": true, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "replicate": { @@ -2017,17 +3401,25 @@ "url": "https://docs.litellm.ai/docs/providers/replicate", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "runwayml": { @@ -2035,34 +3427,51 @@ "url": "https://docs.litellm.ai/docs/providers/runwayml/videos", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": true, + "image_edits": false, "audio_transcriptions": false, "audio_speech": true, - "moderations": false, - "batches": false, "rerank": false, - "video_generations": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": true, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "sagemaker_chat": { "display_name": "Sagemaker Chat (`sagemaker_chat`)", "url": "https://docs.litellm.ai/docs/providers/aws_sagemaker", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "searxng": { @@ -2070,16 +3479,25 @@ "url": "https://docs.litellm.ai/docs/search/searxng", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "search": true + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "scaledown": { @@ -2087,17 +3505,25 @@ "url": "https://docs.litellm.ai/docs/providers/scaledown", "endpoints": { "chat_completions": true, - "messages": false, - "responses": false, + "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false, - "interactions": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "sambanova": { @@ -2105,53 +3531,51 @@ "url": "https://docs.litellm.ai/docs/providers/sambanova", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "sap": { "display_name": "SAP Generative AI Hub (`sap`)", "url": "https://docs.litellm.ai/docs/providers/sap", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true - } - }, - "reka": { - "display_name": "Reka (`reka`)", - "url": "https://docs.litellm.ai/docs/providers/reka", - "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": false, - "image_generations": false, - "audio_transcriptions": false, - "audio_speech": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false, + "messages": false, + "interactions": false, + "systemone": false, "a2a": false, - "interactions": false + "generateContent": false } }, "scaleway": { @@ -2159,17 +3583,25 @@ "url": "https://docs.litellm.ai/docs/providers/scaleway", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": true, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "scx-ai": { @@ -2177,16 +3609,25 @@ "url": "https://docs.litellm.ai/docs/providers/scx_ai", "endpoints": { "chat_completions": true, - "messages": false, - "responses": false, + "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "inferenceapis": { @@ -2194,17 +3635,25 @@ "url": "https://docs.litellm.ai/docs/providers/inferenceapis", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false, - "interactions": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "snowflake": { @@ -2212,69 +3661,180 @@ "url": "https://docs.litellm.ai/docs/providers/snowflake", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true + } + }, + "soniox": { + "display_name": "Soniox (`soniox`)", + "url": "https://docs.litellm.ai/docs/providers/soniox", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": true, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "synthetic": { "display_name": "Synthetic (`synthetic`)", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": true, + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "tensormesh": { + "display_name": "Tensormesh (`tensormesh`)", + "url": "https://docs.litellm.ai/docs/providers/tensormesh", + "endpoints": { + "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true + } + }, + "tencent": { + "display_name": "Tencent TokenHub (`tencent`)", + "url": "https://docs.litellm.ai/docs/providers/tencent", + "endpoints": { + "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "text-completion-codestral": { "display_name": "Text Completion Codestral (`text-completion-codestral`)", "url": "https://docs.litellm.ai/docs/providers/codestral", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "text-completion-openai": { "display_name": "Text Completion OpenAI (`text-completion-openai`)", "url": "https://docs.litellm.ai/docs/providers/text_completion_openai", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": true, "embeddings": false, "image_generations": false, - "audio_transcriptions": true, - "audio_speech": true, - "moderations": true, - "batches": true, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "together_ai": { @@ -2282,56 +3842,312 @@ "url": "https://docs.litellm.ai/docs/providers/togetherai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": true, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "topaz": { "display_name": "Topaz (`topaz`)", "url": "https://docs.litellm.ai/docs/providers/topaz", "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, "image_variations": true } }, + "nace": { + "display_name": "Nace (`nace`)", + "url": "https://console.nace.ai/docs/drex", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "typesafe": { + "display_name": "TypeSafe (`typesafe`)", + "url": "https://docs.typesafe.ai/models", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "strands_decider": { + "display_name": "Strands Decider (`strands_decider`)", + "url": "https://docs.litellm.ai/docs/providers", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, "tavily": { "display_name": "Tavily (`tavily`)", "url": "https://docs.litellm.ai/docs/search/tavily", "endpoints": { - "search": true + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "serper": { "display_name": "Serper (`serper`)", "url": "https://docs.litellm.ai/docs/search/serper", "endpoints": { - "search": true + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "you_com": { + "display_name": "You.com (`you_com`)", + "url": "https://docs.litellm.ai/docs/search/you_com", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "apiserpent": { + "display_name": "APISerpent (`apiserpent`)", + "url": "https://docs.litellm.ai/docs/search/apiserpent", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "tinyfish": { + "display_name": "TinyFish (`tinyfish`)", + "url": "https://docs.tinyfish.ai/search-api", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "nimble": { + "display_name": "Nimble (`nimble`)", + "url": "https://docs.nimbleway.com/api-reference/search/search", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "triton": { "display_name": "Triton (`triton`)", "url": "https://docs.litellm.ai/docs/providers/triton-inference-server", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "v0": { @@ -2339,17 +4155,25 @@ "url": "https://docs.litellm.ai/docs/providers/v0", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "vercel_ai_gateway": { @@ -2357,36 +4181,52 @@ "url": "https://docs.litellm.ai/docs/providers/vercel_ai_gateway", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "vllm": { "display_name": "VLLM (`vllm`)", "url": "https://docs.litellm.ai/docs/providers/vllm", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": true, + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, - "batches": true, - "files": true, - "rerank": true, - "a2a": true, - "interactions": true + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, + "files": true } }, "volcengine": { @@ -2394,17 +4234,25 @@ "url": "https://docs.litellm.ai/docs/providers/volcano", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": true, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "voyage": { @@ -2412,15 +4260,25 @@ "url": "https://docs.litellm.ai/docs/providers/voyage", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": true, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": true + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "wandb": { @@ -2428,35 +4286,51 @@ "url": "https://docs.litellm.ai/docs/providers/wandb_inference", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "watsonx_text": { "display_name": "Watsonx Text (`watsonx_text`)", "url": "https://docs.litellm.ai/docs/providers/watsonx", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "xai": { @@ -2464,18 +4338,25 @@ "url": "https://docs.litellm.ai/docs/providers/xai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, - "image_generations": false, - "audio_transcriptions": false, + "image_generations": true, + "image_edits": false, + "audio_transcriptions": true, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, + "ocr": false, + "search": false, + "moderations": false, + "realtime": true, + "video_generations": true, + "batches": false, + "messages": true, "interactions": true, - "realtime": true + "systemone": false, + "a2a": true, + "generateContent": true } }, "xinference": { @@ -2483,15 +4364,25 @@ "url": "https://docs.litellm.ai/docs/providers/xinference", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, - "embeddings": true, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "zai": { @@ -2499,90 +4390,182 @@ "url": "https://docs.litellm.ai/docs/providers/zai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "ragflow": { "display_name": "RAGFlow (`ragflow`)", "url": "https://docs.litellm.ai/docs/providers/ragflow", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "vector_stores_create": true, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, + "vector_stores_create": true } }, "cursor": { "display_name": "Cursor BYOK (`cursor`)", "url": "https://docs.litellm.ai/docs/providers/cursor", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "langgraph": { "display_name": "LangGraph (`langgraph`)", "url": "https://docs.litellm.ai/docs/providers/langgraph", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "microsoft_365_copilot": { + "display_name": "Microsoft 365 Copilot (`microsoft_365_copilot`)", + "url": "https://docs.litellm.ai/docs/providers/microsoft_365_copilot", + "endpoints": { + "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true + } + }, + "langflow": { + "display_name": "LangFlow (`langflow`)", + "url": "https://docs.litellm.ai/docs/providers/langflow", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "vertex_ai/agent_engine": { "display_name": "Vertex AI Agent Engine (`vertex_ai/agent_engine`)", "url": "https://docs.litellm.ai/docs/providers/vertex_ai_agent_engine", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "pydantic_ai_agents": { @@ -2590,16 +4573,25 @@ "url": "https://docs.litellm.ai/docs/providers/pydantic_ai_agent", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "stability": { @@ -2607,34 +4599,51 @@ "url": "https://docs.litellm.ai/docs/providers/stability", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": true, "image_edits": true, "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "venice": { "display_name": "Venice.ai (`venice`)", "url": "https://docs.litellm.ai/docs/providers/venice", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "gigachat": { @@ -2642,22 +4651,77 @@ "url": "https://docs.litellm.ai/docs/providers/gigachat", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": true + "text_completion": true, + "embeddings": true, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "google_pse": { "display_name": "Google PSE (`google_pse`)", "url": "https://docs.litellm.ai/docs/search/google_pse", "endpoints": { - "search": true + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "milvus": { "display_name": "Milvus (`milvus`)", "url": "https://docs.litellm.ai/docs/providers/milvus_vector_stores", "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, "vector_stores_search": true } }, @@ -2666,14 +4730,105 @@ "url": "https://docs.litellm.ai/docs/providers/minimax", "endpoints": { "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": true, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": true, + "batches": false, "messages": true, - "responses": true + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "pg_vector": { "display_name": "PG Vector (`pg_vector`)", "url": "https://docs.litellm.ai/docs/providers/pg_vector", "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, + "vector_stores_search": true + } + }, + "mongodb": { + "display_name": "MongoDB Atlas (`mongodb`)", + "url": "https://docs.litellm.ai/docs/providers/mongodb_vector_stores", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, + "vector_stores_search": true + } + }, + "valkey": { + "display_name": "Valkey (`valkey`)", + "url": "https://docs.litellm.ai/docs/providers/valkey_vector_stores", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, "vector_stores_search": true } }, @@ -2681,9 +4836,26 @@ "display_name": "Helicone (`helicone`)", "url": "https://docs.litellm.ai/docs/providers/helicone", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "llamagate": { @@ -2691,8 +4863,25 @@ "url": "https://docs.litellm.ai/docs/providers/llamagate", "endpoints": { "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": true, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, "messages": true, - "responses": true + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "xiaomi_mimo": { @@ -2700,27 +4889,52 @@ "url": "https://docs.litellm.ai/docs/providers/xiaomi_mimo", "endpoints": { "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, "messages": true, - "responses": true + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "manus": { "display_name": "Manus (`manus`)", "url": "https://docs.litellm.ai/docs/providers/manus", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, - "files": true, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, + "files": true } }, "sarvam": { @@ -2728,8 +4942,155 @@ "url": "https://docs.litellm.ai/docs/providers/sarvam", "endpoints": { "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, "messages": true, - "responses": true + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true + } + }, + "bedrock_mantle": { + "display_name": "Bedrock Mantle (`bedrock_mantle`)", + "url": "https://docs.litellm.ai/docs/providers/bedrock", + "endpoints": { + "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true + } + }, + "searchapi": { + "display_name": "SearchAPI (`searchapi`)", + "url": "https://docs.litellm.ai/docs/providers/searchapi", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "black_forest_labs": { + "display_name": "Black Forest Labs (`black_forest_labs`)", + "url": "https://docs.litellm.ai/docs/providers/black_forest_labs", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": true, + "image_edits": true, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "reka": { + "display_name": "Reka (`reka`)", + "url": "https://docs.litellm.ai/docs/providers/reka", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "empiriolabs": { + "display_name": "EmpirioLabs (`empiriolabs`)", + "url": "https://docs.litellm.ai/docs/providers/empiriolabs", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "openinfer": { @@ -2737,16 +5098,155 @@ "url": "https://docs.litellm.ai/docs/providers/openinfer", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true + } + }, + "agentcore": { + "display_name": "AgentCore (`agentcore`)", + "url": "https://docs.litellm.ai/docs/providers", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "anyscale": { + "display_name": "Anyscale (`anyscale`)", + "url": "https://docs.litellm.ai/docs/providers/anyscale", + "endpoints": { + "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true + } + }, + "bing_grounding": { + "display_name": "Bing Grounding (`bing_grounding`)", + "url": "https://docs.litellm.ai/docs/providers", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "opencode_go": { + "display_name": "OpenCode Go (`opencode_go`)", + "url": "https://docs.litellm.ai/docs/providers/opencode_go", + "endpoints": { + "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true + } + }, + "transcribe": { + "display_name": "Transcribe (`transcribe`)", + "url": "https://docs.litellm.ai/docs/providers", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": true, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } } }, @@ -2959,6 +5459,13 @@ "provider_json_field": "compact", "url": "https://docs.litellm.ai/docs/response_api" }, + "sandbox": { + "docs_label": "sandbox", + "display_name": "Code Execution Sandbox API", + "leftnav_label": "/sandbox", + "provider_json_field": "sandbox", + "url": "https://docs.litellm.ai/docs/providers/e2b" + }, "search": { "docs_label": "search", "display_name": "Search API", @@ -2973,6 +5480,13 @@ "provider_json_field": "skills", "url": "https://docs.litellm.ai/docs/skills" }, + "systemone": { + "docs_label": "systemone", + "display_name": "System One Decision API", + "leftnav_label": "/laya/v1/systemone", + "provider_json_field": "systemone", + "url": "https://docs.litellm.ai/docs/auto_router/decision_classifiers" + }, "text_completion": { "docs_label": "text_completion", "display_name": "OpenAI Completions API", diff --git a/litellm/proxy/_experimental/mcp_server/__init__.py b/litellm/proxy/_experimental/mcp_server/__init__.py new file mode 100644 index 00000000000..cf217531dc4 --- /dev/null +++ b/litellm/proxy/_experimental/mcp_server/__init__.py @@ -0,0 +1,4 @@ +import litellm.proxy.mcp_server as _mcp_server +from litellm.litellm_core_utils.deprecated_package import alias_deprecated_package + +alias_deprecated_package(__name__, _mcp_server) diff --git a/litellm/proxy/_lazy_features.py b/litellm/proxy/_lazy_features.py index 28c701e0fc2..db01475154b 100644 --- a/litellm/proxy/_lazy_features.py +++ b/litellm/proxy/_lazy_features.py @@ -163,7 +163,7 @@ LAZY_FEATURES: Final[tuple[LazyFeature, ...]] = ( # /.well-known/oauth-authorization-server: the root document is the # gateway's own authorization server metadata (token endpoint /token). name="mcp_discoverable", - module_path="litellm.proxy._experimental.mcp_server.discoverable_endpoints", + module_path="litellm.proxy.mcp_server.discoverable_endpoints", path_prefixes=( "/oauth/client-metadata.json", "/.well-known/oauth-", @@ -185,19 +185,19 @@ LAZY_FEATURES: Final[tuple[LazyFeature, ...]] = ( # No /mcp/oauth prefix here: the mounted /mcp sub-app would # shadow it, and there are no actual routes there anyway. name="mcp_byok_oauth", - module_path="litellm.proxy._experimental.mcp_server.byok_oauth_endpoints", + module_path="litellm.proxy.mcp_server.byok_oauth_endpoints", path_prefixes=("/v1/mcp/oauth", "/.well-known/oauth-"), ), LazyFeature( name="mcp_rest", - module_path="litellm.proxy._experimental.mcp_server.rest_endpoints", + module_path="litellm.proxy.mcp_server.rest_endpoints", path_prefixes=("/mcp-rest",), ), LazyFeature( # Hardcoded /mcp matches BASE_MCP_ROUTE; importing the constant # here would defeat lazy loading. name="mcp_app", - module_path="litellm.proxy._experimental.mcp_server.server", + module_path="litellm.proxy.mcp_server.server", path_prefixes=("/mcp",), register_fn=_mount_app("/mcp", attr_name="app"), persistent_swagger_stub=True, @@ -207,6 +207,11 @@ LAZY_FEATURES: Final[tuple[LazyFeature, ...]] = ( module_path="litellm.proxy.management_endpoints.config_override_endpoints", path_prefixes=("/config_overrides",), ), + LazyFeature( + name="codex_passthrough", + module_path="litellm.proxy.pass_through_endpoints.codex_passthrough_endpoints", + path_prefixes=("/backend-api/codex/",), + ), LazyFeature( name="llm_passthrough", module_path="litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints", @@ -356,7 +361,7 @@ class LazyFeatureMiddleware: async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: # Short-circuit once every feature has loaded. if scope["type"] in ("http", "websocket") and len(self._loaded) < len(self._features): - path: str = scope.get("path", "") + path: str = str(_scope_value(scope, "path")) # Strip the request's root_path so prefix matching works under a # server root path. Without this, requests like /api/v1/policies/... # never match the registered prefixes (/policies/...) and lazy @@ -584,6 +589,7 @@ def _make_warmup_router(app: "FastAPI", features: tuple[LazyFeature, ...] = LAZY from fastapi import APIRouter, Depends, HTTPException from fastapi.openapi.utils import get_openapi + from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.proxy.auth.user_api_key_auth import user_api_key_auth router: Final = APIRouter() @@ -603,17 +609,22 @@ def _make_warmup_router(app: "FastAPI", features: tuple[LazyFeature, ...] = LAZY await _force_load(app, feat, features) feat_routes: Final = [r for r in app.routes if feat.matches(getattr(r, "path", ""))] - full: Final = get_openapi(title=app.title, version=app.version, routes=feat_routes) + full: Final[Mapping[str, object]] = MappingProxyType( + get_openapi(title=app.title, version=app.version, routes=feat_routes) + ) + paths: Final = as_str_mapping(full.get("paths", {})) or {} + components: Final = as_str_mapping(full.get("components", {})) or {} # Force all operations under one tag so they group under a single Swagger # section — many lazy modules tag routes inconsistently. - for path_ops in full.get("paths", {}).values(): - for op in path_ops.values(): - if isinstance(op, dict): - op["tags"] = [feat.name] + for path_ops in paths.values(): + for op in (as_str_mapping(path_ops) or {}).values(): + operation = as_str_mapping(op) + if isinstance(operation, dict): + operation["tags"] = [feat.name] return { "stub_path": feat.path_prefixes[0], "paths": full.get("paths", {}), - "components": {"schemas": full.get("components", {}).get("schemas", {})}, + "components": {"schemas": components.get("schemas", {})}, } return router diff --git a/litellm/proxy/_lazy_openapi_snapshot.json b/litellm/proxy/_lazy_openapi_snapshot.json index 0dd978ee855..166072e9613 100644 --- a/litellm/proxy/_lazy_openapi_snapshot.json +++ b/litellm/proxy/_lazy_openapi_snapshot.json @@ -8673,6 +8673,184 @@ } } }, + "codex_passthrough": { + "components": { + "schemas": { + "HTTPValidationError": { + "properties": { + "detail": { + "items": { + "$ref": "#/components/schemas/ValidationError" + }, + "title": "Detail", + "type": "array" + } + }, + "title": "HTTPValidationError", + "type": "object" + }, + "ValidationError": { + "properties": { + "ctx": { + "title": "Context", + "type": "object" + }, + "input": { + "title": "Input" + }, + "loc": { + "items": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "integer" + } + ] + }, + "title": "Location", + "type": "array" + }, + "msg": { + "title": "Message", + "type": "string" + }, + "type": { + "title": "Error Type", + "type": "string" + } + }, + "required": [ + "loc", + "msg", + "type" + ], + "title": "ValidationError", + "type": "object" + } + } + }, + "paths": { + "/backend-api/codex/{endpoint}": { + "get": { + "description": "Forward a client's ChatGPT subscription with separate LiteLLM authentication.", + "operationId": "codex_passthrough_route_backend_api_codex__endpoint__get", + "parameters": [ + { + "in": "path", + "name": "endpoint", + "required": true, + "schema": { + "enum": [ + "models", + "responses" + ], + "title": "Endpoint", + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": {} + } + }, + "description": "Successful Response" + }, + "422": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + "description": "Validation Error" + } + }, + "security": [ + { + "APIKeyHeader": [] + } + ], + "summary": "Codex Passthrough Route", + "tags": [ + "codex_passthrough" + ] + }, + "post": { + "description": "Forward a client's ChatGPT subscription with separate LiteLLM authentication.", + "operationId": "codex_passthrough_route_backend_api_codex__endpoint__post", + "parameters": [ + { + "in": "path", + "name": "endpoint", + "required": true, + "schema": { + "enum": [ + "models", + "responses" + ], + "title": "Endpoint", + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "additionalProperties": true, + "type": "object" + } + } + }, + "required": true + }, + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "additionalProperties": true, + "type": "object" + } + }, + "text/event-stream": { + "schema": { + "type": "string" + } + } + }, + "description": "Unmodified Codex response or server-sent events" + }, + "422": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + "description": "Validation Error" + } + }, + "security": [ + { + "APIKeyHeader": [] + } + ], + "summary": "Codex Passthrough Route", + "tags": [ + "codex_passthrough" + ] + } + } + } + }, "compliance": { "components": { "schemas": { @@ -22858,6 +23036,25 @@ "title": "Body_image_edit_api_openai_deployments__model__images_edits_post", "type": "object" }, + "CacheWriteTokensDetails": { + "additionalProperties": true, + "properties": { + "ttl_12h_tokens": { + "title": "Ttl 12H Tokens", + "type": "integer" + }, + "ttl_30m_tokens": { + "title": "Ttl 30M Tokens", + "type": "integer" + } + }, + "required": [ + "ttl_30m_tokens", + "ttl_12h_tokens" + ], + "title": "CacheWriteTokensDetails", + "type": "object" + }, "CachedTokensDetails": { "properties": { "audio_tokens": { @@ -24352,6 +24549,27 @@ ], "title": "Audio Tokens" }, + "cache_write_tokens": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "title": "Cache Write Tokens" + }, + "cache_write_tokens_details": { + "anyOf": [ + { + "$ref": "#/components/schemas/CacheWriteTokensDetails" + }, + { + "type": "null" + } + ] + }, "cached_tokens": { "default": 0, "title": "Cached Tokens", diff --git a/litellm/proxy/_lazy_openapi_snapshot.py b/litellm/proxy/_lazy_openapi_snapshot.py index 00a05307a89..c5a63b0f990 100644 --- a/litellm/proxy/_lazy_openapi_snapshot.py +++ b/litellm/proxy/_lazy_openapi_snapshot.py @@ -16,6 +16,7 @@ import sys from collections.abc import Callable, Mapping from dataclasses import dataclass from pathlib import Path +from types import MappingProxyType from typing import TYPE_CHECKING, Final from typing_extensions import ReadOnly, TypedDict @@ -61,7 +62,7 @@ def load_snapshot() -> dict[str, dict] | None: return None -def _normalize_operation_ids(paths: dict[str, dict]) -> None: +def _normalize_operation_ids(paths: Mapping[str, object]) -> None: """Make FastAPI-generated operation IDs stable for multi-method routes. FastAPI derives the default operation ID suffix from the first item in the @@ -69,26 +70,30 @@ def _normalize_operation_ids(paths: dict[str, dict]) -> None: set iteration order can vary between processes, which makes the snapshot drift even when no routes changed. """ + from litellm.litellm_core_utils.core_helpers import as_str_mapping + for path_ops in paths.values(): - if not isinstance(path_ops, dict): + operations = as_str_mapping(path_ops) + if not isinstance(operations, dict): continue - methods = {method for method in path_ops if method in HTTP_METHOD_SUFFIXES} + methods = {method for method in operations if method in HTTP_METHOD_SUFFIXES} if not methods: continue - for method, operation in path_ops.items(): - if method not in HTTP_METHOD_SUFFIXES or not isinstance(operation, dict): + for method, operation in operations.items(): + entry = as_str_mapping(operation) + if method not in HTTP_METHOD_SUFFIXES or not isinstance(entry, dict): continue - operation_id = operation.get("operationId") + operation_id = entry.get("operationId") if not isinstance(operation_id, str): continue for suffix in methods: suffix_token = f"_{suffix}" if operation_id.endswith(suffix_token): - operation["operationId"] = operation_id[: -len(suffix_token)] + f"_{method}" + entry["operationId"] = operation_id[: -len(suffix_token)] + f"_{method}" break @@ -117,6 +122,7 @@ def _register_feature(app: "FastAPI", feat: "LazyFeature") -> str | None: def _feature_fragment(app: "FastAPI", feat: "LazyFeature", used_operation_ids: set[str]) -> SnapshotFragment | None: from fastapi.openapi.utils import get_openapi + from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.proxy.proxy_server import ensure_unique_openapi_operation_ids feat_routes: Final = [r for r in app.routes if feat.matches(getattr(r, "path", ""))] @@ -124,22 +130,29 @@ def _feature_fragment(app: "FastAPI", feat: "LazyFeature", used_operation_ids: s return None _stabilize_multi_method_route_ids(feat_routes) full: Final = get_openapi(title=app.title, version=app.version, routes=feat_routes) - paths: Final = full.get("paths", {}) + openapi: Final[Mapping[str, object]] = MappingProxyType(full) + paths: Final = as_str_mapping(openapi.get("paths", {})) or {} _normalize_operation_ids(paths) for path_ops in paths.values(): - for method, op in path_ops.items(): - if isinstance(op, dict): - operation_id = op.get("operationId") + for method, op in (as_str_mapping(path_ops) or {}).items(): + operation = as_str_mapping(op) + if isinstance(operation, dict): + operation_id = operation.get("operationId") if isinstance(operation_id, str): for suffix in HTTP_METHOD_SUFFIXES: if operation_id.endswith(f"_{suffix}"): - op["operationId"] = operation_id[: -len(suffix)] + method + operation["operationId"] = operation_id[: -len(suffix)] + method break - op["tags"] = [feat.name] - unique: Final = ensure_unique_openapi_operation_ids(full, used_operation_ids) + operation["tags"] = [feat.name] + unique: Final[Mapping[str, object]] = MappingProxyType( + ensure_unique_openapi_operation_ids(full, used_operation_ids) + ) + components: Final = as_str_mapping(unique.get("components", {})) or {} return { - "paths": paths, - "components": {"schemas": unique.get("components", {}).get("schemas", {})}, + "paths": { + path: operations for path, entry in paths.items() if (operations := as_str_mapping(entry)) is not None + }, + "components": {"schemas": as_str_mapping(components.get("schemas", {})) or {}}, } diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index 5f631113158..64baf389d6d 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -37,7 +37,7 @@ from litellm.litellm_core_utils.initialize_dynamic_callback_params import ( validate_langfuse_span_scope_value, validate_no_callback_env_reference, ) -from litellm.proxy._experimental.mcp_server.stdio_gate import MCP_STDIO_DISABLED_MESSAGE, is_mcp_stdio_enabled +from litellm.proxy.mcp_server.stdio_gate import MCP_STDIO_DISABLED_MESSAGE, is_mcp_stdio_enabled from litellm.types.agents import ( AgentCaller as AgentCaller, # noqa: PLC0414 # public re-export ) @@ -219,6 +219,8 @@ from litellm.types.proxy.auth.user_roles import ( # noqa: E402 # re-export aft KeyManagementRoutes as KeyManagementRoutes, # noqa: PLC0414 # public re-export ) +MODEL_LIST_ROUTES: Final = ("/models", "/v1/models", "/claude_code_gateway/v1/models") + class LiteLLMRoutes(enum.Enum): openai_route_names = [ @@ -307,8 +309,7 @@ class LiteLLMRoutes(enum.Enum): "/threads/{thread_id}/runs", "/v1/threads/{thread_id}/runs", # models - "/models", - "/v1/models", + *MODEL_LIST_ROUTES, # token counter "/utils/token_counter", "/utils/model_info", @@ -390,6 +391,7 @@ class LiteLLMRoutes(enum.Enum): ] mapped_pass_through_routes = [ + "/backend-api/codex", "/bedrock", "/comprehendmedical", "/azure_speech", @@ -577,8 +579,7 @@ class LiteLLMRoutes(enum.Enum): "/health/services", "/key/list", "/user/filter/ui", - "/models", - "/v1/models", + *MODEL_LIST_ROUTES, "/sso/get/ui_settings", "/get/user_banner", "/get/latest_release_info", @@ -760,8 +761,7 @@ class LiteLLMRoutes(enum.Enum): "/model/info", "/v2/model/info", "/v2/key/info", - "/models", - "/v1/models", + *MODEL_LIST_ROUTES, "/global/spend", "/global/spend/logs", "/global/spend/keys", @@ -1767,8 +1767,10 @@ class BudgetNewRequest(LiteLLMPydanticObjectBase): max_parallel_requests: int | None = Field( default=None, description="Max concurrent requests allowed for this budget id." ) - tpm_limit: int | None = Field(default=None, description="Max tokens per minute, allowed for this budget id.") - rpm_limit: int | None = Field(default=None, description="Max requests per minute, allowed for this budget id.") + tpm_limit: int | None = Field(default=None, ge=0, description="Max tokens per minute, allowed for this budget id.") + rpm_limit: int | None = Field( + default=None, ge=0, description="Max requests per minute, allowed for this budget id." + ) tpd_limit: int | None = Field( default=None, description="Max tokens per day, charged by batch submissions, allowed for this budget id." ) @@ -1879,6 +1881,8 @@ RouterSettingsDict = Annotated[ class NewTeamRequest(TeamBase): + tpm_limit: int | None = Field(default=None, ge=0) + rpm_limit: int | None = Field(default=None, ge=0) router_settings: RouterSettingsDict | None = None model_aliases: dict | None = None model_max_budget: GenericBudgetConfigType | None = Field( @@ -1958,8 +1962,8 @@ class UpdateTeamRequest(LiteLLMPydanticObjectBase): team_alias: str | None = None organization_id: str | None = None metadata: dict | None = None - tpm_limit: int | None = None - rpm_limit: int | None = None + tpm_limit: int | None = Field(default=None, ge=0) + rpm_limit: int | None = Field(default=None, ge=0) tpd_limit: int | None = None max_budget: float | None = None soft_budget: float | None = None @@ -3273,7 +3277,7 @@ class LiteLLM_OrganizationTableWithMembers(LiteLLM_OrganizationTable): members: list[LiteLLM_OrganizationMembershipTable] = [] teams: list[LiteLLM_TeamTable] = [] - litellm_budget_table: LiteLLM_BudgetTable | None = None + litellm_budget_table: LiteLLM_BudgetTableFull | None = None created_at: datetime updated_at: datetime @@ -5264,6 +5268,7 @@ class ToolDiscoveryQueueItem(TypedDict, total=False): team_id: str | None # team that triggered discovery key_alias: str | None # human-readable key alias user_agent: str | None # HTTP User-Agent of the caller + call_count: ReadOnly[int] # invocations folded into this row since the previous flush from litellm.models.managed_files import ( # noqa: E402 diff --git a/litellm/proxy/a2a/discovery.py b/litellm/proxy/a2a/discovery.py index ff58c9c85ec..03d1be7d185 100644 --- a/litellm/proxy/a2a/discovery.py +++ b/litellm/proxy/a2a/discovery.py @@ -16,10 +16,13 @@ fetcher dispatches by ``discovery_mode``: from collections.abc import Mapping from enum import Enum -from typing import Any, Final +from typing import Final from urllib.parse import urlencode +from pydantic import TypeAdapter + from litellm._logging import verbose_proxy_logger +from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.litellm_core_utils.url_utils import SSRFError, async_safe_get from litellm.llms.custom_httpx.http_handler import get_async_httpx_client from litellm.types.llms.custom_http import httpxSpecialProvider @@ -46,6 +49,8 @@ AGENT_CARD_WELL_KNOWN_PATHS: Final[tuple[str, ...]] = ( DEFAULT_DISCOVERY_TIMEOUT_SECONDS: Final = 10.0 +_DECODED_JSON: Final = TypeAdapter(object) + class AgentCardDiscoveryError(Exception): """Raised when none of the well-known paths returned a usable agent card.""" @@ -87,7 +92,7 @@ async def fetch_well_known_card( params: Mapping[str, object] | None = None, timeout: float = DEFAULT_DISCOVERY_TIMEOUT_SECONDS, headers: dict[str, str] | None = None, -) -> dict[str, Any]: +) -> dict[str, object]: """ Fetch an agent card from ``base_url`` using the strategy chosen by ``discovery_mode``. Returns the parsed JSON from the first path that @@ -137,13 +142,14 @@ async def fetch_well_known_card( continue try: - card = response.json() + decoded = _DECODED_JSON.validate_python(response.json()) except Exception as exc: last_error = f"{url}: invalid JSON ({exc})" continue + card = as_str_mapping(decoded) if not isinstance(card, dict): - last_error = f"{url}: expected JSON object, got {type(card).__name__}" + last_error = f"{url}: expected JSON object, got {type(decoded).__name__}" continue verbose_proxy_logger.debug("A2A discovery succeeded at %s", url) diff --git a/litellm/proxy/agent_endpoints/a2a_endpoints.py b/litellm/proxy/agent_endpoints/a2a_endpoints.py index c11d296837e..4691c7b0bc5 100644 --- a/litellm/proxy/agent_endpoints/a2a_endpoints.py +++ b/litellm/proxy/agent_endpoints/a2a_endpoints.py @@ -23,6 +23,7 @@ from pydantic import TypeAdapter, ValidationError import litellm from litellm._logging import verbose_proxy_logger +from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.litellm_core_utils.url_utils import SSRFError, validate_url from litellm.llms.a2a.common_utils import resolve_a2a_hop_auth_header from litellm.proxy._types import UserAPIKeyAuth @@ -281,7 +282,7 @@ async def _a2a_sse_event_source( request_id: str | int | None = None, extra_headers: Mapping[str, str] | None = None, served_version: A2AVersion = "0.3", -) -> AsyncGenerator[Mapping[str, object], None]: +) -> AsyncGenerator[object, None]: """Stream an upstream A2A SSE response as parsed JSON-RPC event dicts. Upstream HTTP/JSON-RPC errors are surfaced as a single JSON-RPC error event @@ -327,12 +328,14 @@ async def _a2a_sse_event_source( if not payload: continue try: - event = json.loads(payload) + event = _DECODED_JSON.validate_python(json.loads(payload)) except Exception: continue - if isinstance(event, dict): - event = normalize_stream_event(event, served_version, request_id=request_id) - yield event + event_fields = as_str_mapping(event) + if isinstance(event_fields, dict): + yield normalize_stream_event(event_fields, served_version, request_id=request_id) + else: + yield event finally: await resp.aclose() @@ -741,7 +744,7 @@ async def invoke_agent_a2a( # Get backend URL and agent name agent_card_params: Final = agent.agent_card_params or {} agent_url: Final = agent_card_params.get("url") - agent_name: Final = agent_card_params.get("name", agent_id) + agent_name: Final = (as_str_mapping(agent_card_params) or {}).get("name", agent_id) # Get litellm_params (may include custom_llm_provider for completion bridge) litellm_params: dict[str, object] = agent.litellm_params or {} diff --git a/litellm/proxy/agent_endpoints/a2a_routing.py b/litellm/proxy/agent_endpoints/a2a_routing.py index 9a6f674db2c..fb727367caf 100644 --- a/litellm/proxy/agent_endpoints/a2a_routing.py +++ b/litellm/proxy/agent_endpoints/a2a_routing.py @@ -18,6 +18,7 @@ from litellm.a2a_protocol.litellm_completion_bridge.handler import ( bridge_model_name, ) from litellm.constants import A2A_CHAT_COMPLETION_BRIDGE_PROVIDERS +from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth from litellm.proxy.agent_endpoints.databricks_oauth import ( resolve_databricks_backend_auth, @@ -173,13 +174,14 @@ async def route_a2a_agent_request( return _call_route(route_type, _bridge_agent_request(data, agent, bridge_auth.litellm_params)) # Get API base URL from agent config - if not agent.agent_card_params or "url" not in agent.agent_card_params: + card_params: Final = as_str_mapping(agent.agent_card_params) + if not card_params or "url" not in card_params: verbose_proxy_logger.error("[A2A] Agent '%s' has no URL configured", agent_name) route_name = ROUTE_ENDPOINT_MAPPING.get(route_type, route_type) raise ProxyModelNotFoundError(route=route_name, model_name=model_name, retryable_with_model_read_through=False) # Inject API base and route to litellm - data["api_base"] = agent.agent_card_params["url"] + data["api_base"] = card_params["url"] verbose_proxy_logger.debug("[A2A] Routing %s to %s", model_name, data["api_base"]) return _call_route(route_type, data) diff --git a/litellm/proxy/agent_endpoints/auth/agent_permission_handler.py b/litellm/proxy/agent_endpoints/auth/agent_permission_handler.py index dd002a2763e..9be9d4c7121 100644 --- a/litellm/proxy/agent_endpoints/auth/agent_permission_handler.py +++ b/litellm/proxy/agent_endpoints/auth/agent_permission_handler.py @@ -16,7 +16,6 @@ from fastapi import HTTPException from pydantic import TypeAdapter, ValidationError from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.ui_session_utils import build_effective_auth_contexts from litellm.proxy._types import ( UI_TEAM_ID, LiteLLM_ObjectPermissionTable, @@ -30,6 +29,7 @@ from litellm.proxy.agent_endpoints.auth.agent_access_groups import ( ) from litellm.proxy.agent_endpoints.auth.agent_caller import agent_caller_auth from litellm.proxy.agent_endpoints.auth.managed_authorization import managed_agent_policy +from litellm.proxy.mcp_server.ui_session_utils import build_effective_auth_contexts from litellm.repositories.table_repositories import AgentsRepository from litellm.types.agents import AgentResponse @@ -244,7 +244,7 @@ class AgentRequestHandler: or user_api_key_auth is None ): return False - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler key_hash: Final = user_api_key_auth.api_key or user_api_key_auth.token authority: Final = ( @@ -905,7 +905,7 @@ async def _managed_actor_agent_access(auth: UserAPIKeyAuth) -> AgentAccess: async def _verified_human_agent_sources( user_id: str | None, *, allowed_team_ids: frozenset[str] | None = None ) -> tuple[tuple[str | None, frozenset[str]], ...]: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler if user_id is None: return () diff --git a/litellm/proxy/agent_endpoints/databricks_oauth.py b/litellm/proxy/agent_endpoints/databricks_oauth.py index 7425c240d10..bebba009d82 100644 --- a/litellm/proxy/agent_endpoints/databricks_oauth.py +++ b/litellm/proxy/agent_endpoints/databricks_oauth.py @@ -48,6 +48,7 @@ _DEFAULT_SCOPE: Final = "all-apis" _TOKEN_EXPIRY_BUFFER_SECONDS: Final = 60 _DEFAULT_TTL_SECONDS: Final = 3600 _OAUTH_BLOCK: Final = TypeAdapter(Mapping[str, object]) +_TOKEN_RESPONSE_BODY: Final = TypeAdapter(object) def _resolve_secret(value: object) -> str | None: @@ -275,7 +276,7 @@ class DatabricksAppOAuthTokenCache(InMemoryCache): except httpx.HTTPError as exc: raise ValueError(f"Databricks App OAuth token request failed: {exc}") from exc - body: Final[object] = response.json() + body: Final = _TOKEN_RESPONSE_BODY.validate_python(response.json()) if not isinstance(body, dict): raise ValueError( f"Databricks App OAuth token response returned non-object JSON (got {type(body).__name__})" diff --git a/litellm/proxy/agent_endpoints/managed_identity.py b/litellm/proxy/agent_endpoints/managed_identity.py index abab21901ee..fab7ebbc61d 100644 --- a/litellm/proxy/agent_endpoints/managed_identity.py +++ b/litellm/proxy/agent_endpoints/managed_identity.py @@ -119,6 +119,10 @@ def managed_write_fields( return AgentIdentityFailure(message=f"Invalid agent identity configuration: {exc}") +def _identity_fields(identity: EntraIdentityConfig) -> Mapping[str, object]: + return identity.model_dump() + + def _identity_write(identity: EntraIdentityConfig | None, existing: AgentResponse | None) -> ManagedWriteFields: if identity is None: unbind: Final[ManagedWriteFields] = { @@ -134,7 +138,7 @@ def _identity_write(identity: EntraIdentityConfig | None, existing: AgentRespons existing and existing.identity and existing.identity.active - and all(getattr(existing.identity, name) == value for name, value in identity.model_dump().items()) + and all(getattr(existing.identity, name) == value for name, value in _identity_fields(identity).items()) ): unchanged: Final[ManagedWriteFields] = {} return unchanged diff --git a/litellm/proxy/agent_endpoints/model_list_helpers.py b/litellm/proxy/agent_endpoints/model_list_helpers.py index 4a88644bae5..447b4f52aaf 100644 --- a/litellm/proxy/agent_endpoints/model_list_helpers.py +++ b/litellm/proxy/agent_endpoints/model_list_helpers.py @@ -51,7 +51,7 @@ async def append_agents_to_model_group( async def append_agents_to_model_info( models: list[dict], user_api_key_dict: UserAPIKeyAuth, -) -> list[dict]: +) -> list[dict[str, object]]: """ Append A2A agents to model info list for UI display. diff --git a/litellm/proxy/anthropic_endpoints/claude_code_endpoints/claude_code_marketplace.py b/litellm/proxy/anthropic_endpoints/claude_code_endpoints/claude_code_marketplace.py index 8e348423837..b0088d93112 100644 --- a/litellm/proxy/anthropic_endpoints/claude_code_endpoints/claude_code_marketplace.py +++ b/litellm/proxy/anthropic_endpoints/claude_code_endpoints/claude_code_marketplace.py @@ -21,6 +21,7 @@ import json import re from collections.abc import Mapping, Sequence from datetime import datetime, timezone +from types import MappingProxyType from typing import Annotated, Final, Protocol, TypedDict, get_args from urllib.parse import urlsplit @@ -299,7 +300,7 @@ def _validate_installation_preference(spec: PluginSpec) -> None: def _build_plugin_manifest(name: str, spec: PluginSpec) -> Mapping[str, object]: """Build the stored manifest dict shared by plugin create and update.""" - dumped: Final[Mapping[str, object]] = spec.model_dump(exclude_none=True) + dumped: Final[Mapping[str, object]] = MappingProxyType(spec.model_dump(exclude_none=True)) return {"name": name, **{key: value for key, value in dumped.items() if value and key != "name"}} diff --git a/litellm/proxy/anthropic_endpoints/endpoints.py b/litellm/proxy/anthropic_endpoints/endpoints.py index b12676e08f3..3d2f89be15f 100644 --- a/litellm/proxy/anthropic_endpoints/endpoints.py +++ b/litellm/proxy/anthropic_endpoints/endpoints.py @@ -19,7 +19,7 @@ from litellm.anthropic_interface.exceptions import ( ) from litellm.integrations.custom_guardrail import ModifyResponseException from litellm.litellm_core_utils.tool_fields import first_validation_error -from litellm.llms.anthropic.pass_through.context_management import ( +from litellm.llms.anthropic.messages.context_management import ( AnthropicContextManagementError, ) from litellm.llms.base_llm.guardrail_translation.utils import ( diff --git a/litellm/proxy/anthropic_endpoints/gateway_endpoints.py b/litellm/proxy/anthropic_endpoints/gateway_endpoints.py index 4c4155379cd..1911cb574ef 100644 --- a/litellm/proxy/anthropic_endpoints/gateway_endpoints.py +++ b/litellm/proxy/anthropic_endpoints/gateway_endpoints.py @@ -37,18 +37,6 @@ from litellm.constants import ( CLI_SSO_SESSION_TTL_SECONDS, LITELLM_CLI_SOURCE_IDENTIFIER, ) -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( - PROXY_API_AUDIENCE, - MintedProxyCredential, - MintProxyCredential, - SessionSigning, - proxy_credential_response, - refresh_proxy_credential, - resolve_session_signing, - revoke_session_refresh_token, -) -from litellm.proxy._experimental.mcp_server.oauth_utils import TOKEN_NO_CACHE_HEADERS -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import SessionPrincipal from litellm.proxy._types import LiteLLM_UserTable, LitellmUserRoles from litellm.proxy.anthropic_endpoints.endpoints import anthropic_response, count_tokens from litellm.proxy.auth.user_api_key_auth import user_api_key_auth @@ -58,6 +46,19 @@ from litellm.proxy.common_utils.http_parsing_utils import ( # noqa: F401 # leg ) from litellm.proxy.management_endpoints.sso_helper_utils import CLI_SSO_SESSIONS_TARGET from litellm.proxy.management_endpoints.ui_sso import CliSsoTeamDetail +from litellm.proxy.mcp_server.gateway_dcr_flow import ( + PROXY_API_AUDIENCE, + MintedProxyCredential, + MintProxyCredential, + SessionSigning, + proxy_credential_response, + refresh_proxy_credential, + resolve_session_signing, + revoke_session_refresh_token, +) +from litellm.proxy.mcp_server.oauth_utils import TOKEN_NO_CACHE_HEADERS +from litellm.proxy.mcp_server.outbound_credentials.session_token import SessionPrincipal +from litellm.proxy.proxy_server import model_list from litellm.types.llms.base import LiteLLMBaseModel GATEWAY_PREFIX: Final = "/claude_code_gateway" @@ -158,6 +159,13 @@ router: Final = APIRouter( _GATEWAY_ENABLED: Final = (Depends(ensure_gateway_enabled),) _AUTHENTICATED: Final = (Depends(user_api_key_auth),) +router.add_api_route( + "/v1/models", + model_list, + methods=["GET"], + dependencies=_GATEWAY_ENABLED, + include_in_schema=False, +) router.add_api_route( "/v1/messages", anthropic_response, @@ -332,7 +340,7 @@ async def _claim_device_code(login_id: str, cache: DualCache) -> bool: def _proxy_credential_minter() -> MintProxyCredential: - from litellm.proxy._experimental.mcp_server.proxy_api_credentials import mint_proxy_credential + from litellm.proxy.mcp_server.proxy_api_credentials import mint_proxy_credential return mint_proxy_credential diff --git a/litellm/proxy/auth/auth_checks.py b/litellm/proxy/auth/auth_checks.py index 8887d86570a..448643ef59b 100644 --- a/litellm/proxy/auth/auth_checks.py +++ b/litellm/proxy/auth/auth_checks.py @@ -15,6 +15,7 @@ import re import time from collections.abc import Awaitable, Callable, Iterator, Mapping, Sequence from dataclasses import dataclass +from datetime import datetime from functools import partial from itertools import chain from types import MappingProxyType @@ -47,6 +48,7 @@ from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider from litellm.litellm_core_utils.safe_json_loads import safe_json_loads from litellm.models.project import LiteLLM_ProjectTable from litellm.proxy._types import ( + MODEL_LIST_ROUTES, RBAC_ROLES, UI_TEAM_ID, CallInfo, @@ -393,7 +395,7 @@ def _member_allowed_models(membership: _TeamMembershipModelScope) -> Sequence[st class _RawCacheRead(Protocol): - async def async_get_cache(self, *, key: str) -> object: ... + async def async_get_cache(self, *, key: str, local_only: bool = ...) -> object: ... def _raw_cache(cache: _RawCacheRead) -> _RawCacheRead: @@ -910,8 +912,7 @@ def _global_proxy_budget_check(global_proxy_spend: float | None, skip_budget_che and not skip_budget_checks and global_proxy_spend is not None and RouteChecks.is_llm_api_route(route=route) - and route != "/v1/models" - and route != "/models" + and route not in MODEL_LIST_ROUTES ): if math.isfinite(litellm.max_budget) and global_proxy_spend > litellm.max_budget: raise litellm.BudgetExceededError( @@ -1028,8 +1029,7 @@ async def check_tools_allowlist( # budget cannot reach side-effectful routes like /health/services (Slack/email/webhook). See #27923. MODEL_DISCOVERY_ROUTES: Final = frozenset( { - "/v1/models", - "/models", + *MODEL_LIST_ROUTES, "/model/info", "/v1/model/info", "/v2/model/info", @@ -1800,6 +1800,20 @@ async def get_team_member_default_budget( return budget +def resolve_effective_team_member_budget( + member_budget: LiteLLM_BudgetTable | None, + team_default_budget: LiteLLM_BudgetTable | None, + now: datetime, +) -> float | None: + if member_budget is not None and member_budget.max_budget is not None: + return member_budget.effective_max_budget(now) + if team_default_budget is None or team_default_budget.max_budget is None or team_default_budget.max_budget <= 0: + return None + return team_default_budget.max_budget + ( + member_budget.active_temp_budget_increase(now) if member_budget is not None else 0.0 + ) + + async def resolve_default_end_user_budget( prisma_client: PrismaClient, user_api_key_cache: UserApiKeyCache, @@ -2712,7 +2726,7 @@ async def get_team_membership( use_writer=True, ) - l1_cached: Final[object] = await user_api_key_cache.async_get_cache(key=_key, local_only=True) + l1_cached: Final = await _raw_cache(user_api_key_cache).async_get_cache(key=_key, local_only=True) l1_membership: Final = _membership_from_cached_payload(l1_cached) if not isinstance(l1_membership, _TeamMembershipCacheMiss): return l1_membership @@ -6447,8 +6461,29 @@ def _search_tool_deny_by_default(general_settings: Mapping[str, object]) -> bool return True +def _is_dashboard_session(valid_token: UserAPIKeyAuth | None) -> bool: + return valid_token is not None and valid_token.team_id == UI_TEAM_ID + + +def _is_search_tool_strict_identity(valid_token: UserAPIKeyAuth) -> bool: + if not _is_dashboard_session(valid_token): + return _is_strict_grant_identity(valid_token) + return valid_token.user_role not in ( + LitellmUserRoles.PROXY_ADMIN, + LitellmUserRoles.PROXY_ADMIN_VIEW_ONLY, + ) + + +def _search_tool_strict_layers( + valid_token: UserAPIKeyAuth, team_object: LiteLLM_TeamTable | None +) -> frozenset[GrantLayer]: + if _is_dashboard_session(valid_token): + return frozenset(("user",)) + return _strict_grant_layers(True, valid_token, team_object) + + def is_search_tool_deny_by_default_applied(valid_token: UserAPIKeyAuth, general_settings: Mapping[str, object]) -> bool: - return _search_tool_deny_by_default(general_settings) and _is_strict_grant_identity(valid_token) + return _search_tool_deny_by_default(general_settings) and _is_search_tool_strict_identity(valid_token) def _search_tool_denied(object_type: GrantLayer, message: str) -> ProxyException: @@ -6492,12 +6527,12 @@ async def resolve_search_tool_grants( load_team_object: TeamObjectLoader, ) -> SearchToolGrants: """ - Without `general_settings.search_tool_deny_by_default`, or for the master key and dashboard sessions, + Without `general_settings.search_tool_deny_by_default`, or for the master key and admin dashboard sessions, the key and team lists only restrict when nonempty. With it, the identities `_strict_grant_layers` names must each list the tool, and a missing record, `null`, `[]`, or a team or user that fails to load grants nothing """ if not is_search_tool_deny_by_default_applied(valid_token, general_settings): - team_object: Final = await load_team_object() + team_object: Final = await load_team_object() if not _is_dashboard_session(valid_token) else None return SearchToolGrants( grants=MappingProxyType( {"key": valid_token.object_permission, "team": team_object.object_permission if team_object else None} @@ -6507,8 +6542,10 @@ async def resolve_search_tool_grants( from litellm.proxy.proxy_server import prisma_client, user_api_key_cache - strict_team_object: Final = await _strict_team_object(load_team_object) - strict_layers: Final = _strict_grant_layers(True, valid_token, strict_team_object) + strict_team_object: Final = ( + await _strict_team_object(load_team_object) if not _is_dashboard_session(valid_token) else None + ) + strict_layers: Final = _search_tool_strict_layers(valid_token, strict_team_object) if prisma_client is None: return SearchToolGrants(grants=MappingProxyType({}), strict_layers=strict_layers) user_object: Final = ( @@ -6593,7 +6630,7 @@ def check_unregistered_search_fallback( """The unregistered provider fallback names no search tool that a grant could list, so deny-by-default denies it""" if not is_search_tool_deny_by_default_applied(valid_token, general_settings): return True - layer: Final = min(_strict_grant_layers(True, valid_token, None), key=("key", "team", "user").index) + layer: Final = min(_search_tool_strict_layers(valid_token, None), key=("key", "team", "user").index) raise _search_tool_denied( layer, "No registered search tool is available and search_tool_deny_by_default is enabled", @@ -7035,29 +7072,24 @@ async def _check_team_member_budget( # Per-member override wins; otherwise fall back to the team-level # default configured via team.metadata["team_member_budget_id"]. - team_member_budget: float | None = None member_budget_row: Final = loaded_membership.litellm_budget_table if loaded_membership is not None else None now: Final = get_utc_datetime() - if member_budget_row is not None and member_budget_row.max_budget is not None: - team_member_budget = member_budget_row.effective_max_budget(now=now) - else: - default_budget_id: Final = (team_object.metadata or {}).get("team_member_budget_id") - if isinstance(default_budget_id, str): - default_budget: Final = await get_team_member_default_budget( - budget_id=default_budget_id, - prisma_client=prisma_client, - user_api_key_cache=user_api_key_cache, - ) - # Treat 0 on the team default as "no cap". - # Per-member rows still respect 0 as an explicit admin disable. - if ( - default_budget is not None - and default_budget.max_budget is not None - and default_budget.max_budget > 0 - ): - team_member_budget = default_budget.max_budget + ( - member_budget_row.active_temp_budget_increase(now=now) if member_budget_row is not None else 0.0 - ) + default_budget_id: Final = (team_object.metadata or {}).get("team_member_budget_id") + team_default_budget: Final = ( + await get_team_member_default_budget( + budget_id=default_budget_id, + prisma_client=prisma_client, + user_api_key_cache=user_api_key_cache, + ) + if (member_budget_row is None or member_budget_row.max_budget is None) + and isinstance(default_budget_id, str) + else None + ) + team_member_budget: Final = resolve_effective_team_member_budget( + member_budget=member_budget_row, + team_default_budget=team_default_budget, + now=now, + ) if team_member_budget is not None: team_member_spend = (loaded_membership.spend if loaded_membership is not None else 0.0) or 0.0 diff --git a/litellm/proxy/auth/auth_exception_handler.py b/litellm/proxy/auth/auth_exception_handler.py index f6637a1fdf3..ed743764fce 100644 --- a/litellm/proxy/auth/auth_exception_handler.py +++ b/litellm/proxy/auth/auth_exception_handler.py @@ -12,7 +12,7 @@ import litellm from litellm._logging import verbose_proxy_logger, verbose_proxy_stdout_logger from litellm.constants import EMPTY_MAPPING from litellm.integrations.otel.runtime import seed_request_identity -from litellm.litellm_core_utils.core_helpers import is_expected_client_error +from litellm.litellm_core_utils.core_helpers import as_str_mapping, is_expected_client_error from litellm.proxy._types import ( LitellmUserRoles, ModelAccessDeniedProxyException, @@ -24,6 +24,7 @@ from litellm.proxy.auth.auth_utils import ( # noqa: F401 # legacy module expor _get_request_ip_address, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export get_request_ip_address, is_invalid_virtual_key_error, + is_unauthorized_error, mark_invalid_virtual_key_error, normalize_request_route, ) @@ -139,7 +140,7 @@ class UserAPIKeyAuthExceptionHandler: async def handle_authentication_error( e: Exception, request: Request, - request_data: dict[str, object], + request_data: object, route: str, parent_otel_span: Span | None, api_key: str, @@ -190,6 +191,8 @@ class UserAPIKeyAuthExceptionHandler: request_route=route, ) else: + request_mapping: Final = as_str_mapping(request_data) + request_context: Final[dict[str, object]] = dict(request_mapping) if request_mapping is not None else {} # raise the exception to the caller requester_ip: Final = get_request_ip_address( request=request, @@ -198,11 +201,11 @@ class UserAPIKeyAuthExceptionHandler: user_agent: Final = _get_user_agent(request) # Log authentication failures before identity seeding and callbacks, so the log - # survives a raising callback pipeline. Classify and route malformed virtual-key - # rejections to WARNING on stdout (suppressible via LITELLM_LOG=ERROR). + # survives a raising callback pipeline. Route 401 rejections to WARNING on stdout + # (suppressible via LITELLM_LOG=ERROR); anything else is unexpected and logs at ERROR. log_extra: Final = {"requester_ip": requester_ip} is_invalid_virtual_key: Final = is_invalid_virtual_key_error(e) - is_quiet_log: Final = is_invalid_virtual_key and not litellm.log_client_error_tracebacks + is_quiet_log: Final = is_unauthorized_error(e) and not litellm.log_client_error_tracebacks logger: Final = verbose_proxy_stdout_logger if is_quiet_log else verbose_proxy_logger logger.log( logging.WARNING if is_quiet_log else logging.ERROR, @@ -229,7 +232,7 @@ class UserAPIKeyAuthExceptionHandler: # without this the failed trace would carry no team/key attributes. seed_request_identity( user_api_key_dict, - model=request_data.get("model"), + model=request_context.get("model"), ) # Budget checks live in tenant-scoped helpers (key / team / org / tag) @@ -242,14 +245,14 @@ class UserAPIKeyAuthExceptionHandler: resolve_llm_provider_for_rate_limit, ) - budget_model: Final = request_data.get("model") + budget_model: Final = request_context.get("model") _, e.llm_provider = resolve_llm_provider_for_rate_limit( budget_model if isinstance(budget_model, str) else None ) # Allow callbacks to transform the error response transformed_exception: Final = await proxy_logging_obj.post_call_failure_hook( - request_data=_with_client_context(request_data, requester_ip, user_agent), + request_data=_with_client_context(request_context, requester_ip, user_agent), original_exception=e, user_api_key_dict=user_api_key_dict, error_type=ProxyErrorTypes.auth_error, diff --git a/litellm/proxy/auth/auth_utils.py b/litellm/proxy/auth/auth_utils.py index 7a186d84aa5..aa6ddae438d 100644 --- a/litellm/proxy/auth/auth_utils.py +++ b/litellm/proxy/auth/auth_utils.py @@ -48,6 +48,16 @@ from litellm.types.utils import CustomPricingLiteLLMParams, oauth_token_exchange from litellm.types.videos.main import DecodedVideoId +def is_unauthorized_error(exception: BaseException | None) -> bool: + """True when the proxy itself rejected the caller's credentials with a 401.""" + if not isinstance(exception, (HTTPException, ProxyException)): + return False + + code: Final[object] = getattr(exception, "code", None) + status_code: Final[object] = code if code is not None else getattr(exception, "status_code", None) + return str(status_code) == str(status.HTTP_401_UNAUTHORIZED) + + def is_invalid_virtual_key_error(exception: BaseException | None) -> bool: """True when an authentication error rejects a malformed virtual key. @@ -57,15 +67,7 @@ def is_invalid_virtual_key_error(exception: BaseException | None) -> bool: match would let a request body demote an authorization failure to the quiet log path. """ - if not isinstance(exception, (HTTPException, ProxyException)): - return False - - code: Final[object] = getattr(exception, "code", None) - status_code: Final[object] = code if code is not None else getattr(exception, "status_code", None) - if str(status_code) != str(status.HTTP_401_UNAUTHORIZED): - return False - - return getattr(exception, INVALID_VIRTUAL_KEY_ERROR_MARKER, False) is True + return is_unauthorized_error(exception) and getattr(exception, INVALID_VIRTUAL_KEY_ERROR_MARKER, False) is True def log_model_access_denial(exc: BaseException) -> None: @@ -736,7 +738,9 @@ def is_request_body_safe( def _reject_request_credential_params(litellm_params: Mapping[str, object], *, manages_deployments: bool) -> None: if manages_deployments: - reject_server_owned_wif_fields(litellm_params) + reject_server_owned_wif_fields( + MappingProxyType({key: value for key, value in litellm_params.items() if key != "chatgpt_auth_file"}) + ) else: reject_server_owned_wif_params(litellm_params) reject_federated_credential_reference(litellm_params) @@ -924,8 +928,9 @@ def get_request_route(request: Request) -> str: scope: Final = request.scope if not isinstance(scope, dict): return str(request.url.path) - raw_path: Final[str] = str(scope.get("path", request.url.path)) - root_path: Final[str] = str(scope.get("app_root_path", scope.get("root_path", ""))).rstrip("/") + scope_fields: Final[Mapping[str, object]] = MappingProxyType(scope) + raw_path: Final[str] = str(scope_fields.get("path", request.url.path)) + root_path: Final[str] = str(scope_fields.get("app_root_path", scope_fields.get("root_path", ""))).rstrip("/") if not isinstance(raw_path, str): return str(request.url.path) # Strip root_path only when it matches whole path segments — guarding @@ -1520,8 +1525,15 @@ def get_model_rate_limit_from_metadata( metadata_accessor_key: Literal["team_metadata", "organization_metadata", "project_metadata"], rate_limit_key: Literal["model_rpm_limit", "model_tpm_limit", "model_itpm_limit", "model_otpm_limit"], ) -> dict[str, int] | None: - if getattr(user_api_key_dict, metadata_accessor_key): - return getattr(user_api_key_dict, metadata_accessor_key).get(rate_limit_key) + metadata: Final = ( + user_api_key_dict.team_metadata + if metadata_accessor_key == "team_metadata" + else user_api_key_dict.organization_metadata + if metadata_accessor_key == "organization_metadata" + else user_api_key_dict.project_metadata + ) + if metadata: + return metadata.get(rate_limit_key) return None diff --git a/litellm/proxy/auth/ip_address_utils.py b/litellm/proxy/auth/ip_address_utils.py index f1ca2c70f3b..0b349e6a733 100644 --- a/litellm/proxy/auth/ip_address_utils.py +++ b/litellm/proxy/auth/ip_address_utils.py @@ -283,7 +283,7 @@ class IPAddressUtils: @staticmethod def get_mcp_client_ip( request: Request, - general_settings: dict[str, Any] | None = None, + general_settings: dict[str, object] | None = None, ) -> str | None: """ Extract client IP from a FastAPI request for MCP access control. @@ -371,4 +371,4 @@ class IPAddressUtils: return client_ip case _HopCountUnset(): pass - return get_request_ip_address(request, use_x_forwarded_for=use_xff) + return get_request_ip_address(request, use_x_forwarded_for=use_xff is True) diff --git a/litellm/proxy/auth/rds_iam_token.py b/litellm/proxy/auth/rds_iam_token.py index a9f349d1750..e291c78294c 100644 --- a/litellm/proxy/auth/rds_iam_token.py +++ b/litellm/proxy/auth/rds_iam_token.py @@ -3,7 +3,7 @@ import re from collections.abc import Mapping from dataclasses import dataclass from types import MappingProxyType -from typing import Any, Final +from typing import Final, Protocol import httpx @@ -223,11 +223,15 @@ def rds_region_from_hostname(db_host: str) -> str | None: return match.group("region").lower() +class _RdsAuthTokenClient(Protocol): + def generate_db_auth_token(self, *, DBHostname: str, Port: str, DBUsername: str, Region: str | None) -> str: ... + + def generate_iam_auth_token( db_host: str, db_port: str, db_user: str, - client: Any | None = None, + client: _RdsAuthTokenClient | None = None, *, region: str | None = None, ) -> str: diff --git a/litellm/proxy/auth/route_checks.py b/litellm/proxy/auth/route_checks.py index 720bfabb95a..74e4c4c6d11 100644 --- a/litellm/proxy/auth/route_checks.py +++ b/litellm/proxy/auth/route_checks.py @@ -7,12 +7,15 @@ from fastapi import HTTPException, Request, status from litellm._logging import verbose_proxy_logger from litellm.proxy._types import ( + MODEL_LIST_ROUTES, UI_TEAM_ID, CommonProxyErrors, KeyManagementRoutes, LiteLLM_UserTable, LiteLLMRoutes, LitellmUserRoles, + ProxyErrorTypes, + ProxyException, UserAPIKeyAuth, ) @@ -93,8 +96,7 @@ _SELF_SCOPED_CREDENTIAL_ROUTES: Final = ( _UNBILLED_ROUTES: Final[frozenset[str]] = frozenset( { - "/models", - "/v1/models", + *MODEL_LIST_ROUTES, "/utils/token_counter", "/utils/transform_request", "/responses/input_tokens", @@ -160,7 +162,7 @@ class RouteChecks: if allowed_route in LiteLLMRoutes._member_names_: if RouteChecks.check_route_access( route=route, - allowed_routes=LiteLLMRoutes._member_map_[allowed_route].value, + allowed_routes=LiteLLMRoutes[allowed_route].value, ): if ( allowed_route in _AUTH_ENFORCED_PASS_THROUGH_ROUTE_GROUPS @@ -284,7 +286,7 @@ class RouteChecks: route (str): The route being accessed Raises: - Exception: With user role and masked user_id information + ProxyException: 401 with user role and masked user_id information """ user_role = "unknown" user_id = "unknown" @@ -293,8 +295,14 @@ class RouteChecks: user_id = user_obj.user_id or "unknown" masked_user_id: Final = RouteChecks._mask_user_id(user_id) - raise Exception( - f"Only proxy admin can be used to generate, delete, update info for new keys/users/teams. Route={route}. Your role={user_role}. Your user_id={masked_user_id}" + raise ProxyException( + message=( + "Authentication Error, Only proxy admin can be used to generate, delete, update info for new " + f"keys/users/teams. Route={route}. Your role={user_role}. Your user_id={masked_user_id}" + ), + type=ProxyErrorTypes.auth_error, + param="None", + code=status.HTTP_401_UNAUTHORIZED, ) @staticmethod diff --git a/litellm/proxy/auth/ui_session_models.py b/litellm/proxy/auth/ui_session_models.py index a09899ad931..845d2a3e23b 100644 --- a/litellm/proxy/auth/ui_session_models.py +++ b/litellm/proxy/auth/ui_session_models.py @@ -7,9 +7,6 @@ from dataclasses import dataclass from typing import TYPE_CHECKING, Final from litellm.constants import UI_SESSION_TOKEN_TEAM_ID -from litellm.proxy._experimental.mcp_server.ui_session_utils import ( - is_ui_session_credential, -) from litellm.proxy._types import ( LiteLLM_TeamMembership, LiteLLM_TeamTableCachedObj, @@ -33,6 +30,7 @@ from litellm.proxy.auth.resolvers.grants import ( user_models, ) from litellm.proxy.auth.team_grants import team_grants +from litellm.proxy.mcp_server.ui_session_utils import is_ui_session_credential from litellm.types.proxy.management_endpoints.model_management_endpoints import ( ModelGroupTeam, ) diff --git a/litellm/proxy/auth/user_api_key_auth.py b/litellm/proxy/auth/user_api_key_auth.py index 25354384392..556fef6a36f 100644 --- a/litellm/proxy/auth/user_api_key_auth.py +++ b/litellm/proxy/auth/user_api_key_auth.py @@ -13,6 +13,7 @@ import re import secrets from collections.abc import Mapping, Sequence from datetime import datetime, timezone +from types import MappingProxyType from typing import Final, NamedTuple, Protocol, Union, cast import fastapi @@ -177,6 +178,7 @@ from litellm.proxy.utils import ( normalize_route_for_root_path, ) from litellm.repositories.table_repositories import JWTKeyMappingRepository, TeamMembershipRepository +from litellm.repositories.user_repository import UserRepository from litellm.repositories.verification_token_repository import VerificationTokenRepository from litellm.router_utils.common_utils import resolve_model_group_alias, resolve_served_model from litellm.router_utils.fallback_event_handlers import ( @@ -1319,7 +1321,7 @@ async def fetch_global_spend_with_event_coordination( async def _load_global_spend() -> float | None: proxy_budget_row: Final = await bounded_db_lookup( - prisma_client.db.litellm_usertable.find_unique(where={"user_id": LITELLM_PROXY_BUDGET_NAME}), + UserRepository(prisma_client).table.find_unique(where={"user_id": LITELLM_PROXY_BUDGET_NAME}), name="proxy_budget", ) return float(proxy_budget_row.spend) if proxy_budget_row is not None else None @@ -1635,7 +1637,7 @@ async def _auto_register_jwt_mapping( if minted: try: async with db_span("delete_orphaned_jwt_key", "LiteLLM_VerificationToken"): - await prisma_client.db.litellm_verificationtoken.delete(where={"token": token_hash}) + await VerificationTokenRepository(prisma_client).table.delete(where={"token": token_hash}) except Exception as delete_err: # Don't fail the request if cleanup fails — the orphan is # unmapped and inert. Log so an operator can prune it later. @@ -2511,10 +2513,20 @@ async def user_api_key_auth_builder( parent_otel_span=parent_otel_span, ) elif api_key is None: # only require api key if master key is set - raise Exception("No api key passed in.") + raise ProxyException( + message="Authentication Error, No api key passed in.", + type=ProxyErrorTypes.auth_error, + param="None", + code=status.HTTP_401_UNAUTHORIZED, + ) elif api_key == "": # missing 'Bearer ' prefix - raise Exception("Malformed API Key passed in. Ensure Key has `Bearer ` prefix.") + raise ProxyException( + message="Authentication Error, Malformed API Key passed in. Ensure Key has `Bearer ` prefix.", + type=ProxyErrorTypes.auth_error, + param="None", + code=status.HTTP_401_UNAUTHORIZED, + ) if route == "/user/auth": if general_settings.get("allow_user_auth", False) is True: @@ -2693,7 +2705,7 @@ async def user_api_key_auth_builder( and valid_token.last_refreshed_at is not None and team_obj.last_refreshed_at > valid_token.last_refreshed_at ): - team_obj_dict: Final = team_obj.__dict__ + team_obj_dict: Final[Mapping[str, object]] = MappingProxyType(team_obj.__dict__) for k, v in team_obj_dict.items(): field_name = f"team_{k}" @@ -2750,7 +2762,12 @@ async def user_api_key_auth_builder( ## IF it's not a master key ## Route should not be in master_key_only_routes if route in LiteLLMRoutes.master_key_only_routes.value: - raise Exception(f"Tried to access route={route}, which is only for MASTER KEY") + raise ProxyException( + message=f"Authentication Error, Tried to access route={route}, which is only for MASTER KEY", + type=ProxyErrorTypes.auth_error, + param="None", + code=status.HTTP_401_UNAUTHORIZED, + ) ## Check DB @@ -2878,7 +2895,12 @@ async def validate_resolved_virtual_key( # noqa: C901 # Preserve ordering of e ## base case ## key is disabled if valid_token.blocked is True: - raise Exception("Key is blocked. Update via `/key/unblock` if you're an admin.") + raise ProxyException( + message="Authentication Error, Key is blocked. Update via `/key/unblock` if you're an admin.", + type=ProxyErrorTypes.auth_error, + param="None", + code=status.HTTP_401_UNAUTHORIZED, + ) if RouteChecks.is_llm_api_route(route=route): from litellm.proxy.auth.ui_session_models import load_ui_session_model_sources @@ -2946,8 +2968,14 @@ async def validate_resolved_virtual_key( # noqa: C901 # Preserve ordering of e and isinstance(user_obj.metadata, dict) and user_obj.metadata.get("scim_active") is False ): - raise Exception( - f"User={valid_token.user_id} has been deactivated via SCIM. Keys owned by this user cannot be used." + raise ProxyException( + message=( + f"Authentication Error, User={valid_token.user_id} has been deactivated via SCIM. " + "Keys owned by this user cannot be used." + ), + type=ProxyErrorTypes.auth_error, + param="None", + code=status.HTTP_401_UNAUTHORIZED, ) # Check 2a. Check if model has zero cost - if so, skip all budget checks @@ -3264,7 +3292,12 @@ async def validate_resolved_virtual_key( # noqa: C901 # Preserve ordering of e if valid_token is None: # No token was found when looking up in the DB - raise Exception("Invalid proxy server token passed") + raise ProxyException( + message="Authentication Error, Invalid proxy server token passed", + type=ProxyErrorTypes.auth_error, + param="None", + code=status.HTTP_401_UNAUTHORIZED, + ) if valid_token_dict is not None: virtual_key_auth_obj: Final = await _return_user_api_key_auth_obj( user_obj=user_obj, diff --git a/litellm/proxy/caching_routes.py b/litellm/proxy/caching_routes.py index 597080be3b3..775d00ed53e 100644 --- a/litellm/proxy/caching_routes.py +++ b/litellm/proxy/caching_routes.py @@ -1,3 +1,4 @@ +from collections.abc import Mapping from typing import Final from fastapi import APIRouter, Depends, HTTPException, Request @@ -19,6 +20,10 @@ router: Final = APIRouter( ) +def _copy_cache_params(cache_params: Mapping[str, object]) -> Mapping[str, object]: + return dict(**cache_params) + + def _extract_cache_params() -> dict[str, object]: """ Safely extracts and cleans cache parameters. @@ -41,7 +46,7 @@ def _extract_cache_params() -> dict[str, object]: try: cache_params: Final = vars(litellm.cache.cache) cleaned_params: Final = ( - HealthCheckCacheParams.model_validate(dict(**cache_params)).model_dump() if cache_params else {} + HealthCheckCacheParams.model_validate(_copy_cache_params(cache_params)).model_dump() if cache_params else {} ) return masker.mask_dict(cleaned_params) except (AttributeError, TypeError) as e: diff --git a/litellm/proxy/client/chat.py b/litellm/proxy/client/chat.py index c027bf2fe98..ccdef44f9e8 100644 --- a/litellm/proxy/client/chat.py +++ b/litellm/proxy/client/chat.py @@ -59,7 +59,7 @@ class ChatClient: frequency_penalty: float | None = None, user: str | None = None, return_request: bool = False, - ) -> dict[str, Any] | requests.Request: + ) -> dict[str, object] | requests.Request: """ Create a chat completion. @@ -184,7 +184,8 @@ class ChatClient: response.raise_for_status() # Parse SSE stream - for line in response.iter_lines(): + lines: Final[Iterator[object]] = response.iter_lines() + for line in lines: if line: line = _SSE_LINE.validate_python(line).decode("utf-8") if line.startswith("data: "): diff --git a/litellm/proxy/client/cli/commands/debug.py b/litellm/proxy/client/cli/commands/debug.py index 8728a9323b7..89b93e2bbb8 100644 --- a/litellm/proxy/client/cli/commands/debug.py +++ b/litellm/proxy/client/cli/commands/debug.py @@ -15,6 +15,7 @@ from datetime import datetime, timezone from pathlib import Path from types import MappingProxyType from typing import Final +from urllib.parse import quote import click import requests @@ -177,7 +178,7 @@ class SpendLogsFetcher: return DebugFailure(f"Unexpected {uri} response: {e}") def payload(self, request_id: str) -> RequestResponsePayload | None | DebugFailure: - uri: Final = f"/spend/logs/ui/{request_id}" + uri: Final = f"/spend/logs/ui/{quote(request_id, safe='')}" raw: Final = self._get(uri) if isinstance(raw, DebugFailure): return raw diff --git a/litellm/proxy/client/cli/commands/encryption.py b/litellm/proxy/client/cli/commands/encryption.py index ef73b4f0d2d..61c8db617af 100644 --- a/litellm/proxy/client/cli/commands/encryption.py +++ b/litellm/proxy/client/cli/commands/encryption.py @@ -4,9 +4,14 @@ from typing import Final import click import rich +from pydantic import TypeAdapter + +from litellm.litellm_core_utils.core_helpers import as_str_mapping from ...http_client import HTTPClient -from .auth import cli_context_obj +from ._cli_context import cli_context_values + +_DECODED_JSON: Final = TypeAdapter(object) @click.group() @@ -40,23 +45,32 @@ def migrate(ctx: click.Context, check_only: bool, dry_run: bool): lite encryption migrate --check # attestation scan, no writes lite encryption migrate # perform the migration """ - client: Final = HTTPClient(cli_context_obj(ctx)["base_url"], ctx.obj["api_key"]) + context: Final = cli_context_values(ctx) + client: Final = HTTPClient(context["base_url"], context["api_key"]) - if check_only: - response = client.request("GET", "/credentials/migrate-encryption/check") - else: - response = client.request( + response: Final = _DECODED_JSON.validate_python( + client.request("GET", "/credentials/migrate-encryption/check") + if check_only + else client.request( "POST", "/credentials/migrate-encryption", json={}, params={"dry_run": "true"} if dry_run else None, ) + ) rich.print_json(data=response) - report: Final = response.get("report", {}) if isinstance(response, dict) else {} + report_value: Final = (as_str_mapping(response) or {}).get("report", {}) + report: Final = as_str_mapping(report_value) + if report is None: + raise click.ClickException(f"Unexpected report in the proxy response: {report_value!r}") residual: Final = report.get("residual_legacy") - if residual is not None and residual > 0: + if residual is None: + return + if not isinstance(residual, int | float): + raise click.ClickException(f"Unexpected residual_legacy in the proxy response: {residual!r}") + if residual > 0: rich.print(f"[yellow]Residual legacy values remaining: {residual}[/yellow]") elif residual == 0: rich.print("[green]No legacy values remaining (residual_legacy == 0).[/green]") diff --git a/litellm/proxy/client/cli/commands/statusline_script.py b/litellm/proxy/client/cli/commands/statusline_script.py index 5aeefa0c739..fef3e313ee5 100644 --- a/litellm/proxy/client/cli/commands/statusline_script.py +++ b/litellm/proxy/client/cli/commands/statusline_script.py @@ -89,6 +89,28 @@ class Fetch(Protocol): def __call__(self, credentials: Credentials, session_id: str) -> Fetched: ... +class _ResponseBody(Protocol): + def read(self) -> bytes: ... + + +class _OpenedResponse(Protocol): + def __enter__(self) -> _ResponseBody: ... + + def __exit__(self, *exc_info: object) -> None: ... + + +class _UrlOpener(Protocol): + def __call__(self, url: urllib.request.Request, /, *, timeout: float) -> _OpenedResponse: ... + + +def _url_opener() -> _UrlOpener: + return urllib.request.urlopen + + +def _json_decoder() -> Callable[[bytes | str], object]: + return json.loads + + def as_mapping(value: object) -> Mapping[str, object]: return value if isinstance(value, dict) else EMPTY @@ -106,7 +128,7 @@ def printable(value: object) -> str: def load_json(raw: bytes | str) -> object: try: - return json.loads(raw) + return _json_decoder()(raw) except ValueError: return None @@ -195,7 +217,7 @@ def fetch_session(credentials: Credentials, session_id: str) -> Fetched: }, ) try: - with urllib.request.urlopen(request, timeout=FETCH_TIMEOUT_SECONDS) as response: + with _url_opener()(request, timeout=FETCH_TIMEOUT_SECONDS) as response: raw: Final[bytes] = response.read() except urllib.error.HTTPError as error: return Fetched(session=None, definitive=400 <= error.code < 500) diff --git a/litellm/proxy/client/cli/interface.py b/litellm/proxy/client/cli/interface.py index f7c545ef48e..7c01732119e 100644 --- a/litellm/proxy/client/cli/interface.py +++ b/litellm/proxy/client/cli/interface.py @@ -189,7 +189,7 @@ def execute_command(path: ShellScope, ctx: click.Context, cli: click.Group) -> N try: if path[0].startswith("-"): cli.main( - ["--base-url", ctx.obj["base_url"], *path], + ["--base-url", cli_context_obj(ctx)["base_url"], *path], prog_name="lite", obj={"secret_vault": context_secret_vault(ctx)}, standalone_mode=False, diff --git a/litellm/proxy/client/cli/main.py b/litellm/proxy/client/cli/main.py index 3f1e7f4259c..a1964d8a1bb 100644 --- a/litellm/proxy/client/cli/main.py +++ b/litellm/proxy/client/cli/main.py @@ -4,6 +4,7 @@ from collections.abc import Callable, Iterator, Mapping, MutableMapping from typing import Final, Literal, Protocol import click +from pydantic import TypeAdapter from litellm._version import version as litellm_version from litellm.litellm_core_utils.cli_token_utils import load_cli_token @@ -89,10 +90,13 @@ class LazyCommands(MutableMapping[str, click.Command]): return len(self._loaders) +_MODULE_ATTRIBUTE: Final = TypeAdapter(object) + + def _command_in(module: str, attribute: str) -> Callable[[], click.Command]: @functools.cache def load() -> click.Command: - match getattr(importlib.import_module(module, __package__), attribute): + match _MODULE_ATTRIBUTE.validate_python(getattr(importlib.import_module(module, __package__), attribute)): case click.Command() as command: return command case _: diff --git a/litellm/proxy/client/credentials.py b/litellm/proxy/client/credentials.py index ebcd79457a6..649fe529936 100644 --- a/litellm/proxy/client/credentials.py +++ b/litellm/proxy/client/credentials.py @@ -75,7 +75,7 @@ class CredentialsManagementClient: credential_values: Mapping[str, object], return_request: bool = False, display_name: str | None = None, - ) -> dict[str, Any] | requests.Request: + ) -> dict[str, object] | requests.Request: """ Create a new credential. @@ -121,7 +121,7 @@ class CredentialsManagementClient: self, credential_name: str, return_request: bool = False, - ) -> dict[str, Any] | requests.Request: + ) -> dict[str, object] | requests.Request: """ Delete a credential by name. @@ -182,7 +182,7 @@ class CredentialsManagementClient: self, credential_name: str, return_request: bool = False, - ) -> dict[str, Any] | requests.Request: + ) -> dict[str, object] | requests.Request: """ Get a credential by name. diff --git a/litellm/proxy/client/http_client.py b/litellm/proxy/client/http_client.py index aa0b986b1ad..96a170c75cb 100644 --- a/litellm/proxy/client/http_client.py +++ b/litellm/proxy/client/http_client.py @@ -4,6 +4,11 @@ from collections.abc import Mapping from typing import Any, Final import requests +from typing_extensions import TypedDict, Unpack + + +class _RequestOptions(TypedDict, total=False, extra_items=object): + pass class HTTPClient: @@ -29,7 +34,7 @@ class HTTPClient: data: Mapping[str, object] | list | bytes | None = None, json: Mapping[str, object] | list | None = None, headers: dict[str, str] | None = None, - **kwargs: Any, + **kwargs: Unpack[_RequestOptions], ) -> Any: """Make an HTTP request to the LiteLLM proxy server. diff --git a/litellm/proxy/client/model_groups.py b/litellm/proxy/client/model_groups.py index fef307600c4..1555d170212 100644 --- a/litellm/proxy/client/model_groups.py +++ b/litellm/proxy/client/model_groups.py @@ -1,4 +1,4 @@ -from typing import Any, Final +from typing import Final import requests @@ -31,7 +31,7 @@ class ModelGroupsManagementClient: headers["Authorization"] = f"Bearer {self._api_key}" return headers - def info(self, return_request: bool = False) -> list[dict[str, Any]] | requests.Request: + def info(self, return_request: bool = False) -> list[dict[str, object]] | requests.Request: """ Get detailed information about all model groups from the server. diff --git a/litellm/proxy/client/models.py b/litellm/proxy/client/models.py index 1b50f8c24f3..1361a3e6364 100644 --- a/litellm/proxy/client/models.py +++ b/litellm/proxy/client/models.py @@ -158,7 +158,7 @@ class ModelsManagementClient: model_id: str | None = None, model_name: str | None = None, return_request: bool = False, - ) -> dict[str, Any] | requests.Request: + ) -> dict[str, object] | requests.Request: """ Get information about a specific model by its ID or name. @@ -168,7 +168,7 @@ class ModelsManagementClient: return_request (bool): If True, returns the prepared request object instead of executing it Returns: - Union[Dict[str, Any], requests.Request]: Either the model information from the server or + dict[str, object] | requests.Request: Either the model information from the server or a prepared request object if return_request is True Raises: diff --git a/litellm/proxy/common_request_processing.py b/litellm/proxy/common_request_processing.py index 23faa964d5f..3b9c17baa02 100644 --- a/litellm/proxy/common_request_processing.py +++ b/litellm/proxy/common_request_processing.py @@ -6,6 +6,7 @@ import math from collections.abc import AsyncGenerator, AsyncIterator, Awaitable, Callable, Coroutine, Mapping, Sequence from datetime import datetime from functools import lru_cache +from itertools import chain from types import MappingProxyType from typing import ( TYPE_CHECKING, @@ -69,7 +70,11 @@ from litellm.litellm_core_utils.get_supported_openai_params import ( from litellm.litellm_core_utils.internal_call_metadata import is_unbilled_non_inference_call_from_params from litellm.litellm_core_utils.litellm_logging import BilledRoundsDispatch from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj -from litellm.litellm_core_utils.llm_cost_calc.guardrail_cost import guardrail_information_cost +from litellm.litellm_core_utils.llm_cost_calc.guardrail_cost import ( + guardrail_entries, + guardrail_information_cost, + object_mapping, +) from litellm.litellm_core_utils.llm_response_utils.get_headers import ( get_response_headers, ) @@ -119,6 +124,7 @@ from litellm.proxy.common_utils.sse_keepalive import ( ) from litellm.proxy.dd_span_tagger import DDSpanTagger from litellm.proxy.guardrails.auto_router_compression import arm_pre_call as _arm_auto_router_compression +from litellm.proxy.hooks.parallel_request_limiter_v3 import get_or_create_request_stash from litellm.proxy.native_compaction import with_proxy_compaction_executor from litellm.proxy.route_llm_request import ( route_request, @@ -305,6 +311,23 @@ async def close_guarded_stream(stream: object) -> None: ) +def _guardrail_entries_for_headers( + request_metadata_bucket: object, logging_obj: LiteLLMLoggingObj +) -> tuple[object, ...]: + """Guardrail entries the proxy hooks wrote on the request plus the ones the call recorded on its own logging + object (a Bedrock deployment's native guardrail trace), each once: the hooks copy theirs into the logging object.""" + litellm_params: Final = object_mapping(logging_obj.model_call_details.get("litellm_params")) or {} + buckets: Final = (object_mapping(request_metadata_bucket), object_mapping(litellm_params.get("metadata"))) + entries: Final = tuple( + chain.from_iterable( + guardrail_entries(metadata.get("standard_logging_guardrail_information")) + for metadata in buckets + if metadata is not None + ) + ) + return tuple(entry for index, entry in enumerate(entries) if entry not in entries[:index]) + + def resolve_litellm_call_id(client_call_id: str | None) -> str: if client_call_id is not None and 0 < len(client_call_id) <= MAX_LITELLM_CALL_ID_LENGTH: return client_call_id @@ -1416,6 +1439,8 @@ async def open_sse_before_first_byte( if interval is None: return await produce_response + # Share admission state with stream cleanup before the producer copies this context. + get_or_create_request_stash() produce_task: Final = asyncio.ensure_future(produce_response) await asyncio.wait((produce_task,), timeout=interval) if produce_task.done(): @@ -3235,9 +3260,9 @@ class ProxyBaseLLMRequestProcessing: if is_unbilled_non_inference_call_from_params(logging_obj.call_type, logging_obj.litellm_params, response) else computed_cost_for_headers ) - _, request_metadata_bucket = get_or_create_metadata_bucket(self.data) + request_metadata_bucket: Final[object] = get_or_create_metadata_bucket(self.data)[1] # pyright: ignore[reportUnknownVariableType, reportUnknownMemberType] # self.data is an untyped dict guardrail_cost_for_headers: Final = guardrail_information_cost( - request_metadata_bucket.get("standard_logging_guardrail_information") + _guardrail_entries_for_headers(request_metadata_bucket, logging_obj) # pyright: ignore[reportUnknownArgumentType] # bucket comes from the untyped request dict ) response_cost_for_headers: Final = ( (llm_cost_for_headers if isinstance(llm_cost_for_headers, (int, float)) else 0.0) @@ -4684,6 +4709,7 @@ class ProxyBaseLLMRequestProcessing: total_tokens=total_tokens, completion_tokens_details=usage.get("completion_tokens_details"), prompt_tokens_details=usage.get("prompt_tokens_details"), + server_tool_use=usage.get("server_tool_use"), ) @staticmethod @@ -4821,10 +4847,15 @@ class ProxyBaseLLMRequestProcessing: model_info = metadata.get("model_info") or {} model_id = model_info.get("id", None) - # 3. Final fallback to self.data["litellm_metadata"] (for routes like /v1/responses that populate data before error) + # 3. Final fallback to the request metadata the router updates in place with the selected deployment if not model_id: - litellm_metadata: Final = self.data.get("litellm_metadata", {}) or {} - model_info = litellm_metadata.get("model_info", {}) or {} - model_id = model_info.get("id", None) + model_id = self._metadata_model_id("litellm_metadata") or self._metadata_model_id("metadata") return model_id + + def _metadata_model_id(self, metadata_key: str) -> str | None: + match self.data.get(metadata_key): + case {"model_info": {"id": str() as request_model_id}}: + return request_model_id + case _: + return None diff --git a/litellm/proxy/common_utils/auth_cache_invalidation_pubsub.py b/litellm/proxy/common_utils/auth_cache_invalidation_pubsub.py index 40cdb117476..b2640d2a765 100644 --- a/litellm/proxy/common_utils/auth_cache_invalidation_pubsub.py +++ b/litellm/proxy/common_utils/auth_cache_invalidation_pubsub.py @@ -1,11 +1,15 @@ import asyncio import json -from collections.abc import Sequence +from collections.abc import Mapping, Sequence from dataclasses import asdict, dataclass +from types import MappingProxyType from typing import TYPE_CHECKING, Final +from pydantic import TypeAdapter + from litellm._internal_context import with_service_target from litellm._logging import verbose_proxy_logger +from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.proxy.common_utils.config_sync_pubsub import ( # noqa: F401 # legacy module exports ConfigSyncPubSub, _ConfigSyncPubSub, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export @@ -30,6 +34,7 @@ _pending_publishes: Final[set[asyncio.Task[None]]] = set() # mutable-ok: strong _in_flight_publishes: Final = asyncio.Semaphore(_MAX_IN_FLIGHT_PUBLISHES) _BACKOFF_INITIAL_SECONDS: Final = 5.0 _BACKOFF_MAX_SECONDS: Final = 60.0 +_DECODED_JSON: Final = TypeAdapter(object) def auth_cache_invalidation_channel(redis_cache: "RedisCache") -> str: @@ -46,7 +51,9 @@ class _CacheInvalidationMessage: def _cache_invalidation_message_json(cache_key: str, new_value: float | None = None, ttl: float | None = None) -> str: - message: Final = asdict(_CacheInvalidationMessage(cache_key=cache_key, new_value=new_value, ttl=ttl)) + message: Final[Mapping[str, object]] = MappingProxyType( + asdict(_CacheInvalidationMessage(cache_key=cache_key, new_value=new_value, ttl=ttl)) + ) return json.dumps({field: value for field, value in message.items() if value is not None}) @@ -62,10 +69,10 @@ def _message_from_data(data: object) -> _CacheInvalidationMessage | None: if not isinstance(data, str): return None try: - parsed: Final = json.loads(data) + parsed: Final = as_str_mapping(_DECODED_JSON.validate_python(json.loads(data))) except json.JSONDecodeError: return None - if not isinstance(parsed, dict): + if parsed is None: return None cache_key: Final = parsed.get("cache_key") if not isinstance(cache_key, str): diff --git a/litellm/proxy/common_utils/callback_utils.py b/litellm/proxy/common_utils/callback_utils.py index 46434a997b7..f889748c504 100644 --- a/litellm/proxy/common_utils/callback_utils.py +++ b/litellm/proxy/common_utils/callback_utils.py @@ -6,6 +6,7 @@ from dataclasses import dataclass from itertools import accumulate from typing import TYPE_CHECKING, Any, Final, Literal, NoReturn, Optional, TypeAlias +from pydantic import TypeAdapter from typing_extensions import ReadOnly, TypedDict, assert_never import litellm @@ -39,6 +40,7 @@ from litellm.types.utils import ( ) _CALLBACK_VAR_MASKER: Final = SensitiveDataMasker() +_LOADED_CALLBACK: Final = TypeAdapter(object) # Compound names that are credential-bearing but don't contain any of the # default sensitive segments (so SensitiveDataMasker won't flag them). _EXTRA_SENSITIVE_CALLBACK_KEYS: Final = {"gcs_path_service_account"} @@ -389,9 +391,11 @@ def initialize_callbacks_on_proxy( imported_list.append( _loaded_callback_or_raise( entry=callback, - loaded=get_instance_fn( - value=callback, - config_file_path=config_file_path, + loaded=_LOADED_CALLBACK.validate_python( + get_instance_fn( + value=callback, + config_file_path=config_file_path, + ) ), ) ) @@ -408,9 +412,11 @@ def initialize_callbacks_on_proxy( litellm.callbacks = [ _loaded_callback_or_raise( entry=value, - loaded=get_instance_fn( - value=value, - config_file_path=config_file_path, + loaded=_LOADED_CALLBACK.validate_python( + get_instance_fn( + value=value, + config_file_path=config_file_path, + ) ), ) ] diff --git a/litellm/proxy/common_utils/debug_utils.py b/litellm/proxy/common_utils/debug_utils.py index 33633150711..ec4baa76514 100644 --- a/litellm/proxy/common_utils/debug_utils.py +++ b/litellm/proxy/common_utils/debug_utils.py @@ -11,12 +11,14 @@ from collections.abc import Mapping, Sequence from typing import TYPE_CHECKING, Annotated, Final, NamedTuple, Protocol, TypedDict from fastapi import APIRouter, Depends, HTTPException, Query +from pydantic import TypeAdapter from typing_extensions import ReadOnly from litellm import get_secret_str from litellm._logging import verbose_proxy_logger from litellm.constants import PYTHON_GC_THRESHOLD from litellm.litellm_core_utils.bug_report import EnvironmentReport +from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.auth.user_api_key_auth import user_api_key_auth from litellm.proxy.bug_report_config import build_proxy_environment_report @@ -26,6 +28,7 @@ if TYPE_CHECKING: from litellm.router import Router router: Final = APIRouter() +_DECODED_JSON: Final = TypeAdapter(object) # Configure garbage collection thresholds from environment variables @@ -885,8 +888,8 @@ def init_verbose_loggers(): return if os.path.isfile(worker_config): return - _settings: Final = json.loads(worker_config) - if not isinstance(_settings, dict): + _settings: Final = as_str_mapping(_DECODED_JSON.validate_python(json.loads(worker_config))) + if _settings is None: return debug: Final = _settings.get("debug", None) diff --git a/litellm/proxy/common_utils/http_parsing_utils.py b/litellm/proxy/common_utils/http_parsing_utils.py index 245a56678eb..9f7fed40ab3 100644 --- a/litellm/proxy/common_utils/http_parsing_utils.py +++ b/litellm/proxy/common_utils/http_parsing_utils.py @@ -6,7 +6,7 @@ from typing import Annotated, Any, Final, Literal, Union, get_args, get_origin import orjson from fastapi import Request, UploadFile, status -from pydantic import TypeAdapter +from pydantic import TypeAdapter, ValidationError from starlette._utils import get_route_path from starlette.requests import HTTPConnection from typing_extensions import NotRequired, ReadOnly, Required, assert_never @@ -31,6 +31,7 @@ _BINARY_CONTENT_TYPES: Final[frozenset[str]] = frozenset({"application/x-protobu _ANNOTATION_QUALIFIERS: Final[frozenset[object]] = frozenset({Annotated, NotRequired, ReadOnly, Required}) _DECODED_JSON: Final = TypeAdapter(object) +_JSON_REQUEST_BODY: Final = TypeAdapter(Mapping[str, object]) def resolve_inference_model( @@ -161,13 +162,11 @@ def coerce_numeric_form_fields( } -def _parse_binary_body(body: bytes) -> dict: +def _parse_binary_body(body: bytes) -> dict[str, object]: """JSON sent under a binary content type still parses; real binary (protobuf) carries no params -> {}.""" try: - parsed: Final = orjson.loads(body) - if isinstance(parsed, dict): - return parsed - except orjson.JSONDecodeError: + return dict(_JSON_REQUEST_BODY.validate_python(orjson.loads(body))) + except (orjson.JSONDecodeError, ValidationError): pass return {} @@ -272,7 +271,7 @@ async def read_request_body(request: Request | None) -> dict: parsed_body = {} else: try: - parsed_body = orjson.loads(body) + parsed_body = dict(_JSON_REQUEST_BODY.validate_python(orjson.loads(body))) except orjson.JSONDecodeError as e: # The surrogate-repair fallback below runs two full-body re.sub # passes, which block the event loop on multi-MB malformed bodies. @@ -298,8 +297,9 @@ async def read_request_body(request: Request | None) -> dict: body_str = re.sub(r"(? dict: safe_set_request_parsed_body(request=request, parsed_body=parsed_body) return parsed_body + except ValidationError as e: + from fastapi.routing import APIRoute + + from litellm.proxy.auth.auth_utils import ( + request_dispatched_to_pass_through_endpoint, + request_dispatched_to_provider_pass_through, + ) + from litellm.proxy.lens.buffering import LensRoute + + route: Final[object] = request.scope.get("route") if request is not None else None + if request is not None and ( + request_dispatched_to_pass_through_endpoint(request) + or request_dispatched_to_provider_pass_through(request) + or isinstance(route, LensRoute) + or ( + isinstance(route, APIRoute) + and route.body_field is not None + and not route.body_field.field_info.is_required() + and (await request.body()).strip() == b"null" + ) + ): + return {} + raise ProxyException( + message="Invalid JSON payload: expected an object", + type="invalid_request_error", + param="request_body", + code=status.HTTP_400_BAD_REQUEST, + ) from e except (json.JSONDecodeError, orjson.JSONDecodeError, ProxyException) as e: # Re-raise ProxyException as-is verbose_proxy_logger.error("Invalid JSON payload received: %s", e) @@ -415,7 +443,9 @@ def rewrite_request_model( if request is None: return cached_body: Final = _safe_get_request_parsed_body(request=request) - body: Final = {**cached_body, "model": model} if cached_body is not None else request_data + body: Final = ( + {**_JSON_REQUEST_BODY.validate_python(cached_body), "model": model} if cached_body is not None else request_data + ) safe_set_request_parsed_body(request=request, parsed_body=body) request._json = body # pyright: ignore[reportPrivateUsage] # Starlette JSON cache request._body = orjson.dumps(body) # pyright: ignore[reportPrivateUsage] # Starlette body cache diff --git a/litellm/proxy/common_utils/load_config_utils.py b/litellm/proxy/common_utils/load_config_utils.py index 4a082eb307b..640a947f9c5 100644 --- a/litellm/proxy/common_utils/load_config_utils.py +++ b/litellm/proxy/common_utils/load_config_utils.py @@ -15,6 +15,7 @@ if TYPE_CHECKING: from litellm.integrations.gcs_bucket.gcs_bucket_base import GCSBucketBase _BUCKET_CONFIG_ADAPTER: Final = TypeAdapter(dict[str, object]) +_DECODED_YAML: Final = TypeAdapter(object) class BucketObjectFetcher(Protocol): @@ -31,7 +32,7 @@ class SyncBucketObjectReader(Protocol): def _parsed_config(object_key: str, file_contents: str) -> object | None: try: - parsed: Final = yaml.safe_load(file_contents) + parsed: Final = _DECODED_YAML.validate_python(yaml.safe_load(file_contents)) except yaml.YAMLError as e: verbose_proxy_logger.error("Config object %s is not valid YAML: %s", object_key, e) return None diff --git a/litellm/proxy/common_utils/proxy_rate_limit_error.py b/litellm/proxy/common_utils/proxy_rate_limit_error.py index 089d0b7a226..02da6f706d1 100644 --- a/litellm/proxy/common_utils/proxy_rate_limit_error.py +++ b/litellm/proxy/common_utils/proxy_rate_limit_error.py @@ -37,7 +37,7 @@ This module provides a single proxy-side error class that: import json from collections.abc import Mapping -from typing import Any, Final +from typing import Final from fastapi import HTTPException from pydantic import TypeAdapter, ValidationError @@ -171,7 +171,7 @@ class ProxyRateLimitError(HTTPException, RateLimitError): def __init__( self, - detail: Any, + detail: object, headers: Mapping[str, object] | None = None, category: str | RateLimitErrorCategory = RateLimitErrorCategory.LITELLM_RATE_LIMIT, rate_limit_type: str | RateLimitType | None = None, diff --git a/litellm/proxy/common_utils/reset_budget_job.py b/litellm/proxy/common_utils/reset_budget_job.py index ccf2232e379..59fd00cec43 100644 --- a/litellm/proxy/common_utils/reset_budget_job.py +++ b/litellm/proxy/common_utils/reset_budget_job.py @@ -65,6 +65,7 @@ from litellm.repositories.table_repositories import ( from litellm.repositories.team_repository import TeamRepository from litellm.repositories.unit_of_work import ( LinkedSpendResetWrites, + SpendResetWrites, budget_cascade_unit_of_work, enduser_spend_reset_unit_of_work, spend_reset_unit_of_work, @@ -235,7 +236,7 @@ def _enduser_invalidation_where(budget_ids: Sequence[str]) -> dict[str, object]: def _queue_budget_linked_resets( - writes: LinkedSpendResetWrites, + writes: SpendResetWrites, cascade: "_BudgetCascade", extra: Mapping[str, object] = MappingProxyType({}), ) -> None: @@ -908,6 +909,7 @@ class ResetBudgetJob: db_span("reset_budget_cascade", "LiteLLM_BudgetTable"), budget_cascade_unit_of_work(self._new_batch) as uow, ): + uow.team_memberships.queue_total_spend_repair(cascade.budget_ids) _queue_budget_linked_resets(uow.team_memberships, cascade) _queue_budget_linked_resets(uow.keys, cascade, extra=_LINKED_KEYS_WHERE) _queue_budget_linked_resets(uow.organizations, cascade, extra=_SPENT_ROWS_WHERE) diff --git a/litellm/proxy/container_endpoints/handler_factory.py b/litellm/proxy/container_endpoints/handler_factory.py index 35bd69ef0bd..a2ffdd4d59d 100644 --- a/litellm/proxy/container_endpoints/handler_factory.py +++ b/litellm/proxy/container_endpoints/handler_factory.py @@ -13,6 +13,7 @@ from typing import Final from fastapi import APIRouter, Depends, Request, Response from fastapi.responses import ORJSONResponse +from pydantic import TypeAdapter from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.auth.user_api_key_auth import user_api_key_auth @@ -26,6 +27,8 @@ from litellm.proxy.container_endpoints.ownership import ( get_container_forwarding_params, ) +_UPLOADED_FILE_FIELD: Final = TypeAdapter(object) + def _load_endpoints_config() -> dict: """Load the endpoints configuration from JSON file.""" @@ -304,7 +307,7 @@ async def _process_multipart_upload_request( raise HTTPException(status_code=400, detail="Missing required 'file' field") # convert_upload_files_to_file_data returns list of tuples, extract single file - file_list: Final = data["file"] + file_list: Final = _UPLOADED_FILE_FIELD.validate_python(data["file"]) if isinstance(file_list, list) and len(file_list) > 0: data["file"] = file_list[0] diff --git a/litellm/proxy/container_endpoints/ownership.py b/litellm/proxy/container_endpoints/ownership.py index aeb0bb1e3d0..9e4ab3c3c4e 100644 --- a/litellm/proxy/container_endpoints/ownership.py +++ b/litellm/proxy/container_endpoints/ownership.py @@ -1,13 +1,14 @@ import json from collections.abc import Awaitable, Callable, Mapping, Sequence from collections.abc import Set as AbstractSet -from typing import TYPE_CHECKING, Any, Final, TypeAlias +from typing import TYPE_CHECKING, Final, Protocol, TypeAlias from fastapi import HTTPException from pydantic import BaseModel from litellm._logging import verbose_proxy_logger from litellm.caching.in_memory_cache import InMemoryCache +from litellm.litellm_core_utils.core_helpers import has_attributes from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.common_utils.resource_ownership import ( get_primary_resource_owner_scope, @@ -111,12 +112,20 @@ def _get_response_id(response: object) -> str | None: return value if isinstance(value, str) else None -def _dump_response(response: Any) -> dict[str, object]: +class _SupportsModelDump(Protocol): + def model_dump(self) -> Mapping[str, object]: ... + + +class _SupportsPydanticDict(Protocol): + def dict(self) -> Mapping[str, object]: ... + + +def _dump_response(response: object) -> Mapping[str, object]: if isinstance(response, dict): return dict(response) - if hasattr(response, "model_dump"): + if has_attributes(response, _SupportsModelDump, "model_dump"): return response.model_dump() - if hasattr(response, "dict"): + if has_attributes(response, _SupportsPydanticDict, "dict"): return response.dict() return {"id": _get_response_id(response)} @@ -199,9 +208,11 @@ async def record_container_owner( original_container_id, resolved_provider = decode_container_id_for_ownership(container_id, custom_llm_provider) model_object_id: Final = _container_model_object_id(original_container_id, resolved_provider) - file_object: Final = _dump_response(response) - file_object["custom_llm_provider"] = resolved_provider - file_object["provider_container_id"] = original_container_id + file_object: Final = { + **_dump_response(response), + "custom_llm_provider": resolved_provider, + "provider_container_id": original_container_id, + } # Prisma Python requires Json fields to be serialized as a JSON string. file_object_json: Final[str] = json.dumps(file_object) diff --git a/litellm/proxy/db/autorouter_session_rollup.py b/litellm/proxy/db/autorouter_session_rollup.py index 75882bc3fb1..4ddcf7e600b 100644 --- a/litellm/proxy/db/autorouter_session_rollup.py +++ b/litellm/proxy/db/autorouter_session_rollup.py @@ -526,7 +526,7 @@ async def _upsert_turn_with_retry( except DB_RETRY_SAFE_ERROR_TYPES: if attempt >= n_retry_times: raise - await asyncio.sleep(2**attempt + random.uniform(0, 1)) + await asyncio.sleep(2.0**attempt + random.uniform(0, 1)) else: return diff --git a/litellm/proxy/db/db_spend_update_writer.py b/litellm/proxy/db/db_spend_update_writer.py index 4e98823ba77..8ac2597c99b 100644 --- a/litellm/proxy/db/db_spend_update_writer.py +++ b/litellm/proxy/db/db_spend_update_writer.py @@ -12,11 +12,11 @@ import json import os import random import time -import traceback from collections.abc import AsyncGenerator, Callable, Coroutine, Iterable, Mapping, Sequence from contextlib import asynccontextmanager from contextvars import ContextVar from datetime import datetime, timedelta, timezone +from functools import reduce from types import MappingProxyType from typing import TYPE_CHECKING, Any, Final, Literal, Protocol, TypeAlias, TypeVar, cast, overload from urllib.parse import quote, unquote @@ -37,7 +37,6 @@ from litellm.constants import ( from litellm.litellm_core_utils.litellm_logging import coerce_model_access_groups from litellm.litellm_core_utils.safe_json_loads import safe_json_loads from litellm.proxy._types import ( - DB_CONNECTION_ERROR_TYPES, DB_RETRY_SAFE_ERROR_TYPES, BaseDailySpendTransaction, DailyAgentSpendTransaction, @@ -74,7 +73,7 @@ from litellm.proxy.db.db_transaction_queue.window_spend_update_queue import ( WindowSpendTransaction, WindowSpendUpdateQueue, ) -from litellm.proxy.db.exception_handler import PrismaDBExceptionHandler +from litellm.proxy.db.exception_handler import PrismaDBExceptionHandler, db_write_failure_is_requeue_safe from litellm.proxy.db.model_usage_rollup import build_model_usage_transaction from litellm.proxy.db.request_error_tracking import request_error_accumulator from litellm.proxy.db.rollup_lock_timeout import apply_rollup_lock_timeout @@ -90,6 +89,7 @@ from litellm.proxy.spend_tracking.savings import ( ) from litellm.proxy.spend_tracking.spend_log_error_logger import spend_log_error from litellm.repositories.prisma_protocols import BatchTable +from litellm.responses.streaming_iterator import spawn_logging_task from litellm.types.utils import CallTypes if TYPE_CHECKING: @@ -104,6 +104,7 @@ else: RESPONSES_SESSION_CALL_TYPES: Final = frozenset({CallTypes.responses.value, CallTypes.aresponses.value}) _SPEND_METADATA_ADAPTER: Final = TypeAdapter(Mapping[str, object]) +_CALL_KWARG_VALUE: Final = TypeAdapter(object) _JsonPayload: TypeAlias = Mapping[str, object] | Sequence[object] | str | int | float | bool | None _JSON_VALUE_ADAPTER: Final[TypeAdapter[_JsonPayload]] = TypeAdapter( _JsonPayload, config=ConfigDict(strict=True, hide_input_in_errors=True) @@ -249,16 +250,6 @@ class _DailySpendCommit(Protocol[_DailySpendTransactionT]): ) -> None: ... -_DATA_REJECTED_SQLSTATE_CLASSES: Final = frozenset({"22", "23"}) - - -def _spend_commit_failure_is_requeue_safe(e: Exception) -> bool: - if isinstance(e, DB_CONNECTION_ERROR_TYPES): - return isinstance(e, DB_RETRY_SAFE_ERROR_TYPES) - sqlstate: Final = PrismaDBExceptionHandler.postgres_sqlstate(e) - return sqlstate is None or sqlstate[:2] not in _DATA_REJECTED_SQLSTATE_CLASSES - - _SpendTableName = Literal[ "user_list_transactions", "end_user_list_transactions", @@ -296,7 +287,7 @@ def _spend_tables_left_to_send( _SPEND_TABLE_COMMIT_ORDER[len(committed)] if len(committed) < len(_SPEND_TABLE_COMMIT_ORDER) else None ) dropped: Final[frozenset[_SpendTableName]] = ( - frozenset() if in_flight is None or _spend_commit_failure_is_requeue_safe(failure) else frozenset({in_flight}) + frozenset() if in_flight is None or db_write_failure_is_requeue_safe(failure) else frozenset({in_flight}) ) if dropped and in_flight is not None: spend_log_error( @@ -313,6 +304,52 @@ def _spend_tables_left_to_send( return cast(DBSpendUpdateTransactions, remaining) if any(remaining.values()) else None +class _SpendRestore(TypedDict, total=False): + db_spend_update_transactions: ReadOnly[DBSpendUpdateTransactions] + daily_spend_update_transactions: ReadOnly[Mapping[str, BaseDailySpendTransaction]] + daily_team_spend_update_transactions: ReadOnly[Mapping[str, BaseDailySpendTransaction]] + daily_org_spend_update_transactions: ReadOnly[Mapping[str, BaseDailySpendTransaction]] + daily_end_user_spend_update_transactions: ReadOnly[Mapping[str, BaseDailySpendTransaction]] + daily_agent_spend_update_transactions: ReadOnly[Mapping[str, BaseDailySpendTransaction]] + window_spend_update_transactions: ReadOnly[Sequence[WindowSpendTransaction]] + + +def _merged_spend_restore(first: _SpendRestore, second: _SpendRestore) -> _SpendRestore: + return {**first, **second} + + +def _report_spend_update_step_failure(step_name: str, *, payload: Mapping[str, object], exc: Exception) -> None: + spend_log_error( + "Spend tracking - %s failed, this request is missing from that spend rollup. request_id=%s api_key=%s", + step_name, + payload.get("request_id"), + payload.get("api_key"), + exc=exc, + ) + + +_EMPTY_SPEND_LOG_METADATA: Final = cast(SpendLogsMetadata, MappingProxyType({})) # cast-ok: empty read-only metadata + + +def _parse_spend_log_metadata(payload: Mapping[str, object]) -> SpendLogsMetadata: + """Malformed metadata costs the request its metadata-derived fields, never its daily rollup row.""" + raw: Final = payload.get("metadata") + if not isinstance(raw, str): + return _EMPTY_SPEND_LOG_METADATA + try: + parsed: Final[SpendLogsMetadata] = json.loads(raw) + except json.JSONDecodeError as e: + spend_log_error( + "Spend tracking - unreadable spend log metadata, rollups for this request are written without " + "metadata-derived fields. request_id=%s api_key=%s", + payload.get("request_id"), + payload.get("api_key"), + exc=e, + ) + return _EMPTY_SPEND_LOG_METADATA + return parsed + + def _is_billed_retry_attempt(metadata: SpendLogsMetadata) -> bool: """An earlier billed retry attempt's own spend row, not a request the caller sent.""" return BILLED_RETRY_ATTEMPT_METADATA_KEY in metadata and metadata[BILLED_RETRY_ATTEMPT_METADATA_KEY] is True @@ -435,6 +472,8 @@ _TEAM_ADVISORY_LOCK_SQL: Final = "SELECT pg_advisory_xact_lock(hashtext($1)) IS # recreates the member. The rows travel as one JSON document, not as a numeric array: Prisma # types a raw array parameter from the first batch a connection sees, so after an all-$0 batch # (integers) every later fractional batch on that connection failed with "improper binary format". +# total_spend is floored at spend before adding: rows written before total_spend existed (migration +# 20260421135425, default 0) carry their history only in spend, so a plain increment keeps them behind forever. _TEAM_MEMBER_SPEND_SQL: Final = """ INSERT INTO "LiteLLM_TeamMembership" (user_id, team_id, spend, total_spend) SELECT member.user_id, member.team_id, member.cost, member.cost @@ -450,7 +489,7 @@ WHERE EXISTS ( ) ON CONFLICT (user_id, team_id) DO UPDATE SET spend = "LiteLLM_TeamMembership".spend + EXCLUDED.spend, - total_spend = "LiteLLM_TeamMembership".total_spend + EXCLUDED.total_spend + total_spend = GREATEST("LiteLLM_TeamMembership".total_spend, "LiteLLM_TeamMembership".spend) + EXCLUDED.total_spend """ @@ -647,8 +686,8 @@ class DBSpendUpdateWriter: "disable_spend_logs=True. Skipping writing spend logs to db. Other spend updates - Key/User/Team table will still occur." ) - # Single task replaces 11 create_task() calls - asyncio.create_task( + spawn_logging_task( + asyncio.get_running_loop(), self._batch_database_updates( response_cost=response_cost, user_id=user_id, @@ -661,7 +700,8 @@ class DBSpendUpdateWriter: litellm_proxy_budget_name=litellm_proxy_budget_name, payload=payload, request_model_access_groups=get_request_model_access_groups(kwargs), - ) + ), + task_name="spend rollups", ) self._enqueue_tool_registry_upsert( @@ -812,7 +852,7 @@ class DBSpendUpdateWriter: spend=payload["spend"], total_tokens=payload["total_tokens"], completion_response=completion_response, - realtime_tool_calls=(kwargs or {}).get("realtime_tool_calls"), + realtime_tool_calls=_CALL_KWARG_VALUE.validate_python((kwargs or {}).get("realtime_tool_calls")), ) if transaction is None: return @@ -1086,91 +1126,52 @@ class DBSpendUpdateWriter: project_id: str | None = None, ): """ - Runs all 13 spend-update helpers sequentially inside a single asyncio task. - - Each helper is wrapped in try/except so one failure doesn't prevent the others. - - The deepcopy runs here, off the awaited request path, so the daily spend - helpers get a payload isolated from the spend-log queue entry and the caller. + Runs every spend-update helper for one request. Each helper goes through + _run_spend_update_step so one failure never skips the sibling writes. The deepcopy + isolates the daily spend helpers' payload from the spend-log queue entry and the caller. """ payload_copy: Final = copy.deepcopy(payload) request_tags: Final = payload_copy.get("request_tags") - try: - await self._update_user_db( + await self._run_spend_update_step( + "_update_user_db", + self._update_user_db( response_cost=response_cost, user_id=user_id, prisma_client=prisma_client, litellm_proxy_budget_name=litellm_proxy_budget_name, end_user_id=end_user_id, - ) - except Exception: - verbose_proxy_logger.debug( - "_batch_database_updates: _update_user_db failed: %s", - traceback.format_exc(), - ) - - try: - await self._update_key_db( - response_cost=response_cost, - hashed_token=hashed_token, - prisma_client=prisma_client, - ) - except Exception: - verbose_proxy_logger.debug( - "_batch_database_updates: _update_key_db failed: %s", - traceback.format_exc(), - ) - - try: - await self._update_team_db( - response_cost=response_cost, - team_id=team_id, - user_id=user_id, - prisma_client=prisma_client, - ) - except Exception: - verbose_proxy_logger.debug( - "_batch_database_updates: _update_team_db failed: %s", - traceback.format_exc(), - ) - - try: - await self._update_org_db( - response_cost=response_cost, - org_id=org_id, - user_id=user_id, - prisma_client=prisma_client, - ) - except Exception: - verbose_proxy_logger.debug( - "_batch_database_updates: _update_org_db failed: %s", - traceback.format_exc(), - ) - - try: - await self._update_project_db( - response_cost=response_cost, - project_id=project_id, - prisma_client=prisma_client, - ) - except Exception: # noqa: BLE001 # a project enqueue failure must not skip the sibling spend writes - verbose_proxy_logger.debug( - "_batch_database_updates: _update_project_db failed: %s", - traceback.format_exc(), - ) - - try: - await self._update_tag_db( - response_cost=response_cost, - request_tags=request_tags, - prisma_client=prisma_client, - ) - except Exception: - verbose_proxy_logger.debug( - "_batch_database_updates: _update_tag_db failed: %s", - traceback.format_exc(), - ) - + ), + payload=payload_copy, + ) + await self._run_spend_update_step( + "_update_key_db", + self._update_key_db(response_cost=response_cost, hashed_token=hashed_token, prisma_client=prisma_client), + payload=payload_copy, + ) + await self._run_spend_update_step( + "_update_team_db", + self._update_team_db( + response_cost=response_cost, team_id=team_id, user_id=user_id, prisma_client=prisma_client + ), + payload=payload_copy, + ) + await self._run_spend_update_step( + "_update_org_db", + self._update_org_db( + response_cost=response_cost, org_id=org_id, user_id=user_id, prisma_client=prisma_client + ), + payload=payload_copy, + ) + await self._run_spend_update_step( + "_update_project_db", + self._update_project_db(response_cost=response_cost, project_id=project_id, prisma_client=prisma_client), + payload=payload_copy, + ) + await self._run_spend_update_step( + "_update_tag_db", + self._update_tag_db(response_cost=response_cost, request_tags=request_tags, prisma_client=prisma_client), + payload=payload_copy, + ) await self._update_model_access_group_db( response_cost=response_cost, request_model_access_groups=request_model_access_groups, @@ -1178,96 +1179,64 @@ class DBSpendUpdateWriter: prisma_client=prisma_client, router=get_llm_router(), ) - - _agent_id_for_spend: Final = payload_copy.get("agent_id") - try: - await self._update_agent_db( - response_cost=response_cost, - agent_id=_agent_id_for_spend, - prisma_client=prisma_client, - ) - except Exception: - verbose_proxy_logger.debug( - "_batch_database_updates: _update_agent_db failed: %s", - traceback.format_exc(), - ) - - try: - await self.add_spend_log_transaction_to_daily_user_transaction( - payload=payload_copy, - prisma_client=prisma_client, - ) - except Exception: - verbose_proxy_logger.debug( - "_batch_database_updates: add_spend_log_transaction_to_daily_user_transaction failed: %s", - traceback.format_exc(), - ) - - try: - await self.add_spend_log_transaction_to_daily_end_user_transaction( - payload=payload_copy, - prisma_client=prisma_client, - ) - except Exception: - verbose_proxy_logger.debug( - "_batch_database_updates: add_spend_log_transaction_to_daily_end_user_transaction failed: %s", - traceback.format_exc(), - ) - - try: - await self.add_spend_log_transaction_to_daily_agent_transaction( - payload=payload_copy, - prisma_client=prisma_client, - ) - except Exception: - verbose_proxy_logger.debug( - "_batch_database_updates: add_spend_log_transaction_to_daily_agent_transaction failed: %s", - traceback.format_exc(), - ) - - try: - await self.add_spend_log_transaction_to_daily_team_transaction( - payload=payload_copy, - prisma_client=prisma_client, - ) - except Exception: - verbose_proxy_logger.debug( - "_batch_database_updates: add_spend_log_transaction_to_daily_team_transaction failed: %s", - traceback.format_exc(), - ) + await self._run_spend_update_step( + "_update_agent_db", + self._update_agent_db( + response_cost=response_cost, agent_id=payload_copy.get("agent_id"), prisma_client=prisma_client + ), + payload=payload_copy, + ) + await self._run_spend_update_step( + "add_spend_log_transaction_to_daily_user_transaction", + self.add_spend_log_transaction_to_daily_user_transaction(payload=payload_copy, prisma_client=prisma_client), + payload=payload_copy, + ) + await self._run_spend_update_step( + "add_spend_log_transaction_to_daily_end_user_transaction", + self.add_spend_log_transaction_to_daily_end_user_transaction( + payload=payload_copy, prisma_client=prisma_client + ), + payload=payload_copy, + ) + await self._run_spend_update_step( + "add_spend_log_transaction_to_daily_agent_transaction", + self.add_spend_log_transaction_to_daily_agent_transaction( + payload=payload_copy, prisma_client=prisma_client + ), + payload=payload_copy, + ) + await self._run_spend_update_step( + "add_spend_log_transaction_to_daily_team_transaction", + self.add_spend_log_transaction_to_daily_team_transaction(payload=payload_copy, prisma_client=prisma_client), + payload=payload_copy, + ) try: self._record_request_error(payload=payload_copy, prisma_client=prisma_client) - except Exception: # noqa: BLE001 # the rollup must never skip the sibling spend writes - verbose_proxy_logger.debug( - "_batch_database_updates: _record_request_error failed: %s", - traceback.format_exc(), - ) - - try: - await self.add_spend_log_transaction_to_daily_org_transaction( - payload=payload_copy, - org_id=org_id, - prisma_client=prisma_client, - ) - except Exception: - verbose_proxy_logger.debug( - "_batch_database_updates: add_spend_log_transaction_to_daily_org_transaction failed: %s", - traceback.format_exc(), - ) - - try: - await self.add_spend_log_transaction_to_daily_tag_transaction( - payload=payload_copy, - prisma_client=prisma_client, - ) - except Exception: - verbose_proxy_logger.debug( - "_batch_database_updates: add_spend_log_transaction_to_daily_tag_transaction failed: %s", - traceback.format_exc(), - ) - + except Exception as e: # noqa: BLE001 # the rollup must never skip the sibling spend writes + _report_spend_update_step_failure("_record_request_error", payload=payload_copy, exc=e) + await self._run_spend_update_step( + "add_spend_log_transaction_to_daily_org_transaction", + self.add_spend_log_transaction_to_daily_org_transaction( + payload=payload_copy, org_id=org_id, prisma_client=prisma_client + ), + payload=payload_copy, + ) + await self._run_spend_update_step( + "add_spend_log_transaction_to_daily_tag_transaction", + self.add_spend_log_transaction_to_daily_tag_transaction(payload=payload_copy, prisma_client=prisma_client), + payload=payload_copy, + ) await self._enqueue_model_usage_transaction(payload=payload_copy, prisma_client=prisma_client) + @staticmethod + async def _run_spend_update_step( + step_name: str, step: Coroutine[object, object, object], *, payload: SpendLogsPayload + ) -> None: + try: + await step + except Exception as e: # noqa: BLE001 # one helper failing must not skip the sibling spend writes + _report_spend_update_step_failure(step_name, payload=payload, exc=e) + async def _update_key_db( self, response_cost: float | None, @@ -1657,15 +1626,13 @@ class DBSpendUpdateWriter: window_spend_update_queue=self.window_spend_update_queue, ) - await self._flush_tool_discovery_queue(prisma_client=prisma_client) - # Only commit from redis to db if this pod is the leader if await self.pod_lock_manager.acquire_lock( cronjob_id=DB_SPEND_UPDATE_JOB_NAME, ): verbose_proxy_logger.debug("acquired lock for spend updates") - uncommitted: dict[str, Any] = {} # mutable-ok: tracks popped categories still needing commit + uncommitted: dict[str, _SpendRestore] = {} # mutable-ok: tracks popped categories still needing commit committed_spend_tables: Final[list[_SpendTableName]] = [] # mutable-ok: filled as each table lands try: @@ -1680,13 +1647,41 @@ class DBSpendUpdateWriter: ) = await self.redis_update_buffer.get_all_transactions_from_redis_buffer_pipeline() uncommitted = { - "db_spend_update_transactions": db_spend_update_transactions, - "daily_spend_update_transactions": daily_spend_update_transactions, - "daily_team_spend_update_transactions": daily_team_spend_update_transactions, - "daily_org_spend_update_transactions": daily_org_spend_update_transactions, - "daily_end_user_spend_update_transactions": daily_end_user_spend_update_transactions, - "daily_agent_spend_update_transactions": daily_agent_spend_update_transactions, - "window_spend_update_transactions": window_spend_update_transactions, + "db_spend_update_transactions": ( + {} + if db_spend_update_transactions is None + else {"db_spend_update_transactions": db_spend_update_transactions} + ), + "daily_spend_update_transactions": ( + {} + if daily_spend_update_transactions is None + else {"daily_spend_update_transactions": daily_spend_update_transactions} + ), + "daily_team_spend_update_transactions": ( + {} + if daily_team_spend_update_transactions is None + else {"daily_team_spend_update_transactions": daily_team_spend_update_transactions} + ), + "daily_org_spend_update_transactions": ( + {} + if daily_org_spend_update_transactions is None + else {"daily_org_spend_update_transactions": daily_org_spend_update_transactions} + ), + "daily_end_user_spend_update_transactions": ( + {} + if daily_end_user_spend_update_transactions is None + else {"daily_end_user_spend_update_transactions": daily_end_user_spend_update_transactions} + ), + "daily_agent_spend_update_transactions": ( + {} + if daily_agent_spend_update_transactions is None + else {"daily_agent_spend_update_transactions": daily_agent_spend_update_transactions} + ), + "window_spend_update_transactions": ( + {} + if window_spend_update_transactions is None + else {"window_spend_update_transactions": window_spend_update_transactions} + ), } if db_spend_update_transactions is not None: @@ -1715,9 +1710,12 @@ class DBSpendUpdateWriter: on_table_committed=committed_spend_tables.append, ) except Exception as e: - uncommitted["db_spend_update_transactions"] = _spend_tables_left_to_send( + left_to_send: Final = _spend_tables_left_to_send( db_spend_update_transactions, committed_spend_tables, e ) + uncommitted["db_spend_update_transactions"] = ( + {} if left_to_send is None else {"db_spend_update_transactions": left_to_send} + ) raise uncommitted.pop("db_spend_update_transactions", None) @@ -1772,7 +1770,7 @@ class DBSpendUpdateWriter: window_spend_transactions=window_spend_update_transactions, ) except Exception as e: - if not _spend_commit_failure_is_requeue_safe(e): + if not db_write_failure_is_requeue_safe(e): uncommitted.pop("window_spend_update_transactions", None) spend_log_error( "Spend tracking - dropped %d budget window increments: the failed statement may have " @@ -1791,7 +1789,7 @@ class DBSpendUpdateWriter: exc=e, ) finally: - to_restore = {name: txns for name, txns in uncommitted.items() if txns is not None} + to_restore: Final = reduce(_merged_spend_restore, uncommitted.values(), _SpendRestore()) if to_restore: await self.redis_update_buffer.restore_transactions_to_redis(**to_restore) await self.pod_lock_manager.release_lock( @@ -1938,7 +1936,7 @@ class DBSpendUpdateWriter: window_spend_transactions=window_spend_update_transactions, ) except Exception as e: # noqa: BLE001 # the increments go back on the queue; the rest of the flush must run - if _spend_commit_failure_is_requeue_safe(e): + if db_write_failure_is_requeue_safe(e): spend_log_error( "Spend tracking - failed to commit budget window spend updates. " "Re-queued %d window increments for retry on next tick. Error: %s", @@ -1956,9 +1954,6 @@ class DBSpendUpdateWriter: exc=e, ) - ################## Tool Registry Upserts ################## - await self._flush_tool_discovery_queue(prisma_client=prisma_client) - async def commit_daily_tag_spend_to_db( self, prisma_client: PrismaClient, @@ -2090,20 +2085,6 @@ class DBSpendUpdateWriter: ) raise - async def _flush_tool_discovery_queue( - self, - prisma_client: PrismaClient, - ) -> None: - """Flush ToolDiscoveryQueue and batch-upsert new tools into LiteLLM_ToolTable.""" - from litellm.proxy.db.tool_registry_writer import batch_upsert_tools - - try: - items: Final = self.tool_discovery_queue.flush() - if items: - await batch_upsert_tools(prisma_client=prisma_client, items=items) - except Exception as e: - verbose_proxy_logger.debug("_flush_tool_discovery_queue error (non-blocking): %s", e) - @staticmethod async def handle_spend_update_failure( e: Exception, @@ -2115,7 +2096,6 @@ class DBSpendUpdateWriter: """Retry a failed spend-update transaction on connection errors, deadlocks or a rollup ``lock_timeout`` (55P03), else re-raise. All three roll the transaction back before any increment applied, so re-sending the same batch cannot double-count.""" - from litellm.proxy.db.exception_handler import PrismaDBExceptionHandler from litellm.proxy.utils import raise_failed_update_spend_exception is_retryable = ( @@ -2624,7 +2604,7 @@ class DBSpendUpdateWriter: _mark_daily_spend_commit_started() _mark_daily_spend_commit_finished() except Exception as batch_error: - if _spend_commit_failure_is_requeue_safe(batch_error): + if db_write_failure_is_requeue_safe(batch_error): spend_log_error( "Daily %s spend batch upsert failed. Table: %s, Rows: %d, Error: %s", entity_type, @@ -2810,7 +2790,7 @@ class DBSpendUpdateWriter: date: Final = start_time.isoformat() if isinstance(start_time, datetime) else str(start_time or "") if not date: return - metadata: Final[SpendLogsMetadata] = json.loads(payload["metadata"]) + metadata: Final = _parse_spend_log_metadata(payload) internal_origin: Final = bool(metadata.get(INTERNAL_CALL_ORIGIN_METADATA_KEY)) # pyright: ignore[reportUnknownMemberType] # TypedDict.get overloads carry Any defaults request_error_accumulator.record( payload=payload, @@ -2861,7 +2841,7 @@ class DBSpendUpdateWriter: # spend, token and per-entity columns written here stay either way. request_status: Final = prisma_client.get_request_status(payload) verbose_proxy_logger.debug("Logged request status: %s", request_status) - _metadata: Final[SpendLogsMetadata] = json.loads(payload["metadata"]) + _metadata: Final = _parse_spend_log_metadata(payload) usage_obj: Final = _metadata.get("usage_object", {}) or {} if isinstance(payload["startTime"], datetime): start_time: Final = payload["startTime"].isoformat() diff --git a/litellm/proxy/db/db_transaction_queue/pod_lock_manager.py b/litellm/proxy/db/db_transaction_queue/pod_lock_manager.py index 627b30e83f7..1116cd604a3 100644 --- a/litellm/proxy/db/db_transaction_queue/pod_lock_manager.py +++ b/litellm/proxy/db/db_transaction_queue/pod_lock_manager.py @@ -1,7 +1,7 @@ import asyncio import json import logging -from typing import TYPE_CHECKING, Any, Final +from typing import TYPE_CHECKING, Any, Final, TypeAlias from litellm._internal_context import with_service_target from litellm._logging import verbose_proxy_logger @@ -14,7 +14,9 @@ from litellm.types.services import ServiceTypes POD_LOCK_TARGET: Final = "pod_lock" if TYPE_CHECKING: - ProxyLogging = Any + from litellm.proxy.utils import ProxyLogging as _ProxyLogging + + ProxyLogging: TypeAlias = _ProxyLogging else: ProxyLogging = Any diff --git a/litellm/proxy/db/db_transaction_queue/redis_update_buffer.py b/litellm/proxy/db/db_transaction_queue/redis_update_buffer.py index 54d20bd4507..3a4375ac54a 100644 --- a/litellm/proxy/db/db_transaction_queue/redis_update_buffer.py +++ b/litellm/proxy/db/db_transaction_queue/redis_update_buffer.py @@ -9,8 +9,10 @@ import json from collections.abc import Mapping, Sequence from datetime import datetime from functools import reduce +from itertools import chain from typing import TYPE_CHECKING, Any, Final, Literal, TypeAlias, TypeVar, cast +from pydantic import TypeAdapter from redis.exceptions import RedisError from litellm._internal_context import with_service_target @@ -26,6 +28,7 @@ from litellm.constants import ( REDIS_DAILY_TEAM_SPEND_UPDATE_BUFFER_KEY, REDIS_SPEND_LOGS_BUFFER_KEY, REDIS_SPEND_LOGS_BUFFER_MAX_ROWS, + REDIS_TOOL_DISCOVERY_BUFFER_KEY, REDIS_UPDATE_BUFFER_KEY, REDIS_WINDOW_SPEND_UPDATE_BUFFER_KEY, ) @@ -41,12 +44,17 @@ from litellm.proxy._types import ( DBSpendUpdateTransactions, Litellm_EntityType, SpendUpdateQueueItem, + ToolDiscoveryQueueItem, ) from litellm.proxy.db.db_transaction_queue.base_update_queue import service_logger_obj from litellm.proxy.db.db_transaction_queue.daily_spend_update_queue import ( DailySpendUpdateQueue, ) from litellm.proxy.db.db_transaction_queue.spend_update_queue import SpendUpdateQueue +from litellm.proxy.db.db_transaction_queue.tool_discovery_queue import ( + ToolDiscoveryQueue, + aggregate_tool_discoveries, +) from litellm.proxy.db.db_transaction_queue.window_spend_update_queue import ( WindowSpendTransaction, WindowSpendUpdateQueue, @@ -98,6 +106,7 @@ _SPEND_TRANSACTION_FIELDS: Final[tuple[_SpendTransactionField, ...]] = ( ) _ValueT = TypeVar("_ValueT") +_DECODED_JSON: Final = TypeAdapter(object) def _spend_log_json_default(value: object) -> str: @@ -109,7 +118,7 @@ def _encode_spend_log_row(row: SpendLogRow) -> str: def _decode_spend_log_row(encoded: str) -> dict[str, object] | None: - decoded: Final = json.loads(encoded) + decoded: Final = _DECODED_JSON.validate_python(json.loads(encoded)) return decoded if isinstance(decoded, dict) else None @@ -133,6 +142,9 @@ def _merged_entity_transactions( ) +_TOOL_DISCOVERY_ITEMS: Final = TypeAdapter(list[ToolDiscoveryQueueItem]) + + class RedisUpdateBuffer: """ Handles buffering database `UPDATE` transactions in Redis before committing them to the database @@ -557,6 +569,56 @@ class RedisUpdateBuffer: str(e), ) + @with_service_target(SPEND_QUEUE_TARGET) + async def store_tool_discoveries_in_redis(self, tool_discovery_queue: ToolDiscoveryQueue) -> None: + """Move this worker's pending tool rows to Redis so only the leader writes LiteLLM_ToolTable.""" + if self.redis_cache is None: + return + items: Final = tool_discovery_queue.flush() + if not items: + return + try: + _ = await self.redis_cache.async_rpush_pipeline( + rpush_list=[ + RedisPipelineRpushOperation(key=REDIS_TOOL_DISCOVERY_BUFFER_KEY, values=[safe_dumps(items)]) + ] + ) + except (RedisError, OSError, asyncio.TimeoutError) as e: + verbose_proxy_logger.error( + "Tool discovery - failed to push %d tool rows to Redis, restoring them for the next tick. Error: %s", + len(items), + str(e), + ) + for item in items: + tool_discovery_queue.add_update(item) + + @with_service_target(SPEND_QUEUE_TARGET) + async def restore_tool_discoveries_to_redis(self, items: Sequence[ToolDiscoveryQueueItem]) -> None: + """Put drained tool rows back for the next drain after a write that provably did not apply.""" + if self.redis_cache is None or not items: + return + _ = await self.redis_cache.async_rpush_pipeline( + rpush_list=[ + RedisPipelineRpushOperation(key=REDIS_TOOL_DISCOVERY_BUFFER_KEY, values=[safe_dumps(list(items))]) + ] + ) + + @with_service_target(SPEND_QUEUE_TARGET) + async def get_all_tool_discoveries_from_redis_buffer(self) -> tuple[ToolDiscoveryQueueItem, ...]: + """Drain every worker's tool rows and fold them to one row per tool_name.""" + if self.redis_cache is None: + return () + popped: Final = await self.redis_cache.async_lpop_pipeline( + lpop_list=[ + RedisPipelineLpopOperation(key=REDIS_TOOL_DISCOVERY_BUFFER_KEY, count=MAX_REDIS_BUFFER_DEQUEUE_COUNT) + ] + ) + entries: Final = popped[0] if popped else None + if not entries: + return () + batches: Final = tuple(_TOOL_DISCOVERY_ITEMS.validate_json(entry) for entry in entries) + return aggregate_tool_discoveries(chain.from_iterable(batches)) + @with_service_target(SPEND_QUEUE_TARGET) async def store_spend_logs_in_redis( self, diff --git a/litellm/proxy/db/db_transaction_queue/tool_discovery_queue.py b/litellm/proxy/db/db_transaction_queue/tool_discovery_queue.py index d5f6a447131..e9ec040023c 100644 --- a/litellm/proxy/db/db_transaction_queue/tool_discovery_queue.py +++ b/litellm/proxy/db/db_transaction_queue/tool_discovery_queue.py @@ -1,52 +1,57 @@ """ -In-memory buffer for tool registry upserts. - -Unlike SpendUpdateQueue (which aggregates increments), ToolDiscoveryQueue -uses set-deduplication: each unique tool_name is only queued once per flush -cycle (~30s). The seen-set is cleared on every flush so that call_count -increments in subsequent cycles rather than stopping after the first flush. +In-memory buffer for tool registry upserts, aggregated by tool_name so one flush carries one row per +tool with the number of times it was invoked since the previous flush. """ +from collections.abc import Iterable from typing import Final +from pydantic import TypeAdapter + from litellm._logging import verbose_proxy_logger from litellm.proxy._types import ToolDiscoveryQueueItem +_ITEM: Final = TypeAdapter(ToolDiscoveryQueueItem) + + +def _merged(existing: ToolDiscoveryQueueItem | None, item: ToolDiscoveryQueueItem) -> ToolDiscoveryQueueItem: + """The first sighting keeps its origin and caller fields, later sightings only add to call_count.""" + increment: Final = item.get("call_count", 1) + if existing is None: + return _ITEM.validate_python({**item, "call_count": increment}) + return _ITEM.validate_python({**existing, "call_count": existing.get("call_count", 1) + increment}) + + +def aggregate_tool_discoveries(items: Iterable[ToolDiscoveryQueueItem]) -> tuple[ToolDiscoveryQueueItem, ...]: + """Collapse items to one per tool_name, summing call_count, in first-seen order.""" + by_name: Final[dict[str, ToolDiscoveryQueueItem]] = {} # mutable-ok: single pass fold keyed by tool_name + for item in items: + if not (tool_name := item.get("tool_name", "")): + continue + by_name[tool_name] = _merged(by_name.get(tool_name), item) + return tuple(by_name.values()) + class ToolDiscoveryQueue: - """ - In-memory buffer for tool registry upserts. - - Deduplicates by tool_name within each flush cycle: a tool is only queued - once per ~30s batch, so call_count increments once per flush cycle the - tool appears in (not once per invocation, but not once per pod lifetime - either). The seen-set is cleared on flush so subsequent batches can - re-count the same tool. - """ + """In-memory buffer for tool registry upserts, one pending row per tool_name with a running call_count.""" def __init__(self) -> None: - self._seen_tool_names: set[str] = set() - self._pending: list[ToolDiscoveryQueueItem] = [] + self._pending: dict[str, ToolDiscoveryQueueItem] = {} # mutable-ok: folded per add_update, cleared on flush def add_update(self, item: ToolDiscoveryQueueItem) -> None: - """Enqueue a tool discovery item if tool_name has not been seen before.""" + """Count one more invocation of item's tool_name, keeping the first sighting's origin and caller fields.""" tool_name: Final = item.get("tool_name", "") if not tool_name: return - if tool_name in self._seen_tool_names: - verbose_proxy_logger.debug("ToolDiscoveryQueue: skipping already-seen tool %s", tool_name) - return - self._seen_tool_names.add(tool_name) - self._pending.append(item) + self._pending[tool_name] = _merged(self._pending.get(tool_name), item) verbose_proxy_logger.debug( - "ToolDiscoveryQueue: queued new tool %s (origin=%s)", + "ToolDiscoveryQueue: tool %s call_count=%s (origin=%s)", tool_name, + self._pending[tool_name].get("call_count"), item.get("origin"), ) def flush(self) -> list[ToolDiscoveryQueueItem]: - """Return and clear all pending items. Resets seen-set so the next - flush cycle can re-count the same tools.""" - items, self._pending = self._pending, [] - self._seen_tool_names.clear() + """Return and clear all pending rows.""" + items, self._pending = list(self._pending.values()), {} return items diff --git a/litellm/proxy/db/exception_handler.py b/litellm/proxy/db/exception_handler.py index 379e0012ea8..5dfcaa4b2f8 100644 --- a/litellm/proxy/db/exception_handler.py +++ b/litellm/proxy/db/exception_handler.py @@ -8,6 +8,7 @@ from pydantic import TypeAdapter, ValidationError from litellm._logging import verbose_proxy_logger from litellm.proxy._types import ( DB_CONNECTION_ERROR_TYPES, + DB_RETRY_SAFE_ERROR_TYPES, ProxyErrorTypes, ProxyException, ) @@ -637,3 +638,14 @@ async def call_with_db_reconnect_retry( # propagate — repeated reconnect-loops are the watchdog's job, not # this helper's. return await coro_factory() + + +_DATA_REJECTED_SQLSTATE_CLASSES: Final = frozenset({"22", "23"}) + + +def db_write_failure_is_requeue_safe(e: Exception) -> bool: + """Whether a failed write provably never applied, so its rows can be sent again without double counting.""" + if isinstance(e, DB_CONNECTION_ERROR_TYPES): + return isinstance(e, DB_RETRY_SAFE_ERROR_TYPES) + sqlstate: Final = PrismaDBExceptionHandler.postgres_sqlstate(e) + return sqlstate is None or sqlstate[:2] not in _DATA_REJECTED_SQLSTATE_CLASSES diff --git a/litellm/proxy/db/prisma_client.py b/litellm/proxy/db/prisma_client.py index 53971ed412c..3d783d8aba1 100644 --- a/litellm/proxy/db/prisma_client.py +++ b/litellm/proxy/db/prisma_client.py @@ -1126,6 +1126,18 @@ class PrismaManager: return False return ProxyExtrasDBManager.build_request_log_indexes() + @staticmethod + def migration_data_check_report(use_migrate: bool = True) -> str | None: + """The read-only pre-migration row check on its own, for `--check_migrations_against_existing_data`: the + refusal the migration step would print, or None when the pending schema changes + can be applied to the rows the database has.""" + from litellm_proxy_extras.utils import ( + ProxyExtrasDBManager, # pyright: ignore[reportUnknownVariableType] # litellm-proxy-extras is an optional install + ) + + refusal: Final[object] = ProxyExtrasDBManager.migration_data_check_report(use_migrate=use_migrate) # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] # litellm-proxy-extras is an optional install + return refusal if isinstance(refusal, str) else None + @staticmethod def start_request_log_index_build() -> None: """Build the request-log indexes on a daemon thread, for a serving proxy that ran the diff --git a/litellm/proxy/db/prisma_query_span.py b/litellm/proxy/db/prisma_query_span.py index 75625c6c0f2..2747a765f2a 100644 --- a/litellm/proxy/db/prisma_query_span.py +++ b/litellm/proxy/db/prisma_query_span.py @@ -20,6 +20,8 @@ from dataclasses import dataclass from types import MappingProxyType from typing import Final +from pydantic import TypeAdapter + from litellm.integrations.otel.model.spans import PG_CATALOG, PRISMA_RELATIONS @@ -34,6 +36,7 @@ class PrismaQuery: UNKNOWN_PRISMA_QUERY: Final = PrismaQuery("prisma_query", None, None) +_DECODED_JSON: Final = TypeAdapter(object) _ROOT_FIELD: Final = re.compile(r"result:\s*(\w+)") _RAW_SQL: Final = re.compile(r'query:\s*"((?:[^"\\]|\\.)*)"') @@ -111,7 +114,7 @@ def sql_operation(sql: str) -> tuple[str | None, str | None]: def _query_text(content: str) -> str: try: - payload: Final[object] = json.loads(content) + payload: Final = _DECODED_JSON.validate_python(json.loads(content)) except ValueError: return content query: Final = payload.get("query") if isinstance(payload, dict) else None diff --git a/litellm/proxy/db/proxy_worker_heartbeat.py b/litellm/proxy/db/proxy_worker_heartbeat.py index 673b549b645..3214c0974b4 100644 --- a/litellm/proxy/db/proxy_worker_heartbeat.py +++ b/litellm/proxy/db/proxy_worker_heartbeat.py @@ -56,6 +56,7 @@ class _LiveWorkerCountRow(TypedDict): _COUNT_ROWS_ADAPTER: Final = TypeAdapter(tuple[_LiveWorkerCountRow, ...]) +_RAW_QUERY_RESULT: Final = TypeAdapter(object) class _HeartbeatExecute(Protocol): @@ -99,7 +100,9 @@ async def count_live_proxy_workers(prisma_client: PrismaClient) -> int | None: db: Final = prisma_client.db primary_db: Final = db.writer if isinstance(db, RoutingPrismaWrapper) else db async with db_span("count_live_proxy_workers", "LiteLLM_ProxyWorkerHeartbeat"): - rows: Final = await primary_db.query_raw(COUNT_SQL, PROXY_WORKER_LIVENESS_WINDOW_SECONDS) + rows: Final = _RAW_QUERY_RESULT.validate_python( + await primary_db.query_raw(COUNT_SQL, PROXY_WORKER_LIVENESS_WINDOW_SECONDS) + ) return _COUNT_ROWS_ADAPTER.validate_python(rows)[0]["live_workers"] except Exception as count_err: # noqa: BLE001 # an unknown count must degrade to "warn", never to a 503 verbose_proxy_logger.debug("Live proxy worker count unavailable: %s", count_err) diff --git a/litellm/proxy/db/routing_prisma_wrapper.py b/litellm/proxy/db/routing_prisma_wrapper.py index 48ad57fd06e..52a0be3d49e 100644 --- a/litellm/proxy/db/routing_prisma_wrapper.py +++ b/litellm/proxy/db/routing_prisma_wrapper.py @@ -298,7 +298,7 @@ class RoutingPrismaWrapper: def __getattr__(self, name: str) -> Any: if name in _TOP_LEVEL_READ_METHODS: - return getattr(self.read_target, name) + return _DELEGATED_ATTRIBUTE.validate_python(getattr(self.read_target, name)) writer_attr: Final = _DELEGATED_ATTRIBUTE.validate_python(getattr(self._writer, name)) # Per-model action accessors are non-callable instances that expose # both `find_many` and `create`. Methods like execute_raw / batch_ / diff --git a/litellm/proxy/db/spend_log_tool_index.py b/litellm/proxy/db/spend_log_tool_index.py index 7ac414bec00..591ad81a4e5 100644 --- a/litellm/proxy/db/spend_log_tool_index.py +++ b/litellm/proxy/db/spend_log_tool_index.py @@ -19,7 +19,7 @@ from collections.abc import Mapping, Sequence from dataclasses import dataclass from datetime import datetime, timezone from itertools import chain, groupby -from typing import TYPE_CHECKING, Any, Final, Literal, Protocol +from typing import TYPE_CHECKING, Final, Literal, Protocol from pydantic import BaseModel, ConfigDict, TypeAdapter, ValidationError from typing_extensions import LiteralString @@ -122,7 +122,7 @@ def build_tool_usage_transaction( spend: float, total_tokens: int, completion_response: object, - realtime_tool_calls: Any = None, + realtime_tool_calls: object = None, ) -> ToolUsageTransaction | None: """None when the request invoked no tools. Realtime sessions carry invoked tools in kwargs["realtime_tool_calls"] (OpenAI tool_calls shape) rather than diff --git a/litellm/proxy/db/tool_registry_writer.py b/litellm/proxy/db/tool_registry_writer.py index 2e3530d7613..f7ec88945a1 100644 --- a/litellm/proxy/db/tool_registry_writer.py +++ b/litellm/proxy/db/tool_registry_writer.py @@ -14,8 +14,17 @@ from typing import TYPE_CHECKING, Final, Protocol from pydantic import TypeAdapter from litellm._logging import verbose_proxy_logger +from litellm.constants import TOOL_DISCOVERY_COMMIT_JOB_NAME from litellm.proxy._types import ToolDiscoveryQueueItem -from litellm.proxy.db.exception_handler import call_with_db_reconnect_retry +from litellm.proxy.db.db_span import db_span +from litellm.proxy.db.db_transaction_queue.pod_lock_manager import PodLockManager +from litellm.proxy.db.db_transaction_queue.redis_update_buffer import RedisUpdateBuffer +from litellm.proxy.db.db_transaction_queue.tool_discovery_queue import ( + ToolDiscoveryQueue, + aggregate_tool_discoveries, +) +from litellm.proxy.db.exception_handler import call_with_db_reconnect_retry, db_write_failure_is_requeue_safe +from litellm.proxy.db.tool_table_bulk_upsert import build_tool_bulk_upsert from litellm.repositories.object_permission_repository import ObjectPermissionRepository from litellm.repositories.prisma_protocols import TableActions from litellm.repositories.table_repositories import ToolRepository @@ -105,58 +114,75 @@ def _row_to_model(row: object) -> LiteLLM_ToolTableRow: async def batch_upsert_tools( prisma_client: "PrismaClient", - items: list[ToolDiscoveryQueueItem], + items: Sequence[ToolDiscoveryQueueItem], ) -> None: - """ - Batch-upsert tool registry rows via Prisma. + """Write a batch of discovered tools to LiteLLM_ToolTable in a single statement. Raises on failure so the + caller decides whether the rows can be retried.""" + rows: Final = aggregate_tool_discoveries(items) + if not rows: + return + sql, params = build_tool_bulk_upsert(rows) + async with db_span("commit_tool_discoveries", "LiteLLM_ToolTable"): + await prisma_client.db.execute_raw(sql, *params) # pyright: ignore[reportAny] # untyped prisma client + verbose_proxy_logger.debug("tool_registry_writer: upserted %d tool(s)", len(rows)) - On first insert: sets input_policy/output_policy = "untrusted" (default), call_count = 1. - On conflict: increments call_count; preserves existing policies. - """ + +async def flush_tool_discovery_queue(prisma_client: "PrismaClient", tool_discovery_queue: ToolDiscoveryQueue) -> None: + """One worker's own rows straight to LiteLLM_ToolTable, the path without the Redis buffer.""" + items: Final = tool_discovery_queue.flush() if not items: return try: - data: Final = [item for item in items if item.get("tool_name")] - if not data: - return - now: Final = datetime.now(timezone.utc) - table: Final = _tool_table_actions(prisma_client) - for item in data: - tool_name = item.get("tool_name", "") - origin = item.get("origin") or "user_defined" - created_by = item.get("created_by") or "system" - key_hash = item.get("key_hash") - team_id = item.get("team_id") - key_alias = item.get("key_alias") - user_agent = item.get("user_agent") - await table.upsert( - where={"tool_name": tool_name}, - data={ - "create": { - "tool_id": str(uuid.uuid4()), - "tool_name": tool_name, - "origin": origin, - "input_policy": "untrusted", - "output_policy": "untrusted", - "call_count": 1, - "created_by": created_by, - "updated_by": created_by, - "key_hash": key_hash, - "team_id": team_id, - "key_alias": key_alias, - "user_agent": user_agent, - "last_used_at": now, - }, - "update": { - "call_count": {"increment": 1}, - "updated_at": now, - "last_used_at": now, - }, - }, + await batch_upsert_tools(prisma_client=prisma_client, items=items) + except Exception as e: # noqa: BLE001 # a lost tool row only delays its discovery, the scheduler job must not fail + verbose_proxy_logger.debug("flush_tool_discovery_queue error (non-blocking): %s", e) + + +async def commit_tool_discoveries( + prisma_client: "PrismaClient", + tool_discovery_queue: ToolDiscoveryQueue, + redis_update_buffer: RedisUpdateBuffer, + pod_lock_manager: PodLockManager, + use_redis_buffer: bool, +) -> None: + """Scheduled alongside update_spend on its own lock, so tool table writes never ride the spend commit. + + With the Redis buffer every worker hands its rows to Redis and the holder of the tool lock writes them all in + one statement. Without it each worker writes its own rows.""" + if not use_redis_buffer: + await flush_tool_discovery_queue(prisma_client=prisma_client, tool_discovery_queue=tool_discovery_queue) + return + await redis_update_buffer.store_tool_discoveries_in_redis(tool_discovery_queue=tool_discovery_queue) + if not await pod_lock_manager.acquire_lock(cronjob_id=TOOL_DISCOVERY_COMMIT_JOB_NAME): + return + try: + await _commit_tool_discoveries_from_redis(prisma_client=prisma_client, redis_update_buffer=redis_update_buffer) + finally: + await pod_lock_manager.release_lock(cronjob_id=TOOL_DISCOVERY_COMMIT_JOB_NAME) + + +async def _commit_tool_discoveries_from_redis( + prisma_client: "PrismaClient", redis_update_buffer: RedisUpdateBuffer +) -> None: + """Tool lock holder only: drain every worker's tool rows from Redis and write them in one statement.""" + items: Final = await redis_update_buffer.get_all_tool_discoveries_from_redis_buffer() + if not items: + return + try: + await batch_upsert_tools(prisma_client=prisma_client, items=items) + except Exception as e: # noqa: BLE001 # the rows go back to redis or are dropped, the scheduler job must not fail + if db_write_failure_is_requeue_safe(e): + await redis_update_buffer.restore_tool_discoveries_to_redis(items) + verbose_proxy_logger.error( + "Tool discovery - %d tool rows went back to Redis for the next tick. Error: %s", len(items), str(e) ) - verbose_proxy_logger.debug("tool_registry_writer: upserted %d tool(s)", len(data)) - except Exception as e: - verbose_proxy_logger.error("tool_registry_writer batch_upsert_tools error: %s", e) + return + verbose_proxy_logger.error( + "Tool discovery - dropped %d tool rows: the failed statement may have applied or the database " + "refused the data, so re-sending it is not safe. Error: %s", + len(items), + str(e), + ) _NO_OWNERS: Final[Mapping[str, ToolDiscoveryUser]] = MappingProxyType({}) diff --git a/litellm/proxy/db/tool_table_bulk_upsert.py b/litellm/proxy/db/tool_table_bulk_upsert.py new file mode 100644 index 00000000000..e586042ae7c --- /dev/null +++ b/litellm/proxy/db/tool_table_bulk_upsert.py @@ -0,0 +1,71 @@ +"""One multi-row ``INSERT ... ON CONFLICT ("tool_name") DO UPDATE`` per batch of discovered tools. + +LiteLLM_ToolTable holds one row per tool name the proxy has seen. A batch arrives already folded to one +entry per tool name with a summed call_count, and this statement inserts the names the table has not seen +with the untrusted policies the columns default to, and for the names it has adds the batch's call_count +while leaving the policies and the discovering caller's fields alone. Same shape as daily_spend_bulk_upsert. +""" + +import uuid +from collections.abc import Mapping, Sequence +from itertools import chain +from types import MappingProxyType +from typing import Final, TypeAlias + +from litellm.proxy._types import ToolDiscoveryQueueItem + +SqlValue: TypeAlias = str | int | None + +_TOOL_ROW_COLUMNS: Final[tuple[str, ...]] = ( + "tool_id", + "tool_name", + "origin", + "call_count", + "created_by", + "updated_by", + "key_hash", + "team_id", + "key_alias", + "user_agent", +) +_CASTS: Final[Mapping[str, str]] = MappingProxyType({"call_count": "integer"}) + + +def _row_params(item: ToolDiscoveryQueueItem) -> tuple[SqlValue, ...]: + created_by: Final = item.get("created_by") or "system" + return ( + str(uuid.uuid4()), + item.get("tool_name", ""), + item.get("origin") or "user_defined", + item.get("call_count", 1), + created_by, + created_by, + item.get("key_hash"), + item.get("team_id"), + item.get("key_alias"), + item.get("user_agent"), + ) + + +def build_tool_bulk_upsert(items: Sequence[ToolDiscoveryQueueItem]) -> tuple[str, tuple[SqlValue, ...]]: + """The single statement writing one batch of distinct tool_names, plus its positional arguments.""" + width: Final = len(_TOOL_ROW_COLUMNS) + rows: Final = ", ".join( + "(" + + ", ".join( + f"${row_index * width + offset + 1}::{_CASTS.get(column, 'text')}" + for offset, column in enumerate(_TOOL_ROW_COLUMNS) + ) + + ", (NOW() AT TIME ZONE 'UTC'), (NOW() AT TIME ZONE 'UTC'))" + for row_index in range(len(items)) + ) + columns: Final = ", ".join(f'"{column}"' for column in _TOOL_ROW_COLUMNS) + sql: Final = ( + f'INSERT INTO "LiteLLM_ToolTable" ({columns}, "last_used_at", "updated_at")\n' + f"VALUES {rows}\n" + 'ON CONFLICT ("tool_name") DO UPDATE SET\n' + ' "call_count" = "LiteLLM_ToolTable"."call_count" + EXCLUDED."call_count",\n' + ' "last_used_at" = EXCLUDED."last_used_at",\n' + ' "updated_at" = EXCLUDED."updated_at"' + ) + return sql, tuple(chain.from_iterable(map(_row_params, items))) diff --git a/litellm/proxy/discovery_endpoints/agent_skills_archive.py b/litellm/proxy/discovery_endpoints/agent_skills_archive.py index 1f2fca3992e..94a0c3e2cf1 100644 --- a/litellm/proxy/discovery_endpoints/agent_skills_archive.py +++ b/litellm/proxy/discovery_endpoints/agent_skills_archive.py @@ -16,6 +16,7 @@ from types import MappingProxyType from typing import Final import yaml +from pydantic import TypeAdapter MAX_ARCHIVE_UNPACKED_BYTES: Final = 50 * 1024 * 1024 MAX_ARCHIVE_ENTRIES: Final = 1000 @@ -26,6 +27,7 @@ _ZIP_ENTRY_PERMISSIONS: Final = 0o644 << 16 _FRONTMATTER_PATTERN: Final = re.compile(r"^---\s*\n(.*?)\n---\s*(?:\n|$)", re.DOTALL) _WINDOWS_DRIVE_PATTERN: Final = re.compile(r"^[A-Za-z]:") _EMPTY_FRONTMATTER: Final[Mapping[str, object]] = MappingProxyType({}) +_DECODED_YAML: Final = TypeAdapter(object) @dataclass(frozen=True, slots=True) @@ -100,7 +102,7 @@ def _manifest_frontmatter(manifest: bytes) -> Mapping[str, object]: if match is None: return _EMPTY_FRONTMATTER try: - parsed: Final = yaml.safe_load(match.group(1)) + parsed: Final = _DECODED_YAML.validate_python(yaml.safe_load(match.group(1))) except yaml.YAMLError: return _EMPTY_FRONTMATTER if not isinstance(parsed, dict): diff --git a/litellm/proxy/discovery_endpoints/agent_skills_endpoints.py b/litellm/proxy/discovery_endpoints/agent_skills_endpoints.py index 2050cc40e6d..830f7b0334e 100644 --- a/litellm/proxy/discovery_endpoints/agent_skills_endpoints.py +++ b/litellm/proxy/discovery_endpoints/agent_skills_endpoints.py @@ -10,7 +10,6 @@ import asyncio import re from collections.abc import Sequence from itertools import groupby -from operator import itemgetter from types import MappingProxyType from typing import Final @@ -173,11 +172,15 @@ def _slugify(raw: str | None) -> str | None: return _NON_SLUG_PATTERN.sub("-", raw.lower()).strip("-")[:MAX_SKILL_NAME_LENGTH].rstrip("-") or None +def _entry_name(entry: tuple[int, str]) -> str: + return entry[1] + + def _deduplicated(names: Sequence[str]) -> tuple[str, ...]: ordinals: Final = MappingProxyType( { position: ordinal - for _, duplicates in groupby(sorted(enumerate(names), key=itemgetter(1)), key=itemgetter(1)) + for _, duplicates in groupby(sorted(enumerate(names), key=_entry_name), key=_entry_name) for ordinal, (position, _) in enumerate(duplicates) } ) diff --git a/litellm/proxy/discovery_endpoints/ui_discovery_endpoints.py b/litellm/proxy/discovery_endpoints/ui_discovery_endpoints.py index 86e77596e70..8225984a964 100644 --- a/litellm/proxy/discovery_endpoints/ui_discovery_endpoints.py +++ b/litellm/proxy/discovery_endpoints/ui_discovery_endpoints.py @@ -4,8 +4,8 @@ from typing import Final from fastapi import APIRouter -from litellm.proxy._experimental.mcp_server.stdio_gate import is_mcp_stdio_enabled from litellm.proxy.common_utils.html_forms.default_credentials_hint import should_hide_default_credentials_hint +from litellm.proxy.mcp_server.stdio_gate import is_mcp_stdio_enabled from litellm.types.proxy.discovery_endpoints.ui_discovery_endpoints import ( UiDiscoveryEndpoints, ) diff --git a/litellm/proxy/example_config_yaml/custom_auth.py b/litellm/proxy/example_config_yaml/custom_auth.py index b7646ce5e3d..c53074638c6 100644 --- a/litellm/proxy/example_config_yaml/custom_auth.py +++ b/litellm/proxy/example_config_yaml/custom_auth.py @@ -30,7 +30,7 @@ async def generate_key_fn(data: GenerateKeyRequest): data_json: Final = data.json() # Unpacking variables - team_id: Final = data_json.get("team_id") + team_id: Final = data.team_id data_json.get("duration") data_json.get("models") data_json.get("aliases") diff --git a/litellm/proxy/example_config_yaml/custom_callbacks.py b/litellm/proxy/example_config_yaml/custom_callbacks.py index 2c689811dc8..5ae55060930 100644 --- a/litellm/proxy/example_config_yaml/custom_callbacks.py +++ b/litellm/proxy/example_config_yaml/custom_callbacks.py @@ -7,10 +7,14 @@ import traceback sys.path.insert(0, os.path.abspath("../..")) # Adds the parent directory to the system path import inspect +from typing import Final + +from pydantic import TypeAdapter import litellm from litellm.integrations.custom_logger import CustomLogger -from typing import Final + +_ATTRIBUTE_VALUE: Final = TypeAdapter(object) # This file includes the custom callbacks for LiteLLM Proxy @@ -27,7 +31,11 @@ class MyCustomHandler(CustomLogger): print_verbose(f"{blue_color_code}Initialized LiteLLM custom logger") try: print_verbose("Logger Initialized with following methods:") - methods: Final = [method for method in dir(self) if inspect.ismethod(getattr(self, method))] + methods: Final = [ + method + for method in dir(self) + if inspect.ismethod(_ATTRIBUTE_VALUE.validate_python(getattr(self, method))) + ] # Pretty print_verbose the methods for method in methods: diff --git a/litellm/proxy/guardrails/_content_utils.py b/litellm/proxy/guardrails/_content_utils.py index 17bea031794..8581dca603b 100644 --- a/litellm/proxy/guardrails/_content_utils.py +++ b/litellm/proxy/guardrails/_content_utils.py @@ -9,8 +9,9 @@ every text fragment. """ from collections.abc import Callable, Iterator, Mapping, Sequence -from typing import Any, Final +from typing import Final +from litellm.litellm_core_utils.core_helpers import iter_items from litellm.responses.litellm_completion_transformation.compaction_items import ( compaction_summary, input_items, @@ -231,7 +232,7 @@ def is_string_batch_input(data: Mapping[str, object]) -> bool: return isinstance(input_value, list) and bool(input_value) and all(isinstance(item, str) for item in input_value) -def apply_redacted_messages_back(data: dict[str, Any], redacted_messages: Sequence[object]) -> bool: +def apply_redacted_messages_back(data: dict[str, object], redacted_messages: Sequence[object]) -> bool: """Write redacted messages back to whichever field(s) the caller used. Mask/anonymize paths take a synthesised messages list (from @@ -249,9 +250,9 @@ def apply_redacted_messages_back(data: dict[str, Any], redacted_messages: Sequen carry exactly one message per inspected element: a partial rewrite would forward the remaining originals unredacted. Callers must block on False. """ + input_value: Final = data.get("input") if is_string_batch_input(data): - batch: Final = data["input"] - inspected_indices: Final = tuple(idx for idx, item in enumerate(batch) if item) + inspected_indices: Final = tuple(idx for idx, item in enumerate(iter_items(input_value)) if item) if len(redacted_messages) != len(inspected_indices): return False if any(not isinstance(message, Mapping) or message.get("content") is None for message in redacted_messages): @@ -259,12 +260,12 @@ def apply_redacted_messages_back(data: dict[str, Any], redacted_messages: Sequen redacted_texts: Final = tuple( "\n".join(_iter_text_parts_in_content(message["content"])) for message in redacted_messages ) - for idx, text in zip(inspected_indices, redacted_texts): - batch[idx] = text + if isinstance(input_value, list): + for idx, text in zip(inspected_indices, redacted_texts): + input_value[idx] = text return True if "messages" in data: data["messages"] = redacted_messages - input_value: Final = data.get("input") if isinstance(input_value, str): text_parts: Final[list[str]] = [] for msg in redacted_messages: diff --git a/litellm/proxy/guardrails/anthropic_sse.py b/litellm/proxy/guardrails/anthropic_sse.py index 2baeabdce7b..3f19f5cb386 100644 --- a/litellm/proxy/guardrails/anthropic_sse.py +++ b/litellm/proxy/guardrails/anthropic_sse.py @@ -13,15 +13,15 @@ from types import MappingProxyType from typing import Final from litellm.litellm_core_utils.core_helpers import as_str_mapping -from litellm.llms.anthropic.pass_through.messages.utils import filtered_safeguard_results, redacted_stop_details -from litellm.llms.anthropic.pass_through.stream_assembly import anthropic_message_delta_fields -from litellm.llms.anthropic.pass_through.stream_assembly import ( +from litellm.llms.anthropic.messages.native.utils import filtered_safeguard_results, redacted_stop_details +from litellm.llms.anthropic.messages.stream_assembly import anthropic_message_delta_fields +from litellm.llms.anthropic.messages.stream_assembly import ( assemble_anthropic_sse_stream as assemble_anthropic_sse_stream, # noqa: PLC0414 # public re-export ) -from litellm.llms.anthropic.pass_through.stream_assembly import ( +from litellm.llms.anthropic.messages.stream_assembly import ( is_anthropic_sse_stream as is_anthropic_sse_stream, # noqa: PLC0414 # public re-export ) -from litellm.llms.anthropic.pass_through.stream_assembly import ( +from litellm.llms.anthropic.messages.stream_assembly import ( is_raw_sse_stream as is_raw_sse_stream, # noqa: PLC0414 # public re-export ) from litellm.types.utils import Choices, ModelResponse @@ -50,7 +50,7 @@ def anthropic_sse_error_frames(message: str) -> tuple[bytes, ...]: ) -from litellm.llms.anthropic.pass_through.stream_assembly import ( # noqa: E402 # re-export after the definitions above +from litellm.llms.anthropic.messages.stream_assembly import ( # noqa: E402 # re-export after the definitions above is_sse_error_stream as is_sse_error_stream, # noqa: PLC0414 # public re-export ) @@ -111,10 +111,10 @@ def anthropic_sse_chunks_from_response( the input the classifier judged. Their free-text ``explanation`` was written about the text the guardrail rewrote, so it is dropped unless the caller rewrites no text (``keep_explanations``). """ - from litellm.llms.anthropic.pass_through.adapters.transformation import ( + from litellm.llms.anthropic.messages.adapters.transformation import ( LiteLLMAnthropicMessagesAdapter, ) - from litellm.llms.anthropic.pass_through.messages.fake_stream_iterator import ( + from litellm.llms.anthropic.messages.native.fake_stream_iterator import ( FakeAnthropicMessagesStreamIterator, ) diff --git a/litellm/proxy/guardrails/guardrail_endpoints.py b/litellm/proxy/guardrails/guardrail_endpoints.py index 70e7aac12b5..a5822bfb0e3 100644 --- a/litellm/proxy/guardrails/guardrail_endpoints.py +++ b/litellm/proxy/guardrails/guardrail_endpoints.py @@ -90,6 +90,7 @@ if TYPE_CHECKING: router: Final = APIRouter() GUARDRAIL_REGISTRY: Final = GuardrailRegistry() _DECODED_JSON: Final = TypeAdapter(object) +_DECODED_YAML: Final = TypeAdapter(object) def _as_str_object_mapping(mapping: Mapping[str, object]) -> Mapping[str, object]: @@ -1682,7 +1683,7 @@ async def validate_blocked_words_file(request: dict[str, str]): if not file_content: return {"valid": False, "error": "No file content provided"} - data: Final = yaml.safe_load(file_content) + data: Final = _DECODED_YAML.validate_python(yaml.safe_load(file_content)) if not isinstance(data, dict) or "blocked_words" not in data: return { diff --git a/litellm/proxy/guardrails/guardrail_hooks/agent_365/agent_365.py b/litellm/proxy/guardrails/guardrail_hooks/agent_365/agent_365.py index ac0a6911184..aabac874ca2 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/agent_365/agent_365.py +++ b/litellm/proxy/guardrails/guardrail_hooks/agent_365/agent_365.py @@ -63,6 +63,7 @@ _INVALID_ASSERTION_AADSTS_PREFIX: Final = "50027" _AADSTS_CODES_ADAPTER: Final = TypeAdapter(tuple[int, ...]) _MCP_CALL_TYPES: Final[tuple[str, ...]] = ("mcp_call", "call_mcp_tool") _TOOL_INPUT_SCHEMA_ADAPTER: Final = TypeAdapter(dict[str, object]) +_DECODED_JSON: Final = TypeAdapter(object) _OBO_CACHE_MAX_ENTRIES: Final = 1000 _DEFAULT_TOKEN_TTL_SECONDS: Final = 3599.0 _TOKEN_EXPIRY_SLACK_SECONDS: Final = 60.0 @@ -343,7 +344,7 @@ class Agent365Guardrail(CustomGuardrail): latency_ms: float, ) -> dict: # mutable-ok: returns the request data dict per hook contract try: - parsed_verdict: Final = response.json() + parsed_verdict: Final = _DECODED_JSON.validate_python(response.json()) except ValueError: return self._handle_unavailable( data=data, @@ -486,7 +487,7 @@ class Agent365Guardrail(CustomGuardrail): response=response, ) try: - parsed_body: Final = response.json() + parsed_body: Final = _DECODED_JSON.validate_python(response.json()) except ValueError as exc: raise Agent365MalformedResponseError("the Entra token endpoint returned a non-JSON body") from exc if not isinstance(parsed_body, dict): diff --git a/litellm/proxy/guardrails/guardrail_hooks/airia/airia.py b/litellm/proxy/guardrails/guardrail_hooks/airia/airia.py index 993c1d30949..389706d7417 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/airia/airia.py +++ b/litellm/proxy/guardrails/guardrail_hooks/airia/airia.py @@ -2,12 +2,13 @@ import os import uuid from collections.abc import Mapping from typing import ( - Any, # noqa: TID251 # the only type CustomGuardrail.__init__ accepts for its open-ended kwargs Final, Literal, ) import httpx +from pydantic import TypeAdapter +from typing_extensions import TypedDict, Unpack from litellm._logging import verbose_proxy_logger from litellm.exceptions import GuardrailRaisedException @@ -36,6 +37,12 @@ DEFAULT_BLOCKED_MESSAGE: Final = "Blocked by your organization's content policy. SUPPORTED_EVENT_HOOKS: Final = (GuardrailEventHooks.pre_call, GuardrailEventHooks.post_call) +_DECODED_JSON: Final = TypeAdapter(object) + + +class _CustomGuardrailOptions(TypedDict, total=False, extra_items=object): + pass + def _stream_cannot_carry_a_rewrite(request_data: Mapping[str, object] | None) -> bool: """Whether this is a streamed response on a route the framework can only block, not rewrite. @@ -97,7 +104,7 @@ class AiriaGuardrail(CustomGuardrail): timeout: float | None = None, supported_event_hooks: list[GuardrailEventHooks] | None = None, # mutable-ok: matches CustomGuardrail.__init__ async_handler: AsyncHTTPHandler | None = None, # dependency-injected in tests; defaults to a real client - **kwargs: Any, # kwargs-ok: passed straight through to CustomGuardrail.__init__ + **kwargs: Unpack[_CustomGuardrailOptions], # kwargs-ok: passed straight through to CustomGuardrail.__init__ ) -> None: resolved_timeout: Final = timeout or float(os.getenv("AIRIA_TIMEOUT", "10")) @@ -161,7 +168,7 @@ class AiriaGuardrail(CustomGuardrail): headers={"Authorization": f"Bearer {self.api_key}"}, ) response.raise_for_status() - raw_body: Final[object] = response.json() + raw_body: Final = _DECODED_JSON.validate_python(response.json()) body: Final = _as_object(raw_body) if body is None: raise TypeError(f"expected a JSON object in the response body, got {type(raw_body).__name__}") diff --git a/litellm/proxy/guardrails/guardrail_hooks/akto/akto.py b/litellm/proxy/guardrails/guardrail_hooks/akto/akto.py index 224f1f78270..da131931aec 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/akto/akto.py +++ b/litellm/proxy/guardrails/guardrail_hooks/akto/akto.py @@ -38,9 +38,9 @@ from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, httpxSpecialProvider, ) -from litellm.proxy._experimental.mcp_server.utils import JSONLeafPath, json_string_leaves from litellm.proxy._types import SpecialHeaders from litellm.proxy.litellm_pre_call_utils import get_chain_id_from_headers +from litellm.proxy.mcp_server.utils import JSONLeafPath, json_string_leaves from litellm.types.guardrails import GuardrailEventHooks, LitellmParams, Mode from litellm.types.proxy.guardrails.guardrail_hooks.akto import AktoGuardrailConfigModelOptionalParams from litellm.types.utils import CallTypes, GenericGuardrailAPIInputs diff --git a/litellm/proxy/guardrails/guardrail_hooks/block_code_execution/__init__.py b/litellm/proxy/guardrails/guardrail_hooks/block_code_execution/__init__.py index 64770fdf0f7..5bf471265c8 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/block_code_execution/__init__.py +++ b/litellm/proxy/guardrails/guardrail_hooks/block_code_execution/__init__.py @@ -2,6 +2,7 @@ from typing import TYPE_CHECKING, Final, Literal, cast +from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.types.guardrails import GuardrailEventHooks, SupportedGuardrailIntegrations from .block_code_execution import BlockCodeExecutionGuardrail @@ -26,7 +27,7 @@ def _get_param( value: Final = getattr(litellm_params, key, default) if value is not None: return value - raw: Final = guardrail.get("litellm_params") + raw: Final = as_str_mapping(guardrail.get("litellm_params")) if isinstance(raw, dict) and key in raw: return raw[key] return default diff --git a/litellm/proxy/guardrails/guardrail_hooks/cato_networks/cato_networks.py b/litellm/proxy/guardrails/guardrail_hooks/cato_networks/cato_networks.py index 936f862b10b..19b9bccd8aa 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/cato_networks/cato_networks.py +++ b/litellm/proxy/guardrails/guardrail_hooks/cato_networks/cato_networks.py @@ -23,6 +23,7 @@ from litellm import DualCache from litellm._logging import verbose_proxy_logger from litellm._version import version as litellm_version from litellm.integrations.custom_guardrail import CustomGuardrail +from litellm.litellm_core_utils.core_helpers import iter_items from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, get_ssl_configuration, @@ -222,7 +223,7 @@ class CatoNetworksGuardrail(CustomGuardrail): return [] @staticmethod - def _iter_schema_string_refs(data: Mapping[str, Any]): + def _iter_schema_string_refs(data: Mapping[str, object]): """Yield ``(container, key)`` for every non-empty schema string the proxy forwards to the model inside tool/function and structured-output schemas: each ``tools[].function`` and legacy ``functions[]`` entry plus the @@ -235,10 +236,10 @@ class CatoNetworksGuardrail(CustomGuardrail): list_keys: Final = ("enum", "examples") stack: Final[list] = [] - for tool in data.get("tools") or []: + for tool in iter_items(data.get("tools") or ()): if isinstance(tool, dict) and isinstance(tool.get("function"), dict): stack.append(tool["function"]) - for function in data.get("functions") or []: + for function in iter_items(data.get("functions") or ()): if isinstance(function, dict): stack.append(function) response_format: Final = data.get("response_format") diff --git a/litellm/proxy/guardrails/guardrail_hooks/cisco_ai_defense/cisco_ai_defense.py b/litellm/proxy/guardrails/guardrail_hooks/cisco_ai_defense/cisco_ai_defense.py index ab43d32e260..45e785fd53c 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/cisco_ai_defense/cisco_ai_defense.py +++ b/litellm/proxy/guardrails/guardrail_hooks/cisco_ai_defense/cisco_ai_defense.py @@ -35,6 +35,7 @@ from litellm.integrations.custom_guardrail import ( CustomGuardrail, log_guardrail_information, ) +from litellm.litellm_core_utils.core_helpers import iter_items from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, httpxSpecialProvider, @@ -1743,7 +1744,7 @@ class CiscoAIDefenseGuardrail(CiscoAIDefenseMcpMixin, CustomGuardrail): @staticmethod def _extract_masked_entity_count( - rules: list[dict[str, Any]], + rules: Sequence[Mapping[str, object]], ) -> dict[str, int] | None: """Count entity-type detections per Cisco rule for the logging payload.""" if not rules: @@ -1752,8 +1753,7 @@ class CiscoAIDefenseGuardrail(CiscoAIDefenseMcpMixin, CustomGuardrail): for rule in rules: if not isinstance(rule, dict): continue - entity_types = rule.get("entity_types") or [] - for entity_type in entity_types: + for entity_type in iter_items(rule.get("entity_types") or ()): if not isinstance(entity_type, str): continue counts[entity_type] = counts.get(entity_type, 0) + 1 diff --git a/litellm/proxy/guardrails/guardrail_hooks/compresr/__init__.py b/litellm/proxy/guardrails/guardrail_hooks/compresr/__init__.py index 498f9bf4099..c5ca97ff760 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/compresr/__init__.py +++ b/litellm/proxy/guardrails/guardrail_hooks/compresr/__init__.py @@ -2,6 +2,7 @@ from __future__ import annotations from typing import TYPE_CHECKING, Final +from litellm.litellm_core_utils.core_helpers import attribute_or_none from litellm.types.guardrails import ( GuardrailEventHooks, Mode, @@ -26,7 +27,7 @@ def _coerce_event_hook( def _get_optional_value(litellm_params: LitellmParams, optional_params: object | None, attribute_name: str) -> object: if optional_params is not None: - value: Final = getattr(optional_params, attribute_name, None) + value: Final = attribute_or_none(optional_params, attribute_name) if value is not None: return value return getattr(litellm_params, attribute_name, None) diff --git a/litellm/proxy/guardrails/guardrail_hooks/compresr/compresr.py b/litellm/proxy/guardrails/guardrail_hooks/compresr/compresr.py index 029feba89fb..4d910cde603 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/compresr/compresr.py +++ b/litellm/proxy/guardrails/guardrail_hooks/compresr/compresr.py @@ -28,6 +28,7 @@ from urllib.parse import urlparse import httpx from fastapi import HTTPException from httpx import Response as HttpxResponse +from pydantic import TypeAdapter import litellm from litellm._logging import verbose_proxy_logger @@ -72,6 +73,7 @@ if TYPE_CHECKING: ) BYPASS_HEADER: Final = "x-compresr-bypass" +_AGENTIC_LOOP_MODEL: Final = TypeAdapter(object) COMPRESR_RETRIEVE_TOOL_NAME: Final = "compresr_retrieve" DEFAULT_API_BASE: Final = "https://api.compresr.ai" DEFAULT_COMPRESSION_MODEL: Final = "latte_v2" @@ -1118,7 +1120,7 @@ class CompresrGuardrail(CustomGuardrail): full_model_name = model if logging_obj is not None: agentic_params: Final = getattr(logging_obj, "model_call_details", {}).get("agentic_loop_params", {}) - candidate: Final = agentic_params.get("model", model) + candidate: Final = _AGENTIC_LOOP_MODEL.validate_python(agentic_params.get("model", model)) if isinstance(candidate, str) and candidate: full_model_name = candidate diff --git a/litellm/proxy/guardrails/guardrail_hooks/crowdstrike_aidr/crowdstrike_aidr.py b/litellm/proxy/guardrails/guardrail_hooks/crowdstrike_aidr/crowdstrike_aidr.py index 34725803c60..ee3a957f607 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/crowdstrike_aidr/crowdstrike_aidr.py +++ b/litellm/proxy/guardrails/guardrail_hooks/crowdstrike_aidr/crowdstrike_aidr.py @@ -5,7 +5,7 @@ from collections.abc import Mapping, Sequence from typing import TYPE_CHECKING, Annotated, Final, Literal, NamedTuple, Optional, cast from fastapi import HTTPException -from pydantic import ConfigDict, Field, ValidationError +from pydantic import ConfigDict, Field, TypeAdapter, ValidationError from typing_extensions import override from litellm._logging import verbose_proxy_logger @@ -37,6 +37,8 @@ if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj from litellm.types.proxy.guardrails.guardrail_hooks.base import GuardrailConfigModel +_DECODED_JSON: Final = TypeAdapter(object) + class CrowdStrikeAIDRGuardrailMissingSecrets(Exception): """Custom exception for missing CrowdStrike AIDR secrets.""" @@ -362,7 +364,7 @@ class CrowdStrikeAIDRHandler(CustomGuardrail): assert response is not None response.raise_for_status() - response_body: Final[object] = response.json() + response_body: Final = _DECODED_JSON.validate_python(response.json()) raw_result: Final[object] = response_body.get("result") if isinstance(response_body, dict) else None blocked_signal: Final[object] = raw_result.get("blocked") if isinstance(raw_result, dict) else None diff --git a/litellm/proxy/guardrails/guardrail_hooks/custom_code/__init__.py b/litellm/proxy/guardrails/guardrail_hooks/custom_code/__init__.py index 13d7178dfe9..0f9ce15e65b 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/custom_code/__init__.py +++ b/litellm/proxy/guardrails/guardrail_hooks/custom_code/__init__.py @@ -39,7 +39,7 @@ def initialize_guardrail(litellm_params: "LitellmParams", guardrail: "Guardrail" raise ValueError("Custom code guardrail requires a guardrail_name") # Get the custom code from litellm_params - custom_code: Final = getattr(litellm_params, "custom_code", None) + custom_code: Final = litellm_params.custom_code if not custom_code: raise ValueError("Custom code guardrail requires 'custom_code' in litellm_params") diff --git a/litellm/proxy/guardrails/guardrail_hooks/generic_guardrail_api/generic_guardrail_api.py b/litellm/proxy/guardrails/guardrail_hooks/generic_guardrail_api/generic_guardrail_api.py index 199da7df30d..ecd23d86540 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/generic_guardrail_api/generic_guardrail_api.py +++ b/litellm/proxy/guardrails/guardrail_hooks/generic_guardrail_api/generic_guardrail_api.py @@ -21,6 +21,7 @@ from litellm.integrations.custom_guardrail import ( CustomGuardrail, log_guardrail_information, ) +from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.llms.custom_httpx.http_handler import ( AsyncHTTPHandler, get_async_httpx_client, @@ -126,6 +127,13 @@ def _sanitize_inbound_headers( return sanitized or None +def _logged_inbound_headers(details: Mapping[str, object]) -> Mapping[object, object] | None: + litellm_params: Final = as_str_mapping(details.get("litellm_params", {})) + metadata: Final = as_str_mapping(litellm_params.get("metadata", {})) if litellm_params is not None else None + headers: Final = metadata.get("headers", None) if metadata is not None else None + return headers if isinstance(headers, dict) else None + + def _extract_inbound_headers( request_data: dict, logging_obj: Optional["LiteLLMLoggingObj"], @@ -163,7 +171,7 @@ def _extract_inbound_headers( if logging_obj and getattr(logging_obj, "model_call_details", None): try: details: Final = logging_obj.model_call_details or {} - headers = details.get("litellm_params", {}).get("metadata", {}).get("headers", None) + headers = _logged_inbound_headers(details) if headers: return _sanitize_inbound_headers(headers, extra_allowlist=extra_allowlist) except Exception: @@ -283,7 +291,7 @@ class GenericGuardrailAPI(CustomGuardrail): ) self.num_retries: int = num_retries or 0 self.headers = headers or {} - self.extra_headers = extra_headers or [] + self.extra_headers: Sequence[object] = extra_headers or [] # If api_key is provided, add it as x-api-key header if api_key: diff --git a/litellm/proxy/guardrails/guardrail_hooks/grayswan/grayswan.py b/litellm/proxy/guardrails/guardrail_hooks/grayswan/grayswan.py index f32228a6204..7ff5aa2466b 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/grayswan/grayswan.py +++ b/litellm/proxy/guardrails/guardrail_hooks/grayswan/grayswan.py @@ -34,6 +34,7 @@ if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj GRAYSWAN_BLOCK_ERROR_MSG: Final = "Blocked by Gray Swan Guardrail" +_DECODED_JSON: Final = TypeAdapter(object) class _GraySwanMonitorResponse(TypedDict): @@ -705,7 +706,9 @@ class GraySwanGuardrail(CustomGuardrail): {**existing_headers, **inbound_headers} if isinstance(existing_headers, dict) else inbound_headers ) if cleaned_litellm_metadata: - sanitized: Final[object] = safe_json_loads(safe_dumps(cleaned_litellm_metadata), default={}) + sanitized: Final = _DECODED_JSON.validate_python( + safe_json_loads(safe_dumps(cleaned_litellm_metadata), default={}) + ) if isinstance(sanitized, dict) and sanitized: payload["litellm_metadata"] = sanitized diff --git a/litellm/proxy/guardrails/guardrail_hooks/javelin/javelin.py b/litellm/proxy/guardrails/guardrail_hooks/javelin/javelin.py index d5edcc19a02..a1d0900ebed 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/javelin/javelin.py +++ b/litellm/proxy/guardrails/guardrail_hooks/javelin/javelin.py @@ -2,6 +2,7 @@ from datetime import datetime from typing import TYPE_CHECKING, Final from fastapi import HTTPException +from pydantic import TypeAdapter import litellm from litellm._logging import verbose_proxy_logger @@ -23,6 +24,8 @@ from litellm.types.utils import CallTypesLiteral, GuardrailStatus if TYPE_CHECKING: from litellm.types.proxy.guardrails.guardrail_hooks.base import GuardrailConfigModel +_DECODED_JSON: Final = TypeAdapter(object) + class JavelinGuardrail(CustomGuardrail): @classmethod @@ -113,7 +116,9 @@ class JavelinGuardrail(CustomGuardrail): json=dict(request), timeout=self.timeout, ) - verbose_proxy_logger.debug("Javelin Guardrail: Javelin guard API response: %s", response.json()) + verbose_proxy_logger.debug( + "Javelin Guardrail: Javelin guard API response: %s", _DECODED_JSON.validate_python(response.json()) + ) response_data: Final = response.json() # Ensure the response has the required assessments field if "assessments" not in response_data: diff --git a/litellm/proxy/guardrails/guardrail_hooks/lakera_ai_v2.py b/litellm/proxy/guardrails/guardrail_hooks/lakera_ai_v2.py index 8efd1dc79e3..7c0cdb0d36f 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/lakera_ai_v2.py +++ b/litellm/proxy/guardrails/guardrail_hooks/lakera_ai_v2.py @@ -7,6 +7,7 @@ from types import MappingProxyType from typing import Final, Literal from fastapi import HTTPException +from pydantic import TypeAdapter import litellm from litellm._logging import verbose_proxy_logger @@ -40,6 +41,9 @@ from litellm.types.proxy.guardrails.guardrail_hooks.lakera_ai_v2 import ( ) from litellm.types.utils import CallTypesLiteral, GuardrailStatus, ModelResponse +_DECODED_JSON: Final = TypeAdapter(object) +_RESPONSE_FIELDS: Final = TypeAdapter(Mapping[str, object]) + _DETECTOR_CATEGORY_PHRASES: Final[Mapping[str, str]] = MappingProxyType( { "prompt_injection": "a potential prompt injection attempt", @@ -402,7 +406,9 @@ class LakeraAIGuardrail(CustomGuardrail): json=request, timeout=self.timeout, ) - verbose_proxy_logger.debug("Lakera AI v2 guard response: %s", response.json()) + verbose_proxy_logger.debug( + "Lakera AI v2 guard response: %s", _DECODED_JSON.validate_python(response.json()) + ) lakera_response = LakeraAIResponse(**response.json()) return lakera_response, masked_entity_count except Exception as e: @@ -801,7 +807,7 @@ class LakeraAIGuardrail(CustomGuardrail): choice_idx = choice_indices[idx] response_dict["choices"][choice_idx]["message"]["content"] = msg.get("content", "") add_guardrail_to_applied_guardrails_header(request_data=data, guardrail_name=self.guardrail_name) - return ModelResponse(**response_dict) + return ModelResponse(**_RESPONSE_FIELDS.validate_python(response_dict)) # inject_system_message has nothing left to inject into once a response # already exists, so it is treated the same as monitor: log and allow. diff --git a/litellm/proxy/guardrails/guardrail_hooks/lasso/lasso.py b/litellm/proxy/guardrails/guardrail_hooks/lasso/lasso.py index e05db5003fa..97b35769f63 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/lasso/lasso.py +++ b/litellm/proxy/guardrails/guardrail_hooks/lasso/lasso.py @@ -9,7 +9,7 @@ import json import os import uuid from collections.abc import Mapping, Sequence -from typing import TYPE_CHECKING, Any, Final, Literal, TypedDict +from typing import TYPE_CHECKING, Final, Literal, TypedDict try: import ulid @@ -39,6 +39,7 @@ from litellm.integrations.custom_guardrail import ( log_guardrail_information, ) from litellm.integrations.custom_guardrail import dc as global_cache +from litellm.litellm_core_utils.core_helpers import iter_items from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, httpxSpecialProvider, @@ -397,13 +398,15 @@ class LassoGuardrail(CustomGuardrail): HTTPException: If blocking violations are detected """ raw_messages: Final[list[dict[str, object]]] = data.get("messages") or [] - messages: list[dict[str, Any]] = self._expand_messages_for_classification(raw_messages) if raw_messages else [] - messages_count: Final = len(messages) - if data.get("input") is not None: - # Responses-API payloads carry text in data["input"]. Inspect it - # alongside any "messages" array — otherwise a caller can attach - # benign messages and stash blocked content in input to bypass. - messages.extend(build_inspection_messages({"input": data["input"]})) + expanded_messages: Final = self._expand_messages_for_classification(raw_messages) if raw_messages else [] + messages_count: Final = len(expanded_messages) + # Responses-API payloads carry text in data["input"]. Inspect it + # alongside any "messages" array — otherwise a caller can attach + # benign messages and stash blocked content in input to bypass. + input_messages: Final = ( + build_inspection_messages({"input": data["input"]}) if data.get("input") is not None else [] + ) + messages: Final[Sequence[Mapping[str, object]]] = [*expanded_messages, *input_messages] if not messages: return data @@ -421,7 +424,7 @@ class LassoGuardrail(CustomGuardrail): data: dict, cache: DualCache, message_type: Literal["PROMPT", "COMPLETION"], - messages: list[dict[str, object]], + messages: Sequence[Mapping[str, object]], ) -> dict: """Handle classification without masking.""" try: @@ -439,7 +442,7 @@ class LassoGuardrail(CustomGuardrail): data: dict, cache: DualCache, message_type: Literal["PROMPT", "COMPLETION"], - messages: list[dict[str, object]], + messages: Sequence[Mapping[str, object]], messages_count: int, ) -> dict: """Handle masking with classifix endpoint. @@ -470,7 +473,7 @@ class LassoGuardrail(CustomGuardrail): text_parts = [msg["content"] for msg in masked_for_input if isinstance(msg.get("content"), str)] if text_parts: data["input"] = "\n".join(text_parts) - self._log_masking_applied(message_type, dict(response)) + self._log_masking_applied(message_type, response) return data except Exception as e: @@ -479,7 +482,7 @@ class LassoGuardrail(CustomGuardrail): def _map_masked_messages_back( self, - original_messages: list[dict[str, Any]], + original_messages: Sequence[Mapping[str, object]], masked_messages: Sequence[Mapping[str, object]], ) -> list[dict[str, object]]: """Map Lasso-format masked messages back onto the original OpenAI-format messages. @@ -492,7 +495,7 @@ class LassoGuardrail(CustomGuardrail): """ # Index masked content by type so we can look up by id without caring about order. masked_tool_use: Final[dict[object, dict[str, object]]] = {} - masked_tool_result: Final[dict[str, str]] = {} + masked_tool_result: Final[dict[object, str]] = {} masked_text: Final[list[str]] = [] for msg in masked_messages: @@ -567,12 +570,12 @@ class LassoGuardrail(CustomGuardrail): def _update_tool_calls_from_masked( self, - tool_calls: list[object], + tool_calls: object, masked_tool_use: Mapping[object, Mapping[str, object]], ) -> list[object]: """Replace tool_call arguments with masked values returned by Lasso.""" updated: Final = [] - for call in tool_calls: + for call in iter_items(tool_calls): call_id = self._get_field(call, "id") if call_id and call_id in masked_tool_use: masked_input = masked_tool_use[call_id].get("input") @@ -627,7 +630,7 @@ class LassoGuardrail(CustomGuardrail): def _log_masking_applied( self, message_type: Literal["PROMPT", "COMPLETION"], - response: dict[str, Any], + response: LassoResponse, ) -> None: """Log masking application with structured context.""" conversation_id: Final = getattr(self, "conversation_id", "unknown") @@ -637,12 +640,12 @@ class LassoGuardrail(CustomGuardrail): "guardrail_name": getattr(self, "guardrail_name", "unknown"), "message_type": message_type, "violations_count": len(response.get("findings", {})), - "masked_fields": len(response.get("messages", [])), + "masked_fields": len(response.get("messages") or []), "conversation_id": conversation_id, }, ) - def _expand_messages_for_classification(self, messages: list[dict[str, Any]]) -> list[dict[str, object]]: + def _expand_messages_for_classification(self, messages: Sequence[Mapping[str, object]]) -> list[dict[str, object]]: """ Convert raw OpenAI-format messages to Lasso API format with content blocks. @@ -701,7 +704,7 @@ class LassoGuardrail(CustomGuardrail): expanded.append({"role": role, "content": content}) if role == "assistant": - for call in msg.get("tool_calls") or []: + for call in iter_items(msg.get("tool_calls") or []): call_id, name, input_data = self._extract_tool_call_fields(call) if not call_id or not name: verbose_proxy_logger.warning( @@ -749,7 +752,7 @@ class LassoGuardrail(CustomGuardrail): def _prepare_payload( self, - messages: list[dict[str, object]], + messages: Sequence[Mapping[str, object]], data: dict, cache: DualCache, message_type: Literal["PROMPT", "COMPLETION"] = "PROMPT", diff --git a/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/competitor_intent/airline.py b/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/competitor_intent/airline.py index 5e2b85250d2..76c3a86d701 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/competitor_intent/airline.py +++ b/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/competitor_intent/airline.py @@ -13,6 +13,9 @@ import json from pathlib import Path from typing import Any, Final +from pydantic import TypeAdapter + +from litellm.litellm_core_utils.core_helpers import iter_items from litellm.proxy.guardrails.guardrail_hooks.litellm_content_filter.competitor_intent.base import ( # noqa: F401 # legacy module exports BaseCompetitorIntentChecker, _compile_marker, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export @@ -114,6 +117,7 @@ AIRLINE_EXPLICIT_OTHER_MEANING_MARKER: Final = ( ) _MAJOR_AIRLINES_PATH: Final = Path(__file__).resolve().parent / "major_airlines.json" +_DECODED_JSON: Final = TypeAdapter(object) def _load_competitors_excluding_brand(brand_self: list[str]) -> list[str]: @@ -127,11 +131,11 @@ def _load_competitors_excluding_brand(brand_self: list[str]) -> list[str]: return [] try: with open(_MAJOR_AIRLINES_PATH, encoding="utf-8") as f: - airlines: Final = json.load(f) + airlines: Final = _DECODED_JSON.validate_python(json.load(f)) except (json.JSONDecodeError, OSError): return [] result: Final[list[str]] = [] - for entry in airlines: + for entry in iter_items(airlines): if not isinstance(entry, dict): continue match_str = entry.get("match") or "" diff --git a/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/content_filter.py b/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/content_filter.py index 40e44151e65..f58c8705815 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/content_filter.py +++ b/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/content_filter.py @@ -78,6 +78,7 @@ from .patterns import PATTERN_EXTRA_CONFIG, get_compiled_pattern MAX_KEYWORD_VALUE_GAP_WORDS: Final = 1 _DECODED_ARGUMENTS: Final = TypeAdapter(object) +_JSON_ENTRIES: Final = TypeAdapter(list[object]) GAP_WORD_TOKENIZER: Final = re.compile(r"\b\w+\b") SENTENCE_TERMINATORS: Final = re.compile(r"[.!?]+") @@ -699,9 +700,8 @@ class ContentFilterGuardrail(CustomGuardrail): Severity mapping: 4,3 -> high; 2 -> medium; 1 -> low. """ with open(file_path, "r") as f: - entries = json.load(f) - if not isinstance(entries, list): - entries = [entries] + decoded: Final = _DECODED_ARGUMENTS.validate_python(json.load(f)) + entries: Final = _JSON_ENTRIES.validate_python(decoded) if isinstance(decoded, list) else [decoded] # Derive category name from filename (e.g. harm_toxic_abuse.json -> harm_toxic_abuse) category_name: Final = os.path.splitext(os.path.basename(file_path))[0] severity_map: Final = {4: "high", 3: "high", 2: "medium", 1: "low"} @@ -806,7 +806,7 @@ class ContentFilterGuardrail(CustomGuardrail): """ try: with open(file_path, "r") as f: - data: Final = yaml.safe_load(f) + data: Final = _DECODED_ARGUMENTS.validate_python(yaml.safe_load(f)) if not isinstance(data, dict) or "blocked_words" not in data: raise ValueError("Invalid format: file must contain 'blocked_words' key with list of words") diff --git a/litellm/proxy/guardrails/guardrail_hooks/llm_shield_proxy/llm_shield_proxy.py b/litellm/proxy/guardrails/guardrail_hooks/llm_shield_proxy/llm_shield_proxy.py index 7fb87080cd1..d2dafb04fe0 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/llm_shield_proxy/llm_shield_proxy.py +++ b/litellm/proxy/guardrails/guardrail_hooks/llm_shield_proxy/llm_shield_proxy.py @@ -5,7 +5,7 @@ import uuid from collections.abc import AsyncGenerator, AsyncIterable, Iterator, Mapping, Sequence from typing import ( TYPE_CHECKING, - Any, # noqa: TID251 # the streaming hook and the flush copy pass provider chunks through untyped + Any, # noqa: TID251 # the streaming hook passes provider chunks through untyped ClassVar, Final, Literal, @@ -23,7 +23,7 @@ from litellm.integrations.custom_guardrail import ( CustomGuardrail, log_guardrail_information, ) -from litellm.litellm_core_utils.core_helpers import attribute_items +from litellm.litellm_core_utils.core_helpers import attribute_items, attribute_or_none, iter_items, require_attributes from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, httpxSpecialProvider, @@ -99,13 +99,8 @@ class _CustomGuardrailOptions(TypedDict, total=False, extra_items=object): pass -class _ContentDelta(Protocol): - content: object - - -class _FinishingDelta(Protocol): - content: object - tool_calls: object +class _DeepCopyable(Protocol): + def model_copy(self, *, deep: bool) -> object: ... class LLMShieldProxyGuardrail(CustomGuardrail): @@ -528,7 +523,7 @@ class LLMShieldProxyGuardrail(CustomGuardrail): one tool call's accumulating `arguments`. A shared window would splice the text held back for one stream onto another. """ - delta: Final = getattr(choice, "delta", None) + delta: Final = attribute_or_none(choice, "delta") index: Final = choice_index(choice) is_final: Final = bool(getattr(choice, "finish_reason", None)) if isinstance(choice, TextChoices): @@ -566,7 +561,7 @@ class LLMShieldProxyGuardrail(CustomGuardrail): async def _restore_content_window( self, - delta: _ContentDelta, + delta: object, key: CarryKey, carries: CarryWindows, session_id: str, @@ -574,19 +569,19 @@ class LLMShieldProxyGuardrail(CustomGuardrail): ) -> None: """Restores one delta's content through its own window.""" carry: Final = carries.get(key, "") - text: Final = getattr(delta, "content", None) + text: Final = attribute_or_none(delta, "content") if not isinstance(text, str) or not text: if is_final and carry: flushed, remaining = await self._stream_step("", carry, True, session_id) carries[key] = remaining # rebind-ok: this stream's window advances. if flushed: - delta.content = flushed + write_field(delta, "content", flushed) return emitted, remaining = await self._stream_step(text, carry, is_final, session_id) carries[key] = remaining # rebind-ok: this stream's window advances. - delta.content = emitted + write_field(delta, "content", emitted) async def _restore_tool_call_window( self, @@ -618,7 +613,7 @@ class LLMShieldProxyGuardrail(CustomGuardrail): async def _flush_finished_choice( self, - delta: _FinishingDelta, + delta: object, choice_index: int, carries: CarryWindows, session_id: str, @@ -643,12 +638,12 @@ class LLMShieldProxyGuardrail(CustomGuardrail): if not text: continue if tool_index is None: - delta.content = text + write_field(delta, "content", text) else: continuations.extend(continuation_delta(tool_index, text)) if continuations: - existing: Final = tuple(getattr(delta, "tool_calls", None) or ()) - delta.tool_calls = [*existing, *continuations] + existing: Final = tuple(attribute_items(delta, "tool_calls")) + write_field(delta, "tool_calls", [*existing, *continuations]) async def _flush_trailing( self, last_chunk: object, carries: CarryWindows, session_id: str @@ -676,7 +671,7 @@ class LLMShieldProxyGuardrail(CustomGuardrail): chunk = self._chunk_for_choice(last_chunk, choice_index) if chunk is None: continue - choice: object = chunk.choices[0] + choice = read_list(chunk, "choices")[0] delta = read_field(choice, "delta") if isinstance(choice, TextChoices): choice.text = text @@ -688,26 +683,26 @@ class LLMShieldProxyGuardrail(CustomGuardrail): yield chunk @staticmethod - def _chunk_for_choice(last_chunk: Any, index: int) -> Any: + def _chunk_for_choice(last_chunk: object, index: int) -> object | None: """A single-choice copy of the last chunk, carrying only `index`. Emitting one choice per chunk keeps a flush from reading as content on a choice it does not belong to. """ - chunk: Final = last_chunk.model_copy(deep=True) - raw_choices: Final = getattr(chunk, "choices", None) + chunk: Final = require_attributes(last_chunk, _DeepCopyable, "model_copy").model_copy(deep=True) + raw_choices: Final = attribute_or_none(chunk, "choices") if not raw_choices: return None - choices: Final[tuple[object, ...]] = tuple(raw_choices) + choices: Final = tuple(iter_items(raw_choices)) position: Final = next((at for at, choice in enumerate(choices) if choice_index(choice) == index), 0) - kept: Final = raw_choices[position] - if getattr(kept, "delta", None) is None and not isinstance(kept, TextChoices): + kept: Final = choices[position] + if attribute_or_none(kept, "delta") is None and not isinstance(kept, TextChoices): return None - kept.index = index - kept.finish_reason = None - chunk.choices = [kept] + write_field(kept, "index", index) + write_field(kept, "finish_reason", None) + write_field(chunk, "choices", [kept]) if hasattr(chunk, "usage"): - del chunk.usage + delattr(chunk, "usage") return chunk async def _stream_step(self, text: str, carry: str, final: bool, session_id: str) -> tuple[str, str]: diff --git a/litellm/proxy/guardrails/guardrail_hooks/llm_shield_proxy/stream_restorers.py b/litellm/proxy/guardrails/guardrail_hooks/llm_shield_proxy/stream_restorers.py index 4ef8bbdbb3e..ef007155c46 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/llm_shield_proxy/stream_restorers.py +++ b/litellm/proxy/guardrails/guardrail_hooks/llm_shield_proxy/stream_restorers.py @@ -7,9 +7,12 @@ from enum import Enum from types import MappingProxyType from typing import ( Final, + Protocol, TypeAlias, ) +from pydantic import TypeAdapter + from .payload import ( JsonBody, MutableRequest, @@ -24,6 +27,8 @@ from .payload import ( write_field, ) +_OPAQUE_VALUE: Final = TypeAdapter(object) + ANTHROPIC_DELTA_FIELDS: Final = MappingProxyType({"text_delta": "text", "input_json_delta": "partial_json"}) SSE_EVENT_BOUNDARY: Final = re.compile(rb"(\r?\n\r?\n)") @@ -80,6 +85,15 @@ def opens_like_sse(head: bytes) -> bool | None: return False +class _ValuedEnum(Protocol): + @property + def value(self) -> object: ... + + +def _enum_value(member: _ValuedEnum) -> object: + return member.value + + def responses_event_type(chunk: object) -> str | None: """The event type of a Responses API stream event, or None for any other chunk. @@ -90,7 +104,7 @@ def responses_event_type(chunk: object) -> str | None: if isinstance(chunk, (bytes, str)): return None kind: Final = read_field(chunk, "type") - value: Final = kind.value if isinstance(kind, Enum) else kind + value: Final = _enum_value(kind) if isinstance(kind, Enum) else kind return value if isinstance(value, str) and value.startswith("response.") else None @@ -173,7 +187,7 @@ class AnthropicSSERestorer: return block line: Final = lines[data_lines[0]] try: - parsed: Final[object] = json.loads(line[len("data:") :]) + parsed: Final = _OPAQUE_VALUE.validate_python(json.loads(line[len("data:") :])) except ValueError: return block event: Final = as_object(parsed) diff --git a/litellm/proxy/guardrails/guardrail_hooks/mcp_end_user_permission/__init__.py b/litellm/proxy/guardrails/guardrail_hooks/mcp_end_user_permission/__init__.py index 95db4bd4f77..fa64d306f22 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/mcp_end_user_permission/__init__.py +++ b/litellm/proxy/guardrails/guardrail_hooks/mcp_end_user_permission/__init__.py @@ -1,4 +1,6 @@ -from typing import TYPE_CHECKING, Any, Final, cast +from collections.abc import Mapping +from types import MappingProxyType +from typing import TYPE_CHECKING, Final, Protocol, cast from litellm.types.guardrails import SupportedGuardrailIntegrations @@ -8,13 +10,22 @@ if TYPE_CHECKING: from litellm.types.guardrails import Guardrail, LitellmParams +class _ParamsLookup(Protocol): + def get(self, key: str, /) -> object: ... + + +_NO_PARAMS: Final = MappingProxyType[str, object]({}) + + def initialize_guardrail(litellm_params: "LitellmParams", guardrail: "Guardrail"): import litellm # Default to always-on. Only disable if the user explicitly sets default_on: false. # We check the raw guardrail dict because LitellmParams normalizes None → False, # making it impossible to distinguish "not set" from "explicitly false" via litellm_params. - _raw_default_on: Final = cast(dict[str, Any], guardrail).get("litellm_params", {}).get("default_on") + _raw_default_on: Final = ( + cast(Mapping[str, _ParamsLookup], guardrail).get("litellm_params", _NO_PARAMS).get("default_on") + ) _default_on: Final = _raw_default_on is not False _callback: Final = MCPEndUserPermissionGuardrail( diff --git a/litellm/proxy/guardrails/guardrail_hooks/mcp_end_user_permission/mcp_end_user_permission.py b/litellm/proxy/guardrails/guardrail_hooks/mcp_end_user_permission/mcp_end_user_permission.py index d7ce3438fca..ab35ead03c7 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/mcp_end_user_permission/mcp_end_user_permission.py +++ b/litellm/proxy/guardrails/guardrail_hooks/mcp_end_user_permission/mcp_end_user_permission.py @@ -189,7 +189,7 @@ class MCPEndUserPermissionGuardrail(CustomGuardrail): if not direct_mcp_servers and not mcp_access_groups: return None # Both empty → no restrictions - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) diff --git a/litellm/proxy/guardrails/guardrail_hooks/mcp_jwt_signer/mcp_jwt_signer.py b/litellm/proxy/guardrails/guardrail_hooks/mcp_jwt_signer/mcp_jwt_signer.py index 221c4b3752b..2e3f7120726 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/mcp_jwt_signer/mcp_jwt_signer.py +++ b/litellm/proxy/guardrails/guardrail_hooks/mcp_jwt_signer/mcp_jwt_signer.py @@ -74,14 +74,14 @@ import os import re import time from collections.abc import Mapping, Sequence -from typing import TYPE_CHECKING, Any, Final, Optional +from typing import TYPE_CHECKING, Final, Optional import httpx import jwt from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey, RSAPublicKey -from typing_extensions import NotRequired, ReadOnly, TypedDict +from typing_extensions import NotRequired, ReadOnly, TypedDict, Unpack from litellm._logging import verbose_proxy_logger from litellm.caching import DualCache @@ -90,7 +90,6 @@ from litellm.integrations.custom_guardrail import ( log_guardrail_information, ) from litellm.proxy._types import UserAPIKeyAuth -from litellm.types.guardrail_base_init import GuardrailBaseInitKwargs from litellm.types.guardrails import GuardrailEventHooks from litellm.types.utils import CallTypesLiteral @@ -98,6 +97,10 @@ if TYPE_CHECKING: from jwt.types import Options +class _CustomGuardrailOptions(TypedDict, total=False, extra_items=object): + pass + + class _OIDCDiscoveryDocument(TypedDict, total=False): jwks_uri: str @@ -279,11 +282,13 @@ class MCPJWTSigner(CustomGuardrail): debug_headers: bool = False, # FR-10: Configurable scopes allowed_scopes: list[str] | None = None, - **kwargs: Any, + **kwargs: Unpack[_CustomGuardrailOptions], ) -> None: - kwargs.setdefault("supported_event_hooks", list(self.get_supported_event_hooks())) - base_kwargs: Final[GuardrailBaseInitKwargs] = kwargs - super().__init__(**base_kwargs) + options: Final[_CustomGuardrailOptions] = { + "supported_event_hooks": list(self.get_supported_event_hooks()), + **kwargs, + } + super().__init__(**options) # --- Signing key setup --- key_material: Final = os.environ.get(self.SIGNING_KEY_ENV) diff --git a/litellm/proxy/guardrails/guardrail_hooks/mcp_security/mcp_security_guardrail.py b/litellm/proxy/guardrails/guardrail_hooks/mcp_security/mcp_security_guardrail.py index 8482567b6da..9c0a574ae3b 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/mcp_security/mcp_security_guardrail.py +++ b/litellm/proxy/guardrails/guardrail_hooks/mcp_security/mcp_security_guardrail.py @@ -6,7 +6,7 @@ on the LiteLLM gateway. Blocks or alerts when unregistered servers are found. """ from collections.abc import Mapping -from typing import Any, Final, Literal +from typing import TYPE_CHECKING, Final, Literal from fastapi import HTTPException @@ -21,6 +21,9 @@ from litellm.responses.mcp.litellm_proxy_mcp_handler import ( ) from litellm.types.guardrails import GuardrailEventHooks +if TYPE_CHECKING: + from litellm.caching.caching import DualCache + class MCPSecurityGuardrail(CustomGuardrail): def __init__( @@ -40,7 +43,7 @@ class MCPSecurityGuardrail(CustomGuardrail): async def async_pre_call_hook( self, user_api_key_dict: UserAPIKeyAuth, - cache: Any, + cache: "DualCache", data: dict, call_type: str, ) -> Exception | str | dict | None: @@ -101,7 +104,7 @@ class MCPSecurityGuardrail(CustomGuardrail): if not requested_servers: return frozenset() - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) diff --git a/litellm/proxy/guardrails/guardrail_hooks/microsoft_purview/__init__.py b/litellm/proxy/guardrails/guardrail_hooks/microsoft_purview/__init__.py index ed955ac829d..06de4ef0e93 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/microsoft_purview/__init__.py +++ b/litellm/proxy/guardrails/guardrail_hooks/microsoft_purview/__init__.py @@ -1,5 +1,6 @@ from typing import TYPE_CHECKING, Final +from litellm.litellm_core_utils.core_helpers import attribute_or_none from litellm.types.guardrails import SupportedGuardrailIntegrations from .purview_dlp import MicrosoftPurviewDLPGuardrail @@ -11,8 +12,8 @@ if TYPE_CHECKING: def initialize_guardrail(litellm_params: "LitellmParams", guardrail: "Guardrail"): import litellm - tenant_id: Final = getattr(litellm_params, "tenant_id", None) - client_id: Final = getattr(litellm_params, "client_id", None) + tenant_id: Final = attribute_or_none(litellm_params, "tenant_id") + client_id: Final = attribute_or_none(litellm_params, "client_id") # client_secret can be passed via the standard api_key field or as # a dedicated client_secret parameter. diff --git a/litellm/proxy/guardrails/guardrail_hooks/noma/noma_v2.py b/litellm/proxy/guardrails/guardrail_hooks/noma/noma_v2.py index 718401b6e68..43eb54d1464 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/noma/noma_v2.py +++ b/litellm/proxy/guardrails/guardrail_hooks/noma/noma_v2.py @@ -10,9 +10,12 @@ import json import os from collections.abc import Callable, Mapping from datetime import datetime -from typing import TYPE_CHECKING, Any, ClassVar, Final, Literal, Optional, TypeAlias, cast +from typing import TYPE_CHECKING, ClassVar, Final, Literal, Optional, TypeAlias, cast from urllib.parse import urlparse +from pydantic import TypeAdapter +from typing_extensions import TypedDict, Unpack + from litellm._logging import verbose_proxy_logger from litellm.integrations.custom_guardrail import ( CustomGuardrail, @@ -25,7 +28,6 @@ from litellm.llms.custom_httpx.http_handler import ( httpxSpecialProvider, ) from litellm.proxy.guardrails.guardrail_hooks.noma.noma import NomaBlockedMessage -from litellm.types.guardrail_base_init import GuardrailBaseInitKwargs from litellm.types.guardrails import GuardrailEventHooks from litellm.types.proxy.guardrails.guardrail_hooks.noma import NomaV2StreamingParams from litellm.types.utils import GenericGuardrailAPIInputs, GuardrailStatus @@ -39,6 +41,7 @@ _DEFAULT_API_BASE: Final = "https://api.noma.security/" _AIDR_SCAN_ENDPOINT: Final = "/litellm/guardrail" _INTERVENED_INPUT_FIELDS: Final = ("texts", "images", "tools", "tool_calls") _DEFAULT_API_BASE_HOSTNAME: Final = urlparse(_DEFAULT_API_BASE).hostname +_DECODED_JSON: Final = TypeAdapter(object) _GuardrailJsonResponse: TypeAlias = Exception | str | dict[str, object] @@ -50,6 +53,10 @@ _LOGGING_KEYS_DUPLICATING_SCAN_INPUTS: Final = _KEYS_DUPLICATING_SCAN_INPUTS + ( ) +class _CustomGuardrailOptions(TypedDict, total=False, extra_items=object): + pass + + class _Action(str, enum.Enum): BLOCKED = "BLOCKED" NONE = "NONE" @@ -74,7 +81,7 @@ class NomaV2Guardrail(CustomGuardrail): streaming_end_of_stream_only: bool | None = None, streaming_sampling_rate: int | None = None, streaming_buffer_release_on_scan: bool | None = None, - **kwargs: Any, + **kwargs: Unpack[_CustomGuardrailOptions], ) -> None: self.async_handler = get_async_httpx_client(llm_provider=httpxSpecialProvider.GuardrailCallback) @@ -115,10 +122,11 @@ class NomaV2Guardrail(CustomGuardrail): if streaming.streaming_buffer_release_on_scan is not None: self.streaming_buffer_release_on_scan: bool = streaming.streaming_buffer_release_on_scan - kwargs.setdefault("supported_event_hooks", list(self.get_supported_event_hooks())) - - base_kwargs: Final[GuardrailBaseInitKwargs] = kwargs - super().__init__(**base_kwargs) + options: Final[_CustomGuardrailOptions] = { + "supported_event_hooks": list(self.get_supported_event_hooks()), + **kwargs, + } + super().__init__(**options) @staticmethod def get_config_model() -> type["GuardrailConfigModel"] | None: @@ -219,7 +227,7 @@ class NomaV2Guardrail(CustomGuardrail): except (ValueError, TypeError): json_str = safe_dumps(payload) - safe_payload: Final[object] = safe_json_loads(json_str, default={}) + safe_payload: Final = _DECODED_JSON.validate_python(safe_json_loads(json_str, default={})) if safe_payload == {} and payload: verbose_proxy_logger.warning( "Noma v2 guardrail: payload serialization failed, falling back to empty payload" diff --git a/litellm/proxy/guardrails/guardrail_hooks/onyx/onyx.py b/litellm/proxy/guardrails/guardrail_hooks/onyx/onyx.py index 1a6feb47215..7c26c4c4c56 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/onyx/onyx.py +++ b/litellm/proxy/guardrails/guardrail_hooks/onyx/onyx.py @@ -10,6 +10,7 @@ from typing import TYPE_CHECKING, Final, Literal, Optional import httpx from fastapi import HTTPException +from pydantic import TypeAdapter from litellm._logging import verbose_proxy_logger from litellm.integrations.custom_guardrail import ( @@ -27,6 +28,8 @@ from litellm.types.utils import GenericGuardrailAPIInputs, ModelResponse if TYPE_CHECKING: from litellm.types.proxy.guardrails.guardrail_hooks.base import GuardrailConfigModel +_DECODED_JSON: Final = TypeAdapter(object) + class OnyxGuardrail(CustomGuardrail): @classmethod @@ -115,7 +118,7 @@ class OnyxGuardrail(CustomGuardrail): try: response: Final = ModelResponse(**request_data) parsed: Final = response.json() - payload = parsed.get("response", {}) + payload = _DECODED_JSON.validate_python(parsed.get("response", {})) except Exception as e: verbose_proxy_logger.error( "Error in converting request_data to ModelResponse: %s", diff --git a/litellm/proxy/guardrails/guardrail_hooks/openai/__init__.py b/litellm/proxy/guardrails/guardrail_hooks/openai/__init__.py index fe526b72ac3..4d120a2dd26 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/openai/__init__.py +++ b/litellm/proxy/guardrails/guardrail_hooks/openai/__init__.py @@ -1,6 +1,7 @@ from typing import TYPE_CHECKING, Final import litellm +from litellm.litellm_core_utils.core_helpers import attribute_or_none from litellm.proxy.guardrails.guardrail_hooks.openai.moderations import ( OpenAIModerationGuardrail, ) @@ -40,12 +41,12 @@ def initialize_guardrail(litellm_params: "LitellmParams", guardrail: "Guardrail" return openai_moderation_guardrail -def _get_config_value(litellm_params, optional_params, attribute_name): +def _get_config_value(litellm_params: object, optional_params: object, attribute_name: str) -> object: if optional_params is not None: - value: Final = getattr(optional_params, attribute_name, None) + value: Final = attribute_or_none(optional_params, attribute_name) if value is not None: return value - return getattr(litellm_params, attribute_name, None) + return attribute_or_none(litellm_params, attribute_name) guardrail_initializer_registry: Final = { diff --git a/litellm/proxy/guardrails/guardrail_hooks/openai/moderations.py b/litellm/proxy/guardrails/guardrail_hooks/openai/moderations.py index 7af5eaf1da9..98be35079c3 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/openai/moderations.py +++ b/litellm/proxy/guardrails/guardrail_hooks/openai/moderations.py @@ -8,6 +8,7 @@ from types import MappingProxyType from typing import TYPE_CHECKING, Final, Literal, Optional from fastapi import HTTPException +from pydantic import TypeAdapter from litellm._logging import verbose_proxy_logger from litellm.integrations.custom_guardrail import ( @@ -40,6 +41,8 @@ if TYPE_CHECKING: from litellm.types.llms.openai import OpenAIModerationResponse from litellm.types.proxy.guardrails.guardrail_hooks.base import GuardrailConfigModel +_DECODED_JSON: Final = TypeAdapter(object) + def _config_secret(value: object) -> object: return get_secret_str(value) if isinstance(value, str) and value.startswith("os.environ/") else value @@ -151,7 +154,9 @@ class OpenAIModerationGuardrail(OpenAIGuardrailBase, CustomGuardrail): timeout=self.timeout, ) - verbose_proxy_logger.debug("OpenAI Moderation guard response: %s", response.json()) + verbose_proxy_logger.debug( + "OpenAI Moderation guard response: %s", _DECODED_JSON.validate_python(response.json()) + ) if response.status_code != 200: raise HTTPException( diff --git a/litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/panw_prisma_airs.py b/litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/panw_prisma_airs.py index 8e03f7db4f5..d50001ba636 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/panw_prisma_airs.py +++ b/litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/panw_prisma_airs.py @@ -18,6 +18,7 @@ from urllib.parse import urlparse import httpx from fastapi import HTTPException from pydantic import ConfigDict, TypeAdapter, ValidationError, field_validator +from typing_extensions import NotRequired, ReadOnly, TypedDict from litellm._logging import verbose_proxy_logger from litellm._uuid import uuid @@ -129,6 +130,21 @@ _RESPONSES_INPUT: Final[TypeAdapter[_ResponsesInput]] = TypeAdapter(_ResponsesIn _DECODED_ARGUMENTS: Final = TypeAdapter(object) +class _AirsToolEvent(TypedDict): + metadata: ReadOnly[Mapping[str, object]] + input: NotRequired[ReadOnly[str]] + + +def _mcp_tool_input(mcp_arguments: object) -> str | None: + if mcp_arguments is not None and mcp_arguments != "": + serialized_args: Final = ( + json.dumps(mcp_arguments) if isinstance(mcp_arguments, (dict, list)) else str(mcp_arguments) + ) + if serialized_args.strip(): + return serialized_args + return None + + if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj from litellm.types.proxy.guardrails.guardrail_hooks.base import GuardrailConfigModel @@ -339,7 +355,7 @@ class PanwPrismaAirsHandler(CustomGuardrail): is_response: bool = False, metadata: Mapping[str, object] | None = None, call_id: object = None, - tool_event: dict[str, Any] | None = None, + tool_event: _AirsToolEvent | None = None, ) -> dict[str, object]: """Call PANW Prisma AIRS API to scan content or a tool_event.""" @@ -561,7 +577,7 @@ class PanwPrismaAirsHandler(CustomGuardrail): if request_data.get("server_name"): return request_data["server_name"] try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -894,7 +910,7 @@ class PanwPrismaAirsHandler(CustomGuardrail): if not line.startswith("data: "): continue try: - data = json.loads(line[6:]) + data = _DECODED_ARGUMENTS.validate_python(json.loads(line[6:])) except (json.JSONDecodeError, ValueError): continue if not isinstance(data, dict): @@ -1954,24 +1970,21 @@ class PanwPrismaAirsHandler(CustomGuardrail): # "mcp_tool_name"/"mcp_arguments". Check canonical first, then fallback. mcp_tool_name: Final = request_data.get("mcp_tool_name") or self._mcp_name_fallback(request_data) if mcp_tool_name and input_type == "request": - mcp_tool_event: Final[dict[str, object]] = { - "metadata": { - "ecosystem": "mcp", - "method": "tools/call", - "server_name": self._get_mcp_server_name(request_data, mcp_tool_name), - "tool_invoked": mcp_tool_name, - }, + mcp_tool_metadata: Final = { + "ecosystem": "mcp", + "method": "tools/call", + "server_name": self._get_mcp_server_name(request_data, mcp_tool_name), + "tool_invoked": mcp_tool_name, } mcp_arguments = request_data.get("mcp_arguments") if mcp_arguments is None: mcp_arguments = request_data.get("arguments") - if mcp_arguments is not None and mcp_arguments != "": - if isinstance(mcp_arguments, (dict, list)): - serialized_args = json.dumps(mcp_arguments) - else: - serialized_args = str(mcp_arguments) - if serialized_args.strip(): - mcp_tool_event["input"] = serialized_args + mcp_tool_input: Final = _mcp_tool_input(mcp_arguments) + mcp_tool_event: Final[_AirsToolEvent] = ( + {"metadata": mcp_tool_metadata} + if mcp_tool_input is None + else {"metadata": mcp_tool_metadata, "input": mcp_tool_input} + ) mcp_scan_result: Final = await self._call_panw_api( tool_event=mcp_tool_event, diff --git a/litellm/proxy/guardrails/guardrail_hooks/presidio.py b/litellm/proxy/guardrails/guardrail_hooks/presidio.py index cadc9ca689b..7e2f6bfec33 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/presidio.py +++ b/litellm/proxy/guardrails/guardrail_hooks/presidio.py @@ -85,6 +85,7 @@ class _PresidioAnonymizeResponse(TypedDict): _PRESIDIO_ANONYMIZE_ADAPTER: Final[TypeAdapter[_PresidioAnonymizeResponse | None]] = TypeAdapter( _PresidioAnonymizeResponse | None ) +_DECODED_JSON: Final = TypeAdapter(object) class _JsonResponse(Protocol): @@ -1595,10 +1596,11 @@ class _OPTIONAL_PresidioPIIMasking(CustomGuardrail): if line.startswith("data: ") and line != "data: [DONE]": raw_json = line[6:] try: - event = json.loads(raw_json) + event = _DECODED_JSON.validate_python(json.loads(raw_json)) delta = event.get("delta") if isinstance(event, dict) else None if ( - isinstance(delta, dict) + isinstance(event, dict) + and isinstance(delta, dict) and event.get("type") == "content_block_delta" and delta.get("type") == "text_delta" and isinstance(delta.get("text"), str) diff --git a/litellm/proxy/guardrails/guardrail_hooks/qualifire/qualifire.py b/litellm/proxy/guardrails/guardrail_hooks/qualifire/qualifire.py index a92e67046bd..6150fccac0c 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/qualifire/qualifire.py +++ b/litellm/proxy/guardrails/guardrail_hooks/qualifire/qualifire.py @@ -10,6 +10,7 @@ import os from typing import Any, Final, Literal from fastapi import HTTPException +from pydantic import TypeAdapter from litellm._logging import verbose_proxy_logger from litellm.integrations.custom_guardrail import ( @@ -29,6 +30,7 @@ from litellm.types.utils import GenericGuardrailAPIInputs GUARDRAIL_NAME: Final = "qualifire" DEFAULT_QUALIFIRE_API_BASE: Final = "https://proxy.qualifire.ai" +_DECODED_JSON: Final = TypeAdapter(object) class QualifireGuardrail(CustomGuardrail): @@ -188,7 +190,7 @@ class QualifireGuardrail(CustomGuardrail): args = function_info.get("arguments", {}) if isinstance(args, str): try: - args = json.loads(args) + args = _DECODED_JSON.validate_python(json.loads(args)) except json.JSONDecodeError: args = {} api_tool_calls.append( diff --git a/litellm/proxy/guardrails/guardrail_hooks/reco/__init__.py b/litellm/proxy/guardrails/guardrail_hooks/reco/__init__.py new file mode 100644 index 00000000000..a15a372c462 --- /dev/null +++ b/litellm/proxy/guardrails/guardrail_hooks/reco/__init__.py @@ -0,0 +1,72 @@ +from collections.abc import Mapping +from types import MappingProxyType +from typing import TYPE_CHECKING, Final + +from pydantic import BaseModel, TypeAdapter + +from litellm.secret_managers.main import get_secret_str +from litellm.types.guardrails import SupportedGuardrailIntegrations +from litellm.types.proxy.guardrails.guardrail_hooks.reco import RecoOptionalParams + +from .reco import RecoGuardrail + +if TYPE_CHECKING: + from litellm.types.guardrails import Guardrail, LitellmParams + +_CONFIG_MAPPING: Final = TypeAdapter(Mapping[str, object]) + + +def _optional_params_mapping(optional_params: object) -> Mapping[str, object]: + """optional_params arrives as a pydantic object from YAML, or as a plain dict when reconciled from the DB.""" + if optional_params is None: + return MappingProxyType({}) + raw: Final = ( + optional_params.model_dump(exclude_unset=True) if isinstance(optional_params, BaseModel) else optional_params + ) + return _CONFIG_MAPPING.validate_python(raw) + + +def _first_configured(field_name: str, sources: tuple[Mapping[str, object], ...]) -> object: + value: Final = next((source[field_name] for source in sources if source.get(field_name) is not None), None) + if isinstance(value, str) and value.startswith("os.environ/"): + return get_secret_str(value) + return value + + +def initialize_guardrail(litellm_params: "LitellmParams", guardrail: "Guardrail") -> RecoGuardrail: + import litellm + + # Top-level fields only count when set explicitly: their defaults are fail-closed and would flip Reco's. + explicit_top_level: Final = _CONFIG_MAPPING.validate_python( + litellm_params.model_dump(include=litellm_params.model_fields_set & RecoOptionalParams.model_fields.keys()) + ) + sources: Final = (_optional_params_mapping(litellm_params.optional_params), explicit_top_level) + configured: Final = ( + (field_name, _first_configured(field_name, sources)) for field_name in RecoOptionalParams.model_fields + ) + reco_params: Final = RecoOptionalParams.model_validate( + {field_name: value for field_name, value in configured if value is not None} + ) + + _reco_callback: Final = RecoGuardrail( + guardrail_name=guardrail["guardrail_name"], + reco_tenant_id=reco_params.reco_tenant_id, + api_base=reco_params.api_base, + unreachable_fallback=reco_params.unreachable_fallback, + fail_on_error=reco_params.fail_on_error, + event_hook=litellm_params.mode, + default_on=bool(litellm_params.default_on), + ) + litellm.logging_callback_manager.add_litellm_callback(_reco_callback) + + return _reco_callback + + +guardrail_initializer_registry: Final = { + SupportedGuardrailIntegrations.RECO.value: initialize_guardrail, +} + + +guardrail_class_registry: Final = { + SupportedGuardrailIntegrations.RECO.value: RecoGuardrail, +} diff --git a/litellm/proxy/guardrails/guardrail_hooks/reco/reco.py b/litellm/proxy/guardrails/guardrail_hooks/reco/reco.py new file mode 100644 index 00000000000..c8998a20367 --- /dev/null +++ b/litellm/proxy/guardrails/guardrail_hooks/reco/reco.py @@ -0,0 +1,84 @@ +from collections.abc import Mapping, Sequence +from typing import TYPE_CHECKING, Final, Literal, Optional + +from litellm.exceptions import GuardrailRaisedException +from litellm.integrations.custom_guardrail import ( + log_guardrail_information, # pyright: ignore[reportUnknownVariableType] # decorator is untyped +) +from litellm.proxy.guardrails.guardrail_hooks.generic_guardrail_api.generic_guardrail_api import ( + GenericGuardrailAPI, +) +from litellm.types.guardrails import GuardrailEventHooks, Mode +from litellm.types.proxy.guardrails.guardrail_hooks.reco import validate_reco_tenant_id +from litellm.types.utils import GenericGuardrailAPIInputs + +if TYPE_CHECKING: + from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj + from litellm.types.proxy.guardrails.guardrail_hooks.base import GuardrailConfigModel + from litellm.types.proxy.guardrails.guardrail_hooks.reco import RecoOptionalParams + + +class RecoGuardrail(GenericGuardrailAPI): + """Reco guardrail integration for LiteLLM, built on the Generic Guardrail API wire contract.""" + + def __init__( + self, + reco_tenant_id: str | None, + api_base: str | None, + headers: Mapping[str, str] | None = None, + unreachable_fallback: Literal["fail_closed", "fail_open"] = "fail_closed", + fail_on_error: bool = True, + guardrail_name: str | None = None, + event_hook: str | Sequence[str] | Mode | None = None, + default_on: bool = False, + ) -> None: + if not reco_tenant_id: + raise ValueError("reco_tenant_id is required for the Reco guardrail") + if not api_base: + raise ValueError("api_base is required for the Reco guardrail") + + validated_tenant_id: Final = validate_reco_tenant_id(reco_tenant_id) + + super().__init__( # pyright: ignore[reportUnknownMemberType] # parent takes untyped extra_headers and **kwargs + headers={**(headers or {}), "X-Reco-Tenant-Id": validated_tenant_id}, + api_base=api_base, + unreachable_fallback=unreachable_fallback, + fail_on_error=fail_on_error, + guardrail_name=guardrail_name, + event_hook=event_hook, + default_on=default_on, + ) + + @log_guardrail_information + async def apply_guardrail( + self, + inputs: GenericGuardrailAPIInputs, + request_data: dict[str, object], # mutable-ok: must match GenericGuardrailAPI.apply_guardrail's own param type + input_type: Literal["request", "response"], + logging_obj: Optional["LiteLLMLoggingObj"] = None, + ) -> GenericGuardrailAPIInputs: + # GenericGuardrailAPI raises with a hardcoded module-level guardrail_name on BLOCKED, + # not the guardrail's own configured name. Re-raise with the right one instead of + # patching the shared base class. + try: + return await super().apply_guardrail( # pyright: ignore[reportUnknownMemberType] # parent annotates request_data as a bare dict + inputs=inputs, request_data=request_data, input_type=input_type, logging_obj=logging_obj + ) + except GuardrailRaisedException as e: + raise GuardrailRaisedException( + guardrail_name=self.guardrail_name, + message=e.message, + should_wrap_with_default_message=False, + status_code=e.status_code, + blocked_content=e.blocked_content, + ) from e + + @staticmethod + def get_config_model() -> type["GuardrailConfigModel[RecoOptionalParams]"] | None: + from litellm.types.proxy.guardrails.guardrail_hooks.reco import RecoConfigModel + + return RecoConfigModel + + @classmethod + def get_supported_event_hooks(cls) -> list[GuardrailEventHooks]: # mutable-ok: fixed by base class + return [GuardrailEventHooks.pre_call] diff --git a/litellm/proxy/guardrails/guardrail_hooks/semantic_guard/route_loader.py b/litellm/proxy/guardrails/guardrail_hooks/semantic_guard/route_loader.py index 1a571047977..342e5b64714 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/semantic_guard/route_loader.py +++ b/litellm/proxy/guardrails/guardrail_hooks/semantic_guard/route_loader.py @@ -10,6 +10,7 @@ from collections.abc import Mapping, Sequence from typing import TYPE_CHECKING, Final import yaml +from pydantic import TypeAdapter from litellm._logging import verbose_logger from litellm.constants import DEFAULT_SEMANTIC_GUARD_SIMILARITY_THRESHOLD @@ -22,6 +23,7 @@ if TYPE_CHECKING: ROUTE_TEMPLATES_DIR: Final = os.path.join(os.path.dirname(__file__), "route_templates") +_DECODED_YAML: Final = TypeAdapter(object) class SemanticGuardRouteLoader: @@ -55,7 +57,7 @@ class SemanticGuardRouteLoader: if not os.path.exists(file_path): raise ValueError(f"SemanticGuard: custom routes file not found: {file_path}") with open(file_path, "r") as f: - data: Final = yaml.safe_load(f) + data: Final = _DECODED_YAML.validate_python(yaml.safe_load(f)) if isinstance(data, list): return data if isinstance(data, dict): diff --git a/litellm/proxy/guardrails/guardrail_hooks/semantic_guard/semantic_guard.py b/litellm/proxy/guardrails/guardrail_hooks/semantic_guard/semantic_guard.py index 2fbd50b5863..37acee28b53 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/semantic_guard/semantic_guard.py +++ b/litellm/proxy/guardrails/guardrail_hooks/semantic_guard/semantic_guard.py @@ -6,13 +6,14 @@ via embedding similarity. Smarter than regex (understands intent), lighter than an LLM call (~20-50ms per request for embedding). """ -from typing import TYPE_CHECKING, Any, Final, Protocol +from typing import TYPE_CHECKING, Final, Protocol from litellm._logging import verbose_logger from litellm.integrations.custom_guardrail import ( CustomGuardrail, log_guardrail_information, ) +from litellm.litellm_core_utils.core_helpers import attribute_items, attribute_or_none, require_attributes from litellm.proxy.guardrails.guardrail_hooks.semantic_guard.route_loader import ( SemanticGuardRouteLoader, ) @@ -188,17 +189,21 @@ def _extract_user_text(messages: list) -> str: return "" -def _extract_response_text(response: Any) -> str: +class _MessageContent(Protocol): + @property + def content(self) -> object: ... + + +def _extract_response_text(response: object) -> str: """Extract text from every LLM response choice.""" - if hasattr(response, "choices") and response.choices: - text_parts: Final[list[str]] = [] - for choice in response.choices: - if hasattr(choice, "message") and choice.message: - text = _content_to_text(choice.message.content) - if text: - text_parts.append(text) - return "\n".join(text_parts) - return "" + text_parts: Final[list[str]] = [] + for choice in attribute_items(response, "choices"): + message = attribute_or_none(choice, "message") + if message: + text = _content_to_text(require_attributes(message, _MessageContent, "content").content) + if text: + text_parts.append(text) + return "\n".join(text_parts) def _content_to_text(content: object) -> str: diff --git a/litellm/proxy/guardrails/guardrail_hooks/straiker/straiker.py b/litellm/proxy/guardrails/guardrail_hooks/straiker/straiker.py index f2f3ec201f5..589b865618b 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/straiker/straiker.py +++ b/litellm/proxy/guardrails/guardrail_hooks/straiker/straiker.py @@ -559,7 +559,7 @@ def _v3_answer(request_data: Mapping[str, object], model: str | None) -> Mapping return _v3_text_completion_as_chat(response) if not isinstance(response, ModelResponse) or not _v3_anthropic_messages_route(request_data): return _jsonable_dict(response) - from litellm.llms.anthropic.pass_through.adapters.transformation import ( + from litellm.llms.anthropic.messages.adapters.transformation import ( LiteLLMAnthropicMessagesAdapter, ) diff --git a/litellm/proxy/guardrails/guardrail_hooks/tool_policy/tool_policy_guardrail.py b/litellm/proxy/guardrails/guardrail_hooks/tool_policy/tool_policy_guardrail.py index de0f8856522..fbf1f2576ff 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/tool_policy/tool_policy_guardrail.py +++ b/litellm/proxy/guardrails/guardrail_hooks/tool_policy/tool_policy_guardrail.py @@ -105,7 +105,7 @@ def _resolve_tool_names_from_messages(messages: list[dict]) -> dict[str, str]: fn = (tc.get("function") or {}).get("name") else: tc_id = getattr(tc, "id", None) - fn_obj = getattr(tc, "function", None) + fn_obj: object = getattr(tc, "function", None) fn = getattr(fn_obj, "name", None) if fn_obj else None if tc_id and fn: mapping[tc_id] = fn diff --git a/litellm/proxy/guardrails/guardrail_hooks/unified_guardrail/unified_guardrail.py b/litellm/proxy/guardrails/guardrail_hooks/unified_guardrail/unified_guardrail.py index 3ad9d1a2c42..d713f1078a2 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/unified_guardrail/unified_guardrail.py +++ b/litellm/proxy/guardrails/guardrail_hooks/unified_guardrail/unified_guardrail.py @@ -15,6 +15,7 @@ from typing import TYPE_CHECKING, Any, Final, Protocol, TypeAlias, cast, runtime import anyio from fastapi import HTTPException +from pydantic import TypeAdapter from litellm._logging import verbose_proxy_logger from litellm.caching.caching import DualCache @@ -50,6 +51,8 @@ A2A_CALL_TYPES: Final = (CallTypes.asend_message, CallTypes.send_message) GUARDRAIL_NAME: Final = "unified_llm_guardrails" +_DECODED_JSON: Final = TypeAdapter(object) + _RequestData: TypeAlias = dict[str, object] @@ -183,7 +186,7 @@ def _get_a2a_request_id(responses_so_far: Sequence[object], request_data: dict) return item.get("id") if isinstance(item, str): try: - obj = json.loads(item.strip()) + obj = _DECODED_JSON.validate_python(json.loads(item.strip())) if isinstance(obj, dict) and "id" in obj: return obj.get("id") except (json.JSONDecodeError, TypeError): @@ -729,7 +732,7 @@ class UnifiedLLMGuardrails(CustomLogger): user_api_key_dict: UserAPIKeyAuth, call_type: str, sampling_rate: int, - end_of_stream_only: bool, + end_of_stream_only: object, mappings: Mapping[CallTypes, type["BaseTranslation"]], ) -> AsyncGenerator[object, None]: """Emit guardrail text transformations as new deltas on the stream. @@ -1135,16 +1138,19 @@ class UnifiedLLMGuardrails(CustomLogger): guardrail_to_apply = request_data.pop("guardrail_to_apply", None) typed_request_data: Final[_RequestData] = request_data - def _streaming_flag(name: str, default: object) -> Any: + def _streaming_setting(name: str, default: object) -> object: return self.resolve_streaming_flag(guardrail_to_apply, name, default) + def _streaming_flag(name: str, default: object) -> Any: + return _streaming_setting(name, default) + sampling_rate: Final[int] = _streaming_flag("streaming_sampling_rate", 5) # Only apply the guardrail at end of stream (not per chunk). - end_of_stream_only: bool = _streaming_flag("streaming_end_of_stream_only", False) + end_of_stream_only: object = _streaming_setting("streaming_end_of_stream_only", False) # "block_only" (default) drops guardrail text rewrites on the streaming # path; "incremental_diff" emits them as synthetic deltas (see # _run_incremental_transform_stream). - streaming_transform_mode: Final[str] = _streaming_flag("streaming_transform_mode", "block_only") + streaming_transform_mode: Final = _streaming_setting("streaming_transform_mode", "block_only") # Withhold every chunk until end-of-stream moderation passes, then # release the original chunks (clean) or only the block message # (blocked) -- moderating the whole response *before* any content @@ -1152,10 +1158,10 @@ class UnifiedLLMGuardrails(CustomLogger): # release the original chunks are replayed as-is, so a # content-rewriting guardrail (e.g. PII masking) would leak # unredacted content. Guarded below via mask_response_content. - buffer_until_moderated: bool = _streaming_flag( + buffer_until_moderated: object = _streaming_setting( "streaming_buffer_until_moderated", buffer_until_moderated_default ) - release_on_scan: Final[bool] = _streaming_flag("streaming_buffer_release_on_scan", False) + release_on_scan: Final = _streaming_setting("streaming_buffer_release_on_scan", False) if ( buffer_until_moderated diff --git a/litellm/proxy/guardrails/guardrail_registry.py b/litellm/proxy/guardrails/guardrail_registry.py index 7521c1e9f45..24b30e65e2b 100644 --- a/litellm/proxy/guardrails/guardrail_registry.py +++ b/litellm/proxy/guardrails/guardrail_registry.py @@ -102,6 +102,16 @@ def _as_json_array(value: object) -> list[object] | None: return _JSON_ARRAY.validate_python(value) if isinstance(value, list) else None +def _extra_param_items(litellm_params: LitellmParams) -> Iterable[tuple[str, object]]: + return ( + litellm_params.model_dump(exclude_none=True).items() + if hasattr(litellm_params, "model_dump") + else iter(litellm_params) + if litellm_params + else () + ) + + def contains_encrypted_marker(value: object, depth: int = 0) -> bool: """True if any string in value, at any JSON depth, starts with the encrypted-value prefix.""" if depth > DEFAULT_MAX_RECURSE_DEPTH: @@ -904,13 +914,7 @@ class InMemoryGuardrailHandler: # This matches the behavior of other guardrail initializers (e.g., initialize_lakera) # and aligns with the documented behavior for custom guardrails excluded_extra_param_keys: Final = frozenset(("guardrail", "mode", "default_on", "stream_scope")) - extra_params_items: Final = ( - litellm_params.model_dump(exclude_none=True).items() - if hasattr(litellm_params, "model_dump") - else iter(litellm_params) - if litellm_params - else () - ) + extra_params_items: Final = _extra_param_items(litellm_params) extra_params: Final = MappingProxyType( {key: value for key, value in extra_params_items if key not in excluded_extra_param_keys} ) diff --git a/litellm/proxy/guardrails/tool_name_extraction.py b/litellm/proxy/guardrails/tool_name_extraction.py index 526f58dcd36..c49835905fb 100644 --- a/litellm/proxy/guardrails/tool_name_extraction.py +++ b/litellm/proxy/guardrails/tool_name_extraction.py @@ -6,8 +6,8 @@ knowledge lives in one place. Uses guardrail translation handlers where availabl with standalone extractors for generate_content and MCP. """ -from collections.abc import Mapping -from typing import Any, Final +from collections.abc import Callable, Mapping +from typing import Final from litellm.litellm_core_utils.api_route_to_call_types import get_call_types_for_route from litellm.llms import load_guardrail_translation_mappings @@ -15,7 +15,7 @@ from litellm.llms.base_llm.guardrail_translation.utils import list_field from litellm.types.utils import CallTypes # Call types that have no guardrail translation handler; we use standalone extractors -STANDALONE_EXTRACTORS: Final[dict[str, Any]] = {} +STANDALONE_EXTRACTORS: Final[dict[str, Callable[[Mapping[str, object]], list[str]]]] = {} def _extract_generate_content_tool_names(data: Mapping[str, object]) -> list[str]: @@ -28,7 +28,7 @@ def _extract_generate_content_tool_names(data: Mapping[str, object]) -> list[str return names -def _extract_mcp_tool_names(data: dict) -> list[str]: +def _extract_mcp_tool_names(data: Mapping[str, object]) -> list[str]: """MCP call_tool: name or mcp_tool_name in body""" names: Final[list[str]] = [] name: Final = data.get("name") or data.get("mcp_tool_name") diff --git a/litellm/proxy/guardrails/usage_endpoints.py b/litellm/proxy/guardrails/usage_endpoints.py index 2f466f22ef8..caa66bddf39 100644 --- a/litellm/proxy/guardrails/usage_endpoints.py +++ b/litellm/proxy/guardrails/usage_endpoints.py @@ -11,10 +11,11 @@ from types import MappingProxyType from typing import TYPE_CHECKING, Any, Final, Literal, TypeVar, overload from fastapi import APIRouter, Depends, Query -from pydantic import BaseModel, Field +from pydantic import BaseModel, Field, TypeAdapter from typing_extensions import NotRequired, ReadOnly, TypedDict from litellm._logging import verbose_proxy_logger +from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.auth.user_api_key_auth import user_api_key_auth from litellm.proxy.guardrails.usage_tracking import guardrail_status_to_action @@ -838,28 +839,41 @@ def _snippet(text: object, max_len: int = 200) -> str | None: return result -def _input_snippet_for_log(sl: "prisma_models.LiteLLM_SpendLogs") -> str | None: - """Snippet for request input: prefer messages, fall back to proxy_server_request (same as drawer).""" - out = _snippet(sl.messages) +_DECODED_JSON: Final = TypeAdapter(object) + + +def _request_dict(value: object) -> Mapping[str, object] | None: + mapping: Final = as_str_mapping(value) + return mapping if isinstance(mapping, dict) else None + + +def _proxy_request_snippet(psr: object) -> str | None: + request: Final = _request_dict(psr) + if request is None: + return _snippet(psr) + msgs: Final = request.get("messages") + body: Final = _request_dict(request.get("body")) if msgs is None else None + out: Final = _snippet(body.get("messages") if body is not None else msgs) if out: return out - psr = getattr(sl, "proxy_server_request", None) + return _snippet(psr) + + +def _input_snippet_for_log(sl: "prisma_models.LiteLLM_SpendLogs") -> str | None: + """Snippet for request input: prefer messages, fall back to proxy_server_request (same as drawer).""" + out: Final = _snippet(sl.messages) + if out: + return out + psr: Final[object] = getattr(sl, "proxy_server_request", None) if not psr: return None - if isinstance(psr, str): - try: - psr = json.loads(psr) - except Exception: - return _snippet(psr) - if isinstance(psr, dict): - msgs = psr.get("messages") - if msgs is None and isinstance(psr.get("body"), dict): - msgs = psr["body"].get("messages") - out = _snippet(msgs) - if out: - return out + if not isinstance(psr, str): + return _proxy_request_snippet(psr) + try: + decoded: Final = _DECODED_JSON.validate_python(json.loads(psr)) + except Exception: return _snippet(psr) - return _snippet(psr) + return _proxy_request_snippet(decoded) @router.get( diff --git a/litellm/proxy/health_endpoints/_health_endpoints.py b/litellm/proxy/health_endpoints/_health_endpoints.py index 684f1619512..53c54fe15bf 100644 --- a/litellm/proxy/health_endpoints/_health_endpoints.py +++ b/litellm/proxy/health_endpoints/_health_endpoints.py @@ -2304,7 +2304,15 @@ async def test_model_connection( ) selected_by_id: Final = deployment_by_id is not None - reject_server_owned_wif_fields(request_litellm_params) + reject_server_owned_wif_fields( + MappingProxyType( + { + key: value + for key, value in _OBJECT_MAPPING.validate_python(request_litellm_params).items() + if key != "chatgpt_auth_file" + } + ) + ) # Merge: config params (from proxy config) as base, request params override litellm_params = { **_config_base_for_health_check( diff --git a/litellm/proxy/hooks/key_management_event_hooks.py b/litellm/proxy/hooks/key_management_event_hooks.py index 47c3869fb64..8f9aebecf30 100644 --- a/litellm/proxy/hooks/key_management_event_hooks.py +++ b/litellm/proxy/hooks/key_management_event_hooks.py @@ -455,10 +455,10 @@ class KeyManagementEventHooks: try: from litellm.proxy import proxy_server as proxy_server_module + from litellm.proxy.proxy_server import prisma_client except ImportError: return None - prisma_client: Final = getattr(proxy_server_module, "prisma_client", None) user_api_key_cache: Final = getattr(proxy_server_module, "user_api_key_cache", None) if prisma_client is None or user_api_key_cache is None: diff --git a/litellm/proxy/hooks/mcp_semantic_filter/hook.py b/litellm/proxy/hooks/mcp_semantic_filter/hook.py index d33811d3dea..c6e26999766 100644 --- a/litellm/proxy/hooks/mcp_semantic_filter/hook.py +++ b/litellm/proxy/hooks/mcp_semantic_filter/hook.py @@ -18,16 +18,16 @@ from litellm.constants import ( DEFAULT_MCP_SEMANTIC_FILTER_TOP_K, ) from litellm.integrations.custom_logger import CustomLogger -from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( +from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticToolFilterContextWindowError, ) if TYPE_CHECKING: from litellm.caching.caching import DualCache - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy._types import UserAPIKeyAuth from litellm.router import Router @@ -487,7 +487,7 @@ class SemanticToolFilterHook(CustomLogger): Returns: SemanticToolFilterHook instance if enabled, None otherwise """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) diff --git a/litellm/proxy/hooks/parallel_request_limiter.py b/litellm/proxy/hooks/parallel_request_limiter.py index 47ea50debc9..05c64317a44 100644 --- a/litellm/proxy/hooks/parallel_request_limiter.py +++ b/litellm/proxy/hooks/parallel_request_limiter.py @@ -892,7 +892,7 @@ class _PROXY_MaxParallelRequestsHandler(CustomLogger): {**_hidden_params, "additional_headers": _additional_headers}, ) - return await super().async_post_call_success_hook(data, user_api_key_dict, response) + await super().async_post_call_success_hook(data, user_api_key_dict, response) PROXY_MaxParallelRequestsHandler: Final = _PROXY_MaxParallelRequestsHandler diff --git a/litellm/proxy/hooks/parallel_request_limiter_v3.py b/litellm/proxy/hooks/parallel_request_limiter_v3.py index a2bb691b401..567b8452ae2 100644 --- a/litellm/proxy/hooks/parallel_request_limiter_v3.py +++ b/litellm/proxy/hooks/parallel_request_limiter_v3.py @@ -101,7 +101,7 @@ if TYPE_CHECKING: from litellm.types.agents import AgentResponse from litellm.types.caching import RedisPipelineIncrementOperation - Span = _Span | Any + Span = _Span InternalUsageCache = _InternalUsageCache else: Span = Any diff --git a/litellm/proxy/hooks/proxy_track_cost_callback.py b/litellm/proxy/hooks/proxy_track_cost_callback.py index 6801c8521e5..c11b59a809a 100644 --- a/litellm/proxy/hooks/proxy_track_cost_callback.py +++ b/litellm/proxy/hooks/proxy_track_cost_callback.py @@ -38,6 +38,7 @@ from litellm.proxy.db.db_spend_update_writer import ( ) from litellm.proxy.hooks.search_free_tier import apply_search_free_tier from litellm.proxy.litellm_pre_call_utils import LiteLLMProxyRequestSetup, metadata_variable_name_for_route +from litellm.proxy.route_llm_request import ProxyModelNotFoundError from litellm.proxy.spend_tracking.spend_counter_batch import post_call_counter_keys, spend_counter_batch_scope from litellm.proxy.spend_tracking.spend_event import ( ObjectMapping, @@ -60,7 +61,12 @@ from litellm.proxy.spend_tracking.spend_tracking_utils import ( # noqa: F401 # sanitize_error_information_for_spend_logs, should_store_prompts_and_responses_in_spend_logs, ) -from litellm.proxy.utils import BilledFailedAttempt, ProxyUpdateSpend +from litellm.proxy.utils import ( + REJECTED_BEFORE_REQUEST_SETUP, + REJECTED_BEFORE_REQUEST_SETUP_KEY, + BilledFailedAttempt, + ProxyUpdateSpend, +) from litellm.types.router import Deployment from litellm.types.utils import ( CallTypes, @@ -396,6 +402,8 @@ class _ProxyDBLogger(CustomLogger): request_route: Final = user_api_key_dict.request_route if ( ProxyDBLogger._should_track_errors_in_db() is False + or ProxyDBLogger._skips_pre_routing_rejections() + and is_pre_routing_rejection(original_exception, _REQUEST_DATA.validate_python(request_data)) or request_route is not None and not ( RouteChecks.is_llm_api_route(route=request_route) or RouteChecks.is_info_route(route=request_route) @@ -862,16 +870,40 @@ class _ProxyDBLogger(CustomLogger): If users want to disable error tracking, they can set the disable_error_logs flag in the general_settings """ - from litellm.proxy.proxy_server import general_settings - - if general_settings.get("disable_error_logs") is True: + if _general_setting_enabled("disable_error_logs"): return False return + @staticmethod + def _skips_pre_routing_rejections() -> bool: + """``general_settings.disable_pre_routing_error_logs`` keeps requests the proxy rejected before + selecting a deployment out of the spend logs, so a client retrying a bad key or an exhausted + budget cannot flood ``LiteLLM_SpendLogs`` with zero-spend rows.""" + return _general_setting_enabled("disable_pre_routing_error_logs") + + +def _general_setting_enabled(name: str) -> bool: + from litellm.proxy.proxy_server import general_settings + + return name in general_settings and general_settings[name] is True + ProxyDBLogger: Final = _ProxyDBLogger +_REQUEST_DATA: Final = TypeAdapter(dict[str, object]) + + +def is_pre_routing_rejection(exception: Exception, request_data: Mapping[str, object]) -> bool: + """The pipeline sets up the logging object only after auth, body parsing and model resolution succeed, and + before guardrails or routing run. ``ProxyLogging._handle_logging_proxy_only_error`` marks a failure that + arrives without one with the ``REJECTED_BEFORE_REQUEST_SETUP`` sentinel, so that request never had a provider + considered. An unknown model is the one later rejection that still never reached a provider.""" + return request_data.get(REJECTED_BEFORE_REQUEST_SETUP_KEY) is REJECTED_BEFORE_REQUEST_SETUP or isinstance( + exception, ProxyModelNotFoundError + ) + + def _write_spend_metadata_to_kwargs(kwargs: dict, metadata: dict) -> None: patch = {k: v for k, v in metadata.items() if (k.startswith("user_api_key") or k == "tags") and v is not None} if not patch: diff --git a/litellm/proxy/hooks/rate_limiter_utils.py b/litellm/proxy/hooks/rate_limiter_utils.py index bbe38068638..c4949834896 100644 --- a/litellm/proxy/hooks/rate_limiter_utils.py +++ b/litellm/proxy/hooks/rate_limiter_utils.py @@ -7,6 +7,7 @@ from typing import Final import litellm from litellm._logging import verbose_proxy_logger from litellm.constants import PROXY_LLM_PROVIDER_FALLBACK +from litellm.litellm_core_utils.core_helpers import iter_items from litellm.types.router import ModelGroupInfo from litellm.types.utils import PriorityReservationDict @@ -85,10 +86,10 @@ def _resolve_provider_from_router_alias( if llm_router is None: return None try: - model_list: Final = getattr(llm_router, "model_list", None) + model_list: Final[object] = getattr(llm_router, "model_list", None) if not model_list: return None - for deployment in model_list: + for deployment in iter_items(model_list): if not isinstance(deployment, dict): continue if deployment.get("model_name") != model: diff --git a/litellm/proxy/litellm_pre_call_utils.py b/litellm/proxy/litellm_pre_call_utils.py index 8dc7501bc3b..1e7cdc44c70 100644 --- a/litellm/proxy/litellm_pre_call_utils.py +++ b/litellm/proxy/litellm_pre_call_utils.py @@ -99,6 +99,8 @@ _CREDENTIAL_HEADER_NAMES: Final = SpecialHeaders.litellm_credential_header_names {"cookie", "proxy-authorization"} ) _TRANSPORT_ONLY_CREDENTIAL_KEYS: Final = frozenset({"provider_specific_header", "headers", "api_key"}) +_REQUEST_FIELDS: Final = TypeAdapter(Mapping[str, object]) +_REQUEST_ENTRIES: Final = TypeAdapter(tuple[object, ...]) # Matches any header of the form x--session-id (case-insensitive). # Excludes the two explicit litellm headers which are handled with higher priority. @@ -289,6 +291,9 @@ _DESTINATION_ONLY_CALLBACK_VARS: Final[frozenset[str]] = frozenset({CAPTURE_MESS _CALLBACK_CREDENTIAL_KEYS: Final = frozenset(StandardCallbackDynamicParams.__annotations__) | frozenset( {TRUSTED_CALLBACK_VARS_FIELD} ) +_HEADERS_THAT_CANNOT_CHANGE_PROVIDER_AUTH: Final = frozenset( + {*(f"x-litellm-{key}" for key in StandardLoggingUserAPIKeyMetadata.__annotations__), *ANTHROPIC_API_HEADERS} +) service_logger_obj: Final = ServiceLogging() # used for tracking latency on OTEL # Bounded dedup for stale-alias warnings (FIFO eviction when over cap). _MAX_STALE_ALIAS_WARNING_KEYS: Final = 10_000 @@ -461,10 +466,7 @@ _ALLOW_CLIENT_MESSAGE_REDACTION_OPT_OUT_METADATA_KEY: Final = "allow_client_mess _CLIENT_PRICING_CONTROL_FIELDS: Final = frozenset(CustomPricingLiteLLMParams.model_fields.keys()) | {"base_model"} # ``model_info`` carries the same pricing fields when read by # ``use_custom_pricing_for_model``; strip from metadata for the same reason. -# ``standard_logging_guardrail_information`` is proxy-written telemetry summed -# into response_cost and spend; a client seeding it forges (even negative) -# guardrail cost. -_CLIENT_PRICING_METADATA_FIELDS: Final = frozenset({"model_info", "standard_logging_guardrail_information"}) +_CLIENT_PRICING_METADATA_FIELDS: Final = frozenset({"model_info"}) # ``attempted_fallbacks`` and ``original_model_group`` are written by the router # and read by spend logs as fact; a client value has no legitimate meaning and no # key or team setting keeps it, so the strip is never gated. @@ -794,6 +796,19 @@ def _strip_client_pricing_overrides(data: dict[str, object]) -> None: ) +def strip_client_guardrail_information(data: dict[str, object]) -> None: # mutable-ok: strips the request body in place + """Guardrail hooks write this field and its cost is billed, so no key or team setting keeps a caller's value.""" + for metadata_key in ("metadata", "litellm_metadata"): + if ( + isinstance(metadata := data.get(metadata_key), dict) + and "standard_logging_guardrail_information" in metadata + ): + del metadata["standard_logging_guardrail_information"] + verbose_proxy_logger.debug( + "Stripped client-supplied guardrail information from request body: %s", metadata_key + ) + + def _strip_router_reserved_metadata( data: dict[str, object], # mutable-ok: strips in place on the request body the pre-call pipeline threads through ) -> None: @@ -1417,13 +1432,14 @@ def clean_headers( Cleaned headers dict """ from litellm.llms.anthropic.common_utils import is_anthropic_oauth_key + from litellm.llms.chatgpt.common_utils import is_chatgpt_oauth_key clean_headers: Final = {} litellm_key_lower: Final = litellm_key_header_name.lower() if litellm_key_header_name is not None else None for header, value in headers.items(): header_lower = header.lower() - if header_lower == "authorization" and is_anthropic_oauth_key(value): + if header_lower == "authorization" and (is_anthropic_oauth_key(value) or is_chatgpt_oauth_key(value)): if authenticated_with_header is None or authenticated_with_header.lower() != "authorization": clean_headers[header] = value continue @@ -1450,9 +1466,47 @@ def clean_headers( return clean_headers +def _request_fields(value: object) -> Mapping[str, object]: + try: + return _REQUEST_FIELDS.validate_python(value) + except PydanticValidationError: + return MappingProxyType({}) + + +def _request_entries(value: object) -> tuple[object, ...]: + if value is None: + return () + try: + return _REQUEST_ENTRIES.validate_python(value) + except PydanticValidationError: + return (value,) + + +def _carries_a_caller_header(headers: object) -> bool: + return any(name.lower() not in _HEADERS_THAT_CANNOT_CHANGE_PROVIDER_AUTH for name in _request_fields(headers)) + + +def _caller_credential_fields(data: Mapping[str, object]) -> tuple[str, ...]: + """Names of the request fields through which the caller can change how the provider authenticates the call: + ``api_key``, ``organization``, and ``headers``, ``extra_headers`` or a ``provider_specific_header`` entry's + ``extra_headers`` that carry any header besides the key and user details the proxy adds under + ``add_user_information_to_llm_headers`` and the ``anthropic-version`` and ``anthropic-beta`` headers.""" + carried: Final = { + "api_key": "api_key" in data, + "extra_headers": _carries_a_caller_header(data.get("extra_headers")), + "headers": _carries_a_caller_header(data.get("headers")), + "organization": "organization" in data, + "provider_specific_header": any( + _carries_a_caller_header(_request_fields(entry).get("extra_headers")) + for entry in _request_entries(data.get("provider_specific_header")) + ), + } + return tuple(name for name, sent in sorted(carried.items()) if sent) + + def _is_credential_header(header: str) -> bool: """Whether `header` carries a caller credential rather than request context.""" - return header.lower() in _CREDENTIAL_HEADER_NAMES + return header.lower().removeprefix("x-pass-") in _CREDENTIAL_HEADER_NAMES def redact_credential_headers(headers: Mapping[str, str]) -> Mapping[str, str]: @@ -2481,7 +2535,7 @@ async def add_litellm_data_to_request( _headers, allow_client_message_redaction_opt_out=_allow_client_message_redaction_opt_out, ) - from litellm.proxy._experimental.mcp_server.utils import upstream_credential_headers + from litellm.proxy.mcp_server.utils import upstream_credential_headers _mcp_credential_headers: Final = upstream_credential_headers(_headers) _logging_safe_headers: Final = redact_credential_headers( @@ -2604,6 +2658,8 @@ async def add_litellm_data_to_request( data[_metadata_variable_name]["used_client_oauth_token"] = add_provider_specific_headers_to_request( data=data, headers=_headers ) + caller_fields: Final = _caller_credential_fields(_REQUEST_FIELDS.validate_python(data)) + data["proxy_server_request"]["caller_credential_fields"] = caller_fields # rebind-ok: data is an out-param ## Cache Controls cache_control_header: Final = _headers.get("Cache-Control", None) @@ -2649,6 +2705,7 @@ async def add_litellm_data_to_request( # would silently skip the field. if not _key_or_team_allows_client_pricing_override(user_api_key_dict): _strip_client_pricing_overrides(data) + strip_client_guardrail_information(data) _strip_router_reserved_metadata(data) # Same reason as the strips above: runs after the metadata string-to-dict parse @@ -4282,6 +4339,7 @@ _NATIVE_MESSAGES_ANTHROPIC_API_HEADER_PROVIDERS: Final = ",".join( (LlmProviders.AZURE_AI.value, LlmProviders.DATABRICKS.value) ) _ANTHROPIC_OAUTH_CREDENTIAL_PROVIDERS: Final = ",".join(sorted(ANTHROPIC_OAUTH_FORWARD_PROVIDERS)) +_CHATGPT_OAUTH_CREDENTIAL_PROVIDERS: Final = LlmProviders.CHATGPT.value def add_provider_specific_headers_to_request( @@ -4289,6 +4347,7 @@ def add_provider_specific_headers_to_request( headers: Mapping[str, str], ) -> bool: from litellm.llms.anthropic.common_utils import is_anthropic_oauth_key + from litellm.llms.chatgpt.common_utils import select_chatgpt_client_credential_headers anthropic_api_headers: Final = {header: headers[header] for header in ANTHROPIC_API_HEADERS if header in headers} anthropic_oauth_credential_headers: Final = { @@ -4296,6 +4355,8 @@ def add_provider_specific_headers_to_request( for header, value in headers.items() if header.lower() == "authorization" and is_anthropic_oauth_key(value) } + chatgpt_oauth_credential_headers: Final = dict(select_chatgpt_client_credential_headers(headers)) + typesafe_danger_zone_headers: Final = { header: value for header, value in headers.items() @@ -4320,13 +4381,17 @@ def add_provider_specific_headers_to_request( ProviderSpecificHeader( custom_llm_provider=LlmProviders.TYPESAFE.value, extra_headers=typesafe_danger_zone_headers ), + ProviderSpecificHeader( + custom_llm_provider=_CHATGPT_OAUTH_CREDENTIAL_PROVIDERS, + extra_headers=chatgpt_oauth_credential_headers, + ), ) if scoped_header["extra_headers"] ] if scoped_headers: data["provider_specific_header"] = scoped_headers[0] if len(scoped_headers) == 1 else scoped_headers - return bool(anthropic_oauth_credential_headers) + return bool(anthropic_oauth_credential_headers or chatgpt_oauth_credential_headers) def _add_otel_traceparent_to_data(data: dict, request: Request): diff --git a/litellm/proxy/management_endpoints/access_group_endpoints.py b/litellm/proxy/management_endpoints/access_group_endpoints.py index 5f31aa788e2..6558c82f80c 100644 --- a/litellm/proxy/management_endpoints/access_group_endpoints.py +++ b/litellm/proxy/management_endpoints/access_group_endpoints.py @@ -9,7 +9,7 @@ from typing_extensions import ReadOnly, TypedDict from litellm._internal_context import with_service_target from litellm._logging import verbose_proxy_logger -from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager +from litellm.litellm_core_utils.core_helpers import iter_items from litellm.proxy._types import ( CommonProxyErrors, LiteLLM_AccessGroupTable, @@ -36,6 +36,7 @@ from litellm.proxy.management_helpers.resource_display_names import ( key_display_names, mcp_server_display_names, ) +from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.utils import PrismaClient, get_prisma_client_or_throw from litellm.repositories.table_repositories import AccessGroupRepository, TeamRepository from litellm.types.access_group import ( @@ -166,6 +167,16 @@ class _AccessGroupTx(Protocol): def litellm_agentstable(self) -> _AgentTable: ... +class _AccessGroupTransaction(Protocol): + async def __aenter__(self) -> _AccessGroupTx: ... + + async def __aexit__(self, *exc_info: object) -> None: ... + + +def _access_group_transaction(prisma_client: PrismaClient) -> _AccessGroupTransaction: + return prisma_client.db.tx() + + def _require_proxy_admin(user_api_key_dict: UserAPIKeyAuth) -> None: if user_api_key_dict.user_role != LitellmUserRoles.PROXY_ADMIN: raise HTTPException( @@ -191,6 +202,10 @@ def _tool_permissions_json(value: Mapping[str, Sequence[str]] | None) -> "Json": return Json(None) if value is None else Json({server: list(tools) for server, tools in value.items()}) +def _explicitly_set_fields(data: AccessGroupUpdateRequest) -> Mapping[str, object]: + return data.model_dump(exclude_unset=True) + + @dataclass(frozen=True, slots=True) class _ResourceNames: mcp_servers: Mapping[str, str] @@ -539,7 +554,7 @@ async def create_access_group( try: tx: _AccessGroupTx - async with prisma_client.db.tx() as tx: + async with _access_group_transaction(prisma_client) as tx: existing: Final = await tx.litellm_accessgrouptable.find_unique( where={"access_group_name": data.access_group_name} ) @@ -647,7 +662,7 @@ async def update_access_group( _require_proxy_admin(user_api_key_dict) prisma_client: Final = get_prisma_client_or_throw(CommonProxyErrors.db_not_connected_error.value) - update_fields: Final = data.model_dump(exclude_unset=True) + update_fields: Final = _explicitly_set_fields(data) update_data: Final[dict] = {"updated_by": user_api_key_dict.user_id} for field, value in update_fields.items(): if field in ( @@ -658,7 +673,7 @@ async def update_access_group( "access_agent_ids", "access_skill_names", ): - value = list(value or ()) + value = list(iter_items(value or ())) update_data[field] = ( _tool_permissions_json(data.mcp_tool_permissions) if field == "mcp_tool_permissions" else value ) @@ -672,7 +687,7 @@ async def update_access_group( try: tx: _AccessGroupTx - async with prisma_client.db.tx() as tx: + async with _access_group_transaction(prisma_client) as tx: # Read inside the transaction so delta computation is consistent with the write, # avoiding a TOCTOU race where a concurrent update could make deltas stale. existing: Final = await tx.litellm_accessgrouptable.find_unique(where={"access_group_id": access_group_id}) @@ -687,10 +702,10 @@ async def update_access_group( old_team_ids: Final[set[str]] = set(attached[access_group_id]) old_key_ids: Final[set[str]] = set(existing.assigned_key_ids or []) new_team_ids: Final[set[str]] = ( - set(update_fields["assigned_team_ids"] or []) if "assigned_team_ids" in update_fields else old_team_ids + set(data.assigned_team_ids or []) if "assigned_team_ids" in update_fields else old_team_ids ) new_key_ids: Final[set[str]] = ( - set(update_fields["assigned_key_ids"] or []) if "assigned_key_ids" in update_fields else old_key_ids + set(data.assigned_key_ids or []) if "assigned_key_ids" in update_fields else old_key_ids ) teams_to_add = list(new_team_ids - old_team_ids) @@ -747,7 +762,7 @@ async def delete_access_group( affected_key_tokens: list[str] = [] tx: _AccessGroupTx - async with prisma_client.db.tx() as tx: + async with _access_group_transaction(prisma_client) as tx: existing: Final = await tx.litellm_accessgrouptable.find_unique(where={"access_group_id": access_group_id}) if existing is None: raise HTTPException( diff --git a/litellm/proxy/management_endpoints/auto_router_endpoints.py b/litellm/proxy/management_endpoints/auto_router_endpoints.py index d40f64f435f..9c46e711cf6 100644 --- a/litellm/proxy/management_endpoints/auto_router_endpoints.py +++ b/litellm/proxy/management_endpoints/auto_router_endpoints.py @@ -54,6 +54,7 @@ from litellm.proxy.management_helpers.auto_router_permissions import ( from litellm.repositories.autorouter_session_repository import AutoRouterSessionRepository from litellm.repositories.base_repository import SupportsModelDump from litellm.repositories.daily_activity_sql import build_where_clause +from litellm.repositories.table_repositories import PrismaTableRepository from litellm.repositories.team_repository import TeamRepository from litellm.repositories.user_repository import UserRepository from litellm.repositories.verification_token_repository import VerificationTokenRepository @@ -179,7 +180,7 @@ class _ShadowEvalAttemptRow(Protocol): class _ShadowEvalFunnelTable(Protocol): - async def create_many(self, data: Sequence[Mapping[str, object]], skip_duplicates: bool) -> int: ... + async def create_many(self, data: Sequence[Mapping[str, object]], *, skip_duplicates: bool) -> int: ... class _ShadowEvalAttemptTable(Protocol): @@ -204,16 +205,28 @@ def _user_rows(prisma_client: "PrismaClient") -> _UserRowsTable: return UserRepository(prisma_client).table +class _ShadowEvalJobRepository(PrismaTableRepository[_ShadowEvalJobRow]): + table_name = "litellm_shadowevaljob" + + +class _ShadowEvalFunnelRepository(PrismaTableRepository[object]): + table_name = "litellm_shadowevalfunnel" + + +class _ShadowEvalAttemptRepository(PrismaTableRepository[_ShadowEvalAttemptRow]): + table_name = "litellm_shadowevalattempt" + + def _shadow_eval_jobs(prisma_client: "PrismaClient") -> _ShadowEvalJobTable: - return prisma_client.db.litellm_shadowevaljob + return _ShadowEvalJobRepository(prisma_client).table def _shadow_eval_funnel(prisma_client: "PrismaClient") -> _ShadowEvalFunnelTable: - return prisma_client.db.litellm_shadowevalfunnel # pyright: ignore[reportAttributeAccessIssue] # generated client + return _ShadowEvalFunnelRepository(prisma_client).table def _shadow_eval_attempts(prisma_client: "PrismaClient") -> _ShadowEvalAttemptTable: - return prisma_client.db.litellm_shadowevalattempt + return _ShadowEvalAttemptRepository(prisma_client).table async def _query_raw(prisma_client: "PrismaClient", query: str, *args: object) -> Sequence[Mapping[str, object]]: @@ -221,6 +234,10 @@ async def _query_raw(prisma_client: "PrismaClient", query: str, *args: object) - return await prisma_client.db.query_raw(query, *args) +async def _execute_raw(prisma_client: "PrismaClient", query: str, *args: object) -> int: + return await prisma_client.db.execute_raw(query, *args) + + async def _authorize_router_dry_run(user_api_key_dict: UserAPIKeyAuth, team_id: str | None) -> LiteLLM_TeamTable | None: from litellm.proxy.management_endpoints.model_management_endpoints import ( ModelManagementAuthChecks, @@ -1788,7 +1805,7 @@ async def start_shadow_eval( # deliberate. Sweep and claim filter on exact (target_type, id) pairs so a team id # that happens to equal a key hash never matches the other kind's slot. for target_type, ids in requested_by_type: - await prisma_client.db.execute_raw(_SWEEP_FINISHED_JOBS_SQL, list(ids), target_type) + await _execute_raw(prisma_client, _SWEEP_FINISHED_JOBS_SQL, list(ids), target_type) claimed: Final = await _shadow_eval_jobs(prisma_client).find_many( where={ "OR": [ @@ -2005,8 +2022,8 @@ async def stop_shadow_eval_job( raise HTTPException(status_code=500, detail=CommonProxyErrors.db_not_connected_error.value) stamp: Final = datetime.now(timezone.utc) operator: Final = user_api_key_dict.user_id or "operator" - claimed: Final = await prisma_client.db.execute_raw( - _STOP_JOB_SQL, job_id, operator, stamp.replace(tzinfo=None).isoformat() + claimed: Final = await _execute_raw( + prisma_client, _STOP_JOB_SQL, job_id, operator, stamp.replace(tzinfo=None).isoformat() ) legs: Final = _LEG_ROWS.validate_python( await _shadow_eval_jobs(prisma_client).find_many(where={"group_id": job_id}) or () diff --git a/litellm/proxy/management_endpoints/common_utils.py b/litellm/proxy/management_endpoints/common_utils.py index adf89c29279..983c3d24513 100644 --- a/litellm/proxy/management_endpoints/common_utils.py +++ b/litellm/proxy/management_endpoints/common_utils.py @@ -569,8 +569,8 @@ _TEAM_MEMBER_BUDGET_LIMIT_FIELDS: Final = ( "temp_budget_expiry", ) -_TEMP_BUDGET_FIELDS: Final = frozenset({"temp_budget_increase", "temp_budget_expiry"}) +_BUDGET_COLUMNS: Final = TypeAdapter(dict[str, object]) MEMBER_BUDGET_PATCH_FIELDS: Final = MappingProxyType( { @@ -653,8 +653,8 @@ async def upsert_budget_and_membership( ``shared_budget_ids`` extends that protection to any other row more than one membership points at, which a caller patching several members at once has already counted; a row listed there is cloned rather than written in place. - A patch that only touches the temporary budget pair never copies permanent - limits into a new row, so the member keeps inheriting the live team default. + A patch whose every field already matches the shared row changes nothing and + is a no-op rather than a clone. """ ignore_default_model_budget_clear: Final = ( existing_budget_id is not None @@ -685,7 +685,6 @@ async def upsert_budget_and_membership( is_shared_default: Final = existing_budget_id is not None and ( existing_budget_id == team_default_budget_id or existing_budget_id in (shared_budget_ids or frozenset()) ) - temp_only: Final = frozenset(write_data) <= _TEMP_BUDGET_FIELDS async def _disconnect(): await tx.litellm_teammembership.update( @@ -707,11 +706,15 @@ async def upsert_budget_and_membership( return source_row: Final = ( - await tx.litellm_budgettable.find_unique(where={"budget_id": existing_budget_id}) - if is_shared_default and not temp_only - else None + await tx.litellm_budgettable.find_unique(where={"budget_id": existing_budget_id}) if is_shared_default else None ) - source: Final[Mapping[str, object]] = source_row.model_dump() if source_row is not None else MappingProxyType({}) + source: Final[Mapping[str, object]] = ( + MappingProxyType(_BUDGET_COLUMNS.validate_python(source_row.model_dump())) + if source_row is not None + else MappingProxyType({}) + ) + if is_shared_default and all(source.get(field) == value for field, value in effective_patch.items()): + return create_data: Final[dict[str, object]] = { # mutable-ok: Prisma create payloads are dict-shaped "created_by": user_api_key_dict.user_id or "", @@ -740,7 +743,7 @@ async def upsert_budget_and_membership( create_data.pop("budget_reset_at", None) if not _has_meaningful_budget_limit(create_data): - if existing_budget_id is not None and not temp_only: + if existing_budget_id is not None: await _disconnect() return diff --git a/litellm/proxy/management_endpoints/credential_migration.py b/litellm/proxy/management_endpoints/credential_migration.py index b1f0002e143..14dd9ce6e8a 100644 --- a/litellm/proxy/management_endpoints/credential_migration.py +++ b/litellm/proxy/management_endpoints/credential_migration.py @@ -42,6 +42,7 @@ from litellm.proxy.db.db_span import db_span if TYPE_CHECKING: from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.utils import PrismaClient + from litellm.repositories.prisma_protocols import TableActions from litellm.proxy.common_utils.encrypt_decrypt_utils import ( # noqa: F401 # legacy module exports _ALGO_AES_GCM, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export _ENCRYPTION_ALGORITHM_SETTING, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export @@ -523,7 +524,7 @@ async def _scan_one_table( scalar_columns: tuple, ) -> LocationReport: report: Final = LocationReport(location=location) - table: Final = getattr(prisma_client.db, db_attr, None) + table: Final[TableActions[object] | None] = getattr(prisma_client.db, db_attr, None) if table is None: return report try: diff --git a/litellm/proxy/management_endpoints/key_budget_change.py b/litellm/proxy/management_endpoints/key_budget_change.py index 3143ef53d76..197a13cdb13 100644 --- a/litellm/proxy/management_endpoints/key_budget_change.py +++ b/litellm/proxy/management_endpoints/key_budget_change.py @@ -9,6 +9,7 @@ from typing import Final, Literal, TypeAlias from pydantic import TypeAdapter, ValidationError from litellm._logging import verbose_proxy_logger +from litellm.litellm_core_utils.duration_parser import normalize_duration from litellm.models.team import BudgetLimitEntry from litellm.models.verification_token import LiteLLM_VerificationToken from litellm.proxy._types import UpdateKeyRequest @@ -99,6 +100,30 @@ def _budget_limits_change(data: UpdateKeyRequest, existing: LiteLLM_Verification return "tightened" if kept_or_lowered else "loosened" +def _reset_schedule(budget_duration: str | None) -> str | None: + return None if budget_duration is None else normalize_duration(budget_duration) + + +def _changes_budget_duration(data: UpdateKeyRequest, existing: LiteLLM_VerificationToken) -> bool: + return "budget_duration" in data.model_fields_set and _reset_schedule(data.budget_duration) != _reset_schedule( + existing.budget_duration + ) + + +def _changes_budget_id(data: UpdateKeyRequest, existing: LiteLLM_VerificationToken) -> bool: + return "budget_id" in data.model_fields_set and data.budget_id != existing.budget_id + + +def _budget_duration_change(data: UpdateKeyRequest, existing: LiteLLM_VerificationToken) -> _FieldChange: + """ + Any new `budget_duration` restarts the reset schedule from now, so only clearing it tightens the + stored `max_budget`. A key with no `max_budget` has no cap for the schedule to reset. + """ + if existing.max_budget is None or not _changes_budget_duration(data, existing): + return "unchanged" + return "tightened" if data.budget_duration is None else "loosened" + + @dataclass(frozen=True, slots=True) class EffectiveKeyBudget: max_budget: float | None @@ -122,12 +147,23 @@ def effective_key_budget(data: UpdateKeyRequest, existing: LiteLLM_VerificationT def classify_key_budget_change(data: UpdateKeyRequest, existing: LiteLLM_VerificationToken) -> KeyBudgetChange: - overrides_linked_budget: Final = ( - existing.budget_id is not None and _max_budget_change(data, existing) != "unchanged" + overrides_linked_budget: Final = existing.budget_id is not None and ( + _max_budget_change(data, existing) != "unchanged" or _changes_budget_duration(data, existing) ) - if data.spend is not None or "soft_budget" in data.model_fields_set or overrides_linked_budget: + if ( + data.spend is not None + or "soft_budget" in data.model_fields_set + or overrides_linked_budget + or _changes_budget_id(data, existing) + ): return KeyBudgetAdminOnly() - changes: Final = frozenset((_max_budget_change(data, existing), _budget_limits_change(data, existing))) + changes: Final = frozenset( + ( + _max_budget_change(data, existing), + _budget_limits_change(data, existing), + _budget_duration_change(data, existing), + ) + ) if "loosened" in changes: return KeyBudgetLoosened() if "tightened" in changes: diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.py index eebc537509b..e4688784bee 100644 --- a/litellm/proxy/management_endpoints/key_management_endpoints.py +++ b/litellm/proxy/management_endpoints/key_management_endpoints.py @@ -44,14 +44,6 @@ from litellm.litellm_core_utils.duration_parser import duration_in_seconds from litellm.litellm_core_utils.safe_json_dumps import safe_dumps from litellm.models.credentials import CredentialItem from litellm.models.project import LiteLLM_ProjectTable -from litellm.proxy._experimental.mcp_server.db import ( - rotate_mcp_server_credentials_master_key, - rotate_mcp_user_credentials_master_key, - rotate_mcp_user_env_vars_master_key, -) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( - rotate_sso_identity_assertions_master_key, -) from litellm.proxy._types import * from litellm.proxy._types import Litellm_EntityType, LiteLLM_VerificationToken, hash_token from litellm.proxy.auth.auth_checks import ( # noqa: F401 # legacy module exports @@ -153,6 +145,14 @@ from litellm.proxy.management_helpers.team_member_permission_checks import ( TeamMemberPermissionChecks, ) from litellm.proxy.management_helpers.utils import management_endpoint_wrapper +from litellm.proxy.mcp_server.db import ( + rotate_mcp_server_credentials_master_key, + rotate_mcp_user_credentials_master_key, + rotate_mcp_user_env_vars_master_key, +) +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( + rotate_sso_identity_assertions_master_key, +) from litellm.proxy.search_endpoints.search_tool_registry import rotate_search_tools_master_key from litellm.proxy.spend_tracking.budget_reservation import get_budget_window_start from litellm.proxy.spend_tracking.spend_counter_batch import SPEND_COUNTERS_TARGET @@ -167,6 +167,7 @@ from litellm.proxy.utils import ( # noqa: F401 # legacy module exports handle_exception_on_proxy, hash_token_if_needed, is_valid_api_key, + require_enterprise_license, ) from litellm.repositories.base_repository import BaseRepository, record_to_dict from litellm.repositories.budget_repository import BudgetRepository @@ -211,6 +212,7 @@ if TYPE_CHECKING: from prisma import models as prisma_models _RepositoryModelT = TypeVar("_RepositoryModelT", bound=BaseModel) +_RawRowT = TypeVar("_RawRowT") class _UserRowLike(Protocol): @@ -234,6 +236,12 @@ class _TxTables(Protocol): litellm_proxymodeltable: TableActions[object] +class _ModelReencryptTransaction(Protocol): + async def __aenter__(self) -> _TxTables: ... + + async def __aexit__(self, *exc_info: object) -> None: ... + + class _ModelParamsUpdate(TypedDict): litellm_params: ReadOnly["prisma.Json"] @@ -334,6 +342,14 @@ def _credentials_table(prisma_client: PrismaClient) -> TableActions[CredentialIt ) +async def _query_raw_rows(prisma_client: PrismaClient, query: str, *args: object) -> Sequence[_RawRowT]: + return await prisma_client.db.query_raw(query, *args) + + +def _model_reencrypt_transaction(prisma_client: PrismaClient) -> _ModelReencryptTransaction: + return prisma_client.db.tx(timeout=timedelta(minutes=2)) + + def _config_table(prisma_client: PrismaClient, *, use_writer: bool = False) -> _ConfigTableActions: return cast( # cast-ok: ConfigRepository.table hides the write actions this module needs on that same object "_ConfigTableActions", ConfigRepository(prisma_client, use_writer=use_writer).table @@ -1313,11 +1329,6 @@ async def validate_team_id_used_in_service_account_request( return True -_BUDGET_NUMERIC_KEYS = frozenset( - ["max_budget", "soft_budget", "max_parallel_requests", "tpm_limit", "rpm_limit", "tpd_limit"] -) - - def _enforce_upperbound_key_params( data: GenerateKeyRequest | UpdateKeyRequest, fill_defaults: bool = True, @@ -1332,13 +1343,20 @@ def _enforce_upperbound_key_params( # (GHSA-2rv4-xv66-fpjg): float('nan') passes every `< 0` check because # nan < 0 is False, and spend >= nan is always False, permanently disabling # budget enforcement for any key that carries it. - for elem in data: - key, value = elem - if key in _BUDGET_NUMERIC_KEYS and value is not None: - if not math.isfinite(value): + budget_numeric_fields: Final = ( + ("max_budget", data.max_budget), + ("max_parallel_requests", data.max_parallel_requests), + ("tpm_limit", data.tpm_limit), + ("rpm_limit", data.rpm_limit), + ("tpd_limit", data.tpd_limit), + ("soft_budget", data.soft_budget), + ) + for field_name, field_value in budget_numeric_fields: + if field_value is not None: + if not math.isfinite(field_value): raise HTTPException( status_code=400, - detail={"error": f"{key} must be a finite number. Received: {value}"}, + detail={"error": f"{field_name} must be a finite number. Received: {field_value}"}, ) if litellm.upperbound_key_generate_params is None: @@ -5242,10 +5260,13 @@ async def generate_key_helper_fn( if isinstance(saved_token["metadata"], str): saved_token["metadata"] = json.loads(saved_token["metadata"]) if isinstance(saved_token["permissions"], str): - if "get_spend_routes" in saved_token["permissions"] and premium_user is not True: - raise ValueError("get_spend_routes permission is only available for LiteLLM Enterprise users") - saved_token["permissions"] = json.loads(saved_token["permissions"]) + if ( + isinstance(saved_token["permissions"], dict) + and "get_spend_routes" in saved_token["permissions"] + and premium_user is not True + ): + require_enterprise_license("get_spend_routes") if isinstance(saved_token["model_max_budget"], str): saved_token["model_max_budget"] = json.loads(saved_token["model_max_budget"]) router_settings = cast(dict | None, saved_token.get("router_settings")) @@ -5746,8 +5767,7 @@ async def rotate_master_key( ] ) verbose_proxy_logger.debug("Re-encrypting litellm_params on %s model rows", len(reencrypted_models)) - async with prisma_client.db.tx(timeout=timedelta(minutes=2)) as tx_ctx: - tx: Final[_TxTables] = tx_ctx + async with _model_reencrypt_transaction(prisma_client) as tx: for reencrypted_model in reencrypted_models: await tx.litellm_proxymodeltable.update_many( data=_ModelParamsUpdate(litellm_params=prisma.Json(reencrypted_model.litellm_params)), @@ -7344,7 +7364,7 @@ async def key_aliases( where_sql: Final = " AND ".join(where_parts) count_sql: Final = f'SELECT COUNT(*) AS count FROM "LiteLLM_VerificationToken" WHERE {where_sql}' - count_rows: Final[Sequence[Mapping[str, int]]] = await prisma_client.db.query_raw(count_sql, *query_params) + count_rows: Final[Sequence[Mapping[str, int]]] = await _query_raw_rows(prisma_client, count_sql, *query_params) total_count: Final = int(count_rows[0]["count"]) if count_rows else 0 aliases_params: Final = query_params + [size, (page - 1) * size] @@ -7357,7 +7377,9 @@ async def key_aliases( f" ORDER BY key_alias ASC" f" LIMIT ${limit_idx} OFFSET ${offset_idx}" ) - alias_rows: Final[Sequence[Mapping[str, str]]] = await prisma_client.db.query_raw(aliases_sql, *aliases_params) + alias_rows: Final[Sequence[Mapping[str, str]]] = await _query_raw_rows( + prisma_client, aliases_sql, *aliases_params + ) aliases: Final[list[str]] = [row["key_alias"] for row in alias_rows if row.get("key_alias")] total_pages: Final = -(-total_count // size) if total_count > 0 else 0 @@ -7879,7 +7901,7 @@ async def block_key( --header "Authorization: Bearer $LITELLM_MASTER_KEY" \ --header 'Content-Type: application/json' \ --data '{ - "key": "sk-Fn8Ej39NxjAXrvpUGKghGw" + "key": "YOUR_VIRTUAL_KEY" }' ``` @@ -7993,7 +8015,7 @@ async def unblock_key( --header "Authorization: Bearer $LITELLM_MASTER_KEY" \ --header 'Content-Type: application/json' \ --data '{ - "key": "sk-Fn8Ej39NxjAXrvpUGKghGw" + "key": "YOUR_VIRTUAL_KEY" }' ``` diff --git a/litellm/proxy/management_endpoints/management_v1/spend_logs.py b/litellm/proxy/management_endpoints/management_v1/spend_logs.py index b93c05c555f..da84c2d0013 100644 --- a/litellm/proxy/management_endpoints/management_v1/spend_logs.py +++ b/litellm/proxy/management_endpoints/management_v1/spend_logs.py @@ -1,10 +1,12 @@ """`/management/v1/spend_logs` facets.""" +from collections.abc import Sequence from datetime import datetime, timezone from functools import partial -from typing import Annotated, Final, Literal +from typing import Annotated, Final, Literal, Protocol from fastapi import APIRouter, Depends, Query, Request +from typing_extensions import ReadOnly, TypedDict from litellm._logging import verbose_proxy_logger from litellm.proxy._types import CommonProxyErrors, UserAPIKeyAuth @@ -19,6 +21,7 @@ from litellm.proxy.list_api.common import ( reject_unknown_query_params, ) from litellm.proxy.management_endpoints.management_v1.common import MANAGEMENT_V1_PREFIX +from litellm.proxy.utils import PrismaClient from litellm.types.proxy.management_endpoints.management_v1 import ( FacetListResponse, PageMeta, @@ -33,6 +36,19 @@ router: Final = APIRouter(prefix=MANAGEMENT_V1_PREFIX) SPEND_LOGS_FACET_SCAN_CAP: Final = 10000 +class _FacetRow(TypedDict, total=False): + end_user: ReadOnly[str | None] + user: ReadOnly[str | None] + + +class _FacetQuery(Protocol): + async def __call__(self, query: str, *args: object) -> Sequence[_FacetRow]: ... + + +def _facet_query(prisma_client: PrismaClient) -> _FacetQuery: + return prisma_client.db.query_raw + + def _as_utc(value: datetime) -> datetime: return value.replace(tzinfo=timezone.utc) if value.tzinfo is None else value.astimezone(timezone.utc) @@ -125,8 +141,8 @@ async def _list_spend_log_facet( f" ORDER BY {column_sql} ASC" f" LIMIT ${scan_idx + 1} OFFSET ${scan_idx + 2}" ) - rows: Final = await prisma_client.db.query_raw(facet_sql, *params) - values: Final[list[str]] = [row[column] for row in rows if row.get(column)] + rows: Final = await _facet_query(prisma_client)(facet_sql, *params) + values: Final[list[str]] = [value for row in rows if (value := row.get(column))] has_more: Final = len(values) > page_size return FacetListResponse( diff --git a/litellm/proxy/management_endpoints/mcp_management_endpoints.py b/litellm/proxy/management_endpoints/mcp_management_endpoints.py index a014b9cf8a5..f6b836bc4be 100644 --- a/litellm/proxy/management_endpoints/mcp_management_endpoints.py +++ b/litellm/proxy/management_endpoints/mcp_management_endpoints.py @@ -49,7 +49,7 @@ from fastapi.responses import JSONResponse from pydantic import TypeAdapter from typing_extensions import ReadOnly, TypedDict -from litellm.proxy._experimental.mcp_server.catalog import catalog_operation, public_catalog_operation +from litellm.proxy.mcp_server.catalog import catalog_operation, public_catalog_operation try: from prisma.errors import RecordNotFoundError, UniqueViolationError @@ -63,19 +63,6 @@ from litellm._logging import verbose_logger, verbose_proxy_logger from litellm._uuid import uuid from litellm.constants import LITELLM_PROXY_ADMIN_NAME, MCP_GATEWAY_SESSION_ID_PREFIX_LENGTH from litellm.litellm_core_utils.core_helpers import as_str_mapping -from litellm.proxy._experimental.mcp_server.utils import ( - LITELLM_MCP_SERVER_DESCRIPTION, - LITELLM_MCP_SERVER_NAME, - MCP_SERVERS_TARGET, - McpServerPayloadLike, - build_env_var_setup_url, - collect_env_var_references, - get_server_prefix, - parse_admin_env_vars, -) -from litellm.proxy._experimental.mcp_server.utils import ( - validate_and_normalize_mcp_server_payload as _base_validate_and_normalize_mcp_server_payload, -) from litellm.proxy.common_utils.encrypt_decrypt_utils import ( decrypt_value_helper, encrypt_value_helper, @@ -87,6 +74,19 @@ from litellm.proxy.management_helpers.audit_logs import ( get_audit_log_changed_by, is_audit_logging_enabled, ) +from litellm.proxy.mcp_server.utils import ( + LITELLM_MCP_SERVER_DESCRIPTION, + LITELLM_MCP_SERVER_NAME, + MCP_SERVERS_TARGET, + McpServerPayloadLike, + build_env_var_setup_url, + collect_env_var_references, + get_server_prefix, + parse_admin_env_vars, +) +from litellm.proxy.mcp_server.utils import ( + validate_and_normalize_mcp_server_payload as _base_validate_and_normalize_mcp_server_payload, +) from litellm.repositories.table_repositories import ( MCPServerRepository, MCPUserCredentialsRepository, @@ -104,6 +104,14 @@ class _HasServerId(Protocol): server_id: str +class _TemporaryServerCacheWriter(Protocol): + async def async_set_cache(self, *, key: str, value: str, ttl: int) -> object: ... + + +class _TemporaryServerCacheReader(Protocol): + async def async_get_cache(self, *, key: str) -> object: ... + + def _session_cookie_claims(claims: Mapping[str, object]) -> Mapping[str, object]: return claims @@ -151,63 +159,6 @@ if MCP_AVAILABLE: def validate_tool_name(name: str) -> _ToolNameValidationResult: return _ToolNameValidationResult() - from litellm.proxy._experimental.mcp_server.contracts import TargetCatalog - from litellm.proxy._experimental.mcp_server.db import ( - McpIdentifierConflict, - approve_mcp_server, - create_draft_mcp_server, - create_mcp_server_if_identifier_free, - delete_mcp_server, - delete_user_credential, - delete_user_env_vars, - get_all_mcp_servers, - get_draft_mcp_server, - get_mcp_server, - get_mcp_servers, - get_mcp_submissions, - get_user_env_vars, - get_user_env_vars_bulk, - get_user_oauth_credential, - is_resubmitted_oauth_client, - list_server_user_credentials, - list_user_oauth_credentials, - mcp_oauth_token_identity, - merge_user_env_vars, - oauth_credentials_for_upstream_edit, - purge_user_oauth_credentials_for_server, - reject_mcp_server, - set_mcp_server_pinned_tools, - stale_mcp_auth_fields, - store_user_credential, - store_user_oauth_credential, - update_mcp_server, - ) - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( # noqa: F401 # legacy module exports - _raise_if_not_oauth2, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export - authorize_with_server, - client_supplied_application_type, - client_supplied_redirect_uris, - exchange_token_with_server, - get_request_base_url, - raise_if_not_oauth2, - redeem_passthrough_authorization_code, - register_client_with_server, - resolve_ephemeral_dcr_client, - ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - global_mcp_server_manager, - ) - from litellm.proxy._experimental.mcp_server.server_resolution import ( - MCPServerTargetCatalog, - authorize_mcp_server, - resolve_mcp_server, - ) - from litellm.proxy._experimental.mcp_server.ui_session_utils import ( - admitted_user_context, - build_effective_auth_contexts, - granted_toolset_ids, - is_ui_session_credential, - ) from litellm.proxy._types import ( LiteLLM_MCPServerTable, LiteLLM_ObjectPermissionTable, @@ -258,6 +209,63 @@ if MCP_AVAILABLE: convert_connector_entries, ) from litellm.proxy.management_helpers.utils import management_endpoint_wrapper + from litellm.proxy.mcp_server.contracts import TargetCatalog + from litellm.proxy.mcp_server.db import ( + McpIdentifierConflict, + approve_mcp_server, + create_draft_mcp_server, + create_mcp_server_if_identifier_free, + delete_mcp_server, + delete_user_credential, + delete_user_env_vars, + get_all_mcp_servers, + get_draft_mcp_server, + get_mcp_server, + get_mcp_servers, + get_mcp_submissions, + get_user_env_vars, + get_user_env_vars_bulk, + get_user_oauth_credential, + is_resubmitted_oauth_client, + list_server_user_credentials, + list_user_oauth_credentials, + mcp_oauth_token_identity, + merge_user_env_vars, + oauth_credentials_for_upstream_edit, + purge_user_oauth_credentials_for_server, + reject_mcp_server, + set_mcp_server_pinned_tools, + stale_mcp_auth_fields, + store_user_credential, + store_user_oauth_credential, + update_mcp_server, + ) + from litellm.proxy.mcp_server.discoverable_endpoints import ( # noqa: F401 # legacy module exports + _raise_if_not_oauth2, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export + authorize_with_server, + client_supplied_application_type, + client_supplied_redirect_uris, + exchange_token_with_server, + get_request_base_url, + raise_if_not_oauth2, + redeem_passthrough_authorization_code, + register_client_with_server, + resolve_ephemeral_dcr_client, + ) + from litellm.proxy.mcp_server.mcp_server_manager import ( + global_mcp_server_manager, + ) + from litellm.proxy.mcp_server.server_resolution import ( + MCPServerTargetCatalog, + authorize_mcp_server, + resolve_mcp_server, + ) + from litellm.proxy.mcp_server.ui_session_utils import ( + admitted_user_context, + build_effective_auth_contexts, + granted_toolset_ids, + is_ui_session_credential, + ) from litellm.types.mcp import ( MCP_ADMIN_CONFIG_CREDENTIAL_KEYS, MCPAuth, @@ -527,7 +535,7 @@ if MCP_AVAILABLE: """ if litellm.cache is None or not hasattr(litellm.cache, "cache"): return - cache_backend: Final = getattr(litellm.cache, "cache", None) + cache_backend: Final[_TemporaryServerCacheWriter | None] = getattr(litellm.cache, "cache", None) if cache_backend is None or not hasattr(cache_backend, "async_set_cache"): return @@ -566,7 +574,7 @@ if MCP_AVAILABLE: """ if litellm.cache is None or not hasattr(litellm.cache, "cache"): return None - cache_backend: Final = getattr(litellm.cache, "cache", None) + cache_backend: Final[_TemporaryServerCacheReader | None] = getattr(litellm.cache, "cache", None) if cache_backend is None or not hasattr(cache_backend, "async_get_cache"): return None @@ -1089,7 +1097,7 @@ if MCP_AVAILABLE: """ Get all MCP tools available for the current key, including those from access groups """ - from litellm.proxy._experimental.mcp_server.server import _list_mcp_tools + from litellm.proxy.mcp_server.server import _list_mcp_tools listing: Final = await _list_mcp_tools( user_api_key_auth=user_api_key_dict, @@ -1114,7 +1122,7 @@ if MCP_AVAILABLE: """ Get all available MCP access groups from the database AND config """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) from litellm.proxy.proxy_server import prisma_client @@ -1670,7 +1678,7 @@ if MCP_AVAILABLE: status_code=status.HTTP_403_FORBIDDEN, detail={"error": "Admin access required to view MCP gateway sessions."}, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( get_mcp_gateway_sessions_report, ) @@ -1705,7 +1713,7 @@ if MCP_AVAILABLE: "error": "Provide session_id_prefix and/or user_id to select the sessions to terminate.", }, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( terminate_mcp_gateway_sessions, ) @@ -1769,7 +1777,7 @@ if MCP_AVAILABLE: status_code=status.HTTP_404_NOT_FOUND, detail={"error": f"MCP server '{server_id}' not found in the database."}, ) - from litellm.proxy._experimental.mcp_server.rest_endpoints import fetch_pinnable_tool_catalog + from litellm.proxy.mcp_server.rest_endpoints import fetch_pinnable_tool_catalog snapshot: Final = await fetch_pinnable_tool_catalog(server, request, user_api_key_dict) if not snapshot: @@ -2334,12 +2342,12 @@ if MCP_AVAILABLE: # issued to this client could mint fresh upstream access tokens through # us. Require normal LiteLLM auth for those. if not api_key: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 - global_mcp_server_manager, - ) from litellm.proxy.auth.auth_utils import ( # noqa: PLC0415 get_request_route, ) + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 + global_mcp_server_manager, + ) server_id: Final[str] = request.path_params.get("server_id", "") if server_id: @@ -2669,7 +2677,7 @@ if MCP_AVAILABLE: ) if payload.save: await store_user_credential(prisma_client, user_id, server_id, payload.credential) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _invalidate_byok_cred_cache, ) @@ -2700,7 +2708,7 @@ if MCP_AVAILABLE: await delete_user_credential(prisma_client, target_user_id, server_id) except RecordNotFoundError: pass # Already deleted or didn't exist - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _invalidate_byok_cred_cache, ) @@ -2724,7 +2732,7 @@ if MCP_AVAILABLE: """Persist the OAuth2 access token obtained by the calling user.""" prisma_client: Final = get_prisma_client_or_throw("Database not connected. Connect a database to your proxy") await _authorize_and_fetch_mcp_server(prisma_client, user_api_key_dict, server_id) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # keep manager import lazy + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # keep manager import lazy global_mcp_server_manager as _manager, ) @@ -2761,7 +2769,7 @@ if MCP_AVAILABLE: expires_in=payload.expires_in, scopes=payload.scopes, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 global_mcp_server_manager, ) @@ -2805,7 +2813,7 @@ if MCP_AVAILABLE: await delete_user_credential(prisma_client, target_user_id, server_id) except RecordNotFoundError: pass # Already gone — treat as a successful delete - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 global_mcp_server_manager, ) @@ -3099,7 +3107,7 @@ if MCP_AVAILABLE: allowed_names: Final = {spec["name"] for spec in user_specs} updates: Final = {k: v for k, v in payload.values.items() if k in allowed_names and v != ""} merged: Final = await merge_user_env_vars(prisma_client, user_id, server_id, updates, allowed_names) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( invalidate_user_env_vars_cache, ) @@ -3126,7 +3134,7 @@ if MCP_AVAILABLE: ) server: Final = await _authorize_and_fetch_mcp_server(prisma_client, user_api_key_dict, server_id) await delete_user_env_vars(prisma_client, user_id, server_id) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( invalidate_user_env_vars_cache, ) @@ -3361,7 +3369,7 @@ if MCP_AVAILABLE: try: # Update the public model groups import litellm - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) from litellm.proxy.proxy_server import proxy_config @@ -3524,7 +3532,7 @@ if MCP_AVAILABLE: # MCP Toolset endpoints # --------------------------------------------------------------------------- - from litellm.proxy._experimental.mcp_server.toolset_db import ( + from litellm.proxy.mcp_server.toolset_db import ( create_mcp_toolset, delete_mcp_toolset, get_mcp_toolset, @@ -3569,7 +3577,7 @@ if MCP_AVAILABLE: status_code=status.HTTP_409_CONFLICT, detail={"error": f"A toolset named '{payload.toolset_name}' already exists."}, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -3665,7 +3673,7 @@ if MCP_AVAILABLE: status_code=status.HTTP_404_NOT_FOUND, detail={"error": f"Toolset '{payload.toolset_id}' not found."}, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -3695,7 +3703,7 @@ if MCP_AVAILABLE: status_code=status.HTTP_404_NOT_FOUND, detail={"error": f"Toolset '{toolset_id}' not found."}, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) diff --git a/litellm/proxy/management_endpoints/model_management_endpoints.py b/litellm/proxy/management_endpoints/model_management_endpoints.py index fc0868a5fc9..e625ea6f9f2 100644 --- a/litellm/proxy/management_endpoints/model_management_endpoints.py +++ b/litellm/proxy/management_endpoints/model_management_endpoints.py @@ -145,6 +145,7 @@ from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.bedrock import AwsSessionTag from litellm.types.proxy.management_endpoints.model_management_endpoints import ( AutoRouterClassifierDefaultPromptResponse, + PatchModelRequest, UpdateUsefulLinksRequest, ) from litellm.types.router import ( @@ -160,6 +161,7 @@ from litellm.types.utils import ( OIDC_SECRET_REFERENCE_PREFIX, echoed_cost_map_fields, echoed_cost_map_pricing_fields, + is_server_derived_pricing_key, without_server_derived_pricing, ) from litellm.utils import get_utc_datetime @@ -995,6 +997,7 @@ def _ptu_zeroed_pricing( def _ptu_pricing_delta( *, stored_model_info: Mapping[str, object], + stored_litellm_params: Mapping[str, object], model_info: Mapping[str, object], litellm_params: Mapping[str, object], patch: updateDeployment, @@ -1014,6 +1017,24 @@ def _ptu_pricing_delta( supplied: Final = patch.litellm_params.model_dump(exclude_none=True) if patch.litellm_params else _EMPTY_MODEL_INFO zeroed: Final = _ptu_zeroed_pricing(model_info=model_info, litellm_params=litellm_params, supplied=supplied) if zeroed: + retains_ptu: Final = all(stored_model_info.get(field) is not None for field in _PTU_PRICED_PAIR) + protected_pricing: Final = frozenset( + field + for field in _CUSTOM_PRICING_FIELDS + if retains_ptu + and (stored_litellm_params.get(field) is not None or stored_model_info.get(field) is not None) + ).union(zeroed) + removed_ptu_pricing: Final = tuple( + field for field in _param_keys_to_remove(patch) if field in protected_pricing + ) + if removed_ptu_pricing: + raise HTTPException( + status_code=400, + detail=( + f"PTU billing requires {', '.join(removed_ptu_pricing)}, so these pricing parameters cannot be removed. " + "Keep them when enabling PTU, or clear ptu_count and cost_per_ptu_per_hour together to disable it." + ), + ) return zeroed, frozenset() was_ptu: Final = any(stored_model_info.get(field) is not None for field in _PTU_PRICED_PAIR) if not was_ptu or not _explicitly_cleared_ptu_fields(patch.model_info) & _PTU_PRICED_PAIR: @@ -1069,6 +1090,10 @@ def _loaded_catalog_entry( return loaded_catalog().get(catalog_key, MappingProxyType({})) +def _param_keys_to_remove(patch: updateDeployment) -> tuple[str, ...]: + return patch.litellm_params_to_remove if isinstance(patch, PatchModelRequest) else () + + def update_db_model( db_model: Deployment, updated_patch: updateDeployment, @@ -1077,7 +1102,8 @@ def update_db_model( if updated_patch.model_info is not None: _raise_if_ptu_cost_attribution_disabled(updated_patch.model_info.model_dump(exclude_none=True)) merged_model_name: Final = updated_patch.model_name or db_model.model_name - merged_litellm_params: Final = db_model.litellm_params.model_dump(exclude_none=True) + stored_litellm_params: Final = db_model.litellm_params.model_dump(exclude_none=True, exclude_unset=True) + merged_litellm_params: Final = dict(stored_litellm_params) stored_model_info: Final = _dump_without_none(db_model.model_info) echoed_pricing: Final = echoed_cost_map_pricing_fields(stored_model_info) merged_model_info: Final[dict[str, object]] = { @@ -1093,7 +1119,7 @@ def update_db_model( if k == "complexity_router_config" else encrypt_value_helper(v) ) - for k, v in updated_patch.litellm_params.model_dump(exclude_none=True).items() + for k, v in updated_patch.litellm_params.model_dump(exclude_none=True, exclude_unset=True).items() } merged_litellm_params.update(encrypted_params) @@ -1144,11 +1170,17 @@ def update_db_model( for field in _explicitly_cleared_ptu_fields(updated_patch.model_info): merged_model_info.pop(field, None) + for field in _param_keys_to_remove(updated_patch): + merged_litellm_params.pop(field, None) + if is_server_derived_pricing_key(field): + merged_model_info.pop(field, None) + _validate_ptu_model_info(merged_model_info) ptu_pricing, ptu_released = _ptu_pricing_delta( stored_model_info=db_model.model_info.model_dump(exclude_none=True) if db_model.model_info else _EMPTY_MODEL_INFO, + stored_litellm_params=stored_litellm_params, model_info=merged_model_info, litellm_params=merged_litellm_params, patch=updated_patch, @@ -1255,7 +1287,7 @@ async def get_kubernetes_pods( ) async def patch_model( model_id: str, # Get model_id from path parameter - patch_data: updateDeployment, # Create a specific schema for PATCH operations + patch_data: PatchModelRequest, user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth), ): """ @@ -1319,18 +1351,34 @@ async def patch_model( param=None, ) + removals: Final = _param_keys_to_remove(patch_data) + incoming_params: Final = ( + updateLiteLLMParams.model_validate( + { + **(patch_data.litellm_params.model_dump(exclude_unset=True) if patch_data.litellm_params else {}), + **dict.fromkeys(removals), + } + ) + if removals + else patch_data.litellm_params + ) + remaining_params: Final = db_model.litellm_params.model_copy(update=dict.fromkeys(removals)) write_authorization: Final = await ModelManagementAuthChecks.can_user_make_model_call( model_params=db_model, user_api_key_dict=user_api_key_dict, prisma_client=prisma_client, premium_user=premium_user, - incoming_params=submitted_litellm_params(patch_data.litellm_params), + incoming_params=submitted_litellm_params(incoming_params), member_operation="update", incoming_model_params=patch_data, ) member_write: Final = write_authorization if isinstance(write_authorization, MemberAutoRouterWrite) else None - member_marker: Final = _member_auto_router_marker_for_update( - incoming_params=patch_data.litellm_params, existing=db_model, member_write=member_write + member_marker: Final = ( + False + if db_model.model_info.member_auto_router and STRATEGY_ROUTER_PARAM_FIELDS.intersection(removals) + else _member_auto_router_marker_for_update( + incoming_params=incoming_params, existing=db_model, member_write=member_write + ) ) marker_info: Final = ( ModelInfo(id=db_model.model_info.id) @@ -1367,27 +1415,26 @@ async def patch_model( ) ModelManagementAuthChecks.can_user_attach_credential( - litellm_params=patch_data.litellm_params, + litellm_params=incoming_params, user_api_key_dict=user_api_key_dict, existing_litellm_params=db_model.litellm_params, null_detaches=True, ) - await _raise_on_invalid_credential_name(patch_data.litellm_params, db_model.litellm_params, prisma_client) + await _raise_on_invalid_credential_name(incoming_params, db_model.litellm_params, prisma_client) ModelManagementAuthChecks.can_user_set_aws_session_tags( - litellm_params=patch_data.litellm_params, + litellm_params=incoming_params, user_api_key_dict=user_api_key_dict, existing_litellm_params=db_model.litellm_params, + null_detaches="aws_session_tags" in removals, ) _raise_on_strategy_router_write_violation( - incoming_params=patch_data.litellm_params, - existing_params=db_model.litellm_params, + incoming_params=incoming_params, + existing_params=remaining_params, ) - effective_params: Final = _effective_complexity_router_params( - patch_data.litellm_params, db_model.litellm_params - ) + effective_params: Final = _effective_complexity_router_params(incoming_params, remaining_params) requested_model_name: Final = patch_data.model_name stored_model_name: str | None = None @@ -1818,20 +1865,20 @@ async def _update_team_model_in_db( db_model=db_model, ) - # Ensure model_info exists and set team_public_model_name - if patch_data.model_info is None: - from litellm.types.router import ModelInfo - - patch_data.model_info = ModelInfo() - patch_data.model_info.team_public_model_name = public_model_name - # Check if team assignment is new or changed db_team_id: Final = db_model.model_info.team_id if db_model.model_info else None is_new_team_assignment: Final = db_team_id != patch_team_id # Team rows keep their internal UUID-based model_name; the public name lives in model_info - patch_data.model_name = f"model_name_{patch_team_id}_{uuid.uuid4()}" if is_new_team_assignment else None - row: Final = await write_row(update_db_model(db_model=db_model, updated_patch=patch_data)) + team_patch: Final = patch_data.model_copy( + update={ + "model_name": f"model_name_{patch_team_id}_{uuid.uuid4()}" if is_new_team_assignment else None, + "model_info": (patch_data.model_info or ModelInfo()).model_copy( + update={"team_public_model_name": public_model_name} + ), + } + ) + row: Final = await write_row(update_db_model(db_model=db_model, updated_patch=team_patch)) if is_new_team_assignment: await _setup_new_team_model_assignment( @@ -2228,14 +2275,16 @@ class ModelManagementAuthChecks: litellm_params: GenericLiteLLMParams | None, user_api_key_dict: UserAPIKeyAuth, existing_litellm_params: GenericLiteLLMParams | None = None, + *, + null_detaches: bool = False, ) -> Literal[True]: - if litellm_params is None or litellm_params.aws_session_tags is None: + if litellm_params is None or (litellm_params.aws_session_tags is None and not null_detaches): return True if user_api_key_dict.user_role == LitellmUserRoles.PROXY_ADMIN: return True existing_tags: Final = existing_litellm_params.aws_session_tags if existing_litellm_params is not None else None if existing_tags is not None and _canonical_session_tags(existing_tags) == _canonical_session_tags( - litellm_params.aws_session_tags + litellm_params.aws_session_tags or () ): return True raise ProxyException( @@ -3217,12 +3266,13 @@ async def update_useful_links( ) -def _validated_labeled_tiers( - tier_labels: dict[ComplexityTier, str], # mutable-ok: Pydantic materializes JSON object fields as dicts -) -> tuple[tuple[ComplexityTier, str], ...]: +_DECODED_JSON: Final = TypeAdapter(object) + + +def _validated_labeled_tiers(tier_labels: object) -> tuple[tuple[ComplexityTier, str], ...]: """Validate tier labels once for both prompt-preview transports.""" try: - return ComplexityRouterConfig(tier_labels=tier_labels).labeled_tiers() + return ComplexityRouterConfig.model_validate({"tier_labels": tier_labels}).labeled_tiers() except (TypeError, ValidationError) as e: raise ProxyException( message=f"tier_labels must be a JSON object of tier name to display name: {e}", @@ -3237,7 +3287,7 @@ def _labeled_tiers_from_query(tier_labels: str | None) -> tuple[tuple[Complexity if not tier_labels: return None try: - parsed: Final = json.loads(tier_labels) + parsed: Final = _DECODED_JSON.validate_python(json.loads(tier_labels)) except JSONDecodeError as e: raise ProxyException( message=f"tier_labels must be a JSON object of tier name to display name: {e}", diff --git a/litellm/proxy/management_endpoints/organization_endpoints.py b/litellm/proxy/management_endpoints/organization_endpoints.py index d7a44cdd0b8..e1d19d8efae 100644 --- a/litellm/proxy/management_endpoints/organization_endpoints.py +++ b/litellm/proxy/management_endpoints/organization_endpoints.py @@ -504,9 +504,8 @@ async def new_organization( _budget: Final = await _table(BudgetRepository(prisma_client)).create( data={ - **new_budget, + **build_budget_write_data(new_budget, user_api_key_dict.user_id or litellm_proxy_admin_name), "created_by": user_api_key_dict.user_id or litellm_proxy_admin_name, - "updated_by": user_api_key_dict.user_id or litellm_proxy_admin_name, } ) diff --git a/litellm/proxy/management_endpoints/router_settings_endpoints.py b/litellm/proxy/management_endpoints/router_settings_endpoints.py index 64566221d4d..1f4ca442d20 100644 --- a/litellm/proxy/management_endpoints/router_settings_endpoints.py +++ b/litellm/proxy/management_endpoints/router_settings_endpoints.py @@ -71,10 +71,11 @@ def _get_routing_strategies_from_router_class() -> list[str]: # Get the routing_strategy parameter routing_strategy_param: Final = sig.parameters.get("routing_strategy") + routing_strategy_annotation: Final[object] = routing_strategy_param.annotation if routing_strategy_param else None - if routing_strategy_param and routing_strategy_param.annotation: + if routing_strategy_param and routing_strategy_annotation: # Extract Literal values using get_args - literal_values: Final = get_args(routing_strategy_param.annotation) + literal_values: Final = get_args(routing_strategy_annotation) if literal_values: return list(literal_values) diff --git a/litellm/proxy/management_endpoints/sso/saml_sso.py b/litellm/proxy/management_endpoints/sso/saml_sso.py index ba265acfe4a..d9fe9fcf8f4 100644 --- a/litellm/proxy/management_endpoints/sso/saml_sso.py +++ b/litellm/proxy/management_endpoints/sso/saml_sso.py @@ -38,13 +38,13 @@ from pydantic import ValidationError from litellm._internal_context import with_service_target from litellm._logging import verbose_proxy_logger from litellm.caching.dual_cache import DualCache -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( - SSOIdentityAssertion, - assertion_from_saml_login, -) from litellm.proxy.auth.ip_address_utils import IPAddressUtils from litellm.proxy.management_endpoints.sso_helper_utils import SSO_SESSIONS_TARGET from litellm.proxy.management_endpoints.types import CustomOpenID, get_litellm_user_role +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( + SSOIdentityAssertion, + assertion_from_saml_login, +) from litellm.proxy.utils import get_custom_url try: diff --git a/litellm/proxy/management_endpoints/team_endpoints.py b/litellm/proxy/management_endpoints/team_endpoints.py index c7adae2ce8d..1fa18e9b2b8 100644 --- a/litellm/proxy/management_endpoints/team_endpoints.py +++ b/litellm/proxy/management_endpoints/team_endpoints.py @@ -52,6 +52,7 @@ from litellm.proxy._types import ( CommonProxyErrors, DeleteTeamRequest, LiteLLM_AuditLogs, + LiteLLM_BudgetTable, LiteLLM_DeletedTeamTable, Litellm_EntityType, LiteLLM_ManagementEndpoint_MetadataFields, @@ -114,6 +115,7 @@ from litellm.proxy.auth.auth_checks import ( # noqa: F401 # legacy module expo get_user_object, invalidate_team_member_spend_state, jwt_key_mapping_cache_key, + resolve_effective_team_member_budget, ) from litellm.proxy.auth.auth_utils import ( enforce_batch_limits_are_admin_only, @@ -244,6 +246,7 @@ from litellm.types.proxy.management_endpoints.team_endpoints import ( BulkUpdateTeamMemberPermissionsResponse, GetTeamMemberPermissionsResponse, TeamIdSearchMatch, + TeamListCallerMembership, TeamListItem, TeamListResponse, TeamMemberAddResult, @@ -254,6 +257,7 @@ from litellm.types.proxy.management_endpoints.team_endpoints import ( UpdateTeamMemberPermissionsRequest, ) from litellm.types.utils import BudgetConfig, GenericBudgetConfigType +from litellm.utils import get_utc_datetime if TYPE_CHECKING: from prisma import Prisma @@ -302,6 +306,34 @@ class _TeamIdRow(Protocol): def team_id(self) -> str: ... +class _TeamListBudgetRow(Protocol): + @property + def budget_id(self) -> str: ... + + @property + def budget_reset_at(self) -> datetime | None: ... + + @property + def max_budget(self) -> float | None: ... + + @property + def temp_budget_expiry(self) -> datetime | None: ... + + @property + def temp_budget_increase(self) -> float | None: ... + + +class _TeamListMembershipRow(Protocol): + @property + def team_id(self) -> str: ... + + @property + def spend(self) -> float | None: ... + + @property + def litellm_budget_table(self) -> _TeamListBudgetRow | None: ... + + class _CacheableTeamRow(_TeamIdRow, _ModelDumpRow, Protocol): ... @@ -479,6 +511,14 @@ def _team_db(prisma_client: PrismaClient | None) -> "TableActions[prisma_models. return TeamRepository(prisma_client).table +class _ExecuteRaw(Protocol): + async def __call__(self, query: str, *args: object) -> int: ... + + +def _execute_raw(prisma_client: PrismaClient) -> _ExecuteRaw: + return prisma_client.db.execute_raw + + def _team_tx_db(tx: "Prisma") -> "TableActions[prisma_models.LiteLLM_TeamTable]": return cast( # cast-ok: generated actions type Json columns as str; TableActions widens inputs to Mapping "TableActions[prisma_models.LiteLLM_TeamTable]", tx.litellm_teamtable @@ -973,7 +1013,7 @@ async def get_all_team_memberships( returned_tm: Final[list[LiteLLM_TeamMembership]] = [] for tm in team_memberships: - returned_tm.append(LiteLLM_TeamMembership.model_validate(tm.model_dump())) + returned_tm.append(with_total_spend_floor(LiteLLM_TeamMembership.model_validate(tm.model_dump()))) return returned_tm @@ -3092,7 +3132,7 @@ async def _process_team_members( # Resolve allowed_models: explicit request value, or fall back to team's default_team_member_models member_allowed_models = data.allowed_models - team_default_member_models: Final = getattr(complete_team_data, "default_team_member_models", None) + team_default_member_models: Final = complete_team_data.default_team_member_models if member_allowed_models is None and team_default_member_models: member_allowed_models = team_default_member_models @@ -4162,6 +4202,23 @@ def _check_not_resetting_own_spend(user_id: str, user_api_key_dict: UserAPIKeyAu _raise_reset_spend_error(status.HTTP_403_FORBIDDEN, "Cannot reset your own spend. Ask a proxy admin.") +# One statement so the validated spend cannot go stale between the read and the write: the WHERE re-checks +# reset_to <= spend, and total_spend is floored at spend before spend drops so the history survives the reset. +_RESET_TEAM_MEMBER_SPEND_SQL: Final = """ +UPDATE "LiteLLM_TeamMembership" +SET total_spend = GREATEST(total_spend, spend), spend = $3::float8 +WHERE user_id = $1 AND team_id = $2 AND spend >= $3::float8 +""" + + +def with_total_spend_floor(membership: LiteLLM_TeamMembership) -> LiteLLM_TeamMembership: + """Rows written before total_spend existed (migration 20260421135425) hold their history only in spend.""" + spend: Final = membership.spend or 0.0 + if (membership.total_spend or 0.0) >= spend: + return membership + return membership.model_copy(update={"total_spend": spend}) + + def _raise_reset_spend_error(status_code: int, message: str) -> NoReturn: detail: Final = {"error": message} raise HTTPException(status_code=status_code, detail=detail) @@ -4246,10 +4303,12 @@ async def reset_team_member_spend_fn( current_spend: Final = membership.spend or 0.0 reset_to: Final = _validate_team_member_reset_spend_value(data.reset_to, membership) - await _team_membership_db(prisma_client).update( - where=membership_where, - data={"spend": reset_to}, - ) + reset_rows: Final = await _execute_raw(prisma_client)(_RESET_TEAM_MEMBER_SPEND_SQL, user_id, team_id, reset_to) + if reset_rows == 0: + _raise_reset_spend_error( + status.HTTP_409_CONFLICT, + f"Member spend changed since it was read; reset_to ({reset_to}) must be <= current spend. Retry.", + ) await invalidate_team_member_spend_state( user_id=user_id, @@ -5459,16 +5518,15 @@ async def team_member_me( user_api_key_cache=user_api_key_cache, ) - caller_user_email: Final = user_api_key_dict.user_email - member_role: str | None = None - for m in team_table.members_with_roles: - # Match by user_id when present, else fall back to email — members - # added by email may have user_id=None on the stored entry. - if (m.user_id is not None and m.user_id == caller_user_id) or ( - m.user_email is not None and caller_user_email is not None and m.user_email == caller_user_email - ): - member_role = m.role - break + caller_identity: Final = _TeamListCallerIdentity( + user_id=caller_user_id, + user_email=user_api_key_dict.user_email, + ) + matched_member: Final = next( + (member for member in team_table.members_with_roles if _team_member_matches_caller(member, caller_identity)), + None, + ) + member_role: Final = matched_member.role if matched_member is not None else None if member_role is None: # Caller is not a member of this team. Even proxy admins get 404 here — @@ -5509,16 +5567,17 @@ async def team_member_me( litellm_budget_table=None, ) + floored: Final = with_total_spend_floor(membership) return TeamMemberInfoResponse( user_id=caller_user_id, team_id=team_id, team_alias=team_table.team_alias, role=member_role, user_email=user_email, - spend=membership.spend, - total_spend=membership.total_spend, - budget_id=membership.budget_id, - litellm_budget_table=membership.litellm_budget_table, + spend=floored.spend, + total_spend=floored.total_spend, + budget_id=floored.budget_id, + litellm_budget_table=floored.litellm_budget_table, ) @@ -5878,11 +5937,16 @@ def _convert_teams_to_response_models( members_count = len(members_with_roles) keys_count = counts.get(team_dict.get("team_id") or "", 0) team_list.append( - TeamListItem( - **team_dict, - members_count=members_count, - keys_count=keys_count, - access_group_skill_names=None, + TeamListItem.model_validate( + cast( # cast-ok: TeamListItem validates the Prisma model dump + object, + { + **team_dict, + "members_count": members_count, + "keys_count": keys_count, + "access_group_skill_names": None, + }, + ) ) ) return team_list @@ -5913,6 +5977,137 @@ async def _get_keys_count_by_team( return {row["team_id"]: row.get("_count", {}).get("team_id", 0) for row in grouped if row.get("team_id")} +def _team_list_budget_model(budget_row: _TeamListBudgetRow | None) -> LiteLLM_BudgetTable | None: + if budget_row is None: + return None + return LiteLLM_BudgetTable( + max_budget=budget_row.max_budget, + temp_budget_expiry=budget_row.temp_budget_expiry, + temp_budget_increase=budget_row.temp_budget_increase, + ) + + +@dataclass(frozen=True, slots=True) +class _TeamListCallerIdentity: + user_id: str | None + user_email: str | None + + +def _team_member_matches_caller(member: Member, caller_identity: _TeamListCallerIdentity) -> bool: + return (member.user_id is not None and member.user_id == caller_identity.user_id) or ( + member.user_email is not None + and caller_identity.user_email is not None + and member.user_email == caller_identity.user_email + ) + + +def _caller_in_roster(team: TeamListItem, caller_identity: _TeamListCallerIdentity) -> bool: + return any(_team_member_matches_caller(member, caller_identity) for member in team.members_with_roles) + + +def _team_member_default_budget_id( + team: TeamListItem, + caller_identity: _TeamListCallerIdentity, + memberships_by_team: Mapping[str, _TeamListMembershipRow], +) -> str | None: + membership_row: Final = memberships_by_team.get(team.team_id) + if membership_row is None and not _caller_in_roster(team, caller_identity): + return None + member_budget: Final = _team_list_budget_model( + membership_row.litellm_budget_table if membership_row is not None else None + ) + if member_budget is not None and member_budget.max_budget is not None: + return None + metadata: Final = cast( # cast-ok: team metadata is stored as a JSON object + "dict[str, object] | None", team.metadata + ) + if metadata is None: + return None + budget_id: Final = metadata.get("team_member_budget_id") + return budget_id if isinstance(budget_id, str) else None + + +def _team_list_caller_membership( + team: TeamListItem, + caller_identity: _TeamListCallerIdentity, + memberships_by_team: Mapping[str, _TeamListMembershipRow], + default_budget_id: str | None, + budgets_by_id: Mapping[str, _TeamListBudgetRow], + now: datetime, +) -> TeamListCallerMembership | None: + membership_row: Final = memberships_by_team.get(team.team_id) + if membership_row is None and not _caller_in_roster(team, caller_identity): + return None + member_budget_row: Final = membership_row.litellm_budget_table if membership_row is not None else None + member_budget: Final = _team_list_budget_model(member_budget_row) + default_budget_row: Final = budgets_by_id.get(default_budget_id) if default_budget_id is not None else None + team_default_budget: Final = _team_list_budget_model(default_budget_row) + max_budget: Final = resolve_effective_team_member_budget( + member_budget=member_budget, + team_default_budget=team_default_budget, + now=now, + ) + budget_reset_at: Final = ( + member_budget_row.budget_reset_at if member_budget_row is not None and max_budget is not None else None + ) + return TeamListCallerMembership( + spend=(membership_row.spend if membership_row is not None else 0.0) or 0.0, + max_budget=max_budget, + budget_reset_at=budget_reset_at, + ) + + +async def _enrich_team_list_with_caller_membership( + prisma_client: PrismaClient, + teams: Sequence[TeamListItem], + caller_identity: _TeamListCallerIdentity, + now: datetime, +) -> tuple[TeamListItem, ...]: + caller_user_id: Final = caller_identity.user_id + if caller_user_id is None: + return tuple(team.model_copy(update={"caller_membership": None}) for team in teams) + if not teams: + return () + + page_team_ids: Final = tuple(team.team_id for team in teams) + membership_rows: Final[Sequence[_TeamListMembershipRow]] = await _team_membership_db(prisma_client).find_many( + # bounded-ok: page_team_ids is capped at 100 teams by list_team_v2 + where={"team_id": {"in": page_team_ids}, "user_id": caller_user_id}, + include={"litellm_budget_table": True}, + ) + memberships_by_team: Final = {row.team_id: row for row in membership_rows} + default_budget_id_by_team: Final = MappingProxyType( + {team.team_id: _team_member_default_budget_id(team, caller_identity, memberships_by_team) for team in teams} + ) + default_budget_ids: Final = tuple( + dict.fromkeys(budget_id for budget_id in default_budget_id_by_team.values() if budget_id is not None) + ) + default_budget_rows: Final[Sequence[_TeamListBudgetRow]] = ( + await _budget_db(prisma_client).find_many( + # bounded-ok: default_budget_ids is derived from this page of at most 100 teams + where={"budget_id": {"in": default_budget_ids}}, + ) + if default_budget_ids + else () + ) + budgets_by_id: Final = {row.budget_id: row for row in default_budget_rows} + return tuple( + team.model_copy( + update={ + "caller_membership": _team_list_caller_membership( + team=team, + caller_identity=caller_identity, + memberships_by_team=memberships_by_team, + default_budget_id=default_budget_id_by_team.get(team.team_id), + budgets_by_id=budgets_by_id, + now=now, + ) + } + ) + for team in teams + ) + + async def _enforce_list_team_v2_access( user_api_key_dict: UserAPIKeyAuth, user_id: str | None, @@ -6026,7 +6221,7 @@ async def list_team_v2( sort_order: str = fastapi.Query(default="asc", description="Sort order ('asc' or 'desc')"), status: str | None = fastapi.Query(default=None, description="Filter by status (e.g. 'deleted')"), user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth), -): +) -> TeamListResponse: """ Get a paginated list of teams with filtering and sorting options. @@ -6101,13 +6296,13 @@ async def list_team_v2( ) if where_conditions is None: - return { - "teams": [], - "total": 0, - "page": page, - "page_size": page_size, - "total_pages": 0, - } + return TeamListResponse( + teams=[], + total=0, + page=page, + page_size=page_size, + total_pages=0, + ) from litellm.proxy.management_helpers.team_list_sorting import ( COMPUTED_TEAM_SORTS, @@ -6219,13 +6414,27 @@ async def list_team_v2( team_groups, tuple(ag_id for ag_id in (team_item.access_group_ids or []) if ag_id not in ag_lookup) ) - return { - "teams": team_list, - "total": total_count, - "page": page, - "page_size": page_size, - "total_pages": total_pages, - } + caller_identity: Final = _TeamListCallerIdentity( + user_id=user_api_key_dict.user_id, + user_email=user_api_key_dict.user_email, + ) + team_list_with_caller_membership: Final = ( + await _enrich_team_list_with_caller_membership( + prisma_client=prisma_client, + teams=tuple(team for team in team_list if isinstance(team, TeamListItem)), + caller_identity=caller_identity, + now=get_utc_datetime(), + ) + if not use_deleted_table and team_list + else team_list + ) + return TeamListResponse( + teams=list(team_list_with_caller_membership), + total=total_count, + page=page, + page_size=page_size, + total_pages=total_pages, + ) async def _authorize_and_filter_teams( @@ -6572,7 +6781,7 @@ async def append_team_models( # When the team currently has models=[] (unrestricted access), the # CASE expression inserts the 'all-proxy-models' sentinel first. models_to_add: Final = list(data.models) - await prisma_client.db.execute_raw( + await _execute_raw(prisma_client)( 'UPDATE "LiteLLM_TeamTable" ' "SET models = (" " SELECT ARRAY(SELECT DISTINCT unnest(" diff --git a/litellm/proxy/management_endpoints/ui_sso.py b/litellm/proxy/management_endpoints/ui_sso.py index fd5eb672811..22c4f27d94a 100644 --- a/litellm/proxy/management_endpoints/ui_sso.py +++ b/litellm/proxy/management_endpoints/ui_sso.py @@ -72,17 +72,6 @@ from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, httpxSpecialProvider, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.login_assertion_exchange import ( - exchange_login_assertion_if_configured, -) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( - GOOGLE_REFRESH_TOKEN_PARAMS, - MICROSOFT_REFRESH_TOKEN_SCOPE, - SSOIdentityAssertion, - assertion_from_sso_login, - ema_assertion_retention_enabled, - retain_sso_identity_assertion_for_ema, -) from litellm.proxy._types import ( CommonProxyErrors, LiteLLM_UserTable, @@ -143,6 +132,17 @@ from litellm.proxy.management_endpoints.types import ( get_litellm_user_role, is_valid_litellm_user_role, ) +from litellm.proxy.mcp_server.outbound_credentials.login_assertion_exchange import ( + exchange_login_assertion_if_configured, +) +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( + GOOGLE_REFRESH_TOKEN_PARAMS, + MICROSOFT_REFRESH_TOKEN_SCOPE, + SSOIdentityAssertion, + assertion_from_sso_login, + ema_assertion_retention_enabled, + retain_sso_identity_assertion_for_ema, +) from litellm.proxy.utils import ( PrismaClient, ProxyLogging, @@ -278,6 +278,12 @@ class _CustomSsoCall(Protocol): async def __call__(self, sso_response: object) -> SSOUserDefinedValues | None: ... +def _configured_custom_sso() -> _CustomSsoCall | None: + from litellm.proxy.proxy_server import user_custom_sso + + return user_custom_sso + + class _ServicePrincipalAssignment(Protocol): def get(self, key: str) -> str: ... @@ -1051,6 +1057,11 @@ class _UserinfoFallbackCapableSSO(Protocol): ) -> CustomOpenID | None: ... +class _GenericSSOClient(_UserinfoFallbackCapableSSO, Protocol): + @property + def refresh_token(self) -> str | None: ... + + async def _verify_generic_sso_or_fall_back_to_id_token( generic_sso: _UserinfoFallbackCapableSSO, request: Request, @@ -1578,7 +1589,7 @@ async def get_generic_sso_response( team_mappings: Final = await _setup_team_mappings() generic_include_token_claims: Final = os.getenv("GENERIC_INCLUDE_TOKEN_CLAIMS", "false").lower() == "true" - def response_convertor(response: Mapping[str, object], httpx_session: object): + def response_convertor(response: Mapping[str, object], httpx_session: object) -> CustomOpenID: nonlocal received_response # return for user debugging response_id_token: Final = response.get("id_token") response_access_token: Final = response.get("access_token") @@ -1613,7 +1624,7 @@ async def get_generic_sso_response( discovery_document=discovery, response_convertor=response_convertor, ) - generic_sso: Final = SSOProvider( + generic_sso: Final[_GenericSSOClient] = SSOProvider( client_id=generic_client_id, client_secret=generic_client_secret, redirect_uri=redirect_url, @@ -1712,9 +1723,7 @@ async def get_generic_sso_response( access_token_str: str | None = combined_response.get("access_token") else: result = await _verify_generic_sso_or_fall_back_to_id_token( - generic_sso=cast( # cast-ok: fastapi-sso builds the provider class dynamically via create_provider - _UserinfoFallbackCapableSSO, generic_sso - ), + generic_sso=generic_sso, request=request, token_exchange_params=token_exchange_params, additional_headers=additional_generic_sso_headers_dict, @@ -2350,9 +2359,7 @@ async def _build_cli_sso_user_defined_values( result: OpenID | dict, parsed_openid_result: ParsedOpenIDResult, ) -> SSOUserDefinedValues | None: - from litellm.proxy.proxy_server import user_custom_sso - - custom_sso_handler: Final[_CustomSsoCall | None] = user_custom_sso + custom_sso_handler: Final = _configured_custom_sso() user_id: Final = parsed_openid_result.get("user_id") if custom_sso_handler is not None: if inspect.iscoroutinefunction(custom_sso_handler): @@ -2438,10 +2445,8 @@ async def _complete_cli_sso_callback_session( ): from fastapi.responses import HTMLResponse - from litellm.proxy.proxy_server import user_custom_sso - user_id: Final = parsed_openid_result.get("user_id") - if user_custom_sso is None: + if _configured_custom_sso() is None: _require_sso_user_id(user_id) user_email: Final = parsed_openid_result.get("user_email") user_info: Final = await get_user_info_from_db( @@ -3807,7 +3812,6 @@ class SSOAuthenticationHandler: proxy_logging_obj, redis_usage_cache, user_api_key_cache, - user_custom_sso, ) from litellm.proxy.utils import get_prisma_client_or_throw from litellm.types.proxy.ui_sso import ReturnedUITokenObject @@ -3832,7 +3836,7 @@ class SSOAuthenticationHandler: # But if it is, we want their models preferences user_defined_values: SSOUserDefinedValues | None = None - custom_sso_handler: Final[_CustomSsoCall | None] = user_custom_sso + custom_sso_handler: Final = _configured_custom_sso() if custom_sso_handler is not None: if inspect.iscoroutinefunction(custom_sso_handler): user_defined_values = await custom_sso_handler(result) diff --git a/litellm/proxy/management_helpers/object_permission_utils.py b/litellm/proxy/management_helpers/object_permission_utils.py index 3468396c6f6..a719a5c67d4 100644 --- a/litellm/proxy/management_helpers/object_permission_utils.py +++ b/litellm/proxy/management_helpers/object_permission_utils.py @@ -300,7 +300,7 @@ async def _resolve_mcp_server_identifiers_to_ids( if not identifiers: return {} - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -310,7 +310,7 @@ async def _resolve_mcp_server_identifiers_to_ids( identifiers=identifiers, prisma_client=prisma_client, ): - server_id = getattr(server, "server_id", None) + server_id = server.server_id if not server_id: continue for identifier in identifiers: @@ -450,7 +450,7 @@ async def _resolve_team_allowed_mcp_servers( - Servers from mcp_access_groups - Server IDs referenced in mcp_tool_permissions keys """ - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -475,7 +475,7 @@ async def _resolve_team_allowed_mcp_servers( def get_allow_all_keys_server_ids() -> set[str]: """Return the set of MCP server IDs marked with allow_all_keys=True.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -487,7 +487,7 @@ _get_allow_all_keys_server_ids: Final = get_allow_all_keys_server_ids def _get_all_mcp_server_ids() -> set[str]: """Return every MCP server id registered on the proxy (config + DB union).""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) diff --git a/litellm/proxy/_experimental/mcp_server/AGENTS.md b/litellm/proxy/mcp_server/AGENTS.md similarity index 98% rename from litellm/proxy/_experimental/mcp_server/AGENTS.md rename to litellm/proxy/mcp_server/AGENTS.md index 8c53216f77a..25150c11f1d 100644 --- a/litellm/proxy/_experimental/mcp_server/AGENTS.md +++ b/litellm/proxy/mcp_server/AGENTS.md @@ -12,7 +12,7 @@ wiring must change with it. Respect the current package boundaries: ```text -litellm/proxy/_experimental/mcp_server/ +litellm/proxy/mcp_server/ AGENTS.md server.py # ASGI/MCP route handling, sessions, tool calls [PR7: 7-arm only — move BYOK/OAuth pre-fetch into resolver] mcp_server_manager.py # upstream server registry, clients, tool routing [PR7: _create_mcp_client swaps resolve_mcp_auth -> resolve_credentials] @@ -89,7 +89,7 @@ module materially harder to understand. ## Tests -Mirror this package under `tests/unit/proxy/_experimental/mcp_server/`. +Mirror this package under `tests/unit/proxy/mcp_server/`. For regressions, extend the existing mapped test file instead of creating a new one. Use subdirectories that match the implementation path, such as `auth/test_token_endpoint_auth.py` for `auth/token_endpoint_auth.py` and diff --git a/litellm/proxy/_experimental/mcp_server/README.md b/litellm/proxy/mcp_server/README.md similarity index 100% rename from litellm/proxy/_experimental/mcp_server/README.md rename to litellm/proxy/mcp_server/README.md diff --git a/litellm/proxy/_experimental/mcp_server/auth/litellm_auth_handler.py b/litellm/proxy/mcp_server/auth/litellm_auth_handler.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/auth/litellm_auth_handler.py rename to litellm/proxy/mcp_server/auth/litellm_auth_handler.py diff --git a/litellm/proxy/_experimental/mcp_server/auth/managed_agent_access.py b/litellm/proxy/mcp_server/auth/managed_agent_access.py similarity index 89% rename from litellm/proxy/_experimental/mcp_server/auth/managed_agent_access.py rename to litellm/proxy/mcp_server/auth/managed_agent_access.py index 096b7eb3c77..a01db0db6d8 100644 --- a/litellm/proxy/_experimental/mcp_server/auth/managed_agent_access.py +++ b/litellm/proxy/mcp_server/auth/managed_agent_access.py @@ -8,15 +8,15 @@ from litellm.types.proxy.agent_identity import AgentIdentityFailure async def _delegated_resource_subject(user_id: str) -> UserAPIKeyAuth: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler human: Final = await MCPRequestHandler.reload_admitted_user(user_id, requires_fresh_policy=True) return human.model_copy(update=MappingProxyType({"mcp_explicit_grants_only": True})) async def managed_agent_servers(auth: UserAPIKeyAuth) -> tuple[str, ...]: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager agent: Final = auth.managed_agent_policy if agent is None: @@ -49,7 +49,7 @@ async def managed_agent_servers(auth: UserAPIKeyAuth) -> tuple[str, ...]: async def managed_agent_tools(server_id: str, auth: UserAPIKeyAuth) -> list[str] | None: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler if server_id not in await managed_agent_servers(auth): return [] diff --git a/litellm/proxy/_experimental/mcp_server/auth/token_endpoint_auth.py b/litellm/proxy/mcp_server/auth/token_endpoint_auth.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/auth/token_endpoint_auth.py rename to litellm/proxy/mcp_server/auth/token_endpoint_auth.py diff --git a/litellm/proxy/_experimental/mcp_server/auth/user_api_key_auth_mcp.py b/litellm/proxy/mcp_server/auth/user_api_key_auth_mcp.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/auth/user_api_key_auth_mcp.py rename to litellm/proxy/mcp_server/auth/user_api_key_auth_mcp.py index 53b56c7b31d..cc7080738d0 100644 --- a/litellm/proxy/_experimental/mcp_server/auth/user_api_key_auth_mcp.py +++ b/litellm/proxy/mcp_server/auth/user_api_key_auth_mcp.py @@ -21,32 +21,7 @@ import litellm from litellm._internal_context import with_service_target from litellm._logging import verbose_logger from litellm.constants import MCP_ALL_TOOLS_WILDCARD, MCP_PEEKED_BODY_SCOPE_KEY -from litellm.experimental_mcp_client.client import strip_auth_scheme -from litellm.proxy._experimental.mcp_server.catalog import global_manager -from litellm.proxy._experimental.mcp_server.oauth_utils import ( - get_passthrough_resource_metadata_url, - get_passthrough_www_authenticate, - get_request_base_url, - well_known_root_suffix, -) -from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( - BridgeEnvelopeAdmitted, - BridgeEnvelopeInvalid, - NotBridgeEnvelope, - envelope_keys_from_master_key, - is_bridge_envelope_shaped, - resolve_bridge_envelope, -) -from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( - EnvelopeIdentity, -) -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credentials import ( - is_session_bearer_shaped, -) -from litellm.proxy._experimental.mcp_server.utils import ( - asgi_scope_fields, - strip_known_server_prefix, -) +from litellm.mcp_client.client import strip_auth_scheme from litellm.proxy._types import ( UI_TEAM_ID, LiteLLM_AccessGroupTable, @@ -86,6 +61,32 @@ from litellm.proxy.common_utils.user_api_key_cache import ( get_management_object_ttl, user_object_permission_id_cache_key, ) +from litellm.proxy.mcp_server.catalog import global_manager +from litellm.proxy.mcp_server.oauth_utils import ( + get_passthrough_resource_metadata_url, + get_passthrough_www_authenticate, + get_request_base_url, + get_route_relative_request_path, + well_known_root_suffix, +) +from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( + BridgeEnvelopeAdmitted, + BridgeEnvelopeInvalid, + NotBridgeEnvelope, + envelope_keys_from_master_key, + is_bridge_envelope_shaped, + resolve_bridge_envelope, +) +from litellm.proxy.mcp_server.outbound_credentials.envelope import ( + EnvelopeIdentity, +) +from litellm.proxy.mcp_server.outbound_credentials.session_credentials import ( + is_session_bearer_shaped, +) +from litellm.proxy.mcp_server.utils import ( + asgi_scope_fields, + strip_known_server_prefix, +) from litellm.repositories.table_repositories import ( AgentsRepository, MCPServerRepository, @@ -99,6 +100,7 @@ if TYPE_CHECKING: _EMPTY_TOOLSET_GRANTS: Final[Mapping[str, Sequence[str]]] = MappingProxyType({}) OPTIONAL_STRING_ADAPTER: Final[TypeAdapter[str | None]] = TypeAdapter(str | None) +_CACHED_VALUE: Final = TypeAdapter(object) def _normalize_caller_admission_credential(value: str) -> str: @@ -199,7 +201,7 @@ def _is_mcp_passthrough_cold_start(mcp_servers: list[str] | None, client_ip: str cannot be resolved.""" if not mcp_servers: return False - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -214,7 +216,7 @@ def _is_legacy_delegate_cold_start(mcp_servers: list[str] | None, client_ip: str """Allow only credential-free legacy delegates to reach the route's OAuth challenge.""" if not mcp_servers: return False - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, global_mcp_server_manager, ) @@ -306,7 +308,7 @@ def _gateway_dcr_challenge_target( client_ip: str | None, ) -> str | None: """Resolve a single path target whose sign-in metadata advertises the gateway.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -326,8 +328,8 @@ def gateway_dcr_challenge_scope( ) -> str | None: if MCPRequestHandler.extract_target_server_names_from_path(route) or not mcp_servers: return None - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import gateway_server_scope - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.gateway_dcr_flow import gateway_server_scope + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -386,7 +388,7 @@ def _gateway_dcr_challenge( """The RFC 9728 challenge pointing the client at the protected-resource metadata matching the scope it requested: the per-server document (same URL spelling the request arrived on) when the single target advertises gateway-owned sign-in, - else the gateway's aggregate document. Either way the client discovers the gateway + else a gateway document containing the public resource. Either way the client discovers the gateway as its authorization server and starts the same sign-in flow. ``invalid_token`` adds the RFC 6750 error code for a request that DID @@ -396,10 +398,13 @@ def _gateway_dcr_challenge( client_ip: Final = IPAddressUtils.get_mcp_client_ip(request) target: Final = _gateway_dcr_challenge_target(route, mcp_servers, client_ip) server_scope: Final = gateway_dcr_challenge_scope(route, mcp_servers, client_ip) if target is None else None + public_path: Final = get_route_relative_request_path(request.scope).rstrip("/") + aggregate_resource: Final = public_path == "/mcp" or public_path.startswith("/mcp/") + metadata_suffix: Final = f"{well_known_root_suffix()}/mcp" if aggregate_resource else "" resource_metadata_url: Final = ( get_passthrough_resource_metadata_url(request.scope, target) if target is not None - else f"{get_request_base_url(request)}/.well-known/oauth-protected-resource{well_known_root_suffix()}/mcp" + else f"{get_request_base_url(request)}/.well-known/oauth-protected-resource{metadata_suffix}" ) error_attr: Final = 'error="invalid_token", ' if invalid_token else "" scope_attr: Final = f', scope="{server_scope}"' if server_scope is not None else "" @@ -914,7 +919,7 @@ class MCPRequestHandler: transparent proxy and the caller's ``Authorization`` is an upstream token, never a LiteLLM key. A mixed-target request keeps normal auth. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) from litellm.types.mcp import MCPAuth @@ -941,7 +946,7 @@ class MCPRequestHandler: envelope admission arm never fires for an aggregate scope or a server that did not opt into the bridge. Mirrors :meth:`_target_servers_are_true_passthrough`. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -1158,7 +1163,7 @@ class MCPRequestHandler: mint-time snapshot. Pre-DB gates (size, IP, route allowlist) run first, mirroring the standard pipeline. Fails closed with the requested scope's ``invalid_token`` challenge on an expired, tampered, foreign, or refresh token, or a missing/deactivated/policy-rejected user.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.session_credentials import ( NotSessionBearer, SessionBearerAdmitted, SessionBearerInvalid, @@ -1327,7 +1332,7 @@ class MCPRequestHandler: so each is resolved to an id via ``expand_permission_list`` before the membership check. Returns None (no descriptors) when nothing applies; a lookup failure narrows to None rather than raising, since rate limiting must not deny a request authorization already allowed.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -1368,7 +1373,7 @@ class MCPRequestHandler: if auth is None: return None - refreshed = auth.model_copy() + refreshed: Final = auth.model_copy(update={"requires_fresh_policy": True}) if (auth.mcp_admitted_user_subject or auth.is_session_token) and auth.user_id: # A session credential (``lite login`` or a redeemed ID-JAG) has no key row, its authority is # sealed in the token: refresh the live user policy and keep the token's team, routes and models. @@ -1386,7 +1391,12 @@ class MCPRequestHandler: refreshed.project_id = current.project_id refreshed.user_id = current.user_id refreshed.access_group_ids = current.access_group_ids - refreshed.requires_fresh_policy = True + else: + return refreshed + if refreshed.mcp_toolset_id is not None: + from litellm.proxy.mcp_server.server import apply_toolset_scope + + return await apply_toolset_scope(refreshed, refreshed.mcp_toolset_id) return refreshed @staticmethod @@ -1406,10 +1416,10 @@ class MCPRequestHandler: project, org, and budget state are NOT re-checked here; the caller runs the admitted identity through ``_enforce_admitted_live_policy`` for those. """ - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy.auth.auth_checks import get_key_object + from litellm.proxy.mcp_server.bridge_token_flow import ( master_key_admin_auth, # noqa: PLC0415 # inline import avoids a module-load circular import ) - from litellm.proxy.auth.auth_checks import get_key_object from litellm.proxy.proxy_server import prisma_client, user_api_key_cache admin: Final = master_key_admin_auth(key_hash) @@ -1651,7 +1661,7 @@ class MCPRequestHandler: @staticmethod def get_guardrail_bearer_token(headers: Headers, auth: UserAPIKeyAuth) -> SecretStr | None: - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( _custom_litellm_key_header_name, # pyright: ignore[reportPrivateUsage] # reuse the shared credential-header setting ) @@ -1874,7 +1884,7 @@ class MCPRequestHandler: from litellm.proxy.proxy_server import general_settings if managed_agent_policy(user_api_key_auth) is not None: - from litellm.proxy._experimental.mcp_server.auth.managed_agent_access import managed_agent_servers + from litellm.proxy.mcp_server.auth.managed_agent_access import managed_agent_servers return MCPServerAccess(server_ids=await managed_agent_servers(user_api_key_auth), scope="scoped") @@ -2247,7 +2257,7 @@ class MCPRequestHandler: intersected with it, so the route narrows a team grant exactly as it narrows the user's own.""" if auth.mcp_toolset_id is None: return None - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -2298,8 +2308,8 @@ class MCPRequestHandler: if not is_mcp_admitted_user_subject(auth) and not personal_key_inherits_team_grants(auth): return auth try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.operations import ( _get_allowed_mcp_servers, _resolve_display_name_to_original, resolve_scoped_mcp_server, @@ -2463,7 +2473,7 @@ class MCPRequestHandler: onto a server reached through a different source. A source that grants the server with no tool restriction means the user can use every tool on it, so allow-all wins the union. When no source grants the server the result is ``[]`` — deny all, fail closed.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -2610,8 +2620,8 @@ class MCPRequestHandler: async def personal_key_team_rpm_limits( auth: UserAPIKeyAuth, server: MCPServer, tool_name: str ) -> Mapping[str, Mapping[str, int]] | None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.auth.auth_checks import get_team_object + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.proxy_server import prisma_client, proxy_logging_obj, user_api_key_cache try: @@ -2662,7 +2672,7 @@ class MCPRequestHandler: then carries the key's OWN tool rules, never a team's; otherwise nothing is allowed. Each team resolves through the raising ``_single_credential_tools`` so one team's fault reaches the caller's fail-closed handler instead of becoming an allow-all ``None`` in the union.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -2763,7 +2773,7 @@ class MCPRequestHandler: nothing (deleted or unknown ids, a swallowed DB fault, or a toolset with no tools): that is a KNOWN restriction with unknown contents, and every caller already turns this error into deny rather than letting the level read as unrestricted.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -2817,7 +2827,7 @@ class MCPRequestHandler: ``mcp_tool_permissions`` entry for it. A granting group with no entry grants every tool, so ``None`` wins. A group that does not grant the server contributes nothing, and an explicit ``[]`` entry on a granting group grants no tools. ``None`` when no group grants the server.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -2838,7 +2848,7 @@ class MCPRequestHandler: @staticmethod def _group_grants_server(group: LiteLLM_AccessGroupTable, server_id: str) -> bool: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -2882,7 +2892,7 @@ class MCPRequestHandler: """Servers the key's object permission grants on its own: ``mcp_servers`` by id, name or alias and legacy ``mcp_access_groups`` by the tag the server carries, exactly as server admission resolves them. A tag never doubles as a server name, so a tag that collides with one grants nothing by itself.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager if key_obj_perm is None: return frozenset() @@ -3044,7 +3054,7 @@ class MCPRequestHandler: return None if managed_agent_policy(user_api_key_auth) is not None: - from litellm.proxy._experimental.mcp_server.auth.managed_agent_access import managed_agent_tools + from litellm.proxy.mcp_server.auth.managed_agent_access import managed_agent_tools return await managed_agent_tools(server_id, user_api_key_auth) @@ -3101,7 +3111,7 @@ class MCPRequestHandler: # server_ids OR names/aliases; normalize to server_id-keyed form # before lookup so a name-based key does not silently drop its # tool restrictions when server_id is the resolved uuid. - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -3193,7 +3203,7 @@ class MCPRequestHandler: fail-open (skip the org step, keep the key/team/agent restrictions; letting the raise escape would collapse them to allow-all, WIDER than before the fault), while a keyless source re-raises so the outer handler denies that one source (its only org bound is this ceiling).""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -3307,12 +3317,12 @@ class MCPRequestHandler: if user_api_key_auth is None: return [] try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - global_mcp_server_manager, - ) from litellm.proxy.auth.auth_checks import ( get_mcp_server_ids_from_access_groups, ) + from litellm.proxy.mcp_server.mcp_server_manager import ( + global_mcp_server_manager, + ) from litellm.proxy.proxy_server import ( prisma_client, proxy_logging_obj, @@ -3364,12 +3374,12 @@ class MCPRequestHandler: if user_api_key_auth is None: return [] try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - global_mcp_server_manager, - ) from litellm.proxy.auth.auth_checks import ( get_object_permission, ) + from litellm.proxy.mcp_server.mcp_server_manager import ( + global_mcp_server_manager, + ) from litellm.proxy.proxy_server import ( prisma_client, proxy_logging_obj, @@ -3528,7 +3538,7 @@ class MCPRequestHandler: ``mcp_servers``, the ``all_proxy_servers`` sentinel → the full registry, legacy access groups, tool-perm-referenced servers, toolset-referenced servers) unioned with its unified ``access_group_ids`` servers.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -3740,7 +3750,7 @@ class MCPRequestHandler: if object_permissions is None: return [] - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -3845,7 +3855,7 @@ class MCPRequestHandler: try: # Permission entries may be server_ids OR names/aliases — expand to ids. - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -3980,7 +3990,7 @@ class MCPRequestHandler: ``mcp_tool_permissions`` or reached through ``mcp_toolsets`` count as entitled, exactly as they do for a key or a team, so granting one tool never requires naming its server twice. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -4120,7 +4130,7 @@ class MCPRequestHandler: restriction. Returns ``[]`` (deny every tool on this server) when the entitlement cannot be resolved, because the caller's own except-handler treats a raise as allow-all for key auth. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -4163,7 +4173,7 @@ class MCPRequestHandler: axis twin of ``apply_agent_caller_ceiling``, so the headers only ever narrow. Denies every tool on the server when the caller's team cannot be loaded, since a caller we cannot resolve must not read as unrestricted.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -4207,7 +4217,7 @@ class MCPRequestHandler: user_api_key_auth: UserAPIKeyAuth | None = None, ) -> Sequence[str] | None: """Narrow a key/team tool allowlist by the end user's (customer's) tool entitlement.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) from litellm.proxy.proxy_server import prisma_client @@ -4253,7 +4263,7 @@ class MCPRequestHandler: cache_key: Final = f"agent_object_permission_id:{agent_id}" try: - cached: Final[object] = await user_api_key_cache.async_get_cache(key=cache_key) + cached: Final = _CACHED_VALUE.validate_python(await user_api_key_cache.async_get_cache(key=cache_key)) if cached == MCPRequestHandler._AGENT_NO_PERMISSION_SENTINEL: return None if isinstance(cached, str) and cached: @@ -4343,7 +4353,7 @@ class MCPRequestHandler: return [] try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -4380,7 +4390,7 @@ class MCPRequestHandler: allow, or None when the agent has none attached. Unlike the object_permission path above, an attached group set that names no servers is an empty ceiling and denies every server. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -4459,7 +4469,7 @@ class MCPRequestHandler: ) try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -4535,7 +4545,7 @@ class MCPRequestHandler: try: # Import here to avoid circular import - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) diff --git a/litellm/proxy/_experimental/mcp_server/bridge_token_flow.py b/litellm/proxy/mcp_server/bridge_token_flow.py similarity index 95% rename from litellm/proxy/_experimental/mcp_server/bridge_token_flow.py rename to litellm/proxy/mcp_server/bridge_token_flow.py index 9f393f25e49..63428dfb28a 100644 --- a/litellm/proxy/_experimental/mcp_server/bridge_token_flow.py +++ b/litellm/proxy/mcp_server/bridge_token_flow.py @@ -13,24 +13,24 @@ from pydantic import SecretStr from typing_extensions import assert_never from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.oauth_utils import TOKEN_NO_CACHE_HEADERS from litellm.proxy.common_utils.encrypt_decrypt_utils import ( # noqa: F401 # legacy module exports _V2_GCM_PREFIX, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export V2_GCM_PREFIX, # pyright: ignore[reportPrivateUsage] # reuse the encrypted credential's format discriminator ) +from litellm.proxy.mcp_server.oauth_utils import TOKEN_NO_CACHE_HEADERS from litellm.types.mcp_server.mcp_server_manager import MCPServer if TYPE_CHECKING: from litellm.models.user import LiteLLM_UserTable - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import _BridgeAuthorizationCode - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.auth.handle_jwt import JWTIdentity + from litellm.proxy.mcp_server.discoverable_endpoints import _BridgeAuthorizationCode + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( EnvelopeIdentity, EnvelopeKeys, RefreshCredential, UpstreamTokenGrant, ) - from litellm.proxy._types import UserAPIKeyAuth - from litellm.proxy.auth.handle_jwt import JWTIdentity def _litellm_key_from_request(request: Request) -> str | None: @@ -87,14 +87,14 @@ async def oauth_authorization_uses_gateway_credential(request: Request) -> bool: async def _opaque_bearer_is_gateway_credential(token: str) -> bool: - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # envelope imports bridge types - is_envelope, - is_refresh_envelope, - ) from litellm.proxy._types import hash_token # noqa: PLC0415 # proxy import cycle from litellm.proxy.auth.auth_checks import ExperimentalUIJWTToken # noqa: PLC0415 # proxy import cycle from litellm.proxy.auth.resolvers.exceptions import KeyNotFoundError # noqa: PLC0415 # proxy import cycle from litellm.proxy.auth.resolvers.store import IdentityStore # noqa: PLC0415 # proxy import cycle + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # envelope imports bridge types + is_envelope, + is_refresh_envelope, + ) from litellm.proxy.proxy_server import ( # noqa: PLC0415 # startup owns the identity store dependencies prisma_client, user_api_key_cache, @@ -447,16 +447,16 @@ async def _resolve_request_auth( async def can_store_oauth_credential(request: Request, auth: "UserAPIKeyAuth", server_id: str) -> bool: """Apply the same write policy to request credentials and verified signed-callback users.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # registry imports auth helpers - global_mcp_server_manager, - ) - from litellm.proxy._experimental.mcp_server.ui_session_utils import ( - can_access_mcp_server, # noqa: PLC0415 # proxy import cycle - ) from litellm.proxy.auth.route_checks import RouteChecks # noqa: PLC0415 # proxy import cycle from litellm.proxy.auth.user_api_key_auth import ( # noqa: PLC0415 # proxy import cycle run_centralized_common_checks, # pyright: ignore[reportPrivateUsage] # reuse admission policy for the credential-write action ) + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # registry imports auth helpers + global_mcp_server_manager, + ) + from litellm.proxy.mcp_server.ui_session_utils import ( + can_access_mcp_server, # noqa: PLC0415 # proxy import cycle + ) write_route: Final = f"/v1/mcp/server/{server_id}/oauth-user-credential" try: @@ -584,7 +584,7 @@ def _bridge_grant_from_token_response(token_response: object) -> "UpstreamTokenG lifetime leaves the grant ``expires_in`` ``None`` for the envelope fallback, a positive value is honoured, and an explicit already-elapsed value is a rejection rather than a silent fall-through to the cap.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import UpstreamTokenGrant, ) @@ -790,18 +790,18 @@ async def prepare_bridge_mint( presented key keeps its resolution origin so the mapper statuses it truthfully; neither source present is ``no_identity``. The refresh_token grant has its own phase-1 (:func:`_prepare_bridge_refresh`), which recovers identity from the presented refresh envelope.""" - from litellm.proxy._experimental.mcp_server.client_allowlist import ( # noqa: PLC0415 # keep mint policy dependencies local + from litellm.proxy._types import UserAPIKeyAuth # noqa: PLC0415 # proxy import cycle + from litellm.proxy.auth.handle_jwt import JWTHandler # noqa: PLC0415 # proxy import cycle + from litellm.proxy.mcp_server.client_allowlist import ( # noqa: PLC0415 # keep mint policy dependencies local load_mcp_client_allowlist, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( # noqa: PLC0415 # inline import avoids a module-load circular import envelope_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import key_hash_identity, user_identity, ) - from litellm.proxy._types import UserAPIKeyAuth # noqa: PLC0415 # proxy import cycle - from litellm.proxy.auth.handle_jwt import JWTHandler # noqa: PLC0415 # proxy import cycle from litellm.proxy.proxy_server import ( # noqa: PLC0415 # inline import avoids a module-load circular import general_settings, master_key, @@ -877,7 +877,7 @@ async def prepare_bridge_refresh( never a raw upstream refresh token, so a missing value, a non-envelope, an unopenable envelope, or one minted for another server is ``invalid_grant``. Running before the exchange means a rejected refresh never consumes or rotates the upstream refresh token.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( # noqa: PLC0415 # inline import avoids a module-load circular import BridgeRefreshOpened, envelope_keys_from_master_key, open_bridge_refresh_envelope, @@ -917,10 +917,10 @@ def finish_bridge_mint( fresh refresh envelope. The only hard failures here are properties of the upstream access token (no usable token, an already-expired lifetime, or a token too large to seal); a refresh token that cannot be sealed degrades to an access-only response rather than failing the whole exchange.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( # noqa: PLC0415 # inline import avoids a module-load circular import build_bridge_token_response, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import EnvelopeLifetimeUnrepresentable, SealedEnvelope, UpstreamTokenGrant, @@ -961,7 +961,7 @@ def _upstream_refresh_credential(token_response: object) -> "RefreshCredential | token would hand the client a full-TTL-capped envelope the IdP will reject, so the exchange degrades to an access-only response (the client re-authenticates at access expiry), mirroring how :func:`_bridge_grant_from_token_response` refuses an already-elapsed access token instead of capping it.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import RefreshCredential, ) @@ -988,10 +988,10 @@ def _mint_refresh_envelope_value( ``None`` when the upstream returned no refresh token or the refresh token is too large to seal. A too-large refresh token degrades to an access-only response (logged) rather than failing an exchange that already succeeded upstream: the client simply re-authenticates when the access envelope expires.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( # noqa: PLC0415 # inline import avoids a module-load circular import build_bridge_refresh_token_response, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import SealedEnvelope, ) diff --git a/litellm/proxy/_experimental/mcp_server/byok_credential_cache.py b/litellm/proxy/mcp_server/byok_credential_cache.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/byok_credential_cache.py rename to litellm/proxy/mcp_server/byok_credential_cache.py diff --git a/litellm/proxy/_experimental/mcp_server/byok_oauth_endpoints.py b/litellm/proxy/mcp_server/byok_oauth_endpoints.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/byok_oauth_endpoints.py rename to litellm/proxy/mcp_server/byok_oauth_endpoints.py index 2181e92baa9..868b73e39f1 100644 --- a/litellm/proxy/_experimental/mcp_server/byok_oauth_endpoints.py +++ b/litellm/proxy/mcp_server/byok_oauth_endpoints.py @@ -25,16 +25,16 @@ from fastapi import APIRouter, Depends, Form, HTTPException, Request from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse from litellm._logging import verbose_proxy_logger -from litellm.proxy._experimental.mcp_server.catalog import public_catalog_operation -from litellm.proxy._experimental.mcp_server.db import store_user_credential -from litellm.proxy._experimental.mcp_server.oauth_utils import ( +from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server.catalog import public_catalog_operation +from litellm.proxy.mcp_server.db import store_user_credential +from litellm.proxy.mcp_server.oauth_utils import ( BYOK_RESOURCE_METADATA_PATH, TOKEN_NO_CACHE_HEADERS, get_request_base_url, validate_loopback_redirect_uri, well_known_root_suffix, ) -from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.middleware.per_request_root_path_middleware import get_server_root_paths # --------------------------------------------------------------------------- @@ -779,7 +779,7 @@ async def byok_authorize_get( help_url = "" if server_id: try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -955,7 +955,7 @@ async def byok_token( ) # Invalidate any cached negative result so the user isn't blocked # for up to the TTL period after completing the OAuth flow. - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _invalidate_byok_cred_cache, ) diff --git a/litellm/proxy/_experimental/mcp_server/capabilities.py b/litellm/proxy/mcp_server/capabilities.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/capabilities.py rename to litellm/proxy/mcp_server/capabilities.py diff --git a/litellm/proxy/_experimental/mcp_server/catalog.py b/litellm/proxy/mcp_server/catalog.py similarity index 93% rename from litellm/proxy/_experimental/mcp_server/catalog.py rename to litellm/proxy/mcp_server/catalog.py index 71eb2112bd5..cfa620c978e 100644 --- a/litellm/proxy/_experimental/mcp_server/catalog.py +++ b/litellm/proxy/mcp_server/catalog.py @@ -23,15 +23,15 @@ from pydantic import BaseModel, ConfigDict, JsonValue, TypeAdapter from litellm._logging import verbose_logger from litellm.caching.in_memory_cache import InMemoryCache -from litellm.proxy._experimental.mcp_server.result_conversion import age_freshness, aggregate_freshness +from litellm.proxy.mcp_server.result_conversion import age_freshness, aggregate_freshness if TYPE_CHECKING: from mcp.types import ListToolsResult, PaginatedRequestParams, PaginatedResult - from litellm.proxy._experimental.mcp_server.contracts import CatalogListRequest, CatalogListResult, OperationContext - from litellm.proxy._experimental.mcp_server.db import OAuthCredentialPayload - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import AggregateToolListing, ServerOutcome - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.contracts import CatalogListRequest, CatalogListResult, OperationContext + from litellm.proxy.mcp_server.db import OAuthCredentialPayload + from litellm.proxy.mcp_server.faults.list_outcomes import AggregateToolListing, ServerOutcome + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp_server.mcp_server_manager import MCPServer from litellm.types.mcp_server.tool_registry import MCPTool @@ -90,7 +90,7 @@ def _check_oauth_revision(selected: MCPServer, candidate: MCPServer | None) -> N def _snapshot(manager: MCPServerManager, database_identity: str) -> CatalogSnapshot: - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry servers: Final = manager.config_mcp_servers | manager.registry detached: Final = MappingProxyType({key: value.model_copy(deep=True) for key, value in servers.items()}) @@ -154,7 +154,7 @@ class CatalogSnapshots: if not should_load_db_object("mcp"): return _snapshot(self.manager, self._database_identity) - from litellm.proxy._experimental.mcp_server.db import get_mcp_catalog_revision + from litellm.proxy.mcp_server.db import get_mcp_catalog_revision try: revision: Final = await get_mcp_catalog_revision(prisma_client) @@ -198,7 +198,7 @@ class CatalogSnapshots: if current is not None: yield current return - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry shared: Final = await self._fresh_snapshot() initial_routing: Final = self._unchanged_routing(shared.servers, self.manager.published_tool_routes) @@ -227,7 +227,7 @@ class CatalogSnapshots: def _unchanged_routing( self, servers: Mapping[str, MCPServer], routing: Mapping[str, str] ) -> MappingProxyType[str, str]: - from litellm.proxy._experimental.mcp_server.utils import normalize_server_name + from litellm.proxy.mcp_server.utils import normalize_server_name current: Final = self.manager.config_mcp_servers | self.manager.registry unchanged: Final = ( @@ -252,7 +252,7 @@ class CatalogSnapshots: server: MCPServer, resolve: Callable[[MCPServer], Awaitable[MCPServer]], ) -> MCPServer: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import oauth_endpoints_unresolved + from litellm.proxy.mcp_server.mcp_server_manager import oauth_endpoints_unresolved snapshot: Final = self.current() selected: Final = snapshot.servers.get(server.server_id) if snapshot is not None else None @@ -270,7 +270,7 @@ class CatalogSnapshots: return resolved async def reload(self) -> None: - from litellm.proxy._experimental.mcp_server.db import get_mcp_catalog_revision + from litellm.proxy.mcp_server.db import get_mcp_catalog_revision from litellm.proxy.proxy_server import prisma_client revision: Final = await get_mcp_catalog_revision(prisma_client) if prisma_client is not None else None @@ -294,8 +294,8 @@ class CatalogSnapshots: self._operation.reset(token) async def _reload_and_publish(self, *, reuse_unchanged: bool) -> None: - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry - from litellm.proxy._experimental.mcp_server.utils import normalize_server_name + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.utils import normalize_server_name previous_config: Final = MappingProxyType( {key: value.model_copy(deep=True) for key, value in self.manager.config_mcp_servers.items()} @@ -399,8 +399,8 @@ class CatalogSnapshots: async def _stage_servers( self, rows: Sequence[BaseModel], *, reuse_unchanged: bool ) -> dict[str, MCPServer]: # mutable-ok: assign_unique_short_prefix requires a dict registry - from litellm.proxy._experimental.mcp_server.db import LiteLLM_MCPServerTable - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.db import LiteLLM_MCPServerTable + from litellm.proxy.mcp_server.mcp_server_manager import ( carry_forward_resolved_oauth_endpoints, oauth_endpoints_unresolved, warn_on_server_name_fields, @@ -464,20 +464,20 @@ class CatalogSnapshots: return new_registry async def _reload(self, *, reuse_unchanged: bool) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - config_ids_capturing_db_identifiers, - warn_on_shared_identifier_prefixes, - ) from litellm.proxy.management_endpoints.mcp_management_endpoints import ( get_prisma_client_or_throw, ) + from litellm.proxy.mcp_server.mcp_server_manager import ( + config_ids_capturing_db_identifiers, + warn_on_shared_identifier_prefixes, + ) verbose_logger.debug("Loading MCP servers from database into registry...") prisma_client: Final = get_prisma_client_or_throw("Database not connected. Connect a database to your proxy") # Load only "active", legacy "approved", and NULL (no approval workflow) rows. # Pending/rejected servers are excluded at the DB level so we never load them. - from litellm.proxy._experimental.mcp_server.db import get_runtime_mcp_server_rows + from litellm.proxy.mcp_server.db import get_runtime_mcp_server_rows raw_rows: Final[Sequence[BaseModel]] = await get_runtime_mcp_server_rows(prisma_client) database_identity: Final = hashlib.sha256( @@ -584,7 +584,7 @@ def catalog_operation( def global_manager() -> MCPServerManager: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager return global_mcp_server_manager @@ -608,8 +608,8 @@ async def paginate_catalog( from pydantic import ValidationError from litellm.constants import MCP_TOOL_LISTING_MAX_PAGES - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error - from litellm.proxy._experimental.mcp_server.state_tokens import open_state, seal_state + from litellm.proxy.mcp_server.outbound_credentials.result import Error + from litellm.proxy.mcp_server.state_tokens import open_state, seal_state ordered: Final = tuple(sorted(server_ids)) purpose: Final = "mcp.catalog.list.v1:" + method @@ -673,7 +673,7 @@ async def paginate_catalog( for task in tasks: task.cancel() await asyncio.gather(*tasks, return_exceptions=True) - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY + from litellm.proxy.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY elapsed: Final = time.monotonic() - started pages: Final = tuple( @@ -719,7 +719,7 @@ async def list_tools_page( ) -> ListToolsResult: from mcp.types import ListToolsResult - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY + from litellm.proxy.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY pages, next_cursor, outcomes = await paginate_catalog( method="tools/list", @@ -773,9 +773,9 @@ async def get_filtered_server_tools( ) -> tuple[ListToolsResult, ServerOutcome]: from mcp.types import ListToolsResult - from litellm.proxy._experimental.mcp_server.exceptions import MCPUpstreamAuthError - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ServerListOk, classify_list_exception - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.exceptions import MCPUpstreamAuthError + from litellm.proxy.mcp_server.faults.list_outcomes import ServerListOk, classify_list_exception + from litellm.proxy.mcp_server.operations import ( _get_byok_credential, _get_user_oauth_extra_headers_from_db, _prepare_mcp_server_headers, @@ -806,7 +806,7 @@ async def get_filtered_server_tools( # Prefer server-stored per-user OAuth when configured, so a stale # Authorization header from the MCP client cannot override Redis/DB # (same issue as call_tool in mcp_server_manager: VS Code caches tokens). - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 to_server_spec, ) @@ -885,8 +885,8 @@ async def get_filtered_server_tools( user_api_key_auth=user_api_key_auth, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ListedToolsCaller - from litellm.proxy._experimental.mcp_server.utils import strip_known_server_prefix + from litellm.proxy.mcp_server.mcp_server_manager import ListedToolsCaller + from litellm.proxy.mcp_server.utils import strip_known_server_prefix record: Final = partial( global_mcp_server_manager.record_listed_tools, @@ -908,7 +908,7 @@ async def get_filtered_server_tools( listing_updates.callback(record) if mcp_proxy_mode: - from litellm.proxy._experimental.mcp_server.tool_search import with_mcp_proxy_identity + from litellm.proxy.mcp_server.tool_search import with_mcp_proxy_identity filtered_tools = [with_mcp_proxy_identity(tool, server.server_id) for tool in filtered_tools] else: @@ -936,7 +936,7 @@ async def get_filtered_server_tools( def _caller_scope(context: OperationContext, servers: Sequence[MCPServer]) -> str: - from litellm.proxy._experimental.mcp_server.utils import upstream_credential_headers + from litellm.proxy.mcp_server.utils import upstream_credential_headers caller: Final = context.user_api_key_auth headers: Final = context.raw_headers or {} @@ -975,18 +975,18 @@ async def aggregate_gateway_tools( from mcp.types import ListToolsResult, PaginatedRequestParams from pydantic import TypeAdapter - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError + from litellm.proxy.mcp_server.faults.list_outcomes import ( SERVER_OUTCOMES_META_KEY, AggregateToolListing, ServerOutcome, classify_list_exception, ) - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( _aggregate_server_key, _mcp_server_rate_limit_rejection, global_mcp_server_manager, ) - from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError async with global_mcp_server_manager.catalog.operation() as snapshot: servers: Final = {server.server_id: server for server in allowed} @@ -1065,12 +1065,12 @@ async def list_gateway_tools( ) -> ListToolsResult: from mcp.types import INTERNAL_ERROR, ListToolsResult - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.mcp_server.faults.list_outcomes import ( SERVER_OUTCOMES_META_KEY, listing_failed_outright, outcome_wire_value, ) - from litellm.proxy._experimental.mcp_server.operations import _list_mcp_tools + from litellm.proxy.mcp_server.operations import _list_mcp_tools caller, auth, servers, server_headers, oauth_headers, headers, client_ip = context.legacy_auth() listing: Final = await _list_mcp_tools( @@ -1115,13 +1115,13 @@ async def list_gateway_catalog( PaginatedRequestParams, ) - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.operations import ( _get_allowed_mcp_servers, global_mcp_server_manager, raise_denied_scoped_mcp_access, ) - from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError context = replace(context, _caller=await MCPRequestHandler.refresh_catalog_authority(context.user_api_key_auth)) params: Final = request.params or PaginatedRequestParams() @@ -1146,11 +1146,11 @@ async def list_gateway_catalog( from mcp.shared.exceptions import MCPError from mcp.types import INVALID_PARAMS - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.mcp_server.faults.list_outcomes import ( SERVER_OUTCOMES_META_KEY, classify_list_exception, ) - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( _aggregate_server_key, _mcp_server_rate_limit_rejection, ) @@ -1173,12 +1173,9 @@ async def list_gateway_catalog( try: page: Final = await fetch_optional_catalog_page(context, request, server, allowed, cursor) + page_meta: Final[Mapping[str, object]] = page.meta or {} return page.model_copy( - update={ - "meta": { - key: value for key, value in (page.meta or {}).items() if key != SERVER_OUTCOMES_META_KEY - } - } + update={"meta": {key: value for key, value in page_meta.items() if key != SERVER_OUTCOMES_META_KEY}} ) except Exception as error: if cursor is not None: @@ -1207,7 +1204,7 @@ async def list_gateway_catalog( ) if params.cursor is None and servers and len(rejections) == len(servers): raise rejections[0] - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.mcp_server.faults.list_outcomes import ( SERVER_OUTCOMES_META_KEY, ServerOutcome, outcome_wire_value, @@ -1235,7 +1232,7 @@ async def fetch_optional_catalog_page( ) -> CatalogListResult: from mcp.types import PaginatedRequestParams - from litellm.proxy._experimental.mcp_server.operations import _prepare_mcp_server_headers, global_mcp_server_manager + from litellm.proxy.mcp_server.operations import _prepare_mcp_server_headers, global_mcp_server_manager caller, auth, _, server_headers, oauth_headers, raw_headers, client_ip = context.legacy_auth() auth_header, extra_headers = _prepare_mcp_server_headers( @@ -1272,7 +1269,7 @@ def combine_optional_catalog( ListResourceTemplatesResult, ) - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY + from litellm.proxy.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY outcomes: Final = (meta or {}).get(SERVER_OUTCOMES_META_KEY) incomplete: Final = isinstance(outcomes, dict) and any( diff --git a/litellm/proxy/_experimental/mcp_server/client_allowlist.py b/litellm/proxy/mcp_server/client_allowlist.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/client_allowlist.py rename to litellm/proxy/mcp_server/client_allowlist.py diff --git a/litellm/proxy/_experimental/mcp_server/contracts.py b/litellm/proxy/mcp_server/contracts.py similarity index 96% rename from litellm/proxy/_experimental/mcp_server/contracts.py rename to litellm/proxy/mcp_server/contracts.py index 84cd2751444..43c42d3b0df 100644 --- a/litellm/proxy/_experimental/mcp_server/contracts.py +++ b/litellm/proxy/mcp_server/contracts.py @@ -10,8 +10,8 @@ from typing import TYPE_CHECKING, Final, Literal, Protocol, TypeAlias from mcp.types import ErrorData, InputRequest, InputResponse, InputResponses from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.tool_outcome import WireCompat from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server.tool_outcome import WireCompat from litellm.types.mcp_server.mcp_server_manager import MCPServer if TYPE_CHECKING: @@ -33,7 +33,7 @@ if TYPE_CHECKING: ListToolsResult | ListPromptsResult | ListResourcesResult | ListResourceTemplatesResult ) - from litellm.proxy._experimental.mcp_server.server_resolution import ResolvedMCPServer + from litellm.proxy.mcp_server.server_resolution import ResolvedMCPServer class TargetCatalog(Protocol): diff --git a/litellm/proxy/_experimental/mcp_server/cost_calculator.py b/litellm/proxy/mcp_server/cost_calculator.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/cost_calculator.py rename to litellm/proxy/mcp_server/cost_calculator.py diff --git a/litellm/proxy/_experimental/mcp_server/db.py b/litellm/proxy/mcp_server/db.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/db.py rename to litellm/proxy/mcp_server/db.py index 7302b74f15a..27f8b90a586 100644 --- a/litellm/proxy/_experimental/mcp_server/db.py +++ b/litellm/proxy/mcp_server/db.py @@ -15,14 +15,6 @@ from litellm._logging import verbose_proxy_logger from litellm._uuid import uuid from litellm.constants import MCP_PER_USER_TOKEN_EXPIRY_BUFFER_SECONDS from litellm.llms.custom_httpx.http_handler import get_async_httpx_client -from litellm.proxy._experimental.mcp_server.oauth_identity_binding import ( - RefreshTokenPresented, - credential_binding_matches, - enforce_oauth_identity_binding, -) -from litellm.proxy._experimental.mcp_server.oauth_utils import ( - build_upstream_oauth2_token_request, -) from litellm.proxy._types import ( LiteLLM_MCPServerTable, MCPApprovalStatus, @@ -42,6 +34,14 @@ from litellm.proxy.common_utils.encrypt_decrypt_utils import ( # noqa: F401 # encrypt_value_helper, get_salt_key, ) +from litellm.proxy.mcp_server.oauth_identity_binding import ( + RefreshTokenPresented, + credential_binding_matches, + enforce_oauth_identity_binding, +) +from litellm.proxy.mcp_server.oauth_utils import ( + build_upstream_oauth2_token_request, +) from litellm.proxy.utils import PrismaClient from litellm.repositories.config_repository import ConfigRepository from litellm.repositories.object_permission_repository import ObjectPermissionRepository @@ -165,6 +165,7 @@ _CLIENT_FORWARDED_AUTH_TYPES: Final["frozenset[str]"] = frozenset({"true_passthr _MINTED_TOKEN_CREDENTIAL_FIELDS: Final["frozenset[str]"] = frozenset({"access_token", "refresh_token", "expires_in"}) _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_input_in_errors=True)) +_DECODED_JSON: Final = TypeAdapter(object) def _bind_submitted_oauth_client( @@ -339,7 +340,7 @@ def _decrypt_env_vars_on_returned_row(row: object) -> None: return if isinstance(env_vars, str): try: - env_vars = json.loads(env_vars) + env_vars = _DECODED_JSON.validate_python(json.loads(env_vars)) except (json.JSONDecodeError, TypeError): return if not isinstance(env_vars, list): @@ -476,8 +477,9 @@ def _prepare_mcp_server_data( # Serialize JSON fields from ``data_dict`` (not ``data``) so the # exclude_unset filter is respected. Reading back from ``data`` would # reintroduce defaults (e.g. ``env={}``) for fields the caller never set. - if data_dict.get("static_headers") is not None: - data_dict["static_headers"] = encrypt_secret_map(data_dict["static_headers"]) + static_headers: Final[Mapping[str, str] | None] = data_dict.get("static_headers") + if static_headers is not None: + data_dict["static_headers"] = encrypt_secret_map(static_headers) # env_vars is read from ``data_dict`` (not ``data``) like every other JSON # column so the exclude_unset filter is respected: a partial update that @@ -489,11 +491,13 @@ def _prepare_mcp_server_data( _encrypt_global_env_var_values(serialized_env_vars) data_dict["env_vars"] = safe_dumps(serialized_env_vars) - if data_dict.get("mcp_info") is not None: - data_dict["mcp_info"] = safe_dumps(data_dict["mcp_info"]) + mcp_info: Final[object] = data_dict.get("mcp_info") + if mcp_info is not None: + data_dict["mcp_info"] = safe_dumps(mcp_info) - if data_dict.get("env") is not None: - data_dict["env"] = encrypt_secret_map(data_dict["env"]) + env: Final[Mapping[str, str] | None] = data_dict.get("env") + if env is not None: + data_dict["env"] = encrypt_secret_map(env) if "tool_name_to_display_name" in data_dict: data_dict["tool_name_to_display_name"] = safe_dumps(data_dict["tool_name_to_display_name"] or {}) @@ -1062,7 +1066,7 @@ async def delete_mcp_server( ) if credential_user_ids: if invalidate_token_cache is None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -2027,7 +2031,7 @@ async def purge_user_oauth_credentials_for_server( where={"server_id": server_id, "user_id": {"in": [row.user_id for row in oauth_rows]}} ) if invalidate_token_cache is None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -2234,7 +2238,7 @@ async def resolve_user_oauth_access_token( if not user_id or not server_id: return None try: - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( + from litellm.proxy.mcp_server.oauth2_token_cache import ( compute_per_user_token_ttl, mcp_per_user_token_cache, ) diff --git a/litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py b/litellm/proxy/mcp_server/discoverable_endpoints.py similarity index 97% rename from litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py rename to litellm/proxy/mcp_server/discoverable_endpoints.py index 3b2c2e09df5..eb12b15cdae 100644 --- a/litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py +++ b/litellm/proxy/mcp_server/discoverable_endpoints.py @@ -22,11 +22,21 @@ from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, httpxSpecialProvider, ) -from litellm.proxy._experimental.mcp_server.auth.token_endpoint_auth import ( +from litellm.proxy.auth.ip_address_utils import IPAddressUtils +from litellm.proxy.auth.user_api_key_auth import user_api_key_auth +from litellm.proxy.common_utils.encrypt_decrypt_utils import ( + decrypt_value_helper, + encrypt_value_helper, +) +from litellm.proxy.common_utils.http_parsing_utils import ( # noqa: F401 # legacy module exports + _read_request_body, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export + read_request_body, +) +from litellm.proxy.mcp_server.auth.token_endpoint_auth import ( TokenEndpointAuthConfigError, normalize_token_endpoint_auth_method, ) -from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( # noqa: F401 # legacy module exports +from litellm.proxy.mcp_server.bridge_token_flow import ( # noqa: F401 # legacy module exports _bridge_mint_error_response, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export _BridgeMintReady, _BridgeRefreshReady, @@ -45,8 +55,8 @@ from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( # noqa: prepare_bridge_refresh, reload_active_user_by_id, ) -from litellm.proxy._experimental.mcp_server.catalog import public_catalog_operation -from litellm.proxy._experimental.mcp_server.faults import ( +from litellm.proxy.mcp_server.catalog import public_catalog_operation +from litellm.proxy.mcp_server.faults import ( CallerRejected, CredentialSource, UpstreamProtocolFault, @@ -55,7 +65,7 @@ from litellm.proxy._experimental.mcp_server.faults import ( dcr_fault_detail, render_token_fault, ) -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( +from litellm.proxy.mcp_server.gateway_dcr_flow import ( JWT_BEARER_GRANT_TYPE, VendorCredentialState, aggregate_authorize, @@ -72,21 +82,21 @@ from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( revoke_refresh_token, supported_grant_types, ) -from litellm.proxy._experimental.mcp_server.id_jag_grant import ( +from litellm.proxy.mcp_server.id_jag_grant import ( basic_client_id, jwt_bearer_available, redeem_id_jag_assertion, ) -from litellm.proxy._experimental.mcp_server.idp_token_exchange import ( +from litellm.proxy.mcp_server.idp_token_exchange import ( exchange_idp_subject_token, token_exchange_available, ) -from litellm.proxy._experimental.mcp_server.oauth_identity_binding import ( +from litellm.proxy.mcp_server.oauth_identity_binding import ( RefreshOwnershipProven, RefreshTokenPresented, enforce_oauth_identity_binding, ) -from litellm.proxy._experimental.mcp_server.oauth_utils import ( +from litellm.proxy.mcp_server.oauth_utils import ( CIMD_METADATA_PATH, TOKEN_NO_CACHE_HEADERS, build_upstream_authorize_url, @@ -101,27 +111,17 @@ from litellm.proxy._experimental.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, well_known_root_suffix, ) -from litellm.proxy._experimental.mcp_server.proxy_api_credentials import ( +from litellm.proxy.mcp_server.proxy_api_credentials import ( lookup_consent_teams, mint_proxy_credential, ) -from litellm.proxy.auth.ip_address_utils import IPAddressUtils -from litellm.proxy.auth.user_api_key_auth import user_api_key_auth -from litellm.proxy.common_utils.encrypt_decrypt_utils import ( - decrypt_value_helper, - encrypt_value_helper, -) -from litellm.proxy.common_utils.http_parsing_utils import ( # noqa: F401 # legacy module exports - _read_request_body, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export - read_request_body, -) from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.mcp import MCPAuth, MCPCredentials from litellm.types.mcp_server.mcp_server_manager import MCPServer, MCPTokenEndpointAuthMethod if TYPE_CHECKING: - from litellm.proxy._experimental.mcp_server.db import OAuthCredentialPayload from litellm.proxy._types import LiteLLM_MCPServerTable + from litellm.proxy.mcp_server.db import OAuthCredentialPayload # TTL cache for upstream OAuth metadata fetched from pass-through MCP servers. # Keeps us from hammering the upstream IdP on each discovery request. @@ -472,15 +472,15 @@ def redeem_passthrough_authorization_code( return sealed -def _session_cookie_user_id(request: Request) -> str | None: +async def _session_cookie_user_id(request: Request) -> str | None: """The signed-in litellm user for a browser request, or ``None``. Thin wrapper so the aggregate DCR flow's verbs receive the identity as a plain value instead of parsing cookies themselves.""" - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( # noqa: PLC0415 # circular import at module load - user_id_from_session_cookie, + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( # noqa: PLC0415 # circular import at module load + get_authenticated_browser_user_id, ) - return user_id_from_session_cookie(request) + return await get_authenticated_browser_user_id(request) def _redirect_to_litellm_login(request: Request) -> RedirectResponse: @@ -578,7 +578,7 @@ def _append_query_params(url: str, params: dict[str, str]) -> str: def _resolve_mcp_server_by_name_or_id(lookup: str, client_ip: str | None) -> MCPServer | None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -598,7 +598,7 @@ def _resolve_oauth2_server_for_root_endpoints( without a server name prefix, we try to find the right server automatically. Returns the server if exactly one OAuth2 server is configured, else None. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -684,7 +684,7 @@ async def _store_per_user_token_server_side( Errors are logged but NOT re-raised — the token is always returned to the client even when server-side storage fails. """ - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.oauth2_token_cache import ( # noqa: PLC0415 compute_per_user_token_ttl, mcp_per_user_token_cache, ) @@ -701,12 +701,12 @@ async def _store_per_user_token_server_side( expires_in = None refresh_token: Final[str | None] = token_response.get("refresh_token") or None - raw_scope: Final[object] = token_response.get("scope", requested_scope) + raw_scope: Final[object] = _DECODED_JSON.validate_python(token_response.get("scope", requested_scope)) scopes: Final[list[str] | None] = raw_scope.split() if isinstance(raw_scope, str) else None try: prisma_client: Final = get_prisma_client_or_throw("Database not connected. Cannot store per-user OAuth token.") - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 store_user_oauth_credential, ) @@ -735,7 +735,7 @@ async def _store_per_user_token_server_side( ) return # Don't warm Redis if DB write failed - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 global_mcp_server_manager, ) @@ -762,7 +762,7 @@ def raise_if_not_oauth2(mcp_server: MCPServer) -> None: modes (``_persist_dcr_client_registration`` skips them unconditionally, so even the admin Authorize path with ``replace_stale_client`` enabled writes nothing to the server row). """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # circular import with mcp_server_manager at module load + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # circular import with mcp_server_manager at module load UPSTREAM_OAUTH_DISCOVERY_AUTH_TYPES, ) @@ -825,7 +825,7 @@ async def _server_with_oauth_endpoints( """ if needed_endpoint(mcp_server) is not None and not needs_cimd_discovery(mcp_server): return mcp_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # circular import with mcp_server_manager at module load + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # circular import with mcp_server_manager at module load global_mcp_server_manager, ) @@ -972,10 +972,10 @@ def _bridge_access_denied_redirect(redirect_uri: str, state: str, mcp_server: MC async def _user_can_reach_mcp_server(user_id: str, server_id: str) -> bool: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -996,17 +996,13 @@ async def _resolve_oauth_authorization_user( enforce_binding: bool, ) -> str | RedirectResponse: """Resolve the authorization subject without replacing denied credentials with cookie grants.""" - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( # noqa: PLC0415 # proxy import cycle - user_id_from_session_cookie, - ) - use_gateway_credential: Final = enforce_binding and await oauth_authorization_uses_gateway_credential(request) request_user_id: Final = ( await authorize_oauth_credential_request(request, mcp_server.server_id) if use_gateway_credential else None ) if use_gateway_credential and request_user_id is None: return _bridge_access_denied_redirect(redirect_uri, state, mcp_server) - user_id: Final = request_user_id or user_id_from_session_cookie(request) + user_id: Final = request_user_id or await _session_cookie_user_id(request) if user_id is None: return _redirect_to_litellm_login(request) if not await _user_can_reach_mcp_server(user_id, mcp_server.server_id): @@ -1017,14 +1013,14 @@ async def _resolve_oauth_authorization_user( async def _managed_authorization_scope( request: Request, server: MCPServer, scope: str | None, authorized_user_id: str | None ) -> tuple[str | None, str | None]: - from litellm.proxy._experimental.mcp_server.db import get_user_oauth_credential + from litellm.proxy.mcp_server.db import get_user_oauth_credential from litellm.proxy.proxy_server import prisma_client gateway_credential: Final = authorized_user_id is None and await oauth_authorization_uses_gateway_credential( request ) session_user: Final = ( - _session_cookie_user_id(request) if authorized_user_id is None and not gateway_credential else None + await _session_cookie_user_id(request) if authorized_user_id is None and not gateway_credential else None ) scope_user_id: Final = authorized_user_id or ( await authorize_oauth_credential_request(request, server.server_id) @@ -1218,7 +1214,7 @@ async def _saved_refresh_credential( if not user_id or not refresh_token or not server.needs_user_oauth_token or server.auth_type != MCPAuth.oauth2: return None from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.db import get_user_oauth_credential + from litellm.proxy.mcp_server.db import get_user_oauth_credential if proxy_server.prisma_client is None: return None @@ -1528,7 +1524,7 @@ async def exchange_token_with_server( try: # Identity binding above must retain the verified caller even when a write is # denied. Authorize persistence separately, immediately before its side effect. - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler # A sealed code delegates a verified user for this authorized server. Raw # request credentials retain their own JWT/key restrictions during resolution. @@ -1687,7 +1683,7 @@ async def _load_store_dcr_credentials( (which has no LiteLLM_MCPServerTable row). Returns None when the store has no usable client_id or the DB is unreachable. Registration writes request strict reads so a failed lookup cannot be mistaken for an absent client.""" - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 # avoids circular import + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 # avoids circular import get_mcp_server_oauth_client_credentials, ) from litellm.proxy.utils import get_prisma_client_or_throw # noqa: PLC0415 # avoids circular import @@ -1741,8 +1737,8 @@ async def _resolve_persisted_dcr_client( the server-scoped store, while a rowless non-config server is a throwaway temp/session server with no persisted client. Returns (row_or_None, credentials_or_None); the row is only needed by the reuse path to refresh the registry for a DB-declared server.""" - from litellm.proxy._experimental.mcp_server.db import get_mcp_server # noqa: PLC0415 # avoids circular import - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # avoids circular import + from litellm.proxy.mcp_server.db import get_mcp_server # noqa: PLC0415 # avoids circular import + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # avoids circular import global_mcp_server_manager, ) from litellm.proxy.utils import get_prisma_client_or_throw # noqa: PLC0415 # avoids circular import @@ -1797,7 +1793,7 @@ async def _reuse_persisted_dcr_client_if_available( async def _refresh_persisted_dcr_server(persisted_server: Optional["LiteLLM_MCPServerTable"]) -> None: if persisted_server is not None and persisted_server.approval_status != "draft": - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # avoids circular import + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # avoids circular import global_mcp_server_manager, ) @@ -1914,16 +1910,16 @@ async def _persist_dcr_client_registration( "dcr_server_url": mcp_server.url, } - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 # avoids circular import + from litellm.proxy._types import UpdateMCPServerRequest # noqa: PLC0415 + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 # avoids circular import McpIdentifierConflict, create_mcp_server_oauth_client_credentials_if_absent, update_mcp_server, upsert_mcp_server_oauth_client_credentials, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 global_mcp_server_manager, ) - from litellm.proxy._types import UpdateMCPServerRequest # noqa: PLC0415 from litellm.proxy.utils import get_prisma_client_or_throw # noqa: PLC0415 try: @@ -2359,7 +2355,7 @@ async def authorize_mcp_session( code_challenge=code_challenge, code_challenge_method=code_challenge_method, response_type=response_type, - session_user_id=_session_cookie_user_id(request), + session_user_id=await _session_cookie_user_id(request), resource=resource, scope=scope, ) @@ -2391,7 +2387,7 @@ async def authorize( code_challenge=code_challenge, code_challenge_method=code_challenge_method, response_type=response_type, - session_user_id=_session_cookie_user_id(request), + session_user_id=await _session_cookie_user_id(request), lookup_consent_teams=lookup_consent_teams, ) return aggregate_authorize( @@ -2402,12 +2398,12 @@ async def authorize( code_challenge=code_challenge, code_challenge_method=code_challenge_method, response_type=response_type, - session_user_id=_session_cookie_user_id(request), + session_user_id=await _session_cookie_user_id(request), resource=resource, scope=scope, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager lookup_name: Final[str | None] = mcp_server_name or client_id client_ip: Final = IPAddressUtils.get_mcp_client_ip(request) @@ -2536,7 +2532,7 @@ async def _vendor_credential_state( The one reading of "authorized" the connect page displays and the finish step enforces, so the button a user sees and the grant they get cannot disagree. A read fault is neither, and fails the scoped grant closed.""" - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 # circular import at module load + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 # circular import at module load get_user_oauth_credential, oauth_grant_state, ) @@ -2560,7 +2556,7 @@ async def authorize_flow(request: Request, flow: str) -> Response: return await describe_connect_flow( request=request, flow_handle=flow, - session_user_id=_session_cookie_user_id(request), + session_user_id=await _session_cookie_user_id(request), lookup_vendor_credential=_vendor_credential_state, lookup_server_reachability=_user_can_reach_mcp_server, ) @@ -2586,7 +2582,7 @@ async def authorize_complete( return await complete_connect_flow( request=request, flow_handle=flow, - session_user_id=_session_cookie_user_id(request), + session_user_id=await _session_cookie_user_id(request), cache=user_api_key_cache, delivery=delivery, team_id=team_id, @@ -3188,7 +3184,7 @@ def _aggregate_header_scopes(request: Request) -> tuple[str, ...]: discovery request, so a client that skips the 401 challenge (Claude Code re-authenticating a server it already knows needs auth) still carries the selection to ``/authorize`` through ``scopes_supported``. Empty when the header is absent or any entry does not resolve.""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( # noqa: PLC0415 # proxy import cycle + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( # noqa: PLC0415 # proxy import cycle MCPRequestHandler, gateway_dcr_challenge_scope, ) @@ -3493,7 +3489,7 @@ async def register_client(request: Request, mcp_server_name: str | None = None): request=request, request_body=data, token_exchange_available=token_exchange_available() ) client_application_type: Final = client_supplied_application_type(data.get("application_type")) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async with global_mcp_server_manager.catalog.operation(): dummy_return: Final = { diff --git a/litellm/proxy/_experimental/mcp_server/elicitation_handler.py b/litellm/proxy/mcp_server/elicitation_handler.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/elicitation_handler.py rename to litellm/proxy/mcp_server/elicitation_handler.py diff --git a/litellm/proxy/_experimental/mcp_server/exceptions.py b/litellm/proxy/mcp_server/exceptions.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/exceptions.py rename to litellm/proxy/mcp_server/exceptions.py index ca2f04bb96a..8be3ae78d15 100644 --- a/litellm/proxy/_experimental/mcp_server/exceptions.py +++ b/litellm/proxy/mcp_server/exceptions.py @@ -4,7 +4,7 @@ from typing import Final from fastapi import HTTPException -from litellm.proxy._experimental.mcp_server.oauth_utils import encode_upstream_scope +from litellm.proxy.mcp_server.oauth_utils import encode_upstream_scope TOKEN_EXCHANGE_SUBJECT_ERROR: Final = ( "Missing or invalid subject token. Authenticate with your identity provider and send its token " diff --git a/litellm/proxy/_experimental/mcp_server/faults/__init__.py b/litellm/proxy/mcp_server/faults/__init__.py similarity index 81% rename from litellm/proxy/_experimental/mcp_server/faults/__init__.py rename to litellm/proxy/mcp_server/faults/__init__.py index de7ee5c866a..bcaa6314869 100644 --- a/litellm/proxy/_experimental/mcp_server/faults/__init__.py +++ b/litellm/proxy/mcp_server/faults/__init__.py @@ -7,16 +7,16 @@ a server-fault status) unrepresentable, and gives the trust-boundary rule one en spec-defined machine fields may cross to callers, upstream prose and raw bodies go to server logs. """ -from litellm.proxy._experimental.mcp_server.faults.classify import ( +from litellm.proxy.mcp_server.faults.classify import ( classify_upstream_dcr_rejection, classify_upstream_token_rejection, ) -from litellm.proxy._experimental.mcp_server.faults.render_oauth import ( +from litellm.proxy.mcp_server.faults.render_oauth import ( dcr_fault_detail, render_token_fault, ) -from litellm.proxy._experimental.mcp_server.faults.traversal import iter_exception_tree -from litellm.proxy._experimental.mcp_server.faults.types import ( +from litellm.proxy.mcp_server.faults.traversal import iter_exception_tree +from litellm.proxy.mcp_server.faults.types import ( CallerRejected, CredentialSource, GatewayRejected, diff --git a/litellm/proxy/_experimental/mcp_server/faults/classify.py b/litellm/proxy/mcp_server/faults/classify.py similarity index 96% rename from litellm/proxy/_experimental/mcp_server/faults/classify.py rename to litellm/proxy/mcp_server/faults/classify.py index bb41436b495..b5e5cbcd27d 100644 --- a/litellm/proxy/_experimental/mcp_server/faults/classify.py +++ b/litellm/proxy/mcp_server/faults/classify.py @@ -10,9 +10,10 @@ from __future__ import annotations from typing import Final import httpx +from pydantic import TypeAdapter from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.faults.types import ( +from litellm.proxy.mcp_server.faults.types import ( GATEWAY_CAPABILITY_CODES, GATEWAY_CREDENTIAL_CODES, MAX_WIRE_FIELD_CHARS, @@ -25,6 +26,8 @@ from litellm.proxy._experimental.mcp_server.faults.types import ( UpstreamReportedFault, ) +_DECODED_JSON: Final = TypeAdapter(object) + def _safe_text(response: httpx.Response) -> str: try: @@ -35,7 +38,7 @@ def _safe_text(response: httpx.Response) -> str: def _safe_json(response: httpx.Response) -> object: try: - return response.json() + return _DECODED_JSON.validate_python(response.json()) except Exception: return None diff --git a/litellm/proxy/_experimental/mcp_server/faults/list_outcomes.py b/litellm/proxy/mcp_server/faults/list_outcomes.py similarity index 85% rename from litellm/proxy/_experimental/mcp_server/faults/list_outcomes.py rename to litellm/proxy/mcp_server/faults/list_outcomes.py index 84673c8c738..b8af3ead8fb 100644 --- a/litellm/proxy/_experimental/mcp_server/faults/list_outcomes.py +++ b/litellm/proxy/mcp_server/faults/list_outcomes.py @@ -3,8 +3,8 @@ The aggregate listing deliberately keeps serving the healthy subset when one server fails, but a failed server must contribute a classified outcome instead of silently shrinking the list: an empty contribution with no signal makes a broken upstream indistinguishable from a healthy server with no -tools. Outcomes carry only machine fields (category and status code) so nothing from an upstream -body crosses the trust boundary; classification is total, so any exception out of a server fetch +tools. Outcomes carry machine fields and controlled diagnostics so nothing from an upstream body +crosses the trust boundary; classification is total, so any exception out of a server fetch becomes an outcome, never a second failure. """ @@ -21,8 +21,10 @@ from urllib.request import parse_http_list, parse_keqv_list import anyio import httpx import httpx2 +from mcp import MCPError +from mcp.types import CONNECTION_CLOSED from mcp.types import Tool as MCPTool -from pydantic import ConfigDict, TypeAdapter +from pydantic import ConfigDict, PositiveInt, TypeAdapter from typing_extensions import assert_never from litellm._logging import verbose_logger @@ -31,12 +33,12 @@ from litellm.constants import ( MCP_UPSTREAM_RATE_LIMIT_MAX_DELAY_SECONDS, MCP_UPSTREAM_RATE_LIMIT_MAX_RETRIES, ) -from litellm.proxy._experimental.mcp_server.exceptions import ( +from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError +from litellm.proxy.mcp_server.exceptions import ( MCPServerListError, MCPUpstreamAuthError, ) -from litellm.proxy._experimental.mcp_server.faults.traversal import iter_exception_tree -from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError +from litellm.proxy.mcp_server.faults.traversal import iter_exception_tree from litellm.types.llms.base import LiteLLMBaseModel ListFaultCategory: TypeAlias = Literal[ @@ -65,6 +67,16 @@ class ServerListFault(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) tag: ListFaultCategory status_code: int | None = None + sse_event_limit_bytes: PositiveInt | None = None + + @property + def public_message(self) -> str | None: + if self.sse_event_limit_bytes is None: + return None + return ( + f"Upstream MCP SSE event exceeded the {self.sse_event_limit_bytes} byte per-event limit. " + "Paginate tools/list responses so each event stays below the limit." + ) ServerOutcome: TypeAlias = ServerListOk | ServerListFault @@ -155,6 +167,18 @@ def raise_classified_list_failure( raise MCPServerListError(classify_list_exception(exc), server_name) from exc +def _sse_event_limit(exc: BaseException) -> int | None: + """The SDK replaces decoder exceptions with CONNECTION_CLOSED and a fixed diagnostic.""" + if not isinstance(exc, (httpx2.SSEError, MCPError)): + return None + if isinstance(exc, MCPError) and exc.error.code != CONNECTION_CLOSED: + return None + prefix: Final = "SSE stream failed: " if isinstance(exc, MCPError) else "" + message: Final = exc.error.message if isinstance(exc, MCPError) else str(exc) + matched: Final = re.fullmatch(prefix + r"Server-sent event exceeded the ([1-9][0-9]{0,18}) byte limit\.", message) + return int(matched[1]) if matched is not None else None + + def classify_list_exception(exc: BaseException) -> ServerListFault: """Classify a per-server listing failure into exactly one outcome. Total: an exception this function cannot recognize is the gateway's own fault (``internal``), never a re-raise.""" @@ -179,6 +203,11 @@ def classify_list_exception(exc: BaseException) -> ServerListFault: response: Final = _find_upstream_response(exc) if response is not None: return ServerListFault(tag="upstream_error", status_code=response.status_code) + sse_event_limit: Final = next( + (limit for error in iter_exception_tree(exc) if (limit := _sse_event_limit(error)) is not None), None + ) + if sse_event_limit is not None: + return ServerListFault(tag="upstream_error", sse_event_limit_bytes=sse_event_limit) if isinstance(exc, (httpx.TimeoutException, httpx2.TimeoutException)): return ServerListFault(tag="timeout") if isinstance(exc, (httpx.TransportError, httpx2.TransportError)): @@ -226,7 +255,7 @@ def rate_limit_retry_delay( ) -> float: if retry_after_seconds is not None: return min(retry_after_seconds, max_delay) - return min(max_delay, base_delay * 2**attempt * (1 + jitter)) + return min(max_delay, base_delay * 2.0**attempt * (1 + jitter)) T: Final = TypeVar("T") @@ -295,7 +324,7 @@ def listing_failed_outright(outcomes: Mapping[str, ServerOutcome]) -> bool: def outcome_wire_value(outcome: ServerOutcome) -> dict[str, object]: """The client-visible form of one outcome, for the tools/list result ``_meta`` and the REST - response: category plus status code only, never upstream prose or URLs.""" + response: category, status code and controlled diagnostics, never upstream prose or URLs.""" match outcome.tag: case "ok": return {"status": "ok", "tool_count": outcome.tool_count} @@ -303,6 +332,15 @@ def outcome_wire_value(outcome: ServerOutcome) -> dict[str, object]: return { "status": outcome.tag, **({"http_status": outcome.status_code} if outcome.status_code is not None else {}), + **( + { + "reason": "sse_event_too_large", + "limit_bytes": outcome.sse_event_limit_bytes, + "message": outcome.public_message, + } + if outcome.sse_event_limit_bytes is not None + else {} + ), } case _: assert_never(outcome.tag) diff --git a/litellm/proxy/_experimental/mcp_server/faults/render_oauth.py b/litellm/proxy/mcp_server/faults/render_oauth.py similarity index 96% rename from litellm/proxy/_experimental/mcp_server/faults/render_oauth.py rename to litellm/proxy/mcp_server/faults/render_oauth.py index 3ecf5310482..92fa457e476 100644 --- a/litellm/proxy/_experimental/mcp_server/faults/render_oauth.py +++ b/litellm/proxy/mcp_server/faults/render_oauth.py @@ -11,8 +11,8 @@ from typing import Final from fastapi.responses import JSONResponse from typing_extensions import assert_never -from litellm.proxy._experimental.mcp_server.faults.types import CallerRejected, UpstreamOAuthFault -from litellm.proxy._experimental.mcp_server.oauth_utils import TOKEN_NO_CACHE_HEADERS +from litellm.proxy.mcp_server.faults.types import CallerRejected, UpstreamOAuthFault +from litellm.proxy.mcp_server.oauth_utils import TOKEN_NO_CACHE_HEADERS def _gateway_rejected_description(code: str) -> str: diff --git a/litellm/proxy/_experimental/mcp_server/faults/traversal.py b/litellm/proxy/mcp_server/faults/traversal.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/faults/traversal.py rename to litellm/proxy/mcp_server/faults/traversal.py diff --git a/litellm/proxy/_experimental/mcp_server/faults/types.py b/litellm/proxy/mcp_server/faults/types.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/faults/types.py rename to litellm/proxy/mcp_server/faults/types.py diff --git a/litellm/proxy/_experimental/mcp_server/gateway_dcr_flow.py b/litellm/proxy/mcp_server/gateway_dcr_flow.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/gateway_dcr_flow.py rename to litellm/proxy/mcp_server/gateway_dcr_flow.py index 70e4bac01b5..ae74d878b36 100644 --- a/litellm/proxy/_experimental/mcp_server/gateway_dcr_flow.py +++ b/litellm/proxy/mcp_server/gateway_dcr_flow.py @@ -58,8 +58,15 @@ from typing_extensions import NotRequired, ReadOnly, TypedDict, assert_never from litellm._internal_context import with_service_target from litellm._logging import verbose_logger from litellm.caching.caching import DualCache -from litellm.proxy._experimental.mcp_server.catalog import catalog_operation, global_manager -from litellm.proxy._experimental.mcp_server.oauth_utils import ( +from litellm.proxy.common_utils.encrypt_decrypt_utils import ( + decrypt_value_helper, + encrypt_value_helper, +) +from litellm.proxy.common_utils.html_forms.native_client_consent import ( + render_native_client_consent_page, +) +from litellm.proxy.mcp_server.catalog import catalog_operation, global_manager +from litellm.proxy.mcp_server.oauth_utils import ( TOKEN_NO_CACHE_HEADERS, UPSTREAM_SCOPE_PREFIX, UpstreamScope, @@ -70,13 +77,13 @@ from litellm.proxy._experimental.mcp_server.oauth_utils import ( is_loopback_redirect_host, validate_redirect_uri_shape, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials.session_credentials import ( SessionRefreshOpened, SessionSigningConfigError, active_session_signing_keys, open_session_refresh_bearer, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import ( +from litellm.proxy.mcp_server.outbound_credentials.session_token import ( SESSION_ISSUER, SESSION_REFRESH_TTL_SECONDS, MintedSessionToken, @@ -91,13 +98,6 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token i open_session_refresh_token, open_session_token, ) -from litellm.proxy.common_utils.encrypt_decrypt_utils import ( - decrypt_value_helper, - encrypt_value_helper, -) -from litellm.proxy.common_utils.html_forms.native_client_consent import ( - render_native_client_consent_page, -) from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -624,7 +624,7 @@ def _is_aggregate_resource(request: Request, resource: str) -> bool: def _gateway_flow_server(name: str) -> MCPServer | None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # proxy import cycle + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # proxy import cycle global_mcp_server_manager, ) @@ -656,7 +656,7 @@ def resolve_scoped_resource_server(request: Request, resource: str | None) -> MC base: Final = canonicalize_url_identity(get_request_base_url(request)) if _is_aggregate_resource(request, resource) or not canonical.startswith(f"{base}/"): return None - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( # noqa: PLC0415 # proxy import cycle + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( # noqa: PLC0415 # proxy import cycle MCPRequestHandler, ) @@ -992,7 +992,7 @@ async def _flow_target( ) -> tuple[Literal["unscoped", "interactive", "m2m", "stale"], MCPServer | None]: if server_id is None: return "unscoped", None - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # import cycle + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # import cycle MCPServerManager, global_mcp_server_manager, ) diff --git a/litellm/proxy/_experimental/mcp_server/guardrail_translation/__init__.py b/litellm/proxy/mcp_server/guardrail_translation/__init__.py similarity index 88% rename from litellm/proxy/_experimental/mcp_server/guardrail_translation/__init__.py rename to litellm/proxy/mcp_server/guardrail_translation/__init__.py index ac06aa93c96..c4b52b745a3 100644 --- a/litellm/proxy/_experimental/mcp_server/guardrail_translation/__init__.py +++ b/litellm/proxy/mcp_server/guardrail_translation/__init__.py @@ -2,7 +2,7 @@ from typing import Final -from litellm.proxy._experimental.mcp_server.guardrail_translation.handler import ( +from litellm.proxy.mcp_server.guardrail_translation.handler import ( MCPGuardrailTranslationHandler, ) from litellm.types.utils import CallTypes diff --git a/litellm/proxy/_experimental/mcp_server/guardrail_translation/handler.py b/litellm/proxy/mcp_server/guardrail_translation/handler.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/guardrail_translation/handler.py rename to litellm/proxy/mcp_server/guardrail_translation/handler.py index d1a8084f4b2..28c51148da5 100644 --- a/litellm/proxy/_experimental/mcp_server/guardrail_translation/handler.py +++ b/litellm/proxy/mcp_server/guardrail_translation/handler.py @@ -13,7 +13,7 @@ every ``description`` string in the schema lead ``texts``, so a guardrail that blocks or masks them decides what the client gets to see in ``tools/list``. Note: For MCP tool definitions (schema) -> OpenAI tools=[], see -litellm.experimental_mcp_client.tools.transform_mcp_tool_to_openai_tool +litellm.mcp_client.tools.transform_mcp_tool_to_openai_tool when you have a full MCP Tool from list_tools. Here we only have the call payload (name + arguments) so we just build the tool definition. """ @@ -25,9 +25,9 @@ from fastapi import HTTPException from mcp.types import Tool as MCPTool from litellm._logging import verbose_proxy_logger -from litellm.experimental_mcp_client.tools import transform_mcp_tool_to_openai_tool from litellm.llms.base_llm.guardrail_translation.base_translation import BaseTranslation -from litellm.proxy._experimental.mcp_server.utils import ( +from litellm.mcp_client.tools import transform_mcp_tool_to_openai_tool +from litellm.proxy.mcp_server.utils import ( MAX_STRUCTURED_CONTENT_SCAN_DEPTH, JSONLeafPath, json_string_leaves, diff --git a/litellm/proxy/_experimental/mcp_server/id_jag_grant.py b/litellm/proxy/mcp_server/id_jag_grant.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/id_jag_grant.py rename to litellm/proxy/mcp_server/id_jag_grant.py index f2177df5a26..96f212e3bd7 100644 --- a/litellm/proxy/_experimental/mcp_server/id_jag_grant.py +++ b/litellm/proxy/mcp_server/id_jag_grant.py @@ -27,20 +27,20 @@ from pydantic import TypeAdapter, ValidationError from litellm._logging import verbose_proxy_logger from litellm.models.user import LiteLLM_UserTable -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( +from litellm.proxy._types import IdJagRequestingApp +from litellm.proxy.auth.handle_jwt import ID_JAG_TYP, AssertionRejection, JWTHandler +from litellm.proxy.mcp_server.gateway_dcr_flow import ( AssertionIdentity, ConsentTeam, SubjectIdentity, SubjectTokenRefusal, ) -from litellm.proxy._experimental.mcp_server.idp_token_exchange import ( +from litellm.proxy.mcp_server.idp_token_exchange import ( gateway_outage_refusal, log_line, read_token_exchange_prerequisites, ) -from litellm.proxy._experimental.mcp_server.oauth_utils import proxy_base_url_from_env -from litellm.proxy._types import IdJagRequestingApp -from litellm.proxy.auth.handle_jwt import ID_JAG_TYP, AssertionRejection, JWTHandler +from litellm.proxy.mcp_server.oauth_utils import proxy_base_url_from_env ID_JAG_REQUIRED_CLAIMS: Final = ("iss", "sub", "aud", "exp", "iat", "jti", "client_id") REJECTED_ASSERTION: Final = "assertion was rejected" @@ -395,10 +395,10 @@ class AssertionRedemption: async def redeem_id_jag_assertion( assertion: str, client_id: str, client_secret: str | None, request: Request ) -> AssertionIdentity | SubjectTokenRefusal: - from litellm.proxy._experimental.mcp_server.proxy_api_credentials import ( # noqa: PLC0415 # circular import at module load + from litellm.proxy.auth.auth_checks import get_user_object # noqa: PLC0415 # circular import at module load + from litellm.proxy.mcp_server.proxy_api_credentials import ( # noqa: PLC0415 # circular import at module load lookup_consent_teams_from_database, ) - from litellm.proxy.auth.auth_checks import get_user_object # noqa: PLC0415 # circular import at module load from litellm.proxy.proxy_server import ( # noqa: PLC0415 # rebound after startup, so read them per call jwt_handler, prisma_client, diff --git a/litellm/proxy/_experimental/mcp_server/idp_token_exchange.py b/litellm/proxy/mcp_server/idp_token_exchange.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/idp_token_exchange.py rename to litellm/proxy/mcp_server/idp_token_exchange.py index 5044a5bd3dc..c8ccdc9bca6 100644 --- a/litellm/proxy/_experimental/mcp_server/idp_token_exchange.py +++ b/litellm/proxy/mcp_server/idp_token_exchange.py @@ -13,10 +13,10 @@ from fastapi import HTTPException, Request from typing_extensions import assert_never from litellm._logging import verbose_proxy_logger -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import SubjectIdentity, SubjectTokenRefusal from litellm.proxy._types import JWTAuthBuilderResult, ProxyException from litellm.proxy.auth.handle_jwt import JWTAuthManager, JWTHandler from litellm.proxy.db.exception_handler import PrismaDBExceptionHandler +from litellm.proxy.mcp_server.gateway_dcr_flow import SubjectIdentity, SubjectTokenRefusal EXCHANGE_ROUTE: Final = "/token" REJECTED_SUBJECT_TOKEN: Final = "subject_token was rejected by the gateway's JWT auth" diff --git a/litellm/proxy/_experimental/mcp_server/interactions.py b/litellm/proxy/mcp_server/interactions.py similarity index 97% rename from litellm/proxy/_experimental/mcp_server/interactions.py rename to litellm/proxy/mcp_server/interactions.py index 42addcfb65b..24cedb57ef8 100644 --- a/litellm/proxy/_experimental/mcp_server/interactions.py +++ b/litellm/proxy/mcp_server/interactions.py @@ -25,9 +25,9 @@ from mcp.types import ( ) from pydantic import BaseModel, ConfigDict, Field, JsonValue, TypeAdapter, ValidationError -from litellm.proxy._experimental.mcp_server.contracts import OperationContext -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error -from litellm.proxy._experimental.mcp_server.state_tokens import StateTokenError, open_state, seal_state +from litellm.proxy.mcp_server.contracts import OperationContext +from litellm.proxy.mcp_server.outbound_credentials.result import Error +from litellm.proxy.mcp_server.state_tokens import StateTokenError, open_state, seal_state from litellm.types.mcp_server.mcp_server_manager import MCPServer diff --git a/litellm/proxy/_experimental/mcp_server/legacy_callbacks.py b/litellm/proxy/mcp_server/legacy_callbacks.py similarity index 87% rename from litellm/proxy/_experimental/mcp_server/legacy_callbacks.py rename to litellm/proxy/mcp_server/legacy_callbacks.py index 440b184e6ee..3d2f97492bb 100644 --- a/litellm/proxy/_experimental/mcp_server/legacy_callbacks.py +++ b/litellm/proxy/mcp_server/legacy_callbacks.py @@ -13,14 +13,14 @@ from mcp.types import ( ) from litellm.constants import MCP_CLIENT_TIMEOUT -from litellm.proxy._experimental.mcp_server.contracts import OperationContext -from litellm.proxy._experimental.mcp_server.mcp_context import get_active_mcp_request_ctx -from litellm.proxy._experimental.mcp_server.scope_challenge import ( +from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server.contracts import OperationContext +from litellm.proxy.mcp_server.mcp_context import get_active_mcp_request_ctx +from litellm.proxy.mcp_server.scope_challenge import ( OAuthScopeResponse, is_tool_call_request, scope_response_from_request, ) -from litellm.proxy._types import UserAPIKeyAuth class SamplingCallback(Protocol): @@ -43,7 +43,7 @@ def create_sampling_callback( client_ip: str | None = None, operation_context: OperationContext | None = None, ) -> SamplingCallback: - from litellm.proxy._experimental.mcp_server.server import get_active_auth_context + from litellm.proxy.mcp_server.server import get_active_auth_context auth: Final = get_active_auth_context() if operation_context is None and user_api_key_auth is None else None captured: Final = ( @@ -60,7 +60,7 @@ def create_sampling_callback( context: ClientRequestContext, params: CreateMessageRequestParams ) -> CreateMessageResult | CreateMessageResultWithTools | ErrorData: import litellm - from litellm.proxy._experimental.mcp_server.sampling_handler import handle_sampling_create_message + from litellm.proxy.mcp_server.sampling_handler import handle_sampling_create_message return await handle_sampling_create_message( context=context, @@ -75,7 +75,7 @@ def create_sampling_callback( def create_elicitation_callback(timeout: float | None = None) -> ElicitationCallback: - from litellm.proxy._experimental.mcp_server.server import get_active_mcp_session + from litellm.proxy.mcp_server.server import get_active_mcp_session downstream_session: Final = get_active_mcp_session() request: Final = get_active_mcp_request_ctx() @@ -94,7 +94,7 @@ def create_elicitation_callback(timeout: float | None = None) -> ElicitationCall code=-32602, message="A legacy upstream cannot resume input for a modern client; the operation may have partially completed", ) - from litellm.proxy._experimental.mcp_server.elicitation_handler import handle_elicitation_request + from litellm.proxy.mcp_server.elicitation_handler import handle_elicitation_request return await handle_elicitation_request( context=context, diff --git a/litellm/proxy/_experimental/mcp_server/mcp_context.py b/litellm/proxy/mcp_server/mcp_context.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/mcp_context.py rename to litellm/proxy/mcp_server/mcp_context.py diff --git a/litellm/proxy/_experimental/mcp_server/mcp_debug.py b/litellm/proxy/mcp_server/mcp_debug.py similarity index 96% rename from litellm/proxy/_experimental/mcp_server/mcp_debug.py rename to litellm/proxy/mcp_server/mcp_debug.py index bf74ea99e55..94b3d96a359 100644 --- a/litellm/proxy/_experimental/mcp_server/mcp_debug.py +++ b/litellm/proxy/mcp_server/mcp_debug.py @@ -124,7 +124,7 @@ from litellm.litellm_core_utils.secret_redaction import REDACTED, redact_string from litellm.litellm_core_utils.sensitive_data_masker import SensitiveDataMasker if TYPE_CHECKING: - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import AuthResolution + from litellm.proxy.mcp_server.outbound_credentials.types import AuthResolution # Header the client sends to opt into debug mode MCP_DEBUG_REQUEST_HEADER: Final = "x-litellm-mcp-debug" @@ -137,7 +137,7 @@ MCP_AUTH_DIAGNOSTICS_SCOPE_KEY: Final = "litellm.mcp.auth_diagnostics" def record_auth_resolution(server_id: str, source: AuthResolution) -> None: - from litellm.proxy._experimental.mcp_server.mcp_context import get_active_mcp_request_ctx + from litellm.proxy.mcp_server.mcp_context import get_active_mcp_request_ctx context: Final[object] = get_active_mcp_request_ctx() request: Final[object] = getattr(context, "request", None) @@ -155,7 +155,7 @@ class MCPAuthDiagnostics: self._outcomes = tuple(item for item in self._outcomes if item[0] != server_id) + ((server_id, resolution),) def resolution(self) -> str: - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import AuthResolution + from litellm.proxy.mcp_server.outbound_credentials.types import AuthResolution match self._outcomes: case (): @@ -166,7 +166,7 @@ class MCPAuthDiagnostics: return AuthResolution.multiple.value def headers(self) -> Mapping[str, str]: - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import AuthResolution + from litellm.proxy.mcp_server.outbound_credentials.types import AuthResolution if len(self._outcomes) <= 1: return MappingProxyType({"x-mcp-debug-auth-resolution": self.resolution()}) @@ -370,16 +370,16 @@ class MCPDebug: if not raw_headers or not MCPDebug.is_debug_enabled(raw_headers): return {} - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) server_url: str | None = None server_auth_type: str | None = None - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import AuthResolution + from litellm.proxy.mcp_server.outbound_credentials.types import AuthResolution auth_resolution: Final = AuthResolution.unresolved.value @@ -471,7 +471,7 @@ def _body_secret_values(request: httpx.Request | httpx2.Request) -> tuple[str, . body: Final = _JSON_BODY.validate_json(raw) except ValueError: return None - from litellm.proxy._experimental.mcp_server.utils import ( # noqa: PLC0415 # MCP utils imports clients; inspect bodies only after initialization + from litellm.proxy.mcp_server.utils import ( # noqa: PLC0415 # MCP utils imports clients; inspect bodies only after initialization json_string_leaves, ) @@ -613,7 +613,7 @@ def describe_upstream_response(response: httpx.Response | httpx2.Response) -> st def describe_upstream_http_failure(exc: BaseException) -> str | None: - from litellm.proxy._experimental.mcp_server.faults.traversal import ( # noqa: PLC0415 # fault package initialization imports the credential resolver + from litellm.proxy.mcp_server.faults.traversal import ( # noqa: PLC0415 # fault package initialization imports the credential resolver iter_exception_tree, ) diff --git a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py b/litellm/proxy/mcp_server/mcp_server_manager.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/mcp_server_manager.py rename to litellm/proxy/mcp_server/mcp_server_manager.py index 7eddf592262..8e613a8a6e8 100644 --- a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py +++ b/litellm/proxy/mcp_server/mcp_server_manager.py @@ -73,7 +73,12 @@ from litellm.constants import ( MCP_UPSTREAM_SESSION_SHUTDOWN_TIMEOUT_SECONDS, ) from litellm.exceptions import BlockedPiiEntityError, GuardrailRaisedException -from litellm.experimental_mcp_client.client import ( +from litellm.integrations.custom_guardrail import ( + _sync_guardrail_info_to_logging_obj, # pyright: ignore[reportPrivateUsage] - the same bridge @log_guardrail_information uses; reimplementing it here would fork the metadata-key logic +) +from litellm.litellm_core_utils.url_utils import SSRFError, async_safe_get +from litellm.llms.custom_httpx.http_handler import get_async_httpx_client +from litellm.mcp_client.client import ( SESSION_CLEANUP_TIMEOUT_MESSAGE, MCPClient, PersistentMCPSession, @@ -81,102 +86,114 @@ from litellm.experimental_mcp_client.client import ( strip_auth_scheme, to_basic_credentials, ) -from litellm.integrations.custom_guardrail import ( - _sync_guardrail_info_to_logging_obj, # pyright: ignore[reportPrivateUsage] - the same bridge @log_guardrail_information uses; reimplementing it here would fork the metadata-key logic +from litellm.proxy._types import ( + LiteLLM_MCPServerTable, + MCPAuthType, + MCPEnvVar, + MCPTransport, + MCPTransportType, + SpecialMCPServerNames, + UserAPIKeyAuth, + is_per_server_oauth_discovery_eligible, ) -from litellm.litellm_core_utils.url_utils import SSRFError, async_safe_get -from litellm.llms.custom_httpx.http_handler import get_async_httpx_client -from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( # noqa: F401 # legacy module exports +from litellm.proxy.agent_endpoints.auth.managed_authorization import managed_agent_policy +from litellm.proxy.auth.ip_address_utils import IPAddressUtils +from litellm.proxy.common_utils.encrypt_decrypt_utils import decrypt_value_helper +from litellm.proxy.common_utils.user_api_key_cache import get_management_object_ttl +from litellm.proxy.management_endpoints.sso.id_jag_assertion_capture import ( + id_jag_assertion_capture_gap_at_startup, +) +from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( # noqa: F401 # legacy module exports MCPRequestHandler, MCPServerAccess, _is_mcp_admitted_user_subject, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export is_mcp_admitted_user_subject, ) -from litellm.proxy._experimental.mcp_server.catalog import _configuration_identity, _DiscoveryCache, _DiscoveryKey -from litellm.proxy._experimental.mcp_server.contracts import OperationContext -from litellm.proxy._experimental.mcp_server.elicitation_handler import ( +from litellm.proxy.mcp_server.catalog import _configuration_identity, _DiscoveryCache, _DiscoveryKey +from litellm.proxy.mcp_server.contracts import OperationContext +from litellm.proxy.mcp_server.elicitation_handler import ( MCP_ELICITATION_AVAILABLE, ) -from litellm.proxy._experimental.mcp_server.exceptions import ( +from litellm.proxy.mcp_server.exceptions import ( MCPServerListError, MCPUpstreamAuthError, ) -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( +from litellm.proxy.mcp_server.faults.list_outcomes import ( ServerListFault, raise_classified_list_failure, retry_upstream_rate_limit, upstream_auth_challenge, upstream_insufficient_scope, ) -from litellm.proxy._experimental.mcp_server.interactions import bind_target -from litellm.proxy._experimental.mcp_server.legacy_callbacks import get_scope_response, has_active_mcp_request_context -from litellm.proxy._experimental.mcp_server.mcp_debug import describe_upstream_http_failure, record_auth_resolution -from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( +from litellm.proxy.mcp_server.interactions import bind_target +from litellm.proxy.mcp_server.legacy_callbacks import get_scope_response, has_active_mcp_request_context +from litellm.proxy.mcp_server.mcp_debug import describe_upstream_http_failure, record_auth_resolution +from litellm.proxy.mcp_server.oauth2_token_cache import ( MCPPerUserTokenCache, mcp_per_user_token_cache, ) -from litellm.proxy._experimental.mcp_server.oauth_utils import ( # noqa: F401 # legacy module exports +from litellm.proxy.mcp_server.oauth_utils import ( # noqa: F401 # legacy module exports _redact_mcp_resource_url, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export canonicalize_url_identity, get_byok_www_authenticate, needs_cimd_discovery, redact_mcp_resource_url, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials import ( Error, Ok, UpstreamCredentialProvider, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( +from litellm.proxy.mcp_server.outbound_credentials.adapter import ( raise_public, raise_token_exchange_challenge, to_server_spec, to_subject, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( InvalidatableOAuthTokenStore, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.per_user_oauth_store import ( +from litellm.proxy.mcp_server.outbound_credentials.per_user_oauth_store import ( LazyPerUserOAuthTokenStore, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchange_provider import ( +from litellm.proxy.mcp_server.outbound_credentials.token_exchange_provider import ( build_token_exchanger, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.types import ( DEFAULT_CREDENTIAL_HEADER, AuthResolution, IdJagConfig, PassthroughConfig, TokenExchangeConfig, ) -from litellm.proxy._experimental.mcp_server.result_conversion import ( +from litellm.proxy.mcp_server.result_conversion import ( WireCompat, complete_call_tool_result, handler_outcome, to_gateway_tool, ) -from litellm.proxy._experimental.mcp_server.sampling_handler import ( +from litellm.proxy.mcp_server.sampling_handler import ( MCP_SAMPLING_AVAILABLE, ) -from litellm.proxy._experimental.mcp_server.stdio_gate import ( +from litellm.proxy.mcp_server.stdio_gate import ( MCP_STDIO_DISABLED_MESSAGE, is_mcp_stdio_blocked, warn_if_mcp_stdio_blocked, ) -from litellm.proxy._experimental.mcp_server.tool_catalog_guard import ( +from litellm.proxy.mcp_server.tool_catalog_guard import ( CatalogAlert, apply_description_overrides, pin_tool_catalog, scan_tool_descriptions, ) -from litellm.proxy._experimental.mcp_server.upstream import ( +from litellm.proxy.mcp_server.upstream import ( passthrough_token_from_mcp_auth_header, prepare_upstream_client, resolve_upstream_auth, take_forwarded_authorization, to_server_spec_fail_closed, ) -from litellm.proxy._experimental.mcp_server.utils import ( +from litellm.proxy.mcp_server.utils import ( MCP_SERVERS_TARGET, MCP_TOOL_PREFIX_SEPARATOR, MCPMissingUserEnvVarsError, @@ -201,23 +218,6 @@ from litellm.proxy._experimental.mcp_server.utils import ( strip_known_server_prefix, validate_mcp_server_name, ) -from litellm.proxy._types import ( - LiteLLM_MCPServerTable, - MCPAuthType, - MCPEnvVar, - MCPTransport, - MCPTransportType, - SpecialMCPServerNames, - UserAPIKeyAuth, - is_per_server_oauth_discovery_eligible, -) -from litellm.proxy.agent_endpoints.auth.managed_authorization import managed_agent_policy -from litellm.proxy.auth.ip_address_utils import IPAddressUtils -from litellm.proxy.common_utils.encrypt_decrypt_utils import decrypt_value_helper -from litellm.proxy.common_utils.user_api_key_cache import get_management_object_ttl -from litellm.proxy.management_endpoints.sso.id_jag_assertion_capture import ( - id_jag_assertion_capture_gap_at_startup, -) from litellm.proxy.middleware.per_request_root_path_middleware import ( get_request_root_path, ) @@ -242,7 +242,7 @@ from litellm.types.utils import CallTypes if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj - from litellm.proxy._experimental.mcp_server.contracts import CatalogListRequest, CatalogListResult + from litellm.proxy.mcp_server.contracts import CatalogListRequest, CatalogListResult from litellm.types.mcp_server.mcp_toolset import MCPToolset try: @@ -488,6 +488,10 @@ class _AuthorizationServerMetadataPayload(TypedDict, total=False): token_endpoint_auth_methods_supported: Sequence[str] +def _mapping_value(source: Mapping[str, object], key: str, default: object) -> object: + return source.get(key, default) + + def _blank_to_none(value: str | None) -> str | None: """Collapse an absent, empty, or whitespace-only string to ``None``. @@ -1028,7 +1032,7 @@ async def _openapi_spec_health( ) -> tuple[Literal["healthy", "unhealthy", "unknown"], str | None]: """Check specification availability, not upstream operations or user credentials.""" from litellm.llms.custom_httpx.http_handler import HTTPResponseLimitError - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import load_openapi_spec_async + from litellm.proxy.mcp_server.openapi_to_mcp_generator import load_openapi_spec_async if not spec_path.startswith(("http://", "https://")): return "unknown", "OpenAPI servers have no protocol-level health probe" @@ -1460,7 +1464,7 @@ async def _resolve_byok_mcp_auth_header( if not mcp_server.is_byok: return mcp_auth_header - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( _check_byok_credential, _get_byok_credential, ) @@ -1831,7 +1835,7 @@ def _create_sampling_callback( ): if not MCP_SAMPLING_AVAILABLE: return None - from litellm.proxy._experimental.mcp_server.legacy_callbacks import create_sampling_callback + from litellm.proxy.mcp_server.legacy_callbacks import create_sampling_callback return create_sampling_callback(user_api_key_auth, raw_headers, client_ip, operation_context) @@ -1839,7 +1843,7 @@ def _create_sampling_callback( def _create_elicitation_callback(timeout: float | None = None): if not MCP_ELICITATION_AVAILABLE: return None - from litellm.proxy._experimental.mcp_server.legacy_callbacks import create_elicitation_callback + from litellm.proxy.mcp_server.legacy_callbacks import create_elicitation_callback return create_elicitation_callback(timeout=timeout) @@ -2031,7 +2035,7 @@ class MCPServerManager: self._template_discovery_cache = _DiscoveryCache[ListResourceTemplatesResult]( discovery_ttl, discovery_clock, TypeAdapter(ListResourceTemplatesResult) ) - from litellm.proxy._experimental.mcp_server.catalog import CatalogSnapshots + from litellm.proxy.mcp_server.catalog import CatalogSnapshots self.catalog = CatalogSnapshots(self) self.registry: dict[str, MCPServer] = {} @@ -2757,7 +2761,9 @@ class MCPServerManager: server_id=server_id, name=name_for_prefix, protocol_version=TypeAdapter(MCPUpstreamProtocol).validate_python( - server_config.get("protocol_version", mcp_info.get("protocol_version", "auto")) + _mapping_value( + server_config, "protocol_version", _mapping_value(mcp_info, "protocol_version", "auto") + ) ), alias=alias, server_name=server_name, @@ -2881,7 +2887,7 @@ class MCPServerManager: """Overlay each config-declared server's persisted DCR client (from the server-scoped store) onto its in-memory object so token refresh authenticates after a restart. A best-effort no-op when the DB is unreachable at config-load time.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( # noqa: PLC0415 # circular import + from litellm.proxy.mcp_server.discoverable_endpoints import ( # noqa: PLC0415 # circular import hydrate_config_server_dcr_client, ) @@ -2913,16 +2919,16 @@ class MCPServerManager: server: The MCPServer instance to register tools for base_url: Base URL for API calls """ - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( build_input_schema, create_tool_function, load_openapi_spec_async, resolve_operation_params, ) - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( get_base_url as get_openapi_base_url, ) - from litellm.proxy._experimental.mcp_server.tool_registry import ( + from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) @@ -3055,7 +3061,7 @@ class MCPServerManager: self.remove_server_tool_routing(server) def remove_server_tool_routing(self, server: MCPServer) -> None: - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry prefix_root: Final = normalize_server_name(get_server_prefix(server)) if server.spec_path and prefix_root: @@ -3122,7 +3128,7 @@ class MCPServerManager: ) -> _EnvVarList | None: env_vars_list: Final = _deserialize_json_list(getattr(mcp_server, "env_vars", None)) if env_vars_are_encrypted: - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 decrypt_global_env_var_values, ) @@ -3572,7 +3578,7 @@ class MCPServerManager: return [] try: - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 get_active_submitted_mcp_server_ids_for_user, ) from litellm.proxy.proxy_server import prisma_client, user_api_key_cache @@ -3829,7 +3835,7 @@ class MCPServerManager: one silently renames the tool when a native name happens to begin with it (``greyhound_internal_events`` on a server prefixed ``greyhound``). """ - from litellm.proxy._experimental.mcp_server.toolset_db import list_mcp_toolsets + from litellm.proxy.mcp_server.toolset_db import list_mcp_toolsets from litellm.proxy.proxy_server import prisma_client, user_api_key_cache if not toolset_ids or prisma_client is None: @@ -3927,7 +3933,7 @@ class MCPServerManager: return MCPToolset(**cached) return cached - from litellm.proxy._experimental.mcp_server.toolset_db import ( + from litellm.proxy.mcp_server.toolset_db import ( get_mcp_toolset_by_name, ) @@ -4285,7 +4291,7 @@ class MCPServerManager: "is configured. Connect a database to your proxy to use per-user " "MCP env vars." ) - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 get_user_env_vars, ) @@ -4449,7 +4455,7 @@ class MCPServerManager: record_listing: bool = False, listing_updates: ExitStack | None = None, ) -> ListToolsResult: - from litellm.proxy._experimental.mcp_server.tool_registry import ( + from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) @@ -4656,7 +4662,7 @@ class MCPServerManager: self._template_discovery_cache.invalidate(server_id) def invalidate_server_definition_caches(self, server_id: str) -> None: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( # noqa: PLC0415 # lazy: discoverable_endpoints lazily imports this module's manager singleton + from litellm.proxy.mcp_server.discoverable_endpoints import ( # noqa: PLC0415 # lazy: discoverable_endpoints lazily imports this module's manager singleton invalidate_oauth_metadata_cache, ) @@ -5824,7 +5830,7 @@ class MCPServerManager: Returns: List of tools with prefixed names """ - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry if register_bare_names and listing_updates is not None: listing_updates.callback(self._create_prefixed_tools, tools, server, add_prefix=add_prefix) @@ -5936,7 +5942,7 @@ class MCPServerManager: deriving the spellings routing accepts, never by stripping the entry, which would cut a second boundary out of a native name that opens with the server prefix. """ - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( server_applies_tool_allowlist, ) @@ -5999,7 +6005,7 @@ class MCPServerManager: Raises: HTTPException: If tool is not allowed for this key/team """ - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -6044,7 +6050,7 @@ class MCPServerManager: """ from mcp.types import TextContent - from litellm.proxy._experimental.mcp_server.tool_registry import ( + from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) @@ -6862,7 +6868,7 @@ class MCPServerManager: return oauth2_headers try: - from litellm.proxy._experimental.mcp_server.operations import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.operations import ( # noqa: PLC0415 _get_user_oauth_extra_headers_from_db, ) @@ -7102,7 +7108,7 @@ class MCPServerManager: ) async def _call_openapi_via_handler(): - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( request_auth_header, request_extra_headers, request_resolved_auth_headers, @@ -7201,7 +7207,7 @@ class MCPServerManager: Returns: MCPServer if found, None otherwise """ - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry registered_tool: Final = global_mcp_tool_registry.get_tool(tool_name) if registered_tool is not None: diff --git a/litellm/proxy/_experimental/mcp_server/oauth2_flow_backfill.py b/litellm/proxy/mcp_server/oauth2_flow_backfill.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/oauth2_flow_backfill.py rename to litellm/proxy/mcp_server/oauth2_flow_backfill.py index 71281b276fa..1ef67df498f 100644 --- a/litellm/proxy/_experimental/mcp_server/oauth2_flow_backfill.py +++ b/litellm/proxy/mcp_server/oauth2_flow_backfill.py @@ -42,7 +42,7 @@ from typing import Final, Literal, Protocol from pydantic import JsonValue from litellm._logging import verbose_proxy_logger -from litellm.proxy._experimental.mcp_server.db import ( # noqa: F401 # legacy module exports +from litellm.proxy.mcp_server.db import ( # noqa: F401 # legacy module exports _decode_oauth_payload, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export decode_oauth_payload, decrypt_credentials, diff --git a/litellm/proxy/_experimental/mcp_server/oauth2_token_cache.py b/litellm/proxy/mcp_server/oauth2_token_cache.py similarity index 96% rename from litellm/proxy/_experimental/mcp_server/oauth2_token_cache.py rename to litellm/proxy/mcp_server/oauth2_token_cache.py index 6d4fefcdb6c..1e6e83c0f4b 100644 --- a/litellm/proxy/_experimental/mcp_server/oauth2_token_cache.py +++ b/litellm/proxy/mcp_server/oauth2_token_cache.py @@ -11,6 +11,7 @@ from collections.abc import Mapping from typing import TYPE_CHECKING, Final import httpx +from pydantic import TypeAdapter from litellm._internal_context import with_service_target from litellm._logging import verbose_logger @@ -25,22 +26,24 @@ from litellm.constants import ( MCP_PER_USER_TOKEN_REDIS_KEY_PREFIX, ) from litellm.llms.custom_httpx.http_handler import get_async_httpx_client -from litellm.proxy._experimental.mcp_server.oauth_utils import ( - build_upstream_oauth2_token_request, - resolve_upstream_resource, -) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import OAuthToken -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_cache_codec import OAuthTokenCacheCodec -from litellm.proxy._experimental.mcp_server.utils import MCP_OAUTH_TOKENS_TARGET from litellm.proxy.common_utils.encrypt_decrypt_utils import ( decrypt_value_helper, encrypt_value_helper, ) +from litellm.proxy.mcp_server.oauth_utils import ( + build_upstream_oauth2_token_request, + resolve_upstream_resource, +) +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import OAuthToken +from litellm.proxy.mcp_server.outbound_credentials.token_cache_codec import OAuthTokenCacheCodec +from litellm.proxy.mcp_server.utils import MCP_OAUTH_TOKENS_TARGET from litellm.types.llms.custom_http import httpxSpecialProvider if TYPE_CHECKING: from litellm.types.mcp_server.mcp_server_manager import MCPServer +_DECODED_JSON: Final = TypeAdapter(object) + class MCPOAuth2TokenCache(InMemoryCache): """ @@ -160,7 +163,7 @@ class MCPOAuth2TokenCache(InMemoryCache): f"failed with status {exc.response.status_code}" ) from exc - body: Final = response.json() + body: Final = _DECODED_JSON.validate_python(response.json()) if not isinstance(body, dict): raise ValueError( diff --git a/litellm/proxy/_experimental/mcp_server/oauth_identity_binding.py b/litellm/proxy/mcp_server/oauth_identity_binding.py similarity index 97% rename from litellm/proxy/_experimental/mcp_server/oauth_identity_binding.py rename to litellm/proxy/mcp_server/oauth_identity_binding.py index c31560a9f63..6fdda498d50 100644 --- a/litellm/proxy/_experimental/mcp_server/oauth_identity_binding.py +++ b/litellm/proxy/mcp_server/oauth_identity_binding.py @@ -18,6 +18,7 @@ from typing import Final, Literal, Protocol, TypeAlias import jwt from fastapi import HTTPException from jwt.types import Options +from pydantic import TypeAdapter from typing_extensions import assert_never from litellm._logging import verbose_logger @@ -38,6 +39,7 @@ _ALLOWED_ID_TOKEN_ALGORITHMS: Final = ( "PS512", ) _JWKS_CACHE_TTL_SECONDS: Final = 3600 +_DECODED_JSON: Final = TypeAdapter(object) _jwks_cache: Final = InMemoryCache(default_ttl=_JWKS_CACHE_TTL_SECONDS) JwksFetcher: TypeAlias = Callable[ @@ -103,7 +105,7 @@ async def _fetch_issuer_jwks(binding: MCPOAuthIdentityBinding) -> Sequence[Mappi client: Final = get_async_httpx_client(llm_provider=httpxSpecialProvider.Oauth2Check) response: Final = await client.get(jwks_url) response.raise_for_status() - document: Final = response.json() + document: Final = _DECODED_JSON.validate_python(response.json()) keys: Final = document.get("keys") if isinstance(document, dict) else None if not isinstance(keys, list): raise TypeError(f"JWKS document at {jwks_url} has no 'keys' array") @@ -116,7 +118,7 @@ async def _discover_jwks_url(issuer: str) -> str: client: Final = get_async_httpx_client(llm_provider=httpxSpecialProvider.Oauth2Check) response: Final = await client.get(discovery_url) response.raise_for_status() - metadata: Final = response.json() + metadata: Final = _DECODED_JSON.validate_python(response.json()) jwks_uri: Final = metadata.get("jwks_uri") if isinstance(metadata, dict) else None if not isinstance(jwks_uri, str) or not jwks_uri: raise ValueError(f"OIDC discovery at {discovery_url} returned no jwks_uri") @@ -182,7 +184,7 @@ def _upstream_principal( async def _load_caller_principal(litellm_user_id: str, binding: MCPOAuthIdentityBinding) -> str | None: if binding.caller_field == "user_id": return litellm_user_id - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.bridge_token_flow import ( # noqa: PLC0415 # inline import avoids a module-load circular import load_active_user_by_id, ) @@ -196,7 +198,7 @@ async def _load_stored_refresh_token( litellm_user_id: str, server_id: str, binding: MCPOAuthIdentityBinding ) -> VerifiedRefreshToken | None: try: - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 # keep database imports lazy + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 # keep database imports lazy get_user_oauth_credential, ) from litellm.proxy.utils import get_prisma_client_or_throw # noqa: PLC0415 # keep database imports lazy diff --git a/litellm/proxy/_experimental/mcp_server/oauth_issuer_stamp_backfill.py b/litellm/proxy/mcp_server/oauth_issuer_stamp_backfill.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/oauth_issuer_stamp_backfill.py rename to litellm/proxy/mcp_server/oauth_issuer_stamp_backfill.py index eb02ed64e91..c417187396f 100644 --- a/litellm/proxy/_experimental/mcp_server/oauth_issuer_stamp_backfill.py +++ b/litellm/proxy/mcp_server/oauth_issuer_stamp_backfill.py @@ -40,8 +40,8 @@ from typing import Final, Protocol from urllib.parse import urlparse from litellm._logging import verbose_proxy_logger -from litellm.proxy._experimental.mcp_server.oauth_utils import canonicalize_url_identity from litellm.proxy.db.db_span import db_span +from litellm.proxy.mcp_server.oauth_utils import canonicalize_url_identity from litellm.proxy.utils import PrismaClient # The actor the removed discovery write-back stamped rows with. diff --git a/litellm/proxy/_experimental/mcp_server/oauth_utils.py b/litellm/proxy/mcp_server/oauth_utils.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/oauth_utils.py rename to litellm/proxy/mcp_server/oauth_utils.py index 133bad780bf..76343f77e32 100644 --- a/litellm/proxy/_experimental/mcp_server/oauth_utils.py +++ b/litellm/proxy/mcp_server/oauth_utils.py @@ -14,15 +14,15 @@ from fastapi import HTTPException, Request from starlette.types import Scope from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.auth.token_endpoint_auth import ( +from litellm.proxy.auth.ip_address_utils import IPAddressUtils +from litellm.proxy.mcp_server.auth.token_endpoint_auth import ( TokenEndpointClientAuth, build_token_endpoint_client_auth, normalize_token_endpoint_auth_method, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( GOOGLE_REFRESH_TOKEN_PARAMS, ) -from litellm.proxy.auth.ip_address_utils import IPAddressUtils from litellm.proxy.middleware.per_request_root_path_middleware import get_request_root_path if TYPE_CHECKING: diff --git a/litellm/proxy/_experimental/mcp_server/openapi_to_mcp_generator.py b/litellm/proxy/mcp_server/openapi_to_mcp_generator.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/openapi_to_mcp_generator.py rename to litellm/proxy/mcp_server/openapi_to_mcp_generator.py index f0353f309a9..96d178dbeb1 100644 --- a/litellm/proxy/_experimental/mcp_server/openapi_to_mcp_generator.py +++ b/litellm/proxy/mcp_server/openapi_to_mcp_generator.py @@ -16,7 +16,7 @@ import httpx from typing_extensions import ReadOnly, Required from litellm.llms.custom_httpx.http_handler import MaskedHTTPStatusError -from litellm.proxy._experimental.mcp_server.exceptions import ( +from litellm.proxy.mcp_server.exceptions import ( MCPOpenApiUpstreamError, MCPUpstreamAuthError, ) @@ -54,8 +54,8 @@ from litellm.llms.custom_httpx.http_handler import ( header_value, httpxSpecialProvider, ) -from litellm.proxy._experimental.mcp_server.tool_outcome import JsonResult, TextResult, parse_http_body -from litellm.proxy._experimental.mcp_server.tool_registry import ( +from litellm.proxy.mcp_server.tool_outcome import JsonResult, TextResult, parse_http_body +from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) from litellm.types.mcp import MCPAuthType, credential_redirect_hook, custom_credential_slot @@ -442,7 +442,7 @@ def _merge_openapi_tool_request_headers( the MCP caller (allowlisted by ``MCPServer.extra_headers``) This matches the existing MCP invariant in - :func:`litellm.proxy._experimental.mcp_server.utils.merge_mcp_headers` + :func:`litellm.proxy.mcp_server.utils.merge_mcp_headers` and the managed MCP path, where ``static_headers`` always wins over caller-forwarded headers. Keeping the same precedence here prevents an authenticated caller from overriding an operator-configured value @@ -542,11 +542,11 @@ def create_tool_function( """ effective_headers: Final = _merge_openapi_tool_request_headers(headers) if auth_type is not None: - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( raise_public, validate_static_credential, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error, Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Error, Ok match validate_static_credential(auth_type, effective_headers, upstream_token_header, headers or ()): case Error(error): diff --git a/litellm/proxy/_experimental/mcp_server/operations.py b/litellm/proxy/mcp_server/operations.py similarity index 97% rename from litellm/proxy/_experimental/mcp_server/operations.py rename to litellm/proxy/mcp_server/operations.py index 39e882fcab0..763e3578a96 100644 --- a/litellm/proxy/_experimental/mcp_server/operations.py +++ b/litellm/proxy/mcp_server/operations.py @@ -56,40 +56,51 @@ from litellm.constants import ( MCP_TOOL_LISTING_TIMEOUT, ) from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj -from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( +from litellm.proxy._types import ( + UserAPIKeyAuth, +) +from litellm.proxy.common_utils.auth_cache_invalidation_pubsub import ( + publish_auth_cache_invalidation, +) +from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError +from litellm.proxy.litellm_pre_call_utils import ( + LiteLLMProxyRequestSetup, + get_chain_id_from_headers, +) +from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) -from litellm.proxy._experimental.mcp_server.byok_credential_cache import ( +from litellm.proxy.mcp_server.byok_credential_cache import ( byok_credential_cache, byok_credential_cache_key, cache_byok_credential, get_cached_byok_credential, ) -from litellm.proxy._experimental.mcp_server.capabilities import ( +from litellm.proxy.mcp_server.capabilities import ( build_discovery, configured_versions, disabled_capabilities, enabled_gateway_operations, ) -from litellm.proxy._experimental.mcp_server.catalog import catalog_operation, global_manager -from litellm.proxy._experimental.mcp_server.contracts import ( +from litellm.proxy.mcp_server.catalog import catalog_operation, global_manager +from litellm.proxy.mcp_server.contracts import ( AuthorizedToolCall, OperationContext, ProgressCallback, ) -from litellm.proxy._experimental.mcp_server.db import OAuthCredentialPayload -from litellm.proxy._experimental.mcp_server.exceptions import ( +from litellm.proxy.mcp_server.db import OAuthCredentialPayload +from litellm.proxy.mcp_server.exceptions import ( MCPToolResultError, MCPUpstreamAuthError, ) -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( +from litellm.proxy.mcp_server.faults.list_outcomes import ( AggregateToolListing, ServerListOk, ServerOutcome, classify_list_exception, outcome_wire_value, ) -from litellm.proxy._experimental.mcp_server.interactions import ( +from litellm.proxy.mcp_server.interactions import ( BoundInputRequiredResult, ContinuationState, InteractionOperation, @@ -97,8 +108,8 @@ from litellm.proxy._experimental.mcp_server.interactions import ( seal_continuation, target_digest, ) -from litellm.proxy._experimental.mcp_server.legacy_callbacks import get_scope_response -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: F401 # legacy module exports +from litellm.proxy.mcp_server.legacy_callbacks import get_scope_response +from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: F401 # legacy module exports MCPServerManager, _caller_authorization_fans_out, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export _client_forwarded_authorization_headers, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export @@ -111,12 +122,12 @@ from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: resolve_openapi_tool_auth, should_strip_caller_authorization, ) -from litellm.proxy._experimental.mcp_server.oauth_utils import ( # noqa: F401 # legacy module exports +from litellm.proxy.mcp_server.oauth_utils import ( # noqa: F401 # legacy module exports _redact_mcp_resource_url, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export get_byok_www_authenticate, redact_mcp_resource_url, ) -from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( # noqa: F401 # legacy module exports +from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( # noqa: F401 # legacy module exports _request_auth_header, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export _request_extra_headers, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export _request_resolved_auth_headers, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export @@ -124,16 +135,16 @@ from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( # request_extra_headers, request_resolved_auth_headers, ) -from litellm.proxy._experimental.mcp_server.result_conversion import ( +from litellm.proxy.mcp_server.result_conversion import ( WireCompat, complete_call_tool_result, handler_outcome, to_call_tool_result, ) -from litellm.proxy._experimental.mcp_server.tool_registry import ( +from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) -from litellm.proxy._experimental.mcp_server.utils import ( +from litellm.proxy.mcp_server.utils import ( MCP_TOOL_PREFIX_SEPARATOR, MCPMissingUserEnvVarsError, add_server_prefix_to_name, @@ -148,20 +159,9 @@ from litellm.proxy._experimental.mcp_server.utils import ( split_server_prefix_from_name, strip_known_server_prefix, ) -from litellm.proxy._experimental.mcp_server.utils import ( +from litellm.proxy.mcp_server.utils import ( server_answers_to as _server_answers_to, ) -from litellm.proxy._types import ( - UserAPIKeyAuth, -) -from litellm.proxy.common_utils.auth_cache_invalidation_pubsub import ( - publish_auth_cache_invalidation, -) -from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError -from litellm.proxy.litellm_pre_call_utils import ( - LiteLLMProxyRequestSetup, - get_chain_id_from_headers, -) from litellm.types.mcp import ( DEFAULT_CREDENTIAL_HEADER, MCP_LEGACY_VERSIONS, @@ -426,7 +426,7 @@ async def _dispatch_virtual_mcp_tool( the caller falls through to normal tool routing. """ from litellm.llms.litellm_proxy.skills.skill_search import DEFAULT_SKILL_SEARCH_TOP_K - from litellm.proxy._experimental.mcp_server.tool_search import ( + from litellm.proxy.mcp_server.tool_search import ( AGENT_SEARCH_TOOL_NAME, DEFAULT_AGENT_SEARCH_TOP_K, MCP_PROXY_CALL_TOOL_NAME, @@ -799,7 +799,7 @@ def filter_tools_by_allowed_tools( Returns: Filtered list of tools """ - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( server_applies_tool_allowlist, ) @@ -911,7 +911,7 @@ def _client_has_per_server_auth_header( """ if not mcp_server_auth_headers: return False - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( lookup_mcp_server_auth_in_headers, ) @@ -960,7 +960,7 @@ async def _get_user_oauth_extra_headers_from_db( """ if server.auth_type != MCPAuth.oauth2 or user_api_key_auth is None: return None - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 resolve_user_oauth_access_token, ) @@ -981,7 +981,7 @@ async def _prefetch_oauth_creds_for_user( if not user_id: return {} try: - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 list_user_oauth_credentials, ) from litellm.proxy.utils import get_prisma_client_or_throw # noqa: PLC0415 @@ -1015,7 +1015,7 @@ def _prepare_mcp_server_headers( """ server_auth_header: dict[str, str] | str | None = None if mcp_server_auth_headers: - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( lookup_mcp_server_auth_in_headers, ) @@ -1182,8 +1182,8 @@ async def find_mcp_proxy_tool( ) -> MCPTool | None: """Resolve an /mcp/proxy tool_id against the caller's catalog, returning as soon as the server that owns it has listed instead of waiting for every allowed server.""" - from litellm.proxy._experimental.mcp_server.catalog import get_filtered_server_tools - from litellm.proxy._experimental.mcp_server.tool_search import mcp_proxy_tool_id + from litellm.proxy.mcp_server.catalog import get_filtered_server_tools + from litellm.proxy.mcp_server.tool_search import mcp_proxy_tool_id allowed_mcp_servers: Final = await _get_allowed_mcp_servers( user_api_key_auth=user_api_key_auth, @@ -1366,7 +1366,7 @@ async def _get_tools_from_mcp_servers( await _prefetch_oauth_creds_for_user(user_api_key_auth) if _has_oauth2_server else {} ) - from litellm.proxy._experimental.mcp_server.catalog import get_filtered_server_tools + from litellm.proxy.mcp_server.catalog import get_filtered_server_tools context: Final = OperationContext( _caller=user_api_key_auth, @@ -1413,7 +1413,7 @@ async def _get_tools_from_mcp_servers( }, ) else: - from litellm.proxy._experimental.mcp_server.catalog import aggregate_gateway_tools + from litellm.proxy.mcp_server.catalog import aggregate_gateway_tools aggregated = await aggregate_gateway_tools( context, @@ -1912,7 +1912,7 @@ async def _get_byok_credential( if cached is not None: return cached.credential - from litellm.proxy._experimental.mcp_server.db import get_user_credential + from litellm.proxy.mcp_server.db import get_user_credential from litellm.proxy.proxy_server import prisma_client if prisma_client is None: @@ -1970,7 +1970,7 @@ async def _check_byok_credential( ) return - from litellm.proxy._experimental.mcp_server.db import get_user_credential + from litellm.proxy.mcp_server.db import get_user_credential from litellm.proxy.proxy_server import prisma_client if prisma_client is None: @@ -2032,7 +2032,7 @@ def _challenge_missing_token_exchange_subject( return if global_mcp_server_manager.extract_subject_token(oauth2_headers, raw_headers, user_api_key_auth) is not None: return - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 # lazy: adapter pulls MCP subgraph + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 # lazy: adapter pulls MCP subgraph raise_token_exchange_challenge, ) from litellm.proxy.middleware.per_request_root_path_middleware import ( # noqa: PLC0415 # lazy: middleware imports proxy utils @@ -3262,7 +3262,7 @@ async def _execute_handle_list_tools( ) from mcp.types import Tool - from litellm.proxy._experimental.mcp_server.tool_search import ( + from litellm.proxy.mcp_server.tool_search import ( get_mcp_proxy_tool_definitions, get_virtual_tool_definitions, ) @@ -3280,8 +3280,8 @@ async def _execute_handle_list_tools( raise MCPError(code=INVALID_PARAMS, message="Invalid pagination cursor; start a fresh listing") return ListToolsResult(tools=[Tool.model_validate(d) for d in get_virtual_tool_definitions()]) - from litellm.proxy._experimental.mcp_server.catalog import list_gateway_catalog - from litellm.proxy._experimental.mcp_server.server_resolution import MCPServerTargetCatalog + from litellm.proxy.mcp_server.catalog import list_gateway_catalog + from litellm.proxy.mcp_server.server_resolution import MCPServerTargetCatalog catalog: Final = MCPServerTargetCatalog( global_mcp_server_manager, @@ -3310,7 +3310,7 @@ async def _execute_handle_list_tools( async def _discover_tools_listing( context: OperationContext, host_progress_callback: ProgressCallback | None ) -> ListToolsResult: - from litellm.proxy._experimental.mcp_server.catalog import ToolListingFailedOutright + from litellm.proxy.mcp_server.catalog import ToolListingFailedOutright try: return await _execute_handle_list_tools( @@ -3487,8 +3487,8 @@ async def _execute_list_prompts( from mcp.shared.exceptions import MCPError from mcp.types import INVALID_PARAMS, INVALID_REQUEST - from litellm.proxy._experimental.mcp_server.catalog import list_gateway_catalog - from litellm.proxy._experimental.mcp_server.server_resolution import MCPServerTargetCatalog + from litellm.proxy.mcp_server.catalog import list_gateway_catalog + from litellm.proxy.mcp_server.server_resolution import MCPServerTargetCatalog if context.mcp_proxy_mode: _reject_mcp_proxy_operation() @@ -3551,8 +3551,8 @@ async def _execute_list_resources( from mcp.shared.exceptions import MCPError from mcp.types import INVALID_PARAMS, INVALID_REQUEST - from litellm.proxy._experimental.mcp_server.catalog import list_gateway_catalog - from litellm.proxy._experimental.mcp_server.server_resolution import MCPServerTargetCatalog + from litellm.proxy.mcp_server.catalog import list_gateway_catalog + from litellm.proxy.mcp_server.server_resolution import MCPServerTargetCatalog if context.mcp_proxy_mode: _reject_mcp_proxy_operation() @@ -3581,8 +3581,8 @@ async def _execute_list_resource_templates( from mcp.shared.exceptions import MCPError from mcp.types import INVALID_PARAMS, INVALID_REQUEST - from litellm.proxy._experimental.mcp_server.catalog import list_gateway_catalog - from litellm.proxy._experimental.mcp_server.server_resolution import MCPServerTargetCatalog + from litellm.proxy.mcp_server.catalog import list_gateway_catalog + from litellm.proxy.mcp_server.server_resolution import MCPServerTargetCatalog if context.mcp_proxy_mode: _reject_mcp_proxy_operation() @@ -3809,7 +3809,7 @@ class GatewayOperations: ) try: results: Final = await asyncio.gather(*tasks) - from litellm.proxy._experimental.mcp_server.subscriptions import subscription_capabilities + from litellm.proxy.mcp_server.subscriptions import subscription_capabilities async def discover_notifications() -> tuple[frozenset[str], ServerCapabilities]: remaining: Final = deadline - time.monotonic() diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/__init__.py b/litellm/proxy/mcp_server/outbound_credentials/__init__.py similarity index 85% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/__init__.py rename to litellm/proxy/mcp_server/outbound_credentials/__init__.py index 3260603c3ca..3d5fcf08d8e 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/__init__.py +++ b/litellm/proxy/mcp_server/outbound_credentials/__init__.py @@ -8,19 +8,19 @@ CredError]``) rather than raised, so every seam is total. Nothing here is wired request path yet. """ -from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( +from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( NoOpAuth, StaticHeaderAuth, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.resolver import ( +from litellm.proxy.mcp_server.outbound_credentials.resolver import ( UpstreamCredentialProvider, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( +from litellm.proxy.mcp_server.outbound_credentials.result import ( Error, Ok, Result, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.types import ( DEFAULT_CREDENTIAL_HEADER, Ambient, ApiKeyConfig, diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/adapter.py b/litellm/proxy/mcp_server/outbound_credentials/adapter.py similarity index 97% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/adapter.py rename to litellm/proxy/mcp_server/outbound_credentials/adapter.py index 37404ceece8..1aac70cd847 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/adapter.py +++ b/litellm/proxy/mcp_server/outbound_credentials/adapter.py @@ -20,11 +20,11 @@ from fastapi import HTTPException from pydantic import SecretStr from typing_extensions import assert_never -from litellm.experimental_mcp_client.client import MCPClient, strip_auth_scheme, to_basic_credentials -from litellm.proxy._experimental.mcp_server.exceptions import TOKEN_EXCHANGE_SUBJECT_ERROR, MCPServerURLCredentialsError -from litellm.proxy._experimental.mcp_server.oauth_utils import resolve_upstream_resource -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error, Ok, Result -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.mcp_client.client import MCPClient, strip_auth_scheme, to_basic_credentials +from litellm.proxy.mcp_server.exceptions import TOKEN_EXCHANGE_SUBJECT_ERROR, MCPServerURLCredentialsError +from litellm.proxy.mcp_server.oauth_utils import resolve_upstream_resource +from litellm.proxy.mcp_server.outbound_credentials.result import Error, Ok, Result +from litellm.proxy.mcp_server.outbound_credentials.types import ( DEFAULT_CREDENTIAL_HEADER, ApiKeyConfig, AuthorizationCodeConfig, diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/authz_code_refresher.py b/litellm/proxy/mcp_server/outbound_credentials/authz_code_refresher.py similarity index 94% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/authz_code_refresher.py rename to litellm/proxy/mcp_server/outbound_credentials/authz_code_refresher.py index a653ef5e5ff..286b761b969 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/authz_code_refresher.py +++ b/litellm/proxy/mcp_server/outbound_credentials/authz_code_refresher.py @@ -17,16 +17,16 @@ from typing import TYPE_CHECKING, Final, Protocol from fastapi import HTTPException from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.auth.token_endpoint_auth import ( +from litellm.proxy.mcp_server.auth.token_endpoint_auth import ( TokenEndpointAuthConfigError, ) -from litellm.proxy._experimental.mcp_server.oauth_identity_binding import ( +from litellm.proxy.mcp_server.oauth_identity_binding import ( BindingValidator, RefreshTokenPresented, enforce_oauth_identity_binding, ) -from litellm.proxy._experimental.mcp_server.oauth_utils import build_upstream_oauth2_token_request, get_cimd_client_id -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.oauth_utils import build_upstream_oauth2_token_request, get_cimd_client_id +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/bridge_credentials.py b/litellm/proxy/mcp_server/outbound_credentials/bridge_credentials.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/bridge_credentials.py rename to litellm/proxy/mcp_server/outbound_credentials/bridge_credentials.py index 1441d9662be..2326bcebdc3 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/bridge_credentials.py +++ b/litellm/proxy/mcp_server/outbound_credentials/bridge_credentials.py @@ -16,7 +16,7 @@ from typing import Final, Literal, TypeAlias from pydantic import ConfigDict, SecretStr -from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( +from litellm.proxy.mcp_server.outbound_credentials.envelope import ( EnvelopeIdentity, EnvelopeKeys, EnvelopeMintError, diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/client_credentials.py b/litellm/proxy/mcp_server/outbound_credentials/client_credentials.py similarity index 96% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/client_credentials.py rename to litellm/proxy/mcp_server/outbound_credentials/client_credentials.py index 1652f5d8bd4..d130de4f405 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/client_credentials.py +++ b/litellm/proxy/mcp_server/outbound_credentials/client_credentials.py @@ -40,17 +40,17 @@ from pydantic import ConfigDict, Field, SecretStr, TypeAdapter, ValidationError from typing_extensions import assert_never from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( InMemoryTokenCacheBackend, OAuthToken, TokenCacheBackend, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( +from litellm.proxy.mcp_server.outbound_credentials.result import ( Error, Ok, Result, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.types import ( ClientCredentialsConfig, CredError, HeaderCarrier, @@ -105,7 +105,7 @@ async def post_client_credentials_grant( from litellm.llms.custom_httpx.http_handler import ( # noqa: PLC0415 # defer heavy handler import to call time get_async_httpx_client, # pyright: ignore[reportUnknownVariableType] # handler factory params are coarsely typed ) - from litellm.proxy._experimental.mcp_server.mcp_debug import ( # noqa: PLC0415 # diagnostics import credential enums through this package + from litellm.proxy.mcp_server.mcp_debug import ( # noqa: PLC0415 # diagnostics import credential enums through this package describe_upstream_http_failure, describe_upstream_response, safe_upstream_url, @@ -298,7 +298,7 @@ def _prepare_grant(config: ClientCredentialsConfig) -> Result[_PreparedGrant, Cr ) return Error(CredError.of_misconfigured(f"client_credentials config is missing: {missing}")) - from litellm.proxy._experimental.mcp_server.auth.token_endpoint_auth import ( # noqa: PLC0415 # keep package v1-free at import time + from litellm.proxy.mcp_server.auth.token_endpoint_auth import ( # noqa: PLC0415 # keep package v1-free at import time build_token_endpoint_client_auth, ) diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/dual_cache_token_backend.py b/litellm/proxy/mcp_server/outbound_credentials/dual_cache_token_backend.py similarity index 92% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/dual_cache_token_backend.py rename to litellm/proxy/mcp_server/outbound_credentials/dual_cache_token_backend.py index 69ff7cda2b7..b360b787962 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/dual_cache_token_backend.py +++ b/litellm/proxy/mcp_server/outbound_credentials/dual_cache_token_backend.py @@ -14,13 +14,13 @@ from typing import Final, Protocol from litellm._internal_context import with_service_target from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_cache_codec import ( +from litellm.proxy.mcp_server.outbound_credentials.token_cache_codec import ( OAuthTokenCacheCodec, ) -from litellm.proxy._experimental.mcp_server.utils import MCP_OAUTH_TOKENS_TARGET +from litellm.proxy.mcp_server.utils import MCP_OAUTH_TOKENS_TARGET class AsyncCache(Protocol): diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/envelope.py b/litellm/proxy/mcp_server/outbound_credentials/envelope.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/envelope.py rename to litellm/proxy/mcp_server/outbound_credentials/envelope.py diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/httpx_auth.py b/litellm/proxy/mcp_server/outbound_credentials/httpx_auth.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/httpx_auth.py rename to litellm/proxy/mcp_server/outbound_credentials/httpx_auth.py diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/login_assertion_exchange.py b/litellm/proxy/mcp_server/outbound_credentials/login_assertion_exchange.py similarity index 92% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/login_assertion_exchange.py rename to litellm/proxy/mcp_server/outbound_credentials/login_assertion_exchange.py index fcd8ae22ce3..6280a313f1a 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/login_assertion_exchange.py +++ b/litellm/proxy/mcp_server/outbound_credentials/login_assertion_exchange.py @@ -27,24 +27,24 @@ from datetime import datetime, timezone from typing import Final, Protocol from litellm._logging import verbose_proxy_logger -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error, Ok, Result -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_refresher import ( +from litellm.proxy._types import LiteLLM_MCPServerTable +from litellm.proxy.mcp_server.outbound_credentials.result import Error, Ok, Result +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_refresher import ( SSOClientConfig, sso_client_config, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( SSOIdentityAssertion, with_login_refresh_token, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_endpoint import ExchangedToken -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.token_endpoint import ExchangedToken +from litellm.proxy.mcp_server.outbound_credentials.types import ( ClientAuth, CredError, IdJagConfig, IdJagSubjectSource, ServerSpec, ) -from litellm.proxy._types import LiteLLM_MCPServerTable from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -236,14 +236,14 @@ async def exchange_login_assertion_if_configured( exchange when one of them presents a login refresh token. Nothing here can fail the login.""" if assertion is None: return None - from litellm.proxy._experimental.mcp_server.db import get_all_mcp_servers # noqa: PLC0415 # import cycle - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # avoids import cycle + from litellm.proxy.mcp_server.db import get_all_mcp_servers # noqa: PLC0415 # import cycle + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # avoids import cycle global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 # import cycle + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 # import cycle to_server_spec, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.token_endpoint import ( # noqa: PLC0415 # cycle + from litellm.proxy.mcp_server.outbound_credentials.token_endpoint import ( # noqa: PLC0415 # cycle TokenEndpointClient, ) from litellm.proxy.proxy_server import prisma_client # noqa: PLC0415 # runtime global diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/oauth_token_store.py b/litellm/proxy/mcp_server/outbound_credentials/oauth_token_store.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/oauth_token_store.py rename to litellm/proxy/mcp_server/outbound_credentials/oauth_token_store.py diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/per_user_oauth_store.py b/litellm/proxy/mcp_server/outbound_credentials/per_user_oauth_store.py similarity index 92% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/per_user_oauth_store.py rename to litellm/proxy/mcp_server/outbound_credentials/per_user_oauth_store.py index 2e9f3232c8d..f3748f99ba4 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/per_user_oauth_store.py +++ b/litellm/proxy/mcp_server/outbound_credentials/per_user_oauth_store.py @@ -16,15 +16,15 @@ from functools import partial from typing import TYPE_CHECKING, Final from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.oauth_identity_binding import credential_binding_matches -from litellm.proxy._experimental.mcp_server.outbound_credentials.authz_code_refresher import ( +from litellm.proxy.mcp_server.oauth_identity_binding import credential_binding_matches +from litellm.proxy.mcp_server.outbound_credentials.authz_code_refresher import ( AuthorizationCodeRefresher, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.dual_cache_token_backend import ( +from litellm.proxy.mcp_server.outbound_credentials.dual_cache_token_backend import ( AsyncCache, DualCacheTokenCacheBackend, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( CachedOAuthTokenStore, InvalidatableOAuthTokenStore, OAuthToken, @@ -33,13 +33,13 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_sto TokenCacheBackend, TokenStoreUnavailable, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.runtime_refresh_coordinator import ( +from litellm.proxy.mcp_server.outbound_credentials.runtime_refresh_coordinator import ( runtime_refresh_coordinator, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_cache_codec import ( +from litellm.proxy.mcp_server.outbound_credentials.token_cache_codec import ( OAuthTokenCacheCodec, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.v2_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.v2_token_store import ( V2PerUserTokenStore, ) @@ -54,7 +54,7 @@ StoreBuilder = Callable[[ServerLookup], tuple[InvalidatableOAuthTokenStore, bool async def _read_credential(user_id: str, server_id: str) -> Mapping[str, object] | None: - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 get_user_oauth_credential, ) from litellm.proxy.proxy_server import prisma_client # noqa: PLC0415 @@ -74,7 +74,7 @@ async def _persist_credential( identity_binding_proof: str | None = None, cimd_client_id: str | None = None, ) -> None: - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 store_user_oauth_credential, ) from litellm.proxy.proxy_server import prisma_client # noqa: PLC0415 diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/presented_token_store.py b/litellm/proxy/mcp_server/outbound_credentials/presented_token_store.py similarity index 90% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/presented_token_store.py rename to litellm/proxy/mcp_server/outbound_credentials/presented_token_store.py index c88d31dd6bc..a7078676528 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/presented_token_store.py +++ b/litellm/proxy/mcp_server/outbound_credentials/presented_token_store.py @@ -11,7 +11,7 @@ from __future__ import annotations from dataclasses import dataclass -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/redis_distributed_lock.py b/litellm/proxy/mcp_server/outbound_credentials/redis_distributed_lock.py similarity index 97% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/redis_distributed_lock.py rename to litellm/proxy/mcp_server/outbound_credentials/redis_distributed_lock.py index c7eefed75ed..7262cb6f100 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/redis_distributed_lock.py +++ b/litellm/proxy/mcp_server/outbound_credentials/redis_distributed_lock.py @@ -21,7 +21,7 @@ from dataclasses import KW_ONLY, dataclass from typing import Final, Protocol from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.outbound_credentials.redis_refresh_coordinator import ( +from litellm.proxy.mcp_server.outbound_credentials.redis_refresh_coordinator import ( LockAcquisition, ) diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/redis_refresh_coordinator.py b/litellm/proxy/mcp_server/outbound_credentials/redis_refresh_coordinator.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/redis_refresh_coordinator.py rename to litellm/proxy/mcp_server/outbound_credentials/redis_refresh_coordinator.py index d2c660eb2af..98446f2b66e 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/redis_refresh_coordinator.py +++ b/litellm/proxy/mcp_server/outbound_credentials/redis_refresh_coordinator.py @@ -28,7 +28,7 @@ from dataclasses import KW_ONLY, dataclass from enum import Enum from typing import Final, Protocol -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/resolver.py b/litellm/proxy/mcp_server/outbound_credentials/resolver.py similarity index 97% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/resolver.py rename to litellm/proxy/mcp_server/outbound_credentials/resolver.py index ea0cdee5c1c..dff578ef274 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/resolver.py +++ b/litellm/proxy/mcp_server/outbound_credentials/resolver.py @@ -30,28 +30,28 @@ import httpx2 from typing_extensions import assert_never from litellm._logging import verbose_proxy_logger -from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials.client_credentials import ( ClientCredentialsBearerAuth, ClientCredentialsTokenSource, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( +from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( NoOpAuth, StaticHeaderAuth, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, OAuthTokenStore, TokenStoreUnavailable, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( +from litellm.proxy.mcp_server.outbound_credentials.result import ( Error, Ok, Result, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_refresher import ( +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_refresher import ( default_sso_assertion_store, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( AssertionStoreUnavailable, SSOAssertionStore, SSOIdentityAssertion, @@ -59,15 +59,15 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_s exchanged_refresh_token_issued_for, login_refresh_token_expired, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_endpoint import ( +from litellm.proxy.mcp_server.outbound_credentials.token_endpoint import ( ExchangedToken, ExchangedTokenCache, TokenEndpointClient, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchanger import ( +from litellm.proxy.mcp_server.outbound_credentials.token_exchanger import ( TokenExchanger, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.types import ( ApiKeyConfig, AuthorizationCodeConfig, AuthResolution, diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/result.py b/litellm/proxy/mcp_server/outbound_credentials/result.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/result.py rename to litellm/proxy/mcp_server/outbound_credentials/result.py diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/runtime_refresh_coordinator.py b/litellm/proxy/mcp_server/outbound_credentials/runtime_refresh_coordinator.py similarity index 85% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/runtime_refresh_coordinator.py rename to litellm/proxy/mcp_server/outbound_credentials/runtime_refresh_coordinator.py index e799838b5b7..9376d1bda50 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/runtime_refresh_coordinator.py +++ b/litellm/proxy/mcp_server/outbound_credentials/runtime_refresh_coordinator.py @@ -14,13 +14,13 @@ from __future__ import annotations from typing import Final -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( RefreshCoordinator, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.redis_distributed_lock import ( +from litellm.proxy.mcp_server.outbound_credentials.redis_distributed_lock import ( RedisDistributedLock, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.redis_refresh_coordinator import ( +from litellm.proxy.mcp_server.outbound_credentials.redis_refresh_coordinator import ( RedisRefreshCoordinator, ) diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/session_credentials.py b/litellm/proxy/mcp_server/outbound_credentials/session_credentials.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/session_credentials.py rename to litellm/proxy/mcp_server/outbound_credentials/session_credentials.py index b216f463824..6e3d09f4dd2 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/session_credentials.py +++ b/litellm/proxy/mcp_server/outbound_credentials/session_credentials.py @@ -22,7 +22,7 @@ from typing import Final, Literal, TypeAlias from pydantic import ConfigDict, Field, SecretStr, ValidationError -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import ( +from litellm.proxy.mcp_server.outbound_credentials.session_token import ( AsymmetricSessionKeys, OpenedSessionToken, SessionExpired, diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/session_token.py b/litellm/proxy/mcp_server/outbound_credentials/session_token.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/session_token.py rename to litellm/proxy/mcp_server/outbound_credentials/session_token.py diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/sso_assertion_refresher.py b/litellm/proxy/mcp_server/outbound_credentials/sso_assertion_refresher.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/sso_assertion_refresher.py rename to litellm/proxy/mcp_server/outbound_credentials/sso_assertion_refresher.py index ae5e9d0417e..84a20bf4f5c 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/sso_assertion_refresher.py +++ b/litellm/proxy/mcp_server/outbound_credentials/sso_assertion_refresher.py @@ -58,22 +58,22 @@ from litellm.exceptions import Timeout from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, # pyright: ignore[reportUnknownVariableType] # litellm http handler is untyped ) -from litellm.proxy._experimental.mcp_server.auth.token_endpoint_auth import ( +from litellm.proxy.mcp_server.auth.token_endpoint_auth import ( build_token_endpoint_client_auth, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( InProcessRefreshCoordinator, RefreshCoordinator, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( +from litellm.proxy.mcp_server.outbound_credentials.result import ( Error, Ok, Result, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.runtime_refresh_coordinator import ( +from litellm.proxy.mcp_server.outbound_credentials.runtime_refresh_coordinator import ( runtime_refresh_coordinator, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( AssertionStoreUnavailable, DbSSOAssertionStore, SSOAssertionStore, diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/sso_assertion_store.py b/litellm/proxy/mcp_server/outbound_credentials/sso_assertion_store.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/sso_assertion_store.py rename to litellm/proxy/mcp_server/outbound_credentials/sso_assertion_store.py index 19b3bc294d5..fb4d838aff9 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/sso_assertion_store.py +++ b/litellm/proxy/mcp_server/outbound_credentials/sso_assertion_store.py @@ -294,7 +294,7 @@ async def ema_assertion_retention_enabled() -> bool: snapshot of the DB state that can be stale both ways (a server added on another pod would silently drop the write, one removed on another pod would keep retaining bearer material), and a gate guarding a shared-DB write must judge against that storage's authority.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # avoids import cycle + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # avoids import cycle global_mcp_server_manager, ) from litellm.proxy.proxy_server import prisma_client # noqa: PLC0415 # runtime global diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_cache_codec.py b/litellm/proxy/mcp_server/outbound_credentials/token_cache_codec.py similarity index 95% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/token_cache_codec.py rename to litellm/proxy/mcp_server/outbound_credentials/token_cache_codec.py index 56dc3f19cdd..4576e925939 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_cache_codec.py +++ b/litellm/proxy/mcp_server/outbound_credentials/token_cache_codec.py @@ -14,7 +14,7 @@ from typing import Final from pydantic import TypeAdapter, ValidationError -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_endpoint.py b/litellm/proxy/mcp_server/outbound_credentials/token_endpoint.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/token_endpoint.py rename to litellm/proxy/mcp_server/outbound_credentials/token_endpoint.py index 1ee1b7ecf2f..6fd63450b26 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_endpoint.py +++ b/litellm/proxy/mcp_server/outbound_credentials/token_endpoint.py @@ -39,12 +39,12 @@ from litellm.exceptions import Timeout from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, # pyright: ignore[reportUnknownVariableType] # litellm http handler is untyped ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( +from litellm.proxy.mcp_server.outbound_credentials.result import ( Error, Ok, Result, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.types import ( ClientAuth, ClientSecretAuth, CredError, diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_exchange_provider.py b/litellm/proxy/mcp_server/outbound_credentials/token_exchange_provider.py similarity index 94% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/token_exchange_provider.py rename to litellm/proxy/mcp_server/outbound_credentials/token_exchange_provider.py index 2501f751d8e..0beab749076 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_exchange_provider.py +++ b/litellm/proxy/mcp_server/outbound_credentials/token_exchange_provider.py @@ -12,6 +12,7 @@ from __future__ import annotations from typing import Final import httpx +from pydantic import TypeAdapter from litellm._logging import verbose_logger from litellm.constants import ( @@ -20,10 +21,10 @@ from litellm.constants import ( MCP_OAUTH2_TOKEN_EXPIRY_BUFFER_SECONDS, MCP_TOKEN_EXCHANGE_CACHE_MAX_SIZE, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( InMemoryTokenCacheBackend, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchanger import ( +from litellm.proxy.mcp_server.outbound_credentials.token_exchanger import ( OboTokenExchanger, SubjectTokenRejected, TokenExchangeClientError, @@ -34,6 +35,7 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchanger _GATEWAY_FAULT_OAUTH_ERRORS: Final = frozenset( {"invalid_client", "unauthorized_client", "unsupported_grant_type", "invalid_target", "invalid_scope"} ) +_DECODED_JSON: Final = TypeAdapter(object) def _oauth_error_fields(response: httpx.Response) -> tuple[str | None, str | None]: @@ -46,7 +48,7 @@ def _oauth_error_fields(response: httpx.Response) -> tuple[str | None, str | Non it can carry IdP internals and must never reach the caller. """ try: - body: Final[object] = response.json() + body: Final = _DECODED_JSON.validate_python(response.json()) except Exception: # noqa: BLE001 return None, None if not isinstance(body, dict): diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_exchanger.py b/litellm/proxy/mcp_server/outbound_credentials/token_exchanger.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/token_exchanger.py rename to litellm/proxy/mcp_server/outbound_credentials/token_exchanger.py index 2e72d98c77d..83457d5cef1 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_exchanger.py +++ b/litellm/proxy/mcp_server/outbound_credentials/token_exchanger.py @@ -27,22 +27,22 @@ from typing import Final, Literal, Protocol from typing_extensions import assert_never from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.auth.token_endpoint_auth import ( +from litellm.proxy.mcp_server.auth.token_endpoint_auth import ( build_token_endpoint_client_auth, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( InMemoryTokenCacheBackend, InProcessRefreshCoordinator, OAuthToken, RefreshCoordinator, TokenCacheBackend, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( +from litellm.proxy.mcp_server.outbound_credentials.result import ( Error, Ok, Result, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.types import ( CredError, ServerSpec, TokenExchangeConfig, diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/types.py b/litellm/proxy/mcp_server/outbound_credentials/types.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/types.py rename to litellm/proxy/mcp_server/outbound_credentials/types.py index 45c53af9349..5a30fafd7d9 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/types.py +++ b/litellm/proxy/mcp_server/outbound_credentials/types.py @@ -35,7 +35,7 @@ from expression import case, tag, tagged_union from pydantic import ConfigDict, Field, SecretStr, field_validator from typing_extensions import assert_never -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( +from litellm.proxy.mcp_server.outbound_credentials.result import ( Error, Ok, Result, diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/v2_token_store.py b/litellm/proxy/mcp_server/outbound_credentials/v2_token_store.py similarity index 97% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/v2_token_store.py rename to litellm/proxy/mcp_server/outbound_credentials/v2_token_store.py index 56ab8e6bbdc..a1a3b88259e 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/v2_token_store.py +++ b/litellm/proxy/mcp_server/outbound_credentials/v2_token_store.py @@ -14,7 +14,7 @@ from collections.abc import Awaitable, Callable, Mapping from datetime import datetime, timezone from typing import Final -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) diff --git a/litellm/proxy/_experimental/mcp_server/proxy_api_credentials.py b/litellm/proxy/mcp_server/proxy_api_credentials.py similarity index 96% rename from litellm/proxy/_experimental/mcp_server/proxy_api_credentials.py rename to litellm/proxy/mcp_server/proxy_api_credentials.py index fd637a2f187..53fe4ce457d 100644 --- a/litellm/proxy/_experimental/mcp_server/proxy_api_credentials.py +++ b/litellm/proxy/mcp_server/proxy_api_credentials.py @@ -8,13 +8,6 @@ from collections.abc import Sequence from typing import Final from litellm.constants import CLI_JWT_EXPIRATION_HOURS -from litellm.proxy._experimental.mcp_server.bridge_token_flow import load_active_user_by_id -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( - ConsentTeam, - MintedProxyCredential, - ProxyCredentialMintFailure, - ReloadUserFailure, -) from litellm.proxy._types import LiteLLM_UserTable from litellm.proxy.auth.auth_checks import ExperimentalUIJWTToken, effective_user_role from litellm.proxy.management_endpoints.ui_sso import ( @@ -22,6 +15,13 @@ from litellm.proxy.management_endpoints.ui_sso import ( fetch_cli_sso_team_details, selected_cli_sso_team_detail, ) +from litellm.proxy.mcp_server.bridge_token_flow import load_active_user_by_id +from litellm.proxy.mcp_server.gateway_dcr_flow import ( + ConsentTeam, + MintedProxyCredential, + ProxyCredentialMintFailure, + ReloadUserFailure, +) async def lookup_consent_teams(user_id: str) -> tuple[ConsentTeam, ...] | ReloadUserFailure: diff --git a/litellm/proxy/_experimental/mcp_server/rest_endpoints.py b/litellm/proxy/mcp_server/rest_endpoints.py similarity index 96% rename from litellm/proxy/_experimental/mcp_server/rest_endpoints.py rename to litellm/proxy/mcp_server/rest_endpoints.py index ee063b81ae4..2737b567985 100644 --- a/litellm/proxy/_experimental/mcp_server/rest_endpoints.py +++ b/litellm/proxy/mcp_server/rest_endpoints.py @@ -24,35 +24,6 @@ from litellm.exceptions import ( GuardrailRaisedException, ModifyResponseException, ) -from litellm.proxy._experimental.mcp_server.catalog import catalog_operation, global_manager -from litellm.proxy._experimental.mcp_server.exceptions import ( - MCPServerListError, - MCPServerURLCredentialsError, - MCPUpstreamAuthError, -) -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( - ServerListOk, - ServerOutcome, - classify_list_exception, - list_fault_http_status, - outcome_wire_value, -) -from litellm.proxy._experimental.mcp_server.faults.traversal import iter_exception_tree -from litellm.proxy._experimental.mcp_server.oauth_utils import ( # noqa: F401 # legacy module exports - _redact_mcp_resource_url, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export - redact_mcp_resource_url, -) -from litellm.proxy._experimental.mcp_server.result_conversion import WireCompat, complete_call_tool_result -from litellm.proxy._experimental.mcp_server.ui_session_utils import ( - acting_user_auth, - build_effective_auth_contexts, -) -from litellm.proxy._experimental.mcp_server.utils import ( - MCPMissingUserEnvVarsError, - add_server_prefix_to_name, - get_server_prefix, - merge_mcp_headers, -) from litellm.proxy._types import ( LitellmUserRoles, UserAPIKeyAuth, @@ -61,13 +32,42 @@ from litellm.proxy._types import ( from litellm.proxy.auth.ip_address_utils import IPAddressUtils from litellm.proxy.auth.user_api_key_auth import user_api_key_auth from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError +from litellm.proxy.mcp_server.catalog import catalog_operation, global_manager +from litellm.proxy.mcp_server.exceptions import ( + MCPServerListError, + MCPServerURLCredentialsError, + MCPUpstreamAuthError, +) +from litellm.proxy.mcp_server.faults.list_outcomes import ( + ServerListOk, + ServerOutcome, + classify_list_exception, + list_fault_http_status, + outcome_wire_value, +) +from litellm.proxy.mcp_server.faults.traversal import iter_exception_tree +from litellm.proxy.mcp_server.oauth_utils import ( # noqa: F401 # legacy module exports + _redact_mcp_resource_url, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export + redact_mcp_resource_url, +) +from litellm.proxy.mcp_server.result_conversion import WireCompat, complete_call_tool_result +from litellm.proxy.mcp_server.ui_session_utils import ( + acting_user_auth, + build_effective_auth_contexts, +) +from litellm.proxy.mcp_server.utils import ( + MCPMissingUserEnvVarsError, + add_server_prefix_to_name, + get_server_prefix, + merge_mcp_headers, +) from litellm.responses.mcp.request_context import MCPRequestContext if TYPE_CHECKING: from mcp.types import CallToolResult, InputRequiredResult from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj - from litellm.proxy._experimental.mcp_server.db import OAuthCredentialPayload + from litellm.proxy.mcp_server.db import OAuthCredentialPayload from litellm.proxy.utils import ProxyLogging from litellm.proxy.common_utils.http_parsing_utils import ( # noqa: F401 # legacy module exports _safe_get_request_headers, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export @@ -82,7 +82,7 @@ class _MCPModelMetadata(TypedDict): def _stamp_mcp_tool_metadata(logging_obj: "LiteLLMLoggingObj | None", server_id: str, tool_name: str) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager if logging_obj is None: return @@ -227,22 +227,22 @@ if MCP_AVAILABLE: from mcp.shared.exceptions import MCPError from mcp.types import Tool as MCPTool - from litellm.experimental_mcp_client.client import MCPClient, as_mcp_read_timeout from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj from litellm.llms.litellm_proxy.skills.skill_search import ( DEFAULT_SKILL_SEARCH_TOP_K, ) - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: F401 # legacy module exports + from litellm.mcp_client.client import MCPClient, as_mcp_read_timeout + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: F401 # legacy module exports _UPSTREAM_OAUTH_DISCOVERY_AUTH_TYPES, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export UPSTREAM_OAUTH_DISCOVERY_AUTH_TYPES, ListedToolsCaller, global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( get_request_base_url, ) - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( ListMCPToolsRestAPIResponseObject, MCPInfo, MCPServer, @@ -254,12 +254,12 @@ if MCP_AVAILABLE: fire_mcp_tool_call_failure_logging, resolve_native_tool_name_for_server, ) - from litellm.proxy._experimental.mcp_server.server import ( # noqa: F401 # legacy module exports + from litellm.proxy.mcp_server.server import ( # noqa: F401 # legacy module exports _apply_toolset_scope, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export apply_toolset_scope, reject_disallowed_mcp_client, ) - from litellm.proxy._experimental.mcp_server.tool_catalog_guard import ( + from litellm.proxy.mcp_server.tool_catalog_guard import ( apply_description_overrides, scan_tool_descriptions, ) @@ -337,7 +337,8 @@ if MCP_AVAILABLE: ``mcp_tool_search_enabled``). Kept out of ``call_tool_rest_api`` so that endpoint stays a single dispatch. An upstream 401 raised by the virtual ``mcp_tool_call`` propagates unhandled to the caller's ``except MCPUpstreamAuthError`` relay, the same as the direct call path.""" - from litellm.proxy._experimental.mcp_server.tool_search import ( + from litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessing + from litellm.proxy.mcp_server.tool_search import ( AGENT_SEARCH_TOOL_NAME, DEFAULT_AGENT_SEARCH_TOP_K, MCP_TOOL_SEARCH_TOOL_NAME, @@ -348,7 +349,6 @@ if MCP_AVAILABLE: handle_mcp_tool_search, handle_skill_search, ) - from litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessing from litellm.proxy.proxy_server import general_settings, proxy_config, proxy_logging_obj if not getattr(getattr(user_api_key_dict, "object_permission", None), "mcp_tool_search_enabled", False): @@ -443,7 +443,7 @@ if MCP_AVAILABLE: mcp_auth_header: str | None, ) -> dict[str, str] | str | None: """Helper function to get server-specific auth header with case-insensitive matching.""" - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( lookup_mcp_server_auth_in_headers, ) @@ -466,7 +466,7 @@ if MCP_AVAILABLE: round-trip whose result is discarded. Mirrors the same guard on the protocol listing path and in ``_resolve_oauth2_headers_for_tool_call``. """ - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( to_server_spec, ) @@ -511,7 +511,7 @@ if MCP_AVAILABLE: if not user_id or not server_id: return None try: - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( get_user_oauth_credential, resolve_valid_user_oauth_token, ) @@ -555,7 +555,7 @@ if MCP_AVAILABLE: if not user_id: return {} try: - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( list_user_oauth_credentials, ) from litellm.proxy.utils import get_prisma_client_or_throw @@ -603,7 +603,7 @@ if MCP_AVAILABLE: Returns: Tuple of (mcp_auth_header, mcp_server_auth_headers, raw_headers, oauth2_headers) """ - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( OPTIONAL_STRING_ADAPTER, MCPRequestHandler, ) @@ -957,7 +957,7 @@ if MCP_AVAILABLE: status_code=list_fault_http_status(fault), detail={ "error": fault.tag, - "message": f"Failed to list tools from server {get_server_prefix(server)}", + "message": fault.public_message or f"Failed to list tools from server {get_server_prefix(server)}", }, ) from e except Exception as e: @@ -1062,7 +1062,7 @@ if MCP_AVAILABLE: False, ) ): - from litellm.proxy._experimental.mcp_server.tool_search import ( + from litellm.proxy.mcp_server.tool_search import ( get_virtual_tool_definitions, ) @@ -1344,7 +1344,7 @@ if MCP_AVAILABLE: tool_name: Final[str | None] = data.get("name") tool_arguments: Final[dict[str, object]] = data.get("arguments") or {} - from litellm.proxy._experimental.mcp_server.tool_search import VIRTUAL_TOOL_NAMES + from litellm.proxy.mcp_server.tool_search import VIRTUAL_TOOL_NAMES if tool_name in VIRTUAL_TOOL_NAMES: return await _handle_virtual_mcp_tool(request, data, tool_name, user_api_key_dict) @@ -1594,7 +1594,7 @@ if MCP_AVAILABLE: temporary client the same credentials, or a server that the saved connection reaches fine fails one of them. """ - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -1725,16 +1725,16 @@ if MCP_AVAILABLE: # becomes the upstream credential, so it is not also forwarded as a caller header. Gated # to the v2-mapped oauth2 case (to_server_spec non-None); M2M (client_credentials), # delegate/passthrough, and token-exchange are unaffected. - from litellm.proxy._experimental.mcp_server.outbound_credentials import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.outbound_credentials import ( # noqa: PLC0415 UpstreamCredentialProvider, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 to_server_spec, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( # noqa: PLC0415 OAuthToken, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.presented_token_store import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.outbound_credentials.presented_token_store import ( # noqa: PLC0415 PresentedOAuthTokenStore, ) @@ -1795,7 +1795,7 @@ if MCP_AVAILABLE: async def _preview_openapi_tools(spec_path: str) -> dict: """Generate tool previews from an OpenAPI spec without creating a server.""" - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( OPENAPI_TOOL_NAME_MAX_LEN, build_input_schema, load_openapi_spec_async, diff --git a/litellm/proxy/_experimental/mcp_server/result_conversion.py b/litellm/proxy/mcp_server/result_conversion.py similarity index 92% rename from litellm/proxy/_experimental/mcp_server/result_conversion.py rename to litellm/proxy/mcp_server/result_conversion.py index 61435f94c94..8955381add1 100644 --- a/litellm/proxy/_experimental/mcp_server/result_conversion.py +++ b/litellm/proxy/mcp_server/result_conversion.py @@ -13,12 +13,12 @@ from __future__ import annotations import json import math from collections.abc import Sequence -from typing import Final, TypeAlias, TypeVar +from typing import Final, Protocol, TypeAlias, TypeVar from mcp.types import CacheableResult, CallToolResult, ContentBlock, InputRequiredResult, TextContent, Tool from typing_extensions import ReadOnly, TypedDict, assert_never -from litellm.proxy._experimental.mcp_server.tool_outcome import ( +from litellm.proxy.mcp_server.tool_outcome import ( JsonResult, TextResult, WireCompat, @@ -105,8 +105,17 @@ def complete_call_tool_result(outcome: ToolOutcome, compat: WireCompat) -> CallT return converted +class _StructuredContentCarrier(Protocol): + @property + def structured_content(self) -> object: ... + + +def _structured_content(result: _StructuredContentCarrier) -> object: + return result.structured_content + + def _downgrade_structured_content(result: CallToolResult) -> CallToolResult: - structured: Final = result.structured_content + structured: Final = _structured_content(result) if structured is None or isinstance(structured, dict): return result fallback: Final = TextContent(type="text", text=json.dumps(structured)) diff --git a/litellm/proxy/_experimental/mcp_server/sampling_handler.py b/litellm/proxy/mcp_server/sampling_handler.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/sampling_handler.py rename to litellm/proxy/mcp_server/sampling_handler.py index e1469f2fff7..ec14f81aef2 100644 --- a/litellm/proxy/_experimental/mcp_server/sampling_handler.py +++ b/litellm/proxy/mcp_server/sampling_handler.py @@ -222,7 +222,7 @@ def _select_model_by_priority( input_cost = info.get("input_cost_per_token") or 0.0 output_cost = info.get("output_cost_per_token") or 0.0 total_cost = input_cost + output_cost - max_output = info.get("max_output_tokens") or info.get("max_tokens") or 0 + max_output = info.get("max_output_tokens") or 0 output_tps = info.get("output_tokens_per_second") or 0.0 scored.append( _ScoredModel( @@ -1047,7 +1047,7 @@ def _build_sampling_request( ) -> "Request": """The synthetic FastAPI Request for sampling sub-calls, carrying the original MCP connection's headers and client IP.""" - from litellm.proxy._experimental.mcp_server.utils import build_synthetic_mcp_request + from litellm.proxy.mcp_server.utils import build_synthetic_mcp_request return build_synthetic_mcp_request( path="/mcp/sampling/createMessage", diff --git a/litellm/proxy/_experimental/mcp_server/scope_challenge.py b/litellm/proxy/mcp_server/scope_challenge.py similarity index 61% rename from litellm/proxy/_experimental/mcp_server/scope_challenge.py rename to litellm/proxy/mcp_server/scope_challenge.py index c326418bee7..128b27b0f91 100644 --- a/litellm/proxy/_experimental/mcp_server/scope_challenge.py +++ b/litellm/proxy/mcp_server/scope_challenge.py @@ -10,7 +10,7 @@ from starlette.requests import Request from starlette.responses import JSONResponse from starlette.types import Message, Send -from litellm.proxy._experimental.mcp_server.exceptions import MCPUpstreamAuthError +from litellm.proxy.mcp_server.exceptions import MCPUpstreamAuthError if TYPE_CHECKING: from mcp.server.context import CallNext, HandlerResult, ServerRequestContext @@ -33,9 +33,8 @@ class OAuthScopeResponse: self._request_path = request_path self._ready = asyncio.Event() self._lock = asyncio.Lock() - self._start: Message | None = None self._challenge: MCPUpstreamAuthError | None = None - self._refused = False + self._closed = False @property def pending(self) -> bool: @@ -50,31 +49,33 @@ class OAuthScopeResponse: self._ready.set() async def __call__(self, message: Message) -> None: - if message["type"] == "http.response.start": - self._start = message - if message["status"] != 200: - self.allow() - return - await self._ready.wait() async with self._lock: - if self._refused: + if self._closed: return - if self._start is not None: - start: Final = self._start - self._start = None - if self._challenge is not None: - error: Final = self._challenge.to_http_exception(self._base_url, self._request_path) - response: Final = JSONResponse( - status_code=error.status_code, content={"detail": error.detail}, headers=error.headers - ) - self._refused = True - await self._send( - {"type": "http.response.start", "status": response.status_code, "headers": response.raw_headers} - ) - await self._send({"type": "http.response.body", "body": bytes(response.body)}) - return - await self._send(start) - await self._send(message) + try: + if message["type"] == "http.response.start": + if message["status"] != 200: + self.allow() + await self._ready.wait() + if self._challenge is not None: + error: Final = self._challenge.to_http_exception(self._base_url, self._request_path) + response: Final = JSONResponse( + status_code=error.status_code, content={"detail": error.detail}, headers=error.headers + ) + self._closed = True + await self._send( + { + "type": "http.response.start", + "status": response.status_code, + "headers": response.raw_headers, + } + ) + await self._send({"type": "http.response.body", "body": bytes(response.body)}) + return + await self._send(message) + except BaseException: + self._closed = True + raise def scope_response_from_request(request: object) -> OAuthScopeResponse | None: diff --git a/litellm/proxy/_experimental/mcp_server/semantic_tool_filter.py b/litellm/proxy/mcp_server/semantic_tool_filter.py similarity index 96% rename from litellm/proxy/_experimental/mcp_server/semantic_tool_filter.py rename to litellm/proxy/mcp_server/semantic_tool_filter.py index 2f88d8c361f..4fe723d6b24 100644 --- a/litellm/proxy/_experimental/mcp_server/semantic_tool_filter.py +++ b/litellm/proxy/mcp_server/semantic_tool_filter.py @@ -6,20 +6,22 @@ Filters MCP tools semantically for /chat/completions and /responses endpoints. import asyncio from collections.abc import Mapping, Sequence -from typing import TYPE_CHECKING, Any, Final +from typing import TYPE_CHECKING, Final, TypeVar from litellm._logging import verbose_logger from litellm.exceptions import ContextWindowExceededError from litellm.litellm_core_utils.exception_mapping_utils import ExceptionCheckers -from litellm.proxy._experimental.mcp_server.catalog import catalog_operation, global_manager -from litellm.proxy._experimental.mcp_server.faults import iter_exception_tree -from litellm.proxy._experimental.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR +from litellm.proxy.mcp_server.catalog import catalog_operation, global_manager +from litellm.proxy.mcp_server.faults import iter_exception_tree +from litellm.proxy.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR if TYPE_CHECKING: from semantic_router.routers import SemanticRouter from litellm.router import Router +_Tool: Final = TypeVar("_Tool") + class SemanticToolFilterContextWindowError(Exception): """Raised when the embedding model exceeds its context window, so semantic filtering cannot run.""" @@ -82,7 +84,7 @@ class SemanticMCPToolFilter: @catalog_operation(global_manager) async def build_router_from_mcp_registry(self) -> None: """Build semantic router from all MCP tools in the registry (no auth checks).""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -265,9 +267,9 @@ class SemanticMCPToolFilter: async def filter_tools( self, query: str, - available_tools: list[Any], + available_tools: list[_Tool], top_k: int | None = None, - ) -> list[Any]: + ) -> list[_Tool]: """ Filter tools semantically based on query. @@ -390,7 +392,7 @@ class SemanticMCPToolFilter: separator: Final = client_name[-len(canonical) - 1] return separator in ("_", "-") - def _get_tools_by_names(self, tool_names: Sequence[str], available_tools: Sequence[object]) -> list[object]: + def _get_tools_by_names(self, tool_names: Sequence[str], available_tools: Sequence[_Tool]) -> list[_Tool]: """ Get tools from available_tools by their names, preserving the semantic router's ordering. @@ -406,13 +408,13 @@ class SemanticMCPToolFilter: # Exact matches win over suffix matches when both are present, and # each incoming tool is returned at most once even if two canonical # names happen to be tail-compatible with the same incoming name. - available_by_name: Final[dict[str, object]] = {} + available_by_name: Final[dict[str, _Tool]] = {} for tool in available_tools: client_name, _ = self.extract_tool_info(tool) if client_name and client_name not in available_by_name: available_by_name[client_name] = tool - matched: Final[list[object]] = [] + matched: Final[list[_Tool]] = [] used_ids: Final[set[int]] = set() for canonical in tool_names: tool = available_by_name.get(canonical) diff --git a/litellm/proxy/_experimental/mcp_server/server.py b/litellm/proxy/mcp_server/server.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/server.py rename to litellm/proxy/mcp_server/server.py index b3426089375..32f790a8e81 100644 --- a/litellm/proxy/_experimental/mcp_server/server.py +++ b/litellm/proxy/mcp_server/server.py @@ -14,7 +14,7 @@ import time import types from collections import Counter from collections.abc import AsyncGenerator, AsyncIterator, Callable, Iterable, Mapping, Sequence, Set -from typing import TYPE_CHECKING, Final, NoReturn, Protocol +from typing import TYPE_CHECKING, Final, Literal, NoReturn, Protocol import httpx from fastapi import FastAPI, HTTPException @@ -35,23 +35,29 @@ from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, httpxSpecialProvider, ) -from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( # noqa: F401 # legacy module exports +from litellm.proxy._types import ( + ProxyException, + SpecialMCPServerNames, + UserAPIKeyAuth, +) +from litellm.proxy.auth.ip_address_utils import IPAddressUtils +from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( # noqa: F401 # legacy module exports MCPRequestHandler, _is_mcp_admitted_user_subject, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export is_mcp_admitted_user_subject, ) -from litellm.proxy._experimental.mcp_server.client_allowlist import ( +from litellm.proxy.mcp_server.client_allowlist import ( MCPClientAllowlist, check_mcp_client_allowed, load_mcp_client_allowlist, ) -from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( +from litellm.proxy.mcp_server.discoverable_endpoints import ( get_request_base_url, ) -from litellm.proxy._experimental.mcp_server.exceptions import ( +from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) -from litellm.proxy._experimental.mcp_server.mcp_context import ( # noqa: F401 # legacy module exports +from litellm.proxy.mcp_server.mcp_context import ( # noqa: F401 # legacy module exports _mcp_active_toolset_id, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export _mcp_gateway_initialize_instructions, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export _mcp_gateway_server_name, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export @@ -62,43 +68,37 @@ from litellm.proxy._experimental.mcp_server.mcp_context import ( # noqa: F401 mcp_gateway_initialize_instructions, mcp_gateway_server_name, ) -from litellm.proxy._experimental.mcp_server.mcp_debug import ( +from litellm.proxy.mcp_server.mcp_debug import ( MCP_AUTH_DIAGNOSTICS_SCOPE_KEY, MCPAuthDiagnostics, MCPDebug, ) -from litellm.proxy._experimental.mcp_server.oauth_utils import ( +from litellm.proxy.mcp_server.oauth_utils import ( get_passthrough_www_authenticate, get_route_relative_request_path, redact_mcp_resource_url, well_known_root_suffix, ) -from litellm.proxy._experimental.mcp_server.scope_challenge import ( +from litellm.proxy.mcp_server.scope_challenge import ( SCOPE_RESPONSE_KEY, OAuthScopeResponse, finish_scope_response, is_tool_call_request, ) -from litellm.proxy._experimental.mcp_server.ui_session_utils import ( +from litellm.proxy.mcp_server.ui_session_utils import ( ActingUser, GrantedToolsetIds, acting_user_auth, granted_toolset_ids, is_ui_session_credential, ) -from litellm.proxy._experimental.mcp_server.utils import ( +from litellm.proxy.mcp_server.utils import ( LITELLM_MCP_SERVER_DESCRIPTION, LITELLM_MCP_SERVER_NAME, LITELLM_MCP_SERVER_VERSION, asgi_scope_fields, merge_mcp_headers, ) -from litellm.proxy._types import ( - ProxyException, - SpecialMCPServerNames, - UserAPIKeyAuth, -) -from litellm.proxy.auth.ip_address_utils import IPAddressUtils from litellm.types.mcp import ( MCPAuth, MCPGatewaySession, @@ -150,9 +150,19 @@ def _scope_headers(scope: Scope) -> Sequence[tuple[bytes, bytes]]: return asgi_scope_fields(scope).get("headers", []) +class _RawHeaderPairsSource(Protocol): + def get( + self, key: Literal["headers"], default: Sequence[tuple[bytes | str, bytes | str]], / + ) -> Sequence[tuple[bytes | str, bytes | str]]: ... + + +def _raw_header_pairs(source: _RawHeaderPairsSource) -> Sequence[tuple[bytes | str, bytes | str]]: + return source.get("headers", []) + + def unsupported_protocol_version(scope: Scope) -> str | None: """Admit configured HTTP revisions while keeping SSE on the legacy protocol.""" - from litellm.proxy._experimental.mcp_server.capabilities import configured_versions + from litellm.proxy.mcp_server.capabilities import configured_versions headers: Final[Iterable[tuple[bytes, bytes]]] = scope.get("headers") or () values: Final = tuple( @@ -537,14 +547,14 @@ if MCP_AVAILABLE: ReadResourceRequest, ) - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.contracts import OperationContext - from litellm.proxy._experimental.mcp_server.interactions import InteractionOperation - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.contracts import OperationContext + from litellm.proxy.mcp_server.interactions import InteractionOperation + from litellm.proxy.mcp_server.operations import ( _invalidate_byok_cred_cache, _mcp_session_id_from_headers, ) - from litellm.proxy._experimental.mcp_server.result_conversion import wire_compat_for + from litellm.proxy.mcp_server.result_conversion import wire_compat_for try: from mcp.server.streamable_http_manager import StreamableHTTPSessionManager @@ -566,16 +576,16 @@ if MCP_AVAILABLE: ReadResourceRequestParams, ) - from litellm.proxy._experimental.mcp_server.auth.litellm_auth_handler import ( + from litellm.proxy.mcp_server.auth.litellm_auth_handler import ( MCPAuthenticatedUser, ) - from litellm.proxy._experimental.mcp_server.capabilities import ( + from litellm.proxy.mcp_server.capabilities import ( GatewayVersionPolicy, configured_versions, disabled_capabilities, disabled_operations, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, global_mcp_server_manager, ) @@ -585,10 +595,10 @@ if MCP_AVAILABLE: # Defined here because we don't want to add `mcp` as a # required dependency for `litellm` pip package ###################################################### - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( ListMCPToolsRestAPIResponseObject, ) - from litellm.proxy._experimental.mcp_server.sse_transport import SseServerTransport + from litellm.proxy.mcp_server.sse_transport import SseServerTransport def _gateway_create_initialization_options( self, @@ -936,7 +946,7 @@ if MCP_AVAILABLE: raise MCPError(code=METHOD_NOT_FOUND, message="Operation unavailable on /mcp/proxy") - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( _build_virtual_call_logging_obj, _dispatch_virtual_mcp_tool, ) @@ -1026,7 +1036,7 @@ if MCP_AVAILABLE: UnsubscribeRequestParams, ) - from litellm.proxy._experimental.mcp_server.subscriptions import GatewaySubscriptions, SubscriptionAuthorization + from litellm.proxy.mcp_server.subscriptions import GatewaySubscriptions, SubscriptionAuthorization subscriptions: Final = GatewaySubscriptions() legacy_subscription_request: Final[contextvars.ContextVar[StarletteRequest | None]] = contextvars.ContextVar( @@ -1116,7 +1126,7 @@ if MCP_AVAILABLE: ############ Helper Functions ########################## ######################################################## - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( _client_has_passthrough_authorization, _client_has_per_server_auth_header, _get_allowed_mcp_servers, @@ -1179,7 +1189,7 @@ if MCP_AVAILABLE: mcp_gateway_initialize_instructions.reset(instructions_token) mcp_gateway_server_name.reset(server_name_token) - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( _MCP_CREDENTIAL_REQUEST_FIELDS, _aggregate_server_key, _check_byok_credential, @@ -1319,7 +1329,7 @@ if MCP_AVAILABLE: Extract mcp-session-id from ASGI scope headers. Returns None if not present. """ - scope_headers: Final[Sequence[tuple[bytes | str, bytes | str]]] = scope.get("headers", []) + scope_headers: Final = _raw_header_pairs(scope) for header_name, header_value in scope_headers: name = header_name if isinstance(header_name, bytes) else header_name.encode() if name.lower() == b"mcp-session-id": @@ -1669,7 +1679,7 @@ if MCP_AVAILABLE: Fixes https://github.com/BerriAI/litellm/issues/20992 """ _mcp_session_header: Final = b"mcp-session-id" - _headers: Final[Sequence[tuple[bytes | str, bytes | str]]] = scope.get("headers", []) + _headers: Final = _raw_header_pairs(scope) def _normalize_header_name(header_name: object) -> bytes | None: if isinstance(header_name, bytes): @@ -1797,7 +1807,7 @@ if MCP_AVAILABLE: return acting.model_copy(update={"mcp_toolset_id": toolset_id}) tool_permissions = await operations.global_mcp_server_manager.resolve_toolset_tool_permissions( - toolset_ids=[toolset_id] + toolset_ids=[toolset_id], requires_fresh_policy=acting.requires_fresh_policy ) server_ids: Final = list(tool_permissions.keys()) existing_op: Final = acting.object_permission @@ -1826,7 +1836,7 @@ if MCP_AVAILABLE: await operations.global_mcp_server_manager.resolve_toolset_tool_permissions(toolset_ids=[toolset_id]) ) - from litellm.proxy._experimental.mcp_server.catalog import catalog_operation + from litellm.proxy.mcp_server.catalog import catalog_operation @catalog_operation(lambda: operations.global_mcp_server_manager) async def _raise_preemptive_401_for_unauthenticated_servers( @@ -1961,7 +1971,7 @@ if MCP_AVAILABLE: ) is None ): - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 # lazy: adapter pulls MCP subgraph + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 # lazy: adapter pulls MCP subgraph raise_token_exchange_challenge, ) from litellm.proxy.middleware.per_request_root_path_middleware import ( # noqa: PLC0415 # lazy: middleware imports proxy utils @@ -2869,7 +2879,7 @@ if MCP_AVAILABLE: mcp_servers, _sse_client_ip, scoped_server_endpoint=scoped_server_endpoint, - is_initialize=scope.get("method") == "GET", + is_initialize=asgi_scope_fields(scope).get("method", "") == "GET", ): async with ( sse.connect_sse(transport_scope, receive, send) as (read_stream, write_stream), @@ -3090,7 +3100,7 @@ if MCP_AVAILABLE: ) -> Send: async def wrapped_send(message: Message) -> None: if message.get("type") == "http.response.start": - response_headers: Final[Sequence[tuple[bytes | str, bytes | str]]] = message.get("headers", []) + response_headers: Final = _raw_header_pairs(message) for key, value in response_headers: header_name = key if isinstance(key, bytes) else str(key).encode() if header_name.lower() == b"mcp-session-id": diff --git a/litellm/proxy/_experimental/mcp_server/server_resolution.py b/litellm/proxy/mcp_server/server_resolution.py similarity index 96% rename from litellm/proxy/_experimental/mcp_server/server_resolution.py rename to litellm/proxy/mcp_server/server_resolution.py index 31bcd897e72..96c485c0d3c 100644 --- a/litellm/proxy/_experimental/mcp_server/server_resolution.py +++ b/litellm/proxy/mcp_server/server_resolution.py @@ -6,12 +6,12 @@ from typing import TYPE_CHECKING, Final, Literal, Protocol from fastapi import HTTPException, status -from litellm.proxy._experimental.mcp_server.ui_session_utils import can_access_mcp_server from litellm.proxy._types import LiteLLM_MCPServerTable, UserAPIKeyAuth +from litellm.proxy.mcp_server.ui_session_utils import can_access_mcp_server from litellm.types.mcp_server.mcp_server_manager import MCPServer if TYPE_CHECKING: - from litellm.proxy._experimental.mcp_server.contracts import CatalogListRequest, CatalogListResult, OperationContext + from litellm.proxy.mcp_server.contracts import CatalogListRequest, CatalogListResult, OperationContext class MCPServerRegistry(Protocol): diff --git a/litellm/proxy/_experimental/mcp_server/sse_transport.py b/litellm/proxy/mcp_server/sse_transport.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/sse_transport.py rename to litellm/proxy/mcp_server/sse_transport.py diff --git a/litellm/proxy/_experimental/mcp_server/state_tokens.py b/litellm/proxy/mcp_server/state_tokens.py similarity index 97% rename from litellm/proxy/_experimental/mcp_server/state_tokens.py rename to litellm/proxy/mcp_server/state_tokens.py index 88f98bef6b8..b65a8ca4e88 100644 --- a/litellm/proxy/_experimental/mcp_server/state_tokens.py +++ b/litellm/proxy/mcp_server/state_tokens.py @@ -12,7 +12,7 @@ from cryptography.hazmat.primitives.ciphers.aead import AESGCM from cryptography.hazmat.primitives.kdf.hkdf import HKDF from pydantic import BaseModel, ConfigDict, JsonValue, ValidationError -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error, Ok, Result +from litellm.proxy.mcp_server.outbound_credentials.result import Error, Ok, Result _PREFIX: Final = "mcp_state_v1." _MAX_TOKEN_LENGTH: Final = 65536 diff --git a/litellm/proxy/_experimental/mcp_server/stdio_gate.py b/litellm/proxy/mcp_server/stdio_gate.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/stdio_gate.py rename to litellm/proxy/mcp_server/stdio_gate.py diff --git a/litellm/proxy/_experimental/mcp_server/subscriptions.py b/litellm/proxy/mcp_server/subscriptions.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/subscriptions.py rename to litellm/proxy/mcp_server/subscriptions.py index e9de5692d83..f133752ee32 100644 --- a/litellm/proxy/_experimental/mcp_server/subscriptions.py +++ b/litellm/proxy/mcp_server/subscriptions.py @@ -48,17 +48,17 @@ from mcp.types import ( ) from litellm.constants import MCP_TOOL_LISTING_MAX_PAGES, MCP_TOOL_LISTING_TIMEOUT -from litellm.experimental_mcp_client.client import MCPClient -from litellm.proxy._experimental.mcp_server import operations -from litellm.proxy._experimental.mcp_server.catalog import ( - ToolListingFailedOutright, -) -from litellm.proxy._experimental.mcp_server.catalog import ( - _configuration_identity as configuration_identity, # pyright: ignore[reportPrivateUsage] # reuse catalog-owned configuration identity without treating discovered metadata as configuration -) -from litellm.proxy._experimental.mcp_server.contracts import OperationContext +from litellm.mcp_client.client import MCPClient from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError +from litellm.proxy.mcp_server import operations +from litellm.proxy.mcp_server.catalog import ( + ToolListingFailedOutright, +) +from litellm.proxy.mcp_server.catalog import ( + _configuration_identity as configuration_identity, # pyright: ignore[reportPrivateUsage] # reuse catalog-owned configuration identity without treating discovered metadata as configuration +) +from litellm.proxy.mcp_server.contracts import OperationContext from litellm.types.mcp import MCP_LEGACY_VERSIONS from litellm.types.mcp_server.mcp_server_manager import MCPServer diff --git a/litellm/proxy/_experimental/mcp_server/tool_catalog_guard.py b/litellm/proxy/mcp_server/tool_catalog_guard.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/tool_catalog_guard.py rename to litellm/proxy/mcp_server/tool_catalog_guard.py index b3c70a33d0e..4bf7b584977 100644 --- a/litellm/proxy/_experimental/mcp_server/tool_catalog_guard.py +++ b/litellm/proxy/mcp_server/tool_catalog_guard.py @@ -12,7 +12,7 @@ from mcp.types import Tool as MCPTool from pydantic import TypeAdapter from typing_extensions import ReadOnly, TypedDict -from litellm.proxy._experimental.mcp_server.utils import logging_safe_mcp_headers, strip_known_server_prefix +from litellm.proxy.mcp_server.utils import logging_safe_mcp_headers, strip_known_server_prefix from litellm.types.mcp import MCPPreCallRequestObject from litellm.types.mcp_server.mcp_server_manager import MCPServer, PinnedMCPTool from litellm.types.utils import CallTypes diff --git a/litellm/proxy/_experimental/mcp_server/tool_outcome.py b/litellm/proxy/mcp_server/tool_outcome.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/tool_outcome.py rename to litellm/proxy/mcp_server/tool_outcome.py diff --git a/litellm/proxy/_experimental/mcp_server/tool_registry.py b/litellm/proxy/mcp_server/tool_registry.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/tool_registry.py rename to litellm/proxy/mcp_server/tool_registry.py diff --git a/litellm/proxy/_experimental/mcp_server/tool_search.py b/litellm/proxy/mcp_server/tool_search.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/tool_search.py rename to litellm/proxy/mcp_server/tool_search.py index 371a1ff6fc9..96bcf8fbacf 100644 --- a/litellm/proxy/_experimental/mcp_server/tool_search.py +++ b/litellm/proxy/mcp_server/tool_search.py @@ -20,7 +20,6 @@ from typing_extensions import ReadOnly, Required, assert_never import litellm from litellm.llms.litellm_proxy.skills.skill_search import DEFAULT_SKILL_SEARCH_TOP_K -from litellm.proxy._experimental.mcp_server.result_conversion import WireCompat, complete_call_tool_result from litellm.proxy.agent_endpoints.agent_search import DEFAULT_AGENT_SEARCH_TOP_K from litellm.proxy.common_utils.semantic_text_index import ( Embedder, @@ -28,6 +27,7 @@ from litellm.proxy.common_utils.semantic_text_index import ( SemanticTextIndex, router_embedder, ) +from litellm.proxy.mcp_server.result_conversion import WireCompat, complete_call_tool_result from litellm.types.mcp import MCPToolSearchSettings if TYPE_CHECKING: @@ -549,7 +549,7 @@ async def handle_mcp_tool_search( oauth2_headers: dict[str, str] | None = None, raw_headers: dict[str, str] | None = None, ) -> CallToolResult: - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( _list_mcp_tools, ) from litellm.proxy.proxy_server import llm_router, proxy_logging_obj @@ -606,7 +606,7 @@ async def handle_mcp_proxy_tool( from fastapi import HTTPException from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( _list_mcp_tools, find_mcp_proxy_tool, ) @@ -713,7 +713,7 @@ async def handle_mcp_tool_call( incoming_bearer_token: SecretStr | None | EllipsisType = ..., guardrail_auth: UserAPIKeyAuth | None = None, ) -> CallToolResult: - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( _get_allowed_mcp_servers, execute_mcp_tool, raise_denied_scoped_mcp_access, diff --git a/litellm/proxy/_experimental/mcp_server/toolset_db.py b/litellm/proxy/mcp_server/toolset_db.py similarity index 95% rename from litellm/proxy/_experimental/mcp_server/toolset_db.py rename to litellm/proxy/mcp_server/toolset_db.py index f3a78d206d7..ae40e8af0d9 100644 --- a/litellm/proxy/_experimental/mcp_server/toolset_db.py +++ b/litellm/proxy/mcp_server/toolset_db.py @@ -117,7 +117,7 @@ async def list_mcp_toolsets( except Exception as e: if use_writer: raise - verbose_proxy_logger.warning("litellm.proxy._experimental.mcp_server.toolset_db::list_mcp_toolsets - %s", e) + verbose_proxy_logger.warning("litellm.proxy.mcp_server.toolset_db::list_mcp_toolsets - %s", e) return [] @@ -131,6 +131,10 @@ async def get_mcp_toolset_by_name( return _toolset_from_row(row) +def _set_fields(data: UpdateMCPToolsetRequest) -> Mapping[str, object]: + return data.model_dump(exclude_unset=True) + + async def update_mcp_toolset( prisma_client: PrismaClient, data: UpdateMCPToolsetRequest, @@ -143,7 +147,7 @@ async def update_mcp_toolset( data_dict: Final = dict( ( (field, json.dumps(value) if field == "tools" else value) - for field, value in data.model_dump(exclude_unset=True).items() + for field, value in _set_fields(data).items() if field != "toolset_id" and (field not in ("toolset_name", "tools") or value is not None) ), updated_by=touched_by, diff --git a/litellm/proxy/_experimental/mcp_server/ui_session_utils.py b/litellm/proxy/mcp_server/ui_session_utils.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/ui_session_utils.py rename to litellm/proxy/mcp_server/ui_session_utils.py index 9f60f0afbb6..308a41b8938 100644 --- a/litellm/proxy/_experimental/mcp_server/ui_session_utils.py +++ b/litellm/proxy/mcp_server/ui_session_utils.py @@ -97,7 +97,7 @@ async def admitted_user_context(user_api_key_auth: UserAPIKeyAuth) -> UserAPIKey user_id: Final = user_api_key_auth.user_id if not is_ui_session_credential(user_api_key_auth) or user_id is None: return None - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -192,7 +192,7 @@ async def toolset_grant_contexts( if not is_keyless_mcp_subject(user_api_key_auth): return (user_api_key_auth,) - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -269,7 +269,7 @@ async def granted_toolset_ids( ``require_key_mcp_access_defined``, which inherits nothing. A keyless subject's team sources always inherit. A team that cannot be read contributes nothing while every other source still counts, and an own grant that is named but cannot be read grants nothing. No grant anywhere yields the empty set.""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) from litellm.proxy.proxy_server import general_settings diff --git a/litellm/proxy/_experimental/mcp_server/upstream.py b/litellm/proxy/mcp_server/upstream.py similarity index 94% rename from litellm/proxy/_experimental/mcp_server/upstream.py rename to litellm/proxy/mcp_server/upstream.py index 1e39c068806..96a1c2db9ba 100644 --- a/litellm/proxy/_experimental/mcp_server/upstream.py +++ b/litellm/proxy/mcp_server/upstream.py @@ -7,12 +7,13 @@ import httpx2 from fastapi import HTTPException from litellm.constants import MCP_CLIENT_TIMEOUT, MCP_NPM_CACHE_DIR, MCP_STDIO_ALLOWED_COMMANDS -from litellm.experimental_mcp_client.client import MCPClient, MCPSigV4Auth -from litellm.proxy._experimental.mcp_server.legacy_callbacks import ElicitationCallback, SamplingCallback -from litellm.proxy._experimental.mcp_server.mcp_debug import record_auth_resolution -from litellm.proxy._experimental.mcp_server.oauth2_token_cache import resolve_mcp_auth, resolved_token_header -from litellm.proxy._experimental.mcp_server.outbound_credentials import Error, Ok, UpstreamCredentialProvider -from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( +from litellm.mcp_client.client import MCPClient, MCPSigV4Auth +from litellm.proxy._types import MCPTransport, UserAPIKeyAuth +from litellm.proxy.mcp_server.legacy_callbacks import ElicitationCallback, SamplingCallback +from litellm.proxy.mcp_server.mcp_debug import record_auth_resolution +from litellm.proxy.mcp_server.oauth2_token_cache import resolve_mcp_auth, resolved_token_header +from litellm.proxy.mcp_server.outbound_credentials import Error, Ok, UpstreamCredentialProvider +from litellm.proxy.mcp_server.outbound_credentials.adapter import ( prepare_mcp_client, raise_public, raise_token_exchange_challenge, @@ -20,8 +21,8 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import to_server_spec, to_subject, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source +from litellm.proxy.mcp_server.outbound_credentials.types import ( DEFAULT_CREDENTIAL_HEADER, AuthorizationCodeConfig, AuthResolution, @@ -32,8 +33,7 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( ServerSpec, TokenExchangeConfig, ) -from litellm.proxy._experimental.mcp_server.stdio_gate import MCP_STDIO_DISABLED_MESSAGE, is_mcp_stdio_enabled -from litellm.proxy._types import MCPTransport, UserAPIKeyAuth +from litellm.proxy.mcp_server.stdio_gate import MCP_STDIO_DISABLED_MESSAGE, is_mcp_stdio_enabled from litellm.types.mcp import ( MCPAuth, MCPStdioConfig, diff --git a/litellm/proxy/_experimental/mcp_server/utils.py b/litellm/proxy/mcp_server/utils.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/utils.py rename to litellm/proxy/mcp_server/utils.py index 1684b9c5c30..ee8f3ea3b30 100644 --- a/litellm/proxy/_experimental/mcp_server/utils.py +++ b/litellm/proxy/mcp_server/utils.py @@ -13,6 +13,8 @@ from collections.abc import Set as AbstractSet from typing import Any, Final, Literal, Protocol, overload from urllib.parse import quote +from pydantic import TypeAdapter + from litellm._logging import verbose_logger from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -21,6 +23,7 @@ if typing.TYPE_CHECKING: MCP_SERVERS_TARGET: Final = "mcp_servers" MCP_OAUTH_TOKENS_TARGET: Final = "mcp_oauth_tokens" +_DECODED_JSON: Final = TypeAdapter(object) class ASGIScopeFields(Protocol): @@ -243,7 +246,7 @@ def _parse_mcp_info_dict(mcp_info: object) -> Mapping[str, object] | None: return mcp_info if isinstance(mcp_info, str): try: - parsed: Final[object] = json.loads(mcp_info) + parsed: Final = _DECODED_JSON.validate_python(json.loads(mcp_info)) except (ValueError, TypeError): return None return parsed if isinstance(parsed, dict) else None diff --git a/litellm/proxy/memory/memory_endpoints.py b/litellm/proxy/memory/memory_endpoints.py index 34c80bcdce3..4457df460d4 100644 --- a/litellm/proxy/memory/memory_endpoints.py +++ b/litellm/proxy/memory/memory_endpoints.py @@ -181,8 +181,8 @@ async def _assert_write_access( """ if _is_admin(user_api_key_dict): return - row_user_id: Final = getattr(row, "user_id", None) - row_team_id: Final = getattr(row, "team_id", None) + row_user_id: Final = row.user_id + row_team_id: Final = row.team_id # Personal ownership. if row_user_id and row_user_id == user_api_key_dict.user_id: diff --git a/litellm/proxy/moyai_endpoints.py b/litellm/proxy/moyai_endpoints.py index c4d8ad139f7..45f4502ec4e 100644 --- a/litellm/proxy/moyai_endpoints.py +++ b/litellm/proxy/moyai_endpoints.py @@ -20,9 +20,10 @@ from typing import TYPE_CHECKING, Annotated, Final from urllib.parse import urlencode, urlparse from fastapi import APIRouter, Depends, HTTPException, Request, status -from pydantic import BaseModel +from pydantic import BaseModel, TypeAdapter from litellm._internal_context import with_service_target +from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth from litellm.proxy.auth.user_api_key_auth import user_api_key_auth from litellm.proxy.ui_crud_endpoints.proxy_setting_endpoints import ( @@ -114,6 +115,9 @@ def _sign_connect_code(master_key: str, moyai_url: str, user_id: str | None) -> return f"{_b64url(payload)}.{_b64url(signature)}" +_DECODED_CONNECT_PAYLOAD: Final = TypeAdapter(object) + + def _decode_connect_code(master_key: str, code: str) -> _MoyaiConnectCode: try: payload_b64, signature_b64 = code.split(".", 1) @@ -125,18 +129,23 @@ def _decode_connect_code(master_key: str, code: str) -> _MoyaiConnectCode: if not hmac.compare_digest(signature, expected): raise HTTPException(status_code=400, detail="Invalid Moyai connect code") try: - payload: Final = json.loads(payload_raw) + payload: Final = as_str_mapping(_DECODED_CONNECT_PAYLOAD.validate_python(json.loads(payload_raw))) except (ValueError, TypeError): raise HTTPException(status_code=400, detail="Invalid Moyai connect code") - if not isinstance(payload, dict) or not isinstance(payload.get("exp"), int) or payload["exp"] < int(time.time()): + if payload is None: raise HTTPException(status_code=400, detail="Invalid Moyai connect code") - if not isinstance(payload.get("moyai_origin"), str) or not isinstance(payload.get("nonce"), str): + exp: Final = payload.get("exp") + if not isinstance(exp, int) or exp < int(time.time()): + raise HTTPException(status_code=400, detail="Invalid Moyai connect code") + moyai_origin: Final = payload.get("moyai_origin") + nonce: Final = payload.get("nonce") + if not isinstance(moyai_origin, str) or not isinstance(nonce, str): raise HTTPException(status_code=400, detail="Invalid Moyai connect code") user_id: Final = payload.get("user_id") return _MoyaiConnectCode( - moyai_origin=payload["moyai_origin"], - nonce=payload["nonce"], - exp=payload["exp"], + moyai_origin=moyai_origin, + nonce=nonce, + exp=exp, user_id=user_id if isinstance(user_id, str) else None, ) diff --git a/litellm/proxy/openai_files_endpoints/batch_file_validation.py b/litellm/proxy/openai_files_endpoints/batch_file_validation.py index 1aa24eed4cd..5d596aece32 100644 --- a/litellm/proxy/openai_files_endpoints/batch_file_validation.py +++ b/litellm/proxy/openai_files_endpoints/batch_file_validation.py @@ -4,12 +4,15 @@ from dataclasses import dataclass from itertools import chain from typing import BinaryIO, Final, NoReturn +from pydantic import TypeAdapter from typing_extensions import assert_never +from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.proxy._types import ProxyException from litellm.proxy.openai_files_endpoints.file_usage_caps import FileUsageLimit, describe_limit_source _MB: Final = 1024 * 1024 +_DECODED_LINE: Final = TypeAdapter(object) @dataclass(frozen=True, slots=True) @@ -95,10 +98,10 @@ def _iter_lines(file_source: bytes | BinaryIO) -> Iterator[bytes]: def _check_line(line_number: int, raw_line: bytes, line_shape: BatchLineShape) -> BatchFileValidationFailure | None: try: - parsed: Final = json.loads(raw_line) + parsed: Final = as_str_mapping(_DECODED_LINE.validate_python(json.loads(raw_line))) except (ValueError, RecursionError): return BatchFileInvalidJsonLine(line_number=line_number) - if not isinstance(parsed, dict): + if parsed is None: return BatchFileLineNotObject(line_number=line_number) missing: Final = next((key for key in line_shape.required_keys if key not in parsed), None) if missing is None: diff --git a/litellm/proxy/openai_files_endpoints/storage_backend_service.py b/litellm/proxy/openai_files_endpoints/storage_backend_service.py index afc1e1c96fa..1f507982e65 100644 --- a/litellm/proxy/openai_files_endpoints/storage_backend_service.py +++ b/litellm/proxy/openai_files_endpoints/storage_backend_service.py @@ -8,10 +8,11 @@ storage backends (e.g., Azure Blob Storage) and managing associated metadata. import base64 import time from collections.abc import Sequence -from typing import Any, Final, cast +from typing import Final from litellm._logging import verbose_proxy_logger from litellm._uuid import uuid as uuid_module +from litellm.litellm_core_utils.core_helpers import require_attributes from litellm.litellm_core_utils.hidden_params import get_or_create_hidden_params from litellm.llms.base_llm.files.storage_backend import BaseFileStorageBackend from litellm.llms.base_llm.files.storage_backend_factory import get_storage_backend @@ -19,6 +20,7 @@ from litellm.llms.base_llm.files.transformation import BaseFileEndpoints from litellm.proxy._types import ProxyException, UserAPIKeyAuth from litellm.proxy.utils import PrismaClient, ProxyLogging from litellm.types.llms.openai import OpenAIFileObject, OpenAIFilesPurpose +from litellm.types.passthrough_endpoints.managed_id_rewriter import ManagedFileIdWriter from litellm.types.utils import ExtractedFileData, SpecialEnums @@ -232,11 +234,10 @@ class StorageBackendFileService: proxy_logging_obj: Proxy logging object user_api_key_dict: User API key authentication data """ - managed_files_obj = proxy_logging_obj.get_proxy_hook("managed_files") + managed_files_obj: Final = proxy_logging_obj.get_proxy_hook("managed_files") if not managed_files_obj or not isinstance(managed_files_obj, BaseFileEndpoints): verbose_proxy_logger.warning("Managed files hook not available, skipping managed files storage") return - managed_files_obj = cast(Any, managed_files_obj) # Create model mappings using storage URL model_mappings: Final = {model_name: storage_url for model_name in target_model_names} @@ -260,7 +261,10 @@ class StorageBackendFileService: ) # Store in managed files - await managed_files_obj.store_unified_file_id( + managed_files_writer: Final = require_attributes( + managed_files_obj, ManagedFileIdWriter, "store_unified_file_id" + ) + await managed_files_writer.store_unified_file_id( file_id=base64_unified_file_id, file_object=file_object, litellm_parent_otel_span=user_api_key_dict.parent_otel_span, diff --git a/litellm/proxy/pass_through_endpoints/codex_passthrough_endpoints.py b/litellm/proxy/pass_through_endpoints/codex_passthrough_endpoints.py new file mode 100644 index 00000000000..3087faa9f67 --- /dev/null +++ b/litellm/proxy/pass_through_endpoints/codex_passthrough_endpoints.py @@ -0,0 +1,87 @@ +import hmac +from types import MappingProxyType +from typing import Annotated, Final, Literal + +from fastapi import APIRouter, Depends, HTTPException, Request, Response + +from litellm.llms.chatgpt.common_utils import CHATGPT_API_BASE +from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.auth.user_api_key_auth import user_api_key_auth +from litellm.proxy.pass_through_endpoints.pass_through_endpoints import pass_through_request + +router: Final = APIRouter() +_HEADERS: Final = frozenset( + { + "authorization", + "chatgpt-account-id", + "content-type", + "accept", + "user-agent", + "originator", + "openai-beta", + "session-id", + "thread-id", + "session_id", + "conversation_id", + "x-codex-turn-metadata", + "x-codex-turn-state", + } +) + + +@router.get("/backend-api/codex/{endpoint}", tags=["ChatGPT Pass-through", "pass-through"]) +@router.post( + "/backend-api/codex/{endpoint}", + tags=["ChatGPT Pass-through", "pass-through"], + openapi_extra={ + "requestBody": { + "required": True, + "content": {"application/json": {"schema": {"type": "object", "additionalProperties": True}}}, + } + }, + responses={ + 200: { + "description": "Unmodified Codex response or server-sent events", + "content": { + "application/json": {"schema": {"type": "object", "additionalProperties": True}}, + "text/event-stream": {"schema": {"type": "string"}}, + }, + } + }, +) +async def codex_passthrough_route( + endpoint: Literal["models", "responses"], + request: Request, + user_api_key_dict: Annotated[UserAPIKeyAuth, Depends(user_api_key_auth)], +) -> Response: + """Forward a client's ChatGPT subscription with separate LiteLLM authentication.""" + expected_method: Final = "GET" if endpoint == "models" else "POST" + if request.method != expected_method: + raise HTTPException(status_code=405, detail="Method not allowed", headers={"Allow": expected_method}) + + authorization: Final = request.headers.get("authorization", "") + scheme, _, token = authorization.partition(" ") + gateway_key: Final = request.headers.get("x-litellm-api-key", "") + gateway_parts: Final = gateway_key.split() + gateway_token: Final = ( + gateway_parts[-1] + if len(gateway_parts) == 1 or (len(gateway_parts) == 2 and gateway_parts[0].lower() == "bearer") + else "" + ) + if scheme.lower() != "bearer" or not token.strip() or not gateway_token: + raise HTTPException( + status_code=401, + detail="Send the ChatGPT bearer in Authorization and the LiteLLM key in x-litellm-api-key", + ) + if hmac.compare_digest(token.strip().encode(), gateway_token.encode()): + raise HTTPException(status_code=401, detail="ChatGPT and LiteLLM credentials must be separate") + + headers: Final = MappingProxyType({name: value for name, value in request.headers.items() if name in _HEADERS}) + return await pass_through_request( + request=request, + target=f"{CHATGPT_API_BASE}/{endpoint}", + custom_headers=dict(headers), + user_api_key_dict=user_api_key_dict, + custom_llm_provider="chatgpt", + upstream_headers_filter=lambda _: headers, + ) diff --git a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py index 16fbd1de376..9eef4f0ef9d 100644 --- a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py +++ b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py @@ -1305,7 +1305,7 @@ async def handle_bedrock_count_tokens( verbose_proxy_logger.error("BedrockError in handle_bedrock_count_tokens: %s", e) from litellm.litellm_core_utils.llm_response_utils.get_headers import get_response_headers - provider_headers: Final = getattr(getattr(e, "response", None), "headers", None) + provider_headers: Final = e.response.headers raise HTTPException( status_code=e.status_code, detail={"error": e.message}, diff --git a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py index 23ef89b3c5c..7c7eb51bc5d 100644 --- a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py +++ b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py @@ -1,28 +1,34 @@ import asyncio import json -from collections.abc import Mapping, Sequence +from collections.abc import Iterator, Mapping, Sequence from datetime import datetime from typing import TYPE_CHECKING, Any, Final, cast import httpx -from pydantic import ConfigDict, TypeAdapter +from pydantic import ConfigDict, TypeAdapter, ValidationError import litellm from litellm._logging import verbose_proxy_logger from litellm.constants import ANTHROPIC_BATCHES_ROUTE +from litellm.litellm_core_utils.core_helpers import ( + native_messages_reported_cost, + override_stamped_response_cost, + response_cost_in_hidden_params, +) from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj from litellm.litellm_core_utils.litellm_logging import use_custom_pricing_for_model from litellm.litellm_core_utils.prompt_templates.common_utils import ( get_content_from_model_response, ) from litellm.llms.anthropic import get_anthropic_config -from litellm.llms.anthropic.pass_through.stream_assembly import ( +from litellm.llms.anthropic.messages.stream_assembly import ( build_complete_streaming_response, build_complete_streaming_response_legacy, build_usage_only_response_from_chunks, collapse_pure_text_chunks, split_sse_chunk_into_events, ) +from litellm.llms.bedrock.common_utils import BEDROCK_INVOKE_TRACE_FIELD from litellm.proxy._types import PassThroughEndpointLoggingTypedDict from litellm.proxy.auth.auth_utils import get_end_user_id_from_request_body from litellm.proxy.pass_through_endpoints.llm_provider_handlers.batch_attribution import ( @@ -53,6 +59,49 @@ else: _JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_input_in_errors=True)) +def _event_payload(event: str) -> Mapping[str, object] | None: + data_lines: Final = tuple( + line.strip()[len("data:") :].strip() for line in event.splitlines() if line.strip().startswith("data:") + ) + if not data_lines or data_lines[0] in ("", "[DONE]"): + return None + try: + return _JSON_OBJECT.validate_json(data_lines[0]) + except ValidationError: + return None + + +def _bedrock_trace_payload(all_chunks: Sequence[str | bytes]) -> Mapping[str, object] | None: + payloads: Final = ( + _event_payload(event) + for chunk in reversed(all_chunks) + for event in reversed(split_sse_chunk_into_events(chunk)) + ) # comprehension-ok: chunk then event, read newest first + return next( + (payload for payload in payloads if payload is not None and BEDROCK_INVOKE_TRACE_FIELD in payload), None + ) + + +def _message_delta_usages(all_chunks: Sequence[str | bytes]) -> Iterator[object]: + for chunk in reversed(all_chunks): + yield from ( + payload.get("usage") + for payload in map(_event_payload, reversed(split_sse_chunk_into_events(chunk))) + if payload is not None and payload.get("type") == "message_delta" + ) + + +def _stamp_reported_stream_cost( + response: ModelResponse, all_chunks: Sequence[str | bytes], logging_obj: LiteLLMLoggingObj +) -> None: + """The final ``message_delta`` is where a provider that prices its own responses reports the cost.""" + provider: Final = logging_obj.model_call_details.get("custom_llm_provider") + costs: Final = (native_messages_reported_cost(usage, provider) for usage in _message_delta_usages(all_chunks)) + reported: Final = next((cost for cost in costs if cost is not None), None) + if reported is not None: + override_stamped_response_cost(response, reported) + + class AnthropicPassthroughLoggingHandler: @staticmethod def anthropic_passthrough_handler( @@ -104,6 +153,7 @@ class AnthropicPassthroughLoggingHandler: json_mode=False, litellm_params={}, ) + logging_obj.record_native_bedrock_guardrail(response_body) # pyright: ignore[reportUnknownArgumentType] # response_body is an untyped dict param kwargs = AnthropicPassthroughLoggingHandler._create_anthropic_response_logging_payload( litellm_model_response=litellm_model_response, @@ -222,6 +272,7 @@ class AnthropicPassthroughLoggingHandler: ) if not isinstance(response, ModelResponse): return response + _stamp_reported_stream_cost(response, all_chunks, litellm_logging_obj) recovered_usage: Final = AnthropicPassthroughLoggingHandler._recover_interrupted_stream_output_tokens( response=response, all_chunks=all_chunks, model=model ) @@ -286,13 +337,21 @@ class AnthropicPassthroughLoggingHandler: if custom_llm_provider and not model.startswith(f"{custom_llm_provider}/") else model ) + custom_pricing: Final = use_custom_pricing_for_model( + litellm_params=(logging_obj.litellm_params if hasattr(logging_obj, "litellm_params") else None) + ) + reported_cost: Final = ( + response_cost_in_hidden_params(litellm_model_response) + if isinstance(litellm_model_response, ModelResponse) + else None + ) + if reported_cost is not None and not custom_pricing: + return reported_cost return litellm.completion_cost( completion_response=litellm_model_response, model=model_for_cost, custom_llm_provider=custom_llm_provider, - custom_pricing=use_custom_pricing_for_model( - litellm_params=(logging_obj.litellm_params if hasattr(logging_obj, "litellm_params") else None) - ), + custom_pricing=custom_pricing, router_model_id=logging_obj.get_router_model_id(), ) @@ -500,6 +559,7 @@ class AnthropicPassthroughLoggingHandler: "result": None, "kwargs": {}, } + litellm_logging_obj.record_native_bedrock_guardrail(_bedrock_trace_payload(all_chunks)) kwargs: Final = AnthropicPassthroughLoggingHandler._create_anthropic_response_logging_payload( litellm_model_response=complete_streaming_response, model=model, diff --git a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/comprehend_medical_passthrough_logging_handler.py b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/comprehend_medical_passthrough_logging_handler.py index 7527c504c59..3fb4fbd555d 100644 --- a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/comprehend_medical_passthrough_logging_handler.py +++ b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/comprehend_medical_passthrough_logging_handler.py @@ -27,11 +27,15 @@ COMPREHEND_MEDICAL_COST_PER_UNIT_USD: Final[Mapping[str, float]] = MappingProxyT COMPREHEND_MEDICAL_SUPPORTED_OPERATIONS: Final = frozenset(COMPREHEND_MEDICAL_COST_PER_UNIT_USD) +def _operation_from_headers(headers: Mapping[str, str]) -> str: + target: Final = headers.get("x-amz-target", "") + return target.split(".")[-1] + + class ComprehendMedicalPassthroughLoggingHandler: @staticmethod def _operation_from_response(httpx_response: httpx.Response) -> str: - target: Final[str] = httpx_response.request.headers.get("x-amz-target", "") - return target.split(".")[-1] + return _operation_from_headers(httpx_response.request.headers) @staticmethod def get_cost_for_operation(operation: str, text: str) -> float: diff --git a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/openai_passthrough_logging_handler.py b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/openai_passthrough_logging_handler.py index c763b5dc26e..c410150df70 100644 --- a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/openai_passthrough_logging_handler.py +++ b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/openai_passthrough_logging_handler.py @@ -10,6 +10,7 @@ from typing import Final, Literal, TypeAlias from urllib.parse import urlparse import httpx +from pydantic import TypeAdapter import litellm from litellm._logging import verbose_proxy_logger @@ -95,6 +96,8 @@ def is_openai_compatible_url(url_route: str | None) -> bool: hostname: Final = parsed_url.hostname if not hostname: return False + if hostname == "chatgpt.com" and parsed_url.path.startswith("/backend-api/codex/"): + return True if _hostname_matches(hostname, _OPENAI_HOSTNAMES): return True if _hostname_matches(hostname, _AZURE_OPENAI_HOSTNAMES): @@ -198,7 +201,7 @@ class OpenAIPassthroughLoggingHandler(BasePassthroughLoggingHandler): if not url_route: return False parsed_url: Final = urlparse(url_route) - return _is_openai_compatible_host(parsed_url.hostname) and ( + return is_openai_compatible_url(url_route) and ( "/v1/responses" in parsed_url.path or "/responses" in parsed_url.path ) @@ -424,7 +427,9 @@ class OpenAIPassthroughLoggingHandler(BasePassthroughLoggingHandler): ) = None handler_instance: Final = OpenAIPassthroughLoggingHandler() - custom_llm_provider: Final = kwargs.get("custom_llm_provider", "openai") + custom_llm_provider: Final = TypeAdapter(str).validate_python( + kwargs.get("custom_llm_provider", logging_obj.model_call_details.get("custom_llm_provider", "openai")) + ) if is_chat_completions: # Handle chat completions with existing logic diff --git a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/tinyfish_passthrough_logging_handler.py b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/tinyfish_passthrough_logging_handler.py index e277655f1e1..2afc1d17bc2 100644 --- a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/tinyfish_passthrough_logging_handler.py +++ b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/tinyfish_passthrough_logging_handler.py @@ -36,6 +36,7 @@ from litellm.types.passthrough_endpoints.tinyfish import ( from litellm.types.utils import StandardPassThroughResponseObject _RUN_ADAPTER: Final = TypeAdapter(TinyfishRun) +_DECODED_JSON: Final = TypeAdapter(object) _EMPTY_KWARGS: Final[Mapping[str, object]] = MappingProxyType({}) @@ -323,7 +324,7 @@ class TinyFishPassthroughLoggingHandler: "TinyFish passthrough: GET /v1/runs/%s returned %s", safe_run_id, response.status_code ) return None - payload: Final[object] = response.json() # any-ok: httpx Response.json() -> Any + payload: Final = _DECODED_JSON.validate_python(response.json()) return _parse_run(payload) except Exception as e: # noqa: BLE001 # billing/logging must never break the relayed request verbose_proxy_logger.warning("[Non blocking logging error] TinyFish run fetch failed: %s", e) @@ -413,7 +414,7 @@ def _run_id_from_sse_chunks(all_chunks: Sequence[str]) -> str | None: if not line.startswith("data:"): continue try: - event_payload: object = json.loads(line[5:].strip()) # any-ok: json.loads -> Any + event_payload: object = _DECODED_JSON.validate_python(json.loads(line[5:].strip())) except json.JSONDecodeError: continue event = _parse_run(event_payload) diff --git a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/transcribe_passthrough_logging_handler.py b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/transcribe_passthrough_logging_handler.py index 79f6dee90f7..5b45316a44c 100644 --- a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/transcribe_passthrough_logging_handler.py +++ b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/transcribe_passthrough_logging_handler.py @@ -492,6 +492,10 @@ def s3_media_url(media_uri: str, aws_region_name: str) -> str | None: return f"https://{bucket}.s3.{aws_region_name}.{dns_suffix}/{quote(key)}" +def _header_or_default(headers: Mapping[str, str], name: str, default: str) -> str: + return headers.get(name, default) + + def media_predates_job(headers: Mapping[str, str], job_created_at: float) -> bool: try: modified_at: Final = parsedate_to_datetime(headers["last-modified"]).timestamp() @@ -501,7 +505,7 @@ def media_predates_job(headers: Mapping[str, str], job_created_at: float) -> boo async def write_media_within_limit(response: httpx.Response, media_file: IO[bytes], max_bytes: int) -> bool: - if int(response.headers.get("content-length", "0")) > max_bytes: + if int(_header_or_default(response.headers, "content-length", "0")) > max_bytes: return False async for chunk in response.aiter_bytes(): _ = media_file.write(chunk) @@ -591,8 +595,7 @@ class TranscribePassthroughLoggingHandler: @staticmethod def _operation_from_response(httpx_response: httpx.Response) -> str: - headers: Final[Mapping[str, str]] = httpx_response.request.headers - target: Final[str] = headers.get("x-amz-target", "") + target: Final = _header_or_default(httpx_response.request.headers, "x-amz-target", "") return target.split(".")[-1] @staticmethod diff --git a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py index e1e8864678e..97f2c10afb1 100644 --- a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py +++ b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py @@ -118,6 +118,8 @@ from litellm.proxy.litellm_pre_call_utils import ( # noqa: F401 # legacy modul _key_or_team_allows_client_pricing_override, # pyright: ignore[reportPrivateUsage] # reuse the proxy's pricing trust policy _strip_client_pricing_overrides, # pyright: ignore[reportPrivateUsage] # sanitize before trusted hooks add guardrail costs get_dynamic_logging_metadata, # pyright: ignore[reportPrivateUsage] # shared proxy helper, same import style as _read_request_body above + redact_credential_headers, + strip_client_guardrail_information, ) from litellm.proxy.route_llm_request import ProxyModelNotFoundError from litellm.proxy.route_priority import ( @@ -409,6 +411,8 @@ class HttpPassThroughEndpointHelpers(BasePassthroughUtils): @staticmethod def get_endpoint_type(url: str, custom_llm_provider: str | None = None) -> EndpointType: parsed_url: Final = urlparse(url) + if custom_llm_provider == "chatgpt": + return EndpointType.OPENAI if custom_llm_provider in ("typesafe", "laya", "bespoke") and parsed_url.path.removesuffix("/").endswith( "/v1/systemone" ): @@ -723,7 +727,7 @@ class HttpPassThroughEndpointHelpers(BasePassthroughUtils): "url": str(request.url), "method": request.method, "body": copy.copy(_parsed_body), # use copy instead of deepcopy - "headers": request.headers, + "headers": redact_credential_headers(request.headers), }, }, "call_type": "pass_through_endpoint", @@ -1220,10 +1224,11 @@ async def pass_through_request( _parsed_body, ) + client_body: Final = TypeAdapter(dict[str, object]).validate_python(_parsed_body) + strip_client_guardrail_information(client_body) if not _key_or_team_allows_client_pricing_override(user_api_key_dict): - pricing_body: Final = TypeAdapter(dict[str, object]).validate_python(_parsed_body) - _strip_client_pricing_overrides(pricing_body) - _parsed_body = pricing_body + _strip_client_pricing_overrides(client_body) + _parsed_body = client_body if custom_llm_provider in ("laya", "bespoke"): decision_request: Final = TypeAdapter(Mapping[str, object]).validate_python(_parsed_body) checkpoint: Final = validate_oss_request(custom_llm_provider, decision_request) @@ -1490,7 +1495,7 @@ async def pass_through_request( additional_args={ "complete_input_dict": _parsed_body, "api_base": str(logging_url), - "headers": upstream_headers, + "headers": redact_credential_headers(upstream_headers), }, ) stream = HttpPassThroughEndpointHelpers.update_stream_param_based_on_request_body( @@ -1561,7 +1566,7 @@ async def pass_through_request( data=_parsed_body or {}, user_api_key_dict=user_api_key_dict, response=relay_response, - request_headers=dict(request.headers), + request_headers=dict(redact_credential_headers(request.headers)), ) if callback_headers: _response_headers.update(callback_headers) @@ -1653,7 +1658,7 @@ async def pass_through_request( data=_parsed_body or {}, user_api_key_dict=user_api_key_dict, response=detected_relay_response, - request_headers=dict(request.headers), + request_headers=dict(redact_credential_headers(request.headers)), ) if callback_headers: _response_headers.update(callback_headers) @@ -1703,7 +1708,7 @@ async def pass_through_request( data=_parsed_body or {}, user_api_key_dict=user_api_key_dict, response=response, - request_headers=dict(request.headers), + request_headers=dict(redact_credential_headers(request.headers)), ) if relay_callback_headers: relay_custom_headers.update(relay_callback_headers) @@ -1878,7 +1883,7 @@ async def pass_through_request( data=_parsed_body or {}, user_api_key_dict=user_api_key_dict, response=response, - request_headers=dict(request.headers), + request_headers=dict(redact_credential_headers(request.headers)), ) if callback_headers: custom_headers.update(callback_headers) diff --git a/litellm/proxy/pass_through_endpoints/streaming_handler.py b/litellm/proxy/pass_through_endpoints/streaming_handler.py index b6a067b7666..c94dc16a8f5 100644 --- a/litellm/proxy/pass_through_endpoints/streaming_handler.py +++ b/litellm/proxy/pass_through_endpoints/streaming_handler.py @@ -311,7 +311,7 @@ class PassThroughStreamingHandler: @staticmethod def _error_frame_closed_at(endpoint_type: EndpointType, raw_bytes: Sequence[bytes]) -> tuple[str, str, int] | None: - from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( + from litellm.llms.anthropic.messages.native.streaming_iterator import ( closing_superseded_attempt, parse_anthropic_error_event, ) @@ -342,7 +342,7 @@ class PassThroughStreamingHandler: - Vertex AI - OpenAI """ - from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( + from litellm.llms.anthropic.messages.native.streaming_iterator import ( is_message_stop_chunk, # pyright: ignore[reportPrivateUsage] # both native stream paths share terminal-event detection is_provider_error_chunk, # pyright: ignore[reportPrivateUsage] # provider errors must not become cache evidence ) diff --git a/litellm/proxy/pass_through_endpoints/upstream_usage_headers.py b/litellm/proxy/pass_through_endpoints/upstream_usage_headers.py index 59b8d40577a..e70d583a027 100644 --- a/litellm/proxy/pass_through_endpoints/upstream_usage_headers.py +++ b/litellm/proxy/pass_through_endpoints/upstream_usage_headers.py @@ -7,6 +7,7 @@ records the reported values without recomputing them. """ import math +from collections.abc import Mapping from dataclasses import dataclass from typing import Final @@ -89,7 +90,7 @@ def _parse_total_tokens(raw_value: str | None) -> int | None: return total_tokens -def parse_upstream_reported_usage(headers: httpx.Headers) -> UpstreamReportedUsage | None: +def parse_upstream_reported_usage(headers: Mapping[str, str]) -> UpstreamReportedUsage | None: """Read the reported totals off an upstream pass-through response. Returns ``None`` when neither header is present, which is the normal case diff --git a/litellm/proxy/policy_engine/attachment_registry.py b/litellm/proxy/policy_engine/attachment_registry.py index c751091ff9b..15e7b7e8482 100644 --- a/litellm/proxy/policy_engine/attachment_registry.py +++ b/litellm/proxy/policy_engine/attachment_registry.py @@ -5,10 +5,10 @@ Attachments define WHERE policies apply, separate from the policy definitions. This allows the same policy to be attached to multiple scopes. """ -from collections.abc import Callable +from collections.abc import Callable, Mapping from datetime import datetime, timezone from types import MappingProxyType -from typing import TYPE_CHECKING, Any, Final, TypedDict +from typing import TYPE_CHECKING, Final, TypedDict from litellm._logging import verbose_proxy_logger from litellm.repositories.table_repositories import PolicyAttachmentRepository @@ -102,7 +102,7 @@ class AttachmentRegistry: self._initialized = True verbose_proxy_logger.info("Loaded %s policy attachments", len(self._attachments)) - def _parse_attachment(self, attachment_data: dict[str, Any]) -> PolicyAttachment: + def _parse_attachment(self, attachment_data: Mapping[str, object]) -> PolicyAttachment: """ Parse an attachment from raw configuration data. @@ -112,15 +112,17 @@ class AttachmentRegistry: Returns: Parsed PolicyAttachment object """ - return PolicyAttachment( - policy=attachment_data.get("policy", ""), - scope=attachment_data.get("scope"), - teams=attachment_data.get("teams"), - keys=attachment_data.get("keys"), - models=attachment_data.get("models"), - tags=attachment_data.get("tags"), - priority=attachment_data.get("priority"), - default=attachment_data.get("default", False), + return PolicyAttachment.model_validate( + { + "policy": attachment_data.get("policy", ""), + "scope": attachment_data.get("scope"), + "teams": attachment_data.get("teams"), + "keys": attachment_data.get("keys"), + "models": attachment_data.get("models"), + "tags": attachment_data.get("tags"), + "priority": attachment_data.get("priority"), + "default": attachment_data.get("default", False), + } ) def get_attached_policies( diff --git a/litellm/proxy/policy_engine/pipeline_executor.py b/litellm/proxy/policy_engine/pipeline_executor.py index 1b1b2302236..4ad29bd3478 100644 --- a/litellm/proxy/policy_engine/pipeline_executor.py +++ b/litellm/proxy/policy_engine/pipeline_executor.py @@ -11,7 +11,7 @@ from collections.abc import Callable, Mapping, Sequence from types import MappingProxyType from typing import TYPE_CHECKING, Final, Literal, TypeVar, cast -from pydantic import BaseModel +from pydantic import BaseModel, TypeAdapter import litellm from litellm._logging import verbose_proxy_logger @@ -52,6 +52,8 @@ try: except ImportError: HTTPException = None +_LEGACY_HOOK_REPLACEMENT: Final = TypeAdapter(object) + class UndeliverableStreamRewrite(Exception): def __init__(self, guardrail_name: str, reason: str) -> None: @@ -232,10 +234,12 @@ class _LegacyHookStreamAdapter(CustomGuardrail): logging_obj: "LiteLLMLoggingObj | None" = None, ) -> GenericGuardrailAPIInputs: hooked: Final = self.endpoint_translation.post_call_hook_response(request_data.get("response")) - replacement: Final = await self.inner.async_post_call_success_hook( - data=request_data, - user_api_key_dict=self.user_api_key_dict, - response=hooked, + replacement: Final = _LEGACY_HOOK_REPLACEMENT.validate_python( + await self.inner.async_post_call_success_hook( + data=request_data, + user_api_key_dict=self.user_api_key_dict, + response=hooked, + ) ) rewrite: Final = hooked if replacement is None else replacement if rewrite is None: diff --git a/litellm/proxy/policy_engine/policy_endpoints.py b/litellm/proxy/policy_engine/policy_endpoints.py index f4b38bea14e..68ac71c567b 100644 --- a/litellm/proxy/policy_engine/policy_endpoints.py +++ b/litellm/proxy/policy_engine/policy_endpoints.py @@ -623,7 +623,7 @@ async def test_pipeline( ``` """ try: - validated_pipeline: Final = GuardrailPipeline(**request.pipeline) + validated_pipeline: Final = GuardrailPipeline.model_validate(request.pipeline) except Exception as e: raise HTTPException(status_code=400, detail=f"Invalid pipeline: {e}") diff --git a/litellm/proxy/proxy_cli.py b/litellm/proxy/proxy_cli.py index 7f68b72a522..fc33ab1bd0b 100644 --- a/litellm/proxy/proxy_cli.py +++ b/litellm/proxy/proxy_cli.py @@ -218,6 +218,23 @@ class ProxyInitializationHelpers: _run_health_check = run_health_check + @staticmethod + def run_migration_data_check(use_migrate: bool) -> int: + """`--check_migrations_against_existing_data`: the pre-migration row check against DATABASE_URL, nothing applied. + 0 when the pending schema changes fit the rows, 2 with the refusal when they do not.""" + if os.getenv("DATABASE_URL") is None: + raise click.UsageError("--check_migrations_against_existing_data requires DATABASE_URL") + from litellm.proxy.db.prisma_client import PrismaManager + + refusal: Final[str | None] = PrismaManager.migration_data_check_report(use_migrate=use_migrate) # pyright: ignore[reportUnknownVariableType] # litellm-proxy-extras is an optional install + if refusal is None: + print("LiteLLM Proxy: the pending migrations and indexes can be applied to the rows this database has.") + return 0 + print( + f"\033[1;31mLiteLLM Proxy: Database migration cannot proceed. {refusal}\033[0m", file=sys.stderr, flush=True + ) + return 2 + @staticmethod def run_config_validation(config: str | None) -> None: if config is None: @@ -978,6 +995,13 @@ class ProxyInitializationHelpers: default=False, help="Load and validate the config file (including mcp_servers) without starting the server, then exit. Exit code 1 on any config error.", ) +@click.option( + "--check_migrations_against_existing_data", + is_flag=True, + default=False, + help="Check, read-only, that the rows in DATABASE_URL can take this version's pending migrations and indexes, " + "print what would block them, then exit without applying anything. Exit code 2 when something blocks.", +) @click.option( "--keepalive_timeout", default=None, @@ -1127,6 +1151,7 @@ def run_server( use_prisma_db_push: bool, skip_server_startup, validate_config: bool, + check_migrations_against_existing_data: bool, keepalive_timeout, timeout_worker_healthcheck, max_requests_before_restart: int | None, @@ -1172,6 +1197,8 @@ def run_server( if validate_config is True: ProxyInitializationHelpers.run_config_validation(config) return + if check_migrations_against_existing_data is True: + sys.exit(ProxyInitializationHelpers.run_migration_data_check(use_migrate=not use_prisma_db_push)) if enforce_prisma_migration_check: print( "\033[1;33mLiteLLM Proxy: --enforce_prisma_migration_check is " diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 222b34282df..d19802701cb 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -24,6 +24,7 @@ from collections.abc import ( Awaitable, Callable, Collection, + Container, Iterable, Mapping, MutableMapping, @@ -360,6 +361,7 @@ from litellm.litellm_core_utils.core_helpers import ( get_parent_otel_span_from_kwargs, iter_items, normalize_drop_params, + require_attributes, ) from litellm.litellm_core_utils.credential_accessor import CredentialAccessor from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj @@ -372,7 +374,7 @@ from litellm.litellm_core_utils.sensitive_data_masker import ( SensitiveDataMasker, mask_sensitive_keys, ) -from litellm.llms.anthropic.pass_through.convertible_blocks import ( +from litellm.llms.anthropic.messages.convertible_blocks import ( deployment_drops_params, drop_non_string_tool_result_texts, malformed_tool_result_count_error, @@ -381,9 +383,6 @@ from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler from litellm.llms.openai.live import parse_live_session_start from litellm.llms.openai_like.model_info import MODEL_INFO_REFRESH_SECONDS from litellm.llms.vertex_ai.vertex_llm_base import VertexBase -from litellm.proxy._experimental.mcp_server.byok_credential_cache import byok_credential_cache -from litellm.proxy._experimental.mcp_server.catalog import public_catalog_operation -from litellm.proxy._experimental.mcp_server.stdio_gate import MCP_STDIO_ENABLED_ENV_VAR, is_mcp_stdio_flag_key from litellm.proxy._lazy_features import attach_lazy_features, reserve_lazy_slot from litellm.proxy._types import * from litellm.proxy.agent_endpoints.auth.agent_access_groups import CeilingResolver, resolve_agent_access_group_ceiling @@ -474,6 +473,7 @@ from litellm.proxy.common_utils.codex_model_catalog import codex_model_list_body from litellm.proxy.common_utils.config_includes import resolve_include_file_path, resolve_includes from litellm.proxy.common_utils.config_sync_pubsub import ConfigSyncSubscriber from litellm.proxy.common_utils.credential_hydration import decrypted_or_stored +from litellm.proxy.common_utils.custom_openapi_spec import JsonObject from litellm.proxy.common_utils.debug_utils import init_verbose_loggers from litellm.proxy.common_utils.debug_utils import router as debugging_endpoints_router from litellm.proxy.common_utils.discoverable_model_filter import ( @@ -783,6 +783,9 @@ from litellm.proxy.management_helpers.team_metadata_validation import ( TEAM_METADATA_VALIDATOR_REGISTRY, parse_team_metadata_schema, ) +from litellm.proxy.mcp_server.byok_credential_cache import byok_credential_cache +from litellm.proxy.mcp_server.catalog import public_catalog_operation +from litellm.proxy.mcp_server.stdio_gate import MCP_STDIO_ENABLED_ENV_VAR, is_mcp_stdio_flag_key from litellm.proxy.memory.memory_endpoints import router as memory_router from litellm.proxy.middleware.billable_request_metrics_middleware import ( BillableRequestMetricsMiddleware, @@ -1141,7 +1144,7 @@ def _redact_worker_config_for_logging(worker_config: str | dict[str, JsonValue] return None if isinstance(worker_config, dict): return _redact_secret_values_in_obj(worker_config) - parsed: Final = safe_json_loads(worker_config, default=None) + parsed: Final[JsonValue] = safe_json_loads(worker_config, default=None) if isinstance(parsed, dict): return safe_dumps(_redact_secret_values_in_obj(parsed)) return worker_config @@ -1467,11 +1470,13 @@ async def proxy_startup_event(app: FastAPI) -> AsyncGenerator[ProxyLifespanState ) _module_path, _func_name = _hook_spec.rsplit(":", 1) _module = importlib.import_module(_module_path) - _hook_fn = getattr(_module, _func_name) + _hook_fn = _UNTYPED_VALUE.validate_python(getattr(_module, _func_name)) if inspect.iscoroutinefunction(_hook_fn): await _hook_fn() - else: + elif callable(_hook_fn): _hook_fn() + else: + raise TypeError(f"'{type(_hook_fn).__name__}' object is not callable") verbose_proxy_logger.info("Worker startup hook '%s' executed successfully", _hook_spec) except Exception as e: verbose_proxy_logger.error("Worker startup hook '%s' failed: %s", _hook_spec, e) @@ -1919,15 +1924,22 @@ def _strip_operation_id_method_suffix(operation_id: str) -> str: return operation_id +class _SupportsValues(Protocol): + def values(self) -> Iterable[JsonValue]: ... + + +def _openapi_path_items(openapi_schema: JsonObject) -> Iterable[JsonObject]: + paths: Final = require_attributes(openapi_schema.get("paths", {}), _SupportsValues, "values") + return (path_item for path_item in paths.values() if isinstance(path_item, dict)) + + def ensure_unique_openapi_operation_ids( - openapi_schema: dict[str, Any], + openapi_schema: JsonObject, reserved_operation_ids: set[str] | None = None, -) -> dict[str, Any]: +) -> JsonObject: operation_entries: Final = [] operation_id_counts: Final[dict[str, int]] = {} - for path_item in openapi_schema.get("paths", {}).values(): - if not isinstance(path_item, dict): - continue + for path_item in _openapi_path_items(openapi_schema): for method, operation in path_item.items(): if method not in _OPENAPI_HTTP_METHODS or not isinstance(operation, dict): continue @@ -2004,6 +2016,19 @@ from starlette.routing import BaseRoute from litellm.proxy.common_utils.openapi_route import OpenAPISchema, serve_openapi_off_the_event_loop +class _OpenAPIQueryParam(Protocol): + @property + def name(self) -> object: ... + + @property + def required(self) -> object: ... + + +def _query_param_name_and_required(param: object) -> tuple[object, object]: + fields: Final = require_attributes(param, _OpenAPIQueryParam, "name", "required") + return fields.name, fields.required + + def _inject_websocket_stubs_into_openapi_schema(openapi_schema: dict, websocket_routes: list) -> dict: """ Add a synthetic GET stub for each WebSocket route so it appears in Swagger UI. @@ -2020,14 +2045,15 @@ def _inject_websocket_stubs_into_openapi_schema(openapi_schema: dict, websocket_ try: if hasattr(route, "dependant") and route.dependant is not None: # Handle both FastAPI <0.120 and >=0.120 - query_params = getattr(route.dependant, "query_params", []) + query_params = _UNTYPED_VALUE.validate_python(getattr(route.dependant, "query_params", [])) if query_params: - for param in query_params: + for param in iter_items(query_params): + name, required = _query_param_name_and_required(param) parameters.append( { - "name": param.name, + "name": name, "in": "query", - "required": param.required, + "required": required, "schema": {"type": "string"}, } ) @@ -5577,6 +5603,13 @@ def _log_ignored_cost_map_copy(model_id: str, fields: tuple[str, ...]) -> None: _DB_CONFIG_CALLBACK_EVENT_TYPES: Final[Mapping[str, tuple[Literal["success", "failure"], ...]]] = MappingProxyType( {"success_callback": ("success",), "failure_callback": ("failure",), "callbacks": ("success", "failure")} ) +_DB_CONFIG_CALLBACK_LISTS: Final[Mapping[str, Callable[[], Container[object]]]] = MappingProxyType( + { + "success_callback": lambda: litellm.success_callback, + "failure_callback": lambda: litellm.failure_callback, + "callbacks": lambda: litellm.callbacks, + } +) _CALLBACK_LIST_NAMES: Final = ( "callbacks", "success_callback", @@ -5587,7 +5620,9 @@ _CALLBACK_LIST_NAMES: Final = ( def _callback_list_entries(list_name: str) -> tuple[tuple[str, object], ...]: - return tuple((list_name, entry) for entry in getattr(litellm, list_name)) + return tuple( + (list_name, entry) for entry in iter_items(_UNTYPED_VALUE.validate_python(getattr(litellm, list_name))) + ) def _registered_callback_entries() -> tuple[tuple[str, object], ...]: @@ -5616,7 +5651,7 @@ def _restore_displaced_callback(list_name: str, entry: object) -> None: def _unregister_db_callback(registration: _DbCallbackRegistration) -> None: for list_name, entry in registration.added: litellm.logging_callback_manager.remove_callback_from_list_by_object( - getattr(litellm, list_name), entry, require_self=False + _UNTYPED_VALUE.validate_python(getattr(litellm, list_name)), entry, require_self=False ) for list_name, entry in registration.displaced: _restore_displaced_callback(list_name, entry) @@ -7347,7 +7382,7 @@ class ProxyConfig: ## MCP TOOLS mcp_tools_config: Final = config.get("mcp_tools", None) if mcp_tools_config: - from litellm.proxy._experimental.mcp_server.tool_registry import ( + from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) @@ -7364,7 +7399,7 @@ class ProxyConfig: mcp_servers_config: Final = config.get("mcp_servers", None) if mcp_servers_config: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -7825,7 +7860,7 @@ class ProxyConfig: self, callback: str, event_types: list[Literal["success", "failure"]], - existing_callbacks: list, + existing_callbacks: Container[object], ) -> None: """ Helper method to add a single callback to litellm for specified event types. @@ -7868,7 +7903,7 @@ class ProxyConfig: self._add_callback_from_db_to_in_memory_litellm_callbacks( callback=callback, event_types=list(_DB_CONFIG_CALLBACK_EVENT_TYPES[setting_key]), - existing_callbacks=getattr(litellm, setting_key), + existing_callbacks=_DB_CONFIG_CALLBACK_LISTS[setting_key](), ) after: Final = _registered_callback_entries() return _DbCallbackRegistration( @@ -8363,8 +8398,12 @@ class ProxyConfig: environment_read: Final = next(self._environment_read_numbers) sections: Final = tuple(self._settings_stores) responses: Final = await asyncio.gather(*(get_config_param(prisma_client, section) for section in sections)) + response: _ConfigParamValueRow | None for section, response in zip(sections, responses): - if response is None or (param_value := getattr(response, "param_value", None)) is None: + if response is None: + continue + param_value: JsonValue = getattr(response, "param_value", None) + if param_value is None: continue verbose_proxy_logger.debug( @@ -8391,7 +8430,10 @@ class ProxyConfig: self, prisma_client: PrismaClient, row: object, environment_before_db: Mapping[str, str], read: int ) -> None: current: Final = await self._environment_row_not_behind_the_applied_one(prisma_client, row) - if current is None or (param_value := getattr(current, "param_value", None)) is None: + if current is None: + return + param_value: Final[object] = getattr(current, "param_value", None) + if param_value is None: return self._apply_db_environment_variables(param_value, _config_row_revision(current), environment_before_db, read) @@ -9361,19 +9403,19 @@ class ProxyConfig: ) async def _init_mcp_servers_in_db(self): - from litellm.proxy._experimental.mcp_server.utils import is_mcp_available + from litellm.proxy.mcp_server.utils import is_mcp_available if not is_mcp_available(): verbose_proxy_logger.debug("MCP module not available, skipping MCP server initialization") return - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.oauth2_flow_backfill import ( + from litellm.proxy.mcp_server.oauth2_flow_backfill import ( backfill_null_oauth2_flows, ) - from litellm.proxy._experimental.mcp_server.oauth_issuer_stamp_backfill import ( + from litellm.proxy.mcp_server.oauth_issuer_stamp_backfill import ( backfill_discovery_stamped_issuers, ) @@ -9412,11 +9454,11 @@ class ProxyConfig: """ if not self._should_load_db_object(object_type="mcp"): return - from litellm.proxy._experimental.mcp_server.utils import is_mcp_available + from litellm.proxy.mcp_server.utils import is_mcp_available if not is_mcp_available(): return - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -11255,6 +11297,19 @@ class ProxyStartupEvent: misfire_grace_time=APSCHEDULER_MISFIRE_GRACE_TIME, ) + ### TOOL DISCOVERY (own lock, same interval, never rides the spend commit) ### + from litellm.proxy.utils import commit_tool_discoveries + + scheduler.add_job( # pyright: ignore[reportUnknownMemberType] # apscheduler is untyped + commit_tool_discoveries, + "interval", + seconds=batch_writing_interval, + args=[prisma_client, proxy_logging_obj], + id="commit_tool_discoveries_job", + replace_existing=True, + misfire_grace_time=APSCHEDULER_MISFIRE_GRACE_TIME, + ) + ### UPDATE DAILY TAG SPEND (separate scheduler job with longer interval) ### ## Reduces QPS as there are more tags for a single request tag_spend_update_interval: Final = int(batch_writing_interval * DAILY_TAG_SPEND_BATCH_MULTIPLIER) @@ -15117,7 +15172,7 @@ def _router_default_litellm_params(router: Router | None) -> Mapping[str, object def _count_context_management( context_management: JsonValue, model: str, request_litellm_params: Mapping[str, JsonValue] ) -> CountContextManagement | None: - from litellm.llms.anthropic.pass_through.adapters.handler import context_management_explicitly_dropped + from litellm.llms.anthropic.messages.adapters.handler import context_management_explicitly_dropped if context_management is None or llm_router is None: return None @@ -15998,7 +16053,23 @@ async def _get_caller_byok_team_scope( return key_team_scope | set(user_row.teams or []) -def _byok_row_outside_caller_teams(model_info_dict: dict[str, JsonValue], allowed_team_ids: set[str] | None) -> bool: +class _SupportsGet(Protocol): + def get(self, key: str, default: object = None, /) -> object: ... + + +def _with_get(value: object) -> _SupportsGet: + return require_attributes(value, _SupportsGet, "get") + + +class _SupportsLower(Protocol): + def lower(self) -> object: ... + + +def _lowered(value: object) -> object: + return require_attributes(value, _SupportsLower, "lower").lower() + + +def _byok_row_outside_caller_teams(model_info_dict: object, allowed_team_ids: set[str] | None) -> bool: """Whether a team BYOK row belongs to a team the caller is not a member of. `team_id` is only set on team BYOK rows; non-team rows fall through @@ -16006,7 +16077,7 @@ def _byok_row_outside_caller_teams(model_info_dict: dict[str, JsonValue], allowe """ if allowed_team_ids is None: return False - team_id: Final = model_info_dict.get("team_id") + team_id: Final = _with_get(model_info_dict).get("team_id") if team_id is None: return False return team_id not in allowed_team_ids @@ -16107,7 +16178,7 @@ async def _fetch_db_models_for_search( async def _apply_search_filter_to_models( - all_models: list[dict[str, Any]], + all_models: list[dict[str, object]], search: str, prisma_client: PrismaClient | None, proxy_config: ProxyConfig, @@ -16159,7 +16230,7 @@ async def _apply_search_filter_to_models( prisma_client=prisma_client, ) - def _is_byok_outside_caller_teams(model_info_dict: dict[str, JsonValue]) -> bool: + def _is_byok_outside_caller_teams(model_info_dict: object) -> bool: return _byok_row_outside_caller_teams(model_info_dict, allowed_team_ids) def _model_matches_search(m: dict[str, Any]) -> bool: @@ -16196,7 +16267,7 @@ async def _apply_search_filter_to_models( db_model_ids_in_router: Final = set() for m in filtered_router_models: - model_info = m.get("model_info", {}) + model_info = _with_get(m.get("model_info", {})) is_db_model = model_info.get("db_model", False) model_id = model_info.get("id") @@ -16307,7 +16378,7 @@ def _sort_models( reverse: Final = sort_order.lower() == "desc" def get_sort_key(model: dict[str, Any]) -> Any: - model_info: Final = model.get("model_info", {}) + model_info: Final = _with_get(_UNTYPED_VALUE.validate_python(model.get("model_info", {}))) if sort_by == "model_name": # Team BYOK models persist an internal `model_name` (e.g. @@ -16319,7 +16390,7 @@ def _sort_models( team_public_model_name: Final = model_info.get("team_public_model_name") if team_public_model_name: return str(team_public_model_name).lower() - return model.get("model_name", "").lower() + return _lowered(_UNTYPED_VALUE.validate_python(model.get("model_name", ""))) elif sort_by == "created_at": created_at: Final = model_info.get("created_at") @@ -16345,8 +16416,8 @@ def _sort_models( return normalized_dt elif sort_by == "costs": - input_cost: Final = model_info.get("input_cost_per_token", 0) or 0 - output_cost: Final = model_info.get("output_cost_per_token", 0) or 0 + input_cost: Final = model.get("model_info", {}).get("input_cost_per_token", 0) or 0 + output_cost: Final = model.get("model_info", {}).get("output_cost_per_token", 0) or 0 total_cost: Final = input_cost + output_cost # Put 0 or None costs at the end for asc, at the start for desc if total_cost == 0: @@ -16581,7 +16652,7 @@ async def _authorize_team_id_query( async def _filter_models_by_team_id( - all_models: list[dict[str, Any]], + all_models: list[dict[str, object]], team_id: str, prisma_client: PrismaClient, llm_router: Router, @@ -16625,7 +16696,7 @@ async def _filter_models_by_team_id( # every public model the admin can call. filtered_models: Final = [] for _model in all_models: - model_info = _model.get("model_info", {}) + model_info = _with_get(_model.get("model_info", {})) model_id = model_info.get("id", None) # BYOK rows owned by this team are always accessible to it, even if @@ -16690,6 +16761,35 @@ async def _find_model_by_id( return all_models, search_total_count +async def _models_with_stored_param_keys( + models: Sequence[Mapping[str, object]], model_id: str, prisma_client: PrismaClient +) -> Sequence[Mapping[str, object]]: + visible_model: Final = next( + (model for model in models if _with_get(model.get("model_info", {})).get("id") == model_id), None + ) + if visible_model is None: + return models + stored: Final = await ModelRepository(WriterPinnedClient(prisma_client.db)).table.find_unique( + where={"model_id": model_id} + ) + if stored is None: + return models + raw_params: Final = _UNTYPED_VALUE.validate_python(stored.litellm_params) + stored_params: Final = ( + _LITELLM_PARAMS_COPY.validate_json(raw_params) + if isinstance(raw_params, str) + else _LITELLM_PARAMS_COPY.validate_python(raw_params) + ) + visible_params: Final = _LITELLM_PARAMS_COPY.validate_python(visible_model.get("litellm_params", {})) + editor_model: Final = MappingProxyType( + { + **visible_model, + "litellm_params": {key: value for key, value in visible_params.items() if key in stored_params}, + } + ) + return tuple(editor_model if model is visible_model else model for model in models) + + @router.get( "/v2/model/info", tags=["model management"], @@ -16707,6 +16807,10 @@ async def model_info_v2( size: int = Query(50, description="Page size", ge=1), search: str | None = fastapi.Query(None, description="Search model names (case-insensitive partial match)"), modelId: str | None = fastapi.Query(None, description="Search for a specific model by its unique ID"), + use_stored_params: bool = fastapi.Query( + False, + description="With modelId, omit runtime-only litellm_params defaults from a DB-stored model's editor view.", + ), teamId: str | None = fastapi.Query( None, description="Filter models by team ID. Returns models with direct_access=True or teamId in access_via_team_ids", @@ -16758,6 +16862,7 @@ async def model_info_v2( page / size: Pagination controls (defaults: page=1, size=50). search: Case-insensitive partial match on model name or team public name. modelId: Return a single deployment by LiteLLM model id. + use_stored_params: With modelId, return only persisted litellm_params keys, retaining normal redaction. teamId: Filter to models with direct access or team membership for this team id. sortBy / sortOrder: Sort by model_name, created_at, updated_at, costs, or status. blocked: Filter by routing status (false = active, true = paused). @@ -16794,6 +16899,9 @@ async def model_info_v2( """ global llm_model_list, general_settings, user_config_file_path, proxy_config, llm_router + if use_stored_params is True and not isinstance(modelId, str): + raise HTTPException(status_code=400, detail="use_stored_params requires modelId") + # Return empty data array when no models are configured (graceful handling for fresh installs) if llm_router is None or not llm_router.model_list: return { @@ -16929,6 +17037,14 @@ async def model_info_v2( # Translate `model_name` to the public name for team-scoped rows. all_models = [_translate_model_name_for_response(m) for m in all_models] + if use_stored_params is True and isinstance(modelId, str): + return _paginate_models_response( + all_models=await _models_with_stored_param_keys(all_models, modelId, prisma_client), + page=page, + size=size, + total_count=search_total_count, + search=search, + ) return _paginate_models_response( all_models=all_models, page=page, @@ -17442,7 +17558,7 @@ def _filter_v1_model_info_deployments( return [model for model in all_models if _deployment_matches_allowed_model_names(model, allowed_model_names)] -def _translate_model_name_for_response(model: dict) -> dict: +def _translate_model_name_for_response(model: dict) -> dict[str, object]: """For team-scoped DB rows, replace `model_name` with the public name in `model_info.team_public_model_name` before returning. The DB column and the in-memory router index keep the internal mangled name @@ -21661,11 +21777,11 @@ async def _stream_mcp_asgi_response(handle_fn, scope: dict, receive) -> "Streami ) async def proxy_mcp_route(request: Request) -> Response: """Serve the fixed three-tool MCP proxy surface.""" - from litellm.proxy._experimental.mcp_server.mcp_context import ( # pyright: ignore[reportPrivateUsage] # route-owned mode + from litellm.proxy.mcp_server.mcp_context import ( # pyright: ignore[reportPrivateUsage] # route-owned mode _mcp_proxy_mode, # pyright: ignore[reportPrivateUsage] # route-owned mode ) - from litellm.proxy._experimental.mcp_server.server import handle_streamable_http_mcp - from litellm.proxy._experimental.mcp_server.utils import is_mcp_available + from litellm.proxy.mcp_server.server import handle_streamable_http_mcp + from litellm.proxy.mcp_server.utils import is_mcp_available if not is_mcp_available(): raise HTTPException(status_code=404, detail="Not Found") @@ -21688,12 +21804,12 @@ async def aggregate_mcp_route(request: Request): """Serve the aggregate MCP endpoint on the bare ``/mcp`` spelling: the ``/mcp`` mount cannot match its bare prefix, and the resulting 307 breaks MCP clients behind TLS-terminating proxies.""" - from litellm.proxy._experimental.mcp_server.utils import is_mcp_available + from litellm.proxy.mcp_server.utils import is_mcp_available if not is_mcp_available(): raise HTTPException(status_code=404, detail="Not Found") - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, ) @@ -21719,10 +21835,10 @@ async def toolset_mcp_route(toolset_name: str, request: Request): will be rejected with a 403. """ try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, mcp_active_toolset_id, ) @@ -21737,8 +21853,7 @@ async def toolset_mcp_route(toolset_name: str, request: Request): detail=f"Toolset '{toolset_name}' not found", ) - scope: Final = dict(request.scope) - scope["path"] = "/mcp" + scope: Final = {**request.scope, "_original_path": request.scope.get("path", ""), "path": "/mcp"} token: Final = mcp_active_toolset_id.set(toolset.toolset_id) try: @@ -21755,7 +21870,7 @@ async def toolset_mcp_route(toolset_name: str, request: Request): async def _mcp_forward_as_path(path_segment: str, request: Request): """Rewrite path to /mcp/{path_segment} and stream the response.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, ) @@ -21788,11 +21903,11 @@ async def _resolve_mcp_csv_tokens(csv_segment: str, client_ip: str | None) -> li all-unmatched server filter falls back to the full ``allowed_mcp_servers`` list and silently broadens the request scope). """ - from litellm.proxy._experimental.mcp_server.catalog import global_manager + from litellm.proxy.mcp_server.catalog import global_manager async with global_manager().catalog.operation(): from litellm.constants import DEFAULT_MCP_NAMESPACE_CSV_MAX_TOKENS - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -21822,7 +21937,7 @@ async def _is_mcp_access_group_cached(name: str) -> bool: list) cannot hide a real group for long. """ from litellm.constants import DEFAULT_MCP_ACCESS_GROUP_NEGATIVE_CACHE_TTL - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -21855,10 +21970,10 @@ async def dynamic_mcp_route(mcp_server_name: str, request: Request): 4. MCP access group tag (DB lookup, cached) """ try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.auth.ip_address_utils import IPAddressUtils + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy.auth.ip_address_utils import IPAddressUtils client_ip: Final = IPAddressUtils.get_mcp_client_ip(request) @@ -21885,7 +22000,7 @@ async def dynamic_mcp_route(mcp_server_name: str, request: Request): # 3. Toolset name (cached) if prisma_client is not None: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, mcp_active_toolset_id, ) diff --git a/litellm/proxy/public_endpoints/provider_create_fields.json b/litellm/proxy/public_endpoints/provider_create_fields.json index 4bec42a7868..d96f2976508 100644 --- a/litellm/proxy/public_endpoints/provider_create_fields.json +++ b/litellm/proxy/public_endpoints/provider_create_fields.json @@ -17,6 +17,34 @@ ], "default_model_placeholder": "scaledown/summarize" }, + { + "provider": "ABLITERATION", + "provider_display_name": "Abliteration", + "litellm_provider": "abliteration", + "credential_fields": [ + { + "key": "api_key", + "label": "API Key", + "placeholder": null, + "tooltip": null, + "required": true, + "field_type": "password", + "options": null, + "default_value": null + }, + { + "key": "api_base", + "label": "API Base", + "placeholder": "https://api.abliteration.ai/v1", + "tooltip": "Optional. Leave blank to use the provider's default endpoint.", + "required": false, + "field_type": "text", + "options": null, + "default_value": null + } + ], + "default_model_placeholder": "abliteration/abliterated-model-large-v2" + }, { "provider": "AIML", "provider_display_name": "AI/ML API", @@ -1995,6 +2023,24 @@ ], "default_model_placeholder": "laya/english" }, + { + "provider": "OPENCODE_GO", + "provider_display_name": "OpenCode Go", + "litellm_provider": "opencode_go", + "credential_fields": [ + { + "key": "api_key", + "label": "API Key", + "placeholder": "OpenCode Console API key", + "tooltip": "Use a Console API key with an active Go or Go Plus subscription.", + "required": true, + "field_type": "password", + "options": null, + "default_value": null + } + ], + "default_model_placeholder": "glm-5.3-flash" + }, { "provider": "LAMBDA_AI", "provider_display_name": "Lambda Ai", @@ -3185,6 +3231,34 @@ ], "default_model_placeholder": "gpt-3.5-turbo" }, + { + "provider": "REFUSELESS", + "provider_display_name": "Refuseless", + "litellm_provider": "refuseless", + "credential_fields": [ + { + "key": "api_key", + "label": "API Key", + "placeholder": null, + "tooltip": null, + "required": true, + "field_type": "password", + "options": null, + "default_value": null + }, + { + "key": "api_base", + "label": "API Base", + "placeholder": "https://api.refuseless.com/v1", + "tooltip": "Optional. Leave blank to use the provider's default endpoint.", + "required": false, + "field_type": "text", + "options": null, + "default_value": null + } + ], + "default_model_placeholder": "refuseless/glm-5.3-abliterated" + }, { "provider": "REPLICATE", "provider_display_name": "Replicate", diff --git a/litellm/proxy/public_endpoints/public_endpoints.py b/litellm/proxy/public_endpoints/public_endpoints.py index 351e4c10d87..9f33e0d2adc 100644 --- a/litellm/proxy/public_endpoints/public_endpoints.py +++ b/litellm/proxy/public_endpoints/public_endpoints.py @@ -342,7 +342,7 @@ async def get_agents(request: Request): response_model=list[MCPPublicServer], ) async def get_mcp_servers(): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) diff --git a/litellm/proxy/public_endpoints/public_v1/model_hub.py b/litellm/proxy/public_endpoints/public_v1/model_hub.py index cd634e490b6..e58149fba0b 100644 --- a/litellm/proxy/public_endpoints/public_v1/model_hub.py +++ b/litellm/proxy/public_endpoints/public_v1/model_hub.py @@ -107,10 +107,14 @@ def _features(row: ModelGroupInfoProxy) -> tuple[str, ...]: The hub's feature control has always been a multi-select over the `supports_*` flags. One boolean filter per flag would AND them, which is the opposite of what it does. """ + return _enabled_features(row.model_dump()) + + +def _enabled_features(fields: Mapping[str, object]) -> tuple[str, ...]: return tuple( sorted( name.removeprefix(FEATURE_PREFIX) - for name, value in row.model_dump().items() + for name, value in fields.items() if name.startswith(FEATURE_PREFIX) and value is True ) ) diff --git a/litellm/proxy/response_api_endpoints/endpoints.py b/litellm/proxy/response_api_endpoints/endpoints.py index 312c5124ca5..97bbf893e3e 100644 --- a/litellm/proxy/response_api_endpoints/endpoints.py +++ b/litellm/proxy/response_api_endpoints/endpoints.py @@ -2116,7 +2116,7 @@ def _without_untrusted_metadata(key: str, value: object) -> object: if not name.startswith("user_api_key_") and name not in _UNTRUSTED_METADATA_CONTROL_FIELDS and name not in _CLIENT_PRICING_METADATA_FIELDS - and name not in ("headers", "pii_tokens", *_CLIENT_GUARDRAIL_SELECTORS) + and name not in ("headers", "pii_tokens", _GUARDRAIL_INFORMATION_KEY, *_CLIENT_GUARDRAIL_SELECTORS) } diff --git a/litellm/proxy/response_polling/polling_handler.py b/litellm/proxy/response_polling/polling_handler.py index 787f27f56c8..e50587b1a0e 100644 --- a/litellm/proxy/response_polling/polling_handler.py +++ b/litellm/proxy/response_polling/polling_handler.py @@ -308,10 +308,7 @@ def should_use_polling_for_request( # Otherwise, check ALL deployments for this model_name in router elif llm_router is not None: try: - # Get all deployment indices for this model name - indices: Final = llm_router.model_name_to_deployment_indices.get(model, []) - for idx in indices: - deployment_dict = llm_router.model_list[idx] + for deployment_dict in llm_router.deployments_named(model) or (): litellm_params = deployment_dict.get("litellm_params", {}) # Check custom_llm_provider first diff --git a/litellm/proxy/spend_tracking/budget_reservation.py b/litellm/proxy/spend_tracking/budget_reservation.py index 803df9f83ca..0b91e57f01e 100644 --- a/litellm/proxy/spend_tracking/budget_reservation.py +++ b/litellm/proxy/spend_tracking/budget_reservation.py @@ -728,7 +728,9 @@ async def _get_team_member_budget_counter( membership_cache_key: Final = team_membership_reservation_cache_key( user_id=valid_token.user_id, team_id=team_object.team_id ) - cached_team_membership: Final = await user_api_key_cache.async_get_cache(key=membership_cache_key) + cached_team_membership: Final = _CACHED_VALUE.validate_python( + await user_api_key_cache.async_get_cache(key=membership_cache_key) + ) team_membership: LiteLLM_TeamMembership | None = None if isinstance(cached_team_membership, LiteLLM_TeamMembership): team_membership = cached_team_membership diff --git a/litellm/proxy/spend_tracking/ptu_flat_cost_rollup.py b/litellm/proxy/spend_tracking/ptu_flat_cost_rollup.py index ea543aeae6e..4abc79febe1 100644 --- a/litellm/proxy/spend_tracking/ptu_flat_cost_rollup.py +++ b/litellm/proxy/spend_tracking/ptu_flat_cost_rollup.py @@ -21,6 +21,8 @@ from itertools import chain, groupby from types import MappingProxyType from typing import TYPE_CHECKING, Final, Protocol +from pydantic import TypeAdapter + from litellm._internal_context import with_service_target from litellm._logging import verbose_proxy_logger from litellm.constants import ( @@ -135,6 +137,9 @@ def _public_model_name(row: object, model_info: Mapping[str, object]) -> str: return str(getattr(row, "model_name", "") or "") +_DECODED_JSON: Final = TypeAdapter(object) + + def _decode_model_info(raw: object) -> "Mapping[str, object] | None": """A deployment's model_info as a mapping, decoding a JSON string, else None. @@ -143,7 +148,7 @@ def _decode_model_info(raw: object) -> "Mapping[str, object] | None": """ if isinstance(raw, str): try: - decoded: Final[object] = json.loads(raw) + decoded: Final = _DECODED_JSON.validate_python(json.loads(raw)) except (TypeError, ValueError): return None return decoded if isinstance(decoded, dict) else None diff --git a/litellm/proxy/spend_tracking/savings.py b/litellm/proxy/spend_tracking/savings.py index 2aab8deb034..604a7a389e6 100644 --- a/litellm/proxy/spend_tracking/savings.py +++ b/litellm/proxy/spend_tracking/savings.py @@ -19,6 +19,7 @@ from pydantic import ConfigDict, Field import litellm from litellm._logging import verbose_proxy_logger from litellm.constants import INTERNAL_CALL_ORIGIN_METADATA_KEY +from litellm.litellm_core_utils.get_llm_provider_logic import resolve_model_and_provider_for_metadata from litellm.litellm_core_utils.llm_cost_calc.utils import ( calculate_prompt_caching_savings, generic_cost_per_token, @@ -69,7 +70,9 @@ def _resolve_model(model: str | None, custom_llm_provider: str | None) -> _Model if not model: return None try: - resolved_model, provider, _, _ = litellm.get_llm_provider(model=model, custom_llm_provider=custom_llm_provider) + resolved_model, provider = resolve_model_and_provider_for_metadata( + model=model, custom_llm_provider=custom_llm_provider + ) except Exception as e: # noqa: BLE001 # get_llm_provider raises for unroutable names; degrade to an unavailable estimate verbose_proxy_logger.debug( "savings: cannot resolve provider for model=%s custom_llm_provider=%s (%s)", model, custom_llm_provider, e diff --git a/litellm/proxy/spend_tracking/spend_management_endpoints.py b/litellm/proxy/spend_tracking/spend_management_endpoints.py index 84278f4619d..3c65fc0bf06 100644 --- a/litellm/proxy/spend_tracking/spend_management_endpoints.py +++ b/litellm/proxy/spend_tracking/spend_management_endpoints.py @@ -3045,7 +3045,7 @@ async def ui_view_spend_logs( ) sql_params.extend([page_size, skip]) - data: Final = await prisma_client.db.query_raw(sql_query, *sql_params) + data: Final[Sequence[Mapping[str, object]]] = await _query_raw(prisma_client, sql_query, *sql_params) if request_id is not None and not is_v2 and not is_admin_view: await _assert_user_owns_fetched_spend_rows( @@ -3064,7 +3064,7 @@ async def ui_view_spend_logs( return await _build_ui_spend_logs_response( prisma_client, - data, + list(data), total_records, page, page_size, diff --git a/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py b/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py index d51e1167888..0efd4e4c619 100644 --- a/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py +++ b/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py @@ -8,6 +8,7 @@ from types import MappingProxyType from typing import ( Annotated, Final, + Literal, NamedTuple, Protocol, cast, # noqa: TID251 # prisma types Json columns as fields.Json but de-serializes them to plain python on read @@ -23,7 +24,6 @@ import litellm from litellm._internal_context import with_service_target from litellm._logging import verbose_proxy_logger from litellm.litellm_core_utils.sensitive_data_masker import mask_sensitive_keys -from litellm.proxy._experimental.mcp_server.tool_search import MCP_TOOL_SEARCH_SETTINGS_KEY from litellm.proxy._types import * from litellm.proxy.auth.user_api_key_auth import user_api_key_auth from litellm.proxy.common_utils.validation_error_body import public_validation_errors @@ -39,6 +39,7 @@ from litellm.proxy.management_endpoints.team_admin_field_permissions import ( TEAM_ADMIN_EDITABLE_TEAM_FIELDS_SETTING, TEAM_ADMIN_RAISE_MAX_BUDGET_PERMISSION, ) +from litellm.proxy.mcp_server.tool_search import MCP_TOOL_SEARCH_SETTINGS_KEY from litellm.proxy.spend_tracking.ptu_feature_flag import ( PTU_COST_ATTRIBUTION_ENV_VAR, is_ptu_cost_attribution_enabled, @@ -233,6 +234,9 @@ class DefaultTeamSettingsResponse(SettingsResponse): class UIThemeSettingsResponse(SettingsResponse): """Response model for UI theme settings""" + logo_url_via_proxy: bool = False + logo_url_dark_via_proxy: bool = False + _TEAM_ADMIN_FIELD_ENUM: Final = tuple(sorted(SUPPORTED_TEAM_ADMIN_PERMISSIONS)) @@ -256,6 +260,11 @@ class UISettings(LiteLLMBaseModel): model_config = ConfigDict(extra="allow") + usage_default_time_range: Literal["today", "last_7_days", "last_30_days", "month_to_date", "year_to_date"] = Field( + default="last_7_days", + description="Default date range when opening Usage without an explicit URL range. Calendar ranges use the browser timezone.", + ) + disable_model_add_for_internal_users: bool = Field( default=False, description=( @@ -386,6 +395,7 @@ class UISettingsResponse(SettingsResponse): # Allowlist of UI settings that can be stored ALLOWED_UI_SETTINGS_FIELDS: Final = { + "usage_default_time_range", "disable_model_add_for_internal_users", "disable_team_admin_delete_team_user", "enabled_ui_pages_internal_users", @@ -1370,7 +1380,7 @@ async def update_sso_settings( tags=["UI Theme Settings"], response_model=UIThemeSettingsResponse, ) -async def get_ui_theme_settings(): +async def get_ui_theme_settings() -> UIThemeSettingsResponse: """ Get UI theme configuration from the litellm_settings. Returns current logo settings for UI customization. @@ -1383,18 +1393,23 @@ async def get_ui_theme_settings(): # Load existing config config: Final = await proxy_config.get_config() - result: Final = await _get_settings_with_schema( - settings_key="ui_theme_config", - settings_class=UIThemeConfig, - config=config, + result: Final = _SettingsWithSchema.model_validate( + await _get_settings_with_schema( + settings_key="ui_theme_config", + settings_class=UIThemeConfig, + config=config, + ) ) - - stored_values: Final = result.get("values", {}) - result["values"] = { - **stored_values, - **{field: _resolve_ui_theme_field(stored_values, field) for field in _UI_THEME_FIELD_ENV_VARS}, + values: Final = { + **result.values, + **{field: _resolve_ui_theme_field(result.values, field) for field in _UI_THEME_FIELD_ENV_VARS}, } - return result + return UIThemeSettingsResponse( + values=values, + field_schema=result.field_schema, + logo_url_via_proxy=values["logo_url"] is None and bool(os.getenv("UI_LOGO_PATH", "").strip()), + logo_url_dark_via_proxy=values["logo_url_dark"] is None and bool(os.getenv("UI_LOGO_PATH_DARK", "").strip()), + ) def _validate_public_image_url(value: str | None, field_name: str) -> None: diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index a7ad682bc65..408f6e34efa 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -19,6 +19,7 @@ from collections.abc import ( Awaitable, Callable, Coroutine, + Iterable, Iterator, Mapping, Sequence, @@ -51,7 +52,7 @@ from typing import ( import anyio import httpx -from typing_extensions import Never, ReadOnly, TypedDict +from typing_extensions import Never, NotRequired, ReadOnly, TypedDict from litellm import _custom_logger_compatible_callbacks_literal from litellm.constants import ( @@ -183,6 +184,7 @@ from litellm.proxy.auth.route_checks import RouteChecks from litellm.proxy.common_utils.callback_utils import add_guardrail_to_applied_guardrails_header from litellm.proxy.common_utils.config_sync_pubsub import publish_config_param_change from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache +from litellm.proxy.db import tool_registry_writer from litellm.proxy.db.create_views import ( create_missing_views, create_view_tolerating_race, @@ -190,6 +192,7 @@ from litellm.proxy.db.create_views import ( ) from litellm.proxy.db.db_span import db_span from litellm.proxy.db.db_spend_update_writer import DBSpendUpdateWriter +from litellm.proxy.db.db_transaction_queue.redis_update_buffer import RedisUpdateBuffer from litellm.proxy.db.db_url_settings import ( DatabaseURLSettings, add_missing_query_params, @@ -323,10 +326,22 @@ class _RelTuplesRow(TypedDict): reltuples: ReadOnly[int] +class _TeamMemberRow(TypedDict): + role: ReadOnly[Literal["admin", "user"]] + user_id: ReadOnly[NotRequired[str | None]] + user_email: ReadOnly[NotRequired[str | None]] + + +class _TeamMembershipRow(TypedDict): + user_id: ReadOnly[str | None] + team_members_with_roles: ReadOnly[Iterable[_TeamMemberRow] | None] + + _VIEW_SETUP_POLL_INTERVAL_SECONDS: Final = 5.0 _VIEW_SETUP_DEADLINE_SECONDS: Final = 15 * 60.0 _VIEW_SETUP_GATE_TABLE: Final = '"LiteLLM_SpendLogs"' _VIEW_SETUP_GATE_PROBE_ROWS: Final = TypeAdapter(tuple[Mapping[str, bool], ...]) +_DELEGATED_ATTRIBUTE: Final = TypeAdapter(object) _ViewSetupOutcome: TypeAlias = Literal["ready", "timed_out"] _ViewSetupAttempt: TypeAlias = Literal["ready", "table_missing"] | Exception @@ -364,6 +379,47 @@ class _UpdateManyBatch(Protocol): async def commit(self) -> None: ... +def _update_many_batch(db: PrismaWrapper | RoutingPrismaWrapper) -> _UpdateManyBatch: + return db.batch_() + + +def _query_raw_rows( + db: PrismaWrapper | RoutingPrismaWrapper, query: str, *args: object +) -> Awaitable[Sequence[Mapping[str, object]]]: + return db.query_raw(query, *args) + + +def _query_first_row( + db: PrismaWrapper | RoutingPrismaWrapper, query: str, *args: object +) -> Awaitable[Mapping[str, object] | None]: + return db.query_first(query, *args) + + +def _team_member_for_user(row: _TeamMembershipRow) -> Member | None: + members_with_roles: Final = row["team_members_with_roles"] + if members_with_roles is None: + return None + user_id: Final = row["user_id"] + if user_id is None: + return None + matches: Final = [ + Member(**member) + for member in members_with_roles + if member.get("user_id") is not None and user_id == member.get("user_id") + ] + return matches[-1] if matches else None + + +class _EndUserSpendTransaction(Protocol): + def batch_(self) -> contextlib.AbstractAsyncContextManager[_EndUserSpendBatch]: ... + + +def _end_user_spend_transaction( + db: PrismaWrapper | RoutingPrismaWrapper, timeout: timedelta +) -> contextlib.AbstractAsyncContextManager[_EndUserSpendTransaction]: + return db.tx(timeout=timeout) + + unified_guardrail: Final = UnifiedLLMGuardrails() NON_OPENAI_STREAM_GUARDRAIL_TRANSLATION_CALL_TYPES: "frozenset[CallTypes]" = frozenset({CallTypes.anthropic_messages}) @@ -543,7 +599,7 @@ class _UpstreamStreamBoundary(Generic[_T]): self.failure: BaseException | None = None def __getattr__(self, name: str) -> object: - return getattr(self._source, name) + return _DELEGATED_ATTRIBUTE.validate_python(getattr(self._source, name)) def __aiter__(self) -> "_UpstreamStreamBoundary[_T]": return self @@ -1331,7 +1387,8 @@ def _stamp_deployment_attribution( callbacks key off it and must not count a proxy-side reject against the deployment. A failure after the provider handoff keeps the metadata the router stamped; a request that never reached a provider is flagged ``PROXY_REJECTED_BEFORE_ROUTING_KEY`` (deployment metrics key off it) whatever - its metadata says, since ``metadata.model_info`` can be caller supplied.""" + its metadata says, since ``metadata.model_info`` can be caller supplied. Its ``deployment`` and + ``model_group`` always come from the router config, never from the caller's metadata.""" attribution: Final = _deployment_attribution_for_model_group(model_group, team_id) if "custom_llm_provider" in attribution: litellm_params["custom_llm_provider"] = attribution["custom_llm_provider"] @@ -1346,9 +1403,13 @@ def _stamp_deployment_attribution( if not isinstance(metadata, dict): return attribution metadata.setdefault("model_info", attribution["model_info"]) - metadata.setdefault("deployment", attribution["deployment"]) - if isinstance(model_group, str): - metadata.setdefault("model_group", model_group) + routing: Final = MappingProxyType( + {"deployment": attribution["deployment"], **({"model_group": model_group} if model_group else {})} + ) + metadata.update(routing) + litellm_metadata: Final = litellm_params.get("litellm_metadata") + if isinstance(litellm_metadata, dict): + litellm_metadata.update(routing) return attribution @@ -1420,7 +1481,17 @@ def _call_type_for_route(route: str | None) -> str | None: return call_types[0].value if len(operations) == 1 else None +REJECTED_BEFORE_REQUEST_SETUP_KEY: Final = "litellm_rejected_before_request_setup" +REJECTED_BEFORE_REQUEST_SETUP: Final = object() +"""Stored under ``REJECTED_BEFORE_REQUEST_SETUP_KEY`` on ``request_data`` when the failure handler finds no logging +object, meaning the request died (auth, body parsing, model resolution) before the pipeline set one up. A sentinel +object rather than ``True`` because ``request_data`` is the client body: JSON cannot forge this identity, so a +client can neither hide a guardrail block nor force a row by sending the key or a ``litellm_call_id`` itself.""" + _PROXY_ONLY_LLM_API_ERRORS: Final = (HTTPException, ProxyException, GuardrailRaisedException) +_PROXY_ONLY_ERROR_LOGGED_FIELDS: Final = frozenset( + {"model", "messages", "input", "prompt", "user", "stream", "litellm_call_id"} +) _LOG_DB_METRICS_CALL_TYPES: Final = frozenset(("get_data", "insert_data", "update_data", "delete_data")) @@ -1455,6 +1526,57 @@ def _provider_billed_the_failure(exception: Exception) -> bool: return _timed_out_reading_from_provider(exception) or _client_disconnected(exception) +def _as_str_mapping(value: object) -> Mapping[str, object]: + if not isinstance(value, Mapping): + return MappingProxyType({}) + return cast( # cast-ok: the runtime Mapping check validates the container shape + Mapping[str, object], value + ) + + +def _proxy_only_error_logged_metadata_keys(*, authenticated: bool, past_pre_call: bool) -> frozenset[str]: + return frozenset( + key + for key, logged in (("tags", authenticated), ("standard_logging_guardrail_information", past_pre_call)) + if logged + ) + + +def _is_logged_metadata_value(key: str, value: object) -> bool: + if key != "tags": + return True + tags: Final = cast(list[object], value) if isinstance(value, list) else None # cast-ok: isinstance checked the list + return tags is not None and all(isinstance(item, str) for item in tags) + + +def _proxy_only_error_log_metadata( + value: object, logged_keys: frozenset[str] +) -> dict[str, object] | None: # mutable-ok: router attribution stamps the logged metadata in place + metadata: Final = _as_str_mapping(value) + if not isinstance(value, Mapping): + return None + return { + key: value for key, value in metadata.items() if key in logged_keys and _is_logged_metadata_value(key, value) + } + + +def _proxy_only_error_log_fields( + request_data: Mapping[str, object], logged_metadata_keys: frozenset[str] +) -> Mapping[str, object]: + metadata_fields: Final = { + key: filtered_metadata + for key in ("metadata", "litellm_metadata") + if (filtered_metadata := _proxy_only_error_log_metadata(request_data.get(key), logged_metadata_keys)) + is not None + } + return MappingProxyType( + { + **{key: value for key, value in request_data.items() if key in _PROXY_ONLY_ERROR_LOGGED_FIELDS}, + **metadata_fields, + } + ) + + def _failure_fields_to_lift( request_data: Mapping[str, object], provider_billed: bool = False, dispatched_call_type: str | None = None ) -> Mapping[str, object]: @@ -3715,6 +3837,7 @@ class ProxyLogging: user_api_key_dict=user_api_key_dict, route=route, original_exception=original_exception, + error_type=error_type, ) request_data.update( @@ -3809,6 +3932,7 @@ class ProxyLogging: user_api_key_dict: UserAPIKeyAuth, route: str | None = None, original_exception: Exception | None = None, + error_type: ProxyErrorTypes | None = None, ): """ Handle logging for proxy only errors by calling `litellm_logging_obj.async_failure_handler` @@ -3817,39 +3941,67 @@ class ProxyLogging: """ litellm_logging_obj: Logging | None = request_data.get("litellm_logging_obj", None) set_up_by_request: Final = litellm_logging_obj is not None + request_fields: Final = cast(Mapping[str, object], request_data) # cast-ok: request bodies are str-keyed JSON + logged_metadata_keys: Final = _proxy_only_error_logged_metadata_keys( + authenticated=error_type != ProxyErrorTypes.auth_error, past_pre_call=set_up_by_request + ) + user_api_key_logged_metadata: Final = LiteLLMProxyRequestSetup.get_sanitized_user_information_from_key( + user_api_key_dict=user_api_key_dict + ) if litellm_logging_obj is None: from litellm._uuid import uuid request_data.setdefault("litellm_call_id", str(uuid.uuid4())) - user_api_key_logged_metadata: Final = LiteLLMProxyRequestSetup.get_sanitized_user_information_from_key( - user_api_key_dict=user_api_key_dict - ) litellm_logging_obj, data = litellm.utils.function_setup( original_function=route or "IGNORE_THIS", rules_obj=litellm.utils.Rules(), start_time=datetime.now(), - **request_data, + **_proxy_only_error_log_fields( # pyright: ignore[reportArgumentType] # the allowlist never carries is_async_call + request_fields, logged_metadata_keys + ), ) request_data["litellm_logging_obj"] = litellm_logging_obj # rebind-ok: lifted then popped by the caller + request_data.update({REJECTED_BEFORE_REQUEST_SETUP_KEY: REJECTED_BEFORE_REQUEST_SETUP}) if "metadata" not in request_data: request_data["metadata"] = {} request_data["metadata"].update(user_api_key_logged_metadata) if litellm_logging_obj is not None: ## UPDATE LOGGING INPUT - _optional_params: Final = {} - _litellm_params: Final = {} + _optional_params: Final[dict[str, object]] = {} # mutable-ok: filled below, then handed to the logger + _litellm_params: Final[dict[str, object]] = {} # mutable-ok: filled below, then handed to the logger litellm_param_keys: Final = LoggedLiteLLMParams.__annotations__.keys() - for k, v in request_data.items(): + for k, v in _proxy_only_error_log_fields(request_fields, logged_metadata_keys).items(): if k in litellm_param_keys: _litellm_params[k] = v elif k not in ("model", "user", "litellm_logging_obj"): _optional_params[k] = v + existing: Final = _as_str_mapping( + litellm_logging_obj.litellm_params # pyright: ignore[reportUnknownMemberType, reportUnknownArgumentType] # Logging.litellm_params is untyped + ) + litellm_params: Final = { + **_litellm_params, + "metadata": { + **_as_str_mapping(existing.get("metadata")), + **_as_str_mapping(_litellm_params.get("metadata")), + **user_api_key_logged_metadata, + }, + **{ + key: { + **_as_str_mapping(existing.get(key)), + **_as_str_mapping(value), + **user_api_key_logged_metadata, + } + for key, value in _litellm_params.items() + if key == "litellm_metadata" + }, + } + attribution: Final = _stamp_deployment_attribution( - _litellm_params, + litellm_params, request_data.get("model"), user_api_key_dict.team_id, dispatched=_reached_deployment(litellm_logging_obj), @@ -3859,7 +4011,7 @@ class ProxyLogging: model=request_data.get("model", ""), user=request_data.get("user", ""), optional_params=_optional_params, - litellm_params=_litellm_params, + litellm_params=litellm_params, **( {"custom_llm_provider": attribution["custom_llm_provider"]} if "custom_llm_provider" in attribution @@ -5494,7 +5646,9 @@ class PrismaClient: raise e - async def _query_first_with_cached_plan_fallback(self, sql_query: str, *args) -> dict | None: + async def _query_first_with_cached_plan_fallback( + self, sql_query: str, *args: object + ) -> Mapping[str, object] | None: """ Execute a query, recovering once from PostgreSQL's "cached plan must not change result type" error. @@ -5745,7 +5899,7 @@ class PrismaClient: LIMIT $1 OFFSET $2 """ - response = await self.db.query_raw(sql_query, limit, offset) + response = await _query_raw_rows(self.db, sql_query, limit, offset) return response elif table_name == "spend": verbose_proxy_logger.debug("PrismaClient: get_data: table_name == 'spend'") @@ -5889,7 +6043,7 @@ class PrismaClient: """ response = ( - await self.writer_db.query_first(sql_query, hashed_token) + await _query_first_row(self.writer_db, sql_query, hashed_token) if use_writer else await self._query_first_with_cached_plan_fallback(sql_query, hashed_token) ) @@ -5925,31 +6079,14 @@ class PrismaClient: if response["team_blocked"] is None: response["team_blocked"] = False - team_member: Member | None = None - if response["team_members_with_roles"] is not None and response["user_id"] is not None: - ## find the team member corresponding to user id - """ - [ - { - "role": "admin", - "user_id": "default_user_id", - "user_email": null - }, - { - "role": "user", - "user_id": null, - "user_email": "test@email.com" - } - ] - """ - for tm in response["team_members_with_roles"]: - if tm.get("user_id") is not None and response["user_id"] == tm.get("user_id"): - team_member = Member(**tm) + ## find the team member corresponding to user id + team_member: Final = _team_member_for_user(response) response["team_member"] = team_member - response = LiteLLM_VerificationTokenView(**response, last_refreshed_at=time.time()) + token_view: Final = LiteLLM_VerificationTokenView(**response, last_refreshed_at=time.time()) # for prisma we need to cast the expires time to str - if response.expires is not None and isinstance(response.expires, datetime): - response.expires = response.expires.isoformat() + if token_view.expires is not None and isinstance(token_view.expires, datetime): + token_view.expires = token_view.expires.isoformat() + response = token_view return response except Exception as e: import traceback @@ -6239,7 +6376,7 @@ class PrismaClient: """ Batch write update queries """ - batcher: _UpdateManyBatch = self.db.batch_() + batcher: _UpdateManyBatch = _update_many_batch(self.db) for idx, t in enumerate(data_list): # check if plain text or hash if t.token.startswith("sk-"): @@ -6264,7 +6401,7 @@ class PrismaClient: """ Batch write update queries """ - batcher = self.db.batch_() + batcher = _update_many_batch(self.db) for user in sorted(data_list, key=attrgetter("user_id")): try: data_json = self.jsonify_object(data=user.model_dump(exclude_none=True)) @@ -6289,7 +6426,7 @@ class PrismaClient: """ Batch write update queries """ - batcher = self.db.batch_() + batcher = _update_many_batch(self.db) for enduser in data_list: try: data_json = self.jsonify_object(data=enduser.model_dump(exclude_none=True)) @@ -6314,7 +6451,7 @@ class PrismaClient: """ Batch write update queries """ - batcher = self.db.batch_() + batcher = _update_many_batch(self.db) for budget in data_list: try: data_json = self.jsonify_object(data=budget.model_dump(exclude_none=True)) @@ -6337,7 +6474,7 @@ class PrismaClient: and isinstance(data_list, list) ): # Batch write update queries - batcher = self.db.batch_() + batcher = _update_many_batch(self.db) for idx, team in enumerate(data_list): try: data_json = self.jsonify_team_object(db_data=team.model_dump(exclude_none=True)) @@ -7002,7 +7139,7 @@ class PrismaClient: # caller's own retried query, a stronger check than SELECT 1, # and a reader that fails to come back sets `_reader_unavailable` # so reads fall through to the writer just recreated here. - await self.writer_db.query_raw("SELECT 1") + await _query_raw_rows(self.writer_db, "SELECT 1") # A recreate can decline: the optimistic-lock guard no-ops when # the writer generation moved since cycle entry, and the routing # wrapper then leaves the reader untouched as well. Callers that @@ -7350,7 +7487,7 @@ class PrismaClient: async def _view_setup_gate_table_present(self) -> bool: rows: Final = _VIEW_SETUP_GATE_PROBE_ROWS.validate_python( - await self.db.query_raw("SELECT to_regclass($1) IS NOT NULL AS present", _VIEW_SETUP_GATE_TABLE) + await _query_raw_rows(self.db, "SELECT to_regclass($1) IS NOT NULL AS present", _VIEW_SETUP_GATE_TABLE) ) return rows[0]["present"] @@ -7360,7 +7497,7 @@ class PrismaClient: await asyncio.sleep(self._db_health_watchdog_interval_seconds) async with db_span("db_health_watchdog", None): await asyncio.wait_for( - self.db.query_raw("SELECT 1"), + _query_raw_rows(self.db, "SELECT 1"), timeout=self._db_health_watchdog_probe_timeout_seconds, ) if isinstance(self.db, RoutingPrismaWrapper) and self.db.writer_unavailable: @@ -7420,7 +7557,7 @@ class PrismaClient: async def _writer_is_read_only(self, writer: PrismaWrapper) -> bool: """True iff the pooled writer session answers reads but rejects writes (SQLSTATE 25006).""" rows: Final = _WRITER_WRITABILITY_PROBE_ROWS.validate_python( - await writer.query_raw(_WRITER_WRITABILITY_PROBE_SQL) + await _query_raw_rows(writer, _WRITER_WRITABILITY_PROBE_SQL) ) return any(row.get("transaction_read_only") == "on" for row in rows) @@ -7447,7 +7584,7 @@ class PrismaClient: """ sql_query: Final = "SELECT 1" async with db_span("health_check", None): - response: Final[object] = await wrapper.query_raw(sql_query) + response: Final[object] = await _query_raw_rows(wrapper, sql_query) return response async def _probe_answers_now(self, wrapper: PrismaWrapper) -> bool: @@ -8000,7 +8137,7 @@ class ProxyUpdateSpend: try: async with ( db_span("update_end_user_spend", "LiteLLM_EndUserTable"), - prisma_client.db.tx(timeout=timedelta(seconds=60)) as transaction, + _end_user_spend_transaction(prisma_client.db, timedelta(seconds=60)) as transaction, ): batcher: _EndUserSpendBatch async with transaction.batch_() as batcher: @@ -8143,6 +8280,18 @@ class ProxyUpdateSpend: return False +async def commit_tool_discoveries(prisma_client: PrismaClient, proxy_logging_obj: ProxyLogging) -> None: + """Scheduler job writing discovered tools to LiteLLM_ToolTable, on its own lock, next to update_spend.""" + writer: Final = proxy_logging_obj.db_spend_update_writer + await tool_registry_writer.commit_tool_discoveries( + prisma_client=prisma_client, + tool_discovery_queue=writer.tool_discovery_queue, + redis_update_buffer=writer.redis_update_buffer, + pod_lock_manager=writer.pod_lock_manager, + use_redis_buffer=RedisUpdateBuffer.should_commit_spend_updates_to_redis(), + ) + + async def update_spend( prisma_client: PrismaClient, db_writer_client: AsyncHTTPHandler | None, diff --git a/litellm/proxy/vector_store_endpoints/utils.py b/litellm/proxy/vector_store_endpoints/utils.py index b97c3a949d5..8ce48fc3516 100644 --- a/litellm/proxy/vector_store_endpoints/utils.py +++ b/litellm/proxy/vector_store_endpoints/utils.py @@ -9,15 +9,15 @@ from pydantic import ConfigDict, TypeAdapter import litellm from litellm._logging import verbose_proxy_logger -from litellm.proxy._experimental.mcp_server.ui_session_utils import ( - is_ui_session_credential, - resolve_ui_session_team_ids, -) from litellm.proxy._types import ( LiteLLM_ObjectPermissionTable, LitellmUserRoles, UserAPIKeyAuth, ) +from litellm.proxy.mcp_server.ui_session_utils import ( + is_ui_session_credential, + resolve_ui_session_team_ids, +) from litellm.types.utils import LlmProviders from litellm.types.vector_stores import LiteLLM_ManagedVectorStore from litellm.utils import ProviderConfigManager diff --git a/litellm/proxy/video_endpoints/endpoints.py b/litellm/proxy/video_endpoints/endpoints.py index d4643994043..6d9249d5572 100644 --- a/litellm/proxy/video_endpoints/endpoints.py +++ b/litellm/proxy/video_endpoints/endpoints.py @@ -4,6 +4,7 @@ from typing import Final from fastapi import APIRouter, Depends, File, Form, Request, Response, UploadFile from fastapi.responses import ORJSONResponse +from pydantic import TypeAdapter from starlette.datastructures import UploadFile as StarletteUploadFile from litellm.proxy._types import * @@ -36,6 +37,7 @@ from litellm.types.videos.utils import ( ) router: Final = APIRouter() +_OPAQUE_VALUE_ADAPTER: Final = TypeAdapter(object) @router.post( @@ -582,7 +584,9 @@ async def video_create_character( if video_file: data["video"] = video_file[0] - target_model_name: Final = extract_model_from_target_model_names(data.get("target_model_names")) + target_model_name: Final = extract_model_from_target_model_names( + _OPAQUE_VALUE_ADAPTER.validate_python(data.get("target_model_names")) + ) if target_model_name and not data.get("model"): data["model"] = target_model_name diff --git a/litellm/proxy/video_endpoints/utils.py b/litellm/proxy/video_endpoints/utils.py index a2be42f1b76..56123e4bee3 100644 --- a/litellm/proxy/video_endpoints/utils.py +++ b/litellm/proxy/video_endpoints/utils.py @@ -15,7 +15,7 @@ if TYPE_CHECKING: from litellm.router import Router -def extract_model_from_target_model_names(target_model_names: Any) -> str | None: +def extract_model_from_target_model_names(target_model_names: object) -> str | None: if isinstance(target_model_names, str): model_names: Final = [m.strip() for m in target_model_names.split(",") if m.strip()] return model_names[0] if model_names else None diff --git a/litellm/rag/ingestion/bedrock_ingestion.py b/litellm/rag/ingestion/bedrock_ingestion.py index 1e7aa6ac1c6..5520912dd41 100644 --- a/litellm/rag/ingestion/bedrock_ingestion.py +++ b/litellm/rag/ingestion/bedrock_ingestion.py @@ -106,11 +106,11 @@ class BedrockRAGIngestion(BaseRAGIngestion, BaseAWSLLM): ) self.embedding_model = self.vector_store_config.get("embedding_model") or "amazon.titan-embed-text-v2:0" - self.wait_for_ingestion = self.vector_store_config.get("wait_for_ingestion", False) + self.wait_for_ingestion: object = self.vector_store_config.get("wait_for_ingestion", False) self.ingestion_timeout: int = _get_int(self.vector_store_config.get("ingestion_timeout"), 300) # Get AWS region using BaseAWSLLM method - _aws_region: Final = self.vector_store_config.get("aws_region_name") + _aws_region: Final[object] = self.vector_store_config.get("aws_region_name") self.aws_region_name = self.get_aws_region_name_for_non_llm_api_calls( aws_region_name=str(_aws_region) if _aws_region else None ) diff --git a/litellm/realtime_api/main.py b/litellm/realtime_api/main.py index 088dfb54155..7b9068ff95e 100644 --- a/litellm/realtime_api/main.py +++ b/litellm/realtime_api/main.py @@ -33,7 +33,7 @@ from litellm.types.router import GenericLiteLLMParams from litellm.types.utils import CallTypes, LlmProviders from litellm.utils import ProviderConfigManager, resolve_api_key_secret_reference -from ..litellm_core_utils.core_helpers import normalize_drop_params +from ..litellm_core_utils.core_helpers import as_str_mapping, normalize_drop_params from ..litellm_core_utils.credential_accessor import CredentialAccessor from ..litellm_core_utils.get_litellm_params import get_litellm_params from ..litellm_core_utils.litellm_logging import Logging as LiteLLMLogging @@ -83,6 +83,13 @@ def _with_resolved_session_model(session: dict[str, object], model_name: str) -> return {**session, "model": model_name} +def _resolved_request_session(request_data: Mapping[str, object], model_name: str) -> Mapping[str, object] | None: + session: Final = as_str_mapping(request_data.get("session")) + if not isinstance(session, dict): + return None + return _with_resolved_session_model(session, model_name) + + def _build_litellm_metadata(kwargs: dict) -> dict[str, object]: """Build the litellm_metadata dict for guardrail checking (internal only, not forwarded to provider).""" metadata: Final[dict[str, object]] = {**(kwargs.get("litellm_metadata") or {})} @@ -189,8 +196,9 @@ async def acreate_realtime_client_secret( custom_llm_provider=custom_llm_provider, ) request_data: Final = req.model_dump(exclude_none=True, exclude={"model"}) - if isinstance(request_data.get("session"), dict): - request_data["session"] = _with_resolved_session_model(request_data["session"], model_name) + resolved_session: Final = _resolved_request_session(request_data, model_name) + if resolved_session is not None: + request_data["session"] = resolved_session return await base_llm_http_handler.async_realtime_client_secret_handler( api_base=resolved_api_base, api_key=await _realtime_http_bearer_token( diff --git a/litellm/repositories/base_repository.py b/litellm/repositories/base_repository.py index 81fba770b70..92f8ba984f4 100644 --- a/litellm/repositories/base_repository.py +++ b/litellm/repositories/base_repository.py @@ -8,6 +8,7 @@ from typing import Any, Final, Generic, Protocol, TypeVar, runtime_checkable from pydantic import BaseModel +from litellm.litellm_core_utils.core_helpers import attribute_or_none from litellm.repositories.chunked_in import find_many_in from litellm.repositories.prisma_protocols import TableActions @@ -131,4 +132,4 @@ def is_unique_violation(exc: BaseException) -> bool: return "P2002" in str(exc) or "unique constraint" in str(exc).lower() if isinstance(exc, UniqueViolationError): return True - return getattr(exc, "code", None) == "P2002" + return attribute_or_none(exc, "code") == "P2002" diff --git a/litellm/repositories/prisma_protocols.py b/litellm/repositories/prisma_protocols.py index c42301a9316..63cfcbc7b45 100644 --- a/litellm/repositories/prisma_protocols.py +++ b/litellm/repositories/prisma_protocols.py @@ -171,4 +171,6 @@ class PrismaBatch(Protocol): @property def litellm_projecttable(self) -> BatchTable: ... + def execute_raw(self, query: str, *args: object) -> None: ... + async def commit(self) -> None: ... diff --git a/litellm/repositories/team_repository.py b/litellm/repositories/team_repository.py index 57f6fd33c11..b89d87aa354 100644 --- a/litellm/repositories/team_repository.py +++ b/litellm/repositories/team_repository.py @@ -75,6 +75,7 @@ class _PrismaClientView(Protocol): _MEMBERS_WITH_ROLES_ADAPTER: Final = TypeAdapter(list[Member]) +_RAW_COLUMN: Final = TypeAdapter(object) _JSON_ENCODED_TEAM_FIELDS: Final = ( "metadata", "model_spend", @@ -142,7 +143,7 @@ class TeamRepository(BaseRepository[LiteLLM_TeamTable]): ) if not rows: return None - raw_value: Final[object] = rows[0]["members_with_roles"] + raw_value: Final = _RAW_COLUMN.validate_python(rows[0]["members_with_roles"]) parsed: Final[object] = json.loads(raw_value) if isinstance(raw_value, str) else raw_value if not parsed: return [] diff --git a/litellm/repositories/unit_of_work.py b/litellm/repositories/unit_of_work.py index 95f4f5e81be..f6aad883479 100644 --- a/litellm/repositories/unit_of_work.py +++ b/litellm/repositories/unit_of_work.py @@ -15,11 +15,11 @@ instead of full-model writes, which trip ``prisma.errors.DataError`` on rows carrying fields the update input type rejects (see #27730). """ -from collections.abc import AsyncGenerator, Callable, Mapping +from collections.abc import AsyncGenerator, Callable, Mapping, Sequence from contextlib import asynccontextmanager from dataclasses import dataclass from datetime import datetime -from typing import Final +from typing import Final, Protocol, runtime_checkable from litellm.repositories.prisma_protocols import BatchTable, PrismaBatch @@ -62,6 +62,13 @@ class TeamSpendResetWrites: ) +@runtime_checkable +class SpendResetWrites(Protocol): + def queue_spend_zero(self, where: Mapping[str, object]) -> None: ... + + def queue_spend_decrement(self, where: Mapping[str, object], amount: float) -> None: ... + + @dataclass(frozen=True, slots=True) class LinkedSpendResetWrites: table: BatchTable @@ -78,6 +85,30 @@ class LinkedSpendResetWrites: ) +# Membership rows written before total_spend existed (migration 20260421135425, default 0) hold their +# history only in spend. Zeroing spend would erase it, so the floor lands in the same batch, ahead of the reset. +_TEAM_MEMBERSHIP_TOTAL_SPEND_REPAIR_SQL: Final = """ +UPDATE "LiteLLM_TeamMembership" +SET total_spend = spend +WHERE budget_id = ANY($1::text[]) AND spend > total_spend +""" + + +@dataclass(frozen=True, slots=True) +class TeamMembershipSpendResetWrites: + resets: LinkedSpendResetWrites + batch: PrismaBatch + + def queue_spend_zero(self, where: Mapping[str, object]) -> None: + self.resets.queue_spend_zero(where) + + def queue_spend_decrement(self, where: Mapping[str, object], amount: float) -> None: + self.resets.queue_spend_decrement(where, amount) + + def queue_total_spend_repair(self, budget_ids: Sequence[str]) -> None: + self.batch.execute_raw(_TEAM_MEMBERSHIP_TOTAL_SPEND_REPAIR_SQL, list(budget_ids)) + + @dataclass(frozen=True, slots=True) class BudgetWindowWrites: table: BatchTable @@ -106,7 +137,7 @@ class BudgetCascadeUnitOfWork: ``enduser_spend_reset_unit_of_work`` because one tier can gate millions. """ - team_memberships: LinkedSpendResetWrites + team_memberships: TeamMembershipSpendResetWrites keys: LinkedSpendResetWrites organizations: LinkedSpendResetWrites tags: LinkedSpendResetWrites @@ -132,7 +163,9 @@ async def budget_cascade_unit_of_work( ) -> AsyncGenerator[BudgetCascadeUnitOfWork, None]: batch = new_batch() yield BudgetCascadeUnitOfWork( - team_memberships=LinkedSpendResetWrites(table=batch.litellm_teammembership), + team_memberships=TeamMembershipSpendResetWrites( + resets=LinkedSpendResetWrites(table=batch.litellm_teammembership), batch=batch + ), keys=LinkedSpendResetWrites(table=batch.litellm_verificationtoken), organizations=LinkedSpendResetWrites(table=batch.litellm_organizationtable), tags=LinkedSpendResetWrites(table=batch.litellm_tagtable), diff --git a/litellm/rerank_api/main.py b/litellm/rerank_api/main.py index f7e2616324f..65d9b89cf79 100644 --- a/litellm/rerank_api/main.py +++ b/litellm/rerank_api/main.py @@ -1,6 +1,6 @@ import asyncio import contextvars -from collections.abc import Awaitable +from collections.abc import Awaitable, Coroutine from functools import partial from typing import Final, Literal @@ -76,7 +76,7 @@ async def arerank( func_with_context: Final = partial(ctx.run, func) init_response: Final = await loop.run_in_executor(None, func_with_context) - if asyncio.iscoroutine(init_response): + if isinstance(init_response, Coroutine): response = await init_response else: response = init_response diff --git a/litellm/rerank_api/rerank_utils.py b/litellm/rerank_api/rerank_utils.py index f365ae749d1..4924625b011 100644 --- a/litellm/rerank_api/rerank_utils.py +++ b/litellm/rerank_api/rerank_utils.py @@ -1,4 +1,4 @@ -from typing import Any, Final +from typing import Final from litellm.llms.base_llm.rerank.transformation import BaseRerankConfig @@ -8,7 +8,7 @@ def get_optional_rerank_params( model: str, drop_params: bool, query: str, - documents: list[str | dict[str, Any]], + documents: list[str | dict[str, object]], custom_llm_provider: str | None = None, top_n: int | None = None, rank_fields: list[str] | None = None, diff --git a/litellm/responses/bridge_check.py b/litellm/responses/bridge_check.py index 60318d6b184..504150b330c 100644 --- a/litellm/responses/bridge_check.py +++ b/litellm/responses/bridge_check.py @@ -10,7 +10,7 @@ from litellm.llms.azure_ai.common_utils import ( azure_ai_supports_native_responses, foundry_chat_rejects_function_tools_while_reasoning, ) -from litellm.llms.openai.chat.gpt_5_transformation import OpenAIGPT5Config +from litellm.llms.openai.chat.gpt_reasoning_transformation import OpenAIGPT5Config from litellm.secret_managers.main import get_secret_str from litellm.types.llms.openai import OpenAIWebSearchOptions from litellm.types.utils import LlmProviders @@ -175,7 +175,7 @@ def responses_api_bridge_check( pinned_mode: Final = ( None if explicit_responses_prefix else deployment_routing_mode(deployment_model_info, custom_llm_provider) ) - if explicit_responses_prefix or pinned_mode == "responses": + if custom_llm_provider == LlmProviders.CHATGPT or explicit_responses_prefix or pinned_mode == "responses": model = model.replace("responses/", "") model_info["mode"] = "responses" elif pinned_mode == "chat" and backend_serves_chat_completions(model_info): diff --git a/litellm/responses/file_search/emulated_handler.py b/litellm/responses/file_search/emulated_handler.py index 7121908517b..f29f6c83ef0 100644 --- a/litellm/responses/file_search/emulated_handler.py +++ b/litellm/responses/file_search/emulated_handler.py @@ -15,7 +15,7 @@ import json import time import uuid from collections.abc import Iterable, Sequence -from typing import TYPE_CHECKING, Any, Final, TypeAlias, cast # noqa: TID251 # see kwargs-ok / cast-ok markers +from typing import TYPE_CHECKING, Final, TypeAlias, cast # noqa: TID251 # see cast-ok markers from typing_extensions import NotRequired, ReadOnly, TypedDict @@ -517,7 +517,7 @@ async def aresponses_with_emulated_file_search( model: str, tools: Iterable[ToolParam] | None = None, # Pass-through params — forwarded as-is to the underlying aresponses call - **kwargs: Any, # kwargs-ok: `object` would surface the caller's partially-unknown dict at its call site + **kwargs: object, # kwargs-ok: pass-through params forwarded as-is to the underlying aresponses call ) -> ResponsesAPIResponse: """ Emulated file_search for providers that don't support it natively. diff --git a/litellm/responses/litellm_completion_transformation/custom_tools.py b/litellm/responses/litellm_completion_transformation/custom_tools.py index fcda6b31b00..98e1984550c 100644 --- a/litellm/responses/litellm_completion_transformation/custom_tools.py +++ b/litellm/responses/litellm_completion_transformation/custom_tools.py @@ -23,6 +23,7 @@ from typing import Final, Literal, TypeAlias from pydantic import TypeAdapter, ValidationError from litellm.exceptions import BadRequestError +from litellm.litellm_core_utils.core_helpers import as_str_mapping from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import ( ChatCompletionToolParam, @@ -30,6 +31,7 @@ from litellm.types.llms.openai import ( ) _MAX_ARGUMENTS_LEN: Final = 1_000_000 +_DECODED_JSON: Final = TypeAdapter(object) TOOL_CALL_ITEM_ID_PREFIX_BY_TYPE: Final = MappingProxyType( {"function_call": "fc", "custom_tool_call": "ctc", "tool_search_call": "tsc"} @@ -111,8 +113,8 @@ def unwrap_custom_tool_arguments(arguments: str) -> str: if len(arguments) > _MAX_ARGUMENTS_LEN: return arguments try: - parsed: Final = json.loads(arguments) - if isinstance(parsed, dict) and "content" in parsed: + parsed: Final = as_str_mapping(_DECODED_JSON.validate_python(json.loads(arguments))) + if parsed is not None and "content" in parsed: return str(parsed["content"]) except (json.JSONDecodeError, TypeError, ValueError): pass diff --git a/litellm/responses/litellm_completion_transformation/handler.py b/litellm/responses/litellm_completion_transformation/handler.py index c9d800421f7..ea3bda1b8b5 100644 --- a/litellm/responses/litellm_completion_transformation/handler.py +++ b/litellm/responses/litellm_completion_transformation/handler.py @@ -133,7 +133,6 @@ class LiteLLMCompletionTransformationHandler: litellm_completion_response: Final[ModelResponse | litellm.CustomStreamWrapper] = await litellm.acompletion( **acompletion_args, ) - if isinstance(litellm_completion_response, ModelResponse): responses_api_response: Final[ResponsesAPIResponse] = ( LiteLLMCompletionResponsesConfig.transform_chat_completion_response_to_responses_api_response( diff --git a/litellm/responses/litellm_completion_transformation/streaming_iterator.py b/litellm/responses/litellm_completion_transformation/streaming_iterator.py index c25dd4a405e..b5ef9e95741 100644 --- a/litellm/responses/litellm_completion_transformation/streaming_iterator.py +++ b/litellm/responses/litellm_completion_transformation/streaming_iterator.py @@ -5,6 +5,7 @@ from itertools import filterfalse from typing import Any, Final, cast import litellm +from litellm.litellm_core_utils.core_helpers import as_str_mapping, attribute_items from litellm.litellm_core_utils.hidden_params import get_or_create_hidden_params, served_from_cache from litellm.litellm_core_utils.litellm_logging import BilledRoundsSpend from litellm.main import stream_chunk_builder @@ -84,14 +85,18 @@ def _output_items_with_id(items: tuple[Any, ...], item_type: str, item_id: str | ) +def _is_signed_thinking_block(block: object) -> bool: + fields: Final = as_str_mapping(block) + return fields is not None and isinstance(block, dict) and bool(fields.get("signature") or fields.get("data")) + + def _streams_compaction(chunk: ModelResponseStream) -> bool: delta_fields: Final = chunk.choices[0].delta.provider_specific_fields if chunk.choices else None return delta_fields is not None and "compaction_blocks" in delta_fields def _delta_has_signed_thinking_block(delta: object) -> bool: - blocks: Final = getattr(delta, "thinking_blocks", None) or () - return any(isinstance(b, dict) and (b.get("signature") or b.get("data")) for b in blocks) + return any(_is_signed_thinking_block(block) for block in attribute_items(delta, "thinking_blocks")) def _delta_carries_output(delta: ChatCompletionDelta) -> bool: @@ -1427,7 +1432,7 @@ class LiteLLMCompletionStreamingIterator(ResponsesAPIStreamingIterator): def _is_unstreamed_empty_message(self, item: object) -> bool: if getattr(item, "type", None) != "message" or self._message_output_index is not None: return False - return not any(getattr(part, "text", None) for part in getattr(item, "content", None) or ()) + return not any(getattr(part, "text", None) for part in attribute_items(item, "content")) def finished_round_event(self) -> ResponseCompletedEvent | ResponseIncompleteEvent | None: if not isinstance(self.litellm_model_response, ModelResponse): diff --git a/litellm/responses/litellm_completion_transformation/transformation.py b/litellm/responses/litellm_completion_transformation/transformation.py index 02d9566d396..3850654daf9 100644 --- a/litellm/responses/litellm_completion_transformation/transformation.py +++ b/litellm/responses/litellm_completion_transformation/transformation.py @@ -2062,7 +2062,19 @@ class LiteLLMCompletionResponsesConfig: - ItemReference """ if input_item.get("type") == "web_search_call": - search: Final = ResponseFunctionWebSearch.model_validate(input_item) + try: + search: Final = ResponseFunctionWebSearch.model_validate(input_item) + except ValidationError as exc: + errors: Final = exc.errors(include_url=False, include_input=False) + if len(errors) != 1 or errors[0]["type"] != "missing" or errors[0]["loc"] != ("action",): + raise + replay: Final = ResponseFunctionWebSearch.model_construct(None, **input_item) + return [ + GenericChatCompletionMessage( + role="assistant", + content="Hosted web search: " + replay.model_dump_json(exclude_none=True), + ) + ] return [ GenericChatCompletionMessage( role="assistant", @@ -3663,18 +3675,20 @@ class LiteLLMCompletionResponsesConfig: if count is not None } ) - response_usage.input_tokens_details = InputTokensDetails( - cached_tokens=prompt_details.cached_tokens if prompt_details.cached_tokens is not None else 0, - text_tokens=prompt_details.text_tokens, - audio_tokens=prompt_details.audio_tokens, - image_tokens=prompt_details.image_tokens, - video_tokens=prompt_details.video_tokens, - cached_tokens_details=( - cached_tokens_details if isinstance(cached_tokens_details, CachedTokensDetails) else None - ), - **cache_write_extra, - **cache_type_extra, - **grounding_request_counts, + response_usage.input_tokens_details = InputTokensDetails.model_validate( + { + "cached_tokens": prompt_details.cached_tokens if prompt_details.cached_tokens is not None else 0, + "text_tokens": prompt_details.text_tokens, + "audio_tokens": prompt_details.audio_tokens, + "image_tokens": prompt_details.image_tokens, + "video_tokens": prompt_details.video_tokens, + "cached_tokens_details": ( + cached_tokens_details if isinstance(cached_tokens_details, CachedTokensDetails) else None + ), + **cache_write_extra, + **cache_type_extra, + **grounding_request_counts, + } ) # Translate completion_tokens_details to output_tokens_details diff --git a/litellm/responses/main.py b/litellm/responses/main.py index 0b526adf4fa..d993b05f5b7 100644 --- a/litellm/responses/main.py +++ b/litellm/responses/main.py @@ -6,10 +6,10 @@ from contextlib import contextmanager from dataclasses import dataclass from functools import partial from types import MappingProxyType -from typing import TYPE_CHECKING, Any, Final, Literal, NoReturn, Optional, TypeAlias, cast +from typing import TYPE_CHECKING, Annotated, Any, Final, Literal, NoReturn, Optional, TypeAlias, cast import httpx -from pydantic import BaseModel, TypeAdapter, ValidationError +from pydantic import BaseModel, ConfigDict, Field, TypeAdapter, ValidationError from typing_extensions import ( TypeIs, # noqa: TID251 # narrows a client input item before its mark is read assert_never, @@ -87,7 +87,13 @@ from litellm.llms.openai.data_residency import infer_openai_data_residency from litellm.types.responses.main import * from litellm.types.responses.streaming_websocket import ResponsesWebSocketRequestDefaults from litellm.types.router import GenericLiteLLMParams -from litellm.types.utils import ADDRESSED_RESPONSE_ID_FIELD, CallTypes, all_litellm_params +from litellm.types.utils import ( + ADDRESSED_RESPONSE_ID_FIELD, + CallTypes, + CostPerToken, + CustomPricingLiteLLMParams, + all_litellm_params, +) from litellm.utils import ( ProviderConfigManager, client, @@ -185,6 +191,7 @@ def mock_responses_api_response( _STR_MAPPING: Final = TypeAdapter(Mapping[str, object]) +_FORWARDED_VALUE: Final = TypeAdapter(object) def _client_trace_id(request_kwargs: Mapping[str, object]) -> str | None: @@ -546,6 +553,47 @@ async def aresponses_api_with_mcp( return response +def _per_call_custom_pricing(litellm_params: GenericLiteLLMParams) -> Mapping[str, float]: + return MappingProxyType( + litellm_params.model_dump(include=set(CustomPricingLiteLLMParams.model_fields), exclude_none=True) + ) + + +class _DeploymentModelInfo(BaseModel): + model_config = ConfigDict(frozen=True) + id: object = None + + +_DEPLOYMENT_MODEL_INFO: Final[TypeAdapter[_DeploymentModelInfo | object]] = TypeAdapter( + Annotated[_DeploymentModelInfo | object, Field(union_mode="left_to_right")] +) + + +def _is_router_deployment(deployment_model_info: object) -> bool: + """A Router stamps the deployment's model_info (with its id) onto every call it routes.""" + parsed: Final = _DEPLOYMENT_MODEL_INFO.validate_python(deployment_model_info) + return isinstance(parsed, _DeploymentModelInfo) and parsed.id is not None + + +_COST_PER_TOKEN: Final = TypeAdapter(CostPerToken) + + +def _per_call_cost_per_token(litellm_params: GenericLiteLLMParams) -> CostPerToken | None: + if litellm_params.input_cost_per_token is None or litellm_params.output_cost_per_token is None: + return None + return _COST_PER_TOKEN.validate_python( + litellm_params.model_dump( + include={ + "input_cost_per_token", + "output_cost_per_token", + "cache_read_input_token_cost", + "cache_creation_input_token_cost", + }, + exclude_none=True, + ) + ) + + def _bridges_to_chat_completions( responses_api_provider_config: BaseResponsesAPIConfig | None, use_chat_completions_api: bool ) -> bool: @@ -657,10 +705,12 @@ def _api_base_kwarg(kwargs: Mapping[str, object]) -> str | None: return api_base if isinstance(api_base, str) else None -def _dispatched_model_name(model: str, custom_llm_provider: str, api_base: str | None) -> str: - provider_model, _, _, _ = litellm.get_llm_provider( - model=model, custom_llm_provider=custom_llm_provider, api_base=api_base - ) +def _dispatched_model_name( + model: str, custom_llm_provider: str, api_base: str | None, litellm_params: GenericLiteLLMParams | None = None +) -> str: + from litellm.litellm_core_utils.get_llm_provider_logic import resolve_model_and_provider_for_metadata + + provider_model, _ = resolve_model_and_provider_for_metadata(model=model, custom_llm_provider=custom_llm_provider) return _strip_responses_routing_prefix(provider_model) @@ -670,6 +720,7 @@ def _will_bridge_to_chat_completions( use_chat_completions_api: bool, model_info: object, api_base: str | None, + litellm_params: GenericLiteLLMParams | None = None, ) -> bool: """``_bridges_to_chat_completions`` for callers running before the provider config is resolved. @@ -686,7 +737,7 @@ def _will_bridge_to_chat_completions( return True return _bridges_to_chat_completions( _resolve_responses_api_provider_config( - _dispatched_model_name(normalized_model[0], custom_llm_provider, api_base), + _dispatched_model_name(normalized_model[0], custom_llm_provider, api_base, litellm_params), custom_llm_provider, model_info, api_base, @@ -702,12 +753,15 @@ def provider_stores_the_conversation(model: str, custom_llm_provider: str | None first MCP round runs as an internal call that writes no spend log at all. """ api_base: Final = _api_base_kwarg(kwargs) + litellm_params: Final = GenericLiteLLMParams(**kwargs) return not _will_bridge_to_chat_completions( model, - custom_llm_provider or litellm.get_llm_provider(model=model, api_base=api_base)[1], + custom_llm_provider + or litellm.get_llm_provider(model=model, api_base=api_base, litellm_params=litellm_params)[1], bool(kwargs.get("use_chat_completions_api")), kwargs.get("model_info"), api_base, + litellm_params, ) @@ -819,7 +873,7 @@ async def aresponses( stream: bool | None = None, temperature: float | None = None, text: Optional["ResponseText"] = None, - text_format: type["BaseModel"] | dict | None = None, + text_format: type["BaseModel"] | dict[str, object] | None = None, tool_choice: ToolChoice | None = None, tools: Iterable[ToolParam] | None = None, top_p: float | None = None, @@ -857,7 +911,8 @@ async def aresponses( model=model, api_base=local_vars.get("base_url", None), litellm_params=GenericLiteLLMParams( - **cast("dict[str, object]", kwargs) # cast-ok: kwargs is the untyped request dict + extra_headers=extra_headers, + **cast("dict[str, object]", kwargs), # cast-ok: kwargs is the untyped request dict ), ) # Update local_vars with detected provider (fixes #19782) @@ -888,6 +943,7 @@ async def aresponses( bool(kwargs.get("use_chat_completions_api")), kwargs.get("model_info"), _api_base_kwarg(kwargs), + GenericLiteLLMParams(**kwargs), ), ): _stamp_injection_points_for_the_hook(kwargs, model, custom_llm_provider, input, tools) @@ -919,7 +975,7 @@ async def aresponses( original_model=original_model, swapped_model=model, custom_llm_provider=custom_llm_provider, - kwargs=kwargs, + kwargs={**kwargs, "extra_headers": extra_headers}, prompt_id=prompt_id, ) kwargs.pop("prompt_id", None) @@ -1003,11 +1059,14 @@ def _resolve_prompt_swapped_provider( kwargs: Mapping[str, object], prompt_id: str | None, ) -> str: - swapped_provider: Final = litellm.get_llm_provider(model=swapped_model)[1] + litellm_params: Final = GenericLiteLLMParams(**kwargs) + swapped_provider: Final = litellm.get_llm_provider(model=swapped_model, litellm_params=litellm_params)[1] if kwargs.get("api_key") is None and kwargs.get("api_base") is None: return swapped_provider try: - original_provider: Final = custom_llm_provider or litellm.get_llm_provider(model=original_model)[1] + original_provider: Final = ( + custom_llm_provider or litellm.get_llm_provider(model=original_model, litellm_params=litellm_params)[1] + ) except litellm.BadRequestError: return swapped_provider if swapped_provider == original_provider: @@ -1060,6 +1119,7 @@ def _apply_prompt_management_to_responses_call( use_chat_completions_api, kwargs.get("model_info"), _api_base_kwarg(kwargs), + GenericLiteLLMParams(**kwargs), ), ): _stamp_injection_points_for_the_hook(kwargs, model, custom_llm_provider, input, tools) @@ -1094,7 +1154,7 @@ def _apply_prompt_management_to_responses_call( original_model=original_model, swapped_model=model, custom_llm_provider=custom_llm_provider, - kwargs=kwargs, + kwargs={**kwargs, "extra_headers": local_vars.get("extra_headers")}, prompt_id=prompt_id, ) ) @@ -1308,7 +1368,7 @@ def _responses_try_dispatch_emulated_file_search( user: str | None, service_tier: str | None, safety_identifier: str | None, - text_format: type[BaseModel] | dict | None, + text_format: type[BaseModel] | dict[str, object] | None, allowed_openai_params: list[str] | None, extra_headers: dict[str, object] | None, extra_query: dict[str, object] | None, @@ -1343,7 +1403,7 @@ def _responses_try_dispatch_emulated_file_search( "background": background, "stream": stream, "temperature": temperature, - "text": text, + "text": _FORWARDED_VALUE.validate_python(text), "tool_choice": tool_choice, "top_p": top_p, "truncation": truncation, @@ -1388,7 +1448,7 @@ def responses( stream: bool | None = None, temperature: float | None = None, text: Optional["ResponseText"] = None, - text_format: type["BaseModel"] | dict | None = None, + text_format: type["BaseModel"] | dict[str, object] | None = None, tool_choice: ToolChoice | None = None, tools: Iterable[ToolParam] | None = None, top_p: float | None = None, @@ -1450,7 +1510,8 @@ def responses( model=model, api_base=local_vars.get("base_url", None), litellm_params=GenericLiteLLMParams( - **cast("dict[str, object]", kwargs) # cast-ok: kwargs is the untyped request dict + extra_headers=extra_headers, + **cast("dict[str, object]", kwargs), # cast-ok: kwargs is the untyped request dict ), ) local_vars["custom_llm_provider"] = custom_llm_provider @@ -1466,8 +1527,16 @@ def responses( use_chat_completions_api=use_chat_completions_api, ) - # get llm provider logic - litellm_params: Final = GenericLiteLLMParams(**kwargs) + from litellm.litellm_core_utils.core_helpers import attribute_or_none + + litellm_params: Final = GenericLiteLLMParams(extra_headers=extra_headers, **kwargs) + provider_headers: Final = ResponsesAPIRequestUtils.merge_provider_specific_headers( + extra_headers=extra_headers, + provider_specific_header=attribute_or_none(litellm_params, "provider_specific_header"), + custom_llm_provider=custom_llm_provider, + ) + local_vars["extra_headers"] = provider_headers + affinity_api_base: Final = ( get_openai_credentials(api_base=litellm_params.api_base).api_base if custom_llm_provider == "openai" @@ -1477,7 +1546,7 @@ def responses( try: effective_extra_headers: Final = ( add_provider_affinity_header( - headers=extra_headers or MappingProxyType({}), + headers=provider_headers or MappingProxyType({}), litellm_params=MappingProxyType( { "provider_affinity_header": litellm_params.provider_affinity_header, @@ -1490,7 +1559,7 @@ def responses( default_header=default_affinity_header, ) if litellm_params.provider_affinity_header is not None or default_affinity_header is not None - else extra_headers + else provider_headers ) except ValueError as affinity_error: raise litellm.BadRequestError( @@ -1673,6 +1742,7 @@ def responses( optional_params=dict(responses_api_request_params), litellm_params={ **responses_api_request_params, + **_per_call_custom_pricing(litellm_params), "aresponses": _is_async, "litellm_call_id": litellm_call_id, "model_info": kwargs.get("model_info"), @@ -1683,6 +1753,9 @@ def responses( custom_llm_provider=custom_llm_provider, ) + if not _is_router_deployment(deployment_model_info): + litellm_logging_obj.custom_cost_per_token = _per_call_cost_per_token(litellm_params) + litellm_logging_obj.custom_cost_per_second = litellm_params.cost_per_second # Decode any litellm-encoded encrypted-content item IDs back to their original IDs input = with_compaction_items_as_summaries( with_compaction_items_as_params(ResponsesAPIRequestUtils.restore_encrypted_content_item_ids_in_input(input)) diff --git a/litellm/responses/mcp/chat_completions_handler.py b/litellm/responses/mcp/chat_completions_handler.py index b100858b306..cd072825ef5 100644 --- a/litellm/responses/mcp/chat_completions_handler.py +++ b/litellm/responses/mcp/chat_completions_handler.py @@ -4,6 +4,7 @@ import logging from types import MappingProxyType from typing import TYPE_CHECKING, Final, cast +from pydantic import TypeAdapter from typing_extensions import TypedDict, Unpack from litellm._internal_context import internal_sub_call @@ -24,6 +25,8 @@ from litellm.utils import CustomStreamWrapper if TYPE_CHECKING: from litellm.types.proxy.auth.user_api_key_auth import UserAPIKeyAuth +_DELEGATED_ATTRIBUTE: Final = TypeAdapter(object) + class _MCPCompletionKwargs(TypedDict, total=False, extra_items=object): """Extra keywords forwarded verbatim to ``litellm.acompletion``, which owns their contract.""" @@ -566,7 +569,7 @@ async def acompletion_with_mcp( def __getattr__(self, name: str) -> object: # Delegate all other attributes to original wrapper - return getattr(self._original_wrapper, name) + return _DELEGATED_ATTRIBUTE.validate_python(getattr(self._original_wrapper, name)) # Helper class to wrap async iterator for sync iteration class _SyncIteratorWrapper: diff --git a/litellm/responses/mcp/litellm_proxy_mcp_handler.py b/litellm/responses/mcp/litellm_proxy_mcp_handler.py index e3c3ab671ea..c01d07fb5c3 100644 --- a/litellm/responses/mcp/litellm_proxy_mcp_handler.py +++ b/litellm/responses/mcp/litellm_proxy_mcp_handler.py @@ -11,8 +11,8 @@ from typing_extensions import Unpack from litellm._logging import verbose_logger from litellm.constants import MAXIMUM_TRACEBACK_LINES_TO_LOG from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj -from litellm.proxy._experimental.mcp_server.catalog import catalog_operation, global_manager -from litellm.proxy._experimental.mcp_server.utils import ( +from litellm.proxy.mcp_server.catalog import catalog_operation, global_manager +from litellm.proxy.mcp_server.utils import ( iter_known_server_prefixes, logging_safe_mcp_headers, split_server_prefix_from_name, @@ -48,7 +48,7 @@ if TYPE_CHECKING: from mcp.types import CallToolResult from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.ui_session_utils import GrantedToolsetIds + from litellm.proxy.mcp_server.ui_session_utils import GrantedToolsetIds from litellm.proxy.utils import ProxyLogging from litellm.responses.mcp.mcp_streaming_iterator import MCPEnhancedStreamingIterator from litellm.types.proxy.auth.user_api_key_auth import UserAPIKeyAuth @@ -71,7 +71,7 @@ class _AresponsesOptions(ExtraItemsTypedDict, total=False, extra_items=object): def _registered_mcp_servers() -> Collection[MCPServer]: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -89,7 +89,7 @@ def _registry_serves(name: str, servers: Collection[MCPServer]) -> bool: async def _toolset_exists(name: str) -> bool: try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) from litellm.proxy.proxy_server import prisma_client @@ -193,7 +193,7 @@ class LiteLLM_Proxy_MCP_Handler: from litellm.proxy._types import LiteLLM_ObjectPermissionTable try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -253,10 +253,10 @@ class LiteLLM_Proxy_MCP_Handler: List of MCP tools List names of allowed MCP servers """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_allowed_mcp_servers_from_mcp_server_names, _get_tools_from_mcp_servers, ) @@ -282,12 +282,12 @@ class LiteLLM_Proxy_MCP_Handler: toolset = await global_mcp_server_manager.get_toolset_by_name_cached(prisma_client, name) if toolset is not None: if user_api_key_auth is not None: - from litellm.proxy._experimental.mcp_server.ui_session_utils import ( - granted_toolset_ids, - ) from litellm.proxy.management_endpoints.common_utils import ( user_api_key_has_admin_view, ) + from litellm.proxy.mcp_server.ui_session_utils import ( + granted_toolset_ids, + ) if not user_api_key_has_admin_view(user_api_key_auth) and toolset.toolset_id not in ( await (granted_toolsets or granted_toolset_ids)(user_api_key_auth) @@ -527,7 +527,7 @@ class LiteLLM_Proxy_MCP_Handler: target_format: Literal["responses", "chat"] = "responses", ) -> Sequence[FunctionToolParam | ChatCompletionToolParam]: """Transform MCP tools to OpenAI-compatible format.""" - from litellm.experimental_mcp_client.tools import ( + from litellm.mcp_client.tools import ( transform_mcp_tool_to_openai_responses_api_tool, transform_mcp_tool_to_openai_tool, ) @@ -720,10 +720,10 @@ class LiteLLM_Proxy_MCP_Handler: from litellm._uuid import uuid from litellm.exceptions import BlockedPiiEntityError, GuardrailRaisedException - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _resolve_display_name_to_original, ) from litellm.proxy.proxy_server import proxy_logging_obj diff --git a/litellm/responses/mcp/mcp_streaming_iterator.py b/litellm/responses/mcp/mcp_streaming_iterator.py index 030911238ec..cc79d1c88bb 100644 --- a/litellm/responses/mcp/mcp_streaming_iterator.py +++ b/litellm/responses/mcp/mcp_streaming_iterator.py @@ -3,6 +3,7 @@ from typing import TYPE_CHECKING, Any, Final, cast from litellm._logging import verbose_logger from litellm._uuid import uuid +from litellm.litellm_core_utils.agentic_loop_settings import validated_max_agentic_loops from litellm.responses.litellm_completion_transformation.streaming_iterator import LiteLLMCompletionStreamingIterator from litellm.responses.mcp.request_context import MCPRequestContext from litellm.responses.mcp.stream_round_billing import StreamedRoundBilling @@ -289,6 +290,10 @@ class MCPEnhancedStreamingIterator(BaseResponsesAPIStreamingIterator): self.mcp_tools_with_litellm_proxy = mcp_tools_with_litellm_proxy or [] self.user_api_key_auth = user_api_key_auth self.original_request_params = original_request_params or {} + configured_rounds: Final = validated_max_agentic_loops( + self.original_request_params.get("max_agentic_loops"), field="litellm_params.max_agentic_loops" + ) + self.max_tool_call_rounds: int = MAX_MCP_TOOL_CALL_ROUNDS if configured_rounds is None else configured_rounds self.should_auto_execute = self._should_auto_execute_tools() # Streaming state management @@ -363,7 +368,7 @@ class MCPEnhancedStreamingIterator(BaseResponsesAPIStreamingIterator): from starlette.datastructures import Headers - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -509,7 +514,7 @@ class MCPEnhancedStreamingIterator(BaseResponsesAPIStreamingIterator): 2. mcp_discovery - Emit MCP discovery events (after response.output_item.added) 3. continue_initial_response - Stream the current round's response (initial or follow-up). On completion, if auto-execute is on and the response contains tool calls, loops back - through tool_execution/follow-up instead of ending, up to MAX_MCP_TOOL_CALL_ROUNDS. + through tool_execution/follow-up instead of ending, up to self.max_tool_call_rounds. 4. tool_execution - Emit tool execution events 5. finished - End iteration """ @@ -1015,14 +1020,14 @@ class MCPEnhancedStreamingIterator(BaseResponsesAPIStreamingIterator): # Remove tool_choice to avoid forcing more tool calls follow_up_params.pop("tool_choice", None) - if self.tool_call_round >= MAX_MCP_TOOL_CALL_ROUNDS: + if self.tool_call_round >= self.max_tool_call_rounds: # Hit the round cap: drop tools entirely so the model must # answer in text instead of emitting another (unexecuted) # tool call that would otherwise end the stream in silence. follow_up_params.pop("tools", None) verbose_logger.warning( - "MCP auto-execute hit MAX_MCP_TOOL_CALL_ROUNDS=%s; forcing a text-only follow-up.", - MAX_MCP_TOOL_CALL_ROUNDS, + "MCP auto-execute hit max_agentic_loops=%s; forcing a text-only follow-up.", + self.max_tool_call_rounds, ) follow_up_response: Final = await aresponses(**follow_up_params) diff --git a/litellm/responses/mcp/tool_precheck.py b/litellm/responses/mcp/tool_precheck.py index b76f4066e6d..a29e6895f9a 100644 --- a/litellm/responses/mcp/tool_precheck.py +++ b/litellm/responses/mcp/tool_precheck.py @@ -7,7 +7,7 @@ LITELLM_PROXY_MCP_SERVER_URL: Final = "litellm_proxy" LITELLM_PROXY_MCP_SERVER_URL_PREFIX: Final = f"{LITELLM_PROXY_MCP_SERVER_URL}/mcp/" _PROXY_MCP_PATH_RE: Final = re.compile(r"^https?://.+/mcp/([^/]+)$") -_GATEWAY_REGISTRY_MODULE: Final = "litellm.proxy._experimental.mcp_server.mcp_server_manager" +_GATEWAY_REGISTRY_MODULE: Final = "litellm.proxy.mcp_server.mcp_server_manager" def _mcp_server_url(tool: object) -> str | None: diff --git a/litellm/responses/sse_output_recovery.py b/litellm/responses/sse_output_recovery.py index cdabcb504d3..e7d0a540022 100644 --- a/litellm/responses/sse_output_recovery.py +++ b/litellm/responses/sse_output_recovery.py @@ -11,9 +11,12 @@ import json from collections.abc import Mapping from typing import Final, SupportsInt, TypeAlias, cast # noqa: TID251 # int() re-checks the cast below at runtime +from pydantic import TypeAdapter + from litellm.constants import STREAM_SSE_DONE_STRING _MAX_CONTENT_INDEX: Final = 1024 +_DECODED_JSON: Final = TypeAdapter(object) _ConvertibleToInt: TypeAlias = SupportsInt | str @@ -33,7 +36,7 @@ def parse_sse_json_chunk(chunk: str) -> dict[str, object] | None: if not stripped_chunk or stripped_chunk == STREAM_SSE_DONE_STRING or stripped_chunk.startswith("event:"): return None try: - parsed_chunk: Final[object] = json.loads(stripped_chunk) + parsed_chunk: Final = _DECODED_JSON.validate_python(json.loads(stripped_chunk)) except json.JSONDecodeError: return None if not isinstance(parsed_chunk, dict): diff --git a/litellm/responses/streaming_iterator.py b/litellm/responses/streaming_iterator.py index 0d59c93786c..50ab3e4f75a 100644 --- a/litellm/responses/streaming_iterator.py +++ b/litellm/responses/streaming_iterator.py @@ -28,7 +28,7 @@ from typing import ( import httpx from openai._streaming import SSEDecoder -from pydantic import BaseModel, ValidationError +from pydantic import BaseModel, TypeAdapter, ValidationError from typing_extensions import TypeIs import litellm @@ -166,6 +166,7 @@ def _typed_gets_litellm_params(fn: _GetsLitellmParams) -> _GetsLitellmParams: _SHOULD_STORE_RESULT_IN_CACHE_ATTR: Final = "_should_store_result_in_cache" _UNMASK_PII_TEXT_ATTR: Final = "_unmask_pii_text" +_DECODED_JSON: Final = TypeAdapter(object) def _load_json_object(payload: str | bytes) -> dict[str, object]: @@ -175,7 +176,7 @@ def _load_json_object(payload: str | bytes) -> dict[str, object]: def _load_json_value(payload: str | bytes) -> object: """Parse a JSON payload whose top-level shape the caller narrows itself.""" - return json.loads(payload) + return _DECODED_JSON.validate_python(json.loads(payload)) def _model_id_from_metadata(litellm_metadata: Mapping[str, object] | None) -> str | None: diff --git a/litellm/responses/utils.py b/litellm/responses/utils.py index 503d85aaed9..a6b042a2234 100644 --- a/litellm/responses/utils.py +++ b/litellm/responses/utils.py @@ -5,14 +5,18 @@ from functools import reduce from typing import Any, Final, Optional, TypeVar, Union, cast, get_type_hints, overload from pydantic import BaseModel, TypeAdapter +from typing_extensions import TypedDict as ExtraItemsTypedDict from typing_extensions import TypeIs # noqa: TID251 # narrows untyped wire payloads without a runtime conversion import litellm from litellm._logging import verbose_logger +from litellm.litellm_core_utils.core_helpers import as_str_mapping, attribute_or_none, iter_items from litellm.litellm_core_utils.dot_notation_indexing import delete_nested_value, is_nested_path +from litellm.litellm_core_utils.get_provider_specific_headers import ProviderSpecificHeaderUtils from litellm.llms.base_llm.responses.transformation import BaseResponsesAPIConfig, ReasoningSummaryLevel from litellm.types.llms.openai import ( AllMessageValues, + InputTokensDetails, OutputTokensDetails, ResponseAPIUsage, ResponseInputParam, @@ -23,13 +27,23 @@ from litellm.types.llms.openai import ( ) from litellm.types.responses.main import DecodedResponseId from litellm.types.utils import ( + CacheCreationTokenDetails, CompletionTokensDetailsWrapper, PromptTokensDetailsWrapper, + ProviderSpecificHeader, SpecialEnums, Usage, text_tokens_without_nested_reasoning, ) +_PROVIDER_SPECIFIC_HEADER_ADAPTER: Final[ + TypeAdapter[ProviderSpecificHeader | Sequence[ProviderSpecificHeader] | None] +] = TypeAdapter(ProviderSpecificHeader | Sequence[ProviderSpecificHeader] | None) + + +class _UsageExtraFields(ExtraItemsTypedDict, total=False, extra_items=object): + pass + def _apply_nested_drop_params(params: dict[str, object], additional_drop_params: list[str] | None) -> dict[str, object]: nested_paths: Final = tuple(path for path in additional_drop_params or () if is_nested_path(path)) @@ -41,6 +55,17 @@ def _output_token_detail(details: object, field: str) -> int | None: return value if isinstance(value, int) else None +def _cache_write_lifetimes(cache_write_tokens_details: object) -> CacheCreationTokenDetails | None: + """OpenAI Responses splits `cache_write_tokens` into `ttl_30m_tokens` and `ttl_12h_tokens`.""" + ttl_30m_tokens: Final = _output_token_detail(cache_write_tokens_details, "ttl_30m_tokens") + ttl_12h_tokens: Final = _output_token_detail(cache_write_tokens_details, "ttl_12h_tokens") + if ttl_30m_tokens is None and ttl_12h_tokens is None: + return None + return CacheCreationTokenDetails( + ephemeral_30m_input_tokens=ttl_30m_tokens, ephemeral_12h_input_tokens=ttl_12h_tokens + ) + + def _is_object_sequence(value: object) -> TypeIs[Sequence[object]]: # guard-ok: a list is a Sequence of anything return isinstance(value, list) @@ -51,6 +76,28 @@ def _is_object_dict( return isinstance(value, dict) +def _prompt_tokens_details_wrapper(details: object) -> PromptTokensDetailsWrapper: + if _is_object_dict(details): + input_details: Final = InputTokensDetails.model_validate(details) + return PromptTokensDetailsWrapper( + **input_details.model_dump(exclude={"cache_write_tokens_details"}), + cache_creation_token_details=_cache_write_lifetimes(input_details.cache_write_tokens_details), + ) + return PromptTokensDetailsWrapper( + cached_tokens=getattr(details, "cached_tokens", None), + audio_tokens=getattr(details, "audio_tokens", None), + text_tokens=getattr(details, "text_tokens", None), + image_tokens=getattr(details, "image_tokens", None), + cached_tokens_details=getattr(details, "cached_tokens_details", None), + video_tokens=getattr(details, "video_tokens", None), + cache_write_tokens=getattr(details, "cache_write_tokens", None), + cache_creation_token_details=_cache_write_lifetimes(getattr(details, "cache_write_tokens_details", None)), + cache_type=getattr(details, "cache_type", None), + web_search_requests=getattr(details, "web_search_requests", None), + google_maps_grounding_requests=getattr(details, "google_maps_grounding_requests", None), + ) + + def normalize_responses_api_stream_options( stream_options: object, ) -> ResponsesAPIStreamOptions | None: @@ -192,6 +239,20 @@ class ResponsesAPIRequestUtils: **extra_headers, } + @staticmethod + def merge_provider_specific_headers( + extra_headers: Mapping[str, object] | None, + provider_specific_header: object, + custom_llm_provider: str | None, + ) -> dict[str, object] | None: # mutable-ok: legacy Responses request fields require a dict + scoped_headers: Final = ProviderSpecificHeaderUtils.get_provider_specific_headers( + provider_specific_header=_PROVIDER_SPECIFIC_HEADER_ADAPTER.validate_python(provider_specific_header), + custom_llm_provider=custom_llm_provider, + ) + if extra_headers is None and not scoped_headers: + return None + return {**(extra_headers or {}), **scoped_headers} + @staticmethod def _check_valid_arg( supported_params: list[str] | None, @@ -1047,7 +1108,7 @@ class ResponsesAPIRequestUtils: @staticmethod def _update_container_ids_in_response( - responses_api_response: ResponsesAPIResponse | dict[str, Any], + responses_api_response: ResponsesAPIResponse | dict[str, object], custom_llm_provider: str | None, litellm_metadata: dict[str, Any] | None = None, ) -> ResponsesAPIResponse | dict[str, object]: @@ -1061,15 +1122,16 @@ class ResponsesAPIRequestUtils: model_id: Final = model_info.get("id") # Get the output list - if isinstance(responses_api_response, dict): - output = responses_api_response.get("output", []) - else: - output = getattr(responses_api_response, "output", []) + output: Final = ( + responses_api_response.get("output", []) + if isinstance(responses_api_response, dict) + else attribute_or_none(responses_api_response, "output") + ) if not output: return responses_api_response - for item in output: + for item in iter_items(output): ResponsesAPIRequestUtils.encode_container_id_on_output_item( item=item, custom_llm_provider=custom_llm_provider, @@ -1128,7 +1190,7 @@ class ResponsesAPIRequestUtils: """ from starlette.datastructures import Headers - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -1244,27 +1306,11 @@ class ResponseAPILoggingUtils: response_api_usage = usage_input prompt_tokens: Final[int] = response_api_usage.input_tokens or 0 completion_tokens: Final[int] = response_api_usage.output_tokens or 0 - prompt_tokens_details: PromptTokensDetailsWrapper | None = None - if response_api_usage.input_tokens_details: - if isinstance(response_api_usage.input_tokens_details, dict): - prompt_tokens_details = PromptTokensDetailsWrapper(**response_api_usage.input_tokens_details) - else: - prompt_tokens_details = PromptTokensDetailsWrapper( - cached_tokens=getattr(response_api_usage.input_tokens_details, "cached_tokens", None), - audio_tokens=getattr(response_api_usage.input_tokens_details, "audio_tokens", None), - text_tokens=getattr(response_api_usage.input_tokens_details, "text_tokens", None), - image_tokens=getattr(response_api_usage.input_tokens_details, "image_tokens", None), - cached_tokens_details=getattr( - response_api_usage.input_tokens_details, "cached_tokens_details", None - ), - video_tokens=getattr(response_api_usage.input_tokens_details, "video_tokens", None), - cache_write_tokens=getattr(response_api_usage.input_tokens_details, "cache_write_tokens", None), - cache_type=getattr(response_api_usage.input_tokens_details, "cache_type", None), - web_search_requests=getattr(response_api_usage.input_tokens_details, "web_search_requests", None), - google_maps_grounding_requests=getattr( - response_api_usage.input_tokens_details, "google_maps_grounding_requests", None - ), - ) + prompt_tokens_details: Final = ( + _prompt_tokens_details_wrapper(response_api_usage.input_tokens_details) + if response_api_usage.input_tokens_details + else None + ) completion_tokens_details: CompletionTokensDetailsWrapper | None = None output_tokens_details: Final[OutputTokensDetails | None] = getattr( response_api_usage, "output_tokens_details", None @@ -1288,20 +1334,22 @@ class ResponseAPILoggingUtils: audio_tokens=audio_tokens, ) - extra_usage_fields: Final = { - key: value - for key, value in (response_api_usage.model_extra or {}).items() - if key - not in ( - "input_token_details", - "output_token_details", - "prompt_tokens", - "completion_tokens", - "total_tokens", - "prompt_tokens_details", - "completion_tokens_details", - ) - } + extra_usage_fields: Final = _UsageExtraFields( + **{ + key: value + for key, value in (as_str_mapping(response_api_usage.model_extra) or {}).items() + if key + not in ( + "input_token_details", + "output_token_details", + "prompt_tokens", + "completion_tokens", + "total_tokens", + "prompt_tokens_details", + "completion_tokens_details", + ) + } + ) chat_usage: Final = Usage( prompt_tokens=prompt_tokens, completion_tokens=completion_tokens, diff --git a/litellm/router.py b/litellm/router.py index da04e59f18a..0d4045e6ca8 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -98,7 +98,9 @@ from litellm.litellm_core_utils.credential_accessor import CredentialAccessor, r from litellm.litellm_core_utils.dd_tracing import tracer from litellm.litellm_core_utils.get_llm_provider_logic import ( declared_authenticating_provider, + inferred_provider, is_registered_custom_provider, + resolve_model_and_provider_for_metadata, ) from litellm.litellm_core_utils.hidden_params import ( HIDDEN_PARAMS_ATTR as _HIDDEN_PARAMS_ATTR, @@ -438,6 +440,7 @@ from litellm.utils import ( EmbeddingResponse, ModelInfoLookupMiss, ModelResponse, + ProviderConfigManager, Rules, TextCompletionResponse, function_setup, @@ -560,6 +563,7 @@ _ALIAS_PARAMS_NEVER_FORWARDED: Final = frozenset( {"model", "api_base", "api_key", "api_version", "responses_api_version"} ) _ALIAS_MARKER_FORWARDED_PARAMS_KWARG: Final = "_alias_marker_forwarded_params" +_FORWARDED_CREDENTIAL_ISOLATION_PROVIDERS: Final = frozenset({"chatgpt", "anthropic"}) _CLAUDE_CODE_SESSION_ID_RE: Final = re.compile(r"^[a-zA-Z0-9_\-]{8,}$") _CLAUDE_CODE_SESSION_ROUTER_TTL_SECONDS: Final = 3600 CLAUDE_CODE_SESSION_ROUTER_BINDING_TARGET: Final = "claude_code_session_router_binding" @@ -567,6 +571,13 @@ CLAUDE_CODE_SESSION_ROUTER_BINDING_TARGET: Final = "claude_code_session_router_b _PRE_CALL_CHECK_FILTERED_PARAMS: Final = frozenset({"response_format"}) _STREAM_TIMEOUT_AWARE_GENERIC_HANDLERS: Final = frozenset({"anthropic_messages", "aresponses", "responses"}) _video_call_deployment_id: Final[ContextVar[str | None]] = ContextVar("video_call_deployment_id", default=None) +_routed_call_type: Final[ContextVar[str | None]] = ContextVar("routed_call_type", default=None) +_ROUTE_CAPABILITY_RESOLVERS: Final[Mapping[str, Callable[[str, LlmProviders], object | None]]] = MappingProxyType( + { + "adecisions": ProviderConfigManager.get_provider_decisions_config, + "decisions": ProviderConfigManager.get_provider_decisions_config, + } +) _RUNTIME_TOGGLEABLE_PRE_CALL_CHECKS: Final[Mapping[str, type[CustomLogger]]] = MappingProxyType( { "prompt_caching": PromptCachingDeploymentCheck, @@ -726,7 +737,7 @@ def _anthropic_stream_forwards_ping_live(chunk: object, has_generated_content: b """A `ping` keepalive reaches the client live whenever the stream has not committed: it carries no lifecycle, so it cannot create overlapping lifecycles on the wire, and it keeps the connection alive while lifecycle frames sit buffered for a possible fallback during a long thinking pass.""" - from litellm.llms.anthropic.pass_through.messages.streaming_iterator import is_anthropic_ping_chunk + from litellm.llms.anthropic.messages.native.streaming_iterator import is_anthropic_ping_chunk return not has_generated_content and is_anthropic_ping_chunk(chunk) @@ -742,7 +753,7 @@ def _without_line_breaks(value: object) -> str: def _anthropic_stream_error_is_gateway_verdict(chunk: object) -> bool: """AgenticAnthropicStreamingIterator's own retrieval-failure frame is the gateway's verdict, not a provider failure: another deployment would rerun the same failed hook, so it reaches the client instead of falling back.""" - from litellm.llms.anthropic.pass_through.messages.agentic_streaming_iterator import ( + from litellm.llms.anthropic.messages.native.agentic_streaming_iterator import ( is_server_fulfilled_tool_leak_error, ) @@ -823,6 +834,7 @@ def _mid_stream_retry_trigger(error: "MidStreamFallbackError") -> Exception: _RestT: Final = TypeVar("_RestT", Iterator[object], AsyncIterator[object]) +_RouteDeploymentsT: Final = TypeVar("_RouteDeploymentsT", bound=Sequence[Mapping[str, object]] | Mapping[str, object]) @dataclass(frozen=True, slots=True) @@ -905,7 +917,7 @@ def _stream_commits_now(chunk: object, has_generated_content: bool, buffered_chu pre-content buffer cap was hit) rather than keep buffering lifecycle frames toward a possible fallback. """ - from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( + from litellm.llms.anthropic.messages.native.streaming_iterator import ( is_anthropic_content_delta_chunk, ) @@ -934,7 +946,7 @@ MAX_HELD_PRE_OUTPUT_RESPONSES_EVENTS: Final = 200 def _retry_policy_ceiling(policy: RetryPolicy) -> int: """The most retries any error class under this policy can be granted.""" - retry_counts: Final[Iterable[object]] = policy.model_dump().values() + retry_counts: Final[tuple[object, ...]] = tuple(policy.model_dump().values()) return max((retries for retries in retry_counts if isinstance(retries, int)), default=0) @@ -1238,6 +1250,7 @@ class Router: fallback_access_check: FallbackAccessCheck | None = None, fallback_budget_check: FallbackBudgetCheck | None = None, auto_router_capability_limit: AutoRouterCapabilityLimit | None = None, + session_affinity_repin_on_failover: bool = False, ) -> None: """ Initialize the Router class with the given parameters for caching, reliability, and routing strategy. @@ -1274,6 +1287,8 @@ class Router: alerting_config (AlertingConfig): Slack alerting configuration. Defaults to None. provider_budget_config (ProviderBudgetConfig): Provider budget configuration. Use this to set llm_provider budget limits. example $100/day to OpenAI, $100/day to Azure, etc. Defaults to None. deployment_affinity_ttl_seconds (int): TTL for user-key -> deployment affinity mapping. Defaults to 3600. + session_affinity_repin_on_failover (bool): After a successful replacement response, move a session pin + whose deployment is in cooldown or removed. Async routes only. Defaults to False. Applied at startup. ignore_invalid_deployments (bool): Ignores invalid deployments, and continues with other deployments. Default is to raise an error. enable_weighted_failover (bool): When True and the routing strategy is "simple-shuffle", a retryable failure on one deployment causes the request to re-pick (weighted) across the other deployments in the same model group before any cross-group fallback runs. Bounded by `max_fallbacks`. Async-only: currently honored by `router.acompletion()` and other async entrypoints. The sync `router.completion()` path falls back to the regular fallback flow. Defaults to False. enable_mid_stream_fallback_continuation (bool): When True, a chat-completions stream that breaks after plain assistant text has been delivered continues on a fallback deployment via assistant prefill instead of surfacing the error. Only deployments whose model supports assistant prefill are eligible, so the partial text is continued, not regenerated; if none is, the original error is surfaced. Streams that emitted tool calls, thinking blocks, audio/images, or constrained (JSON / forced tool_choice) output are never continued. Async-only. Defaults to False. @@ -1428,6 +1443,9 @@ class Router: # Maps (team_id, team_public_model_name) -> list of indices in model_list self.team_model_to_deployment_indices: dict[tuple[str, str], list[int]] = {} self.team_public_model_names: frozenset[str] = frozenset() + # Guards model_list and the three index maps above: writers change them, and readers turn an + # index into a deployment, under it, so a lookup never lands between a removal and its re-index + self._deployment_index_lock = threading.RLock() # Initialize cache attributes that ``_invalidate_model_group_info_cache`` # and ``_invalidate_access_groups_cache`` touch *before* the first @@ -1458,21 +1476,23 @@ class Router: self._provider_unresolved_deployments: tuple[Callable[[], Deployment | None], ...] = () self.deployment_affinity_ttl_seconds = deployment_affinity_ttl_seconds + self.session_affinity_repin_on_failover = session_affinity_repin_on_failover self.model_group_affinity_config = model_group_affinity_config warn_on_unknown_model_group_affinity_flags(model_group_affinity_config) if model_list is not None: # set_model_list will build indices automatically self.set_model_list(model_list) - # Track this router so a price data reload can rebuild its deployments' - # cost-map entries from the list it is serving at that moment. - _live_routers.add(self) self.healthy_deployments: list = self.model_list for m in model_list: if "model" in m["litellm_params"]: self.deployment_latency_map[m["litellm_params"]["model"]] = 0 else: self.model_list: list = [] # initialize an empty list - to allow _add_deployment and delete_deployment to work + # Track this router so a price data reload can rebuild its deployments' + # cost-map entries from the list it is serving at that moment, whether + # those deployments came from model_list or were added later from the DB. + _live_routers.add(self) if allowed_fails is not None: self.allowed_fails = allowed_fails @@ -2167,8 +2187,8 @@ class Router: public_model_name: Final = deployment.model_info.team_public_model_name if team_id is None or public_model_name is None: return False - sibling_indices: Final = self.team_model_to_deployment_indices.get((team_id, public_model_name)) or () - routable_siblings: Final = self._filter_blocked_deployments([self.model_list[idx] for idx in sibling_indices]) + siblings: Final = self._team_deployments_named(team_id, public_model_name) or () + routable_siblings: Final = self._filter_blocked_deployments([dict(sibling) for sibling in siblings]) return len(routable_siblings) > 1 _OVERRIDABLE_ROUTING_STRATEGIES: frozenset[str] = frozenset({"simple-shuffle", *_DEFAULT_SELECTOR_ATTR_BY_STRATEGY}) @@ -2853,6 +2873,7 @@ class Router: enable_session_id_affinity=False, model_group_affinity_config=self.model_group_affinity_config, is_priority_group=self._is_priority_routing_group, + session_affinity_repin_on_failover=self.session_affinity_repin_on_failover, ) self.optional_callbacks.append(affinity_callback) litellm.logging_callback_manager.add_litellm_callback(affinity_callback) @@ -2899,6 +2920,7 @@ class Router: enable_session_id_affinity=enable_session_id_affinity, model_group_affinity_config=self.model_group_affinity_config, is_priority_group=self._is_priority_routing_group, + session_affinity_repin_on_failover=self.session_affinity_repin_on_failover, ) self.optional_callbacks.append(affinity_callback) litellm.logging_callback_manager.add_litellm_callback(affinity_callback) @@ -4783,9 +4805,39 @@ class Router: deployment_litellm_model_name = deployment["litellm_params"]["model"] deployment_api_base = deployment["litellm_params"].get("api_base") deployment_model_name: Final = deployment["model_name"] - if is_clientside_credential(request_kwargs=kwargs): + from litellm.litellm_core_utils.get_provider_specific_headers import ProviderSpecificHeaderUtils + + request_context: Final = cast( # cast-ok: the router's legacy request dict has string keys + Mapping[str, object], kwargs + ) + raw_deployment_params: Final[object] = deployment["litellm_params"] + deployment_context: Final = _LITELLM_PARAMS_ADAPTER.validate_python( + raw_deployment_params.model_dump(exclude_none=True) + if isinstance(raw_deployment_params, LiteLLM_Params) + else raw_deployment_params + ) + declared_provider: Final = deployment_context.get("custom_llm_provider") + declared_model: Final = deployment_context.get("model") + deployment_provider: Final = ( + declared_provider + if isinstance(declared_provider, str) + else inferred_provider(declared_model if isinstance(declared_model, str) else None) + ) + forwarded_authorization: Final = ( + ProviderSpecificHeaderUtils.forwarded_authorization( + request_context.get("provider_specific_header"), deployment_provider + ) + if deployment_provider in _FORWARDED_CREDENTIAL_ISOLATION_PROVIDERS + else None + ) + if is_clientside_credential(request_kwargs=kwargs) or forwarded_authorization is not None: deployment_pydantic_obj: Final = self._handle_clientside_credential( - deployment=deployment, kwargs=kwargs, function_name=function_name + deployment=deployment, + kwargs={ + **kwargs, + **({"api_key": forwarded_authorization} if forwarded_authorization is not None else {}), + }, + function_name=function_name, ) model_info = deployment_pydantic_obj.model_info.model_dump() deployment_litellm_model_name = deployment_pydantic_obj.litellm_params.model @@ -6193,7 +6245,7 @@ class Router: try: parent_otel_span: Final = get_parent_otel_span_from_kwargs(kwargs) try: - with self._video_call_pin(handler_name, kwargs): + with self._video_call_pin(handler_name, kwargs), self._route_capability_pin(handler_name): deployment = await self.async_get_available_deployment( # rebind-ok: set on success, see pre-init model=model, request_kwargs=kwargs, @@ -6255,7 +6307,7 @@ class Router: response=response, kwargs=kwargs, ): - from litellm.llms.anthropic.pass_through.messages.utils import ( + from litellm.llms.anthropic.messages.native.utils import ( safeguard_refusal_error, ) @@ -6372,16 +6424,16 @@ class Router: including pings and provider error frames, is forwarded live and verbatim instead. """ - from litellm.llms.anthropic.pass_through.messages.fake_stream_iterator import ( + from litellm.llms.anthropic.messages.native.fake_stream_iterator import ( FakeAnthropicMessagesStreamIterator, ) - from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( + from litellm.llms.anthropic.messages.native.streaming_iterator import ( aclose_if_supported, aclose_superseded_attempt, parse_anthropic_error_event, parse_anthropic_refusal_stop_details, ) - from litellm.llms.anthropic.pass_through.messages.utils import ( + from litellm.llms.anthropic.messages.native.utils import ( safeguard_refusal_error, ) @@ -6504,7 +6556,7 @@ class Router: has_generated_content: bool, buffered_lifecycle_chunks: tuple[bytes, ...], model: str, - initial_kwargs: dict[str, Any], # mutable-ok: handed to _aanthropic_messages_fallback_attempt, which mutates it + initial_kwargs: dict[str, object], # mutable-ok: _aanthropic_messages_fallback_attempt mutates it wrapper: "FallbackAwareAnthropicMessagesStream", close_superseded: Callable[[], Awaitable[None]], ) -> AsyncGenerator[bytes, None]: @@ -6745,7 +6797,7 @@ class Router: A retry stamps the retry headers async_function_with_retries would have for a pre-stream retry; a later hop the recovered stream makes replaces them with its own, the way a fallback's do. """ - from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( + from litellm.llms.anthropic.messages.native.streaming_iterator import ( aclose_if_supported, anthropic_messages_response_as_sse_events, ) @@ -6921,6 +6973,15 @@ class Router: finally: _video_call_deployment_id.reset(token) + @staticmethod + @contextlib.contextmanager + def _route_capability_pin(handler_name: str | None) -> Generator[None]: + token: Final = _routed_call_type.set(handler_name) + try: + yield + finally: + _routed_call_type.reset(token) + @staticmethod def _narrow_to_video_deployment(healthy_deployments: Sequence[_DeploymentT]) -> Sequence[_DeploymentT]: """ @@ -6954,7 +7015,7 @@ class Router: kwargs=kwargs, metadata_variable_name=metadata_variable_name, ) - with self._video_call_pin(handler_name, kwargs): + with self._video_call_pin(handler_name, kwargs), self._route_capability_pin(handler_name): deployment: Final = self.get_available_deployment( model=model, messages=kwargs.get("messages", None), @@ -9282,6 +9343,12 @@ class Router: if model_group is None or deployment_id is None or self.get_deployment(model_id=str(deployment_id)) is None: return + if self.session_affinity_repin_on_failover: + await self._repin_session_after_success( + _LITELLM_PARAMS_ADAPTER.validate_python(litellm_params), + _OPAQUE_VALUE_ADAPTER.validate_python(completion_response), + ) + # Always track deployment successes for cooldown logic, regardless of TPM/RPM limits increment_deployment_successes_for_current_minute( litellm_router_instance=self, @@ -9305,6 +9372,36 @@ class Router: "litellm.router.Router::deployment_callback_on_success(): Exception occured - %s", e ) + async def _repin_session_after_success(self, litellm_params: Mapping[str, object], response: object) -> None: + if not self.session_affinity_repin_on_failover: + return + try: + from litellm.router_utils.pre_call_checks.deployment_affinity_check import completed_affinity_response + + if not completed_affinity_response(response): + return + callback: Final = next( + (logger for logger in self._optional_loggers() if isinstance(logger, DeploymentAffinityCheck)), + None, + ) + if callback is None: + return + model_group: Final = callback.get_repin_model_group(litellm_params) + if model_group is None or self._is_priority_routing_group(model_group): + return + registered_ids: Final = self.get_candidate_model_ids_for_route( + model=model_group, team_id=get_request_team_id(litellm_params) + ) + cooldown_ids: Final = frozenset( + model_id + for model_id, _ in await self.cooldown_cache.async_get_active_cooldowns( + model_ids=list(registered_ids), parent_otel_span=None + ) + ) + await callback.async_repin_session_after_success(litellm_params, model_group, registered_ids - cooldown_ids) + except Exception as error: # noqa: BLE001 # Optional pin updates must not interrupt success accounting + verbose_router_logger.debug("Session re-pinning failed: %s", error) + async def increment_deployment_usage_for_response( self, response: object, @@ -9834,7 +9931,7 @@ class Router: when a content-policy fallback is configured; a plain refusal without stop_details, or any response with nothing configured, is returned to the client unchanged. """ - from litellm.llms.anthropic.pass_through.messages.utils import ( + from litellm.llms.anthropic.messages.native.utils import ( get_safeguard_refusal_stop_details, ) @@ -10767,20 +10864,17 @@ class Router: # O(k) via the name→indices map: only touch deployments whose name # is listed in `available_models`, instead of scanning model_list. for name in config.available_models: - indices = self.model_name_to_deployment_indices.get(name, []) - if not indices: + deployments = self.deployments_named(name) + if not deployments: continue - d = (self.model_list or [])[indices[0]] - mi = d.get("model_info") if isinstance(d, dict) else d.model_info - mi_dict: dict[str, Any] = mi if isinstance(mi, dict) else (mi.model_dump() if mi else {}) + d = deployments[0] + mi_dict: dict[str, Any] = d.get("model_info") or {} prefs_raw = mi_dict.get("adaptive_router_preferences") if prefs_raw is not None: model_to_prefs[name] = AdaptiveRouterPreferences(**prefs_raw) # model_info is the conventional pricing location elsewhere in LiteLLM; litellm_params wins if set. - lp = d.get("litellm_params") if isinstance(d, dict) else d.litellm_params - lp_dict: dict[str, Any] = lp if isinstance(lp, dict) else (lp.model_dump() if lp else {}) - cost = lp_dict.get("input_cost_per_token") + cost = d.get("litellm_params", {}).get("input_cost_per_token") if cost is None: cost = mi_dict.get("input_cost_per_token") if cost is not None: @@ -10872,10 +10966,11 @@ class Router: def set_model_list(self, model_list: list): original_model_list: Final = copy.deepcopy(model_list) self._discovered_model_info_cache.flush_cache() - self.model_list = [] - self.model_id_to_deployment_index_map = {} # Reset the index - self.model_name_to_deployment_indices = {} # Reset the model_name index - self.team_model_to_deployment_indices = {} # Reset the team_model index + with self._deployment_index_lock: + self.model_list = [] + self.model_id_to_deployment_index_map = {} # Reset the index + self.model_name_to_deployment_indices = {} # Reset the model_name index + self.team_model_to_deployment_indices = {} # Reset the team_model index self.team_pattern_routers = {} self.team_public_model_names = frozenset() # Reset per-strategy router registries so hot-reload doesn't leave @@ -10987,6 +11082,10 @@ class Router: custom_llm_provider = None dynamic_api_key = None api_base = None + elif declared_authenticating_provider(litellm_model, deployment.litellm_params.custom_llm_provider) is not None: + _model, custom_llm_provider = ( # rebind-ok: each branch resolves the deployment provider + self._model_group_llm_provider(deployment.litellm_params) + ) else: # check if model provider in supported providers ( @@ -11266,26 +11365,27 @@ class Router: - model: dict - the model to add to the list - model_id: Optional[str] - the model ID to use for indexing. If None, will try to get from model["model_info"]["id"] """ - idx: Final = len(self.model_list) - self.model_list.append(model) - self._invalidate_model_group_info_cache() - self._invalidate_access_groups_cache() + with self._deployment_index_lock: + idx: Final = len(self.model_list) + self.model_list.append(model) + self._invalidate_model_group_info_cache() + self._invalidate_access_groups_cache() - # Update model_id index for O(1) lookup - if model_id is not None: - self.model_id_to_deployment_index_map[model_id] = idx - elif model.get("model_info", {}).get("id") is not None: - self.model_id_to_deployment_index_map[model["model_info"]["id"]] = idx + # Update model_id index for O(1) lookup + if model_id is not None: + self.model_id_to_deployment_index_map[model_id] = idx + elif model.get("model_info", {}).get("id") is not None: + self.model_id_to_deployment_index_map[model["model_info"]["id"]] = idx - # Update model_name index for O(1) lookup - model_name: Final = model.get("model_name") - if model_name: - if model_name not in self.model_name_to_deployment_indices: - self.model_name_to_deployment_indices[model_name] = [] - self.model_name_to_deployment_indices[model_name].append(idx) + # Update model_name index for O(1) lookup + model_name: Final = model.get("model_name") + if model_name: + if model_name not in self.model_name_to_deployment_indices: + self.model_name_to_deployment_indices[model_name] = [] + self.model_name_to_deployment_indices[model_name].append(idx) - # Update team_model index for O(1) team-scoped lookup - self._update_team_model_index(model, idx) + # Update team_model index for O(1) team-scoped lookup + self._update_team_model_index(model, idx) def upsert_deployment(self, deployment: Deployment) -> Deployment | None: """ @@ -11312,18 +11412,15 @@ class Router: # if there is a new litellm param -> then update the deployment # remove the previous deployment - removal_idx: int | None = None - deployment_id: Final = deployment.model_info.id - deployment_fast_mapping: Final = self.model_id_to_deployment_index_map - - if deployment_id in deployment_fast_mapping: - removal_idx = deployment_fast_mapping[deployment_id] - + with self._deployment_index_lock: + removal_idx: Final = self.model_id_to_deployment_index_map.get(_deployment_model_id) if removal_idx is not None: self.model_list.pop(removal_idx) self._invalidate_model_group_info_cache() self._invalidate_access_groups_cache() - self._update_deployment_indices_after_removal(model_id=deployment_id, removal_idx=removal_idx) + self._update_deployment_indices_after_removal( + model_id=_deployment_model_id, removal_idx=removal_idx + ) # Free the outgoing deployment's pre-routing strategy slot (keyed by the # OLD model_name/tags) before the re-add below re-registers it. @@ -11557,35 +11654,32 @@ class Router: - The deleted deployment - OR None (if deleted deployment not found) """ - deployment_idx = None - if id in self.model_id_to_deployment_index_map: - deployment_idx = self.model_id_to_deployment_index_map[id] - try: - if deployment_idx is not None: + with self._deployment_index_lock: + deployment_idx: Final = self.model_id_to_deployment_index_map.get(id) + if deployment_idx is None: + return None # Pop the item from the list first item: Final = self.model_list.pop(deployment_idx) self._invalidate_model_group_info_cache() self._invalidate_access_groups_cache() self._update_deployment_indices_after_removal(model_id=id, removal_idx=deployment_idx) - _budget_limiter: Final = self.get_router_deployment_budget_limiter() - if _budget_limiter is not None: - _budget_limiter.unregister_deployment_budget(model_id=id) - try: - self._unregister_pre_routing_strategy_for_deployment( - deployment=item if isinstance(item, Deployment) else Deployment(**item) - ) - except Exception: - verbose_router_logger.exception( - "delete_deployment: could not release pre-routing strategies for model_id=%s; " - "the deployment is out of the model_list and its indices are repaired", - id, - ) - return item - else: - return None + _budget_limiter: Final = self.get_router_deployment_budget_limiter() + if _budget_limiter is not None: + _budget_limiter.unregister_deployment_budget(model_id=id) + try: + self._unregister_pre_routing_strategy_for_deployment( + deployment=item if isinstance(item, Deployment) else Deployment(**item) + ) + except Exception: + verbose_router_logger.exception( + "delete_deployment: could not release pre-routing strategies for model_id=%s; " + "the deployment is out of the model_list and its indices are repaired", + id, + ) except Exception: return None + return item def get_router_deployment_budget_limiter( self, @@ -11634,6 +11728,18 @@ class Router: if _budget_limiter is not None: _budget_limiter.register_deployment_budget(deployment=deployment.to_json(exclude_none=True)) + def deployments_named(self, model_name: str) -> tuple[DeploymentTypedDict, ...] | None: + """The deployments indexed under `model_name`, read under the index lock, or None when the name is not indexed.""" + with self._deployment_index_lock: + indices: Final = self.model_name_to_deployment_indices.get(model_name) + return None if indices is None else tuple(self.model_list[idx] for idx in indices) + + def _team_deployments_named(self, team_id: str, public_model_name: str) -> tuple[DeploymentTypedDict, ...] | None: + """The deployments `team_id` serves under `public_model_name`, or None when that pair is not indexed.""" + with self._deployment_index_lock: + indices: Final = self.team_model_to_deployment_indices.get((team_id, public_model_name)) + return None if indices is None else tuple(self.model_list[idx] for idx in indices) + def get_deployment(self, model_id: str) -> Deployment | None: """ Returns -> Deployment or None @@ -11641,9 +11747,10 @@ class Router: Raise Exception -> if model found in invalid format """ # Use O(1) lookup via model_id_to_deployment_index_map only - if model_id in self.model_id_to_deployment_index_map: - idx: Final = self.model_id_to_deployment_index_map[model_id] - model: Final = self.model_list[idx] + with self._deployment_index_lock: + idx: Final = self.model_id_to_deployment_index_map.get(model_id) + model: Final = None if idx is None else self.model_list[idx] + if model is not None: if isinstance(model, dict): return Deployment(**model) elif isinstance(model, Deployment): @@ -11677,17 +11784,17 @@ class Router: Optimized with O(1) index lookup instead of O(n) linear scan. """ # O(1) lookup in model_name index - if model_group_name in self.model_name_to_deployment_indices: - indices: Final = self.model_name_to_deployment_indices[model_group_name] - if indices: - # Return first deployment for this model_name - model: Final = self.model_list[indices[0]] - if isinstance(model, dict): - return Deployment(**model) - elif isinstance(model, Deployment): - return model - else: - raise Exception(f"Model Name invalid - {type(model)}") + with self._deployment_index_lock: + indices: Final = self.model_name_to_deployment_indices.get(model_group_name) + # Return first deployment for this model_name + model: Final = self.model_list[indices[0]] if indices else None + if model is not None: + if isinstance(model, dict): + return Deployment(**model) + elif isinstance(model, Deployment): + return model + else: + raise Exception(f"Model Name invalid - {type(model)}") return None @staticmethod @@ -11710,11 +11817,12 @@ class Router: by other teams so a shared model name never resolves another team's credentials. """ - indices: Final = self.model_name_to_deployment_indices.get(model_group_name) or () - usable: Final = ( - self.model_list[idx] for idx in indices if self.deployment_usable_by_team(self.model_list[idx], team_id) - ) - first_usable: Final = next(usable, None) + with self._deployment_index_lock: + indices: Final = self.model_name_to_deployment_indices.get(model_group_name) or () + usable: Final = ( + self.model_list[idx] for idx in indices if self.deployment_usable_by_team(self.model_list[idx], team_id) + ) + first_usable: Final = next(usable, None) if first_usable is None: return None return Deployment(**first_usable) if isinstance(first_usable, dict) else first_usable @@ -11817,11 +11925,10 @@ class Router: this never triggers pattern matching or deep copies, so it is safe to call per listed model on the /v1/models hot path. """ - indices: Final = self.model_name_to_deployment_indices.get(model_name) - if not indices: + deployments: Final = self.deployments_named(model_name) + if not deployments: return None - deployments: Final = tuple(self.model_list[index] for index in indices) model_infos: Final = tuple( MappingProxyType( { @@ -11994,10 +12101,11 @@ class Router: def _get_team_public_name_deployment(self, model_id: str, team_id: str | None) -> Deployment | None: if team_id is None: return None - team_indices: Final = self.team_model_to_deployment_indices.get((team_id, model_id)) - if not team_indices: + with self._deployment_index_lock: + team_indices: Final = self.team_model_to_deployment_indices.get((team_id, model_id)) + team_model: Final = self.model_list[team_indices[0]] if team_indices else None + if team_model is None: return None - team_model: Final = self.model_list[team_indices[0]] return Deployment(**team_model) if isinstance(team_model, dict) else team_model def _get_wildcard_deployment_usable_by_team(self, model_id: str, team_id: str | None) -> Deployment | None: @@ -12157,7 +12265,6 @@ class Router: _fallback_entry = litellm.model_cost.get(_azure_fallback_key) _fallback_resolves = _fallback_entry is not None and ( (_fallback_entry.get("max_input_tokens") or 0) > 0 - or (_fallback_entry.get("max_tokens") or 0) > 0 or (_fallback_entry.get("input_cost_per_token") or 0) > 0 ) if _fallback_resolves: @@ -12236,10 +12343,9 @@ class Router: Optimized with O(1) index lookup instead of O(n) linear scan. """ # O(1) lookup via model_id_to_deployment_index_map - if id in self.model_id_to_deployment_index_map: - idx: Final = self.model_id_to_deployment_index_map[id] - return self.model_list[idx] - return None + with self._deployment_index_lock: + idx: Final = self.model_id_to_deployment_index_map.get(id) + return None if idx is None else self.model_list[idx] def get_model_group(self, id: str) -> list | None: """ @@ -12332,6 +12438,17 @@ class Router: ) return model_info + @staticmethod + def _model_group_llm_provider(litellm_params: LiteLLM_Params) -> tuple[str, str]: + try: + return resolve_model_and_provider_for_metadata( + model=litellm_params.model, + custom_llm_provider=litellm_params.custom_llm_provider, + ) + except litellm.exceptions.BadRequestError as e: + verbose_router_logger.error("litellm.router.py::get_model_group_info() - %s", e) + return "", "" + def _set_model_group_info( self, model_group: str, user_facing_model_group_name: str, team_id: str | None = None ) -> ModelGroupInfo | None: @@ -12420,15 +12537,7 @@ class Router: deployment_is_mapped = deployment_is_catalog_mapped(model_info, model_info_dict) # get llm provider - litellm_model, llm_provider = "", "" - try: - litellm_model, llm_provider, _, _ = litellm.get_llm_provider( - model=litellm_params.model, - custom_llm_provider=litellm_params.custom_llm_provider, - litellm_params=litellm_params, - ) - except litellm.exceptions.BadRequestError as e: - verbose_router_logger.error("litellm.router.py::get_model_group_info() - %s", e) + litellm_model, llm_provider = self._model_group_llm_provider(litellm_params) if model_info is None: supported_openai_params = litellm.get_supported_openai_params( @@ -12909,20 +13018,19 @@ class Router: if model_name is not None: # O(1) lookup in model_name index, then O(k) iteration where k = deployments for this model_name - if model_name in self.model_name_to_deployment_indices: - indices: Final = self.model_name_to_deployment_indices[model_name] - for idx in indices: - model = self.model_list[idx] - if "model_info" in model and "id" in model["model_info"]: - if exclude_team_models and model["model_info"].get("team_id"): - continue - ids.append(model["model_info"]["id"]) + for model in self.deployments_named(model_name) or (): + if "model_info" in model and "id" in model["model_info"]: + if exclude_team_models and model["model_info"].get("team_id"): + continue + ids.append(model["model_info"]["id"]) else: # When model_name is None, return all model IDs # Use the index map keys for O(n) where n = total deployments - for model_id in self.model_id_to_deployment_index_map: - idx = self.model_id_to_deployment_index_map[model_id] - model = self.model_list[idx] + with self._deployment_index_lock: + id_indices: Final = tuple(self.model_id_to_deployment_index_map.items()) + models: Final = tuple(self.model_list) + for model_id, idx in id_indices: + model = models[idx] if "model_info" in model and "id" in model["model_info"]: if exclude_team_models and model["model_info"].get("team_id"): continue @@ -13028,6 +13136,7 @@ class Router: healthy_deployments=remaining, request_kwargs=tag_request, metadata_variable_name=metadata_variable_name, + request_deployments=request_deployments, ) except ValueError: # tag routing sends this request to none of the rest break @@ -13200,7 +13309,9 @@ class Router: # handled downstream by the pattern_router in _common_checks_available_deployment. return None - def should_include_deployment(self, model_name: str, model: dict, team_id: str | None = None) -> bool: + def should_include_deployment( + self, model_name: str, model: DeploymentTypedDict | dict, team_id: str | None = None + ) -> bool: """ Get the team-specific model name if team_id matches the deployment. """ @@ -13248,12 +13359,10 @@ class Router: # O(1) lookup in team_model index when team_id is provided if team_id is not None: - key: Final = (team_id, model_name) - if key in self.team_model_to_deployment_indices: - indices = self.team_model_to_deployment_indices[key] + team_models: Final = self._team_deployments_named(team_id, model_name) + if team_models is not None: # O(k) where k = team deployments for this model_name (typically 1-10) - for idx in indices: - model = self.model_list[idx] + for model in team_models: if not self.should_include_deployment(model_name=model_name, model=model, team_id=team_id): continue if model_alias is not None: @@ -13266,12 +13375,10 @@ class Router: return returned_models # O(1) lookup in model_name index - if model_name in self.model_name_to_deployment_indices: - indices = self.model_name_to_deployment_indices[model_name] - + named_models: Final = self.deployments_named(model_name) + if named_models is not None: # O(k) where k = deployments for this model_name (typically 1-10) - for idx in indices: - model = self.model_list[idx] + for model in named_models: if self.should_include_deployment(model_name=model_name, model=model, team_id=team_id): if model_alias is not None: # Optimized: Use shallow copy since we only modify top-level model_name @@ -13285,7 +13392,7 @@ class Router: # Fallback: if team_id is provided and model_name not in index, # check if model_name matches any team_public_model_name # O(n) scan but only when team_id lookup fails - for idx, model in enumerate(self.model_list): + for _idx, model in enumerate(self.model_list): if self.should_include_deployment(model_name=model_name, model=model, team_id=team_id): if model_alias is not None: # Optimized: Use shallow copy since we only modify top-level model_name @@ -13683,21 +13790,21 @@ class Router: return [{**DeploymentTypedDict(**m), "model_name": model_name} for m in matches] def wildcard_route_deployments(self, model: str, team_id: str | None) -> Sequence[Mapping[str, object]]: - """The deployments routing serves ``model`` from through a wildcard: the most specific - proxy-wide pattern matching it, else ``team_id``'s own pattern, never both.""" - proxy_wide: Final[Sequence[Mapping[str, object]]] = self.pattern_router.get_deployments_by_pattern(model=model) + """The deployments routing serves ``model`` from through a wildcard: ``team_id``'s own pattern + matching it, else the most specific proxy-wide pattern, never both.""" team_router: Final = self.team_pattern_routers.get(team_id) if team_id is not None else None - if proxy_wide or team_router is None: - return proxy_wide - return team_router.get_deployments_by_pattern(model=model) + team_owned: Final[Sequence[Mapping[str, object]]] = ( + team_router.get_deployments_by_pattern(model=model) if team_router is not None else () + ) + return team_owned or self.pattern_router.get_deployments_by_pattern(model=model) def wildcard_routed_models(self, model: str, team_id: str | None) -> frozenset[str]: """The models wildcard_route_deployments would route ``model`` to, without copying the deployments.""" - proxy_wide: Final = self.pattern_router.get_models_by_pattern(model=model) team_router: Final = self.team_pattern_routers.get(team_id) if team_id is not None else None - if proxy_wide or team_router is None: - return proxy_wide - return team_router.get_models_by_pattern(model=model) + team_owned: Final = ( + team_router.get_models_by_pattern(model=model) if team_router is not None else frozenset[str]() + ) + return team_owned or self.pattern_router.get_models_by_pattern(model=model) def team_ptu_ceiling(self, team_id: str, model_group: str) -> PTUTeamCeiling | None: """The per-minute ceiling ``team_id``'s PTU shares set on the group serving ``model_group``, @@ -14041,7 +14148,7 @@ class Router: `tools` (Chat Completions, Responses and Anthropic Messages shapes) and the Anthropic Messages top-level `system` block. """ - from litellm.llms.anthropic.pass_through.messages.utils import ( + from litellm.llms.anthropic.messages.native.utils import ( anthropic_system_to_openai_message, ) @@ -14186,6 +14293,113 @@ class Router: deployment, group, Router._params_neither_dropped_nor_allowed(call_settings, params) ) + @staticmethod + def _deployment_declares_no_vision(deployment: DeploymentTypedDict, group: str) -> bool: + plain_deployment: Final = cast(Mapping[str, object], deployment) # cast-ok: router deployments are plain dicts + model_info: Final = cast(Mapping[str, object], plain_deployment.get("model_info") or {}) # cast-ok: plain dict + declared: Final = model_info.get("supports_vision") + if declared is not None: + return declared is False + raw_params: Final = plain_deployment.get("litellm_params") or {} + params: Final = cast(Mapping[str, object], raw_params) # cast-ok: router deployments are plain dicts + if not params: + return False + base_model: Final = model_info.get("base_model") or params.get("base_model") + try: + model, custom_llm_provider = Router._capability_model_and_provider(deployment["litellm_params"], group) + return litellm.utils.is_vision_explicitly_disabled( + base_model if isinstance(base_model, str) else model, custom_llm_provider + ) + except Exception as e: # noqa: BLE001 # best-effort filter: an unresolvable provider must not narrow the request + verbose_router_logger.debug( + "litellm.router.py::_deployment_declares_no_vision: keeping deployment for model=%s. Got - %s", group, e + ) + return False + + @staticmethod + def _deployment_serves_route( + deployment: DeploymentTypedDict, + group: str, + resolver: Callable[[str, LlmProviders], object | None], + ) -> bool: + if "litellm_params" not in deployment: + return True + + try: + model, resolved_custom_llm_provider = Router._capability_model_and_provider( + deployment["litellm_params"], group + ) + provider: Final = next( + (member for member in LlmProviders if member.value == resolved_custom_llm_provider), + None, + ) + return provider is not None and resolver(model, provider) is not None + except Exception as e: # noqa: BLE001 # best-effort capability filter + verbose_router_logger.debug( + "litellm.router.py::_deployment_serves_route: keeping deployment for model=%s. Got - %s", group, e + ) + return True + + @staticmethod + def _without_deployments_that_cannot_serve_route( + healthy_deployments: _RouteDeploymentsT, group: str + ) -> _RouteDeploymentsT: + handler_name: Final = _routed_call_type.get() + resolver: Final = _ROUTE_CAPABILITY_RESOLVERS.get(handler_name) if handler_name is not None else None + if resolver is None or isinstance(healthy_deployments, Mapping): + return healthy_deployments + + filtered_deployments: Final = [ + deployment + for deployment in healthy_deployments + if Router._deployment_serves_route( + cast(DeploymentTypedDict, deployment), # cast-ok: router candidates use the deployment shape + group, + resolver, + ) + ] + if not filtered_deployments: + return healthy_deployments + return cast(_RouteDeploymentsT, filtered_deployments) # cast-ok: same list shape as the input candidates + + @staticmethod + def _without_declared_text_only_deployments( + healthy_deployments: _RouteDeploymentsT, + group: str, + messages: list[dict[str, str]] | None, # mutable-ok: handed to _request_carries_image as-is + request_kwargs: Mapping[str, object] | None, + ) -> _RouteDeploymentsT: + if isinstance(healthy_deployments, Mapping) or not Router._request_carries_image( + messages, request_kwargs or {} + ): + return healthy_deployments + + vision_capable_deployments: Final = [ + deployment + for deployment in healthy_deployments + if not Router._deployment_declares_no_vision( + cast(DeploymentTypedDict, deployment), # cast-ok: router candidates use the deployment shape + group, + ) + ] + if not vision_capable_deployments: + return healthy_deployments + return cast(_RouteDeploymentsT, vision_capable_deployments) # cast-ok: same list shape as the input candidates + + @staticmethod + def _request_carries_image( + messages: list[dict[str, str]] | None, # mutable-ok: handed to resolve_structured_messages as-is + request_kwargs: Mapping[str, object], + ) -> bool: + from litellm.litellm_core_utils.prompt_templates.common_utils import request_contains_image_content + from litellm.litellm_core_utils.prompt_templates.factory import resolve_structured_messages + + structured: Final = resolve_structured_messages( + messages=cast(list[dict[str, object]] | None, messages), # cast-ok: chat messages are plain dicts + request_kwargs=cast(dict[str, object], request_kwargs), # cast-ok: the resolver only reads the mapping + ) + return bool(structured) and request_contains_image_content(structured) + @staticmethod def _pre_call_check_requested_chat_params(request_kwargs: Mapping[str, object]) -> frozenset[str]: requested: Final = litellm.utils.get_non_default_params(passed_params=dict(request_kwargs)) @@ -14221,7 +14435,7 @@ class Router: # We only pop from the list, not modify deployment dicts - 100x+ faster on hot path (every request) _returned_deployments = list(healthy_deployments) - invalid_model_indices: Final = set() # Use set for O(1) membership checks + invalid_model_indices: Final = set[int]() # Use set for O(1) membership checks _context_window_error = False _potential_error_str = "" @@ -14443,12 +14657,13 @@ class Router: def _team_deployments_across_teams(self, model: str) -> list[DeploymentTypedDict]: """Every team's deployments under public name `model`, for a proxy admin calling without a team.""" - team_deployments: Final = [ - self.model_list[index] - for (_, public_model_name), indices in self.team_model_to_deployment_indices.items() - if public_model_name == model - for index in indices - ] + with self._deployment_index_lock: + team_deployments: Final = [ + self.model_list[index] + for (_, public_model_name), indices in self.team_model_to_deployment_indices.items() + if public_model_name == model + for index in indices + ] team_ids: Final = { team_id for deployment in team_deployments @@ -14796,6 +15011,13 @@ class Router: if verbose_router_logger.isEnabledFor(logging.DEBUG): verbose_router_logger.debug("healthy_deployments after web search filter: %s", healthy_deployments) + healthy_deployments = ( # pyright: ignore[reportUnknownVariableType] # rebind-ok: route filter narrows + self._without_deployments_that_cannot_serve_route( + healthy_deployments, # pyright: ignore[reportUnknownArgumentType] # legacy selector type + model, + ) + ) + if isinstance(healthy_deployments, dict): if (healthy_deployments.get("model_info") or {}).get("blocked") is True: raise litellm.ServiceUnavailableError( @@ -14810,10 +15032,12 @@ class Router: ) # Health-check-based filtering (before cooldown) - healthy_deployments = await self._async_filter_health_check_unhealthy_deployments( - healthy_deployments=healthy_deployments, - parent_otel_span=parent_otel_span, - health_check_probe=health_check_probe, + healthy_deployments = ( # rebind-ok: filtered candidates enter health checks + await self._async_filter_health_check_unhealthy_deployments( + healthy_deployments=healthy_deployments, + parent_otel_span=parent_otel_span, + health_check_probe=health_check_probe, + ) ) routing_read_batch: Final = RoutingReadBatch.active() @@ -14877,6 +15101,7 @@ class Router: request_kwargs=request_kwargs, healthy_deployments=healthy_deployments, metadata_variable_name=self._get_metadata_variable_name_from_kwargs(request_kwargs), + request_deployments=request_deployments, ) # narrow to whatever `self.routing_plugins` left in candidate_models @@ -14887,8 +15112,11 @@ class Router: ## ORDER FILTERING ## -> if user set 'order' in deployments, return deployments with lowest order (e.g. order=1 > order=2) _target_order: Final = (request_kwargs or {}).pop("_target_order", None) - batch_candidates: Final = cast( # cast-ok: router deployments are plain dicts - list[dict[str, object]], healthy_deployments + batch_candidates: Final = self._without_declared_text_only_deployments( + cast(list[dict[str, object]], healthy_deployments), # cast-ok: router deployments are plain dicts + model, + messages, + cast(Mapping[str, object] | None, request_kwargs), # cast-ok: legacy signature uses a bare dict ) embedding_batch_admitting: Final = deployments_admitting_embedding_batch( batch_candidates, @@ -16064,6 +16292,12 @@ class Router: specific_deployment=specific_deployment, request_kwargs=request_kwargs, ) + healthy_deployments = ( # pyright: ignore[reportUnknownVariableType] # rebind-ok: route filter narrows + self._without_deployments_that_cannot_serve_route( + healthy_deployments, # pyright: ignore[reportUnknownArgumentType] # legacy selector type + model, + ) + ) strategy, strategy_selector = self._get_routing_context(model, request_kwargs) routing_kwargs: Final = _ROUTING_KWARGS_ADAPTER.validate_python(request_kwargs) pick_attributes: Final = _deployment_pick_attributes(model, routing_kwargs) @@ -16121,8 +16355,11 @@ class Router: ## ORDER FILTERING ## -> if user set 'order' in deployments, return deployments with lowest order (e.g. order=1 > order=2) _target_order: Final = (request_kwargs or {}).pop("_target_order", None) - batch_candidates: Final = cast( # cast-ok: router deployments are plain dicts - list[dict[str, object]], healthy_deployments + batch_candidates: Final = self._without_declared_text_only_deployments( + cast(list[dict[str, object]], healthy_deployments), # cast-ok: router deployments are plain dicts + model, + messages, + cast(Mapping[str, object] | None, request_kwargs), # cast-ok: legacy signature uses a bare dict ) embedding_batch_admitting: Final = deployments_admitting_embedding_batch( batch_candidates, diff --git a/litellm/router_strategy/complexity_router/complexity_router.py b/litellm/router_strategy/complexity_router/complexity_router.py index a475358e1f0..12968bf7d4a 100644 --- a/litellm/router_strategy/complexity_router/complexity_router.py +++ b/litellm/router_strategy/complexity_router/complexity_router.py @@ -28,7 +28,7 @@ from threading import Lock from types import MappingProxyType from typing import TYPE_CHECKING, Any, Final, Literal, NamedTuple, cast -from pydantic import BaseModel, TypeAdapter, ValidationError, create_model +from pydantic import BaseModel, Field, TypeAdapter, ValidationError, create_model from pydantic_core import ErrorDetails from typing_extensions import ReadOnly, TypedDict @@ -773,6 +773,56 @@ def _newest_turn_is_human_ask( return _last_human_ask_index(messages, marker_pairs) == newest_activity +_CODEX_TURN_METADATA_KEY: Final = "x-codex-turn-metadata" +_CODEX_COMPACTION_SUMMARY_PREFIX: Final = ( + "Another language model started to solve this problem and produced a summary of its thinking process." +) + + +class _CodexTurnMetadata(BaseModel, frozen=True): + request_kind: str | None = None + + +class _CodexTurnMetadataCarrier(BaseModel, frozen=True): + turn_metadata: str | None = Field(default=None, alias=_CODEX_TURN_METADATA_KEY) + + +class _CodexProxyRequest(BaseModel, frozen=True): + headers: _CodexTurnMetadataCarrier | None = None + + +class _CodexRequestMetadata(BaseModel, frozen=True): + """Codex sends its turn metadata in the Responses body's `client_metadata` and projects it onto a + header of the same name for transports without that field""" + + client_metadata: _CodexTurnMetadataCarrier | None = None + proxy_server_request: _CodexProxyRequest | None = None + + def turn_metadata_values(self) -> tuple[str | None, ...]: + headers: Final = self.proxy_server_request.headers if self.proxy_server_request else None + return ( + self.client_metadata.turn_metadata if self.client_metadata else None, + headers.turn_metadata if headers else None, + ) + + +def _codex_request_kind(value: str | None) -> str | None: + if value is None: + return None + try: + return _CodexTurnMetadata.model_validate_json(value).request_kind + except ValidationError: + return None + + +def _is_codex_compaction_request(request_kwargs: Mapping[str, object]) -> bool: + try: + request_metadata: Final = _CodexRequestMetadata.model_validate(request_kwargs) + except ValidationError: + return False + return any(_codex_request_kind(value) == "compaction" for value in request_metadata.turn_metadata_values()) + + def _iter_system_scope_texts( body_system: object, messages: Sequence[Mapping[str, object]], @@ -787,10 +837,9 @@ def _iter_system_scope_texts( must go through the staleness-aware tail scan instead -- scanning it here would floor every turn of a session that once planned, for any pattern whose client injects mid-conversation. """ - if isinstance(body_system, str): - yield body_system - elif isinstance(body_system, list): - yield _message_text(body_system) + body_system_text: Final = _message_text(body_system) + if body_system_text: + yield body_system_text for msg in messages: if msg.get("role") != "system": return @@ -3126,17 +3175,14 @@ class ComplexityRouter(CustomLogger): model_to_prefs: Final[dict[str, AdaptiveRouterPreferences]] = {} model_to_cost: Final[dict[str, float]] = {} - model_list: Final = getattr(self.litellm_router_instance, "model_list", None) or [] - name_to_indices: Final = getattr(self.litellm_router_instance, "model_name_to_deployment_indices", {}) or {} for name in available_models: - indices = name_to_indices.get(name, []) - if not indices: + deployments = self.litellm_router_instance.deployments_named(name) + if not deployments: model_to_prefs[name] = AdaptiveRouterPreferences(quality_tier=2, strengths=[]) model_to_cost[name] = 0.0 continue - deployment = model_list[indices[0]] - mi = deployment.get("model_info") if isinstance(deployment, dict) else deployment.model_info - mi_dict: dict[str, Any] = mi if isinstance(mi, dict) else (mi.model_dump() if mi else {}) + deployment = deployments[0] + mi_dict: dict[str, Any] = deployment.get("model_info") or {} prefs_raw = mi_dict.get("adaptive_router_preferences") if prefs_raw is not None: model_to_prefs[name] = AdaptiveRouterPreferences(**prefs_raw) @@ -3144,9 +3190,7 @@ class ComplexityRouter(CustomLogger): model_to_prefs[name] = AdaptiveRouterPreferences(quality_tier=2, strengths=[]) # model_info is the conventional pricing location elsewhere in LiteLLM; litellm_params wins if set. - lp = deployment.get("litellm_params") if isinstance(deployment, dict) else deployment.litellm_params - lp_dict: dict[str, Any] = lp if isinstance(lp, dict) else (lp.model_dump() if lp else {}) - cost = lp_dict.get("input_cost_per_token") + cost = deployment.get("litellm_params", {}).get("input_cost_per_token") if cost is None: cost = mi_dict.get("input_cost_per_token") model_to_cost[name] = float(cost) if cost is not None else 0.0 @@ -4268,14 +4312,31 @@ class ComplexityRouter(CustomLogger): def _reminder_markers_for_request(self, request_kwargs: Mapping[str, object]) -> tuple[tuple[str, str], ...]: if self.config.reminder_markers is not None: return self._reminder_markers - if any( + return _CODEX_REMINDER_MARKERS if self._is_codex_request(request_kwargs) else _DEFAULT_REMINDER_MARKERS + + @staticmethod + def _is_codex_request(request_kwargs: Mapping[str, object]) -> bool: + return any( is_codex_user_agent(user_agent) for metadata_key in ("litellm_metadata", "metadata") if isinstance(metadata := request_kwargs.get(metadata_key), Mapping) if isinstance(user_agent := metadata.get("user_agent"), str) - ): - return _CODEX_REMINDER_MARKERS - return _DEFAULT_REMINDER_MARKERS + ) + + def _is_codex_compaction_lifecycle( + self, + request_kwargs: Mapping[str, object], + resolved_messages: Sequence[Mapping[str, object]] | None, + marker_pairs: tuple[tuple[str, str], ...], + ) -> bool: + """Codex's compaction call and the first request after it carry a synthetic user turn (the + summarization prompt, then the summary), so `user_turn` must read both as continuations.""" + if _is_codex_compaction_request(request_kwargs): + return True + if not resolved_messages or not self._is_codex_request(request_kwargs): + return False + newest_ask: Final = _newest_turn_ask(resolved_messages, marker_pairs) + return newest_ask is not None and newest_ask.startswith(_CODEX_COMPACTION_SUMMARY_PREFIX) @staticmethod def _iter_metadata_dicts(request_kwargs: dict) -> list[dict]: @@ -4385,15 +4446,22 @@ class ComplexityRouter(CustomLogger): # In 'user_turn' mode a held pin is replayed only on continuation turns; a new human # ask falls through and re-classifies. session_affinity restores pin-first for asks too. - pin_replay_allowed: Final = bool(self.config.session_affinity) or not _newest_turn_is_human_ask( - resolved_messages, marker_pairs + codex_compaction: Final = self._is_codex_compaction_lifecycle(request_kwargs, resolved_messages, marker_pairs) + pin_replay_allowed: Final = ( + bool(self.config.session_affinity) + or not _newest_turn_is_human_ask(resolved_messages, marker_pairs) + or codex_compaction ) if cache_key is not None and pin_replay_allowed: pinned_value: Final = await self.litellm_router_instance.cache.async_get_cache(key=cache_key) pinned_pin: Final = _parse_session_affinity_pin(pinned_value, self.config.tier_names()) if pinned_pin is not None: - user_message: Final = _newest_turn_ask(resolved_messages, marker_pairs) if resolved_messages else None + user_message: Final = ( + _newest_turn_ask(resolved_messages, marker_pairs) + if resolved_messages and not codex_compaction + else None + ) pin_escalation_keyword: Final = ( self._matched_escalation_keyword(user_message) if user_message is not None else None ) diff --git a/litellm/router_strategy/complexity_router/config.py b/litellm/router_strategy/complexity_router/config.py index 4a2c56daf00..ec960a19f79 100644 --- a/litellm/router_strategy/complexity_router/config.py +++ b/litellm/router_strategy/complexity_router/config.py @@ -7,12 +7,12 @@ All values are configurable via proxy config.yaml. import math import re -import warnings +import sys from collections.abc import Iterable, Mapping from dataclasses import dataclass from enum import Enum from types import MappingProxyType -from typing import Annotated, Final, Literal, NamedTuple +from typing import TYPE_CHECKING, Annotated, Final, Literal, NamedTuple from pydantic import ( ConfigDict, @@ -27,8 +27,13 @@ from pydantic import ( from litellm.types.llms.base import LiteLLMBaseModel -with warnings.catch_warnings(): - warnings.simplefilter("ignore", DeprecationWarning) +if TYPE_CHECKING: + import sre_constants + import sre_parse +elif sys.version_info >= (3, 11): + from re import _constants as sre_constants + from re import _parser as sre_parse +else: import sre_constants import sre_parse diff --git a/litellm/router_strategy/lowest_latency.py b/litellm/router_strategy/lowest_latency.py index 28ed062f1ec..4e994d3fdc6 100644 --- a/litellm/router_strategy/lowest_latency.py +++ b/litellm/router_strategy/lowest_latency.py @@ -3,7 +3,7 @@ import random from collections.abc import Sequence from datetime import datetime, timedelta -from math import ceil +from math import ceil, isfinite from typing import TYPE_CHECKING, Any, Final from pydantic import Field @@ -46,6 +46,16 @@ def _percentile_latency(samples: Sequence[float], percentile: float) -> float: return values[index] +def _usable_latency_samples(samples: Sequence[float]) -> tuple[float, ...]: + """Drop samples that cannot be a real elapsed time. + + ``completion_start_time - start_time`` goes negative when the timestamps invert. + A negative or NaN sample pushes ``lowest_latency + buffer`` below every candidate, + leaving the deployment filter empty. + """ + return tuple(sample for sample in samples if isfinite(sample) and sample >= 0) + + def _ttft_seconds(elapsed: timedelta | float) -> float: if isinstance(elapsed, timedelta): return elapsed.total_seconds() @@ -469,16 +479,17 @@ class LowestLatencyLoggingHandler(CustomLogger): item_rpm = item_map.get(precise_minute, {}).get("rpm", 0) item_tpm = item_map.get(precise_minute, {}).get("tpm", 0) + ttft_samples = _usable_latency_samples(item_ttft_latency) use_ttft = ( request_kwargs is not None and request_kwargs.get("stream", None) is not None and request_kwargs["stream"] is True - and len(item_ttft_latency) > 0 + and len(ttft_samples) > 0 ) selected_latency = ( - _percentile_latency(item_ttft_latency, self.routing_args.ttft_percentile) + _percentile_latency(ttft_samples, self.routing_args.ttft_percentile) if use_ttft and self.routing_args.ttft_percentile is not None - else _average_latency(item_ttft_latency if use_ttft else item_latency) + else _average_latency(ttft_samples if use_ttft else _usable_latency_samples(item_latency)) ) # -------------- # @@ -512,10 +523,9 @@ class LowestLatencyLoggingHandler(CustomLogger): # Find deployments within buffer of lowest latency buffer: Final = self.routing_args.lowest_latency_buffer * lowest_latency - valid_deployments: Final = [x for x in sorted_deployments if x[1] <= lowest_latency + buffer] + valid_deployments: Final = tuple(x for x in sorted_deployments if x[1] <= lowest_latency + buffer) - # Pick a random deployment from valid deployments - random_valid_deployment: Final = random.choice(valid_deployments) + random_valid_deployment: Final = random.choice(valid_deployments or sorted_deployments) deployment = random_valid_deployment[0] metadata_field: Final = self._select_metadata_field(request_kwargs) if request_kwargs is not None and metadata_field in request_kwargs: diff --git a/litellm/router_strategy/quality_router/quality_router.py b/litellm/router_strategy/quality_router/quality_router.py index 1d119375778..d8c52b4c8b6 100644 --- a/litellm/router_strategy/quality_router/quality_router.py +++ b/litellm/router_strategy/quality_router/quality_router.py @@ -47,13 +47,13 @@ class QualityRouter(CustomLogger): model_name: str, litellm_router_instance: "Router", default_model: str | None = None, - quality_router_config: dict[str, Any] | None = None, + quality_router_config: Mapping[str, object] | None = None, ): self.model_name = model_name self.litellm_router_instance = litellm_router_instance if quality_router_config: - self.config = QualityRouterConfig(**quality_router_config) + self.config = QualityRouterConfig.model_validate(dict(**quality_router_config)) else: self.config = QualityRouterConfig() @@ -185,7 +185,7 @@ class QualityRouter(CustomLogger): if isinstance(raw_prefs, RoutingPreferences): prefs = raw_prefs elif isinstance(raw_prefs, dict): - prefs = RoutingPreferences(**raw_prefs) + prefs = RoutingPreferences.model_validate(dict(**raw_prefs)) else: # A Pydantic object of some other shape — coerce via its dict. prefs = RoutingPreferences( diff --git a/litellm/router_strategy/savings_baseline.py b/litellm/router_strategy/savings_baseline.py index b5b80ddae6d..add0f78fd3a 100644 --- a/litellm/router_strategy/savings_baseline.py +++ b/litellm/router_strategy/savings_baseline.py @@ -14,7 +14,7 @@ bare string with no provider beside them; an operator who writes ``deepseek-r1`` Azure would otherwise be priced against whoever else owns that name. """ -from collections.abc import Iterable +from collections.abc import Iterable, Mapping from typing import TYPE_CHECKING, Final, NamedTuple from litellm._logging import verbose_router_logger @@ -80,12 +80,11 @@ def _models_in(router: "Router", group_name: str) -> tuple[Baseline, ...]: straight at a provider model rather than at a configured group, and prices under its own name because there is no deployment to override it. """ - indices: Final = router.model_name_to_deployment_indices.get(group_name) - if not indices: + deployments: Final = router.deployments_named(group_name) + if not deployments: return (Baseline(qualified),) if (qualified := canonical_model(group_name)) else () - def candidate(index: int) -> Baseline | None: - deployment: Final = router.model_list[index] + def candidate(deployment: Mapping[str, object]) -> Baseline | None: params: Final = deployment.get("litellm_params") if not isinstance(params, dict): return None @@ -98,7 +97,7 @@ def _models_in(router: "Router", group_name: str) -> tuple[Baseline, ...]: deployment_id: Final = info.get("id") if isinstance(info, dict) else None return Baseline(qualified, str(deployment_id) if deployment_id else None) - return tuple(c for index in indices if (c := candidate(index)) is not None) + return tuple(c for deployment in deployments if (c := candidate(deployment)) is not None) def _priced(router: "Router", candidate: Baseline) -> tuple[float, Baseline] | None: diff --git a/litellm/router_strategy/tag_based_routing.py b/litellm/router_strategy/tag_based_routing.py index f13fd3fc630..d3996f504a5 100644 --- a/litellm/router_strategy/tag_based_routing.py +++ b/litellm/router_strategy/tag_based_routing.py @@ -9,10 +9,12 @@ Use this to route requests between Teams """ import re -from collections.abc import Mapping, Sequence +from collections.abc import Iterable, Mapping, Sequence from dataclasses import replace from types import MappingProxyType -from typing import TYPE_CHECKING, Any, Final, Literal, Protocol, overload +from typing import TYPE_CHECKING, Any, Final, Literal, Protocol, TypedDict, overload + +from typing_extensions import ReadOnly from litellm._logging import verbose_logger from litellm.constants import ( @@ -56,6 +58,10 @@ class _DeploymentLike(Protocol): def get(self, key: Literal["model_name"], /) -> object: ... +class _DeploymentWithModelInfo(TypedDict, total=False): + model_info: ReadOnly[Mapping[str, object]] + + class _MetadataLike(Protocol): @overload def get(self, key: Literal["tags"], /) -> Sequence[str] | None: ... @@ -285,13 +291,14 @@ def _unknown_required_tag_hides_an_answer( def _chain_allows_fail_open( healthy_deployments: _DeploymentPool, + request_deployments: Iterable[_DeploymentLike | _DeploymentWithModelInfo], excluded_set: frozenset[str], required_set: frozenset[str], routing_confirmed: frozenset[str], ) -> bool: if _unknown_required_tag_hides_an_answer(healthy_deployments, excluded_set, required_set, routing_confirmed): return False - return any((d.get("model_info") or {}).get("allow_fail_open") is True for d in healthy_deployments) + return any((d.get("model_info") or {}).get("allow_fail_open") is True for d in request_deployments) def _trusted_only_pool( @@ -327,6 +334,7 @@ def _trusted_only_pool( def _resolve_or_fail_open( + request_deployments: Iterable[_DeploymentLike | _DeploymentWithModelInfo], pool: Sequence[_DeploymentLike], healthy_deployments: _DeploymentPool, excluded_set: frozenset[str], @@ -339,7 +347,7 @@ def _resolve_or_fail_open( ) -> tuple[_DeploymentLike, ...]: if pool: return tuple(pool) - if _chain_allows_fail_open(healthy_deployments, excluded_set, required_set, routing_confirmed): + if _chain_allows_fail_open(healthy_deployments, request_deployments, excluded_set, required_set, routing_confirmed): # Fall open only within whatever still satisfies whichever constraints # trace back to key/team policy. A constraint with no inherited backing at # all (or, when inherited_tags is unavailable, any constraint at all) can @@ -356,6 +364,7 @@ def _resolve_or_fail_open( def _resolve_constraint_only_pool( + request_deployments: Iterable[_DeploymentLike | _DeploymentWithModelInfo], healthy_deployments: _DeploymentPool, excluded_set: frozenset[str], required_set: frozenset[str], @@ -371,6 +380,7 @@ def _resolve_constraint_only_pool( else _exclude_deployments(_default_tagged_pool(healthy_deployments), excluded_set) ) return _resolve_or_fail_open( + request_deployments, pool, healthy_deployments, excluded_set, @@ -553,6 +563,8 @@ async def get_deployments_for_tag( healthy_deployments: _DeploymentPool, request_kwargs: _RequestKwargsLike | None = None, metadata_variable_name: Literal["metadata", "litellm_metadata"] = "metadata", + *, + request_deployments: Iterable[_DeploymentLike | _DeploymentWithModelInfo], ) -> _DeploymentPool: """ Returns a list of deployments that match the requested model and tags in the request. @@ -624,6 +636,7 @@ async def get_deployments_for_tag( if constraint_only: return _resolve_constraint_only_pool( + request_deployments, healthy_deployments, excluded_set, required_set, @@ -675,6 +688,7 @@ async def get_deployments_for_tag( if len(new_healthy_deployments) == 0 and len(default_deployments) == 0: return _resolve_or_fail_open( + request_deployments, (), healthy_deployments, excluded_set, @@ -692,6 +706,7 @@ async def get_deployments_for_tag( and _tag_known_to_group(llm_router_instance, model, positive_tags, routing_confirmed) ): return _resolve_or_fail_open( + request_deployments, (), healthy_deployments, excluded_set, diff --git a/litellm/router_utils/baseline_request.py b/litellm/router_utils/baseline_request.py index 2f6262197a1..59878421068 100644 --- a/litellm/router_utils/baseline_request.py +++ b/litellm/router_utils/baseline_request.py @@ -7,7 +7,7 @@ from typing import Final, cast from pydantic import JsonValue, TypeAdapter, ValidationError -from litellm.llms.anthropic.pass_through.messages.utils import anthropic_messages_optional_param_keys +from litellm.llms.anthropic.messages.native.utils import anthropic_messages_optional_param_keys CACHE_SETTINGS: Final = ( "system", diff --git a/litellm/router_utils/pre_call_checks/deployment_affinity_check.py b/litellm/router_utils/pre_call_checks/deployment_affinity_check.py index 88fb8876175..8693eaa5151 100644 --- a/litellm/router_utils/pre_call_checks/deployment_affinity_check.py +++ b/litellm/router_utils/pre_call_checks/deployment_affinity_check.py @@ -16,6 +16,7 @@ import hashlib from collections.abc import Callable, Mapping, Sequence from typing import Final, cast +from pydantic import TypeAdapter from typing_extensions import ReadOnly, TypedDict from litellm._internal_context import with_service_target @@ -38,6 +39,27 @@ class DeploymentAffinityCacheValue(TypedDict, closed=True): model_id: ReadOnly[str] +def _affinity_response_fields(response: object) -> Mapping[str, object]: + return ( + TypeAdapter(Mapping[str, object]).validate_python(response) + if isinstance(response, Mapping) + else {name: getattr(response, name, None) for name in ("response", "status", "error")} + ) + + +def completed_affinity_response(response: object) -> bool: + if response is None: + return False + envelope: Final = _affinity_response_fields(response) + if envelope.get("error") is not None or envelope.get("status") not in (None, "completed"): + return False + nested: Final = envelope.get("response") + fields: Final = _affinity_response_fields(nested) if nested is not None else envelope + return ( + fields.get("response") is None and fields.get("error") is None and fields.get("status") in (None, "completed") + ) + + VALID_MODEL_GROUP_AFFINITY_FLAGS: Final = frozenset( { "deployment_affinity", @@ -86,6 +108,7 @@ class DeploymentAffinityCheck(CustomLogger): enable_session_id_affinity: bool = False, model_group_affinity_config: dict[str, list[str]] | None = None, is_priority_group: Callable[[str], bool] | None = None, + session_affinity_repin_on_failover: bool = False, ): super().__init__() self.cache = cache @@ -95,6 +118,7 @@ class DeploymentAffinityCheck(CustomLogger): self.enable_session_id_affinity = enable_session_id_affinity self.model_group_affinity_config: dict[str, list[str]] = model_group_affinity_config or {} self.is_priority_group = is_priority_group + self.session_affinity_repin_on_failover = session_affinity_repin_on_failover def _get_effective_flags(self, model_group: str) -> tuple[bool, bool, bool]: """ @@ -297,7 +321,7 @@ class DeploymentAffinityCheck(CustomLogger): return f"{cls.USER_ID_AFFINITY_PREFIX}{user_id}" @staticmethod - def _get_session_id_from_request_kwargs(request_kwargs: dict) -> str | None: + def _get_session_id_from_request_kwargs(request_kwargs: Mapping[str, object]) -> str | None: for metadata in DeploymentAffinityCheck._iter_metadata_dicts(request_kwargs): session_id = DeploymentAffinityCheck._get_session_id_from_metadata_dict(metadata=metadata) if session_id is not None: @@ -305,7 +329,7 @@ class DeploymentAffinityCheck(CustomLogger): return None @staticmethod - def _get_marker_session_affinity_ttl(request_kwargs: dict) -> int | None: + def _get_marker_session_affinity_ttl(request_kwargs: Mapping[str, object]) -> int | None: """TTL from the session-affinity marker the Router stamps at pre-routing time when an auto-router routed this request with session_affinity enabled. Marker presence enables session pinning for this request only; anything that @@ -357,7 +381,7 @@ class DeploymentAffinityCheck(CustomLogger): model: str, healthy_deployments: list, messages: list[AllMessageValues] | None, - request_kwargs: dict | None = None, + request_kwargs: dict[str, object] | None = None, parent_otel_span: Span | None = None, ) -> list[dict]: """ @@ -418,7 +442,15 @@ class DeploymentAffinityCheck(CustomLogger): session_cache_key: Final = self.get_session_affinity_cache_key( model_group=stable_model_map_key, session_id=session_id, user_key=user_key ) - session_cache_result: Final = await self.cache.async_get_cache(key=session_cache_key) + session_cache_result: Final = ( + await self._read_shared_session_pin( + session_cache_key, + self._get_marker_session_affinity_ttl(request_kwargs) or self.ttl_seconds, + parent_otel_span, + ) + if self.session_affinity_repin_on_failover + else await self.cache.async_get_cache(key=session_cache_key) + ) session_model_id: str | None = None if isinstance(session_cache_result, dict): @@ -482,6 +514,71 @@ class DeploymentAffinityCheck(CustomLogger): ) return [deployment] + async def _read_shared_session_pin(self, cache_key: str, ttl_seconds: int, parent_otel_span: Span | None) -> object: + redis_cache: Final = self.cache.redis_cache + if redis_cache is None: + return TypeAdapter(object).validate_python(await self.cache.async_get_cache(key=cache_key)) + local_before: Final = TypeAdapter(object).validate_python(self.cache.in_memory_cache.get_cache(cache_key)) + try: + shared: Final[object] = await redis_cache.async_get_cache( + key=cache_key, parent_otel_span=parent_otel_span, raise_on_error=True + ) + except Exception: # noqa: BLE001 # Optional affinity falls back locally on Redis admission or read failure + verbose_router_logger.debug("Session pin read failed, using pod-local affinity") + return TypeAdapter(object).validate_python(await self.cache.async_get_cache(key=cache_key, local_only=True)) + if self.cache.in_memory_cache.get_cache(cache_key) is local_before: + if shared is None: + self.cache.in_memory_cache.delete_cache(cache_key) + else: + self._set_local_pin(cache_key, shared, ttl_seconds) + return shared + + def get_repin_model_group(self, request_kwargs: Mapping[str, object]) -> str | None: + model_group: Final = next( + ( + value + for metadata in self._iter_metadata_dicts(request_kwargs) + if isinstance(value := metadata.get("deployment_model_name"), str) and value + ), + None, + ) + if model_group is None or self._get_session_id_from_request_kwargs(request_kwargs) is None: + return None + if ( + not self._get_effective_flags(model_group)[2] + and self._get_marker_session_affinity_ttl(request_kwargs) is None + ): + return None + return model_group + + async def async_repin_session_after_success( + self, + request_kwargs: Mapping[str, object], + model_group: str, + eligible_deployment_ids: frozenset[str], + ) -> None: + marker_ttl: Final = self._get_marker_session_affinity_ttl(request_kwargs) + if not self._get_effective_flags(model_group)[2] and marker_ttl is None: + return + session_id: Final = self._get_session_id_from_request_kwargs(request_kwargs) + if session_id is None: + return + model_info: Final = TypeAdapter(Mapping[str, object]).validate_python(request_kwargs.get("model_info") or {}) + model_id: Final = model_info.get("id") + if model_id is None or str(model_id) not in eligible_deployment_ids: + return + cache_key: Final = self.get_session_affinity_cache_key( + model_group, session_id, self.get_user_key_from_request_kwargs(request_kwargs) + ) + await claim_affinity_pin( + self.cache, + cache_key, + DeploymentAffinityCacheValue(model_id=str(model_id)), + marker_ttl if marker_ttl is not None else self.ttl_seconds, + eligible_values=tuple(DeploymentAffinityCacheValue(model_id=value) for value in eligible_deployment_ids), + preserve_legacy_model_ids=True, + ) + async def async_pre_call_deployment_hook( self, kwargs: dict[str, object], call_type: CallTypes | None ) -> dict | None: diff --git a/litellm/router_utils/pre_call_checks/io_token_rate_limit_check.py b/litellm/router_utils/pre_call_checks/io_token_rate_limit_check.py index 086f5517c29..2e350a2f87b 100644 --- a/litellm/router_utils/pre_call_checks/io_token_rate_limit_check.py +++ b/litellm/router_utils/pre_call_checks/io_token_rate_limit_check.py @@ -148,7 +148,7 @@ def _model_max_output_tokens(model_name: str) -> int | None: # this lookup is a fallback default and must never fail the request. with contextlib.suppress(Exception): info: Final = litellm.get_model_info(model=model_name) - model_max: Final = info.get("max_output_tokens") or info.get("max_tokens") + model_max: Final = info.get("max_output_tokens") if model_max is not None: return max(0, int(model_max)) return None diff --git a/litellm/router_utils/reasoning_effort_capability.py b/litellm/router_utils/reasoning_effort_capability.py index 4357722970f..16b8a22a40f 100644 --- a/litellm/router_utils/reasoning_effort_capability.py +++ b/litellm/router_utils/reasoning_effort_capability.py @@ -469,7 +469,7 @@ def _supports_none_reasoning_effort(model_info: Mapping[str, object], flag: obje if model_info.get("litellm_provider") != "azure": return flag is not False - from litellm.llms.azure.chat.gpt_5_transformation import AzureOpenAIGPT5Config + from litellm.llms.azure.chat.gpt_reasoning_transformation import AzureOpenAIGPT5Config key: Final = model_info.get("key") if not isinstance(key, str) or not AzureOpenAIGPT5Config.is_model_gpt_5_model(key): diff --git a/litellm/rust_bridge/host/callbacks_legacy_python.py b/litellm/rust_bridge/host/callbacks_legacy_python.py index ae913882968..2d2f5072544 100644 --- a/litellm/rust_bridge/host/callbacks_legacy_python.py +++ b/litellm/rust_bridge/host/callbacks_legacy_python.py @@ -377,7 +377,7 @@ def stream_success( end: datetime.datetime, first_chunk: datetime.datetime | None, ) -> None: - from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( + from litellm.llms.anthropic.messages.native.streaming_iterator import ( GLOBAL_PASS_THROUGH_SUCCESS_HANDLER_OBJ, ) from litellm.proxy.pass_through_endpoints.streaming_handler import PassThroughStreamingHandler diff --git a/litellm/rust_bridge/host/routes/messages.py b/litellm/rust_bridge/host/routes/messages.py index 1024141d5a2..017ff65e2a7 100644 --- a/litellm/rust_bridge/host/routes/messages.py +++ b/litellm/rust_bridge/host/routes/messages.py @@ -10,7 +10,7 @@ from pydantic import TypeAdapter, ValidationError import litellm from litellm.litellm_core_utils.core_helpers import normalize_drop_params from litellm.litellm_core_utils.request_timeout_resolver import get_configured_request_timeout -from litellm.llms.anthropic.pass_through.utils import is_reasoning_auto_summary_enabled +from litellm.llms.anthropic.messages.utils import is_reasoning_auto_summary_enabled from litellm.rust_bridge import failures from litellm.rust_bridge.public_call import known_params, optional_str from litellm.types.llms.anthropic_messages.anthropic_response import AnthropicMessagesResponse @@ -64,7 +64,7 @@ def body_params(request: Mapping[str, object]) -> Mapping[str, object]: def stream_hidden_params(headers: Sequence[tuple[str, str]]) -> Mapping[str, object]: - from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( + from litellm.llms.anthropic.messages.native.streaming_iterator import ( anthropic_messages_stream_hidden_params, ) diff --git a/litellm/rust_bridge/messages/detectors.py b/litellm/rust_bridge/messages/detectors.py index b53e80805a5..5f75858d350 100644 --- a/litellm/rust_bridge/messages/detectors.py +++ b/litellm/rust_bridge/messages/detectors.py @@ -73,7 +73,7 @@ def _resolved_provider(request: NativeCall) -> str | None: def intercepted(request: NativeCall) -> bool: """The async Messages handler delegates matching tools to a registered interceptor.""" - from litellm.llms.anthropic.pass_through.messages.interceptors import get_messages_interceptors + from litellm.llms.anthropic.messages.native.interceptors import get_messages_interceptors tools: Final = optional_sequence(request.resolved.get("tools")) if not tools: @@ -85,6 +85,6 @@ def intercepted(request: NativeCall) -> bool: def safeguards_classifier(request: NativeCall) -> bool: """Python's proxy classifier evaluates dangerous tool use for non-Claude models.""" - from litellm.llms.anthropic.pass_through.safeguards import native_route_classifies + from litellm.llms.anthropic.messages.safeguards import native_route_classifies return native_route_classifies(str(request.resolved["model"]), request.resolved.get("safeguards")) diff --git a/litellm/sandbox/__init__.py b/litellm/sandbox/__init__.py index 1974859fb1e..bcbb7bc5743 100644 --- a/litellm/sandbox/__init__.py +++ b/litellm/sandbox/__init__.py @@ -7,7 +7,10 @@ They resolve lazily so `import litellm` does not pull in litellm.harness. import importlib from typing import Final +from pydantic import TypeAdapter + _HARNESS_SANDBOX_MODULE: Final = "litellm.harness.sandbox" +_HARNESS_EXPORT: Final = TypeAdapter(object) _HARNESS_EXPORTS: Final = frozenset( { "local", @@ -23,5 +26,5 @@ _HARNESS_EXPORTS: Final = frozenset( def __getattr__(name: str) -> object: if name in _HARNESS_EXPORTS: - return getattr(importlib.import_module(_HARNESS_SANDBOX_MODULE), name) + return _HARNESS_EXPORT.validate_python(getattr(importlib.import_module(_HARNESS_SANDBOX_MODULE), name)) raise AttributeError(f"module {__name__!r} has no attribute {name!r}") diff --git a/litellm/secret_managers/base_secret_manager.py b/litellm/secret_managers/base_secret_manager.py index e537dd1d998..9c25086c451 100644 --- a/litellm/secret_managers/base_secret_manager.py +++ b/litellm/secret_managers/base_secret_manager.py @@ -1,6 +1,6 @@ import re from abc import ABC, abstractmethod -from typing import Any, Final +from typing import Final import httpx @@ -73,7 +73,7 @@ class BaseSecretManager(ABC): optional_params: dict | None = None, timeout: float | httpx.Timeout | None = None, tags: dict | list | None = None, - ) -> dict[str, Any]: + ) -> dict[str, object]: """ Asynchronously write a secret to the secret manager. diff --git a/litellm/secret_managers/cyberark_secret_manager.py b/litellm/secret_managers/cyberark_secret_manager.py index a1ec7c0a386..abfa9649e91 100644 --- a/litellm/secret_managers/cyberark_secret_manager.py +++ b/litellm/secret_managers/cyberark_secret_manager.py @@ -1,7 +1,7 @@ import asyncio import base64 import os -from typing import Any, Final +from typing import Final from urllib.parse import quote import httpx @@ -278,7 +278,7 @@ class CyberArkSecretManager(BaseSecretManager): optional_params: dict | None = None, timeout: float | httpx.Timeout | None = None, tags: dict | list | None = None, - ) -> dict[str, Any]: + ) -> dict[str, object]: """ Writes a secret to CyberArk Conjur using an async HTTPX client. diff --git a/litellm/secret_managers/main.py b/litellm/secret_managers/main.py index f4234e26c60..b33cf0e6b7e 100644 --- a/litellm/secret_managers/main.py +++ b/litellm/secret_managers/main.py @@ -24,6 +24,7 @@ from litellm.types.llms.base import LiteLLMBaseModel oidc_cache: Final = DualCache() _PARSED_LITERAL: Final = TypeAdapter(object) +_SECRET_MANAGER_CLIENT: Final = TypeAdapter(object) @lru_cache(maxsize=128) @@ -383,7 +384,7 @@ def get_secret( try: if _should_read_secret_from_secret_manager() and litellm.secret_manager_client is not None: try: - client: Final = litellm.secret_manager_client + client: Final = _SECRET_MANAGER_CLIENT.validate_python(litellm.secret_manager_client) key_manager = "local" if key_management_system is not None: key_manager = key_management_system.value diff --git a/litellm/types/decisions.py b/litellm/types/decisions.py index 5ad6e45e6d2..33b2c677d31 100644 --- a/litellm/types/decisions.py +++ b/litellm/types/decisions.py @@ -650,7 +650,7 @@ class DecisionsIRUsage: class DecisionsIRResponse: model: str | None answers: tuple[DecisionsIRAnswer, ...] - usage: DecisionsIRUsage + usage: DecisionsIRUsage | None extra: Mapping[str, object] = field(default_factory=lambda: _NO_EXTRA) diff --git a/litellm/types/guardrails.py b/litellm/types/guardrails.py index ff063d2e233..e1b891caaaf 100644 --- a/litellm/types/guardrails.py +++ b/litellm/types/guardrails.py @@ -59,6 +59,9 @@ from litellm.types.proxy.guardrails.guardrail_hooks.qohash import ( from litellm.types.proxy.guardrails.guardrail_hooks.qualifire import ( QualifireGuardrailConfigModel, ) +from litellm.types.proxy.guardrails.guardrail_hooks.reco import ( + RecoConfigModel, +) from litellm.types.proxy.guardrails.guardrail_hooks.repelloai import ( RepelloAIGuardrailConfigModel, ) @@ -153,6 +156,7 @@ class SupportedGuardrailIntegrations(Enum): TYPESAFE = "typesafe" STRAIKER = "straiker" ALICE = "alice" + RECO = "reco" AGENT_365 = "agent_365" LLM_SHIELD_PROXY = "llm_shield_proxy" CONDUCT = "conduct" @@ -1398,6 +1402,7 @@ class LitellmParams( # pyright: ignore[reportIncompatibleVariableOverride] # o QostodianNexusConfigModel, VigilGuardGuardrailConfigModel, SingulrGuardrailConfigModel, + RecoConfigModel, Agent365GuardrailConfigModel, WingbackGuardrailConfigModel, ): diff --git a/litellm/types/integrations/langfuse_otel.py b/litellm/types/integrations/langfuse_otel.py index 5647f28c757..459f2e984a4 100644 --- a/litellm/types/integrations/langfuse_otel.py +++ b/litellm/types/integrations/langfuse_otel.py @@ -32,6 +32,8 @@ class LangfuseSpanAttributes(str, Enum): OBSERVATION_COMPLETION_START_TIME = "langfuse.observation.completion_start_time" # ---- Trace-level metadata ---- + TRACE_INPUT = "langfuse.trace.input" + TRACE_OUTPUT = "langfuse.trace.output" TRACE_USER_ID = "user.id" SESSION_ID = "session.id" TAGS = "langfuse.trace.tags" diff --git a/litellm/types/litellm_params.py b/litellm/types/litellm_params.py index 089f21a33c1..717b74e5741 100644 --- a/litellm/types/litellm_params.py +++ b/litellm/types/litellm_params.py @@ -91,6 +91,7 @@ class ProviderConnection: litellm_credential_name: str | None = None configurable_clientside_auth_params: "Sequence[str | ConfigurableClientsideParamsCustomAuth] | None" = None use_xai_oauth: bool | None = None + chatgpt_auth_file: str | None = None github_copilot_auth_type: str | None = None github_copilot_host: str | None = None github_copilot_user_session: object | None = None diff --git a/litellm/types/llms/openai.py b/litellm/types/llms/openai.py index 62dc152ca84..9a4ecf37127 100644 --- a/litellm/types/llms/openai.py +++ b/litellm/types/llms/openai.py @@ -683,12 +683,12 @@ class ChatCompletionCachedContent(TypedDict): class PromptCacheBreakpoint(TypedDict): mode: ReadOnly[Literal["explicit"]] - ttl: NotRequired[ReadOnly[Literal["30m"]]] + ttl: NotRequired[ReadOnly[Literal["30m", "12h"]]] class PromptCacheOptions(TypedDict, total=False): mode: ReadOnly[Literal["implicit", "explicit"]] - ttl: ReadOnly[Literal["30m"]] + ttl: ReadOnly[Literal["30m", "12h"]] class ChatCompletionThinkingBlock(TypedDict, total=False): @@ -1382,10 +1382,23 @@ class OutputTokensDetails(BaseLiteLLMOpenAIResponseObject): model_config = {"extra": "allow"} +class CacheWriteTokensDetails(BaseLiteLLMOpenAIResponseObject): + ttl_30m_tokens: int + ttl_12h_tokens: int + + model_config = ConfigDict(extra="allow", frozen=True) + + +def _is_none(value: object) -> bool: + return value is None + + class InputTokensDetails(BaseLiteLLMOpenAIResponseObject): audio_tokens: int | None = None cached_tokens: int = 0 cached_tokens_details: CachedTokensDetails | None = None + cache_write_tokens: int | None = Field(default=None, exclude_if=_is_none) + cache_write_tokens_details: CacheWriteTokensDetails | None = Field(default=None, exclude_if=_is_none) image_tokens: int | None = None text_tokens: int | None = None video_tokens: int | None = None diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/reco.py b/litellm/types/proxy/guardrails/guardrail_hooks/reco.py new file mode 100644 index 00000000000..ef3b3935340 --- /dev/null +++ b/litellm/types/proxy/guardrails/guardrail_hooks/reco.py @@ -0,0 +1,48 @@ +import uuid +from typing import Literal + +from pydantic import BaseModel, ConfigDict, Field, field_validator + +from .base import GuardrailConfigModel + + +def validate_reco_tenant_id(value: str) -> str: + try: + uuid.UUID(value) + except ValueError as e: + raise ValueError(f"reco_tenant_id must be a valid UUID, got {value!r}") from e + return value + + +class RecoOptionalParams(BaseModel): + """Configuration parameters for the Reco guardrail""" + + model_config = ConfigDict(frozen=True) + + reco_tenant_id: str = Field( + description="Tenant identifier for the Reco account, as a UUID. Sent as the X-Reco-Tenant-Id header on every guardrail request.", + ) + api_base: str = Field( + description="Base URL for the Reco guardrail API. Reco's endpoint is per-region and per-silo, so this must be set explicitly rather than defaulted.", + ) + unreachable_fallback: Literal["fail_closed", "fail_open"] = Field( + default="fail_closed", + description="Behavior when Reco is unreachable. 'fail_closed' (default) blocks the request; 'fail_open' lets it through uninspected. Only applies while fail_on_error is true.", + ) + fail_on_error: bool = Field( + default=True, + description="Behavior on any Reco error, including unreachability. True (default) blocks the request; False lets it through uninspected.", + ) + + @field_validator("reco_tenant_id") + @classmethod + def _check_reco_tenant_id(cls, v: str) -> str: + return validate_reco_tenant_id(v) + + +class RecoConfigModel(GuardrailConfigModel[RecoOptionalParams]): + """Configuration parameters for the Reco guardrail""" + + @staticmethod + def ui_friendly_name() -> str: + return "Reco" diff --git a/litellm/types/proxy/management_endpoints/key_requests.py b/litellm/types/proxy/management_endpoints/key_requests.py index baa02b68d98..172357d8ac4 100644 --- a/litellm/types/proxy/management_endpoints/key_requests.py +++ b/litellm/types/proxy/management_endpoints/key_requests.py @@ -55,6 +55,8 @@ class LiteLLMKeyType(str, enum.Enum): class GenerateKeyRequest(KeyRequestBase): + tpm_limit: int | None = Field(default=None, ge=0) + rpm_limit: int | None = Field(default=None, ge=0) soft_budget: float | None = None send_invite_email: bool | None = None key_type: LiteLLMKeyType | None = Field( @@ -82,6 +84,8 @@ def _is_mapping(value: object) -> TypeIs[Mapping[object, object]]: # guard-ok: class UpdateKeyRequest(KeyRequestBase): + tpm_limit: int | None = Field(default=None, ge=0) + rpm_limit: int | None = Field(default=None, ge=0) # Note: the defaults of all Params here MUST BE NONE # else they will get overwritten duration: str | None = None diff --git a/litellm/types/proxy/management_endpoints/model_management_endpoints.py b/litellm/types/proxy/management_endpoints/model_management_endpoints.py index aedb16cda14..5eb41edf63e 100644 --- a/litellm/types/proxy/management_endpoints/model_management_endpoints.py +++ b/litellm/types/proxy/management_endpoints/model_management_endpoints.py @@ -1,11 +1,37 @@ from collections.abc import Mapping from datetime import datetime +from typing import Annotated, Final -from pydantic import ConfigDict, Field +from pydantic import ConfigDict, Field, model_validator from litellm.types.llms.base import LiteLLMBaseModel -from ...router import ModelGroupInfo +from ...router import ModelGroupInfo, updateDeployment + + +class PatchModelRequest(updateDeployment): + litellm_params_to_remove: tuple[Annotated[str, Field(min_length=1)], ...] = Field( + default=(), + description=( + "Top-level litellm_params keys to delete. Omitted parameters remain unchanged. " + "The required model key and keys also supplied in litellm_params cannot be removed. " + "Removing an absent key or repeating a key is a no-op." + ), + ) + + model_config = ConfigDict(frozen=True, protected_namespaces=()) + + @model_validator(mode="after") + def validate_param_removals(self) -> "PatchModelRequest": + removals: Final = frozenset(self.litellm_params_to_remove) + if "model" in removals: + raise ValueError("The required litellm_params.model cannot be removed") + conflicts: Final[frozenset[str]] = ( + removals.intersection(self.litellm_params.model_fields_set) if self.litellm_params else frozenset() + ) + if conflicts: + raise ValueError(f"Cannot set and remove the same litellm_params keys: {', '.join(sorted(conflicts))}") + return self class ModelGroupTeam(LiteLLMBaseModel): diff --git a/litellm/types/proxy/management_endpoints/team_endpoints.py b/litellm/types/proxy/management_endpoints/team_endpoints.py index 51c48e6ebf9..742842bd028 100644 --- a/litellm/types/proxy/management_endpoints/team_endpoints.py +++ b/litellm/types/proxy/management_endpoints/team_endpoints.py @@ -1,4 +1,5 @@ from collections.abc import Mapping +from datetime import datetime from typing import Final, Literal from pydantic import ConfigDict, Field, field_validator, model_validator @@ -83,11 +84,22 @@ class BulkUpdateTeamMemberPermissionsResponse(LiteLLMBaseModel): permissions_appended: list[str] | None = None +class TeamListCallerMembership(LiteLLMBaseModel): + """The calling user's own spend and effective member budget in a team.""" + + spend: float = 0.0 + max_budget: float | None = None + budget_reset_at: datetime | None = None + + model_config = ConfigDict(frozen=True) + + class TeamListItem(LiteLLM_TeamTable): """A team item in the paginated list response, enriched with computed fields.""" members_count: int = 0 keys_count: int = 0 + caller_membership: TeamListCallerMembership | None = None # Resources inherited from access groups (separate from direct assignments) access_group_models: list[str] | None = None access_group_mcp_server_ids: list[str] | None = None diff --git a/litellm/types/proxy/management_endpoints/user_requests.py b/litellm/types/proxy/management_endpoints/user_requests.py index 49dda5995bc..e53dc4152c3 100644 --- a/litellm/types/proxy/management_endpoints/user_requests.py +++ b/litellm/types/proxy/management_endpoints/user_requests.py @@ -16,6 +16,8 @@ class NewUserRequestTeam(LiteLLMPydanticObjectBase): class NewUserRequest(GenerateRequestBase): + tpm_limit: int | None = Field(default=None, ge=0) + rpm_limit: int | None = Field(default=None, ge=0) max_budget: float | None = None user_email: str | None = None user_alias: str | None = None @@ -47,6 +49,8 @@ class NewUserRequest(GenerateRequestBase): class UpdateUserRequestNoUserIDorEmail(GenerateRequestBase): # shared with BulkUpdateUserRequest + tpm_limit: int | None = Field(default=None, ge=0) + rpm_limit: int | None = Field(default=None, ge=0) # repr=False keeps the plaintext out of management-endpoint alerts, which str() the request model password: str | None = Field(default=None, repr=False) spend: float | None = None diff --git a/litellm/types/router.py b/litellm/types/router.py index cd1389aea9d..ba9b82e2a57 100644 --- a/litellm/types/router.py +++ b/litellm/types/router.py @@ -572,6 +572,10 @@ class GenericLiteLLMParams(CredentialLiteLLMParams, CustomPricingLiteLLMParams): default=False, description="Use stored xAI OAuth credentials when no xAI API key is configured.", ) + chatgpt_auth_file: str | None = Field( + default=None, + description="Path to a ChatGPT OAuth auth.json for this deployment.", + ) fireworks_forward_user_id: bool | None = Field( default=None, description="Send the LiteLLM user id of the calling key as the `user` field on Fireworks AI chat, responses and messages requests.", diff --git a/litellm/types/utils.py b/litellm/types/utils.py index 5939a350970..7e8645fd0dd 100644 --- a/litellm/types/utils.py +++ b/litellm/types/utils.py @@ -322,11 +322,23 @@ class ModelInfoBase(ProviderSpecificModelInfo, total=False): cache_creation_input_token_cost_above_272k_tokens_flex: float | None cache_creation_input_token_cost_above_272k_tokens_ultrafast: ReadOnly[float | None] cache_creation_input_token_cost_above_1hr: float | None + cache_creation_input_token_cost_above_12hr: ReadOnly[float | None] + cache_creation_input_token_cost_above_12hr_flex: ReadOnly[float | None] + cache_creation_input_token_cost_above_12hr_priority: ReadOnly[float | None] + cache_creation_input_token_cost_above_12hr_above_272k_tokens: ReadOnly[float | None] + cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex: ReadOnly[float | None] + cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority: ReadOnly[float | None] + cache_creation_input_token_cost_above_12hr_batches: ReadOnly[float | None] + cache_creation_input_token_cost_above_12hr_ultrafast: ReadOnly[float | None] + cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches: ReadOnly[float | None] + cache_creation_input_token_cost_above_12hr_above_272k_tokens_ultrafast: ReadOnly[float | None] cache_creation_input_token_cost_flex: float | None # OpenAI flex service tier pricing cache_creation_input_token_cost_priority: float | None # OpenAI priority service tier pricing cache_creation_input_token_cost_ultrafast: ReadOnly[float | None] # OpenAI ultrafast service tier pricing cache_read_input_token_cost: float | None cache_read_input_audio_token_cost: ReadOnly[float | None] + cache_read_input_audio_token_cost_flex: ReadOnly[float | None] + cache_read_input_audio_token_cost_priority: ReadOnly[float | None] cache_read_input_image_token_cost: ReadOnly[float | None] explicit_cache_read_input_token_cost: ReadOnly[float | None] cache_read_input_token_cost_flex: float | None # OpenAI flex service tier pricing @@ -342,6 +354,7 @@ class ModelInfoBase(ProviderSpecificModelInfo, total=False): cache_read_input_token_cost_above_272k_tokens_ultrafast: ReadOnly[float | None] cache_read_input_token_cost_above_512k_tokens: float | None cache_read_input_token_cost_batches: ReadOnly[float | None] + cache_read_input_audio_token_cost_batches: ReadOnly[float | None] cache_read_input_token_cost_above_200k_tokens_batches: ReadOnly[float | None] cache_read_input_token_cost_above_100k_tokens_batches: ReadOnly[float | None] cache_read_input_token_cost_above_272k_tokens_batches: ReadOnly[float | None] @@ -355,6 +368,8 @@ class ModelInfoBase(ProviderSpecificModelInfo, total=False): off_peak_pricing: ReadOnly[OffPeakPricing | None] # time-windowed off-peak rates input_cost_per_character: float | None # only for vertex ai models input_cost_per_audio_token: float | None + input_cost_per_audio_token_flex: ReadOnly[float | None] + input_cost_per_audio_token_priority: ReadOnly[float | None] input_cost_per_token_above_128k_tokens: float | None # only for vertex ai models input_cost_per_token_above_200k_tokens: float | None # only for vertex ai gemini-2.5-pro models input_cost_per_token_above_100k_tokens: ReadOnly[float | None] @@ -1804,7 +1819,9 @@ class CompletionTokensDetailsWrapper(CompletionTokensDetails): # wrapper for ol class CacheCreationTokenDetails(LiteLLMBaseModel): ephemeral_5m_input_tokens: int | None = None + ephemeral_30m_input_tokens: int | None = None ephemeral_1h_input_tokens: int | None = None + ephemeral_12h_input_tokens: int | None = None class PromptTokensDetailsWrapper( @@ -3954,6 +3971,16 @@ class MirroredPricingParams(LiteLLMBaseModel): explicit_cache_read_input_token_cost: float | None = None cache_creation_input_token_cost: float | None = None cache_creation_input_token_cost_above_1hr: float | None = None + cache_creation_input_token_cost_above_12hr: float | None = None + cache_creation_input_token_cost_above_12hr_flex: float | None = None + cache_creation_input_token_cost_above_12hr_priority: float | None = None + cache_creation_input_token_cost_above_12hr_above_272k_tokens: float | None = None + cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex: float | None = None + cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority: float | None = None + cache_creation_input_token_cost_above_12hr_batches: float | None = None + cache_creation_input_token_cost_above_12hr_ultrafast: float | None = None + cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches: float | None = None + cache_creation_input_token_cost_above_12hr_above_272k_tokens_ultrafast: float | None = None tiered_pricing: list[dict[str, Any]] | None = None @@ -4006,14 +4033,19 @@ class CustomPricingLiteLLMParams(MirroredPricingParams): cache_read_input_token_cost_above_100k_tokens_batches: float | None = None cache_read_input_token_cost_above_200k_tokens_batches: float | None = None cache_read_input_token_cost_above_272k_tokens_batches: float | None = None + cache_read_input_audio_token_cost_batches: float | None = None cache_creation_input_token_cost_batches: float | None = None cache_creation_input_token_cost_above_100k_tokens_batches: float | None = None cache_creation_input_token_cost_above_200k_tokens_batches: float | None = None cache_creation_input_token_cost_above_272k_tokens_batches: float | None = None cache_read_input_audio_token_cost: float | None = None + cache_read_input_audio_token_cost_flex: float | None = None + cache_read_input_audio_token_cost_priority: float | None = None cache_read_input_image_token_cost: float | None = None input_cost_per_character_above_128k_tokens: float | None = None input_cost_per_audio_token: float | None = None + input_cost_per_audio_token_flex: float | None = None + input_cost_per_audio_token_priority: float | None = None input_cost_per_token_cache_hit: float | None = None input_cost_per_token_above_128k_tokens: float | None = None input_cost_per_token_above_100k_tokens: float | None = None @@ -4328,6 +4360,7 @@ server_owned_wif_litellm_params: Final = ( + openai_wif_litellm_params + oauth_token_exchange_litellm_params + github_copilot_oauth_litellm_params + + ("chatgpt_auth_file",) ) secret_bearing_wif_litellm_params: Final = tuple(sorted(WIF_SECRET_BEARING_KEYS)) @@ -4382,6 +4415,7 @@ GenericBudgetConfigType = dict[str, BudgetConfig] class LlmProviders(str, Enum): + REFUSELESS = "refuseless" OPENAI = "openai" CHATGPT = "chatgpt" OPENAI_LIKE = "openai_like" # embedding only @@ -4409,6 +4443,7 @@ class LlmProviders(str, Enum): VERTEX_AI = "vertex_ai" VERTEX_AI_BETA = "vertex_ai_beta" GEMINI = "gemini" + ABLITERATION = "abliteration" AI21 = "ai21" BASETEN = "baseten" BLACK_FOREST_LABS = "black_forest_labs" @@ -4454,6 +4489,7 @@ class LlmProviders(str, Enum): PUBLICAI = "publicai" V0 = "v0" MORPH = "morph" + OPENCODE_GO = "opencode_go" LAMBDA_AI = "lambda_ai" INCEPTION = "inception" TEXT_COMPLETION_INCEPTION = "text-completion-inception" diff --git a/litellm/utils.py b/litellm/utils.py index 809a94cd93e..6f0b1ca2e3e 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -1641,7 +1641,7 @@ def _deployment_provider(kwargs: Mapping[str, object]) -> str: return "" -async def async_pre_call_deployment_hook(kwargs: dict[str, Any], call_type: str) -> dict[str, Any]: +async def async_pre_call_deployment_hook(kwargs: Mapping[str, object], call_type: str) -> dict[str, Any]: """ Allow modifying the request just before it's sent to the deployment. @@ -2964,12 +2964,14 @@ def supports_native_streaming(model: str, custom_llm_provider: str | None) -> bo Raises: Exception: If the given model is not found in model_prices_and_context_window.json. """ + from litellm.litellm_core_utils.get_llm_provider_logic import resolve_model_and_provider_for_metadata + try: - model, custom_llm_provider, _, _ = litellm.get_llm_provider( + resolved_model, resolved_provider = resolve_model_and_provider_for_metadata( model=model, custom_llm_provider=custom_llm_provider ) - model_info: Final = get_model_info_helper(model=model, custom_llm_provider=custom_llm_provider) + model_info: Final = get_model_info_helper(model=resolved_model, custom_llm_provider=resolved_provider) supports_native_streaming = model_info.get("supports_native_streaming", True) if supports_native_streaming is None: supports_native_streaming = True @@ -4287,7 +4289,7 @@ def get_optional_params_embeddings( # retrieve all parameters passed to the function passed_params: Final = locals() - custom_llm_provider = passed_params.pop("custom_llm_provider", None) + passed_params.pop("custom_llm_provider", None) special_params: Final = passed_params.pop("kwargs") passed_params.pop("drop_params", None) @@ -4325,7 +4327,7 @@ def get_optional_params_embeddings( provider_config: BaseEmbeddingConfig | None = None optional_params = {} - if custom_llm_provider is not None and custom_llm_provider in LlmProviders._member_map_.values(): + if custom_llm_provider in LlmProviders._member_map_.values(): provider_config = ProviderConfigManager.get_provider_embedding_config( model=model, provider=LlmProviders(custom_llm_provider), @@ -6077,11 +6079,8 @@ def get_max_tokens(model: str) -> int | None: return None try: - if model in litellm.model_cost: - if "max_output_tokens" in litellm.model_cost[model]: - return litellm.model_cost[model]["max_output_tokens"] - elif "max_tokens" in litellm.model_cost[model]: - return litellm.model_cost[model]["max_tokens"] + if model in litellm.model_cost and "max_output_tokens" in litellm.model_cost[model]: + return litellm.model_cost[model]["max_output_tokens"] get_llm_provider: Final = litellm_utils.get_llm_provider model, custom_llm_provider, _, _ = get_llm_provider(model=model) if custom_llm_provider == "huggingface": @@ -6090,8 +6089,6 @@ def get_max_tokens(model: str) -> int | None: if model in litellm.model_cost: # check if extracted model is in model_list if "max_output_tokens" in litellm.model_cost[model]: return litellm.model_cost[model]["max_output_tokens"] - elif "max_tokens" in litellm.model_cost[model]: - return litellm.model_cost[model]["max_tokens"] else: raise Exception() return None @@ -6740,7 +6737,7 @@ def get_model_info_helper( returned_model_info: Final = ModelInfoBase( key=key, - max_tokens=_model_info.get("max_tokens", None), + max_tokens=_model_info.get("max_output_tokens") or _model_info.get("max_input_tokens"), max_input_tokens=_model_info.get("max_input_tokens", None), max_output_tokens=_model_info.get("max_output_tokens", None), input_cost_per_token=_input_cost_per_token, @@ -6773,6 +6770,13 @@ def get_model_info_helper( ), cache_read_input_token_cost=_model_info.get("cache_read_input_token_cost", None), cache_read_input_audio_token_cost=_model_info.get("cache_read_input_audio_token_cost", None), + cache_read_input_audio_token_cost_flex=_model_info.get("cache_read_input_audio_token_cost_flex", None), + cache_read_input_audio_token_cost_priority=_model_info.get( + "cache_read_input_audio_token_cost_priority", None + ), + cache_read_input_audio_token_cost_batches=_model_info.get( + "cache_read_input_audio_token_cost_batches", None + ), explicit_cache_read_input_token_cost=_model_info.get("explicit_cache_read_input_token_cost", None), prompt_cache_min_tokens=_model_info.get("prompt_cache_min_tokens", None), cache_read_input_token_cost_above_200k_tokens=_model_info.get( @@ -6817,6 +6821,36 @@ def get_model_info_helper( cache_creation_input_token_cost_above_1hr=_model_info.get( "cache_creation_input_token_cost_above_1hr", None ), + cache_creation_input_token_cost_above_12hr=_model_info.get( + "cache_creation_input_token_cost_above_12hr", None + ), + cache_creation_input_token_cost_above_12hr_flex=_model_info.get( + "cache_creation_input_token_cost_above_12hr_flex", None + ), + cache_creation_input_token_cost_above_12hr_priority=_model_info.get( + "cache_creation_input_token_cost_above_12hr_priority", None + ), + cache_creation_input_token_cost_above_12hr_above_272k_tokens=_model_info.get( + "cache_creation_input_token_cost_above_12hr_above_272k_tokens", None + ), + cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex=_model_info.get( + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex", None + ), + cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority=_model_info.get( + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority", None + ), + cache_creation_input_token_cost_above_12hr_batches=_model_info.get( + "cache_creation_input_token_cost_above_12hr_batches", None + ), + cache_creation_input_token_cost_above_12hr_ultrafast=_model_info.get( + "cache_creation_input_token_cost_above_12hr_ultrafast", None + ), + cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches=_model_info.get( + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches", None + ), + cache_creation_input_token_cost_above_12hr_above_272k_tokens_ultrafast=_model_info.get( + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_ultrafast", None + ), off_peak_pricing=_model_info.get("off_peak_pricing", None), input_cost_per_character=_model_info.get("input_cost_per_character", None), input_cost_per_token_above_128k_tokens=_model_info.get("input_cost_per_token_above_128k_tokens", None), @@ -6840,6 +6874,8 @@ def get_model_info_helper( input_cost_per_second=_model_info.get("input_cost_per_second", None), input_cost_per_text_message=_model_info.get("input_cost_per_text_message", None), input_cost_per_audio_token=_model_info.get("input_cost_per_audio_token", None), + input_cost_per_audio_token_flex=_model_info.get("input_cost_per_audio_token_flex", None), + input_cost_per_audio_token_priority=_model_info.get("input_cost_per_audio_token_priority", None), input_cost_per_image_token=_model_info.get("input_cost_per_image_token", None), input_cost_per_video_token=_model_info.get("input_cost_per_video_token", None), input_cost_per_audio_token_batches=_model_info.get("input_cost_per_audio_token_batches", None), @@ -8201,9 +8237,7 @@ def trim_messages( if max_tokens is None: # Check if model is valid if model in litellm.model_cost: - max_tokens_for_model: Final = litellm.model_cost[model].get( - "max_input_tokens", litellm.model_cost[model]["max_tokens"] - ) + max_tokens_for_model: Final = litellm.model_cost[model]["max_input_tokens"] max_tokens = int(max_tokens_for_model * trim_ratio) else: # if user did not specify max (input) tokens @@ -9033,8 +9067,9 @@ _get_bundled_model_cost_map = get_bundled_model_cost_map def _get_model_cost_entry_for_provider_config( model: str, provider: LlmProviders, -) -> dict[str, object]: +) -> Mapping[str, object]: candidate_keys: Final = (model, f"{provider.value}/{model}") + model_info: Mapping[str, object] | None for model_key in candidate_keys: model_info = litellm.model_cost.get(model_key) if model_info is not None: @@ -9098,6 +9133,7 @@ class ProviderConfigManager: LlmProviders.DATABRICKS: (lambda: litellm.DatabricksConfig(), False), LlmProviders.XAI: (lambda: litellm.XAIChatConfig(), False), LlmProviders.ZAI: (lambda: litellm.ZAIChatConfig(), False), + LlmProviders.OPENCODE_GO: (ProviderConfigManager.get_opencode_go_config, True), LlmProviders.LAMBDA_AI: (lambda: litellm.LambdaAIChatConfig(), False), LlmProviders.INCEPTION: (lambda: litellm.InceptionChatConfig(), False), LlmProviders.LLAMA: (lambda: litellm.LlamaAPIConfig(), False), @@ -9289,6 +9325,12 @@ class ProviderConfigManager: return get_bedrock_chat_config(model=model) + @staticmethod + def get_opencode_go_config(model: str) -> BaseConfig: + from litellm.llms.opencode.chat.transformation import go_chat_config + + return go_chat_config(model) + @staticmethod def get_bedrock_mantle_config(model: str) -> BaseConfig: from litellm.llms.bedrock_mantle.chat.claude_transformation import bedrock_mantle_chat_config @@ -9524,7 +9566,7 @@ class ProviderConfigManager: return get_nvidia_nim_rerank_config(model) elif litellm.LlmProviders.VERTEX_AI == provider: - return litellm.VertexAIRerankConfig() + return ProviderConfigManager._get_vertex_ai_rerank_config_cached() elif litellm.LlmProviders.FIREWORKS_AI == provider: return litellm.FireworksAIRerankConfig() elif litellm.LlmProviders.VOYAGE == provider: @@ -9543,6 +9585,11 @@ class ProviderConfigManager: return get_dashscope_family_rerank_config(provider.value) return litellm.CohereRerankConfig() + @staticmethod + @lru_cache(maxsize=1) + def _get_vertex_ai_rerank_config_cached() -> BaseRerankConfig: + return litellm.VertexAIRerankConfig() + @staticmethod def get_provider_decisions_config(model: str, provider: LlmProviders) -> BaseDecisionsConfig | None: if provider == LlmProviders.PERPLEXITY: @@ -9563,12 +9610,18 @@ class ProviderConfigManager: return litellm.DatabricksDecisionsConfig() if provider == LlmProviders.HOSTED_VLLM: return litellm.HostedVLLMDecisionsConfig() + if provider == LlmProviders.LM_STUDIO: + return litellm.LMStudioDecisionsConfig() if provider == LlmProviders.LAYA: return litellm.LayaDecisionsConfig() if provider == LlmProviders.BESPOKE: return litellm.BespokeDecisionsConfig() - if provider == LlmProviders.OPENAI: - return litellm.OpenAIDecisionsConfig() + if provider in (LlmProviders.OPENAI, LlmProviders.AZURE): + configs: Final = { + LlmProviders.OPENAI: litellm.OpenAIDecisionsConfig, + LlmProviders.AZURE: litellm.AzureDecisionsConfig, + } + return configs[provider]() if provider == LlmProviders.AZURE_AI: return litellm.AzureAIDecisionsConfig() return None @@ -9592,6 +9645,11 @@ class ProviderConfigManager: model: str, provider: LlmProviders, ) -> BaseAnthropicMessagesConfig | None: + if provider == LlmProviders.OPENCODE_GO: + from litellm.llms.opencode.common_utils import go_endpoint + from litellm.llms.opencode.messages.transformation import OpenCodeGoMessagesConfig + + return OpenCodeGoMessagesConfig() if go_endpoint(model) == "/v1/messages" else None model_lower: Final = model.lower() if litellm.LlmProviders.ANTHROPIC == provider: return litellm.AnthropicMessagesConfig() @@ -9610,7 +9668,7 @@ class ProviderConfigManager: return BedrockMantleAnthropicMessagesConfig() elif litellm.LlmProviders.VERTEX_AI == provider: if "claude" in model_lower: - from litellm.llms.vertex_ai.vertex_ai_partner_models.anthropic.experimental_pass_through.transformation import ( + from litellm.llms.vertex_ai.vertex_ai_partner_models.anthropic.messages.transformation import ( VertexAIPartnerModelsAnthropicMessagesConfig, ) @@ -9818,6 +9876,11 @@ class ProviderConfigManager: if provider is None: return None + if provider == LlmProviders.OPENCODE_GO: + from litellm.llms.opencode.common_utils import go_endpoint + from litellm.llms.opencode.responses.transformation import OpenCodeGoResponsesConfig + + return OpenCodeGoResponsesConfig() if go_endpoint(model or "") == "/v1/responses" else None if litellm.LlmProviders.OPENAI == provider: return litellm.OpenAIResponsesAPIConfig() elif litellm.LlmProviders.AZURE == provider: @@ -9957,6 +10020,10 @@ class ProviderConfigManager: model: str | None, provider: LlmProviders, ) -> BaseLLMModelInfo | None: + if provider == LlmProviders.OPENCODE_GO: + from litellm.llms.opencode.chat.transformation import OpenCodeGoChatConfig + + return OpenCodeGoChatConfig() if LlmProviders.FIREWORKS_AI == provider: return litellm.FireworksAIConfig() elif LlmProviders.BASETEN == provider: @@ -10859,18 +10926,12 @@ def extract_duration_from_srt_or_vtt(srt_or_vtt_content: str) -> float | None: # Regular expression to match timestamps in the format "hh:mm:ss,ms" or "hh:mm:ss.ms" timestamp_pattern: Final = r"(\d{2}):(\d{2}):(\d{2})[.,](\d{3})" - timestamps: Final[Sequence[tuple[str, str, str, str]]] = re.findall(timestamp_pattern, srt_or_vtt_content) - - if not timestamps: - return None + timestamps: Final = re.finditer(timestamp_pattern, srt_or_vtt_content) # Convert timestamps to seconds and find the max (end time) - durations: Final = [] - match: tuple[str, str, str, str] - for match in timestamps: - hours, minutes, seconds, milliseconds = map(int, match) - total_seconds = hours * 3600 + minutes * 60 + seconds + milliseconds / 1000.0 - durations.append(total_seconds) + durations: Final = [ + int(match[1]) * 3600 + int(match[2]) * 60 + int(match[3]) + int(match[4]) / 1000.0 for match in timestamps + ] return max(durations) if durations else None diff --git a/litellm/vector_stores/main.py b/litellm/vector_stores/main.py index 8b33b1ce12c..9f53accfa0b 100644 --- a/litellm/vector_stores/main.py +++ b/litellm/vector_stores/main.py @@ -5,7 +5,7 @@ LiteLLM SDK Functions for Creating and Searching Vector Stores import asyncio import builtins import contextvars -from collections.abc import Coroutine, Mapping +from collections.abc import Coroutine, Iterator, Mapping from functools import partial from typing import TYPE_CHECKING, Final @@ -53,6 +53,10 @@ def _direct_vector_store_embedding_executor( ) +def _items_without_key(values: Mapping[str, object], excluded_key: str) -> Iterator[tuple[str, object]]: + return ((key, value) for key, value in values.items() if key != excluded_key) + + def mock_vector_store_search_response( mock_results: builtins.list[VectorStoreSearchResult] | None = None, ): @@ -307,7 +311,7 @@ async def asearch( embedding_executor: Final = _direct_vector_store_embedding_executor( kwargs.pop("_direct_vector_store_embedding_executor", None), router, kwargs ) - local_vars: Final = {key: value for key, value in locals().items() if key != "embedding_executor"} + local_vars: Final = dict(_items_without_key(locals(), "embedding_executor")) try: loop: Final = asyncio.get_event_loop() @@ -391,7 +395,7 @@ def search( embedding_executor: Final = _direct_vector_store_embedding_executor( kwargs.pop("_direct_vector_store_embedding_executor", None), router, kwargs ) - local_vars: Final = {key: value for key, value in locals().items() if key != "embedding_executor"} + local_vars: Final = dict(_items_without_key(locals(), "embedding_executor")) try: litellm_logging_obj: Final[LiteLLMLoggingObj] = kwargs.get("litellm_logging_obj") litellm_call_id: Final[str | None] = kwargs.get("litellm_call_id", None) @@ -694,7 +698,7 @@ def list( timeout: float | httpx.Timeout | None = None, custom_llm_provider: str | None = None, **kwargs, -): +) -> Mapping[str, object] | Coroutine[object, object, Mapping[str, object]]: """ List vector stores. @@ -992,7 +996,7 @@ def delete( timeout: float | httpx.Timeout | None = None, custom_llm_provider: str | None = None, **kwargs, -): +) -> Mapping[str, object] | Coroutine[object, object, Mapping[str, object]]: """ Delete a vector store. diff --git a/migrations/Dockerfile b/migrations/Dockerfile index 84ea67fcc5f..2b1fd029143 100644 --- a/migrations/Dockerfile +++ b/migrations/Dockerfile @@ -1,5 +1,5 @@ -ARG LITELLM_BUILD_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:81211e15a86ea1d5357f284482af45730c51de45eaf10ad9ce205d6bfc2df323 -ARG LITELLM_RUNTIME_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:81211e15a86ea1d5357f284482af45730c51de45eaf10ad9ce205d6bfc2df323 +ARG LITELLM_BUILD_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:360896efb0753a5701c48f860e17130c205eae5a264797aa3e7ea126ee2923a7 +ARG LITELLM_RUNTIME_IMAGE=cgr.dev/chainguard/wolfi-base@sha256:360896efb0753a5701c48f860e17130c205eae5a264797aa3e7ea126ee2923a7 ARG UV_IMAGE=ghcr.io/astral-sh/uv:0.11.7@sha256:240fb85ab0f263ef12f492d8476aa3a2e4e1e333f7d67fbdd923d00a506a516a FROM $UV_IMAGE AS uvbin @@ -137,7 +137,9 @@ ENV HOME=/home/nonroot \ PRISMA_CLI_QUERY_ENGINE_TYPE=binary \ PRISMA_OFFLINE_MODE=true -COPY --from=builder --chown=nonroot:nonroot /app /app +COPY --from=builder --chown=nonroot:nonroot /app/.venv /app/.venv +COPY --from=builder --chown=nonroot:nonroot /app/litellm /app/litellm +COPY --from=builder --chown=nonroot:nonroot /app/run.py /app/run.py COPY --from=builder /opt/prisma /opt/prisma RUN chmod -R a+rX /opt/prisma && \ diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index 3edb30b4218..39500330096 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -9,9 +9,8 @@ "input_cost_per_audio_token": 0.0, "input_cost_per_token": 0.0, "litellm_provider": "one of https://docs.litellm.ai/docs/providers", - "max_input_tokens": "max input tokens, if the provider specifies it. if not default to max_tokens", - "max_output_tokens": "max output tokens, if the provider specifies it. if not default to max_tokens", - "max_tokens": "LEGACY parameter. set to max_output_tokens if provider specifies it. IF not set to max_input_tokens, if provider specifies it.", + "max_input_tokens": "max input tokens, if the provider specifies it", + "max_output_tokens": "max output tokens, if the provider specifies it", "mode": "one of: chat, embedding, completion, image_generation, audio_transcription, audio_speech, image_generation, moderation, rerank, search", "output_cost_per_reasoning_token": 0.0, "output_cost_per_token": 0.0, @@ -49,37 +48,132 @@ "1024-x-1024/50-steps/stability.stable-diffusion-xl-v1": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.04 }, "1024-x-1024/max-steps/stability.stable-diffusion-xl-v1": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.08 }, "512-x-512/50-steps/stability.stable-diffusion-xl-v0": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.018 }, "512-x-512/max-steps/stability.stable-diffusion-xl-v0": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.036 }, + "abliteration/abliterated-model": { + "cache_read_input_token_cost": 1e-07, + "input_cost_per_token": 1e-06, + "litellm_provider": "abliteration", + "max_input_tokens": 262144, + "max_output_tokens": 262134, + "mode": "chat", + "output_cost_per_token": 3e-06, + "source": "https://abliteration.ai/pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": true, + "reasoning_effort_levels": [ + "none", + "minimal", + "low", + "medium", + "high", + "xhigh", + "max" + ] + }, + "abliteration/abliterated-model-large": { + "cache_read_input_token_cost": 3e-07, + "input_cost_per_token": 3e-06, + "litellm_provider": "abliteration", + "max_input_tokens": 1000000, + "max_output_tokens": 999990, + "mode": "chat", + "output_cost_per_token": 5e-06, + "source": "https://abliteration.ai/pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false, + "reasoning_effort_levels": [ + "none", + "minimal", + "low", + "medium", + "high", + "xhigh", + "max" + ] + }, + "abliteration/abliterated-model-large-v2": { + "cache_read_input_token_cost": 3e-07, + "input_cost_per_token": 3e-06, + "litellm_provider": "abliteration", + "max_input_tokens": 1000000, + "max_output_tokens": 999990, + "mode": "chat", + "output_cost_per_token": 5e-06, + "source": "https://abliteration.ai/pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_none_reasoning_effort": false, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false, + "reasoning_effort_levels": [ + "minimal", + "low", + "medium", + "high", + "xhigh", + "max" + ] + }, + "abliteration/abliterated-model-large-flash": { + "cache_read_input_token_cost": 1e-07, + "input_cost_per_token": 1e-06, + "litellm_provider": "abliteration", + "max_input_tokens": 1048576, + "max_output_tokens": 262144, + "mode": "chat", + "output_cost_per_token": 2e-06, + "source": "https://abliteration.ai/pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": true, + "reasoning_effort_levels": [ + "none", + "minimal", + "low", + "medium", + "high", + "xhigh", + "max" + ] + }, "ai21.j2-mid-v1": { "input_cost_per_token": 1.25e-05, "litellm_provider": "bedrock", "max_input_tokens": 8191, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 1.25e-05, "source": "https://aws.amazon.com/bedrock/pricing/" @@ -89,7 +183,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8191, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 1.88e-05, "source": "https://aws.amazon.com/bedrock/pricing/" @@ -100,7 +193,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 256000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-ai21-labs-jamba-1-5-large.md" @@ -111,7 +203,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 256000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-ai21-labs-jamba-1-5-mini.md" @@ -121,7 +212,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 70000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7e-07, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -298,7 +388,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-writer-palmyra-x4.md", @@ -311,7 +400,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-writer-palmyra-x5.md", @@ -324,7 +412,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-writer-palmyra-x4.md", @@ -337,7 +424,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-writer-palmyra-x5.md", @@ -352,7 +438,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -368,7 +453,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 2.4e-07, "output_cost_per_token_batches": 1.2e-07, @@ -389,7 +473,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 1.25e-06, @@ -414,7 +497,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -435,7 +517,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 3.311e-06, "supports_function_calling": true, @@ -455,7 +536,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.1e-05, "source": "https://aws.amazon.com/nova/pricing/", @@ -474,7 +554,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 3.597e-06, "supports_function_calling": true, @@ -494,7 +573,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.1e-05, "source": "https://aws.amazon.com/nova/pricing/", @@ -518,7 +596,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.75e-06, "output_cost_per_token_batches": 1.375e-06, @@ -544,7 +621,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_batches": 5.5e-06, @@ -562,7 +638,6 @@ "amazon.nova-2-multimodal-embeddings-v1:0": { "litellm_provider": "bedrock", "max_input_tokens": 8172, - "max_tokens": 8172, "mode": "embedding", "input_cost_per_token": 1.35e-07, "input_cost_per_image": 6e-05, @@ -583,7 +658,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 1.4e-07, "output_cost_per_token_batches": 7e-08, @@ -602,7 +676,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 1.25e-05, "output_cost_per_token_batches": 6.25e-06, @@ -626,7 +699,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 3.2e-06, "output_cost_per_token_batches": 1.6e-06, @@ -644,9 +716,12 @@ "input_cost_per_audio_token": 3e-06, "input_cost_per_token": 3.3e-07, "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 64000, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2.75e-06, + "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-amazon-nova-2-sonic.md", "supports_audio_input": true, "supports_audio_output": true }, @@ -656,7 +731,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "rerank", "output_cost_per_token": 0.0 }, @@ -665,7 +739,6 @@ "input_cost_per_token": 8e-07, "litellm_provider": "bedrock", "max_input_tokens": 128, - "max_tokens": 128, "metadata": { "notes": "'supports_image_input' is a deprecated field. Use 'supports_embedding_image_input' instead." }, @@ -680,7 +753,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "bedrock", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536 @@ -689,7 +761,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "bedrock", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536 @@ -698,7 +769,6 @@ "input_cost_per_token": 2e-08, "litellm_provider": "bedrock", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -736,7 +806,6 @@ "input_cost_per_image": 0.0001, "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -751,7 +820,6 @@ "input_cost_per_image": 0.0001, "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -766,7 +834,6 @@ "input_cost_per_image": 0.0001, "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -780,7 +847,6 @@ "input_cost_per_image": 0.0001, "litellm_provider": "bedrock", "max_input_tokens": 500, - "max_tokens": 500, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 512, @@ -794,7 +860,6 @@ "input_cost_per_image": 0.0001, "litellm_provider": "bedrock", "max_input_tokens": 500, - "max_tokens": 500, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 512, @@ -808,7 +873,6 @@ "input_cost_per_image": 0.0001, "litellm_provider": "bedrock", "max_input_tokens": 500, - "max_tokens": 500, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 512, @@ -856,7 +920,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 42000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 6e-07 }, @@ -865,7 +928,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 42000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 2e-07 }, @@ -874,7 +936,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 42000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.5e-06 }, @@ -885,7 +946,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4e-06, "supports_assistant_prefill": true, @@ -905,7 +965,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "source": "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonBedrockFoundationModels/current/index.json", @@ -937,7 +996,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "source": "https://aws.amazon.com/about-aws/whats-new/2025/10/claude-4-5-haiku-anthropic-amazon-bedrock", @@ -960,7 +1018,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -978,7 +1035,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -997,7 +1053,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.8e-05, "supports_assistant_prefill": true, @@ -1017,7 +1072,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -1035,7 +1089,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_function_calling": true, @@ -1050,7 +1103,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-06, "supports_tool_choice": true @@ -1063,7 +1115,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "search_context_cost_per_query": { @@ -1093,7 +1144,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "search_context_cost_per_query": { @@ -1121,7 +1171,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -1160,7 +1209,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -1200,7 +1248,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -1240,7 +1287,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -1280,7 +1326,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -1320,7 +1365,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -1360,7 +1404,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -1401,7 +1444,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "thinking_always_on": true, "supports_function_calling": true, @@ -1423,7 +1465,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -1466,7 +1507,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -1509,7 +1549,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -1552,7 +1591,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -1592,7 +1630,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "search_context_cost_per_query": { @@ -1635,7 +1672,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "search_context_cost_per_query": { @@ -1674,7 +1710,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "search_context_cost_per_query": { @@ -1717,7 +1752,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "search_context_cost_per_query": { @@ -1756,7 +1790,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-05, "search_context_cost_per_query": { @@ -1799,7 +1832,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-05, "search_context_cost_per_query": { @@ -1838,7 +1870,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-05, "search_context_cost_per_query": { @@ -1876,7 +1907,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-05, "search_context_cost_per_query": { @@ -1918,7 +1948,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -1961,7 +1990,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "search_context_cost_per_query": { @@ -2006,7 +2034,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -2049,7 +2076,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "search_context_cost_per_query": { @@ -2094,7 +2120,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -2137,7 +2162,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-05, "search_context_cost_per_query": { @@ -2182,7 +2206,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -2225,7 +2248,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-05, "search_context_cost_per_query": { @@ -2265,7 +2287,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -2308,7 +2329,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-05, "search_context_cost_per_query": { @@ -2353,7 +2373,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -2391,7 +2410,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-05, "search_context_cost_per_query": { @@ -2431,7 +2449,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -2476,7 +2493,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -2521,7 +2537,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -2566,7 +2581,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -2611,7 +2625,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -2656,7 +2669,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -2699,7 +2711,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -2741,7 +2752,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "search_context_cost_per_query": { @@ -2786,7 +2796,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "search_context_cost_per_query": { @@ -2831,7 +2840,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "search_context_cost_per_query": { @@ -2876,7 +2884,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "search_context_cost_per_query": { @@ -2921,7 +2928,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "search_context_cost_per_query": { @@ -2966,7 +2972,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "search_context_cost_per_query": { @@ -3007,7 +3012,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -3046,7 +3050,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -3085,7 +3088,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.65e-05, "search_context_cost_per_query": { @@ -3124,7 +3126,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.65e-05, "search_context_cost_per_query": { @@ -3163,7 +3164,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.65e-05, "search_context_cost_per_query": { @@ -3202,7 +3202,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.65e-05, "search_context_cost_per_query": { @@ -3242,7 +3241,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -3282,7 +3280,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -3315,7 +3312,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05 }, @@ -3324,7 +3320,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_tool_choice": true @@ -3334,7 +3329,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-07 }, @@ -3343,7 +3337,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1e-06 }, @@ -3352,7 +3345,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1e-06, "source": "https://docs.anyscale.com/preview/endpoints/text-generation/supported-models/codellama-CodeLlama-70b-Instruct-hf" @@ -3362,7 +3354,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://docs.anyscale.com/preview/endpoints/text-generation/supported-models/google-gemma-7b-it" @@ -3372,7 +3363,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.5e-07 }, @@ -3381,7 +3371,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1e-06 }, @@ -3390,7 +3379,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-07 }, @@ -3399,7 +3387,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1e-06, "source": "https://docs.anyscale.com/preview/endpoints/text-generation/supported-models/meta-llama-Meta-Llama-3-70B-Instruct" @@ -3409,7 +3396,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://docs.anyscale.com/preview/endpoints/text-generation/supported-models/meta-llama-Meta-Llama-3-8B-Instruct" @@ -3419,7 +3405,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://docs.anyscale.com/preview/endpoints/text-generation/supported-models/mistralai-Mistral-7B-Instruct-v0.1", @@ -3430,7 +3415,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 65536, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://docs.anyscale.com/preview/endpoints/text-generation/supported-models/mistralai-Mixtral-8x22B-Instruct-v0.1", @@ -3441,7 +3425,6 @@ "litellm_provider": "anyscale", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://docs.anyscale.com/preview/endpoints/text-generation/supported-models/mistralai-Mixtral-8x7B-Instruct-v0.1", @@ -3453,7 +3436,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 2.52e-07, "supports_function_calling": true, @@ -3469,7 +3451,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 1.48e-07, "supports_function_calling": true, @@ -3485,7 +3466,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 3.36e-06, "output_cost_per_token_flex": 1.68e-06, @@ -3504,7 +3484,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5.5e-06, "source": "https://aws.amazon.com/about-aws/whats-new/2025/10/claude-4-5-haiku-anthropic-amazon-bedrock", @@ -3539,7 +3518,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -3591,7 +3569,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.65e-05, "search_context_cost_per_query": { @@ -3624,7 +3601,6 @@ "input_cost_per_token": 1.1e-07, "litellm_provider": "azure", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/" @@ -3636,7 +3612,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 6e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -3666,7 +3641,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -3681,7 +3655,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "supports_assistant_prefill": true, @@ -3705,7 +3678,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "supports_assistant_prefill": true, @@ -3730,7 +3702,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -3761,7 +3732,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -3793,7 +3763,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -3826,7 +3795,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -3864,7 +3832,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -3895,7 +3862,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -3934,7 +3900,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -3967,7 +3932,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -3992,7 +3956,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "search_context_cost_per_query": { @@ -4026,7 +3989,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": false, @@ -4048,7 +4010,6 @@ "litellm_provider": "azure", "max_input_tokens": 8192, "max_output_tokens": 1024, - "max_tokens": 1024, "mode": "chat", "output_cost_per_token": 1.2e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -4083,7 +4044,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", "supports_function_calling": true, @@ -4101,7 +4061,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_above_272k_tokens": 7.5e-05, @@ -4150,7 +4109,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_above_272k_tokens": 7.5e-07, @@ -4199,7 +4157,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -4248,7 +4205,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -4300,7 +4256,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "output_cost_per_token_above_272k_tokens": 4.5e-05, @@ -4339,9 +4294,8 @@ "deprecation_date": "2027-05-18", "input_cost_per_token": 5e-06, "litellm_provider": "azure_ai", - "max_input_tokens": 272000, + "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "source": "https://azure.microsoft.com/en-us/pricing/details/cognitive-services/openai-service/", @@ -4391,7 +4345,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 6e-06, "source": "https://azure.microsoft.com/en-us/pricing/details/cognitive-services/openai-service/", @@ -4435,7 +4388,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "output_cost_per_token_above_272k_tokens": 4.5e-05, @@ -4482,7 +4434,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "output_cost_per_token_above_272k_tokens": 4.5e-05, @@ -4529,7 +4480,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_above_272k_tokens": 2.25e-05, @@ -4577,7 +4527,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_above_272k_tokens": 2.25e-05, @@ -4625,7 +4574,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -4671,7 +4619,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -4713,7 +4660,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.5e-06, "output_cost_per_token_priority": 9e-06, @@ -4755,7 +4701,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.5e-06, "output_cost_per_token_priority": 9e-06, @@ -4797,7 +4742,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.25e-06, "output_cost_per_token_priority": 2.5e-06, @@ -4839,7 +4783,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.25e-06, "output_cost_per_token_priority": 2.5e-06, @@ -4879,7 +4822,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 200000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://azure.microsoft.com/en-us/pricing/details/ai-foundry-models/aoai/", "comment": "Flat cost of $0.14 per M input tokens for Azure AI Foundry Model Router infrastructure. Use pattern: azure_ai/model_router/ where deployment-name is your Azure deployment (e.g., azure-model-router)" @@ -4891,7 +4833,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 200000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://azure.microsoft.com/en-us/pricing/details/ai-foundry-models/aoai/", "comment": "Catalog-name twin of azure_ai/model_router: the flat $0.14 per M input tokens is the router's own fee, the routed model is priced on top of it" @@ -4904,7 +4845,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_batches": 5.5e-06, @@ -4925,7 +4865,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_batches": 5.5e-06, @@ -4945,7 +4884,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_batches": 5.5e-06, @@ -4964,7 +4902,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6.6e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -4983,7 +4920,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6.6e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -5002,7 +4938,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 2.2e-05, "output_cost_per_token": 2.64e-06, @@ -5022,7 +4957,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 0.00022, "output_cost_per_token": 2.2e-05, @@ -5042,7 +4976,6 @@ "litellm_provider": "azure", "max_input_tokens": 16000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 8.8e-05, "output_cost_per_token": 2.2e-05, @@ -5072,7 +5005,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_batches": 5.5e-06, @@ -5112,7 +5044,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-06, "output_cost_per_token_batches": 1.1e-06, @@ -5151,7 +5082,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "supported_endpoints": [ @@ -5192,7 +5122,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -5224,7 +5153,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 2.2e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -5257,7 +5185,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.4e-07, "output_cost_per_token_batches": 2.2e-07, @@ -5294,7 +5221,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6.6e-05, "output_cost_per_token_batches": 3.3e-05, @@ -5313,7 +5239,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6.6e-05, "output_cost_per_token_batches": 3.3e-05, @@ -5331,7 +5256,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -5349,7 +5273,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -5367,7 +5290,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -5385,7 +5307,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -5405,7 +5326,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -5422,7 +5342,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -5439,7 +5358,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -5459,7 +5377,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -5480,7 +5397,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "supported_endpoints": [ @@ -5521,7 +5437,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -5553,7 +5468,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 2e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -5583,7 +5497,6 @@ "litellm_provider": "azure", "max_input_tokens": 4097, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-06, "supports_function_calling": true, @@ -5593,7 +5506,7 @@ "input_cost_per_token": 1.65e-06, "litellm_provider": "azure_text", "max_input_tokens": 4097, - "max_tokens": 4097, + "max_output_tokens": 4097, "mode": "completion", "output_cost_per_token": 2.2e-06, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/" @@ -5603,7 +5516,6 @@ "litellm_provider": "azure", "max_input_tokens": 4097, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-06, "supports_function_calling": true, @@ -5615,7 +5527,6 @@ "litellm_provider": "azure", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/legacy-models", @@ -5627,7 +5538,6 @@ "litellm_provider": "azure", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/legacy-models", @@ -5638,7 +5548,7 @@ "input_cost_per_token": 1.65e-06, "litellm_provider": "azure_text", "max_input_tokens": 4097, - "max_tokens": 4097, + "max_output_tokens": 4097, "mode": "completion", "output_cost_per_token": 2.2e-06, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/" @@ -5647,7 +5557,7 @@ "input_cost_per_token": 1.65e-06, "litellm_provider": "azure_text", "max_input_tokens": 4097, - "max_tokens": 4097, + "max_output_tokens": 4097, "mode": "completion", "output_cost_per_token": 2.2e-06, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/" @@ -5658,7 +5568,6 @@ "litellm_provider": "azure", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-05, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -5670,7 +5579,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3e-05, "supports_function_calling": true, @@ -5683,7 +5591,6 @@ "litellm_provider": "azure", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-05, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/legacy-models", @@ -5695,7 +5602,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3e-05, "supports_function_calling": true, @@ -5708,7 +5614,6 @@ "litellm_provider": "azure", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.00012, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/legacy-models", @@ -5720,7 +5625,6 @@ "litellm_provider": "azure", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.00012, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/legacy-models", @@ -5731,7 +5635,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3.3e-05, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/", @@ -5744,7 +5647,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3.3e-05, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/", @@ -5758,7 +5660,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3.3e-05, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/", @@ -5775,7 +5676,6 @@ "litellm_provider": "azure", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "output_cost_per_token_batches": 4e-06, @@ -5813,7 +5713,6 @@ "litellm_provider": "azure", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "output_cost_per_token_batches": 4e-06, @@ -5851,7 +5750,6 @@ "litellm_provider": "azure", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.6e-06, "output_cost_per_token_batches": 8e-07, @@ -5889,7 +5787,6 @@ "litellm_provider": "azure", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.6e-06, "output_cost_per_token_batches": 8e-07, @@ -5925,7 +5822,6 @@ "litellm_provider": "azure", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-07, "output_cost_per_token_batches": 2e-07, @@ -5959,7 +5855,6 @@ "litellm_provider": "azure", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-07, "output_cost_per_token_batches": 2e-07, @@ -5993,7 +5888,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 0.00015, "output_cost_per_token_batches": 7.5e-05, @@ -6013,7 +5907,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "supports_function_calling": true, @@ -6030,7 +5923,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 7.5e-06, @@ -6049,7 +5941,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -6069,7 +5960,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -6088,7 +5978,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 8e-05, "output_cost_per_token": 1e-05, @@ -6121,7 +6010,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 8e-05, "output_cost_per_token": 1e-05, @@ -6153,7 +6041,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1e-05, @@ -6186,7 +6073,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1e-05, @@ -6202,6 +6088,8 @@ "text", "audio" ], + "supports_audio_input": true, + "supports_audio_output": true, "supports_function_calling": true, "supports_native_streaming": true, "supports_parallel_function_calling": true, @@ -6219,7 +6107,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -6251,7 +6138,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -6266,6 +6152,8 @@ "text", "audio" ], + "supports_audio_input": true, + "supports_audio_output": true, "supports_function_calling": true, "supports_native_streaming": true, "supports_parallel_function_calling": true, @@ -6282,7 +6170,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 8e-05, "output_cost_per_token": 1e-05, @@ -6314,7 +6201,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -6332,7 +6218,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -6350,7 +6235,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 6e-07, @@ -6384,7 +6268,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -6406,7 +6289,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1.6e-05, @@ -6441,7 +6323,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1.6e-05, @@ -6475,7 +6356,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1.6e-05, @@ -6510,7 +6390,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1.6e-05, @@ -6544,7 +6423,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 2.4e-05, @@ -6579,7 +6457,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -6614,7 +6491,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -6648,7 +6524,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -6712,7 +6587,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 0.0002, "output_cost_per_token": 2e-05, @@ -6731,7 +6605,6 @@ "litellm_provider": "azure", "max_input_tokens": 16000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 8e-05, "output_cost_per_token": 2e-05, @@ -6785,7 +6658,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "audio_transcription", "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/gpt-realtime-whisper", "supported_endpoints": [ @@ -6809,7 +6681,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_priority": 2e-05, @@ -6852,7 +6723,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "output_cost_per_token_priority": 2e-05, @@ -6887,7 +6757,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 2e-06, "output_cost_per_token_priority": 3.6e-06, @@ -6924,7 +6793,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -6963,7 +6831,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -7000,7 +6867,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7036,7 +6902,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-06, "output_cost_per_token_batches": 1e-06, @@ -7075,7 +6940,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-06, "output_cost_per_token_batches": 1e-06, @@ -7114,7 +6978,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4e-07, "output_cost_per_token_batches": 2e-07, @@ -7150,7 +7013,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4e-07, "output_cost_per_token_batches": 2e-07, @@ -7186,7 +7048,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00012, "output_cost_per_token_batches": 6e-05, @@ -7220,7 +7081,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "supported_endpoints": [ @@ -7261,7 +7121,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7286,7 +7145,6 @@ "litellm_provider": "azure", "max_input_tokens": 111616, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7308,7 +7166,6 @@ "litellm_provider": "azure", "max_input_tokens": 111616, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.4e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7329,7 +7186,6 @@ "litellm_provider": "azure", "max_input_tokens": 111616, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.4e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7350,7 +7206,6 @@ "litellm_provider": "azure", "max_input_tokens": 111616, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7372,7 +7227,6 @@ "litellm_provider": "azure", "max_input_tokens": 111616, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.54e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7393,7 +7247,6 @@ "litellm_provider": "azure", "max_input_tokens": 111616, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.54e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7414,7 +7267,6 @@ "litellm_provider": "azure", "max_input_tokens": 111616, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7436,7 +7288,6 @@ "litellm_provider": "azure", "max_input_tokens": 111616, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.54e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7457,7 +7308,6 @@ "litellm_provider": "azure", "max_input_tokens": 111616, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.54e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7478,7 +7328,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 6.6e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7494,7 +7343,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 6.6e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7510,7 +7358,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7542,7 +7389,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7574,7 +7420,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 2e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7610,7 +7455,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.4e-05, "output_cost_per_token_batches": 7e-06, @@ -7650,7 +7494,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.4e-05, "output_cost_per_token_batches": 7e-06, @@ -7688,7 +7531,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.4e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -7722,7 +7564,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.4e-05, "output_cost_per_token_priority": 2.8e-05, @@ -7754,7 +7595,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.000168, "output_cost_per_token_batches": 8.4e-05, @@ -7793,7 +7633,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.000168, "output_cost_per_token_batches": 8.4e-05, @@ -7842,7 +7681,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_above_272k_tokens": 2.25e-05, @@ -7898,7 +7736,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions", @@ -7948,7 +7785,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions", @@ -7998,7 +7834,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_above_272k_tokens": 2.25e-05, @@ -8054,7 +7889,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions", @@ -8104,7 +7938,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions", @@ -8155,7 +7988,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -8204,7 +8036,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -8258,7 +8089,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "output_cost_per_token_above_272k_tokens": 3e-05, @@ -8319,7 +8149,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "output_cost_per_token_above_272k_tokens": 3e-05, @@ -8383,7 +8212,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "output_cost_per_token_above_272k_tokens": 3e-05, @@ -8447,7 +8275,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_272k_tokens": 1.8e-05, @@ -8511,7 +8338,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_272k_tokens": 1.8e-05, @@ -8575,7 +8401,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_above_272k_tokens": 1.8e-06, @@ -8639,7 +8464,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_above_272k_tokens": 1.8e-06, @@ -8691,7 +8515,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_above_272k_tokens": 7.5e-05, @@ -8740,7 +8563,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_above_272k_tokens": 7.5e-05, @@ -8789,7 +8611,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_above_272k_tokens": 7.5e-07, @@ -8838,7 +8659,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_above_272k_tokens": 7.5e-07, @@ -8893,7 +8713,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -8946,7 +8765,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -8993,7 +8811,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -9042,7 +8859,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -9091,7 +8907,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_above_272k_tokens": 1.65e-05, @@ -9140,7 +8955,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_272k_tokens": 1.8e-05, @@ -9189,7 +9003,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_272k_tokens": 1.8e-05, @@ -9232,9 +9045,8 @@ "deprecation_date": "2027-05-18", "input_cost_per_token": 5e-06, "litellm_provider": "azure", - "max_input_tokens": 272000, + "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "reasoning_effort_levels": [ @@ -9271,7 +9083,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "reasoning_effort_levels": [ @@ -9317,7 +9128,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-05, "output_cost_per_token_above_272k_tokens": 3.3e-05, @@ -9372,7 +9182,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-05, "output_cost_per_token_above_272k_tokens": 3.3e-05, @@ -9428,7 +9237,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.32e-05, "output_cost_per_token_above_272k_tokens": 1.98e-05, @@ -9484,7 +9292,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.32e-06, "output_cost_per_token_above_272k_tokens": 1.98e-06, @@ -9534,7 +9341,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-05, "output_cost_per_token_above_272k_tokens": 8.25e-05, @@ -9583,7 +9389,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-07, "output_cost_per_token_above_272k_tokens": 8.25e-07, @@ -9638,7 +9443,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_above_272k_tokens": 1.65e-05, @@ -9679,9 +9483,8 @@ "deprecation_date": "2027-05-18", "input_cost_per_token": 5.5e-06, "litellm_provider": "azure", - "max_input_tokens": 272000, + "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3.3e-05, "reasoning_effort_levels": [ @@ -9727,7 +9530,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-05, "output_cost_per_token_above_272k_tokens": 3.3e-05, @@ -9782,7 +9584,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-05, "output_cost_per_token_above_272k_tokens": 3.3e-05, @@ -9838,7 +9639,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.32e-05, "output_cost_per_token_above_272k_tokens": 1.98e-05, @@ -9894,7 +9694,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.32e-06, "output_cost_per_token_above_272k_tokens": 1.98e-06, @@ -9953,7 +9752,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "output_cost_per_token_above_272k_tokens": 4.5e-05, @@ -10012,7 +9810,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token_above_272k_tokens_batches": 2.475e-05, "output_cost_per_token_batches": 1.65e-05, @@ -10067,7 +9864,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token_above_272k_tokens_batches": 2.475e-05, "output_cost_per_token_batches": 1.65e-05, @@ -10119,7 +9915,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "output_cost_per_token_above_272k_tokens": 4.5e-05, @@ -10179,7 +9974,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "output_cost_per_token_batches": 1.5e-05, @@ -10238,7 +10032,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -10291,7 +10084,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -10345,7 +10137,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -10398,7 +10189,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "search_context_cost_per_query": { "search_context_size_high": 0.01, @@ -10445,7 +10235,6 @@ "litellm_provider": "azure", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -10489,7 +10278,6 @@ "litellm_provider": "azure", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -10531,7 +10319,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.5e-06, "search_context_cost_per_query": { @@ -10582,7 +10369,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.5e-06, "search_context_cost_per_query": { @@ -10634,7 +10420,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.25e-06, "search_context_cost_per_query": { @@ -10682,7 +10467,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.25e-06, "search_context_cost_per_query": { @@ -11058,7 +10842,7 @@ "input_cost_per_token": 8e-06, "litellm_provider": "azure", "max_input_tokens": 32000, - "max_tokens": 32000, + "max_output_tokens": 32000, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_function_calling": true @@ -11067,7 +10851,7 @@ "input_cost_per_token": 8e-06, "litellm_provider": "azure", "max_input_tokens": 32000, - "max_tokens": 32000, + "max_output_tokens": 32000, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_function_calling": true @@ -11079,7 +10863,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6e-05, "supports_function_calling": true, @@ -11097,7 +10880,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6e-05, "output_cost_per_token_batches": 3e-05, @@ -11116,7 +10898,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_batches": 2.2e-06, @@ -11134,7 +10915,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_batches": 2.2e-06, @@ -11152,7 +10932,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8e-06, "supported_endpoints": [ @@ -11183,7 +10962,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8e-06, "output_cost_per_token_batches": 4e-06, @@ -11215,7 +10993,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 4e-05, "search_context_cost_per_query": { @@ -11253,7 +11030,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "supports_prompt_caching": true, @@ -11270,7 +11046,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_batches": 2.2e-06, @@ -11287,7 +11062,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 8e-05, "output_cost_per_token_batches": 4e-05, @@ -11318,7 +11092,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 8e-05, "output_cost_per_token_batches": 4e-05, @@ -11349,7 +11122,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "supported_endpoints": [ @@ -11380,7 +11152,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_batches": 2.2e-06, @@ -11425,7 +11196,6 @@ "input_cost_per_token": 1.43e-07, "litellm_provider": "azure", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/" @@ -11435,7 +11205,6 @@ "input_cost_per_token": 2.2e-08, "litellm_provider": "azure", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/" @@ -11445,7 +11214,6 @@ "input_cost_per_token": 1.1e-07, "litellm_provider": "azure", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://azure.microsoft.com/en-us/pricing/details/azure-openai/" @@ -11496,7 +11264,6 @@ "litellm_provider": "azure", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8.8e-06, "output_cost_per_token_batches": 4.4e-06, @@ -11534,7 +11301,6 @@ "litellm_provider": "azure", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.76e-06, "output_cost_per_token_batches": 8.8e-07, @@ -11570,7 +11336,6 @@ "litellm_provider": "azure", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4.4e-07, "output_cost_per_token_batches": 2.2e-07, @@ -11604,7 +11369,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_batches": 5.5e-06, @@ -11625,7 +11389,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_batches": 5.5e-06, @@ -11645,7 +11408,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_batches": 5.5e-06, @@ -11664,7 +11426,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6.6e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -11683,7 +11444,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6.6e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -11702,7 +11462,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 2.2e-05, "output_cost_per_token": 2.64e-06, @@ -11722,7 +11481,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 0.00022, "output_cost_per_token": 2.2e-05, @@ -11742,7 +11500,6 @@ "litellm_provider": "azure", "max_input_tokens": 16000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 8.8e-05, "output_cost_per_token": 2.2e-05, @@ -11772,7 +11529,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_batches": 5.5e-06, @@ -11812,7 +11568,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-06, "output_cost_per_token_batches": 1.1e-06, @@ -11850,7 +11605,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.4e-07, "output_cost_per_token_batches": 2.2e-07, @@ -11888,7 +11642,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "supported_endpoints": [ @@ -11929,7 +11682,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -11961,7 +11713,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 2.2e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -11994,7 +11745,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6.6e-05, "output_cost_per_token_batches": 3.3e-05, @@ -12013,7 +11763,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6.6e-05, "output_cost_per_token_batches": 3.3e-05, @@ -12031,7 +11780,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -12049,7 +11797,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8.8e-06, "output_cost_per_token_batches": 4.4e-06, @@ -12082,7 +11829,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8.8e-06, "output_cost_per_token_batches": 4.4e-06, @@ -12115,7 +11861,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -12133,7 +11878,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -12151,7 +11895,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -12172,7 +11915,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -12196,7 +11938,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "azure_ai", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -12207,7 +11948,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "azure_ai", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -12219,7 +11959,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 256000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12237,7 +11976,6 @@ "azure_ai/FLUX-1.1-pro": { "litellm_provider": "azure_ai", "max_input_tokens": 5000, - "max_tokens": 5000, "mode": "image_generation", "output_cost_per_image": 0.04, "source": "https://techcommunity.microsoft.com/blog/azure-ai-foundry-blog/black-forest-labs-flux-1-kontext-pro-and-flux1-1-pro-now-available-in-azure-ai-f/4434659", @@ -12248,7 +11986,6 @@ "azure_ai/FLUX.1-Kontext-pro": { "litellm_provider": "azure_ai", "max_input_tokens": 5000, - "max_tokens": 5000, "mode": "image_generation", "output_cost_per_image": 0.04, "source": "https://azure.microsoft.com/en-us/pricing/details/ai-foundry-models/black-forest-labs/", @@ -12259,7 +11996,6 @@ "azure_ai/flux.2-pro": { "litellm_provider": "azure_ai", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "image_generation", "output_cost_per_image": 0.04, "source": "https://learn.microsoft.com/en-us/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure", @@ -12271,7 +12007,6 @@ "input_cost_per_pixel": 5e-08, "litellm_provider": "azure_ai", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "image_generation", "source": "https://azure.microsoft.com/en-us/pricing/details/ai-foundry-models/black-forest-labs/", "supported_endpoints": [ @@ -12293,7 +12028,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "mode": "chat", "output_cost_per_token": 1.85e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12308,7 +12042,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 3.828e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12324,7 +12057,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3.52e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12340,7 +12072,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 202800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.84e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12355,7 +12086,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.84e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12370,7 +12100,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 7.26e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12385,7 +12114,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_token": 4.46e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12407,7 +12135,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 3.3e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12430,7 +12157,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12453,7 +12179,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12476,7 +12201,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-05, "reasoning_effort_levels": [ @@ -12505,7 +12229,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 1.32e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12520,7 +12243,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 512000, "max_output_tokens": 512000, - "max_tokens": 512000, "mode": "chat", "output_cost_per_token": 1.32e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12563,7 +12285,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 2.64e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12629,7 +12350,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 256000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12652,7 +12372,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.1e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure", @@ -12664,7 +12383,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 1e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12677,7 +12395,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 10000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 7.8e-07, "source": "https://azure.microsoft.com/en-us/blog/introducing-the-llama-4-herd-in-azure-ai-foundry-and-azure-databricks/", @@ -12691,7 +12408,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 8192, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 3.7e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12703,7 +12419,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 3.54e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12715,7 +12430,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6.8e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12728,7 +12442,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6.8e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12741,7 +12454,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 5.2e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12754,7 +12466,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 5.2e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12767,7 +12478,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12780,7 +12490,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12793,7 +12502,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6.4e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12806,7 +12514,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 5.2e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12819,7 +12526,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 5.2e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12832,7 +12538,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12846,7 +12551,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 131072, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12859,7 +12563,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 131072, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3.2e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12873,7 +12576,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 131072, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12885,7 +12587,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12927,7 +12628,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 131072, "max_output_tokens": 8182, - "max_tokens": 8182, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -12967,7 +12667,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 5.4e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -12981,7 +12680,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models" @@ -12993,7 +12691,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models" @@ -13004,7 +12701,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://techcommunity.microsoft.com/blog/azure-ai-foundry-blog/introducing-cohere-rerank-4-0-in-microsoft-foundry/4477076" @@ -13015,7 +12711,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://techcommunity.microsoft.com/blog/azure-ai-foundry-blog/introducing-cohere-rerank-4-0-in-microsoft-foundry/4477076" @@ -13025,7 +12720,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.68e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure", @@ -13040,7 +12734,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.68e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure", @@ -13056,7 +12749,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4.56e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -13068,7 +12760,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 3.48e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -13084,7 +12775,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 5.1e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -13101,7 +12791,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 1.32e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure", @@ -13114,7 +12803,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "azure_ai", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 3072, @@ -13134,7 +12822,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://learn.microsoft.com/en-us/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure", @@ -13151,7 +12838,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -13172,7 +12858,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -13192,7 +12877,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -13211,7 +12895,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -13228,7 +12911,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", "supports_function_calling": true, @@ -13242,7 +12924,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", "supports_function_calling": true, @@ -13256,7 +12937,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 256000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure", @@ -13271,7 +12951,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.00971, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models" @@ -13282,7 +12961,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 70000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -13294,7 +12972,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -13311,7 +12988,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -13335,7 +13011,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 4e-08, "source": "https://marketplace.microsoft.com/en/marketplace/apps/000-000.ministral-3b-2410-offer?tab=Overview", @@ -13348,7 +13023,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 32000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 1.2e-05, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -13361,7 +13035,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -13373,7 +13046,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://marketplace.microsoft.com/en/marketplace/apps/000-000.mistral-ai-large-2407-offer?tab=Overview", @@ -13385,7 +13057,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 256000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -13399,7 +13070,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 131072, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2e-06, "supports_assistant_prefill": true, @@ -13412,7 +13082,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 131072, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -13424,7 +13093,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 32000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://learn.microsoft.com/en-us/azure/foundry/openai/concepts/retired-models", @@ -13437,7 +13105,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -13451,7 +13118,6 @@ "litellm_provider": "text-completion-openai", "max_input_tokens": 16384, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 4e-07, "output_cost_per_token_batches": 2e-07, @@ -13463,7 +13129,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_tool_choice": true }, @@ -13473,7 +13138,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_tool_choice": true }, @@ -13483,7 +13147,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_tool_choice": true }, @@ -13493,7 +13156,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_tool_choice": true }, @@ -13518,7 +13180,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -13528,7 +13189,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat" }, "bedrock/ap-northeast-1/1-month-commitment/anthropic.claude-v2:1": { @@ -13537,7 +13197,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -13547,7 +13206,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -13557,7 +13215,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat" }, "bedrock/ap-northeast-1/6-month-commitment/anthropic.claude-v2:1": { @@ -13566,7 +13223,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -13575,7 +13231,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 7.55e-06, "supports_tool_choice": true @@ -13585,7 +13240,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_tool_choice": true @@ -13595,7 +13249,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_tool_choice": true @@ -13606,7 +13259,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 163840, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2.22e-06, "output_cost_per_token_flex": 1.11e-06, @@ -13626,7 +13278,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -13644,7 +13295,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -13664,7 +13314,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3.03e-06, "output_cost_per_token_flex": 1.52e-06, @@ -13678,7 +13327,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3.6e-06, "output_cost_per_token_flex": 1.8e-06, @@ -13696,7 +13344,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -13715,7 +13362,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_flex": 1.25e-06, @@ -13729,7 +13375,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3e-06, "output_cost_per_token_flex": 1.5e-06, @@ -13749,7 +13394,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4.2e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-70b-instruct.md" @@ -13760,7 +13404,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-8b-instruct.md" @@ -13771,7 +13414,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 163840, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2.22e-06, "output_cost_per_token_flex": 1.11e-06, @@ -13791,7 +13433,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -13809,7 +13450,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -13829,7 +13469,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 2.94e-06, "output_cost_per_token_flex": 1.47e-06, @@ -13843,7 +13482,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3.6e-06, "output_cost_per_token_flex": 1.8e-06, @@ -13861,7 +13499,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -13879,7 +13516,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -13898,7 +13534,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 163840, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2.22e-06, "output_cost_per_token_flex": 1.11e-06, @@ -13918,7 +13553,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -13936,7 +13570,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -13955,7 +13588,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3.6e-06, "output_cost_per_token_flex": 1.8e-06, @@ -13973,7 +13605,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -13991,7 +13622,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4.03e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-70b-instruct.md" @@ -14002,7 +13632,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6.9e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-8b-instruct.md" @@ -14013,7 +13642,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 163840, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2.22e-06, "output_cost_per_token_flex": 1.11e-06, @@ -14033,7 +13661,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -14051,7 +13678,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -14070,7 +13696,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3.6e-06, "output_cost_per_token_flex": 1.8e-06, @@ -14088,7 +13713,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -14098,7 +13722,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat" }, "bedrock/eu-central-1/1-month-commitment/anthropic.claude-v2:1": { @@ -14107,7 +13730,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -14117,7 +13739,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -14127,7 +13748,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat" }, "bedrock/eu-central-1/6-month-commitment/anthropic.claude-v2:1": { @@ -14136,7 +13756,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -14145,7 +13764,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 8.38e-06, "supports_tool_choice": true @@ -14155,7 +13773,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05 }, @@ -14164,7 +13781,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_tool_choice": true @@ -14176,7 +13792,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -14194,7 +13809,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -14213,7 +13827,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -14231,7 +13844,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 3.78e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-70b-instruct.md" @@ -14242,7 +13854,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6.5e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-8b-instruct.md" @@ -14254,7 +13865,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -14272,7 +13882,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -14291,7 +13900,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -14309,7 +13917,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4.55e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-70b-instruct.md" @@ -14320,7 +13927,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.8e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-8b-instruct.md" @@ -14332,7 +13938,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.86e-06, "output_cost_per_token_flex": 9.3e-07, @@ -14350,7 +13955,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -14369,7 +13973,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 256000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.01e-06, "output_cost_per_token_flex": 5.05e-07, @@ -14388,7 +13991,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.86e-06, "output_cost_per_token_flex": 9.3e-07, @@ -14406,7 +14008,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.6e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mistral-7b-instruct.md", @@ -14417,7 +14018,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.56e-05, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mistral-large.md", @@ -14429,7 +14029,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 9.1e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mixtral-8x7b-instruct.md", @@ -14442,7 +14041,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -14460,7 +14058,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -14479,7 +14076,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -14496,7 +14092,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "metadata": { "notes": "Anthropic via Invoke route does not currently support pdf input." }, @@ -14515,7 +14110,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 5.88e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-70b-instruct.md" @@ -14526,7 +14120,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.01e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-8b-instruct.md" @@ -14537,7 +14130,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 163840, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2.22e-06, "output_cost_per_token_flex": 1.11e-06, @@ -14557,7 +14149,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -14575,7 +14166,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -14595,7 +14185,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3.03e-06, "output_cost_per_token_flex": 1.52e-06, @@ -14609,7 +14198,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3.6e-06, "output_cost_per_token_flex": 1.8e-06, @@ -14627,7 +14215,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.44e-06, "output_cost_per_token_flex": 7.2e-07, @@ -14645,7 +14232,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -14655,7 +14241,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat" }, "bedrock/us-east-1/1-month-commitment/anthropic.claude-v2:1": { @@ -14664,7 +14249,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -14674,7 +14258,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -14684,7 +14267,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat" }, "bedrock/us-east-1/6-month-commitment/anthropic.claude-v2:1": { @@ -14693,7 +14275,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -14702,7 +14283,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-06, "supports_tool_choice": true @@ -14712,7 +14292,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_tool_choice": true @@ -14722,7 +14301,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_tool_choice": true @@ -14733,7 +14311,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 3.5e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-70b-instruct.md" @@ -14744,7 +14321,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-8b-instruct.md" @@ -14755,7 +14331,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mistral-7b-instruct.md", @@ -14766,7 +14341,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.2e-05, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mistral-large.md", @@ -14778,7 +14352,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mixtral-8x7b-instruct.md", @@ -14790,7 +14363,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 163840, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.85e-06, "output_cost_per_token_flex": 9.25e-07, @@ -14810,7 +14382,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_flex": 6e-07, @@ -14830,7 +14401,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "supports_function_calling": true, "supports_system_messages": true, @@ -14847,7 +14417,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_flex": 1.25e-06, @@ -14861,7 +14430,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3e-06, "output_cost_per_token_flex": 1.5e-06, @@ -14879,7 +14447,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_flex": 6e-07, @@ -14897,7 +14464,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 163840, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.85e-06, "output_cost_per_token_flex": 9.25e-07, @@ -14917,7 +14483,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_flex": 6e-07, @@ -14935,7 +14500,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-minimax-minimax-m2-5.html", "supports_function_calling": true, @@ -14955,7 +14519,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_flex": 1.25e-06, @@ -14969,7 +14532,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3e-06, "output_cost_per_token_flex": 1.5e-06, @@ -14987,7 +14549,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_flex": 6e-07, @@ -15005,7 +14566,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 3.84e-06, "supports_function_calling": true, @@ -15019,7 +14579,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "bedrock", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536 @@ -15028,7 +14587,6 @@ "input_cost_per_token": 2e-07, "litellm_provider": "bedrock", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024 @@ -15038,7 +14596,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 42000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.7e-06 }, @@ -15047,7 +14604,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 42000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 4e-07 }, @@ -15056,7 +14612,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 42000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.5e-06 }, @@ -15069,7 +14624,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.8e-05, "supports_assistant_prefill": true, @@ -15098,7 +14652,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.8e-05, "supports_assistant_prefill": true, @@ -15119,7 +14672,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8000, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 3.5e-06, "supports_pdf_input": true @@ -15129,7 +14681,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8000, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 2.65e-06, "supports_pdf_input": true @@ -15137,7 +14688,6 @@ "bedrock/us-gov-west-1/amazon.nova-2-multimodal-embeddings-v1:0": { "litellm_provider": "bedrock", "max_input_tokens": 8172, - "max_tokens": 8172, "mode": "embedding", "input_cost_per_token": 1.62e-07, "input_cost_per_image": 7.2e-05, @@ -15156,7 +14706,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 2.88e-07, "supports_function_calling": true, @@ -15172,7 +14721,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 1.68e-07, "supports_function_calling": true, @@ -15186,7 +14734,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 3.84e-06, "supports_function_calling": true, @@ -15200,7 +14747,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "bedrock", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536 @@ -15209,7 +14755,6 @@ "input_cost_per_token": 1.1e-07, "litellm_provider": "bedrock", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024 @@ -15219,7 +14764,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 42000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.6e-06 }, @@ -15228,7 +14772,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 42000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 4e-07 }, @@ -15237,7 +14780,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 42000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.5e-06 }, @@ -15250,7 +14792,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.8e-05, "supports_assistant_prefill": true, @@ -15279,7 +14820,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.8e-05, "supports_assistant_prefill": true, @@ -15300,7 +14840,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8000, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 3.5e-06, "supports_pdf_input": true @@ -15310,7 +14849,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8000, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 6e-07, "supports_pdf_input": true @@ -15321,7 +14859,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 3.5e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-70b-instruct.md" @@ -15332,7 +14869,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-8b-instruct.md" @@ -15343,7 +14879,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -15353,7 +14888,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat" }, "bedrock/us-west-2/1-month-commitment/anthropic.claude-v2:1": { @@ -15362,7 +14896,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -15372,7 +14905,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -15382,7 +14914,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat" }, "bedrock/us-west-2/6-month-commitment/anthropic.claude-v2:1": { @@ -15391,7 +14922,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "supports_tool_choice": true }, @@ -15400,7 +14930,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-06, "supports_tool_choice": true @@ -15410,7 +14939,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_tool_choice": true @@ -15420,7 +14948,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 100000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.4e-05, "supports_tool_choice": true @@ -15431,7 +14958,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mistral-7b-instruct.md", @@ -15442,7 +14968,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.2e-05, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mistral-large.md", @@ -15454,7 +14979,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mixtral-8x7b-instruct.md", @@ -15466,7 +14990,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 163840, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.85e-06, "output_cost_per_token_flex": 9.25e-07, @@ -15486,7 +15009,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_flex": 6e-07, @@ -15506,7 +15028,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 196000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "supports_function_calling": true, "supports_system_messages": true, @@ -15523,7 +15044,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_flex": 1.25e-06, @@ -15537,7 +15057,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3e-06, "output_cost_per_token_flex": 1.5e-06, @@ -15555,7 +15074,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_flex": 6e-07, @@ -15574,7 +15092,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4e-06, "supports_assistant_prefill": true, @@ -15659,12 +15176,31 @@ "/v1/images/generations" ] }, + "cerebras/llama-3.1-70b": { + "input_cost_per_token": 6e-07, + "litellm_provider": "cerebras", + "max_input_tokens": 128000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 6e-07, + "supports_function_calling": true, + "supports_tool_choice": true + }, + "cerebras/llama-3.1-8b": { + "input_cost_per_token": 1e-07, + "litellm_provider": "cerebras", + "max_input_tokens": 128000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 1e-07, + "supports_function_calling": true, + "supports_tool_choice": true + }, "cerebras/llama-3.3-70b": { "input_cost_per_token": 8.5e-07, "litellm_provider": "cerebras", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-06, "supports_function_calling": true, @@ -15675,7 +15211,6 @@ "litellm_provider": "cerebras", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -15686,7 +15221,6 @@ "litellm_provider": "cerebras", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-07, "supports_function_calling": true, @@ -15697,7 +15231,6 @@ "litellm_provider": "cerebras", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 7.5e-07, "source": "https://www.cerebras.ai/blog/openai-gpt-oss-120b-runs-fastest-on-cerebras", @@ -15712,7 +15245,6 @@ "litellm_provider": "cerebras", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 8e-07, "source": "https://inference-docs.cerebras.ai/support/pricing", @@ -15725,7 +15257,6 @@ "litellm_provider": "cerebras", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.49e-06, "source": "https://api.cerebras.ai/public/v1/models/qwen-3.8-27b", @@ -15741,7 +15272,6 @@ "litellm_provider": "nlp_cloud", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 5e-07 }, @@ -15772,7 +15302,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "output_cost_per_token_batches": 2.5e-06, @@ -15799,7 +15328,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "output_cost_per_token_batches": 2.5e-06, @@ -15828,7 +15356,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 7.5e-06, @@ -15862,7 +15389,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 7.5e-06, @@ -15898,7 +15424,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -15942,7 +15467,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -15989,7 +15513,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 7.5e-06, @@ -16033,7 +15556,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -16062,7 +15584,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -16096,7 +15617,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -16133,7 +15653,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -16176,7 +15695,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -16219,7 +15737,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -16263,7 +15780,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -16307,7 +15823,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_batches": 2.5e-05, @@ -16352,7 +15867,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_batches": 2.5e-05, @@ -16398,7 +15912,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "output_cost_per_token_batches": 1e-05, @@ -16444,7 +15957,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -16492,7 +16004,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -16608,7 +16119,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 3072, "max_output_tokens": 3072, - "max_tokens": 3072, "mode": "chat", "output_cost_per_token": 1.923e-06, "rpm": 300 @@ -16618,7 +16128,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 2048, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 1.923e-06, "rpm": 300 @@ -16628,7 +16137,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.923e-06, "rpm": 300 @@ -16638,7 +16146,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.923e-06, "rpm": 300 @@ -16648,7 +16155,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 7.5e-07, "rpm": 300, @@ -16660,7 +16166,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "rpm": 300 @@ -16670,7 +16175,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 80000, "max_output_tokens": 80000, - "max_tokens": 80000, "mode": "chat", "output_cost_per_token": 3.35e-07, "rpm": 300 @@ -16680,7 +16184,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3e-08, "rpm": 300 @@ -16690,7 +16193,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 15000, "max_output_tokens": 15000, - "max_tokens": 15000, "mode": "chat", "output_cost_per_token": 0.0, "rpm": 300 @@ -16701,7 +16203,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4e-06, "rpm": 20, @@ -16713,7 +16214,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 80000, "max_output_tokens": 80000, - "max_tokens": 80000, "mode": "chat", "output_cost_per_token": 4.881e-06, "rpm": 300, @@ -16724,7 +16224,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 2.87e-07, "rpm": 300 @@ -16734,7 +16233,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 60000, "max_output_tokens": 60000, - "max_tokens": 60000, "mode": "chat", "output_cost_per_token": 2.01e-07, "rpm": 300 @@ -16745,7 +16243,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4e-06, "rpm": 20, @@ -16757,7 +16254,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4e-07, "rpm": 300, @@ -16769,7 +16265,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "rpm": 300 @@ -16779,7 +16274,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 24000, "max_output_tokens": 24000, - "max_tokens": 24000, "mode": "chat", "output_cost_per_token": 2.253e-06, "rpm": 300, @@ -16790,7 +16284,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 131000, "max_output_tokens": 131000, - "max_tokens": 131000, "mode": "chat", "output_cost_per_token": 1.12e-07, "rpm": 300, @@ -16801,7 +16294,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1e-06, "rpm": 300 @@ -16812,7 +16304,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4.4e-06, "rpm": 20, @@ -16824,7 +16315,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 1.5e-06, "rpm": 300, @@ -16836,7 +16326,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.55e-07, "rpm": 300 @@ -16846,7 +16335,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3.35e-07, "rpm": 300, @@ -16858,7 +16346,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 3500, "max_output_tokens": 3500, - "max_tokens": 3500, "mode": "chat", "output_cost_per_token": 0.0, "rpm": 300 @@ -16868,7 +16355,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 3e-07, "rpm": 300, @@ -16880,7 +16366,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.55e-07, "rpm": 300, @@ -16891,7 +16376,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6.76e-07, "rpm": 300, @@ -16902,7 +16386,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-07, "rpm": 300, @@ -16914,7 +16397,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 131000, "max_output_tokens": 131000, - "max_tokens": 131000, "mode": "chat", "output_cost_per_token": 8.5e-07, "rpm": 300, @@ -16925,7 +16407,6 @@ "litellm_provider": "cloudflare", "max_input_tokens": 24000, "max_output_tokens": 24000, - "max_tokens": 24000, "mode": "chat", "output_cost_per_token": 1e-06, "rpm": 300, @@ -16936,7 +16417,6 @@ "litellm_provider": "codestral", "max_input_tokens": 32000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://docs.mistral.ai/capabilities/code_generation/", @@ -16948,7 +16428,6 @@ "litellm_provider": "codestral", "max_input_tokens": 32000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://docs.mistral.ai/capabilities/code_generation/", @@ -16960,7 +16439,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -16971,7 +16449,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -16981,7 +16458,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "bedrock", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -16991,7 +16467,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "bedrock", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -17001,7 +16476,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "bedrock", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536, @@ -17012,7 +16486,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "bedrock", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536, @@ -17023,7 +16496,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "bedrock", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536, @@ -17034,7 +16506,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "cohere", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536, @@ -17046,7 +16517,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "cohere", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 2048, @@ -17057,7 +16527,6 @@ "input_cost_per_token": 8e-08, "litellm_provider": "cohere", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 2048, @@ -17079,7 +16548,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-cohere-rerank-3-5.md" @@ -17089,7 +16557,6 @@ "litellm_provider": "cohere_chat", "max_input_tokens": 256000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1e-05, "supports_function_calling": true, @@ -17101,7 +16568,6 @@ "litellm_provider": "cohere_chat", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "source": "https://docs.cohere.com/docs/models" }, @@ -17110,7 +16576,6 @@ "litellm_provider": "cohere_chat", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://docs.cohere.com/docs/command-a-plus", @@ -17125,7 +16590,6 @@ "litellm_provider": "cohere", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 2e-06 }, @@ -17134,7 +16598,6 @@ "litellm_provider": "cohere_chat", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -17145,7 +16608,6 @@ "litellm_provider": "cohere_chat", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1e-05, "supports_function_calling": true, @@ -17156,7 +16618,6 @@ "litellm_provider": "cohere_chat", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://docs.cohere.com/v2/docs/command-r7b", @@ -17169,7 +16630,7 @@ "input_cost_per_token": 1.12e-06, "litellm_provider": "coralbricks", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.coralbricks.ai/pricing", @@ -17192,7 +16653,7 @@ "input_cost_per_token": 1.12e-06, "litellm_provider": "coralbricks", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.coralbricks.ai/pricing", @@ -17215,7 +16676,7 @@ "input_cost_per_token": 1.12e-06, "litellm_provider": "coralbricks", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.coralbricks.ai/pricing", @@ -17238,7 +16699,7 @@ "input_cost_per_token": 1e-08, "litellm_provider": "coralbricks", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.coralbricks.ai/pricing", @@ -17261,7 +16722,7 @@ "input_cost_per_token": 1e-08, "litellm_provider": "coralbricks", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.coralbricks.ai/pricing", @@ -17284,7 +16745,7 @@ "input_cost_per_token": 1e-08, "litellm_provider": "coralbricks", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.coralbricks.ai/pricing", @@ -17307,7 +16768,6 @@ "litellm_provider": "openai", "max_input_tokens": 8192, "max_output_tokens": 1024, - "max_tokens": 1024, "mode": "chat", "output_cost_per_token": 1.2e-05, "supported_endpoints": [ @@ -17337,7 +16797,6 @@ "litellm_provider": "openai", "max_input_tokens": 8192, "max_output_tokens": 1024, - "max_tokens": 1024, "mode": "chat", "output_cost_per_token": 1.2e-05, "supported_endpoints": [ @@ -17368,7 +16827,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4.2e-07, "source": "https://api-docs.deepseek.com/quick_start/pricing", @@ -17390,7 +16848,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 4.2e-07, "source": "https://api-docs.deepseek.com/quick_start/pricing", @@ -17412,7 +16869,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17428,7 +16884,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17444,7 +16899,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 4.8e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17460,7 +16914,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 202745, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17476,7 +16929,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17492,7 +16944,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 229376, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17508,7 +16959,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 1000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17520,7 +16970,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17549,7 +16998,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17579,7 +17027,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 30720, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6.4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17592,7 +17039,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17605,7 +17051,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 129024, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17618,7 +17063,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 4e-06, "output_cost_per_token": 1.2e-06, @@ -17632,7 +17076,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 4e-06, "output_cost_per_token": 1.2e-06, @@ -17645,7 +17088,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17676,7 +17118,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17707,7 +17148,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17739,7 +17179,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 5e-07, "output_cost_per_token": 2e-07, @@ -17753,7 +17192,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 1000000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -17766,7 +17204,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 1000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 5e-07, "output_cost_per_token": 2e-07, @@ -17780,7 +17217,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 1000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 5e-07, "output_cost_per_token": 2e-07, @@ -17793,7 +17229,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17804,7 +17239,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17853,7 +17287,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17898,7 +17331,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17947,7 +17379,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -17992,7 +17423,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 258048, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -18029,7 +17459,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 258048, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -18066,7 +17495,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 258048, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -18104,7 +17532,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -18116,7 +17543,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -18129,7 +17555,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.6e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -18142,7 +17567,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -18156,7 +17580,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 6.4e-07, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -18169,7 +17592,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2.87e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -18182,7 +17604,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 260096, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -18220,7 +17641,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 991808, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -18254,7 +17674,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 991808, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 7.5e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -18268,7 +17687,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 991808, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -18304,7 +17722,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 991808, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -18322,7 +17739,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 991808, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.7e-07, "source": "https://docs.modelstudio.console.alibabacloud.com/en/model-studio/model-pricing", @@ -18341,7 +17757,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 991808, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.7e-07, "source": "https://docs.modelstudio.console.alibabacloud.com/en/model-studio/model-pricing", @@ -18360,7 +17775,6 @@ "litellm_provider": "dashscope", "max_input_tokens": 98304, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -18681,7 +18095,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://www.qwencloud.com/models", @@ -18697,7 +18110,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://www.qwencloud.com/models", @@ -18713,7 +18125,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 4.8e-06, "source": "https://www.qwencloud.com/models", @@ -18729,7 +18140,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 202745, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.qwencloud.com/models", @@ -18745,7 +18155,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.qwencloud.com/models", @@ -18761,7 +18170,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 229376, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://www.qwencloud.com/models", @@ -18777,7 +18185,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 1000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://www.qwencloud.com/models", @@ -18789,7 +18196,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -18818,7 +18224,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -18848,7 +18253,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 30720, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6.4e-06, "source": "https://www.qwencloud.com/models", @@ -18861,7 +18265,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.qwencloud.com/models", @@ -18874,7 +18277,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 129024, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.qwencloud.com/models", @@ -18887,7 +18289,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 4e-06, "output_cost_per_token": 1.2e-06, @@ -18901,7 +18302,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 4e-06, "output_cost_per_token": 1.2e-06, @@ -18914,7 +18314,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -18945,7 +18344,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -18976,7 +18374,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19008,7 +18405,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 5e-07, "output_cost_per_token": 2e-07, @@ -19022,7 +18418,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 1000000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://www.qwencloud.com/models", @@ -19035,7 +18430,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 1000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 5e-07, "output_cost_per_token": 2e-07, @@ -19049,7 +18443,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 1000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 5e-07, "output_cost_per_token": 2e-07, @@ -19062,7 +18455,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19073,7 +18465,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19122,7 +18513,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19167,7 +18557,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19216,7 +18605,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19261,7 +18649,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 258048, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19298,7 +18685,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 258048, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19335,7 +18721,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 258048, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19373,7 +18758,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.qwencloud.com/models", @@ -19385,7 +18769,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.qwencloud.com/models", @@ -19398,7 +18781,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.6e-06, "source": "https://www.qwencloud.com/models", @@ -19411,7 +18793,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://www.qwencloud.com/models", @@ -19425,7 +18806,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 6.4e-07, "source": "https://www.qwencloud.com/models", @@ -19438,7 +18818,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2.87e-06, "source": "https://www.qwencloud.com/models", @@ -19451,7 +18830,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 260096, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19489,7 +18867,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 991808, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19523,7 +18900,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 991808, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 7.5e-06, "source": "https://www.qwencloud.com/models", @@ -19537,7 +18913,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 991808, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.qwencloud.com/models", "supports_function_calling": true, @@ -19573,7 +18948,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 991808, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://www.qwencloud.com/models", @@ -19589,7 +18963,6 @@ "litellm_provider": "qwencloud", "max_input_tokens": 98304, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://www.qwencloud.com/models", @@ -19910,7 +19283,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -19926,7 +19298,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -19942,7 +19313,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 4.8e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -19958,7 +19328,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 202745, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -19974,7 +19343,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -19990,7 +19358,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 229376, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -20006,7 +19373,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 1000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -20018,7 +19384,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20047,7 +19412,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20077,7 +19441,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 30720, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6.4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -20090,7 +19453,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -20103,7 +19465,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 129024, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -20116,7 +19477,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 4e-06, "output_cost_per_token": 1.2e-06, @@ -20130,7 +19490,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 4e-06, "output_cost_per_token": 1.2e-06, @@ -20143,7 +19502,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20174,7 +19532,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20205,7 +19562,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 997952, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20237,7 +19593,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 5e-07, "output_cost_per_token": 2e-07, @@ -20251,7 +19606,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 1000000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -20264,7 +19618,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 1000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 5e-07, "output_cost_per_token": 2e-07, @@ -20278,7 +19631,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 1000000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_reasoning_token": 5e-07, "output_cost_per_token": 2e-07, @@ -20291,7 +19643,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 129024, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20302,7 +19653,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20351,7 +19701,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20396,7 +19745,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20445,7 +19793,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 997952, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20490,7 +19837,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 258048, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20527,7 +19873,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 258048, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20564,7 +19909,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 258048, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20602,7 +19946,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -20614,7 +19957,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -20627,7 +19969,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.6e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -20640,7 +19981,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -20654,7 +19994,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 6.4e-07, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -20667,7 +20006,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2.87e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/model-pricing", @@ -20680,7 +20018,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 260096, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20718,7 +20055,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 991808, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20752,7 +20088,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 991808, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 7.5e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -20766,7 +20101,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 991808, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "source": "https://www.alibabacloud.com/help/en/model-studio/models", "supports_function_calling": true, @@ -20802,7 +20136,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 991808, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -20820,7 +20153,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 991808, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.7e-07, "source": "https://docs.modelstudio.console.alibabacloud.com/en/model-studio/model-pricing", @@ -20839,7 +20171,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 991808, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.7e-07, "source": "https://docs.modelstudio.console.alibabacloud.com/en/model-studio/model-pricing", @@ -20858,7 +20189,6 @@ "litellm_provider": "qwen_ai_platform", "max_input_tokens": 98304, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://www.alibabacloud.com/help/en/model-studio/models", @@ -21180,7 +20510,6 @@ "input_dbu_cost_per_token": 1.429e-06, "litellm_provider": "databricks", "max_input_tokens": 512, - "max_tokens": 512, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070, based on databricks Llama 3.1 70B conversion. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21198,7 +20527,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -21227,7 +20555,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -21257,7 +20584,6 @@ "litellm_provider": "databricks", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21281,7 +20607,6 @@ "litellm_provider": "databricks", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21305,7 +20630,6 @@ "litellm_provider": "databricks", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21329,7 +20653,6 @@ "litellm_provider": "databricks", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21354,7 +20677,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21379,7 +20701,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -21406,7 +20727,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -21434,7 +20754,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -21463,7 +20782,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -21498,7 +20816,6 @@ "litellm_provider": "databricks", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21522,7 +20839,6 @@ "litellm_provider": "databricks", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21545,7 +20861,6 @@ "litellm_provider": "databricks", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21569,7 +20884,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21594,7 +20908,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields. Introductory launch rates of 28.571 input / 142.857 output / 35.714 cache write / 2.857 cache read DBU run through 2026-08-31; the standard rates are listed here because entries carry no expiry date." }, @@ -21623,7 +20936,6 @@ "token_count_framing": 97, "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Billing reads the per-token dollar fields; the '*_dbu_cost_per_token' fields are the published Databricks rates, kept for reference. Context/max output are the DeepSeek-published model limits (1M context, 384K max output)." }, @@ -21656,7 +20968,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Billing reads the per-token dollar fields; the '*_dbu_cost_per_token' fields are the published Databricks rates, kept for reference. Context/max output are the DeepSeek-published model limits (1M context, 384K max output)." }, @@ -21685,7 +20996,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21719,7 +21029,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21754,7 +21063,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21782,7 +21090,6 @@ "litellm_provider": "databricks", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "metadata": { "notes": "Databricks DBU rates not yet published for this model; endpoint metadata only." }, @@ -21803,7 +21110,6 @@ "litellm_provider": "databricks", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "metadata": { "notes": "Databricks DBU rates not yet published for this model; endpoint metadata only." }, @@ -21828,7 +21134,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21861,7 +21166,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21893,7 +21197,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -21909,7 +21212,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Databricks DBU rates not yet published for this model; endpoint metadata only." }, @@ -21934,7 +21236,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Databricks DBU rates not yet published for this model; endpoint metadata only." }, @@ -21963,7 +21264,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -21995,7 +21295,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22026,7 +21325,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22059,7 +21357,6 @@ "litellm_provider": "databricks", "max_input_tokens": 128000, "max_output_tokens": 32000, - "max_tokens": 32000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22076,7 +21373,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Billing reads the per-token dollar fields; the '*_dbu_cost_per_token' fields are the published Databricks rates, kept for reference." }, @@ -22104,7 +21400,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22135,7 +21430,6 @@ "litellm_provider": "databricks", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22165,7 +21459,6 @@ "litellm_provider": "databricks", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22185,7 +21478,6 @@ "litellm_provider": "databricks", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22205,7 +21497,6 @@ "litellm_provider": "databricks", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22225,7 +21516,6 @@ "litellm_provider": "databricks", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22245,7 +21535,6 @@ "litellm_provider": "databricks", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22274,7 +21563,6 @@ "litellm_provider": "databricks", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22303,7 +21591,6 @@ "litellm_provider": "databricks", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22332,7 +21619,6 @@ "litellm_provider": "databricks", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields. Rates reflect OpenAI's promotional pricing in effect through November 21, 2026; afterwards input, cache and Batch rates are 25% higher and output rates 50% higher." }, @@ -22361,7 +21647,6 @@ "litellm_provider": "databricks", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22390,7 +21675,6 @@ "litellm_provider": "databricks", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22419,7 +21703,6 @@ "litellm_provider": "databricks", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22448,7 +21731,6 @@ "litellm_provider": "databricks", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22477,7 +21759,6 @@ "litellm_provider": "databricks", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22497,7 +21778,6 @@ "litellm_provider": "databricks", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22517,7 +21797,6 @@ "litellm_provider": "databricks", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22534,7 +21813,6 @@ "litellm_provider": "databricks", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22576,7 +21854,6 @@ "input_dbu_cost_per_token": 1.857e-06, "litellm_provider": "databricks", "max_input_tokens": 8192, - "max_tokens": 8192, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070, based on databricks Llama 3.1 70B conversion. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22623,7 +21900,6 @@ "token_count_framing": 100, "max_input_tokens": 1000000, "max_output_tokens": 1048576, - "max_tokens": 1048576, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Billing reads the per-token dollar fields; the '*_dbu_cost_per_token' fields are the published Databricks rates, kept for reference." }, @@ -22657,7 +21933,6 @@ "litellm_provider": "databricks", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Databricks documentation now provides both DBU costs (_dbu_cost_per_token) and dollar costs(_cost_per_token)." }, @@ -22675,7 +21950,6 @@ "litellm_provider": "databricks", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22692,7 +21966,6 @@ "litellm_provider": "databricks", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "metadata": { "notes": "Input/output cost per token is dbu cost * $0.070, based on databricks Llama 3.1 70B conversion. Number provided for reference, '*_dbu_cost_per_token' used in actual calculation." }, @@ -22710,7 +21983,6 @@ "litellm_provider": "databricks", "max_input_tokens": 262144, "max_output_tokens": 25000, - "max_tokens": 25000, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22760,7 +22032,6 @@ "input_dbu_cost_per_token": 2.86e-07, "litellm_provider": "databricks", "max_input_tokens": 32768, - "max_tokens": 32768, "metadata": { "notes": "Costs per token are the published Global DBU rates times $0.070 per DBU. The '*_dbu_cost_per_token' fields are provided for reference; cost calculation reads the dollar '*_cost_per_token' fields." }, @@ -22806,7 +22077,6 @@ "litellm_provider": "text-completion-openai", "max_input_tokens": 16384, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 2e-06, "output_cost_per_token_batches": 1e-06, @@ -23401,7 +22671,6 @@ ] }, "deepinfra/Gryphe/MythoMax-L2-13b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 4e-07, @@ -23413,7 +22682,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/NousResearch/Hermes-3-Llama-3.1-405B": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-06, @@ -23424,7 +22692,6 @@ "supports_function_calling": true }, "deepinfra/NousResearch/Hermes-3-Llama-3.1-70B": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 7e-07, @@ -23435,7 +22702,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/QwQ-32B": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.5e-07, @@ -23446,7 +22712,6 @@ "supports_function_calling": true }, "deepinfra/Qwen/Qwen2.5-72B-Instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 3.6e-07, @@ -23458,7 +22723,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen2.5-7B-Instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 4e-08, @@ -23468,7 +22732,6 @@ "supports_tool_choice": false }, "deepinfra/Qwen/Qwen2.5-VL-32B-Instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2e-07, @@ -23480,7 +22743,6 @@ "supports_function_calling": true }, "deepinfra/Qwen/Qwen3-14B": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 1.2e-07, @@ -23492,7 +22754,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-235B-A22B": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 1.8e-07, @@ -23503,7 +22764,6 @@ "supports_function_calling": true }, "deepinfra/Qwen/Qwen3-235B-A22B-Instruct-2507": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 9e-08, @@ -23515,7 +22775,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-235B-A22B-Thinking-2507": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 3e-07, @@ -23526,7 +22785,6 @@ "supports_function_calling": true }, "deepinfra/Qwen/Qwen3-30B-A3B": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 1.2e-07, @@ -23538,7 +22796,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-32B": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 8e-08, @@ -23550,7 +22807,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-Coder-480B-A35B-Instruct": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 4e-07, @@ -23561,7 +22817,6 @@ "supports_function_calling": true }, "deepinfra/Qwen/Qwen3-Coder-480B-A35B-Instruct-Turbo": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 3e-07, @@ -23575,7 +22830,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-Next-80B-A3B-Instruct": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 9e-08, @@ -23587,7 +22841,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-Next-80B-A3B-Thinking": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.4e-07, @@ -23598,7 +22851,6 @@ "supports_function_calling": true }, "deepinfra/Sao10K/L3-8B-Lunaris-v1-Turbo": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 4e-08, @@ -23608,7 +22860,6 @@ "supports_tool_choice": false }, "deepinfra/Sao10K/L3.1-70B-Euryale-v2.2": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 8.5e-07, @@ -23619,7 +22870,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Sao10K/L3.3-70B-Euryale-v2.3": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 6.5e-07, @@ -23629,7 +22879,6 @@ "supports_tool_choice": false }, "deepinfra/allenai/olmOCR-7B-0725-FP8": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2.7e-07, @@ -23639,7 +22888,6 @@ "supports_tool_choice": false }, "deepinfra/anthropic/claude-3-7-sonnet-latest": { - "max_tokens": 200000, "max_input_tokens": 200000, "max_output_tokens": 200000, "input_cost_per_token": 3.3e-06, @@ -23651,7 +22899,6 @@ "supports_function_calling": true }, "deepinfra/anthropic/claude-4-opus": { - "max_tokens": 200000, "max_input_tokens": 200000, "max_output_tokens": 200000, "input_cost_per_token": 1.65e-05, @@ -23662,7 +22909,6 @@ "supports_function_calling": true }, "deepinfra/anthropic/claude-4-sonnet": { - "max_tokens": 200000, "max_input_tokens": 200000, "max_output_tokens": 200000, "input_cost_per_token": 3.3e-06, @@ -23673,7 +22919,6 @@ "supports_function_calling": true }, "deepinfra/deepseek-ai/DeepSeek-R1": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 7e-07, @@ -23684,7 +22929,6 @@ "supports_function_calling": true }, "deepinfra/deepseek-ai/DeepSeek-R1-0528": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 5e-07, @@ -23696,7 +22940,6 @@ "supports_function_calling": true }, "deepinfra/deepseek-ai/DeepSeek-R1-0528-Turbo": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-06, @@ -23707,7 +22950,6 @@ "supports_function_calling": true }, "deepinfra/deepseek-ai/DeepSeek-R1-Distill-Llama-70B": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -23717,7 +22959,6 @@ "supports_tool_choice": false }, "deepinfra/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2.7e-07, @@ -23728,7 +22969,6 @@ "supports_function_calling": true }, "deepinfra/deepseek-ai/DeepSeek-R1-Turbo": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 1e-06, @@ -23739,7 +22979,6 @@ "supports_function_calling": true }, "deepinfra/deepseek-ai/DeepSeek-V3": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 3.2e-07, @@ -23751,7 +22990,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/deepseek-ai/DeepSeek-V3-0324": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 2.4e-07, @@ -23765,7 +23003,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/deepseek-ai/DeepSeek-V3.1": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 2.5e-07, @@ -23779,7 +23016,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/deepseek-ai/DeepSeek-V3.1-Terminus": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 2.7e-07, @@ -23791,7 +23027,6 @@ "supports_function_calling": true }, "deepinfra/google/gemini-2.5-flash": { - "max_tokens": 1000000, "max_input_tokens": 1000000, "max_output_tokens": 1000000, "input_cost_per_token": 3e-07, @@ -23807,7 +23042,6 @@ "supports_audio_input": true }, "deepinfra/google/gemini-2.5-pro": { - "max_tokens": 1000000, "max_input_tokens": 1000000, "max_output_tokens": 1000000, "input_cost_per_token": 1.25e-06, @@ -23822,7 +23056,6 @@ "supports_audio_input": true }, "deepinfra/google/gemma-3-12b-it": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 5e-08, @@ -23834,7 +23067,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemma-3-27b-it": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 8e-08, @@ -23846,7 +23078,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemma-3-4b-it": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 5e-08, @@ -23858,7 +23089,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/meta-llama/Llama-3.2-11B-Vision-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 4.9e-08, @@ -23868,7 +23098,6 @@ "supports_tool_choice": false }, "deepinfra/meta-llama/Llama-3.2-3B-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-08, @@ -23879,7 +23108,6 @@ "supports_function_calling": true }, "deepinfra/meta-llama/Llama-3.3-70B-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2.3e-07, @@ -23890,7 +23118,6 @@ "supports_function_calling": true }, "deepinfra/meta-llama/Llama-3.3-70B-Instruct-Turbo": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -23902,7 +23129,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 2e-07, @@ -23914,7 +23140,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/meta-llama/Llama-4-Scout-17B-16E-Instruct": { - "max_tokens": 327680, "max_input_tokens": 327680, "max_output_tokens": 327680, "input_cost_per_token": 1e-07, @@ -23926,7 +23151,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/meta-llama/Llama-Guard-3-8B": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 5.5e-08, @@ -23936,7 +23160,6 @@ "supports_tool_choice": false }, "deepinfra/meta-llama/Llama-Guard-4-12B": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 1.8e-07, @@ -23946,7 +23169,6 @@ "supports_tool_choice": false }, "deepinfra/meta-llama/Meta-Llama-3-8B-Instruct": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 3e-08, @@ -23957,7 +23179,6 @@ "supports_function_calling": true }, "deepinfra/meta-llama/Meta-Llama-3.1-70B-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 4e-07, @@ -23968,7 +23189,6 @@ "supports_function_calling": true }, "deepinfra/meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 4e-07, @@ -23980,7 +23200,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/meta-llama/Meta-Llama-3.1-8B-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 3e-08, @@ -23991,7 +23210,6 @@ "supports_function_calling": true }, "deepinfra/meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-08, @@ -24003,7 +23221,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/microsoft/WizardLM-2-8x22B": { - "max_tokens": 65536, "max_input_tokens": 65536, "max_output_tokens": 65536, "input_cost_per_token": 4.8e-07, @@ -24013,7 +23230,6 @@ "supports_tool_choice": false }, "deepinfra/microsoft/phi-4": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 7e-08, @@ -24024,7 +23240,6 @@ "supports_function_calling": true }, "deepinfra/mistralai/Mistral-Nemo-Instruct-2407": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.9e-08, @@ -24036,7 +23251,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/mistralai/Mistral-Small-24B-Instruct-2501": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 5e-08, @@ -24047,7 +23261,6 @@ "supports_function_calling": true }, "deepinfra/mistralai/Mistral-Small-3.2-24B-Instruct-2506": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 7.5e-08, @@ -24058,7 +23271,6 @@ "supports_function_calling": true }, "deepinfra/mistralai/Mixtral-8x7B-Instruct-v0.1": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 4e-07, @@ -24069,7 +23281,6 @@ "supports_function_calling": true }, "deepinfra/moonshotai/Kimi-K2-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 5e-07, @@ -24080,7 +23291,6 @@ "supports_function_calling": true }, "deepinfra/moonshotai/Kimi-K2-Instruct-0905": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 5e-07, @@ -24092,7 +23302,6 @@ "supports_function_calling": true }, "deepinfra/nvidia/Llama-3.1-Nemotron-70B-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 6e-07, @@ -24103,7 +23312,6 @@ "supports_function_calling": true }, "deepinfra/nvidia/Llama-3.3-Nemotron-Super-49B-v1.5": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -24127,7 +23335,6 @@ "supports_prompt_caching": true }, "deepinfra/nvidia/NVIDIA-Nemotron-Nano-9B-v2": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 4e-08, @@ -24138,7 +23345,6 @@ "supports_function_calling": true }, "deepinfra/openai/gpt-oss-120b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 3.7e-08, @@ -24150,7 +23356,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/openai/gpt-oss-20b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 3e-08, @@ -24162,7 +23367,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/zai-org/GLM-4.5": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 4e-07, @@ -24181,7 +23385,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4.2e-07, "source": "https://api-docs.deepseek.com/quick_start/pricing", @@ -24204,7 +23407,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.8e-07, "supports_assistant_prefill": true, @@ -24219,7 +23421,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 65536, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.19e-06, "supports_assistant_prefill": true, @@ -24236,7 +23437,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 4.2e-07, "source": "https://api-docs.deepseek.com/quick_start/pricing", @@ -24261,7 +23461,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 65536, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.1e-06, "supports_assistant_prefill": true, @@ -24276,7 +23475,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "mode": "chat", "output_cost_per_token": 4e-07, "supports_assistant_prefill": true, @@ -24291,7 +23489,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.68e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-deepseek-deepseek-v3-1.html", @@ -24308,7 +23505,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 164000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.85e-06, "output_cost_per_token_batches": 9.25e-07, @@ -24328,7 +23524,6 @@ "litellm_provider": "nlp_cloud", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "completion", "output_cost_per_token": 5e-07 }, @@ -24337,7 +23532,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 98304, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 0.0, "supports_assistant_prefill": true, @@ -24351,7 +23545,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 0.0, "supports_assistant_prefill": true, @@ -24365,7 +23558,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 229376, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 0.0, "supports_assistant_prefill": true, @@ -24378,7 +23570,6 @@ "input_cost_per_token": 0.0, "litellm_provider": "volcengine", "max_input_tokens": 4096, - "max_tokens": 4096, "metadata": { "notes": "Volcengine Doubao embedding model - standard version with 2560 dimensions" }, @@ -24390,7 +23581,6 @@ "input_cost_per_token": 0.0, "litellm_provider": "volcengine", "max_input_tokens": 4096, - "max_tokens": 4096, "metadata": { "notes": "Volcengine Doubao embedding model - large version with 2048 dimensions" }, @@ -24402,7 +23592,6 @@ "input_cost_per_token": 0.0, "litellm_provider": "volcengine", "max_input_tokens": 4096, - "max_tokens": 4096, "metadata": { "notes": "Volcengine Doubao embedding model - text-240915 version with 4096 dimensions" }, @@ -24414,7 +23603,6 @@ "input_cost_per_token": 0.0, "litellm_provider": "volcengine", "max_input_tokens": 4096, - "max_tokens": 4096, "metadata": { "notes": "Volcengine Doubao embedding model - text-250515 version with 2048 dimensions" }, @@ -24426,7 +23614,6 @@ "input_cost_per_token": 0.0, "litellm_provider": "volcengine", "max_input_tokens": 4096, - "max_tokens": 4096, "metadata": { "notes": "Volcengine Doubao embedding model - text-240715 version with 2560 dimensions" }, @@ -24539,7 +23726,6 @@ "mode": "search" }, "sail/moonshotai/Kimi-K3": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 2.5e-06, @@ -24561,7 +23747,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/zai-org/GLM-5.3": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 9.8e-07, @@ -24583,7 +23768,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/zai-org/GLM-5.3-Flash": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 1.1e-07, @@ -24605,7 +23789,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/deepseek-ai/DeepSeek-V4-Pro-0813": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 9.2e-07, @@ -24627,7 +23810,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/deepseek-ai/DeepSeek-V4-Flash-0731": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 9e-08, @@ -24649,7 +23831,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/deepseek-ai/DeepSeek-V4.1-Flash": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 9e-08, @@ -24671,7 +23852,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/moonshotai/Kimi-K2.6": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1e-06, @@ -24694,7 +23874,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/google/gemma-4-31B-it": { - "max_tokens": 256000, "max_input_tokens": 256000, "max_output_tokens": 256000, "input_cost_per_token": 4e-07, @@ -24717,7 +23896,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/nvidia/Gemma-4-31B-IT-NVFP4": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.4e-07, @@ -24740,7 +23918,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/google/gemma-4-12B-it": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 3e-07, @@ -24762,7 +23939,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/openai/gpt-oss-120b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 6e-08, @@ -24778,7 +23954,6 @@ "source": "https://docs.sailresearch.com/models" }, "sail/Qwen/Qwen3.6-35B-A3B": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 5e-08, @@ -25017,7 +24192,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "cohere", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -25026,7 +24200,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "cohere", "max_input_tokens": 512, - "max_tokens": 512, "metadata": { "notes": "'supports_image_input' is a deprecated field. Use 'supports_embedding_image_input' instead." }, @@ -25039,7 +24212,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "cohere", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "supports_embedding_image_input": true @@ -25048,7 +24220,6 @@ "input_cost_per_token": 0.0001, "litellm_provider": "cohere", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "supports_embedding_image_input": true @@ -25059,7 +24230,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 3.12e-07, "supports_function_calling": true, @@ -25075,7 +24245,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 1.84e-07, "supports_function_calling": true, @@ -25091,7 +24260,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 4.2e-06, "output_cost_per_token_flex": 2.1e-06, @@ -25108,7 +24276,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4e-06, "supports_assistant_prefill": true, @@ -25131,7 +24298,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5.5e-06, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -25159,7 +24325,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -25175,7 +24340,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -25194,7 +24358,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -25214,7 +24377,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_function_calling": true, @@ -25231,7 +24393,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "search_context_cost_per_query": { @@ -25262,7 +24423,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "search_context_cost_per_query": { @@ -25293,7 +24453,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -25333,7 +24492,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.65e-05, "search_context_cost_per_query": { @@ -25367,7 +24525,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.3e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-2-1b-instruct.md", @@ -25380,7 +24537,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.9e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-2-3b-instruct.md", @@ -25392,7 +24548,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-pixtral-large.md", @@ -27658,14 +26813,12 @@ "litellm_provider": "featherless_ai", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat" }, "featherless_ai/featherless-ai/Qwerky-QwQ-32B": { "litellm_provider": "featherless_ai", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat" }, "fireworks-ai-4.1b-to-16b": { @@ -27713,7 +26866,6 @@ "input_cost_per_token": 1.6e-08, "litellm_provider": "fireworks_ai-embedding-models", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://fireworks.ai/pricing" @@ -27723,7 +26875,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 65536, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://fireworks.ai/pricing", @@ -27736,7 +26887,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 163840, "max_output_tokens": 20480, - "max_tokens": 20480, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://fireworks.ai/pricing", @@ -27748,7 +26898,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 163840, "max_output_tokens": 160000, - "max_tokens": 160000, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://fireworks.ai/pricing", @@ -27760,7 +26909,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 163840, "max_output_tokens": 20480, - "max_tokens": 20480, "mode": "chat", "output_cost_per_token": 2.19e-06, "source": "https://fireworks.ai/pricing", @@ -27772,7 +26920,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://fireworks.ai/pricing", @@ -27784,7 +26931,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://fireworks.ai/models/fireworks/deepseek-v3-0324", @@ -27796,7 +26942,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.68e-06, "source": "https://fireworks.ai/pricing", @@ -27809,7 +26954,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.68e-06, "source": "https://fireworks.ai/pricing", @@ -27822,7 +26966,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "mode": "chat", "output_cost_per_token": 1.68e-06, "source": "https://fireworks.ai/models/fireworks/deepseek-v3p2", @@ -27837,7 +26980,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 2.8e-07, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -27856,7 +26998,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3.96e-06, "output_cost_per_token_priority": 4.95e-06, @@ -27876,7 +27017,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3.96e-06, "output_cost_per_token_priority": 4.95e-06, @@ -27892,7 +27032,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://fireworks.ai/pricing", @@ -27905,7 +27044,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 96000, - "max_tokens": 96000, "mode": "chat", "output_cost_per_token": 2.19e-06, "source": "https://fireworks.ai/models/fireworks/glm-4p5", @@ -27919,7 +27057,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 96000, - "max_tokens": 96000, "mode": "chat", "output_cost_per_token": 8.8e-07, "source": "https://artificialanalysis.ai/models/glm-4-5-air", @@ -27934,7 +27071,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 202752, "max_output_tokens": 202800, - "max_tokens": 202800, "mode": "chat", "source": "https://fireworks.ai/pricing", "supports_function_calling": true, @@ -27948,7 +27084,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 202752, "max_output_tokens": 202800, - "max_tokens": 202800, "mode": "chat", "output_cost_per_token": 2.2e-06, "source": "https://fireworks.ai/models/fireworks/glm-4p7", @@ -27963,7 +27098,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 202752, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -27982,7 +27116,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_priority": 5.5e-06, @@ -28002,7 +27135,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_priority": 7.2e-07, @@ -28019,7 +27151,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -28034,7 +27165,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://fireworks.ai/models/fireworks/kimi-k2-instruct", @@ -28047,7 +27177,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://app.fireworks.ai/models/fireworks/kimi-k2-instruct-0905", @@ -28060,7 +27189,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://fireworks.ai/pricing", @@ -28075,7 +27203,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://fireworks.ai/pricing", @@ -28092,7 +27219,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-06, "output_cost_per_token_priority": 6e-06, @@ -28112,7 +27238,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-06, "output_cost_per_token_priority": 6e-06, @@ -28128,7 +27253,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://fireworks.ai/pricing", @@ -28141,7 +27265,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://fireworks.ai/pricing", @@ -28154,7 +27277,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://fireworks.ai/pricing", @@ -28168,7 +27290,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://fireworks.ai/pricing", @@ -28181,7 +27302,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://fireworks.ai/pricing", @@ -28194,7 +27314,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://fireworks.ai/pricing", @@ -28207,7 +27326,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 8.8e-07, "source": "https://fireworks.ai/pricing", @@ -28219,7 +27337,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://fireworks.ai/pricing", @@ -28232,7 +27349,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 196608, "max_output_tokens": 204800, - "max_tokens": 204800, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://fireworks.ai/models/fireworks/minimax-m2p1", @@ -28248,7 +27364,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 512000, "max_output_tokens": 512000, - "max_tokens": 512000, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_priority": 1.8e-06, @@ -28264,7 +27379,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 65536, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://fireworks.ai/pricing", @@ -28277,7 +27391,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://fireworks.ai/pricing", @@ -28290,7 +27403,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://fireworks.ai/pricing", @@ -28303,7 +27415,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://fireworks.ai/pricing", @@ -28317,7 +27428,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 2.8e-07, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -28333,7 +27443,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 202752, "max_output_tokens": 202800, - "max_tokens": 202800, "mode": "chat", "output_cost_per_token": 2.2e-06, "source": "https://fireworks.ai/models/fireworks/glm-4p7", @@ -28348,7 +27457,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 202752, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -28364,7 +27472,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 202800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 8.8e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -28383,7 +27490,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_priority": 5.5e-06, @@ -28403,7 +27509,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_priority": 7.2e-07, @@ -28420,7 +27525,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -28436,7 +27540,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://fireworks.ai/pricing", @@ -28453,7 +27556,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-06, "output_cost_per_token_priority": 6e-06, @@ -28471,7 +27573,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -28490,7 +27591,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-06, "output_cost_per_token_priority": 6e-06, @@ -28508,7 +27608,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -28524,7 +27623,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 196608, "max_output_tokens": 204800, - "max_tokens": 204800, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://fireworks.ai/models/fireworks/minimax-m2p1", @@ -28540,7 +27638,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 512000, "max_output_tokens": 512000, - "max_tokens": 512000, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_priority": 1.8e-06, @@ -28557,7 +27654,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.6e-06, "source": "https://api.fireworks.ai/v1/serverless/models", @@ -28571,7 +27667,6 @@ "input_cost_per_token": 8e-09, "litellm_provider": "fireworks_ai-embedding-models", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://fireworks.ai/pricing" @@ -28580,7 +27675,6 @@ "input_cost_per_token": 8e-09, "litellm_provider": "fireworks_ai-embedding-models", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://fireworks.ai/pricing" @@ -28589,7 +27683,6 @@ "input_cost_per_token": 8e-09, "litellm_provider": "fireworks_ai-embedding-models", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://fireworks.ai/pricing" @@ -28598,7 +27691,6 @@ "input_cost_per_token": 1.6e-08, "litellm_provider": "fireworks_ai-embedding-models", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "source": "https://fireworks.ai/pricing" @@ -28607,7 +27699,6 @@ "litellm_provider": "friendliai", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "input_cost_per_token": 1.5e-07, "output_cost_per_token": 5e-07, "cache_read_input_token_cost": 3e-08, @@ -28635,7 +27726,6 @@ "litellm_provider": "friendliai", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "input_cost_per_token": 1.26e-06, "output_cost_per_token": 3.96e-06, "cache_read_input_token_cost": 2.34e-07, @@ -28663,7 +27753,6 @@ "litellm_provider": "friendliai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "input_cost_per_token": 1.4e-07, "output_cost_per_token": 4e-07, "supports_prompt_caching": false, @@ -28686,7 +27775,6 @@ "litellm_provider": "friendliai", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "input_cost_per_token": 1.4e-06, "output_cost_per_token": 4.4e-06, "cache_read_input_token_cost": 2.6e-07, @@ -28713,7 +27801,6 @@ "litellm_provider": "friendliai", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "input_cost_per_token": 5e-07, "output_cost_per_token": 1.5e-06, "cache_read_input_token_cost": 2.5e-07, @@ -28737,7 +27824,6 @@ "litellm_provider": "friendliai", "max_input_tokens": 196608, "max_output_tokens": 196608, - "max_tokens": 196608, "input_cost_per_token": 3e-07, "output_cost_per_token": 1.2e-06, "cache_read_input_token_cost": 6e-08, @@ -28761,7 +27847,6 @@ "litellm_provider": "friendliai", "max_input_tokens": 202752, "max_output_tokens": 202752, - "max_tokens": 202752, "input_cost_per_token": 1.4e-06, "output_cost_per_token": 4.4e-06, "cache_read_input_token_cost": 2.6e-07, @@ -28788,7 +27873,6 @@ "litellm_provider": "text-completion-openai", "max_input_tokens": 16384, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 1.6e-06, "output_cost_per_token_batches": 9e-07, @@ -28801,7 +27885,6 @@ "litellm_provider": "text-completion-openai", "max_input_tokens": 16384, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 1.2e-05, "output_cost_per_token_batches": 6e-06, @@ -28814,7 +27897,6 @@ "litellm_provider": "openai", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_batches": 3e-06, @@ -28828,7 +27910,6 @@ "litellm_provider": "openai", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-06, "supports_system_messages": true, @@ -28840,7 +27921,6 @@ "litellm_provider": "openai", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-06, "supports_system_messages": true, @@ -28852,7 +27932,6 @@ "litellm_provider": "openai", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-06, "supports_system_messages": true, @@ -28864,7 +27943,6 @@ "litellm_provider": "openai", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-05, "source": "OpenAI needs to add pricing for this ft model, will be updated when added by OpenAI. Defaulting to base model pricing", @@ -28881,7 +27959,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -28902,7 +27979,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -28922,7 +27998,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_batches": 6e-07, @@ -28944,7 +28019,6 @@ "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_batches": 6e-06, @@ -28965,7 +28039,6 @@ "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3.2e-06, "output_cost_per_token_batches": 1.6e-06, @@ -28986,7 +28059,6 @@ "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-07, "output_cost_per_token_batches": 4e-07, @@ -29007,7 +28079,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 1.6e-05, "output_cost_per_token_batches": 8e-06, @@ -29030,7 +28101,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_reasoning_token": 2.5e-06, "output_cost_per_token": 2.5e-06, @@ -29087,7 +28157,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.039, "output_cost_per_image_token": 3e-05, @@ -29145,7 +28214,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.134, "output_cost_per_image_token": 0.00012, @@ -29199,7 +28267,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.134, "output_cost_per_image_token": 0.00012, @@ -29251,7 +28318,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.0672, "output_cost_per_image_token": 6e-05, @@ -29297,7 +28363,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.0672, "output_cost_per_image_token": 6e-05, @@ -29337,7 +28402,6 @@ "cache_read_input_token_cost_batches": 1.25e-08, "cache_read_input_token_cost_flex": 1.25e-08, "cache_read_input_token_cost_priority": 4.5e-08, - "deprecation_date": "2027-06-28", "input_cost_per_image": 0.00028, "input_cost_per_token": 2.5e-07, "input_cost_per_token_batches": 1.25e-07, @@ -29346,7 +28410,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "image_generation", "output_cost_per_image": 0.0336, "output_cost_per_image_token": 3e-05, @@ -29386,7 +28449,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 1.5e-06, "output_cost_per_token": 1.5e-06, @@ -29445,7 +28507,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 1.5e-06, "output_cost_per_token": 1.5e-06, @@ -29505,7 +28566,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 2.5e-06, "output_cost_per_token": 2.5e-06, @@ -29561,7 +28621,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_image": 0.134, "output_cost_per_image_token": 0.00012, @@ -29599,7 +28658,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_reasoning_token": 4e-07, "output_cost_per_token": 4e-07, @@ -29654,7 +28712,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_reasoning_token": 4e-07, "output_cost_per_token": 4e-07, @@ -29701,7 +28758,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_reasoning_token": 2.5e-06, "output_cost_per_token": 2.5e-06, @@ -29748,7 +28804,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2e-06, @@ -29794,7 +28849,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2e-06, @@ -29838,7 +28892,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2e-06, @@ -29890,7 +28943,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_200k_tokens": 1.5e-05, @@ -29952,7 +29004,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_image": 0.00012, "output_cost_per_token": 1.2e-05, @@ -30005,7 +29056,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_200k_tokens": 1.8e-05, @@ -30058,7 +29108,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_200k_tokens": 1.8e-05, @@ -30119,7 +29168,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_token": 3e-06, "output_cost_per_token_batches": 1.5e-06, @@ -30166,7 +29214,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_reasoning_token": 9e-06, "output_cost_per_token": 9e-06, @@ -30229,7 +29276,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -30290,7 +29336,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -30354,7 +29399,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -30410,7 +29454,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 7.5e-06, "output_cost_per_token": 7.5e-06, @@ -30458,7 +29501,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 4.5e-06, @@ -30501,7 +29543,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_image": 0.00012, "output_cost_per_token": 1.2e-05, @@ -30554,7 +29595,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_200k_tokens": 1.8e-05, @@ -30611,7 +29651,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2e-05, @@ -30644,7 +29683,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_reasoning_token": 2.5e-06, @@ -30682,7 +29720,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 5e-06, "output_cost_per_token": 5e-06, @@ -30729,7 +29766,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_200k_tokens": 1.5e-05, @@ -30753,7 +29789,6 @@ "input_cost_per_token_batches": 1.2e-07, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 2048, - "max_tokens": 2048, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -30770,7 +29805,6 @@ "input_cost_per_video_token_batches": 6e-06, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -30788,7 +29822,6 @@ "input_cost_per_video_token_batches": 6e-06, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -30807,7 +29840,6 @@ "input_cost_per_video_token_batches": 6e-06, "litellm_provider": "vertex_ai", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -30826,7 +29858,6 @@ "input_cost_per_video_token_batches": 6e-06, "litellm_provider": "vertex_ai", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -30840,7 +29871,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1000000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -30852,7 +29882,6 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "gemini", "max_input_tokens": 2048, - "max_tokens": 2048, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -30871,7 +29900,6 @@ "input_cost_per_video_token_batches": 6e-06, "litellm_provider": "gemini", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -30892,7 +29920,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.134, "output_cost_per_image_token": 0.00012, @@ -30938,7 +29965,6 @@ "litellm_provider": "gemini", "max_input_tokens": 65536, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "image_generation", "output_cost_per_image": 0.045, "output_cost_per_image_token": 6e-05, @@ -30990,7 +30016,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 1.5e-06, "output_cost_per_token": 1.5e-06, @@ -31050,7 +30075,6 @@ "input_cost_per_video_token_batches": 6e-06, "litellm_provider": "gemini", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -31067,7 +30091,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "rpm": 1000, @@ -31104,7 +30127,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "rpm": 1000, @@ -31137,16 +30159,19 @@ }, "gemini/gemini-2.5-flash": { "cache_read_input_audio_token_cost": 1e-07, + "cache_read_input_audio_token_cost_batches": 1e-07, + "cache_read_input_audio_token_cost_flex": 1e-07, + "cache_read_input_audio_token_cost_priority": 1.8e-07, "cache_read_input_token_cost": 3e-08, "cache_read_input_token_cost_batches": 3e-08, "cache_read_input_token_cost_flex": 3e-08, "cache_read_input_token_cost_priority": 5.4e-08, "input_cost_per_audio_token": 1e-06, + "input_cost_per_audio_token_flex": 5e-07, "input_cost_per_token": 3e-07, "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 2.5e-06, "output_cost_per_token": 2.5e-06, @@ -31209,7 +30234,6 @@ "supports_reasoning": false, "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.039, "output_cost_per_image_token": 3e-05, @@ -31261,7 +30285,6 @@ "litellm_provider": "gemini", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.134, "output_cost_per_image_token": 0.00012, @@ -31310,7 +30333,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.134, "output_cost_per_image_token": 0.00012, @@ -31353,7 +30375,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.045, "output_cost_per_image_token": 6e-05, @@ -31395,7 +30416,6 @@ "litellm_provider": "gemini", "max_input_tokens": 65536, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "image_generation", "output_cost_per_image": 0.0336, "output_cost_per_image_token": 3e-05, @@ -31434,7 +30454,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_batches": 6e-06, @@ -31466,16 +30485,19 @@ }, "gemini/gemini-2.5-flash-lite": { "cache_read_input_audio_token_cost": 3e-08, + "cache_read_input_audio_token_cost_batches": 3e-08, + "cache_read_input_audio_token_cost_flex": 3e-08, + "cache_read_input_audio_token_cost_priority": 5.4e-08, "cache_read_input_token_cost": 1e-08, "cache_read_input_token_cost_batches": 1e-08, "cache_read_input_token_cost_flex": 1e-08, "cache_read_input_token_cost_priority": 1.8e-08, "input_cost_per_audio_token": 3e-07, + "input_cost_per_audio_token_flex": 1.5e-07, "input_cost_per_token": 1e-07, "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 4e-07, "output_cost_per_token": 4e-07, @@ -31532,7 +30554,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -31591,7 +30612,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 2.5e-06, "output_cost_per_token": 2.5e-06, @@ -31650,7 +30670,6 @@ "litellm_provider": "gemini", "max_input_tokens": 8192, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "audio_speech", "output_cost_per_audio_token": 1e-05, "output_cost_per_token": 1e-05, @@ -31680,7 +30699,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_200k_tokens": 1.5e-05, @@ -31734,7 +30752,6 @@ "litellm_provider": "gemini", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_200k_tokens": 1.5e-05, @@ -31760,12 +30777,16 @@ }, "gemini/gemini-3.1-flash-lite": { "cache_read_input_audio_token_cost": 5e-08, + "cache_read_input_audio_token_cost_batches": 2.5e-08, + "cache_read_input_audio_token_cost_flex": 2.5e-08, + "cache_read_input_audio_token_cost_priority": 9e-08, "cache_read_input_token_cost": 2.5e-08, "cache_read_input_token_cost_batches": 1.25e-08, "cache_read_input_token_cost_flex": 1.25e-08, "cache_read_input_token_cost_priority": 4.5e-08, "deprecation_date": "2027-05-07", "input_cost_per_audio_token": 5e-07, + "input_cost_per_audio_token_flex": 2.5e-07, "input_cost_per_token": 2.5e-07, "input_cost_per_token_batches": 1.25e-07, "input_cost_per_token_flex": 1.25e-07, @@ -31773,7 +30794,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 1.5e-06, "output_cost_per_token": 1.5e-06, @@ -31835,7 +30855,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 2.5e-06, "output_cost_per_token": 2.5e-06, @@ -31886,15 +30905,18 @@ }, "gemini/gemini-3-flash-preview": { "cache_read_input_audio_token_cost": 1e-07, + "cache_read_input_audio_token_cost_batches": 1e-07, + "cache_read_input_audio_token_cost_flex": 1e-07, + "cache_read_input_audio_token_cost_priority": 1.8e-07, "cache_read_input_token_cost": 5e-08, "cache_read_input_token_cost_batches": 5e-08, "cache_read_input_token_cost_flex": 5e-08, "input_cost_per_audio_token": 1e-06, + "input_cost_per_audio_token_flex": 5e-07, "input_cost_per_token": 5e-07, "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3e-06, "output_cost_per_token": 3e-06, @@ -31956,7 +30978,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 9e-06, "output_cost_per_token": 9e-06, @@ -32021,7 +31042,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -32083,7 +31103,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -32146,7 +31165,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -32204,7 +31222,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 9e-06, "output_cost_per_token": 9e-06, @@ -32242,7 +31259,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_200k_tokens": 1.8e-05, @@ -32306,7 +31322,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_200k_tokens": 1.8e-05, @@ -32375,7 +31390,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_reasoning_token": 3e-06, "output_cost_per_token": 3e-06, @@ -32420,7 +31434,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_reasoning_token": 9e-06, "output_cost_per_token": 9e-06, @@ -32455,7 +31468,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_reasoning_token": 9e-06, "output_cost_per_token": 9e-06, @@ -32518,7 +31530,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -32579,7 +31590,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -32643,7 +31653,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -32699,7 +31708,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 7.5e-06, "output_cost_per_token": 7.5e-06, @@ -32746,7 +31754,6 @@ "litellm_provider": "gemini", "max_input_tokens": 8192, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2e-05, @@ -32781,7 +31788,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 8192, - "max_tokens": 8192, "metadata": { "notes": "Rate limits not documented for gemini-exp-1114. Assuming same as gemini-1.5-pro.", "supports_tool_choice": true @@ -32804,7 +31810,6 @@ "litellm_provider": "gemini", "max_input_tokens": 2097152, "max_output_tokens": 8192, - "max_tokens": 8192, "metadata": { "notes": "Rate limits not documented for gemini-exp-1206. Assuming same as gemini-1.5-pro.", "supports_tool_choice": true @@ -32825,7 +31830,7 @@ "input_cost_per_token": 3.5e-07, "litellm_provider": "gemini", "max_output_tokens": 8192, - "max_tokens": 8192, + "max_input_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.05e-06, "source": "https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models#foundation_models", @@ -32839,7 +31844,7 @@ "input_cost_per_token": 3.5e-07, "litellm_provider": "gemini", "max_output_tokens": 8192, - "max_tokens": 8192, + "max_input_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.05e-06, "source": "https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models#foundation_models", @@ -32863,7 +31868,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_character": 0, "output_cost_per_character_above_128k_tokens": 0, @@ -32883,7 +31887,6 @@ "litellm_provider": "gemini", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "supports_function_calling": true, "supports_reasoning": true, @@ -32899,7 +31902,6 @@ "litellm_provider": "gemini", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "supports_function_calling": true, "supports_reasoning": true, @@ -32935,7 +31937,6 @@ "litellm_provider": "gemini", "max_input_tokens": 32767, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_character": 0, "output_cost_per_character_above_128k_tokens": 0, @@ -32954,7 +31955,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_image": 0.04, "output_cost_per_token": 0, @@ -32979,7 +31979,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0, "source": "https://ai.google.dev/gemini-api/docs/pricing", @@ -33003,7 +32002,6 @@ "deprecation_date": "2026-10-22", "litellm_provider": "gemini", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.1, "output_cost_per_second_1080p": 0.12, @@ -33020,7 +32018,6 @@ "deprecation_date": "2026-10-22", "litellm_provider": "gemini", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.4, "output_cost_per_second_4k": 0.6, @@ -33036,7 +32033,6 @@ "deprecation_date": "2026-10-22", "litellm_provider": "gemini", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.05, "output_cost_per_second_1080p": 0.08, @@ -33051,7 +32047,6 @@ "gemini/veo-3.1-fast-generate-001": { "litellm_provider": "gemini", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.1, "output_cost_per_second_1080p": 0.12, @@ -33067,7 +32062,6 @@ "gemini/veo-3.1-generate-001": { "litellm_provider": "gemini", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.4, "output_cost_per_second_4k": 0.6, @@ -33086,7 +32080,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33109,7 +32102,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33132,7 +32124,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 128000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 5e-06, "supported_endpoints": [ @@ -33153,7 +32144,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 128000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_above_100k_tokens": 2.5e-06, @@ -33178,7 +32168,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33196,11 +32185,11 @@ "github_copilot/claude-opus-4.8-fast": { "cache_creation_input_token_cost": 1.25e-05, "cache_read_input_token_cost": 1e-06, + "deprecation_date": "2026-11-16", "input_cost_per_token": 1e-05, "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33223,7 +32212,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33245,7 +32233,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33268,7 +32255,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33290,7 +32276,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33313,7 +32298,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 3.75e-06, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33332,7 +32316,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3.75e-06, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33349,7 +32332,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 16384, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_function_calling": true }, @@ -33357,7 +32339,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 16384, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_function_calling": true }, @@ -33365,7 +32346,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_function_calling": true }, @@ -33373,7 +32353,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_function_calling": true }, @@ -33381,7 +32360,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 64000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_function_calling": true, "supports_parallel_function_calling": true @@ -33391,7 +32369,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/model-deprecation-history.yml", "supports_function_calling": true, @@ -33404,7 +32381,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/model-deprecation-history.yml", "supports_function_calling": true, @@ -33420,7 +32396,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 64000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_function_calling": true, "supports_parallel_function_calling": true, @@ -33430,7 +32405,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 64000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_function_calling": true, "supports_parallel_function_calling": true, @@ -33440,7 +32414,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 64000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "supports_function_calling": true, "supports_parallel_function_calling": true @@ -33449,7 +32422,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 64000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "supports_function_calling": true, "supports_parallel_function_calling": true, @@ -33459,7 +32431,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 64000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_function_calling": true, "supports_parallel_function_calling": true @@ -33468,7 +32439,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 64000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "supports_function_calling": true, "supports_parallel_function_calling": true @@ -33480,7 +32450,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://github.blog/changelog/2026-10-19-github-copilot-models-deprecated-on-october-19-2026", @@ -33495,7 +32464,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.4e-05, "supported_endpoints": [ @@ -33516,7 +32484,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_above_272k_tokens": 2.25e-05, @@ -33538,7 +32505,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 4.5e-06, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33560,7 +32526,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 3e-05, "output_cost_per_token_above_272k_tokens": 4.5e-05, @@ -33584,7 +32549,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.2e-06, "output_cost_per_token_above_200k_tokens": 1.8e-06, @@ -33608,7 +32572,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 2e-05, "output_cost_per_token_above_272k_tokens": 3e-05, @@ -33633,7 +32596,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_272k_tokens": 1.8e-05, @@ -33655,9 +32617,8 @@ "input_cost_per_token": 1e-05, "input_cost_per_token_above_272k_tokens": 2e-05, "litellm_provider": "github_copilot", - "max_input_tokens": 272000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 5e-05, "output_cost_per_token_above_272k_tokens": 7.5e-05, @@ -33679,9 +32640,8 @@ "input_cost_per_token": 1e-07, "input_cost_per_token_above_272k_tokens": 2e-07, "litellm_provider": "github_copilot", - "max_input_tokens": 272000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 5e-07, "output_cost_per_token_above_272k_tokens": 7.5e-07, @@ -33703,9 +32663,8 @@ "input_cost_per_token": 2e-06, "input_cost_per_token_above_272k_tokens": 4e-06, "litellm_provider": "github_copilot", - "max_input_tokens": 272000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -33727,9 +32686,8 @@ "input_cost_per_token": 2e-06, "input_cost_per_token_above_272k_tokens": 4e-06, "litellm_provider": "github_copilot", - "max_input_tokens": 272000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -33749,7 +32707,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 917504, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33767,7 +32724,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.2e-06, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -33782,19 +32738,16 @@ "github_copilot/text-embedding-3-small": { "litellm_provider": "github_copilot", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding" }, "github_copilot/text-embedding-3-small-inference": { "litellm_provider": "github_copilot", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding" }, "github_copilot/text-embedding-ada-002": { "litellm_provider": "github_copilot", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding" }, "chatgpt/gpt-6-sol": { @@ -33806,7 +32759,6 @@ ], "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "source": "https://developers.openai.com/api/docs/pricing", "supports_function_calling": true, "supports_max_reasoning_effort": true, @@ -33827,7 +32779,6 @@ ], "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "source": "https://developers.openai.com/api/docs/pricing", "supports_function_calling": true, "supports_max_reasoning_effort": true, @@ -33848,7 +32799,6 @@ ], "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "source": "https://developers.openai.com/api/docs/pricing", "supports_function_calling": true, "supports_max_reasoning_effort": true, @@ -33869,7 +32819,6 @@ ], "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "source": "https://developers.openai.com/api/docs/pricing", "supports_function_calling": true, "supports_max_reasoning_effort": true, @@ -33886,7 +32835,6 @@ "source": "https://platform.openai.com/docs/models/gpt-5.5", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/chat/completions", @@ -33906,7 +32854,6 @@ "source": "https://platform.openai.com/docs/models/gpt-5.6-luna", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/chat/completions", @@ -33926,7 +32873,6 @@ "source": "https://platform.openai.com/docs/models/gpt-5.6-sol", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/chat/completions", @@ -33946,7 +32892,6 @@ "source": "https://platform.openai.com/docs/models/gpt-5.6-terra", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/chat/completions", @@ -33965,7 +32910,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/chat/completions", @@ -33985,7 +32929,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/responses" @@ -34003,7 +32946,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/responses" @@ -34021,7 +32963,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/responses" @@ -34035,7 +32976,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "responses", "supported_endpoints": [ "/v1/chat/completions", @@ -34050,7 +32990,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "responses", "supported_endpoints": [ "/v1/chat/completions", @@ -34066,7 +33005,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/responses" @@ -34081,7 +33019,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "responses", "supported_endpoints": [ "/v1/chat/completions", @@ -34101,7 +33038,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "supported_endpoints": [ "/v1/responses" @@ -34116,7 +33052,6 @@ "litellm_provider": "chatgpt", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "responses", "supported_endpoints": [ "/v1/responses" @@ -34132,7 +33067,6 @@ "litellm_provider": "gigachat", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true, @@ -34143,7 +33077,6 @@ "litellm_provider": "gigachat", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true, @@ -34155,7 +33088,6 @@ "litellm_provider": "gigachat", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true, @@ -34166,7 +33098,6 @@ "input_cost_per_token": 0.0, "litellm_provider": "gigachat", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024 @@ -34175,7 +33106,6 @@ "input_cost_per_token": 0.0, "litellm_provider": "gigachat", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024 @@ -34184,7 +33114,6 @@ "input_cost_per_token": 0.0, "litellm_provider": "gigachat", "max_input_tokens": 4096, - "max_tokens": 4096, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 2560 @@ -34193,7 +33122,6 @@ "input_cost_per_token": 0.0, "litellm_provider": "gigachat", "max_input_tokens": 4096, - "max_tokens": 4096, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 2048 @@ -34203,7 +33131,6 @@ "litellm_provider": "gmi", "max_input_tokens": 409600, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 2.5e-05, "supports_function_calling": true, @@ -34215,7 +33142,6 @@ "litellm_provider": "gmi", "max_input_tokens": 409600, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -34226,7 +33152,6 @@ "litellm_provider": "gmi", "max_input_tokens": 409600, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -34237,7 +33162,6 @@ "litellm_provider": "gmi", "max_input_tokens": 409600, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_function_calling": true, @@ -34248,7 +33172,6 @@ "litellm_provider": "gmi", "max_input_tokens": 409600, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.4e-05, "supports_function_calling": true @@ -34258,7 +33181,6 @@ "litellm_provider": "gmi", "max_input_tokens": 409600, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1e-05, "supports_function_calling": true @@ -34268,7 +33190,6 @@ "litellm_provider": "gmi", "max_input_tokens": 409600, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1e-05, "supports_function_calling": true @@ -34278,7 +33199,6 @@ "litellm_provider": "gmi", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "supports_function_calling": true, @@ -34289,7 +33209,6 @@ "litellm_provider": "gmi", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -34300,7 +33219,6 @@ "litellm_provider": "gmi", "max_input_tokens": 163840, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 4e-07, "supports_function_calling": true @@ -34310,7 +33228,6 @@ "litellm_provider": "gmi", "max_input_tokens": 163840, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 8.8e-07, "supports_function_calling": true @@ -34320,7 +33237,6 @@ "litellm_provider": "gmi", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3e-06, "supports_function_calling": true, @@ -34332,7 +33248,6 @@ "litellm_provider": "gmi", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06 }, @@ -34341,7 +33256,6 @@ "litellm_provider": "gmi", "max_input_tokens": 196608, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06 }, @@ -34373,7 +33287,6 @@ "litellm_provider": "baseten", "max_input_tokens": 200000, "max_output_tokens": 200000, - "max_tokens": 200000, "mode": "chat", "output_cost_per_token": 2.2e-06, "source": "https://inference.baseten.co/v1/models", @@ -34418,7 +33331,6 @@ "litellm_provider": "baseten", "max_input_tokens": 128072, "max_output_tokens": 128072, - "max_tokens": 128072, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inference.baseten.co/v1/models", @@ -34448,7 +33360,6 @@ "litellm_provider": "gmi", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.4e-06, "supports_vision": true @@ -34458,7 +33369,6 @@ "litellm_provider": "gmi", "max_input_tokens": 202752, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 2e-06 }, @@ -34471,7 +33381,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2.9e-07, "output_cost_per_token_batches": 1.5e-07, @@ -34493,7 +33402,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 3.8e-07, "output_cost_per_token_batches": 1.9e-07, @@ -34515,7 +33423,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 8e-08, "output_cost_per_token_batches": 4e-08, @@ -34547,7 +33454,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -34587,7 +33493,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -34621,7 +33526,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -34653,7 +33557,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 1.25e-06, @@ -34674,7 +33577,6 @@ "litellm_provider": "openai", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://developers.openai.com/api/docs/pricing", @@ -34690,7 +33592,6 @@ "litellm_provider": "openai", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-06, "output_cost_per_token_batches": 7.5e-07, @@ -34708,7 +33609,6 @@ "litellm_provider": "openai", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2e-06, "output_cost_per_token_batches": 2e-06, @@ -34725,7 +33625,6 @@ "litellm_provider": "openai", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 4e-06, "supports_prompt_caching": true, @@ -34738,7 +33637,6 @@ "litellm_provider": "text-completion-openai", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 2e-06, "source": "https://developers.openai.com/api/docs/pricing" @@ -34748,7 +33646,6 @@ "litellm_provider": "text-completion-openai", "max_input_tokens": 8192, "max_output_tokens": 4097, - "max_tokens": 4097, "mode": "completion", "output_cost_per_token": 2e-06 }, @@ -34758,7 +33655,6 @@ "litellm_provider": "openai", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-05, "supports_function_calling": true, @@ -34773,7 +33669,6 @@ "litellm_provider": "openai", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-05, "output_cost_per_token_batches": 3e-05, @@ -34789,7 +33684,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3e-05, "supports_function_calling": true, @@ -34804,7 +33698,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3e-05, "supports_function_calling": true, @@ -34822,7 +33715,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3e-05, "output_cost_per_token_batches": 1.5e-05, @@ -34844,7 +33736,6 @@ "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "output_cost_per_token_batches": 4e-06, @@ -34888,7 +33779,6 @@ "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "output_cost_per_token_priority": 1.4e-05, @@ -34931,7 +33821,6 @@ "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.6e-06, "output_cost_per_token_batches": 8e-07, @@ -34975,7 +33864,6 @@ "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.6e-06, "output_cost_per_token_priority": 2.8e-06, @@ -35019,7 +33907,6 @@ "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-07, "output_cost_per_token_batches": 2e-07, @@ -35057,7 +33944,6 @@ "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-07, "output_cost_per_token_priority": 8e-07, @@ -35094,7 +33980,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -35117,7 +34002,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 7.5e-06, @@ -35141,7 +34025,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_priority": 1.7e-05, @@ -35166,7 +34049,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_priority": 1.7e-05, @@ -35188,7 +34070,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 8e-05, "output_cost_per_token": 1e-05, @@ -35206,7 +34087,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 8e-05, "output_cost_per_token": 1e-05, @@ -35224,7 +34104,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1e-05, @@ -35261,7 +34140,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1e-05, @@ -35296,7 +34174,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1e-05, @@ -35334,7 +34211,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -35372,7 +34248,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -35409,7 +34284,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -35450,7 +34324,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -35480,7 +34353,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_priority": 1e-06, @@ -35507,7 +34379,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 6e-07, @@ -35527,7 +34398,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -35545,7 +34415,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -35572,7 +34441,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -35653,7 +34521,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -35680,7 +34547,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -36234,7 +35100,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -36280,7 +35145,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "source": "https://developers.openai.com/api/docs/models/gpt-5-codex", @@ -36315,7 +35179,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_priority": 2e-05, @@ -36365,7 +35228,6 @@ "litellm_provider": "openai", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 2e-06, "source": "https://developers.openai.com/api/docs/models/gpt-5.1-codex-mini", @@ -36396,7 +35258,6 @@ "litellm_provider": "openai", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "source": "https://developers.openai.com/api/docs/models/gpt-5.1-codex-max", @@ -36428,7 +35289,6 @@ "litellm_provider": "openai", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1e-05, "source": "https://developers.openai.com/api/docs/models/gpt-5.1-codex", @@ -36460,7 +35320,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://developers.openai.com/api/docs/models/gpt-5.1-chat-latest", @@ -36495,7 +35354,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_priority": 2e-05, @@ -36547,7 +35405,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.4e-05, "output_cost_per_token_priority": 2.8e-05, @@ -36598,7 +35455,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.4e-05, "source": "https://developers.openai.com/api/docs/models/gpt-5.2-codex", @@ -36630,7 +35486,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.4e-05, "source": "https://developers.openai.com/api/docs/models/gpt-5.2-chat-latest", @@ -36665,7 +35520,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.4e-05, "output_cost_per_token_priority": 2.8e-05, @@ -36715,7 +35569,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.000168, "output_cost_per_token_batches": 8.4e-05, @@ -36757,7 +35610,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.000168, "output_cost_per_token_batches": 8.4e-05, @@ -36795,6 +35647,16 @@ }, "gpt-6-astra": { "cache_creation_input_token_cost": 1.25e-05, + "cache_creation_input_token_cost_above_12hr": 2.5e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 5e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches": 2.5e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": 2.5e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": 0.0001, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_ultrafast": 0.0003, + "cache_creation_input_token_cost_above_12hr_batches": 1.25e-05, + "cache_creation_input_token_cost_above_12hr_flex": 1.25e-05, + "cache_creation_input_token_cost_above_12hr_priority": 5e-05, + "cache_creation_input_token_cost_above_12hr_ultrafast": 0.00015, "cache_creation_input_token_cost_above_272k_tokens": 2.5e-05, "cache_creation_input_token_cost_above_272k_tokens_flex": 1.25e-05, "cache_creation_input_token_cost_above_272k_tokens_priority": 5e-05, @@ -36827,7 +35689,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_above_272k_tokens": 7.5e-05, @@ -36880,6 +35741,14 @@ }, "gpt-6-sol": { "cache_creation_input_token_cost": 2.5e-06, + "cache_creation_input_token_cost_above_12hr": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 1e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": 2e-05, + "cache_creation_input_token_cost_above_12hr_batches": 2.5e-06, + "cache_creation_input_token_cost_above_12hr_flex": 2.5e-06, + "cache_creation_input_token_cost_above_12hr_priority": 1e-05, "cache_creation_input_token_cost_above_272k_tokens": 5e-06, "cache_creation_input_token_cost_above_272k_tokens_flex": 2.5e-06, "cache_creation_input_token_cost_above_272k_tokens_priority": 1e-05, @@ -36906,7 +35775,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -36957,6 +35825,14 @@ }, "gpt-6-luna": { "cache_creation_input_token_cost": 1.25e-07, + "cache_creation_input_token_cost_above_12hr": 2.5e-07, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 5e-07, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches": 2.5e-07, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": 2.5e-07, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": 1e-06, + "cache_creation_input_token_cost_above_12hr_batches": 1.25e-07, + "cache_creation_input_token_cost_above_12hr_flex": 1.25e-07, + "cache_creation_input_token_cost_above_12hr_priority": 5e-07, "cache_creation_input_token_cost_decisions": 1.25e-07, "cache_creation_input_token_cost_above_272k_tokens": 2.5e-07, "cache_creation_input_token_cost_above_272k_tokens_decisions": 2.5e-07, @@ -36989,7 +35865,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_decisions": 0.0, @@ -37043,6 +35918,12 @@ }, "gpt-5.6": { "cache_creation_input_token_cost": 5e-06, + "cache_creation_input_token_cost_above_12hr": 1e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 2e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": 1e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": 4e-05, + "cache_creation_input_token_cost_above_12hr_flex": 5e-06, + "cache_creation_input_token_cost_above_12hr_priority": 2e-05, "cache_creation_input_token_cost_above_272k_tokens": 1e-05, "cache_creation_input_token_cost_above_272k_tokens_flex": 5e-06, "cache_creation_input_token_cost_above_272k_tokens_priority": 2e-05, @@ -37069,7 +35950,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "output_cost_per_token_above_272k_tokens": 3e-05, @@ -37117,6 +35997,14 @@ }, "gpt-5.6-sol": { "cache_creation_input_token_cost": 5e-06, + "cache_creation_input_token_cost_above_12hr": 1e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 2e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches": 1e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": 1e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": 4e-05, + "cache_creation_input_token_cost_above_12hr_batches": 5e-06, + "cache_creation_input_token_cost_above_12hr_flex": 5e-06, + "cache_creation_input_token_cost_above_12hr_priority": 2e-05, "cache_creation_input_token_cost_above_272k_tokens": 1e-05, "cache_creation_input_token_cost_above_272k_tokens_flex": 5e-06, "cache_creation_input_token_cost_above_272k_tokens_priority": 2e-05, @@ -37143,7 +36031,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "output_cost_per_token_above_272k_tokens": 3e-05, @@ -37193,6 +36080,14 @@ }, "gpt-5.6-terra": { "cache_creation_input_token_cost": 2.5e-06, + "cache_creation_input_token_cost_above_12hr": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 1e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": 2e-05, + "cache_creation_input_token_cost_above_12hr_batches": 2.5e-06, + "cache_creation_input_token_cost_above_12hr_flex": 2.5e-06, + "cache_creation_input_token_cost_above_12hr_priority": 1e-05, "cache_creation_input_token_cost_above_272k_tokens": 5e-06, "cache_creation_input_token_cost_above_272k_tokens_flex": 2.5e-06, "cache_creation_input_token_cost_above_272k_tokens_priority": 1e-05, @@ -37219,7 +36114,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_272k_tokens": 1.8e-05, @@ -37268,6 +36162,14 @@ }, "gpt-5.6-luna": { "cache_creation_input_token_cost": 2.5e-07, + "cache_creation_input_token_cost_above_12hr": 5e-07, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 1e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches": 5e-07, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": 5e-07, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": 2e-06, + "cache_creation_input_token_cost_above_12hr_batches": 2.5e-07, + "cache_creation_input_token_cost_above_12hr_flex": 2.5e-07, + "cache_creation_input_token_cost_above_12hr_priority": 1e-06, "cache_creation_input_token_cost_above_272k_tokens": 5e-07, "cache_creation_input_token_cost_above_272k_tokens_flex": 2.5e-07, "cache_creation_input_token_cost_above_272k_tokens_priority": 1e-06, @@ -37294,7 +36196,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_above_272k_tokens": 1.8e-06, @@ -37343,6 +36244,7 @@ }, "gpt-5.6-cyber": { "cache_creation_input_token_cost": 1.5625e-05, + "cache_creation_input_token_cost_above_12hr": 3.125e-05, "cache_creation_input_token_cost_above_272k_tokens": 3.125e-05, "cache_read_input_token_cost": 1.25e-06, "cache_read_input_token_cost_above_272k_tokens": 2.5e-06, @@ -37351,7 +36253,6 @@ "litellm_provider": "openai", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 7.5e-05, "output_cost_per_token_above_272k_tokens": 0.0001125, @@ -37390,7 +36291,6 @@ "litellm_provider": "openai", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 7.5e-05, "output_cost_per_token_above_272k_tokens": 0.0001125, @@ -37429,7 +36329,6 @@ "litellm_provider": "openai", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 7.5e-05, "output_cost_per_token_above_272k_tokens": 0.0001125, @@ -37467,7 +36366,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "output_cost_per_token_above_272k_tokens": 3e-05, @@ -37506,7 +36404,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 2e-05, "output_cost_per_token_above_272k_tokens": 3e-05, @@ -37540,7 +36437,6 @@ "litellm_provider": "openai", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "reasoning_effort_levels": [ @@ -37586,7 +36482,6 @@ "litellm_provider": "openai", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "output_cost_per_token_above_272k_tokens": 4.5e-05, @@ -37649,7 +36544,6 @@ "litellm_provider": "openai", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "output_cost_per_token_above_272k_tokens": 4.5e-05, @@ -37705,7 +36599,6 @@ "litellm_provider": "openai", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -37757,7 +36650,6 @@ "litellm_provider": "openai", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -37816,7 +36708,6 @@ "litellm_provider": "openai", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_above_272k_tokens": 2.25e-05, @@ -37874,7 +36765,6 @@ "litellm_provider": "openai", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_above_272k_tokens": 2.25e-05, @@ -37925,7 +36815,6 @@ "litellm_provider": "openai", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -37978,7 +36867,6 @@ "litellm_provider": "openai", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 0.00018, "output_cost_per_token_above_272k_tokens": 0.00027, @@ -38034,7 +36922,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.5e-06, "output_cost_per_token_flex": 2.25e-06, @@ -38089,7 +36976,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.5e-06, "output_cost_per_token_flex": 2.25e-06, @@ -38142,7 +37028,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.25e-06, "output_cost_per_token_flex": 6.25e-07, @@ -38194,7 +37079,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.25e-06, "output_cost_per_token_flex": 6.25e-07, @@ -38241,7 +37125,6 @@ "litellm_provider": "openai", "max_input_tokens": 400000, "max_output_tokens": 272000, - "max_tokens": 272000, "mode": "responses", "output_cost_per_token": 0.00012, "output_cost_per_token_batches": 6e-05, @@ -38284,7 +37167,6 @@ "litellm_provider": "openai", "max_input_tokens": 400000, "max_output_tokens": 272000, - "max_tokens": 272000, "mode": "responses", "output_cost_per_token": 0.00012, "output_cost_per_token_batches": 6e-05, @@ -38333,7 +37215,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -38379,7 +37260,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "supported_endpoints": [ @@ -38415,7 +37295,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://developers.openai.com/api/docs/models/gpt-5-chat-latest", @@ -38448,7 +37327,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.4e-05, "output_cost_per_token_priority": 2.8e-05, @@ -38492,7 +37370,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.4e-05, "source": "https://developers.openai.com/api/docs/models/gpt-5.3-chat-latest", @@ -38529,7 +37406,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-06, "output_cost_per_token_batches": 1e-06, @@ -38581,7 +37457,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-06, "output_cost_per_token_batches": 1e-06, @@ -38631,7 +37506,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4e-07, "output_cost_per_token_batches": 2e-07, @@ -38681,7 +37555,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4e-07, "output_cost_per_token_batches": 2e-07, @@ -38767,7 +37640,6 @@ "litellm_provider": "openai", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1.6e-05, @@ -38802,7 +37674,6 @@ "litellm_provider": "openai", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1.6e-05, @@ -38837,7 +37708,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 2.4e-05, @@ -38872,7 +37742,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 2.4e-05, @@ -38909,7 +37778,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "realtime", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -38947,7 +37815,6 @@ "litellm_provider": "openai", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -38983,7 +37850,6 @@ "litellm_provider": "openai", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 1.6e-05, @@ -39009,7 +37875,6 @@ }, "gradient_ai/alibaba-qwen3-32b": { "litellm_provider": "gradient_ai", - "max_tokens": 40960, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions" @@ -39024,7 +37889,6 @@ "gradient_ai/anthropic-claude-3-opus": { "input_cost_per_token": 1.5e-05, "litellm_provider": "gradient_ai", - "max_tokens": 1024, "mode": "chat", "output_cost_per_token": 7.5e-05, "supported_endpoints": [ @@ -39040,7 +37904,6 @@ "gradient_ai/anthropic-claude-3.5-haiku": { "input_cost_per_token": 8e-07, "litellm_provider": "gradient_ai", - "max_tokens": 1024, "mode": "chat", "output_cost_per_token": 4e-06, "supported_endpoints": [ @@ -39056,7 +37919,6 @@ "gradient_ai/anthropic-claude-3.5-sonnet": { "input_cost_per_token": 3e-06, "litellm_provider": "gradient_ai", - "max_tokens": 1024, "mode": "chat", "output_cost_per_token": 1.5e-05, "supported_endpoints": [ @@ -39072,7 +37934,6 @@ "gradient_ai/anthropic-claude-3.7-sonnet": { "input_cost_per_token": 3e-06, "litellm_provider": "gradient_ai", - "max_tokens": 1024, "mode": "chat", "output_cost_per_token": 1.5e-05, "supported_endpoints": [ @@ -39088,7 +37949,6 @@ "gradient_ai/deepseek-r1-distill-llama-70b": { "input_cost_per_token": 9.9e-07, "litellm_provider": "gradient_ai", - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 9.9e-07, "supported_endpoints": [ @@ -39104,7 +37964,6 @@ "gradient_ai/llama3-8b-instruct": { "input_cost_per_token": 2e-07, "litellm_provider": "gradient_ai", - "max_tokens": 512, "mode": "chat", "output_cost_per_token": 2e-07, "supported_endpoints": [ @@ -39120,7 +37979,6 @@ "gradient_ai/llama3.3-70b-instruct": { "input_cost_per_token": 6.5e-07, "litellm_provider": "gradient_ai", - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 6.5e-07, "supported_endpoints": [ @@ -39136,7 +37994,6 @@ "gradient_ai/mistral-nemo-instruct-2407": { "input_cost_per_token": 3e-07, "litellm_provider": "gradient_ai", - "max_tokens": 512, "mode": "chat", "output_cost_per_token": 3e-07, "supported_endpoints": [ @@ -39151,7 +38008,6 @@ }, "gradient_ai/openai-gpt-4o": { "litellm_provider": "gradient_ai", - "max_tokens": 16384, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions" @@ -39165,7 +38021,6 @@ }, "gradient_ai/openai-gpt-4o-mini": { "litellm_provider": "gradient_ai", - "max_tokens": 16384, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions" @@ -39180,7 +38035,6 @@ "gradient_ai/openai-o3": { "input_cost_per_token": 2e-06, "litellm_provider": "gradient_ai", - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8e-06, "supported_endpoints": [ @@ -39196,7 +38050,6 @@ "gradient_ai/openai-o3-mini": { "input_cost_per_token": 1.1e-06, "litellm_provider": "gradient_ai", - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "supported_endpoints": [ @@ -39212,7 +38065,6 @@ "lemonade/Qwen3-Coder-30B-A3B-Instruct-GGUF": { "input_cost_per_token": 0, "litellm_provider": "lemonade", - "max_tokens": 32768, "max_input_tokens": 262144, "max_output_tokens": 32768, "mode": "chat", @@ -39224,7 +38076,6 @@ "lemonade/gpt-oss-20b-mxfp4-GGUF": { "input_cost_per_token": 0, "litellm_provider": "lemonade", - "max_tokens": 32768, "max_input_tokens": 131072, "max_output_tokens": 32768, "mode": "chat", @@ -39236,7 +38087,6 @@ "lemonade/gpt-oss-120b-mxfp-GGUF": { "input_cost_per_token": 0, "litellm_provider": "lemonade", - "max_tokens": 32768, "max_input_tokens": 131072, "max_output_tokens": 32768, "mode": "chat", @@ -39248,7 +38098,6 @@ "lemonade/Gemma-3-4b-it-GGUF": { "input_cost_per_token": 0, "litellm_provider": "lemonade", - "max_tokens": 8192, "max_input_tokens": 128000, "max_output_tokens": 8192, "mode": "chat", @@ -39260,7 +38109,6 @@ "lemonade/Qwen3-4B-Instruct-2507-GGUF": { "input_cost_per_token": 0, "litellm_provider": "lemonade", - "max_tokens": 32768, "max_input_tokens": 262144, "max_output_tokens": 32768, "mode": "chat", @@ -39274,7 +38122,6 @@ "litellm_provider": "amazon_nova", "max_input_tokens": 128000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 1.4e-07, "supports_function_calling": true, @@ -39286,7 +38133,6 @@ "litellm_provider": "amazon_nova", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 2.4e-07, "supports_function_calling": true, @@ -39300,7 +38146,6 @@ "litellm_provider": "amazon_nova", "max_input_tokens": 1000000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 1.25e-05, "supports_function_calling": true, @@ -39314,7 +38159,6 @@ "litellm_provider": "amazon_nova", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 3.2e-06, "supports_function_calling": true, @@ -39328,7 +38172,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "groq", "max_input_tokens": 8192, - "max_tokens": 8192, + "max_output_tokens": 8192, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://console.groq.com/docs/model/llama-guard-3-8b" @@ -39338,7 +38182,6 @@ "litellm_provider": "groq", "max_input_tokens": 512, "max_output_tokens": 512, - "max_tokens": 512, "mode": "chat", "output_cost_per_token": 3e-08, "source": "https://console.groq.com/docs/models" @@ -39348,7 +38191,6 @@ "litellm_provider": "groq", "max_input_tokens": 512, "max_output_tokens": 512, - "max_tokens": 512, "mode": "chat", "output_cost_per_token": 4e-08, "source": "https://console.groq.com/docs/model/meta-llama/llama-prompt-guard-2-86m" @@ -39359,7 +38201,6 @@ "litellm_provider": "groq", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 6e-07, "search_context_cost_per_query": { @@ -39380,7 +38221,6 @@ "litellm_provider": "groq", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3e-07, "search_context_cost_per_query": { @@ -39401,7 +38241,6 @@ "litellm_provider": "groq", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3e-07, "search_context_cost_per_query": { @@ -39420,7 +38259,6 @@ "litellm_provider": "groq", "max_input_tokens": 4000, "max_output_tokens": 50000, - "max_tokens": 50000, "mode": "audio_speech", "source": "https://console.groq.com/docs/model/canopylabs/orpheus-v1-english" }, @@ -39429,7 +38267,6 @@ "litellm_provider": "groq", "max_input_tokens": 4000, "max_output_tokens": 50000, - "max_tokens": 50000, "mode": "audio_speech", "source": "https://console.groq.com/docs/models" }, @@ -39447,7 +38284,6 @@ }, "heroku/claude-3-5-haiku": { "litellm_provider": "heroku", - "max_tokens": 8192, "mode": "chat", "supports_function_calling": true, "supports_system_messages": true, @@ -39457,7 +38293,6 @@ }, "heroku/claude-3-5-sonnet-latest": { "litellm_provider": "heroku", - "max_tokens": 8192, "mode": "chat", "supports_function_calling": true, "supports_system_messages": true, @@ -39467,7 +38302,6 @@ }, "heroku/claude-3-7-sonnet": { "litellm_provider": "heroku", - "max_tokens": 8192, "mode": "chat", "supports_function_calling": true, "supports_system_messages": true, @@ -39477,7 +38311,6 @@ }, "heroku/claude-4-sonnet": { "litellm_provider": "heroku", - "max_tokens": 8192, "mode": "chat", "supports_function_calling": true, "supports_system_messages": true, @@ -39523,7 +38356,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -39536,7 +38368,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-07, "supports_function_calling": true, @@ -39549,7 +38380,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -39562,7 +38392,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -39575,7 +38404,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-06, "supports_function_calling": true, @@ -39588,7 +38416,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-07, "supports_function_calling": true, @@ -39601,7 +38428,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.5e-07, "supports_function_calling": true, @@ -39614,7 +38440,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2e-07, "supports_function_calling": true, @@ -39627,7 +38452,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-07, "supports_function_calling": true, @@ -39640,7 +38464,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -39653,7 +38476,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -39666,7 +38488,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -39679,7 +38500,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -39692,7 +38512,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -39705,7 +38524,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -39718,7 +38536,6 @@ "litellm_provider": "hyperbolic", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-06, "supports_function_calling": true, @@ -39731,7 +38548,6 @@ "litellm_provider": "ai21", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "completion", "output_cost_per_token": 3e-06 }, @@ -39740,7 +38556,6 @@ "litellm_provider": "ai21", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "completion", "output_cost_per_token": 1e-05 }, @@ -39749,7 +38564,6 @@ "litellm_provider": "ai21", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "completion", "output_cost_per_token": 1.5e-05 }, @@ -39758,7 +38572,6 @@ "litellm_provider": "ai21", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4e-07, "supports_tool_choice": true @@ -39768,7 +38581,6 @@ "litellm_provider": "ai21", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 8e-06, "supports_tool_choice": true @@ -39778,7 +38590,6 @@ "litellm_provider": "ai21", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 8e-06, "supports_tool_choice": true @@ -39788,7 +38599,6 @@ "litellm_provider": "ai21", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4e-07, "supports_tool_choice": true @@ -39798,7 +38608,6 @@ "litellm_provider": "ai21", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4e-07, "supports_tool_choice": true @@ -39808,7 +38617,6 @@ "litellm_provider": "ai21", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 8e-06, "supports_tool_choice": true @@ -39818,7 +38626,6 @@ "litellm_provider": "ai21", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 8e-06, "supports_tool_choice": true @@ -39828,7 +38635,6 @@ "litellm_provider": "ai21", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4e-07, "supports_tool_choice": true @@ -39838,7 +38644,6 @@ "litellm_provider": "ai21", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4e-07, "supports_tool_choice": true @@ -39848,7 +38653,6 @@ "litellm_provider": "jina_ai", "max_input_tokens": 1024, "max_output_tokens": 1024, - "max_tokens": 1024, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://api.jina.ai/v1/models" @@ -39868,7 +38672,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.65e-05, "search_context_cost_per_query": { @@ -39905,7 +38708,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5.5e-06, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -39933,7 +38735,6 @@ "litellm_provider": "crusoe", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "mode": "chat", "output_cost_per_token": 7e-06, "supports_function_calling": false, @@ -39946,7 +38747,6 @@ "litellm_provider": "crusoe", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "mode": "chat", "output_cost_per_token": 1.5e-06, "supports_function_calling": true, @@ -39959,7 +38759,6 @@ "litellm_provider": "crusoe", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1e-07, "supports_function_calling": true, @@ -39973,7 +38772,6 @@ "litellm_provider": "crusoe", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-07, "supports_function_calling": true, @@ -39986,7 +38784,6 @@ "litellm_provider": "crusoe", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 2.5e-06, "supports_function_calling": false, @@ -39999,7 +38796,6 @@ "litellm_provider": "crusoe", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 8e-07, "supports_function_calling": true, @@ -40012,7 +38808,6 @@ "litellm_provider": "crusoe", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 3e-06, "supports_function_calling": true, @@ -40026,7 +38821,6 @@ "litellm_provider": "inception", "max_input_tokens": 128000, "max_output_tokens": 50000, - "max_tokens": 50000, "mode": "chat", "output_cost_per_token": 7.5e-07, "supports_function_calling": true, @@ -40041,7 +38835,6 @@ "litellm_provider": "inception", "max_input_tokens": 260000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 7.5e-07, "source": "https://docs.inceptionlabs.ai/get-started/models", @@ -40056,7 +38849,7 @@ "input_cost_per_token": 1.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 3.8e-07, "source": "https://inferenceapis.com/pricing", @@ -40077,7 +38870,7 @@ "input_cost_per_token": 1.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 3.8e-07, "source": "https://inferenceapis.com/pricing", @@ -40098,7 +38891,7 @@ "input_cost_per_token": 1.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 3.8e-07, "source": "https://inferenceapis.com/pricing", @@ -40119,7 +38912,7 @@ "input_cost_per_token": 1.72e-06, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 5.15e-06, "source": "https://inferenceapis.com/pricing", @@ -40140,7 +38933,7 @@ "input_cost_per_token": 1.72e-06, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 5.15e-06, "source": "https://inferenceapis.com/pricing", @@ -40161,7 +38954,7 @@ "input_cost_per_token": 4e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.6e-06, "source": "https://inferenceapis.com/pricing", @@ -40182,7 +38975,7 @@ "input_cost_per_token": 1.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 3.8e-07, "source": "https://inferenceapis.com/pricing", @@ -40203,7 +38996,7 @@ "input_cost_per_token": 4e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.6e-06, "source": "https://inferenceapis.com/pricing", @@ -40224,7 +39017,7 @@ "input_cost_per_token": 1.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 3.8e-07, "source": "https://inferenceapis.com/pricing", @@ -40245,7 +39038,7 @@ "input_cost_per_token": 1.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 3.8e-07, "source": "https://inferenceapis.com/pricing", @@ -40266,7 +39059,7 @@ "input_cost_per_token": 1.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 3.8e-07, "source": "https://inferenceapis.com/pricing", @@ -40287,7 +39080,7 @@ "input_cost_per_token": 1.72e-06, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 5.15e-06, "source": "https://inferenceapis.com/pricing", @@ -40308,7 +39101,7 @@ "input_cost_per_token": 4e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.6e-06, "source": "https://inferenceapis.com/pricing", @@ -40329,7 +39122,7 @@ "input_cost_per_token": 1.82e-06, "litellm_provider": "inferenceapis", "max_input_tokens": 1048575, - "max_tokens": 1048575, + "max_output_tokens": 1048575, "mode": "chat", "output_cost_per_token": 5.72e-06, "source": "https://inferenceapis.com/pricing", @@ -40350,7 +39143,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048575, - "max_tokens": 1048575, + "max_output_tokens": 1048575, "mode": "chat", "output_cost_per_token": 6.6e-07, "source": "https://inferenceapis.com/pricing", @@ -40370,7 +39163,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 8e-07, "source": "https://inferenceapis.com/pricing", @@ -40389,7 +39182,7 @@ "input_cost_per_token": 4e-08, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.9e-07, "source": "https://inferenceapis.com/pricing", @@ -40409,7 +39202,7 @@ "input_cost_per_token": 8.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 4.42e-06, "source": "https://inferenceapis.com/pricing", @@ -40429,7 +39222,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inferenceapis.com/pricing", @@ -40448,7 +39241,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inferenceapis.com/pricing", @@ -40467,7 +39260,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inferenceapis.com/pricing", @@ -40486,7 +39279,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inferenceapis.com/pricing", @@ -40505,7 +39298,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inferenceapis.com/pricing", @@ -40524,7 +39317,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inferenceapis.com/pricing", @@ -40544,7 +39337,7 @@ "input_cost_per_token": 3.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 524288, - "max_tokens": 524288, + "max_output_tokens": 524288, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://inferenceapis.com/pricing", @@ -40565,7 +39358,7 @@ "input_cost_per_token": 3.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 524288, - "max_tokens": 524288, + "max_output_tokens": 524288, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://inferenceapis.com/pricing", @@ -40586,7 +39379,7 @@ "input_cost_per_token": 8.9e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 4.42e-06, "source": "https://inferenceapis.com/pricing", @@ -40606,7 +39399,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 8e-07, "source": "https://inferenceapis.com/pricing", @@ -40625,7 +39418,7 @@ "input_cost_per_token": 4e-08, "litellm_provider": "inferenceapis", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.9e-07, "source": "https://inferenceapis.com/pricing", @@ -40644,7 +39437,7 @@ "input_cost_per_token": 2.6e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.15e-06, "source": "https://inferenceapis.com/pricing", @@ -40664,7 +39457,7 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inferenceapis.com/pricing", @@ -40684,7 +39477,7 @@ "input_cost_per_token": 2.6e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.15e-06, "source": "https://inferenceapis.com/pricing", @@ -40703,7 +39496,7 @@ "input_cost_per_token": 2.6e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.15e-06, "source": "https://inferenceapis.com/pricing", @@ -40723,7 +39516,7 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inferenceapis.com/pricing", @@ -40744,7 +39537,7 @@ "input_cost_per_token": 1.82e-06, "litellm_provider": "inferenceapis", "max_input_tokens": 1048575, - "max_tokens": 1048575, + "max_output_tokens": 1048575, "mode": "chat", "output_cost_per_token": 5.72e-06, "source": "https://inferenceapis.com/pricing", @@ -40765,7 +39558,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "inferenceapis", "max_input_tokens": 1048575, - "max_tokens": 1048575, + "max_output_tokens": 1048575, "mode": "chat", "output_cost_per_token": 6.6e-07, "source": "https://inferenceapis.com/pricing", @@ -40787,7 +39580,6 @@ "litellm_provider": "text-completion-inception", "max_input_tokens": 32000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "completion", "output_cost_per_token": 7.5e-07 }, @@ -40796,7 +39588,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -40810,7 +39601,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -40824,7 +39614,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 8e-07, "supports_function_calling": true, @@ -40838,7 +39627,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -40851,7 +39639,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 8e-07, "supports_function_calling": true, @@ -40864,7 +39651,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -40877,7 +39663,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4e-08, "supports_function_calling": true, @@ -40890,7 +39675,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-07, "supports_function_calling": true, @@ -40903,7 +39687,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4e-08, "supports_function_calling": true, @@ -40916,7 +39699,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1e-07, "supports_function_calling": true, @@ -40929,7 +39711,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 16384, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1e-07, "supports_function_calling": true, @@ -40942,7 +39723,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 8e-07, "supports_function_calling": true, @@ -40955,7 +39735,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -40968,7 +39747,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4e-08, "supports_function_calling": true, @@ -40981,7 +39759,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -40994,7 +39771,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.5e-08, "supports_function_calling": true, @@ -41008,7 +39784,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.5e-08, "supports_function_calling": true, @@ -41021,7 +39796,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -41034,7 +39808,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1e-07, "supports_function_calling": true, @@ -41047,7 +39820,6 @@ "litellm_provider": "lambda_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1e-07, "supports_function_calling": true, @@ -41092,14 +39864,12 @@ "max-x-max/50-steps/stability.stable-diffusion-xl-v0": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.036 }, "max-x-max/max-steps/stability.stable-diffusion-xl-v0": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.072 }, @@ -41195,7 +39965,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 8192, "max_output_tokens": 1024, - "max_tokens": 1024, "mode": "chat", "output_cost_per_character": 1.5e-05, "source": "https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models#foundation_models", @@ -41206,7 +39975,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 32768, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_character": 1e-06, "source": "https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models#foundation_models", @@ -41217,7 +39985,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1e-06, "source": "https://aws.amazon.com/bedrock/pricing/" @@ -41227,7 +39994,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.56e-06, "source": "https://aws.amazon.com/bedrock/pricing/" @@ -41238,7 +40004,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/bedrock/USD/current/bedrock.json", @@ -41252,7 +40017,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.2e-07, "output_cost_per_token_batches": 3.6e-07, @@ -41267,7 +40031,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.2e-07, "output_cost_per_token_batches": 1.1e-07, @@ -41281,7 +40044,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.6e-07, "source": "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/bedrock/USD/current/bedrock.json", @@ -41295,7 +40057,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-2-1b-instruct.md", @@ -41308,7 +40069,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-2-3b-instruct.md", @@ -41321,7 +40081,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/bedrock/USD/current/bedrock.json", @@ -41336,7 +40095,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.2e-07, "output_cost_per_token_batches": 3.6e-07, @@ -41350,7 +40108,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 3.5e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-70b-instruct.md" @@ -41361,7 +40118,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-8b-instruct.md" @@ -41373,7 +40129,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 9.7e-07, "output_cost_per_token_batches": 4.85e-07, @@ -41396,7 +40151,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 10000000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6.6e-07, "output_cost_per_token_batches": 3.3e-07, @@ -41418,7 +40172,6 @@ "litellm_provider": "meta", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.25e-06, "search_context_cost_per_query": { @@ -41459,7 +40212,6 @@ "litellm_provider": "meta", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.25e-06, "search_context_cost_per_query": { @@ -41500,7 +40252,6 @@ "litellm_provider": "meta", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-07, "search_context_cost_per_query": { @@ -41541,7 +40292,6 @@ "litellm_provider": "meta", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.25e-06, "search_context_cost_per_query": { @@ -41582,7 +40332,6 @@ "litellm_provider": "meta", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-07, "search_context_cost_per_query": { @@ -41639,7 +40388,6 @@ "litellm_provider": "meta", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-05, "search_context_cost_per_query": { @@ -41680,7 +40428,6 @@ "litellm_provider": "meta_llama", "max_input_tokens": 128000, "max_output_tokens": 4028, - "max_tokens": 4028, "mode": "chat", "source": "https://ai.developer.meta.com/docs/models", "supported_modalities": [ @@ -41696,7 +40443,6 @@ "litellm_provider": "meta_llama", "max_input_tokens": 128000, "max_output_tokens": 4028, - "max_tokens": 4028, "mode": "chat", "source": "https://ai.developer.meta.com/docs/models", "supported_modalities": [ @@ -41712,7 +40458,6 @@ "litellm_provider": "meta_llama", "max_input_tokens": 1000000, "max_output_tokens": 4028, - "max_tokens": 4028, "mode": "chat", "source": "https://ai.developer.meta.com/docs/models", "supported_modalities": [ @@ -41729,7 +40474,6 @@ "litellm_provider": "meta_llama", "max_input_tokens": 10000000, "max_output_tokens": 4028, - "max_tokens": 4028, "mode": "chat", "source": "https://ai.developer.meta.com/docs/models", "supported_modalities": [ @@ -41751,7 +40495,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_batches": 6e-07, @@ -41774,7 +40517,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 196000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_batches": 6e-07, @@ -41798,7 +40540,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 196000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token_batches": 6e-07, "output_cost_per_token_priority": 2.1e-06, @@ -41996,7 +40737,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 2e-06, "output_cost_per_token_batches": 1e-06, @@ -42018,7 +40758,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 40000, - "max_tokens": 40000, "mode": "chat", "output_cost_per_token": 1.5e-06, "output_cost_per_token_batches": 7.5e-07, @@ -42040,7 +40779,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2e-07, "output_cost_per_token_batches": 1e-07, @@ -42062,7 +40800,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1e-07, "output_cost_per_token_batches": 5e-08, @@ -42084,7 +40821,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.5e-07, "output_cost_per_token_batches": 7e-08, @@ -42104,7 +40840,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mistral-7b-instruct.md", @@ -42115,7 +40850,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.2e-05, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mistral-large.md", @@ -42126,7 +40860,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/bedrock/USD/current/bedrock.json", @@ -42141,7 +40874,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.5e-06, "output_cost_per_token_batches": 7.5e-07, @@ -42161,7 +40893,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3e-06, "output_cost_per_token_batches": 1.5e-06, @@ -42174,7 +40905,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-mixtral-8x7b-instruct.md", @@ -42189,7 +40919,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 32768, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4e-08, "output_cost_per_token_batches": 2e-08, @@ -42209,7 +40938,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 32768, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 3e-07, "output_cost_per_token_batches": 1.5e-07, @@ -42226,7 +40954,6 @@ "litellm_provider": "mistral", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://docs.mistral.ai/models/model-cards/codestral-25-08", @@ -42241,7 +40968,6 @@ "litellm_provider": "mistral", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://docs.mistral.ai/models/model-cards/codestral-25-08", @@ -42256,7 +40982,6 @@ "litellm_provider": "mistral", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2.5e-07, "source": "https://mistral.ai/technology/", @@ -42269,7 +40994,6 @@ "litellm_provider": "mistral", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://docs.mistral.ai/models/devstral-small-2-25-12", @@ -42284,7 +41008,6 @@ "litellm_provider": "mistral", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://mistral.ai/news/devstral-2-vibe-cli", @@ -42299,7 +41022,6 @@ "litellm_provider": "mistral", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://mistral.ai/news/devstral-2-vibe-cli", @@ -42313,7 +41035,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://docs.mistral.ai/models/ministral-3-14b-25-12", @@ -42329,7 +41050,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://docs.mistral.ai/models/ministral-3-14b-25-12", @@ -42345,7 +41065,6 @@ "litellm_provider": "mistral", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://docs.mistral.ai/models/ministral-3-3b-25-12", @@ -42361,7 +41080,6 @@ "litellm_provider": "mistral", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://docs.mistral.ai/models/ministral-3-3b-25-12", @@ -42376,7 +41094,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "mistral", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "source": "https://docs.mistral.ai/models/mistral-embed-23-12" }, @@ -42386,7 +41103,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 7.5e-06, "reasoning_effort_levels": [ @@ -42567,7 +41283,6 @@ "litellm_provider": "mistral", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://docs.mistral.ai/models/voxtral-small-25-07", @@ -42582,7 +41297,6 @@ "litellm_provider": "mistral", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://docs.mistral.ai/models/voxtral-small-25-07", @@ -42598,7 +41312,6 @@ "litellm_provider": "mistral", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "reasoning_effort_levels": [ @@ -42624,7 +41337,6 @@ "litellm_provider": "mistral", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "reasoning_effort_levels": [ @@ -42640,13 +41352,34 @@ "supports_response_schema": true, "supports_tool_choice": true }, + "mistral/zai-glm-5-3-flash": { + "cache_read_input_token_cost": 3e-08, + "input_cost_per_token": 1.5e-07, + "litellm_provider": "mistral", + "max_input_tokens": 1048576, + "max_output_tokens": 131072, + "mode": "chat", + "output_cost_per_token": 5e-07, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ], + "source": "https://docs.mistral.ai/models/zai-glm-5-3-flash", + "supports_assistant_prefill": true, + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": true + }, "mistral/zai-glm-5": { "cache_read_input_token_cost": 1.4e-07, "input_cost_per_token": 1.4e-06, "litellm_provider": "mistral", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "reasoning_effort_levels": [ @@ -42668,7 +41401,6 @@ "litellm_provider": "mistral", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "reasoning_effort_levels": [ @@ -42690,7 +41422,6 @@ "litellm_provider": "mistral", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "reasoning_effort_levels": [ @@ -42769,7 +41500,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 7.5e-06, "source": "https://docs.mistral.ai/models/model-cards/mistral-medium-3-5-26-04", @@ -42786,7 +41516,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://docs.mistral.ai/models/model-cards/mistral-small-4-0-26-03", @@ -42801,7 +41530,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "mistral", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding" }, "mistral/codestral-embed": { @@ -42809,7 +41537,6 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "mistral", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding" }, "mistral/codestral-embed-2505": { @@ -42817,7 +41544,6 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "mistral", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding" }, "mistral/mistral-large-4": { @@ -42825,7 +41551,7 @@ "input_cost_per_token": 6.8e-07, "litellm_provider": "mistral", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 2.09e-06, "reasoning_effort_levels": [ @@ -42846,7 +41572,7 @@ "input_cost_per_token": 6.8e-07, "litellm_provider": "mistral", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 2.09e-06, "reasoning_effort_levels": [ @@ -42868,7 +41594,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://docs.mistral.ai/models/mistral-large-3-25-12", @@ -42884,7 +41609,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://docs.mistral.ai/models/mistral-large-3-25-12", @@ -42900,7 +41624,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://docs.mistral.ai/models/mistral-large-3-25-12", @@ -42916,7 +41639,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 7.5e-06, "reasoning_effort_levels": [ @@ -42937,7 +41659,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 7.5e-06, "reasoning_effort_levels": [ @@ -42958,7 +41679,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 7.5e-06, "reasoning_effort_levels": [ @@ -42979,7 +41699,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 7.5e-06, "reasoning_effort_levels": [ @@ -43000,7 +41719,6 @@ "litellm_provider": "mistral", "max_input_tokens": 32000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 3e-07, "supports_assistant_prefill": true, @@ -43014,7 +41732,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 6e-07, "reasoning_effort_levels": [ @@ -43035,7 +41752,6 @@ "litellm_provider": "mistral", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://mistral.ai/pricing", @@ -43051,7 +41767,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://mistral.ai/pricing", @@ -43067,7 +41782,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://mistral.ai/pricing", @@ -43083,7 +41797,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://mistral.ai/pricing", @@ -43099,7 +41812,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://mistral.ai/pricing", @@ -43115,7 +41827,6 @@ "litellm_provider": "mistral", "max_input_tokens": 32000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2.5e-07, "supports_assistant_prefill": true, @@ -43128,7 +41839,6 @@ "litellm_provider": "mistral", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://mistral.ai/technology/", @@ -43142,7 +41852,6 @@ "litellm_provider": "mistral", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-06, "supports_assistant_prefill": true, @@ -43159,7 +41868,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 1.25e-06, @@ -43181,7 +41889,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 3e-06, "output_cost_per_token_batches": 1.5e-06, @@ -43201,7 +41908,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://platform.kimi.ai/docs/pricing/chat-k27-code", @@ -43219,7 +41925,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://platform.moonshot.ai/docs/guide/kimi-k2-5-quickstart", @@ -43236,7 +41941,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://platform.kimi.ai/docs/pricing/chat-k26", @@ -43253,7 +41957,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.5e-05, "reasoning_effort_levels": [ @@ -43274,7 +41977,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-06, "source": "https://platform.moonshot.ai/docs/pricing", @@ -43287,7 +41989,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-06, "source": "https://platform.moonshot.ai/docs/pricing", @@ -43301,7 +42002,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://platform.moonshot.ai/docs/pricing", @@ -43314,7 +42014,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://platform.moonshot.ai/docs/pricing", @@ -43328,7 +42027,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://platform.moonshot.ai/docs/pricing", @@ -43341,7 +42039,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://platform.moonshot.ai/docs/pricing", @@ -43355,7 +42052,6 @@ "litellm_provider": "moonshot", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-06, "source": "https://platform.moonshot.ai/docs/pricing", @@ -43368,7 +42064,6 @@ "litellm_provider": "morph", "max_input_tokens": 16000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 1.2e-06, "supports_function_calling": false, @@ -43382,7 +42077,6 @@ "litellm_provider": "morph", "max_input_tokens": 16000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 1.9e-06, "supports_function_calling": false, @@ -43400,7 +42094,6 @@ "input_cost_per_video_per_second_above_8s_interval": 0.001, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 2048, - "max_tokens": 2048, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 768, @@ -43424,7 +42117,6 @@ "input_cost_per_video_per_second_above_8s_interval": 0.001, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 2048, - "max_tokens": 2048, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 768, @@ -43584,7 +42276,6 @@ ] }, "nebius/deepseek-ai/DeepSeek-R1": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 8e-07, @@ -43596,7 +42287,6 @@ "source": "https://nebius.com/prices" }, "nebius/deepseek-ai/DeepSeek-R1-0528": { - "max_tokens": 164000, "max_input_tokens": 164000, "max_output_tokens": 164000, "input_cost_per_token": 8e-07, @@ -43608,7 +42298,6 @@ "source": "https://nebius.com/prices" }, "nebius/deepseek-ai/DeepSeek-R1-Distill-Llama-70B": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2.5e-07, @@ -43619,7 +42308,6 @@ "source": "https://nebius.com/prices" }, "nebius/deepseek-ai/DeepSeek-V3": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 5e-07, @@ -43630,7 +42318,6 @@ "source": "https://nebius.com/prices" }, "nebius/deepseek-ai/DeepSeek-V3-0324": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 5e-07, @@ -43641,7 +42328,6 @@ "source": "https://nebius.com/prices" }, "nebius/google/gemma-3-27b-it": { - "max_tokens": 110000, "max_input_tokens": 110000, "max_output_tokens": 110000, "input_cost_per_token": 1e-07, @@ -43653,7 +42339,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/google%2Fgemma-3-27b-it" }, "nebius/meta-llama/Llama-3.3-70B-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.3e-07, @@ -43664,7 +42349,6 @@ "source": "https://nebius.com/prices" }, "nebius/meta-llama/Llama-Guard-3-8B": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2e-08, @@ -43674,7 +42358,6 @@ "source": "https://nebius.com/prices" }, "nebius/meta-llama/Meta-Llama-3.1-8B-Instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2e-08, @@ -43685,7 +42368,6 @@ "source": "https://nebius.com/prices" }, "nebius/meta-llama/Meta-Llama-3.1-70B-Instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 1.3e-07, @@ -43696,7 +42378,6 @@ "source": "https://nebius.com/prices" }, "nebius/meta-llama/Meta-Llama-3.1-405B-Instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 1e-06, @@ -43707,7 +42388,6 @@ "source": "https://nebius.com/prices" }, "nebius/mistralai/Mistral-Nemo-Instruct-2407": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 4e-08, @@ -43718,7 +42398,6 @@ "source": "https://nebius.com/prices" }, "nebius/NousResearch/Hermes-3-Llama-3.1-405B": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 1e-06, @@ -43729,7 +42408,6 @@ "source": "https://nebius.com/prices" }, "nebius/nvidia/Llama-3.1-Nemotron-Ultra-253B-v1": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 6e-07, @@ -43740,7 +42418,6 @@ "source": "https://nebius.com/prices" }, "nebius/nvidia/Llama-3.3-Nemotron-Super-49B-v1": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -43751,7 +42428,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen3-235B-A22B": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 2e-07, @@ -43762,7 +42438,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen3-32B": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 1e-07, @@ -43773,7 +42448,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/Qwen%2FQwen3-32B" }, "nebius/Qwen/Qwen3-30B-A3B": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -43784,7 +42458,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen3-14B": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 8e-08, @@ -43795,7 +42468,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen3-4B": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 8e-08, @@ -43806,7 +42478,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/QwQ-32B": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1.5e-07, @@ -43818,7 +42489,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen2.5-72B-Instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 1.3e-07, @@ -43829,7 +42499,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen2.5-32B-Instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 6e-08, @@ -43840,7 +42509,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen2.5-Coder-7B": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-08, @@ -43851,7 +42519,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen2.5-VL-72B-Instruct": { - "max_tokens": 32000, "max_input_tokens": 32000, "max_output_tokens": 32000, "input_cost_per_token": 2.5e-07, @@ -43863,7 +42530,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/image2text/Qwen%2FQwen2.5-VL-72B-Instruct" }, "nebius/Qwen/Qwen2-VL-72B-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.3e-07, @@ -43875,7 +42541,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen2-VL-7B-Instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-08, @@ -43886,7 +42551,6 @@ "source": "https://nebius.com/prices" }, "nebius/deepseek-ai/DeepSeek-V4-Flash": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 1.4e-07, @@ -43898,7 +42562,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/deepseek-ai%2FDeepSeek-V4-Flash" }, "nebius/deepseek-ai/DeepSeek-V4-Flash-0731": { - "max_tokens": 1024000, "max_input_tokens": 1024000, "max_output_tokens": 1024000, "input_cost_per_token": 1.4e-07, @@ -43910,7 +42573,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/deepseek-ai%2FDeepSeek-V4-Flash-0731" }, "nebius/deepseek-ai/DeepSeek-V4-Pro": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 1.75e-06, @@ -43936,7 +42598,6 @@ "litellm_provider": "nebius", "max_input_tokens": 1048000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://tokenfactory.nebius.com/endpoints?modals=endpoint-details&model-id=deepseek-ai/DeepSeek-V4.1-Flash", @@ -43945,7 +42606,6 @@ "supports_vision": true }, "nebius/MiniMaxAI/MiniMax-M2.5": { - "max_tokens": 196608, "max_input_tokens": 196608, "max_output_tokens": 196608, "input_cost_per_token": 3e-07, @@ -43957,7 +42617,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/MiniMaxAI%2FMiniMax-M2.5" }, "nebius/MiniMaxAI/MiniMax-M3": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 3e-07, @@ -43970,7 +42629,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/MiniMaxAI%2FMiniMax-M3" }, "nebius/moonshotai/Kimi-K2.6": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 9.5e-07, @@ -43983,7 +42641,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/image2text/moonshotai%2FKimi-K2.6" }, "nebius/moonshotai/Kimi-K2.7-Code": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 9.5e-07, @@ -43996,7 +42653,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/moonshotai%2FKimi-K2.7-Code" }, "nebius/moonshotai/Kimi-K3": { - "max_tokens": 1024000, "max_input_tokens": 1024000, "max_output_tokens": 1024000, "input_cost_per_token": 3e-06, @@ -44009,7 +42665,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/image2text/moonshotai%2FKimi-K3" }, "nebius/NousResearch/Hermes-4-405B": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-06, @@ -44021,7 +42676,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/NousResearch%2FHermes-4-405B" }, "nebius/NousResearch/Hermes-4-70B": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.3e-07, @@ -44033,7 +42687,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/NousResearch%2FHermes-4-70B" }, "nebius/nvidia/Cosmos3-Super-Reasoner": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1e-07, @@ -44046,7 +42699,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/image2text/nvidia%2FCosmos3-Super-Reasoner" }, "nebius/nvidia/Llama-3_1-Nemotron-Ultra-253B-v1": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 6e-07, @@ -44057,7 +42709,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/nvidia%2FLlama-3_1-Nemotron-Ultra-253B-v1" }, "nebius/nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 6e-08, @@ -44069,7 +42720,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/nvidia%2FNVIDIA-Nemotron-3-Nano-30B-A3B" }, "nebius/nvidia/Nemotron-3-Nano-Omni": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 6e-08, @@ -44082,7 +42732,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/nvidia%2FNemotron-3-Nano-Omni" }, "nebius/nvidia/nemotron-3-super-120b-a12b": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 3e-07, @@ -44094,7 +42743,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/nvidia%2Fnemotron-3-super-120b-a12b" }, "nebius/nvidia/Nemotron-3-Ultra-550b-a55b": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 1e-06, @@ -44106,7 +42754,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/nvidia%2FNemotron-3-Ultra-550b-a55b" }, "nebius/nvidia/Nemotron-3_5-Lightning": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 6e-08, @@ -44118,7 +42765,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/nvidia%2FNemotron-3_5-Lightning" }, "nebius/openai/gpt-oss-120b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.5e-07, @@ -44130,7 +42776,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/openai%2Fgpt-oss-120b" }, "nebius/openbmb/MiniCPM-V-4_5": { - "max_tokens": 32000, "max_input_tokens": 32000, "max_output_tokens": 32000, "input_cost_per_token": 6.58e-07, @@ -44141,7 +42786,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/image2text/openbmb%2FMiniCPM-V-4_5" }, "nebius/Qwen/Qwen3-235B-A22B-Instruct-2507": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 2e-07, @@ -44152,7 +42796,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/Qwen%2FQwen3-235B-A22B-Instruct-2507" }, "nebius/Qwen/Qwen3-30B-A3B-Instruct-2507": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1e-07, @@ -44163,7 +42806,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/Qwen%2FQwen3-30B-A3B-Instruct-2507" }, "nebius/Qwen/Qwen3-Next-80B-A3B-Thinking": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 1.5e-07, @@ -44175,7 +42817,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/Qwen%2FQwen3-Next-80B-A3B-Thinking" }, "nebius/Qwen/Qwen3.5-397B-A17B": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 6e-07, @@ -44197,7 +42838,6 @@ "supports_reasoning": true }, "nebius/zai-org/GLM-5.1": { - "max_tokens": 202752, "max_input_tokens": 202752, "max_output_tokens": 202752, "input_cost_per_token": 1.4e-06, @@ -44209,7 +42849,6 @@ "source": "https://tokenfactory.nebius.com/models/catalog/text2text/zai-org%2FGLM-5.1" }, "nebius/zai-org/GLM-5.2": { - "max_tokens": 1048576, "max_input_tokens": 1048576, "max_output_tokens": 1048576, "input_cost_per_token": 1.4e-06, @@ -44224,7 +42863,7 @@ "input_cost_per_token": 1.4e-06, "litellm_provider": "nebius", "max_input_tokens": 1024000, - "max_tokens": 1024000, + "max_output_tokens": 1024000, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://tokenfactory.nebius.com/models/catalog/text2text/zai-org%2FGLM-5.3", @@ -44232,7 +42871,6 @@ "supports_reasoning": true }, "nebius/zai-org/GLM-5.3-Flash": { - "max_tokens": 1024000, "max_input_tokens": 1024000, "max_output_tokens": 1024000, "input_cost_per_token": 1.5e-07, @@ -44245,7 +42883,6 @@ "supports_vision": true }, "nebius/BAAI/bge-en-icl": { - "max_tokens": 32768, "max_input_tokens": 32768, "input_cost_per_token": 1e-08, "output_cost_per_token": 0.0, @@ -44254,7 +42891,6 @@ "source": "https://nebius.com/prices" }, "nebius/BAAI/bge-multilingual-gemma2": { - "max_tokens": 8192, "max_input_tokens": 8192, "input_cost_per_token": 1e-08, "output_cost_per_token": 0.0, @@ -44263,7 +42899,6 @@ "source": "https://nebius.com/prices" }, "nebius/intfloat/e5-mistral-7b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "input_cost_per_token": 1e-08, "output_cost_per_token": 0.0, @@ -44272,7 +42907,6 @@ "source": "https://nebius.com/prices" }, "nebius/Qwen/Qwen3-Embedding-8B": { - "max_tokens": 40960, "max_input_tokens": 40960, "input_cost_per_token": 1e-08, "output_cost_per_token": 0.0, @@ -44289,7 +42923,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -44311,7 +42944,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2.3e-07, "output_cost_per_token_batches": 1.2e-07, @@ -44332,7 +42964,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2.4e-07, "output_cost_per_token_batches": 1.2e-07, @@ -44355,7 +42986,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 6.5e-07, "output_cost_per_token_batches": 3.25e-07, @@ -44378,7 +43008,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6e-05, "output_cost_per_token_batches": 3e-05, @@ -44401,7 +43030,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6e-05, "output_cost_per_token_batches": 3e-05, @@ -44423,7 +43051,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 0.0006, "output_cost_per_token_batches": 0.0003, @@ -44457,7 +43084,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 0.0006, "output_cost_per_token_batches": 0.0003, @@ -44495,7 +43121,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8e-06, "output_cost_per_token_batches": 4e-06, @@ -44536,7 +43161,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 4e-05, "source": "https://developers.openai.com/api/docs/models/o3-deep-research", @@ -44569,7 +43193,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 4e-05, "source": "https://developers.openai.com/api/docs/models/o3-deep-research", @@ -44606,7 +43229,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8e-06, "output_cost_per_token_batches": 4e-06, @@ -44649,7 +43271,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_batches": 2.2e-06, @@ -44670,7 +43291,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_batches": 2.2e-06, @@ -44689,7 +43309,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 8e-05, "output_cost_per_token_batches": 4e-05, @@ -44727,7 +43346,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 8e-05, "output_cost_per_token_batches": 4e-05, @@ -44770,7 +43388,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_batches": 2.2e-06, @@ -44798,7 +43415,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 8e-06, "source": "https://developers.openai.com/api/docs/models/o4-mini-deep-research", @@ -44831,7 +43447,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "responses", "output_cost_per_token": 8e-06, "source": "https://developers.openai.com/api/docs/models/o4-mini-deep-research", @@ -44868,7 +43483,6 @@ "litellm_provider": "openai", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_batches": 2.2e-06, @@ -44895,7 +43509,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -44908,7 +43521,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -44921,7 +43533,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1.068e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -44934,7 +43545,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -44948,7 +43558,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -44961,7 +43570,6 @@ "litellm_provider": "oci", "max_input_tokens": 1048576, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -44975,7 +43583,6 @@ "litellm_provider": "oci", "max_input_tokens": 10485760, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -44988,7 +43595,6 @@ "litellm_provider": "oci", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45001,7 +43607,6 @@ "litellm_provider": "oci", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.5e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45014,7 +43619,6 @@ "litellm_provider": "oci", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45027,7 +43631,6 @@ "litellm_provider": "oci", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45040,7 +43643,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45053,7 +43655,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://www.oracle.com/artificial-intelligence/enterprise-ai/cost-estimator/", @@ -45066,7 +43667,6 @@ "litellm_provider": "oci", "max_input_tokens": 256000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://www.oracle.com/artificial-intelligence/enterprise-ai/cost-estimator/", @@ -45079,7 +43679,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://www.oracle.com/artificial-intelligence/enterprise-ai/cost-estimator/", @@ -45092,7 +43691,6 @@ "litellm_provider": "oci", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45112,7 +43710,6 @@ "litellm_provider": "oci", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45131,7 +43728,6 @@ "litellm_provider": "oci", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45151,7 +43747,6 @@ "litellm_provider": "oci", "max_input_tokens": 256000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://www.oracle.com/artificial-intelligence/enterprise-ai/cost-estimator/", @@ -45165,7 +43760,6 @@ "litellm_provider": "oci", "max_input_tokens": 256000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://www.oracle.com/artificial-intelligence/enterprise-ai/cost-estimator/", @@ -45187,7 +43781,6 @@ "litellm_provider": "oci", "max_input_tokens": 256000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45199,7 +43792,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45212,7 +43804,6 @@ "litellm_provider": "oci", "max_input_tokens": 256000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 9e-08, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45224,7 +43815,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45236,7 +43826,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1.56e-06, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45248,7 +43837,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45261,7 +43849,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45273,7 +43860,6 @@ "litellm_provider": "oci", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.5e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45285,7 +43871,6 @@ "litellm_provider": "oci", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.5e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45297,7 +43882,6 @@ "litellm_provider": "oci", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-05, "reasoning_effort_levels": [], @@ -45310,7 +43894,6 @@ "litellm_provider": "oci", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45325,7 +43908,6 @@ "litellm_provider": "oci", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -45341,7 +43923,6 @@ "litellm_provider": "oci", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -45358,7 +43939,6 @@ "litellm_provider": "oci", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -45374,7 +43954,6 @@ "litellm_provider": "oci", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -45388,7 +43967,6 @@ "litellm_provider": "oci", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.5e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45400,7 +43978,6 @@ "litellm_provider": "oci", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45415,7 +43992,6 @@ "litellm_provider": "oci", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45430,7 +44006,6 @@ "litellm_provider": "oci", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45445,7 +44020,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45458,7 +44032,6 @@ "litellm_provider": "oci", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing", @@ -45470,7 +44043,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "oci", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -45480,7 +44052,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "oci", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 384, @@ -45490,7 +44061,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "oci", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -45500,7 +44070,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "oci", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 384, @@ -45510,7 +44079,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "oci", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -45521,7 +44089,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "oci", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 384, @@ -45532,7 +44099,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "oci", "max_input_tokens": 512, - "max_tokens": 512, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 384, @@ -45543,7 +44109,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "oci", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536, @@ -45555,7 +44120,6 @@ "litellm_provider": "ollama", "max_input_tokens": 32768, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": false @@ -45565,7 +44129,6 @@ "litellm_provider": "ollama", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "completion", "output_cost_per_token": 0.0 }, @@ -45574,7 +44137,6 @@ "litellm_provider": "ollama", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 0.0 }, @@ -45583,7 +44145,6 @@ "litellm_provider": "ollama", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "completion", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45593,7 +44154,6 @@ "litellm_provider": "ollama", "max_input_tokens": 32768, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45603,7 +44163,6 @@ "litellm_provider": "ollama", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "completion", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45613,7 +44172,6 @@ "litellm_provider": "ollama", "max_input_tokens": 32768, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45623,7 +44181,6 @@ "litellm_provider": "ollama", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45633,7 +44190,6 @@ "litellm_provider": "ollama", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45643,7 +44199,6 @@ "litellm_provider": "ollama", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45653,7 +44208,6 @@ "litellm_provider": "ollama", "max_input_tokens": 32768, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45663,7 +44217,6 @@ "litellm_provider": "ollama", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -45672,7 +44225,6 @@ "litellm_provider": "ollama", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 0.0 }, @@ -45681,7 +44233,6 @@ "litellm_provider": "ollama", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -45690,7 +44241,6 @@ "litellm_provider": "ollama", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -45699,7 +44249,6 @@ "litellm_provider": "ollama", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -45708,7 +44257,6 @@ "litellm_provider": "ollama", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -45717,7 +44265,6 @@ "litellm_provider": "ollama", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45727,7 +44274,6 @@ "litellm_provider": "ollama", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -45736,7 +44282,6 @@ "litellm_provider": "ollama", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -45745,7 +44290,6 @@ "litellm_provider": "ollama", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "completion", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45755,7 +44299,6 @@ "litellm_provider": "ollama", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45765,7 +44308,6 @@ "litellm_provider": "ollama", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45775,7 +44317,6 @@ "litellm_provider": "ollama", "max_input_tokens": 65536, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45785,7 +44326,6 @@ "litellm_provider": "ollama", "max_input_tokens": 65536, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45795,7 +44335,6 @@ "litellm_provider": "ollama", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45805,7 +44344,6 @@ "litellm_provider": "ollama", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 0.0 }, @@ -45814,7 +44352,6 @@ "litellm_provider": "ollama", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 0.0, "supports_function_calling": true @@ -45824,7 +44361,6 @@ "litellm_provider": "ollama", "max_input_tokens": 2048, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "completion", "output_cost_per_token": 0.0 }, @@ -45833,7 +44369,6 @@ "litellm_provider": "openai", "max_input_tokens": 32768, "max_output_tokens": 0, - "max_tokens": 0, "mode": "moderation", "output_cost_per_token": 0.0 }, @@ -45842,11 +44377,11 @@ "litellm_provider": "openai", "max_input_tokens": 32768, "max_output_tokens": 0, - "max_tokens": 0, "mode": "moderation", "output_cost_per_token": 0.0 }, "openai.gpt-oss-120b-1:0": { + "supports_vision": false, "supported_endpoints": [ "/v1/chat/completions" ], @@ -45859,7 +44394,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -45872,6 +44406,7 @@ "supports_tool_choice": true }, "openai.gpt-oss-20b-1:0": { + "supports_vision": false, "supported_endpoints": [ "/v1/chat/completions" ], @@ -45884,7 +44419,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 3e-07, "output_cost_per_token_batches": 1.5e-07, @@ -45904,7 +44438,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -45926,7 +44459,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 2e-07, "output_cost_per_token_batches": 1e-07, @@ -45945,7 +44477,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 131000, "max_output_tokens": 131000, - "max_tokens": 131000, "mode": "chat", "output_cost_per_token": 6.7e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -45959,7 +44490,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 131000, "max_output_tokens": 131000, - "max_tokens": 131000, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -45972,7 +44502,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 131000, "max_output_tokens": 131000, - "max_tokens": 131000, "mode": "chat", "output_cost_per_token": 6.7e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -45985,7 +44514,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 131000, "max_output_tokens": 131000, - "max_tokens": 131000, "mode": "chat", "output_cost_per_token": 6.7e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -45998,7 +44526,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 127000, "max_output_tokens": 127000, - "max_tokens": 127000, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46011,7 +44538,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 118000, "max_output_tokens": 118000, - "max_tokens": 118000, "mode": "chat", "output_cost_per_token": 1.3e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46024,7 +44550,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.8e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46038,7 +44563,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 6.3e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46051,7 +44575,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 8.7e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46064,7 +44587,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 9.1e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46078,7 +44600,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 2.3e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46092,7 +44613,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 131000, "max_output_tokens": 131000, - "max_tokens": 131000, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46106,7 +44626,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 131000, "max_output_tokens": 131000, - "max_tokens": 131000, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46120,7 +44639,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 2.9e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46134,7 +44652,6 @@ "litellm_provider": "ovhcloud", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 1.9e-07, "source": "https://www.ovhcloud.com/en/public-cloud/ai-endpoints/catalog/", @@ -46167,7 +44684,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.4e-06 }, @@ -46176,7 +44692,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 2.8e-06 }, @@ -46185,7 +44700,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.8e-06 }, @@ -46194,7 +44708,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1e-06 }, @@ -46203,7 +44716,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-07 }, @@ -46212,7 +44724,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.8e-07 }, @@ -46221,7 +44732,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.8e-07 }, @@ -46230,7 +44740,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.8e-06 }, @@ -46240,7 +44749,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.8e-06 }, @@ -46249,7 +44757,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.8e-07 }, @@ -46259,7 +44766,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.8e-07 }, @@ -46315,7 +44821,7 @@ "input_cost_per_token": 1e-06, "litellm_provider": "perplexity", "max_input_tokens": 128000, - "max_tokens": 128000, + "max_output_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-06, "search_context_cost_per_query": { @@ -46330,7 +44836,7 @@ "input_cost_per_token": 2e-06, "litellm_provider": "perplexity", "max_input_tokens": 128000, - "max_tokens": 128000, + "max_output_tokens": 128000, "mode": "chat", "output_cost_per_reasoning_token": 3e-06, "output_cost_per_token": 8e-06, @@ -46347,7 +44853,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.8e-06 }, @@ -46357,7 +44862,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 12000, "max_output_tokens": 12000, - "max_tokens": 12000, "mode": "chat", "output_cost_per_token": 1.8e-06 }, @@ -46366,7 +44870,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 200000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -46380,7 +44883,7 @@ "input_cost_per_token": 1e-06, "litellm_provider": "perplexity", "max_input_tokens": 128000, - "max_tokens": 128000, + "max_output_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-06, "search_context_cost_per_query": { @@ -46395,7 +44898,7 @@ "input_cost_per_token": 2e-06, "litellm_provider": "perplexity", "max_input_tokens": 128000, - "max_tokens": 128000, + "max_output_tokens": 128000, "mode": "chat", "output_cost_per_token": 8e-06, "search_context_cost_per_query": { @@ -46411,7 +44914,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 2.8e-07 }, @@ -46421,7 +44923,6 @@ "litellm_provider": "perplexity", "max_input_tokens": 12000, "max_output_tokens": 12000, - "max_tokens": 12000, "mode": "chat", "output_cost_per_token": 2.8e-07 }, @@ -46430,7 +44931,6 @@ "litellm_provider": "publicai", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://platform.publicai.co/docs", @@ -46442,7 +44942,6 @@ "litellm_provider": "publicai", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://platform.publicai.co/docs", @@ -46454,7 +44953,6 @@ "litellm_provider": "publicai", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://platform.publicai.co/docs", @@ -46466,7 +44964,6 @@ "litellm_provider": "publicai", "max_input_tokens": 16384, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://platform.publicai.co/docs", @@ -46478,7 +44975,6 @@ "litellm_provider": "publicai", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://platform.publicai.co/docs", @@ -46490,7 +44986,6 @@ "litellm_provider": "publicai", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://platform.publicai.co/docs", @@ -46730,7 +45225,6 @@ "input_cost_per_token": 4e-09, "litellm_provider": "perplexity", "max_input_tokens": 32768, - "max_tokens": 32768, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -46740,7 +45234,6 @@ "input_cost_per_token": 3e-08, "litellm_provider": "perplexity", "max_input_tokens": 32768, - "max_tokens": 32768, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 2560, @@ -46751,7 +45244,6 @@ "litellm_provider": "publicai", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://platform.publicai.co/docs", @@ -46763,7 +45255,6 @@ "litellm_provider": "publicai", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://platform.publicai.co/docs", @@ -46776,7 +45267,6 @@ "litellm_provider": "publicai", "max_input_tokens": 32768, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://platform.publicai.co/docs", @@ -46790,7 +45280,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.8e-06, "supports_function_calling": true, @@ -46805,7 +45294,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 8.8e-07, "output_cost_per_token_flex": 4.4e-07, @@ -46825,7 +45313,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -46844,7 +45331,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 32768, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_batches": 3e-07, @@ -46861,7 +45347,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -46877,7 +45362,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.45e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-qwen-qwen3-next-80b-a3b.html", @@ -46893,7 +45377,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.41e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-qwen-qwen3-next-80b-a3b.html", @@ -46909,7 +45392,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.236e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-qwen-qwen3-next-80b-a3b.html", @@ -46925,7 +45407,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.41e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-qwen-qwen3-next-80b-a3b.html", @@ -46941,7 +45422,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.86e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-qwen-qwen3-next-80b-a3b.html", @@ -46957,7 +45437,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.45e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-qwen-qwen3-next-80b-a3b.html", @@ -46975,7 +45454,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 2.66e-06, "output_cost_per_token_batches": 1.33e-06, @@ -46996,7 +45474,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_batches": 6e-07, @@ -47051,7 +45528,6 @@ "litellm_provider": "replicate", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 5e-07, "supports_tool_choice": true @@ -47061,7 +45537,6 @@ "litellm_provider": "replicate", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 5e-07, "supports_tool_choice": true @@ -47071,7 +45546,6 @@ "litellm_provider": "replicate", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.75e-06, "supports_tool_choice": true @@ -47081,7 +45555,6 @@ "litellm_provider": "replicate", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.75e-06, "supports_tool_choice": true @@ -47091,7 +45564,6 @@ "litellm_provider": "replicate", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.5e-07, "supports_tool_choice": true @@ -47101,7 +45573,6 @@ "litellm_provider": "replicate", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.5e-07, "supports_tool_choice": true @@ -47111,7 +45582,6 @@ "litellm_provider": "replicate", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.75e-06, "supports_tool_choice": true @@ -47121,7 +45591,6 @@ "litellm_provider": "replicate", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.75e-06, "supports_tool_choice": true @@ -47131,7 +45600,6 @@ "litellm_provider": "replicate", "max_input_tokens": 8086, "max_output_tokens": 8086, - "max_tokens": 8086, "mode": "chat", "output_cost_per_token": 2.5e-07, "supports_tool_choice": true @@ -47141,7 +45609,6 @@ "litellm_provider": "replicate", "max_input_tokens": 8086, "max_output_tokens": 8086, - "max_tokens": 8086, "mode": "chat", "output_cost_per_token": 2.5e-07, "supports_tool_choice": true @@ -47151,7 +45618,6 @@ "litellm_provider": "replicate", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.5e-07, "supports_tool_choice": true @@ -47161,7 +45627,6 @@ "litellm_provider": "replicate", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.5e-07, "supports_tool_choice": true @@ -47171,7 +45636,6 @@ "litellm_provider": "replicate", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1e-06, "supports_tool_choice": true @@ -47300,7 +45764,6 @@ "mode": "chat", "max_input_tokens": 65536, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_function_calling": true, "supports_system_messages": true }, @@ -47455,7 +45918,6 @@ "mode": "chat", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "supports_function_calling": true, "supports_reasoning": true, "supports_system_messages": true @@ -47476,7 +45938,6 @@ "mode": "chat", "max_input_tokens": 65536, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_reasoning": true, "supports_system_messages": true }, @@ -47486,7 +45947,6 @@ "litellm_provider": "cohere", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "rerank", "output_cost_per_token": 0.0 }, @@ -47496,7 +45956,6 @@ "litellm_provider": "cohere", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "rerank", "output_cost_per_token": 0.0 }, @@ -47506,7 +45965,6 @@ "litellm_provider": "cohere", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "rerank", "output_cost_per_token": 0.0 }, @@ -47516,7 +45974,6 @@ "litellm_provider": "cohere", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://cohere.com/pricing" @@ -47527,7 +45984,6 @@ "litellm_provider": "cohere", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://cohere.com/pricing" @@ -47558,7 +46014,6 @@ "litellm_provider": "sagemaker", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 0.0 }, @@ -47567,7 +46022,6 @@ "litellm_provider": "sagemaker", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -47576,7 +46030,6 @@ "litellm_provider": "sagemaker", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 0.0 }, @@ -47585,7 +46038,6 @@ "litellm_provider": "sagemaker", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -47594,7 +46046,6 @@ "litellm_provider": "sagemaker", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "completion", "output_cost_per_token": 0.0 }, @@ -47603,7 +46054,6 @@ "litellm_provider": "sagemaker", "max_input_tokens": 4096, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -47612,7 +46062,6 @@ "litellm_provider": "sambanova", "max_input_tokens": 196608, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://cloud.sambanova.ai/plans/pricing", @@ -47625,7 +46074,6 @@ "litellm_provider": "sambanova", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 7e-06, "source": "https://cloud.sambanova.ai/plans/pricing" @@ -47635,7 +46083,6 @@ "litellm_provider": "sambanova", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "metadata": { "notes": "For vision models, images are converted to 6432 input tokens and are billed at that amount" }, @@ -47652,7 +46099,6 @@ "litellm_provider": "sambanova", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://cloud.sambanova.ai/plans/pricing", @@ -47661,7 +46107,6 @@ "supports_tool_choice": true }, "sambanova/DeepSeek-V3.1": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 3e-06, @@ -47674,7 +46119,6 @@ "source": "https://cloud.sambanova.ai/plans/pricing" }, "sambanova/gpt-oss-120b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2.2e-07, @@ -47687,7 +46131,6 @@ "source": "https://cloud.sambanova.ai/plans/pricing" }, "sambanova/DeepSeek-V3.2": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 3e-06, @@ -47699,7 +46142,6 @@ "source": "https://cloud.sambanova.ai/plans/pricing" }, "sambanova/gemma-4-31B-it": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 3.8e-07, @@ -47715,7 +46157,6 @@ "litellm_provider": "scx-ai", "max_input_tokens": 1000000, "max_output_tokens": 375000, - "max_tokens": 375000, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://scx.ai/models/deepseek-v4-1-flash", @@ -47730,7 +46171,6 @@ "litellm_provider": "scx-ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3.08e-06, "source": "https://scx.ai/models/glm-5-3", @@ -47746,7 +46186,6 @@ "litellm_provider": "scx-ai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 1.413e-05, "source": "https://scx.ai/models/kimi-k3", @@ -47762,7 +46201,6 @@ "litellm_provider": "scx-ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.98e-06, "source": "https://scx.ai/pricing", @@ -47779,7 +46217,6 @@ "litellm_provider": "scx-ai", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.99e-06, "source": "https://scx.ai/pricing", @@ -47794,7 +46231,6 @@ "litellm_provider": "snowflake", "max_input_tokens": 200000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "input_cost_per_token": 3e-06, "output_cost_per_token": 1.5e-05, @@ -47810,7 +46246,6 @@ "litellm_provider": "snowflake", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "input_cost_per_token": 1.35e-06, "output_cost_per_token": 5.4e-06, @@ -47821,56 +46256,48 @@ "litellm_provider": "snowflake", "max_input_tokens": 8000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/jamba-1.5-large": { "litellm_provider": "snowflake", "max_input_tokens": 256000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/jamba-1.5-mini": { "litellm_provider": "snowflake", "max_input_tokens": 256000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/jamba-instruct": { "litellm_provider": "snowflake", "max_input_tokens": 256000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/llama2-70b-chat": { "litellm_provider": "snowflake", "max_input_tokens": 4096, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/llama3-70b": { "litellm_provider": "snowflake", "max_input_tokens": 8000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/llama3-8b": { "litellm_provider": "snowflake", "max_input_tokens": 8000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/llama3.1-405b": { "litellm_provider": "snowflake", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "input_cost_per_token": 1.2e-06, "output_cost_per_token": 1.2e-06, @@ -47881,7 +46308,6 @@ "litellm_provider": "snowflake", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "input_cost_per_token": 7.2e-07, "output_cost_per_token": 7.2e-07, @@ -47892,7 +46318,6 @@ "litellm_provider": "snowflake", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "input_cost_per_token": 2.4e-07, "output_cost_per_token": 2.4e-07, @@ -47902,18 +46327,15 @@ "litellm_provider": "snowflake", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/llama3.2-3b": { "litellm_provider": "snowflake", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/llama3.3-70b": { - "max_tokens": 16384, "max_input_tokens": 128000, "max_output_tokens": 16384, "input_cost_per_token": 7.2e-07, @@ -47927,21 +46349,18 @@ "litellm_provider": "snowflake", "max_input_tokens": 32000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/mistral-large": { "litellm_provider": "snowflake", "max_input_tokens": 32000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/mistral-large2": { "litellm_provider": "snowflake", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "input_cost_per_token": 2e-06, "output_cost_per_token": 6e-06, @@ -47953,39 +46372,33 @@ "litellm_provider": "snowflake", "max_input_tokens": 32000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/reka-core": { "litellm_provider": "snowflake", "max_input_tokens": 32000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/reka-flash": { "litellm_provider": "snowflake", "max_input_tokens": 100000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/snowflake-arctic": { "litellm_provider": "snowflake", "max_input_tokens": 4096, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/snowflake-llama-3.1-405b": { "litellm_provider": "snowflake", "max_input_tokens": 8000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat" }, "snowflake/snowflake-llama-3.3-70b": { - "max_tokens": 16384, "max_input_tokens": 128000, "max_output_tokens": 16384, "input_cost_per_token": 7.2e-07, @@ -48182,21 +46595,18 @@ "stability.sd3-5-large-v1:0": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.08 }, "stability.sd3-large-v1:0": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.08 }, "stability.stable-image-core-v1:0": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.04 }, @@ -48372,21 +46782,18 @@ "stability.stable-image-core-v1:1": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.04 }, "stability.stable-image-ultra-v1:0": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.14 }, "stability.stable-image-ultra-v1:1": { "litellm_provider": "bedrock", "max_input_tokens": 77, - "max_tokens": 77, "mode": "image_generation", "output_cost_per_image": 0.14 }, @@ -48420,7 +46827,6 @@ "litellm_provider": "text-completion-codestral", "max_input_tokens": 32000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "completion", "output_cost_per_token": 0.0, "source": "https://docs.mistral.ai/capabilities/code_generation/" @@ -48430,7 +46836,6 @@ "litellm_provider": "text-completion-codestral", "max_input_tokens": 32000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "completion", "output_cost_per_token": 0.0, "source": "https://docs.mistral.ai/capabilities/code_generation/" @@ -48441,7 +46846,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 2048, - "max_tokens": 2048, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 768, @@ -48453,7 +46857,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 2048, - "max_tokens": 2048, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 768, @@ -48464,7 +46867,6 @@ "input_cost_per_token_batches": 6.5e-08, "litellm_provider": "openai", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding", "output_cost_per_token": 0.0, "output_cost_per_token_batches": 0.0, @@ -48476,7 +46878,6 @@ "input_cost_per_token_batches": 1e-08, "litellm_provider": "openai", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding", "output_cost_per_token": 0.0, "output_cost_per_token_batches": 0.0, @@ -48487,7 +46888,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "openai", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1536, @@ -48498,7 +46898,6 @@ "input_cost_per_token_batches": 5e-08, "litellm_provider": "openai", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding", "output_cost_per_token": 0.0, "output_cost_per_token_batches": 0.0 @@ -48508,7 +46907,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 3072, @@ -48518,7 +46916,6 @@ "input_cost_per_token": 6.25e-09, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 3072, - "max_tokens": 3072, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 768, @@ -48530,7 +46927,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "vertex_ai-embedding-models", "max_input_tokens": 2048, - "max_tokens": 2048, "mode": "embedding", "output_cost_per_token": 0, "output_vector_size": 768, @@ -48541,7 +46937,6 @@ "litellm_provider": "vertex_ai-text-models", "max_input_tokens": 8192, "max_output_tokens": 1024, - "max_tokens": 1024, "mode": "completion", "output_cost_per_token": 2.8e-05, "source": "https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models#foundation_models" @@ -48551,7 +46946,6 @@ "litellm_provider": "vertex_ai-text-models", "max_input_tokens": 8192, "max_output_tokens": 1024, - "max_tokens": 1024, "mode": "completion", "output_cost_per_token": 2.8e-05, "source": "https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models#foundation_models" @@ -48577,7 +46971,8 @@ "together-ai-8.1b-21b": { "input_cost_per_token": 3e-07, "litellm_provider": "together_ai", - "max_tokens": 1000, + "max_output_tokens": 1000, + "max_input_tokens": 1000, "mode": "chat", "output_cost_per_token": 3e-07 }, @@ -48630,7 +47025,6 @@ "litellm_provider": "together_ai", "max_input_tokens": 65536, "max_output_tokens": 8192, - "max_tokens": 8192, "metadata": { "successor": "together_ai/deepseek-ai/DeepSeek-V4-Pro-0813" }, @@ -48646,7 +47040,7 @@ "input_cost_per_token": 1.04e-06, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.04e-06, "source": "https://api.together.ai/v1/models", @@ -48673,7 +47067,7 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://api.together.ai/v1/models", @@ -48694,7 +47088,7 @@ "input_cost_per_token": 6e-07, "litellm_provider": "together_ai", "max_input_tokens": 202752, - "max_tokens": 202752, + "max_output_tokens": 202752, "metadata": { "successor": "together_ai/zai-org/GLM-5.2" }, @@ -48708,10 +47102,11 @@ }, "together_ai/MiniMaxAI/MiniMax-M3": { "cache_read_input_token_cost": 6e-08, + "deprecation_date": "2026-11-06", "input_cost_per_token": 3e-07, "litellm_provider": "together_ai", "max_input_tokens": 524288, - "max_tokens": 524288, + "max_output_tokens": 524288, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://api.together.ai/v1/models", @@ -48728,7 +47123,7 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "together_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://www.together.ai/pricing", @@ -48738,7 +47133,7 @@ "input_cost_per_token": 0.0, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://docs.together.ai/docs/serverless-models" @@ -48747,7 +47142,7 @@ "input_cost_per_token": 1.7e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 2.5e-07, "source": "https://api.together.ai/v1/models", @@ -48762,7 +47157,7 @@ "input_cost_per_token": 5e-07, "litellm_provider": "together_ai", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://api.together.ai/v1/models", @@ -48773,7 +47168,7 @@ "input_cost_per_token": 1.5e-06, "litellm_provider": "together_ai", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 4.5e-06, "source": "https://www.together.ai/pricing", @@ -48783,7 +47178,7 @@ "input_cost_per_token": 3.2e-07, "litellm_provider": "together_ai", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 1.28e-06, "source": "https://api.together.ai/v1/models" @@ -48793,7 +47188,7 @@ "input_cost_per_token": 2e-06, "litellm_provider": "together_ai", "max_input_tokens": 1010000, - "max_tokens": 1010000, + "max_output_tokens": 1010000, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://api.together.ai/v1/models", @@ -48803,7 +47198,7 @@ "input_cost_per_token": 1e-07, "litellm_provider": "together_ai", "max_input_tokens": 32768, - "max_tokens": 32768, + "max_output_tokens": 32768, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://api.together.ai/v1/models" @@ -48814,7 +47209,7 @@ "input_cost_per_token": 1.4e-07, "litellm_provider": "together_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 2.8e-07, "source": "https://api.together.ai/v1/models", @@ -48829,7 +47224,7 @@ "input_cost_per_token": 3e-07, "litellm_provider": "together_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://api.together.ai/v1/models", @@ -48843,7 +47238,7 @@ "input_cost_per_token": 1.32e-06, "litellm_provider": "together_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 3.96e-06, "source": "https://api.together.ai/v1/models", @@ -48858,7 +47253,7 @@ "input_cost_per_token": 3.5e-07, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://api.together.ai/v1/models", @@ -48869,7 +47264,7 @@ "input_cost_per_token": 1.25e-06, "litellm_provider": "together_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 4.25e-06, "source": "https://docs.together.ai/docs/serverless-models", @@ -48882,7 +47277,7 @@ "input_cost_per_token": 3e-06, "litellm_provider": "together_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.5e-05, "reasoning_effort_levels": [ @@ -48901,10 +47296,11 @@ }, "together_ai/thinkingmachines/Inkling": { "cache_read_input_token_cost": 1.7e-07, + "deprecation_date": "2026-11-06", "input_cost_per_token": 1e-06, "litellm_provider": "together_ai", "max_input_tokens": 524288, - "max_tokens": 524288, + "max_output_tokens": 524288, "mode": "chat", "output_cost_per_token": 4.05e-06, "source": "https://api.together.ai/v1/models", @@ -48920,7 +47316,6 @@ "litellm_provider": "together_ai", "max_input_tokens": 1048575, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://api.together.ai/v1/models", @@ -48937,7 +47332,6 @@ "litellm_provider": "together_ai", "max_input_tokens": 1048575, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://api.together.ai/v1/models", @@ -48954,7 +47348,6 @@ "litellm_provider": "together_ai", "max_input_tokens": 1048575, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://api.together.ai/v1/models", @@ -49039,7 +47432,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 2.4e-07, "output_cost_per_token_batches": 1.2e-07, @@ -49058,7 +47450,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 1.4e-07, "output_cost_per_token_batches": 7e-08, @@ -49079,7 +47470,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 300000, "max_output_tokens": 10000, - "max_tokens": 10000, "mode": "chat", "output_cost_per_token": 3.2e-06, "output_cost_per_token_batches": 1.6e-06, @@ -49100,7 +47490,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4e-06, "supports_assistant_prefill": true, @@ -49120,7 +47509,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5.5e-06, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -49148,7 +47536,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -49166,7 +47553,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -49185,7 +47571,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -49203,7 +47588,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_function_calling": true, @@ -49221,7 +47605,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "search_context_cost_per_query": { @@ -49260,7 +47643,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.65e-05, "search_context_cost_per_query": { @@ -49302,7 +47684,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.8e-05, "supports_assistant_prefill": true, @@ -49334,7 +47715,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "prompt_cache_min_tokens": 1024, @@ -49374,7 +47754,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "prompt_cache_min_tokens": 1024, @@ -49413,7 +47792,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "prompt_cache_min_tokens": 512, @@ -49451,7 +47829,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.4e-05, "prompt_cache_min_tokens": 512, @@ -49489,7 +47866,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-05, "supports_adaptive_thinking": true, @@ -49525,7 +47901,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.88e-07, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -49543,7 +47918,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-nvidia-nvidia-nemotron-nano-12b-v2-vl-bf16.html", @@ -49559,7 +47933,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.76e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-nvidia-nvidia-nemotron-nano-9b-v2.html", @@ -49574,7 +47947,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 256000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 7.8e-07, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -49587,11 +47959,11 @@ "supports_vision": false }, "us-gov.openai.gpt-oss-20b-1:0": { + "supports_vision": false, "input_cost_per_token": 8.4e-08, "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 3.6e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-20b.html", @@ -49606,11 +47978,11 @@ "supports_tool_choice": true }, "us-gov.openai.gpt-oss-120b-1:0": { + "supports_vision": false, "input_cost_per_token": 1.8e-07, "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-120b.html", @@ -49637,7 +48009,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "supports_function_calling": true, "supports_prompt_caching": false, @@ -49654,7 +48025,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5.5e-06, "supports_assistant_prefill": true, @@ -49684,7 +48054,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "search_context_cost_per_query": { @@ -49712,7 +48081,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -49749,7 +48117,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "search_context_cost_per_query": { @@ -49786,7 +48153,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.75e-05, "search_context_cost_per_query": { @@ -49826,7 +48192,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "search_context_cost_per_query": { @@ -49857,7 +48222,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 5.4e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-deepseek-deepseek-r1.html", @@ -49873,7 +48237,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "mode": "chat", "output_cost_per_token": 1.85e-06, "output_cost_per_token_batches": 9.25e-07, @@ -49894,7 +48257,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 163840, "max_output_tokens": 163840, - "max_tokens": 163840, "mode": "chat", "output_cost_per_token": 2.22e-06, "output_cost_per_token_flex": 1.11e-06, @@ -49912,7 +48274,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/bedrock/USD/current/bedrock.json", @@ -49926,7 +48287,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.2e-07, "output_cost_per_token_batches": 3.6e-07, @@ -49941,7 +48301,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2.2e-07, "output_cost_per_token_batches": 1.1e-07, @@ -49955,7 +48314,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.6e-07, "source": "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/bedrock/USD/current/bedrock.json", @@ -49969,7 +48327,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-2-1b-instruct.md", @@ -49982,7 +48339,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-meta-llama-3-2-3b-instruct.md", @@ -49995,7 +48351,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/bedrock/USD/current/bedrock.json", @@ -50010,7 +48365,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.2e-07, "output_cost_per_token_batches": 3.6e-07, @@ -50025,7 +48379,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 9.7e-07, "output_cost_per_token_batches": 4.85e-07, @@ -50048,7 +48401,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 10000000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6.6e-07, "output_cost_per_token_batches": 3.3e-07, @@ -50069,7 +48421,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-mistral-ai-pixtral-large.md", @@ -50081,7 +48432,6 @@ "litellm_provider": "v0", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -50095,7 +48445,6 @@ "litellm_provider": "v0", "max_input_tokens": 512000, "max_output_tokens": 512000, - "max_tokens": 512000, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_function_calling": true, @@ -50109,7 +48458,6 @@ "litellm_provider": "v0", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -50123,7 +48471,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 40960, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 2.4e-07 }, @@ -50132,7 +48479,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 40960, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07 }, @@ -50141,7 +48487,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 40960, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 3e-07 }, @@ -50150,7 +48495,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 40960, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -50161,7 +48505,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 262144, "max_output_tokens": 66536, - "max_tokens": 66536, "mode": "chat", "output_cost_per_token": 1.6e-06, "supports_function_calling": true, @@ -50172,7 +48515,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 300000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.4e-07, "supports_vision": true, @@ -50184,7 +48526,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.4e-07, "supports_function_calling": true, @@ -50195,7 +48536,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 300000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 3.2e-06, "supports_vision": true, @@ -50207,7 +48547,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -50218,7 +48557,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.25e-06, "supports_vision": true, @@ -50233,7 +48571,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_vision": true, @@ -50248,7 +48585,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 4e-06, "supports_vision": true, @@ -50263,7 +48599,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_vision": true, @@ -50278,7 +48613,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_vision": true, @@ -50293,7 +48627,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_vision": true, @@ -50308,7 +48641,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -50321,7 +48653,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -50339,7 +48670,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -50357,7 +48687,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -50376,7 +48705,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "supports_assistant_prefill": true, @@ -50396,7 +48724,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_assistant_prefill": true, @@ -50416,7 +48743,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_assistant_prefill": true, @@ -50436,7 +48762,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "supports_assistant_prefill": true, @@ -50459,7 +48784,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "supports_assistant_prefill": false, @@ -50480,7 +48804,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -50500,7 +48823,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -50517,7 +48839,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 256000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1e-05, "supports_function_calling": true, @@ -50529,7 +48850,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -50540,7 +48860,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1e-05, "supports_function_calling": true, @@ -50551,7 +48870,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -50560,7 +48878,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.19e-06, "supports_tool_choice": true @@ -50570,7 +48887,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 9.9e-07, "supports_function_calling": true, @@ -50582,7 +48898,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 9e-07, "supports_tool_choice": true @@ -50592,7 +48907,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 1000000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 2.5e-06, "supports_vision": true, @@ -50611,7 +48925,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1e-05, "supports_vision": true, @@ -50632,7 +48945,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -50641,7 +48953,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2e-07, "supports_vision": true, @@ -50653,7 +48964,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -50662,7 +48972,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -50671,7 +48980,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 32000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-06 }, @@ -50680,7 +48988,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.9e-07, "supports_tool_choice": true @@ -50690,7 +48997,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 8e-08, "supports_tool_choice": true @@ -50700,7 +49006,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "supports_tool_choice": true @@ -50710,7 +49015,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 8e-08, "supports_function_calling": true, @@ -50721,7 +49025,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.6e-07, "supports_vision": true, @@ -50733,7 +49036,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1e-07 }, @@ -50742,7 +49044,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-07, "supports_function_calling": true, @@ -50753,7 +49054,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "supports_vision": true, @@ -50765,7 +49065,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "supports_function_calling": true, @@ -50776,7 +49075,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 6e-07, "supports_tool_choice": true @@ -50786,7 +49084,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 3e-07, "supports_vision": true, @@ -50798,7 +49095,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 256000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 9e-07, "supports_function_calling": true, @@ -50809,7 +49105,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -50818,7 +49113,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.8e-07, "supports_function_calling": true, @@ -50830,7 +49124,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "supports_function_calling": true, @@ -50842,7 +49135,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-06, "supports_function_calling": true @@ -50852,7 +49144,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 4e-08, "supports_function_calling": true, @@ -50863,7 +49154,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1e-07, "supports_vision": true, @@ -50875,7 +49165,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "chat", "output_cost_per_token": 0.0 }, @@ -50884,7 +49173,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 32000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 6e-06, "supports_function_calling": true, @@ -50895,7 +49183,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 7.9e-07 }, @@ -50904,7 +49191,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 32000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -50916,7 +49202,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 65536, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 1.2e-06, "supports_function_calling": true @@ -50926,7 +49211,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1.5e-07, "supports_vision": true, @@ -50939,7 +49223,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 6e-06, "supports_vision": true, @@ -50952,7 +49235,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 2.2e-06, "supports_function_calling": true, @@ -50963,7 +49245,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 32768, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.2e-06 }, @@ -50972,7 +49253,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 32768, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.9e-06 }, @@ -50981,7 +49261,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 16385, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-06, "supports_function_calling": true, @@ -50992,7 +49271,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 8192, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2e-06 }, @@ -51001,7 +49279,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 3e-05, "supports_vision": true, @@ -51015,7 +49292,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "supports_vision": true, @@ -51030,7 +49306,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.6e-06, "supports_vision": true, @@ -51045,7 +49320,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 1047576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4e-07, "supports_vision": true, @@ -51060,7 +49334,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "supports_vision": true, @@ -51075,7 +49348,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-07, "supports_vision": true, @@ -51090,7 +49362,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6e-05, "supports_vision": true, @@ -51105,7 +49376,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8e-06, "supports_vision": true, @@ -51120,7 +49390,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "supports_function_calling": true, @@ -51134,7 +49403,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.4e-06, "supports_vision": true, @@ -51147,7 +49415,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -51156,7 +49423,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -51165,7 +49431,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 0, "max_output_tokens": 0, - "max_tokens": 0, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -51174,7 +49439,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 127000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1e-06 }, @@ -51183,7 +49447,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 200000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 1.5e-05 }, @@ -51192,7 +49455,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 127000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 5e-06 }, @@ -51201,7 +49463,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 127000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 8e-06 }, @@ -51210,7 +49471,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_vision": true, @@ -51222,7 +49482,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_vision": true, @@ -51234,7 +49493,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "chat", "output_cost_per_token": 1e-05, "supports_function_calling": true, @@ -51245,7 +49503,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1e-05, "supports_vision": true, @@ -51257,7 +49514,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -51268,7 +49524,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.5e-05, "supports_function_calling": true @@ -51278,7 +49533,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-07, "supports_function_calling": true, @@ -51289,7 +49543,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4e-06, "supports_function_calling": true, @@ -51300,7 +49553,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_function_calling": true, @@ -51311,7 +49563,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.2e-06, "supports_function_calling": true, @@ -51322,7 +49573,6 @@ "litellm_provider": "vercel_ai_gateway", "max_input_tokens": 128000, "max_output_tokens": 96000, - "max_tokens": 96000, "mode": "chat", "output_cost_per_token": 1.1e-06, "supports_function_calling": true, @@ -51334,7 +49584,6 @@ "input_cost_per_token": 4.5e-07, "max_input_tokens": 200000, "max_output_tokens": 200000, - "max_tokens": 200000, "mode": "chat", "output_cost_per_token": 1.8e-06, "source": "https://vercel.com/ai-gateway/models/glm-4.6", @@ -51385,7 +49634,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 5e-06, "supports_assistant_prefill": true, @@ -51399,7 +49647,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 5e-06, "supports_assistant_prefill": true, @@ -51419,7 +49666,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "output_cost_per_token_batches": 2.5e-06, @@ -51448,7 +49694,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "output_cost_per_token_batches": 2.5e-06, @@ -51471,7 +49716,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -51487,7 +49731,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -51502,7 +49745,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.25e-06, "supports_assistant_prefill": true, @@ -51516,7 +49758,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.25e-06, "supports_assistant_prefill": true, @@ -51530,7 +49771,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_assistant_prefill": true, @@ -51544,7 +49784,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 7.5e-05, "supports_assistant_prefill": true, @@ -51557,7 +49796,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -51570,7 +49808,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.5e-05, "supports_assistant_prefill": true, @@ -51590,7 +49827,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -51625,7 +49861,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -51664,7 +49899,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -51702,7 +49936,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -51739,7 +49972,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -51777,7 +50009,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -51815,7 +50046,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_batches": 2.5e-05, @@ -51853,7 +50083,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "search_context_cost_per_query": { @@ -51897,7 +50126,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_batches": 2.5e-05, @@ -51935,7 +50163,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "search_context_cost_per_query": { @@ -51980,7 +50207,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -52019,7 +50245,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -52056,7 +50281,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "output_cost_per_token_batches": 1.25e-05, @@ -52097,7 +50321,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "output_cost_per_token_batches": 1.25e-05, @@ -52140,7 +50363,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -52179,7 +50401,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "output_cost_per_token_batches": 1.25e-05, @@ -52219,7 +50440,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 7.5e-06, @@ -52249,7 +50469,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -52288,7 +50507,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 7.5e-06, @@ -52327,7 +50545,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 7.5e-06, @@ -52351,7 +50568,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -52363,7 +50579,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -52375,7 +50590,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -52387,7 +50601,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -52399,7 +50612,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -52410,7 +50622,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -52421,7 +50632,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true, @@ -52435,7 +50645,6 @@ "litellm_provider": "vertex_ai-deepseek_models", "max_input_tokens": 163840, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.7e-06, "output_cost_per_token_batches": 8.5e-07, @@ -52457,7 +50666,6 @@ "litellm_provider": "vertex_ai-deepseek_models", "max_input_tokens": 163840, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.68e-06, "output_cost_per_token_batches": 8.4e-07, @@ -52478,7 +50686,6 @@ "litellm_provider": "vertex_ai-deepseek_models", "max_input_tokens": 65336, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 5.4e-06, "output_cost_per_token_batches": 2.7e-06, @@ -52501,7 +50708,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.039, "output_cost_per_image_token": 3e-05, @@ -52560,7 +50766,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.134, "output_cost_per_image_token": 0.00012, @@ -52595,7 +50800,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.134, "output_cost_per_image_token": 0.00012, @@ -52628,7 +50832,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.0672, "output_cost_per_image_token": 6e-05, @@ -52656,7 +50859,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.0672, "output_cost_per_image_token": 6e-05, @@ -52677,7 +50879,6 @@ "cache_read_input_token_cost_batches": 1.25e-08, "cache_read_input_token_cost_flex": 1.25e-08, "cache_read_input_token_cost_priority": 4.5e-08, - "deprecation_date": "2027-06-28", "input_cost_per_image": 0.00028, "input_cost_per_token": 2.5e-07, "input_cost_per_token_batches": 1.25e-07, @@ -52686,7 +50887,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "image_generation", "output_cost_per_image": 0.0336, "output_cost_per_image_token": 3e-05, @@ -52726,7 +50926,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 1.5e-06, "output_cost_per_token": 1.5e-06, @@ -52785,7 +50984,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 1.5e-06, "output_cost_per_token": 1.5e-06, @@ -52846,7 +51044,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 2.5e-06, "output_cost_per_token": 2.5e-06, @@ -52903,7 +51100,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 65536, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_image": 0.134, "output_cost_per_image_token": 0.00012, @@ -52917,7 +51113,6 @@ "litellm_provider": "vertex_ai-ai21_models", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4e-07, "supports_tool_choice": true @@ -52928,7 +51123,6 @@ "litellm_provider": "vertex_ai-ai21_models", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 8e-06, "supports_tool_choice": true @@ -52939,7 +51133,6 @@ "litellm_provider": "vertex_ai-ai21_models", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 8e-06, "supports_tool_choice": true @@ -52950,7 +51143,6 @@ "litellm_provider": "vertex_ai-ai21_models", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4e-07, "supports_tool_choice": true @@ -52961,7 +51153,6 @@ "litellm_provider": "vertex_ai-ai21_models", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4e-07, "supports_tool_choice": true @@ -52991,7 +51182,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "audio_speech", "output_cost_per_image": 0.04, "output_cost_per_token": 0, @@ -53027,7 +51217,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "audio_speech", "output_cost_per_image": 0.08, "output_cost_per_token": 0, @@ -53064,7 +51253,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 128000, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 1.6e-05, "source": "https://console.cloud.google.com/vertex-ai/publishers/meta/model-garden/llama-3.2-90b-vision-instruct-maas", @@ -53077,7 +51265,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 128000, "max_output_tokens": 2048, - "max_tokens": 2048, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://console.cloud.google.com/vertex-ai/publishers/meta/model-garden/llama-3.2-90b-vision-instruct-maas", @@ -53090,7 +51277,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 128000, "max_output_tokens": 2048, - "max_tokens": 2048, "metadata": { "notes": "VertexAI states that The Llama 3.1 API service for llama-3.1-70b-instruct-maas and llama-3.1-8b-instruct-maas are in public preview and at no cost." }, @@ -53106,7 +51292,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 128000, "max_output_tokens": 2048, - "max_tokens": 2048, "metadata": { "notes": "VertexAI states that The Llama 3.2 API service is at no cost during public preview, and will be priced as per dollar-per-1M-tokens at GA." }, @@ -53123,7 +51308,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 1.15e-06, "output_cost_per_token_batches": 5.75e-07, @@ -53145,7 +51329,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 1.15e-06, "output_cost_per_token_batches": 5.75e-07, @@ -53167,7 +51350,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 10000000, "max_output_tokens": 10000000, - "max_tokens": 10000000, "mode": "chat", "output_cost_per_token": 7e-07, "output_cost_per_token_batches": 3.5e-07, @@ -53189,7 +51371,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 10000000, "max_output_tokens": 10000000, - "max_tokens": 10000000, "mode": "chat", "output_cost_per_token": 7e-07, "output_cost_per_token_batches": 3.5e-07, @@ -53210,7 +51391,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://cloud.google.com/vertex-ai/generative-ai/pricing#partner-models", @@ -53221,7 +51401,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://cloud.google.com/vertex-ai/generative-ai/pricing#partner-models", @@ -53232,7 +51411,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://cloud.google.com/vertex-ai/generative-ai/pricing#partner-models", @@ -53245,7 +51423,6 @@ "litellm_provider": "vertex_ai-minimax_models", "max_input_tokens": 196608, "max_output_tokens": 196608, - "max_tokens": 196608, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53259,7 +51436,6 @@ "litellm_provider": "vertex_ai-moonshot_models", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53274,7 +51450,6 @@ "litellm_provider": "vertex_ai-zai_models", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53292,7 +51467,6 @@ "litellm_provider": "vertex_ai-zai_models", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3.2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53309,7 +51483,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53321,7 +51494,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53333,7 +51505,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53345,7 +51516,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53357,7 +51527,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 6e-06, "supports_function_calling": true, @@ -53368,7 +51537,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 6e-06, "supports_function_calling": true, @@ -53379,7 +51547,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 6e-06, "supports_function_calling": true, @@ -53390,7 +51557,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 6e-06, "supports_function_calling": true, @@ -53401,7 +51567,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-06, "supports_function_calling": true, @@ -53412,7 +51577,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-07, "supports_function_calling": true, @@ -53423,7 +51587,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -53436,7 +51599,6 @@ "litellm_provider": "vertex_ai-mistral_models", "max_input_tokens": 32000, "max_output_tokens": 8191, - "max_tokens": 8191, "mode": "chat", "output_cost_per_token": 3e-07, "supports_function_calling": true, @@ -53470,7 +51632,6 @@ "litellm_provider": "vertex_ai-openai_models", "max_input_tokens": 262144, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://cloud.google.com/vertex-ai/generative-ai/docs/maas/google/gemma-4-26b-a4b-it", @@ -53487,7 +51648,6 @@ "litellm_provider": "vertex_ai-openai_models", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3.6e-07, "output_cost_per_token_batches": 1.8e-07, @@ -53500,7 +51660,6 @@ "litellm_provider": "vertex_ai-openai_models", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2.5e-07, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53515,7 +51674,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53532,7 +51690,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53552,7 +51709,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 2000000, "max_output_tokens": 2000000, - "max_tokens": 2000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -53572,7 +51728,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 2000000, "max_output_tokens": 2000000, - "max_tokens": 2000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -53593,7 +51748,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 200000, "max_output_tokens": 200000, - "max_tokens": 200000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -53613,7 +51767,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 524288, "max_output_tokens": 524288, - "max_tokens": 524288, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -53632,7 +51785,6 @@ "litellm_provider": "vertex_ai-qwen_models", "max_input_tokens": 262144, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 8.8e-07, "output_cost_per_token_batches": 4.4e-07, @@ -53652,7 +51804,6 @@ "litellm_provider": "vertex_ai-qwen_models", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.8e-06, "output_cost_per_token_batches": 9e-07, @@ -53669,7 +51820,6 @@ "litellm_provider": "vertex_ai-qwen_models", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53685,7 +51835,6 @@ "litellm_provider": "vertex_ai-qwen_models", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -53698,7 +51847,6 @@ "vertex_ai/veo-3.1-generate-preview": { "litellm_provider": "vertex_ai-video-models", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.4, "output_cost_per_second_4k": 0.6, @@ -53713,7 +51861,6 @@ "vertex_ai/veo-3.1-fast-generate-preview": { "litellm_provider": "vertex_ai-video-models", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.1, "output_cost_per_second_1080p": 0.12, @@ -53730,7 +51877,6 @@ "deprecation_date": "2026-11-17", "litellm_provider": "vertex_ai-video-models", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.4, "output_cost_per_second_4k": 0.6, @@ -53746,7 +51892,6 @@ "deprecation_date": "2026-11-17", "litellm_provider": "vertex_ai-video-models", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.1, "output_cost_per_second_1080p": 0.12, @@ -53762,7 +51907,6 @@ "vertex_ai/veo-3.1-lite-generate-001": { "litellm_provider": "vertex_ai-video-models", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.05, "output_cost_per_second_1080p": 0.08, @@ -53780,7 +51924,6 @@ "litellm_provider": "voyage", "max_input_tokens": 16000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "rerank", "output_cost_per_token": 0.0 }, @@ -53789,7 +51932,6 @@ "litellm_provider": "voyage", "max_input_tokens": 8000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "rerank", "output_cost_per_token": 0.0 }, @@ -53798,7 +51940,6 @@ "litellm_provider": "voyage", "max_input_tokens": 8000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://docs.voyageai.com/docs/pricing" @@ -53808,7 +51949,6 @@ "litellm_provider": "voyage", "max_input_tokens": 4000, "max_output_tokens": 4000, - "max_tokens": 4000, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://docs.voyageai.com/docs/pricing" @@ -53818,7 +51958,6 @@ "litellm_provider": "voyage", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "rerank", "output_cost_per_token": 0.0 }, @@ -53827,7 +51966,6 @@ "litellm_provider": "voyage", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "rerank", "output_cost_per_token": 0.0 }, @@ -53836,7 +51974,6 @@ "litellm_provider": "voyage", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://docs.voyageai.com/docs/pricing" @@ -53846,7 +51983,6 @@ "litellm_provider": "voyage", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://docs.voyageai.com/docs/pricing" @@ -53855,7 +51991,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "voyage", "max_input_tokens": 4000, - "max_tokens": 4000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53863,7 +51998,6 @@ "input_cost_per_token": 6e-08, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53871,7 +52005,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -53881,7 +52014,6 @@ "input_cost_per_token": 1.8e-07, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53889,7 +52021,6 @@ "input_cost_per_token": 2e-08, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53897,7 +52028,6 @@ "input_cost_per_token": 6e-08, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53905,7 +52035,6 @@ "input_cost_per_token": 2e-08, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53913,7 +52042,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 16000, - "max_tokens": 16000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53921,7 +52049,6 @@ "input_cost_per_token": 1.8e-07, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53929,7 +52056,6 @@ "input_cost_per_token": 1.8e-07, "litellm_provider": "voyage", "max_input_tokens": 120000, - "max_tokens": 120000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53937,7 +52063,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53945,7 +52070,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 16000, - "max_tokens": 16000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53953,7 +52077,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 16000, - "max_tokens": 16000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -53963,7 +52086,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 16000, - "max_tokens": 16000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53971,7 +52093,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "voyage", "max_input_tokens": 4096, - "max_tokens": 4096, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53979,7 +52100,6 @@ "input_cost_per_token": 1e-07, "litellm_provider": "voyage", "max_input_tokens": 4000, - "max_tokens": 4000, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -53987,13 +52107,11 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0 }, "wandb/openai/gpt-oss-120b": { "supports_reasoning": true, - "max_tokens": 131072, "max_input_tokens": 131000, "max_output_tokens": 131072, "input_cost_per_token": 3e-08, @@ -54004,7 +52122,6 @@ }, "wandb/openai/gpt-oss-20b": { "supports_reasoning": true, - "max_tokens": 131072, "max_input_tokens": 131000, "max_output_tokens": 131072, "input_cost_per_token": 3e-08, @@ -54014,7 +52131,6 @@ "source": "https://wandb.ai/site/pricing/tokens/" }, "wandb/moonshotai/Kimi-K2.5": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "cache_read_input_token_cost": 1e-07, @@ -54029,7 +52145,6 @@ "supports_vision": true }, "wandb/meta-llama/Llama-3.1-8B-Instruct": { - "max_tokens": 128000, "max_input_tokens": 131000, "max_output_tokens": 128000, "input_cost_per_token": 2.2e-07, @@ -54040,7 +52155,6 @@ }, "wandb/deepseek-ai/DeepSeek-V3.1": { "supports_reasoning": true, - "max_tokens": 128000, "max_input_tokens": 161000, "max_output_tokens": 128000, "input_cost_per_token": 5.5e-07, @@ -54050,7 +52164,6 @@ "source": "https://wandb.ai/site/pricing/tokens/" }, "wandb/meta-llama/Llama-3.3-70B-Instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 7.1e-07, @@ -54064,7 +52177,6 @@ "litellm_provider": "watsonx", "max_input_tokens": 8192, "max_output_tokens": 1024, - "max_tokens": 1024, "mode": "chat", "output_cost_per_token": 2e-07, "supports_audio_input": false, @@ -54082,7 +52194,6 @@ "litellm_provider": "watsonx", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1e-05, "supports_audio_input": false, @@ -54096,7 +52207,6 @@ "supports_vision": false }, "watsonx/bigscience/mt0-xxl-13b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1.908e-06, @@ -54109,7 +52219,6 @@ "source": "https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-models.html?context=wx" }, "watsonx/bigscience/mt0-xxl": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1.908e-06, @@ -54122,7 +52231,6 @@ "source": "https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-models.html?context=wx" }, "watsonx/core42/jais-13b-chat": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 0.0005, @@ -54134,7 +52242,6 @@ "supports_vision": false }, "watsonx/google/flan-t5-xl-3b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 6e-07, @@ -54146,7 +52253,6 @@ "supports_vision": false }, "watsonx/ibm/granite-13b-chat-v2": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 6e-07, @@ -54158,7 +52264,6 @@ "supports_vision": false }, "watsonx/ibm/granite-13b-instruct-v2": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 6e-07, @@ -54170,7 +52275,6 @@ "supports_vision": false }, "watsonx/ibm/granite-3-3-8b-instruct": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -54182,7 +52286,6 @@ "supports_vision": false }, "watsonx/ibm/granite-4-h-small": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 6.36e-08, @@ -54195,7 +52298,6 @@ "source": "https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-models.html?context=wx" }, "watsonx/ibm/granite-guardian-3-2-2b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 1e-07, @@ -54207,7 +52309,6 @@ "supports_vision": false }, "watsonx/ibm/granite-guardian-3-3-8b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -54219,7 +52320,6 @@ "supports_vision": false }, "watsonx/ibm/granite-ttm-1024-96-r2": { - "max_tokens": 512, "max_input_tokens": 512, "max_output_tokens": 512, "input_cost_per_token": 3.8e-07, @@ -54231,7 +52331,6 @@ "supports_vision": false }, "watsonx/ibm/granite-ttm-1536-96-r2": { - "max_tokens": 512, "max_input_tokens": 512, "max_output_tokens": 512, "input_cost_per_token": 3.8e-07, @@ -54243,7 +52342,6 @@ "supports_vision": false }, "watsonx/ibm/granite-ttm-512-96-r2": { - "max_tokens": 512, "max_input_tokens": 512, "max_output_tokens": 512, "input_cost_per_token": 3.8e-07, @@ -54255,7 +52353,6 @@ "supports_vision": false }, "watsonx/ibm/granite-vision-3-2-2b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 1e-07, @@ -54267,7 +52364,6 @@ "supports_vision": true }, "watsonx/meta-llama/llama-3-2-11b-vision-instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 3.5e-07, @@ -54279,7 +52375,6 @@ "supports_vision": true }, "watsonx/meta-llama/llama-3-2-1b-instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 1e-07, @@ -54291,7 +52386,6 @@ "supports_vision": false }, "watsonx/meta-llama/llama-3-2-3b-instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 1.5e-07, @@ -54303,7 +52397,6 @@ "supports_vision": false }, "watsonx/meta-llama/llama-3-2-90b-vision-instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2e-06, @@ -54315,7 +52408,6 @@ "supports_vision": true }, "watsonx/meta-llama/llama-3-3-70b-instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 7.526e-07, @@ -54328,7 +52420,6 @@ "source": "https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-models.html?context=wx" }, "watsonx/meta-llama/llama-4-maverick-17b": { - "max_tokens": 8192, "max_input_tokens": 131072, "max_output_tokens": 8192, "input_cost_per_token": 3.71e-07, @@ -54341,7 +52432,6 @@ "source": "https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-models.html?context=wx" }, "watsonx/meta-llama/llama-4-maverick-17b-128e-instruct-fp8": { - "max_tokens": 8192, "max_input_tokens": 131072, "max_output_tokens": 8192, "input_cost_per_token": 3.71e-07, @@ -54354,7 +52444,6 @@ "source": "https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-models.html?context=wx" }, "watsonx/meta-llama/llama-guard-3-11b-vision": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 3.5e-07, @@ -54366,7 +52455,6 @@ "supports_vision": true }, "watsonx/mistralai/mistral-medium-2505": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 3e-06, @@ -54378,7 +52466,6 @@ "supports_vision": false }, "watsonx/mistralai/mistral-small-2503": { - "max_tokens": 32000, "max_input_tokens": 32000, "max_output_tokens": 32000, "input_cost_per_token": 1e-07, @@ -54390,7 +52477,6 @@ "supports_vision": false }, "watsonx/mistralai/mistral-small-3-1-24b-instruct-2503": { - "max_tokens": 16384, "max_input_tokens": 131072, "max_output_tokens": 16384, "input_cost_per_token": 1.06e-07, @@ -54403,7 +52489,6 @@ "source": "https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-models.html?context=wx" }, "watsonx/mistralai/pixtral-12b-2409": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 3.5e-07, @@ -54415,7 +52500,6 @@ "supports_vision": true }, "watsonx/openai/gpt-oss-120b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.59e-07, @@ -54428,7 +52512,6 @@ "source": "https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-models.html?context=wx" }, "watsonx/sdaia/allam-1-13b-instruct": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 1.8e-06, @@ -54465,7 +52548,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "responses", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -54490,7 +52572,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -54514,7 +52595,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -54540,7 +52620,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -54568,7 +52647,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -54596,7 +52674,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_above_200k_tokens": 5e-06, @@ -54620,7 +52697,6 @@ "litellm_provider": "xai", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -54642,7 +52718,6 @@ "litellm_provider": "xai", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -54664,7 +52739,6 @@ "litellm_provider": "xai", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -54686,7 +52760,6 @@ "litellm_provider": "xai", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -54708,7 +52781,6 @@ "litellm_provider": "xai", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -54730,7 +52802,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 203000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-06, "output_cost_per_token_batches": 1.1e-06, @@ -54753,7 +52824,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token_batches": 1.6e-06, "output_cost_per_token_priority": 5.6e-06, @@ -54776,7 +52846,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 203000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4e-07, "output_cost_per_token_batches": 2e-07, @@ -55374,7 +53443,6 @@ } }, "fireworks_ai/accounts/fireworks/models/qwen3-coder-480b-a35b-instruct": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 4.5e-07, @@ -55384,7 +53452,6 @@ "supports_reasoning": true }, "fireworks_ai/accounts/fireworks/models/flux-kontext-pro": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 4e-08, @@ -55393,7 +53460,6 @@ "mode": "image_generation" }, "fireworks_ai/accounts/fireworks/models/SSD-1B": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1.3e-10, @@ -55402,7 +53468,6 @@ "mode": "image_generation" }, "fireworks_ai/accounts/fireworks/models/chronos-hermes-13b-v2": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -55411,7 +53476,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-13b": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2e-07, @@ -55420,7 +53484,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-13b-instruct": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2e-07, @@ -55429,7 +53492,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-13b-python": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2e-07, @@ -55438,7 +53500,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-34b": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 9e-07, @@ -55447,7 +53508,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-34b-instruct": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 9e-07, @@ -55456,7 +53516,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-34b-python": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 9e-07, @@ -55465,7 +53524,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-70b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -55474,7 +53532,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-70b-instruct": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -55483,7 +53540,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-70b-python": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -55492,7 +53548,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-7b": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2e-07, @@ -55501,7 +53556,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-7b-instruct": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2e-07, @@ -55510,7 +53564,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-llama-7b-python": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2e-07, @@ -55519,7 +53572,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/code-qwen-1p5-7b": { - "max_tokens": 65536, "max_input_tokens": 65536, "max_output_tokens": 65536, "input_cost_per_token": 2e-07, @@ -55528,7 +53580,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/codegemma-2b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 1e-07, @@ -55537,7 +53588,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/codegemma-7b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -55546,7 +53596,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/cogito-671b-v2-p1": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 1.2e-06, @@ -55555,7 +53604,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/cogito-v1-preview-llama-3b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -55564,7 +53612,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/cogito-v1-preview-llama-70b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -55573,7 +53620,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/cogito-v1-preview-llama-8b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -55582,7 +53628,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/cogito-v1-preview-qwen-14b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -55591,7 +53636,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/cogito-v1-preview-qwen-32b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -55600,7 +53644,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/flux-kontext-max": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 8e-08, @@ -55609,7 +53652,6 @@ "mode": "image_generation" }, "fireworks_ai/accounts/fireworks/models/dbrx-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1.2e-06, @@ -55618,7 +53660,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-coder-1b-base": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 1e-07, @@ -55627,7 +53668,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-coder-33b-instruct": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 9e-07, @@ -55636,7 +53676,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-coder-7b-base": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -55645,7 +53684,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-coder-7b-base-v1p5": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -55654,7 +53692,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-coder-7b-instruct-v1p5": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -55663,7 +53700,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-coder-v2-lite-base": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 5e-07, @@ -55672,7 +53708,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-coder-v2-lite-instruct": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 5e-07, @@ -55681,7 +53716,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-prover-v2": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 1.2e-06, @@ -55690,7 +53724,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-r1-0528-distill-qwen3-8b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -55699,7 +53732,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-r1-distill-llama-70b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -55708,7 +53740,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-r1-distill-llama-8b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -55717,7 +53748,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-r1-distill-qwen-14b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -55726,7 +53756,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-r1-distill-qwen-1p5b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -55735,7 +53764,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-r1-distill-qwen-32b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -55744,7 +53772,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-r1-distill-qwen-7b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -55753,7 +53780,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-v2-lite-chat": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 5e-07, @@ -55762,7 +53788,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/deepseek-v2p5": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1.2e-06, @@ -55771,7 +53796,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/devstral-small-2505": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -55780,7 +53804,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/dobby-mini-unhinged-plus-llama-3-1-8b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -55789,7 +53812,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/dobby-unhinged-llama-3-3-70b-new": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -55798,7 +53820,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/dolphin-2-9-2-qwen2-72b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -55807,7 +53828,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/dolphin-2p6-mixtral-8x7b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 5e-07, @@ -55816,7 +53836,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/ernie-4p5-21b-a3b-pt": { - "max_tokens": 4096, "max_input_tokens": 131072, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -55825,7 +53844,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/ernie-4p5-300b-a47b-pt": { - "max_tokens": 4096, "max_input_tokens": 131072, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -55834,7 +53852,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/fare-20b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -55843,7 +53860,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/firefunction-v1": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 5e-07, @@ -55852,7 +53868,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/firellava-13b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -55861,7 +53876,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/firesearch-ocr-v6": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -55870,7 +53884,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/fireworks-asr-large": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 0.0, @@ -55879,7 +53892,6 @@ "mode": "audio_transcription" }, "fireworks_ai/accounts/fireworks/models/fireworks-asr-v2": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 0.0, @@ -55888,7 +53900,6 @@ "mode": "audio_transcription" }, "fireworks_ai/accounts/fireworks/models/flux-1-dev": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -55897,7 +53908,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/flux-1-dev-controlnet-union": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1e-09, @@ -55906,7 +53916,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/flux-1-dev-fp8": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 5e-10, @@ -55915,7 +53924,6 @@ "mode": "image_generation" }, "fireworks_ai/accounts/fireworks/models/flux-1-schnell": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -55924,7 +53932,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/flux-1-schnell-fp8": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 3.5e-10, @@ -55933,7 +53940,6 @@ "mode": "image_generation" }, "fireworks_ai/accounts/fireworks/models/gemma-2b-it": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 1e-07, @@ -55942,7 +53948,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/gemma-3-27b-it": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -55951,7 +53956,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/gemma-7b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -55960,7 +53964,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/gemma-7b-it": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -55969,7 +53972,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/gemma2-9b-it": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -55978,7 +53980,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/glm-4p5v": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.2e-06, @@ -55988,7 +53989,6 @@ "supports_reasoning": true }, "fireworks_ai/accounts/fireworks/models/gpt-oss-safeguard-120b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.2e-06, @@ -55997,7 +53997,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/gpt-oss-safeguard-20b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 5e-07, @@ -56006,7 +54005,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/hermes-2-pro-mistral-7b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56015,7 +54013,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/internvl3-38b": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 9e-07, @@ -56024,7 +54021,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/internvl3-78b": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 9e-07, @@ -56033,7 +54029,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/internvl3-8b": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2e-07, @@ -56042,7 +54037,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/japanese-stable-diffusion-xl": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1.3e-10, @@ -56051,7 +54045,6 @@ "mode": "image_generation" }, "fireworks_ai/accounts/fireworks/models/kat-coder": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 9e-07, @@ -56060,7 +54053,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/kat-dev-32b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -56069,7 +54061,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/kat-dev-72b-exp": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -56078,7 +54069,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-guard-2-8b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -56087,7 +54077,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-guard-3-1b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -56096,7 +54085,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-guard-3-8b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -56105,7 +54093,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v2-13b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -56114,7 +54101,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v2-13b-chat": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -56123,7 +54109,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v2-70b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -56132,7 +54117,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v2-70b-chat": { - "max_tokens": 2048, "max_input_tokens": 2048, "max_output_tokens": 2048, "input_cost_per_token": 9e-07, @@ -56141,7 +54125,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v2-7b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -56150,7 +54133,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v2-7b-chat": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -56159,7 +54141,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3-70b-instruct": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 9e-07, @@ -56168,7 +54149,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3-70b-instruct-hf": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 9e-07, @@ -56177,7 +54157,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3-8b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -56186,7 +54165,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3-8b-instruct-hf": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -56195,7 +54173,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3p1-405b-instruct-long": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -56204,7 +54181,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3p1-70b-instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -56213,7 +54189,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3p1-70b-instruct-1b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -56222,7 +54197,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3p1-nemotron-70b-instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -56231,7 +54205,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3p2-1b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -56240,7 +54213,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3p2-3b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -56249,7 +54221,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llama-v3p3-70b-instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -56258,7 +54229,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llamaguard-7b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -56267,7 +54237,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/llava-yi-34b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -56276,7 +54245,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/minimax-m1-80k": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -56285,7 +54253,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/minimax-m2": { - "max_tokens": 4096, "max_input_tokens": 196608, "max_output_tokens": 4096, "input_cost_per_token": 3e-07, @@ -56294,7 +54261,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/ministral-3-14b-instruct-2512": { - "max_tokens": 256000, "max_input_tokens": 256000, "max_output_tokens": 256000, "input_cost_per_token": 2e-07, @@ -56303,7 +54269,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/ministral-3-3b-instruct-2512": { - "max_tokens": 256000, "max_input_tokens": 256000, "max_output_tokens": 256000, "input_cost_per_token": 1e-07, @@ -56312,7 +54277,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/ministral-3-8b-instruct-2512": { - "max_tokens": 256000, "max_input_tokens": 256000, "max_output_tokens": 256000, "input_cost_per_token": 2e-07, @@ -56321,7 +54285,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mistral-7b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56330,7 +54293,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mistral-7b-instruct-4k": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56339,7 +54301,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mistral-7b-instruct-v0p2": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56348,7 +54309,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mistral-7b-instruct-v3": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56357,7 +54317,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mistral-7b-v0p2": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56366,7 +54325,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mistral-large-3-fp8": { - "max_tokens": 256000, "max_input_tokens": 256000, "max_output_tokens": 256000, "input_cost_per_token": 1.2e-06, @@ -56375,7 +54333,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mistral-nemo-base-2407": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2e-07, @@ -56384,7 +54341,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mistral-nemo-instruct-2407": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2e-07, @@ -56393,7 +54349,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mistral-small-24b-instruct-2501": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 9e-07, @@ -56402,7 +54357,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mixtral-8x22b": { - "max_tokens": 65536, "max_input_tokens": 65536, "max_output_tokens": 65536, "input_cost_per_token": 1.2e-06, @@ -56411,7 +54365,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mixtral-8x22b-instruct": { - "max_tokens": 65536, "max_input_tokens": 65536, "max_output_tokens": 65536, "input_cost_per_token": 1.2e-06, @@ -56420,7 +54373,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mixtral-8x7b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 5e-07, @@ -56429,7 +54381,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mixtral-8x7b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 5e-07, @@ -56438,7 +54389,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mixtral-8x7b-instruct-hf": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 5e-07, @@ -56447,7 +54397,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/mythomax-l2-13b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -56456,7 +54405,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/nemotron-nano-v2-12b-vl": { - "max_tokens": 4096, "max_input_tokens": 131072, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -56465,7 +54413,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/nous-capybara-7b-v1p9": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56474,7 +54421,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/nous-hermes-2-mixtral-8x7b-dpo": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 5e-07, @@ -56483,7 +54429,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/nous-hermes-2-yi-34b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -56492,7 +54437,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/nous-hermes-llama2-13b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -56501,7 +54445,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/nous-hermes-llama2-70b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -56510,7 +54453,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/nous-hermes-llama2-7b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -56519,7 +54461,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/nvidia-nemotron-nano-12b-v2": { - "max_tokens": 131072, "max_input_tokens": 128000, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -56528,7 +54469,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/nvidia-nemotron-nano-9b-v2": { - "max_tokens": 131072, "max_input_tokens": 128000, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -56537,7 +54477,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/openchat-3p5-0106-7b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -56546,7 +54485,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/openhermes-2-mistral-7b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56555,7 +54493,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/openhermes-2p5-mistral-7b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56564,7 +54501,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/openorca-7b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56573,7 +54509,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/phi-2-3b": { - "max_tokens": 2048, "max_input_tokens": 2048, "max_output_tokens": 2048, "input_cost_per_token": 1e-07, @@ -56582,7 +54517,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/phi-3-mini-128k-instruct": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -56591,7 +54525,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/phi-3-vision-128k-instruct": { - "max_tokens": 32064, "max_input_tokens": 32064, "max_output_tokens": 32064, "input_cost_per_token": 2e-07, @@ -56600,7 +54533,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/phind-code-llama-34b-python-v1": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 9e-07, @@ -56609,7 +54541,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/phind-code-llama-34b-v1": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 9e-07, @@ -56618,7 +54549,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/phind-code-llama-34b-v2": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 9e-07, @@ -56627,7 +54557,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/playground-v2-1024px-aesthetic": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1.3e-10, @@ -56636,7 +54565,6 @@ "mode": "image_generation" }, "fireworks_ai/accounts/fireworks/models/playground-v2-5-1024px-aesthetic": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1.3e-10, @@ -56645,7 +54573,6 @@ "mode": "image_generation" }, "fireworks_ai/accounts/fireworks/models/pythia-12b": { - "max_tokens": 2048, "max_input_tokens": 2048, "max_output_tokens": 2048, "input_cost_per_token": 2e-07, @@ -56654,7 +54581,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen-qwq-32b-preview": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 9e-07, @@ -56663,7 +54589,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen-v2p5-14b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56672,7 +54597,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen-v2p5-7b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -56681,7 +54605,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen1p5-72b-chat": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 9e-07, @@ -56690,7 +54613,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2-7b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56699,7 +54621,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2-vl-2b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -56708,7 +54629,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2-vl-72b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 9e-07, @@ -56717,7 +54637,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2-vl-7b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56726,7 +54645,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-0p5b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -56735,7 +54653,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-14b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2e-07, @@ -56744,7 +54661,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-1p5b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -56753,7 +54669,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-32b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -56762,7 +54677,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-32b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 9e-07, @@ -56771,7 +54685,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-72b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -56780,7 +54693,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-72b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 9e-07, @@ -56789,7 +54701,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-7b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56798,7 +54709,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-0p5b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -56807,7 +54717,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-0p5b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -56816,7 +54725,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-14b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56825,7 +54733,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-14b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56834,7 +54741,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-1p5b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -56843,7 +54749,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-1p5b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -56852,7 +54757,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-32b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 9e-07, @@ -56861,7 +54765,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-32b-instruct-128k": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -56870,7 +54773,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-32b-instruct-32k-rope": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 9e-07, @@ -56879,7 +54781,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-32b-instruct-64k": { - "max_tokens": 65536, "max_input_tokens": 65536, "max_output_tokens": 65536, "input_cost_per_token": 9e-07, @@ -56888,7 +54789,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-3b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -56897,7 +54797,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-3b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1e-07, @@ -56906,7 +54805,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-7b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56915,7 +54813,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-coder-7b-instruct": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -56924,7 +54821,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-math-72b-instruct": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -56933,7 +54829,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-vl-32b-instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 9e-07, @@ -56942,7 +54837,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-vl-3b-instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2e-07, @@ -56951,7 +54845,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-vl-72b-instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 9e-07, @@ -56960,7 +54853,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen2p5-vl-7b-instruct": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2e-07, @@ -56969,7 +54861,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-0p6b": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 1e-07, @@ -56978,7 +54869,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-14b": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 2e-07, @@ -56987,7 +54877,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-1p7b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -56996,7 +54885,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-1p7b-fp8-draft": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1e-07, @@ -57005,7 +54893,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-1p7b-fp8-draft-131072": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1e-07, @@ -57014,7 +54901,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-1p7b-fp8-draft-40960": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 1e-07, @@ -57023,7 +54909,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-235b-a22b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 2.2e-07, @@ -57032,7 +54917,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-235b-a22b-instruct-2507": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 2.2e-07, @@ -57041,7 +54925,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-235b-a22b-thinking-2507": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 2.2e-07, @@ -57050,7 +54933,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-30b-a3b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.5e-07, @@ -57059,7 +54941,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-30b-a3b-instruct-2507": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 5e-07, @@ -57068,7 +54949,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-30b-a3b-thinking-2507": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 9e-07, @@ -57077,7 +54957,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-32b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -57087,7 +54966,6 @@ "supports_reasoning": true }, "fireworks_ai/accounts/fireworks/models/qwen3-4b": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 2e-07, @@ -57096,7 +54974,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-4b-instruct-2507": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 2e-07, @@ -57105,7 +54982,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-8b": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 2e-07, @@ -57115,7 +54991,6 @@ "supports_reasoning": true }, "fireworks_ai/accounts/fireworks/models/qwen3-coder-30b-a3b-instruct": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.5e-07, @@ -57124,7 +54999,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-coder-480b-instruct-bf16": { - "max_tokens": 4096, "max_input_tokens": 262144, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -57133,7 +55007,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-embedding-0p6b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 0.0, @@ -57142,7 +55015,6 @@ "mode": "embedding" }, "fireworks_ai/accounts/fireworks/models/qwen3-embedding-4b": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 0.0, @@ -57151,7 +55023,6 @@ "mode": "embedding" }, "fireworks_ai/accounts/fireworks/models/qwen3-next-80b-a3b-instruct": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -57160,7 +55031,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-next-80b-a3b-thinking": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -57169,7 +55039,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-reranker-0p6b": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 0.0, @@ -57178,7 +55047,6 @@ "mode": "rerank" }, "fireworks_ai/accounts/fireworks/models/qwen3-reranker-4b": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 0.0, @@ -57187,7 +55055,6 @@ "mode": "rerank" }, "fireworks_ai/accounts/fireworks/models/qwen3-reranker-8b": { - "max_tokens": 40960, "max_input_tokens": 40960, "max_output_tokens": 40960, "input_cost_per_token": 2e-07, @@ -57197,7 +55064,6 @@ "source": "https://api.fireworks.ai/v1/serverless/models" }, "fireworks_ai/accounts/fireworks/models/qwen3-vl-235b-a22b-instruct": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 2.2e-07, @@ -57206,7 +55072,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-vl-235b-a22b-thinking": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 2.2e-07, @@ -57215,7 +55080,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-vl-30b-a3b-instruct": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.5e-07, @@ -57224,7 +55088,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-vl-30b-a3b-thinking": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.5e-07, @@ -57233,7 +55096,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-vl-32b-instruct": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -57242,7 +55104,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/qwen3-vl-8b-instruct": { - "max_tokens": 4096, "max_input_tokens": 262144, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -57256,7 +55117,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.6e-06, "source": "https://api.fireworks.ai/v1/serverless/models", @@ -57267,7 +55127,6 @@ "supports_vision": true }, "fireworks_ai/accounts/fireworks/models/qwq-32b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-07, @@ -57276,7 +55135,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/rolm-ocr": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 2e-07, @@ -57285,7 +55143,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/snorkel-mistral-7b-pairrm-dpo": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -57294,7 +55151,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/stable-diffusion-xl-1024-v1-0": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1.3e-10, @@ -57303,7 +55159,6 @@ "mode": "image_generation" }, "fireworks_ai/accounts/fireworks/models/stablecode-3b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 1e-07, @@ -57312,7 +55167,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/starcoder-16b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -57321,7 +55175,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/starcoder-7b": { - "max_tokens": 8192, "max_input_tokens": 8192, "max_output_tokens": 8192, "input_cost_per_token": 2e-07, @@ -57330,7 +55183,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/starcoder2-15b": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2e-07, @@ -57339,7 +55191,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/starcoder2-3b": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 1e-07, @@ -57348,7 +55199,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/starcoder2-7b": { - "max_tokens": 16384, "max_input_tokens": 16384, "max_output_tokens": 16384, "input_cost_per_token": 2e-07, @@ -57357,7 +55207,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/toppy-m-7b": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -57366,7 +55215,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/yi-34b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -57375,7 +55223,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/yi-34b-200k-capybara": { - "max_tokens": 200000, "max_input_tokens": 200000, "max_output_tokens": 200000, "input_cost_per_token": 9e-07, @@ -57384,7 +55231,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/yi-34b-chat": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 9e-07, @@ -57393,7 +55239,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/yi-6b": { - "max_tokens": 4096, "max_input_tokens": 4096, "max_output_tokens": 4096, "input_cost_per_token": 2e-07, @@ -57402,7 +55247,6 @@ "mode": "chat" }, "fireworks_ai/accounts/fireworks/models/zephyr-7b-beta": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 2e-07, @@ -57416,7 +55260,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 202800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 8.8e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -57433,7 +55276,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -57450,7 +55292,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -57465,7 +55306,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 256000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 3.6e-06, "supports_function_calling": true, @@ -57477,7 +55317,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 256000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-06, "supports_function_calling": true, @@ -57489,7 +55328,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 256000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 2.25e-06, "supports_function_calling": true @@ -57505,7 +55343,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 128000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-07, "supports_function_calling": true, @@ -57516,7 +55353,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 128000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 6e-07, "supports_function_calling": true @@ -57532,7 +55368,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 256000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 5e-07, "supports_function_calling": true, @@ -57544,7 +55379,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 256000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 7.5e-06, "supports_reasoning": true, @@ -57557,7 +55391,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 128000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3.5e-07, "supports_function_calling": true, @@ -57568,7 +55401,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 2e-07, "supports_vision": true, @@ -57586,7 +55418,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 9e-07, "supports_function_calling": true @@ -57598,7 +55429,6 @@ "output_cost_per_token": 4e-07, "max_input_tokens": 163840, "max_output_tokens": 65536, - "max_tokens": 65536, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57615,7 +55445,6 @@ "output_cost_per_token": 1.2e-06, "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57631,7 +55460,6 @@ "output_cost_per_token": 2.2e-06, "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57648,7 +55476,6 @@ "output_cost_per_token": 3.3e-07, "max_input_tokens": 262144, "max_output_tokens": 32000, - "max_tokens": 32000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57665,7 +55492,6 @@ "output_cost_per_token": 1.38e-07, "max_input_tokens": 65536, "max_output_tokens": 65536, - "max_tokens": 65536, "supports_vision": true, "supports_system_messages": true }, @@ -57676,7 +55502,6 @@ "output_cost_per_token": 2.5e-06, "max_input_tokens": 262144, "max_output_tokens": 100352, - "max_tokens": 100352, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57693,7 +55518,6 @@ "output_cost_per_token": 1.2e-06, "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57710,7 +55534,6 @@ "output_cost_per_token": 2e-08, "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "supports_vision": true, "supports_system_messages": true }, @@ -57721,7 +55544,6 @@ "output_cost_per_token": 4.1e-07, "max_input_tokens": 163840, "max_output_tokens": 65536, - "max_tokens": 65536, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57736,7 +55558,6 @@ "output_cost_per_token": 3.95e-06, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_vision": true, "supports_system_messages": true, "supports_reasoning": true, @@ -57750,7 +55571,6 @@ "output_cost_per_token": 9e-07, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57768,7 +55588,6 @@ "output_cost_per_token": 2.2e-06, "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57785,7 +55604,6 @@ "output_cost_per_token": 1.2e-06, "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57801,7 +55619,6 @@ "output_cost_per_token": 1.5e-06, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57816,7 +55633,6 @@ "output_cost_per_token": 1.5e-06, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57831,7 +55647,6 @@ "output_cost_per_token": 3e-08, "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_tool_choice": true, "supports_vision": true, "supports_system_messages": true, @@ -57844,7 +55659,6 @@ "output_cost_per_token": 1e-06, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57861,7 +55675,6 @@ "output_cost_per_token": 1.5e-06, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57876,7 +55689,6 @@ "output_cost_per_token": 8.45e-06, "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57890,7 +55702,6 @@ "output_cost_per_token": 6e-07, "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "supports_tool_choice": true, "supports_vision": true, "supports_system_messages": true, @@ -57903,7 +55714,6 @@ "output_cost_per_token": 1e-06, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57920,7 +55730,6 @@ "output_cost_per_token": 2.5e-06, "max_input_tokens": 262144, "max_output_tokens": 100352, - "max_tokens": 100352, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57934,7 +55743,6 @@ "output_cost_per_token": 1.55e-06, "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57948,7 +55756,6 @@ "output_cost_per_token": 2.7e-07, "max_input_tokens": 160000, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57962,7 +55769,6 @@ "output_cost_per_token": 2.5e-07, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57978,7 +55784,6 @@ "output_cost_per_token": 2.3e-06, "max_input_tokens": 131072, "max_output_tokens": 100352, - "max_tokens": 100352, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -57992,7 +55797,6 @@ "output_cost_per_token": 1.12e-06, "max_input_tokens": 163840, "max_output_tokens": 65536, - "max_tokens": 65536, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58008,7 +55812,6 @@ "output_cost_per_token": 2.2e-06, "max_input_tokens": 131072, "max_output_tokens": 98304, - "max_tokens": 98304, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58024,7 +55827,6 @@ "output_cost_per_token": 3e-06, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58038,7 +55840,6 @@ "output_cost_per_token": 5e-08, "max_input_tokens": 16384, "max_output_tokens": 16384, - "max_tokens": 16384, "supports_system_messages": true, "supports_response_schema": true }, @@ -58049,7 +55850,6 @@ "output_cost_per_token": 1e-07, "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_tool_choice": true, "supports_vision": true, "supports_system_messages": true, @@ -58062,7 +55862,6 @@ "output_cost_per_token": 1.8e-06, "max_input_tokens": 65536, "max_output_tokens": 16384, - "max_tokens": 16384, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58080,7 +55879,6 @@ "output_cost_per_token": 1.5e-07, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_tool_choice": true, "supports_vision": false, "supports_system_messages": true, @@ -58094,7 +55892,6 @@ "output_cost_per_token": 5.8e-07, "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58108,7 +55905,6 @@ "output_cost_per_token": 1.5e-07, "max_input_tokens": 32768, "max_output_tokens": 16384, - "max_tokens": 16384, "supports_tool_choice": true, "supports_system_messages": true, "supports_response_schema": true, @@ -58121,7 +55917,6 @@ "output_cost_per_token": 4e-07, "max_input_tokens": 12288, "max_output_tokens": 12288, - "max_tokens": 12288, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58135,7 +55930,6 @@ "output_cost_per_token": 4e-07, "max_input_tokens": 32000, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58149,7 +55943,6 @@ "output_cost_per_token": 1.7e-07, "max_input_tokens": 60288, "max_output_tokens": 16000, - "max_tokens": 16000, "supports_tool_choice": true, "supports_system_messages": true, "supports_response_schema": true @@ -58161,7 +55954,6 @@ "output_cost_per_token": 2.2e-06, "max_input_tokens": 1000000, "max_output_tokens": 40000, - "max_tokens": 40000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58176,7 +55968,6 @@ "output_cost_per_token": 2.5e-06, "max_input_tokens": 163840, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58193,7 +55984,6 @@ "output_cost_per_token": 3e-07, "max_input_tokens": 64000, "max_output_tokens": 32000, - "max_tokens": 32000, "supports_tool_choice": true, "supports_system_messages": true, "supports_response_schema": true, @@ -58206,7 +55996,6 @@ "output_cost_per_token": 4e-08, "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_system_messages": true, "supports_response_schema": true }, @@ -58217,7 +56006,6 @@ "output_cost_per_token": 6.2e-07, "max_input_tokens": 65535, "max_output_tokens": 8000, - "max_tokens": 8000, "supports_system_messages": true, "supports_response_schema": true }, @@ -58228,7 +56016,6 @@ "output_cost_per_token": 9e-08, "max_input_tokens": 128000, "max_output_tokens": 32000, - "max_tokens": 32000, "supports_system_messages": true, "supports_reasoning": true }, @@ -58239,7 +56026,6 @@ "output_cost_per_token": 8e-07, "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_tool_choice": true, "supports_system_messages": true, "supports_response_schema": true, @@ -58252,7 +56038,6 @@ "output_cost_per_token": 7.4e-07, "max_input_tokens": 8192, "max_output_tokens": 8000, - "max_tokens": 8000, "supports_tool_choice": true, "supports_system_messages": true, "supports_response_schema": true @@ -58264,7 +56049,6 @@ "output_cost_per_token": 8e-07, "max_input_tokens": 40960, "max_output_tokens": 20000, - "max_tokens": 20000, "supports_system_messages": true, "supports_reasoning": true, "supports_response_schema": true @@ -58276,7 +56060,6 @@ "output_cost_per_token": 8.5e-07, "max_input_tokens": 1048576, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_vision": true, "supports_system_messages": true, "supports_response_schema": true @@ -58288,7 +56071,6 @@ "output_cost_per_token": 5.9e-07, "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "supports_vision": true, "supports_system_messages": true }, @@ -58299,7 +56081,6 @@ "output_cost_per_token": 1.4e-07, "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_tool_choice": true, "supports_system_messages": true, "supports_response_schema": true @@ -58311,7 +56092,6 @@ "output_cost_per_token": 8e-07, "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_vision": true, "supports_system_messages": true }, @@ -58322,7 +56102,6 @@ "output_cost_per_token": 1.48e-06, "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58335,7 +56114,6 @@ "output_cost_per_token": 2.8e-07, "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "supports_system_messages": true, "supports_reasoning": true }, @@ -58346,7 +56124,6 @@ "output_cost_per_token": 5e-08, "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_tool_choice": true, "supports_system_messages": true, "supports_response_schema": true @@ -58358,7 +56135,6 @@ "output_cost_per_token": 7e-08, "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "supports_system_messages": true }, "novita/baidu/ernie-4.5-vl-424b-a47b": { @@ -58368,7 +56144,6 @@ "output_cost_per_token": 1.25e-06, "max_input_tokens": 123000, "max_output_tokens": 16000, - "max_tokens": 16000, "supports_vision": true, "supports_system_messages": true, "supports_reasoning": true @@ -58380,7 +56155,6 @@ "output_cost_per_token": 1.1e-06, "max_input_tokens": 123000, "max_output_tokens": 12000, - "max_tokens": 12000, "supports_tool_choice": true, "supports_system_messages": true, "supports_response_schema": true @@ -58392,7 +56166,6 @@ "output_cost_per_token": 2.5e-06, "max_input_tokens": 160000, "max_output_tokens": 160000, - "max_tokens": 160000, "supports_system_messages": true }, "novita/qwen/qwen3-32b-fp8": { @@ -58402,7 +56175,6 @@ "output_cost_per_token": 4.5e-07, "max_input_tokens": 40960, "max_output_tokens": 20000, - "max_tokens": 20000, "supports_system_messages": true, "supports_reasoning": true }, @@ -58413,7 +56185,6 @@ "output_cost_per_token": 4.5e-07, "max_input_tokens": 40960, "max_output_tokens": 20000, - "max_tokens": 20000, "supports_system_messages": true, "supports_reasoning": true, "supports_function_calling": true, @@ -58426,7 +56197,6 @@ "output_cost_per_token": 2e-07, "max_input_tokens": 98304, "max_output_tokens": 16384, - "max_tokens": 16384, "supports_vision": true, "supports_system_messages": true }, @@ -58437,7 +56207,6 @@ "output_cost_per_token": 1.3e-06, "max_input_tokens": 64000, "max_output_tokens": 16000, - "max_tokens": 16000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58450,7 +56219,6 @@ "output_cost_per_token": 2.5e-06, "max_input_tokens": 64000, "max_output_tokens": 16000, - "max_tokens": 16000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58465,7 +56233,6 @@ "output_cost_per_token": 5e-08, "max_input_tokens": 8192, "max_output_tokens": 32000, - "max_tokens": 32000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58478,7 +56245,6 @@ "output_cost_per_token": 9e-08, "max_input_tokens": 4096, "max_output_tokens": 3200, - "max_tokens": 3200, "supports_system_messages": true }, "novita/baidu/ernie-4.5-vl-28b-a3b-thinking": { @@ -58488,7 +56254,6 @@ "output_cost_per_token": 3.9e-07, "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58504,7 +56269,6 @@ "output_cost_per_token": 5e-07, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58519,7 +56283,6 @@ "output_cost_per_token": 8.5e-07, "max_input_tokens": 131072, "max_output_tokens": 98304, - "max_tokens": 98304, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58535,7 +56298,6 @@ "output_cost_per_token": 7e-07, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58550,7 +56312,6 @@ "output_cost_per_token": 1e-06, "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58565,7 +56326,6 @@ "output_cost_per_token": 9.7e-07, "max_input_tokens": 65536, "max_output_tokens": 16384, - "max_tokens": 16384, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58582,7 +56342,6 @@ "output_cost_per_token": 9.7e-07, "max_input_tokens": 65536, "max_output_tokens": 16384, - "max_tokens": 16384, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58599,7 +56358,6 @@ "output_cost_per_token": 7.5e-07, "max_input_tokens": 16384, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_system_messages": true }, "novita/baidu/ernie-4.5-vl-28b-a3b": { @@ -58609,7 +56367,6 @@ "output_cost_per_token": 5.6e-07, "max_input_tokens": 30000, "max_output_tokens": 8000, - "max_tokens": 8000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58624,7 +56381,6 @@ "output_cost_per_token": 2.8e-07, "max_input_tokens": 120000, "max_output_tokens": 8000, - "max_tokens": 8000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58637,7 +56393,6 @@ "output_cost_per_token": 1.38e-07, "max_input_tokens": 128000, "max_output_tokens": 20000, - "max_tokens": 20000, "supports_system_messages": true, "supports_reasoning": true }, @@ -58648,7 +56403,6 @@ "output_cost_per_token": 3e-08, "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_system_messages": true, "supports_reasoning": true, "supports_function_calling": true, @@ -58661,7 +56415,6 @@ "output_cost_per_token": 7e-08, "max_input_tokens": 32000, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58675,7 +56428,6 @@ "output_cost_per_token": 5e-08, "max_input_tokens": 32768, "max_output_tokens": 32000, - "max_tokens": 32000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58688,7 +56440,6 @@ "output_cost_per_token": 1.48e-06, "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_tool_choice": true, @@ -58700,8 +56451,7 @@ "input_cost_per_token": 7e-08, "output_cost_per_token": 0, "max_input_tokens": 32768, - "max_output_tokens": 32768, - "max_tokens": 32768 + "max_output_tokens": 32768 }, "novita/qwen/qwen3-embedding-8b": { "litellm_provider": "novita", @@ -58709,8 +56459,7 @@ "input_cost_per_token": 7e-08, "output_cost_per_token": 0, "max_input_tokens": 32768, - "max_output_tokens": 4096, - "max_tokens": 4096 + "max_output_tokens": 4096 }, "novita/baai/bge-m3": { "litellm_provider": "novita", @@ -58718,8 +56467,7 @@ "input_cost_per_token": 1e-08, "output_cost_per_token": 1e-08, "max_input_tokens": 8192, - "max_output_tokens": 96000, - "max_tokens": 96000 + "max_output_tokens": 96000 }, "novita/qwen/qwen3-reranker-8b": { "litellm_provider": "novita", @@ -58727,8 +56475,7 @@ "input_cost_per_token": 5e-08, "output_cost_per_token": 5e-08, "max_input_tokens": 32768, - "max_output_tokens": 4096, - "max_tokens": 4096 + "max_output_tokens": 4096 }, "novita/baai/bge-reranker-v2-m3": { "litellm_provider": "novita", @@ -58736,11 +56483,9 @@ "input_cost_per_token": 1e-08, "output_cost_per_token": 1e-08, "max_input_tokens": 8000, - "max_output_tokens": 8000, - "max_tokens": 8000 + "max_output_tokens": 8000 }, "llamagate/llama-3.1-8b": { - "max_tokens": 8192, "max_input_tokens": 131072, "max_output_tokens": 8192, "input_cost_per_token": 3e-08, @@ -58751,7 +56496,6 @@ "supports_response_schema": true }, "llamagate/llama-3.2-3b": { - "max_tokens": 8192, "max_input_tokens": 131072, "max_output_tokens": 8192, "input_cost_per_token": 4e-08, @@ -58762,7 +56506,6 @@ "supports_response_schema": true }, "llamagate/mistral-7b-v0.3": { - "max_tokens": 8192, "max_input_tokens": 32768, "max_output_tokens": 8192, "input_cost_per_token": 1e-07, @@ -58773,7 +56516,6 @@ "supports_response_schema": true }, "llamagate/qwen3-8b": { - "max_tokens": 8192, "max_input_tokens": 32768, "max_output_tokens": 8192, "input_cost_per_token": 4e-08, @@ -58784,7 +56526,6 @@ "supports_response_schema": true }, "llamagate/dolphin3-8b": { - "max_tokens": 8192, "max_input_tokens": 128000, "max_output_tokens": 8192, "input_cost_per_token": 8e-08, @@ -58795,7 +56536,6 @@ "supports_response_schema": true }, "llamagate/deepseek-r1-8b": { - "max_tokens": 16384, "max_input_tokens": 65536, "max_output_tokens": 16384, "input_cost_per_token": 1e-07, @@ -58807,7 +56547,6 @@ "supports_reasoning": true }, "llamagate/deepseek-r1-7b-qwen": { - "max_tokens": 16384, "max_input_tokens": 131072, "max_output_tokens": 16384, "input_cost_per_token": 8e-08, @@ -58819,7 +56558,6 @@ "supports_reasoning": true }, "llamagate/openthinker-7b": { - "max_tokens": 8192, "max_input_tokens": 32768, "max_output_tokens": 8192, "input_cost_per_token": 8e-08, @@ -58831,7 +56569,6 @@ "supports_reasoning": true }, "llamagate/qwen2.5-coder-7b": { - "max_tokens": 8192, "max_input_tokens": 32768, "max_output_tokens": 8192, "input_cost_per_token": 6e-08, @@ -58842,7 +56579,6 @@ "supports_response_schema": true }, "llamagate/deepseek-coder-6.7b": { - "max_tokens": 4096, "max_input_tokens": 16384, "max_output_tokens": 4096, "input_cost_per_token": 6e-08, @@ -58853,7 +56589,6 @@ "supports_response_schema": true }, "llamagate/codellama-7b": { - "max_tokens": 4096, "max_input_tokens": 16384, "max_output_tokens": 4096, "input_cost_per_token": 6e-08, @@ -58864,7 +56599,6 @@ "supports_response_schema": true }, "llamagate/qwen3-vl-8b": { - "max_tokens": 8192, "max_input_tokens": 32768, "max_output_tokens": 8192, "input_cost_per_token": 1.5e-07, @@ -58876,7 +56610,6 @@ "supports_vision": true }, "llamagate/llava-7b": { - "max_tokens": 2048, "max_input_tokens": 4096, "max_output_tokens": 2048, "input_cost_per_token": 1e-07, @@ -58887,7 +56620,6 @@ "supports_vision": true }, "llamagate/gemma3-4b": { - "max_tokens": 8192, "max_input_tokens": 128000, "max_output_tokens": 8192, "input_cost_per_token": 3e-08, @@ -58899,7 +56631,6 @@ "supports_vision": true }, "llamagate/nomic-embed-text": { - "max_tokens": 8192, "max_input_tokens": 8192, "input_cost_per_token": 2e-08, "output_cost_per_token": 0, @@ -58907,7 +56638,6 @@ "mode": "embedding" }, "llamagate/qwen3-embedding-8b": { - "max_tokens": 40960, "max_input_tokens": 40960, "input_cost_per_token": 2e-08, "output_cost_per_token": 0, @@ -58915,7 +56645,6 @@ "mode": "embedding" }, "libertai/hermes-3-8b-tee": { - "max_tokens": 16000, "max_input_tokens": 16000, "max_output_tokens": 16000, "input_cost_per_token": 1.5e-07, @@ -58929,7 +56658,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/gemma-4-31b-it": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.5e-07, @@ -58943,7 +56671,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/gemma-4-31b-it-thinking": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.5e-07, @@ -58958,7 +56685,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/qwen3.6-27b": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.5e-07, @@ -58972,7 +56698,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/qwen3.6-27b-thinking": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.5e-07, @@ -58987,7 +56712,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/qwen3.6-35b-a3b": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.5e-07, @@ -59001,7 +56725,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/qwen3.6-35b-a3b-thinking": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 1.5e-07, @@ -59016,7 +56739,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/qwen3.5-122b-a10b": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 2.5e-07, @@ -59030,7 +56752,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/qwen3.5-122b-a10b-thinking": { - "max_tokens": 262144, "max_input_tokens": 262144, "max_output_tokens": 262144, "input_cost_per_token": 2.5e-07, @@ -59045,7 +56766,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/deepseek-v4-flash": { - "max_tokens": 200000, "max_input_tokens": 200000, "max_output_tokens": 200000, "input_cost_per_token": 2.5e-07, @@ -59059,7 +56779,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/deepseek-v4-flash-thinking": { - "max_tokens": 200000, "max_input_tokens": 200000, "max_output_tokens": 200000, "input_cost_per_token": 2.5e-07, @@ -59074,7 +56793,6 @@ "source": "https://docs.libertai.io/apis/text/" }, "libertai/bge-m3": { - "max_tokens": 8192, "max_input_tokens": 8192, "input_cost_per_token": 1e-08, "output_cost_per_token": 0.0, @@ -59090,7 +56808,6 @@ "litellm_provider": "sarvam", "max_input_tokens": 8192, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 0, "supports_reasoning": true @@ -59166,7 +56883,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "search_context_cost_per_query": { @@ -59194,7 +56910,6 @@ "litellm_provider": "openai", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "search_context_cost_per_query": { @@ -59226,7 +56941,6 @@ "litellm_provider": "openai", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2.4e-06, @@ -59336,7 +57050,6 @@ "litellm_provider": "gemini", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.039, "output_cost_per_token": 0.0, @@ -59357,7 +57070,6 @@ "litellm_provider": "gemini", "max_input_tokens": 32768, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.039, "output_cost_per_token": 0.0, @@ -59380,7 +57092,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2e-06, @@ -59406,7 +57117,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2e-06, @@ -59433,7 +57143,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2e-06, @@ -59452,6 +57161,7 @@ "supports_audio_input": true, "supports_audio_output": true, "gemini_native_audio": true, + "input_cost_per_video_token": 3e-06, "supports_function_calling": true, "supports_response_schema": false, "supports_vision": true, @@ -59467,7 +57177,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 4.5e-06, @@ -59502,7 +57211,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 4.5e-06, @@ -59536,7 +57244,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 4.5e-06, @@ -59569,7 +57276,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2e-06, @@ -59597,7 +57303,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2e-06, @@ -59626,7 +57331,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2e-06, @@ -59647,6 +57351,7 @@ "tpm": 250000, "rpm": 10, "gemini_native_audio": true, + "input_cost_per_video_token": 3e-06, "supports_function_calling": true, "supports_response_schema": false, "supports_vision": true, @@ -59663,7 +57368,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 4.5e-06, @@ -59700,7 +57404,6 @@ "litellm_provider": "gemini", "max_input_tokens": 8192, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "audio_speech", "output_cost_per_audio_token": 2e-05, "output_cost_per_token": 2e-05, @@ -59727,7 +57430,6 @@ "litellm_provider": "gemini", "max_input_tokens": 8192, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "audio_speech", "output_cost_per_audio_token": 9e-06, "output_cost_per_token": 9e-06, @@ -59752,7 +57454,6 @@ "litellm_provider": "gemini", "max_input_tokens": 8192, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "audio_speech", "output_cost_per_audio_token": 6e-06, "output_cost_per_token": 6e-06, @@ -59772,7 +57473,6 @@ "litellm_provider": "gemini", "max_input_tokens": 8192, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "audio_speech", "output_cost_per_audio_token": 1e-05, "output_cost_per_token": 1e-05, @@ -59792,7 +57492,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 3.75e-06, "output_cost_per_token": 3.75e-06, @@ -59851,7 +57550,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 2.5e-06, "output_cost_per_token": 2.5e-06, @@ -59911,7 +57609,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_200k_tokens": 1.8e-05, @@ -59973,7 +57670,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_200k_tokens": 1.8e-05, @@ -60034,7 +57730,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65535, - "max_tokens": 65535, "mode": "chat", "output_cost_per_reasoning_token": 2.5e-06, "output_cost_per_token": 2.5e-06, @@ -60085,7 +57780,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -60124,7 +57818,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_batches": 7.5e-06, @@ -60156,6 +57849,7 @@ } }, "bedrock_mantle/openai.gpt-oss-120b": { + "supports_vision": false, "input_cost_per_token": 1.5e-07, "input_cost_per_token_batches": 7.5e-08, "input_cost_per_token_flex": 7.5e-08, @@ -60165,7 +57859,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token_batches": 3e-07, "output_cost_per_token_priority": 1.05e-06, @@ -60181,6 +57874,7 @@ "supports_tool_choice": true }, "bedrock_mantle/openai.gpt-oss-20b": { + "supports_vision": false, "input_cost_per_token": 7e-08, "input_cost_per_token_batches": 3.5e-08, "input_cost_per_token_flex": 3.5e-08, @@ -60190,7 +57884,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token_batches": 1.5e-07, "output_cost_per_token_priority": 5.25e-07, @@ -60206,6 +57899,7 @@ "supports_tool_choice": true }, "bedrock_mantle/openai.gpt-oss-safeguard-120b": { + "supports_vision": false, "input_cost_per_token": 1.5e-07, "input_cost_per_token_batches": 7e-08, "input_cost_per_token_flex": 7e-08, @@ -60215,7 +57909,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 131072, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token_batches": 3e-07, "output_cost_per_token_priority": 1.05e-06, @@ -60229,6 +57922,7 @@ "supports_tool_choice": true }, "bedrock_mantle/openai.gpt-oss-safeguard-20b": { + "supports_vision": false, "input_cost_per_token": 7e-08, "input_cost_per_token_batches": 3e-08, "input_cost_per_token_flex": 3e-08, @@ -60238,7 +57932,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 131072, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token_batches": 1e-07, "output_cost_per_token_priority": 3.5e-07, @@ -60266,9 +57959,8 @@ "search_context_size_medium": 0.012 }, "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -60310,9 +58002,8 @@ "search_context_size_medium": 0.012 }, "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -60347,7 +58038,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-56-cyber.html", "use_openai_responses_path": true, @@ -60383,7 +58073,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -60421,9 +58110,8 @@ "search_context_size_medium": 0.012 }, "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -60462,9 +58150,8 @@ "output_cost_per_token_above_272k_tokens": 3.3e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-56-sol.html", "supported_modalities": [ @@ -60499,9 +58186,8 @@ "output_cost_per_token_above_272k_tokens": 3e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-56-sol.html", "supported_modalities": [ @@ -60536,9 +58222,8 @@ "output_cost_per_token_above_272k_tokens": 1.98e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-56-terra.html", "supported_modalities": [ @@ -60573,9 +58258,8 @@ "output_cost_per_token_above_272k_tokens": 1.8e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-56-terra.html", "supported_modalities": [ @@ -60610,9 +58294,8 @@ "output_cost_per_token_above_272k_tokens": 1.98e-06, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-56-luna.html", "supported_modalities": [ @@ -60644,9 +58327,8 @@ "output_cost_per_token_above_272k_tokens": 2.475e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-54.html", "supported_modalities": [ @@ -60676,9 +58358,8 @@ "output_cost_per_token_above_272k_tokens": 2.25e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-54.html", "supported_modalities": [ @@ -60708,9 +58389,8 @@ "output_cost_per_token_above_272k_tokens": 4.95e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-55.html", "supported_modalities": [ @@ -60740,9 +58420,8 @@ "output_cost_per_token_above_272k_tokens": 4.5e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-55.html", "supported_modalities": [ @@ -60775,9 +58454,8 @@ "output_cost_per_token_above_272k_tokens": 1.8e-06, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-56-luna.html", "supported_modalities": [ @@ -60816,9 +58494,8 @@ "output_cost_per_token": 5.5e-05, "output_cost_per_token_above_272k_tokens": 8.25e-05, "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token_above_272k_tokens_ultrafast": 0.000495, "output_cost_per_token_ultrafast": 0.00033, @@ -60857,9 +58534,8 @@ "output_cost_per_token": 1.1e-05, "output_cost_per_token_above_272k_tokens": 1.65e-05, "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -60896,9 +58572,8 @@ "output_cost_per_token": 5.5e-07, "output_cost_per_token_above_272k_tokens": 8.25e-07, "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -60943,9 +58618,8 @@ "output_cost_per_token_above_272k_tokens": 8.25e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token_above_272k_tokens_ultrafast": 0.000495, "output_cost_per_token_ultrafast": 0.00033, @@ -60984,9 +58658,8 @@ "output_cost_per_token_above_272k_tokens": 1.65e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_modalities": [ "text", @@ -61023,9 +58696,8 @@ "output_cost_per_token_above_272k_tokens": 8.25e-07, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_modalities": [ "text", @@ -61068,9 +58740,8 @@ "output_cost_per_token_above_272k_tokens": 7.5e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token_above_272k_tokens_ultrafast": 0.00045, "output_cost_per_token_ultrafast": 0.0003, @@ -61108,9 +58779,8 @@ "output_cost_per_token_above_272k_tokens": 1.5e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_modalities": [ "text", @@ -61143,9 +58813,8 @@ "output_cost_per_token_above_272k_tokens": 1.5e-05, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_modalities": [ "text", @@ -61181,9 +58850,8 @@ "output_cost_per_token_above_272k_tokens": 7.5e-07, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_modalities": [ "text", @@ -61216,9 +58884,8 @@ "output_cost_per_token_above_272k_tokens": 7.5e-07, "litellm_provider": "bedrock_converse", "supports_bedrock_converse_tool_result_images": false, - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supported_modalities": [ "text", @@ -61256,9 +58923,8 @@ "search_context_size_medium": 0.012 }, "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -61296,9 +58962,8 @@ "search_context_size_medium": 0.012 }, "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -61333,7 +58998,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token_batches": 2e-07, "output_cost_per_token_priority": 7e-07, @@ -61359,7 +59023,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token_batches": 2e-07, "output_cost_per_token_priority": 7e-07, @@ -61385,7 +59048,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token_batches": 4e-08, "output_cost_per_token_priority": 1.4e-07, @@ -61415,7 +59077,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 1048576, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token_batches": 1.25e-06, "output_cost_per_token_flex": 1.25e-06, @@ -61443,7 +59104,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token_flex": 3.3e-06, "output_cost_per_token_priority": 1.155e-05, @@ -61468,7 +59128,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5e-06, "source": "https://aws.amazon.com/about-aws/whats-new/2025/10/claude-4-5-haiku-anthropic-amazon-bedrock", @@ -61499,7 +59158,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.2e-05, "search_context_cost_per_query": { @@ -61525,7 +59183,8 @@ "prompt_cache_min_tokens": 512, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-anthropic-claude-opus-5-5.html", "thinking_always_on": true, - "supports_forced_tool_use": false + "supports_forced_tool_use": false, + "token_count_model": {"model":"anthropic.claude-opus-5-5","litellm_provider":"bedrock_mantle","region":"us-east-1"} }, "bedrock_mantle/anthropic.claude-sonnet-5-5": { "bedrock_converse_supports_strict_tools": false, @@ -61537,7 +59196,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "search_context_cost_per_query": { @@ -61585,7 +59243,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token_flex": 3.3e-06, "output_cost_per_token_priority": 1.155e-05, @@ -61613,7 +59270,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token_flex": 3e-06, "output_cost_per_token_priority": 1.05e-05, @@ -61628,7 +59284,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.volcengine.com/docs/82379/1330310", "supports_function_calling": true, @@ -61668,7 +59323,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4.3125e-06, "source": "https://www.volcengine.com/docs/82379/1544106", @@ -61684,7 +59338,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 1024000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4.3125e-06, "source": "https://www.volcengine.com/docs/82379/1544106", @@ -61702,7 +59355,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 1024000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 3.88126e-07, "source": "https://www.volcengine.com/docs/82379/1544106", @@ -61719,7 +59371,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2.15625e-06, "source": "https://www.volcengine.com/docs/82379/1544106", @@ -61733,7 +59384,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.volcengine.com/docs/82379/1330310", "supports_function_calling": true, @@ -61771,7 +59421,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.volcengine.com/docs/82379/1330310", "supports_function_calling": true, @@ -61809,7 +59458,6 @@ "litellm_provider": "volcengine", "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "source": "https://docs.volcengine.com/docs/82379/1330310", "supports_function_calling": true, @@ -61904,7 +59552,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_function_calling": true, "supports_reasoning": true, @@ -61922,7 +59569,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_function_calling": true, "supports_reasoning": true, @@ -61943,7 +59589,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://aws.amazon.com/about-aws/whats-new/2025/10/claude-4-5-haiku-anthropic-amazon-bedrock", @@ -61973,7 +59618,6 @@ "supports_tool_search": true, "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://aws.amazon.com/about-aws/whats-new/2025/10/claude-4-5-haiku-anthropic-amazon-bedrock", @@ -61995,7 +59639,6 @@ } }, "snowflake/claude-sonnet-4-5": { - "max_tokens": 16384, "max_input_tokens": 200000, "max_output_tokens": 16384, "input_cost_per_token": 3e-06, @@ -62013,7 +59656,6 @@ "snowflake/claude-sonnet-4-6": { "supports_adaptive_thinking": true, "supports_legacy_thinking": true, - "max_tokens": 16384, "max_input_tokens": 200000, "max_output_tokens": 16384, "input_cost_per_token": 3e-06, @@ -62029,7 +59671,6 @@ "prompt_cache_min_tokens": 1024 }, "snowflake/claude-4-sonnet": { - "max_tokens": 16384, "max_input_tokens": 200000, "max_output_tokens": 16384, "input_cost_per_token": 3e-06, @@ -62045,7 +59686,6 @@ "prompt_cache_min_tokens": 1024 }, "snowflake/claude-4-opus": { - "max_tokens": 16384, "max_input_tokens": 200000, "max_output_tokens": 16384, "input_cost_per_token": 5e-06, @@ -62062,7 +59702,6 @@ "prompt_cache_min_tokens": 1024 }, "snowflake/claude-haiku-4-5": { - "max_tokens": 16384, "max_input_tokens": 200000, "max_output_tokens": 16384, "input_cost_per_token": 1e-06, @@ -62078,7 +59717,6 @@ "prompt_cache_min_tokens": 4096 }, "snowflake/claude-3-7-sonnet": { - "max_tokens": 16384, "max_input_tokens": 200000, "max_output_tokens": 16384, "input_cost_per_token": 3e-06, @@ -62094,7 +59732,6 @@ "supports_response_schema": true }, "snowflake/openai-gpt-4.1": { - "max_tokens": 16384, "max_input_tokens": 300000, "max_output_tokens": 16384, "input_cost_per_token": 2e-06, @@ -62109,7 +59746,6 @@ "supports_response_schema": true }, "snowflake/openai-gpt-5": { - "max_tokens": 16384, "max_input_tokens": 300000, "max_output_tokens": 16384, "input_cost_per_token": 1.25e-06, @@ -62125,7 +59761,6 @@ "supports_response_schema": true }, "snowflake/openai-gpt-5-mini": { - "max_tokens": 16384, "max_input_tokens": 1000000, "max_output_tokens": 16384, "input_cost_per_token": 3e-07, @@ -62137,7 +59772,6 @@ "supports_response_schema": true }, "snowflake/openai-gpt-5-nano": { - "max_tokens": 16384, "max_input_tokens": 5000000, "max_output_tokens": 16384, "input_cost_per_token": 1.5e-07, @@ -62149,7 +59783,6 @@ "supports_response_schema": true }, "snowflake/llama4-maverick": { - "max_tokens": 16384, "max_input_tokens": 128000, "max_output_tokens": 16384, "input_cost_per_token": 2.4e-07, @@ -62160,7 +59793,6 @@ "supports_system_messages": true }, "snowflake/snowflake-arctic-embed-l-v2.0": { - "max_tokens": 8192, "max_input_tokens": 8192, "input_cost_per_token": 7e-08, "output_cost_per_token": 0.0, @@ -62168,7 +59800,6 @@ "mode": "embedding" }, "snowflake/snowflake-arctic-embed-m-v2.0": { - "max_tokens": 8192, "max_input_tokens": 8192, "input_cost_per_token": 7e-08, "output_cost_per_token": 0.0, @@ -62178,7 +59809,7 @@ "soniox/stt-async-v4": { "litellm_provider": "soniox", "max_output_tokens": 8000, - "max_tokens": 8000, + "max_input_tokens": 8000, "input_cost_per_second": 0.0, "output_cost_per_second": 2.77778e-05, "mode": "audio_transcription", @@ -62191,7 +59822,7 @@ "soniox/stt-async-v5": { "litellm_provider": "soniox", "max_output_tokens": 8000, - "max_tokens": 8000, + "max_input_tokens": 8000, "input_cost_per_second": 0.0, "output_cost_per_second": 2.77778e-05, "mode": "audio_transcription", @@ -62368,7 +59999,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 3e-09, @@ -62422,7 +60052,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 3e-09, @@ -62476,7 +60105,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 3e-09, @@ -62530,7 +60158,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 2.2e-08, @@ -62584,7 +60211,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 3e-09, @@ -62638,7 +60264,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 3e-09, @@ -62692,7 +60317,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 3e-09, @@ -62746,7 +60370,6 @@ "litellm_provider": "deepseek", "max_input_tokens": 1000000, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 2.2e-08, @@ -62800,7 +60423,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 3.48e-06, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -62826,7 +60448,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 2.8e-07, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -62852,7 +60473,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 2.2e-08, @@ -62907,7 +60527,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "off_peak_pricing": { "cache_read_input_token_cost": 3e-09, @@ -62962,7 +60581,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.25e-06, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -62987,7 +60605,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -63012,7 +60629,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -63036,7 +60652,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -63060,7 +60675,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -63084,7 +60698,6 @@ "litellm_provider": "tencent", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -63108,7 +60721,6 @@ "litellm_provider": "tencent", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -63132,7 +60744,6 @@ "litellm_provider": "tencent", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://www.tencentcloud.com/document/product/1300/78937", @@ -63199,7 +60810,6 @@ "source": "https://docs.devin.ai/desktop/models" }, "pinstripes/ps/glm-4.5-air": { - "max_tokens": 128000, "max_input_tokens": 128000, "max_output_tokens": 128000, "input_cost_per_token": 1.25e-07, @@ -63212,7 +60822,6 @@ "source": "https://pinstripes.io/" }, "pinstripes/ps/qwen3.6-35b-a3b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 1.4e-07, @@ -63225,7 +60834,6 @@ "source": "https://pinstripes.io/" }, "pinstripes/ps/qwen3-30b-a3b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 9e-08, @@ -63238,7 +60846,6 @@ "source": "https://pinstripes.io/" }, "pinstripes/ps/qwen3-coder-30b-a3b": { - "max_tokens": 131072, "max_input_tokens": 131072, "max_output_tokens": 131072, "input_cost_per_token": 3e-07, @@ -63251,7 +60858,6 @@ "source": "https://pinstripes.io/" }, "pinstripes/ps/deepseek-v4-flash": { - "max_tokens": 163840, "max_input_tokens": 163840, "max_output_tokens": 163840, "input_cost_per_token": 1e-07, @@ -63264,7 +60870,6 @@ "source": "https://pinstripes.io/" }, "pinstripes/ps/minimax-m2.7": { - "max_tokens": 1000192, "max_input_tokens": 1000192, "max_output_tokens": 1000192, "input_cost_per_token": 2.55e-07, @@ -63281,7 +60886,6 @@ "litellm_provider": "darkbloom", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.65e-07, "source": "https://www.darkbloom.dev/", @@ -63298,7 +60902,6 @@ "litellm_provider": "darkbloom", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 7e-08, "source": "https://www.darkbloom.dev/", @@ -63318,7 +60921,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -63345,7 +60947,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "responses", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -63374,7 +60975,6 @@ "litellm_provider": "xai", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://api.x.ai/v1/language-models", @@ -63447,7 +61047,6 @@ "litellm_provider": "openai", "max_input_tokens": 16000, "max_output_tokens": 2000, - "max_tokens": 2000, "mode": "realtime", "source": "https://developers.openai.com/api/docs/pricing", "supported_modalities": [ @@ -63472,7 +61071,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_batches": 2.5e-05, @@ -63516,7 +61114,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "output_cost_per_token_batches": 2.5e-05, @@ -63559,7 +61156,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-05, "prompt_cache_min_tokens": 512, @@ -63595,7 +61191,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 5e-06, "search_context_cost_per_query": { @@ -63630,7 +61225,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 6e-07, "reasoning_effort_levels": [ @@ -63651,7 +61245,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://docs.mistral.ai/models/model-cards/leanstral-1-5", @@ -63741,7 +61334,6 @@ "mode": "chat", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "supports_function_calling": true, "supports_parallel_function_calling": true, "supports_vision": true, @@ -63840,7 +61432,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "realtime", "output_cost_per_audio_token": 2.1e-05, "output_cost_per_token": 2.1e-05, @@ -63869,7 +61460,6 @@ "litellm_provider": "gemini", "max_input_tokens": 98304, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "audio_transcription", "output_cost_per_token": 1.2e-05, "source": "https://ai.google.dev/gemini-api/docs/pricing", @@ -63894,7 +61484,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "audio_transcription", "output_cost_per_token": 2.1e-05, "source": "https://ai.google.dev/gemini-api/docs/pricing", @@ -63975,7 +61564,6 @@ "input_cost_per_token": 8e-09, "litellm_provider": "perplexity", "max_input_tokens": 32768, - "max_tokens": 32768, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -63985,7 +61573,6 @@ "input_cost_per_token": 5e-08, "litellm_provider": "perplexity", "max_input_tokens": 32768, - "max_tokens": 32768, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 2560, @@ -63995,7 +61582,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -64005,7 +61591,6 @@ "input_cost_per_token": 6e-08, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -64015,7 +61600,6 @@ "input_cost_per_token": 2e-08, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -64025,7 +61609,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -64035,7 +61618,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 120000, - "max_tokens": 120000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -64045,7 +61627,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "voyage", "max_input_tokens": 32000, - "max_tokens": 32000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 1024, @@ -64061,7 +61642,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6.6e-07, "output_cost_per_token_priority": 8.25e-07, @@ -64080,7 +61660,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_priority": 1.5e-06, @@ -64100,7 +61679,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 1.8e-06, "output_cost_per_token_priority": 2.25e-06, @@ -64120,7 +61698,7 @@ "input_cost_per_token_priority": 2.75e-07, "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 6.6e-07, "output_cost_per_token_priority": 8.25e-07, @@ -64138,7 +61716,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_priority": 1.875e-05, @@ -64163,7 +61740,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6.6e-07, "output_cost_per_token_priority": 8.25e-07, @@ -64182,7 +61758,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_priority": 1.5e-06, @@ -64202,7 +61777,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 1.8e-06, "output_cost_per_token_priority": 2.25e-06, @@ -64222,7 +61796,7 @@ "input_cost_per_token_priority": 2.75e-07, "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 6.6e-07, "output_cost_per_token_priority": 8.25e-07, @@ -64239,7 +61813,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6.6e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -64256,7 +61829,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6.6e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -64274,7 +61846,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_priority": 1.875e-05, @@ -64296,7 +61867,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.25e-05, "reasoning_effort_levels": [ @@ -64319,7 +61889,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.25e-05, "output_cost_per_token_priority": 2.8125e-05, @@ -64361,7 +61930,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-06, "output_cost_per_token_priority": 2.25e-06, @@ -64381,7 +61949,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2e-07, "output_cost_per_token_priority": 2.5e-07, @@ -64401,7 +61968,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2.4e-06, "output_cost_per_token_priority": 3e-06, @@ -64421,7 +61987,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 1.5e-06, "output_cost_per_token_priority": 2.25e-06, @@ -64456,7 +62021,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2e-07, "output_cost_per_token_priority": 2.5e-07, @@ -64476,7 +62040,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2.4e-06, "output_cost_per_token_priority": 3e-06, @@ -64511,7 +62074,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6.6e-06, "source": "https://api.fireworks.ai/v1/serverless/models", @@ -64528,7 +62090,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6.6e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -64544,7 +62105,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.25e-05, "reasoning_effort_levels": [ @@ -64567,7 +62127,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.25e-05, "output_cost_per_token_priority": 2.8125e-05, @@ -64589,7 +62148,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://api.novita.ai/v3/openai/models", @@ -64606,7 +62164,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 3.96e-06, "source": "https://novita.ai/pricing", @@ -64623,7 +62180,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://novita.ai/pricing", @@ -64640,7 +62196,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 5.8e-07, "source": "https://novita.ai/pricing", @@ -64657,7 +62212,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://novita.ai/pricing", @@ -64674,7 +62228,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://novita.ai/pricing", @@ -64691,7 +62244,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 1.32e-06, "source": "https://api.novita.ai/v3/openai/models", @@ -64708,7 +62260,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 1.32e-06, "source": "https://novita.ai/pricing", @@ -64725,7 +62276,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.5e-06, "source": "https://novita.ai/pricing", @@ -64741,7 +62291,6 @@ "litellm_provider": "novita", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://novita.ai/pricing", @@ -64758,7 +62307,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 2.8e-07, "source": "https://novita.ai/pricing", @@ -64775,7 +62323,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 3.2000000000000003e-06, "source": "https://novita.ai/pricing", @@ -64792,7 +62339,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.8e-07, "source": "https://novita.ai/pricing", @@ -64808,7 +62354,6 @@ "litellm_provider": "novita", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://novita.ai/pricing", @@ -64825,7 +62370,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.8e-07, "source": "https://novita.ai/pricing", @@ -64841,7 +62385,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2.6e-06, "source": "https://novita.ai/pricing", @@ -64857,7 +62400,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 1.15e-06, "source": "https://novita.ai/pricing", @@ -64873,7 +62415,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 2.0000000000000002e-07, "source": "https://novita.ai/pricing", @@ -64889,7 +62430,6 @@ "litellm_provider": "novita", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.13e-06, "source": "https://novita.ai/pricing", @@ -64905,7 +62445,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3.3600000000000004e-07, "source": "https://novita.ai/pricing", @@ -64922,7 +62461,6 @@ "litellm_provider": "novita", "max_input_tokens": 1000000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3.75e-06, "source": "https://novita.ai/pricing", @@ -64939,7 +62477,6 @@ "litellm_provider": "novita", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.044e-06, "source": "https://novita.ai/pricing", @@ -64955,7 +62492,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3.6000000000000003e-06, "source": "https://novita.ai/pricing", @@ -64971,7 +62507,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 3.4e-06, "source": "https://novita.ai/pricing", @@ -64988,7 +62523,6 @@ "litellm_provider": "novita", "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://novita.ai/pricing", @@ -65005,7 +62539,6 @@ "litellm_provider": "novita", "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://api.novita.ai/v3/openai/models", @@ -65022,7 +62555,6 @@ "litellm_provider": "novita", "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://api.novita.ai/v3/openai/models", @@ -65038,7 +62570,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.0000000000000003e-07, "source": "https://novita.ai/pricing", @@ -65053,7 +62584,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4.0000000000000003e-07, "source": "https://novita.ai/pricing", @@ -65069,7 +62599,6 @@ "litellm_provider": "novita", "max_input_tokens": 202800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://api.novita.ai/v3/openai/models", @@ -65086,7 +62615,6 @@ "litellm_provider": "novita", "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://novita.ai/pricing", @@ -65103,7 +62631,6 @@ "litellm_provider": "novita", "max_input_tokens": 204800, "max_output_tokens": 131100, - "max_tokens": 131100, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://novita.ai/pricing", @@ -65119,7 +62646,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://novita.ai/pricing", @@ -65134,7 +62660,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3.2000000000000003e-06, "source": "https://novita.ai/pricing", @@ -65149,7 +62674,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://novita.ai/pricing", @@ -65164,7 +62688,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3.6000000000000003e-06, "source": "https://novita.ai/pricing", @@ -65180,7 +62703,6 @@ "litellm_provider": "novita", "max_input_tokens": 204800, "max_output_tokens": 131100, - "max_tokens": 131100, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://novita.ai/pricing", @@ -65197,7 +62719,6 @@ "litellm_provider": "novita", "max_input_tokens": 202800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3.2000000000000003e-06, "source": "https://novita.ai/pricing", @@ -65213,7 +62734,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://novita.ai/pricing", @@ -65227,7 +62747,6 @@ "litellm_provider": "novita", "max_input_tokens": 8192, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 3e-08, "source": "https://novita.ai/pricing", @@ -65239,7 +62758,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://novita.ai/pricing", @@ -65256,7 +62774,6 @@ "litellm_provider": "novita", "max_input_tokens": 204800, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.2e-06, "source": "https://api.novita.ai/v3/openai/models", @@ -65273,7 +62790,6 @@ "litellm_provider": "novita", "max_input_tokens": 200000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.0000000000000003e-07, "source": "https://novita.ai/pricing", @@ -65289,7 +62805,6 @@ "litellm_provider": "novita", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.4850000000000002e-06, "source": "https://novita.ai/pricing", @@ -65304,7 +62819,6 @@ "litellm_provider": "novita", "max_input_tokens": 64000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 8.900000000000001e-07, "source": "https://api.novita.ai/v3/openai/models", @@ -65317,7 +62831,6 @@ "litellm_provider": "novita", "max_input_tokens": 64000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://api.novita.ai/v3/openai/models", @@ -65331,7 +62844,6 @@ "litellm_provider": "novita", "max_input_tokens": 64000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 8.900000000000001e-07, "source": "https://api.novita.ai/v3/openai/models", @@ -65344,7 +62856,6 @@ "litellm_provider": "novita", "max_input_tokens": 64000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://api.novita.ai/v3/openai/models", @@ -65358,7 +62869,6 @@ "litellm_provider": "novita", "max_input_tokens": 32000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 1.66e-06, "source": "https://api.novita.ai/v3/openai/models", @@ -65372,7 +62882,6 @@ "litellm_provider": "novita", "max_input_tokens": 131000, "max_output_tokens": 32000, - "max_tokens": 32000, "mode": "chat", "output_cost_per_token": 2e-08, "source": "https://api.novita.ai/v3/openai/models", @@ -65381,7 +62890,7 @@ }, "wandb/deepseek-ai/DeepSeek-V4-Flash": { "supports_reasoning": true, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "max_input_tokens": 1049000, "input_cost_per_token": 1.4e-07, "output_cost_per_token": 2.8e-07, @@ -65395,7 +62904,7 @@ }, "wandb/deepseek-ai/DeepSeek-V4-Flash-0731": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 1.3e-07, "output_cost_per_token": 2.8e-07, @@ -65408,7 +62917,7 @@ }, "wandb/deepseek-ai/DeepSeek-V4-Pro": { "supports_reasoning": true, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "max_input_tokens": 1049000, "input_cost_per_token": 1.15e-06, "output_cost_per_token": 2.55e-06, @@ -65422,7 +62931,7 @@ }, "wandb/google/gemma-4-31B-it": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 1e-07, "output_cost_per_token": 3.4e-07, @@ -65433,7 +62942,7 @@ }, "wandb/ibm-granite/granite-4.1-8b": { "deprecation_date": "2026-10-05", - "max_tokens": 131072, + "max_output_tokens": 131072, "max_input_tokens": 131000, "input_cost_per_token": 5e-08, "output_cost_per_token": 1e-07, @@ -65444,7 +62953,7 @@ }, "wandb/JetBrains/Mellum2-12B-A2.5B-Instruct": { "deprecation_date": "2026-10-05", - "max_tokens": 131072, + "max_output_tokens": 131072, "max_input_tokens": 131000, "input_cost_per_token": 5e-08, "output_cost_per_token": 1e-07, @@ -65455,7 +62964,7 @@ }, "wandb/meta-llama/Llama-3.1-70B-Instruct": { "deprecation_date": "2026-10-05", - "max_tokens": 128000, + "max_output_tokens": 128000, "max_input_tokens": 131000, "input_cost_per_token": 8e-07, "output_cost_per_token": 8e-07, @@ -65466,7 +62975,7 @@ }, "wandb/MiniMaxAI/MiniMax-M3": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 2.3e-07, "output_cost_per_token": 9.6e-07, @@ -65479,7 +62988,7 @@ }, "wandb/moonshotai/Kimi-K2.7-Code": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 7.1e-07, "output_cost_per_token": 3.5e-06, @@ -65492,7 +63001,7 @@ }, "wandb/moonshotai/Kimi-K2.6": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 6.5e-07, "output_cost_per_token": 3.41e-06, @@ -65505,7 +63014,7 @@ }, "wandb/nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 7e-08, "output_cost_per_token": 2e-07, @@ -65518,7 +63027,7 @@ }, "wandb/nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 5e-07, "output_cost_per_token": 2.15e-06, @@ -65531,7 +63040,7 @@ }, "wandb/OpenPipe/Qwen3-14B-Instruct": { "deprecation_date": "2026-10-05", - "max_tokens": 32768, + "max_output_tokens": 32768, "max_input_tokens": 32800, "input_cost_per_token": 5e-08, "output_cost_per_token": 2.2e-07, @@ -65542,7 +63051,7 @@ }, "wandb/Qwen/Qwen3.8-27B": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 4e-07, "output_cost_per_token": 3e-06, @@ -65555,7 +63064,7 @@ }, "wandb/Qwen/Qwen3.6-35B-A3B": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 2.5e-07, "output_cost_per_token": 1.25e-06, @@ -65566,7 +63075,7 @@ }, "wandb/Qwen/Qwen3.6-27B": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 6e-07, "output_cost_per_token": 3.6e-06, @@ -65581,7 +63090,7 @@ "wandb/Qwen/Qwen3.5-35B-A3B": { "deprecation_date": "2026-10-05", "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 2.5e-07, "output_cost_per_token": 1.25e-06, @@ -65592,7 +63101,7 @@ }, "wandb/Qwen/Qwen3-30B-A3B-Instruct-2507": { "deprecation_date": "2026-10-05", - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262000, "input_cost_per_token": 1e-07, "output_cost_per_token": 3e-07, @@ -65625,7 +63134,7 @@ }, "wandb/zai-org/GLM-5.2": { "supports_reasoning": true, - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 1049000, "input_cost_per_token": 7.6e-07, "output_cost_per_token": 2.42e-06, @@ -65637,7 +63146,7 @@ "source": "https://wandb.ai/site/pricing/tokens/" }, "deepinfra/openai/gpt-oss-120b-Turbo": { - "max_tokens": 131072, + "max_output_tokens": 131072, "max_input_tokens": 131072, "input_cost_per_token": 1.5e-07, "output_cost_per_token": 6e-07, @@ -65651,7 +63160,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/MiniMaxAI/MiniMax-M2.7": { - "max_tokens": 196608, + "max_output_tokens": 196608, "max_input_tokens": 196608, "input_cost_per_token": 2.5e-07, "output_cost_per_token": 1e-06, @@ -65667,7 +63176,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3.8-27B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 4e-07, "output_cost_per_token": 3e-06, @@ -65683,7 +63192,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemma-4-31B-it-Ultra": { - "max_tokens": 131072, + "max_output_tokens": 131072, "max_input_tokens": 131072, "input_cost_per_token": 2.7e-07, "output_cost_per_token": 7.6e-07, @@ -65697,7 +63206,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/moonshotai/Kimi-K2.5": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 4.5e-07, "output_cost_per_token": 2.25e-06, @@ -65713,7 +63222,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/zai-org/GLM-4.7-Flash": { - "max_tokens": 202752, + "max_output_tokens": 202752, "max_input_tokens": 202752, "input_cost_per_token": 6e-08, "output_cost_per_token": 4e-07, @@ -65729,7 +63238,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/zai-org/GLM-4.6": { - "max_tokens": 202752, + "max_output_tokens": 202752, "max_input_tokens": 202752, "input_cost_per_token": 5e-07, "output_cost_per_token": 2e-06, @@ -65748,7 +63257,7 @@ "input_cost_per_token": 5e-06, "litellm_provider": "deepinfra", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-05, "prompt_cache_min_tokens": 1024, @@ -65762,7 +63271,7 @@ "supports_vision": true }, "deepinfra/anthropic/claude-sonnet-4-6": { - "max_tokens": 1000000, + "max_output_tokens": 1000000, "max_input_tokens": 1000000, "input_cost_per_token": 3e-06, "output_cost_per_token": 1.5e-05, @@ -65778,7 +63287,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemini-3.5-flash": { - "max_tokens": 1000000, + "max_output_tokens": 1000000, "max_input_tokens": 1000000, "input_cost_per_token": 1.5e-06, "output_cost_per_token": 9e-06, @@ -65793,7 +63302,7 @@ "supports_audio_input": true }, "deepinfra/XiaomiMiMo/MiMo-V2.5": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 4e-07, "output_cost_per_token": 2e-06, @@ -65809,7 +63318,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-Max": { - "max_tokens": 256000, + "max_output_tokens": 256000, "max_input_tokens": 256000, "input_cost_per_token": 1.2e-06, "output_cost_per_token": 6e-06, @@ -65824,7 +63333,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemma-4-31B-it-turbo": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 9e-08, "output_cost_per_token": 3.4e-07, @@ -65839,7 +63348,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/thinkingmachines/Inkling-Small": { - "max_tokens": 524288, + "max_output_tokens": 524288, "max_input_tokens": 524288, "input_cost_per_token": 4.5e-07, "output_cost_per_token": 1.2e-06, @@ -65855,7 +63364,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/meta-models/Muse-Glimmer-30B": { - "max_tokens": 131072, + "max_output_tokens": 131072, "max_input_tokens": 131072, "input_cost_per_token": 3e-07, "output_cost_per_token": 1.2e-06, @@ -65871,7 +63380,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-Max-Thinking": { - "max_tokens": 256000, + "max_output_tokens": 256000, "max_input_tokens": 256000, "input_cost_per_token": 1.2e-06, "output_cost_per_token": 6e-06, @@ -65886,7 +63395,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-VL-235B-A22B-Instruct": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 2e-07, "output_cost_per_token": 8.8e-07, @@ -65901,7 +63410,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3-VL-30B-A3B-Instruct": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 1.5e-07, "output_cost_per_token": 6e-07, @@ -65914,7 +63423,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3.5-27B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 2.6e-07, "output_cost_per_token": 2.6e-06, @@ -65928,7 +63437,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3.6-35B-A3B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 1e-07, "output_cost_per_token": 9.5e-07, @@ -65942,7 +63451,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/nvidia/Nemotron-Content-Safety-3.5": { - "max_tokens": 131072, + "max_output_tokens": 131072, "max_input_tokens": 131072, "input_cost_per_token": 2e-07, "output_cost_per_token": 2e-07, @@ -65955,7 +63464,7 @@ "input_cost_per_token": 5e-06, "litellm_provider": "deepinfra", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-05, "prompt_cache_min_tokens": 512, @@ -65969,7 +63478,7 @@ "supports_vision": true }, "deepinfra/thinkingmachines/Inkling": { - "max_tokens": 524288, + "max_output_tokens": 524288, "max_input_tokens": 524288, "input_cost_per_token": 9.5e-07, "output_cost_per_token": 4.05e-06, @@ -65985,7 +63494,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/moonshotai/Kimi-K2.6": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 7.5e-07, "output_cost_per_token": 3.5e-06, @@ -66001,7 +63510,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/deepseek-ai/DeepSeek-V4-Pro-0813": { - "max_tokens": 1048576, + "max_output_tokens": 1048576, "max_input_tokens": 1048576, "input_cost_per_token": 1.3e-06, "output_cost_per_token": 2.6e-06, @@ -66016,7 +63525,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3.7-Max": { - "max_tokens": 256000, + "max_output_tokens": 256000, "max_input_tokens": 256000, "input_cost_per_token": 2.5e-06, "output_cost_per_token": 7.5e-06, @@ -66031,7 +63540,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/ByteDance/Seed-2.0-mini": { - "max_tokens": 256000, + "max_output_tokens": 256000, "max_input_tokens": 256000, "input_cost_per_token": 1e-07, "output_cost_per_token": 4e-07, @@ -66047,7 +63556,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3.8-2.4T-A95B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 2e-06, "output_cost_per_token": 6e-06, @@ -66063,7 +63572,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/MiniMaxAI/MiniMax-M3": { - "max_tokens": 524288, + "max_output_tokens": 524288, "max_input_tokens": 524288, "input_cost_per_token": 2.8e-07, "output_cost_per_token": 1.1e-06, @@ -66079,7 +63588,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemini-3.1-flash-lite": { - "max_tokens": 1000000, + "max_output_tokens": 1000000, "max_input_tokens": 1000000, "input_cost_per_token": 2.5e-07, "output_cost_per_token": 1.5e-06, @@ -66094,7 +63603,7 @@ "supports_audio_input": true }, "deepinfra/google/gemini-3.7-flash": { - "max_tokens": 1000000, + "max_output_tokens": 1000000, "max_input_tokens": 1000000, "input_cost_per_token": 7.5e-07, "output_cost_per_token": 3.75e-06, @@ -66110,7 +63619,7 @@ "supports_audio_input": true }, "deepinfra/inclusionAI/Ling-3.0-flash": { - "max_tokens": 131072, + "max_output_tokens": 131072, "max_input_tokens": 131072, "input_cost_per_token": 6e-08, "output_cost_per_token": 1.8e-07, @@ -66126,7 +63635,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/stepfun-ai/Step-3.7-Flash": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 2e-07, "output_cost_per_token": 1.15e-06, @@ -66140,7 +63649,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3.5-35B-A3B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 1.4e-07, "output_cost_per_token": 1e-06, @@ -66156,7 +63665,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/ByteDance/Seed-1.8": { - "max_tokens": 256000, + "max_output_tokens": 256000, "max_input_tokens": 256000, "input_cost_per_token": 2.5e-07, "output_cost_per_token": 2e-06, @@ -66172,7 +63681,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/tencent/Hy3": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 1.4e-07, "output_cost_per_token": 5.8e-07, @@ -66188,7 +63697,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/ByteDance/Seed-2.0-code": { - "max_tokens": 256000, + "max_output_tokens": 256000, "max_input_tokens": 256000, "input_cost_per_token": 5e-07, "output_cost_per_token": 3e-06, @@ -66204,7 +63713,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/ByteDance/Seed-2.0-pro": { - "max_tokens": 256000, + "max_output_tokens": 256000, "max_input_tokens": 256000, "input_cost_per_token": 5e-07, "output_cost_per_token": 3e-06, @@ -66220,7 +63729,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/zai-org/GLM-5": { - "max_tokens": 202752, + "max_output_tokens": 202752, "max_input_tokens": 202752, "input_cost_per_token": 6e-07, "output_cost_per_token": 2.08e-06, @@ -66236,7 +63745,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/nvidia/Nemotron-3-Nano-30B-A3B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 5e-08, "output_cost_per_token": 2e-07, @@ -66251,7 +63760,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/moonshotai/Kimi-K2.7-Code": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 6.8e-07, "output_cost_per_token": 3.4e-06, @@ -66270,7 +63779,7 @@ "input_cost_per_token": 2e-06, "litellm_provider": "deepinfra", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 1e-05, "prompt_cache_min_tokens": 1024, @@ -66284,7 +63793,7 @@ "supports_vision": true }, "deepinfra/Qwen/Qwen3.5-397B-A17B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 4.5e-07, "output_cost_per_token": 3e-06, @@ -66300,7 +63809,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/deepseek-ai/DeepSeek-V4-Flash-0731": { - "max_tokens": 1048576, + "max_output_tokens": 1048576, "max_input_tokens": 1048576, "input_cost_per_token": 8e-08, "output_cost_per_token": 1.8e-07, @@ -66316,7 +63825,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemma-4-E4B-it": { - "max_tokens": 131072, + "max_output_tokens": 131072, "max_input_tokens": 131072, "input_cost_per_token": 2e-08, "output_cost_per_token": 1e-07, @@ -66329,7 +63838,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/deepseek-ai/DeepSeek-V3.2": { - "max_tokens": 163840, + "max_output_tokens": 163840, "max_input_tokens": 163840, "input_cost_per_token": 2.6e-07, "output_cost_per_token": 3.8e-07, @@ -66344,7 +63853,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3.8-Max": { - "max_tokens": 256000, + "max_output_tokens": 256000, "max_input_tokens": 256000, "input_cost_per_token": 1.65e-06, "output_cost_per_token": 4.951e-06, @@ -66362,7 +63871,7 @@ "input_cost_per_token": 1e-05, "litellm_provider": "deepinfra", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 5e-05, "prompt_cache_min_tokens": 512, @@ -66377,7 +63886,7 @@ "thinking_always_on": true }, "deepinfra/nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 5e-07, "output_cost_per_token": 2.2e-06, @@ -66393,7 +63902,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3.5-122B-A10B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 2.9e-07, "output_cost_per_token": 2.4e-06, @@ -66407,7 +63916,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/zai-org/GLM-5.1": { - "max_tokens": 202752, + "max_output_tokens": 202752, "max_input_tokens": 202752, "input_cost_per_token": 1.05e-06, "output_cost_per_token": 3.5e-06, @@ -66423,7 +63932,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/deepseek-ai/DeepSeek-V4-Pro": { - "max_tokens": 1048576, + "max_output_tokens": 1048576, "max_input_tokens": 1048576, "input_cost_per_token": 1.3e-06, "output_cost_per_token": 2.6e-06, @@ -66438,7 +63947,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/nvidia/NVIDIA-Nemotron-3-Super-120B-A12B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 8.5e-08, "output_cost_per_token": 4e-07, @@ -66452,7 +63961,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/zai-org/GLM-5.2": { - "max_tokens": 1048576, + "max_output_tokens": 1048576, "max_input_tokens": 1048576, "input_cost_per_token": 7.5e-07, "output_cost_per_token": 2.4e-06, @@ -66468,7 +63977,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/moonshotai/Kimi-K3": { - "max_tokens": 1048576, + "max_output_tokens": 1048576, "max_input_tokens": 1048576, "input_cost_per_token": 2.85e-06, "output_cost_per_token": 1.425e-05, @@ -66486,7 +63995,7 @@ "input_cost_per_token": 5e-06, "litellm_provider": "deepinfra", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-05, "prompt_cache_min_tokens": 2048, @@ -66500,7 +64009,7 @@ "supports_vision": true }, "deepinfra/Qwen/Qwen3.6-27B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 3.2e-07, "output_cost_per_token": 3.2e-06, @@ -66514,7 +64023,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemma-4-26B-A4B-it": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 7e-08, "output_cost_per_token": 3.4e-07, @@ -66528,7 +64037,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemini-3.1-pro": { - "max_tokens": 1000000, + "max_output_tokens": 1000000, "max_input_tokens": 1000000, "input_cost_per_token": 2e-06, "output_cost_per_token": 1.2e-05, @@ -66543,7 +64052,7 @@ "supports_audio_input": true }, "deepinfra/XiaomiMiMo/MiMo-V2.5-Pro": { - "max_tokens": 1048576, + "max_output_tokens": 1048576, "max_input_tokens": 1048576, "input_cost_per_token": 1e-06, "output_cost_per_token": 3e-06, @@ -66559,7 +64068,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/anthropic/claude-haiku-4-5": { - "max_tokens": 200000, + "max_output_tokens": 200000, "max_input_tokens": 200000, "input_cost_per_token": 1e-06, "output_cost_per_token": 5e-06, @@ -66574,7 +64083,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/deepseek-ai/DeepSeek-V4-Flash": { - "max_tokens": 1048576, + "max_output_tokens": 1048576, "max_input_tokens": 1048576, "input_cost_per_token": 9e-08, "output_cost_per_token": 1.8e-07, @@ -66590,7 +64099,6 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/deepseek-ai/DeepSeek-V4.1-Flash": { - "max_tokens": 131072, "max_input_tokens": 1048576, "max_output_tokens": 131072, "input_cost_per_token": 1.4e-07, @@ -66607,7 +64115,6 @@ "source": "https://deepinfra.com/deepseek-ai/DeepSeek-V4.1-Flash" }, "deepinfra/deepseek-ai/DeepSeek-V4.1-Flash-1017": { - "max_tokens": 131072, "max_input_tokens": 1048576, "max_output_tokens": 131072, "input_cost_per_token": 1.4e-07, @@ -66624,7 +64131,7 @@ "source": "https://deepinfra.com/deepseek-ai/DeepSeek-V4.1-Flash-1017" }, "deepinfra/openai/gpt-oss-120b-Ultra": { - "max_tokens": 131072, + "max_output_tokens": 131072, "max_input_tokens": 131072, "input_cost_per_token": 2e-07, "output_cost_per_token": 9.5e-07, @@ -66638,7 +64145,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/Qwen/Qwen3.5-9B": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 1e-07, "output_cost_per_token": 1.5e-07, @@ -66651,7 +64158,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/MiniMaxAI/MiniMax-M2.7-Turbo": { - "max_tokens": 196608, + "max_output_tokens": 196608, "max_input_tokens": 196608, "input_cost_per_token": 3.8e-07, "output_cost_per_token": 1.7e-06, @@ -66667,7 +64174,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/zai-org/GLM-4.7": { - "max_tokens": 202752, + "max_output_tokens": 202752, "max_input_tokens": 202752, "input_cost_per_token": 4e-07, "output_cost_per_token": 1.75e-06, @@ -66683,7 +64190,7 @@ "source": "https://deepinfra.com/pricing" }, "deepinfra/google/gemma-4-31B-it": { - "max_tokens": 262144, + "max_output_tokens": 262144, "max_input_tokens": 262144, "input_cost_per_token": 1.3e-07, "output_cost_per_token": 3.8e-07, @@ -66702,7 +64209,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 9e-06, "output_cost_per_token": 9e-06, @@ -66737,7 +64243,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -66765,7 +64270,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -66793,7 +64297,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -67069,7 +64572,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -67096,7 +64598,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -67123,7 +64624,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "responses", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -67154,7 +64654,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "responses", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -67182,7 +64681,6 @@ "litellm_provider": "groq", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://console.groq.com/docs/model/qwen/qwen3.8-27b", @@ -67198,7 +64696,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 7.5e-06, "reasoning_effort_levels": [ @@ -67219,7 +64716,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 7.5e-06, "reasoning_effort_levels": [ @@ -67240,7 +64736,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 7.5e-06, "reasoning_effort_levels": [ @@ -67261,7 +64756,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 6e-07, "reasoning_effort_levels": [ @@ -67282,7 +64776,6 @@ "litellm_provider": "mistral", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://docs.mistral.ai/models/model-cards/codestral-25-08", @@ -67297,7 +64790,6 @@ "litellm_provider": "mistral", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://docs.mistral.ai/models/model-cards/codestral-25-08", @@ -67312,7 +64804,6 @@ "litellm_provider": "mistral", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://mistral.ai/news/devstral-2-vibe-cli", @@ -67413,7 +64904,6 @@ "litellm_provider": "mistral", "max_input_tokens": 262144, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://docs.mistral.ai/models/model-cards/leanstral-1-5", @@ -67429,7 +64919,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_priority": 5.5e-06, @@ -67448,7 +64937,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6.6e-06, "output_cost_per_token_priority": 8.25e-06, @@ -67467,7 +64955,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.4e-06, "output_cost_per_token_priority": 5.5e-06, @@ -67486,7 +64973,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6.6e-06, "output_cost_per_token_priority": 8.25e-06, @@ -67502,7 +64988,7 @@ "input_cost_per_token": 2.1e-06, "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 6.6e-06, "source": "https://api.fireworks.ai/v1/serverless/models", @@ -67544,7 +65030,7 @@ "input_cost_per_token": 2.1e-06, "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 6.6e-06, "source": "https://docs.fireworks.ai/serverless/pricing", @@ -67561,7 +65047,7 @@ "input_cost_per_token_priority": 1.875e-07, "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_priority": 6.25e-07, @@ -67579,7 +65065,7 @@ "input_cost_per_token_priority": 2.8125e-07, "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 7.5e-07, "output_cost_per_token_priority": 9.375e-07, @@ -67596,7 +65082,7 @@ "input_cost_per_token_priority": 1.875e-07, "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_priority": 6.25e-07, @@ -67614,7 +65100,7 @@ "input_cost_per_token_priority": 2.8125e-07, "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 7.5e-07, "output_cost_per_token_priority": 9.375e-07, @@ -67632,7 +65118,7 @@ "input_cost_per_token_priority": 1e-06, "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 4.05e-06, "output_cost_per_token_priority": 4.05e-06, @@ -67648,7 +65134,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 40960, "max_output_tokens": 40960, - "max_tokens": 40960, "mode": "embedding", "source": "https://api.fireworks.ai/v1/serverless/models" }, @@ -67671,7 +65156,7 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "together_ai", "max_input_tokens": 1000000, - "max_tokens": 1000000, + "max_output_tokens": 1000000, "mode": "chat", "output_cost_per_token": 4.7e-07, "source": "https://api.together.ai/v1/models" @@ -67731,7 +65216,6 @@ "litellm_provider": "cerebras", "max_input_tokens": 131072, "max_output_tokens": 40960, - "max_tokens": 40960, "mode": "chat", "output_cost_per_token": 1.49e-06, "source": "https://api.cerebras.ai/public/v1/models/gemma-4-31b", @@ -67757,7 +65241,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 256000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 5.5e-06, "source": "https://www.scaleway.com/en/pricing/model-as-a-service/", @@ -67771,7 +65254,6 @@ "litellm_provider": "scaleway", "max_input_tokens": 256000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-07, "source": "https://www.scaleway.com/en/pricing/model-as-a-service/", @@ -67787,7 +65269,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -67810,7 +65291,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 1.2e-06, "supports_function_calling": true, @@ -67852,7 +65332,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -67867,7 +65346,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 3.1e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -67882,7 +65360,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 5.5e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -67897,7 +65374,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6.25e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -67913,7 +65389,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 131072, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6.6e-07, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -67930,7 +65405,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 3.2e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -67943,7 +65417,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 7.5e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -68018,7 +65491,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.88e-07, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -68036,7 +65508,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-nvidia-nvidia-nemotron-nano-12b-v2-vl-bf16.html", @@ -68052,7 +65523,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.76e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-nvidia-nvidia-nemotron-nano-9b-v2.html", @@ -68067,7 +65537,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 256000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 7.8e-07, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -68080,11 +65549,11 @@ "supports_vision": false }, "bedrock/us-gov-west-1/openai.gpt-oss-20b-1:0": { + "supports_vision": false, "input_cost_per_token": 8.4e-08, "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 3.6e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-20b.html", @@ -68099,11 +65568,11 @@ "supports_tool_choice": true }, "bedrock/us-gov-west-1/openai.gpt-oss-120b-1:0": { + "supports_vision": false, "input_cost_per_token": 1.8e-07, "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-120b.html", @@ -68128,7 +65597,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "prompt_cache_min_tokens": 1024, @@ -68167,7 +65635,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "prompt_cache_min_tokens": 1024, @@ -68205,7 +65672,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "prompt_cache_min_tokens": 512, @@ -68242,7 +65708,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.4e-05, "prompt_cache_min_tokens": 512, @@ -68280,7 +65745,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-05, "supports_adaptive_thinking": true, @@ -68315,7 +65779,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 262144, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.88e-07, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -68333,7 +65796,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-nvidia-nvidia-nemotron-nano-12b-v2-vl-bf16.html", @@ -68349,7 +65811,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 2.76e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-nvidia-nvidia-nemotron-nano-9b-v2.html", @@ -68364,7 +65825,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 256000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 7.8e-07, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -68377,11 +65837,11 @@ "supports_vision": false }, "bedrock/us-gov-east-1/openai.gpt-oss-20b-1:0": { + "supports_vision": false, "input_cost_per_token": 8.4e-08, "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 3.6e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-20b.html", @@ -68396,11 +65856,11 @@ "supports_tool_choice": true }, "bedrock/us-gov-east-1/openai.gpt-oss-120b-1:0": { + "supports_vision": false, "input_cost_per_token": 1.8e-07, "litellm_provider": "bedrock", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 7.2e-07, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-120b.html", @@ -68425,7 +65885,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "prompt_cache_min_tokens": 1024, @@ -68459,7 +65918,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "prompt_cache_min_tokens": 1024, @@ -68492,7 +65950,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "prompt_cache_min_tokens": 512, @@ -68524,7 +65981,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.4e-05, "prompt_cache_min_tokens": 512, @@ -68557,7 +66013,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-05, "supports_adaptive_thinking": true, @@ -68584,9 +66039,8 @@ }, "bedrock_mantle/us-gov-west-1/openai.gpt-5.6-terra": { "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -68620,9 +66074,8 @@ }, "bedrock_mantle/us-gov-west-1/openai.gpt-5.6-luna": { "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -68656,9 +66109,8 @@ }, "bedrock_mantle/us-gov-west-1/openai.gpt-5.4": { "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -68689,7 +66141,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 1048576, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions", @@ -68713,7 +66164,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions", @@ -68732,7 +66182,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 128000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "use_openai_responses_path": true, "supported_endpoints": [ @@ -68751,7 +66200,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "use_openai_responses_path": true, "supported_endpoints": [ @@ -68770,7 +66218,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "use_openai_responses_path": true, "supported_endpoints": [ @@ -68784,12 +66231,12 @@ "supports_vision": true }, "bedrock_mantle/us-gov-west-1/openai.gpt-oss-20b": { + "supports_vision": false, "input_cost_per_token": 8.4e-08, "output_cost_per_token": 3.6e-07, "litellm_provider": "bedrock_mantle", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-20b.html", "supported_endpoints": [ @@ -68803,12 +66250,12 @@ "supports_tool_choice": true }, "bedrock_mantle/us-gov-west-1/openai.gpt-oss-120b": { + "supports_vision": false, "input_cost_per_token": 1.8e-07, "output_cost_per_token": 7.2e-07, "litellm_provider": "bedrock_mantle", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-120b.html", "supported_endpoints": [ @@ -68831,7 +66278,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.4e-05, "prompt_cache_min_tokens": 512, @@ -68854,7 +66300,8 @@ "supports_xhigh_reasoning_effort": true, "thinking_always_on": true, "supports_forced_tool_use": false, - "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-anthropic-claude-opus-5-5.html" + "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-anthropic-claude-opus-5-5.html", + "token_count_model": {"model":"anthropic.claude-opus-5-5","litellm_provider":"bedrock_mantle","region":"us-gov-west-1"} }, "bedrock_mantle/us-gov-west-1/anthropic.claude-sonnet-5-5": { "bedrock_converse_supports_strict_tools": false, @@ -68867,7 +66314,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "supports_forced_tool_use": false, @@ -68894,9 +66340,8 @@ }, "bedrock_mantle/us-gov-east-1/openai.gpt-5.4": { "litellm_provider": "bedrock_mantle", - "max_input_tokens": 1050000, + "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "use_openai_responses_path": true, "supported_endpoints": [ @@ -68919,7 +66364,8 @@ "supports_vision": true, "input_cost_per_token": 3.3e-06, "cache_read_input_token_cost": 3.3e-07, - "output_cost_per_token": 1.98e-05 + "output_cost_per_token": 1.98e-05, + "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-54.md" }, "bedrock_mantle/us-gov-east-1/xai.grok-4.6": { "use_openai_responses_path": true, @@ -68929,7 +66375,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "supported_endpoints": [ "/v1/chat/completions", @@ -68943,12 +66388,12 @@ "supports_vision": true }, "bedrock_mantle/us-gov-east-1/openai.gpt-oss-20b": { + "supports_vision": false, "input_cost_per_token": 8.4e-08, "output_cost_per_token": 3.6e-07, "litellm_provider": "bedrock_mantle", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-20b.html", "supported_endpoints": [ @@ -68962,12 +66407,12 @@ "supports_tool_choice": true }, "bedrock_mantle/us-gov-east-1/openai.gpt-oss-120b": { + "supports_vision": false, "input_cost_per_token": 1.8e-07, "output_cost_per_token": 7.2e-07, "litellm_provider": "bedrock_mantle", "max_input_tokens": 131072, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-oss-120b.html", "supported_endpoints": [ @@ -68991,7 +66436,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 128000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token_batches": 8.4e-07, "output_cost_per_token_priority": 2.94e-06, @@ -69013,7 +66457,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 256000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token_batches": 1.25e-06, "output_cost_per_token_priority": 4.38e-06, @@ -69035,7 +66478,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 256000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token_batches": 4.4e-07, "output_cost_per_token_priority": 1.54e-06, @@ -69057,7 +66499,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 32000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token_batches": 3e-07, "output_cost_per_token_priority": 1.05e-06, @@ -69080,7 +66521,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 256000, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token_batches": 3e-07, "output_cost_per_token_priority": 1.05e-06, @@ -69102,7 +66542,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 262144, "max_output_tokens": 16000, - "max_tokens": 16000, "mode": "chat", "output_cost_per_token_batches": 9e-07, "output_cost_per_token_priority": 3.15e-06, @@ -69123,7 +66562,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 256000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token_batches": 6e-07, "output_cost_per_token_priority": 2.1e-06, @@ -69145,7 +66583,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 256000, "max_output_tokens": 8000, - "max_tokens": 8000, "mode": "chat", "output_cost_per_token_batches": 1.33e-06, "output_cost_per_token_priority": 4.66e-06, @@ -69164,7 +66601,6 @@ "litellm_provider": "azure", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.375e-05, "supported_endpoints": [ @@ -69198,7 +66634,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 6.05e-06, "supports_prompt_caching": true, @@ -69211,7 +66646,6 @@ "input_cost_per_token": 1.63e-07, "litellm_provider": "azure", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -69219,7 +66653,6 @@ "input_cost_per_token": 2.5e-08, "litellm_provider": "azure", "max_input_tokens": 8191, - "max_tokens": 8191, "mode": "embedding", "output_cost_per_token": 0.0 }, @@ -69250,7 +66683,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_image": 0.04, "output_cost_per_token": 0, @@ -69275,7 +66707,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 0, "source": "https://ai.google.dev/gemini-api/docs/pricing", @@ -69300,7 +66731,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 0, "source": "https://ai.google.dev/gemini-api/docs/pricing", @@ -69325,7 +66755,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 0, "source": "https://ai.google.dev/gemini-api/docs/models/lyria-realtime-exp", @@ -69698,7 +67127,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://inference.baseten.co/v1/models", @@ -69722,7 +67150,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 6.6e-06, "source": "https://inference.baseten.co/v1/models", @@ -69747,7 +67174,7 @@ "output_cost_per_token": 1.5e-07, "source": "https://api.together.ai/v1/models", "max_input_tokens": 128000, - "max_tokens": 128000 + "max_output_tokens": 128000 }, "vertex_ai/gemini-2.5-flash-native-audio": { "deprecation_date": "2026-12-13", @@ -69808,7 +67235,7 @@ "input_cost_per_token": 1.5e-06, "litellm_provider": "vertex_ai", "max_output_tokens": 57920, - "max_tokens": 57920, + "max_input_tokens": 57920, "mode": "chat", "output_cost_per_reasoning_token": 9e-06, "output_cost_per_token": 9e-06, @@ -69871,7 +67298,7 @@ "output_cost_per_token": 3.5e-06, "source": "https://api.together.ai/v1/models", "max_input_tokens": 4096, - "max_tokens": 4096 + "max_output_tokens": 4096 }, "together_ai/meta-llama/Llama-3.2-1B-Instruct": { "input_cost_per_token": 6e-08, @@ -69880,7 +67307,7 @@ "output_cost_per_token": 6e-08, "source": "https://api.together.ai/v1/models", "max_input_tokens": 131072, - "max_tokens": 131072 + "max_output_tokens": 131072 }, "together_ai/meta-llama/Llama-3.2-3B-Instruct": { "input_cost_per_token": 6e-08, @@ -69889,7 +67316,7 @@ "output_cost_per_token": 6e-08, "source": "https://api.together.ai/v1/models", "max_input_tokens": 131072, - "max_tokens": 131072 + "max_output_tokens": 131072 }, "together_ai/Qwen/Qwen2-1.5B-Instruct": { "input_cost_per_token": 2e-08, @@ -69898,7 +67325,7 @@ "output_cost_per_token": 2e-08, "source": "https://api.together.ai/v1/models", "max_input_tokens": 32768, - "max_tokens": 32768 + "max_output_tokens": 32768 }, "together_ai/Qwen/Qwen2.5-14B-Instruct": { "input_cost_per_token": 8e-07, @@ -69907,7 +67334,7 @@ "output_cost_per_token": 8e-07, "source": "https://api.together.ai/v1/models", "max_input_tokens": 32768, - "max_tokens": 32768 + "max_output_tokens": 32768 }, "together_ai/Qwen/Qwen2.5-72B-Instruct": { "input_cost_per_token": 1.2e-06, @@ -69916,14 +67343,13 @@ "output_cost_per_token": 1.2e-06, "source": "https://api.together.ai/v1/models", "max_input_tokens": 32768, - "max_tokens": 32768 + "max_output_tokens": 32768 }, "together_ai/Salesforce/Llama-Rank-V1": { "deprecation_date": "2026-02-06", "input_cost_per_token": 1e-07, "litellm_provider": "together_ai", "max_input_tokens": 8192, - "max_tokens": 8192, "mode": "rerank", "output_cost_per_token": 0.0, "source": "https://api.together.ai/v1/models" @@ -69932,7 +67358,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "together_ai", "max_input_tokens": 16384, - "max_tokens": 16384, + "max_output_tokens": 16384, "mode": "completion", "output_cost_per_token": 2e-07, "source": "https://api.together.xyz/v1/models" @@ -69950,7 +67376,7 @@ "input_cost_per_token": 6e-07, "litellm_provider": "together_ai", "max_input_tokens": 32768, - "max_tokens": 32768, + "max_output_tokens": 32768, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://api.together.ai/v1/models" @@ -69960,7 +67386,7 @@ "input_cost_per_token": 1.2e-06, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://api.together.ai/v1/models" @@ -69970,7 +67396,7 @@ "input_cost_per_token": 9e-07, "litellm_provider": "together_ai", "max_input_tokens": 32768, - "max_tokens": 32768, + "max_output_tokens": 32768, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://api.together.ai/v1/models" @@ -69980,7 +67406,7 @@ "input_cost_per_token": 1.2e-06, "litellm_provider": "together_ai", "max_input_tokens": 32768, - "max_tokens": 32768, + "max_output_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://api.together.ai/v1/models" @@ -69990,7 +67416,7 @@ "input_cost_per_token": 1.2e-06, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://api.together.ai/v1/models" @@ -70000,7 +67426,7 @@ "input_cost_per_token": 8e-07, "litellm_provider": "together_ai", "max_input_tokens": 16384, - "max_tokens": 16384, + "max_output_tokens": 16384, "mode": "chat", "output_cost_per_token": 8e-07, "source": "https://api.together.ai/v1/models" @@ -70010,7 +67436,7 @@ "input_cost_per_token": 1.95e-06, "litellm_provider": "together_ai", "max_input_tokens": 32768, - "max_tokens": 32768, + "max_output_tokens": 32768, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://api.together.ai/v1/models" @@ -70020,7 +67446,7 @@ "input_cost_per_token": 2e-06, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://api.together.ai/v1/models" @@ -70030,7 +67456,7 @@ "input_cost_per_token": 5e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://api.together.ai/v1/models" @@ -70040,7 +67466,7 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://api.together.ai/v1/models" @@ -70050,7 +67476,7 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://api.together.ai/v1/models" @@ -70060,7 +67486,7 @@ "input_cost_per_token": 5e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-06, "source": "https://api.together.ai/v1/models" @@ -70070,7 +67496,7 @@ "input_cost_per_token": 1.8e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 6.8e-07, "source": "https://api.together.ai/v1/models" @@ -70081,7 +67507,7 @@ "input_cost_per_token": 6e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 3.6e-06, "source": "https://api.together.ai/v1/models" @@ -70091,7 +67517,7 @@ "input_cost_per_token": 2e-06, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://api.together.ai/v1/models" @@ -70101,7 +67527,7 @@ "input_cost_per_token": 1.8e-07, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.8e-07, "source": "https://api.together.ai/v1/models" @@ -70111,7 +67537,7 @@ "input_cost_per_token": 1.6e-06, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.6e-06, "source": "https://api.together.ai/v1/models" @@ -70121,7 +67547,7 @@ "input_cost_per_token": 6e-07, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.7e-06, "source": "https://api.together.ai/v1/models" @@ -70131,7 +67557,7 @@ "input_cost_per_token": 8e-07, "litellm_provider": "together_ai", "max_input_tokens": 16384, - "max_tokens": 16384, + "max_output_tokens": 16384, "mode": "chat", "output_cost_per_token": 8e-07, "source": "https://api.together.ai/v1/models" @@ -70141,7 +67567,7 @@ "input_cost_per_token": 8e-07, "litellm_provider": "together_ai", "max_input_tokens": 8192, - "max_tokens": 8192, + "max_output_tokens": 8192, "mode": "chat", "output_cost_per_token": 8e-07, "source": "https://api.together.ai/v1/models" @@ -70151,7 +67577,7 @@ "input_cost_per_token": 3.9e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 9.7e-07, "source": "https://api.together.ai/v1/models" @@ -70161,7 +67587,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "together_ai", "max_input_tokens": 8192, - "max_tokens": 8192, + "max_output_tokens": 8192, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://api.together.ai/v1/models" @@ -70171,7 +67597,7 @@ "input_cost_per_token": 1.8e-07, "litellm_provider": "together_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 5.9e-07, "source": "https://api.together.ai/v1/models" @@ -70181,7 +67607,7 @@ "input_cost_per_token": 8.8e-07, "litellm_provider": "together_ai", "max_input_tokens": 8192, - "max_tokens": 8192, + "max_output_tokens": 8192, "mode": "chat", "output_cost_per_token": 8.8e-07, "source": "https://api.together.ai/v1/models" @@ -70191,7 +67617,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "together_ai", "max_input_tokens": 8192, - "max_tokens": 8192, + "max_output_tokens": 8192, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://api.together.ai/v1/models" @@ -70201,7 +67627,7 @@ "input_cost_per_token": 8.8e-07, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 8.8e-07, "source": "https://api.together.ai/v1/models" @@ -70211,7 +67637,7 @@ "input_cost_per_token": 1.8e-07, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.8e-07, "source": "https://api.together.ai/v1/models" @@ -70221,7 +67647,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "together_ai", "max_input_tokens": 32768, - "max_tokens": 32768, + "max_output_tokens": 32768, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://api.together.ai/v1/models" @@ -70231,7 +67657,7 @@ "input_cost_per_token": 1e-07, "litellm_provider": "together_ai", "max_input_tokens": 32768, - "max_tokens": 32768, + "max_output_tokens": 32768, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://api.together.ai/v1/models" @@ -70241,7 +67667,7 @@ "input_cost_per_token": 6e-07, "litellm_provider": "together_ai", "max_input_tokens": 32768, - "max_tokens": 32768, + "max_output_tokens": 32768, "mode": "chat", "output_cost_per_token": 6e-07, "source": "https://api.together.ai/v1/models" @@ -70252,7 +67678,7 @@ "input_cost_per_token": 1.2e-06, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 4.5e-06, "source": "https://api.together.ai/v1/models" @@ -70263,7 +67689,7 @@ "input_cost_per_token": 9.5e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://api.together.ai/v1/models" @@ -70273,7 +67699,7 @@ "input_cost_per_token": 8.8e-07, "litellm_provider": "together_ai", "max_input_tokens": 32768, - "max_tokens": 32768, + "max_output_tokens": 32768, "mode": "chat", "output_cost_per_token": 8.8e-07, "source": "https://api.together.ai/v1/models" @@ -70284,7 +67710,7 @@ "input_cost_per_token": 6e-07, "litellm_provider": "together_ai", "max_input_tokens": 512288, - "max_tokens": 512288, + "max_output_tokens": 512288, "mode": "chat", "output_cost_per_token": 3.6e-06, "source": "https://api.together.ai/v1/models" @@ -70294,7 +67720,7 @@ "input_cost_per_token": 5e-08, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 2e-07, "source": "https://api.together.ai/v1/models" @@ -70304,7 +67730,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "together_ai", "max_input_tokens": 131072, - "max_tokens": 131072, + "max_output_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.1e-06, "source": "https://api.together.ai/v1/models" @@ -70314,7 +67740,7 @@ "input_cost_per_token": 4.5e-07, "litellm_provider": "together_ai", "max_input_tokens": 202752, - "max_tokens": 202752, + "max_output_tokens": 202752, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://api.together.ai/v1/models" @@ -70324,7 +67750,7 @@ "input_cost_per_token": 1e-06, "litellm_provider": "together_ai", "max_input_tokens": 202752, - "max_tokens": 202752, + "max_output_tokens": 202752, "mode": "chat", "output_cost_per_token": 3.2e-06, "source": "https://api.together.ai/v1/models" @@ -70335,7 +67761,7 @@ "input_cost_per_token": 1.4e-06, "litellm_provider": "together_ai", "max_input_tokens": 202752, - "max_tokens": 202752, + "max_output_tokens": 202752, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://api.together.ai/v1/models" @@ -70402,7 +67828,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.65e-05, "output_cost_per_token_batches": 8.25e-06, @@ -70575,7 +68000,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-05, "output_cost_per_token_above_272k_tokens": 9e-05, @@ -70619,7 +68043,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_above_272k_tokens": 9e-07, @@ -70668,7 +68091,6 @@ "litellm_provider": "azure", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "output_cost_per_token_above_272k_tokens": 1.8e-05, @@ -70724,7 +68146,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8.8e-06, "output_cost_per_token_batches": 4.4e-06, @@ -70738,7 +68159,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 8.8e-06, "output_cost_per_token_batches": 4.4e-06, @@ -70761,7 +68181,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -70775,7 +68194,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 100000, - "max_tokens": 100000, "mode": "chat", "output_cost_per_token": 4.84e-06, "output_cost_per_token_batches": 2.42e-06, @@ -70810,7 +68228,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 4.5e-06, @@ -70832,7 +68249,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 4.5e-06, @@ -70908,7 +68324,6 @@ "litellm_provider": "azure", "max_input_tokens": 128000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "chat", "output_cost_per_token": 1.65e-05, "output_cost_per_token_batches": 8.25e-06, @@ -71121,7 +68536,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "output_cost_per_audio_token": 6.4e-05, "output_cost_per_token": 2.4e-05, @@ -71169,7 +68583,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "audio_transcription", "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", "supported_endpoints": [ @@ -71210,7 +68623,6 @@ "litellm_provider": "azure", "max_input_tokens": 32000, "max_output_tokens": 4096, - "max_tokens": 4096, "mode": "realtime", "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", "supported_modalities": [ @@ -71228,7 +68640,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 512000, "max_output_tokens": 65500, - "max_tokens": 65500, "mode": "chat", "output_cost_per_token": 1.5e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71241,7 +68652,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 9e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71254,7 +68664,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 200000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.2e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71269,7 +68678,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71290,7 +68698,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 5.5e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71308,7 +68715,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71328,7 +68734,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.5e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71349,7 +68754,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71368,7 +68772,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.2e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71383,7 +68786,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.61333e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71412,7 +68814,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.6e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71428,7 +68829,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 4e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71442,7 +68842,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 128000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71457,7 +68856,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 2.84e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71472,7 +68870,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 3.38e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71487,7 +68884,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.411e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71503,7 +68899,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.4246e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71520,7 +68915,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3.0136e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71537,7 +68931,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2.411e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71554,7 +68947,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2.32375e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71571,7 +68963,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 119000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 2.5353e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71584,7 +68975,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71601,7 +68991,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71618,7 +69007,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71635,7 +69023,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.2e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71652,7 +69039,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 2.499999e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71670,7 +69056,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 3.75e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71687,7 +69072,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 131100, - "max_tokens": 131100, "mode": "chat", "output_cost_per_token": 3.9998e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71699,7 +69083,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 131100, - "max_tokens": 131100, "mode": "chat", "output_cost_per_token": 3.9998e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71712,7 +69095,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 7.889e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71727,7 +69109,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3.9438e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71742,7 +69123,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3.9438e-07, "source": "https://aihubmix.com/api/v1/models", @@ -71758,7 +69138,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 200000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3.09848e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71772,7 +69151,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.4e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71788,7 +69166,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71805,7 +69182,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71822,7 +69198,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4.5e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71839,7 +69214,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.25e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71856,7 +69230,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71872,7 +69245,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 0.00018, "source": "https://aihubmix.com/api/v1/models", @@ -71889,7 +69261,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://aihubmix.com/api/v1/models", @@ -71906,7 +69277,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 2e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71923,7 +69293,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1050000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71939,7 +69308,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 400000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 3e-05, "source": "https://aihubmix.com/api/v1/models", @@ -71984,7 +69352,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72000,7 +69367,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72016,7 +69382,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 256000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6.248e-07, "source": "https://aihubmix.com/api/v1/models", @@ -72032,7 +69397,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 2.535e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72048,7 +69412,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 3.9995e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72064,7 +69427,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 7.999e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72080,7 +69442,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://aihubmix.com/api/v1/models", @@ -72096,7 +69457,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3.0984e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72109,7 +69469,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 256000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 8e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72145,7 +69504,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 204800, "max_output_tokens": 204800, - "max_tokens": 204800, "mode": "chat", "output_cost_per_token": 1.1832e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72159,7 +69517,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 524288, - "max_tokens": 524288, "mode": "chat", "output_cost_per_token": 1.152e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72184,7 +69541,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 5.48e-07, "source": "https://aihubmix.com/api/v1/models", @@ -72196,7 +69552,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 9.008e-07, "source": "https://aihubmix.com/api/v1/models", @@ -72211,7 +69566,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 9.864e-07, "source": "https://aihubmix.com/api/v1/models", @@ -72226,7 +69580,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 2.532e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72241,7 +69594,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1.524e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72258,7 +69610,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 262144, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 7.608e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72275,7 +69626,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.128e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72292,7 +69642,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72309,7 +69658,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 3.80025e-07, "source": "https://aihubmix.com/api/v1/models", @@ -72327,7 +69675,6 @@ "litellm_provider": "aihubmix", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 5.07e-06, "source": "https://aihubmix.com/api/v1/models", @@ -72512,7 +69859,7 @@ "input_cost_per_token": 2e-07, "litellm_provider": "wandb", "max_input_tokens": 1049000, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 6.5e-07, "source": "https://wandb.ai/site/pricing/tokens/", @@ -72525,7 +69872,7 @@ "input_cost_per_token": 1e-07, "litellm_provider": "wandb", "max_input_tokens": 262000, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 3e-07, "source": "https://wandb.ai/site/pricing/tokens/", @@ -72566,7 +69913,6 @@ "token_count_tokenizer": "kimi_k3", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.65e-05, "output_cost_per_token_flex": 8.25e-06, @@ -72598,7 +69944,6 @@ "token_count_tokenizer": "kimi_k3", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.5e-05, "output_cost_per_token_flex": 7.5e-06, @@ -72630,7 +69975,6 @@ "token_count_tokenizer": "kimi_k3", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.65e-05, "output_cost_per_token_flex": 8.25e-06, @@ -72652,7 +69996,6 @@ "litellm_provider": "xiaomi_mimo", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 8.7e-07, "source": "https://platform.xiaomimimo.com/static/docs/price/pay-as-you-go.md", @@ -72675,7 +70018,6 @@ "litellm_provider": "xiaomi_mimo", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.8e-07, "source": "https://platform.xiaomimimo.com/static/docs/price/pay-as-you-go.md", @@ -72700,7 +70042,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "output_cost_per_token_batches": 2e-06, @@ -72726,7 +70067,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72748,7 +70088,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72770,7 +70109,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72792,7 +70130,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72813,7 +70150,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72835,7 +70171,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72856,7 +70191,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72878,7 +70212,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72900,7 +70233,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72921,7 +70253,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72943,7 +70274,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72965,7 +70295,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -72986,7 +70315,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -73008,7 +70336,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "responses", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -73033,7 +70360,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "responses", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -73058,7 +70384,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "responses", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -73083,7 +70408,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -73104,7 +70428,6 @@ "litellm_provider": "xai", "max_input_tokens": 1000000, "max_output_tokens": 1000000, - "max_tokens": 1000000, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://api.x.ai/v1/language-models", @@ -73126,7 +70449,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://inference.baseten.co/v1/models", @@ -73144,7 +70466,6 @@ "litellm_provider": "baseten", "max_input_tokens": 262000, "max_output_tokens": 262000, - "max_tokens": 262000, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://inference.baseten.co/v1/models", @@ -73162,7 +70483,6 @@ "litellm_provider": "baseten", "max_input_tokens": 262000, "max_output_tokens": 262000, - "max_tokens": 262000, "mode": "chat", "output_cost_per_token": 4e-06, "source": "https://inference.baseten.co/v1/models", @@ -73179,7 +70499,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://inference.baseten.co/v1/models", @@ -73196,7 +70515,6 @@ "litellm_provider": "baseten", "max_input_tokens": 202800, "max_output_tokens": 202800, - "max_tokens": 202800, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://inference.baseten.co/v1/models", @@ -73214,7 +70532,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 4.05e-06, "source": "https://inference.baseten.co/v1/models", @@ -73232,7 +70549,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://inference.baseten.co/v1/models", @@ -73249,7 +70565,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://inference.baseten.co/v1/models", @@ -73266,7 +70581,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inference.baseten.co/v1/models", @@ -73283,7 +70597,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 2.6e-07, "source": "https://inference.baseten.co/v1/models", @@ -73301,7 +70614,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 3.48e-06, "source": "https://inference.baseten.co/v1/models", @@ -73318,7 +70630,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 3.96e-06, "source": "https://inference.baseten.co/v1/models", @@ -73335,7 +70646,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 6.6e-06, "source": "https://inference.baseten.co/v1/models", @@ -73355,7 +70665,6 @@ "litellm_provider": "xai", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2e-06, "output_cost_per_token_above_200k_tokens": 4e-06, @@ -73376,7 +70685,6 @@ "litellm_provider": "xai", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2e-06, "output_cost_per_token_above_200k_tokens": 4e-06, @@ -73397,7 +70705,6 @@ "litellm_provider": "xai", "max_input_tokens": 256000, "max_output_tokens": 256000, - "max_tokens": 256000, "mode": "chat", "output_cost_per_token": 2e-06, "output_cost_per_token_above_200k_tokens": 4e-06, @@ -73418,7 +70725,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_priority": 1.2e-06, @@ -73436,7 +70742,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 196608, "max_output_tokens": 196608, - "max_tokens": 196608, "mode": "chat", "output_cost_per_token_priority": 1.2e-06, "source": "https://api.fireworks.ai/v1/serverless/models", @@ -73502,7 +70807,6 @@ "litellm_provider": "vertex_ai-zai_models", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 4.4e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -73520,7 +70824,6 @@ "litellm_provider": "vertex_ai-llama_models", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 7.2e-07, "output_cost_per_token_batches": 3.6e-07, @@ -73539,7 +70842,6 @@ "deprecation_date": "2026-06-30", "litellm_provider": "vertex_ai-video-models", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.4, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing#veo", @@ -73555,7 +70857,6 @@ "deprecation_date": "2026-06-30", "litellm_provider": "vertex_ai-video-models", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.1, "output_cost_per_second_1080p": 0.12, @@ -73572,7 +70873,6 @@ "deprecation_date": "2026-06-30", "litellm_provider": "vertex_ai-video-models", "max_input_tokens": 1024, - "max_tokens": 1024, "mode": "video_generation", "output_cost_per_second": 0.5, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing#veo", @@ -73619,7 +70919,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_adaptive_thinking": true, "thinking_always_on": true, @@ -73652,7 +70951,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_adaptive_thinking": true, "thinking_always_on": true, @@ -73685,7 +70983,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_adaptive_thinking": true, "thinking_always_on": true, @@ -73718,7 +71015,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_adaptive_thinking": true, "thinking_always_on": true, @@ -73756,7 +71052,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_adaptive_thinking": true, "thinking_always_on": true, @@ -73789,7 +71084,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_adaptive_thinking": true, "thinking_always_on": true, @@ -73825,7 +71119,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_assistant_prefill": false, "supports_computer_use": true, @@ -73864,7 +71157,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_assistant_prefill": false, "supports_computer_use": true, @@ -73904,7 +71196,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_assistant_prefill": false, "supports_computer_use": true, @@ -73942,7 +71233,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_assistant_prefill": false, "supports_computer_use": true, @@ -73981,7 +71271,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "supports_assistant_prefill": false, "supports_computer_use": true, @@ -74014,7 +71303,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_adaptive_thinking": true, "supports_mid_conversation_system": true, @@ -74052,7 +71340,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "thinking_always_on": true, "supports_function_calling": true, @@ -74072,7 +71359,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "thinking_always_on": true, "supports_function_calling": true, @@ -74092,7 +71378,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "thinking_always_on": true, "supports_function_calling": true, @@ -74114,7 +71399,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 8192, - "max_tokens": 8192, "mode": "chat", "output_cost_per_token": 5.4e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-deepseek-deepseek-r1.html", @@ -74127,7 +71411,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 128000, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "chat", "output_cost_per_token": 6e-06, "source": "https://aws.amazon.com/bedrock/pricing/", @@ -74140,7 +71423,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 256000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 3.5e-06, "source": "https://azure.microsoft.com/en-us/pricing/details/ai-foundry-models/microsoft/", @@ -74176,7 +71458,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "search_context_cost_per_query": { @@ -74214,7 +71495,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_adaptive_thinking": true, "supports_mid_conversation_system": true, @@ -74260,7 +71540,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "search_context_cost_per_query": { @@ -74302,7 +71581,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "search_context_cost_per_query": { @@ -74339,7 +71617,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "supports_forced_tool_use": false, @@ -74376,7 +71653,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "supports_forced_tool_use": false, @@ -74417,7 +71693,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "search_context_cost_per_query": { @@ -74464,7 +71739,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "search_context_cost_per_query": { @@ -74506,7 +71780,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "search_context_cost_per_query": { @@ -74638,7 +71911,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.2e-05, "supports_forced_tool_use": false, @@ -74684,7 +71956,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1.1e-05, "search_context_cost_per_query": { @@ -74729,7 +72000,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -74769,7 +72039,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_batches": 5e-06, @@ -74802,7 +72071,6 @@ "litellm_provider": "prism", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 6.3e-07, "source": "https://prisminference.com/pricing", @@ -74827,7 +72095,6 @@ "litellm_provider": "prism", "max_input_tokens": 1000000, "max_output_tokens": 384000, - "max_tokens": 384000, "mode": "chat", "output_cost_per_token": 2.1e-07, "source": "https://prisminference.com/pricing", @@ -74860,7 +72127,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 524288, "max_output_tokens": 524288, - "max_tokens": 524288, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_flex": 3e-06, @@ -74886,7 +72152,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 524288, "max_output_tokens": 524288, - "max_tokens": 524288, "mode": "chat", "output_cost_per_token": 6.6e-06, "output_cost_per_token_flex": 3.3e-06, @@ -74904,7 +72169,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://inference.baseten.co/v1/models", @@ -74917,6 +72181,16 @@ }, "gpt-6.1-sol": { "cache_creation_input_token_cost": 2.5e-06, + "cache_creation_input_token_cost_above_12hr": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 1e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": 2e-05, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_ultrafast": 6e-05, + "cache_creation_input_token_cost_above_12hr_batches": 2.5e-06, + "cache_creation_input_token_cost_above_12hr_flex": 2.5e-06, + "cache_creation_input_token_cost_above_12hr_priority": 1e-05, + "cache_creation_input_token_cost_above_12hr_ultrafast": 3e-05, "cache_creation_input_token_cost_above_272k_tokens": 5e-06, "cache_creation_input_token_cost_above_272k_tokens_batches": 2.5e-06, "cache_creation_input_token_cost_above_272k_tokens_flex": 2.5e-06, @@ -74949,7 +72223,6 @@ "litellm_provider": "openai", "max_input_tokens": 922000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -75017,7 +72290,6 @@ "supports_bedrock_converse_tool_result_images": false, "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1e-05, "output_cost_per_token_above_272k_tokens": 1.5e-05, @@ -75063,7 +72335,6 @@ "litellm_provider": "bedrock_mantle", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "responses", "output_cost_per_token": 1.1e-05, "output_cost_per_token_above_272k_tokens": 1.65e-05, @@ -75111,7 +72382,6 @@ "supports_bedrock_converse_tool_result_images": false, "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.1e-05, "output_cost_per_token_above_272k_tokens": 1.65e-05, @@ -75146,7 +72416,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 8192, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "audio_speech", "output_cost_per_audio_token": 9e-06, "output_cost_per_token": 9e-06, @@ -75160,7 +72429,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 8192, "max_output_tokens": 16384, - "max_tokens": 16384, "mode": "audio_speech", "output_cost_per_audio_token": 6e-06, "output_cost_per_token": 6e-06, @@ -75177,7 +72445,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 524288, "max_output_tokens": 524288, - "max_tokens": 524288, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -75195,7 +72462,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 262144, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 2.5e-06, "source": "https://azure.microsoft.com/en-us/pricing/details/ai-foundry-models/kimi/", @@ -75228,7 +72494,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.28e-06, "output_cost_per_token_batches": 2.64e-06, @@ -75261,7 +72526,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.808e-06, "output_cost_per_token_batches": 2.904e-06, @@ -75282,10 +72546,12 @@ "input_cost_per_audio_token": 3e-06, "input_cost_per_token": 3.3e-07, "litellm_provider": "bedrock", + "max_input_tokens": 256000, + "max_output_tokens": 64000, "mode": "realtime", "output_cost_per_audio_token": 1.2e-05, "output_cost_per_token": 2.75e-06, - "source": "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonBedrockFoundationModels/current/index.json", + "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-amazon-nova-2-5-sonic.md", "supports_audio_input": true, "supports_audio_output": true }, @@ -75296,7 +72562,6 @@ "litellm_provider": "azure", "max_input_tokens": 200000, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "chat", "output_cost_per_token": 0.0, "source": "https://azure.microsoft.com/en-us/pricing/details/ai-foundry-models/model-router/", @@ -75316,7 +72581,6 @@ "litellm_provider": "gemini", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.0336, "output_cost_per_image_token": 3e-05, @@ -75361,7 +72625,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.0336, "output_cost_per_image_token": 3e-05, @@ -75407,7 +72670,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 131072, "max_output_tokens": 32768, - "max_tokens": 32768, "mode": "image_generation", "output_cost_per_image": 0.0336, "output_cost_per_image_token": 3e-05, @@ -75451,7 +72713,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -75479,7 +72740,6 @@ "token_count_tokenizer": "kimi_k3", "max_input_tokens": 1000000, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.65e-05, "output_cost_per_token_flex": 8.25e-06, @@ -75512,7 +72772,6 @@ "litellm_provider": "anthropic", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_batches": 2.5e-07, @@ -75566,7 +72825,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-07, "search_context_cost_per_query": { @@ -75613,7 +72871,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "supports_forced_tool_use": true, @@ -75658,7 +72915,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "search_context_cost_per_query": { @@ -75701,7 +72957,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "supports_adaptive_thinking": true, "supports_mid_conversation_system": true, @@ -75752,7 +73007,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-07, "search_context_cost_per_query": { @@ -75799,7 +73053,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "search_context_cost_per_query": { @@ -75841,7 +73094,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "supports_forced_tool_use": true, @@ -75883,7 +73135,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "supports_forced_tool_use": true, @@ -75929,7 +73180,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-07, "search_context_cost_per_query": { @@ -75981,7 +73231,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "search_context_cost_per_query": { @@ -76028,7 +73277,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-07, "search_context_cost_per_query": { @@ -76087,7 +73335,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 6e-07, "supports_forced_tool_use": true, @@ -76138,7 +73385,6 @@ "supports_tool_search": true, "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5.5e-07, "search_context_cost_per_query": { @@ -76188,7 +73434,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_batches": 2.5e-07, @@ -76233,7 +73478,6 @@ "litellm_provider": "vertex_ai-anthropic_models", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 5e-07, "output_cost_per_token_batches": 2.5e-07, @@ -76272,7 +73516,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 261120, "max_output_tokens": 98304, - "max_tokens": 98304, "mode": "chat", "output_cost_per_token": 7.5e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-twelvelabs-pegasus-v1-5.html", @@ -76283,7 +73526,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 261120, "max_output_tokens": 98304, - "max_tokens": 98304, "mode": "chat", "output_cost_per_token": 7.5e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-twelvelabs-pegasus-v1-5.html", @@ -76294,7 +73536,6 @@ "litellm_provider": "bedrock", "max_input_tokens": 261120, "max_output_tokens": 98304, - "max_tokens": 98304, "mode": "chat", "output_cost_per_token": 7.5e-06, "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-twelvelabs-pegasus-v1-5.html", @@ -76303,9 +73544,10 @@ "azure_ai/Microsoft-Decision-1": { "input_cost_per_token": 4.2e-08, "litellm_provider": "azure_ai", + "max_input_tokens": 32768, "mode": "evaluation", "output_cost_per_token": 0.0, - "source": "https://prices.azure.com/api/retail/prices?$filter=productName eq 'Microsoft Decision Models'" + "source": "https://learn.microsoft.com/en-us/azure/foundry/foundry-models/concepts/models-sold-directly-by-azure" }, "gpt-rosalind-discovery": { "cache_read_input_token_cost": 5e-07, @@ -76329,7 +73571,6 @@ "input_cost_per_token": 8e-08, "litellm_provider": "azure_ai", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 2048.0, @@ -76349,7 +73590,6 @@ "input_cost_per_token": 1.2e-07, "litellm_provider": "azure_ai", "max_input_tokens": 128000, - "max_tokens": 128000, "mode": "embedding", "output_cost_per_token": 0.0, "output_vector_size": 2048.0, @@ -76418,7 +73658,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 5e-06, "output_cost_per_token": 5e-06, @@ -76464,7 +73703,6 @@ "litellm_provider": "vertex_ai-language-models", "max_input_tokens": 131072, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_reasoning_token": 5e-06, "output_cost_per_token": 5e-06, @@ -76514,7 +73752,6 @@ "litellm_provider": "gemini", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_reasoning_token": 1e-05, "output_cost_per_token": 1e-05, @@ -76573,7 +73810,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_reasoning_token": 1e-05, "output_cost_per_token": 1e-05, @@ -76631,7 +73867,6 @@ "litellm_provider": "vertex_ai", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_reasoning_token": 2e-05, "output_cost_per_token": 2e-05, @@ -76679,7 +73914,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 65536, - "max_tokens": 65536, "mode": "chat", "output_cost_per_token": 1e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -76692,7 +73926,6 @@ "supports_vision": true }, "openinfer/@oi/GLM-5.3-Flash": { - "max_tokens": 393216, "max_input_tokens": 393216, "max_output_tokens": 393216, "input_cost_per_token": 1.95e-07, @@ -76704,7 +73937,6 @@ "source": "https://api.openinfer.ai/v1/models" }, "openinfer/@oi/Qwen3.5-27B": { - "max_tokens": 32768, "max_input_tokens": 32768, "max_output_tokens": 32768, "input_cost_per_token": 1.95e-07, @@ -76716,7 +73948,6 @@ "source": "https://api.openinfer.ai/v1/models" }, "openinfer/@oi/Qwen3.5-9B": { - "max_tokens": 100000, "max_input_tokens": 100000, "max_output_tokens": 100000, "input_cost_per_token": 5e-06, @@ -76795,7 +74026,7 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "together_ai", "max_input_tokens": 262144, - "max_tokens": 262144, + "max_output_tokens": 262144, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://api.together.ai/v1/models", @@ -76818,7 +74049,6 @@ "litellm_provider": "bedrock_converse", "max_input_tokens": 1000000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 3.311e-06, "output_cost_per_token_batches": 1.6555e-06, @@ -76840,7 +74070,6 @@ "litellm_provider": "vertex_ai-deepseek_models", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing", @@ -76864,7 +74093,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 1000000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "chat", "output_cost_per_token": 4e-05, "prompt_cache_min_tokens": 512.0, @@ -76894,7 +74122,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_token": 4.25e-06, "source": "https://inference.baseten.co/v1/models", @@ -76912,7 +74139,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_token": 5e-07, "source": "https://inference.baseten.co/v1/models", @@ -76928,7 +74154,7 @@ "input_cost_per_token": 1.5e-07, "litellm_provider": "wandb", "max_input_tokens": 1049000, - "max_tokens": 943718, + "max_output_tokens": 943718, "mode": "chat", "output_cost_per_token": 7.5e-07, "source": "https://openrouter.ai/api/v1/models/nvidia/nemotron-3.5-super-vl/endpoints", @@ -76944,7 +74170,7 @@ "input_cost_per_token": 4e-07, "litellm_provider": "together_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://api.together.ai/v1/models", @@ -76958,7 +74184,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 131072, - "max_tokens": 131072, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://inference.baseten.co/v1/models", @@ -76972,7 +74197,7 @@ "input_cost_per_token": 2.5e-07, "litellm_provider": "nebius", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1e-06, "source": "https://tokenfactory.nebius.com/models/catalog/text2text/reflection%2Fbeam", @@ -76985,7 +74210,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://inference.baseten.co/v1/models", @@ -77002,7 +74226,6 @@ "litellm_provider": "baseten", "max_input_tokens": 1048576, "max_output_tokens": 262144, - "max_tokens": 262144, "mode": "chat", "output_cost_per_token": 2.4e-06, "source": "https://inference.baseten.co/v1/models", @@ -77021,7 +74244,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 1.2e-06, "output_cost_per_token_priority": 1.5e-06, @@ -77041,7 +74263,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 200000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.5e-05, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -77063,7 +74284,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 272000, "max_output_tokens": 128000, - "max_tokens": 128000, "mode": "responses", "output_cost_per_token": 1.25e-06, "source": "https://raw.githubusercontent.com/github/docs/main/data/tables/copilot/models-and-pricing.yml", @@ -77085,7 +74305,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -77107,7 +74326,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -77129,7 +74347,6 @@ "litellm_provider": "github_copilot", "max_input_tokens": 500000, "max_output_tokens": 500000, - "max_tokens": 500000, "mode": "chat", "output_cost_per_token": 6e-06, "output_cost_per_token_above_200k_tokens": 1.2e-05, @@ -77148,7 +74365,7 @@ "input_cost_per_token": 3e-07, "litellm_provider": "together_ai", "max_input_tokens": 1048576, - "max_tokens": 1048576, + "max_output_tokens": 1048576, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://api.together.ai/v1/models", @@ -77185,7 +74402,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 1048576, - "max_tokens": 1048576, "mode": "chat", "output_cost_per_token": 6e-07, "output_cost_per_token_priority": 9e-07, @@ -77221,7 +74437,6 @@ "litellm_provider": "fireworks_ai", "max_input_tokens": 1048576, "max_output_tokens": 393216, - "max_tokens": 393216, "mode": "chat", "output_cost_per_token": 1.8e-06, "output_cost_per_token_priority": 2.25e-06, @@ -77270,7 +74485,6 @@ "litellm_provider": "azure_ai", "max_input_tokens": 256000, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "output_cost_per_token": 1.2e-06, "source": "https://prices.azure.com/api/retail/prices?$filter=serviceName%20eq%20'Foundry%20Models'%20and%20armRegionName%20eq%20'eastus'%20and%20priceType%20eq%20'Consumption'", @@ -77290,5 +74504,1547 @@ "supports_reasoning": true, "supports_tool_choice": true, "supports_vision": true + }, + "opencode_go/grok-4.7": { + "litellm_provider": "opencode_go", + "mode": "responses", + "supported_endpoints": [ + "/v1/responses" + ], + "input_cost_per_token": 2e-06, + "output_cost_per_token": 6e-06, + "cache_read_input_token_cost": 5e-07, + "max_output_tokens": 500000, + "max_input_tokens": 500000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "tiered_pricing": [ + { + "range": [ + 0, + 200000 + ], + "input_cost_per_token": 2e-06, + "output_cost_per_token": 6e-06, + "cache_read_input_token_cost": 5e-07 + }, + { + "range": [ + 200000, + 500000 + ], + "input_cost_per_token": 4e-06, + "output_cost_per_token": 1.2e-05, + "cache_read_input_token_cost": 1e-06 + } + ], + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/gpt-6-luna": { + "litellm_provider": "opencode_go", + "mode": "responses", + "supported_endpoints": [ + "/v1/responses" + ], + "input_cost_per_token": 1.0000000000000001e-07, + "output_cost_per_token": 5e-07, + "cache_read_input_token_cost": 1e-08, + "cache_creation_input_token_cost": 1.25e-07, + "max_output_tokens": 128000, + "max_input_tokens": 922000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "tiered_pricing": [ + { + "range": [ + 0, + 272000 + ], + "input_cost_per_token": 1.0000000000000001e-07, + "output_cost_per_token": 5e-07, + "cache_read_input_token_cost": 1e-08, + "cache_creation_input_token_cost": 1.25e-07 + }, + { + "range": [ + 272000, + 1050000 + ], + "input_cost_per_token": 2.0000000000000002e-07, + "output_cost_per_token": 7.5e-07, + "cache_read_input_token_cost": 2e-08, + "cache_creation_input_token_cost": 2.5e-07 + } + ], + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/gpt-5.6-luna": { + "litellm_provider": "opencode_go", + "mode": "responses", + "supported_endpoints": [ + "/v1/responses" + ], + "input_cost_per_token": 2.0000000000000002e-07, + "output_cost_per_token": 1.2e-06, + "cache_read_input_token_cost": 2e-08, + "cache_creation_input_token_cost": 2.5e-07, + "max_output_tokens": 128000, + "max_input_tokens": 922000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "tiered_pricing": [ + { + "range": [ + 0, + 272000 + ], + "input_cost_per_token": 2.0000000000000002e-07, + "output_cost_per_token": 1.2e-06, + "cache_read_input_token_cost": 2e-08, + "cache_creation_input_token_cost": 2.5e-07 + }, + { + "range": [ + 272000, + 1050000 + ], + "input_cost_per_token": 4.0000000000000003e-07, + "output_cost_per_token": 1.8000000000000001e-06, + "cache_read_input_token_cost": 4e-08, + "cache_creation_input_token_cost": 5e-07 + } + ], + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/claude-haiku-5-5": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/messages" + ], + "input_cost_per_token": 1.0000000000000001e-07, + "output_cost_per_token": 5e-07, + "cache_read_input_token_cost": 1e-08, + "cache_creation_input_token_cost": 1.25e-07, + "max_output_tokens": 128000, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "tiered_pricing": [ + { + "range": [ + 0, + 100000 + ], + "input_cost_per_token": 1.0000000000000001e-07, + "output_cost_per_token": 5e-07, + "cache_read_input_token_cost": 1e-08, + "cache_creation_input_token_cost": 1.25e-07 + }, + { + "range": [ + 100000, + 1000000 + ], + "input_cost_per_token": 5e-07, + "output_cost_per_token": 2.5e-06, + "cache_read_input_token_cost": 5.0000000000000004e-08, + "cache_creation_input_token_cost": 6.25e-07 + } + ], + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/gemini-4-argon": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1beta/models" + ], + "input_cost_per_token": 2e-06, + "output_cost_per_token": 1e-05, + "cache_read_input_token_cost": 1e-07, + "max_output_tokens": 65536, + "max_input_tokens": 1048576, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/glm-5.3-flash": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 1.5e-07, + "output_cost_per_token": 5e-07, + "cache_read_input_token_cost": 3e-08, + "max_output_tokens": 131072, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/glm-5.3": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 1.4e-06, + "output_cost_per_token": 4.4e-06, + "cache_read_input_token_cost": 2.6e-07, + "max_output_tokens": 131072, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": false, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/glm-5.2": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 1.4e-06, + "output_cost_per_token": 4.4e-06, + "cache_read_input_token_cost": 2.6e-07, + "max_output_tokens": 131072, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": false, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/kimi-k3.1-pro": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 2e-06, + "output_cost_per_token": 1e-05, + "cache_read_input_token_cost": 2.0000000000000002e-07, + "cache_creation_input_token_cost": 2e-06, + "max_output_tokens": 131072, + "max_input_tokens": 1048576, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/kimi-k3": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 3e-06, + "output_cost_per_token": 1.5e-05, + "cache_read_input_token_cost": 3e-07, + "cache_creation_input_token_cost": 3e-06, + "max_output_tokens": 131072, + "max_input_tokens": 1048576, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/kimi-k2.7-code": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 9.499999999999999e-07, + "output_cost_per_token": 4e-06, + "cache_read_input_token_cost": 1.9e-07, + "max_output_tokens": 262144, + "max_input_tokens": 262144, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/longcat-2.0": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 3e-07, + "output_cost_per_token": 1.2e-06, + "cache_read_input_token_cost": 6e-09, + "max_output_tokens": 131072, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": false, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/deepseek-v4.1-flash": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 3e-07, + "output_cost_per_token": 1.2e-06, + "cache_read_input_token_cost": 6e-09, + "max_output_tokens": 384000, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/deepseek-v4-pro": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 1.32e-06, + "output_cost_per_token": 3.96e-06, + "cache_read_input_token_cost": 4.4e-08, + "max_output_tokens": 384000, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": false, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/mimo-v2.6-flash": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 1.4e-07, + "output_cost_per_token": 2.8e-07, + "cache_read_input_token_cost": 2.8e-09, + "max_output_tokens": 131072, + "max_input_tokens": 1048576, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/mimo-v2.6-pro": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 4.35e-07, + "output_cost_per_token": 8.7e-07, + "cache_read_input_token_cost": 3.625e-09, + "max_output_tokens": 131072, + "max_input_tokens": 1048576, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/mimo-v2.5": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 1.4e-07, + "output_cost_per_token": 2.8e-07, + "cache_read_input_token_cost": 2.8e-09, + "max_output_tokens": 128000, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/mimo-v2.5-pro": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 4.35e-07, + "output_cost_per_token": 8.7e-07, + "cache_read_input_token_cost": 3.625e-09, + "max_output_tokens": 128000, + "max_input_tokens": 1048576, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": false, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/minimax-m3.1-flash": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 1.5e-07, + "output_cost_per_token": 6e-07, + "cache_read_input_token_cost": 1.5e-08, + "max_output_tokens": 512000, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/minimax-m3": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/messages" + ], + "input_cost_per_token": 3e-07, + "output_cost_per_token": 1.2e-06, + "cache_read_input_token_cost": 6e-08, + "max_output_tokens": 131072, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/muse-spark-1.3-contributor": { + "litellm_provider": "opencode_go", + "mode": "responses", + "supported_endpoints": [ + "/v1/responses" + ], + "input_cost_per_token": 1.0000000000000001e-07, + "output_cost_per_token": 2.0000000000000002e-07, + "cache_read_input_token_cost": 2e-09, + "max_output_tokens": 131072, + "max_input_tokens": 1048576, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/muse-spark-1.2-contributor": { + "litellm_provider": "opencode_go", + "mode": "responses", + "supported_endpoints": [ + "/v1/responses" + ], + "input_cost_per_token": 1.0000000000000001e-07, + "output_cost_per_token": 2.0000000000000002e-07, + "cache_read_input_token_cost": 2e-09, + "max_output_tokens": 131072, + "max_input_tokens": 1048576, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/qwen3.8-max": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/messages" + ], + "input_cost_per_token": 2e-06, + "output_cost_per_token": 6e-06, + "cache_read_input_token_cost": 2.5e-07, + "cache_creation_input_token_cost": 2.5e-06, + "max_output_tokens": 131072, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/qwen3.8-flash": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/messages" + ], + "input_cost_per_token": 1.5e-07, + "output_cost_per_token": 4.6999999999999995e-07, + "cache_read_input_token_cost": 1.6e-08, + "cache_creation_input_token_cost": 2.0000000000000002e-07, + "max_output_tokens": 131072, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/qwen3.7-plus": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/messages" + ], + "input_cost_per_token": 4.0000000000000003e-07, + "output_cost_per_token": 1.6000000000000001e-06, + "cache_read_input_token_cost": 4e-08, + "cache_creation_input_token_cost": 5e-07, + "max_output_tokens": 65536, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "tiered_pricing": [ + { + "range": [ + 0, + 256000 + ], + "input_cost_per_token": 4.0000000000000003e-07, + "output_cost_per_token": 1.6000000000000001e-06, + "cache_read_input_token_cost": 4e-08, + "cache_creation_input_token_cost": 5e-07 + }, + { + "range": [ + 256000, + 1000000 + ], + "input_cost_per_token": 1.2e-06, + "output_cost_per_token": 4.8e-06, + "cache_read_input_token_cost": 1.2e-07, + "cache_creation_input_token_cost": 1.5e-06 + } + ], + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/hy4-preview": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 8.34e-07, + "output_cost_per_token": 2.501e-06, + "cache_read_input_token_cost": 4.2000000000000006e-08, + "max_output_tokens": 64000, + "max_input_tokens": 1024000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": false, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/hy3": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 1.4e-07, + "output_cost_per_token": 5.8e-07, + "cache_read_input_token_cost": 3.5e-08, + "max_output_tokens": 128000, + "max_input_tokens": 192000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": false, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/longcat-2.5-preview-free": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 0, + "output_cost_per_token": 0, + "cache_read_input_token_cost": 0, + "max_output_tokens": 131072, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/step-5-preview": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 1e-06, + "output_cost_per_token": 2.7e-06, + "cache_read_input_token_cost": 1.0000000000000001e-07, + "max_output_tokens": 65536, + "max_input_tokens": 1000000, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": true, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "opencode_go/beam-free": { + "litellm_provider": "opencode_go", + "mode": "chat", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "input_cost_per_token": 0, + "output_cost_per_token": 0, + "cache_read_input_token_cost": 0, + "max_output_tokens": 131072, + "max_input_tokens": 1048576, + "supports_function_calling": true, + "supports_reasoning": true, + "supports_vision": false, + "source": "https://opencode.ai/v2/docs/console/go/" + }, + "bedrock/claude_platform/claude-fable-5": { + "supports_web_search": true, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 1.25e-05, + "cache_creation_input_token_cost_above_1hr": 2e-05, + "cache_creation_input_token_cost_batches": 6.25e-06, + "cache_read_input_token_cost": 1e-06, + "cache_read_input_token_cost_batches": 5e-07, + "input_cost_per_token": 1e-05, + "input_cost_per_token_batches": 5e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 5e-05, + "output_cost_per_token_batches": 2.5e-05, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "thinking_always_on": true, + "supports_mid_conversation_system": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "supports_max_reasoning_effort": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "prompt_cache_min_tokens": 512, + "supports_native_structured_output": true, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-fable-5-1": { + "supports_web_search": true, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 1.25e-05, + "cache_creation_input_token_cost_above_1hr": 2e-05, + "cache_creation_input_token_cost_batches": 6.25e-06, + "cache_read_input_token_cost": 2.5e-07, + "cache_read_input_token_cost_batches": 1.25e-07, + "input_cost_per_token": 1e-05, + "input_cost_per_token_batches": 5e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 5e-05, + "output_cost_per_token_batches": 2.5e-05, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "thinking_always_on": true, + "supports_mid_conversation_system": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_forced_tool_use": false, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "supports_max_reasoning_effort": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "prompt_cache_min_tokens": 512, + "supports_native_structured_output": true, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-haiku-4-5": { + "cache_creation_input_token_cost": 1.25e-06, + "cache_creation_input_token_cost_above_1hr": 2e-06, + "cache_creation_input_token_cost_batches": 6.25e-07, + "cache_read_input_token_cost": 1e-07, + "cache_read_input_token_cost_batches": 5e-08, + "input_cost_per_token": 1e-06, + "input_cost_per_token_batches": 5e-07, + "litellm_provider": "bedrock", + "max_input_tokens": 200000, + "max_output_tokens": 64000, + "mode": "chat", + "output_cost_per_token": 5e-06, + "output_cost_per_token_batches": 2.5e-06, + "supports_assistant_prefill": true, + "supports_function_calling": true, + "supports_native_structured_output": true, + "supports_computer_use": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": true, + "prompt_cache_min_tokens": 4096, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-haiku-5-5": { + "input_cost_per_token_above_100k_tokens_batches": 2.5e-07, + "output_cost_per_token_above_100k_tokens_batches": 1.25e-06, + "cache_creation_input_token_cost_above_100k_tokens_batches": 3.125e-07, + "cache_read_input_token_cost_above_100k_tokens_batches": 2.5e-08, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 1.25e-07, + "cache_creation_input_token_cost_above_1hr": 2e-07, + "cache_creation_input_token_cost_batches": 6.25e-08, + "cache_read_input_token_cost": 1e-08, + "cache_read_input_token_cost_batches": 5e-09, + "input_cost_per_token": 1e-07, + "input_cost_per_token_batches": 5e-08, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 5e-07, + "output_cost_per_token_batches": 2.5e-07, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "supports_mid_conversation_system": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_native_structured_output": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "supports_max_reasoning_effort": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "supports_forced_tool_use": true, + "thinking_always_on": false, + "prompt_cache_min_tokens": 512, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing", + "supports_web_search": true, + "input_cost_per_token_above_100k_tokens": 5e-07, + "output_cost_per_token_above_100k_tokens": 2.5e-06, + "cache_creation_input_token_cost_above_100k_tokens": 6.25e-07, + "cache_creation_input_token_cost_above_1hr_above_100k_tokens": 1e-06, + "cache_read_input_token_cost_above_100k_tokens": 5e-08 + }, + "bedrock/claude_platform/claude-opus-4-5": { + "cache_creation_input_token_cost": 6.25e-06, + "cache_creation_input_token_cost_above_1hr": 1e-05, + "cache_creation_input_token_cost_batches": 3.125e-06, + "cache_read_input_token_cost": 5e-07, + "cache_read_input_token_cost_batches": 2.5e-07, + "input_cost_per_token": 5e-06, + "input_cost_per_token_batches": 2.5e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 200000, + "max_output_tokens": 64000, + "mode": "chat", + "output_cost_per_token": 2.5e-05, + "output_cost_per_token_batches": 1.25e-05, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_assistant_prefill": true, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_thinking_cache_preservation": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_native_structured_output": true, + "supports_tool_choice": true, + "supports_vision": true, + "supports_output_config": true, + "prompt_cache_min_tokens": 4096, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-opus-4-6": { + "supports_web_search": true, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 6.25e-06, + "cache_creation_input_token_cost_above_1hr": 1e-05, + "cache_creation_input_token_cost_batches": 3.125e-06, + "cache_read_input_token_cost": 5e-07, + "cache_read_input_token_cost_batches": 2.5e-07, + "input_cost_per_token": 5e-06, + "input_cost_per_token_batches": 2.5e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 2.5e-05, + "output_cost_per_token_batches": 1.25e-05, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "supports_legacy_thinking": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_thinking_cache_preservation": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_native_structured_output": true, + "supports_tool_choice": true, + "supports_vision": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "supports_max_reasoning_effort": true, + "prompt_cache_min_tokens": 4096, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-opus-4-7": { + "supports_web_search": true, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 6.25e-06, + "cache_creation_input_token_cost_above_1hr": 1e-05, + "cache_creation_input_token_cost_batches": 3.125e-06, + "cache_read_input_token_cost": 5e-07, + "cache_read_input_token_cost_batches": 2.5e-07, + "input_cost_per_token": 5e-06, + "input_cost_per_token_batches": 2.5e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 2.5e-05, + "output_cost_per_token_batches": 1.25e-05, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_thinking_cache_preservation": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_native_structured_output": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "supports_max_reasoning_effort": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "prompt_cache_min_tokens": 2048, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-opus-4-8": { + "supports_web_search": true, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 6.25e-06, + "cache_creation_input_token_cost_above_1hr": 1e-05, + "cache_creation_input_token_cost_batches": 3.125e-06, + "cache_read_input_token_cost": 5e-07, + "cache_read_input_token_cost_batches": 2.5e-07, + "input_cost_per_token": 5e-06, + "input_cost_per_token_batches": 2.5e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 2.5e-05, + "output_cost_per_token_batches": 1.25e-05, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "supports_mid_conversation_system": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_thinking_cache_preservation": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_native_structured_output": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "supports_max_reasoning_effort": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "prompt_cache_min_tokens": 1024, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-opus-5": { + "supports_web_search": true, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 6.25e-06, + "cache_creation_input_token_cost_above_1hr": 1e-05, + "cache_creation_input_token_cost_batches": 3.125e-06, + "cache_read_input_token_cost": 5e-07, + "cache_read_input_token_cost_batches": 2.5e-07, + "input_cost_per_token": 5e-06, + "input_cost_per_token_batches": 2.5e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 2.5e-05, + "output_cost_per_token_batches": 1.25e-05, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "supports_mid_conversation_system": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_thinking_cache_preservation": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_native_structured_output": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "supports_max_reasoning_effort": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "prompt_cache_min_tokens": 512, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-opus-5-5": { + "supports_web_search": true, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 5e-06, + "cache_creation_input_token_cost_above_1hr": 8e-06, + "cache_creation_input_token_cost_batches": 2.5e-06, + "cache_read_input_token_cost": 2e-07, + "cache_read_input_token_cost_batches": 1e-07, + "input_cost_per_token": 4e-06, + "input_cost_per_token_batches": 2e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 2e-05, + "output_cost_per_token_batches": 1e-05, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "thinking_always_on": true, + "supports_mid_conversation_system": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_forced_tool_use": false, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_native_structured_output": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "supports_max_reasoning_effort": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "prompt_cache_min_tokens": 512, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-sonnet-4-5": { + "cache_creation_input_token_cost": 3.75e-06, + "cache_creation_input_token_cost_above_1hr": 6e-06, + "cache_read_input_token_cost": 3e-07, + "input_cost_per_token": 3e-06, + "cache_creation_input_token_cost_batches": 1.875e-06, + "cache_read_input_token_cost_batches": 1.5e-07, + "deprecation_date": "2026-11-30", + "input_cost_per_token_batches": 1.5e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 200000, + "max_output_tokens": 64000, + "mode": "chat", + "output_cost_per_token": 1.5e-05, + "output_cost_per_token_batches": 7.5e-06, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_assistant_prefill": true, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_native_structured_output": true, + "supports_tool_choice": true, + "supports_vision": true, + "prompt_cache_min_tokens": 1024, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-sonnet-4-6": { + "supports_web_search": true, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 3.75e-06, + "cache_creation_input_token_cost_above_1hr": 6e-06, + "cache_creation_input_token_cost_batches": 1.875e-06, + "cache_read_input_token_cost": 3e-07, + "cache_read_input_token_cost_batches": 1.5e-07, + "input_cost_per_token": 3e-06, + "input_cost_per_token_batches": 1.5e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 1.5e-05, + "output_cost_per_token_batches": 7.5e-06, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "supports_legacy_thinking": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_thinking_cache_preservation": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_native_structured_output": true, + "supports_max_reasoning_effort": true, + "supports_tool_choice": true, + "supports_vision": true, + "supports_output_config": true, + "prompt_cache_min_tokens": 1024, + "provider_specific_entry": { + "us": 1.1 + }, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-sonnet-5": { + "supports_web_search": true, + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 2.5e-06, + "cache_creation_input_token_cost_above_1hr": 4e-06, + "cache_creation_input_token_cost_batches": 1.25e-06, + "cache_read_input_token_cost": 2e-07, + "cache_read_input_token_cost_batches": 1e-07, + "input_cost_per_token": 2e-06, + "input_cost_per_token_batches": 1e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 1e-05, + "output_cost_per_token_batches": 5e-06, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "supports_mid_conversation_system": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_native_structured_output": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_thinking_cache_preservation": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "supports_max_reasoning_effort": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "prompt_cache_min_tokens": 1024, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing" + }, + "bedrock/claude_platform/claude-sonnet-5-5": { + "supports_anthropic_compaction": true, + "cache_creation_input_token_cost": 2.5e-06, + "cache_creation_input_token_cost_above_1hr": 4e-06, + "cache_creation_input_token_cost_batches": 1.25e-06, + "cache_read_input_token_cost": 1e-07, + "cache_read_input_token_cost_batches": 5e-08, + "input_cost_per_token": 2e-06, + "input_cost_per_token_batches": 1e-06, + "litellm_provider": "bedrock", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 1e-05, + "output_cost_per_token_batches": 5e-06, + "search_context_cost_per_query": { + "search_context_size_high": 0.01, + "search_context_size_low": 0.01, + "search_context_size_medium": 0.01 + }, + "supports_adaptive_thinking": true, + "supports_mid_conversation_system": true, + "supports_assistant_prefill": false, + "supports_computer_use": true, + "supports_function_calling": true, + "supports_native_structured_output": true, + "supports_pdf_input": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "supports_max_reasoning_effort": true, + "provider_specific_entry": { + "us": 1.1 + }, + "supports_output_config": true, + "supports_forced_tool_use": false, + "thinking_always_on": true, + "prompt_cache_min_tokens": 512, + "source": "https://platform.claude.com/docs/en/about-claude/pricing#claude-platform-on-aws-pricing", + "supports_web_search": true + }, + "gpt-6.1-terra": { + "cache_creation_input_token_cost": 1.25e-06, + "cache_creation_input_token_cost_above_12hr": 2.5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches": 2.5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": 2.5e-06, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": 1e-05, + "cache_creation_input_token_cost_above_12hr_batches": 1.25e-06, + "cache_creation_input_token_cost_above_12hr_flex": 1.25e-06, + "cache_creation_input_token_cost_above_12hr_priority": 5e-06, + "cache_creation_input_token_cost_above_272k_tokens": 2.5e-06, + "cache_creation_input_token_cost_above_272k_tokens_batches": 1.25e-06, + "cache_creation_input_token_cost_above_272k_tokens_flex": 1.25e-06, + "cache_creation_input_token_cost_above_272k_tokens_priority": 5e-06, + "cache_creation_input_token_cost_batches": 6.25e-07, + "cache_creation_input_token_cost_flex": 6.25e-07, + "cache_creation_input_token_cost_priority": 2.5e-06, + "cache_read_input_token_cost": 5e-08, + "cache_read_input_token_cost_above_272k_tokens": 1e-07, + "cache_read_input_token_cost_above_272k_tokens_batches": 5e-08, + "cache_read_input_token_cost_above_272k_tokens_flex": 5e-08, + "cache_read_input_token_cost_above_272k_tokens_priority": 2e-07, + "cache_read_input_token_cost_batches": 2.5e-08, + "cache_read_input_token_cost_flex": 2.5e-08, + "cache_read_input_token_cost_priority": 1e-07, + "input_cost_per_token": 1e-06, + "input_cost_per_token_above_272k_tokens": 2e-06, + "input_cost_per_token_above_272k_tokens_batches": 1e-06, + "input_cost_per_token_above_272k_tokens_flex": 1e-06, + "input_cost_per_token_above_272k_tokens_priority": 4e-06, + "input_cost_per_token_batches": 5e-07, + "input_cost_per_token_flex": 5e-07, + "input_cost_per_token_priority": 2e-06, + "litellm_provider": "openai", + "max_input_tokens": 922000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 5e-06, + "output_cost_per_token_above_272k_tokens": 7.5e-06, + "output_cost_per_token_above_272k_tokens_batches": 3.75e-06, + "output_cost_per_token_above_272k_tokens_flex": 3.75e-06, + "output_cost_per_token_above_272k_tokens_priority": 1.5e-05, + "output_cost_per_token_batches": 2.5e-06, + "output_cost_per_token_flex": 2.5e-06, + "output_cost_per_token_priority": 1e-05, + "regional_processing_uplift_multiplier_eu": 1.1, + "regional_processing_uplift_multiplier_us": 1.1, + "search_context_cost_per_query": {"search_context_size_high":0.01,"search_context_size_low":0.01,"search_context_size_medium":0.01}, + "source": "https://developers.openai.com/api/docs/pricing", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/batch", + "/v1/responses" + ], + "supported_modalities": [ + "text", + "image" + ], + "supported_output_modalities": [ + "text" + ], + "supports_computer_use": true, + "supports_function_calling": true, + "supports_max_reasoning_effort": true, + "supports_minimal_reasoning_effort": false, + "supports_native_streaming": true, + "supports_none_reasoning_effort": true, + "supports_parallel_function_calling": true, + "supports_pdf_input": true, + "supports_prompt_cache_breakpoint": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_tool_search": true, + "supports_vision": true, + "supports_web_search": true, + "supports_xhigh_reasoning_effort": true + }, + "chatgpt/gpt-6.1-terra": { + "litellm_provider": "chatgpt", + "max_input_tokens": 922000, + "max_output_tokens": 128000, + "mode": "responses", + "source": "https://developers.openai.com/api/docs/pricing", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/responses" + ], + "supports_function_calling": true, + "supports_max_reasoning_effort": true, + "supports_minimal_reasoning_effort": false, + "supports_none_reasoning_effort": true, + "supports_parallel_function_calling": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true + }, + "global.openai.gpt-6.1-terra": { + "cache_creation_input_token_cost": 1.25e-06, + "cache_creation_input_token_cost_above_272k_tokens": 2.5e-06, + "cache_read_input_token_cost": 5e-08, + "cache_read_input_token_cost_above_272k_tokens": 1e-07, + "input_cost_per_token": 1e-06, + "input_cost_per_token_above_272k_tokens": 2e-06, + "litellm_provider": "bedrock_converse", + "max_input_tokens": 922000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 5e-06, + "output_cost_per_token_above_272k_tokens": 7.5e-06, + "source": "https://developers.openai.com/api/docs/models/gpt-6.1-terra", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/responses" + ], + "supported_modalities": [ + "text", + "image" + ], + "supported_output_modalities": [ + "text" + ], + "supports_bedrock_converse_tool_result_images": false, + "supports_bedrock_runtime_chat_completions_response_format": true, + "supports_function_calling": true, + "supports_max_reasoning_effort": true, + "supports_minimal_reasoning_effort": false, + "supports_none_reasoning_effort": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true + }, + "us.openai.gpt-6.1-terra": { + "cache_creation_input_token_cost": 1.375e-06, + "cache_creation_input_token_cost_above_272k_tokens": 2.75e-06, + "cache_read_input_token_cost": 5.5e-08, + "cache_read_input_token_cost_above_272k_tokens": 1.1e-07, + "input_cost_per_token": 1.1e-06, + "input_cost_per_token_above_272k_tokens": 2.2e-06, + "litellm_provider": "bedrock_converse", + "max_input_tokens": 922000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 5.5e-06, + "output_cost_per_token_above_272k_tokens": 8.25e-06, + "source": "https://developers.openai.com/api/docs/models/gpt-6.1-terra", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/responses" + ], + "supported_modalities": [ + "text", + "image" + ], + "supported_output_modalities": [ + "text" + ], + "supports_bedrock_converse_tool_result_images": false, + "supports_bedrock_runtime_chat_completions_response_format": true, + "supports_function_calling": true, + "supports_max_reasoning_effort": true, + "supports_minimal_reasoning_effort": false, + "supports_none_reasoning_effort": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_sampling_params": false, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true + }, + "baseten/decision-models/baseten-elephant-9b-latest": { + "input_cost_per_token": 0.0, + "litellm_provider": "baseten", + "max_input_tokens": 16384, + "mode": "decisions", + "output_cost_per_token": 0.0, + "source": "https://inference.baseten.co/v1/models", + "supports_vision": true + }, + "baseten/decision-models/baseten-mammoth-27b-latest": { + "input_cost_per_token": 0.0, + "litellm_provider": "baseten", + "max_input_tokens": 16384, + "mode": "decisions", + "output_cost_per_token": 0.0, + "source": "https://inference.baseten.co/v1/models", + "supports_vision": true + }, + "github_copilot/gpt-6.1-terra": { + "cache_creation_input_token_cost": 1.25e-06, + "cache_creation_input_token_cost_above_272k_tokens": 2.5e-06, + "cache_read_input_token_cost": 5e-08, + "cache_read_input_token_cost_above_272k_tokens": 1e-07, + "input_cost_per_token": 1e-06, + "input_cost_per_token_above_272k_tokens": 2e-06, + "litellm_provider": "github_copilot", + "max_input_tokens": 922000, + "max_output_tokens": 128000, + "mode": "responses", + "output_cost_per_token": 5e-06, + "output_cost_per_token_above_272k_tokens": 7.5e-06, + "source": "https://github.blog/changelog/2026-10-26-gpt-6-1-terra-in-github-copilot", + "supported_endpoints": [ + "/v1/responses" + ], + "supports_function_calling": true, + "supports_parallel_function_calling": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_vision": true + }, + "refuseless/glm-5.3-abliterated": { + "cache_read_input_token_cost": 2.5e-07, + "input_cost_per_token": 1.25e-06, + "litellm_provider": "refuseless", + "max_input_tokens": 1048576, + "max_output_tokens": 131072, + "mode": "chat", + "output_cost_per_token": 2.25e-06, + "source": "https://refuseless.com/pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ] + }, + "refuseless/glm-5.3-flash-abliterated": { + "cache_read_input_token_cost": 1.5e-07, + "input_cost_per_token": 2.5e-07, + "litellm_provider": "refuseless", + "max_input_tokens": 1048576, + "max_output_tokens": 131072, + "mode": "chat", + "output_cost_per_token": 8e-07, + "source": "https://refuseless.com/pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ] + }, + "refuseless/deepseek-v4.1-flash-abliterated": { + "cache_read_input_token_cost": 4.5e-08, + "input_cost_per_token": 2.2e-07, + "litellm_provider": "refuseless", + "max_input_tokens": 1048576, + "max_output_tokens": 130000, + "mode": "chat", + "output_cost_per_token": 7.5e-07, + "source": "https://refuseless.com/pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ] + }, + "refuseless/deepseek-v4.1-flash-fast": { + "cache_read_input_token_cost": 3e-09, + "input_cost_per_token": 5e-08, + "litellm_provider": "refuseless", + "max_input_tokens": 1048576, + "max_output_tokens": 262144, + "mode": "chat", + "output_cost_per_token": 1.5e-07, + "source": "https://refuseless.com/pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ] + }, + "refuseless/minimax-m3.1-flash": { + "cache_read_input_token_cost": 2e-09, + "input_cost_per_token": 5e-08, + "litellm_provider": "refuseless", + "max_input_tokens": 1048576, + "max_output_tokens": 512000, + "mode": "chat", + "output_cost_per_token": 2.5e-07, + "source": "https://refuseless.com/pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ] + }, + "bedrock_mantle/openai.gpt-6.1-terra": { + "cache_creation_input_token_cost": 1.375e-06, + "cache_creation_input_token_cost_above_272k_tokens": 2.75e-06, + "cache_read_input_token_cost": 5.5e-08, + "cache_read_input_token_cost_above_272k_tokens": 1.1e-07, + "input_cost_per_token": 1.1e-06, + "input_cost_per_token_above_272k_tokens": 2.2e-06, + "litellm_provider": "bedrock_mantle", + "max_input_tokens": 922000, + "max_output_tokens": 128000, + "mode": "responses", + "output_cost_per_token": 5.5e-06, + "output_cost_per_token_above_272k_tokens": 8.25e-06, + "source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-6-1-terra.html", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/responses" + ], + "supported_modalities": [ + "text", + "image" + ], + "supported_output_modalities": [ + "text" + ], + "supports_function_calling": true, + "supports_max_reasoning_effort": true, + "supports_minimal_reasoning_effort": false, + "supports_none_reasoning_effort": true, + "supports_prompt_cache_breakpoint": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": true, + "supports_xhigh_reasoning_effort": true, + "use_openai_responses_path": true } } diff --git a/packaging/litellm-core/pyproject.toml b/packaging/litellm-core/pyproject.toml index 890fa0fd773..27681d9116c 100644 --- a/packaging/litellm-core/pyproject.toml +++ b/packaging/litellm-core/pyproject.toml @@ -3,14 +3,14 @@ name = "litellm-core" version = "1.105.0" description = "Library to easily interface with LLM API providers" readme = "README.md" -requires-python = ">=3.10, <3.15" +requires-python = ">=3.10, <3.16" license = "MIT" license-files = ["LICENSE"] authors = [ { name = "BerriAI" }, ] dependencies = [ - "fastuuid>=0.14.0,<1.0", + "fastuuid>=0.14.0,<1.0; python_version < '3.15'", "filelock>=3.16.1,<4.0", "httpx[http2]>=0.28.0,<1.0", "openai>=2.20.0,<4.0.0", @@ -20,14 +20,16 @@ dependencies = [ "packaging>=24.0", "importlib-metadata>=8.0.0,<9.0", "tiktoken>=0.8.0,<1.0; python_version < '3.14'", - "tiktoken>=0.12.0,<1.0; python_version >= '3.14'", + "tiktoken>=0.12.0,<1.0; python_version == '3.14'", + "tiktoken>=0.14.0,<1.0; python_version >= '3.15'", "click>=8.0.0,<9.0", "jinja2>=3.1.6,<4.0", "aiohttp>=3.14.2,<4.0", "anyio>=4.14.0,<5.0", "async-timeout>=4.0.3,<6.0; python_version < '3.11'", "pydantic>=2.11.0,<3.0.0; python_version < '3.14'", - "pydantic>=2.12.0,<3.0.0; python_version >= '3.14'", + "pydantic>=2.12.0,<3.0.0; python_version == '3.14'", + "pydantic>=2.14.0,<3.0.0; python_version >= '3.15'", "pydantic-settings>=2.14.1,<3.0", "jsonschema>=4.0.0,<5.0", "certifi>=2026.10.19", diff --git a/provider_endpoints_support.json b/provider_endpoints_support.json index d65da3f41fd..9ba6ed342ea 100644 --- a/provider_endpoints_support.json +++ b/provider_endpoints_support.json @@ -33,21 +33,56 @@ } }, "providers": { + "refuseless": { + "display_name": "Refuseless (`refuseless`)", + "url": "https://docs.litellm.ai/docs/providers/refuseless", + "endpoints": { + "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true + } + }, "a2a": { "display_name": "A2A (Agent-to-Agent) (`a2a`)", "url": "https://docs.litellm.ai/docs/providers/a2a", "endpoints": { - "chat_completions": true, - "messages": false, + "chat_completions": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "abliteration": { @@ -55,34 +90,51 @@ "url": "https://docs.litellm.ai/docs/providers/abliteration", "endpoints": { "chat_completions": true, - "messages": false, - "responses": false, + "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "aiml": { "display_name": "AI/ML API (`aiml`)", "url": "https://docs.litellm.ai/docs/providers/aiml", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": true, + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, "image_generations": true, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "ai21": { @@ -90,35 +142,51 @@ "url": "https://docs.litellm.ai/docs/providers/ai21", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "ai21_chat": { "display_name": "AI21 Chat (`ai21_chat`)", "url": "https://docs.litellm.ai/docs/providers/ai21", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "amazon_nova": { @@ -126,17 +194,25 @@ "url": "https://docs.litellm.ai/docs/providers/amazon_nova", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "anthropic": { @@ -144,18 +220,26 @@ "url": "https://docs.litellm.ai/docs/providers/anthropic", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": true, "rerank": false, - "skills": true, - "a2a": true, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true, + "skills": true, "count_tokens": true } }, @@ -163,35 +247,52 @@ "display_name": "Anthropic Text (`anthropic_text`)", "url": "https://docs.litellm.ai/docs/providers/anthropic", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": true, "rerank": false, - "skills": true, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, + "skills": true } }, "apertis": { "display_name": "Apertis (`apertis`)", "endpoints": { - "chat_completions": true, - "messages": false, + "chat_completions": false, "responses": false, - "embeddings": true, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "aihubmix": { @@ -199,52 +300,77 @@ "url": "https://docs.litellm.ai/docs/providers/aihubmix", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": true, - "image_generations": true, - "audio_transcriptions": true, - "audio_speech": true, - "moderations": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": true, - "a2a": false + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "assemblyai": { "display_name": "AssemblyAI (`assemblyai`)", "url": "https://docs.litellm.ai/docs/pass_through/assembly_ai", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": true, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "auto_router": { "display_name": "Auto Router (`auto_router`)", "url": "https://docs.litellm.ai/docs/proxy/auto_routing", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "bedrock": { @@ -252,17 +378,25 @@ "url": "https://docs.litellm.ai/docs/providers/bedrock", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": true, - "image_generations": false, + "image_generations": true, + "image_edits": true, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": true, - "a2a": true, + "ocr": false, + "search": false, + "moderations": false, + "realtime": true, + "video_generations": false, + "batches": false, + "messages": true, "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true, "bedrock_invoke": true, "bedrock_converse": true, "vector_stores_search": true, @@ -276,17 +410,25 @@ "url": "https://docs.litellm.ai/docs/providers/s3_vectors", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, "vector_stores_create": true, "vector_stores_search": true } @@ -296,17 +438,25 @@ "url": "https://docs.litellm.ai/docs/providers/aws_sagemaker", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": true, + "text_completion": true, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "aws_polly": { @@ -314,15 +464,25 @@ "url": "https://docs.litellm.ai/docs/providers/aws_polly", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": true, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "azure": { @@ -330,21 +490,28 @@ "url": "https://docs.litellm.ai/docs/providers/azure", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": true, "image_generations": true, + "image_edits": true, "audio_transcriptions": true, "audio_speech": true, - "moderations": true, - "batches": true, "rerank": false, - "a2a": true, + "ocr": false, + "search": false, + "moderations": false, + "realtime": true, + "video_generations": true, + "batches": true, + "messages": true, "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true, "vector_stores_search": true, "assistants": true, - "fine_tuning": true, - "text_completion": true + "fine_tuning": true } }, "azure_ai": { @@ -352,19 +519,25 @@ "url": "https://docs.litellm.ai/docs/providers/azure_ai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": true, "image_generations": true, "image_edits": true, "audio_transcriptions": true, - "audio_speech": true, - "moderations": true, - "batches": true, - "rerank": false, + "audio_speech": false, + "rerank": true, "ocr": true, - "a2a": true, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": true, + "messages": true, "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true, "vector_stores_create": true, "vector_stores_search": true } @@ -374,52 +547,77 @@ "url": "https://docs.litellm.ai/docs/providers/azure_document_intelligence", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "ocr": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "azure_ai/agents": { "display_name": "Azure AI Foundry Agents (`azure_ai/agents`)", "url": "https://docs.litellm.ai/docs/providers/azure_ai_agents", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "azure_text": { "display_name": "Azure Text (`azure_text`)", "url": "https://docs.litellm.ai/docs/providers/azure", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": true, "embeddings": false, "image_generations": false, - "audio_transcriptions": true, - "audio_speech": true, - "moderations": true, - "batches": true, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "baseten": { @@ -427,53 +625,77 @@ "url": "https://docs.litellm.ai/docs/providers/baseten", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "bytez": { "display_name": "Bytez (`bytez`)", "url": "https://docs.litellm.ai/docs/providers/bytez", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "nadir": { "display_name": "Nadir (`nadir`)", "url": "https://docs.litellm.ai/docs/providers/nadir", "endpoints": { - "chat_completions": true, - "messages": false, + "chat_completions": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, "a2a": false, - "interactions": false + "generateContent": false } }, "cerebras": { @@ -481,69 +703,102 @@ "url": "https://docs.litellm.ai/docs/providers/cerebras", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "charity_engine": { "display_name": "Charity Engine (`charity_engine`)", "url": "https://docs.litellm.ai/docs/providers/charity_engine", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, "a2a": false, - "interactions": false + "generateContent": false } }, "chutes": { "display_name": "Chutes (`chutes`)", "endpoints": { - "chat_completions": true, - "messages": false, + "chat_completions": false, "responses": false, - "embeddings": true, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "clarifai": { "display_name": "Clarifai (`clarifai`)", "url": "https://docs.litellm.ai/docs/providers/clarifai", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "cloudflare": { @@ -551,17 +806,25 @@ "url": "https://docs.litellm.ai/docs/providers/cloudflare_workers", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, - "audio_transcriptions": false, + "image_edits": false, + "audio_transcriptions": true, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "codestral": { @@ -569,17 +832,25 @@ "url": "https://docs.litellm.ai/docs/providers/codestral", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "cognition": { @@ -587,35 +858,51 @@ "url": "https://docs.litellm.ai/docs/providers/cognition", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "cohere": { "display_name": "Cohere (`cohere`)", "url": "https://docs.litellm.ai/docs/providers/cohere", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": true, "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": true, "ocr": true, - "a2a": true, - "interactions": true + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "cohere_chat": { @@ -623,53 +910,77 @@ "url": "https://docs.litellm.ai/docs/providers/cohere", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "cometapi": { "display_name": "CometAPI (`cometapi`)", "url": "https://docs.litellm.ai/docs/providers/cometapi", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": true, + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "compactifai": { "display_name": "CompactifAI (`compactifai`)", "url": "https://docs.litellm.ai/docs/providers/compactifai", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "coralbricks": { @@ -677,35 +988,51 @@ "url": "https://docs.litellm.ai/docs/providers/coralbricks", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false, - "interactions": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "cortecs": { "display_name": "Cortecs (`cortecs`)", "url": "https://docs.litellm.ai/docs/providers/cortecs", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, "a2a": false, - "interactions": false + "generateContent": false } }, "crusoe": { @@ -713,53 +1040,77 @@ "url": "https://docs.litellm.ai/docs/providers/crusoe", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "custom": { "display_name": "Custom (`custom`)", "url": "https://docs.litellm.ai/docs/providers/custom_llm_server", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "custom_openai": { "display_name": "Custom OpenAI (`custom_openai`)", "url": "https://docs.litellm.ai/docs/providers/openai_compatible", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, - "audio_transcriptions": true, - "audio_speech": true, - "moderations": true, - "batches": true, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "dashscope": { @@ -767,18 +1118,25 @@ "url": "https://docs.litellm.ai/docs/providers/dashscope", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, - "image_generations": false, + "image_generations": true, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": true, + "batches": false, + "messages": true, "interactions": true, - "video_generations": true + "systemone": false, + "a2a": true, + "generateContent": true } }, "qwencloud": { @@ -786,18 +1144,25 @@ "url": "https://docs.litellm.ai/docs/providers/qwencloud", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": true, + "text_completion": true, + "embeddings": false, "image_generations": true, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": true, "batches": false, - "rerank": true, - "a2a": true, + "messages": true, "interactions": true, - "video_generations": true + "systemone": false, + "a2a": true, + "generateContent": true } }, "qwen_ai_platform": { @@ -805,18 +1170,25 @@ "url": "https://docs.litellm.ai/docs/providers/qwencloud", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": true, + "text_completion": true, + "embeddings": false, "image_generations": true, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": true, "batches": false, - "rerank": true, - "a2a": true, + "messages": true, "interactions": true, - "video_generations": true + "systemone": false, + "a2a": true, + "generateContent": true } }, "databricks": { @@ -824,17 +1196,25 @@ "url": "https://docs.litellm.ai/docs/providers/databricks", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "dataforseo": { @@ -842,52 +1222,77 @@ "url": "https://docs.litellm.ai/docs/search/dataforseo", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "search": true + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "datarobot": { "display_name": "DataRobot (`datarobot`)", "url": "https://docs.litellm.ai/docs/providers/datarobot", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "deepgram": { "display_name": "Deepgram (`deepgram`)", "url": "https://docs.litellm.ai/docs/providers/deepgram", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": true, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "deepinfra": { @@ -895,17 +1300,25 @@ "url": "https://docs.litellm.ai/docs/providers/deepinfra", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "deepseek": { @@ -913,36 +1326,51 @@ "url": "https://docs.litellm.ai/docs/providers/deepseek", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, "interactions": true, - "search": true + "systemone": false, + "a2a": true, + "generateContent": true } }, "edenai": { "display_name": "Eden AI (`edenai`)", "url": "https://docs.litellm.ai/docs/providers/edenai", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": true, - "image_generations": true, - "audio_transcriptions": true, - "audio_speech": true, - "moderations": false, - "batches": false, + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, "interactions": false, - "video_generations": true + "systemone": false, + "a2a": false, + "generateContent": false } }, "duckduckgo": { @@ -950,16 +1378,25 @@ "url": "https://docs.litellm.ai/docs/search/duckduckgo", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "search": true + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "e2b": { @@ -967,15 +1404,25 @@ "url": "https://docs.litellm.ai/docs/providers/e2b", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, "sandbox": true } }, @@ -983,18 +1430,26 @@ "display_name": "ElevenLabs (`elevenlabs`)", "url": "https://docs.litellm.ai/docs/providers/elevenlabs", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, - "audio_transcriptions": false, + "image_edits": false, + "audio_transcriptions": true, "audio_speech": true, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "exa_ai": { @@ -1002,16 +1457,25 @@ "url": "https://docs.litellm.ai/docs/search/exa_ai", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "search": true + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "brave": { @@ -1019,34 +1483,51 @@ "url": "https://docs.litellm.ai/docs/search/brave", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "search": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "empower": { "display_name": "Empower (`empower`)", "url": "https://docs.litellm.ai/docs/providers/empower", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "fal_ai": { @@ -1054,17 +1535,25 @@ "url": "https://docs.litellm.ai/docs/providers/fal_ai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": true, + "image_edits": true, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": true, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "featherless_ai": { @@ -1072,17 +1561,25 @@ "url": "https://docs.litellm.ai/docs/providers/featherless_ai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "fireworks_ai": { @@ -1090,18 +1587,25 @@ "url": "https://docs.litellm.ai/docs/providers/fireworks_ai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, - "image_generations": false, - "audio_transcriptions": false, + "text_completion": true, + "embeddings": true, + "image_generations": true, + "image_edits": false, + "audio_transcriptions": true, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": true, - "a2a": true, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, "interactions": true, - "systemone": true + "systemone": false, + "a2a": true, + "generateContent": true } }, "firecrawl": { @@ -1109,16 +1613,25 @@ "url": "https://docs.litellm.ai/docs/search/firecrawl", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "search": true + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "fastcrw": { @@ -1126,16 +1639,25 @@ "url": "https://docs.litellm.ai/docs/search/fastcrw", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "search": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "linkup": { @@ -1143,16 +1665,25 @@ "url": "https://docs.litellm.ai/docs/search/linkup", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "search": true + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "friendliai": { @@ -1160,45 +1691,77 @@ "url": "https://docs.litellm.ai/docs/providers/friendliai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "galadriel": { "display_name": "Galadriel (`galadriel`)", "url": "https://docs.litellm.ai/docs/providers/galadriel", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "gdc": { "display_name": "Google Distributed Cloud (GDC)", "url": "https://docs.litellm.ai/docs/providers/gdc", "endpoints": { - "chat_completions": true, - "messages": false, + "chat_completions": false, "responses": false, - "embeddings": false + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "github_copilot": { @@ -1206,17 +1769,25 @@ "url": "https://docs.litellm.ai/docs/providers/github_copilot", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "chatgpt": { @@ -1224,35 +1795,51 @@ "url": "https://docs.litellm.ai/docs/providers/chatgpt", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false, - "interactions": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "github": { "display_name": "GitHub Models (`github`)", "url": "https://docs.litellm.ai/docs/providers/github", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "gmi": { @@ -1260,17 +1847,25 @@ "url": "https://docs.litellm.ai/docs/providers/gmi_cloud", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "vertex_ai": { @@ -1278,25 +1873,30 @@ "url": "https://docs.litellm.ai/docs/providers/vertex", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": true, "image_generations": true, - "audio_transcriptions": false, + "image_edits": true, + "audio_transcriptions": true, "audio_speech": true, - "moderations": false, - "batches": false, - "rerank": false, + "rerank": true, "ocr": true, - "a2a": true, + "search": false, + "moderations": false, + "realtime": true, + "video_generations": true, + "batches": true, + "messages": true, "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true, "vector_stores_search": true, "count_tokens": true, "fine_tuning": true, "rag_ingest": true, - "rag_query": true, - "generateContent": true, - "realtime": true + "rag_query": true } }, "gemini": { @@ -1304,22 +1904,28 @@ "url": "https://docs.litellm.ai/docs/providers/gemini", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, - "image_generations": false, - "audio_transcriptions": false, - "audio_speech": false, - "moderations": false, - "batches": false, + "text_completion": true, + "embeddings": true, + "image_generations": true, + "image_edits": true, + "audio_transcriptions": true, + "audio_speech": true, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": true, + "video_generations": true, + "batches": true, + "messages": true, "interactions": true, + "systemone": false, "a2a": true, + "generateContent": true, "vector_stores_search": true, "count_tokens": true, - "rag_ingest": true, - "realtime": true, - "generateContent": true + "rag_ingest": true } }, "gradient_ai": { @@ -1327,17 +1933,25 @@ "url": "https://docs.litellm.ai/docs/providers/gradient_ai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "groq": { @@ -1345,17 +1959,25 @@ "url": "https://docs.litellm.ai/docs/providers/groq", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, - "audio_transcriptions": false, - "audio_speech": false, - "moderations": false, - "batches": false, + "image_edits": false, + "audio_transcriptions": true, + "audio_speech": true, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "heroku": { @@ -1363,56 +1985,78 @@ "url": "https://docs.litellm.ai/docs/providers/heroku", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "hosted_vllm": { "display_name": "Hosted VLLM (`hosted_vllm`)", "url": "https://docs.litellm.ai/docs/providers/vllm", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": true, + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, - "batches": true, - "files": true, - "rerank": true, - "a2a": true, - "interactions": true, - "video_generations": true, - "systemone": true + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, + "files": true } }, "huggingface": { "display_name": "Huggingface (`huggingface`)", "url": "https://docs.litellm.ai/docs/providers/huggingface", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": true, + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": true, - "a2a": true, - "interactions": true + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "hyperbolic": { @@ -1420,17 +2064,25 @@ "url": "https://docs.litellm.ai/docs/providers/hyperbolic", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "watsonx": { @@ -1438,17 +2090,25 @@ "url": "https://docs.litellm.ai/docs/providers/watsonx", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": true, + "text_completion": true, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": true, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "inception": { @@ -1456,17 +2116,25 @@ "url": "https://docs.litellm.ai/docs/providers/inception", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "infinity": { @@ -1474,15 +2142,25 @@ "url": "https://docs.litellm.ai/docs/providers/infinity", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, - "embeddings": true, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "jina_ai": { @@ -1490,29 +2168,77 @@ "url": "https://docs.litellm.ai/docs/providers/jina_ai", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, - "embeddings": true, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": true, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "bespoke": { "display_name": "Bespoke Nimble (`bespoke`)", "url": "https://docs.litellm.ai/docs/auto_router/decision_classifiers", "endpoints": { - "systemone": true + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": true, + "a2a": false, + "generateContent": false } }, "laya": { "display_name": "Laya (`laya`)", "url": "https://docs.litellm.ai/docs/auto_router/decision_classifiers", "endpoints": { - "systemone": true + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": true, + "a2a": false, + "generateContent": false } }, "lambda_ai": { @@ -1520,17 +2246,25 @@ "url": "https://docs.litellm.ai/docs/providers/lambda_ai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "lemonade": { @@ -1538,17 +2272,25 @@ "url": "https://docs.litellm.ai/docs/providers/lemonade", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "libertai": { @@ -1556,88 +2298,129 @@ "url": "https://docs.litellm.ai/docs/providers/libertai", "endpoints": { "chat_completions": true, - "messages": true, - "responses": false, - "embeddings": false, + "responses": true, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "litellm_proxy": { "display_name": "LiteLLM Proxy (`litellm_proxy`)", "url": "https://docs.litellm.ai/docs/providers/litellm_proxy", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": true, - "image_generations": true, + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "llamafile": { "display_name": "Llamafile (`llamafile`)", "url": "https://docs.litellm.ai/docs/providers/llamafile", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "lm_studio": { "display_name": "LM Studio (`lm_studio`)", "url": "https://docs.litellm.ai/docs/providers/lm_studio", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "maritalk": { "display_name": "Maritalk (`maritalk`)", "url": "https://docs.litellm.ai/docs/providers/maritalk", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "meta_llama": { @@ -1645,17 +2428,25 @@ "url": "https://docs.litellm.ai/docs/providers/meta_llama", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "mistral": { @@ -1663,36 +2454,51 @@ "url": "https://docs.litellm.ai/docs/providers/mistral", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": true, "image_generations": false, - "audio_transcriptions": false, - "audio_speech": false, - "moderations": false, - "batches": true, + "image_edits": false, + "audio_transcriptions": true, + "audio_speech": true, "rerank": false, "ocr": true, + "search": false, + "moderations": true, + "realtime": false, + "video_generations": false, + "batches": true, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "modelscope": { "display_name": "ModelScope (`modelscope`)", "url": "https://docs.litellm.ai/docs/providers/modelscope", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, - "image_generations": true, + "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, "a2a": false, - "interactions": false + "generateContent": false } }, "moonshot": { @@ -1700,35 +2506,51 @@ "url": "https://docs.litellm.ai/docs/providers/moonshot", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "docker_model_runner": { "display_name": "Docker Model Runner (`docker_model_runner`)", "url": "https://docs.litellm.ai/docs/providers/docker_model_runner", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "morph": { @@ -1736,33 +2558,50 @@ "url": "https://docs.litellm.ai/docs/providers/morph", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "nanogpt": { "display_name": "NanoGPT (`nanogpt`)", "endpoints": { - "chat_completions": true, - "messages": false, + "chat_completions": false, "responses": false, - "embeddings": true, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "nebius": { @@ -1770,34 +2609,51 @@ "url": "https://docs.litellm.ai/docs/providers/nebius", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "neosantara": { "display_name": "Neosantara (`neosantara`)", "url": "https://docs.litellm.ai/docs/providers/neosantara", "endpoints": { - "chat_completions": true, - "messages": false, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "nlp_cloud": { @@ -1805,17 +2661,25 @@ "url": "https://docs.litellm.ai/docs/providers/nlp_cloud", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "novita": { @@ -1823,17 +2687,25 @@ "url": "https://novita.ai/models/llm?utm_source=github_litellm&utm_medium=github_readme&utm_campaign=github_link", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": true, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "nscale": { @@ -1841,35 +2713,51 @@ "url": "https://docs.litellm.ai/docs/providers/nscale", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, - "image_generations": false, + "image_generations": true, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "nvidia_nim": { "display_name": "Nvidia NIM (`nvidia_nim`)", "url": "https://docs.litellm.ai/docs/providers/nvidia_nim", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": true, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false, - "a2a": true, - "interactions": true + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "nvidia_riva": { @@ -1877,15 +2765,25 @@ "url": "https://docs.litellm.ai/docs/providers/nvidia_riva", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, - "audio_transcriptions": true, + "image_edits": false, + "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "oci": { @@ -1893,17 +2791,25 @@ "url": "https://docs.litellm.ai/docs/providers/oci", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "ollama": { @@ -1911,53 +2817,77 @@ "url": "https://docs.litellm.ai/docs/providers/ollama", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": true, + "text_completion": true, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "ollama_chat": { "display_name": "Ollama Chat (`ollama_chat`)", "url": "https://docs.litellm.ai/docs/providers/ollama", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "oobabooga": { "display_name": "Oobabooga (`oobabooga`)", "url": "https://docs.litellm.ai/docs/providers/openai_compatible", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, - "audio_transcriptions": true, - "audio_speech": true, - "moderations": true, - "batches": true, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "openai": { @@ -1965,19 +2895,27 @@ "url": "https://docs.litellm.ai/docs/providers/openai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": true, "image_generations": true, + "image_edits": true, "audio_transcriptions": true, "audio_speech": true, - "moderations": true, - "batches": true, "rerank": false, + "ocr": false, + "search": false, + "moderations": true, + "realtime": true, + "video_generations": true, + "batches": true, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true, "container": true, "compact": true, - "a2a": true, - "interactions": true, "vector_store_files": true, "vector_stores_create": true, "vector_stores_search": true, @@ -1986,9 +2924,7 @@ "fine_tuning": true, "image_variations": true, "rag_ingest": true, - "rag_query": true, - "realtime": true, - "text_completion": true + "rag_query": true } }, "opensandbox": { @@ -1996,15 +2932,25 @@ "url": "https://open-sandbox.ai/api/", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, "sandbox": true } }, @@ -2013,15 +2959,25 @@ "url": "https://docs.litellm.ai/docs/providers/openai_compatible", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, - "embeddings": true, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, "assistants": true } }, @@ -2029,18 +2985,26 @@ "display_name": "OpenRouter (`openrouter`)", "url": "https://docs.litellm.ai/docs/providers/openrouter", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": true, + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "ovhcloud": { @@ -2048,17 +3012,25 @@ "url": "https://docs.litellm.ai/docs/providers/ovhcloud", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, - "audio_transcriptions": true, + "image_edits": false, + "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "parallel_ai": { @@ -2066,33 +3038,51 @@ "url": "https://docs.litellm.ai/docs/search/parallel_ai", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "search": true + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "parasail": { "display_name": "Parasail (`parasail`)", "url": "https://docs.litellm.ai/docs/providers/parasail", "endpoints": { - "chat_completions": true, - "messages": false, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "perplexity": { @@ -2100,36 +3090,51 @@ "url": "https://docs.litellm.ai/docs/providers/perplexity", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "petals": { "display_name": "Petals (`petals`)", "url": "https://docs.litellm.ai/docs/providers/petals", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "sail": { @@ -2137,16 +3142,25 @@ "url": "https://docs.litellm.ai/docs/providers/sail", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "meta": { @@ -2154,16 +3168,25 @@ "url": "https://docs.litellm.ai/docs/providers/meta", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, - "image_generations": false, - "audio_transcriptions": false, + "image_generations": true, + "image_edits": true, + "audio_transcriptions": true, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": true, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "pinstripes": { @@ -2171,32 +3194,50 @@ "url": "https://docs.litellm.ai/docs/providers/pinstripes", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": true, + "text_completion": true, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "poe": { "display_name": "Poe (`poe`)", "endpoints": { - "chat_completions": true, - "messages": false, + "chat_completions": false, "responses": false, - "embeddings": true, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "publicai": { @@ -2204,17 +3245,25 @@ "url": "https://docs.litellm.ai/docs/providers/publicai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "darkbloom": { @@ -2222,34 +3271,51 @@ "url": "https://docs.litellm.ai/docs/providers/darkbloom", "endpoints": { "chat_completions": true, - "messages": false, - "responses": false, + "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "predibase": { "display_name": "Predibase (`predibase`)", "url": "https://docs.litellm.ai/docs/providers/predibase", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "prism": { @@ -2257,16 +3323,25 @@ "url": "https://docs.litellm.ai/docs/providers/prism", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "recraft": { @@ -2274,15 +3349,25 @@ "url": "https://docs.litellm.ai/docs/providers/recraft", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": true, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "reducto": { @@ -2290,16 +3375,25 @@ "url": "https://docs.litellm.ai/docs/providers/reducto", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "ocr": true + "ocr": true, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "replicate": { @@ -2307,17 +3401,25 @@ "url": "https://docs.litellm.ai/docs/providers/replicate", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "runwayml": { @@ -2325,34 +3427,51 @@ "url": "https://docs.litellm.ai/docs/providers/runwayml/videos", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": true, + "image_edits": false, "audio_transcriptions": false, "audio_speech": true, - "moderations": false, - "batches": false, "rerank": false, - "video_generations": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": true, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "sagemaker_chat": { "display_name": "Sagemaker Chat (`sagemaker_chat`)", "url": "https://docs.litellm.ai/docs/providers/aws_sagemaker", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "searxng": { @@ -2360,16 +3479,25 @@ "url": "https://docs.litellm.ai/docs/search/searxng", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "search": true + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "scaledown": { @@ -2377,17 +3505,25 @@ "url": "https://docs.litellm.ai/docs/providers/scaledown", "endpoints": { "chat_completions": true, - "messages": false, - "responses": false, + "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false, - "interactions": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "sambanova": { @@ -2395,35 +3531,51 @@ "url": "https://docs.litellm.ai/docs/providers/sambanova", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "sap": { "display_name": "SAP Generative AI Hub (`sap`)", "url": "https://docs.litellm.ai/docs/providers/sap", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "scaleway": { @@ -2431,17 +3583,25 @@ "url": "https://docs.litellm.ai/docs/providers/scaleway", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": true, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": true, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "scx-ai": { @@ -2449,16 +3609,25 @@ "url": "https://docs.litellm.ai/docs/providers/scx_ai", "endpoints": { "chat_completions": true, - "messages": false, - "responses": false, + "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "inferenceapis": { @@ -2466,17 +3635,25 @@ "url": "https://docs.litellm.ai/docs/providers/inferenceapis", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false, - "interactions": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "snowflake": { @@ -2484,17 +3661,25 @@ "url": "https://docs.litellm.ai/docs/providers/snowflake", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "soniox": { @@ -2502,31 +3687,50 @@ "url": "https://docs.litellm.ai/docs/providers/soniox", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": true, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "synthetic": { "display_name": "Synthetic (`synthetic`)", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": true, + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "tensormesh": { @@ -2534,17 +3738,25 @@ "url": "https://docs.litellm.ai/docs/providers/tensormesh", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false, - "text_completion": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "tencent": { @@ -2552,53 +3764,77 @@ "url": "https://docs.litellm.ai/docs/providers/tencent", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false, - "text_completion": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "text-completion-codestral": { "display_name": "Text Completion Codestral (`text-completion-codestral`)", "url": "https://docs.litellm.ai/docs/providers/codestral", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "text-completion-openai": { "display_name": "Text Completion OpenAI (`text-completion-openai`)", "url": "https://docs.litellm.ai/docs/providers/text_completion_openai", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": true, "embeddings": false, "image_generations": false, - "audio_transcriptions": true, - "audio_speech": true, - "moderations": true, - "batches": true, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "together_ai": { @@ -2606,23 +3842,51 @@ "url": "https://docs.litellm.ai/docs/providers/togetherai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": true, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "topaz": { "display_name": "Topaz (`topaz`)", "url": "https://docs.litellm.ai/docs/providers/topaz", "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, "image_variations": true } }, @@ -2630,78 +3894,260 @@ "display_name": "Nace (`nace`)", "url": "https://console.nace.ai/docs/drex", "endpoints": { - "systemone": true + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "typesafe": { "display_name": "TypeSafe (`typesafe`)", "url": "https://docs.typesafe.ai/models", "endpoints": { - "systemone": true + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "strands_decider": { "display_name": "Strands Decider (`strands_decider`)", "url": "https://docs.litellm.ai/docs/providers", "endpoints": { - "systemone": true + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "tavily": { "display_name": "Tavily (`tavily`)", "url": "https://docs.litellm.ai/docs/search/tavily", "endpoints": { - "search": true + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "serper": { "display_name": "Serper (`serper`)", "url": "https://docs.litellm.ai/docs/search/serper", "endpoints": { - "search": true + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "you_com": { "display_name": "You.com (`you_com`)", - "url": "https://docs.litellm.ai/docs/search/you_com" + "url": "https://docs.litellm.ai/docs/search/you_com", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } }, "apiserpent": { "display_name": "APISerpent (`apiserpent`)", "url": "https://docs.litellm.ai/docs/search/apiserpent", "endpoints": { - "search": true + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "tinyfish": { "display_name": "TinyFish (`tinyfish`)", "url": "https://docs.tinyfish.ai/search-api", "endpoints": { - "search": true + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "nimble": { "display_name": "Nimble (`nimble`)", "url": "https://docs.nimbleway.com/api-reference/search/search", "endpoints": { - "search": true + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "triton": { "display_name": "Triton (`triton`)", "url": "https://docs.litellm.ai/docs/providers/triton-inference-server", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "v0": { @@ -2709,17 +4155,25 @@ "url": "https://docs.litellm.ai/docs/providers/v0", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "vercel_ai_gateway": { @@ -2727,36 +4181,52 @@ "url": "https://docs.litellm.ai/docs/providers/vercel_ai_gateway", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "vllm": { "display_name": "VLLM (`vllm`)", "url": "https://docs.litellm.ai/docs/providers/vllm", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": true, + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, - "batches": true, - "files": true, - "rerank": true, - "a2a": true, - "interactions": true + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, + "files": true } }, "volcengine": { @@ -2764,18 +4234,25 @@ "url": "https://docs.litellm.ai/docs/providers/volcano", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": false, + "text_completion": true, + "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": true, + "batches": false, + "messages": true, "interactions": true, - "video_generations": true + "systemone": false, + "a2a": true, + "generateContent": true } }, "voyage": { @@ -2783,15 +4260,25 @@ "url": "https://docs.litellm.ai/docs/providers/voyage", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": true, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": true, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": true + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "wandb": { @@ -2799,35 +4286,51 @@ "url": "https://docs.litellm.ai/docs/providers/wandb_inference", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "watsonx_text": { "display_name": "Watsonx Text (`watsonx_text`)", "url": "https://docs.litellm.ai/docs/providers/watsonx", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "xai": { @@ -2835,18 +4338,25 @@ "url": "https://docs.litellm.ai/docs/providers/xai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, - "image_generations": false, - "audio_transcriptions": false, + "image_generations": true, + "image_edits": false, + "audio_transcriptions": true, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, + "ocr": false, + "search": false, + "moderations": false, + "realtime": true, + "video_generations": true, + "batches": false, + "messages": true, "interactions": true, - "realtime": true + "systemone": false, + "a2a": true, + "generateContent": true } }, "xinference": { @@ -2854,15 +4364,25 @@ "url": "https://docs.litellm.ai/docs/providers/xinference", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, - "embeddings": true, + "text_completion": false, + "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "zai": { @@ -2870,72 +4390,104 @@ "url": "https://docs.litellm.ai/docs/providers/zai", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, "a2a": true, - "interactions": true + "generateContent": true } }, "ragflow": { "display_name": "RAGFlow (`ragflow`)", "url": "https://docs.litellm.ai/docs/providers/ragflow", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "vector_stores_create": true, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, + "vector_stores_create": true } }, "cursor": { "display_name": "Cursor BYOK (`cursor`)", "url": "https://docs.litellm.ai/docs/providers/cursor", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "langgraph": { "display_name": "LangGraph (`langgraph`)", "url": "https://docs.litellm.ai/docs/providers/langgraph", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "microsoft_365_copilot": { @@ -2943,53 +4495,77 @@ "url": "https://docs.litellm.ai/docs/providers/microsoft_365_copilot", "endpoints": { "chat_completions": true, - "messages": false, - "responses": false, + "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false, - "interactions": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "langflow": { "display_name": "LangFlow (`langflow`)", "url": "https://docs.litellm.ai/docs/providers/langflow", "endpoints": { - "chat_completions": true, - "messages": false, + "chat_completions": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "vertex_ai/agent_engine": { "display_name": "Vertex AI Agent Engine (`vertex_ai/agent_engine`)", "url": "https://docs.litellm.ai/docs/providers/vertex_ai_agent_engine", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "pydantic_ai_agents": { @@ -2997,16 +4573,25 @@ "url": "https://docs.litellm.ai/docs/providers/pydantic_ai_agent", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "stability": { @@ -3014,34 +4599,51 @@ "url": "https://docs.litellm.ai/docs/providers/stability", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": true, "image_edits": true, "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "venice": { "display_name": "Venice.ai (`venice`)", "url": "https://docs.litellm.ai/docs/providers/venice", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "gigachat": { @@ -3049,22 +4651,77 @@ "url": "https://docs.litellm.ai/docs/providers/gigachat", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, - "embeddings": true + "text_completion": true, + "embeddings": true, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "google_pse": { "display_name": "Google PSE (`google_pse`)", "url": "https://docs.litellm.ai/docs/search/google_pse", "endpoints": { - "search": true + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "milvus": { "display_name": "Milvus (`milvus`)", "url": "https://docs.litellm.ai/docs/providers/milvus_vector_stores", "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, "vector_stores_search": true } }, @@ -3073,14 +4730,51 @@ "url": "https://docs.litellm.ai/docs/providers/minimax", "endpoints": { "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": true, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": true, + "batches": false, "messages": true, - "responses": true + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "pg_vector": { "display_name": "PG Vector (`pg_vector`)", "url": "https://docs.litellm.ai/docs/providers/pg_vector", "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, "vector_stores_search": true } }, @@ -3088,6 +4782,26 @@ "display_name": "MongoDB Atlas (`mongodb`)", "url": "https://docs.litellm.ai/docs/providers/mongodb_vector_stores", "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, "vector_stores_search": true } }, @@ -3095,6 +4809,26 @@ "display_name": "Valkey (`valkey`)", "url": "https://docs.litellm.ai/docs/providers/valkey_vector_stores", "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, "vector_stores_search": true } }, @@ -3102,9 +4836,26 @@ "display_name": "Helicone (`helicone`)", "url": "https://docs.litellm.ai/docs/providers/helicone", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "llamagate": { @@ -3112,8 +4863,25 @@ "url": "https://docs.litellm.ai/docs/providers/llamagate", "endpoints": { "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": true, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, "messages": true, - "responses": true + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "xiaomi_mimo": { @@ -3121,27 +4889,52 @@ "url": "https://docs.litellm.ai/docs/providers/xiaomi_mimo", "endpoints": { "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, "messages": true, - "responses": true + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "manus": { "display_name": "Manus (`manus`)", "url": "https://docs.litellm.ai/docs/providers/manus", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, - "files": true, "rerank": false, - "a2a": true, - "interactions": true + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false, + "files": true } }, "sarvam": { @@ -3149,8 +4942,25 @@ "url": "https://docs.litellm.ai/docs/providers/sarvam", "endpoints": { "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, "messages": true, - "responses": true + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "bedrock_mantle": { @@ -3158,16 +4968,25 @@ "url": "https://docs.litellm.ai/docs/providers/bedrock", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true } }, "searchapi": { @@ -3175,17 +4994,25 @@ "url": "https://docs.litellm.ai/docs/providers/searchapi", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "search": true, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "black_forest_labs": { @@ -3193,67 +5020,77 @@ "url": "https://docs.litellm.ai/docs/providers/black_forest_labs", "endpoints": { "chat_completions": false, - "messages": false, "responses": false, + "text_completion": false, "embeddings": false, "image_generations": true, "image_edits": true, "audio_transcriptions": false, "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "reka": { "display_name": "Reka (`reka`)", "url": "https://docs.litellm.ai/docs/providers/reka", "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false, - "interactions": false - } - }, - "charity_engine": { - "display_name": "Charity Engine (`charity_engine`)", - "url": "https://docs.litellm.ai/docs/providers/charity_engine", - "endpoints": { - "chat_completions": true, - "messages": true, - "responses": true, - "embeddings": false, - "image_generations": false, - "audio_transcriptions": false, - "audio_speech": false, + "ocr": false, + "search": false, "moderations": false, + "realtime": false, + "video_generations": false, "batches": false, - "rerank": false + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "empiriolabs": { "display_name": "EmpirioLabs (`empiriolabs`)", "url": "https://docs.litellm.ai/docs/providers/empiriolabs", "endpoints": { - "chat_completions": true, - "messages": false, - "responses": true, + "chat_completions": false, + "responses": false, + "text_completion": false, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } }, "openinfer": { @@ -3261,16 +5098,155 @@ "url": "https://docs.litellm.ai/docs/providers/openinfer", "endpoints": { "chat_completions": true, - "messages": true, "responses": true, + "text_completion": true, "embeddings": false, "image_generations": false, + "image_edits": false, "audio_transcriptions": false, "audio_speech": false, - "moderations": false, - "batches": false, "rerank": false, - "a2a": false + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true + } + }, + "agentcore": { + "display_name": "AgentCore (`agentcore`)", + "url": "https://docs.litellm.ai/docs/providers", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "anyscale": { + "display_name": "Anyscale (`anyscale`)", + "url": "https://docs.litellm.ai/docs/providers/anyscale", + "endpoints": { + "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true + } + }, + "bing_grounding": { + "display_name": "Bing Grounding (`bing_grounding`)", + "url": "https://docs.litellm.ai/docs/providers", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": true, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false + } + }, + "opencode_go": { + "display_name": "OpenCode Go (`opencode_go`)", + "url": "https://docs.litellm.ai/docs/providers/opencode_go", + "endpoints": { + "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true + } + }, + "transcribe": { + "display_name": "Transcribe (`transcribe`)", + "url": "https://docs.litellm.ai/docs/providers", + "endpoints": { + "chat_completions": false, + "responses": false, + "text_completion": false, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": true, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": false, + "interactions": false, + "systemone": false, + "a2a": false, + "generateContent": false } } }, diff --git a/pyproject.toml b/pyproject.toml index 817c50df90b..fc860a8fdf4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ name = "litellm" version = "1.108.0" description = "Library to easily interface with LLM API providers" readme = "README.md" -requires-python = ">=3.10, <3.15" +requires-python = ">=3.10, <3.16" license = "MIT" license-files = ["LICENSE"] authors = [ @@ -14,7 +14,7 @@ dependencies = [ # deps. Reproducibility for our Docker/CI comes from `uv.lock`. # When changing a floor, verify it installs + imports on every supported # Python with: `uv pip install --resolution=lowest-direct .` - "fastuuid>=0.14.0,<1.0", + "fastuuid>=0.14.0,<1.0; python_version < '3.15'", "filelock>=3.16.1,<4.0", "httpx[http2]>=0.28.0,<1.0", "openai>=2.20.0,<4.0.0", @@ -23,7 +23,8 @@ dependencies = [ "packaging>=24.0", "importlib-metadata>=8.0.0,<9.0", "tiktoken>=0.8.0,<1.0; python_version < '3.14'", - "tiktoken>=0.12.0,<1.0; python_version >= '3.14'", + "tiktoken>=0.12.0,<1.0; python_version == '3.14'", + "tiktoken>=0.14.0,<1.0; python_version >= '3.15'", "tokenizers>=0.21.0,<1.0", "huggingface-hub>=0.34.0,<2.0", "click>=8.0.0,<9.0", @@ -32,7 +33,8 @@ dependencies = [ "anyio>=4.14.0,<5.0", "async-timeout>=4.0.3,<6.0; python_version < '3.11'", "pydantic>=2.11.0,<3.0.0; python_version < '3.14'", - "pydantic>=2.12.0,<3.0.0; python_version >= '3.14'", + "pydantic>=2.12.0,<3.0.0; python_version == '3.14'", + "pydantic>=2.14.0,<3.0.0; python_version >= '3.15'", "pydantic-settings>=2.14.1,<3.0", "jsonschema>=4.0.0,<5.0", "boto3>=1.43.117,<2.0", @@ -55,17 +57,20 @@ Documentation = "https://docs.litellm.ai" proxy = [ "gunicorn>=23.0.0,<24.0", "uvicorn>=0.33.0,<1.0", - "granian>=2.7.4,<3.0", + "granian>=2.7.4,<3.0; python_version < '3.15'", + "granian>=2.8.0,<3.0; python_version >= '3.15'", "uvloop>=0.22.1,<1.0; sys_platform != 'win32'", "fastapi>=0.136.3,<1.0", "starlette>=1.0.1,<2.0", "backoff>=2.2.1,<3.0", "pyyaml>=6.0.3,<7.0", "rq>=2.7.0,<3.0", - "orjson>=3.11.6,<4.0", + "orjson>=3.11.6,<4.0; python_version < '3.15'", + "orjson>=3.12.0,<4.0; python_version >= '3.15'", # redis-py's C response parser. It arrives with redis (via rq) either way; naming # it here is what makes redis-py select _HiredisParser instead of the Python one. - "hiredis>=3.0.0,<4.0", + "hiredis>=3.0.0,<4.0; python_version < '3.15'", + "hiredis>=3.5.0,<4.0; python_version >= '3.15'", "apscheduler>=3.11.2,<4.0", "fastapi-sso>=0.19.0,<1.0", "PyJWT>=2.13.0,<3.0", @@ -210,8 +215,8 @@ dev = [ "tomli==2.4.1; python_version < '3.11'", "pytest-mock==3.15.1", "pytest-asyncio==1.3.0", - "psycopg==3.3.3", - "psycopg-binary==3.3.3", + "psycopg==3.3.6", + "psycopg-binary==3.3.6", "pytest-xdist==3.8.0", "requests-mock==1.12.1", "responses==0.26.0", @@ -372,21 +377,8 @@ required-version = ">=0.10.9" exclude-newer = "3 days" [tool.uv.exclude-newer-package] -# TODO: ryan, remove after 2026-10-23, once certifi 2026.10.19 (drops the compromised eMudhra root) clears the 3-day window -certifi = "2026-10-20T03:00:00Z" -# TODO(shrey): remove after 2026-10-25, once grpcio 1.84.1 (drops the compromised eMudhra roots from roots.pem) clears the 3-day window -grpcio = "2026-10-22T15:00:00Z" -# TODO(shrey): remove after 2026-10-24, once boto3/botocore 1.43.117 (drops the compromised eMudhra roots from cacert.pem) clear the 3-day window -boto3 = "2026-10-21T19:31:00Z" -botocore = "2026-10-21T19:31:00Z" # TODO: remove after 2026-10-25, once brotli 1.2.1 (CVE-2026-111497) clears the 3-day window brotli = "2026-10-22T14:01:00Z" -# TODO: ryan, remove after 2026-10-24, once mlflow 3.17.2 (GHSA-wqmh-qccw-pqwf) clears the 3-day window -mlflow = "2026-10-21T03:00:00Z" -mlflow-skinny = "2026-10-21T03:00:00Z" -mlflow-tracing = "2026-10-21T03:00:00Z" -# TODO: ryan, remove after 2026-10-25, once pypdf 6.21.2 (GHSA-6c7f-9265-g8fw) clears the 3-day window -pypdf = "2026-10-21T17:00:00Z" [tool.uv.sources] litellm-proxy-extras = { workspace = true } diff --git a/ruff-strict.toml b/ruff-strict.toml index 28102da3ccd..e9db4d95cc8 100644 --- a/ruff-strict.toml +++ b/ruff-strict.toml @@ -2,7 +2,7 @@ extend = "ruff.toml" [lint] preview = true -select = ["ANN", "ASYNC230", "B004", "B006", "B008", "B009", "B010", "B018", "B019", "B021", "B026", "B033", "BLE", "C401", "C404", "C405", "C408", "C414", "C419", "C901", "D419", "DTZ001", "DTZ003", "DTZ005", "DTZ006", "DTZ007", "DTZ011", "EXE001", "EXE002", "F401", "FURB136", "FURB168", "FURB188", "I001", "LOG015", "N999", "PERF102", "PERF401", "PERF402", "PERF403", "PIE790", "PIE800", "PIE804", "PIE810", "PLC0206", "PLC0208", "PLC0414", "PLR0124", "PLR0206", "PLR0402", "PLR1704", "PLR1711", "PLR1714", "PLR1730", "PLR2044", "PLW0127", "PLW0133", "PLW0602", "PLW0603", "PLW1508", "PLW1510", "PYI030", "PYI036", "PYI041", "PYI064", "RET501", "RET504", "RUF010", "RUF012", "RUF015", "RUF019", "RUF022", "RUF023", "RUF046", "RUF051", "RUF059", "RUF100", "S110", "S112", "SIM101", "SIM102", "SIM103", "SIM113", "SIM114", "SIM115", "SIM117", "SIM118", "SIM201", "SIM210", "SIM211", "SIM222", "SIM401", "TC004", "TC005", "TID251", "TRY002", "TRY004", "TRY201", "TRY203", "TRY300", "UP006", "UP007", "UP008", "UP012", "UP018", "UP024", "UP028", "UP031", "UP032", "UP034", "UP035", "UP036", "UP037", "UP045"] +select = ["ANN", "ASYNC230", "B004", "B006", "B008", "B009", "B010", "B018", "B019", "B021", "B026", "B033", "BLE", "C401", "C404", "C405", "C408", "C414", "C419", "C901", "D202", "D403", "D417", "D419", "DTZ001", "DTZ003", "DTZ005", "DTZ006", "DTZ007", "DTZ011", "EXE001", "EXE002", "F401", "FURB136", "FURB168", "FURB188", "I001", "LOG015", "N999", "PERF102", "PERF401", "PERF402", "PERF403", "PIE790", "PIE800", "PIE804", "PIE810", "PLC0206", "PLC0208", "PLC0414", "PLR0124", "PLR0206", "PLR0402", "PLR1704", "PLR1711", "PLR1714", "PLR1730", "PLR2044", "PLW0127", "PLW0133", "PLW0602", "PLW0603", "PLW1508", "PLW1510", "PYI030", "PYI036", "PYI041", "PYI064", "RET501", "RET504", "RUF010", "RUF012", "RUF015", "RUF019", "RUF022", "RUF023", "RUF046", "RUF051", "RUF059", "RUF100", "S110", "S112", "SIM101", "SIM102", "SIM103", "SIM113", "SIM114", "SIM115", "SIM117", "SIM118", "SIM201", "SIM210", "SIM211", "SIM222", "SIM401", "TC004", "TC005", "TID251", "TRY002", "TRY004", "TRY201", "TRY203", "TRY300", "UP006", "UP007", "UP008", "UP012", "UP018", "UP024", "UP028", "UP031", "UP032", "UP034", "UP035", "UP036", "UP037", "UP045"] extend-select = [] # Overrides the inherited list: rules this gate enforces itself must NOT be external here, # so this config's RUF100 flags their stale `# noqa` directives. What remains external is @@ -39,6 +39,9 @@ external = [ [lint.mccabe] max-complexity = 15 +[lint.pydocstyle] +convention = "google" + [lint.pylint] max-args = 5 @@ -68,7 +71,7 @@ max-args = 5 # directly, each with a `# noqa: TID251 # `. "litellm.responses.main.responses".msg = "Import litellm.responses.dispatch.responses so the call routes through dispatch." "litellm.responses.main.aresponses".msg = "Import litellm.responses.dispatch.aresponses so the call routes through dispatch." -"litellm.llms.anthropic.pass_through.messages.handler.anthropic_messages".msg = "Import litellm.messages.anthropic_messages so the call routes through dispatch." -"litellm.llms.anthropic.pass_through.messages.handler.anthropic_messages_handler".msg = "Import litellm.messages.anthropic_messages_handler so the call routes through dispatch." +"litellm.llms.anthropic.messages.native.handler.anthropic_messages".msg = "Import litellm.messages.anthropic_messages so the call routes through dispatch." +"litellm.llms.anthropic.messages.native.handler.anthropic_messages_handler".msg = "Import litellm.messages.anthropic_messages_handler so the call routes through dispatch." "litellm.main.completion".msg = "Import litellm.completion so the call routes through dispatch." "litellm.main.acompletion".msg = "Import litellm.acompletion so the call routes through dispatch." diff --git a/ruff.toml b/ruff.toml index 93396a723e7..715e5551fad 100644 --- a/ruff.toml +++ b/ruff.toml @@ -20,7 +20,7 @@ lint.external = [ # Family entries whose every strict rule graduated into extend-select above (FURB), and # standalone graduated codes (I001, RUF010, RUF022, RUF023, RUF051), are dropped so this # config's RUF100 polices their directives itself. - "ANN", "ASYNC230", "B", "C", "D419", "DTZ", "EXE", "LOG015", "N999", "PERF", + "ANN", "ASYNC230", "B", "C", "D202", "D403", "D417", "D419", "DTZ", "EXE", "LOG015", "N999", "PERF", "PIE", "PL", "PYI", "RET", "RUF012", "RUF015", "RUF019", "RUF046", "RUF059", "S110", "S112", "SIM", "TC", "TID251", "TRY", "UP", # Enforced by upstream litellm's ruff config, but not run in this repo's CI diff --git a/scripts/check_mcp_operation_boundary.py b/scripts/check_mcp_operation_boundary.py index b6c9dcefabf..65c92828fd8 100644 --- a/scripts/check_mcp_operation_boundary.py +++ b/scripts/check_mcp_operation_boundary.py @@ -3,7 +3,7 @@ import sys from pathlib import Path from typing import Final -PACKAGE: Final = Path("litellm/proxy/_experimental/mcp_server") +PACKAGE: Final = Path("litellm/proxy/mcp_server") LEGACY_ADAPTERS: Final = frozenset({"server.py", "legacy_callbacks.py", "mcp_context.py", "mcp_debug.py"}) CONFINED_NAMES: Final = frozenset( { diff --git a/scripts/check_mcp_sdk_install.py b/scripts/check_mcp_sdk_install.py index f5ab51b2f55..f2c2891bfd8 100644 --- a/scripts/check_mcp_sdk_install.py +++ b/scripts/check_mcp_sdk_install.py @@ -8,11 +8,11 @@ MINIMUM_MCP_VERSION: Final[tuple[int, int, int]] = (2, 2, 0) IMPORTED_MODULES: Final[tuple[str, ...]] = ( "litellm", - "litellm.experimental_mcp_client", - "litellm.experimental_mcp_client.client", - "litellm.proxy._experimental.mcp_server.server", - "litellm.proxy._experimental.mcp_server.mcp_server_manager", - "litellm.proxy._experimental.mcp_server.rest_endpoints", + "litellm.mcp_client", + "litellm.mcp_client.client", + "litellm.proxy.mcp_server.server", + "litellm.proxy.mcp_server.mcp_server_manager", + "litellm.proxy.mcp_server.rest_endpoints", ) @@ -50,7 +50,7 @@ def main() -> int: "path": "/mcp", "headers": [(b"mcp-protocol-version", b"2026-07-28")], } - mcp_server: Final = sys.modules["litellm.proxy._experimental.mcp_server.server"] + mcp_server: Final = sys.modules["litellm.proxy.mcp_server.server"] if mcp_server.unsupported_protocol_version(scope) != "2026-07-28": sys.stderr.write("unsupported_protocol_version accepted a modern-only version\n") return 1 diff --git a/scripts/generate_provider_endpoints_support.py b/scripts/generate_provider_endpoints_support.py new file mode 100644 index 00000000000..a2329ccded3 --- /dev/null +++ b/scripts/generate_provider_endpoints_support.py @@ -0,0 +1,248 @@ +from __future__ import annotations + +import argparse +import json +import sys +from collections.abc import Iterator, Mapping, Sequence +from itertools import chain +from pathlib import Path +from types import MappingProxyType +from typing import Final + +from pydantic import JsonValue, TypeAdapter + +ROOT: Final = Path(__file__).resolve().parents[1] +COST_MAP_PATH: Final = ROOT / "model_prices_and_context_window.json" +SOURCE_PATH: Final = ROOT / "provider_endpoints_support.json" +OUTPUT_PATHS: Final = ( + SOURCE_PATH, + ROOT / "litellm/provider_endpoints_support_backup.json", +) +JSON_OBJECT: Final = TypeAdapter(dict[str, JsonValue]) + +MODE_TO_FLAG: Final[Mapping[str, str]] = MappingProxyType( + { + "chat": "chat_completions", + "responses": "responses", + "completion": "text_completion", + "embedding": "embeddings", + "image_generation": "image_generations", + "image_edit": "image_edits", + "audio_transcription": "audio_transcriptions", + "audio_speech": "audio_speech", + "rerank": "rerank", + "ocr": "ocr", + "search": "search", + "moderation": "moderations", + "realtime": "realtime", + "video_generation": "video_generations", + } +) +SUPPORTED_ENDPOINT_TO_FLAG: Final[Mapping[str, str]] = MappingProxyType( + { + "/v1/chat/completions": "chat_completions", + "/v1/responses": "responses", + "/v1/completions": "text_completion", + "/v1/embeddings": "embeddings", + "/v1/images/generations": "image_generations", + "/v1/images/edits": "image_edits", + "/v1/audio/transcriptions": "audio_transcriptions", + "/v1/audio/speech": "audio_speech", + "/v1/ocr": "ocr", + "/v1/realtime": "realtime", + "/v1/videos": "video_generations", + "/v1/batch": "batches", + "/v1/messages": "messages", + "/v1beta/interactions": "interactions", + "/v1/systemone": "systemone", + } +) + + +def _json_object(value: JsonValue, name: str) -> Mapping[str, JsonValue]: + if not isinstance(value, dict): + raise ValueError(f"{name} must be a JSON object") + return value + + +def _provider_slug(provider: str) -> str: + if provider.startswith("vertex_ai-"): + return "vertex_ai" + if provider == "fireworks_ai-embedding-models": + return "fireworks_ai" + if provider == "bedrock_converse": + return "bedrock" + if provider == "text-completion-inception": + return "inception" + return provider + + +def _model_provider_slug(model: JsonValue) -> str | None: + if not isinstance(model, dict): + return None + provider: Final = model.get("litellm_provider") + if not isinstance(provider, str) or not provider: + return None + return _provider_slug(provider) + + +def _model_flags(model: Mapping[str, JsonValue]) -> tuple[str, ...]: + mode: Final = model.get("mode") + mode_flag: Final = MODE_TO_FLAG.get(mode) if isinstance(mode, str) else None + supported_endpoints: Final = model.get("supported_endpoints") + endpoint_flags: Final = ( + tuple( + SUPPORTED_ENDPOINT_TO_FLAG[endpoint] + for endpoint in supported_endpoints + if isinstance(endpoint, str) and endpoint in SUPPORTED_ENDPOINT_TO_FLAG + ) + if isinstance(supported_endpoints, list) + else () + ) + return ((mode_flag,) if mode_flag is not None else ()) + endpoint_flags + + +def _bridge_field(endpoint: JsonValue) -> str | None: + if not isinstance(endpoint, dict) or endpoint.get("bridges_to_chat_completion") is not True: + return None + provider_json_field: Final = endpoint.get("provider_json_field") + return provider_json_field if isinstance(provider_json_field, str) else None + + +def _bridged_fields(endpoints: Mapping[str, JsonValue]) -> tuple[str, ...]: + return tuple( + dict.fromkeys( + provider_json_field + for endpoint in endpoints.values() + if (provider_json_field := _bridge_field(endpoint)) is not None + ) + ) + + +def _derived_keys(bridged_fields: tuple[str, ...]) -> tuple[str, ...]: + return tuple(dict.fromkeys((*MODE_TO_FLAG.values(), *SUPPORTED_ENDPOINT_TO_FLAG.values(), *bridged_fields))) + + +def _model_evidence( + model: JsonValue, bridged_fields: tuple[str, ...] +) -> Iterator[tuple[str, str]]: + provider: Final = _model_provider_slug(model) + if provider is None or not isinstance(model, dict): + return + flags: Final = _model_flags(model) + yield from ((provider, flag) for flag in flags) + if "chat_completions" not in flags: + return + yield from ((provider, flag) for flag in bridged_fields) + + +def _provider_evidence( + cost_map: Mapping[str, JsonValue], bridged_fields: tuple[str, ...] +) -> Iterator[tuple[str, str]]: + return chain.from_iterable( + _model_evidence(model, bridged_fields) + for model_name, model in cost_map.items() + if model_name != "sample_spec" + ) + + +def _provider_slugs(cost_map: Mapping[str, JsonValue]) -> frozenset[str]: + return frozenset( + provider_slug + for model_name, model in cost_map.items() + if model_name != "sample_spec" and (provider_slug := _model_provider_slug(model)) is not None + ) + + +def _generated_provider( + slug: str, + value: JsonValue, + derived_keys: tuple[str, ...], + derived_key_set: frozenset[str], + evidence: frozenset[tuple[str, str]], +) -> dict[str, JsonValue]: + provider: Final = _json_object(value, f"provider {slug}") + current_flags_value: Final = provider.get("endpoints") + current_flags: Final = ( + _json_object(current_flags_value, f"provider {slug} endpoints") + if current_flags_value is not None + else {} + ) + derived_flags: Final = {flag: (slug, flag) in evidence for flag in derived_keys} + handwritten_flags: Final = { + flag: value for flag, value in current_flags.items() if flag not in derived_key_set + } + return { + **provider, + "endpoints": {**derived_flags, **handwritten_flags}, + } + + +def generate_provider_endpoints_support( + cost_map: Mapping[str, JsonValue], + current_json: Mapping[str, JsonValue], +) -> dict[str, JsonValue]: + current_providers: Final = _json_object( + current_json.get("providers"), "provider_endpoints_support providers" + ) + endpoints: Final = _json_object(current_json.get("endpoints"), "provider_endpoints_support endpoints") + bridged_fields: Final = _bridged_fields(endpoints) + derived_keys: Final = _derived_keys(bridged_fields) + derived_key_set: Final = frozenset(derived_keys) + provider_slugs: Final = _provider_slugs(cost_map) + missing_slugs: Final = tuple(sorted(provider_slugs - frozenset(current_providers))) + if missing_slugs: + raise ValueError(f"Cost map providers missing from provider_endpoints_support.json: {', '.join(missing_slugs)}") + evidence: Final = frozenset(_provider_evidence(cost_map, bridged_fields)) + providers: Final = { + slug: _generated_provider(slug, value, derived_keys, derived_key_set, evidence) + for slug, value in current_providers.items() + } + return {**current_json, "providers": providers} + + +def generate_files( + cost_map: Mapping[str, JsonValue], + current_json: Mapping[str, JsonValue], + output_paths: tuple[Path, ...], + check: bool, +) -> int: + generated: Final = generate_provider_endpoints_support(cost_map, current_json) + content: Final = json.dumps(generated, indent=2, ensure_ascii=False) + "\n" + stale_paths: Final = tuple( + path for path in output_paths if not path.exists() or path.read_text(encoding="utf-8") != content + ) + if check: + if not stale_paths: + return 0 + sys.stderr.write( + "provider endpoint support is stale in " + + ", ".join(str(path) for path in stale_paths) + + "\nRun `uv run --no-sync python scripts/generate_provider_endpoints_support.py` to regenerate it\n" + ) + return 1 + for path in output_paths: + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(content, encoding="utf-8") + return 0 + + +def main(argv: Sequence[str] | None = None, *, repo_root: Path = ROOT) -> int: + parser: Final = argparse.ArgumentParser(description="Generate provider endpoint support from the model cost map") + parser.add_argument("--check", action="store_true", help="fail if either generated file is stale") + args: Final = parser.parse_args(argv) + cost_map: Final = JSON_OBJECT.validate_json((repo_root / COST_MAP_PATH.name).read_bytes()) + current_json: Final = JSON_OBJECT.validate_json((repo_root / SOURCE_PATH.name).read_bytes()) + return generate_files( + cost_map, + current_json, + ( + repo_root / SOURCE_PATH.name, + repo_root / OUTPUT_PATHS[1].relative_to(ROOT), + ), + args.check, + ) + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/openapi_docs_gate.py b/scripts/openapi_docs_gate.py index a2a8fad78e9..5f5d1021c22 100755 --- a/scripts/openapi_docs_gate.py +++ b/scripts/openapi_docs_gate.py @@ -76,7 +76,10 @@ def parse_violations(out: str) -> tuple[Violation, ...]: def _check(root: Path, checker: Path) -> tuple[Violation, ...]: resolved: Final = root.resolve() - env: Final = {**os.environ, "PYTHONPATH": os.pathsep.join((str(resolved), os.environ.get("PYTHONPATH", "")))} + env: Final = { + **os.environ, + "PYTHONPATH": os.pathsep.join((str(resolved), str(resolved / "enterprise"), os.environ.get("PYTHONPATH", ""))), + } return parse_violations(_run([sys.executable, str(checker)], cwd=resolved, env=env)) diff --git a/scripts/pre_commit_lint.sh b/scripts/pre_commit_lint.sh index edb69f24e29..371884fb791 100755 --- a/scripts/pre_commit_lint.sh +++ b/scripts/pre_commit_lint.sh @@ -103,7 +103,7 @@ ui_prettier_pattern='^ui/litellm-dashboard/.*\.(js|jsx|ts|tsx|mjs|cjs|json|css|s ui_eslint_pattern='^ui/litellm-dashboard/.*\.(js|jsx|ts|tsx|mjs|cjs)$' litellm_py_files=$(scope_match "$litellm_py_pattern") -if [ -n "$(scope_match '^(litellm/proxy/_experimental/mcp_server/|scripts/check_mcp_operation_boundary\.py)')" ]; then +if [ -n "$(scope_match '^(litellm/proxy/mcp_server/|scripts/check_mcp_operation_boundary\.py)')" ]; then uv run --no-sync python scripts/check_mcp_operation_boundary.py || exit 1 fi e2e_py_files=$(scope_match "$e2e_py_pattern") diff --git a/scripts/sync_together_ai_models.py b/scripts/sync_together_ai_models.py deleted file mode 100644 index 12b128890f1..00000000000 --- a/scripts/sync_together_ai_models.py +++ /dev/null @@ -1,547 +0,0 @@ -"""Sync the together_ai entries of model_prices_and_context_window.json with Together's live serverless catalog. - -Pulls ``GET https://api.together.ai/v1/models?serverless`` plus the deprecations doc, maps API fields onto -registry fields, merges the reviewed capability rules below for everything the API cannot express, and diffs -the result against the registry. Dry run (the default) prints the diff summary and the generated PR body; -``--write`` applies the changes to the root cost map and its ``litellm/`` backup copy. - -Policy highlights: -- Prices arrive per 1M tokens with float artifacts and are normalized to clean per-token values. -- A registry entry absent from the serverless catalog is marked with ``deprecation_date`` from the docs - deprecation table, never deleted; absences with no docs date are surfaced for a human call. -- Availability comes from the API: a model the docs list as removed but the API still serves stays live, - with the conflict surfaced as a warning. -- Manually curated values the API cannot express (``metadata.successor``, ``max_output_tokens`` on existing - entries, capability flags no rule covers) are never overwritten; conflicts are surfaced instead. -""" - -import argparse -import json -import os -import re -import sys -from collections.abc import Mapping, Sequence -from dataclasses import dataclass, field -from pathlib import Path -from types import MappingProxyType -from typing import Final - -import httpx -from pydantic import BaseModel, TypeAdapter, ValidationError - -MODELS_URL: Final = "https://api.together.ai/v1/models?serverless" -DEPRECATIONS_URL: Final = "https://docs.together.ai/docs/deprecations.md" -PROVIDER: Final = "together_ai" -PREFIX: Final = "together_ai/" -SOURCE_URL: Final = "https://docs.together.ai/docs/serverless-models" -COST_MAP_RELPATHS: Final = ( - "model_prices_and_context_window.json", - "litellm/model_prices_and_context_window_backup.json", -) - -TYPE_TO_MODE: Final = MappingProxyType({"chat": "chat", "embedding": "embedding", "moderation": "chat"}) - - -class SyncError(RuntimeError): - pass - - -class CatalogPricing(BaseModel): - input: float - output: float - cached_input: float | None = None - - -class CatalogModel(BaseModel): - id: str - type: str - context_length: int | None = None - pricing: CatalogPricing - - -CATALOG_ADAPTER: Final = TypeAdapter(list[CatalogModel]) - -RegistryEntry = dict[str, object] -CostMap = dict[str, object] - - -@dataclass(frozen=True, slots=True) -class CapabilityRule: - model_id: str - fields: Mapping[str, bool | int] - provenance: str - - -def _rule(model_id: str, provenance: str, **fields: bool | int) -> CapabilityRule: - return CapabilityRule(model_id=model_id, fields=MappingProxyType(dict(fields)), provenance=provenance) - - -_TOOLS: Final = MappingProxyType( - { - "supports_function_calling": True, - "supports_parallel_function_calling": True, - "supports_response_schema": True, - "supports_tool_choice": True, - } -) - -CAPABILITY_RULES: Final = ( - _rule( - "MiniMaxAI/MiniMax-M3", - "reviewed for the LIT-5968 backfill against https://www.together.ai/models/minimax-m3", - **_TOOLS, - supports_reasoning=True, - supports_vision=True, - ), - _rule("Prism-ML/Ternary-Bonsai-27B", "reviewed for the LIT-5968 backfill; no tool or vision support documented"), - _rule( - "Qwen/Qwen3.5-9B", - "reviewed for the LIT-5968 backfill against https://www.together.ai/models/qwen3-5-9b", - **_TOOLS, - supports_reasoning=True, - supports_vision=True, - ), - _rule( - "Qwen/Qwen3.6-Plus", - "reviewed for the LIT-5968 backfill; hybrid reasoning model without a documented tools contract", - supports_reasoning=True, - ), - _rule("Qwen/Qwen3.7-Max", "reviewed for the LIT-5968 backfill; no tool or vision support documented"), - _rule("Qwen/Qwen3.7-Plus", "reviewed for the LIT-5968 backfill; no tool or vision support documented"), - _rule("Qwen/Qwen3.8-2.4T-A95B", "reviewed for the LIT-5968 backfill; no tool or vision support documented"), - _rule("arize-ai/qwen-2-1.5b-instruct", "reviewed for the LIT-5968 backfill; no tool or vision support documented"), - _rule( - "deepseek-ai/DeepSeek-V4-Flash-0731", - "reviewed for the LIT-5968 backfill against https://www.together.ai/models/deepseek-v4-flash", - **_TOOLS, - ), - _rule( - "deepseek-ai/DeepSeek-V4-Pro", - "reviewed for the LIT-5968 backfill against https://www.together.ai/models/deepseek-v4-pro", - **_TOOLS, - supports_reasoning=True, - ), - _rule( - "deepseek-ai/DeepSeek-V4-Pro-0813", - "reviewed for the LIT-5968 backfill against https://www.together.ai/models/deepseek-v4-pro", - **_TOOLS, - ), - _rule("google/gemma-3n-E4B-it", "reviewed for the LIT-5968 backfill; no tool or vision support documented"), - _rule( - "google/gemma-4-31B-it", - "reviewed for the LIT-5968 backfill against https://www.together.ai/models/gemma-4-31b-it", - **_TOOLS, - supports_vision=True, - ), - _rule( - "intfloat/multilingual-e5-large-instruct", - "embedding dims per https://huggingface.co/intfloat/multilingual-e5-large-instruct", - output_vector_size=1024, - ), - _rule( - "meta-llama/Llama-3.3-70B-Instruct-Turbo", - "reviewed for the LIT-5968 backfill against https://docs.together.ai/docs/function-calling", - **_TOOLS, - ), - _rule( - "meta-llama/Llama-Guard-4-12B", - "moderation classifier with a chat-shaped API; no tools per the LIT-5968 backfill review", - ), - _rule("meta-models/Muse-Glimmer-30B", "reviewed for the LIT-5968 backfill; no tool or vision support documented"), - _rule( - "moonshotai/Kimi-K2.7-Code", - "reviewed for the LIT-5968 backfill against https://www.together.ai/models/kimi-k2-7-code", - **_TOOLS, - supports_vision=True, - ), - _rule( - "moonshotai/Kimi-K3", - "reviewed for the LIT-5968 backfill against https://www.together.ai/models/kimi-k3", - **_TOOLS, - supports_reasoning=True, - supports_vision=True, - ), - _rule( - "nvidia/nemotron-3-ultra-550b-a55b", - "reviewed for the LIT-5968 backfill against https://www.together.ai/models/nemotron-3-ultra", - **_TOOLS, - supports_reasoning=True, - ), - _rule( - "openai/gpt-oss-120b", - "reviewed for the LIT-5968 backfill against https://www.together.ai/models/gpt-oss-120b", - **_TOOLS, - supports_reasoning=True, - ), - _rule( - "openai/gpt-oss-20b", - "reviewed for the LIT-5968 backfill against https://www.together.ai/models/gpt-oss-20b", - **_TOOLS, - ), - _rule("pearl-ai/gemma-4-31b-it", "reviewed for the LIT-5968 backfill; no tool or vision support documented"), - _rule( - "thinkingmachines/Inkling", - "reviewed for the LIT-5968 backfill against https://www.together.ai/models/inkling", - **_TOOLS, - ), - _rule("thinkingmachines/Inkling-Small", "reviewed for the LIT-5968 backfill; no tool or vision support documented"), - _rule( - "zai-org/GLM-5.2", - "reviewed for the LIT-5968 backfill against https://www.together.ai/models/glm-5-2;" - " 128K output ceiling per https://docs.z.ai/guides/llm/glm-5.2", - **_TOOLS, - supports_reasoning=True, - max_output_tokens=128000, - max_tokens=128000, - ), - _rule( - "zai-org/GLM-5.3-Flash", - "reviewed for LIT-6489 against https://www.together.ai/models/glm-5-3-flash;" - " 128K output ceiling per https://docs.z.ai/guides/llm/glm-5.3", - **_TOOLS, - supports_reasoning=True, - supports_vision=True, - max_output_tokens=128000, - max_tokens=128000, - ), -) - -RULES_BY_ID: Final = MappingProxyType({rule.model_id: rule for rule in CAPABILITY_RULES}) - - -@dataclass(frozen=True, slots=True) -class DeprecationDoc: - removal_dates: Mapping[str, str] - redirects: Mapping[str, str] - - -_REDIRECT_ROW: Final = re.compile(r"^\|\s*`([^`]+)`\s*\|\s*`([^`]+)`\s*\|") -_REMOVAL_ROW: Final = re.compile(r"^\|\s*(\d{4}-\d{2}-\d{2})\s*\|\s*`([^`]+)`\s*\|") - - -def _section(markdown: str, heading: str) -> str: - level: Final = heading.split(" ", 1)[0] - start: Final = markdown.find(f"\n{heading}\n") - if start < 0: - return "" - body: Final = markdown[start + 1 + len(heading) :] - next_heading: Final = re.search(rf"^{re.escape(level)} ", body, flags=re.MULTILINE) - return body[: next_heading.start()] if next_heading else body - - -def parse_deprecations(markdown: str) -> DeprecationDoc: - redirect_rows: Final = tuple( - m.groups() - for m in (_REDIRECT_ROW.match(line) for line in _section(markdown, "## Active model redirects").splitlines()) - if m - ) - inference: Final = _section(_section(markdown, "## Deprecation history"), "### Inference") - removal_rows: Final = tuple(m.groups() for m in (_REMOVAL_ROW.match(line) for line in inference.splitlines()) if m) - if not redirect_rows or not removal_rows: - raise SyncError( - "deprecations doc parsed to zero redirect or removal rows; the table format at " - f"{DEPRECATIONS_URL} changed and the parser needs updating" - ) - removal_dates: Final = {model: date for date, model in reversed(removal_rows)} - return DeprecationDoc( - removal_dates=MappingProxyType(dict(reversed(removal_dates.items()))), - redirects=MappingProxyType({original: target for original, target in redirect_rows}), - ) - - -def per_token(price_per_million: float) -> float: - return float(f"{price_per_million / 1e6:.6g}") - - -def _resolve_name(name: str, universe: frozenset[str]) -> str | None: - if name in universe: - return name - suffix_matches: Final = tuple(candidate for candidate in universe if candidate.endswith(f"/{name}")) - return suffix_matches[0] if len(suffix_matches) == 1 else None - - -def resolve_successor(model_id: str, doc: DeprecationDoc, live_ids: frozenset[str]) -> str | None: - canonical: Final = live_ids | frozenset(doc.removal_dates) - redirects: Final = { - (_resolve_name(raw_source, canonical) or raw_source): (_resolve_name(raw_target, canonical) or raw_target) - for raw_source, raw_target in doc.redirects.items() - } - seen: Final = set() - current = model_id # rebind-ok: walks the redirect chain - while current in redirects and current not in seen: - seen.add(current) - current = redirects[current] # rebind-ok: walks the redirect chain - return current if current != model_id and current in live_ids else None - - -@dataclass(frozen=True, slots=True) -class SyncOutcome: - cost_map: CostMap - added: tuple[str, ...] = () - updated: tuple[str, ...] = () - deprecated: tuple[str, ...] = () - reappeared: tuple[str, ...] = () - warnings: tuple[str, ...] = () - skipped_types: Mapping[str, int] = field(default_factory=dict) - - @property - def has_changes(self) -> bool: - return bool(self.added or self.updated or self.deprecated or self.reappeared) - - -def _api_fields(model: CatalogModel) -> RegistryEntry: - cached: Final = model.pricing.cached_input - return { - "input_cost_per_token": per_token(model.pricing.input), - "output_cost_per_token": per_token(model.pricing.output), - **({"cache_read_input_token_cost": per_token(cached), "supports_prompt_caching": True} if cached else {}), - **({"max_input_tokens": model.context_length} if model.context_length is not None else {}), - } - - -def _new_entry(model: CatalogModel, mode: str) -> RegistryEntry: - rule: Final = RULES_BY_ID.get(model.id) - legacy_ceiling: Final = {} if model.context_length is None else {"max_tokens": model.context_length} - merged: Final = { - **_api_fields(model), - **legacy_ceiling, - "litellm_provider": PROVIDER, - "mode": mode, - "source": SOURCE_URL, - **(dict(rule.fields) if rule else {}), - } - return dict(sorted(merged.items())) - - -def _updated_entry(entry: RegistryEntry, model: CatalogModel) -> tuple[RegistryEntry, tuple[str, ...]]: - rule: Final = RULES_BY_ID.get(model.id) - desired: Final = {**_api_fields(model), **(dict(rule.fields) if rule else {})} - dropped: Final = () if model.pricing.cached_input else ("cache_read_input_token_cost", "supports_prompt_caching") - changes: Final = tuple( - f"{name}: {entry.get(name)!r} -> {value!r}" for name, value in desired.items() if entry.get(name) != value - ) + tuple( - f"{name}: {entry[name]!r} removed (no longer in the catalog pricing)" for name in dropped if name in entry - ) - merged: Final = {name: value for name, value in {**entry, **desired}.items() if name not in dropped} - return dict(sorted(merged.items())), changes - - -def _with_new_keys_in_block(original: CostMap, result: CostMap, new_keys: Sequence[str]) -> CostMap: - provider_keys: Final = tuple(key for key in original if key.startswith(PREFIX)) - if not new_keys or not provider_keys: - return result - block_end: Final = provider_keys[-1] - return { - key: value - for existing in original - for key, value in ( - (existing, result[existing]), - *((new, result[new]) for new in sorted(new_keys) if existing == block_end), - ) - } - - -def compute_sync(cost_map: CostMap, catalog: Sequence[CatalogModel], doc: DeprecationDoc) -> SyncOutcome: - live_ids: Final = frozenset(model.id for model in catalog) - token_models: Final = {model.id: model for model in catalog if model.type in TYPE_TO_MODE} - skipped: Final = { - model.type: sum(1 for m in catalog if m.type == model.type) - for model in catalog - if model.type not in TYPE_TO_MODE - } - registry_ids: Final = {key.removeprefix(PREFIX): key for key in cost_map if key.startswith(PREFIX)} - - added: Final[list[str]] = [] - updated: Final[list[str]] = [] - deprecated: Final[list[str]] = [] - reappeared: Final[list[str]] = [] - warnings: Final[list[str]] = [] - result: Final[CostMap] = dict(cost_map) - - for model_id, model in sorted(token_models.items()): - mode: Final = TYPE_TO_MODE[model.type] - key: Final = f"{PREFIX}{model_id}" - if model_id in doc.removal_dates: - warnings.append( - f"`{key}` is listed as removed on {doc.removal_dates[model_id]} in the docs but the serverless " - "catalog still serves it; availability kept from the API" - ) - entry = result.get(key) - if not isinstance(entry, dict): - result[key] = _new_entry(model, mode) - added.append(key) - if model.type == "chat" and model_id not in RULES_BY_ID: - warnings.append( - f"`{key}` added without a capability rule; review its tools/vision/reasoning support and add one" - ) - continue - if entry.get("mode") != mode: - warnings.append( - f"`{key}` has curated mode {entry.get('mode')!r} but the catalog maps to {mode!r}; left unchanged" - ) - new_entry, changes = _updated_entry(entry, model) - if "deprecation_date" in new_entry: - new_entry.pop("deprecation_date") - reappeared.append(key) - if changes: - updated.append(f"{key}: " + "; ".join(changes)) - if changes or key in reappeared: - result[key] = new_entry - - for model_id, key in sorted(registry_ids.items()): - if model_id in token_models: - continue - entry = result.get(key) - if not isinstance(entry, dict): - continue - removal_date: Final = doc.removal_dates.get(model_id) - successor: Final = resolve_successor(model_id, doc, live_ids) - metadata = entry.get("metadata") - curated_successor: Final = metadata.get("successor") if isinstance(metadata, dict) else None - new_entry = dict(entry) - if removal_date is not None and entry.get("deprecation_date") != removal_date: - if "deprecation_date" in entry: - warnings.append( - f"`{key}` has curated deprecation_date {entry.get('deprecation_date')!r} but the docs list " - f"{removal_date!r}; left unchanged" - ) - else: - new_entry["deprecation_date"] = removal_date - if removal_date is None and "deprecation_date" not in entry: - warnings.append( - f"`{key}` is absent from the serverless catalog with no removal date in the docs; " - "needs a human deprecation call" - ) - if successor is not None: - desired_successor: Final = f"{PREFIX}{successor}" - if curated_successor is None: - new_entry["metadata"] = dict( - sorted({**(metadata if isinstance(metadata, dict) else {}), "successor": desired_successor}.items()) - ) - elif curated_successor != desired_successor: - warnings.append( - f"`{key}` has curated successor {curated_successor!r} but the docs redirects resolve to " - f"{desired_successor!r}; left unchanged" - ) - if new_entry != entry: - result[key] = dict(sorted(new_entry.items())) - deprecated.append(f"{key}: " + ", ".join(sorted(set(new_entry) - set(entry)) or ["updated"])) - - return SyncOutcome( - cost_map=_with_new_keys_in_block(cost_map, result, tuple(added)), - added=tuple(added), - updated=tuple(updated), - deprecated=tuple(deprecated), - reappeared=tuple(reappeared), - warnings=tuple(warnings), - skipped_types=MappingProxyType(skipped), - ) - - -def _section_block(title: str, lines: Sequence[str], backtick: bool) -> str: - bullets: Final = "\n".join(f"- `{line}`" if backtick else f"- {line}" for line in lines) or "- none" - return f"### {title} ({len(lines)})\n{bullets}\n" - - -def render_pr_body(outcome: SyncOutcome) -> str: - skipped: Final = ", ".join(f"{kind} ({count})" for kind, count in sorted(outcome.skipped_types.items())) or "none" - return ( - "Automated daily sync of the together_ai entries in model_prices_and_context_window.json against " - f"`GET {MODELS_URL}` and {DEPRECATIONS_URL} by scripts/sync_together_ai_models.py.\n" - "\n" - f"{_section_block('Added', outcome.added, backtick=True)}" - "\n" - f"{_section_block('Updated', outcome.updated, backtick=True)}" - "\n" - f"{_section_block('Marked deprecated', outcome.deprecated, backtick=True)}" - "\n" - f"{_section_block('Returned to the catalog', outcome.reappeared, backtick=True)}" - "\n" - f"{_section_block('Warnings needing a human call', outcome.warnings, backtick=False)}" - "\n" - f"Catalog model types outside the sync's token-pricing scope, skipped: {skipped}\n" - ) - - -def render_summary(outcome: SyncOutcome) -> str: - return ( - f"added={len(outcome.added)} updated={len(outcome.updated)} deprecated={len(outcome.deprecated)} " - f"reappeared={len(outcome.reappeared)} warnings={len(outcome.warnings)}" - ) - - -def load_catalog(raw: bytes) -> list[CatalogModel]: - parsed: Final = json.loads(raw) - entries: Final = parsed.get("data") if isinstance(parsed, dict) else parsed - try: - catalog: Final = CATALOG_ADAPTER.validate_python(entries) - except ValidationError as error: - raise SyncError(f"the catalog response no longer matches the expected shape: {error}") from error - if not any(model.type in TYPE_TO_MODE for model in catalog): - raise SyncError( - "the catalog response contains no token-priced models; refusing to mark the whole registry deprecated" - ) - return catalog - - -def _fetch(url: str, headers: Mapping[str, str]) -> bytes: - response: Final = httpx.get(url, headers=dict(headers), timeout=30, follow_redirects=True) - if response.status_code != 200: - raise SyncError(f"GET {url} returned {response.status_code}") - return response.content - - -def _serialize(cost_map: CostMap) -> str: - return json.dumps(cost_map, indent=4, ensure_ascii=False) + "\n" - - -def main(argv: Sequence[str]) -> int: - parser: Final = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--write", action="store_true", help="apply the sync to the cost map files (default: dry run)") - parser.add_argument("--models-json", type=Path, help="recorded catalog response to use instead of the live API") - parser.add_argument( - "--deprecations-md", type=Path, help="recorded deprecations doc to use instead of the live docs" - ) - parser.add_argument("--pr-body-file", type=Path, help="write the generated PR body to this path") - parser.add_argument("--repo-root", type=Path, default=Path(__file__).resolve().parent.parent) - args: Final = parser.parse_args(argv) - - if args.models_json is not None: - catalog_raw: Final = args.models_json.read_bytes() - else: - api_key: Final = os.environ.get("TOGETHER_API_KEY") - if not api_key: - raise SyncError("TOGETHER_API_KEY is not set and --models-json was not given") - catalog_raw = _fetch(MODELS_URL, {"Authorization": f"Bearer {api_key}"}) # rebind-ok: branch-dependent source - catalog: Final = load_catalog(catalog_raw) - markdown: Final = ( - args.deprecations_md.read_text() if args.deprecations_md is not None else _fetch(DEPRECATIONS_URL, {}).decode() - ) - doc: Final = parse_deprecations(markdown) - - cost_map_path: Final = args.repo_root / COST_MAP_RELPATHS[0] - cost_map: Final = json.loads(cost_map_path.read_text()) - outcome: Final = compute_sync(cost_map, catalog, doc) - body: Final = render_pr_body(outcome) - - if args.pr_body_file is not None: - args.pr_body_file.write_text(body) - if args.write and outcome.has_changes: - for relpath in COST_MAP_RELPATHS: - (args.repo_root / relpath).write_text(_serialize(outcome.cost_map)) - print(render_summary(outcome)) - print() - print(body) - if not args.write: - print("dry run: no files were touched") - elif not outcome.has_changes: - print("registry already in sync: no files were touched") - return 0 - - -if __name__ == "__main__": - try: - raise SystemExit(main(sys.argv[1:])) - except SyncError as error: - print(f"SYNC FAILED: {error}", file=sys.stderr) - raise SystemExit(1) from error diff --git a/tests/base_sdk_tests/check_base_sdk_install.py b/tests/base_sdk_tests/check_base_sdk_install.py index 4abd71e39a6..e546549d25f 100644 --- a/tests/base_sdk_tests/check_base_sdk_install.py +++ b/tests/base_sdk_tests/check_base_sdk_install.py @@ -127,7 +127,7 @@ def check_completion_with_function_tool() -> str: def check_mcp_install_guidance() -> str: try: - import litellm.experimental_mcp_client + import litellm.mcp_client except ImportError as error: _require("pip install 'litellm[mcp]'" in str(error), f"missing MCP installation guidance: {error}") _require(isinstance(error.__cause__, ModuleNotFoundError), "original missing-dependency cause was lost") @@ -174,8 +174,8 @@ def check_token_counter() -> str: def check_tokenizer_dependencies() -> str: import litellm - from litellm.rust_bridge import tokenizer from litellm.litellm_core_utils.tokenizer import HuggingFace, HuggingFaceTokenizer, Tokenizer + from litellm.rust_bridge import tokenizer from litellm.utils import claude_json_str _require(isinstance(litellm.encoding, Tokenizer), "runtime alias rejects the default encoding") diff --git a/tests/benchmarks/test_mcp_benchmarks.py b/tests/benchmarks/test_mcp_benchmarks.py index 7e23ab1b4f5..d4464d803cf 100644 --- a/tests/benchmarks/test_mcp_benchmarks.py +++ b/tests/benchmarks/test_mcp_benchmarks.py @@ -10,11 +10,11 @@ request. Both are pure-CPU and deterministic. import pytest from mcp.types import Tool as MCPTool -from litellm.experimental_mcp_client.tools import ( +from litellm.mcp_client.tools import ( transform_mcp_tool_to_openai_tool, transform_openai_tool_call_request_to_mcp_tool_call_request, ) -from litellm.proxy._experimental.mcp_server.utils import ( +from litellm.proxy.mcp_server.utils import ( add_server_prefix_to_name, split_server_prefix_from_name, ) diff --git a/tests/code_coverage_tests/ensure_async_clients_test.py b/tests/code_coverage_tests/ensure_async_clients_test.py index 93ae2e2837b..f4922a11806 100644 --- a/tests/code_coverage_tests/ensure_async_clients_test.py +++ b/tests/code_coverage_tests/ensure_async_clients_test.py @@ -17,7 +17,7 @@ ALLOWED_FILES = [ "../../litellm/llms/base.py", "../../litellm/llms/custom_httpx/httpx_handler.py", "../../litellm/llms/openai/common_utils.py", - "../../litellm/experimental_mcp_client/client.py", + "../../litellm/mcp_client/client.py", # when running on ci/cd "./litellm/__init__.py", "./litellm/llms/custom_httpx/http_handler.py", @@ -27,7 +27,7 @@ ALLOWED_FILES = [ "./litellm/llms/base.py", "./litellm/llms/custom_httpx/httpx_handler.py", "./litellm/llms/openai/common_utils.py", - "./litellm/experimental_mcp_client/client.py", + "./litellm/mcp_client/client.py", ] warning_msg = "this is a serious violation that can impact latency. Creating Async clients per request can add +500ms per request" diff --git a/tests/code_coverage_tests/recursive_detector.py b/tests/code_coverage_tests/recursive_detector.py index 7610d602fff..a5bb5e0b340 100644 --- a/tests/code_coverage_tests/recursive_detector.py +++ b/tests/code_coverage_tests/recursive_detector.py @@ -42,7 +42,7 @@ IGNORE_FUNCTIONS = [ "contains_encrypted_marker", # max depth set. "_rotate_guardrail_row", # bounded by attempts_left. "_delete_nested_value_custom", # max depth set (bounded by number of path segments). - "filter_exceptions_from_params", # max depth set (default 20) to prevent infinite recursion. + "_filter_exceptions_from_params", # max depth set (default 20) to prevent infinite recursion. "__getattr__", # lazy loading pattern in litellm/__init__.py with proper caching to prevent infinite recursion. "_validate_inheritance_chain", # max depth set (default 100) to prevent infinite recursion in policy inheritance validation. "_basic_json_schema_validate", # max depth set. diff --git a/tests/code_coverage_tests/router_code_coverage.py b/tests/code_coverage_tests/router_code_coverage.py index af2f386a362..853b10ad97b 100644 --- a/tests/code_coverage_tests/router_code_coverage.py +++ b/tests/code_coverage_tests/router_code_coverage.py @@ -138,6 +138,9 @@ ignored_function_names = [ "_pre_call_check_requested_chat_params", # Tested through the unsupported-param pre-call check tests in test_router.py "_deployment_supports_param", # Tested through the deployment-capability pre-call check tests in test_router.py "_capability_model_and_provider", # Tested through the authenticating-provider pre-call check test in test_router.py + "_route_capability_pin", # Exercised through Decisions routing tests in test_router.py + "_deployment_serves_route", # Exercised through mixed-group Decisions tests in test_router.py + "_without_deployments_that_cannot_serve_route", # Exercised through Decisions routing tests in test_router.py "_exact_base_model_max_input_tokens", # Tested through get_router_model_info in test_router_model_cost_isolation.py "_base_model_widened_window", # Tested through get_router_model_info in test_router_model_cost_isolation.py "_provider_model_id", # Tested through get_router_model_info in test_router_model_cost_isolation.py @@ -168,6 +171,7 @@ ignored_function_names = [ "_deployment_field", # Read by is_batch_capable, tested through the mixed-group tests in test_router.py "_deployment_provider", # Read by without_deployments_that_cannot_batch, tested through the mixed-group tests in test_router.py "_cannot_run_batches", # Tested through the Azure and OpenAI mixed-group acreate_batch tests in test_router.py + "_team_deployments_named", # Tested through the team lookups in the concurrent delete tests in test_router.py ] diff --git a/tests/code_coverage_tests/test_generate_provider_endpoints_support.py b/tests/code_coverage_tests/test_generate_provider_endpoints_support.py new file mode 100644 index 00000000000..c2ec6f56c3a --- /dev/null +++ b/tests/code_coverage_tests/test_generate_provider_endpoints_support.py @@ -0,0 +1,179 @@ +import json +from collections.abc import Mapping +from pathlib import Path +from typing import Final + +import pytest +from pydantic import JsonValue + +from scripts.generate_provider_endpoints_support import ( + generate_provider_endpoints_support, + main, +) + +ENDPOINTS: Final = { + "a2a": {"provider_json_field": "a2a", "bridges_to_chat_completion": True}, + "messages": {"provider_json_field": "messages", "bridges_to_chat_completion": True}, + "responses": {"provider_json_field": "responses", "bridges_to_chat_completion": True}, + "generateContent": {"provider_json_field": "generateContent", "bridges_to_chat_completion": True}, + "text_completion": {"provider_json_field": "text_completion", "bridges_to_chat_completion": True}, + "count_tokens": {"provider_json_field": "count_tokens"}, +} + + +def _current_json(providers: Mapping[str, JsonValue]) -> dict[str, JsonValue]: + return { + "_comment": "retained", + "_schema": {"version": 1}, + "providers": dict(providers), + "endpoints": ENDPOINTS, + } + + +def _provider(flags: Mapping[str, JsonValue] | None = None) -> dict[str, JsonValue]: + return { + "display_name": "Example (`example`)", + "url": "https://docs.litellm.ai/docs/providers/example", + "endpoints": dict(flags or {}), + } + + +def _flags(generated: Mapping[str, JsonValue], slug: str) -> Mapping[str, JsonValue]: + providers: Final = generated["providers"] + assert isinstance(providers, dict) + provider: Final = providers[slug] + assert isinstance(provider, dict) + flags: Final = provider["endpoints"] + assert isinstance(flags, dict) + return flags + + +def test_mode_derives_chat_flag() -> None: + cost_map: Final = {"example/model": {"litellm_provider": "example", "mode": "chat"}} + current_json: Final = _current_json({"example": _provider()}) + + generated: Final = generate_provider_endpoints_support(cost_map, current_json) + + assert _flags(generated, "example")["chat_completions"] is True + + +def test_supported_endpoint_derives_embedding_flag() -> None: + cost_map: Final = { + "example/model": { + "litellm_provider": "example", + "mode": "completion", + "supported_endpoints": ["/v1/embeddings"], + } + } + current_json: Final = _current_json({"example": _provider()}) + + generated: Final = generate_provider_endpoints_support(cost_map, current_json) + + assert _flags(generated, "example")["embeddings"] is True + + +def test_chat_models_enable_bridge_flags_but_other_models_do_not() -> None: + cost_map: Final = { + "example/chat": {"litellm_provider": "has_chat", "mode": "chat"}, + "example/endpoint-chat": { + "litellm_provider": "endpoint_chat", + "mode": "image_generation", + "supported_endpoints": ["/v1/chat/completions"], + }, + "example/image": {"litellm_provider": "no_chat", "mode": "image_generation"}, + } + current_json: Final = _current_json( + { + "has_chat": _provider(), + "endpoint_chat": _provider(), + "no_chat": _provider(), + } + ) + + generated: Final = generate_provider_endpoints_support(cost_map, current_json) + + assert _flags(generated, "has_chat")["a2a"] is True + assert _flags(generated, "has_chat")["generateContent"] is True + assert _flags(generated, "endpoint_chat")["a2a"] is True + assert _flags(generated, "no_chat")["a2a"] is False + assert _flags(generated, "no_chat")["generateContent"] is False + + +def test_unbacked_derived_flags_reset_and_handwritten_flags_remain() -> None: + cost_map: Final = {"example/model": {"litellm_provider": "example", "mode": "image_generation"}} + current_json: Final = _current_json( + { + "example": _provider({"responses": True, "count_tokens": True, "files": False}), + "without_models": _provider({"responses": True}), + } + ) + + generated: Final = generate_provider_endpoints_support(cost_map, current_json) + flags: Final = _flags(generated, "example") + + assert flags["responses"] is False + assert flags["count_tokens"] is True + assert flags["files"] is False + assert _flags(generated, "without_models")["chat_completions"] is False + + +def test_provider_aliases_share_their_mapped_slugs() -> None: + cost_map: Final = { + "vertex/model-a": {"litellm_provider": "vertex_ai-chat", "mode": "chat"}, + "vertex/model-b": {"litellm_provider": "vertex_ai-embedding", "mode": "embedding"}, + "bedrock/model": {"litellm_provider": "bedrock_converse", "mode": "responses"}, + } + current_json: Final = _current_json({"vertex_ai": _provider(), "bedrock": _provider()}) + + generated: Final = generate_provider_endpoints_support(cost_map, current_json) + + assert _flags(generated, "vertex_ai")["chat_completions"] is True + assert _flags(generated, "vertex_ai")["embeddings"] is True + assert _flags(generated, "bedrock")["responses"] is True + + +def test_cost_map_provider_without_file_entry_is_an_error() -> None: + cost_map: Final = {"example/model": {"litellm_provider": "missing_provider", "mode": "chat"}} + current_json: Final = _current_json({"example": _provider()}) + + with pytest.raises(ValueError, match="missing_provider"): + generate_provider_endpoints_support(cost_map, current_json) + + +def test_check_reports_stale_output_without_writing(tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None: + cost_map: Final = {"example/model": {"litellm_provider": "example", "mode": "chat"}} + current_json: Final = _current_json({"example": _provider()}) + (tmp_path / "model_prices_and_context_window.json").write_text(json.dumps(cost_map), encoding="utf-8") + source_path: Final = tmp_path / "provider_endpoints_support.json" + source_content: Final = json.dumps(current_json) + source_path.write_text(source_content, encoding="utf-8") + + result: Final = main(["--check"], repo_root=tmp_path) + + assert result == 1 + assert source_path.read_text(encoding="utf-8") == source_content + assert not (tmp_path / "litellm/provider_endpoints_support_backup.json").exists() + error_output: Final = capsys.readouterr().err + assert "provider endpoint support is stale" in error_output + assert "scripts/generate_provider_endpoints_support.py" in error_output + + +def test_check_reports_stale_backup_without_writing(tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None: + cost_map: Final = {"example/model": {"litellm_provider": "example", "mode": "chat"}} + current_json: Final = _current_json({"example": _provider()}) + generated: Final = generate_provider_endpoints_support(cost_map, current_json) + generated_content: Final = json.dumps(generated, indent=2, ensure_ascii=False) + "\n" + source_path: Final = tmp_path / "provider_endpoints_support.json" + backup_path: Final = tmp_path / "litellm/provider_endpoints_support_backup.json" + backup_content: Final = "stale\n" + (tmp_path / "model_prices_and_context_window.json").write_text(json.dumps(cost_map), encoding="utf-8") + source_path.write_text(generated_content, encoding="utf-8") + backup_path.parent.mkdir() + backup_path.write_text(backup_content, encoding="utf-8") + + result: Final = main(["--check"], repo_root=tmp_path) + + assert result == 1 + assert source_path.read_text(encoding="utf-8") == generated_content + assert backup_path.read_text(encoding="utf-8") == backup_content + assert str(backup_path) in capsys.readouterr().err diff --git a/tests/code_coverage_tests/unbounded_in_baseline.txt b/tests/code_coverage_tests/unbounded_in_baseline.txt index 1286ea25c4e..1da964681a9 100644 --- a/tests/code_coverage_tests/unbounded_in_baseline.txt +++ b/tests/code_coverage_tests/unbounded_in_baseline.txt @@ -2,12 +2,12 @@ # Fix a site and delete its line; regenerate with `check_unbounded_in_lists.py --update-baseline`. litellm/integrations/shadow_eval_logger.py ShadowEvalLogger._active_jobs prisma job_id.in `[str(record.id) for record in records]` 0 litellm/llms/litellm_proxy/skills/handler.py LiteLLMSkillsHandler.list_skills prisma created_by.in `owner_scopes` 0 -litellm/proxy/_experimental/mcp_server/db.py get_mcp_servers prisma server_id.in `server_ids` 0 -litellm/proxy/_experimental/mcp_server/db.py get_user_env_vars_bulk prisma server_id.in `ids` 0 -litellm/proxy/_experimental/mcp_server/db.py purge_user_oauth_credentials_for_server prisma user_id.in `[row.user_id for row in oauth_rows]` 0 -litellm/proxy/_experimental/mcp_server/oauth2_flow_backfill.py backfill_null_oauth2_flows prisma server_id.in `server_ids_for_flow` 0 -litellm/proxy/_experimental/mcp_server/oauth2_flow_backfill.py backfill_null_oauth2_flows prisma server_id.in `server_ids` 0 -litellm/proxy/_experimental/mcp_server/toolset_db.py list_mcp_toolsets prisma toolset_id.in `toolset_ids` 0 +litellm/proxy/mcp_server/db.py get_mcp_servers prisma server_id.in `server_ids` 0 +litellm/proxy/mcp_server/db.py get_user_env_vars_bulk prisma server_id.in `ids` 0 +litellm/proxy/mcp_server/db.py purge_user_oauth_credentials_for_server prisma user_id.in `[row.user_id for row in oauth_rows]` 0 +litellm/proxy/mcp_server/oauth2_flow_backfill.py backfill_null_oauth2_flows prisma server_id.in `server_ids_for_flow` 0 +litellm/proxy/mcp_server/oauth2_flow_backfill.py backfill_null_oauth2_flows prisma server_id.in `server_ids` 0 +litellm/proxy/mcp_server/toolset_db.py list_mcp_toolsets prisma toolset_id.in `toolset_ids` 0 litellm/proxy/agent_endpoints/endpoints.py _attach_keys_to_agents prisma agent_id.in `agent_ids` 0 litellm/proxy/agent_endpoints/endpoints.py get_agents prisma agent_id.in `agent_ids` 0 litellm/proxy/anthropic_endpoints/claude_code_endpoints/claude_code_skill_access.py SkillVisibility.where prisma name.in `sorted(self.granted)` 0 diff --git a/tests/e2e/coverage_registry/llm_conversational.yaml b/tests/e2e/coverage_registry/llm_conversational.yaml index e3994e598c6..c3c5330c440 100644 --- a/tests/e2e/coverage_registry/llm_conversational.yaml +++ b/tests/e2e/coverage_registry/llm_conversational.yaml @@ -71,13 +71,13 @@ - {id: llm.messages.anthropic.prompt_cache_5m.nonstream.works, module: llm, tier: P0, subject_endpoint: messages, route: anthropic, capability: prompt_cache_5m, streaming: nonstream, assertions: [works], source: "model_prices json", rationale: "Prompt caching via Messages API"} - {id: llm.messages.anthropic.thinking.nonstream.works, module: llm, tier: P1, subject_endpoint: messages, route: anthropic, capability: thinking, streaming: nonstream, assertions: [works], source: "model_prices json", rationale: "Extended thinking via Messages API"} - {id: llm.messages.bedrock_converse.basic.nonstream.works_for_kimi_k3_max_tokens_1, module: llm, tier: P0, subject_endpoint: messages, route: bedrock_converse, capability: basic, streaming: nonstream, assertions: [works_for_kimi_k3_max_tokens_1], source: "llm_translation/test_bedrock_kimi_k3_messages_e2e.py", rationale: "Bedrock Converse accepts max_tokens=1 on the Anthropic Messages surface after LiteLLM applies the model minimum", fail_before_fix: proven} -- {id: llm.messages.bedrock_invoke.mid_conversation_system.nonstream.cache_hit, module: llm, tier: P0, subject_endpoint: messages, route: bedrock_invoke, capability: mid_conversation_system, streaming: nonstream, assertions: [works, cache_hit], source: "llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py", rationale: "Flagged Claude 4.8+/5 must keep mid-conversation system reminders in messages; hoisting mutates the system prefix and collapses the prompt cache (#32578/#32831/#32882)", fail_before_fix: proven} -- {id: llm.messages.bedrock_invoke.mid_conversation_system.nonstream.works, module: llm, tier: P0, subject_endpoint: messages, route: bedrock_invoke, capability: mid_conversation_system, streaming: nonstream, assertions: [works], source: "llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py", rationale: "Claude <= 4.7 rejects role system inside messages; unflagged models must convert reminders to user turns in place (hoisting collapses the prompt cache) or every Claude Code session 400s (#32831)", fail_before_fix: proven} -- {id: llm.messages.bedrock_invoke.web_search_server_tool.nonstream.works, module: llm, tier: P0, subject_endpoint: messages, route: bedrock_invoke, capability: web_search_server_tool, streaming: nonstream, assertions: [works], source: "llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py", rationale: "Bedrock hosts no web_search server tool, so this only works because interception rewrites it before the upstream call and the agentic loop feeds the results back in native shape; a regression that short-circuits or forwards it instead yields raw text or AWS's 400", fail_before_fix: unproven} +- {id: llm.messages.bedrock_invoke.mid_conversation_system.nonstream.cache_hit, module: llm, tier: P0, subject_endpoint: messages, route: bedrock_invoke, capability: mid_conversation_system, streaming: nonstream, assertions: [works, cache_hit], source: "llms/bedrock/messages/invoke_transformations/anthropic_claude_transformation.py", rationale: "Flagged Claude 4.8+/5 must keep mid-conversation system reminders in messages; hoisting mutates the system prefix and collapses the prompt cache (#32578/#32831/#32882)", fail_before_fix: proven} +- {id: llm.messages.bedrock_invoke.mid_conversation_system.nonstream.works, module: llm, tier: P0, subject_endpoint: messages, route: bedrock_invoke, capability: mid_conversation_system, streaming: nonstream, assertions: [works], source: "llms/bedrock/messages/invoke_transformations/anthropic_claude_transformation.py", rationale: "Claude <= 4.7 rejects role system inside messages; unflagged models must convert reminders to user turns in place (hoisting collapses the prompt cache) or every Claude Code session 400s (#32831)", fail_before_fix: proven} +- {id: llm.messages.bedrock_invoke.web_search_server_tool.nonstream.works, module: llm, tier: P0, subject_endpoint: messages, route: bedrock_invoke, capability: web_search_server_tool, streaming: nonstream, assertions: [works], source: "llms/bedrock/messages/invoke_transformations/anthropic_claude_transformation.py", rationale: "Bedrock hosts no web_search server tool, so this only works because interception rewrites it before the upstream call and the agentic loop feeds the results back in native shape; a regression that short-circuits or forwards it instead yields raw text or AWS's 400", fail_before_fix: unproven} - {id: llm.messages.azure_foundry.mid_conversation_system.nonstream.cache_hit, module: llm, tier: P0, subject_endpoint: messages, route: azure_foundry, capability: mid_conversation_system, streaming: nonstream, assertions: [works, cache_hit], source: "llms/azure_ai/anthropic/messages_transformation.py", rationale: "Azure Foundry serves Claude on the native Anthropic contract, so flagged 4.8+/5 must keep mid-conversation system reminders in messages; hoisting mutates the system prefix and collapses the prompt cache (customer RCA gap)", fail_before_fix: proven} - {id: llm.messages.azure_foundry.mid_conversation_system.nonstream.works, module: llm, tier: P0, subject_endpoint: messages, route: azure_foundry, capability: mid_conversation_system, streaming: nonstream, assertions: [works], source: "llms/azure_ai/anthropic/messages_transformation.py", rationale: "Azure Foundry Claude <= 4.7 rejects role system inside messages; unflagged models must convert reminders to user turns in place (hoisting collapses the prompt cache) or every Claude Code session 400s (customer RCA gap)", fail_before_fix: proven} -- {id: llm.messages.vertex.mid_conversation_system.nonstream.cache_hit, module: llm, tier: P0, subject_endpoint: messages, route: vertex, capability: mid_conversation_system, streaming: nonstream, assertions: [works, cache_hit], source: "llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/transformation.py", rationale: "Vertex serves Claude on the native Anthropic contract, so flagged 4.8+/5 must keep mid-conversation system reminders in messages; hoisting mutates the system prefix and collapses the prompt cache (customer RCA gap)", fail_before_fix: proven} -- {id: llm.messages.vertex.mid_conversation_system.nonstream.works, module: llm, tier: P0, subject_endpoint: messages, route: vertex, capability: mid_conversation_system, streaming: nonstream, assertions: [works], source: "llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/transformation.py", rationale: "Vertex Claude <= 4.7 rejects role system inside messages; unflagged models must convert reminders to user turns in place (hoisting collapses the prompt cache) or every Claude Code session 400s (customer RCA gap)", fail_before_fix: proven} +- {id: llm.messages.vertex.mid_conversation_system.nonstream.cache_hit, module: llm, tier: P0, subject_endpoint: messages, route: vertex, capability: mid_conversation_system, streaming: nonstream, assertions: [works, cache_hit], source: "llms/vertex_ai/vertex_ai_partner_models/anthropic/messages/transformation.py", rationale: "Vertex serves Claude on the native Anthropic contract, so flagged 4.8+/5 must keep mid-conversation system reminders in messages; hoisting mutates the system prefix and collapses the prompt cache (customer RCA gap)", fail_before_fix: proven} +- {id: llm.messages.vertex.mid_conversation_system.nonstream.works, module: llm, tier: P0, subject_endpoint: messages, route: vertex, capability: mid_conversation_system, streaming: nonstream, assertions: [works], source: "llms/vertex_ai/vertex_ai_partner_models/anthropic/messages/transformation.py", rationale: "Vertex Claude <= 4.7 rejects role system inside messages; unflagged models must convert reminders to user turns in place (hoisting collapses the prompt cache) or every Claude Code session 400s (customer RCA gap)", fail_before_fix: proven} - {id: llm.responses.openai.basic.nonstream.works, module: llm, tier: P0, subject_endpoint: responses, route: openai, capability: basic, streaming: nonstream, assertions: [works], source: "response_api_endpoints/endpoints.py:26", rationale: "Core endpoint; OpenAI Responses native"} - {id: llm.responses.openai.input_validation.nonstream.works, module: llm, tier: P1, subject_endpoint: responses, route: openai, capability: input_validation, streaming: nonstream, assertions: [works], source: "vendor strategy §9.9 / LIT-4778", rationale: "Responses missing/empty input and missing model are rejected"} - {id: llm.responses.openai.basic.stream.works, module: llm, tier: P0, subject_endpoint: responses, route: openai, capability: basic, streaming: stream, assertions: [works], source: "response_api_endpoints/endpoints.py:26", rationale: "Streaming via /v1/responses"} diff --git a/tests/e2e/coverage_registry/mcp.yaml b/tests/e2e/coverage_registry/mcp.yaml index 2ad815930a9..8eac9adeb33 100644 --- a/tests/e2e/coverage_registry/mcp.yaml +++ b/tests/e2e/coverage_registry/mcp.yaml @@ -1,4 +1,4 @@ -# MCP module. Grounded in litellm/proxy/_experimental/mcp_server/. See tests/e2e/AGENTS.md for the grammar. +# MCP module. Grounded in litellm/proxy/mcp_server/. See tests/e2e/AGENTS.md for the grammar. - id: mcp.list_tools.api_key.succeeds module: mcp tier: P0 diff --git a/tests/e2e/coverage_registry/quota_management.yaml b/tests/e2e/coverage_registry/quota_management.yaml index df554b20204..cbaf46130d6 100644 --- a/tests/e2e/coverage_registry/quota_management.yaml +++ b/tests/e2e/coverage_registry/quota_management.yaml @@ -41,7 +41,7 @@ - {id: quota_management.budget.spend_counter.reseed_matches_db, module: quota_management, tier: P2, behavior: budget, variant: spend_counter, assertions: [reseed_matches_db], exercised_on: [chat_completions], source: "proxy/spend_tracking/budget_reservation.py", rationale: "Concurrent cold-counter reseeds keep the enforcement counter equal to DB spend (#26829)"} - {id: quota_management.spend_tracking.chat_completions.logs_cost, module: quota_management, tier: P0, behavior: spend_tracking, variant: chat_completions, assertions: [logs_cost], exercised_on: [chat_completions], source: "proxy/spend_tracking/spend_tracking_utils.py", rationale: "A paid chat call writes a nonzero spend row"} - {id: quota_management.spend_tracking.stream.logs_cost, module: quota_management, tier: P1, behavior: spend_tracking, variant: stream, assertions: [logs_cost], exercised_on: [chat_completions], source: "proxy/spend_tracking/spend_tracking_utils.py", rationale: "Streaming responses aggregate token counts into a spend row"} -- {id: quota_management.spend_tracking.messages_bridge.logs_cost, module: quota_management, tier: P1, behavior: spend_tracking, variant: messages_bridge, assertions: [logs_cost], exercised_on: [messages], source: "llms/anthropic/pass_through/responses_adapters/handler.py", rationale: "A streaming /v1/messages request served by an openai-provider model is bridged through the anthropic-messages -> Responses adapter and must aggregate the consumed SSE stream into one spend row with nonzero cost and token counts, attributed to custom_llm_provider openai under call_type anthropic_messages"} +- {id: quota_management.spend_tracking.messages_bridge.logs_cost, module: quota_management, tier: P1, behavior: spend_tracking, variant: messages_bridge, assertions: [logs_cost], exercised_on: [messages], source: "llms/anthropic/messages/responses_adapters/handler.py", rationale: "A streaming /v1/messages request served by an openai-provider model is bridged through the anthropic-messages -> Responses adapter and must aggregate the consumed SSE stream into one spend row with nonzero cost and token counts, attributed to custom_llm_provider openai under call_type anthropic_messages"} - {id: quota_management.spend_tracking.embeddings.logs_cost, module: quota_management, tier: P1, behavior: spend_tracking, variant: embeddings, assertions: [logs_cost], exercised_on: [embeddings], source: "proxy/spend_tracking/spend_tracking_utils.py", rationale: "Embedding calls write nonzero spend rows"} - {id: quota_management.spend_tracking.cache_hit.zero_cost, module: quota_management, tier: P1, behavior: spend_tracking, variant: cache_hit, assertions: [zero_cost], exercised_on: [chat_completions], source: "proxy/spend_tracking/spend_tracking_utils.py", rationale: "A response-cache hit logs at zero cost with the cache-hit marker"} - {id: quota_management.spend_tracking.discount_config.logs_cost, module: quota_management, tier: P1, behavior: spend_tracking, variant: discount_config, assertions: [logs_cost], exercised_on: [chat_completions], source: "proxy/management_endpoints/cost_tracking_settings.py + cost_calculator.py", rationale: "A persisted provider discount changes the real request's spend row"} @@ -62,11 +62,11 @@ - {id: quota_management.spend_tracking.cache_write.bills_cache_creation_rate, module: quota_management, tier: P1, behavior: spend_tracking, variant: cache_write, assertions: [bills_cache_creation_rate], exercised_on: [chat_completions], source: "litellm_core_utils/llm_cost_calc/utils.py", rationale: "OpenAI cache-write tokens land on the spend row as cache-creation tokens billed at the cache-creation rate, not silently at the input rate (#34046)"} - {id: quota_management.spend_tracking.cost_breakdown.reports_component_costs, module: quota_management, tier: P1, behavior: spend_tracking, variant: cost_breakdown, assertions: [reports_component_costs], exercised_on: [chat_completions], source: "proxy/spend_tracking/spend_tracking_utils.py", rationale: "The spend row's metadata.cost_breakdown itemizes cache-read, cache-creation, output, and reasoning costs at the deployment's own rates and they sum to the row's spend (#31686)"} - {id: quota_management.spend_tracking.stream_cache_read.bills_cache_read_rate, module: quota_management, tier: P1, behavior: spend_tracking, variant: stream_cache_read, assertions: [bills_cache_read_rate], exercised_on: [chat_completions], source: "litellm_core_utils/streaming_chunk_builder_utils.py", rationale: "A streamed call's reassembled usage keeps the cached-token detail so cache reads bill at the cache-read discount, not full input price (#34812)"} -- {id: quota_management.spend_tracking.messages_bridge.keeps_cache_tokens, module: quota_management, tier: P1, behavior: spend_tracking, variant: messages_bridge, assertions: [keeps_cache_tokens], exercised_on: [messages], source: "llms/anthropic/pass_through/responses_adapters/handler.py", rationale: "A /v1/messages request served by a Responses-only OpenAI model keeps its cache-read tokens and their discounted billing across the bridge (#34957)"} +- {id: quota_management.spend_tracking.messages_bridge.keeps_cache_tokens, module: quota_management, tier: P1, behavior: spend_tracking, variant: messages_bridge, assertions: [keeps_cache_tokens], exercised_on: [messages], source: "llms/anthropic/messages/responses_adapters/handler.py", rationale: "A /v1/messages request served by a Responses-only OpenAI model keeps its cache-read tokens and their discounted billing across the bridge (#34957)"} - {id: quota_management.spend_tracking.service_tier.bills_tier_rates, module: quota_management, tier: P1, behavior: spend_tracking, variant: service_tier, assertions: [bills_tier_rates], exercised_on: [chat_completions], source: "cost_calculator.py", rationale: "A priority service_tier call bills input, output, and reasoning at the deployment's *_priority rates and records the tier on the row (#35923, #35925)"} - {id: quota_management.spend_tracking.service_tier_stream.records_served_tier, module: quota_management, tier: P1, behavior: spend_tracking, variant: service_tier_stream, assertions: [records_served_tier], exercised_on: [chat_completions], source: "litellm_core_utils/streaming_chunk_builder_utils.py", fail_before_fix: proven, rationale: "A streamed call with no service_tier requested bills at the rates of the tier OpenAI stamps on its chunks and records that served tier on the row; the reassembled stream dropped the provider tier so the row recorded none and priced at the default rates"} - {id: quota_management.spend_tracking.service_tier_stream.responses_records_served_tier, module: quota_management, tier: P1, behavior: spend_tracking, variant: service_tier_stream, assertions: [records_served_tier], exercised_on: [responses], source: "responses/streaming_iterator.py", rationale: "A streamed /v1/responses call bills at the tier carried on the response.completed event's inner response and records that served tier on the spend row"} -- {id: quota_management.spend_tracking.service_tier_stream.messages_records_served_tier, module: quota_management, tier: P1, behavior: spend_tracking, variant: service_tier_stream, assertions: [records_served_tier], exercised_on: [messages], source: "llms/anthropic/pass_through/adapters/streaming_iterator.py", rationale: "A streamed /v1/messages call on an OpenAI-backed deployment bills at the tier OpenAI served; the Anthropic wire format has no tier field, so the spend row is the only record of it"} +- {id: quota_management.spend_tracking.service_tier_stream.messages_records_served_tier, module: quota_management, tier: P1, behavior: spend_tracking, variant: service_tier_stream, assertions: [records_served_tier], exercised_on: [messages], source: "llms/anthropic/messages/adapters/streaming_iterator.py", rationale: "A streamed /v1/messages call on an OpenAI-backed deployment bills at the tier OpenAI served; the Anthropic wire format has no tier field, so the spend row is the only record of it"} - {id: quota_management.spend_tracking.cost_headers.additive_components, module: quota_management, tier: P1, behavior: spend_tracking, variant: cost_headers, assertions: [additive_components], exercised_on: [chat_completions], source: "proxy/common_request_processing.py", rationale: "The x-litellm-response-cost-* component headers sum to the total, input covers only fresh tokens, and reasoning stays a subset of output (#36965)"} - {id: quota_management.spend_tracking.passthrough_stream.injects_usage_cost, module: quota_management, tier: P1, behavior: spend_tracking, variant: passthrough_stream, assertions: [injects_usage_cost], exercised_on: [openai_passthrough], source: "proxy/pass_through_endpoints/streaming_handler.py", rationale: "With include_cost_in_streaming_usage on, the /openai passthrough's final streaming usage frame carries the proxy-computed cost (#36503). Uncovered: the flag is only settable in litellm_settings, and the shared e2e stack does not turn it on yet"} - {id: quota_management.spend_tracking.websearch_interception.bills_under_request_session, module: quota_management, tier: P1, behavior: spend_tracking, variant: websearch_interception, assertions: [bills_under_request_session], exercised_on: [messages], source: "integrations/websearch_interception/handler.py", fail_before_fix: proven, rationale: "A web_search server tool the proxy intercepts into litellm.asearch writes its own asearch spend row, and that row carries the parent request's session_id so the session view counts the search and its cost next to the turn that triggered it (LIT-8063)"} diff --git a/tests/e2e/ui/globalSetup.ts b/tests/e2e/ui/globalSetup.ts index d97789c227e..e18d1be390c 100644 --- a/tests/e2e/ui/globalSetup.ts +++ b/tests/e2e/ui/globalSetup.ts @@ -2,7 +2,7 @@ import { chromium, expect, request } from "@playwright/test"; import { users, Role, STORAGE_PATHS } from "./fixtures/users"; import { ARTIFACT_DIR, UI_BASE_URL } from "./constants"; import { expectUnrestrictedDashboard, setInvitedUserPassword } from "./helpers/userOnboarding"; -import { hideLiteAdmin } from "./helpers/navigation"; +import { setAriaHidden } from "./helpers/navigation"; import { masterKey as getMasterKey } from "./helpers/traffic"; import * as fs from "fs"; import * as path from "path"; @@ -78,7 +78,7 @@ async function globalSetup() { await dismiss.click(); } if (role === Role.ProxyAdmin) { - await hideLiteAdmin(page); + await setAriaHidden(page, true); } // The login flow stores a post-login return URL in the litellm_return_url // cookie. If the snapshot captures it before the app consumes it, every diff --git a/tests/e2e/ui/helpers/navigation.ts b/tests/e2e/ui/helpers/navigation.ts index 78288fab743..be46fcf0395 100644 --- a/tests/e2e/ui/helpers/navigation.ts +++ b/tests/e2e/ui/helpers/navigation.ts @@ -62,18 +62,29 @@ export async function dismissFeedbackPopup(page: PlaywrightPage): Promise } } -export async function hideLiteAdmin(page: PlaywrightPage): Promise { +export async function setAriaHidden(page: PlaywrightPage, hidden: boolean): Promise { await page.getByRole("button", { name: /Account menu/i }).click(); const panel = page.getByTestId("sidebar-account-menu-panel"); await expect(panel).toBeVisible({ timeout: 5_000 }); - const toggle = panel.getByRole("switch", { name: "Toggle hide LiteAdmin" }); - if ((await toggle.getAttribute("aria-checked")) !== "true") { - await toggle.click(); + const premium = await panel.getByText("Premium", { exact: true }).isVisible(); + const toggle = panel.getByRole("switch", { name: "Toggle hide Aria Agent", exact: true }); + if (premium) { + await expect(toggle).toBeVisible(); + if ((await toggle.getAttribute("aria-checked")) !== String(hidden)) { + await toggle.click(); + } + await expect(toggle).toHaveAttribute("aria-checked", String(hidden)); + } else { + await expect(toggle).toHaveCount(0); } - await expect(toggle).toHaveAttribute("aria-checked", "true"); await page.keyboard.press("Escape"); await expect(panel).toBeHidden(); - await expect(page.getByRole("button", { name: "LiteAdmin", exact: true })).toBeHidden(); + const aria = page.getByRole("banner").getByRole("button", { name: "Aria Agent", exact: true }); + if (premium && hidden) { + await expect(aria).toBeHidden(); + } else { + await expect(aria).toBeVisible(); + } } /** diff --git a/tests/e2e/ui/tests/logs/logsPagination.spec.ts b/tests/e2e/ui/tests/logs/logsPagination.spec.ts index 416e1c3171f..838a829a3e2 100644 --- a/tests/e2e/ui/tests/logs/logsPagination.spec.ts +++ b/tests/e2e/ui/tests/logs/logsPagination.spec.ts @@ -1,8 +1,14 @@ import { test, expect, type APIRequestContext, type Locator, type Page as PlaywrightPage } from "@playwright/test"; import { ADMIN_STORAGE_PATH } from "../../constants"; -import { navigateToPage, dismissFeedbackPopup } from "../../helpers/navigation"; +import { navigateToPage, dismissFeedbackPopup, setAriaHidden } from "../../helpers/navigation"; import { Page } from "../../fixtures/pages"; -import { CHAT_MODEL_A, createVirtualKey, sendChatCompletion, waitForSpendLog } from "../../helpers/traffic"; +import { + CHAT_MODEL_A, + createVirtualKey, + deleteVirtualKey, + sendChatCompletion, + waitForSpendLog, +} from "../../helpers/traffic"; /** * Session-grouped pagination (#38060): a page of N rows must render exactly N session rows, a @@ -45,6 +51,57 @@ async function setRowsPerPage(page: PlaywrightPage, size: "25" | "50" | "100"): await page.getByRole("option", { name: size, exact: true }).click(); } +test.describe("Logs pagination with Aria in the header", () => { + test.use({ storageState: ADMIN_STORAGE_PATH }); + + for (const viewport of [ + { width: 1440, height: 900 }, + { width: 390, height: 844 }, + ]) { + test(`keeps pagination reachable and Aria available at ${viewport.width}px`, async ({ page, request }) => { + await page.setViewportSize(viewport); + const alias = `e2e-aria-header-${uniqueSuffix()}`; + const key = await createVirtualKey(request, { key_alias: alias }); + try { + const ids = await Promise.all( + Array.from({ length: 26 }, (_, index) => + sendChatCompletion(request, { + model: CHAT_MODEL_A, + prompt: `${alias}-${index}`, + apiKey: key.key, + }), + ), + ); + await Promise.all(ids.map((id) => waitForSpendLog(request, id))); + await openLogs(page); + await setAriaHidden(page, false); + await applyKeyAliasFilter(page, await openFilterDrawer(page), alias); + await setRowsPerPage(page, "25"); + await expect(visibleTestId(page, "pagination-range")).toHaveText("Showing 1-25 of 26"); + await visibleTestId(page, "pagination-next").click(); + await expect(visibleTestId(page, "pagination-range")).toHaveText("Showing 26-26 of 26"); + + const aria = page.getByRole("banner").getByRole("button", { name: "Aria Agent", exact: true }); + await aria.click(); + await expect(page.getByRole("dialog", { name: "Aria Agent", exact: true })).toBeVisible(); + await page.keyboard.press("Escape"); + await expect(aria).toBeFocused(); + await visibleTestId(page, "pagination-first").click(); + await expect(visibleTestId(page, "pagination-range")).toHaveText("Showing 1-25 of 26"); + for (const destination of [Page.Usage, Page.LlmPlayground, Page.ApiKeys]) { + await navigateToPage(page, destination); + await aria.click(); + await expect(page.getByRole("dialog", { name: "Aria Agent", exact: true })).toBeVisible(); + await page.keyboard.press("Escape"); + await expect(aria).toBeFocused(); + } + } finally { + await deleteVirtualKey(request, key.token); + } + }); + } +}); + test.describe("Logs page session-grouped pagination", () => { test.use({ storageState: ADMIN_STORAGE_PATH }); diff --git a/tests/integration/_support/copilot_session_prometheus_worker.py b/tests/integration/_support/copilot_session_prometheus_worker.py new file mode 100644 index 00000000000..a6b2c5d4692 --- /dev/null +++ b/tests/integration/_support/copilot_session_prometheus_worker.py @@ -0,0 +1,162 @@ +"""One SDK process for the SDK provider-401 metric cells: a provider 401 on a caller's own Copilot session, one on +the router deployment's own key, one on a key the router caller passes and one on a direct call's own key, then a +report of the deployment series on that process's default registry. Run as a script by ``run_copilot_session_worker`` so each process registers the +Prometheus metrics exactly once.""" + +from __future__ import annotations + +import asyncio +import json +import subprocess +import sys +from itertools import chain +from dataclasses import dataclass +from typing import Final + +import litellm +import openai +from litellm.integrations.prometheus import PrometheusLogger +from litellm.llms.github_copilot.per_user_auth import GithubCopilotUserSession +from prometheus_client import REGISTRY +from pydantic import TypeAdapter + +COPILOT_DEPLOYMENT: Final = "copilot-per-user-deployment" +OPERATOR_DEPLOYMENT: Final = "operator-key-deployment" +CALLER_SESSION_TOKEN: Final = "caller-copilot-session-token" +OPERATOR_KEY: Final = "rotated-operator-key" +ROUTER_CALLER_KEY: Final = "rotated-router-caller-key" +DIRECT_CALL: Final = "direct-sdk-call" +DIRECT_KEY: Final = "rotated-direct-call-key" +FAILURES: Final = "litellm_deployment_failure_responses_total" +TOTALS: Final = "litellm_deployment_total_requests_total" +LLM_FAILED: Final = "litellm_llm_api_failed_requests_metric_total" +STATE: Final = "litellm_deployment_state" +DEPLOYMENT_SERIES: Final = frozenset({FAILURES, TOTALS, LLM_FAILED, STATE}) +WORKER_TIMEOUT_SECONDS: Final = 120 + + +@dataclass(frozen=True, slots=True) +class Outcome: + deployment: str + status: int | None + + +@dataclass(frozen=True, slots=True) +class Series: + metric: str + model_id: str + api_base: str + value: float + + +@dataclass(frozen=True, slots=True) +class WorkerReport: + api_base: str + outcomes: tuple[Outcome, ...] + series: tuple[Series, ...] + + def values(self, metric: str, model_id: str) -> tuple[float, ...]: + return tuple(s.value for s in self.series if s.metric == metric and s.model_id == model_id) + + def on_the_endpoint(self, metric: str, model_id: str) -> tuple[float, ...]: + return tuple( + s.value for s in self.series if (s.metric, s.model_id, s.api_base) == (metric, model_id, self.api_base) + ) + + def outside_the_router(self, metric: str) -> tuple[float, ...]: + return tuple(s.value for s in self.series if s.metric == metric and not s.model_id) + + def on_a_one_off_deployment(self, metric: str) -> tuple[float, ...]: + named_ids: Final = ("", COPILOT_DEPLOYMENT, OPERATOR_DEPLOYMENT) + return tuple(s.value for s in self.series if s.metric == metric and s.model_id not in named_ids) + + +_REPORT: Final = TypeAdapter(WorkerReport) + + +def run_copilot_session_worker(api_base: str) -> WorkerReport: + completed: Final = subprocess.run( + (sys.executable, "-P", __file__, api_base), + capture_output=True, + text=True, + timeout=WORKER_TIMEOUT_SECONDS, + check=False, + ) + assert completed.returncode == 0, completed.stderr[-3000:] + return _REPORT.validate_json(completed.stdout.splitlines()[-1]) + + +def _deployment_series() -> tuple[Series, ...]: + samples: Final = tuple(chain.from_iterable(family.samples for family in REGISTRY.collect())) + return tuple( + Series( + metric=sample.name, + model_id=str(sample.labels.get("model_id", "")), + api_base=str(sample.labels.get("api_base", "")), + value=float(sample.value), + ) + for sample in samples + if sample.name in DEPLOYMENT_SERIES + ) + + +def _router(api_base: str) -> litellm.Router: + return litellm.Router( + model_list=[ + { + "model_name": COPILOT_DEPLOYMENT, + "litellm_params": { + "model": "github_copilot/gpt-4o", + "litellm_credential_name": "copilot-per-user", + "github_copilot_auth_type": "per_user_oauth", + }, + "model_info": {"id": COPILOT_DEPLOYMENT}, + }, + { + "model_name": OPERATOR_DEPLOYMENT, + "litellm_params": {"model": "openai/gpt-5.6", "api_base": api_base, "api_key": OPERATOR_KEY}, + "model_info": {"id": OPERATOR_DEPLOYMENT}, + }, + ], + num_retries=0, + disable_cooldowns=True, + ) + + +async def _attempt(router: litellm.Router, model: str, **extra: object) -> Outcome: + try: + await router.acompletion(model=model, messages=[{"role": "user", "content": f"{model} worker"}], **extra) + except openai.APIStatusError as error: + return Outcome(deployment=model, status=error.status_code) + return Outcome(deployment=model, status=None) + + +async def _direct_attempt(api_base: str) -> Outcome: + try: + await litellm.acompletion( + model="openai/gpt-5.6", + api_base=api_base, + api_key=DIRECT_KEY, + messages=[{"role": "user", "content": f"{DIRECT_CALL} worker"}], + ) + except openai.APIStatusError as error: + return Outcome(deployment=DIRECT_CALL, status=error.status_code) + return Outcome(deployment=DIRECT_CALL, status=None) + + +async def main(api_base: str) -> None: + litellm.callbacks = [PrometheusLogger()] # test-quality-ok: this worker process exits right after the report + session: Final = GithubCopilotUserSession(token=CALLER_SESSION_TOKEN, api_base=api_base) + router: Final = _router(api_base) + outcomes: Final = ( + await _attempt(router, COPILOT_DEPLOYMENT, github_copilot_user_session=session), + await _attempt(router, OPERATOR_DEPLOYMENT), + await _attempt(router, OPERATOR_DEPLOYMENT, api_key=ROUTER_CALLER_KEY), + await _direct_attempt(api_base), + ) + report: Final = WorkerReport(api_base=api_base, outcomes=outcomes, series=_deployment_series()) + sys.stdout.write(json.dumps(_REPORT.dump_python(report)) + "\n") + + +if __name__ == "__main__": + asyncio.run(main(sys.argv[1])) diff --git a/tests/integration/authorization/test_claude_code_gateway_oauth.py b/tests/integration/authorization/test_claude_code_gateway_oauth.py index 384bf3a2918..a80eeacad46 100644 --- a/tests/integration/authorization/test_claude_code_gateway_oauth.py +++ b/tests/integration/authorization/test_claude_code_gateway_oauth.py @@ -15,6 +15,7 @@ from urllib.parse import parse_qs, urlencode, urlsplit import httpx import pytest import yaml +from anthropic import Anthropic from anthropic.types import Message from integration._support import claude_code as cc from integration._support.client import Gateway, eventually, gateway_from_environment @@ -397,7 +398,31 @@ def test_device_authorization_polls_complete_sso_and_mints_a_model_restricted_be "anthropic-beta": cc.CLI_BETA, "x-claude-code-session-id": f"oauth-{user_id}", } - request_body: Final = {**request_template, "model": model_a} + standard_listing: Final = enabled_gateway.client.get("/v1/models", headers=bearer_headers) + gateway_listing: Final = enabled_gateway.client.get( + "/claude_code_gateway/v1/models", headers=bearer_headers + ) + assert standard_listing.status_code == 200, standard_listing.text + assert gateway_listing.status_code == 200, gateway_listing.text + assert gateway_listing.json() == standard_listing.json() + with Anthropic( + base_url=f"{str(enabled_gateway.client.base_url).rstrip('/')}/claude_code_gateway", + auth_token=access_token.access_token, + ) as sdk: + discovered_models: Final = tuple(sdk.models.list()) + assert {model.id for model in discovered_models} == {model_a, model_c} + discovered_model: Final = next(model for model in discovered_models if model.id == model_a) + openai_listing: Final = enabled_gateway.client.get( + "/claude_code_gateway/v1/models", + headers={"authorization": f"Bearer {access_token.access_token}"}, + ) + assert openai_listing.status_code == 200, openai_listing.text + assert openai_listing.json()["object"] == "list" + assert {model["id"] for model in openai_listing.json()["data"]} == {model_a, model_c} + unauthenticated: Final = enabled_gateway.client.get("/claude_code_gateway/v1/models") + assert unauthenticated.status_code == 401, unauthenticated.text + assert upstream.drain() == () + request_body: Final = {**request_template, "model": discovered_model.id} expected_message: Final = _MESSAGE.validate_python( { **_JSON_OBJECT.validate_json( diff --git a/tests/integration/authorization/test_key_budget_owner_updates.py b/tests/integration/authorization/test_key_budget_owner_updates.py new file mode 100644 index 00000000000..8415c044b6f --- /dev/null +++ b/tests/integration/authorization/test_key_budget_owner_updates.py @@ -0,0 +1,195 @@ +from collections.abc import Iterator +from hashlib import sha256 +from pathlib import Path +from types import MappingProxyType +from typing import Final + +import pytest +import yaml +from integration._support.client import ( + JSON_OBJECT, + Gateway, + Scenario, + eventually, + gateway_from_environment, + string_value, +) +from integration._support.process import owned_proxy +from pydantic import JsonValue + +pytestmark: Final = pytest.mark.shares_worker_state + +CAP: Final = 0.1 +BUDGET_EXCEEDED: Final = 422 +FAST_RESET_TICK: Final = MappingProxyType( + {"PROXY_BUDGET_RESCHEDULER_MIN_TIME": "2", "PROXY_BUDGET_RESCHEDULER_MAX_TIME": "2"} +) + + +@pytest.fixture(scope="module") +def resetting(tmp_path_factory: pytest.TempPathFactory) -> Iterator[Gateway]: + with ( + gateway_from_environment() as shared, + owned_proxy(shared, tmp_path_factory.mktemp("fast-reset"), FAST_RESET_TICK) as replica, + ): + yield replica + + +def _policy_config(directory: Path, policy: str) -> Path: + shared: Final = JSON_OBJECT.validate_python(yaml.safe_load(Path("tests/integration/proxy_config.yaml").read_text())) + general_settings: Final = { + **JSON_OBJECT.validate_python(shared["general_settings"]), + "self_serve_budget_policy": policy, + } + path: Final = directory / f"{policy}.yaml" + path.write_text(yaml.safe_dump({**shared, "general_settings": general_settings})) + return path + + +@pytest.fixture(scope="module", params=("lower_only", "ceiling")) +def self_serve( + request: pytest.FixtureRequest, tmp_path_factory: pytest.TempPathFactory +) -> Iterator[tuple[str, Gateway]]: + policy: Final = string_value(request.param) + directory: Final = tmp_path_factory.mktemp(policy) + with ( + gateway_from_environment() as shared, + owned_proxy(shared, directory, {}, config=_policy_config(directory, policy)) as replica, + ): + yield policy, replica + + +def _owner_credential(scenario: Scenario) -> str: + return scenario.key(user_id=scenario.user(user_role="internal_user")) + + +def _owned_key(gateway: Gateway, scenario: Scenario, owner: str, **fields: JsonValue) -> str: + response: Final = gateway.request("POST", "/key/generate", fields, key=owner) + assert response.status_code == 200, response.text + token: Final = string_value(JSON_OBJECT.validate_json(response.content)["key"]) + scenario.cleanups.callback(scenario.delete_key, token) + return token + + +def _key_row(gateway: Gateway, key: str) -> dict[str, JsonValue]: + rows: Final = gateway.rows( + "SELECT spend, max_budget, budget_duration, budget_id, budget_reset_at::text AS reset_at" + ' FROM "LiteLLM_VerificationToken" WHERE token = %s', + (sha256(key.encode()).hexdigest(),), + ) + assert len(rows) == 1, rows + return rows[0] + + +def _exhaust(gateway: Gateway, key: str) -> None: + gateway.post("/key/update", {"key": key, "spend": CAP}) + assert _key_row(gateway, key)["spend"] == CAP + + +def _chat_status(gateway: Gateway, model: str, key: str) -> int: + return gateway.request( + "POST", "/v1/chat/completions", {"model": model, "messages": [{"role": "user", "content": "budget"}]}, key=key + ).status_code + + +def test_key_owner_cannot_shorten_budget_duration_to_restart_an_exhausted_budget(resetting: Gateway) -> None: + with resetting.scenario() as scenario: + model: Final = scenario.model() + owner: Final = _owner_credential(scenario) + target: Final = _owned_key(resetting, scenario, owner, models=[model], max_budget=CAP, budget_duration="30d") + control: Final = _owned_key(resetting, scenario, owner, models=[model], max_budget=CAP, budget_duration="30d") + _exhaust(resetting, target) + _exhaust(resetting, control) + assert _chat_status(resetting, model, target) == BUDGET_EXCEEDED + before: Final = _key_row(resetting, target) + + denied: Final = resetting.request("POST", "/key/update", {"key": target, "budget_duration": "1s"}, key=owner) + + resetting.post("/key/update", {"key": control, "budget_duration": "1s"}) + eventually(lambda: _key_row(resetting, control)["spend"], lambda spend: spend == 0.0, seconds=60) + assert denied.status_code == 403, denied.text + assert _key_row(resetting, target) == before + assert _chat_status(resetting, model, target) == BUDGET_EXCEEDED + + +def test_key_owner_cannot_swap_or_reschedule_a_tier_key(gateway: Gateway) -> None: + with gateway.scenario() as scenario: + model: Final = scenario.model() + low: Final = scenario.budget(max_budget=CAP) + high: Final = scenario.budget(max_budget=100.0) + owner: Final = _owner_credential(scenario) + target: Final = _owned_key(gateway, scenario, owner, models=[model], budget_id=low) + _exhaust(gateway, target) + assert _chat_status(gateway, model, target) == BUDGET_EXCEEDED + before: Final = _key_row(gateway, target) + + swapped: Final = gateway.request("POST", "/key/update", {"key": target, "budget_id": high}, key=owner) + rescheduled: Final = gateway.request("POST", "/key/update", {"key": target, "budget_duration": "1s"}, key=owner) + + assert swapped.status_code == 403, swapped.text + assert rescheduled.status_code == 403, rescheduled.text + assert _key_row(gateway, target) == before + assert _chat_status(gateway, model, target) == BUDGET_EXCEEDED + + +def test_team_member_cannot_shorten_budget_duration_on_a_team_key(gateway: Gateway) -> None: + with gateway.scenario() as scenario: + team: Final = scenario.team(team_member_permissions=["/key/update", "/key/info"]) + member: Final = scenario.key(user_id=scenario.member(team), team_id=team) + target: Final = scenario.key(team_id=team, max_budget=CAP, budget_duration="30d") + before: Final = _key_row(gateway, target) + + denied: Final = gateway.request("POST", "/key/update", {"key": target, "budget_duration": "1s"}, key=member) + + assert denied.status_code == 403, denied.text + assert _key_row(gateway, target) == before + + +def test_key_owner_keeps_edits_that_cannot_restart_a_budget(gateway: Gateway) -> None: + with gateway.scenario() as scenario: + owner: Final = _owner_credential(scenario) + capped: Final = _owned_key(gateway, scenario, owner, max_budget=CAP, budget_duration="monthly") + uncapped: Final = _owned_key(gateway, scenario, owner) + + renamed: Final = gateway.request("POST", "/key/update", {"key": capped, "key_alias": "renamed"}, key=owner) + resent: Final = gateway.request("POST", "/key/update", {"key": capped, "budget_duration": "30d"}, key=owner) + scheduled: Final = gateway.request("POST", "/key/update", {"key": uncapped, "budget_duration": "1d"}, key=owner) + + assert renamed.status_code == 200, renamed.text + assert resent.status_code == 200, resent.text + assert scheduled.status_code == 200, scheduled.text + assert _key_row(gateway, uncapped)["budget_duration"] == "1d" + + +def test_self_serve_policy_keeps_tier_keys_admin_only(self_serve: tuple[str, Gateway]) -> None: + _, proxy = self_serve + with proxy.scenario() as scenario: + low: Final = scenario.budget(max_budget=CAP) + high: Final = scenario.budget(max_budget=100.0) + owner: Final = _owner_credential(scenario) + target: Final = _owned_key(proxy, scenario, owner, budget_id=low) + before: Final = _key_row(proxy, target) + + swapped: Final = proxy.request("POST", "/key/update", {"key": target, "budget_id": high}, key=owner) + rescheduled: Final = proxy.request("POST", "/key/update", {"key": target, "budget_duration": "1d"}, key=owner) + + assert swapped.status_code == 403, swapped.text + assert rescheduled.status_code == 403, rescheduled.text + assert _key_row(proxy, target) == before + + +def test_self_serve_policy_gates_a_new_reset_period_like_a_raised_cap(self_serve: tuple[str, Gateway]) -> None: + policy, proxy = self_serve + with proxy.scenario() as scenario: + owner: Final = _owner_credential(scenario) + shortened: Final = _owned_key(proxy, scenario, owner, max_budget=CAP, budget_duration="30d") + cleared: Final = _owned_key(proxy, scenario, owner, max_budget=CAP, budget_duration="30d") + + shorten: Final = proxy.request("POST", "/key/update", {"key": shortened, "budget_duration": "1s"}, key=owner) + clear: Final = proxy.request("POST", "/key/update", {"key": cleared, "budget_duration": None}, key=owner) + + assert (shorten.status_code, _key_row(proxy, shortened)["budget_duration"]) == ( + (403, "30d") if policy == "lower_only" else (200, "1s") + ), shorten.text + assert clear.status_code == 200, clear.text + assert _key_row(proxy, cleared)["budget_duration"] is None diff --git a/tests/integration/cost_calculation/cases/openai.py b/tests/integration/cost_calculation/cases/openai.py index acba66223e5..53fd5c1cec2 100644 --- a/tests/integration/cost_calculation/cases/openai.py +++ b/tests/integration/cost_calculation/cases/openai.py @@ -6985,6 +6985,106 @@ GPT_5_6_RESPONSES_CACHE_READ: Final = CostTrackingTestCase( ), ) +GPT_5_6_RESPONSES_CACHE_WRITE_12H: Final = CostTrackingTestCase( + name="gpt-5.6-responses_cache_write_12h", + covers="quota_management.spend_tracking.cost_matrix.logs_cost", + model="gpt-5.6", + endpoint="/v1/responses", + request={ + "model": "$MODEL", + "input": "summarize this text", + "prompt_cache_options": {"mode": "implicit", "ttl": "12h"}, + }, + response=JsonResponse( + content_type="application/json", + body={ + "id": "resp_$REQUEST_ID", + "object": "response", + "created_at": 1700000000, + "status": "completed", + "model": "gpt-5.6", + "output": [ + { + "type": "message", + "id": "msg_$REQUEST_ID", + "status": "completed", + "role": "assistant", + "content": [{"type": "output_text", "text": "scripted response", "annotations": []}], + } + ], + "usage": { + "input_tokens": 12928, + "output_tokens": 380, + "total_tokens": 13308, + "input_tokens_details": { + "cached_tokens": 0, + "cache_write_tokens": 5000, + "cache_write_tokens_details": {"ttl_30m_tokens": 3000, "ttl_12h_tokens": 2000}, + }, + "output_tokens_details": {"reasoning_tokens": 0}, + }, + }, + ), + expected=ExactExpected( + spend=0.0344865, + input_cost=0.0291865, + output_cost=0.00532, + prompt_tokens=12928, + completion_tokens=380, + cache_creation_cost=0.0153125, + ), +) + +GPT_6_LUNA_RESPONSES_CACHE_WRITE_12H_NO_12H_RATE: Final = CostTrackingTestCase( + name="gpt-6-luna-responses_cache_write_12h_no_12h_rate", + covers="quota_management.spend_tracking.cost_matrix.logs_cost", + model="gpt-6-luna", + endpoint="/v1/responses", + request={ + "model": "$MODEL", + "input": "summarize this text", + "prompt_cache_options": {"mode": "implicit", "ttl": "12h"}, + }, + response=JsonResponse( + content_type="application/json", + body={ + "id": "resp_$REQUEST_ID", + "object": "response", + "created_at": 1700000000, + "status": "completed", + "model": "gpt-6-luna", + "output": [ + { + "type": "message", + "id": "msg_$REQUEST_ID", + "status": "completed", + "role": "assistant", + "content": [{"type": "output_text", "text": "scripted response", "annotations": []}], + } + ], + "usage": { + "input_tokens": 12928, + "output_tokens": 380, + "total_tokens": 13308, + "input_tokens_details": { + "cached_tokens": 0, + "cache_write_tokens": 5000, + "cache_write_tokens_details": {"ttl_30m_tokens": 3000, "ttl_12h_tokens": 2000}, + }, + "output_tokens_details": {"reasoning_tokens": 0}, + }, + }, + ), + expected=ExactExpected( + spend=0.0016078, + input_cost=0.0014178, + output_cost=0.00019, + prompt_tokens=12928, + completion_tokens=380, + cache_creation_cost=0.000625, + ), +) + GPT_5_6_RESPONSES_REASONING: Final = CostTrackingTestCase( name="gpt-5.6-responses_reasoning", covers="quota_management.spend_tracking.cost_matrix.logs_cost", @@ -11913,6 +12013,8 @@ CASES: Final[tuple[CostTrackingTestCase, ...]] = ( OMNI_MODERATIONS_NEXT_SINGLE, OMNI_MODERATIONS_NEXT_LIST, GPT_5_6_RESPONSES_CACHE_READ, + GPT_5_6_RESPONSES_CACHE_WRITE_12H, + GPT_6_LUNA_RESPONSES_CACHE_WRITE_12H_NO_12H_RATE, GPT_5_6_RESPONSES_REASONING, GPT_5_6_RESPONSES_STREAM, GPT_5_6_RESPONSES_STREAM_CACHE_READ, diff --git a/tests/integration/cost_calculation/cost_map.py b/tests/integration/cost_calculation/cost_map.py index 012d847e676..cd979528fe6 100644 --- a/tests/integration/cost_calculation/cost_map.py +++ b/tests/integration/cost_calculation/cost_map.py @@ -174,6 +174,8 @@ COST_MAP_ENTRIES: Final[dict[str, dict[str, JsonValue]]] = { }, }, "gpt-5.6": { + "cache_creation_input_token_cost": 2.1875e-06, + "cache_creation_input_token_cost_above_12hr": 4.375e-06, "cache_read_input_token_cost": 1.75e-07, "input_cost_per_audio_token": 4e-05, "input_cost_per_token": 1.75e-06, diff --git a/tests/integration/cost_calculation/cost_tracking_case.py b/tests/integration/cost_calculation/cost_tracking_case.py index e98f6a44222..95363e92366 100644 --- a/tests/integration/cost_calculation/cost_tracking_case.py +++ b/tests/integration/cost_calculation/cost_tracking_case.py @@ -85,6 +85,16 @@ class CostMapEntry(BaseModel): cache_read_input_token_cost: float | None = None cache_creation_input_token_cost: float | None = None cache_creation_input_token_cost_above_1hr: float | None = None + cache_creation_input_token_cost_above_12hr: float | None = None + cache_creation_input_token_cost_above_12hr_flex: float | None = None + cache_creation_input_token_cost_above_12hr_priority: float | None = None + cache_creation_input_token_cost_above_12hr_above_272k_tokens: float | None = None + cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex: float | None = None + cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority: float | None = None + cache_creation_input_token_cost_above_12hr_batches: float | None = None + cache_creation_input_token_cost_above_12hr_ultrafast: float | None = None + cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches: float | None = None + cache_creation_input_token_cost_above_12hr_above_272k_tokens_ultrafast: float | None = None cache_creation_input_token_cost_above_1hr_above_200k_tokens: float | None = None cache_read_input_token_cost_above_200k_tokens: float | None = None cache_creation_input_token_cost_above_200k_tokens: float | None = None diff --git a/tests/integration/database/migrations/test_request_log_indexes.py b/tests/integration/database/migrations/test_request_log_indexes.py index 3b6d1eaf21a..bf37ca80665 100644 --- a/tests/integration/database/migrations/test_request_log_indexes.py +++ b/tests/integration/database/migrations/test_request_log_indexes.py @@ -1,5 +1,6 @@ import os import queue +import secrets import shutil import subprocess import sys @@ -14,7 +15,7 @@ from typing import Final import psycopg import pytest -from litellm_proxy_extras import request_log_indexes +from litellm_proxy_extras import migration_data_checks, request_log_indexes from litellm_proxy_extras.migration_lock import MIGRATION_LOCK_KEY, migration_lock from litellm_proxy_extras.migration_recovery import roll_back_failed_inert_migration from litellm_proxy_extras.request_log_indexes import ( @@ -408,6 +409,12 @@ def test_a_migration_without_a_failed_row_is_not_touched(partitioned_database: s assert _ledger(partitioned_database) == before +def _backend_pid(connection: "psycopg.Connection[tuple[object, ...]]") -> int: + row: Final = connection.execute("SELECT pg_backend_pid()").fetchone() + assert row is not None and isinstance(row[0], int), row + return row[0] + + def _pin_a_snapshot_on(database_url: str, table: str) -> "psycopg.Connection[tuple[object, ...]]": pin: Final = psycopg.connect(database_url) pin.isolation_level = psycopg.IsolationLevel.REPEATABLE_READ @@ -532,7 +539,9 @@ def test_an_invalid_child_index_left_by_an_interrupted_build_is_rebuilt_and_atta @requires_db -def test_partitioning_a_table_the_index_job_already_covered_moves_its_call_id_index_aside(scratch_database: str) -> None: +def test_partitioning_a_table_the_index_job_already_covered_moves_its_call_id_index_aside( + scratch_database: str, +) -> None: """The runbook renames the Prisma indexes off the legacy table so the partitioned table can take their names. The call-id index is built by the index job, not Prisma, and a deployment that partitions after that job ran kept the name on the legacy table, so every later job run reported it as on another table.""" @@ -541,7 +550,9 @@ def test_partitioning_a_table_the_index_job_already_covered_moves_its_call_id_in _partition_spend_logs(scratch_database) - assert _indexed_table(scratch_database, "LiteLLM_SpendLogs_legacy_litellm_call_id_idx") == "LiteLLM_SpendLogs_legacy" + assert ( + _indexed_table(scratch_database, "LiteLLM_SpendLogs_legacy_litellm_call_id_idx") == "LiteLLM_SpendLogs_legacy" + ) assert ensure_request_log_indexes(scratch_database, "public") is True _assert_index_covers_every_partition(scratch_database, CALL_ID_INDEX, "litellm_call_id_idx") @@ -737,7 +748,7 @@ def test_inserts_are_never_held_back_while_attach_partition_waits_for_a_reader_o reader.execute( sql.SQL('SELECT count(*) FROM {} WHERE "litellm_call_id" IS NULL').format(sql.Identifier(partition)) ).fetchone() - reader_pid: Final = reader.execute("SELECT pg_backend_pid()").fetchone()[0] + reader_pid: Final = _backend_pid(reader) with psycopg.connect(partitioned_database, autocommit=True) as inspector: child_lock: Final = inspector.execute( "SELECT 1 FROM pg_locks WHERE pid = %s AND relation = to_regclass(%s) " @@ -800,7 +811,7 @@ def test_an_attach_that_never_gets_its_lock_is_left_for_the_next_index_build( reader.execute( sql.SQL('SELECT count(*) FROM {} WHERE "litellm_call_id" IS NULL').format(sql.Identifier(partition)) ).fetchone() - reader_pid: Final = reader.execute("SELECT pg_backend_pid()").fetchone()[0] + reader_pid: Final = _backend_pid(reader) with psycopg.connect(partitioned_database, autocommit=True) as inspector: child_lock: Final = inspector.execute( "SELECT 1 FROM pg_locks WHERE pid = %s AND relation = to_regclass(%s) " @@ -929,3 +940,183 @@ def test_a_second_copy_of_a_managed_index_is_reported_with_its_drop_statement_an assert 'remove it with: DROP INDEX CONCURRENTLY "public"."call_id_copy"' in caplog.text assert _index_oids(scratch_database)["call_id_copy"] == copy + + +def _insert_spend_log_with_key(conn: "psycopg.Connection[tuple[object, ...]]", request_id: str, api_key: str) -> None: + conn.execute( + 'INSERT INTO "LiteLLM_SpendLogs" ("request_id", "call_type", "startTime", "endTime", "api_key") ' + "VALUES (%s, %s, %s, %s, %s)", + (request_id, "acompletion", "2025-06-03 14:02:11", "2025-06-03 14:02:13", api_key), + ) + + +def _legacy_bearer_token() -> str: + """A raw JWT-sized bearer token the way a pre-v1.99.0 proxy stored it: random, so + Postgres cannot compress it into the 2704-byte btree entry limit.""" + return "Bearer " + secrets.token_hex(1600) + + +def _hash_sql_from(refusal: str) -> str: + return refusal[refusal.index('UPDATE "LiteLLM_SpendLogs"') : refusal.index("{64}$';") + len("{64}$';")] + + +@requires_db +@RESOLVERS +@pytest.mark.parametrize("release", (API_KEY_INDEX_MIGRATION,), ids=("v1.102.1",)) +def test_the_migration_job_refuses_before_the_first_migration_when_spend_log_keys_are_too_long_for_the_index( + scratch_database: str, use_v2_resolver: bool +) -> None: + with psycopg.connect(scratch_database, autocommit=True) as conn: + _insert_spend_log_with_key(conn, "legacy-1", _legacy_bearer_token()) + _insert_spend_log_with_key(conn, "legacy-2", _legacy_bearer_token()) + _insert_spend_log_with_key(conn, "hashed-1", "a" * 64) + ledger_before: Final = _ledger(scratch_database) + + with pytest.raises(RuntimeError) as refused: + ProxyExtrasDBManager.run_migration_job(use_migrate=True, use_v2_resolver=use_v2_resolver) + + refusal: Final = str(refused.value) + assert ( + '"LiteLLM_SpendLogs".api_key, startTime: 2 row(s) with an index entry over 2704 bytes, largest 3232 bytes ' + "(api_key up to 3207 bytes)" + ) in refusal, refusal + assert f'blocks: CREATE INDEX "{API_KEY_INDEX}"' in refusal, refusal + assert _ledger(scratch_database) == ledger_before, "a refused job must not apply a single migration" + assert API_KEY_INDEX not in _index_validity(scratch_database, "api_key_startTime_idx") + + with psycopg.connect(scratch_database, autocommit=True) as conn: + conn.execute(_hash_sql_from(refusal)) # pyright: ignore[reportArgumentType] # the refusal's own SQL + assert ProxyExtrasDBManager.run_migration_job(use_migrate=True, use_v2_resolver=use_v2_resolver) is True + assert _index_validity(scratch_database, "api_key_startTime_idx") == {API_KEY_INDEX: True} + assert len(_ledger(scratch_database)) > len(ledger_before) + + +@requires_db +@pytest.mark.parametrize("release", (API_KEY_INDEX_MIGRATION,), ids=("v1.102.1",)) +def test_a_serving_proxy_index_build_that_meets_too_long_keys_reports_the_rows_instead_of_the_postgres_error( + scratch_database: str, caplog: pytest.LogCaptureFixture +) -> None: + assert ProxyExtrasDBManager.setup_database(use_migrate=True, use_v2_resolver=True) is True + with psycopg.connect(scratch_database, autocommit=True) as conn: + _insert_spend_log_with_key(conn, "legacy-1", _legacy_bearer_token()) + + with caplog.at_level("WARNING", logger="litellm_proxy_extras"): + built: Final = ensure_request_log_indexes(scratch_database, "public") + + assert built is False + assert f"Not building index {API_KEY_INDEX}" in caplog.text, caplog.text + assert '"LiteLLM_SpendLogs".api_key, startTime: 1 row(s) with an index entry over 2704 bytes' in caplog.text, ( + caplog.text + ) + assert "exceeds btree version 4 maximum" not in caplog.text, caplog.text + assert API_KEY_INDEX not in _index_validity(scratch_database, "api_key_startTime_idx") + + +_PROBE_STATEMENTS: Final = ( + 'CREATE UNIQUE INDEX "probe_b_key" ON "preflight_probe" ("b")', + 'ALTER TABLE "preflight_probe" ALTER COLUMN "b" SET NOT NULL', + 'ALTER TABLE "preflight_probe" ADD COLUMN "c" INTEGER NOT NULL', + 'ALTER TABLE "preflight_probe" ADD CONSTRAINT "probe_r_fkey" FOREIGN KEY ("r") REFERENCES "preflight_parent"("id")', + 'ALTER TABLE "preflight_probe" ADD CONSTRAINT "probe_a_check" CHECK ("a" <> \'bad\')', + 'CREATE INDEX "probe_a_idx" ON "preflight_probe" ("a")', +) + + +@requires_db +def test_each_check_kind_counts_exactly_the_rows_postgres_would_reject(scratch_database: str) -> None: + with psycopg.connect(scratch_database, autocommit=True) as conn: + conn.execute('CREATE TABLE "preflight_parent" ("id" INTEGER PRIMARY KEY)') + conn.execute('CREATE TABLE "preflight_probe" ("a" TEXT, "b" INTEGER, "r" INTEGER)') + conn.execute('INSERT INTO "preflight_parent" VALUES (1)') + conn.execute( + 'INSERT INTO "preflight_probe" VALUES (%s, 1, 1), (%s, 1, 1), (%s, NULL, 2), (%s, 2, NULL), (%s, 3, 1)', + ("ok", "ok", "bad", "bad", secrets.token_hex(1400)), + ) + checks: Final = tuple( + check + for statement in _PROBE_STATEMENTS + for check in migration_data_checks.checks_for_statement(statement, "probe") + ) + findings: Final = migration_data_checks.find_blockers(conn, "public", checks) + for statement in _PROBE_STATEMENTS: + with conn.transaction(force_rollback=True), pytest.raises(psycopg.Error): + conn.execute(statement) # pyright: ignore[reportArgumentType] # test SQL + + counted: Final = { + (f.check.kind, f.check.columns): f.rows for f in findings if isinstance(f, migration_data_checks.BlockedChange) + } + assert counted == { + ("duplicates", ("b",)): 1, + ("nulls", ("b",)): 1, + ("any_row", ("c",)): 5, + ("orphans", ("r",)): 1, + ("check_violations", ()): 2, + ("too_long", ("a",)): 1, + } + + +@requires_db +@pytest.mark.parametrize( + ("index_columns", "s_value", "t_value", "longest_fitting_key", "described_as"), + ( + (("k", "t"), None, "2025-06-03 14:02:11", 2684, "k up to 2685 bytes"), + (("s", "k"), "q" * 20, None, 2668, "s up to 20 bytes, k up to 2669 bytes"), + (("s", "k"), None, None, 2684, "k up to 2685 bytes"), + ), + ids=("key then timestamp", "20-byte text then key", "NULL then key"), +) +def test_the_entry_size_check_draws_the_line_exactly_where_postgres_does( + scratch_database: str, + index_columns: tuple[str, ...], + s_value: str | None, + t_value: str | None, + longest_fitting_key: int, + described_as: str, +) -> None: + """One row's key is the longest that still fits the index entry, the other's is one byte + longer. Where that line falls depends on the other indexed column, its alignment and the + null bitmap, so the same two rows go through the check and through Postgres.""" + create_index: Final = sql.SQL('CREATE INDEX "entry_probe_idx" ON "entry_probe" ({})').format( + sql.SQL(", ").join(sql.Identifier(column) for column in index_columns) + ) + with psycopg.connect(scratch_database, autocommit=True) as conn: + conn.execute('CREATE TABLE "entry_probe" ("s" TEXT, "k" TEXT, "t" TIMESTAMP(3))') + conn.execute( + 'INSERT INTO "entry_probe" ("s", "k", "t") VALUES (%s, %s, %s), (%s, %s, %s)', + ( + s_value, + secrets.token_hex(longest_fitting_key)[:longest_fitting_key], + t_value, + s_value, + secrets.token_hex(longest_fitting_key)[: longest_fitting_key + 1], + t_value, + ), + ) + findings: Final = migration_data_checks.find_blockers( + conn, "public", migration_data_checks.checks_for_statement(create_index.as_string(conn), "probe") + ) + with pytest.raises(psycopg.errors.ProgramLimitExceeded, match="exceeds btree version 4 maximum 2704"): + conn.execute(create_index) + conn.execute('DELETE FROM "entry_probe" WHERE octet_length("k") > %s', (longest_fitting_key,)) + conn.execute(create_index) + + (finding,) = findings + assert isinstance(finding, migration_data_checks.BlockedChange) + assert finding.rows == 1, "the check must count the row one byte over the line and not the row on it" + assert finding.detail == f"with an index entry over 2704 bytes, largest 2712 bytes ({described_as})" + + +@requires_db +def test_a_scan_that_cannot_finish_in_time_is_reported_as_unverified_rather_than_passed(scratch_database: str) -> None: + with psycopg.connect(scratch_database, autocommit=True) as conn: + conn.execute('CREATE TABLE "preflight_slow" ("a" INTEGER)') + conn.execute('INSERT INTO "preflight_slow" SELECT generate_series(1, 50)') + (check,) = migration_data_checks.checks_for_statement( + 'ALTER TABLE "preflight_slow" ADD CONSTRAINT "slow" CHECK (pg_sleep(0.1) IS NULL)', "probe" + ) + findings: Final = migration_data_checks.find_blockers(conn, "public", (check,), timeout_seconds=0.5) + timeout_afterwards: Final = conn.execute("SHOW statement_timeout").fetchone() + + assert findings == (migration_data_checks.CouldNotVerify(check, 0.5),) + assert timeout_afterwards == ("0",), "the preflight must hand the session back with the timeout it found" + assert "could not be checked within 0.5 s" in migration_data_checks.report(findings) diff --git a/tests/integration/management/test_team_list_v2.py b/tests/integration/management/test_team_list_v2.py index d608d054daa..4c9171310a6 100644 --- a/tests/integration/management/test_team_list_v2.py +++ b/tests/integration/management/test_team_list_v2.py @@ -1,8 +1,8 @@ -from typing import FrozenSet, Optional +from typing import Final, FrozenSet, Optional import pytest -from tests.integration._support.actors import Actor +from tests.integration._support.actors import Actor, ActorSet, GatewayClient pytestmark = pytest.mark.asyncio(loop_scope="session") @@ -139,3 +139,31 @@ async def test_team_list_v2_invalid_status_is_400(gateway_client, actors): headers={"Authorization": f"Bearer {actors.keys[Actor.PROXY_ADMIN].cleartext}"}, ) assert resp.status_code == 400, resp.text + + +async def test_team_list_v2_returns_caller_membership_only_for_members( + gateway_client: GatewayClient, + actors: ActorSet, +) -> None: + member: Final = actors.keys[Actor.TEAM_ADMIN] + member_response: Final = await gateway_client.get( + f"/v2/team/list?team_id={actors.team_alpha_id}&user_id={member.user_id}", + headers={"Authorization": f"Bearer {member.cleartext}"}, + ) + + assert member_response.status_code == 200, member_response.text + member_team: Final = member_response.json()["teams"][0] + assert member_team["caller_membership"] == { + "spend": 0.0, + "max_budget": None, + "budget_reset_at": None, + } + + admin: Final = actors.keys[Actor.PROXY_ADMIN] + admin_response: Final = await gateway_client.get( + f"/v2/team/list?team_id={actors.team_alpha_id}", + headers={"Authorization": f"Bearer {admin.cleartext}"}, + ) + + assert admin_response.status_code == 200, admin_response.text + assert admin_response.json()["teams"][0]["caller_membership"] is None diff --git a/tests/integration/mcp/test_interactions.py b/tests/integration/mcp/test_interactions.py index 8a4bdb8e8ec..5577cf16067 100644 --- a/tests/integration/mcp/test_interactions.py +++ b/tests/integration/mcp/test_interactions.py @@ -93,6 +93,8 @@ def sdk_interaction_peer(*, sampling: bool = False): import queue from contextlib import asynccontextmanager + from integration._support.asgi import asgi_server + from integration._support.mcp import McpPeer, _capturing, _drain_sse_streams from mcp.server import Server from mcp.server.streamable_http_manager import StreamableHTTPSessionManager from mcp.server.transport_security import TransportSecuritySettings @@ -100,27 +102,25 @@ def sdk_interaction_peer(*, sampling: bool = False): CallToolResult, CreateMessageRequest, CreateMessageRequestParams, - SamplingMessage, ElicitRequest, ElicitRequestFormParams, GetPromptResult, InputRequiredResult, - ListToolsResult, ListPromptsResult, ListResourcesResult, + ListToolsResult, Prompt, PromptMessage, ReadResourceResult, Resource, + SamplingMessage, TextContent, TextResourceContents, Tool, ) + from sse_starlette.sse import AppStatus from starlette.applications import Starlette from starlette.routing import Mount - from integration._support.asgi import asgi_server - from integration._support.mcp import McpPeer, _capturing, _drain_sse_streams - from sse_starlette.sse import AppStatus async def tools(ctx, params): return ListToolsResult(tools=[Tool(name="confirm", input_schema={"type": "object"})]) @@ -666,7 +666,7 @@ def test_modern_subscription_delivers_changes_between_calls_and_refreshes_tools( " data = json.loads(Path(__file__).with_suffix('.json').read_text())\n" " change = data.pop('subscription_test_update', None)\n" " if change:\n" - " from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager as manager\n" + " from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager as manager\n" " server = manager.config_mcp_servers['subscription-server']\n" " fields = {'authorization_url': 'https://authorization.example/authorize'} if change == 'metadata' else {'url': server.url.rstrip('/') + '/changed'}\n" " manager.config_mcp_servers[server.server_id] = server.model_copy(update=fields)\n" @@ -1295,9 +1295,9 @@ def test_subscription_partial_setup_releases_upstream_capacity() -> None: from starlette.applications import Starlette from starlette.routing import Mount - from litellm.experimental_mcp_client.client import MCPClient - from litellm.proxy._experimental.mcp_server.contracts import OperationContext - from litellm.proxy._experimental.mcp_server.subscriptions import GatewaySubscriptions, SubscriptionTarget + from litellm.mcp_client.client import MCPClient + from litellm.proxy.mcp_server.contracts import OperationContext + from litellm.proxy.mcp_server.subscriptions import GatewaySubscriptions, SubscriptionTarget from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer as RegisteredServer diff --git a/tests/integration/mcp/test_mcp_oauth_flows.py b/tests/integration/mcp/test_mcp_oauth_flows.py index 327b053d333..90a462472b2 100644 --- a/tests/integration/mcp/test_mcp_oauth_flows.py +++ b/tests/integration/mcp/test_mcp_oauth_flows.py @@ -792,17 +792,23 @@ def _ui_session_cookie(gateway: Gateway, user_id: str) -> dict[str, str]: def _gateway_session_sign_in( - gateway: Gateway, user_id: str, resource: str | None = None + gateway: Gateway, + user_id: str, + resource: str | None = None, + *, + registration_endpoint: str = "/register", + authorization_endpoint: str = "/authorize", + token_endpoint: str = "/token", ) -> tuple[dict[str, object], str]: registered: Final = gateway.client.post( - "/register", json={"redirect_uris": [CLIENT_REDIRECT], "client_name": "integration"} + registration_endpoint, json={"redirect_uris": [CLIENT_REDIRECT], "client_name": "integration"} ) assert registered.status_code in (200, 201), registered.text client_id: Final = str(_response_object(registered)["client_id"]) pkce: Final = _Pkce(secrets.token_urlsafe(48)) cookies: Final = _ui_session_cookie(gateway, user_id) started: Final = gateway.client.get( - "/authorize", + authorization_endpoint, params={ "client_id": client_id, "redirect_uri": CLIENT_REDIRECT, @@ -823,13 +829,14 @@ def _gateway_session_sign_in( callback: Final = parse_qs(urlsplit(completed.headers["location"]).query) assert "code" in callback, completed.headers["location"] issued: Final = gateway.client.post( - "/token", + token_endpoint, data={ "grant_type": "authorization_code", "code": callback["code"][0], "redirect_uri": CLIENT_REDIRECT, "client_id": client_id, "code_verifier": pkce.verifier, + **({} if resource is None else {"resource": resource}), }, ) assert issued.status_code == 200, issued.text @@ -1292,10 +1299,18 @@ def test_lite_logout_revokes_the_cli_refresh_token_sent_the_way_the_cli_sends_it assert completion.status_code == 200, completion.text -def _toolset_rpc(gateway: Gateway, bearer: str, name: str, method: str, params: dict[str, object]) -> Outcome: +def _toolset_rpc( + gateway: Gateway, + bearer: str, + name: str, + method: str, + params: dict[str, object], + *, + route: str = "/toolset/{name}/mcp", +) -> Outcome: def post(rpc_method: str, rpc_params: dict[str, object]) -> httpx.Response: return gateway.client.post( - f"/toolset/{name}/mcp", + route.format(name=name), json={"jsonrpc": "2.0", "id": 1, "method": rpc_method, "params": rpc_params}, headers={"Authorization": f"Bearer {bearer}", "Accept": "application/json, text/event-stream"}, ) @@ -1306,7 +1321,12 @@ def _toolset_rpc(gateway: Gateway, bearer: str, name: str, method: str, params: return _outcome_from_rpc(post(method, params)) -def test_gateway_session_bearer_of_a_team_member_is_served_the_team_toolset_on_its_route(gateway: Gateway) -> None: +@pytest.mark.parametrize("route", ["/toolset/{name}/mcp", "/{name}/mcp"]) +def test_gateway_session_bearer_of_a_team_member_is_served_the_team_toolset_on_its_route( + gateway: Gateway, route: str +) -> None: + from mcp.shared.auth_utils import check_resource_allowed + with mcp_peer() as peer, gateway.scenario() as scenario: alias: Final = "lit6029sess" + uuid.uuid4().hex[:6] server_id: Final = register_mcp(scenario, peer, alias) @@ -1315,19 +1335,69 @@ def test_gateway_session_bearer_of_a_team_member_is_served_the_team_toolset_on_i granted_id: Final = create_toolset(scenario, ((server_id, "add"),), toolset_name=granted_name) create_toolset(scenario, ((server_id, "multiply"),), toolset_name=withheld_name) member: Final = scenario.member(scenario.team(object_permission={"mcp_toolsets": [granted_id]})) - bearer: Final = _gateway_session_bearer(gateway, member) + path: Final = route.format(name=granted_name) + anonymous: Final = gateway.client.post( + path, + headers=ACCEPT, + json={"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": dict(INITIALIZE)}, + ) + assert anonymous.status_code == 401, anonymous.text + metadata_url: Final = anonymous.headers["www-authenticate"].split('resource_metadata="', 1)[1].split('"', 1)[0] + protected: Final = gateway.client.get(metadata_url) + assert protected.status_code == 200, protected.text + protected_body: Final = _response_object(protected) + resource: Final = str(protected_body["resource"]) + assert check_resource_allowed( + requested_resource=f"{_base(gateway)}{path}", configured_resource=resource + ), protected.text + issuers: Final = TypeAdapter(tuple[str, ...]).validate_python(protected_body["authorization_servers"]) + assert len(issuers) == 1, protected.text + issuer: Final = urlsplit(issuers[0]) + authorization: Final = gateway.client.get( + f"{issuer.scheme}://{issuer.netloc}/.well-known/oauth-authorization-server{issuer.path}" + ) + assert authorization.status_code == 200, authorization.text + authorization_body: Final = _response_object(authorization) + assert authorization_body["issuer"] == issuers[0], authorization.text + token_endpoint: Final = str(authorization_body["token_endpoint"]) + issued, client_id = _gateway_session_sign_in( + gateway, + member, + resource, + registration_endpoint=str(authorization_body["registration_endpoint"]), + authorization_endpoint=str(authorization_body["authorization_endpoint"]), + token_endpoint=token_endpoint, + ) + bearer: Final = _issued_token(issued) assert bearer.startswith("llm_session_"), bearer[:16] - listed: Final = _toolset_rpc(gateway, bearer, granted_name, "tools/list", {}) + listed: Final = _toolset_rpc(gateway, bearer, granted_name, "tools/list", {}, route=route) assert listed.tools == (f"{alias}-add",), listed.raw peer.drain() called: Final = _toolset_rpc( - gateway, bearer, granted_name, "tools/call", {"name": f"{alias}-add", "arguments": {"a": 4, "b": 5}} + gateway, bearer, granted_name, "tools/call", + {"name": f"{alias}-add", "arguments": {"a": 4, "b": 5}}, route=route ) assert called.ok and called.text == "9", called.raw assert len(tool_calls(peer.drain())) == 1 - denied: Final = _toolset_rpc(gateway, bearer, withheld_name, "tools/list", {}) + denied: Final = _toolset_rpc(gateway, bearer, withheld_name, "tools/list", {}, route=route) assert denied.status == 403, denied.raw assert tool_calls(peer.drain()) == () + rotated: Final = gateway.client.post( + token_endpoint, + data={ + "grant_type": "refresh_token", + "refresh_token": str(issued["refresh_token"]), + "client_id": client_id, + "resource": resource, + }, + ) + assert rotated.status_code == 200, rotated.text + rotated_body: Final = _response_object(rotated) + assert rotated_body["refresh_token"] != issued["refresh_token"], rotated.text + refreshed: Final = _toolset_rpc( + gateway, _issued_token(rotated_body), granted_name, "tools/list", {}, route=route + ) + assert refreshed.tools == listed.tools, refreshed.raw def test_resource_scoped_session_bearer_opens_a_team_toolset_inside_its_server_and_none_outside( diff --git a/tests/integration/mcp/test_mcp_protocol_errors.py b/tests/integration/mcp/test_mcp_protocol_errors.py index 4930258ec07..d6e5ac66a34 100644 --- a/tests/integration/mcp/test_mcp_protocol_errors.py +++ b/tests/integration/mcp/test_mcp_protocol_errors.py @@ -4,7 +4,6 @@ import uuid from typing import Final import pytest - from integration._support.client import Gateway from integration._support.mcp import McpPeer, call_tool, register_mcp, tool_names from integration._support.wire import Reply, Request, wire_server @@ -98,11 +97,12 @@ def test_configured_revision_blocks_unadvertised_handshake_and_keeps_allowed_con import yaml from integration._support.mcp import mcp_peer from integration._support.process import owned_proxy - from litellm.experimental_mcp_client.client import MCPClient - from litellm.types.mcp import MCPTransport from mcp import MCPError from mcp.types import CallToolRequestParams + from litellm.mcp_client.client import MCPClient + from litellm.types.mcp import MCPTransport + with mcp_peer() as upstream, gateway.scenario() as scenario: alias: Final = "restricted" + uuid.uuid4().hex[:8] identity: Final = register_mcp(scenario, upstream, alias) diff --git a/tests/integration/mcp/test_mcp_transports.py b/tests/integration/mcp/test_mcp_transports.py index ef240cba570..92fcf37994e 100644 --- a/tests/integration/mcp/test_mcp_transports.py +++ b/tests/integration/mcp/test_mcp_transports.py @@ -8,7 +8,6 @@ from typing import Final import httpx import pytest import yaml -from mcp.shared.exceptions import MCPError from integration._support.client import Gateway from integration._support.database import read_rows from integration._support.mcp import ( @@ -34,6 +33,7 @@ from integration._support.mcp import ( ) from integration._support.mcp_grants import create_toolset from integration._support.process import owned_proxy +from mcp.shared.exceptions import MCPError ADD: Final = {"http": "add", "sse": "add", "stdio": "add", "openapi": "getpet"} ARGUMENTS: Final = {"add": {"a": 3, "b": 4}, "getpet": {"petId": "7"}} @@ -571,7 +571,7 @@ def test_pinned_revision_pairs_list_and_call_through_gateway( from mcp.types import CallToolRequestParams - from litellm.experimental_mcp_client.client import MCPClient + from litellm.mcp_client.client import MCPClient from litellm.types.mcp import MCPTransport with peer_of(peer_kind) as peer, gateway.scenario() as scenario: @@ -616,7 +616,7 @@ def test_legacy_gateway_calls_modern_upstream_without_initialize( from mcp.types import CallToolRequestParams - from litellm.experimental_mcp_client.client import MCPClient + from litellm.mcp_client.client import MCPClient from litellm.types.mcp import MCPTransport with peer_of(peer_kind) as peer, gateway.scenario() as scenario: @@ -661,13 +661,16 @@ def test_sdk_progress_and_cancellation_reach_upstream_without_losing_session( ) -> None: import asyncio import os + from contextlib import asynccontextmanager from pathlib import Path from threading import Event - from contextlib import asynccontextmanager import httpx import httpx2 import yaml + from integration._support.asgi import asgi_server + from integration._support.mcp import _drain_sse_streams + from integration._support.process import owned_proxy from mcp import ClientSession, MCPError from mcp.client.streamable_http import streamable_http_client from mcp.server.mcpserver import Context, MCPServer @@ -677,10 +680,6 @@ def test_sdk_progress_and_cancellation_reach_upstream_without_losing_session( from starlette.applications import Starlette from starlette.routing import Mount - from integration._support.asgi import asgi_server - from integration._support.mcp import _drain_sse_streams - from integration._support.process import owned_proxy - upstream: Final = MCPServer("progress-cancellation-peer") started: Final = Event() stopped: Final = Event() diff --git a/tests/integration/mcp/test_pagination.py b/tests/integration/mcp/test_pagination.py index e52757ec19a..aa464eca30e 100644 --- a/tests/integration/mcp/test_pagination.py +++ b/tests/integration/mcp/test_pagination.py @@ -6,14 +6,14 @@ from typing import Final, Literal import httpx import pytest import yaml +from integration._support.client import Gateway +from integration._support.mcp import McpPeer, paginated_mcp_peer +from integration._support.process import owned_proxy from mcp import ClientSession, MCPError from mcp.client.streamable_http import streamable_http_client from mcp.types import CallToolRequest, CallToolRequestParams, CallToolResult, DiscoverResult, PaginatedRequestParams -from integration._support.client import Gateway -from integration._support.mcp import McpPeer, paginated_mcp_peer -from integration._support.process import owned_proxy -from litellm.experimental_mcp_client.client import MCPClient +from litellm.mcp_client.client import MCPClient from litellm.types.mcp import MCPTransport @@ -422,7 +422,7 @@ def test_failed_upstream_continuation_requires_restart_for_every_catalog(tmp_pat @pytest.mark.parametrize("foreign", [{"foreign": {"status": "error", "message": "foreign outcome"}}, "malformed"]) def test_optional_catalog_ignores_upstream_gateway_outcomes(tmp_path: Path, foreign): - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY + from litellm.proxy.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY async def exercise(gateway): async with catalog_session(gateway) as session: @@ -577,7 +577,8 @@ def test_aggregate_freshness_matches_real_upstream() -> None: ListToolsRequest, ListToolsResult, ) - from litellm.proxy._experimental.mcp_server.catalog import combine_optional_catalog, list_tools_page + + from litellm.proxy.mcp_server.catalog import combine_optional_catalog, list_tools_page async def exercise(peer: McpPeer) -> None: client: Final = MCPClient(server_url=peer.url, transport_type=MCPTransport.http, protocol_version="2026-07-28") @@ -604,8 +605,8 @@ def test_aggregate_freshness_matches_real_upstream() -> None: @pytest.mark.parametrize("ttl_ms", [0, 9000]) def test_discovery_cache_freshness_and_caller_isolation_over_http(ttl_ms: int) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp_server.mcp_server_manager import MCPServer async def exercise(peer: McpPeer) -> None: diff --git a/tests/integration/mcp/test_proxy_mcp_e2e.py b/tests/integration/mcp/test_proxy_mcp_e2e.py index 2f690463143..6fb8d284016 100644 --- a/tests/integration/mcp/test_proxy_mcp_e2e.py +++ b/tests/integration/mcp/test_proxy_mcp_e2e.py @@ -31,8 +31,8 @@ from starlette.requests import Request import litellm from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER -from litellm.proxy._experimental.mcp_server.tool_search import handle_mcp_proxy_tool from litellm.proxy._types import LiteLLM_ObjectPermissionTable, ProxyException, UserAPIKeyAuth +from litellm.proxy.mcp_server.tool_search import handle_mcp_proxy_tool from litellm.proxy.proxy_server import ( app as proxy_app, ) @@ -41,11 +41,11 @@ from litellm.proxy.proxy_server import ( initialize, ) from tests._master_key import MASTER_KEY +from tests.integration._support.ports import allocate_port from tests.integration._support.process import stop_child from tests.integration._support.timing import assert_enforced_within from tests.integration._support.wire import Reply, Wire, wire_server from tests.integration._support.wire import Request as WireRequest -from tests.integration._support.ports import allocate_port CONFIG_TEMPLATE_PATH = Path("tests/integration/mcp/_config_mcp_e2e.yaml") MCP_SERVER_SCRIPT = Path("tests/integration/mcp/_math_server.py") @@ -86,7 +86,7 @@ async def drain_logging_worker() -> typing.AsyncIterator[None]: async def test_schema_validation_stops_expensive_work_and_recovers(cancel: bool, concurrency: int) -> None: import psutil - from litellm.proxy._experimental.mcp_server.tool_search import ( + from litellm.proxy.mcp_server.tool_search import ( _VALIDATION_TIMEOUT_SECONDS, _tool_argument_validation_error, ) @@ -246,8 +246,8 @@ def _clear_proxy_database_env() -> typing.Iterator[None]: async def _initialize_proxy(config_path: str) -> None: - from litellm.proxy._experimental.mcp_server.catalog import CatalogSnapshots - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.catalog import CatalogSnapshots + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager cleanup_router_config_variables() global_mcp_server_manager.catalog = CatalogSnapshots(global_mcp_server_manager) @@ -307,7 +307,7 @@ def _start_proxy_server( failure: Final[Future[BaseException | None]] = Future() async def _serve() -> None: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server await _initialize_proxy(config_path) async with proxy_app.router.lifespan_context(proxy_app), mcp_server.lifespan(proxy_app): diff --git a/tests/integration/mcp_coverage.toml b/tests/integration/mcp_coverage.toml index daa782eade2..439fac10169 100644 --- a/tests/integration/mcp_coverage.toml +++ b/tests/integration/mcp_coverage.toml @@ -4,10 +4,10 @@ core = "sysmon" parallel = true relative_files = true include = [ - "litellm/proxy/_experimental/mcp_server/*", + "litellm/proxy/mcp_server/*", "litellm/proxy/management_endpoints/mcp_management_endpoints.py", "litellm/responses/mcp/*", - "litellm/experimental_mcp_client/*", + "litellm/mcp_client/*", "litellm/proxy/guardrails/guardrail_hooks/mcp_*", ] diff --git a/tests/integration/messages_endpoint/chat_bridge/test_chat_bridge_disconnect_wire.py b/tests/integration/messages_endpoint/chat_bridge/test_chat_bridge_disconnect_wire.py new file mode 100644 index 00000000000..100e760d5be --- /dev/null +++ b/tests/integration/messages_endpoint/chat_bridge/test_chat_bridge_disconnect_wire.py @@ -0,0 +1,232 @@ +import asyncio +import json +from collections.abc import AsyncGenerator, AsyncIterator +from contextlib import ExitStack, asynccontextmanager +from dataclasses import dataclass, field +from enum import Enum +from pathlib import Path +from typing import Final +from urllib.parse import urlsplit + +import httpx +import pytest +import pytest_asyncio +import yaml +from aiohttp import web + +from tests.integration._support.anthropic_sse import LIFECYCLE, delta_text, event_types, parse_sse, user_prompt +from tests.integration._support.client import JSON_OBJECT, Gateway +from tests.integration._support.openai_wire import chat_stream +from tests.integration._support.ports import allocate_port +from tests.integration._support.process import OwnedProxy, owned_proxy_process, paused + +_MODEL: Final = "disconnect-repro" +_KEY: Final = "sk-integration-master-key" +_DEADLINE: Final = 10 +_RACE_ATTEMPTS: Final = 20 + + +class _Mode(Enum): + OCCUPY = "occupy" + QUEUED = "queued" + CONTENT = "content" + COMPLETE = "complete" + + +@dataclass(frozen=True, slots=True) +class _Request: + mode: _Mode + headers_allowed: asyncio.Event = field(default_factory=asyncio.Event) + headers_sent: asyncio.Event = field(default_factory=asyncio.Event) + running: asyncio.Event = field(default_factory=asyncio.Event) + released: asyncio.Event = field(default_factory=asyncio.Event) + + +@dataclass(frozen=True, slots=True) +class _Backend: + url: str + requests: asyncio.Queue[_Request] + runner: web.AppRunner + + +@pytest_asyncio.fixture(loop_scope="function") +async def backend() -> AsyncIterator[_Backend]: + requests: Final[asyncio.Queue[_Request]] = asyncio.Queue() + worker: Final = asyncio.Semaphore(1) + + async def complete(request: web.Request) -> web.StreamResponse: + body: Final = JSON_OBJECT.validate_json(await request.read()) + assert body["model"] == "test-model" and body["stream"] is True, body + assert request.headers["Authorization"] == "Bearer integration-provider-key" + pending: Final = _Request(_Mode(user_prompt(body))) + await requests.put(pending) + response: Final = web.StreamResponse(headers={"Content-Type": "text/event-stream"}) + try: + await pending.headers_allowed.wait() + await response.prepare(request) + pending.headers_sent.set() + async with worker: + pending.running.set() + chunks: Final = chat_stream("chatcmpl-disconnect", "test-model", "hello") + if pending.mode in (_Mode.CONTENT, _Mode.COMPLETE): + for chunk in chunks[:2]: + await response.write(chunk) + if pending.mode is _Mode.COMPLETE: + await response.write(chunks[2]) + await response.write_eof() + else: + await asyncio.Event().wait() + finally: + pending.released.set() + return response + + app: Final = web.Application() + app.router.add_post("/v1/chat/completions", complete) + runner: Final = web.AppRunner(app, handler_cancellation=True, shutdown_timeout=0.1) + await runner.setup() + port: Final = allocate_port() + await web.TCPSite(runner, "127.0.0.1", port).start() + try: + yield _Backend(f"http://127.0.0.1:{port}", requests, runner) + finally: + await runner.cleanup() + + +@pytest_asyncio.fixture(loop_scope="function") +async def proxy(backend: _Backend, tmp_path: Path) -> AsyncIterator[OwnedProxy]: + config: Final = tmp_path / "disconnect.yaml" + config.write_text( + yaml.safe_dump( + { + "model_list": [ + { + "model_name": _MODEL, + "litellm_params": { + "model": "custom_openai/test-model", + "api_base": backend.url + "/v1", + "api_key": "integration-provider-key", + }, + } + ], + "litellm_settings": {"anthropic_sse_ping_interval_seconds": 0}, + "router_settings": {"num_retries": 0}, + "general_settings": {"dangerously_permit_weak_or_unset_master_key": True}, + } + ) + ) + with httpx.Client() as client: + template: Final = Gateway(client, _KEY, backend.url) + with owned_proxy_process( + template, + tmp_path, + {"STORE_MODEL_IN_DB": "False"}, + config=config, + database_setup=(), + remove_environment=("DATABASE_URL", "DATABASE_URL_READ_REPLICA", "REDIS_HOST", "REDIS_PORT"), + ) as owned: + try: + yield owned + finally: + await backend.runner.cleanup() + + +def _body(mode: _Mode) -> bytes: + return json.dumps( + {"model": _MODEL, "stream": True, "max_tokens": 16, "messages": [{"role": "user", "content": mode.value}]} + ).encode() + + +@asynccontextmanager +async def _request( + proxy: OwnedProxy, mode: _Mode, endpoint: str = "/v1/messages" +) -> AsyncGenerator[asyncio.StreamReader, None]: + address: Final = urlsplit(str(proxy.gateway.client.base_url)) + reader, writer = await asyncio.open_connection(address.hostname, address.port) + body: Final = _body(mode) + writer.write( + f"POST {endpoint} HTTP/1.1\r\nHost: localhost\r\nAuthorization: Bearer {_KEY}\r\n" + f"Content-Type: application/json\r\nContent-Length: {len(body)}\r\n\r\n".encode() + + body + ) + await writer.drain() + try: + yield reader + finally: + writer.close() + await writer.wait_closed() + + +async def _next(backend: _Backend, mode: _Mode) -> _Request: + pending: Final = await asyncio.wait_for(backend.requests.get(), _DEADLINE) + assert pending.mode is mode + return pending + + +async def _headers(pending: _Request) -> None: + pending.headers_allowed.set() + await asyncio.wait_for(pending.headers_sent.wait(), _DEADLINE) + + +async def _released(pending: _Request) -> None: + try: + await asyncio.wait_for(pending.released.wait(), _DEADLINE) + except TimeoutError: + pytest.fail(f"Backend {pending.mode.value} request still active after client disconnect", pytrace=False) + + +async def _disconnect_queued_request(backend: _Backend, proxy: OwnedProxy) -> None: + with ExitStack() as scheduling: + async with _request(proxy, _Mode.QUEUED): + queued: Final = await _next(backend, _Mode.QUEUED) + scheduling.enter_context(paused(proxy.process)) + await _headers(queued) + assert not queued.running.is_set() + await _released(queued) + assert backend.requests.empty(), "Disconnect must not trigger another upstream request" + + +async def test_disconnect_with_upstream_headers_pending_releases_queued_request( + backend: _Backend, proxy: OwnedProxy +) -> None: + """Hold headers and the client FIN ready together without patching proxy code.""" + async with _request(proxy, _Mode.OCCUPY): + occupied: Final = await _next(backend, _Mode.OCCUPY) + await _headers(occupied) + await asyncio.wait_for(occupied.running.wait(), _DEADLINE) + for attempt in range(_RACE_ATTEMPTS): + await _disconnect_queued_request(backend, proxy) + assert not occupied.released.is_set(), attempt + await _released(occupied) + + +@pytest.mark.parametrize("endpoint", ["/v1/messages", "/v1/chat/completions"]) +async def test_disconnect_after_content_releases_upstream(backend: _Backend, proxy: OwnedProxy, endpoint: str) -> None: + async with _request(proxy, _Mode.CONTENT, endpoint) as response: + pending: Final = await _next(backend, _Mode.CONTENT) + await _headers(pending) + received: Final = await asyncio.wait_for(response.readuntil(b'"hello"'), _DEADLINE) + assert b"200 OK" in received + if endpoint == "/v1/messages": + assert b"content_block_delta" in received + await _released(pending) + assert backend.requests.empty(), "Disconnect must not trigger another upstream request" + + +async def test_messages_stream_completes_with_unchanged_events(backend: _Backend, proxy: OwnedProxy) -> None: + async with httpx.AsyncClient(base_url=str(proxy.gateway.client.base_url), trust_env=False) as client: + response_task: Final = asyncio.create_task( + client.post( + "/v1/messages", + headers={"Authorization": f"Bearer {_KEY}", "Content-Type": "application/json"}, + content=_body(_Mode.COMPLETE), + ) + ) + pending: Final = await _next(backend, _Mode.COMPLETE) + await _headers(pending) + response: Final = await asyncio.wait_for(response_task, _DEADLINE) + assert response.status_code == 200, response.text + events: Final = parse_sse(response.text) + assert event_types(events) == LIFECYCLE + assert delta_text(events) == "hello" + assert pending.released.is_set() + assert backend.requests.empty(), "Successful streaming must not trigger another upstream request" diff --git a/tests/integration/messages_endpoint/test_guardrail_long_tool_names_wire.py b/tests/integration/messages_endpoint/test_guardrail_long_tool_names_wire.py index 8842e04db6b..89a388423e0 100644 --- a/tests/integration/messages_endpoint/test_guardrail_long_tool_names_wire.py +++ b/tests/integration/messages_endpoint/test_guardrail_long_tool_names_wire.py @@ -14,7 +14,7 @@ from integration._support.ports import allocate_port from integration._support.wire import Reply, Request, Wire, wire_server from pydantic import JsonValue, TypeAdapter -from litellm.llms.anthropic.pass_through.adapters.transformation import truncate_tool_name +from litellm.llms.anthropic.messages.adapters.transformation import truncate_tool_name _JSON_OBJECT: Final = TypeAdapter(dict[str, JsonValue]) _JSON_OBJECTS: Final = TypeAdapter(list[dict[str, JsonValue]]) diff --git a/tests/integration/observability/test_langfuse_otel_trace_fields.py b/tests/integration/observability/test_langfuse_otel_trace_fields.py new file mode 100644 index 00000000000..2b78b402926 --- /dev/null +++ b/tests/integration/observability/test_langfuse_otel_trace_fields.py @@ -0,0 +1,660 @@ +import json +import threading +import uuid +from itertools import product +from collections.abc import Iterator, Mapping, Sequence +from dataclasses import dataclass +from pathlib import Path +from typing import Final + +import pytest +import yaml +from _s3_v2_support import SURFACES, call_surface, mixed_burst, surface_reply +from integration._support.client import Gateway, eventually, gateway_from_environment +from integration._support.process import owned_proxy +from integration._support.wire import Reply, Request, wire_server +from opentelemetry.proto.collector.trace.v1.trace_service_pb2 import ExportTraceServiceRequest +from opentelemetry.proto.common.v1.common_pb2 import AnyValue +from opentelemetry.proto.trace.v1.trace_pb2 import Span + +REDACTED: Final = "redacted-by-litellm" +TRACE_FIELDS: Final = ("langfuse.trace.name", "langfuse.trace.input", "langfuse.trace.output", "langfuse.trace.tags") +SURFACE_CALL_TYPES: Final = { + "chat": "acompletion", + "chat_stream": "acompletion", + "messages": "anthropic_messages", + "messages_stream": "anthropic_messages", + "responses": "aresponses", + "responses_stream": "aresponses", +} +ANTHROPIC_MODEL: Final = "anthropic/claude-sonnet-4-5-20250929" +JUDGE_MODEL: Final = "lit8281-judge-model" +JUDGE_GUARDRAIL: Final = "lit8281-judge" + + +@dataclass(frozen=True, slots=True) +class SpanRecord: + name: str + trace_id: str + parent_span_id: str + attributes: Mapping[str, object] + dropped_attributes: int = 0 + + def tags(self) -> tuple[object, ...]: + raw: Final = self.attributes.get("langfuse.trace.tags") + if isinstance(raw, tuple): + return raw + if not isinstance(raw, str) or not raw: + return () + if raw.strip().startswith("["): + return tuple(json.loads(raw)) + return tuple(tag.strip() for tag in raw.split(",")) if "," in raw else (raw,) + + +def _attribute_value(value: AnyValue) -> object: + kind: Final = value.WhichOneof("value") + if kind == "array_value": + return tuple(_attribute_value(item) for item in value.array_value.values) + return getattr(value, kind) if kind is not None else None + + +def _exported_spans(body: bytes) -> Iterator[Span]: + for resource in ExportTraceServiceRequest.FromString(body).resource_spans: + for scope in resource.scope_spans: + yield from scope.spans + + +def _span_records(body: bytes) -> tuple[SpanRecord, ...]: + return tuple( + SpanRecord( + name=span.name, + trace_id=span.trace_id.hex(), + parent_span_id=span.parent_span_id.hex(), + attributes={pair.key: _attribute_value(pair.value) for pair in span.attributes}, + dropped_attributes=span.dropped_attributes_count, + ) + for span in _exported_spans(body) + ) + + +class LangfuseSink: + def __init__(self) -> None: + self.lock: Final = threading.Lock() + self.outage: Final = threading.Event() + self.accepted: Final[list[SpanRecord]] = [] # mutable-ok: spans accumulate as the exporter delivers them + self.roots: Final[list[SpanRecord]] = [] # mutable-ok: root spans accumulate as the exporter delivers them + self.spans: Final[list[SpanRecord]] = [] # mutable-ok: every span accumulates as the exporter delivers it + self.refusals: Final[list[int]] = [] # mutable-ok: one entry per batch refused during the outage + + def respond(self, request: Request) -> Reply: + if not request.target.endswith("/v1/traces"): + return Reply(body=b"") + assert request.headers.get("x-langfuse-ingestion-version") == "4", request.headers + if self.outage.is_set(): + with self.lock: + self.refusals.append(1) + return Reply(status=503, body=b'{"error": "scripted outage"}') + records: Final = _span_records(request.body) + with self.lock: + self.accepted.extend( + record for record in records if record.attributes.get("langfuse.observation.type") == "generation" + ) + self.roots.extend(record for record in records if not record.parent_span_id) + self.spans.extend(records) + return Reply(body=b"") + + def matching(self, marker: str) -> tuple[SpanRecord, ...]: + with self.lock: + snapshot: Final = tuple(self.accepted) + return tuple(record for record in snapshot if marker in str(tuple(record.attributes.values()))) + + def one(self, marker: str) -> SpanRecord: + return eventually(lambda: self.matching(marker), lambda found: len(found) == 1, seconds=70)[0] + + def in_trace(self, trace_id: str) -> tuple[SpanRecord, ...]: + with self.lock: + return tuple(record for record in self.spans if record.trace_id == trace_id) + + def root_of(self, span: SpanRecord) -> SpanRecord: + def roots() -> tuple[SpanRecord, ...]: + with self.lock: + return tuple(root for root in self.roots if root.trace_id == span.trace_id) + + return eventually(roots, lambda found: len(found) == 1, seconds=70)[0] + + +class OtlpSink: + def __init__(self) -> None: + self.lock: Final = threading.Lock() + self.spans: Final[list[SpanRecord]] = [] # mutable-ok: spans accumulate as the exporter delivers them + + def respond(self, request: Request) -> Reply: + if request.target.endswith("/v1/traces"): + records: Final = _span_records(request.body) + with self.lock: + self.spans.extend(records) + return Reply(body=b"") + + def root_of_request(self, marker: str) -> SpanRecord: + + def roots() -> tuple[SpanRecord, ...]: + with self.lock: + snapshot: Final = tuple(self.spans) + traces: Final = {record.trace_id for record in snapshot if marker in str(tuple(record.attributes.values()))} + return tuple(record for record in snapshot if record.trace_id in traces and not record.parent_span_id) + + return eventually(roots, lambda found: len(found) == 1, seconds=70)[0] + + +def _chat_completion(marker: str, text: str = "langfuse-otel scripted reply") -> bytes: + return json.dumps( + { + "id": marker, + "object": "chat.completion", + "created": 1, + "model": "gpt-4o-mini", + "choices": [{"index": 0, "message": {"role": "assistant", "content": text}, "finish_reason": "stop"}], + "usage": {"prompt_tokens": 5, "completion_tokens": 4, "total_tokens": 9}, + } + ).encode() + + +def _provider(request: Request) -> Reply: + if request.method != "POST" or not request.body: + return Reply(body=b'{"object": "list", "data": []}') + body: Final = json.loads(request.body) + if request.target.endswith("/embeddings"): + return Reply( + body=json.dumps( + { + "object": "list", + "data": [{"object": "embedding", "index": 0, "embedding": [0.25, 0.5]}], + "model": "text-embedding-3-small", + "usage": {"prompt_tokens": 3, "total_tokens": 3}, + } + ).encode() + ) + if body.get("response_format") == {"type": "json_object"}: + return Reply(body=_chat_completion("lit8281-judge-verdict", json.dumps({"overall_score": 100}))) + messages: Final = body.get("messages") + first: Final = messages[0]["content"] if isinstance(messages, list) and messages else None + if isinstance(first, str) and first.startswith("fail-"): + return Reply(status=500, body=b'{"error": {"message": "scripted provider failure", "type": "server_error"}}') + return surface_reply(request) + + +def _langfuse_config(directory: Path, name: str, settings: Mapping[str, object], provider_url: str) -> Path: + base: Final = yaml.safe_load(Path("tests/integration/proxy_config.yaml").read_text()) + judge: Final = { + "model_name": JUDGE_MODEL, + "litellm_params": { + "model": "openai/gpt-4o-mini", + "api_base": provider_url + "/v1", + "api_key": "synthetic-provider-key", + }, + } + config: Final = { + **base, + "model_list": [*base["model_list"], judge], + "guardrails": [ + { + "guardrail_name": JUDGE_GUARDRAIL, + "litellm_params": { + "guardrail": "llm_as_a_judge", + "mode": "post_call", + "judge_model": JUDGE_MODEL, + "on_failure": "log", + "criteria": [{"name": "helpful", "description": "The reply answers the user", "weight": 100}], + }, + } + ], + "litellm_settings": {**base["litellm_settings"], "callbacks": ["langfuse_otel"], **settings}, + } + path: Final = directory / f"{name}.yaml" + path.write_text(yaml.safe_dump(config)) + return path + + +@dataclass(frozen=True, slots=True) +class Rig: + proxy: Gateway + sink: LangfuseSink + openai_model: str + anthropic_model: str + embedding_model: str + key: str + + +def _rig( + tmp_path_factory: pytest.TempPathFactory, name: str, environment: Mapping[str, str], settings: Mapping[str, object] +) -> Iterator[Rig]: + directory: Final = tmp_path_factory.mktemp(name) + sink: Final = LangfuseSink() + with ( + wire_server(sink.respond) as destination, + wire_server(_provider) as provider, + gateway_from_environment() as gateway, + owned_proxy( + gateway, + directory, + { + "LANGFUSE_PUBLIC_KEY": "pk-lf-test", + "LANGFUSE_SECRET_KEY": "sk-lf-test", + "LANGFUSE_HOST": destination.url, + **environment, + }, + config=_langfuse_config(directory, name, settings, provider.url), + workers=2, + ) as proxy, + proxy.scenario() as scenario, + ): + openai_model: Final = scenario.model(api_base=provider.url + "/v1", api_key="synthetic-provider-key") + anthropic_model: Final = scenario.model( + model=ANTHROPIC_MODEL, api_base=provider.url, api_key="synthetic-provider-key" + ) + embedding_model: Final = scenario.model( + model="openai/text-embedding-3-small", + api_base=provider.url + "/v1", + api_key="synthetic-provider-key", + model_info={"mode": "embedding"}, + ) + key: Final = scenario.key(models=[openai_model, anthropic_model, embedding_model]) + yield Rig(proxy, sink, openai_model, anthropic_model, embedding_model, key) + + +SPAN_ATTRIBUTE_LIMIT: Final = 128 + + +@pytest.fixture(scope="module") +def v1(tmp_path_factory: pytest.TempPathFactory) -> Iterator[Rig]: + yield from _rig( + tmp_path_factory, + "langfuse-v1", + {"OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT": str(SPAN_ATTRIBUTE_LIMIT)}, + {"langfuse_default_tags": ["cache_hit"]}, + ) + + +V2_ENVIRONMENT: Final = {"LITELLM_OTEL_V2": "1", "OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT": "span_only"} + + +@pytest.fixture(scope="module") +def v2(tmp_path_factory: pytest.TempPathFactory) -> Iterator[Rig]: + yield from _rig(tmp_path_factory, "langfuse-v2", V2_ENVIRONMENT, {}) + + +@pytest.fixture(scope="module") +def v2_llm_only(tmp_path_factory: pytest.TempPathFactory) -> Iterator[Rig]: + yield from _rig( + tmp_path_factory, "langfuse-v2-llm-only", {**V2_ENVIRONMENT, "LITELLM_OTEL_LANGFUSE_SPAN_SCOPE": "llm_only"}, {} + ) + + +@dataclass(frozen=True, slots=True) +class SharedRig: + rig: Rig + otel: OtlpSink + + +@pytest.fixture(scope="module") +def v2_after_otel(tmp_path_factory: pytest.TempPathFactory) -> Iterator[SharedRig]: + otel: Final = OtlpSink() + with wire_server(otel.respond) as destination: + environment: Final = { + **V2_ENVIRONMENT, + "OTEL_EXPORTER": "otlp_http", + "OTEL_ENDPOINT": destination.url + "/v1/traces", + } + for rig in _rig( + tmp_path_factory, "langfuse-v2-after-otel", environment, {"callbacks": ["otel", "langfuse_otel"]} + ): + yield SharedRig(rig, otel) + + +def _chat( + rig: Rig, + content: str, + metadata: Mapping[str, object] | None = None, + headers: Mapping[str, str] | None = None, + guardrails: Sequence[str] = (), +) -> str: + response: Final = rig.proxy.request( + "POST", + "/v1/chat/completions", + { + "model": rig.openai_model, + "messages": [{"role": "user", "content": content}], + **({"metadata": dict(metadata)} if metadata is not None else {}), + **({"guardrails": list(guardrails)} if guardrails else {}), + }, + key=rig.key, + headers=headers, + ) + assert response.status_code == 200, response.text + return response.text + + +def _trace_fields(spans: tuple[SpanRecord, ...]) -> Iterator[str]: + for record in spans: + yield from (key for key in record.attributes if key in TRACE_FIELDS) + + +def _assert_derived(span: SpanRecord, call_type: str) -> None: + attributes: Final = span.attributes + assert attributes.get("langfuse.trace.name") == f"litellm-{call_type}", attributes + assert attributes.get("langfuse.trace.input") == attributes.get("langfuse.observation.input"), attributes + assert attributes.get("langfuse.trace.output") == attributes.get("langfuse.observation.output"), attributes + tags: Final = span.tags() + assert any(str(tag).startswith("User-Agent: ") for tag in tags), tags + assert len(tags) == len(set(map(str, tags))), tags + + +@pytest.mark.parametrize("surface", SURFACES) +def test_every_surface_derives_trace_name_io_and_tags(v1: Rig, surface: str) -> None: + marker: Final = f"lit8281-{surface}-{uuid.uuid4().hex}" + call_surface(v1.proxy, surface, v1.openai_model, v1.anthropic_model, v1.key, marker) + span: Final = v1.sink.one(marker) + _assert_derived(span, SURFACE_CALL_TYPES[surface]) + assert marker in str(span.attributes["langfuse.trace.input"]), span.attributes + assert span.attributes.get("langfuse.trace.output") is not None, span.attributes + assert any(str(tag).startswith("cache_hit:") for tag in span.tags()), span.tags() + + +def test_inbound_traceparent_joins_the_caller_trace_without_derived_trace_fields(v1: Rig) -> None: + marker: Final = "lit8281-parent-" + uuid.uuid4().hex + trace_id: Final = uuid.uuid4().hex + parent_id: Final = uuid.uuid4().hex[:16] + _chat(v1, marker, headers={"traceparent": f"00-{trace_id}-{parent_id}-01"}) + span: Final = v1.sink.one(marker) + assert (span.trace_id, span.parent_span_id) == (trace_id, parent_id), span + assert not set(TRACE_FIELDS) & set(span.attributes), span.attributes + assert marker in str(span.attributes.get("langfuse.observation.input")), span.attributes + assert span.attributes.get("langfuse.observation.output") is not None, span.attributes + + +def test_inbound_traceparent_still_carries_the_caller_trace_name_and_tags(v1: Rig) -> None: + marker: Final = "lit8281-parent-caller-" + uuid.uuid4().hex + trace_id: Final = uuid.uuid4().hex + _chat( + v1, + marker, + metadata={"trace_name": "caller-trace", "tags": ["caller-tag"]}, + headers={"traceparent": f"00-{trace_id}-{uuid.uuid4().hex[:16]}-01"}, + ) + span: Final = v1.sink.one(marker) + assert span.trace_id == trace_id, span + assert span.attributes.get("langfuse.trace.name") == "caller-trace", span.attributes + assert span.tags() == ("caller-tag",), span.attributes + assert not {"langfuse.trace.input", "langfuse.trace.output"} & set(span.attributes), span.attributes + + +def test_caller_trace_name_and_tags_win_over_derived_values(v1: Rig) -> None: + marker: Final = "lit8281-caller-" + uuid.uuid4().hex + _chat(v1, marker, metadata={"trace_name": "caller-trace", "tags": ["caller-tag", "second-tag"]}) + span: Final = v1.sink.one(marker) + assert span.attributes["langfuse.trace.name"] == "caller-trace", span.attributes + assert span.tags()[:2] == ("caller-tag", "second-tag"), span.tags() + assert span.attributes.get("langfuse.trace.input") == span.attributes.get("langfuse.observation.input") + + +@pytest.mark.parametrize( + ("metadata", "headers", "expected"), + [ + pytest.param({"tags": "c1, c2"}, None, ("c1", "c2"), id="body_comma_string"), + pytest.param({"tags": '["j1", "j2"]'}, None, ("j1", "j2"), id="body_json_array_string"), + pytest.param(None, {"langfuse_tags": "h1,h2"}, ("h1", "h2"), id="header_comma_string"), + ], +) +def test_string_caller_tags_keep_the_tags_langfuse_split_them_into( + v1: Rig, metadata: Mapping[str, object] | None, headers: Mapping[str, str] | None, expected: tuple[str, ...] +) -> None: + marker: Final = "lit8281-strtags-" + uuid.uuid4().hex + _chat(v1, marker, metadata=metadata, headers=headers) + span: Final = v1.sink.one(marker) + assert span.tags()[: len(expected)] == expected, span.attributes + + +def test_trace_name_header_wins_over_the_derived_name(v1: Rig) -> None: + marker: Final = "lit8281-header-" + uuid.uuid4().hex + _chat(v1, marker, headers={"langfuse_trace_name": "header-trace"}) + span: Final = v1.sink.one(marker) + assert span.attributes["langfuse.trace.name"] == "header-trace", span.attributes + + +def test_joined_trace_keeps_caller_tags_and_gets_no_derived_trace_fields(v1: Rig) -> None: + marker: Final = "lit8281-join-" + uuid.uuid4().hex + existing: Final = uuid.uuid4().hex + _chat(v1, marker, metadata={"existing_trace_id": existing, "tags": ["join-tag"]}) + span: Final = v1.sink.one(marker) + attributes: Final = span.attributes + assert attributes.get("langfuse.trace.existing_id") == existing, attributes + assert span.tags() == ("join-tag",), attributes + assert "langfuse.trace.name" not in attributes, attributes + assert "langfuse.trace.input" not in attributes, attributes + assert "langfuse.trace.output" not in attributes, attributes + assert marker in str(attributes.get("langfuse.observation.input")), attributes + + +def test_joined_trace_without_caller_tags_gets_no_trace_tags(v1: Rig) -> None: + marker: Final = "lit8281-join-bare-" + uuid.uuid4().hex + _chat(v1, marker, metadata={"existing_trace_id": uuid.uuid4().hex}) + attributes: Final = v1.sink.one(marker).attributes + assert not { + key for key in attributes if key.startswith("langfuse.trace.") and key != "langfuse.trace.existing_id" + }, attributes + + +def test_mask_flags_redact_the_derived_trace_io(v1: Rig) -> None: + marker: Final = "lit8281-mask-" + uuid.uuid4().hex + _chat(v1, marker, metadata={"mask_input": True, "mask_output": True}) + attributes: Final = v1.sink.one(marker).attributes + assert attributes.get("langfuse.trace.input") == REDACTED, attributes + assert attributes.get("langfuse.trace.output") == REDACTED, attributes + assert attributes.get("langfuse.trace.name") == "litellm-acompletion", attributes + + +@pytest.mark.parametrize( + ("headers", "masked"), + [ + pytest.param({"langfuse_mask_input": "true", "langfuse_mask_output": "true"}, True, id="true"), + pytest.param({"langfuse_mask_input": "false", "langfuse_mask_output": "false"}, False, id="false"), + ], +) +def test_mask_flag_headers_parse_as_booleans(v1: Rig, headers: Mapping[str, str], masked: bool) -> None: + marker: Final = "lit8281-mask-header-" + uuid.uuid4().hex + _chat(v1, marker, headers=headers) + attributes: Final = v1.sink.one(marker).attributes + expected: Final = ( + (REDACTED, REDACTED) + if masked + else (attributes.get("langfuse.observation.input"), attributes.get("langfuse.observation.output")) + ) + assert (attributes.get("langfuse.trace.input"), attributes.get("langfuse.trace.output")) == expected, attributes + assert marker in str(attributes.get("langfuse.observation.input")), attributes + + +@pytest.mark.parametrize( + "tags", + [ + pytest.param(5, id="int"), + pytest.param(["ok-tag", 7, None], id="mixed_list"), + pytest.param("", id="empty_string"), + pytest.param("x" * 5000, id="five_kb_string"), + ], +) +def test_malformed_caller_tags_still_log_the_generation_with_derived_fields(v1: Rig, tags: object) -> None: + marker: Final = "lit8281-badtags-" + uuid.uuid4().hex + _chat(v1, marker, metadata={"tags": tags}) + span: Final = v1.sink.one(marker) + assert span.attributes.get("langfuse.trace.name") == "litellm-acompletion", span.attributes + assert span.attributes.get("langfuse.trace.input") == span.attributes.get("langfuse.observation.input") + assert all(isinstance(tag, str) for tag in span.tags()), span.tags() + + +def test_provider_failure_span_derives_name_and_input_without_output(v1: Rig) -> None: + marker: Final = "fail-lit8281-" + uuid.uuid4().hex + response: Final = v1.proxy.request( + "POST", + "/v1/chat/completions", + {"model": v1.openai_model, "messages": [{"role": "user", "content": marker}]}, + key=v1.key, + ) + assert response.status_code >= 500, response.text + span: Final = v1.sink.one(marker) + assert span.attributes.get("langfuse.trace.name") == "litellm-acompletion", span.attributes + assert span.attributes.get("langfuse.trace.input") == span.attributes.get("langfuse.observation.input") + assert "langfuse.trace.output" not in span.attributes, span.attributes + + +def test_embedding_call_derives_the_trace_name(v1: Rig) -> None: + marker: Final = "lit8281-embed-" + uuid.uuid4().hex + response: Final = v1.proxy.request( + "POST", "/v1/embeddings", {"model": v1.embedding_model, "input": marker, "user": marker}, key=v1.key + ) + assert response.status_code == 200, response.text + span: Final = v1.sink.one(marker) + assert span.attributes.get("langfuse.trace.name") == "litellm-aembedding", span.attributes + assert span.attributes.get("langfuse.trace.output") == span.attributes.get("langfuse.observation.output") + + +def test_identical_requests_each_log_exactly_one_span_with_derived_fields(v1: Rig) -> None: + marker: Final = "lit8281-twice-" + uuid.uuid4().hex + _chat(v1, marker) + _chat(v1, marker) + spans: Final = eventually(lambda: v1.sink.matching(marker), lambda found: len(found) == 2, seconds=70) + for span in spans: + _assert_derived(span, "acompletion") + + +def test_otel_v2_names_the_request_root_and_leaves_trace_io_to_the_root_observation(v2: Rig) -> None: + derived: Final = "lit8281-v2-" + uuid.uuid4().hex + caller: Final = "lit8281-v2-caller-" + uuid.uuid4().hex + _chat(v2, derived) + _chat(v2, caller, metadata={"trace_name": "caller-trace", "tags": ["caller-tag"]}) + derived_span: Final = v2.sink.one(derived) + assert not set(_trace_fields((derived_span,))), derived_span.attributes + root: Final = v2.sink.root_of(derived_span) + assert root.attributes.get("langfuse.trace.name") == "litellm-acompletion", root.attributes + assert derived in str(root.attributes.get("langfuse.observation.input")), root.attributes + assert root.attributes.get("langfuse.observation.output") is not None, root.attributes + caller_span: Final = v2.sink.one(caller) + assert caller_span.attributes.get("langfuse.trace.name") == "caller-trace", caller_span.attributes + assert caller_span.tags() == ("caller-tag",), caller_span.attributes + + +def test_otel_v2_inbound_traceparent_leaves_the_trace_name_to_the_caller(v2: Rig) -> None: + marker: Final = "lit8281-v2-parent-" + uuid.uuid4().hex + trace_id: Final = uuid.uuid4().hex + _chat(v2, marker, headers={"traceparent": f"00-{trace_id}-{uuid.uuid4().hex[:16]}-01"}) + span: Final = v2.sink.one(marker) + assert span.trace_id == trace_id, span + spans: Final = eventually( + lambda: v2.sink.in_trace(trace_id), + lambda found: any(record.parent_span_id != span.parent_span_id for record in found), + seconds=70, + ) + assert not set(_trace_fields(spans)), spans + + +@pytest.mark.parametrize( + ("metadata", "headers"), + [({"trace_name": "caller-trace"}, None), (None, {"langfuse_trace_name": "caller-trace"})], + ids=["body", "header"], +) +def test_otel_v2_post_call_judge_keeps_the_caller_trace_name_on_the_root( + v2: Rig, metadata: Mapping[str, object] | None, headers: Mapping[str, str] | None +) -> None: + marker: Final = "lit8281-v2-judge-" + uuid.uuid4().hex + _chat(v2, marker, metadata=metadata, headers=headers, guardrails=[JUDGE_GUARDRAIL]) + generations: Final = eventually(lambda: v2.sink.matching(marker), lambda found: len(found) == 2, seconds=70) + assert len({generation.trace_id for generation in generations}) == 1, generations + root: Final = v2.sink.root_of(generations[0]) + assert root.attributes.get("langfuse.trace.name") == "caller-trace", root.attributes + + +def test_otel_v2_generic_otel_root_gets_no_derived_langfuse_trace_name(v2_after_otel: SharedRig) -> None: + derived: Final = "lit8281-v2-after-otel-" + uuid.uuid4().hex + caller: Final = "lit8281-v2-after-otel-caller-" + uuid.uuid4().hex + _chat(v2_after_otel.rig, derived) + _chat(v2_after_otel.rig, caller, metadata={"trace_name": "caller-trace"}) + root: Final = v2_after_otel.otel.root_of_request(derived) + assert "langfuse.trace.name" not in root.attributes, root.attributes + caller_root: Final = v2_after_otel.otel.root_of_request(caller) + assert caller_root.attributes.get("langfuse.trace.name") == "caller-trace", caller_root.attributes + + +def test_otel_v2_llm_only_root_generation_keeps_its_span_name_as_the_trace_name(v2_llm_only: Rig) -> None: + marker: Final = "lit8281-v2-llm-only-" + uuid.uuid4().hex + _chat(v2_llm_only, marker) + span: Final = v2_llm_only.sink.one(marker) + assert span.parent_span_id == "", span + assert span.attributes.get("langfuse.trace.name") == span.name, span + assert marker in str(span.attributes.get("langfuse.observation.input")), span.attributes + + +def test_destination_outage_mid_burst_lands_every_span_once_with_derived_fields(v1: Rig) -> None: + marker: Final = "lit8281-chaos-" + uuid.uuid4().hex[:12] + v1.sink.outage.set() + try: + answered: Final = mixed_burst(v1.proxy, v1.openai_model, v1.anthropic_model, v1.key, marker, per_surface=4) + eventually(lambda: len(v1.sink.refusals), lambda refused: refused >= 1, seconds=70) + finally: + v1.sink.outage.clear() + assert len(answered) == 4 * len(SURFACES) + expected: Final = {f"{marker}-{surface}-{index}": surface for surface, index in product(SURFACES, range(4))} + + def landed() -> Mapping[str, tuple[SpanRecord, ...]]: + return {identity: v1.sink.matching(identity) for identity in expected} + + spans: Final = eventually(landed, lambda found: all(len(records) >= 1 for records in found.values()), seconds=120) + assert {identity: len(records) for identity, records in spans.items()} == dict.fromkeys(expected, 1) + for identity, records in spans.items(): + _assert_derived(records[0], SURFACE_CALL_TYPES[expected[identity]]) + + +def _tool(index: int) -> Mapping[str, object]: + return { + "type": "function", + "function": { + "name": f"lookup_{index}", + "description": f"Looks up record {index}", + "parameters": {"type": "object", "properties": {"id": {"type": "string"}}}, + }, + } + + +def _chat_with_tools( + rig: Rig, + content: str, + tools: int, + metadata: Mapping[str, object] | None = None, + headers: Mapping[str, str] | None = None, +) -> SpanRecord: + response: Final = rig.proxy.request( + "POST", + "/v1/chat/completions", + { + "model": rig.openai_model, + "messages": [{"role": "user", "content": content}], + "tools": [_tool(index) for index in range(tools)], + **({"metadata": dict(metadata)} if metadata is not None else {}), + }, + key=rig.key, + headers=headers, + ) + assert response.status_code == (500 if content.startswith("fail-") else 200), response.text + return rig.sink.one(content) + + +@pytest.mark.parametrize(("tools", "prefix"), product((30, 33, 34, 35, 36, 40), ("", "fail-"))) +def test_trace_fields_never_evict_or_drop_another_attribute_of_a_full_span(v1: Rig, tools: int, prefix: str) -> None: + run: Final = uuid.uuid4().hex + derived: Final = _chat_with_tools(v1, f"{prefix}lit8281-full-{tools}-{run}", tools, {"trace_id": uuid.uuid4().hex}) + joined: Final = _chat_with_tools( + v1, + f"{prefix}lit8281-full-joined-{tools}-{run}", + tools, + headers={"traceparent": f"00-{uuid.uuid4().hex}-{uuid.uuid4().hex[:16]}-01"}, + ) + assert set(joined.attributes) <= set(derived.attributes), set(joined.attributes) - set(derived.attributes) + assert derived.dropped_attributes == joined.dropped_attributes, (derived.dropped_attributes, joined.attributes) diff --git a/tests/integration/observability/test_otel_team_sampling_across_pods.py b/tests/integration/observability/test_otel_team_sampling_across_pods.py new file mode 100644 index 00000000000..dc7b295febd --- /dev/null +++ b/tests/integration/observability/test_otel_team_sampling_across_pods.py @@ -0,0 +1,723 @@ +"""A team's Arize sampling rate decides once per trace, so every pod and worker serving a call of it agrees. + +Two proxies share one database, as two pods behind a load balancer do: the first runs one worker, the second +two. Calls of one trace carry the caller's ``traceparent`` and land on different pods and workers; the team's +Arize space must receive every call of a trace or none of them. +""" + +import asyncio +import json +import re +import uuid +from collections.abc import Callable, Generator, Iterator, Mapping, Sequence +from concurrent.futures import ThreadPoolExecutor +from contextlib import contextmanager +from dataclasses import dataclass, replace +from itertools import chain, product +from pathlib import Path +from typing import Final, Literal, TypeAlias +from urllib.parse import urlparse + +import httpx +import pytest +import yaml +from integration._support.client import ( + Scenario, + eventually, + gateway_from_environment, + list_value, + object_value, + until_asserted, +) +from integration._support.database import scratch_database +from integration._support.otlp_sink import Span, SpanSinks, configure_sink, recorded_requests, recorded_spans +from integration._support.process import OwnedProxy, WorkerHealthcheck, owned_proxy_process +from integration._support.wire import Reply, Request, Wire, wire_server +from pydantic import JsonValue, TypeAdapter + +MODEL: Final = "team-sampling" +SERVER: Final = 2 +CALL_ID: Final = "litellm.call_id" +OPERATION: Final = "gen_ai.operation.name" +SPACE: Final = "space-sampled" +CREDENTIALS: Final = {"arize_space_key": SPACE, "arize_api_key": "arize-sampled"} +FAILING: Final = re.compile(rb"sampling-fail") +JSON: Final[TypeAdapter[JsonValue]] = TypeAdapter(JsonValue) +TRACES: Final = 16 +Endpoint: TypeAlias = Literal["chat", "responses", "messages"] +Verdicts: TypeAlias = Mapping[str, tuple[bool, ...]] + + +def _chat_reply(stream: bool) -> Reply: + usage: Final[JsonValue] = {"prompt_tokens": 7, "completion_tokens": 2, "total_tokens": 9} + if not stream: + return Reply( + body=json.dumps( + { + "id": "chatcmpl-sampling", + "object": "chat.completion", + "created": 1, + "model": "gpt-4o-mini", + "choices": [ + {"index": 0, "message": {"role": "assistant", "content": "ok"}, "finish_reason": "stop"} + ], + "usage": usage, + } + ).encode() + ) + chunk: Final = {"id": "chatcmpl-sampling", "object": "chat.completion.chunk", "created": 1, "model": "gpt-4o-mini"} + deltas: Final[tuple[JsonValue, ...]] = ( + {**chunk, "choices": [{"index": 0, "delta": {"role": "assistant", "content": "ok"}}]}, + {**chunk, "choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}]}, + {**chunk, "choices": [], "usage": usage}, + ) + return Reply( + content_type="text/event-stream", + chunks=(*(b"data: " + json.dumps(delta).encode() + b"\n\n" for delta in deltas), b"data: [DONE]\n\n"), + ) + + +def _responses_reply(stream: bool) -> Reply: + response: Final[Mapping[str, JsonValue]] = { + "id": "resp_sampling", + "object": "response", + "created_at": 1, + "status": "completed", + "model": "gpt-4o-mini", + "output": [ + { + "id": "msg_sampling", + "type": "message", + "role": "assistant", + "status": "completed", + "content": [{"type": "output_text", "text": "ok", "annotations": []}], + } + ], + "usage": {"input_tokens": 7, "output_tokens": 2, "total_tokens": 9}, + } + if not stream: + return Reply(body=json.dumps(response).encode()) + events: Final[tuple[Mapping[str, JsonValue], ...]] = ( + { + "type": "response.created", + "sequence_number": 0, + "response": {**response, "status": "in_progress", "output": []}, + }, + { + "type": "response.output_text.delta", + "sequence_number": 1, + "item_id": "msg_sampling", + "output_index": 0, + "content_index": 0, + "delta": "ok", + }, + {"type": "response.completed", "sequence_number": 2, "response": dict(response)}, + ) + return Reply( + content_type="text/event-stream", + chunks=tuple(f"event: {event['type']}\ndata: {json.dumps(event)}\n\n".encode() for event in events), + ) + + +def _upstream(request: Request) -> Reply: + if FAILING.search(request.body) is not None: + return Reply(status=500, body=b'{"error":{"message":"scripted upstream failure","type":"server_error"}}') + stream: Final = object_value(JSON.validate_json(request.body)).get("stream") is True + if request.target.endswith("/responses"): + return _responses_reply(stream) + return _chat_reply(stream) + + +@dataclass(frozen=True, slots=True) +class Sent: + trace_id: str + parent_span_id: str + call_id: str + + +@dataclass(frozen=True, slots=True) +class Call: + path: str + body: Mapping[str, JsonValue] + headers: Mapping[str, str] + sent: Sent + expected: int + + +def _call( + key: str, trace_id: str | None, endpoint: Endpoint = "chat", stream: bool = False, content: str = "hello" +) -> Call: + parent: Final = uuid.uuid4().hex[:16] + call_id: Final = str(uuid.uuid4()) + messages: Final[JsonValue] = [{"role": "user", "content": content}] + path, body = { + "chat": ("/v1/chat/completions", {"model": MODEL, "messages": messages, "stream": stream}), + "responses": ("/v1/responses", {"model": MODEL, "input": content, "stream": stream}), + "messages": ("/v1/messages", {"model": MODEL, "max_tokens": 16, "messages": messages, "stream": stream}), + }[endpoint] + headers: Final = { + "Authorization": f"Bearer {key}", + "x-litellm-call-id": call_id, + "connection": "close", + **({} if trace_id is None else {"traceparent": f"00-{trace_id}-{parent}-01"}), + } + expected: Final = 500 if FAILING.search(content.encode()) else 200 + return Call(path, body, headers, Sent(trace_id or "", parent if trace_id else "", call_id), expected) + + +@dataclass(frozen=True, slots=True) +class Pods: + """``first`` serves with one worker, ``second`` with two.""" + + first: OwnedProxy + second: OwnedProxy + scenario: Scenario + sinks: SpanSinks + + def team_key(self, variables: Mapping[str, str]) -> str: + team: Final = self.scenario.team() + attached: Final = self.first.gateway.request( + "POST", f"/team/{team}/callback", {"callback_name": "arize", "callback_vars": dict(variables)} + ) + assert attached.status_code == 200, attached.text + return self.scenario.key(team_id=team) + + def send(self, pod: OwnedProxy, call: Call) -> Sent: + with pod.gateway.client.stream("POST", call.path, json=call.body, headers=call.headers) as response: + text: Final = response.read().decode() + assert response.status_code == call.expected, text + return call.sent + + async def send_async(self, client: httpx.AsyncClient, call: Call) -> Sent: + async with client.stream("POST", call.path, json=call.body, headers=call.headers) as response: + text: Final = (await response.aread()).decode() + assert response.status_code == call.expected, text + return call.sent + + def on_each_worker(self, pod: OwnedProxy, call: Callable[[], Call]) -> tuple[Sent, ...]: + """One call served by each worker of ``pod``, the others suspended while it runs.""" + workers: Final = sorted(pod.worker_pids()) + assert len(workers) == pod.gateway.workers, workers + sent: Final[list[Sent]] = [] # mutable-ok: one call per worker, in worker order + for serving in workers: + with _suspended_all_but(pod, workers, serving): + sent.append(self.send(pod, call())) + return tuple(sent) + + def fence(self, key: str) -> tuple[Sent, ...]: + """Calls of an unsampled team on the sampled team's exporter, one per worker of both pods. + + Each worker sends spans to that exporter in the order they were handed to it, so all of these + arriving means every call any worker decided before them has been sent too. + """ + return (self.send(self.first, _call(key, uuid.uuid4().hex)),) + self.on_each_worker( + self.second, lambda: _call(key, uuid.uuid4().hex) + ) + + +@contextmanager +def _suspended_all_but(pod: OwnedProxy, workers: Sequence[int], serving: int) -> Generator[None]: + if len(workers) == 1: + yield + return + others: Final = [pid for pid in workers if pid != serving] + with pod.suspended(others[0]): + yield + + +def _space_id(request: Mapping[str, JsonValue]) -> JsonValue: + return {name.lower(): value for name, value in object_value(request.get("headers") or {}).items()}.get( + "arize-space-id" + ) + + +def _space_span_ids(url: str) -> frozenset[str]: + """Span ids the Arize sink received in export requests sent with the team's space id.""" + ours: Final = ( + list_value(request.get("span_ids") or []) for request in recorded_requests(url) if _space_id(request) == SPACE + ) + return frozenset(span_id for span_id in chain.from_iterable(ours) if isinstance(span_id, str)) + + +def _team_spans(pods: Pods, since: int) -> tuple[Span, ...]: + owned: Final = _space_span_ids(pods.sinks.arize) + return tuple(span for span in recorded_spans(pods.sinks.arize, since)[1] if span["span_id"] in owned) + + +def _delivered(spans: tuple[Span, ...], sent: Sequence[Sent]) -> frozenset[str]: + """Call ids of ``sent`` whose server span is among ``spans``.""" + by_parent: Final = {(call.trace_id, call.parent_span_id): call.call_id for call in sent} + return frozenset( + by_parent[(span["trace_id"], span["parent_span_id"])] + for span in spans + if span["kind"] == SERVER and (span["trace_id"], span["parent_span_id"]) in by_parent + ) + + +def _await_logged(pods: Pods, since: int, sent: Sequence[Sent]) -> None: + """Wait until every call of ``sent`` has its model span in the operator's unsampled copy.""" + expected: Final = {call.call_id for call in sent} + eventually( + lambda: ( + { + str(span["attributes"][CALL_ID]) + for span in recorded_spans(pods.sinks.operator, since)[1] + if OPERATION in span["attributes"] and CALL_ID in span["attributes"] + } + & expected + ), + lambda logged: logged == expected, + seconds=60, + ) + + +@dataclass(frozen=True, slots=True) +class Cursors: + operator: int + arize: int + + +def _cursors(pods: Pods) -> Cursors: + return Cursors(recorded_spans(pods.sinks.operator)[0], recorded_spans(pods.sinks.arize)[0]) + + +def _await_flushed(pods: Pods, cursors: Cursors, fence_key: str) -> None: + """Wait until every worker of both pods has sent the team's exporter everything it decided so far.""" + fences: Final = pods.fence(fence_key) + + def arrived() -> None: + delivered: Final = _delivered(_team_spans(pods, cursors.arize), fences) + assert {fence.call_id for fence in fences} <= delivered, "the unsampled team's calls have not arrived yet" + + until_asserted(arrived, seconds=30) + + +def _settled( + pods: Pods, + cursors: Cursors, + by_trace: Mapping[str, Sequence[Sent]], + fence_key: str, + holds: Callable[[tuple[bool, ...]], bool] = lambda kept: len(set(kept)) == 1, +) -> Verdicts: + """Per trace, which of its calls reached the team's space, once every worker has sent what it decided + and ``holds`` is true of every trace.""" + calls: Final = tuple(chain.from_iterable(by_trace.values())) + _await_logged(pods, cursors.operator, calls) + _await_flushed(pods, cursors, fence_key) + + def check() -> Verdicts: + delivered: Final = _delivered(_team_spans(pods, cursors.arize), calls) + verdicts: Final = { + trace_id: tuple(call.call_id in delivered for call in sent) for trace_id, sent in by_trace.items() + } + broken: Final = {trace_id: kept for trace_id, kept in verdicts.items() if not holds(kept)} + assert broken == {}, f"{len(broken)} of {len(verdicts)} traces were split (per call, kept): {broken}" + return verdicts + + return until_asserted(check, seconds=30) + + +def _trace_ids(cell: str, count: int = TRACES) -> tuple[str, ...]: + """Fixed RFC 4122 shaped trace ids, like the uuid4 hex a caller mints for ``traceparent``.""" + return tuple(uuid.uuid5(uuid.NAMESPACE_URL, f"team-sampling/{cell}/{index}").hex for index in range(count)) + + +def _kept(verdicts: Verdicts) -> int: + return sum(1 for kept in verdicts.values() if all(kept)) + + +@pytest.mark.parametrize( + ("variables", "content"), + [({"arize_success_sampling_rate": "0.5"}, "hello"), ({"arize_error_sampling_rate": "0.5"}, "sampling-fail")], + ids=["success-rate", "error-rate"], +) +def test_each_trace_reaches_the_team_space_whole_or_not_at_all( + pods: Pods, variables: Mapping[str, str], content: str +) -> None: + """The ticket's case: three calls per trace load balanced over the pods.""" + sampled: Final = pods.team_key({**CREDENTIALS, **variables}) + cursors: Final = _cursors(pods) + by_trace: Final = { + trace_id: tuple( + pods.send(pod, _call(sampled, trace_id, content=content)) for pod in (pods.first, pods.second, pods.first) + ) + for trace_id in _trace_ids("-".join(sorted(variables))) + } + + verdicts: Final = _settled(pods, cursors, by_trace, pods.team_key(CREDENTIALS)) + + assert 0 < _kept(verdicts) < TRACES, f"a rate of 0.5 kept {_kept(verdicts)} of {TRACES} traces" + + +@pytest.mark.parametrize("client", ["sync", "async"]) +def test_every_endpoint_follows_the_verdict_of_its_trace(pods: Pods, client: str) -> None: + sampled: Final = pods.team_key({**CREDENTIALS, "arize_success_sampling_rate": "0.5"}) + cursors: Final = _cursors(pods) + plan: Final[tuple[tuple[OwnedProxy, Endpoint, bool], ...]] = ( + (pods.first, "chat", False), + (pods.second, "chat", True), + (pods.first, "responses", False), + (pods.second, "messages", True), + ) + + async def send_trace(trace_id: str) -> tuple[Sent, ...]: + clients: Final = { + id(pod): httpx.AsyncClient(base_url=str(pod.gateway.client.base_url), timeout=15, trust_env=False) + for pod in (pods.first, pods.second) + } + try: + return tuple( + await asyncio.gather( + *( + pods.send_async(clients[id(pod)], _call(sampled, trace_id, endpoint, stream)) + for pod, endpoint, stream in plan + ) + ) + ) + finally: + for opened in clients.values(): + await opened.aclose() + + by_trace: Final = { + trace_id: ( + tuple(pods.send(pod, _call(sampled, trace_id, endpoint, stream)) for pod, endpoint, stream in plan) + if client == "sync" + else asyncio.run(send_trace(trace_id)) + ) + for trace_id in _trace_ids(f"endpoints-{client}") + } + + verdicts: Final = _settled(pods, cursors, by_trace, pods.team_key(CREDENTIALS)) + + assert 0 < _kept(verdicts) < TRACES + + +def test_the_workers_of_one_pod_agree(pods: Pods) -> None: + sampled: Final = pods.team_key({**CREDENTIALS, "arize_success_sampling_rate": "0.5"}) + cursors: Final = _cursors(pods) + by_trace: Final = { + trace_id: pods.on_each_worker(pods.second, lambda trace_id=trace_id: _call(sampled, trace_id)) + for trace_id in _trace_ids("workers") + } + + verdicts: Final = _settled(pods, cursors, by_trace, pods.team_key(CREDENTIALS)) + + assert 0 < _kept(verdicts) < TRACES + + +def test_a_replaced_worker_reaches_the_verdict_its_predecessor_reached(pods: Pods) -> None: + """A worker that restarts forgets the verdicts it remembered; the calls it serves next for the same + traces still answer the way the first ones did.""" + sampled: Final = pods.team_key({**CREDENTIALS, "arize_success_sampling_rate": "0.5"}) + cursors: Final = _cursors(pods) + fence_key: Final = pods.team_key(CREDENTIALS) + traces: Final = _trace_ids("replaced") + before: Final = { + trace_id: pods.on_each_worker(pods.second, lambda t=trace_id: _call(sampled, t)) for trace_id in traces + } + _await_logged(pods, cursors.operator, tuple(chain.from_iterable(before.values()))) + _await_flushed(pods, cursors, fence_key) + for victim in sorted(pods.second.worker_pids()): + pods.second.kill_worker(victim) + by_trace: Final = { + trace_id: before[trace_id] + pods.on_each_worker(pods.second, lambda t=trace_id: _call(sampled, t)) + for trace_id in traces + } + + verdicts: Final = _settled(pods, cursors, by_trace, fence_key) + + assert 0 < _kept(verdicts) < TRACES + + +def test_a_failed_call_is_kept_wherever_a_successful_call_of_its_trace_is(pods: Pods) -> None: + """One call of the trace fails on one pod and answers to the error rate, another succeeds on the other + pod and answers to the success rate: with the error rate above the success rate, no trace keeps its + successful call and drops its failed one.""" + sampled: Final = pods.team_key( + {**CREDENTIALS, "arize_success_sampling_rate": "0.3", "arize_error_sampling_rate": "0.7"} + ) + cursors: Final = _cursors(pods) + by_trace: Final = { + trace_id: ( + pods.send(pods.first, _call(sampled, trace_id, content="sampling-fail")), + pods.send(pods.second, _call(sampled, trace_id)), + ) + for trace_id in _trace_ids("mixed", 32) + } + + verdicts: Final = _settled( + pods, cursors, by_trace, pods.team_key(CREDENTIALS), holds=lambda kept: kept[0] or not kept[1] + ) + + assert any(kept == (True, False) for kept in verdicts.values()), "no trace sat between the two rates" + assert any(kept == (True, True) for kept in verdicts.values()), "no trace sat under both rates" + + +def test_a_failed_call_answers_to_the_error_rate_on_a_pod_that_dropped_its_trace(pods: Pods) -> None: + """A pod that already dropped a successful call of the trace still keeps a later failed call of it at an + unset error rate, as the pod that only served the failed call does.""" + sampled: Final = pods.team_key({**CREDENTIALS, "arize_success_sampling_rate": "0.3"}) + cursors: Final = _cursors(pods) + traces: Final = _trace_ids("failed-after-dropped") + succeeded: Final = {trace_id: pods.send(pods.first, _call(sampled, trace_id)) for trace_id in traces} + _await_logged(pods, cursors.operator, tuple(succeeded.values())) + by_trace: Final = { + trace_id: ( + succeeded[trace_id], + pods.send(pods.first, _call(sampled, trace_id, content="sampling-fail")), + pods.send(pods.second, _call(sampled, trace_id, content="sampling-fail")), + ) + for trace_id in traces + } + + verdicts: Final = _settled( + pods, cursors, by_trace, pods.team_key(CREDENTIALS), holds=lambda kept: kept[1] and kept[2] + ) + + assert any(not kept[0] for kept in verdicts.values()), "no successful call was dropped before its trace failed" + + +def test_a_successful_call_answers_to_the_success_rate_on_a_pod_that_kept_its_failed_call(pods: Pods) -> None: + """A pod that already kept a failed call of the trace drops a later successful call of it at a zero + success rate, as the pod that only served the successful call does.""" + sampled: Final = pods.team_key({**CREDENTIALS, "arize_success_sampling_rate": "0.0"}) + cursors: Final = _cursors(pods) + traces: Final = _trace_ids("succeeded-after-kept") + failed: Final = { + trace_id: pods.send(pods.first, _call(sampled, trace_id, content="sampling-fail")) for trace_id in traces + } + _await_logged(pods, cursors.operator, tuple(failed.values())) + by_trace: Final = { + trace_id: ( + failed[trace_id], + pods.send(pods.first, _call(sampled, trace_id)), + pods.send(pods.second, _call(sampled, trace_id)), + ) + for trace_id in traces + } + + _settled(pods, cursors, by_trace, pods.team_key(CREDENTIALS), holds=lambda kept: kept == (True, False, False)) + + +def test_concurrent_calls_of_one_trace_on_one_worker_each_answer_to_their_own_outcome(pods: Pods) -> None: + """A failed and a successful call of the trace in flight at once on the single worker of the first pod + are decided apart: the failed one is kept at an unset error rate, the successful one dropped at a zero + success rate.""" + sampled: Final = pods.team_key({**CREDENTIALS, "arize_success_sampling_rate": "0.0"}) + cursors: Final = _cursors(pods) + traces: Final = _trace_ids("concurrent-mixed") + plan: Final = tuple(product(traces, ("sampling-fail", "hello"))) + + def send(job: tuple[str, str]) -> Sent: + return pods.send(pods.first, _call(sampled, job[0], content=job[1])) + + with ThreadPoolExecutor(max_workers=8) as pool: + sent: Final = tuple(pool.map(send, plan)) + by_trace: Final = {trace_id: tuple(call for call in sent if call.trace_id == trace_id) for trace_id in traces} + + _settled(pods, cursors, by_trace, pods.team_key(CREDENTIALS), holds=lambda kept: kept == (True, False)) + + +@pytest.mark.parametrize( + ("variables", "expected"), + [({"arize_success_sampling_rate": "1.0"}, TRACES), ({"arize_success_sampling_rate": "0.0"}, 0), ({}, TRACES)], + ids=["one", "zero", "unset"], +) +def test_a_rate_at_either_end_keeps_every_trace_or_none( + pods: Pods, variables: Mapping[str, str], expected: int +) -> None: + sampled: Final = pods.team_key({**CREDENTIALS, **variables}) + cursors: Final = _cursors(pods) + by_trace: Final = { + trace_id: tuple(pods.send(pod, _call(sampled, trace_id)) for pod in (pods.first, pods.second)) + for trace_id in _trace_ids(f"edge-{'-'.join(f'{k}={v}' for k, v in sorted(variables.items()))}") + } + + verdicts: Final = _settled(pods, cursors, by_trace, pods.team_key(CREDENTIALS)) + + assert _kept(verdicts) == expected + + +def test_a_request_without_a_traceparent_is_sampled_whole_at_the_rate(pods: Pods) -> None: + """With no caller trace the proxy starts one per request: each request's server and model spans travel + together and the rate still keeps some requests and drops others.""" + sampled: Final = pods.team_key({**CREDENTIALS, "arize_success_sampling_rate": "0.5"}) + cursors: Final = _cursors(pods) + sent: Final = tuple( + pods.send(pod, _call(sampled, None)) for _, pod in product(range(12), (pods.first, pods.second)) + ) + _await_logged(pods, cursors.operator, sent) + trace_of: Final = { + str(span["attributes"][CALL_ID]): span["trace_id"] + for span in recorded_spans(pods.sinks.operator, cursors.operator)[1] + if CALL_ID in span["attributes"] + } + fences: Final = pods.fence(pods.team_key(CREDENTIALS)) + + def check() -> Mapping[str, tuple[bool, bool]]: + spans: Final = _team_spans(pods, cursors.arize) + assert {fence.call_id for fence in fences} <= _delivered(spans, fences), ( + "the unsampled team's calls have not arrived yet" + ) + kinds: Final = { + call.call_id: ( + any(span["kind"] == SERVER for span in spans if span["trace_id"] == trace_of[call.call_id]), + any(OPERATION in span["attributes"] for span in spans if span["trace_id"] == trace_of[call.call_id]), + ) + for call in sent + } + partial: Final = {call_id: kept for call_id, kept in kinds.items() if kept[0] != kept[1]} + assert partial == {}, f"requests reached the space without their whole tree (server, model): {partial}" + return kinds + + kept: Final = sum(1 for server, _ in until_asserted(check, seconds=30).values() if server) + assert 0 < kept < len(sent), f"a rate of 0.5 kept {kept} of {len(sent)} requests" + + +def test_a_key_level_destination_follows_the_verdict_of_its_trace(pods: Pods) -> None: + team: Final = pods.scenario.team() + sampled: Final = pods.scenario.key( + team_id=team, + metadata={ + "logging": [ + { + "callback_name": "arize", + "callback_type": "success", + "callback_vars": {**CREDENTIALS, "arize_success_sampling_rate": "0.5"}, + } + ] + }, + ) + cursors: Final = _cursors(pods) + by_trace: Final = { + trace_id: tuple(pods.send(pod, _call(sampled, trace_id)) for pod in (pods.first, pods.second, pods.first)) + for trace_id in _trace_ids("key-level") + } + + verdicts: Final = _settled(pods, cursors, by_trace, pods.team_key(CREDENTIALS)) + + assert 0 < _kept(verdicts) < TRACES + + +def test_a_concurrent_burst_keeps_every_trace_whole(pods: Pods) -> None: + """Four calls per trace, all in flight at once across both pods.""" + sampled: Final = pods.team_key({**CREDENTIALS, "arize_success_sampling_rate": "0.5"}) + cursors: Final = _cursors(pods) + traces: Final = _trace_ids("burst", 24) + plan: Final = tuple(product(traces, (pods.first, pods.second, pods.first, pods.second))) + + def send(job: tuple[str, OwnedProxy]) -> Sent: + return pods.send(job[1], _call(sampled, job[0])) + + with ThreadPoolExecutor(max_workers=16) as pool: + sent: Final = list(pool.map(send, plan)) + by_trace: Final = {trace_id: tuple(call for call in sent if call.trace_id == trace_id) for trace_id in traces} + + verdicts: Final = _settled(pods, cursors, by_trace, pods.team_key(CREDENTIALS)) + + assert 0 < _kept(verdicts) < len(traces) + + +def test_a_stalled_team_space_during_a_burst_keeps_serving_and_each_trace_whole(pods: Pods) -> None: + """The team's Arize endpoint stops answering while a burst of calls runs over both pods: every call is + still served, and once the endpoint answers again each trace arrives whole or not at all.""" + sampled: Final = pods.team_key({**CREDENTIALS, "arize_success_sampling_rate": "0.5"}) + cursors: Final = _cursors(pods) + traces: Final = _trace_ids("stalled") + plan: Final = tuple(product(traces, (pods.first, pods.second))) + + def send(job: tuple[str, OwnedProxy]) -> Sent: + return pods.send(job[1], _call(sampled, job[0])) + + configure_sink(pods.sinks.arize, paused=True) + try: + with ThreadPoolExecutor(max_workers=8) as pool: + sent: Final = tuple(pool.map(send, plan)) + finally: + configure_sink(pods.sinks.arize, paused=False) + by_trace: Final = {trace_id: tuple(call for call in sent if call.trace_id == trace_id) for trace_id in traces} + + verdicts: Final = _settled(pods, cursors, by_trace, pods.team_key(CREDENTIALS)) + + assert 0 < _kept(verdicts) < len(traces) + + +def _write_config(directory: Path, sinks: SpanSinks, provider: Wire) -> Path: + shared: Final = object_value( + JSON.validate_python(yaml.safe_load(Path("tests/integration/proxy_config.yaml").read_text())) + ) + config: Final = { + **shared, + "model_list": [ + *list_value(shared.get("model_list") or []), + { + "model_name": MODEL, + "litellm_params": { + "model": "openai/gpt-4o-mini", + "api_key": "integration-provider-key", + "api_base": provider.url + "/v1", + }, + }, + ], + "litellm_settings": { + **object_value(shared.get("litellm_settings") or {}), + "callbacks": ["langfuse_otel"], + "otel_tenant_destination_mode": "additive", + "provider_url_destination_allowed_hosts": [urlparse(sinks.operator).netloc, urlparse(sinks.arize).netloc], + }, + "router_settings": {**object_value(shared.get("router_settings") or {}), "num_retries": 0}, + "general_settings": {**object_value(shared.get("general_settings") or {}), "user_api_key_cache_ttl": 2}, + } + path: Final = directory / "team-sampling.yaml" + path.write_text(yaml.safe_dump(config)) + return path + + +@contextmanager +def _two_pods(provider: Wire, sinks: SpanSinks, directory: Path) -> Generator[Pods]: + environment: Final = { + "LITELLM_OTEL_V2": "1", + "OTEL_BSP_SCHEDULE_DELAY": "300", + "MAPPER_NAMES": "genai,openinference", + "LANGFUSE_HOST": sinks.operator, + "LANGFUSE_PUBLIC_KEY": "pk-lf-operator", + "LANGFUSE_SECRET_KEY": "sk-lf-operator", + "ARIZE_SPACE_KEY": "space-operator", + "ARIZE_API_KEY": "arize-operator", + "ARIZE_HTTP_ENDPOINT": sinks.arize + "/v1/traces", + } + removed: Final = ("LITELLM_OTEL_TENANT_DESTINATION_MODE", "OTEL_TRACES_SAMPLER", "OTEL_TRACES_SAMPLER_ARG") + config: Final = _write_config(directory, sinks, provider) + for pod in ("first", "second"): + (directory / pod).mkdir() + with gateway_from_environment() as shared, scratch_database("team_sampling") as database_url: + overrides: Final = {**environment, "DATABASE_URL": database_url} + with ( + owned_proxy_process( + shared, directory / "first", overrides, config=config, remove_environment=removed + ) as first, + owned_proxy_process( + shared, + directory / "second", + overrides, + config=config, + remove_environment=removed, + workers=2, + healthcheck=WorkerHealthcheck.LENIENT, + ) as second, + replace(first.gateway, database_url=database_url).scenario() as scenario, + ): + eventually(second.worker_pids, lambda pids: len(pids) == 2, seconds=120) + yield Pods(first, second, scenario, sinks) + + +@pytest.fixture(scope="module") +def provider() -> Iterator[Wire]: + with wire_server(_upstream) as wire: + yield wire + + +@pytest.fixture(scope="module") +def pods(provider: Wire, audit_sinks: SpanSinks, tmp_path_factory: pytest.TempPathFactory) -> Iterator[Pods]: + with _two_pods(provider, audit_sinks, tmp_path_factory.mktemp("team-sampling")) as started: + yield started diff --git a/tests/integration/observability/test_passthrough_guardrail_scan_text.py b/tests/integration/observability/test_passthrough_guardrail_scan_text.py new file mode 100644 index 00000000000..7437f696d4c --- /dev/null +++ b/tests/integration/observability/test_passthrough_guardrail_scan_text.py @@ -0,0 +1,153 @@ +import json +import uuid +from collections.abc import Iterator, Mapping +from contextlib import ExitStack +from dataclasses import dataclass +from pathlib import Path +from types import MappingProxyType +from typing import Final + +import pytest +import yaml +from integration._support.anthropic_sse import message_json +from integration._support.client import Gateway +from integration._support.openai_wire import chat_reply +from integration._support.process import OwnedProxy, owned_proxy_process +from integration._support.wire import Reply, Request, Wire, wire_server +from pydantic import JsonValue, TypeAdapter + +GENERIC: Final = "passthrough-scan-generic" +AIRS: Final = "passthrough-scan-airs" +OPENAI_ROUTE: Final = "/openai/chat/completions" +ANTHROPIC_ROUTE: Final = "/anthropic/v1/messages" +ROUTE_BODIES: Final[Mapping[str, dict[str, JsonValue]]] = MappingProxyType( + { + OPENAI_ROUTE: {"model": "gpt-5.6", "messages": [{"role": "user", "content": "Say hi in one word"}]}, + ANTHROPIC_ROUTE: { + "model": "claude-sonnet-5-5", + "max_tokens": 16, + "messages": [{"role": "user", "content": "Say hi in one word"}], + }, + } +) +_CONFIG: Final = Path(__file__).resolve().parents[1] / "proxy_config.yaml" +_JSON: Final = TypeAdapter(dict[str, JsonValue]) + + +def _generic_verdict(_request: Request) -> Reply: + return Reply(body=json.dumps({"action": "NONE"}).encode()) + + +def _airs_verdict(_request: Request) -> Reply: + return Reply(body=json.dumps({"action": "allow", "category": "benign", "scan_id": "s", "report_id": "r"}).encode()) + + +def _openai_reply(_request: Request) -> Reply: + return chat_reply("chatcmpl-passthrough-scan", "gpt-5.6", "Hi", stream=False) + + +def _anthropic_reply(_request: Request) -> Reply: + return Reply(body=message_json("msg_passthrough_scan", "claude-sonnet-5-5", "Hi")) + + +def _parsed_texts(texts: JsonValue, vendor_body: dict[str, JsonValue]) -> list[JsonValue]: + assert isinstance(texts, list), vendor_body + return [json.loads(text) if isinstance(text, str) else text for text in texts] + + +def _scanned_payloads(guardrail: str, vendor_body: dict[str, JsonValue]) -> list[JsonValue]: + if guardrail == GENERIC: + return _parsed_texts(vendor_body["texts"], vendor_body) + contents: Final = vendor_body["contents"] + assert isinstance(contents, list), vendor_body + return _parsed_texts([content.get("prompt") for content in contents if isinstance(content, dict)], vendor_body) + + +@dataclass(frozen=True, slots=True) +class PassThroughRig: + owned: OwnedProxy + vendors: Mapping[str, Wire] + upstreams: Mapping[str, Wire] + + +@pytest.fixture(scope="module") +def rig(session_gateway: Gateway, tmp_path_factory: pytest.TempPathFactory) -> Iterator[PassThroughRig]: + directory: Final = tmp_path_factory.mktemp("passthrough-guardrail-scan") + with ExitStack() as stack: + vendors: Final = MappingProxyType( + { + GENERIC: stack.enter_context(wire_server(_generic_verdict)), + AIRS: stack.enter_context(wire_server(_airs_verdict)), + } + ) + upstreams: Final = MappingProxyType( + { + OPENAI_ROUTE: stack.enter_context(wire_server(_openai_reply)), + ANTHROPIC_ROUTE: stack.enter_context(wire_server(_anthropic_reply)), + } + ) + config: Final = _JSON.validate_python(yaml.safe_load(_CONFIG.read_text())) + path: Final = directory / "passthrough-guardrail-scan.yaml" + path.write_text( + yaml.safe_dump( + { + **config, + "guardrails": [ + { + "guardrail_name": GENERIC, + "litellm_params": { + "guardrail": "generic_guardrail_api", + "mode": "pre_call", + "default_on": False, + "api_base": vendors[GENERIC].url, + "api_key": "synthetic-guardrail-key", + }, + }, + { + "guardrail_name": AIRS, + "litellm_params": { + "guardrail": "panw_prisma_airs", + "mode": "pre_call", + "default_on": False, + "api_base": vendors[AIRS].url, + "api_key": "synthetic-airs-key", + "profile_name": "integration", + }, + }, + ], + } + ) + ) + environment: Final = { + "OPENAI_API_BASE": upstreams[OPENAI_ROUTE].url, + "OPENAI_API_KEY": "synthetic-openai-key", + "ANTHROPIC_API_BASE": upstreams[ANTHROPIC_ROUTE].url, + "ANTHROPIC_API_KEY": "synthetic-anthropic-key", + } + owned: Final = stack.enter_context(owned_proxy_process(session_gateway, directory, environment, config=path)) + yield PassThroughRig(owned, vendors, upstreams) + + +@pytest.mark.parametrize("guardrail", [GENERIC, AIRS]) +@pytest.mark.parametrize("route", [OPENAI_ROUTE, ANTHROPIC_ROUTE]) +def test_pass_through_guardrail_scans_the_client_body_without_the_callers_key_metadata( + rig: PassThroughRig, route: str, guardrail: str +) -> None: + gateway: Final = rig.owned.gateway + with gateway.scenario() as scenario: + team: Final = scenario.team() + user: Final = scenario.user( + user_email=f"passthrough-scan-{uuid.uuid4().hex}@example.com", user_role="internal_user", teams=[team] + ) + key: Final = scenario.key(user_id=user, team_id=team) + body: Final = {**ROUTE_BODIES[route], "guardrails": [guardrail]} + + response: Final = gateway.request("POST", route, body, key=key) + + assert response.status_code == 200, response.text + scanned: Final = [ + _scanned_payloads(guardrail, _JSON.validate_json(request.body)) + for request in rig.vendors[guardrail].drain() + ] + assert scanned == [[body]], scanned + assert len(rig.upstreams[route].drain()) == 1 diff --git a/tests/integration/observability/test_prometheus_provider_auth_failure.py b/tests/integration/observability/test_prometheus_provider_auth_failure.py new file mode 100644 index 00000000000..13d264ca6b0 --- /dev/null +++ b/tests/integration/observability/test_prometheus_provider_auth_failure.py @@ -0,0 +1,1074 @@ +from __future__ import annotations + +import asyncio +import json +import threading +import uuid +from collections import Counter +from collections.abc import Iterator, Sequence +from dataclasses import dataclass +from hashlib import sha256 +from pathlib import Path +from typing import Final + +import httpx +import openai +import pytest +import yaml +from integration._support.client import Gateway, Scenario, eventually, gateway_from_environment +from integration._support.database import write_rows +from integration._support.mcp import ENTRY_POINTS, McpCaller, McpPeer, echo_tool, register_mcp, scripted_peer +from integration._support.process import owned_proxy +from integration._support.prometheus_series import Sample, scrape +from integration._support.wire import Reply, Request, Wire, wire_server +from pydantic import JsonValue + +RUN: Final = uuid.uuid4().hex[:8] +REJECTS: Final = "provider-rejects-credential" +HELD_REJECTS: Final = "provider-rejects-credential-when-released" +KEY_NOT_VALID: Final = "provider-key-not-valid" +RATE_LIMITS: Final = "provider-rate-limits" +RECOVERS: Final = "provider-rejects-once" +HEALTHY: Final = "provider-healthy" +AGENT_365_GUARDRAIL: Final = f"agent-365-{RUN}" +CALLER_OAUTH_TOKEN: Final = f"sk-ant-oat01-caller-{RUN}" +REVOKED_GATEWAY_KEY: Final = f"revoked-gateway-key-{RUN}" +UNKNOWN_ORGANIZATION: Final = f"org-unknown-{RUN}" +REVOKED_STORED_KEY: Final = f"sk-revoked-stored-credential-{RUN}" +AZURE_API_VERSION: Final = "2024-02-01" +CALLER_AZURE_CELLS: Final = ( + ("chat", False), + ("embeddings", False), + ("responses", False), + ("messages", False), + ("responses", True), +) +CALLER_CREDENTIAL_CELLS: Final = ( + ("caller-watsonx-token", "token"), + ("caller-gigachat-access-token", "gigachat_access_token"), +) +TOKEN_EXCHANGE_CELLS: Final = ("token-exchange", "token-exchange-credential") +KEYLESS_CELLS: Final = ("keyless", "messages-keyless") +TOKEN_EXCHANGE_SETTINGS: Final = { + "token_exchange_endpoint": "https://login.microsoftonline.com/00000000-0000-4000-8000-0000000c0b01/oauth2/v2.0/token", + "client_id": "synthetic-obo-client-id", + "client_secret": "synthetic-obo-client-secret", +} + +FAILURES: Final = "litellm_deployment_failure_responses_total" +TOTALS: Final = "litellm_deployment_total_requests_total" +LLM_FAILED: Final = "litellm_llm_api_failed_requests_metric_total" +STATE: Final = "litellm_deployment_state" +PROXY_FAILED: Final = "litellm_proxy_failed_requests_metric_total" +SUCCESSES: Final = "litellm_deployment_success_responses_total" +DEPLOYMENT_SERIES: Final = (FAILURES, TOTALS, LLM_FAILED, STATE) + +ENDPOINT_CELLS: Final = ( + "chat", + "chat-stream", + "messages", + "messages-stream", + "responses", + "responses-stream", + "embeddings", +) +REJECTED_CELLS: Final = ( + *ENDPOINT_CELLS, + "sdk-sync", + "sdk-async", + "repeated", + "fallback", + "burst", + "caller-api-key", + "caller-extra-headers", + "caller-headers", + "caller-provider-specific-header", + "plain-extra-headers", + "plain-headers", + "plain-provider-specific-header", + "forwarded-provider-header", + "forwarded-plain-header", + "forwarded-user-information", +) +GATED_CELLS: Final = ("invalid-key", "missing-key", "expired-key", "blocked-key", "no-model-access") +CALLER_SCOPE_CELLS: Final = ("forwarded-gateway-key", "caller-organization", "forwarded-organization") +HEALTHY_CELLS: Final = (*GATED_CELLS, *CALLER_SCOPE_CELLS, "healthy", "key-rpm-limit") +GUARDRAIL_ROWS: Final = ( + "SELECT COALESCE(jsonb_path_query_first(metadata, " + "'$.guardrail_information[*] ? (@.guardrail_name == $name).guardrail_status', " + "jsonb_build_object('name', %s::text)) #>> '{}', 'none') AS status " + 'FROM "LiteLLM_SpendLogs" WHERE api_key = %s AND call_type = %s' +) + + +def name(cell: str) -> str: + return f"prometheus-{cell}-{RUN}" + + +def identity(cell: str) -> str: + return f"{name(cell)}-deployment" + + +def _error(status: int, message: str, kind: str, code: str) -> Reply: + return Reply(status=status, body=json.dumps({"error": {"message": message, "type": kind, "code": code}}).encode()) + + +def _completion() -> Reply: + return Reply( + body=json.dumps( + { + "id": f"chatcmpl-{uuid.uuid4().hex}", + "object": "chat.completion", + "created": 1, + "model": "gpt-4o-mini", + "choices": [{"index": 0, "message": {"role": "assistant", "content": "ok"}, "finish_reason": "stop"}], + "usage": {"prompt_tokens": 3, "completion_tokens": 1, "total_tokens": 4}, + } + ).encode() + ) + + +class Provider: + """Answers by upstream model name. `HELD_REJECTS` waits for `release` before rejecting the credential.""" + + def __init__(self, release: threading.Event) -> None: + self._lock: Final = threading.Lock() + self._seen: Final[Counter[str]] = Counter() + self._release: Final = release + + def __call__(self, request: Request) -> Reply: + sent: Final = json.loads(request.body) + model: Final = str(sent.get("model") or sent.get("model_id") or request.target.split("/")[2]) + if request.headers.get("x-portkey-api-key") == REVOKED_GATEWAY_KEY: + return _error(401, "Invalid gateway API key", "invalid_request_error", "invalid_api_key") + if request.headers.get("authorization") == f"Bearer {REVOKED_STORED_KEY}": + return _error(401, "Incorrect API key provided: sk-revok*****", "invalid_request_error", "invalid_api_key") + if request.headers.get("openai-organization") == UNKNOWN_ORGANIZATION: + return _error( + 401, + "OpenAI-Organization header should match organization for API key", + "invalid_request_error", + "mismatched_organization", + ) + with self._lock: + self._seen[model] += 1 + attempt: Final = self._seen[model] + if model == HELD_REJECTS: + assert self._release.wait(timeout=30), "held provider reply was never released" + if model in (REJECTS, HELD_REJECTS) or (model == RECOVERS and attempt == 1): + return _error(401, "Incorrect API key provided: sk-rotat*****", "invalid_request_error", "invalid_api_key") + if model == KEY_NOT_VALID: + return _error(400, "API key not valid. Please pass a valid API key.", "invalid_request_error", "400") + if model == RATE_LIMITS: + return _error(429, "Rate limit reached for requests", "rate_limit_error", "rate_limit_exceeded") + return _completion() + + +def deployment(cell: str, upstream_model: str, api_base: str) -> dict[str, JsonValue]: + return { + "model_name": name(cell), + "litellm_params": { + "model": f"openai/{upstream_model}", + "api_key": f"sk-deployment-credential-{cell}", + "api_base": api_base, + }, + "model_info": {"id": identity(cell)}, + } + + +def anthropic_deployment(cell: str, api_base: str) -> dict[str, JsonValue]: + return { + "model_name": name(cell), + "litellm_params": { + "model": f"anthropic/{REJECTS}", + "api_key": f"sk-ant-api03-deployment-credential-{cell}", + "api_base": api_base, + }, + "model_info": {"id": identity(cell)}, + } + + +def bedrock_deployment(cell: str, opt_in: dict[str, JsonValue]) -> dict[str, JsonValue]: + return { + "model_name": name(cell), + "litellm_params": { + "model": f"bedrock/converse/{REJECTS}", + "aws_access_key_id": "AKIADEPLOYMENTCREDENTIAL", + "aws_secret_access_key": f"deployment-credential-{cell}", + "aws_region_name": "us-east-1", + **opt_in, + }, + "model_info": {"id": identity(cell)}, + } + + +def keyless_anthropic_deployment(cell: str, api_base: str) -> dict[str, JsonValue]: + return { + "model_name": name(cell), + "litellm_params": {"model": f"anthropic/{REJECTS}", "api_base": api_base}, + "model_info": {"id": identity(cell)}, + } + + +def azure_deployment(cell: str, api_base: str, credential: dict[str, JsonValue]) -> dict[str, JsonValue]: + return { + "model_name": name(cell), + "litellm_params": { + "model": f"azure/{REJECTS}", + "api_base": api_base, + "api_version": AZURE_API_VERSION, + **credential, + }, + "model_info": {"id": identity(cell)}, + } + + +def caller_credential_deployment(cell: str, field: str, api_base: str) -> dict[str, JsonValue]: + provider: Final = "watsonx" if field == "token" else "gigachat" + project: Final[dict[str, JsonValue]] = {"project_id": f"project-{RUN}"} if provider == "watsonx" else {} + return { + "model_name": name(cell), + "litellm_params": { + "model": f"{provider}/{REJECTS}", + "api_base": api_base, + field: f"deployment-credential-{cell}", + **project, + }, + "model_info": {"id": identity(cell)}, + } + + +def token_exchange_deployment(cell: str) -> dict[str, JsonValue]: + settings: Final[dict[str, JsonValue]] = ( + {"litellm_credential_name": f"m365-obo-{RUN}"} if cell.endswith("-credential") else {**TOKEN_EXCHANGE_SETTINGS} + ) + return { + "model_name": name(cell), + "litellm_params": {"model": "microsoft_365_copilot/chat", **settings}, + "model_info": {"id": identity(cell)}, + } + + +def caller_azure_cell(opt_in: str, route: str, inside_extra_body: bool) -> str: + return f"{opt_in}-caller-azure-token-{route}{'-extra-body' if inside_extra_body else ''}" + + +def config(directory: Path, upstream: Wire) -> Path: + api_base: Final = f"{upstream.url}/v1" + configuration: Final = yaml.safe_load(Path("tests/integration/proxy_config.yaml").read_text()) + configuration["model_list"] = [ + *configuration["model_list"], + *(deployment(cell, REJECTS, api_base) for cell in REJECTED_CELLS), + *(deployment(cell, HEALTHY, api_base) for cell in HEALTHY_CELLS), + deployment("held", HELD_REJECTS, api_base), + deployment("key-not-valid", KEY_NOT_VALID, api_base), + deployment("rate-limited", RATE_LIMITS, api_base), + deployment("recovers", RECOVERS, api_base), + anthropic_deployment("anthropic-own-key", upstream.url), + anthropic_deployment("anthropic-sdk-own-key", upstream.url), + anthropic_deployment("caller-oauth", upstream.url), + *(keyless_anthropic_deployment(cell, upstream.url) for cell in KEYLESS_CELLS), + bedrock_deployment( + "deployment-caller-bedrock-endpoint", + {"configurable_clientside_auth_params": ["aws_bedrock_runtime_endpoint"]}, + ), + azure_deployment("azure-own-token", upstream.url, {"azure_ad_token": "deployment-entra-token-azure-own-token"}), + *( + azure_deployment( + caller_azure_cell("deployment", route, inside_extra_body), + upstream.url, + {"configurable_clientside_auth_params": ["azure_ad_token"]}, + ) + for route, inside_extra_body in CALLER_AZURE_CELLS + ), + *(caller_credential_deployment(cell, field, upstream.url) for cell, field in CALLER_CREDENTIAL_CELLS), + *(token_exchange_deployment(cell) for cell in TOKEN_EXCHANGE_CELLS), + { + "model_name": name("caller-api-base"), + "litellm_params": { + "model": f"openai/{REJECTS}", + "api_key": "sk-deployment-credential-caller-api-base", + "api_base": api_base, + "configurable_clientside_auth_params": ["api_base"], + }, + "model_info": {"id": identity("caller-api-base")}, + }, + { + "model_name": name("caller-credential"), + "litellm_params": { + "model": "github_copilot/gpt-4o", + "litellm_credential_name": f"copilot-per-user-{RUN}", + "github_copilot_auth_type": "per_user_oauth", + }, + "model_info": {"id": identity("caller-credential")}, + }, + { + "model_name": name("caller-credential-name"), + "litellm_params": { + "model": f"openai/{HEALTHY}", + "api_base": api_base, + "litellm_credential_name": f"deployment-key-{RUN}", + }, + "model_info": {"id": identity("caller-credential-name")}, + }, + ] + configuration["credential_list"] = [ + *configuration.get("credential_list", []), + {"credential_name": f"m365-obo-{RUN}", "credential_values": {**TOKEN_EXCHANGE_SETTINGS}, "credential_info": {}}, + { + "credential_name": f"deployment-key-{RUN}", + "credential_values": {"api_key": "sk-deployment-credential-caller-credential-name"}, + "credential_info": {}, + }, + { + "credential_name": f"revoked-key-{RUN}", + "credential_values": {"api_key": REVOKED_STORED_KEY}, + "credential_info": {}, + }, + ] + configuration["guardrails"] = [ + { + "guardrail_name": AGENT_365_GUARDRAIL, + "litellm_params": { + "guardrail": "agent_365", + "mode": "pre_mcp_call", + "default_on": True, + "tenant_id": "00000000-0000-4000-8000-0000000a3650", + "client_id": "synthetic-client-id", + "client_secret": "synthetic-client-secret", + }, + } + ] + configuration["litellm_settings"]["callbacks"] = ["prometheus"] + configuration["litellm_settings"]["model_group_settings"] = { + "forward_client_headers_to_llm_api": [ + name("forwarded-provider-header"), + name("forwarded-plain-header"), + name("forwarded-gateway-key"), + name("forwarded-user-information"), + ] + } + configuration["litellm_settings"]["add_user_information_to_llm_headers"] = True + configuration["general_settings"]["forward_llm_provider_auth_headers"] = True + configuration["general_settings"]["forward_openai_org_id"] = True + configuration.setdefault("router_settings", {}).update({"num_retries": 0, "disable_cooldowns": True}) + path: Final = directory / "prometheus-provider-auth-failure.yaml" + path.write_text(yaml.safe_dump(configuration)) + return path + + +@dataclass(frozen=True, slots=True) +class Rig: + gateway: Gateway + upstream: Wire + + @property + def api_base(self) -> str: + return f"{self.upstream.url}/v1" + + +@pytest.fixture(scope="module") +def rig(tmp_path_factory: pytest.TempPathFactory) -> Iterator[Rig]: + directory: Final = tmp_path_factory.mktemp("prometheus-provider-auth-failure") + released: Final = threading.Event() + released.set() + with ( + wire_server(Provider(released)) as upstream, + gateway_from_environment() as shared, + owned_proxy( + shared, + directory, + {"PROXY_CONFIG_RELOAD_INTERVAL_SECONDS": "2"}, + config=config(directory, upstream), + remove_environment=("ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN"), + ) as owned, + ): + yield Rig(owned, upstream) + + +def opted_in_config(directory: Path, upstream: Wire) -> Path: + configuration: Final = yaml.safe_load(Path("tests/integration/proxy_config.yaml").read_text()) + configuration["model_list"] = [ + *configuration["model_list"], + *( + azure_deployment(caller_azure_cell("proxy-wide", route, inside_extra_body), upstream.url, {}) + for route, inside_extra_body in CALLER_AZURE_CELLS + ), + bedrock_deployment("proxy-wide-caller-bedrock-endpoint", {}), + ] + configuration["general_settings"]["allow_client_side_credentials"] = True + configuration["litellm_settings"]["callbacks"] = ["prometheus"] + configuration.setdefault("router_settings", {}).update({"num_retries": 0, "disable_cooldowns": True}) + path: Final = directory / "prometheus-caller-credentials-opted-in.yaml" + path.write_text(yaml.safe_dump(configuration)) + return path + + +@pytest.fixture(scope="module") +def opted_in(tmp_path_factory: pytest.TempPathFactory) -> Iterator[Rig]: + directory: Final = tmp_path_factory.mktemp("prometheus-caller-credentials-opted-in") + released: Final = threading.Event() + released.set() + with ( + wire_server(Provider(released)) as upstream, + gateway_from_environment() as shared, + owned_proxy(shared, directory, {}, config=opted_in_config(directory, upstream)) as owned, + ): + yield Rig(owned, upstream) + + +def series(samples: Sequence[Sample], metric: str, **labels: str) -> tuple[Sample, ...]: + return tuple( + sample + for sample in samples + if sample.name == metric and all(sample.labels.get(label) == value for label, value in labels.items()) + ) + + +def values(samples: Sequence[Sample], metric: str, **labels: str) -> list[float]: + return [sample.value for sample in series(samples, metric, **labels)] + + +def until(gateway: Gateway, metric: str, **labels: str) -> tuple[Sample, ...]: + return eventually(lambda: scrape(gateway), lambda samples: bool(series(samples, metric, **labels)), 30) + + +def messages(cell: str) -> list[JsonValue]: + return [{"role": "user", "content": f"{cell} {uuid.uuid4().hex}"}] + + +def send(gateway: Gateway, cell: str, model: str | None = None, key: str | None = None) -> httpx.Response: + asked: Final = model or name(cell) + stream: Final = cell.endswith("-stream") + if cell.startswith("messages"): + anthropic: Final = {"model": asked, "max_tokens": 16, "messages": messages(cell), "stream": stream} + return gateway.request("POST", "/v1/messages", anthropic, key=key) + if cell.startswith("responses"): + return gateway.request("POST", "/v1/responses", {"model": asked, "input": cell, "stream": stream}, key=key) + if cell == "embeddings": + return gateway.request("POST", "/v1/embeddings", {"model": asked, "input": cell}, key=key) + return gateway.request( + "POST", "/v1/chat/completions", {"model": asked, "messages": messages(cell), "stream": stream}, key=key + ) + + +def assert_reached_with_the_deployment_credential(rig: Rig, cell: str, attempts: int = 1) -> None: + reached: Final = rig.upstream.drain() + assert [request.headers["authorization"] for request in reached] == [ + f"Bearer sk-deployment-credential-{cell}" + ] * attempts, [request.target for request in reached] + + +def recorded(samples: Sequence[Sample], **labels: str) -> list[tuple[str, dict[str, str], float]]: + return [(sample.name, dict(sample.labels), sample.value) for sample in series_of(samples, **labels)] + + +def series_of(samples: Sequence[Sample], **labels: str) -> tuple[Sample, ...]: + return tuple( + sample + for sample in samples + if sample.name.startswith("litellm_") + and all(sample.labels.get(label) == value for label, value in labels.items()) + ) + + +def assert_kept_out_of_the_deployment_metrics(rig: Rig, cell: str) -> None: + samples: Final = until(rig.gateway, PROXY_FAILED, requested_model=name(cell)) + assert {metric: values(samples, metric, model_id=identity(cell)) for metric in DEPLOYMENT_SERIES} == { + metric: [] for metric in DEPLOYMENT_SERIES + }, recorded(samples, model_id=identity(cell)) + + +def assert_recorded_as_a_deployment_failure(rig: Rig, cell: str, status: str, count: float = 1.0) -> None: + samples: Final = until(rig.gateway, FAILURES, model_id=identity(cell)) + observed: Final = recorded(samples, model_id=identity(cell)) + assert values(samples, FAILURES, model_id=identity(cell), exception_status=status) == [count], observed + assert values(samples, TOTALS, model_id=identity(cell)) == [count], observed + assert values(samples, LLM_FAILED, model_id=identity(cell)) == [count], observed + assert values(samples, STATE, model_id=identity(cell)) == [1.0], observed + + +@pytest.mark.parametrize("cell", ENDPOINT_CELLS) +def test_a_provider_401_on_every_endpoint_counts_as_a_deployment_failure_and_a_partial_outage( + rig: Rig, cell: str +) -> None: + rig.upstream.drain() + response: Final = send(rig.gateway, cell) + assert response.status_code == 401, response.text + assert_reached_with_the_deployment_credential(rig, cell) + assert_recorded_as_a_deployment_failure(rig, cell, "401") + + +def test_a_provider_401_seen_by_the_sync_openai_client_is_recorded(rig: Rig) -> None: + rig.upstream.drain() + with ( + openai.OpenAI( + base_url=f"{rig.gateway.client.base_url}/v1", + api_key=rig.gateway.key, + max_retries=0, + http_client=httpx.Client(trust_env=False), + ) as client, + pytest.raises(openai.AuthenticationError, match="Incorrect API key provided"), + ): + client.chat.completions.create(model=name("sdk-sync"), messages=[{"role": "user", "content": "sync"}]) + assert_reached_with_the_deployment_credential(rig, "sdk-sync") + assert_recorded_as_a_deployment_failure(rig, "sdk-sync", "401") + + +def test_a_provider_401_seen_by_the_async_openai_client_is_recorded(rig: Rig) -> None: + async def ask() -> None: + async with openai.AsyncOpenAI( + base_url=f"{rig.gateway.client.base_url}/v1", + api_key=rig.gateway.key, + max_retries=0, + http_client=httpx.AsyncClient(trust_env=False), + ) as client: + await client.chat.completions.create(model=name("sdk-async"), messages=[{"role": "user", "content": "a"}]) + + rig.upstream.drain() + with pytest.raises(openai.AuthenticationError, match="Incorrect API key provided"): + asyncio.run(ask()) + assert_reached_with_the_deployment_credential(rig, "sdk-async") + assert_recorded_as_a_deployment_failure(rig, "sdk-async", "401") + + +def test_each_repeated_provider_401_is_counted_once(rig: Rig) -> None: + rig.upstream.drain() + assert [send(rig.gateway, "repeated").status_code for _ in range(3)] == [401, 401, 401] + assert_reached_with_the_deployment_credential(rig, "repeated", attempts=3) + assert_recorded_as_a_deployment_failure(rig, "repeated", "401", count=3.0) + + +def test_a_provider_401_rescued_by_a_fallback_still_counts_against_the_rejected_deployment(rig: Rig) -> None: + rig.upstream.drain() + response: Final = rig.gateway.request( + "POST", + "/v1/chat/completions", + {"model": name("fallback"), "messages": messages("fallback"), "fallbacks": [name("healthy")]}, + ) + assert response.status_code == 200, response.text + assert [request.headers["authorization"] for request in rig.upstream.drain()] == [ + "Bearer sk-deployment-credential-fallback", + "Bearer sk-deployment-credential-healthy", + ] + assert_recorded_as_a_deployment_failure(rig, "fallback", "401") + rescued: Final = eventually( + lambda: scrape(rig.gateway), lambda samples: values(samples, SUCCESSES, model_id=identity("healthy")) == [1.0] + ) + assert values(rescued, FAILURES, model_id=identity("healthy")) == [] + + +def test_a_provider_auth_message_on_a_non_401_status_is_recorded(rig: Rig) -> None: + rig.upstream.drain() + response: Final = send(rig.gateway, "key-not-valid") + assert response.status_code == 400, response.text + assert_reached_with_the_deployment_credential(rig, "key-not-valid") + assert_recorded_as_a_deployment_failure(rig, "key-not-valid", "400") + + +def test_a_provider_429_is_recorded_as_before(rig: Rig) -> None: + rig.upstream.drain() + response: Final = send(rig.gateway, "rate-limited") + assert response.status_code == 429, response.text + assert_reached_with_the_deployment_credential(rig, "rate-limited") + assert_recorded_as_a_deployment_failure(rig, "rate-limited", "429") + + +def test_a_deployment_marked_down_by_a_provider_401_is_healthy_again_after_a_success(rig: Rig) -> None: + rig.upstream.drain() + assert send(rig.gateway, "recovers").status_code == 401 + assert_recorded_as_a_deployment_failure(rig, "recovers", "401") + recovered: Final = send(rig.gateway, "recovers") + assert recovered.status_code == 200, recovered.text + assert len(rig.upstream.drain()) == 2 + eventually( + lambda: scrape(rig.gateway), + lambda samples: values(samples, STATE, model_id=identity("recovers"), api_base=rig.api_base) == [0.0], + ) + + +def test_a_per_caller_credential_rejection_stays_out_of_the_deployment_metrics(rig: Rig) -> None: + rig.upstream.drain() + response: Final = send(rig.gateway, "caller-credential") + assert response.status_code == 401, response.text + assert "Connect GitHub Copilot" in response.text, response.text + assert rig.upstream.drain() == () + samples: Final = until(rig.gateway, PROXY_FAILED, requested_model=name("caller-credential")) + assert values(samples, FAILURES, model_id=identity("caller-credential")) == [] + assert values(samples, TOTALS, model_id=identity("caller-credential")) == [] + assert values(samples, LLM_FAILED, model_id=identity("caller-credential")) == [] + assert values(samples, STATE, model_id=identity("caller-credential")) == [] + + +def deployment_series(samples: Sequence[Sample]) -> frozenset[tuple[str, tuple[tuple[str, str], ...]]]: + return frozenset((sample.name, sample.identity()) for sample in samples if sample.name in DEPLOYMENT_SERIES) + + +def test_a_provider_401_on_an_api_key_the_caller_sent_stays_out_of_the_deployment_metrics(rig: Rig) -> None: + caller_key: Final = f"sk-caller-supplied-{uuid.uuid4().hex}" + before: Final = deployment_series(scrape(rig.gateway)) + rig.upstream.drain() + response: Final = rig.gateway.request( + "POST", + "/v1/chat/completions", + {"model": name("caller-api-key"), "messages": messages("caller-api-key"), "api_key": caller_key}, + ) + assert response.status_code == 401, response.text + assert [request.headers["authorization"] for request in rig.upstream.drain()] == [f"Bearer {caller_key}"] + samples: Final = until(rig.gateway, PROXY_FAILED, requested_model=name("caller-api-key")) + assert deployment_series(samples) - before == frozenset(), recorded(samples, requested_model=name("caller-api-key")) + + +def test_a_provider_401_on_a_stored_credential_the_caller_names_leaves_a_healthy_deployment_healthy(rig: Rig) -> None: + cell: Final = "caller-credential-name" + rig.upstream.drain() + assert send(rig.gateway, cell).status_code == 200 + assert_reached_with_the_deployment_credential(rig, cell) + response: Final = rig.gateway.request( + "POST", + "/v1/chat/completions", + {"model": name(cell), "messages": messages(cell), "litellm_credential_name": f"revoked-key-{RUN}"}, + ) + assert response.status_code == 401, response.text + assert [request.headers["authorization"] for request in rig.upstream.drain()] == [f"Bearer {REVOKED_STORED_KEY}"] + samples: Final = until(rig.gateway, PROXY_FAILED, requested_model=name(cell)) + observed: Final = recorded(samples, model_id=identity(cell)) + assert values(samples, FAILURES, model_id=identity(cell)) == [], observed + assert values(samples, LLM_FAILED, model_id=identity(cell)) == [], observed + assert values(samples, TOTALS, model_id=identity(cell)) == [1.0], observed + assert values(samples, STATE, model_id=identity(cell)) == [0.0], observed + + +def anthropic_messages(gateway: Gateway, cell: str, key: str, headers: dict[str, str]) -> httpx.Response: + body: Final[dict[str, JsonValue]] = {"model": name(cell), "max_tokens": 16, "messages": messages(cell)} + return gateway.request("POST", "/v1/messages", body, key=key, headers=headers) + + +def caller_header(field: str, header: str, value: str) -> JsonValue: + if field == "provider_specific_header": + return {"custom_llm_provider": "openai", "extra_headers": {header: value}} + return {header: value} + + +@pytest.mark.parametrize( + "cell,field", + [ + ("caller-extra-headers", "extra_headers"), + ("caller-headers", "headers"), + ("caller-provider-specific-header", "provider_specific_header"), + ], +) +def test_a_provider_401_on_an_authorization_header_the_caller_sends_stays_out_of_the_deployment_metrics( + rig: Rig, cell: str, field: str +) -> None: + caller_value: Final = f"Bearer sk-{cell}-{uuid.uuid4().hex}" + rig.upstream.drain() + response: Final = rig.gateway.request( + "POST", + "/v1/chat/completions", + {"model": name(cell), "messages": messages(cell), field: caller_header(field, "Authorization", caller_value)}, + ) + assert response.status_code == 401, response.text + assert [request.headers["authorization"] for request in rig.upstream.drain()] == [caller_value] + samples: Final = until(rig.gateway, PROXY_FAILED, requested_model=name(cell)) + observed: Final = recorded(samples, model_id=identity(cell)) + assert values(samples, FAILURES, model_id=identity(cell)) == [], observed + assert values(samples, TOTALS, model_id=identity(cell)) == [], observed + assert values(samples, LLM_FAILED, model_id=identity(cell)) == [], observed + assert values(samples, STATE, model_id=identity(cell)) == [], observed + + +@pytest.mark.parametrize( + "cell,field", + [ + ("plain-extra-headers", "extra_headers"), + ("plain-headers", "headers"), + ("plain-provider-specific-header", "provider_specific_header"), + ], +) +def test_a_provider_401_on_the_deployments_own_key_stays_out_when_the_caller_sends_a_plain_header( + rig: Rig, cell: str, field: str +) -> None: + trace: Final = f"{cell}-{uuid.uuid4().hex}" + rig.upstream.drain() + response: Final = rig.gateway.request( + "POST", + "/v1/chat/completions", + {"model": name(cell), "messages": messages(cell), field: caller_header(field, "X-Caller-Trace", trace)}, + ) + assert response.status_code == 401, response.text + reached: Final = rig.upstream.drain() + assert [(request.headers["authorization"], request.headers.get("x-caller-trace")) for request in reached] == [ + (f"Bearer sk-deployment-credential-{cell}", trace) + ] + assert_kept_out_of_the_deployment_metrics(rig, cell) + + +def test_a_provider_401_on_a_provider_credential_header_the_proxy_forwards_stays_out_of_the_deployment_metrics( + rig: Rig, +) -> None: + caller_key: Final = f"AIza-forwarded-{uuid.uuid4().hex}" + rig.upstream.drain() + response: Final = rig.gateway.request( + "POST", + "/v1/chat/completions", + {"model": name("forwarded-provider-header"), "messages": messages("forwarded-provider-header")}, + headers={"x-goog-api-key": caller_key}, + ) + assert response.status_code == 401, response.text + assert [request.headers.get("x-goog-api-key") for request in rig.upstream.drain()] == [caller_key] + samples: Final = until(rig.gateway, PROXY_FAILED, requested_model=name("forwarded-provider-header")) + observed: Final = recorded(samples, model_id=identity("forwarded-provider-header")) + assert values(samples, FAILURES, model_id=identity("forwarded-provider-header")) == [], observed + assert values(samples, TOTALS, model_id=identity("forwarded-provider-header")) == [], observed + assert values(samples, LLM_FAILED, model_id=identity("forwarded-provider-header")) == [], observed + assert values(samples, STATE, model_id=identity("forwarded-provider-header")) == [], observed + + +def test_a_provider_401_on_the_deployments_own_key_stays_out_when_the_proxy_forwards_a_plain_header(rig: Rig) -> None: + trace: Final = f"forwarded-plain-header-{uuid.uuid4().hex}" + rig.upstream.drain() + response: Final = rig.gateway.request( + "POST", + "/v1/chat/completions", + {"model": name("forwarded-plain-header"), "messages": messages("forwarded-plain-header")}, + headers={"x-caller-trace": trace}, + ) + assert response.status_code == 401, response.text + assert [ + (request.headers["authorization"], request.headers.get("x-caller-trace")) for request in rig.upstream.drain() + ] == [("Bearer sk-deployment-credential-forwarded-plain-header", trace)] + assert_kept_out_of_the_deployment_metrics(rig, "forwarded-plain-header") + + +def test_a_provider_401_on_the_deployments_own_key_counts_when_the_proxy_forwards_only_its_own_user_information( + rig: Rig, +) -> None: + rig.upstream.drain() + response: Final = send(rig.gateway, "forwarded-user-information") + assert response.status_code == 401, response.text + reached: Final = rig.upstream.drain() + assert [ + (request.headers["authorization"], "x-litellm-user_api_key_hash" in request.headers) for request in reached + ] == [("Bearer sk-deployment-credential-forwarded-user-information", True)] + assert_recorded_as_a_deployment_failure(rig, "forwarded-user-information", "401") + + +def test_a_provider_401_on_a_gateway_key_the_proxy_forwards_stays_out_of_a_healthy_deployments_metrics( + rig: Rig, +) -> None: + rig.upstream.drain() + response: Final = rig.gateway.request( + "POST", + "/v1/chat/completions", + {"model": name("forwarded-gateway-key"), "messages": messages("forwarded-gateway-key")}, + headers={"x-portkey-api-key": REVOKED_GATEWAY_KEY}, + ) + assert response.status_code == 401, response.text + assert [ + (request.headers["authorization"], request.headers.get("x-portkey-api-key")) for request in rig.upstream.drain() + ] == [("Bearer sk-deployment-credential-forwarded-gateway-key", REVOKED_GATEWAY_KEY)] + assert_kept_out_of_the_deployment_metrics(rig, "forwarded-gateway-key") + + +@pytest.mark.parametrize( + "cell,body,headers", + [ + ("caller-organization", {"organization": UNKNOWN_ORGANIZATION}, {}), + ("forwarded-organization", {}, {"OpenAI-Organization": UNKNOWN_ORGANIZATION}), + ], +) +def test_a_provider_401_on_an_organization_the_caller_sends_stays_out_of_a_healthy_deployments_metrics( + rig: Rig, cell: str, body: dict[str, JsonValue], headers: dict[str, str] +) -> None: + rig.upstream.drain() + response: Final = rig.gateway.request( + "POST", "/v1/chat/completions", {"model": name(cell), "messages": messages(cell), **body}, headers=headers + ) + assert response.status_code == 401, response.text + assert [ + (request.headers["authorization"], request.headers.get("openai-organization")) + for request in rig.upstream.drain() + ] == [(f"Bearer sk-deployment-credential-{cell}", UNKNOWN_ORGANIZATION)] + assert_kept_out_of_the_deployment_metrics(rig, cell) + + +@pytest.mark.parametrize( + ("cell", "headers"), + [ + ("anthropic-own-key", {}), + ("anthropic-sdk-own-key", {"anthropic-version": "2023-06-01", "anthropic-beta": "tools-2024-04-04"}), + ], + ids=["no-client-headers", "anthropic-sdk-headers"], +) +def test_a_provider_401_on_an_anthropic_deployments_own_key_is_recorded( + rig: Rig, cell: str, headers: dict[str, str] +) -> None: + with rig.gateway.scenario() as scenario: + key: Final = scenario.key(models=[name(cell)]) + rig.upstream.drain() + response: Final = anthropic_messages(rig.gateway, cell, key, headers) + assert response.status_code == 401, response.text + assert [request.headers.get("x-api-key") for request in rig.upstream.drain()] == [ + f"sk-ant-api03-deployment-credential-{cell}" + ] + assert_recorded_as_a_deployment_failure(rig, cell, "401") + + +def test_a_provider_401_on_an_anthropic_oauth_token_the_caller_sent_stays_out_of_the_deployment_metrics( + rig: Rig, +) -> None: + with rig.gateway.scenario() as scenario: + key: Final = scenario.key(models=[name("caller-oauth")]) + rig.upstream.drain() + response: Final = anthropic_messages( + rig.gateway, + "caller-oauth", + CALLER_OAUTH_TOKEN, + {"x-litellm-api-key": key}, + ) + assert response.status_code == 401, response.text + assert [request.headers.get("authorization") for request in rig.upstream.drain()] == [ + f"Bearer {CALLER_OAUTH_TOKEN}" + ] + samples: Final = until(rig.gateway, PROXY_FAILED, requested_model=name("caller-oauth")) + assert {metric: values(samples, metric, model_id=identity("caller-oauth")) for metric in DEPLOYMENT_SERIES} == { + metric: [] for metric in DEPLOYMENT_SERIES + }, recorded(samples, requested_model=name("caller-oauth")) + + +def test_a_provider_401_on_an_azure_deployments_own_ad_token_is_recorded(rig: Rig) -> None: + rig.upstream.drain() + response: Final = send(rig.gateway, "azure-own-token") + assert response.status_code == 401, response.text + assert [request.headers.get("authorization") for request in rig.upstream.drain()] == [ + "Bearer deployment-entra-token-azure-own-token" + ] + assert_recorded_as_a_deployment_failure(rig, "azure-own-token", "401") + + +def caller_azure_request(cell: str, route: str, credential: dict[str, JsonValue]) -> tuple[str, dict[str, JsonValue]]: + if route == "embeddings": + return "/v1/embeddings", {"model": name(cell), "input": cell, **credential} + if route == "responses": + return "/v1/responses", {"model": name(cell), "input": cell, **credential} + if route == "messages": + return "/v1/messages", {"model": name(cell), "max_tokens": 16, "messages": messages(cell), **credential} + return "/v1/chat/completions", {"model": name(cell), "messages": messages(cell), **credential} + + +@pytest.mark.parametrize( + ("route", "inside_extra_body"), + CALLER_AZURE_CELLS, + ids=[f"{route}{'-extra-body' if inside_extra_body else ''}" for route, inside_extra_body in CALLER_AZURE_CELLS], +) +@pytest.mark.parametrize("opt_in", ("deployment", "proxy-wide")) +def test_a_provider_401_on_an_azure_ad_token_the_caller_sent_stays_out_of_the_deployment_metrics( + request: pytest.FixtureRequest, opt_in: str, route: str, inside_extra_body: bool +) -> None: + opted: Final[Rig] = request.getfixturevalue("rig" if opt_in == "deployment" else "opted_in") + cell: Final = caller_azure_cell(opt_in, route, inside_extra_body) + token: Final = f"caller-entra-token-{uuid.uuid4().hex}" + credential: Final[dict[str, JsonValue]] = ( + {"extra_body": {"azure_ad_token": token}} if inside_extra_body else {"azure_ad_token": token} + ) + opted.upstream.drain() + response: Final = opted.gateway.request("POST", *caller_azure_request(cell, route, credential)) + assert response.status_code == 401, response.text + assert [reached.headers.get("authorization") for reached in opted.upstream.drain()] == [ + None if inside_extra_body else f"Bearer {token}" + ] + samples: Final = until(opted.gateway, PROXY_FAILED, requested_model=name(cell)) + assert {metric: values(samples, metric, model_id=identity(cell)) for metric in DEPLOYMENT_SERIES} == { + metric: [] for metric in DEPLOYMENT_SERIES + }, recorded(samples, requested_model=name(cell)) + + +@pytest.mark.parametrize(("cell", "field"), CALLER_CREDENTIAL_CELLS, ids=[cell for cell, _ in CALLER_CREDENTIAL_CELLS]) +def test_a_provider_401_on_a_provider_credential_the_caller_sent_stays_out_of_the_deployment_metrics( + rig: Rig, cell: str, field: str +) -> None: + caller_credential: Final = f"caller-credential-{uuid.uuid4().hex}" + rig.upstream.drain() + response: Final = rig.gateway.request( + "POST", "/v1/chat/completions", {"model": name(cell), "messages": messages(cell), field: caller_credential} + ) + assert response.status_code == 401, response.text + assert [reached.headers.get("authorization") for reached in rig.upstream.drain()] == [f"Bearer {caller_credential}"] + samples: Final = until(rig.gateway, PROXY_FAILED, requested_model=name(cell)) + assert {metric: values(samples, metric, model_id=identity(cell)) for metric in DEPLOYMENT_SERIES} == { + metric: [] for metric in DEPLOYMENT_SERIES + }, recorded(samples, requested_model=name(cell)) + + +@pytest.mark.parametrize("cell", TOKEN_EXCHANGE_CELLS) +def test_a_token_exchange_deployment_rejecting_a_caller_without_an_identity_token_stays_out_of_the_deployment_metrics( + rig: Rig, cell: str +) -> None: + rig.upstream.drain() + response: Final = send(rig.gateway, cell) + assert response.status_code == 401, response.text + assert "IdP-issued access token" in response.text, response.text + assert rig.upstream.drain() == () + samples: Final = until(rig.gateway, PROXY_FAILED, requested_model=name(cell)) + assert {metric: values(samples, metric, model_id=identity(cell)) for metric in DEPLOYMENT_SERIES} == { + metric: [] for metric in DEPLOYMENT_SERIES + }, recorded(samples, requested_model=name(cell)) + + +@pytest.mark.parametrize("cell", KEYLESS_CELLS) +def test_a_missing_deployment_key_reported_before_the_provider_is_called_stays_out_of_the_deployment_metrics( + rig: Rig, cell: str +) -> None: + rig.upstream.drain() + response: Final = send(rig.gateway, cell) + assert response.status_code == 401, response.text + assert "Missing Anthropic API Key" in response.text, response.text + assert rig.upstream.drain() == () + assert_kept_out_of_the_deployment_metrics(rig, cell) + + +@pytest.mark.parametrize("opt_in", ("deployment", "proxy-wide")) +def test_a_provider_401_at_a_bedrock_endpoint_the_caller_sends_stays_out_of_the_deployment_metrics( + request: pytest.FixtureRequest, opt_in: str +) -> None: + opted: Final[Rig] = request.getfixturevalue("rig" if opt_in == "deployment" else "opted_in") + cell: Final = f"{opt_in}-caller-bedrock-endpoint" + opted.upstream.drain() + response: Final = opted.gateway.request( + "POST", + "/v1/chat/completions", + {"model": name(cell), "messages": messages(cell), "aws_bedrock_runtime_endpoint": opted.upstream.url}, + ) + assert response.status_code == 401, response.text + assert [reached.target for reached in opted.upstream.drain()] == [f"/model/{REJECTS}/converse"] + assert_kept_out_of_the_deployment_metrics(opted, cell) + + +def test_a_provider_401_at_an_api_base_the_caller_sends_counts_against_a_one_off_deployment(rig: Rig) -> None: + caller_api_base: Final = f"{rig.upstream.url}/caller-endpoint-{RUN}/v1" + rig.upstream.drain() + response: Final = rig.gateway.request( + "POST", + "/v1/chat/completions", + {"model": name("caller-api-base"), "messages": messages("caller-api-base"), "api_base": caller_api_base}, + ) + assert response.status_code == 401, response.text + assert [(reached.target, reached.headers["authorization"]) for reached in rig.upstream.drain()] == [ + (f"/caller-endpoint-{RUN}/v1/chat/completions", "Bearer sk-deployment-credential-caller-api-base") + ] + samples: Final = until(rig.gateway, FAILURES, api_base=caller_api_base) + one_off: Final = {sample.labels["model_id"] for sample in series(samples, FAILURES, api_base=caller_api_base)} + assert len(one_off) == 1 and identity("caller-api-base") not in one_off, recorded(samples, api_base=caller_api_base) + assert values(samples, FAILURES, api_base=caller_api_base, exception_status="401") == [1.0] + assert values(samples, TOTALS, api_base=caller_api_base) == [1.0] + assert values(samples, STATE, api_base=caller_api_base) == [1.0] + assert values(samples, LLM_FAILED, model_id=next(iter(one_off))) == [1.0] + assert {metric: values(samples, metric, model_id=identity("caller-api-base")) for metric in DEPLOYMENT_SERIES} == { + metric: [] for metric in DEPLOYMENT_SERIES + } + + +def _gated_key(scenario: Scenario, cell: str) -> str | None: + if cell == "invalid-key": + return f"sk-not-a-virtual-key-{uuid.uuid4().hex}" + if cell == "missing-key": + return None + if cell == "no-model-access": + return scenario.key(models=[name("healthy")]) + key: Final = scenario.key(models=[name(cell)]) + if cell == "expired-key": + write_rows( + "UPDATE \"LiteLLM_VerificationToken\" SET expires = now() - interval '1 hour' WHERE token = %s", + (sha256(key.encode()).hexdigest(),), + database_url=scenario.gateway.database_url, + ) + return key + scenario.gateway.post("/key/block", {"key": key}) + return key + + +def _gated(gateway: Gateway, cell: str, key: str | None) -> httpx.Response: + if key is None: + return gateway.client.post("/v1/chat/completions", json={"model": name(cell), "messages": messages(cell)}) + return send(gateway, cell, key=key) + + +def recorded_before(cell: str) -> list[tuple[str, str, str, float]]: + if cell in ("invalid-key", "expired-key"): + return [] + return sorted([(FAILURES, "", "", 1.0), (TOTALS, "", "", 1.0), (LLM_FAILED, identity(cell), "", 1.0)]) + + +def deployment_rows(samples: Sequence[Sample], cell: str) -> list[tuple[str, str, str, float]]: + return sorted( + (sample.name, sample.labels.get("model_id", ""), sample.labels.get("api_base", ""), sample.value) + for sample in samples + if sample.name in DEPLOYMENT_SERIES + and name(cell) in (sample.labels.get("requested_model"), sample.labels.get("model")) + ) + + +@pytest.mark.parametrize("cell", GATED_CELLS) +def test_a_request_the_proxy_rejects_itself_never_marks_the_deployment_down_and_is_recorded_as_before( + rig: Rig, cell: str +) -> None: + with rig.gateway.scenario() as scenario: + key: Final = _gated_key(scenario, cell) + rig.upstream.drain() + response: Final = _gated(rig.gateway, cell, key) + assert response.status_code == (403 if cell == "no-model-access" else 401), response.text + assert rig.upstream.drain() == () + samples: Final = until(rig.gateway, PROXY_FAILED, requested_model=name(cell)) + assert deployment_rows(samples, cell) == recorded_before(cell), recorded(samples, requested_model=name(cell)) + + +def test_a_key_rate_limit_rejected_at_the_proxy_is_still_counted_as_before(rig: Rig) -> None: + with rig.gateway.scenario() as scenario: + key: Final = scenario.key(models=[name("key-rpm-limit")], rpm_limit=1) + rig.upstream.drain() + admitted: Final = send(rig.gateway, "key-rpm-limit", key=key) + assert admitted.status_code == 200, admitted.text + limited: Final = send(rig.gateway, "key-rpm-limit", key=key) + assert limited.status_code == 429, limited.text + assert len(rig.upstream.drain()) == 1 + samples: Final = until(rig.gateway, FAILURES, requested_model=name("key-rpm-limit"), exception_status="429") + assert values(samples, FAILURES, requested_model=name("key-rpm-limit"), exception_status="429") == [1.0] + eventually( + lambda: scrape(rig.gateway), + lambda observed: ( + values(observed, STATE, model_id=identity("key-rpm-limit"), api_base=rig.api_base) == [0.0] + ), + ) + + +@pytest.fixture(scope="module") +def mcp_peer() -> Iterator[McpPeer]: + with scripted_peer(echo_tool("add")) as peer: + yield peer + + +def test_an_mcp_tool_call_the_proxy_rejects_for_the_caller_stays_out_of_the_llm_failure_metrics( + rig: Rig, mcp_peer: McpPeer +) -> None: + alias: Final = "a365" + RUN + with rig.gateway.scenario() as scenario: + server: Final = register_mcp(scenario, mcp_peer, alias) + key: Final = scenario.key(object_permission={"mcp_servers": [server]}) + hashed: Final = sha256(key.encode()).hexdigest() + outcomes: Final = { + entry: McpCaller(rig.gateway, key, entry, alias).call(f"{alias}-add", {"entry": entry}, server) + for entry in ENTRY_POINTS + } + assert all( + outcome.error is not None and "Agent 365 guardrail rejected" in outcome.raw for outcome in outcomes.values() + ), {entry: outcome.raw for entry, outcome in outcomes.items()} + eventually( + lambda: rig.gateway.rows(GUARDRAIL_ROWS, (AGENT_365_GUARDRAIL, hashed, "call_mcp_tool")), + lambda rows: [row["status"] for row in rows] == ["guardrail_intervened"] * len(ENTRY_POINTS), + seconds=70, + ) + samples: Final = scrape(rig.gateway) + assert values(samples, LLM_FAILED, hashed_api_key=hashed) == [] + assert values(samples, FAILURES, hashed_api_key=hashed) == [] + assert values(samples, TOTALS, hashed_api_key=hashed) == [] diff --git a/tests/integration/observability/test_prometheus_provider_auth_failure_chaos.py b/tests/integration/observability/test_prometheus_provider_auth_failure_chaos.py new file mode 100644 index 00000000000..a1fe1cf4f33 --- /dev/null +++ b/tests/integration/observability/test_prometheus_provider_auth_failure_chaos.py @@ -0,0 +1,147 @@ +import threading +import uuid +from collections.abc import Iterator, Sequence +from concurrent.futures import ThreadPoolExecutor +from contextlib import contextmanager +from dataclasses import dataclass +from pathlib import Path +from typing import Final + +import httpx +import psutil +from integration._support.client import Gateway, eventually +from integration._support.process import OwnedProxy, owned_proxy_process +from integration._support.prometheus_series import Sample, scrape +from integration._support.wire import Wire, wire_server +from test_prometheus_provider_auth_failure import ( + FAILURES, + LLM_FAILED, + STATE, + TOTALS, + Provider, + config, + identity, + name, + send, + values, +) + +BURST: Final = 12 +ENDPOINTS: Final = ("chat", "chat-stream", "messages", "responses") + + +@dataclass(frozen=True, slots=True) +class ChaosRig: + owned: OwnedProxy + upstream: Wire + release: threading.Event + + +@contextmanager +def _rig(gateway: Gateway, tmp_path: Path) -> Iterator[ChaosRig]: + release: Final = threading.Event() + prom_dir: Final = tmp_path / "prom" + prom_dir.mkdir() + with ( + wire_server(Provider(release)) as upstream, + owned_proxy_process( + gateway, + tmp_path, + {"PROMETHEUS_MULTIPROC_DIR": str(prom_dir)}, + config=config(tmp_path, upstream), + workers=2, + ) as owned, + ): + try: + yield ChaosRig(owned, upstream, release) + finally: + release.set() + + +def _status(gateway: Gateway, cell: str, model: str, key: str | None = None) -> int: + try: + return send(gateway, cell, model=model, key=key).status_code + except httpx.HTTPError: + return -1 + + +def _holds_a_connection_to(pid: int, port: int) -> bool: + return any(connection.raddr[1:] == (port,) for connection in psutil.Process(pid).net_connections(kind="tcp")) + + +def _workers_calling_upstream(rig: ChaosRig) -> frozenset[int]: + port: Final = int(rig.upstream.url.rsplit(":", 1)[1]) + return frozenset(pid for pid in rig.owned.worker_pids() if _holds_a_connection_to(pid, port)) + + +def _counted(samples: Sequence[Sample], cell: str) -> tuple[float, float, float]: + return ( + sum(values(samples, FAILURES, model_id=identity(cell))), + sum(values(samples, TOTALS, model_id=identity(cell))), + sum(values(samples, LLM_FAILED, model_id=identity(cell))), + ) + + +def test_a_burst_of_provider_401s_and_proxy_rejects_across_two_workers_counts_only_the_provider_401s( + gateway: Gateway, tmp_path: Path +) -> None: + with _rig(gateway, tmp_path) as rig: + rig.release.set() + workers: Final = eventually(rig.owned.worker_pids, lambda pids: len(pids) == 2) + invalid: Final = f"sk-not-a-virtual-key-{uuid.uuid4().hex}" + calls: Final[tuple[tuple[str, str, str | None], ...]] = tuple( + (ENDPOINTS[index % len(ENDPOINTS)], name("burst"), None) for index in range(BURST) + ) + tuple(("chat", name("invalid-key"), invalid) for _ in range(BURST)) + + def call(cell: str, model: str, key: str | None) -> int: + return _status(rig.owned.gateway, cell, model, key) + + with ThreadPoolExecutor(max_workers=8) as pool: + statuses: Final = tuple(pool.map(call, *zip(*calls, strict=True))) + assert statuses == (401,) * (2 * BURST), statuses + assert len(rig.upstream.drain()) == BURST + samples: Final = eventually( + lambda: scrape(rig.owned.gateway), + lambda observed: _counted(observed, "burst") == (BURST, BURST, BURST), + seconds=70, + return_last_on_timeout=True, + ) + assert _counted(samples, "burst") == (BURST, BURST, BURST), (workers, _counted(samples, "burst")) + assert set(values(samples, STATE, model_id=identity("burst"))) == {1.0} + assert values(samples, FAILURES, requested_model=name("invalid-key")) == [] + assert values(samples, LLM_FAILED, model=name("invalid-key")) == [] + + +def test_a_worker_killed_while_provider_401s_are_in_flight_loses_no_answered_failure( + gateway: Gateway, tmp_path: Path +) -> None: + with _rig(gateway, tmp_path) as rig: + eventually(rig.owned.worker_pids, lambda pids: len(pids) == 2) + with ThreadPoolExecutor(max_workers=8) as pool: + futures: Final = tuple(pool.submit(_status, rig.owned.gateway, "chat", name("held")) for _ in range(BURST)) + eventually(lambda: rig.upstream.received.qsize() >= 8, bool, seconds=30) + victim: Final = min(eventually(lambda: _workers_calling_upstream(rig), bool)) + with rig.owned.replacing_worker(victim) as kill: + kill() + rig.release.set() + statuses: Final = tuple(future.result() for future in futures) + reached: Final = len(rig.upstream.drain()) + answered: Final = statuses.count(401) + lost: Final = statuses.count(-1) + assert answered + lost == BURST and lost > 0, statuses + samples: Final = eventually( + lambda: scrape(rig.owned.gateway), + lambda observed: answered <= _counted(observed, "held")[0] <= reached, + seconds=70, + return_last_on_timeout=True, + ) + counted: Final = _counted(samples, "held") + assert answered <= counted[0] <= reached and counted[0] == counted[1] == counted[2], (statuses, counted) + follow_up: Final = _status(rig.owned.gateway, "chat", name("held")) + assert follow_up == 401 + recounted: Final = eventually( + lambda: _counted(scrape(rig.owned.gateway), "held"), + lambda observed: observed[0] == counted[0] + 1, + seconds=70, + ) + assert recounted == (counted[0] + 1,) * 3 diff --git a/tests/integration/pricing/test_opencode_go_reported_cost_wire.py b/tests/integration/pricing/test_opencode_go_reported_cost_wire.py new file mode 100644 index 00000000000..6ac3bdccf27 --- /dev/null +++ b/tests/integration/pricing/test_opencode_go_reported_cost_wire.py @@ -0,0 +1,198 @@ +import json +from collections.abc import Mapping +from typing import Final + +import pytest +from integration._support.client import Gateway, eventually +from integration._support.database import read_rows +from integration._support.wire import Reply, Request, wire_server +from pydantic import JsonValue, TypeAdapter + +_LIST_COST: Final = 0.00412 +_JSON_OBJECT: Final = TypeAdapter(dict[str, JsonValue]) + +# OpenCode's documented usage block (opencode.ai/v2/docs/console/api/inference, "Cost", read 2026-10-24): +# usage.cost is what hit the prepaid balance (0 inside the Go plan), usage.opencode.list_cost is the model price +_GO_BLOCK: Final[Mapping[str, JsonValue]] = { + "cost": 0, + "opencode": {"billing_source": "go", "list_cost": _LIST_COST, "allowance": _LIST_COST}, +} +_CHAT_USAGE: Final[Mapping[str, JsonValue]] = { + "prompt_tokens": 1200, + "completion_tokens": 300, + "total_tokens": 1500, + **_GO_BLOCK, +} +_RESPONSES_USAGE: Final[Mapping[str, JsonValue]] = { + "input_tokens": 1200, + "output_tokens": 300, + "total_tokens": 1500, + **_GO_BLOCK, +} +_MESSAGES_USAGE: Final[Mapping[str, JsonValue]] = {"input_tokens": 1200, "output_tokens": 300, **_GO_BLOCK} + + +def _approx(value: float) -> object: + return pytest.approx(value, rel=1e-6) # pyright: ignore[reportUnknownMemberType] # pytest lacks typed approx stubs + + +def _data_frame(event: Mapping[str, JsonValue]) -> bytes: + return f"data: {json.dumps(event)}\n\n".encode() + + +def _event_frame(event: Mapping[str, JsonValue]) -> bytes: + return f"event: {event['type']}\ndata: {json.dumps(event)}\n\n".encode() + + +def _chat_completion() -> bytes: + return json.dumps( + { + "id": "chatcmpl-go", + "object": "chat.completion", + "created": 1, + "model": "glm-5.3", + "choices": [{"index": 0, "finish_reason": "stop", "message": {"role": "assistant", "content": "ok"}}], + "usage": dict(_CHAT_USAGE), + } + ).encode() + + +def _chat_stream() -> tuple[bytes, ...]: + text: Final = { + "id": "chatcmpl-go", + "object": "chat.completion.chunk", + "created": 1, + "model": "glm-5.3", + "choices": [{"index": 0, "delta": {"role": "assistant", "content": "ok"}, "finish_reason": None}], + } + finish: Final = {**text, "choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}]} + final_usage: Final = {**text, "choices": [], "usage": dict(_CHAT_USAGE)} + return (*(_data_frame(event) for event in (text, finish, final_usage)), b"data: [DONE]\n\n") + + +def _responses_response() -> Mapping[str, JsonValue]: + return { + "id": "resp_go", + "object": "response", + "created_at": 1, + "status": "completed", + "model": "gpt-6-luna", + "output": [ + { + "id": "msg_go", + "type": "message", + "status": "completed", + "role": "assistant", + "content": [{"type": "output_text", "text": "ok", "annotations": []}], + } + ], + "usage": dict(_RESPONSES_USAGE), + } + + +def _responses_stream() -> tuple[bytes, ...]: + response: Final = _responses_response() + return ( + _event_frame( + {"type": "response.created", "sequence_number": 0, "response": {**response, "status": "in_progress"}} + ), + _event_frame( + { + "type": "response.output_text.delta", + "sequence_number": 1, + "item_id": "msg_go", + "output_index": 0, + "content_index": 0, + "delta": "ok", + } + ), + _event_frame({"type": "response.completed", "sequence_number": 2, "response": response}), + ) + + +def _anthropic_message() -> Mapping[str, JsonValue]: + return { + "id": "msg_go", + "type": "message", + "role": "assistant", + "model": "claude-haiku-5-5", + "content": [{"type": "text", "text": "ok"}], + "stop_reason": "end_turn", + "stop_sequence": None, + "usage": dict(_MESSAGES_USAGE), + } + + +def _anthropic_stream() -> tuple[bytes, ...]: + start: Final = {**_anthropic_message(), "content": [], "stop_reason": None} + return ( + _event_frame( + {"type": "message_start", "message": {**start, "usage": {"input_tokens": 1200, "output_tokens": 0}}} + ), + _event_frame({"type": "content_block_start", "index": 0, "content_block": {"type": "text", "text": ""}}), + _event_frame({"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "ok"}}), + _event_frame({"type": "content_block_stop", "index": 0}), + _event_frame( + { + "type": "message_delta", + "delta": {"stop_reason": "end_turn", "stop_sequence": None}, + "usage": dict(_MESSAGES_USAGE), + } + ), + _event_frame({"type": "message_stop"}), + ) + + +def _respond(request: Request) -> Reply: + assert request.method == "POST", request.method + streaming: Final = _JSON_OBJECT.validate_json(request.body).get("stream") is True + if request.target.endswith("/chat/completions"): + return ( + Reply(content_type="text/event-stream", chunks=_chat_stream()) + if streaming + else Reply(body=_chat_completion()) + ) + if request.target.endswith("/responses"): + if streaming: + return Reply(content_type="text/event-stream", chunks=_responses_stream()) + return Reply(body=json.dumps(_responses_response()).encode()) + assert request.target.endswith("/v1/messages"), request.target + if streaming: + return Reply(content_type="text/event-stream", chunks=_anthropic_stream()) + return Reply(body=json.dumps(_anthropic_message()).encode()) + + +def _logged_spend(call_id: str) -> float: + rows: Final = eventually( + lambda: read_rows('SELECT spend FROM "LiteLLM_SpendLogs" WHERE litellm_call_id = %s', (call_id,)), + lambda values: len(values) == 1, + seconds=70, + ) + return float(rows[0]["spend"]) + + +def _body(path: str, model: str, stream: bool) -> Mapping[str, JsonValue]: + if path == "/v1/responses": + return {"model": model, "input": "hi", "stream": stream} + return {"model": model, "max_tokens": 16, "messages": [{"role": "user", "content": "hi"}], "stream": stream} + + +@pytest.mark.parametrize("stream", (False, True), ids=("non-stream", "stream")) +@pytest.mark.parametrize( + ("path", "model"), + ( + ("/v1/chat/completions", "opencode_go/glm-5.3"), + ("/v1/responses", "opencode_go/gpt-6-luna"), + ("/v1/messages", "opencode_go/claude-haiku-5-5"), + ), + ids=("chat", "responses", "messages"), +) +def test_request_is_billed_at_the_reported_list_cost(gateway: Gateway, path: str, model: str, stream: bool) -> None: + with wire_server(_respond) as wire, gateway.scenario() as scenario: + deployment: Final = scenario.model(model=model, api_base=wire.url, api_key="synthetic-go-key") + response: Final = gateway.request("POST", path, _body(path, deployment, stream)) + assert response.status_code == 200, response.text + assert "ok" in response.text + if not stream: + assert float(response.headers["x-litellm-response-cost"]) == _approx(_LIST_COST) + assert _logged_spend(response.headers["x-litellm-call-id"]) == _approx(_LIST_COST) diff --git a/tests/integration/providers/test_bedrock_native_guardrail_trace_spend.py b/tests/integration/providers/test_bedrock_native_guardrail_trace_spend.py new file mode 100644 index 00000000000..b1f2d5a9181 --- /dev/null +++ b/tests/integration/providers/test_bedrock_native_guardrail_trace_spend.py @@ -0,0 +1,423 @@ +"""A Bedrock deployment whose ``guardrailConfig`` has ``trace: enabled`` bills the policy units Bedrock reports in the +trace as guardrail cost, on every surface the deployment serves: ``/v1/chat/completions`` and ``/v1/responses`` over +Converse and Invoke, streamed and not, and the four ``/bedrock/model/{model}`` pass-through actions. The cost rides +``x-litellm-response-cost`` on non-streaming responses and the spend row's ``spend`` and ``guardrail_information`` +everywhere. ``trace: disabled`` leaves no usage, so nothing is billed beyond the tokens (LIT-10101)""" + +import base64 +import json +import uuid +from collections.abc import Iterator, Mapping +from dataclasses import dataclass +from hashlib import sha256 +from pathlib import Path +from typing import Final + +import boto3 +import pytest +import yaml +from botocore.config import Config +from integration._support.budget import case_timeout_seconds +from integration._support.client import Gateway, Scenario, eventually +from integration._support.process import graceful_stop_seconds, owned_proxy +from integration._support.upstream import _aws_event_frame +from integration._support.wire import Reply, Request, Wire, wire_server +from pydantic import JsonValue, TypeAdapter + +import litellm + +pytestmark: Final = pytest.mark.timeout(2 * graceful_stop_seconds() + 240) + +_MODEL_ID: Final = "anthropic.claude-sonnet-4-5-20250929-v1:0" +_EVENT_STREAM: Final = "application/vnd.amazon.eventstream" +_GUARDRAIL_ID: Final = "native-guardrail" +_INPUT_COST_PER_TOKEN: Final = 0.001 +_OUTPUT_COST_PER_TOKEN: Final = 0.002 +_PROMPT_TOKENS: Final = 5 +_COMPLETION_TOKENS: Final = 1 +_INPUT_USAGE: Final[Mapping[str, int]] = {"topicPolicyUnits": 1, "contentPolicyUnits": 1, "wordPolicyUnits": 1} +_OUTPUT_USAGE: Final[Mapping[str, int]] = {"topicPolicyUnits": 2, "sensitiveInformationPolicyUnits": 2} +_SUMMED_USAGE: Final[Mapping[str, int]] = { + "topicPolicyUnits": 3, + "contentPolicyUnits": 1, + "wordPolicyUnits": 1, + "sensitiveInformationPolicyUnits": 2, +} +_ACTIONS: Final = ("converse", "converse-stream", "invoke", "invoke-with-response-stream") +_JSON_OBJECT: Final = TypeAdapter(dict[str, JsonValue]) +_SPEND_SQL: Final = 'SELECT spend, metadata FROM "LiteLLM_SpendLogs" WHERE api_key=%s ORDER BY "startTime"' + + +def _llm_cost() -> float: + return _PROMPT_TOKENS * _INPUT_COST_PER_TOKEN + _COMPLETION_TOKENS * _OUTPUT_COST_PER_TOKEN + + +def _guardrail_cost() -> float: + """What the proxy's own cost map prices the traced units at, so the test owns the relation, not AWS's rates.""" + rates: Final = litellm.model_cost["bedrock/guardrails"]["guardrail_cost_per_unit"] + return sum(units * rates[counter] for counter, units in _SUMMED_USAGE.items()) + + +def _action(request: Request) -> str: + return request.target.partition("?")[0].rsplit("/", 1)[-1] + + +def _traced(request: Request) -> bool: + if _action(request).startswith("converse"): + config: Final = json.loads(request.body).get("guardrailConfig") or {} + return config.get("trace") == "enabled" + return request.headers.get("x-amzn-bedrock-trace", "").upper() == "ENABLED" + + +def _assessment(usage: Mapping[str, int]) -> dict[str, JsonValue]: + return {"invocationMetrics": {"usage": dict(usage), "guardrailProcessingLatency": 7}} + + +def _converse_trace() -> dict[str, JsonValue]: + return { + "guardrail": { + "inputAssessment": {_GUARDRAIL_ID: _assessment(_INPUT_USAGE)}, + "outputAssessments": {_GUARDRAIL_ID: [_assessment(_OUTPUT_USAGE)]}, + } + } + + +def _invoke_trace() -> dict[str, JsonValue]: + return { + "guardrail": { + "input": {_GUARDRAIL_ID: _assessment(_INPUT_USAGE)}, + "outputs": [{_GUARDRAIL_ID: _assessment(_OUTPUT_USAGE)}], + } + } + + +def _bedrock(request: Request) -> Reply: + """Bedrock's runtime as the caller sees it: a one-token answer, and the guardrail trace with its policy units only + when the request enabled tracing, in the shape of the action that served it.""" + traced: Final = _traced(request) + action: Final = _action(request) + usage: Final = {"inputTokens": _PROMPT_TOKENS, "outputTokens": _COMPLETION_TOKENS, "totalTokens": 6} + converse_trace: Final = {"trace": _converse_trace()} if traced else {} + if action == "converse": + body: Final = { + "output": {"message": {"role": "assistant", "content": [{"text": "ok"}]}}, + "stopReason": "end_turn", + "usage": usage, + "metrics": {"latencyMs": 3}, + **converse_trace, + } + return Reply(body=json.dumps(body).encode()) + if action == "converse-stream" and "toolConfig" in json.loads(request.body): + return Reply( + chunks=( + _aws_event_frame("messageStart", {"role": "assistant"}, "sc", "u"), + _aws_event_frame( + "contentBlockStart", + {"start": {"toolUse": {"toolUseId": "tool-1", "name": "lookup"}}, "contentBlockIndex": 0}, + "sc", + "u", + ), + _aws_event_frame( + "contentBlockDelta", + {"delta": {"toolUse": {"input": '{"q": "x"}'}}, "contentBlockIndex": 0}, + "sc", + "u", + ), + _aws_event_frame("contentBlockStop", {"contentBlockIndex": 0}, "sc", "u"), + _aws_event_frame("messageStop", {"stopReason": "tool_use"}, "sc", "u"), + _aws_event_frame( + "metadata", {"usage": usage, "metrics": {"latencyMs": 3}, **converse_trace}, "sc", "u" + ), + ), + content_type=_EVENT_STREAM, + ) + if action == "converse-stream": + return Reply( + chunks=( + _aws_event_frame("messageStart", {"role": "assistant"}, "sc", "u"), + _aws_event_frame("contentBlockDelta", {"delta": {"text": "ok"}, "contentBlockIndex": 0}, "sc", "u"), + _aws_event_frame("contentBlockStop", {"contentBlockIndex": 0}, "sc", "u"), + _aws_event_frame("messageStop", {"stopReason": "end_turn"}, "sc", "u"), + _aws_event_frame( + "metadata", {"usage": usage, "metrics": {"latencyMs": 3}, **converse_trace}, "sc", "u" + ), + ), + content_type=_EVENT_STREAM, + ) + invoke_trace: Final = {"amazon-bedrock-trace": _invoke_trace()} if traced else {} + if action == "invoke": + message: Final = { + "id": f"msg_{uuid.uuid4().hex[:12]}", + "type": "message", + "role": "assistant", + "model": "claude", + "content": [{"type": "text", "text": "ok"}], + "stop_reason": "end_turn", + "stop_sequence": None, + "usage": {"input_tokens": _PROMPT_TOKENS, "output_tokens": _COMPLETION_TOKENS}, + **invoke_trace, + } + return Reply(body=json.dumps(message).encode()) + events: Final = ( + { + "type": "message_start", + "message": { + "id": f"msg_{uuid.uuid4().hex[:12]}", + "type": "message", + "role": "assistant", + "model": "claude", + "content": [], + "stop_reason": None, + "stop_sequence": None, + "usage": {"input_tokens": _PROMPT_TOKENS, "output_tokens": 0}, + }, + }, + {"type": "content_block_start", "index": 0, "content_block": {"type": "text", "text": ""}}, + {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "ok"}}, + {"type": "content_block_stop", "index": 0}, + { + "type": "message_delta", + "delta": {"stop_reason": "end_turn", "stop_sequence": None}, + "usage": {"output_tokens": _COMPLETION_TOKENS}, + }, + { + "type": "message_stop", + "amazon-bedrock-invocationMetrics": { + "inputTokenCount": _PROMPT_TOKENS, + "outputTokenCount": _COMPLETION_TOKENS, + "invocationLatency": 3, + "firstByteLatency": 1, + }, + **invoke_trace, + }, + ) + return Reply( + chunks=tuple( + _aws_event_frame("chunk", {"bytes": base64.b64encode(json.dumps(event).encode()).decode()}, "sc", "u") + for event in events + ), + content_type=_EVENT_STREAM, + ) + + +def _deployment(wire: Wire, model: str, trace: str) -> Mapping[str, JsonValue]: + return { + "model": model, + "api_base": wire.url, + "aws_access_key_id": "AKIASCRIPTEDPROVIDER", + "aws_secret_access_key": "scripted-secret", + "aws_region_name": "us-east-1", + "use_in_pass_through": True, + "input_cost_per_token": _INPUT_COST_PER_TOKEN, + "output_cost_per_token": _OUTPUT_COST_PER_TOKEN, + "guardrailConfig": {"guardrailIdentifier": _GUARDRAIL_ID, "guardrailVersion": "1", "trace": trace}, + } + + +@dataclass(frozen=True, slots=True) +class Rig: + proxy: Gateway + scenario: Scenario + converse_model: str + invoke_model: str + untraced_model: str + + def key(self) -> str: + return self.scenario.key(key_alias=f"native-trace-{uuid.uuid4().hex[:8]}") + + def runtime(self, monkeypatch: pytest.MonkeyPatch, key: str): # noqa: ANN201 # boto3 clients are untyped + monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", key) + return boto3.client( + "bedrock-runtime", + endpoint_url=f"{str(self.proxy.client.base_url).rstrip('/')}/bedrock", + region_name="us-east-1", + config=Config(read_timeout=case_timeout_seconds(), retries={"total_max_attempts": 1}), + ) + + +@pytest.fixture(scope="module") +def rig(session_gateway: Gateway, tmp_path_factory: pytest.TempPathFactory) -> Iterator[Rig]: + suffix: Final = uuid.uuid4().hex[:12] + converse_model: Final = f"bedrock-traced-converse-{suffix}" + invoke_model: Final = f"bedrock-traced-invoke-{suffix}" + untraced_model: Final = f"bedrock-untraced-{suffix}" + directory: Final = tmp_path_factory.mktemp("bedrock-native-guardrail-trace") + base_config: Final = yaml.safe_load(Path("tests/integration/proxy_config.yaml").read_text()) + with wire_server(_bedrock) as wire: + config: Final = { + **base_config, + "model_list": [ + *base_config.get("model_list", []), + {"model_name": converse_model, "litellm_params": _deployment(wire, f"bedrock/{_MODEL_ID}", "enabled")}, + { + "model_name": invoke_model, + "litellm_params": _deployment(wire, f"bedrock/invoke/{_MODEL_ID}", "enabled"), + }, + {"model_name": untraced_model, "litellm_params": _deployment(wire, f"bedrock/{_MODEL_ID}", "disabled")}, + ], + } + config_path: Final = directory / "bedrock-native-guardrail-trace.yaml" + config_path.write_text(yaml.safe_dump(config)) + with owned_proxy(session_gateway, directory, {}, config=config_path) as proxy, proxy.scenario() as scenario: + yield Rig( + proxy=proxy, + scenario=scenario, + converse_model=converse_model, + invoke_model=invoke_model, + untraced_model=untraced_model, + ) + + +@dataclass(frozen=True, slots=True) +class SpendRow: + spend: float + guardrail_information: tuple[dict[str, JsonValue], ...] + + +def _spend_row(proxy: Gateway, key: str) -> SpendRow: + digest: Final = sha256(key.encode()).hexdigest() + (row,) = eventually(lambda: proxy.rows(_SPEND_SQL, (digest,)), lambda rows: len(rows) == 1, seconds=70) + metadata: Final = _JSON_OBJECT.validate_python( + json.loads(row["metadata"]) if isinstance(row["metadata"], str) else row["metadata"] + ) + raw_information: Final = metadata.get("guardrail_information") + entries: Final = raw_information if isinstance(raw_information, list) else [raw_information] + return SpendRow( + spend=float(str(row["spend"])), + guardrail_information=tuple(_JSON_OBJECT.validate_python(entry) for entry in entries if entry is not None), + ) + + +def _assert_billed_as_guardrail_cost(row: SpendRow) -> None: + assert row.spend == pytest.approx(_llm_cost() + _guardrail_cost()) + (entry,) = row.guardrail_information + assert entry["guardrail_provider"] == "bedrock" + assert entry["guardrail_name"] == _GUARDRAIL_ID + assert entry["guardrail_usage"] == _SUMMED_USAGE + assert isinstance(entry["guardrail_cost"], float) and entry["guardrail_cost"] == pytest.approx(_guardrail_cost()) + + +def _chat_body(model: str, stream: bool) -> dict[str, JsonValue]: + return {"model": model, "messages": [{"role": "user", "content": "hello"}], "max_tokens": 16, "stream": stream} + + +def _responses_body(model: str, stream: bool) -> dict[str, JsonValue]: + return {"model": model, "input": "hello", "stream": stream} + + +@pytest.mark.parametrize("api", ["converse", "invoke"]) +@pytest.mark.parametrize("endpoint", ["/v1/chat/completions", "/v1/responses"]) +def test_non_streaming_response_prices_the_trace_into_the_cost_header_and_the_spend_row( + rig: Rig, endpoint: str, api: str +) -> None: + key: Final = rig.key() + model: Final = rig.converse_model if api == "converse" else rig.invoke_model + body: Final = _chat_body(model, False) if endpoint == "/v1/chat/completions" else _responses_body(model, False) + response: Final = rig.proxy.request("POST", endpoint, body, key=key) + assert response.is_success, response.text[:400] + assert float(response.headers["x-litellm-response-cost"]) == pytest.approx(_llm_cost() + _guardrail_cost()) + _assert_billed_as_guardrail_cost(_spend_row(rig.proxy, key)) + + +@pytest.mark.parametrize("api", ["converse", "invoke"]) +@pytest.mark.parametrize("endpoint", ["/v1/chat/completions", "/v1/responses"]) +def test_streamed_response_prices_the_trace_of_the_final_event_into_the_spend_row( + rig: Rig, endpoint: str, api: str +) -> None: + key: Final = rig.key() + model: Final = rig.converse_model if api == "converse" else rig.invoke_model + body: Final = _chat_body(model, True) if endpoint == "/v1/chat/completions" else _responses_body(model, True) + with rig.proxy.client.stream( + "POST", endpoint, json=body, headers={"Authorization": f"Bearer {key}"}, timeout=case_timeout_seconds() + ) as response: + frames: Final = tuple(line for line in response.iter_lines() if line.startswith("data:")) + assert response.is_success and frames + _assert_billed_as_guardrail_cost(_spend_row(rig.proxy, key)) + + +@pytest.mark.parametrize("action", _ACTIONS) +def test_passthrough_action_prices_the_trace_into_the_spend_row( + rig: Rig, monkeypatch: pytest.MonkeyPatch, action: str +) -> None: + key: Final = rig.key() + runtime: Final = rig.runtime(monkeypatch, key) + messages: Final = [{"role": "user", "content": [{"text": "hello"}]}] + invoke_body: Final = json.dumps( + { + "anthropic_version": "bedrock-2023-05-31", + "max_tokens": 16, + "messages": [{"role": "user", "content": "hello"}], + } + ) + if action == "converse": + getattr(runtime, "converse")(modelId=rig.converse_model, messages=messages) + elif action == "converse-stream": + list(getattr(runtime, "converse_stream")(modelId=rig.converse_model, messages=messages)["stream"]) + elif action == "invoke": + getattr(runtime, "invoke_model")(modelId=rig.converse_model, body=invoke_body)["body"].read() + else: + list( + getattr(runtime, "invoke_model_with_response_stream")(modelId=rig.converse_model, body=invoke_body)["body"] + ) + _assert_billed_as_guardrail_cost(_spend_row(rig.proxy, key)) + + +def test_disabled_trace_bills_only_the_tokens(rig: Rig) -> None: + key: Final = rig.key() + response: Final = rig.proxy.request("POST", "/v1/chat/completions", _chat_body(rig.untraced_model, False), key=key) + assert response.is_success, response.text[:400] + assert "trace" not in response.json() + assert float(response.headers["x-litellm-response-cost"]) == pytest.approx(_llm_cost()) + row: Final = _spend_row(rig.proxy, key) + assert row.spend == pytest.approx(_llm_cost()) + assert row.guardrail_information == () + + +def _messages_body(model: str, stream: bool) -> dict[str, JsonValue]: + return { + "model": model, + "messages": [{"role": "user", "content": f"hello from the messages api, stream={stream}"}], + "max_tokens": 16, + "stream": stream, + } + + +def test_messages_non_streaming_response_applies_the_guardrail_and_prices_its_trace(rig: Rig) -> None: + key: Final = rig.key() + response: Final = rig.proxy.request("POST", "/v1/messages", _messages_body(rig.invoke_model, False), key=key) + assert response.is_success, response.text[:400] + assert "amazon-bedrock-trace" in response.json() + _assert_billed_as_guardrail_cost(_spend_row(rig.proxy, key)) + + +def test_messages_streamed_response_prices_the_trace_of_the_message_stop_event(rig: Rig) -> None: + key: Final = rig.key() + with rig.proxy.client.stream( + "POST", + "/v1/messages", + json=_messages_body(rig.invoke_model, True), + headers={"Authorization": f"Bearer {key}"}, + timeout=case_timeout_seconds(), + ) as response: + body: Final = b"".join(response.iter_bytes()) + assert response.is_success and b"message_stop" in body, body[:400] + _assert_billed_as_guardrail_cost(_spend_row(rig.proxy, key)) + + +def test_passthrough_streamed_tool_call_prices_the_trace_of_the_final_event( + rig: Rig, monkeypatch: pytest.MonkeyPatch +) -> None: + key: Final = rig.key() + runtime: Final = rig.runtime(monkeypatch, key) + tool_config: Final = { + "tools": [{"toolSpec": {"name": "lookup", "inputSchema": {"json": {"type": "object", "properties": {}}}}}] + } + events: Final = list( + getattr(runtime, "converse_stream")( + modelId=rig.converse_model, + messages=[{"role": "user", "content": [{"text": "hello"}]}], + toolConfig=tool_config, + )["stream"] + ) + assert any("contentBlockStart" in event for event in events) + _assert_billed_as_guardrail_cost(_spend_row(rig.proxy, key)) diff --git a/tests/integration/providers/test_decisions_wire.py b/tests/integration/providers/test_decisions_wire.py index ea29914ba65..89ca674ef31 100644 --- a/tests/integration/providers/test_decisions_wire.py +++ b/tests/integration/providers/test_decisions_wire.py @@ -660,3 +660,22 @@ def test_a_deployment_whose_provider_has_no_decisions_support_is_refused_naming_ for provider in _PROVIDERS: assert provider.name in response.text, response.text assert _upstream_calls(gateway, handle) == [] + + +def test_typesafe_gateway_preserves_missing_usage(gateway: Gateway) -> None: + with gateway.scenario() as scenario: + body = {"model": "jev-1.13.0", "answers": {"exp": {"type": "noul", "noul": 0.8}}} + handle = _register(scenario, body) + model = _deployment(scenario, handle, _PROVIDERS[1]) + response = gateway.request( + "POST", + "/v1/systemone", + { + "model": model, + "state": {"finding": "x"}, + "questions": {"exp": {"type": "noul", "instructions": "Is it exploitable?"}}, + }, + ) + assert response.status_code == 200, response.text + assert response.json()["usage"] is None + assert response.json()["answers"] == body["answers"] diff --git a/tests/integration/routing/test_complexity_router_codex_compaction.py b/tests/integration/routing/test_complexity_router_codex_compaction.py new file mode 100644 index 00000000000..2f436901cd0 --- /dev/null +++ b/tests/integration/routing/test_complexity_router_codex_compaction.py @@ -0,0 +1,109 @@ +import json +import uuid +from collections.abc import Callable +from pathlib import Path +from typing import Final + +import yaml +from integration._support.client import Gateway +from integration._support.process import owned_proxy +from integration._support.wire import Reply, Request, wire_server + +_ASK: Final = {"role": "user", "content": "Design a Byzantine fault tolerant consensus protocol and prove it safe"} +_COMPACTION_PROMPT: Final = {"role": "user", "content": "Hello! Summarize the conversation so far."} + + +def _completion(content: str) -> Reply: + return Reply( + body=json.dumps( + { + "id": "chatcmpl-" + uuid.uuid4().hex[:8], + "object": "chat.completion", + "created": 1700000000, + "model": "gpt-4o-mini", + "choices": [ + {"index": 0, "message": {"role": "assistant", "content": content}, "finish_reason": "stop"} + ], + "usage": {"prompt_tokens": 9, "completion_tokens": 3, "total_tokens": 12}, + } + ).encode() + ) + + +def _answering(content: str) -> Callable[[Request], Reply]: + def respond(request: Request) -> Reply: + if request.method == "GET": + return Reply(body=json.dumps({"object": "list", "data": []}).encode()) + return _completion(content) + + return respond + + +def _classifier(request: Request) -> Reply: + if request.method == "GET": + return Reply(body=json.dumps({"object": "list", "data": []}).encode()) + body: Final = request.body.decode() + tier: Final = "SIMPLE" if "Summarize" in body else "REASONING" + return _completion(json.dumps({"tier": tier})) + + +def test_codex_compaction_request_stays_on_the_held_user_turn_model(gateway: Gateway, tmp_path: Path) -> None: + with ( + wire_server(_classifier) as judge, + wire_server(_answering("simple answer")) as simple, + wire_server(_answering("reasoning answer")) as reasoning, + ): + router: Final = "router-" + uuid.uuid4().hex[:8] + config: Final = yaml.safe_load(Path("tests/integration/proxy_config.yaml").read_text()) + config["model_list"] = [ + { + "model_name": name, + "litellm_params": {"model": "openai/gpt-4o-mini", "api_base": url, "api_key": "synthetic"}, + } + for name, url in (("judge", judge.url), ("simple", simple.url), ("reasoning", reasoning.url)) + ] + [ + { + "model_name": router, + "litellm_params": { + "model": "auto_router/complexity_router", + "complexity_router_config": { + "classifier_type": "llm", + "classifier_llm_config": {"model": "judge", "timeout_ms": 20000}, + "classification_mode": "user_turn", + "tiers": { + "SIMPLE": "simple", + "MEDIUM": "simple", + "COMPLEX": "reasoning", + "REASONING": "reasoning", + }, + }, + }, + } + ] + path: Final = tmp_path / "complexity_router.yaml" + path.write_text(yaml.safe_dump(config)) + session: Final = uuid.uuid4().hex + + def codex_headers(request_kind: str) -> dict[str, str]: + return { + "User-Agent": "codex-tui/0.164.0", + "session_id": session, + "x-codex-turn-metadata": json.dumps({"session_id": session, "request_kind": request_kind}), + } + + with owned_proxy(gateway, tmp_path, {}, config=path) as candidate: + ask: Final = candidate.request( + "POST", "/v1/chat/completions", {"model": router, "messages": [_ASK]}, headers=codex_headers("turn") + ) + assert ask.status_code == 200, ask.text + assert ask.json()["choices"][0]["message"]["content"] == "reasoning answer", ask.text + compaction: Final = candidate.request( + "POST", + "/v1/chat/completions", + {"model": router, "messages": [_ASK, {"role": "assistant", "content": "done"}, _COMPACTION_PROMPT]}, + headers=codex_headers("compaction"), + ) + assert compaction.status_code == 200, compaction.text + assert compaction.json()["choices"][0]["message"]["content"] == "reasoning answer", compaction.text + assert len([call for call in judge.drain() if call.method == "POST"]) == 1 + assert [call for call in simple.drain() if call.method == "POST"] == [] diff --git a/tests/integration/routing/test_team_wildcard_precedence.py b/tests/integration/routing/test_team_wildcard_precedence.py new file mode 100644 index 00000000000..38fda682129 --- /dev/null +++ b/tests/integration/routing/test_team_wildcard_precedence.py @@ -0,0 +1,61 @@ +"""A team's own wildcard deployment serves that team's keys even when a proxy-wide wildcard of the +same pattern exists, and the proxy-wide one serves every other key (#48490).""" + +import uuid +from typing import Final + +import pytest +from integration._support.client import Gateway, Scenario + +pytestmark: Final = pytest.mark.timeout(120) + + +def _wildcard(scenario: Scenario, pattern: str, *, team_id: str | None) -> str: + identity: Final = f"wildcard-{uuid.uuid4().hex}" + scenario.gateway.post( + "/model/new", + { + "model_name": pattern, + "litellm_params": { + "model": "openai/*", + "api_key": f"provider-key-{identity}", + "api_base": f"{scenario.gateway.upstream_url}/v1", + }, + "model_info": {"id": identity, **({"team_id": team_id} if team_id is not None else {})}, + }, + ) + scenario.cleanups.callback(scenario.delete_model, identity) + return identity + + +def _served_by(gateway: Gateway, key: str, model: str) -> str: + response: Final = gateway.request( + "POST", + "/v1/chat/completions", + {"model": model, "messages": [{"role": "user", "content": "wildcard precedence control"}]}, + key=key, + ) + assert response.status_code == 200, response.text + return response.headers["x-litellm-model-id"] + + +def test_a_teams_wildcard_serves_its_keys_before_a_proxy_wide_wildcard_of_the_same_pattern(gateway: Gateway) -> None: + with gateway.scenario() as scenario: + byok_team: Final = scenario.team(models=[]) + other_team: Final = scenario.team(models=[]) + pattern: Final = f"byok-{uuid.uuid4().hex}/*" + team_wildcard: Final = _wildcard(scenario, pattern, team_id=byok_team) + shared_wildcard: Final = _wildcard(scenario, pattern, team_id=None) + model: Final = pattern.replace("*", "gpt-4o-mini") + + served: Final = { + "byok team key": _served_by(gateway, scenario.key(team_id=byok_team), model), + "other team key": _served_by(gateway, scenario.key(team_id=other_team), model), + "key without a team": _served_by(gateway, scenario.key(), model), + } + + assert served == { + "byok team key": team_wildcard, + "other team key": shared_wildcard, + "key without a team": shared_wildcard, + } diff --git a/tests/integration/sdk/test_aiohttp_session_rebuild_wire.py b/tests/integration/sdk/test_aiohttp_session_rebuild_wire.py index 1ec1f486bed..f1a18ba389a 100644 --- a/tests/integration/sdk/test_aiohttp_session_rebuild_wire.py +++ b/tests/integration/sdk/test_aiohttp_session_rebuild_wire.py @@ -11,11 +11,30 @@ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer from typing import Final import pytest -from pydantic import JsonValue, TypeAdapter +from pydantic import BaseModel, ConfigDict, JsonValue, TypeAdapter CONFIGURED_KEEPALIVE_SECONDS: Final = 1 IDLE_SECONDS: Final = 2 +EVICTED_CLIENTS: Final = 30 RESPONSES: Final = TypeAdapter(list[dict[str, JsonValue]]) +CHAT_COMPLETION: Final = { + "id": "chatcmpl-scripted", + "object": "chat.completion", + "created": 1700000000, + "model": "gpt-5.4-nano", + "choices": [{"index": 0, "message": {"role": "assistant", "content": "hi"}, "finish_reason": "stop"}], + "usage": {"prompt_tokens": 1, "completion_tokens": 1, "total_tokens": 2}, +} + + +class EvictionReport(BaseModel): + model_config = ConfigDict(frozen=True) + + cache_size: int + cached_clients: int + established_connections: int + unclosed_messages: tuple[str, ...] + REBUILT_SESSION_EXCHANGE: Final = textwrap.dedent( """ @@ -38,6 +57,47 @@ REBUILT_SESSION_EXCHANGE: Final = textwrap.dedent( ) +EVICTED_CLIENTS_EXCHANGE: Final = textwrap.dedent( + """ + import asyncio, gc, json, sys + import psutil + import litellm + from litellm.llms.custom_httpx.aiohttp_transport import LiteLLMAiohttpTransport + + unclosed = [] + + def established(port: int) -> int: + connections = psutil.Process().net_connections("tcp") + return sum(1 for c in connections if c.status == "ESTABLISHED" and c.raddr and c.raddr.port == port) + + async def one_call(base_url: str, index: int) -> None: + await litellm.acompletion( + model="openai/gpt-5.4-nano", + api_key=f"sk-distinct-{index}", + api_base=base_url, + messages=[{"role": "user", "content": "hi"}], + ) + + async def main(base_url: str, port: int, evicted: int) -> None: + asyncio.get_running_loop().set_exception_handler(lambda loop, ctx: unclosed.append(ctx["message"])) + cache = litellm.in_memory_llm_clients_cache + for index in range(cache.max_size_in_memory + evicted): + await one_call(base_url, index) + gc.collect() + await asyncio.gather(*LiteLLMAiohttpTransport._background_close_tasks) + await asyncio.sleep(0) + print(json.dumps({ + "cache_size": cache.max_size_in_memory, + "cached_clients": len(cache.cache_dict), + "established_connections": established(port), + "unclosed_messages": unclosed, + })) + + asyncio.run(main(sys.argv[1], int(sys.argv[2]), int(sys.argv[3]))) + """ +) + + class _ConnectionCountingPeer(ThreadingHTTPServer): daemon_threads = True @@ -62,7 +122,8 @@ class _ConnectionHandler(BaseHTTPRequestHandler): def do_POST(self) -> None: self.rfile.read(int(self.headers["Content-Length"])) - body: Final = json.dumps({"connection": self.connection_number}).encode() + payload: Final = CHAT_COMPLETION if self.path.endswith("/chat/completions") else {"connection": self.connection_number} + body: Final = json.dumps(payload).encode() self.send_response(200) self.send_header("Content-Type", "application/json") self.send_header("Content-Length", str(len(body))) @@ -107,3 +168,24 @@ def test_rebuilt_shared_session_drops_idle_connection_after_configured_keepalive ) -> None: observed: Final = _rebuilt_session_exchange(connection_counting_peer) assert observed == [{"connection": 1}, {"connection": 2}], observed + + +def _evicted_clients_exchange(base_url: str) -> EvictionReport: + completed: Final = subprocess.run( + [sys.executable, "-P", "-c", EVICTED_CLIENTS_EXCHANGE, base_url, base_url.rsplit(":", 1)[1], str(EVICTED_CLIENTS)], + capture_output=True, + text=True, + timeout=300, + check=False, + ) + assert completed.returncode == 0, completed.stderr + return EvictionReport.model_validate_json(completed.stdout) + + +def test_sdk_clients_evicted_from_a_full_client_cache_leave_no_open_session_or_connection( + connection_counting_peer: str, +) -> None: + report: Final = _evicted_clients_exchange(connection_counting_peer) + assert report.cached_clients == report.cache_size, report + assert report.unclosed_messages == (), report + assert report.established_connections <= report.cache_size, report diff --git a/tests/integration/sdk/test_dual_cache_redis.py b/tests/integration/sdk/test_dual_cache_redis.py index ddd01480d36..3527dbf91ee 100644 --- a/tests/integration/sdk/test_dual_cache_redis.py +++ b/tests/integration/sdk/test_dual_cache_redis.py @@ -6,6 +6,7 @@ from unittest.mock import patch import pytest +from litellm.caching.affinity_cache import claim_affinity_pin from litellm.caching.dual_cache import DualCache from litellm.caching.in_memory_cache import InMemoryCache from litellm.caching.redis_cache import RedisCache @@ -92,3 +93,66 @@ async def test_sync_and_async_batch_reads_share_one_redis_without_sync_reads_goi assert in_loop_results == [[expected[key]] for key in in_loop_keys] assert await dual_cache.async_batch_get_cache(keys=[survivor_key]) == [expected[survivor_key]] + + +@pytest.mark.asyncio +async def test_concurrent_session_repin_claims_keep_the_shared_winner_after_recovery() -> None: + redis: Final = _redis_cache() + workers: Final = (DualCache(redis_cache=redis), DualCache(redis_cache=redis)) + key: Final = f"session-repin-{uuid.uuid4().hex}" + choices: Final = ({"model_id": "replacement"}, {"model_id": "other"}) + try: + await redis.async_set_cache(key, {"model_id": "original"}, ttl=60) + for worker in workers: + worker.in_memory_cache.set_cache(key, {"model_id": "original"}, ttl=60) + winners: Final = await asyncio.gather( + *( + claim_affinity_pin(worker, key, choice, 60, eligible_values=choices, preserve_legacy_model_ids=True) + for worker, choice in zip(workers, choices, strict=True) + ) + ) + assert winners[0] == winners[1] and winners[0] in choices + late_original: Final = await claim_affinity_pin( + workers[0], + key, + {"model_id": "original"}, + 60, + eligible_values=({"model_id": "original"}, *choices), + preserve_legacy_model_ids=True, + ) + assert late_original == winners[0] + assert await redis.async_get_cache(key) == winners[0] + finally: + await redis.async_delete_cache(key) + + +@pytest.mark.asyncio +@pytest.mark.parametrize("stored", ["original", '"original"', '{"model_id":"original"}']) +async def test_session_repin_lua_preserves_healthy_legacy_pins_and_replaces_unavailable_ones(stored: str) -> None: + redis: Final = _redis_cache() + cache: Final = DualCache(redis_cache=redis) + key: Final = f"session-repin-legacy-{uuid.uuid4().hex}" + replacement: Final = {"model_id": "replacement"} + try: + redis.redis_client.set(redis.check_and_fix_namespace(key), stored, ex=60) + preserved: Final = await claim_affinity_pin( + cache, + key, + replacement, + 60, + eligible_values=({"model_id": "original"}, replacement), + preserve_legacy_model_ids=True, + ) + assert preserved in ("original", {"model_id": "original"}) + moved: Final = await claim_affinity_pin( + cache, + key, + replacement, + 60, + eligible_values=(replacement,), + preserve_legacy_model_ids=True, + ) + assert moved == replacement + assert await redis.async_get_cache(key) == replacement + finally: + await redis.async_delete_cache(key) diff --git a/tests/integration/sdk/test_langfuse_otel_trace_fields_sdk.py b/tests/integration/sdk/test_langfuse_otel_trace_fields_sdk.py new file mode 100644 index 00000000000..33846960ab2 --- /dev/null +++ b/tests/integration/sdk/test_langfuse_otel_trace_fields_sdk.py @@ -0,0 +1,362 @@ +import json +import os +import subprocess +import sys +import threading +import uuid +from collections.abc import Iterator, Mapping +from dataclasses import dataclass +from typing import Final + +import pytest +from integration._support.client import eventually +from integration._support.wire import Reply, Request, wire_server +from opentelemetry.proto.collector.trace.v1.trace_service_pb2 import ExportTraceServiceRequest +from opentelemetry.proto.trace.v1.trace_pb2 import Span + +CALLS: Final = { + "sync": "completion", + "sync_stream": "completion", + "async": "acompletion", + "async_stream": "acompletion", +} +SDK_CALLS: Final = """ +import asyncio +import sys + +import litellm + +litellm.callbacks = ["langfuse_otel"] +api_base, marker = sys.argv[1], sys.argv[2] + + +def request(call): + return { + "model": "openai/gpt-4o-mini", + "api_base": api_base, + "api_key": "synthetic-provider-key", + "messages": [{"role": "user", "content": f"{marker}-{call}"}], + "stream": call.endswith("_stream"), + } + + +async def async_calls(): + await litellm.acompletion(**request("async")) + async for _ in await litellm.acompletion(**request("async_stream")): + pass + + +litellm.completion(**request("sync")) +for _ in litellm.completion(**request("sync_stream")): + pass +asyncio.run(async_calls()) +print("calls done", flush=True) +sys.stdin.read() +""" + + +APP_TRACE_CALLS: Final = """ +import asyncio +import json +import sys +import threading +import time + +import litellm +from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter +from opentelemetry.sdk.trace import TracerProvider +from opentelemetry.sdk.trace.export import SimpleSpanProcessor + +litellm.callbacks = ["langfuse_otel"] +api_base, marker, sink, writes_onto_app_span = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4] == "1" +app = TracerProvider() +app.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint=sink + "/api/public/otel/v1/traces"))) +tracer = app.get_tracer("checkout-app") + + +def request(call, **extra): + return { + "model": "openai/gpt-4o-mini", + "api_base": api_base, + "api_key": "synthetic-provider-key", + "messages": [{"role": "user", "content": f"{marker}-{call}"}], + **extra, + } + + +def name_trace(root, call): + root.set_attribute("app.call", f"{marker}-{call}") + root.set_attribute("langfuse.trace.name", f"checkout-{marker}-{call}") + root.set_attribute("langfuse.trace.input", json.dumps({"cart": f"{marker}-{call}"})) + + +def close_trace(root, call): + root.set_attribute("langfuse.trace.output", json.dumps({"order": f"{marker}-{call}"})) + root.end() + + +def litellm_wrote_onto(root): + return not writes_onto_app_span or "langfuse.observation.type" in root.attributes + + +def ambient_sync(): + with tracer.start_as_current_span("checkout", end_on_exit=False) as root: + name_trace(root, "ambient_sync") + litellm.completion(**request("ambient_sync")) + deadline = time.monotonic() + 30 + while not litellm_wrote_onto(root) and time.monotonic() < deadline: + threading.Event().wait(0.05) + close_trace(root, "ambient_sync") + + +async def ambient_async(): + with tracer.start_as_current_span("checkout", end_on_exit=False) as root: + name_trace(root, "ambient_async") + await litellm.acompletion(**request("ambient_async")) + deadline = time.monotonic() + 30 + while not litellm_wrote_onto(root) and time.monotonic() < deadline: + await asyncio.sleep(0.05) + close_trace(root, "ambient_async") + + +def caller_span_sync(): + root = tracer.start_span("checkout") + name_trace(root, "caller_span_sync") + litellm.completion(**request("caller_span_sync", metadata={"litellm_parent_otel_span": root})) + close_trace(root, "caller_span_sync") + + +async def caller_span_async(): + root = tracer.start_span("checkout") + name_trace(root, "caller_span_async") + await litellm.acompletion(**request("caller_span_async", metadata={"litellm_parent_otel_span": root})) + close_trace(root, "caller_span_async") + + +async def async_calls(): + await ambient_async() + await caller_span_async() + + +ambient_sync() +caller_span_sync() +asyncio.run(async_calls()) +print("calls done", flush=True) +sys.stdin.read() +""" +APP_CALLS: Final = ("ambient_sync", "ambient_async", "caller_span_sync", "caller_span_async") + + +def _exported_spans(body: bytes) -> Iterator[Span]: + for resource in ExportTraceServiceRequest.FromString(body).resource_spans: + for scope in resource.scope_spans: + yield from scope.spans + + +def _attributes(span: Span) -> Mapping[str, str]: + return {pair.key: pair.value.string_value for pair in span.attributes} + + +@dataclass(frozen=True, slots=True) +class TraceSpan: + trace_id: str + parent_span_id: str + attributes: Mapping[str, str] + + +class TraceSink: + def __init__(self) -> None: + self.lock: Final = threading.Lock() + self.spans: Final[list[TraceSpan]] = [] # mutable-ok: spans accumulate as both exporters deliver + + def respond(self, request: Request) -> Reply: + if not request.target.endswith("/v1/traces"): + return Reply(body=b"") + spans: Final = tuple( + TraceSpan(span.trace_id.hex(), span.parent_span_id.hex(), _attributes(span)) + for span in _exported_spans(request.body) + ) + with self.lock: + self.spans.extend(spans) + return Reply(body=b"") + + def traces(self, marker: str, calls: tuple[str, ...]) -> Mapping[str, tuple[TraceSpan, ...]]: + with self.lock: + snapshot: Final = tuple(self.spans) + roots: Final = { + call: next( + ( + span + for span in snapshot + if not span.parent_span_id and span.attributes.get("app.call") == f"{marker}-{call}" + ), + None, + ) + for call in calls + } + return { + call: tuple(span for span in snapshot if span.trace_id == root.trace_id) + for call, root in roots.items() + if root is not None + } + + +def _trace_values(spans: tuple[TraceSpan, ...], keys: tuple[str, ...]) -> Iterator[tuple[str, str]]: + for span in spans: + yield from ((key, span.attributes[key]) for key in keys if key in span.attributes) + + +def _logged(spans: tuple[TraceSpan, ...]) -> bool: + return any(span.attributes.get("langfuse.observation.type") == "generation" for span in spans) + + +def _chat_reply(request: Request) -> Reply: + body: Final = json.loads(request.body) + content: Final = body["messages"][0]["content"] + if body.get("stream"): + delta: Final = {"id": content, "object": "chat.completion.chunk", "created": 1, "model": "gpt-4o-mini"} + return Reply( + content_type="text/event-stream", + chunks=( + f"data: {json.dumps({**delta, 'choices': [{'index': 0, 'delta': {'role': 'assistant', 'content': 'ok'}}]})}\n\n".encode(), + f"data: {json.dumps({**delta, 'choices': [{'index': 0, 'delta': {}, 'finish_reason': 'stop'}]})}\n\n".encode(), + b"data: [DONE]\n\n", + ), + ) + return Reply( + body=json.dumps( + { + "id": content, + "object": "chat.completion", + "created": 1, + "model": "gpt-4o-mini", + "choices": [{"index": 0, "message": {"role": "assistant", "content": "ok"}, "finish_reason": "stop"}], + "usage": {"prompt_tokens": 5, "completion_tokens": 1, "total_tokens": 6}, + } + ).encode() + ) + + +class GenerationSink: + def __init__(self) -> None: + self.lock: Final = threading.Lock() + self.generations: Final[list[Mapping[str, str]]] = [] # mutable-ok: spans accumulate as the exporter delivers + + def respond(self, request: Request) -> Reply: + if not request.target.endswith("/v1/traces"): + return Reply(body=b"") + spans: Final = tuple(_attributes(span) for span in _exported_spans(request.body)) + with self.lock: + self.generations.extend(span for span in spans if span.get("langfuse.observation.type") == "generation") + return Reply(body=b"") + + def by_call(self, marker: str) -> Mapping[str, tuple[Mapping[str, str], ...]]: + with self.lock: + snapshot: Final = tuple(self.generations) + return { + call: tuple(span for span in snapshot if f'"{marker}-{call}"' in span.get("langfuse.observation.input", "")) + for call in CALLS + } + + +def test_sdk_sync_and_async_calls_derive_trace_name_and_io_from_their_call_type() -> None: + marker: Final = "lit8281-sdk-" + uuid.uuid4().hex + sink: Final = GenerationSink() + with wire_server(sink.respond) as destination, wire_server(_chat_reply) as provider: + child: Final = subprocess.Popen( + [sys.executable, "-P", "-c", SDK_CALLS, provider.url + "/v1", marker], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + env={ + **os.environ, + "LANGFUSE_PUBLIC_KEY": "pk-lf-sdk", + "LANGFUSE_SECRET_KEY": "sk-lf-sdk", + "LANGFUSE_HOST": destination.url, + "OTEL_BSP_SCHEDULE_DELAY": "200", + }, + ) + try: + spans: Final = eventually( + lambda: sink.by_call(marker), + lambda found: all(len(records) == 1 for records in found.values()) or child.poll() is not None, + seconds=70, + ) + finally: + output: Final = child.communicate(input=b"", timeout=60)[0].decode() + assert {call: len(records) for call, records in spans.items()} == dict.fromkeys(CALLS, 1), output + for call, call_type in CALLS.items(): + attributes = spans[call][0] + assert attributes["langfuse.trace.name"] == f"litellm-{call_type}", (call, attributes) + assert attributes["langfuse.trace.input"] == attributes["langfuse.observation.input"], (call, attributes) + assert attributes["langfuse.trace.output"] == attributes["langfuse.observation.output"], (call, attributes) + assert json.loads(attributes["langfuse.trace.output"]) == {"role": "assistant", "content": "ok"}, call + + +@pytest.mark.parametrize( + ("environment", "writes_onto_app_span", "calls"), + [ + pytest.param({}, True, APP_CALLS, id="litellm_writes_onto_the_app_span"), + pytest.param({"USE_OTEL_LITELLM_REQUEST_SPAN": "true"}, False, APP_CALLS, id="litellm_request_child_span"), + pytest.param( + {"LITELLM_OTEL_V2": "1", "OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT": "span_only"}, + False, + ("ambient_async",), + id="otel_v2_llm_call_child_span", + ), + ], +) +def test_sdk_call_inside_an_app_trace_leaves_the_app_trace_name_and_io_alone( + environment: Mapping[str, str], writes_onto_app_span: bool, calls: tuple[str, ...] +) -> None: + marker: Final = "lit8281-app-" + uuid.uuid4().hex + sink: Final = TraceSink() + with wire_server(sink.respond) as destination, wire_server(_chat_reply) as provider: + child: Final = subprocess.Popen( + [ + sys.executable, + "-P", + "-c", + APP_TRACE_CALLS, + provider.url + "/v1", + marker, + destination.url, + "1" if writes_onto_app_span else "0", + ], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + env={ + **os.environ, + "LANGFUSE_PUBLIC_KEY": "pk-lf-sdk", + "LANGFUSE_SECRET_KEY": "sk-lf-sdk", + "LANGFUSE_HOST": destination.url, + "OTEL_BSP_SCHEDULE_DELAY": "200", + **environment, + }, + ) + try: + traces: Final = eventually( + lambda: sink.traces(marker, calls), + lambda found: ( + (len(found) == len(calls) and all(map(_logged, found.values()))) or child.poll() is not None + ), + seconds=70, + ) + finally: + output: Final = child.communicate(input=b"", timeout=60)[0].decode() + assert sorted(call for call, spans in traces.items() if _logged(spans)) == sorted(calls), output + for call, spans in traces.items(): + _assert_the_app_trace_fields_stand(marker, call, spans) + + +def _assert_the_app_trace_fields_stand(marker: str, call: str, spans: tuple[TraceSpan, ...]) -> None: + app: Final = { + "langfuse.trace.name": f"checkout-{marker}-{call}", + "langfuse.trace.input": json.dumps({"cart": f"{marker}-{call}"}), + "langfuse.trace.output": json.dumps({"order": f"{marker}-{call}"}), + } + root: Final = next(span for span in spans if not span.parent_span_id) + assert {key: root.attributes.get(key) for key in app} == app, (call, root.attributes) + written: Final = set(_trace_values(spans, (*app, "langfuse.trace.tags"))) + assert written == set(app.items()), (call, written) diff --git a/tests/integration/sdk/test_prometheus_copilot_session_auth_failure_sdk.py b/tests/integration/sdk/test_prometheus_copilot_session_auth_failure_sdk.py new file mode 100644 index 00000000000..1b5e990fe41 --- /dev/null +++ b/tests/integration/sdk/test_prometheus_copilot_session_auth_failure_sdk.py @@ -0,0 +1,99 @@ +"""A provider 401 on a caller's own per-user GitHub Copilot session is the caller's credential failing, so the +shared Copilot deployment keeps no failure, request or outage series for it, while a provider 401 on the router +deployment's own key, on a key a router caller passes or on the key a direct SDK call brings is counted as a failed +request, the router caller's key against its own one-off deployment.""" + +from __future__ import annotations + +import json +from collections.abc import Iterator +from typing import Final + +import pytest +from integration._support.copilot_session_prometheus_worker import ( + CALLER_SESSION_TOKEN, + COPILOT_DEPLOYMENT, + DEPLOYMENT_SERIES, + DIRECT_CALL, + DIRECT_KEY, + FAILURES, + LLM_FAILED, + OPERATOR_DEPLOYMENT, + OPERATOR_KEY, + ROUTER_CALLER_KEY, + STATE, + TOTALS, + Outcome, + WorkerReport, + run_copilot_session_worker, +) +from integration._support.wire import Reply, Request, wire_server + + +@pytest.fixture(scope="module") +def ran() -> Iterator[tuple[WorkerReport, tuple[Request, ...]]]: + def reject(request: Request) -> Reply: + assert request.method == "POST", request.method + return Reply( + status=401, + body=json.dumps({"error": {"message": "bad credentials", "type": "authentication_error"}}).encode(), + ) + + with wire_server(reject) as upstream: + report: Final = run_copilot_session_worker(upstream.url) + yield report, upstream.drain() + + +def test_every_call_reaches_the_provider_with_its_own_credential_and_fails_with_its_401( + ran: tuple[WorkerReport, tuple[Request, ...]], +) -> None: + report, received = ran + assert report.outcomes == ( + Outcome(deployment=COPILOT_DEPLOYMENT, status=401), + Outcome(deployment=OPERATOR_DEPLOYMENT, status=401), + Outcome(deployment=OPERATOR_DEPLOYMENT, status=401), + Outcome(deployment=DIRECT_CALL, status=401), + ) + assert [r.headers.get("authorization") for r in received] == [ + f"Bearer {CALLER_SESSION_TOKEN}", + f"Bearer {OPERATOR_KEY}", + f"Bearer {ROUTER_CALLER_KEY}", + f"Bearer {DIRECT_KEY}", + ] + + +def test_a_provider_401_on_a_callers_copilot_session_stays_out_of_the_shared_deployment_metrics( + ran: tuple[WorkerReport, tuple[Request, ...]], +) -> None: + report, _ = ran + assert {s.metric for s in report.series if s.model_id == COPILOT_DEPLOYMENT} & DEPLOYMENT_SERIES == set() + + +def test_a_provider_401_on_the_deployments_own_key_counts_as_a_deployment_failure( + ran: tuple[WorkerReport, tuple[Request, ...]], +) -> None: + report, _ = ran + assert report.values(FAILURES, OPERATOR_DEPLOYMENT) == (1.0,) + assert report.values(TOTALS, OPERATOR_DEPLOYMENT) == (1.0,) + assert report.values(LLM_FAILED, OPERATOR_DEPLOYMENT) == (1.0,) + assert report.on_the_endpoint(STATE, OPERATOR_DEPLOYMENT) == (1.0,) + + +def test_a_provider_401_on_the_key_a_direct_sdk_call_brings_is_counted_as_a_failed_request( + ran: tuple[WorkerReport, tuple[Request, ...]], +) -> None: + report, _ = ran + assert report.outside_the_router(FAILURES) == (1.0,) + assert report.outside_the_router(TOTALS) == (1.0,) + assert report.outside_the_router(LLM_FAILED) == (1.0,) + + +def test_a_provider_401_on_a_key_a_router_caller_passes_counts_against_its_own_one_off_deployment( + ran: tuple[WorkerReport, tuple[Request, ...]], +) -> None: + report, _ = ran + assert report.on_a_one_off_deployment(FAILURES) == (1.0,) + assert report.on_a_one_off_deployment(TOTALS) == (1.0,) + assert report.on_a_one_off_deployment(LLM_FAILED) == (1.0,) + assert report.values(FAILURES, OPERATOR_DEPLOYMENT) == (1.0,) + assert report.values(TOTALS, OPERATOR_DEPLOYMENT) == (1.0,) diff --git a/tests/integration/sdk/test_router_concurrent_deployment_delete_sdk.py b/tests/integration/sdk/test_router_concurrent_deployment_delete_sdk.py new file mode 100644 index 00000000000..dc94c96da05 --- /dev/null +++ b/tests/integration/sdk/test_router_concurrent_deployment_delete_sdk.py @@ -0,0 +1,474 @@ +from __future__ import annotations + +import asyncio +import json +import linecache +import sys +import threading +import uuid +from collections.abc import AsyncIterable, Awaitable, Callable, Iterable +from concurrent.futures import ThreadPoolExecutor +from types import FrameType +from typing import Final, TypeVar + +import pytest +from integration._support.client import object_value +from integration._support.openai_wire import chat_reply, openai_error, responses_reply +from integration._support.wire import Reply, Request, Wire, wire_server +from pydantic import JsonValue + +import litellm +from litellm import Router + +_DEPLOYMENTS: Final = 4 +_TARGET: Final = _DEPLOYMENTS - 1 +_SYNC_SECONDS: Final = 10 +_RATE_LIMITED_KEY: Final = "key-rate-limited" +_BURST_THREADS: Final = 8 +_BURST_CALLS: Final = 24 +_CHURN_UPSERTS: Final = 120 +_UNREPORTED_MODEL_ID: Final = frozenset({"aresponses-stream", "aanthropic-messages"}) +_ROUTER_FILE: Final = Router.__init__.__code__.co_filename +_INDEX_LOCK_LINES: Final = frozenset( + number + for number, line in enumerate(linecache.getlines(_ROUTER_FILE), start=1) + if "with self._deployment_index_lock" in line +) + +T = TypeVar("T") + + +def _peer(request: Request) -> Reply: + if request.headers["authorization"] == f"Bearer {_RATE_LIMITED_KEY}": + return openai_error(429) + body: Final = object_value(json.loads(request.body)) + stream: Final = body.get("stream") is True + if request.target == "/v1/responses": + return responses_reply(f"resp_{uuid.uuid4().hex}", "gpt-4o-mini", "ok", stream=stream) + return chat_reply(f"chatcmpl-{uuid.uuid4().hex}", "gpt-4o-mini", "ok", stream=stream) + + +def _deployment( + index: int, + api_base: str, + team: bool, + *, + model: int | None = None, + public_name: str | None = None, + timeout: float = 10, +) -> dict[str, JsonValue]: + team_info: Final[dict[str, JsonValue]] = ( + {"team_id": "team-1", "team_public_model_name": public_name or f"public-{index}"} if team else {} + ) + return { + "model_name": f"model-{index if model is None else model}", + "litellm_params": { + "model": "openai/gpt-4o-mini", + "api_base": api_base, + "api_key": f"key-{index}", + "timeout": timeout, + }, + "model_info": {"id": f"deployment-{index}", **team_info}, + } + + +def _router(wire: Wire, team: bool = False) -> Router: + return Router(model_list=[_deployment(index, f"{wire.url}/v1", team) for index in range(_DEPLOYMENTS)]) + + +def _read_during_held_write(read: Callable[[], T], write: Callable[[], object]) -> T: + """Run `read` on its own thread while `write` waits where the list has shrunk but the index maps have not caught + up. The write resumes once `read` returns or reaches the router's index lock, so a read that skips the lock meets + the half-updated list and a read that takes the lock waits for the write""" + reindex: Final = Router._update_deployment_indices_after_removal.__code__ + held: Final = threading.Event() + release: Final = threading.Event() + settled: Final = threading.Event() + released_in_time: Final[list[bool]] = [] + outcome: Final[list[T]] = [] + failure: Final[list[BaseException]] = [] + + def hold_at_reindex(frame: FrameType, event: str, _arg: object) -> None: + if event == "call" and frame.f_code is reindex and not held.is_set(): + held.set() + released_in_time.append(release.wait(timeout=_SYNC_SECONDS)) + + def run_write() -> None: + previous: Final = sys.getprofile() + sys.setprofile(hold_at_reindex) + try: + write() + finally: + sys.setprofile(previous) + + def watch_read(frame: FrameType, event: str, _arg: object) -> Callable[..., object] | None: + if frame.f_code.co_filename != _ROUTER_FILE: + return None + if event == "line" and frame.f_lineno in _INDEX_LOCK_LINES: + settled.set() + return watch_read + + def run_read() -> None: + previous: Final = sys.gettrace() + sys.settrace(watch_read) + try: + outcome.append(read()) + except BaseException as error: + failure.append(error) + finally: + sys.settrace(previous) + settled.set() + + writer: Final = threading.Thread(target=run_write) + reader: Final = threading.Thread(target=run_read) + writer.start() + try: + assert held.wait(timeout=_SYNC_SECONDS), "the write never reached re-indexing" + reader.start() + assert settled.wait(timeout=_SYNC_SECONDS), "the read neither returned nor reached the index lock" + finally: + release.set() + if reader.ident is not None: + reader.join() + writer.join() + assert released_in_time == [True], "the write was not held for the whole read" + if failure: + raise failure[0] + return outcome[0] + + +def _read_during_held_delete(router: Router, deployment_id: str, read: Callable[[], T]) -> T: + return _read_during_held_write(read, lambda: router.delete_deployment(deployment_id)) + + +def _keys(wire: Wire) -> tuple[str, ...]: + return tuple(request.headers["authorization"] for request in wire.drain()) + + +def _team_metadata(team: bool) -> dict[str, JsonValue]: + return {"user_api_key_team_id": "team-1"} if team else {} + + +def _completion(router: Router, model: str, team: bool) -> str | None: + response: Final = router.completion( + model=model, messages=[{"role": "user", "content": "hi"}], metadata=_team_metadata(team) + ) + return response._hidden_params["model_id"] + + +def _completion_stream(router: Router, model: str, team: bool) -> str | None: + stream: Final = router.completion( + model=model, messages=[{"role": "user", "content": "hi"}], metadata=_team_metadata(team), stream=True + ) + assert isinstance(stream, Iterable), stream + chunks: Final = list(stream) + assert "".join(chunk.choices[0].delta.content or "" for chunk in chunks) == "ok", chunks + return stream._hidden_params["model_id"] + + +def _acompletion(router: Router, model: str, team: bool) -> str | None: + async def call() -> str | None: + response: Final = await router.acompletion( + model=model, messages=[{"role": "user", "content": "hi"}], metadata=_team_metadata(team) + ) + return response._hidden_params["model_id"] + + return asyncio.run(call()) + + +def _acompletion_stream(router: Router, model: str, team: bool) -> str | None: + async def call() -> str | None: + stream: Final = await router.acompletion( + model=model, messages=[{"role": "user", "content": "hi"}], metadata=_team_metadata(team), stream=True + ) + assert isinstance(stream, AsyncIterable), stream + chunks: Final = [chunk async for chunk in stream] + assert "".join(chunk.choices[0].delta.content or "" for chunk in chunks) == "ok", chunks + return stream._hidden_params["model_id"] + + return asyncio.run(call()) + + +def _responses(router: Router, model: str, team: bool) -> str | None: + response: Final = router.responses(model=model, input="hi", metadata=_team_metadata(team)) + assert response.output_text == "ok", response + return response._hidden_params["model_id"] + + +def _aresponses(router: Router, model: str, team: bool) -> str | None: + async def call() -> str | None: + response: Final = await router.aresponses(model=model, input="hi", metadata=_team_metadata(team)) + assert response.output_text == "ok", response + return response._hidden_params["model_id"] + + return asyncio.run(call()) + + +def _aresponses_stream(router: Router, model: str, team: bool) -> str | None: + async def call() -> None: + stream: Final = await router.aresponses(model=model, input="hi", metadata=_team_metadata(team), stream=True) + assert isinstance(stream, AsyncIterable), stream + events: Final = [event.type async for event in stream] + assert events[-1] == "response.completed", events + + asyncio.run(call()) + return None + + +def _aanthropic_messages(router: Router, model: str, team: bool) -> str | None: + async def call() -> None: + response: Final = await router.aanthropic_messages( + model=model, messages=[{"role": "user", "content": "hi"}], max_tokens=16, metadata=_team_metadata(team) + ) + assert response["content"][0]["text"] == "ok", response + + asyncio.run(call()) + return None + + +_CALLS: Final[dict[str, Callable[[Router, str, bool], str | None]]] = { + "completion": _completion, + "completion-stream": _completion_stream, + "acompletion": _acompletion, + "acompletion-stream": _acompletion_stream, + "responses": _responses, + "aresponses": _aresponses, + "aresponses-stream": _aresponses_stream, + "aanthropic-messages": _aanthropic_messages, +} + + +@pytest.mark.parametrize("call", list(_CALLS)) +@pytest.mark.parametrize("team", [False, True], ids=["model-name", "team-public-name"]) +def test_call_reaches_its_deployment_while_another_thread_deletes_one(call: str, team: bool) -> None: + with wire_server(_peer) as wire: + router: Final = _router(wire, team) + served_by: Final = _read_during_held_delete( + router, + "deployment-0", + lambda: _CALLS[call](router, f"public-{_TARGET}" if team else f"model-{_TARGET}", team), + ) + keys: Final = _keys(wire) + + assert served_by == (None if call in _UNREPORTED_MODEL_ID else f"deployment-{_TARGET}") + assert keys == (f"Bearer key-{_TARGET}",) + assert router.get_model_ids() == [f"deployment-{index}" for index in range(1, _DEPLOYMENTS)] + + +@pytest.mark.parametrize("deleted", [0, _TARGET - 1], ids=["first", "next-to-target"]) +def test_completion_reaches_its_deployment_whichever_earlier_deployment_is_deleted(deleted: int) -> None: + with wire_server(_peer) as wire: + router: Final = _router(wire) + served_by: Final = _read_during_held_delete( + router, f"deployment-{deleted}", lambda: _completion(router, f"model-{_TARGET}", team=False) + ) + keys: Final = _keys(wire) + + assert served_by == f"deployment-{_TARGET}" + assert keys == (f"Bearer key-{_TARGET}",) + + +def test_team_completion_reaches_the_remaining_deployment_of_a_shared_public_name_while_its_sibling_is_deleted() -> ( + None +): + with wire_server(_peer) as wire: + api_base: Final = f"{wire.url}/v1" + router: Final = Router( + model_list=[ + _deployment(0, api_base, team=False), + _deployment(1, api_base, team=False), + _deployment(2, api_base, team=True, public_name="public-shared"), + _deployment(3, api_base, team=True, public_name="public-shared"), + ] + ) + served_by: Final = _read_during_held_delete( + router, "deployment-2", lambda: _completion(router, "public-shared", team=True) + ) + keys: Final = _keys(wire) + + assert served_by == "deployment-3" + assert keys == ("Bearer key-3",) + + +def test_completion_for_the_deployment_being_deleted_fails_cleanly_and_sends_nothing() -> None: + with wire_server(_peer) as wire: + router: Final = _router(wire) + with pytest.raises(litellm.BadRequestError): + _read_during_held_delete( + router, + "deployment-0", + lambda: router.completion(model="model-0", messages=[{"role": "user", "content": "hi"}]), + ) + keys: Final = _keys(wire) + + assert keys == () + assert router.get_model_ids() == [f"deployment-{index}" for index in range(1, _DEPLOYMENTS)] + + +def test_provider_error_during_a_concurrent_delete_comes_from_the_requested_deployment() -> None: + with wire_server(_peer) as wire: + api_base: Final = f"{wire.url}/v1" + rate_limited: Final = _deployment(_TARGET, api_base, team=False) + rate_limited["litellm_params"] = {**object_value(rate_limited["litellm_params"]), "api_key": _RATE_LIMITED_KEY} + router: Final = Router( + model_list=[*(_deployment(index, api_base, team=False) for index in range(_TARGET)), rate_limited], + num_retries=0, + ) + with pytest.raises(litellm.RateLimitError): + _read_during_held_delete( + router, + "deployment-0", + lambda: router.completion(model=f"model-{_TARGET}", messages=[{"role": "user", "content": "hi"}]), + ) + served_by: Final = _completion(router, "model-1", team=False) + keys: Final = _keys(wire) + + assert served_by == "deployment-1" + assert keys == (f"Bearer {_RATE_LIMITED_KEY}", "Bearer key-1") + + +def test_two_threads_deleting_the_same_deployment_remove_it_once() -> None: + with wire_server(_peer) as wire: + router: Final = _router(wire) + second: Final = _read_during_held_delete( + router, "deployment-0", lambda: router.delete_deployment("deployment-0") + ) + served_by: Final = _completion(router, f"model-{_TARGET}", team=False) + keys: Final = _keys(wire) + + assert second is None + assert served_by == f"deployment-{_TARGET}" + assert keys == (f"Bearer key-{_TARGET}",) + assert router.get_model_ids() == [f"deployment-{index}" for index in range(1, _DEPLOYMENTS)] + + +def test_completion_reaches_its_deployment_while_another_thread_upserts_an_earlier_one() -> None: + with wire_server(_peer) as wire: + router: Final = _router(wire) + changed: Final = litellm.Deployment(**_deployment(0, f"{wire.url}/v1", team=False, timeout=11)) + served_by: Final = _read_during_held_write( + lambda: _completion(router, f"model-{_TARGET}", team=False), lambda: router.upsert_deployment(changed) + ) + keys: Final = _keys(wire) + + assert served_by == f"deployment-{_TARGET}" + assert keys == (f"Bearer key-{_TARGET}",) + assert sorted(router.get_model_ids()) == [f"deployment-{index}" for index in range(_DEPLOYMENTS)] + + +def test_deployment_added_during_a_concurrent_delete_serves_its_own_requests() -> None: + with wire_server(_peer) as wire: + router: Final = _router(wire) + added: Final = litellm.Deployment(**_deployment(9, f"{wire.url}/v1", team=False)) + _read_during_held_delete(router, "deployment-0", lambda: router.add_deployment(added)) + served: Final = tuple(_completion(router, f"model-{index}", team=False) for index in (9, _TARGET)) + keys: Final = _keys(wire) + + assert served == ("deployment-9", f"deployment-{_TARGET}") + assert keys == ("Bearer key-9", f"Bearer key-{_TARGET}") + + +def test_model_list_set_during_a_concurrent_delete_serves_its_own_requests() -> None: + with wire_server(_peer) as wire: + router: Final = _router(wire) + replacement: Final = [_deployment(index, f"{wire.url}/v1", team=False) for index in range(10, 14)] + _read_during_held_delete(router, "deployment-0", lambda: router.set_model_list(replacement)) + served: Final = tuple(_completion(router, f"model-{index}", team=False) for index in range(10, 14)) + keys: Final = _keys(wire) + + assert served == tuple(f"deployment-{index}" for index in range(10, 14)) + assert keys == tuple(f"Bearer key-{index}" for index in range(10, 14)) + assert router.get_model_ids() == [f"deployment-{index}" for index in range(10, 14)] + + +def _burst_router(api_base: str) -> Router: + """Two deployments per model name, so an upsert of one leaves its model group served.""" + return Router( + model_list=[ + _deployment(index, api_base, team=False, model=index % _DEPLOYMENTS) for index in range(2 * _DEPLOYMENTS) + ] + ) + + +def _churn(router: Router, api_base: str, stop: threading.Event) -> int: + """Upsert the deployments in turn with a changed timeout; each upsert moves one to the end of the list.""" + upserts = 0 + while upserts < _CHURN_UPSERTS and not stop.is_set(): + index, round_number = upserts % (2 * _DEPLOYMENTS), upserts // (2 * _DEPLOYMENTS) + router.upsert_deployment( + litellm.Deployment( + **_deployment(index, api_base, team=False, model=index % _DEPLOYMENTS, timeout=11 + round_number % 2) + ) + ) + upserts += 1 + return upserts + + +def _served_keys(wire: Wire) -> dict[str, str]: + """Which key reached the upstream for each request marker.""" + return { + object_value(json.loads(request.body))["messages"][0]["content"]: request.headers["authorization"] + for request in wire.drain() + } + + +def _assert_each_request_used_its_models_deployment(served: list[tuple[str, str | None]], keys: dict[str, str]) -> None: + for marker, model_id in served: + model: Final = int(marker.split(":")[0]) + assert model_id in (f"deployment-{model}", f"deployment-{model + _DEPLOYMENTS}"), (marker, model_id) + assert keys[marker] == f"Bearer key-{str(model_id).removeprefix('deployment-')}", (marker, keys[marker]) + assert len(keys) == len(served) + + +def test_thread_burst_during_upsert_churn_sends_every_request_with_its_deployments_key() -> None: + with wire_server(_peer) as wire: + api_base: Final = f"{wire.url}/v1" + router: Final = _burst_router(api_base) + stop: Final = threading.Event() + + def call(number: int) -> tuple[str, str | None]: + marker: Final = f"{number % _DEPLOYMENTS}:{number}" + response: Final = router.completion( + model=f"model-{number % _DEPLOYMENTS}", messages=[{"role": "user", "content": marker}] + ) + return marker, response._hidden_params["model_id"] + + with ThreadPoolExecutor(max_workers=_BURST_THREADS + 1) as pool: + churn: Final = pool.submit(_churn, router, api_base, stop) + served: Final = list(pool.map(call, range(_BURST_THREADS * _BURST_CALLS))) + stop.set() + upserts: Final = churn.result() + keys: Final = _served_keys(wire) + + assert upserts > 0 + _assert_each_request_used_its_models_deployment(served, keys) + assert sorted(router.get_model_ids()) == sorted(f"deployment-{index}" for index in range(2 * _DEPLOYMENTS)) + + +async def _gathered(calls: Iterable[Awaitable[tuple[str, str | None]]]) -> list[tuple[str, str | None]]: + return list(await asyncio.gather(*calls)) + + +def test_async_burst_during_upsert_churn_sends_every_request_with_its_deployments_key() -> None: + with wire_server(_peer) as wire: + api_base: Final = f"{wire.url}/v1" + router: Final = _burst_router(api_base) + stop: Final = threading.Event() + + async def call(number: int) -> tuple[str, str | None]: + marker: Final = f"{number % _DEPLOYMENTS}:{number}" + response: Final = await router.acompletion( + model=f"model-{number % _DEPLOYMENTS}", messages=[{"role": "user", "content": marker}] + ) + return marker, response._hidden_params["model_id"] + + with ThreadPoolExecutor(max_workers=1) as pool: + churn: Final = pool.submit(_churn, router, api_base, stop) + served: Final = asyncio.run(_gathered(call(number) for number in range(_BURST_THREADS * _BURST_CALLS))) + stop.set() + upserts: Final = churn.result() + keys: Final = _served_keys(wire) + + assert upserts > 0 + _assert_each_request_used_its_models_deployment(served, keys) + assert sorted(router.get_model_ids()) == sorted(f"deployment-{index}" for index in range(2 * _DEPLOYMENTS)) diff --git a/tests/integration/sdk/test_sync_stream_connection_release_wire.py b/tests/integration/sdk/test_sync_stream_connection_release_wire.py index a8b49d285c3..21774df66d0 100644 --- a/tests/integration/sdk/test_sync_stream_connection_release_wire.py +++ b/tests/integration/sdk/test_sync_stream_connection_release_wire.py @@ -212,3 +212,36 @@ def test_sync_stream_that_raises_mid_stream_releases_the_connection() -> None: assert _open_sessions_settling_to(wire, at_most=0) == 0, ( "a stream that raised mid-way left its TCP session open" ) + + +_STUCK: Final = _Shape( + "hosted_vllm", + "hosted_vllm/stuck-model", + _OPENAI_OPENING, + (_openai_delta("the model is stuck on this", None),) * (10 * litellm.REPEATED_STREAMING_CHUNK_LIMIT), +) + + +def _still_generating_peer(request: Request) -> Reply: + return Reply(content_type="text/event-stream", chunks=(_STUCK.opening, *_STUCK.closing), pause_between_chunks=0.01) + + +def test_sync_stream_stuck_repeating_one_chunk_releases_the_connection() -> None: + with wire_server(_still_generating_peer, keep_alive=True) as wire: + stuck: Final = litellm.completion(**_request_kwargs(_STUCK, wire)) + with pytest.raises(Exception, match="repeating the same chunk"): + for _ in stuck: + pass + assert _open_sessions_settling_to(wire, at_most=0) == 0, "a stream stuck on one chunk left its TCP session open" + + +@pytest.mark.asyncio +async def test_async_stream_stuck_repeating_one_chunk_releases_the_connection() -> None: + with wire_server(_still_generating_peer, keep_alive=True) as wire: + stuck: Final = await litellm.acompletion(**_request_kwargs(_STUCK, wire)) + with pytest.raises(Exception, match="repeating the same chunk"): + async for _ in stuck: + pass + assert await _open_sessions_settling_to_while_the_loop_runs(wire, at_most=0) == 0, ( + "a stream stuck on one chunk left its TCP session open" + ) diff --git a/tests/integration/spend/test_team_member_spend.py b/tests/integration/spend/test_team_member_spend.py index 306138e2bb1..c11dc9db4bf 100644 --- a/tests/integration/spend/test_team_member_spend.py +++ b/tests/integration/spend/test_team_member_spend.py @@ -1,3 +1,4 @@ +import asyncio import os import uuid from collections.abc import Callable, Iterator @@ -7,10 +8,14 @@ from typing import Final import httpx import pytest from integration._support.client import Gateway, Scenario, eventually, object_value, string_value -from integration._support.database import read_rows +from integration._support.database import read_rows, write_rows from pydantic import BaseModel, JsonValue from redis import Redis +from litellm.proxy.common_utils.reset_budget_job import ResetBudgetJob +from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache +from litellm.proxy.utils import PrismaClient, ProxyLogging + def _python_isoformat(value: datetime) -> str: return value.isoformat() @@ -444,9 +449,7 @@ def test_member_update_temp_budget_increase_readmits_a_blocked_member( ) assert added.status_code == 200, added.text default_budget_id: Final = _team_default_budget_id(team) if budget_source == "team-default" else None - default_budget_before: Final = ( - _budget_record(default_budget_id) if default_budget_id is not None else () - ) + default_budget_before: Final = _budget_record(default_budget_id) if default_budget_id is not None else () if default_budget_id is not None: assert len(default_budget_before) == 1, repr(default_budget_before) assert default_budget_before[0].max_budget == 0.05, default_budget_before @@ -503,7 +506,7 @@ def test_member_update_temp_budget_increase_readmits_a_blocked_member( else: assert default_budget_id is not None assert state[0].budget_id != default_budget_id, state - assert state[0].max_budget is None, state + assert state[0].max_budget == 0.05, state default_budget_after: Final = _budget_record(default_budget_id) assert default_budget_after == default_budget_before, repr(default_budget_after) assert default_budget_after[0].max_budget == 0.05, default_budget_after @@ -1024,3 +1027,96 @@ def test_bulk_update_restores_team_default_when_last_member_limit_is_cleared( assert first_observations + second_observations == (provider_model, provider_model), repr( (first_observations, second_observations) ) + + +def _budget_reset_at(budget_id: str) -> str: + rows: Final = read_rows( + 'SELECT budget_reset_at::text AS budget_reset_at FROM "LiteLLM_BudgetTable" WHERE budget_id = %s', (budget_id,) + ) + assert len(rows) == 1, rows + return string_value(rows[0]["budget_reset_at"]) + + +async def _run_scheduled_budget_reset() -> None: + client: Final = PrismaClient( + database_url=os.environ["DATABASE_URL"], proxy_logging_obj=ProxyLogging(user_api_key_cache=UserApiKeyCache()) + ) + await client.connect() + try: + await ResetBudgetJob( + ProxyLogging(user_api_key_cache=UserApiKeyCache()), client + ).reset_budget_for_litellm_budget_table() + finally: + await client.db.disconnect() + + +def test_temp_budget_increase_on_a_team_default_member_keeps_the_team_reset_schedule( + gateway: Gateway, upstream: httpx.Client +) -> None: + with gateway.scenario() as scenario: + model, provider_model = _priced_model(scenario) + team: Final = scenario.team(models=[model], team_member_budget=5, team_member_budget_duration="30d") + topped_up: Final = scenario.user() + untouched: Final = scenario.user() + for user in (topped_up, untouched): + added = gateway.request( + "POST", "/team/member_add", {"team_id": team, "member": {"user_id": user, "role": "user"}} + ) + assert added.status_code == 200, added.text + default_budget_id: Final = _team_default_budget_id(team) + for user in (topped_up, untouched): + key = scenario.key(team_id=team, user_id=user) + chat = _chat(gateway, model, key, f"spend before top-up {uuid.uuid4().hex}") + assert chat.status_code == 200, chat.text + observed: Final = _observed_models(upstream) + assert observed == (provider_model, provider_model), repr(observed) + for user in (topped_up, untouched): + accrued = eventually( + lambda user=user: _budget_state(team, user), + lambda values: len(values) == 1 and values[0].spend is not None and values[0].spend > 0, + seconds=70, + ) + assert accrued[0].budget_id == default_budget_id, accrued + + expiry: Final = datetime.now(timezone.utc) + timedelta(days=30) + granted: Final = _member_update( + gateway, + { + "team_id": team, + "user_id": topped_up, + "temp_budget_increase": 1, + "temp_budget_expiry": expiry.isoformat(), + }, + ) + assert granted.temp_budget_increase == 1, granted + topped_up_state: Final = _budget_state(team, topped_up) + assert len(topped_up_state) == 1, topped_up_state + topped_up_budget_id: Final = topped_up_state[0].budget_id + assert topped_up_budget_id is not None and topped_up_budget_id != default_budget_id, topped_up_state + assert topped_up_state[0].max_budget == 5, topped_up_state + assert topped_up_state[0].budget_duration == "30d", topped_up_state + assert topped_up_state[0].temp_budget_increase == 1, topped_up_state + assert _budget_reset_at(topped_up_budget_id) == _budget_reset_at(default_budget_id), topped_up_state + assert _budget_state(team, untouched)[0].budget_id == default_budget_id + + write_rows( + "UPDATE \"LiteLLM_BudgetTable\" SET budget_reset_at = NOW() - INTERVAL '1 hour' WHERE budget_id IN (%s, %s)", + (default_budget_id, topped_up_budget_id), + ) + asyncio.run(_run_scheduled_budget_reset()) + for user in (topped_up, untouched): + after_reset = _budget_state(team, user) + assert len(after_reset) == 1 and after_reset[0].spend == 0, (user, after_reset) + assert _budget_reset_at(topped_up_budget_id) == _budget_reset_at(default_budget_id) + + cleared: Final = _member_update( + gateway, + {"team_id": team, "user_id": topped_up, "temp_budget_increase": None, "temp_budget_expiry": None}, + ) + assert cleared.temp_budget_increase is None, cleared + final_state: Final = _budget_state(team, topped_up) + assert len(final_state) == 1, final_state + assert final_state[0].budget_id == topped_up_budget_id, final_state + assert final_state[0].budget_duration == "30d", final_state + assert final_state[0].max_budget == 5, final_state + assert final_state[0].temp_budget_increase is None, final_state diff --git a/tests/integration/spend/test_team_member_total_spend_reconciliation.py b/tests/integration/spend/test_team_member_total_spend_reconciliation.py new file mode 100644 index 00000000000..f5ccae0d12b --- /dev/null +++ b/tests/integration/spend/test_team_member_total_spend_reconciliation.py @@ -0,0 +1,273 @@ +from __future__ import annotations + +import asyncio +import json +import os +import uuid +from concurrent.futures import ThreadPoolExecutor +from typing import Final + +import httpx +import pytest +from pydantic import JsonValue, TypeAdapter + +import litellm +from litellm.caching.dual_cache import DualCache +from litellm.proxy.common_utils.reset_budget_job import ResetBudgetJob +from litellm.proxy.utils import PrismaClient, ProxyLogging +from tests.integration._support.client import Gateway, Scenario, eventually, list_value, object_value, string_value +from tests.integration._support.database import read_rows, write_rows +from tests.integration._support.provider import PROVIDER_URL, SharedProvider +from tests.integration._support.wire import Reply + +_CALL_COST: Final = 0.02 +JSON_VALUE: Final = TypeAdapter(JsonValue) +_LEGACY_SPEND: Final = 612.4 +_LEGACY_TOTAL: Final = 148.1 +_HEALTHY_SPEND: Final = 12.25 +_HEALTHY_TOTAL: Final = 97.8 + + +def _completion() -> Reply: + return Reply( + body=json.dumps( + { + "id": f"chatcmpl-{uuid.uuid4().hex}", + "object": "chat.completion", + "created": 1, + "model": "gpt-4o-mini", + "choices": [ + {"index": 0, "message": {"role": "assistant", "content": "scripted"}, "finish_reason": "stop"} + ], + "usage": {"prompt_tokens": 10, "completion_tokens": 5, "total_tokens": 15}, + } + ).encode() + ) + + +def _priced_model(scenario: Scenario) -> str: + return scenario.model(api_base=f"{PROVIDER_URL}/v1", input_cost_per_token=0.001, output_cost_per_token=0.002) + + +def _member_with_budget(gateway: Gateway, scenario: Scenario, team_id: str, *, max_budget: float) -> str: + user_id: Final = scenario.user(user_role="internal_user") + gateway.post( + "/team/member_add", + {"team_id": team_id, "member": {"role": "user", "user_id": user_id}, "max_budget_in_team": max_budget}, + ) + return user_id + + +def _seed_membership(user_id: str, team_id: str, *, spend: float, total_spend: float) -> None: + write_rows( + 'UPDATE "LiteLLM_TeamMembership" SET spend = %s::float8, total_spend = %s::float8 ' + "WHERE user_id = %s AND team_id = %s", + (str(spend), str(total_spend), user_id, team_id), + ) + + +def _membership(user_id: str, team_id: str) -> tuple[float, float]: + rows: Final = read_rows( + 'SELECT spend, total_spend FROM "LiteLLM_TeamMembership" WHERE user_id = %s AND team_id = %s', + (user_id, team_id), + ) + assert len(rows) == 1, rows + return float(str(rows[0]["spend"])), float(str(rows[0]["total_spend"])) + + +def _membership_reaches(user_id: str, team_id: str, *, total_spend: float) -> tuple[float, float]: + return eventually( + lambda: _membership(user_id, team_id), + lambda row: row[1] == pytest.approx(total_spend), + seconds=70, + ) + + +def _served(gateway: Gateway, provider: SharedProvider, model: str, key: str) -> None: + provider.expect(_completion()) + response: Final = gateway.request( + "POST", + "/v1/chat/completions", + {"model": model, "messages": [{"role": "user", "content": f"reconcile {uuid.uuid4().hex}"}]}, + key=key, + ) + assert response.status_code == 200, response.text + assert len(provider.received()) == 1 + + +def _reset_spend(gateway: Gateway, team_id: str, user_id: str, reset_to: float) -> httpx.Response: + return gateway.request("POST", f"/team/{team_id}/member/{user_id}/reset_spend", {"reset_to": reset_to}) + + +def _membership_figures(row: JsonValue) -> tuple[str, tuple[float, float]]: + membership: Final = object_value(row) + return string_value(membership["user_id"]), ( + float(str(membership["spend"])), + float(str(membership["total_spend"])), + ) + + +def _reported_memberships(gateway: Gateway, path: str, params: dict[str, str]) -> dict[str, tuple[float, float]]: + """/team/info answers with one team object, /team/list with a list of them.""" + response: Final = gateway.request("GET", path, params=params) + assert response.status_code == 200, f"GET {path}: {response.status_code} {response.text}" + body: Final = JSON_VALUE.validate_json(response.content) + teams: Final = [object_value(body)] if isinstance(body, dict) else [object_value(team) for team in list_value(body)] + rows: Final = [ + row for team in teams for row in list_value(team["team_memberships"]) + ] # comprehension-ok: flatten memberships across teams + return dict(_membership_figures(row) for row in rows) + + +def test_a_flush_lifts_a_legacy_total_to_the_cycle_spend_and_leaves_a_healthy_row_on_its_baseline( + gateway: Gateway, provider: SharedProvider +) -> None: + with gateway.scenario() as scenario: + model: Final = _priced_model(scenario) + team_id: Final = scenario.team(models=[model]) + legacy: Final = _member_with_budget(gateway, scenario, team_id, max_budget=10_000) + healthy: Final = _member_with_budget(gateway, scenario, team_id, max_budget=10_000) + _seed_membership(legacy, team_id, spend=_LEGACY_SPEND, total_spend=_LEGACY_TOTAL) + _seed_membership(healthy, team_id, spend=_HEALTHY_SPEND, total_spend=_HEALTHY_TOTAL) + legacy_key: Final = scenario.key(user_id=legacy, team_id=team_id, models=[model]) + healthy_key: Final = scenario.key(user_id=healthy, team_id=team_id, models=[model]) + + _served(gateway, provider, model, legacy_key) + _served(gateway, provider, model, healthy_key) + + legacy_row: Final = _membership_reaches( + legacy, team_id, total_spend=max(_LEGACY_SPEND, _LEGACY_TOTAL) + _CALL_COST + ) + assert legacy_row[0] == pytest.approx(_LEGACY_SPEND + _CALL_COST) + healthy_row: Final = _membership_reaches(healthy, team_id, total_spend=_HEALTHY_TOTAL + _CALL_COST) + assert healthy_row[0] == pytest.approx(_HEALTHY_SPEND + _CALL_COST) + + +def test_team_info_and_team_list_report_a_legacy_total_no_lower_than_the_cycle_spend(gateway: Gateway) -> None: + with gateway.scenario() as scenario: + team_id: Final = scenario.team() + legacy: Final = _member_with_budget(gateway, scenario, team_id, max_budget=10_000) + healthy: Final = _member_with_budget(gateway, scenario, team_id, max_budget=10_000) + _seed_membership(legacy, team_id, spend=_LEGACY_SPEND, total_spend=_LEGACY_TOTAL) + _seed_membership(healthy, team_id, spend=_HEALTHY_SPEND, total_spend=_HEALTHY_TOTAL) + + info: Final = _reported_memberships(gateway, "/team/info", {"team_id": team_id}) + listed: Final = _reported_memberships(gateway, "/team/list", {"team_id": team_id}) + + for reported in (info, listed): + assert reported[legacy] == (pytest.approx(_LEGACY_SPEND), pytest.approx(_LEGACY_SPEND)) + assert reported[healthy] == (pytest.approx(_HEALTHY_SPEND), pytest.approx(_HEALTHY_TOTAL)) + assert _membership(legacy, team_id) == (pytest.approx(_LEGACY_SPEND), pytest.approx(_LEGACY_TOTAL)) + + +@pytest.mark.parametrize("reset_to", [0.0, 100.0], ids=["to_zero", "to_nonzero"]) +def test_an_admin_reset_keeps_the_legacy_cycle_spend_as_the_lifetime_floor(gateway: Gateway, reset_to: float) -> None: + with gateway.scenario() as scenario: + team_id: Final = scenario.team() + legacy: Final = _member_with_budget(gateway, scenario, team_id, max_budget=10_000) + _seed_membership(legacy, team_id, spend=_LEGACY_SPEND, total_spend=_LEGACY_TOTAL) + + response: Final = _reset_spend(gateway, team_id, legacy, reset_to) + + assert response.status_code == 200, response.text + assert _membership(legacy, team_id) == (pytest.approx(reset_to), pytest.approx(_LEGACY_SPEND)) + + +def test_concurrent_admin_resets_leave_one_winner_and_a_lifetime_floor_at_the_old_cycle_spend( + gateway: Gateway, +) -> None: + """Two admins reset the same member at once. Each UPDATE re-checks reset_to <= spend, so + the higher reset either lands first or is refused with 409 once the lower one has landed. + Whatever the order, the row ends at the lower value with the old cycle spend preserved.""" + with gateway.scenario() as scenario: + team_id: Final = scenario.team() + legacy: Final = _member_with_budget(gateway, scenario, team_id, max_budget=10_000) + _seed_membership(legacy, team_id, spend=_LEGACY_SPEND, total_spend=_LEGACY_TOTAL) + + with ThreadPoolExecutor(max_workers=2) as pool: + higher, lower = pool.map(lambda value: _reset_spend(gateway, team_id, legacy, value), (600.0, 500.0)) + + assert lower.status_code == 200, lower.text + assert higher.status_code in (200, 409), higher.text + assert _membership(legacy, team_id) == (pytest.approx(500.0), pytest.approx(_LEGACY_SPEND)) + + +def test_an_admin_reset_racing_a_flush_ends_with_the_lifetime_equal_to_old_cycle_plus_cost( + gateway: Gateway, provider: SharedProvider +) -> None: + with gateway.scenario() as scenario: + model: Final = _priced_model(scenario) + team_id: Final = scenario.team(models=[model]) + legacy: Final = _member_with_budget(gateway, scenario, team_id, max_budget=10_000) + _seed_membership(legacy, team_id, spend=_LEGACY_SPEND, total_spend=_LEGACY_TOTAL) + key: Final = scenario.key(user_id=legacy, team_id=team_id, models=[model]) + + _served(gateway, provider, model, key) + reset: Final = _reset_spend(gateway, team_id, legacy, 0.0) + assert reset.status_code == 200, reset.text + + spend, total = _membership_reaches(legacy, team_id, total_spend=_LEGACY_SPEND + _CALL_COST) + assert spend in (pytest.approx(0.0), pytest.approx(_CALL_COST)), (spend, total) + assert total >= spend + + +def _expire_member_budget(user_id: str, team_id: str, *, budget_duration: str) -> None: + write_rows( + "UPDATE \"LiteLLM_BudgetTable\" SET budget_duration = %s, budget_reset_at = NOW() - INTERVAL '1 hour' " + 'WHERE budget_id = (SELECT budget_id FROM "LiteLLM_TeamMembership" WHERE user_id = %s AND team_id = %s)', + (budget_duration, user_id, team_id), + ) + + +async def _run_scheduled_reset() -> None: + client: Final = PrismaClient( + database_url=os.environ["DATABASE_URL"], proxy_logging_obj=ProxyLogging(user_api_key_cache=DualCache()) + ) + await client.connect() + try: + await ResetBudgetJob( + ProxyLogging(user_api_key_cache=DualCache()), client + ).reset_budget_for_litellm_budget_table() + finally: + await client.db.disconnect() + + +@pytest.mark.parametrize( + "spend, max_budget, carried", + [(8.0, 10.0, 0.0), (10.0, 10.0, 0.0), (15.0, 10.0, 5.0)], + ids=["below_cap", "at_cap", "above_cap_carries_overage"], +) +def test_a_scheduled_reset_lifts_the_legacy_total_before_zeroing_or_carrying_the_cycle_spend( + gateway: Gateway, monkeypatch: pytest.MonkeyPatch, spend: float, max_budget: float, carried: float +) -> None: + monkeypatch.setattr(litellm, "budget_rollover", True) + with gateway.scenario() as scenario: + team_id: Final = scenario.team() + legacy: Final = _member_with_budget(gateway, scenario, team_id, max_budget=max_budget) + _seed_membership(legacy, team_id, spend=spend, total_spend=3.0) + _expire_member_budget(legacy, team_id, budget_duration="1d") + + asyncio.run(_run_scheduled_reset()) + + assert _membership(legacy, team_id) == (pytest.approx(carried), pytest.approx(spend)) + asyncio.run(_run_scheduled_reset()) + assert _membership(legacy, team_id) == (pytest.approx(carried), pytest.approx(spend)) + + +def test_a_scheduled_reset_racing_a_flush_ends_with_the_lifetime_equal_to_old_cycle_plus_cost( + gateway: Gateway, provider: SharedProvider +) -> None: + with gateway.scenario() as scenario: + model: Final = _priced_model(scenario) + team_id: Final = scenario.team(models=[model]) + legacy: Final = _member_with_budget(gateway, scenario, team_id, max_budget=10_000) + _seed_membership(legacy, team_id, spend=_LEGACY_SPEND, total_spend=_LEGACY_TOTAL) + _expire_member_budget(legacy, team_id, budget_duration="1d") + key: Final = scenario.key(user_id=legacy, team_id=team_id, models=[model]) + + _served(gateway, provider, model, key) + asyncio.run(_run_scheduled_reset()) + + spend, total = _membership_reaches(legacy, team_id, total_spend=_LEGACY_SPEND + _CALL_COST) + assert spend in (pytest.approx(0.0), pytest.approx(_CALL_COST)), (spend, total) + assert total >= spend diff --git a/tests/test_litellm_rust/messages/test_body_hooks.py b/tests/test_litellm_rust/messages/test_body_hooks.py index 188cd58e00e..59f27d5dc04 100644 --- a/tests/test_litellm_rust/messages/test_body_hooks.py +++ b/tests/test_litellm_rust/messages/test_body_hooks.py @@ -8,8 +8,8 @@ import litellm from litellm.integrations.custom_logger import CustomLogger from litellm.integrations.websearch_interception.handler import WebSearchInterceptionLogger from litellm.litellm_core_utils.litellm_logging import Logging -from litellm.llms.anthropic.pass_through.messages import interceptors -from litellm.llms.anthropic.pass_through.messages.interceptors.base import MessagesInterceptor +from litellm.llms.anthropic.messages.native import interceptors +from litellm.llms.anthropic.messages.native.interceptors.base import MessagesInterceptor from tests.test_litellm_rust.messages.data import BODY_HOOKS, MESSAGES_RESPONSE, REQUEST, call from tests.test_litellm_rust.support.callback_recorder import drain_logging from tests.test_litellm_rust.support.body_hooks import LegacyAgenticLoop, PlannedAgenticLoop, agentic_hooks diff --git a/tests/test_litellm_rust/messages/test_dispatch.py b/tests/test_litellm_rust/messages/test_dispatch.py index 50f71569d73..9430e01ea8a 100644 --- a/tests/test_litellm_rust/messages/test_dispatch.py +++ b/tests/test_litellm_rust/messages/test_dispatch.py @@ -8,7 +8,7 @@ import litellm from litellm.caching.caching import Cache from litellm.integrations.custom_logger import CustomLogger from litellm.integrations.websearch_interception.handler import WebSearchInterceptionLogger -from litellm.llms.anthropic.pass_through.messages import handler as python_messages +from litellm.llms.anthropic.messages.native import handler as python_messages from litellm.messages import dispatch from litellm.messages.dispatch import ( _ADISPATCH, # pyright: ignore[reportPrivateUsage] # tests configured dispatch diff --git a/tests/unit/a2a_protocol/test_utils.py b/tests/unit/a2a_protocol/test_utils.py index 8a219211c62..dfa8449f6e6 100644 --- a/tests/unit/a2a_protocol/test_utils.py +++ b/tests/unit/a2a_protocol/test_utils.py @@ -1,5 +1,8 @@ """Tests for litellm/a2a_protocol/utils.py token/usage extraction.""" +from types import SimpleNamespace +from typing import Final + import pytest pytest.importorskip("a2a.compat.v0_3.types") @@ -7,6 +10,7 @@ pytest.importorskip("a2a.compat.v0_3.types") from a2a.compat.v0_3.types import MessageSendParams, SendMessageRequest from litellm.a2a_protocol.utils import A2ARequestUtils +from tests.unit.litellm_core_utils.attribute_forwarder import AttributeForwarder def _request(user_text: str) -> SendMessageRequest: @@ -39,3 +43,13 @@ def test_calculate_usage_counts_input_tokens_from_request_object(): assert prompt_tokens > 0 assert completion_tokens > 0 assert total_tokens == prompt_tokens + completion_tokens + + +def test_calculate_usage_counts_input_tokens_from_a_message_that_forwards_its_fields(): + request: Final = _request("count these input tokens please") + forwarded_request: Final = SimpleNamespace(params=SimpleNamespace(message=AttributeForwarder(request.params.message))) + response_dict: Final = {"result": {"kind": "message", "parts": [{"kind": "text", "text": "ok"}]}} + + assert A2ARequestUtils.calculate_usage_from_request_response( + request=forwarded_request, response_dict=response_dict + ) == A2ARequestUtils.calculate_usage_from_request_response(request=request, response_dict=response_dict) diff --git a/tests/unit/caching/test_llm_caching_handler.py b/tests/unit/caching/test_llm_caching_handler.py index 0c0fe8ca3c5..a3efd5d97aa 100644 --- a/tests/unit/caching/test_llm_caching_handler.py +++ b/tests/unit/caching/test_llm_caching_handler.py @@ -11,11 +11,14 @@ See: https://github.com/BerriAI/litellm/pull/22247 import asyncio, gc, httpx, importlib, litellm, os, threading, time, weakref import warnings +import aiohttp import pytest +from openai import AsyncOpenAI from litellm.caching.evicted_client_closer import EvictedClientCloser from litellm.caching.llm_caching_handler import LLMClientCache +from litellm.llms.custom_httpx.aiohttp_transport import LiteLLMAiohttpTransport from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER from litellm.llms.custom_httpx.http_handler import( @@ -204,6 +207,36 @@ async def test_evicted_litellm_owned_client_is_closed_once_the_grace_window_elap assert client.closed is True +@pytest.mark.asyncio +async def test_an_evicted_owned_client_collected_inside_its_grace_window_still_closes_its_aiohttp_session(): + """ + The closer holds an evicted client weakly for the whole grace window. An SDK + process that exits, or a proxy that evicts and never calls the cache again, + collects the client first, so only its own finalizer can still close the + aiohttp session (LIT-9767). + """ + clock = _FakeClock() + cache = LLMClientCache( + max_size_in_memory=2, + evicted_client_closer=EvictedClientCloser(grace_seconds=900.0, clock=clock), + ) + session = aiohttp.ClientSession() + client = AsyncOpenAI( + api_key="sk-evicted", + http_client=httpx.AsyncClient(transport=LiteLLMAiohttpTransport(client=session)), + ) + cache.set_cache("client-key", client, litellm_owned_client=True, ttl=600) + + cache.ttl_dict = {key: 0 for key in cache.ttl_dict} + cache.expiration_heap = [(0, key) for _, key in cache.expiration_heap] + cache.evict_cache() + del client + gc.collect() + await asyncio.gather(*LiteLLMAiohttpTransport._background_close_tasks) + + assert session.closed, "the evicted client was collected inside the grace window and left its session open" + + @pytest.mark.asyncio async def test_evicted_caller_supplied_client_is_never_closed(): """litellm does not own a client the caller passed in, so it must stay open.""" diff --git a/tests/unit/containers/test_container_proxy_ownership.py b/tests/unit/containers/test_container_proxy_ownership.py index 780ae9bf6d1..ac5adeee8c1 100644 --- a/tests/unit/containers/test_container_proxy_ownership.py +++ b/tests/unit/containers/test_container_proxy_ownership.py @@ -1,6 +1,7 @@ import json import sys from types import SimpleNamespace +from typing import Final from unittest.mock import AsyncMock, MagicMock import pytest @@ -10,6 +11,7 @@ from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth from litellm.proxy.container_endpoints import ownership from litellm.responses.utils import ResponsesAPIRequestUtils from litellm.types.containers.main import ContainerListResponse, ContainerObject +from tests.unit.litellm_core_utils.attribute_forwarder import AttributeForwarder @pytest.fixture(autouse=True) @@ -97,6 +99,23 @@ async def test_should_not_mutate_dict_container_response_when_recording_owner( assert file_obj["provider_container_id"] == "cntr_provider" +@pytest.mark.asyncio +async def test_should_store_the_full_container_of_a_response_that_forwards_its_fields(monkeypatch): + table: Final = AsyncMock() + table.find_unique.return_value = None + prisma_client: Final = SimpleNamespace(db=SimpleNamespace(litellm_managedobjecttable=table)) + monkeypatch.setattr(ownership, "_get_prisma_client", AsyncMock(return_value=prisma_client)) + + await ownership.record_container_owner( + response=AttributeForwarder(_container("cntr_provider")), + user_api_key_dict=UserAPIKeyAuth(user_id="user-1"), + custom_llm_provider="openai", + ) + + file_obj: Final = json.loads(table.create.await_args.kwargs["data"]["file_object"]) + assert file_obj["status"] == "active" + + @pytest.mark.asyncio async def test_should_record_team_owner_for_keys_without_user_id(monkeypatch): table = AsyncMock() diff --git a/tests/unit/decisions/test_main.py b/tests/unit/decisions/test_main.py index 84e7a970195..b9813289749 100644 --- a/tests/unit/decisions/test_main.py +++ b/tests/unit/decisions/test_main.py @@ -38,6 +38,7 @@ from litellm.types.decisions import ( from litellm.types.router import ModelInfo from litellm.types.utils import LlmProviders from litellm.utils import ProviderConfigManager +from tests.unit.conftest import AsyncOnlyImageFetch _QUESTIONS: Final[Mapping[str, object]] = MappingProxyType( { @@ -400,6 +401,68 @@ async def test_systemone_uses_evaluation_pricing(respx_mock: respx.MockRouter, d ) +@pytest.mark.asyncio +@pytest.mark.parametrize( + ("base_url", "expected_api_base"), + [ + ("https://onprem.example/v1", "https://onprem.example/v1"), + ("", "https://fallback.example/v1"), + (None, "https://fallback.example/v1"), + (123, "https://fallback.example/v1"), + ], +) +async def test_openai_decisions_honors_base_url_alias( + respx_mock: respx.MockRouter, + monkeypatch: pytest.MonkeyPatch, + base_url: str | int | None, + expected_api_base: str, +) -> None: + monkeypatch.setenv("OPENAI_BASE_URL", "https://fallback.example/v1") + route: Final = respx_mock.post(f"{expected_api_base}/decisions").respond(json=_OPENAI_RESPONSE) + response: Final = await litellm.adecisions( + model="openai/gpt-6-luna", + input="The package arrived broken.", + questions=[{"type": "predicate", "name": "is_defect", "instructions": "Is this a defect?"}], + api_key="backend-secret-key", + base_url=base_url, + ) + + assert route.called + assert route.calls[0].request.headers["authorization"] == "Bearer backend-secret-key" + assert response._hidden_params["model"] == "openai/gpt-6-luna" + + +@pytest.mark.asyncio +async def test_openai_systemone_honors_base_url_alias(respx_mock: respx.MockRouter) -> None: + route: Final = respx_mock.post("https://onprem.example/v1/decisions").respond(json=_OPENAI_RESPONSE) + response: Final = await litellm.asystemone( + model="openai/gpt-6-luna", + state="The package arrived broken.", + questions=_QUESTIONS, + api_key="backend-secret-key", + base_url="https://onprem.example/v1", + ) + + assert route.called + assert route.calls[0].request.headers["authorization"] == "Bearer backend-secret-key" + assert response._hidden_params["model"] == "openai/gpt-6-luna" + + +@pytest.mark.asyncio +async def test_openai_decisions_api_base_wins_over_base_url_alias(respx_mock: respx.MockRouter) -> None: + route: Final = respx_mock.post("https://api.openai.com/v1/decisions").respond(json=_OPENAI_RESPONSE) + await litellm.adecisions( + model="openai/gpt-6-luna", + input="The package arrived broken.", + questions=[{"type": "predicate", "name": "is_defect", "instructions": "Is this a defect?"}], + api_key="test-key", + api_base="https://api.openai.com/v1", + base_url="https://onprem.example/v1", + ) + + assert route.called + + @pytest.mark.asyncio async def test_systemone_falls_back_to_plain_pricing_without_decisions_row( respx_mock: respx.MockRouter, @@ -620,7 +683,9 @@ _PPLX_USAGE: Final = {"model": "pplx-decider-v1-27b", "usage": {"input_tokens": ("reply", "detail"), ( pytest.param(_PPLX_USAGE, "DecisionsResponse answers: Field required", id="usage"), - pytest.param({"error": "Rate limit reached"}, "DecisionsResponse answers: Field required", id="rate_limit_text"), + pytest.param( + {"error": "Rate limit reached"}, "DecisionsResponse answers: Field required", id="rate_limit_text" + ), pytest.param({"error": "Request timed out"}, "DecisionsResponse answers: Field required", id="timeout_text"), pytest.param( {**_PPLX_USAGE, "answers": {"rate_limit": None}}, @@ -632,7 +697,9 @@ _PPLX_USAGE: Final = {"model": "pplx-decider-v1-27b", "usage": {"input_tokens": "DecisionsResponse answers.is_defect", id="answer_type_timeout_text", ), - pytest.param(["Rate limit reached"], "DecisionsResponse Input should be a valid dictionary", id="not_an_object"), + pytest.param( + ["Rate limit reached"], "DecisionsResponse Input should be a valid dictionary", id="not_an_object" + ), ), ) async def test_a_malformed_upstream_reply_is_a_server_error_whatever_its_text( @@ -1463,7 +1530,13 @@ async def test_databricks_router_deployment_sends_its_own_key_to_its_own_base( _PROVIDERS_WHOSE_CHAT_MODELS_ALSO_DECIDE: Final = frozenset( - {LlmProviders.OPENAI.value, LlmProviders.OPENROUTER.value, LlmProviders.HOSTED_VLLM.value} + { + LlmProviders.OPENAI.value, + LlmProviders.AZURE.value, + LlmProviders.OPENROUTER.value, + LlmProviders.HOSTED_VLLM.value, + LlmProviders.LM_STUDIO.value, + } ) _DEDICATED_DECIDER_PROVIDERS: Final[tuple[str, ...]] = tuple( sorted( @@ -3729,7 +3802,12 @@ async def test_a_returned_model_registered_without_prices_is_billed_at_the_reque monkeypatch.setitem( litellm.model_cost, "typesafe/jev-test-alias", - {"litellm_provider": "typesafe", "mode": "evaluation", "input_cost_per_token": 0.001, "output_cost_per_token": 0}, + { + "litellm_provider": "typesafe", + "mode": "evaluation", + "input_cost_per_token": 0.001, + "output_cost_per_token": 0, + }, ) monkeypatch.setitem(litellm.model_cost, "typesafe/jev-test-unpriced", unpriced_row) respx_mock.post("https://api.typesafe.ai/v1/systemone").respond(json={**_RESPONSE, "model": "jev-test-unpriced"}) @@ -3799,3 +3877,276 @@ def test_nace_upstream_failures_preserve_status_and_message( ) assert getattr(error.value, "status_code") == status assert upstream.call_count == 1 + + +@pytest.mark.asyncio +@pytest.mark.parametrize("is_async", [False, True]) +@pytest.mark.parametrize( + "usage", [None, {"input_tokens": 0, "output_tokens": 0}, {"input_tokens": 12, "output_tokens": 1}] +) +async def test_native_decisions_distinguishes_missing_usage_from_reported_zero( + is_async: bool, usage: dict[str, int] | None, respx_mock: respx.MockRouter +) -> None: + body = { + **{key: value for key, value in _RESPONSE.items() if key != "usage"}, + "model": "jev-1.13.0", + **({"usage": usage} if usage is not None else {}), + } + respx_mock.post("https://api.typesafe.ai/v1/systemone").respond(json=body) + params = {"model": "typesafe/jev-1.13.0", "state": "review", "questions": _QUESTIONS, "api_key": "synthetic-key"} + response = await litellm.adecisions(**params) if is_async else litellm.decisions(**params) + + assert isinstance(response, DecisionsResponse) + if usage is None: + assert response.usage is None + assert response._hidden_params.get("response_cost") is None + with pytest.raises(ValueError, match="provider did not report usage"): + litellm.completion_cost(completion_response=response) + else: + assert response.usage is not None + assert response.usage.input_tokens == usage["input_tokens"] + assert response.usage.output_tokens == usage["output_tokens"] + expected = litellm.completion_cost(completion_response=response) + assert response._hidden_params["response_cost"] == pytest.approx(expected) + assert (expected == 0) == (usage["input_tokens"] == usage["output_tokens"] == 0) + + +@pytest.mark.asyncio +@pytest.mark.parametrize("use_async", (True, False), ids=("asystemone", "systemone")) +@pytest.mark.parametrize("api_base", ("http://lmstudio.local:1234", "http://lmstudio.local:1234/v1")) +async def test_lm_studio_systemone_preserves_questions_and_omits_placeholder_auth( + use_async: bool, api_base: str, monkeypatch: pytest.MonkeyPatch, respx_mock: respx.MockRouter +) -> None: + monkeypatch.delenv("LM_STUDIO_API_KEY", raising=False) + monkeypatch.setenv("OPENAI_API_KEY", "unrelated-openai-key") + route: Final = respx_mock.post("http://lmstudio.local:1234/v1/systemone").respond(json=_RESPONSE) + kwargs: Final = { + "model": "lm_studio/local-decision", + "state": "review", + "questions": _QUESTIONS, + "api_base": api_base, + } + + response: Final = await litellm.asystemone(**kwargs) if use_async else litellm.systemone(**kwargs) + + assert json.loads(route.calls.last.request.content) == { + "model": "local-decision", + "state": "review", + "questions": dict(_QUESTIONS), + } + assert "authorization" not in route.calls.last.request.headers + assert response.answers["is_defect"] == NoulAnswer(type="noul", noul=0.9) + assert response.answers["sentiment"].choice == "positive" + assert response.answers["severity"].score == 1 + assert response.usage == DecisionsUsage(input_tokens=_INPUT_TOKENS, output_tokens=_OUTPUT_TOKENS) + + +@pytest.mark.asyncio +@pytest.mark.parametrize("use_async", (True, False), ids=("adecisions", "decisions")) +async def test_lm_studio_decisions_translates_openai_questions_and_answers( + use_async: bool, monkeypatch: pytest.MonkeyPatch, respx_mock: respx.MockRouter +) -> None: + monkeypatch.delenv("LM_STUDIO_API_KEY", raising=False) + route: Final = respx_mock.post("http://lmstudio.local:1234/v1/systemone").respond(json=_RESPONSE) + kwargs: Final = { + "model": "lm_studio/local-decision", + "input": "review", + "questions": [{"type": "predicate", "name": "is_defect", "instructions": "Is this a defect?"}], + "api_base": "http://lmstudio.local:1234/v1", + } + + response: Final = await litellm.adecisions(**kwargs) if use_async else litellm.decisions(**kwargs) + + assert json.loads(route.calls.last.request.content) == { + "model": "local-decision", + "state": "review", + "questions": {"is_defect": {"type": "noul", "instructions": "Is this a defect?"}}, + } + assert response.answers[0].type == "predicate" + assert response.answers[0].name == "is_defect" + assert response.answers[0].probability == 0.9 + + +@pytest.mark.asyncio +@pytest.mark.parametrize("explicit_key", (None, "deployment-key")) +async def test_lm_studio_decisions_resolves_environment_connection_and_explicit_key_override( + explicit_key: str | None, monkeypatch: pytest.MonkeyPatch, respx_mock: respx.MockRouter +) -> None: + monkeypatch.setenv("LM_STUDIO_API_BASE", "http://lmstudio.local:1234/v1") + monkeypatch.setenv("LM_STUDIO_API_KEY", "environment-key") + route: Final = respx_mock.post("http://lmstudio.local:1234/v1/systemone").respond(json=_RESPONSE) + + response: Final = await litellm.asystemone( + model="lm_studio/local-decision", state="review", questions=_QUESTIONS, api_key=explicit_key + ) + + assert route.calls.last.request.headers["authorization"] == f"Bearer {explicit_key or 'environment-key'}" + assert response.answers["is_defect"] == NoulAnswer(type="noul", noul=0.9) + + +@pytest.mark.asyncio +async def test_lm_studio_decisions_requires_a_server_before_http( + monkeypatch: pytest.MonkeyPatch, respx_mock: respx.MockRouter +) -> None: + monkeypatch.delenv("LM_STUDIO_API_BASE", raising=False) + with pytest.raises(litellm.BadRequestError, match="api_base is required"): + await litellm.asystemone(model="lm_studio/local-decision", state="review", questions=_QUESTIONS) + assert len(respx_mock.calls) == 0 + + +@pytest.mark.asyncio +@pytest.mark.parametrize("remote_image", (False, True), ids=("inline", "remote")) +async def test_lm_studio_decisions_sends_inline_images_to_systemone( + monkeypatch: pytest.MonkeyPatch, + respx_mock: respx.MockRouter, + remote_image: bool, + async_only_image_fetch: AsyncOnlyImageFetch, +) -> None: + monkeypatch.delenv("LM_STUDIO_API_KEY", raising=False) + image: Final = "https://images.example/input.png" if remote_image else "data:image/png;base64,AA==" + expected_image: Final = async_only_image_fetch.data_url if remote_image else image + route: Final = respx_mock.post("http://lmstudio.local:1234/v1/systemone").respond(json=_RESPONSE) + + response: Final = await litellm.adecisions( + model="lm_studio/local-decision", + input=[ + { + "role": "user", + "content": [{"type": "input_text", "text": "review"}, {"type": "input_image", "image_url": image}], + } + ], + questions=[{"type": "predicate", "name": "is_defect", "instructions": "Is this a defect?"}], + api_base="http://lmstudio.local:1234/v1", + ) + + assert json.loads(route.calls.last.request.content) == { + "model": "local-decision", + "state": "review", + "images": [expected_image], + "questions": {"is_defect": {"type": "noul", "instructions": "Is this a defect?"}}, + } + assert response.answers[0].probability == 0.9 + + +@pytest.mark.asyncio +@pytest.mark.parametrize("remote_image", (False, True), ids=("inline", "remote")) +async def test_hosted_vllm_decisions_sends_input_images_to_systemone( + monkeypatch: pytest.MonkeyPatch, + respx_mock: respx.MockRouter, + remote_image: bool, + async_only_image_fetch: AsyncOnlyImageFetch, +) -> None: + monkeypatch.delenv("HOSTED_VLLM_API_BASE", raising=False) + monkeypatch.delenv("HOSTED_VLLM_API_KEY", raising=False) + image: Final[str] = "https://images.example/input.png" if remote_image else "data:image/png;base64,AA==" + expected_image: Final[str] = async_only_image_fetch.data_url if remote_image else image + route: Final = respx_mock.post("http://vllm.local:8000/v1/systemone").respond(json=_RESPONSE) + + response: Final = await litellm.adecisions( + model="hosted_vllm/Qwen/Qwen3-0.6B", + input=[ + { + "role": "user", + "content": [{"type": "input_text", "text": "review"}, {"type": "input_image", "image_url": image}], + } + ], + questions=[{"type": "predicate", "name": "is_defect", "instructions": "Is this a defect?"}], + api_base="http://vllm.local:8000/v1", + ) + + assert json.loads(route.calls.last.request.content) == { + "model": "Qwen/Qwen3-0.6B", + "state": "review", + "images": [expected_image], + "questions": {"is_defect": {"type": "noul", "instructions": "Is this a defect?"}}, + } + assert response.answers[0].probability == 0.9 + assert async_only_image_fetch.fetched == (["https://images.example/input.png"] if remote_image else []) + + +def test_hosted_vllm_systemone_forwards_images( + monkeypatch: pytest.MonkeyPatch, + respx_mock: respx.MockRouter, +) -> None: + monkeypatch.delenv("HOSTED_VLLM_API_BASE", raising=False) + monkeypatch.delenv("HOSTED_VLLM_API_KEY", raising=False) + image: Final[str] = "data:image/png;base64,AA==" + route: Final = respx_mock.post("http://vllm.local:8000/v1/systemone").respond(json=_RESPONSE) + + litellm.systemone( + model="hosted_vllm/Qwen/Qwen3-0.6B", + state="review", + images=[image], + questions={ + "is_defect": { + "type": "choice", + "instructions": "Is this a defect?", + "criteria": {"yes": "defective", "no": "intact"}, + } + }, + api_base="http://vllm.local:8000", + ) + + assert json.loads(route.calls.last.request.content) == { + "model": "Qwen/Qwen3-0.6B", + "state": "review", + "images": [image], + "questions": { + "is_defect": { + "type": "choice", + "instructions": "Is this a defect?", + "criteria": {"yes": "defective", "no": "intact"}, + } + }, + } + + +@pytest.mark.asyncio +async def test_hosted_vllm_decisions_sends_image_only_input_to_systemone( + monkeypatch: pytest.MonkeyPatch, + respx_mock: respx.MockRouter, +) -> None: + monkeypatch.delenv("HOSTED_VLLM_API_BASE", raising=False) + monkeypatch.delenv("HOSTED_VLLM_API_KEY", raising=False) + image: Final[str] = "data:image/png;base64,AA==" + route: Final = respx_mock.post("http://vllm.local:8000/v1/systemone").respond(json=_RESPONSE) + + await litellm.adecisions( + model="hosted_vllm/Qwen/Qwen3-0.6B", + input=[{"role": "user", "content": [{"type": "input_image", "image_url": image}]}], + questions=[{"type": "predicate", "name": "is_defect", "instructions": "Is this a defect?"}], + api_base="http://vllm.local:8000", + ) + + assert json.loads(route.calls.last.request.content) == { + "model": "Qwen/Qwen3-0.6B", + "state": "", + "images": [image], + "questions": {"is_defect": {"type": "noul", "instructions": "Is this a defect?"}}, + } + + +def test_hosted_vllm_systemone_maps_image_rejection_to_bad_request( + monkeypatch: pytest.MonkeyPatch, + respx_mock: respx.MockRouter, +) -> None: + monkeypatch.delenv("HOSTED_VLLM_API_BASE", raising=False) + monkeypatch.delenv("HOSTED_VLLM_API_KEY", raising=False) + message: Final[str] = "this model does not take image inputs" + route: Final = respx_mock.post("http://vllm.local:8000/v1/systemone").respond( + status_code=400, + json={"error": {"message": message, "type": "BadRequestError", "code": 400}}, + ) + + with pytest.raises(litellm.BadRequestError, match=re.escape(message)) as caught: + litellm.systemone( + model="hosted_vllm/Qwen/Qwen3-0.6B", + state="review", + images=["data:image/png;base64,AA=="], + questions={"is_defect": {"type": "noul", "instructions": "Is this a defect?"}}, + api_base="http://vllm.local:8000", + num_retries=0, + ) + + assert caught.value.status_code == 400 + assert route.call_count == 1 diff --git a/tests/unit/enterprise/proxy/hooks/test_managed_files.py b/tests/unit/enterprise/proxy/hooks/test_managed_files.py index 20ed8ac0c10..7f6e955e831 100644 --- a/tests/unit/enterprise/proxy/hooks/test_managed_files.py +++ b/tests/unit/enterprise/proxy/hooks/test_managed_files.py @@ -31,6 +31,7 @@ from litellm.proxy.openai_files_endpoints.common_utils import ( encode_file_id_with_model, ) from litellm.types.llms.openai import OpenAIFileObject +from tests.unit.litellm_core_utils.attribute_forwarder import AttributeForwarder class _InMemoryManagedFileTable: @@ -451,6 +452,20 @@ async def test_async_pre_call_deployment_hook_prefers_top_level_model_info(): ), "Should prefer top-level model_info over litellm_metadata" +@pytest.mark.asyncio +async def test_async_pre_call_deployment_hook_reads_model_info_that_forwards_its_fields(): + proxy_managed_files: Final = PROXY_LiteLLMManagedFiles(DualCache(), prisma_client=MagicMock()) + kwargs: Final = { + "input_file_id": "managed-file-abc", + "model_file_id_mapping": {"managed-file-abc": {"deployment-xyz": "file-provider-123"}}, + "model_info": AttributeForwarder({"id": "deployment-xyz"}), + } + + result: Final = await proxy_managed_files.async_pre_call_deployment_hook(kwargs=kwargs, call_type=CallTypes.acreate_batch) + + assert result["input_file_id"] == "file-provider-123" + + @pytest.mark.asyncio async def test_async_pre_call_deployment_hook_no_model_info_leaves_file_id_unchanged(): """ diff --git a/tests/unit/experimental_mcp_client/test_init.py b/tests/unit/experimental_mcp_client/test_init.py new file mode 100644 index 00000000000..1ce2a236d9d --- /dev/null +++ b/tests/unit/experimental_mcp_client/test_init.py @@ -0,0 +1,31 @@ +import importlib +import sys +from collections.abc import Mapping + +import pytest + +import litellm.mcp_client +import litellm.mcp_client.client +import litellm.mcp_client.tools + +OLD_PACKAGE = "litellm.experimental_mcp_client" + + +def test_old_package_warns_and_deep_imports_resolve_to_mcp_client(monkeypatch: pytest.MonkeyPatch) -> None: + for name in tuple(sys.modules): + if name.startswith(OLD_PACKAGE): + monkeypatch.delitem(sys.modules, name) + + with pytest.warns(DeprecationWarning, match="litellm.mcp_client"): + import litellm.experimental_mcp_client as old + + assert old.client is litellm.mcp_client.client + assert old.tools is litellm.mcp_client.tools + assert old.__all__ == litellm.mcp_client.__all__ + assert old.load_mcp_tools is litellm.mcp_client.load_mcp_tools + assert old.call_openai_tool is litellm.mcp_client.call_openai_tool + assert importlib.import_module(f"{OLD_PACKAGE}.client") is litellm.mcp_client.client + assert importlib.import_module(f"{OLD_PACKAGE}.tools") is litellm.mcp_client.tools + attrs: Mapping[str, object] = vars(old) + assert attrs["tools"] is litellm.mcp_client.tools + assert attrs["client"] is litellm.mcp_client.client diff --git a/tests/unit/images/test_main.py b/tests/unit/images/test_main.py index ff43e892eab..38af99ff505 100644 --- a/tests/unit/images/test_main.py +++ b/tests/unit/images/test_main.py @@ -1,6 +1,8 @@ import asyncio +import base64 import json from datetime import datetime +from pathlib import Path from typing import Final from unittest.mock import AsyncMock, MagicMock, patch @@ -405,3 +407,56 @@ async def test_azure_image_generation_request_body(): call_args = mock_post.call_args request_json = call_args.kwargs.get("json", {}) assert request_json == expected_body + + +@pytest.mark.asyncio +@pytest.mark.parametrize("asynchronous", [False, True]) +@pytest.mark.parametrize("transport", ["headers", "extra_headers", "scoped", "api_key"]) +@pytest.mark.parametrize("saved_key", [None, "fake-saved-gateway-key"]) +async def test_chatgpt_images_forward_client_login_and_workspace( + asynchronous: bool, + transport: str, + saved_key: str | None, + respx_mock: respx.MockRouter, + monkeypatch: pytest.MonkeyPatch, + tmp_path: Path, +) -> None: + monkeypatch.setenv("CHATGPT_TOKEN_DIR", str(tmp_path)) + claims: Final = {"https://api.openai.com/auth": {"chatgpt_account_id": "client-account"}} + payload: Final = base64.urlsafe_b64encode(json.dumps(claims).encode()).decode().rstrip("=") + token: Final = f"test.{payload}.test" + headers: Final = {"aUtHoRiZaTiOn": f"Bearer {token}", "ChatGPT-Account-Id": "selected-workspace"} + credentials: Final = ( + {"provider_specific_header": {"custom_llm_provider": "chatgpt", "extra_headers": headers}} + if transport == "scoped" + else {"api_key": token, "extra_headers": {"cHaTgPt-AcCoUnT-Id": "selected-workspace"}} + if transport == "api_key" + else {transport: {**headers, "cookie": "fake-cookie", "x-litellm-api-key": "fake-gateway-key"}} + ) + route: Final = respx_mock.post("https://chatgpt.com/backend-api/codex/images/generations").mock( + return_value=httpx.Response(200, json={"created": 1700000000, "data": [{"b64_json": "aW1n"}]}) + ) + params: Final = { + "model": "chatgpt/gpt-image-2", + "prompt": "A blue circle", + "api_key": saved_key, + **( + { + "client": AsyncOpenAI( + api_key="fake", base_url="https://chatgpt.com/backend-api/codex", http_client=httpx.AsyncClient() + ) + } + if asynchronous + else {} + ), + **credentials, + } + response: Final = await litellm.aimage_generation(**params) if asynchronous else litellm.image_generation(**params) + assert response.data[0].b64_json == "aW1n" + request: Final = route.calls.last.request + assert request.headers["authorization"] == f"Bearer {token}" + assert request.headers["chatgpt-account-id"] == "selected-workspace" + assert request.headers.get_list("content-type") == ["application/json"] + assert "cookie" not in request.headers + assert "x-litellm-api-key" not in request.headers + assert json.loads(request.content) == {"model": "gpt-image-2", "prompt": "A blue circle"} diff --git a/tests/unit/integrations/dotprompt/test_prompt_manager.py b/tests/unit/integrations/dotprompt/test_prompt_manager.py index dbd4e4a4c4c..cbf19fe7985 100644 --- a/tests/unit/integrations/dotprompt/test_prompt_manager.py +++ b/tests/unit/integrations/dotprompt/test_prompt_manager.py @@ -7,6 +7,7 @@ from fastapi.testclient import TestClient +from typing import Final from unittest.mock import MagicMock, Mock, patch import httpx @@ -362,6 +363,22 @@ def test_load_prompts_from_json_data(): assert rendered == "Dynamic prompt: test" +def test_load_prompts_from_json_data_skips_malformed_entries(): + manager: Final = PromptManager(prompt_directory=str(Path(__file__).parent)) + initial_count: Final = len(manager.prompts) + + manager.load_prompts_from_json_data( + { + "valid_prompt": {"content": "Valid: {{value}}", "metadata": {"model": "gpt-4"}}, + "string_entry": "not a prompt", + "null_entry": None, + } + ) + + assert len(manager.prompts) == initial_count + 1 + assert manager.render("valid_prompt", {"value": "ok"}) == "Valid: ok" + + def test_prompt_file_to_json_conversion(): """Test converting .prompt files to JSON format.""" # Create a temporary prompt file with frontmatter @@ -661,6 +678,27 @@ def test_prompt_initializer_registers_flat_db_prompt_under_base_id(): assert template.content == "AHOY {{name}}" +def test_prompt_initializer_accepts_params_without_dotprompt_content(): + from types import SimpleNamespace + + from litellm.integrations.dotprompt import prompt_initializer + from litellm.types.prompts.init_prompts import PromptLiteLLMParams, PromptSpec + + litellm_params: Final = SimpleNamespace( + prompt_data={"content": "AHOY {{name}}", "metadata": {"model": "gpt-4o-mini"}}, + ) + prompt_spec: Final = PromptSpec( + prompt_id="agent-prompt", + litellm_params=PromptLiteLLMParams(prompt_integration="dotprompt"), + ) + + dotprompt_manager: Final = prompt_initializer(litellm_params, prompt_spec) + + template: Final = dotprompt_manager.prompt_manager.get_prompt("agent-prompt") + assert template is not None + assert template.content == "AHOY {{name}}" + + def _swap_prompt_manager_and_spec(ignore_prompt_manager_model: bool) -> tuple[DotpromptManager, PromptSpec]: manager = DotpromptManager( prompt_data={"content": "You are a pirate assistant.", "metadata": {"model": "gpt-4o-mini"}}, diff --git a/tests/unit/integrations/gcs_bucket/test_gcs_bucket_base.py b/tests/unit/integrations/gcs_bucket/test_gcs_bucket_base.py index 07874bdbeb5..7ab683e9618 100644 --- a/tests/unit/integrations/gcs_bucket/test_gcs_bucket_base.py +++ b/tests/unit/integrations/gcs_bucket/test_gcs_bucket_base.py @@ -120,6 +120,24 @@ class TestGCSBucketBase: custom_llm_provider="vertex_ai", ) + @pytest.mark.asyncio + async def test_gcs_logging_config_ignores_request_time_bucket_and_credentials(self, monkeypatch): + monkeypatch.setenv("GCS_PATH_SERVICE_ACCOUNT", "/admin/sa.json") + handler = GCSBucketBase(bucket_name="admin-bucket") + + with patch.object(handler, "get_or_create_vertex_instance", new_callable=AsyncMock) as mock_vertex: + config = await handler.get_gcs_logging_config( + { + "standard_callback_dynamic_params": { + "gcs_bucket_name": "caller-bucket", + "gcs_path_service_account": "/caller/sa.json", + } + } + ) + + assert (config["bucket_name"], config["path_service_account"]) == ("admin-bucket", "/admin/sa.json") + mock_vertex.assert_awaited_once_with(credentials="/admin/sa.json") + @pytest.mark.asyncio async def test_log_json_data_on_gcs_url_encodes_object_name(self): handler = GCSBucketBase(bucket_name="test-bucket") diff --git a/tests/unit/integrations/newrelic/test_newrelic.py b/tests/unit/integrations/newrelic/test_newrelic.py index 00a115dd8f2..d09732c6eb2 100644 --- a/tests/unit/integrations/newrelic/test_newrelic.py +++ b/tests/unit/integrations/newrelic/test_newrelic.py @@ -1,6 +1,7 @@ import os import sys from datetime import datetime, timezone +from typing import Final from unittest.mock import MagicMock, patch import pytest @@ -491,6 +492,18 @@ class TestExtractAllMessagesTimestamps: input_msg = next(m for m in messages if not m.get("is_response")) assert input_msg["timestamp"] == int(1_000_000.0 * 1000.0) + def test_input_messages_read_a_start_time_that_only_exposes_timestamp(self): + class EpochSeconds: + def timestamp(self) -> float: + return 1_000_000.0 + + kwargs: Final = {**make_kwargs(messages=[{"role": "user", "content": "Hi"}]), "start_time": EpochSeconds()} + + messages: Final = self.logger._extract_all_messages(kwargs, make_response(), response_model="gpt-4", vendor="openai") + + input_msg: Final = next(m for m in messages if not m.get("is_response")) + assert input_msg["timestamp"] == int(1_000_000.0 * 1000.0) + def test_output_messages_get_end_time_timestamp(self): kwargs = make_kwargs(messages=[{"role": "user", "content": "Hi"}]) response = make_response() diff --git a/tests/unit/integrations/otel/test_langfuse_logger.py b/tests/unit/integrations/otel/test_langfuse_logger.py index d55f0577e03..1ac6635b8ee 100644 --- a/tests/unit/integrations/otel/test_langfuse_logger.py +++ b/tests/unit/integrations/otel/test_langfuse_logger.py @@ -11,6 +11,8 @@ import pytest pytest.importorskip("opentelemetry") +from opentelemetry import trace # noqa: E402 # needs the importorskip above +from opentelemetry.context import Context # noqa: E402 # needs the importorskip above from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter # noqa: E402 from opentelemetry.trace import SpanKind # noqa: E402 @@ -64,8 +66,8 @@ def _logger(*, capture: str = "span_only", mappers: Sequence[str] = ("genai", "l return build_otel_v2_logger(config=cfg, tracer_provider=tracer_provider), exporter -def _start_root(logger): - root = logger._emitter.start_span(SpanRole.PROXY_REQUEST, LITELLM_PROXY_REQUEST_SPAN_NAME) +def _start_root(logger: OpenTelemetryV2, parent_context: Context | None = None): + root: Final = logger._emitter.start_span(SpanRole.PROXY_REQUEST, LITELLM_PROXY_REQUEST_SPAN_NAME, parent_context) set_request_root_span(root) return root @@ -331,13 +333,28 @@ def test_unrenderable_output_never_raises_into_the_request(): assert INPUT_ATTR not in attrs and OUTPUT_ATTR not in attrs +def _inbound_traceparent() -> Context: + caller: Final = trace.SpanContext( + trace_id=0x4BF92F3577B34DA6A3CE929D0E0E4736, + span_id=0x00F067AA0BA902B7, + is_remote=True, + trace_flags=trace.TraceFlags(trace.TraceFlags.SAMPLED), + ) + return trace.set_span_in_context(trace.NonRecordingSpan(caller)) + + def _run_named_request( - logger: OpenTelemetryV2, exporter: InMemorySpanExporter, litellm_params: Mapping[str, object] + logger: OpenTelemetryV2, + exporter: InMemorySpanExporter, + litellm_params: Mapping[str, object], + parent_context: Context | None = None, ) -> tuple[Mapping[str, object], Mapping[str, object]]: response: Final = ModelResponse(choices=[Choices(message=Message(role="assistant", content="pong"))]) - root: Final = _start_root(logger) + root: Final = _start_root(logger, parent_context) logger.log_pre_api_call( - model="gpt-5.4-mini", messages=[], kwargs={"litellm_call_id": "call_1", "litellm_params": litellm_params} + model="gpt-5.4-mini", + messages=[], + kwargs={"litellm_call_id": "call_1", "litellm_params": litellm_params, "call_type": "acompletion"}, ) root.end() payload: Final = { @@ -390,14 +407,113 @@ def test_body_metadata_trace_name_names_the_root_and_the_generation(): assert generation_attrs[TRACE_NAME_ATTR] == "from-body" -def test_unnamed_request_leaves_the_trace_name_off_both_spans(): +def test_unnamed_request_derives_the_trace_name_on_the_root_only(): logger, exporter = _logger() root_attrs, generation_attrs = _run_named_request(logger, exporter, {"proxy_server_request": {"headers": {}}}) + assert root_attrs[TRACE_NAME_ATTR] == "litellm-acompletion" + assert TRACE_NAME_ATTR not in generation_attrs + + +def test_unnamed_request_under_an_inbound_traceparent_leaves_the_trace_name_to_the_caller(): + logger, exporter = _logger() + + root_attrs, generation_attrs = _run_named_request( + logger, exporter, {"proxy_server_request": {"headers": {}}}, _inbound_traceparent() + ) + assert TRACE_NAME_ATTR not in root_attrs and TRACE_NAME_ATTR not in generation_attrs +def test_named_request_under_an_inbound_traceparent_keeps_the_caller_trace_name(): + logger, exporter = _logger() + + root_attrs, generation_attrs = _run_named_request( + logger, + exporter, + {"metadata": {"trace_name": "from-body"}, "proxy_server_request": {"headers": {}}}, + _inbound_traceparent(), + ) + + assert root_attrs[TRACE_NAME_ATTR] == "from-body" + assert generation_attrs[TRACE_NAME_ATTR] == "from-body" + + +UNNAMED: Final = {"proxy_server_request": {"headers": {}}} +JUDGE_PARAMS: Final = {"metadata": {"internal_call_origin": "llm_as_a_judge_guardrail"}} +CALLER_NAMES: Final = ( + {"metadata": {"trace_name": "from-caller"}, "proxy_server_request": {"headers": {}}}, + {"proxy_server_request": {"headers": {"langfuse_trace_name": "from-caller"}}}, +) + + +def _root_trace_name_after( + logger: OpenTelemetryV2, + calls: Sequence[tuple[str, Mapping[str, object]]], + root_logger: OpenTelemetryV2 | None = None, +) -> object: + root: Final = _start_root(root_logger or logger) + for index, (call_type, litellm_params) in enumerate(calls): + logger.log_pre_api_call( + model="gpt-5.4-mini", + messages=[], + kwargs={"litellm_call_id": f"call_{index}", "litellm_params": litellm_params, "call_type": call_type}, + ) + root.end() + return dict(root.attributes or {}).get(TRACE_NAME_ATTR) + + +@pytest.mark.parametrize("later", [JUDGE_PARAMS, UNNAMED], ids=["litellm-sub-call", "untagged-call"]) +@pytest.mark.parametrize("caller", CALLER_NAMES, ids=["body", "header"]) +def test_a_later_call_in_the_request_keeps_the_caller_trace_name_on_the_root( + caller: Mapping[str, object], later: Mapping[str, object] +) -> None: + logger, _ = _logger() + + assert _root_trace_name_after(logger, (("acompletion", caller), ("acompletion", later))) == "from-caller" + + +@pytest.mark.parametrize("caller", CALLER_NAMES, ids=["body", "header"]) +def test_a_caller_trace_name_replaces_the_name_an_earlier_call_derived(caller: Mapping[str, object]) -> None: + logger, _ = _logger() + + assert _root_trace_name_after(logger, (("acompletion", JUDGE_PARAMS), ("acompletion", caller))) == "from-caller" + + +def test_a_later_call_keeps_the_trace_name_the_first_call_derived(): + logger, _ = _logger() + + assert ( + _root_trace_name_after(logger, (("anthropic_messages", UNNAMED), ("acompletion", UNNAMED))) + == "litellm-anthropic_messages" + ) + + +def test_a_litellm_sub_call_before_the_request_call_leaves_the_trace_name_to_the_request_call(): + logger, _ = _logger() + + assert ( + _root_trace_name_after(logger, (("acompletion", JUDGE_PARAMS), ("anthropic_messages", UNNAMED))) + == "litellm-anthropic_messages" + ) + + +def test_a_root_another_vendor_started_gets_no_derived_trace_name(): + logger, _ = _logger() + other_vendor, _ = _logger(mappers=("genai",)) + + assert _root_trace_name_after(logger, (("acompletion", UNNAMED),), root_logger=other_vendor) is None + + +@pytest.mark.parametrize("caller", CALLER_NAMES, ids=["body", "header"]) +def test_a_root_another_vendor_started_still_gets_the_caller_trace_name(caller: Mapping[str, object]) -> None: + logger, _ = _logger() + other_vendor, _ = _logger(mappers=("genai",)) + + assert _root_trace_name_after(logger, (("acompletion", caller),), root_logger=other_vendor) == "from-caller" + + @pytest.mark.parametrize("capture", ["span_only", "no_content"]) def test_body_metadata_user_session_and_tags_land_on_the_root_and_the_generation(capture): logger, exporter = _logger(capture=capture) @@ -420,7 +536,8 @@ def test_body_metadata_user_session_and_tags_land_on_the_root_and_the_generation assert attrs["user.id"] == "user-42" assert attrs["session.id"] == "session-7" assert tuple(attrs["langfuse.trace.tags"]) == ("prod", "eval", "nightly") - assert TRACE_NAME_ATTR not in attrs + assert root_attrs[TRACE_NAME_ATTR] == "litellm-acompletion" + assert TRACE_NAME_ATTR not in generation_attrs def test_langfuse_user_and_session_headers_beat_body_metadata_on_both_spans(): @@ -489,7 +606,9 @@ def test_a_request_without_trace_controls_stamps_none_of_them(): {"metadata": {"user_api_key_team_id": "t1", "tags": []}, "proxy_server_request": {"headers": {}}}, ) - assert set(TRACE_CONTROL_ATTRS).isdisjoint(root_attrs) + caller_only: Final = tuple(attr for attr in TRACE_CONTROL_ATTRS if attr != TRACE_NAME_ATTR) + assert set(caller_only).isdisjoint(root_attrs) + assert root_attrs[TRACE_NAME_ATTR] == "litellm-acompletion" assert set(TRACE_CONTROL_ATTRS).isdisjoint(generation_attrs) diff --git a/tests/unit/integrations/otel/test_otel_v2_destinations.py b/tests/unit/integrations/otel/test_otel_v2_destinations.py index c7a057cca5c..782442aad22 100644 --- a/tests/unit/integrations/otel/test_otel_v2_destinations.py +++ b/tests/unit/integrations/otel/test_otel_v2_destinations.py @@ -4,6 +4,7 @@ import asyncio import contextvars import threading import time +import uuid from base64 import b64encode from collections.abc import Mapping from dataclasses import replace @@ -14,10 +15,12 @@ from typing import Final import pytest from opentelemetry import trace as trace_api +from opentelemetry.context import Context from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.trace import ReadableSpan, TracerProvider from opentelemetry.sdk.trace.export import SimpleSpanProcessor from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter +from opentelemetry.sdk.trace.id_generator import RandomIdGenerator from opentelemetry.trace import Status, StatusCode import litellm @@ -1159,12 +1162,36 @@ class TestFanOut: ARIZE_TEAM_PARAMS = {"arize_space_id": "space-team", "arize_api_key": "key-team"} +def caller_context(trace_id: int) -> Context: + return trace_api.set_span_in_context( + trace_api.NonRecordingSpan( + trace_api.SpanContext(trace_id=trace_id, span_id=1, is_remote=True, trace_flags=trace_api.TraceFlags(0x01)) + ) + ) + + def arize_destination(**rates: str) -> OtelDestination: destination = destination_for("arize", {**ARIZE_TEAM_PARAMS, **rates}) assert destination is not None, "the fixture must resolve for the test to mean anything" return destination +#: Trace ids whose SHA-256 reads 0.40 and 0.80 of the way through its first eight bytes, +#: so a rate of 0.5 keeps the first and drops the second. +KEPT_AT_HALF: Final = 4 +DROPPED_AT_HALF: Final = 5 + + +class _FixedTraceId(RandomIdGenerator): + """Every trace the provider starts gets ``trace_id``.""" + + def __init__(self, trace_id: int) -> None: + self._trace_id = trace_id + + def generate_trace_id(self) -> int: + return self._trace_id + + class TestTenantSampling: """A team's ``arize_success_sampling_rate`` and ``arize_error_sampling_rate`` decide how much of its traffic the fan-out delivers to its space, the way they already decide what @@ -1173,14 +1200,17 @@ class TestTenantSampling: NAMES = {"POST /v1/chat/completions", "auth /v1/chat/completions", "chat gpt-4"} @staticmethod - def _fan_out(dest_exporter, draw=None, global_exporter=None): - provider = TracerProvider() + def _fan_out( + dest_exporter: InMemorySpanExporter, + trace_id: int | None = None, + global_exporter: InMemorySpanExporter | None = None, + ) -> TracerProvider: + provider: Final = TracerProvider() if trace_id is None else TracerProvider(id_generator=_FixedTraceId(trace_id)) if global_exporter is not None: provider.add_span_processor(_OverriddenBackendFilter(SimpleSpanProcessor(global_exporter), "arize")) - kwargs = {"processor_factory": lambda _d: SimpleSpanProcessor(dest_exporter)} - if draw is not None: - kwargs["sampling_draw"] = draw - provider.add_span_processor(TenantFanOutSpanProcessor(**kwargs)) + provider.add_span_processor( + TenantFanOutSpanProcessor(processor_factory=lambda _d: SimpleSpanProcessor(dest_exporter)) + ) return provider @staticmethod @@ -1224,7 +1254,7 @@ class TestTenantSampling: def test_an_unset_rate_exports_everything(self): dest_exporter = InMemorySpanExporter() - provider = self._fan_out(dest_exporter, draw=lambda: 0.99) + provider: Final = self._fan_out(dest_exporter, trace_id=DROPPED_AT_HALF) self._run(provider, (arize_destination(),)) @@ -1300,10 +1330,10 @@ class TestTenantSampling: def test_a_span_that_ends_after_the_root_follows_the_requests_verdict(self): """A post-call database write that starts after the whole request tree has ended - goes where the rest of the tree went, without a second draw.""" + goes where the rest of the tree went, without a second verdict.""" kept_exporter, dropped_exporter = InMemorySpanExporter(), InMemorySpanExporter() - kept = self._fan_out(kept_exporter, draw=lambda: 0.1) - dropped = self._fan_out(dropped_exporter, draw=lambda: 0.9) + kept: Final = self._fan_out(kept_exporter, trace_id=KEPT_AT_HALF) + dropped: Final = self._fan_out(dropped_exporter, trace_id=DROPPED_AT_HALF) destinations = (arize_destination(arize_success_sampling_rate="0.5"),) def late_tree(provider): @@ -1327,14 +1357,263 @@ class TestTenantSampling: } assert dropped_exporter.get_finished_spans() == () + def test_a_span_that_ends_after_a_failed_root_follows_the_failed_requests_verdict(self): + """A post-call database write after a failed request goes where that request went, + though on its own it would answer to the success rate.""" + dest_exporter: Final = InMemorySpanExporter() + provider: Final = self._fan_out(dest_exporter) + destinations: Final = (arize_destination(arize_success_sampling_rate="0.0", arize_error_sampling_rate="1.0"),) + + def run(): + set_request_destinations(destinations) + tracer: Final = get_tracer(provider, "litellm") + with tracer.start_as_current_span("POST /v1/chat/completions") as root: + root.set_status(Status(StatusCode.ERROR, "upstream 500")) + root_context: Final = trace_api.set_span_in_context(root) + with tracer.start_as_current_span("postgres INSERT LiteLLM_SpendLogs", context=root_context): + pass + + in_fresh_context(run) + + assert {s.name for s in dest_exporter.get_finished_spans()} == { + "POST /v1/chat/completions", + "postgres INSERT LiteLLM_SpendLogs", + } + + def test_a_failed_call_after_a_dropped_call_of_its_trace_still_answers_to_the_error_rate(self): + """A process that dropped a successful call of the trace keeps a later failed call of + it at an unset error rate, as a process that only served the failed call does.""" + served_both, served_failed = InMemorySpanExporter(), InMemorySpanExporter() + destinations: Final = (arize_destination(arize_success_sampling_rate="0.5"),) + both: Final = self._fan_out(served_both, trace_id=DROPPED_AT_HALF) + + self._run(both, destinations) + self._run(both, destinations, failed=True) + self._run(self._fan_out(served_failed, trace_id=DROPPED_AT_HALF), destinations, failed=True) + + assert [sorted(s.name for s in exporter.get_finished_spans()) for exporter in (served_both, served_failed)] == [ + sorted(self.NAMES) + ] * 2 + + def test_a_successful_call_after_a_kept_failed_call_of_its_trace_answers_to_the_success_rate(self): + """A process that kept a failed call of the trace drops a later successful call of it + at a zero success rate, as a process that only served the successful call does.""" + served_both, served_success = InMemorySpanExporter(), InMemorySpanExporter() + destinations: Final = (arize_destination(arize_success_sampling_rate="0.0", arize_error_sampling_rate="1.0"),) + both: Final = self._fan_out(served_both, trace_id=KEPT_AT_HALF) + + self._run(both, destinations, failed=True) + self._run(both, destinations) + self._run(self._fan_out(served_success, trace_id=KEPT_AT_HALF), destinations) + + assert len(served_both.get_finished_spans()) == len(self.NAMES), "only the failed call" + assert all(s.name in self.NAMES for s in served_both.get_finished_spans()) + assert served_success.get_finished_spans() == () + + def test_a_late_child_that_fails_after_its_request_was_dropped_is_dropped_with_it(self): + """A post-call write that fails after its successful request was dropped goes where + the request went, rather than reaching the space on its own at the error rate.""" + dest_exporter: Final = InMemorySpanExporter() + provider: Final = self._fan_out(dest_exporter) + destinations: Final = (arize_destination(arize_success_sampling_rate="0.0", arize_error_sampling_rate="1.0"),) + + def run(): + set_request_destinations(destinations) + tracer: Final = get_tracer(provider, "litellm") + with tracer.start_as_current_span("POST /v1/chat/completions") as root: + root_context: Final = trace_api.set_span_in_context(root) + with tracer.start_as_current_span("postgres INSERT LiteLLM_SpendLogs", context=root_context) as write: + write.set_status(Status(StatusCode.ERROR, "connection reset")) + + in_fresh_context(run) + + assert dest_exporter.get_finished_spans() == () + + def test_a_failure_deep_in_a_request_marks_the_whole_request(self): + """A database span that fails under the auth span puts the whole request, root + included, on the error rate.""" + dest_exporter: Final = InMemorySpanExporter() + provider: Final = self._fan_out(dest_exporter) + destinations: Final = (arize_destination(arize_success_sampling_rate="0.0", arize_error_sampling_rate="1.0"),) + + def run(): + set_request_destinations(destinations) + tracer: Final = get_tracer(provider, "litellm") + with tracer.start_as_current_span("POST /v1/chat/completions"): + with tracer.start_as_current_span("auth /v1/chat/completions"): + with tracer.start_as_current_span("postgres SELECT LiteLLM_VerificationToken") as lookup: + lookup.set_status(Status(StatusCode.ERROR, "connection reset")) + with tracer.start_as_current_span("chat gpt-4"): + pass + + in_fresh_context(run) + + assert {s.name for s in dest_exporter.get_finished_spans()} == { + *self.NAMES, + "postgres SELECT LiteLLM_VerificationToken", + } + + def test_a_span_two_levels_down_that_outlives_many_other_spans_still_closes_its_request(self): + """A classifier call under the route span that stays open while the worker serves + more requests than it tracks at once still counts against its own request, so the + request is decided once it ends, on its own outcome.""" + dest_exporter: Final = InMemorySpanExporter() + provider: Final = self._fan_out(dest_exporter) + destinations: Final = (arize_destination(arize_success_sampling_rate="0.0", arize_error_sampling_rate="1.0"),) + + def other_request(): + set_request_destinations(()) + with get_tracer(provider, "litellm").start_as_current_span("POST /v1/chat/completions"): + pass + + def run(): + set_request_destinations(destinations) + tracer: Final = get_tracer(provider, "litellm") + with tracer.start_as_current_span("POST /v1/chat/completions") as root: + with tracer.start_as_current_span("route gpt-4"): + with tracer.start_as_current_span("chat classifier"): + for _ in range(otel_providers._MAX_OPEN_REQUESTS + 1): + contextvars.Context().run(other_request) + with tracer.start_as_current_span("chat gpt-4"): + pass + root.set_status(Status(StatusCode.ERROR, "upstream 500")) + + in_fresh_context(run) + + assert {s.name for s in dest_exporter.get_finished_spans()} == { + "POST /v1/chat/completions", + "route gpt-4", + "chat classifier", + "chat gpt-4", + } + + def test_a_failure_two_levels_down_reaches_its_request_however_many_spans_are_open(self): + """A classifier call that fails while another request holds more spans open than + the worker tracks requests marks its own request, which is then kept at the error + rate as a whole.""" + dest_exporter: Final = InMemorySpanExporter() + provider: Final = self._fan_out(dest_exporter) + destinations: Final = (arize_destination(arize_success_sampling_rate="0.0", arize_error_sampling_rate="1.0"),) + others: Final = contextvars.Context() + + def open_other_request(): + set_request_destinations(()) + tracer: Final = get_tracer(provider, "litellm") + root: Final = tracer.start_span("POST /v1/chat/completions") + parent: Final = trace_api.set_span_in_context(root) + return ( + root, + *(tracer.start_span("chat flood", context=parent) for _ in range(otel_providers._MAX_OPEN_REQUESTS)), + ) + + def run(): + set_request_destinations(destinations) + tracer: Final = get_tracer(provider, "litellm") + with tracer.start_as_current_span("POST /v1/chat/completions"): + with tracer.start_as_current_span("route gpt-4"): + with tracer.start_as_current_span("chat classifier") as classifier: + held_open: Final = others.run(open_other_request) + classifier.set_status(Status(StatusCode.ERROR, "classifier timed out")) + return held_open + + held_open: Final = in_fresh_context(run) + + assert {s.name for s in dest_exporter.get_finished_spans()} == { + "POST /v1/chat/completions", + "route gpt-4", + "chat classifier", + } + for span in held_open: + span.end() + + def test_the_fan_out_forgets_a_span_once_it_ends_and_a_request_once_it_is_pushed_out(self): + """The request lookup holds only spans still open, and only those of the requests + the fan-out still counts, so neither ended spans nor a flood of open requests grow + it past the open request bound.""" + fan_out: Final = TenantFanOutSpanProcessor( + processor_factory=lambda _d: SimpleSpanProcessor(InMemorySpanExporter()) + ) + provider: Final = TracerProvider() + provider.add_span_processor(fan_out) + + def run(): + set_request_destinations((arize_destination(arize_success_sampling_rate="1.0"),)) + tracer: Final = get_tracer(provider, "litellm") + with tracer.start_as_current_span("POST /v1/chat/completions"): + with tracer.start_as_current_span("chat gpt-4"): + pass + assert (fan_out._roots, dict(fan_out._open)) == ({}, {}) + root: Final = tracer.start_span("POST /v1/chat/completions", context=trace_api.Context()) + tracer.start_span("route gpt-4", context=trace_api.set_span_in_context(root)) + return tuple( + tracer.start_span(f"POST {index}", context=trace_api.Context()) + for index in range(otel_providers._MAX_OPEN_REQUESTS) + ) + + held_open: Final = in_fresh_context(run) + + assert len(fan_out._roots) == otel_providers._MAX_OPEN_REQUESTS + for span in held_open: + span.end() + assert (fan_out._roots, dict(fan_out._open)) == ({}, {}) + + def test_a_span_starting_under_an_ended_span_below_the_root_follows_its_request(self): + """A post-call write started under the route span after its failed request ended + is kept with the request at the error rate, rather than decided on its own at the + success rate.""" + dest_exporter: Final = InMemorySpanExporter() + provider: Final = self._fan_out(dest_exporter) + destinations: Final = (arize_destination(arize_success_sampling_rate="0.0", arize_error_sampling_rate="1.0"),) + + def run(): + set_request_destinations(destinations) + tracer: Final = get_tracer(provider, "litellm") + with tracer.start_as_current_span("POST /v1/chat/completions") as root: + with tracer.start_as_current_span("route gpt-4") as route: + route_context: Final = trace_api.set_span_in_context(route) + root.set_status(Status(StatusCode.ERROR, "upstream 500")) + with tracer.start_as_current_span("postgres INSERT LiteLLM_SpendLogs", context=route_context): + pass + + in_fresh_context(run) + + assert {s.name for s in dest_exporter.get_finished_spans()} == { + "POST /v1/chat/completions", + "route gpt-4", + "postgres INSERT LiteLLM_SpendLogs", + } + + def test_concurrent_calls_of_one_trace_each_answer_to_their_own_outcome(self): + """Two calls of the caller's trace in flight at once on one process, one failing, + are decided as two processes serving one each would decide them.""" + dest_exporter: Final = InMemorySpanExporter() + provider: Final = self._fan_out(dest_exporter) + destinations: Final = (arize_destination(arize_success_sampling_rate="0.0", arize_error_sampling_rate="1.0"),) + remote: Final = trace_api.SpanContext( + trace_id=KEPT_AT_HALF, span_id=1, is_remote=True, trace_flags=trace_api.TraceFlags(0x01) + ) + + def run(): + set_request_destinations(destinations) + tracer: Final = get_tracer(provider, "litellm") + caller: Final = trace_api.set_span_in_context(trace_api.NonRecordingSpan(remote)) + with tracer.start_as_current_span("POST failed", context=caller) as failed: + with tracer.start_as_current_span("POST succeeded", context=caller): + pass + failed.set_status(Status(StatusCode.ERROR, "upstream 500")) + + in_fresh_context(run) + + assert [s.name for s in dest_exporter.get_finished_spans()] == ["POST failed"] + def test_a_late_span_whose_verdict_was_forgotten_is_decided_on_its_own_not_stranded(self): """Once enough other requests have been decided to evict a request's verdict, a span of it that starts late (a post-call database write) opens and closes its own count, - so it is decided on a draw of its own as soon as it ends instead of waiting in a tree - nothing would ever close.""" + so it is decided on its own as soon as it ends instead of waiting in a tree nothing + would ever close.""" dest_exporter = InMemorySpanExporter() - provider = self._fan_out(dest_exporter, draw=lambda: 0.1) - destinations = (arize_destination(arize_success_sampling_rate="0.5"),) + provider: Final = self._fan_out(dest_exporter) + destinations: Final = (arize_destination(arize_success_sampling_rate="1.0"),) def run(): set_request_destinations(destinations) @@ -1353,18 +1632,17 @@ class TestTenantSampling: assert names[0] == "POST /v1/chat/completions" assert names[-1] == "postgres INSERT LiteLLM_SpendLogs", "exported as it ended, not held for a root" - def test_a_callers_traceparent_neither_steers_the_draw_nor_hides_the_root(self): - """The draw is random, not read from the trace id a caller may have chosen, and the - server span under a remote parent still closes the tree.""" + def test_a_callers_traceparent_decides_by_its_trace_id_and_still_closes_the_tree(self): + """A request continuing a caller's trace is decided on that trace id, and the server + span under a remote parent still closes the tree.""" dest_exporter = InMemorySpanExporter() - draws = iter([0.9, 0.1]) - provider = self._fan_out(dest_exporter, draw=lambda: next(draws)) + provider: Final = self._fan_out(dest_exporter) destinations = (arize_destination(arize_success_sampling_rate="0.5"),) def run(): set_request_destinations(destinations) tracer = get_tracer(provider, "litellm") - for trace_id in (1, 2): + for trace_id in (DROPPED_AT_HALF, KEPT_AT_HALF): remote = trace_api.SpanContext( trace_id=trace_id, span_id=1, is_remote=True, trace_flags=trace_api.TraceFlags(0x01) ) @@ -1377,12 +1655,12 @@ class TestTenantSampling: kept = dest_exporter.get_finished_spans() assert [s.name for s in kept] == ["chat gpt-4", "POST /v1/chat/completions"] - assert all(s.context.trace_id == 2 for s in kept), "the second request, whose draw of 0.1 passed" + assert all(s.context.trace_id == KEPT_AT_HALF for s in kept) def test_a_root_that_never_ends_holds_the_tree_only_up_to_the_bound(self): dest_exporter = InMemorySpanExporter() - provider = self._fan_out(dest_exporter, draw=lambda: 0.0) - destinations = (arize_destination(arize_success_sampling_rate="0.5"),) + provider: Final = self._fan_out(dest_exporter) + destinations: Final = (arize_destination(arize_success_sampling_rate="1.0"),) def run(): set_request_destinations(destinations) @@ -1397,8 +1675,8 @@ class TestTenantSampling: def test_a_flood_of_waiting_trees_decides_the_oldest_on_what_it_has(self): dest_exporter = InMemorySpanExporter() - provider = self._fan_out(dest_exporter, draw=lambda: 0.0) - destinations = (arize_destination(arize_success_sampling_rate="0.5"),) + provider: Final = self._fan_out(dest_exporter) + destinations: Final = (arize_destination(arize_success_sampling_rate="1.0"),) def run(): set_request_destinations(destinations) @@ -1413,21 +1691,21 @@ class TestTenantSampling: assert [s.name for s in dest_exporter.get_finished_spans()] == ["chat 0"] - def test_a_flood_of_open_traces_forgets_the_oldest_and_decides_it_as_its_spans_end(self): - """The fan-out counts open spans for a bounded number of traces, a bound far above - what one process keeps in flight, since every trace of the provider is counted, not - only the sampled ones. A trace pushed out of that count is decided on what it has as + def test_a_flood_of_open_requests_forgets_the_oldest_and_decides_it_as_its_spans_end(self): + """The fan-out counts open spans for a bounded number of requests, a bound far above + what one process keeps in flight, since every request of the provider is counted, not + only the sampled ones. A request pushed out of that count is decided on what it has as its next span ends, root still open, rather than held until a bound gets to it.""" dest_exporter = InMemorySpanExporter() - provider = self._fan_out(dest_exporter, draw=lambda: 0.0) - destinations = (arize_destination(arize_success_sampling_rate="0.5"),) + provider: Final = self._fan_out(dest_exporter) + destinations: Final = (arize_destination(arize_success_sampling_rate="1.0"),) def run(): set_request_destinations(destinations) tracer = get_tracer(provider, "litellm") root = tracer.start_span("POST /v1/chat/completions", context=trace_api.Context()) tracer.start_span("auth /v1/chat/completions", context=trace_api.set_span_in_context(root)).end() - for index in range(otel_providers._MAX_OPEN_TRACES): + for index in range(otel_providers._MAX_OPEN_REQUESTS): tracer.start_span(f"POST {index}", context=trace_api.Context()) assert dest_exporter.get_finished_spans() == (), "still held before the count is forgotten" tracer.start_span("chat gpt-4", context=trace_api.set_span_in_context(root)).end() @@ -1443,14 +1721,12 @@ class TestTenantSampling: def test_shutdown_decides_what_is_still_held(self): dest_exporter = InMemorySpanExporter() - fan_out = TenantFanOutSpanProcessor( - processor_factory=lambda _d: SimpleSpanProcessor(dest_exporter), sampling_draw=lambda: 0.0 - ) + fan_out: Final = TenantFanOutSpanProcessor(processor_factory=lambda _d: SimpleSpanProcessor(dest_exporter)) provider = TracerProvider() provider.add_span_processor(fan_out) def run(): - set_request_destinations((arize_destination(arize_success_sampling_rate="0.5"),)) + set_request_destinations((arize_destination(arize_success_sampling_rate="1.0"),)) tracer = get_tracer(provider, "litellm") with tracer.start_as_current_span("POST /v1/chat/completions"): with tracer.start_as_current_span("chat gpt-4"): @@ -1476,14 +1752,12 @@ class TestTenantSampling: straggler.end() super().on_end(span) - fan_out = TenantFanOutSpanProcessor( - processor_factory=lambda _d: _EndsAStragglerOnExport(dest_exporter), sampling_draw=lambda: 0.0 - ) + fan_out: Final = TenantFanOutSpanProcessor(processor_factory=lambda _d: _EndsAStragglerOnExport(dest_exporter)) provider = TracerProvider() provider.add_span_processor(fan_out) def run(): - set_request_destinations((arize_destination(arize_success_sampling_rate="0.5"),)) + set_request_destinations((arize_destination(arize_success_sampling_rate="1.0"),)) tracer = get_tracer(provider, "litellm") root = tracer.start_span("POST /v1/chat/completions", context=trace_api.Context()) tracer.start_span("chat gpt-4", context=trace_api.set_span_in_context(root)).end() @@ -1495,20 +1769,20 @@ class TestTenantSampling: assert {s.name for s in dest_exporter.get_finished_spans()} == {"chat gpt-4", "embed ada"} - def test_a_zero_rate_drops_even_a_draw_of_zero(self): + def test_a_zero_rate_drops_a_trace_a_half_rate_keeps(self): dest_exporter = InMemorySpanExporter() - provider = self._fan_out(dest_exporter, draw=lambda: 0.0) + provider: Final = self._fan_out(dest_exporter, trace_id=KEPT_AT_HALF) self._run(provider, (arize_destination(arize_success_sampling_rate="0.0"),)) assert dest_exporter.get_finished_spans() == () - def test_the_draw_is_compared_to_the_rate_the_way_the_legacy_callback_compares_it(self): + def test_the_trace_id_is_read_against_the_rate(self): dropped_exporter, kept_exporter = InMemorySpanExporter(), InMemorySpanExporter() - destinations = (arize_destination(arize_success_sampling_rate="0.2"),) + destinations: Final = (arize_destination(arize_success_sampling_rate="0.5"),) - self._run(self._fan_out(dropped_exporter, draw=lambda: 0.3), destinations) - self._run(self._fan_out(kept_exporter, draw=lambda: 0.2), destinations) + self._run(self._fan_out(dropped_exporter, trace_id=DROPPED_AT_HALF), destinations) + self._run(self._fan_out(kept_exporter, trace_id=KEPT_AT_HALF), destinations) assert dropped_exporter.get_finished_spans() == () assert {s.name for s in kept_exporter.get_finished_spans()} == self.NAMES @@ -1527,6 +1801,39 @@ class TestTenantSampling: assert all(names == self.NAMES for names in by_trace.values()) assert 0 < len(by_trace) < 64 + @pytest.mark.parametrize( + ("rates", "failed"), + [({"arize_success_sampling_rate": "0.5"}, False), ({"arize_error_sampling_rate": "0.5"}, True)], + ids=["success-rate", "error-rate"], + ) + def test_two_processes_serving_one_trace_reach_the_same_verdict(self, rates: Mapping[str, str], failed: bool): + """Two pods behind a load balancer each serve one call of a trace the caller + continued with its ``traceparent``: the team's space gets both calls or neither, + and a rate of 0.5 over UUID-shaped trace ids keeps some traces and drops others.""" + exporters: Final = (InMemorySpanExporter(), InMemorySpanExporter()) + pods: Final = tuple(self._fan_out(exporter) for exporter in exporters) + destinations: Final = (arize_destination(**rates),) + trace_ids: Final = tuple(uuid.uuid5(uuid.NAMESPACE_URL, f"pod/{index}").int for index in range(32)) + + def run(provider: TracerProvider): + set_request_destinations(destinations) + tracer: Final = get_tracer(provider, "litellm") + for trace_id in trace_ids: + with tracer.start_as_current_span("POST /v1/chat/completions", context=caller_context(trace_id)): + with tracer.start_as_current_span("chat gpt-4") as span: + if failed: + span.set_status(Status(StatusCode.ERROR, "upstream 500")) + + for provider in pods: + in_fresh_context(run, provider) + + first, second = ( + {s.context.trace_id for s in exporter.get_finished_spans() if s.context is not None} + for exporter in exporters + ) + assert first == second + assert 0 < len(first) < len(trace_ids) + def test_in_additive_mode_the_operators_own_copy_is_not_sampled(self, monkeypatch): """The rates are the team's setting for the team's space; the operator's backbone keeps every span.""" @@ -1547,7 +1854,7 @@ class TestTenantSampling: assert {s.name for s in dest_exporter.get_finished_spans()} == self.NAMES - def test_two_views_of_one_exporter_each_draw_at_their_own_rate(self): + def test_two_views_of_one_exporter_each_answer_to_their_own_rate(self): """Two destinations to the same space with different rates share an exporter, not a verdict: the 1.0 view gets the tree once and the 0.0 view adds nothing.""" dest_exporter = InMemorySpanExporter() @@ -1582,7 +1889,7 @@ class TestTenantSampling: @pytest.mark.parametrize("bad", ["abc", "-0.1", "1.5", "nan"]) def test_an_unusable_rate_exports_rather_than_dropping(self, bad): dest_exporter = InMemorySpanExporter() - provider = self._fan_out(dest_exporter, draw=lambda: 0.99) + provider: Final = self._fan_out(dest_exporter, trace_id=DROPPED_AT_HALF) self._run(provider, (arize_destination(arize_success_sampling_rate=bad),)) diff --git a/tests/unit/integrations/otel/test_otel_v2_vendor_mappers.py b/tests/unit/integrations/otel/test_otel_v2_vendor_mappers.py index 7e112fcf6a4..98401fd17d3 100644 --- a/tests/unit/integrations/otel/test_otel_v2_vendor_mappers.py +++ b/tests/unit/integrations/otel/test_otel_v2_vendor_mappers.py @@ -802,3 +802,29 @@ def test_resolve_mappers_composition_layers_vocabularies(): def test_resolve_mappers_rejects_unknown_name(): with pytest.raises(ValueError, match="unknown mapper name 'nope'"): resolve_mappers(["genai", "nope"]) + + +def test_langfuse_mapper_leaves_the_trace_name_off_an_unnamed_generation() -> None: + attrs: Final = LangfuseMapper().map(_llm_call(call_type="acompletion", trace=TraceControls())) + + assert "langfuse.trace.name" not in attrs + + +def test_langfuse_mapper_carries_the_caller_trace_name_on_the_generation() -> None: + attrs: Final = LangfuseMapper().map(_llm_call(call_type="acompletion", trace=TraceControls(name="caller-trace"))) + + assert attrs["langfuse.trace.name"] == "caller-trace" + + +@pytest.mark.parametrize( + ("trace", "call_type", "expected"), + [ + (TraceControls(), "aresponses", {"langfuse.trace.name": "litellm-aresponses"}), + (TraceControls(name="caller-trace"), "aresponses", {"langfuse.trace.name": "caller-trace"}), + (TraceControls(), None, {}), + ], +) +def test_langfuse_root_trace_attributes_derive_the_name_only_when_the_caller_gave_none( + trace: TraceControls, call_type: str | None, expected: Mapping[str, object] +) -> None: + assert LangfuseMapper.trace_attributes(trace, call_type) == expected diff --git a/tests/unit/integrations/test_langfuse_otel.py b/tests/unit/integrations/test_langfuse_otel.py index c7608159515..5d37a145de6 100644 --- a/tests/unit/integrations/test_langfuse_otel.py +++ b/tests/unit/integrations/test_langfuse_otel.py @@ -1,17 +1,25 @@ import base64 import json import os +from collections.abc import Mapping, Sequence +from dataclasses import dataclass from datetime import datetime, timezone from typing import Final from unittest.mock import MagicMock, patch import pytest -from opentelemetry.sdk.trace import TracerProvider +from openai.types.responses import ResponseFunctionToolCall +from opentelemetry import trace +from opentelemetry.context import Context +from opentelemetry.sdk.trace import SpanLimits, TracerProvider +from opentelemetry.trace import Span +import litellm +from litellm.constants import REDACTED_BY_LITELLM from litellm.integrations.langfuse.langfuse_otel import LangfuseOtelLogger -from litellm.integrations.opentelemetry import OpenTelemetry, OpenTelemetryConfig +from litellm.integrations.opentelemetry import LITELLM_PROXY_REQUEST_SPAN_NAME, OpenTelemetry, OpenTelemetryConfig from litellm.types.llms.openai import ResponsesAPIResponse -from litellm.types.utils import StandardCallbackDynamicParams +from litellm.types.utils import Choices, ModelResponse, StandardCallbackDynamicParams class TestLangfuseOtelIntegration: @@ -138,7 +146,7 @@ class TestLangfuseOtelIntegration: ) # safe_set_attribute(span, key, value) → positional args - mock_safe_set_attribute.assert_called_once_with( + mock_safe_set_attribute.assert_any_call( mock_span, "langfuse.environment", test_env ) @@ -386,6 +394,7 @@ class TestLangfuseOtelIntegration: actual = { call.args[1]: json.loads(call.args[2]) for call in mock_safe_set_attribute.call_args_list + if call.args[1] in expect_output } assert ( @@ -449,6 +458,7 @@ class TestLangfuseOtelIntegration: actual = { call.args[1]: json.loads(call.args[2]) for call in mock_safe_set_attribute.call_args_list + if call.args[1] in expected } assert ( actual == expected @@ -879,7 +889,11 @@ class TestLangfuseOtelResponsesAPI: Summary( text="Let me analyze this problem step by step...", type="summary_text", - ) + ), + Summary( + text="Now checking the forecast data.", + type="summary_text", + ), ], ), ResponseOutputMessage( @@ -929,22 +943,31 @@ class TestLangfuseOtelResponsesAPI: # Verify output contains reasoning and message assert isinstance(output_data, list) - assert len(output_data) == 2 + assert len(output_data) == 3 - # Verify reasoning summary assert output_data[0]["role"] == "reasoning_summary" assert ( output_data[0]["content"] == "Let me analyze this problem step by step..." ) + assert output_data[1]["role"] == "reasoning_summary" + assert output_data[1]["content"] == "Now checking the forecast data." # Verify message - assert output_data[1]["role"] == "assistant" + assert output_data[2]["role"] == "assistant" assert ( - output_data[1]["content"] + output_data[2]["content"] == "The weather in San Francisco is sunny, 20°C." ) + trace_output_calls: Final = [ + call + for call in mock_safe_set_attribute.call_args_list + if call.args[1] == LangfuseSpanAttributes.TRACE_OUTPUT.value + ] + assert len(trace_output_calls) > 0, "trace.output should be set" + assert trace_output_calls[0].args[2] == output_json + def test_responses_api_with_function_calls(self): """Test Langfuse OTEL logger with Responses API function_call output.""" from litellm.types.integrations.langfuse_otel import LangfuseSpanAttributes @@ -1054,6 +1077,381 @@ class TestLangfuseOtelResponsesAPI: assert output_data[0]["arguments"] == {} +_TRACER: Final = TracerProvider().get_tracer("langfuse-otel-tests") +TRACE_FIELD_KEYS: Final = ( + "langfuse.trace.name", + "langfuse.trace.input", + "langfuse.trace.output", + "langfuse.trace.tags", +) +CALLER: Final = trace.SpanContext( + trace_id=0x4BF92F3577B34DA6A3CE929D0E0E4736, + span_id=0x00F067AA0BA902B7, + is_remote=True, + trace_flags=trace.TraceFlags(trace.TraceFlags.SAMPLED), +) +CHAT_KWARGS: Final = { + "call_type": "acompletion", + "messages": [{"role": "user", "content": "weather?"}], +} + + +def _chat_response(content: str) -> ModelResponse: + return ModelResponse( + id="chatcmpl-derived", + model="gpt-4o", + choices=[Choices(finish_reason="stop", message={"role": "assistant", "content": content})], + ) + + +def _stamped(span: Span, kwargs: Mapping[str, object], response_obj: object = None) -> Mapping[str, object]: + LangfuseOtelLogger._set_langfuse_specific_attributes(span, kwargs, response_obj) + span.end() + return dict(getattr(span, "attributes", None) or {}) + + +def _emitted(kwargs: Mapping[str, object], response_obj: object = None) -> Mapping[str, object]: + return _stamped(_TRACER.start_span("litellm_request"), kwargs, response_obj) + + +def _trace_fields(attributes: Mapping[str, object]) -> Mapping[str, object]: + return {key: attributes[key] for key in TRACE_FIELD_KEYS if key in attributes} + + +class _PresetCache: + @staticmethod + def get_preset_cache_key_from_kwargs(**kwargs: object) -> str: # kwargs-ok: mirrors Cache's signature + return "preset-abc" + + +class TestDerivedTraceFields: + def test_chat_call_derives_trace_name_input_and_output(self) -> None: + attributes: Final = _emitted({**CHAT_KWARGS, "litellm_params": {"metadata": {}}}, _chat_response("Sunny.")) + + assert attributes["langfuse.trace.name"] == "litellm-acompletion" + assert attributes["langfuse.trace.input"] == attributes["langfuse.observation.input"] + assert attributes["langfuse.trace.output"] == attributes["langfuse.observation.output"] + assert json.loads(str(attributes["langfuse.trace.input"])) == [{"role": "user", "content": "weather?"}] + assert json.loads(str(attributes["langfuse.trace.output"])) == {"role": "assistant", "content": "Sunny."} + + def test_missing_call_type_defaults_to_completion(self) -> None: + attributes: Final = _emitted( + {"messages": [{"role": "user", "content": "hi"}], "litellm_params": {"metadata": {}}} + ) + + assert attributes["langfuse.trace.name"] == "litellm-completion" + + def test_caller_trace_name_wins_and_is_the_only_name(self) -> None: + attributes: Final = _emitted( + {"call_type": "acompletion", "litellm_params": {"metadata": {"trace_name": "caller-trace"}}} + ) + + assert attributes["langfuse.trace.name"] == "caller-trace" + + def test_existing_trace_id_keeps_caller_tags_and_leaves_derived_trace_fields_off( + self, monkeypatch: pytest.MonkeyPatch + ) -> None: + monkeypatch.setattr(litellm, "langfuse_default_tags", ["cache_hit"]) + attributes: Final = _emitted( + { + **CHAT_KWARGS, + "cache_hit": True, + "litellm_params": {"metadata": {"existing_trace_id": "abc123", "tags": ["experiment"]}}, + "standard_logging_object": {"request_tags": ["injected"]}, + }, + _chat_response("hi"), + ) + + assert _trace_fields(attributes) == {"langfuse.trace.tags": json.dumps(["experiment"])} + assert attributes["langfuse.trace.existing_id"] == "abc123" + assert "langfuse.observation.input" in attributes + assert "langfuse.observation.output" in attributes + + @pytest.mark.parametrize( + ("mask_flags", "masked_trace_keys"), + [ + ({"mask_input": True}, frozenset({"langfuse.trace.input"})), + ({"mask_output": True}, frozenset({"langfuse.trace.output"})), + ({"mask_input": True, "mask_output": True}, frozenset({"langfuse.trace.input", "langfuse.trace.output"})), + ( + {"mask_input": "true", "mask_output": "TRUE"}, + frozenset({"langfuse.trace.input", "langfuse.trace.output"}), + ), + ({"mask_input": "false", "mask_output": "False"}, frozenset()), + ({"mask_input": False, "mask_output": None}, frozenset()), + ], + ) + def test_mask_flags_redact_the_derived_trace_io( + self, mask_flags: Mapping[str, object], masked_trace_keys: frozenset[str] + ) -> None: + attributes: Final = _emitted( + { + "call_type": "acompletion", + "messages": [{"role": "user", "content": "secret question"}], + "litellm_params": {"metadata": mask_flags}, + }, + _chat_response("secret answer"), + ) + observation_of: Final = { + "langfuse.trace.input": attributes["langfuse.observation.input"], + "langfuse.trace.output": attributes["langfuse.observation.output"], + } + + assert {key: attributes.get(key) for key in observation_of} == { + key: REDACTED_BY_LITELLM if key in masked_trace_keys else observation + for key, observation in observation_of.items() + } + + def test_responses_api_output_mirrors_observation_output_items(self) -> None: + response_obj: Final = ResponsesAPIResponse( + id="response-derived", + created_at=1625247700, + output=[ + ResponseFunctionToolCall( + id="fc-1", + type="function_call", + name="get_weather", + call_id="call-1", + arguments='{"city":"sf"}', + status="completed", + ) + ], + ) + attributes: Final = _emitted({"call_type": "aresponses", "litellm_params": {"metadata": {}}}, response_obj) + + assert attributes["langfuse.trace.name"] == "litellm-aresponses" + assert attributes["langfuse.trace.output"] == attributes["langfuse.observation.output"] + assert json.loads(str(attributes["langfuse.trace.output"])) == [ + { + "id": "fc-1", + "name": "get_weather", + "call_id": "call-1", + "type": "function_call", + "arguments": {"city": "sf"}, + } + ] + + def test_tags_merge_caller_request_and_default_tags_in_order(self, monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setattr(litellm, "langfuse_default_tags", ["cache_hit", "user_api_key_alias"]) + attributes: Final = _emitted( + { + "call_type": "acompletion", + "cache_hit": True, + "litellm_params": {"metadata": {"tags": ["a", "b"], "user_api_key_alias": "k1"}}, + "standard_logging_object": {"request_tags": ["b", "c"]}, + } + ) + + assert json.loads(str(attributes["langfuse.trace.tags"])) == [ + "a", + "b", + "c", + "cache_hit:True", + "user_api_key_alias:k1", + ] + + @pytest.mark.parametrize( + ("metadata", "expected"), + [ + ({}, ["cache_key:preset-abc"]), + ({"hidden_params": {"cache_key": "explicit-key"}}, ["cache_key:explicit-key"]), + ], + ids=["falls_back_to_the_preset_cache_key", "prefers_hidden_params_over_the_preset"], + ) + def test_cache_key_default_tag( + self, monkeypatch: pytest.MonkeyPatch, metadata: Mapping[str, object], expected: Sequence[str] + ) -> None: + monkeypatch.setattr(litellm, "langfuse_default_tags", ["cache_key"]) + monkeypatch.setattr(litellm, "cache", _PresetCache()) + attributes: Final = _emitted({"call_type": "acompletion", "litellm_params": {"metadata": metadata}}) + + assert json.loads(str(attributes["langfuse.trace.tags"])) == expected + + @pytest.mark.parametrize( + ("caller_tags", "expected"), + [ + ("single", ["single", "req"]), + ("h1, h2", ["h1", "h2", "req"]), + ('["j1", "j2"]', ["j1", "j2", "req"]), + (["x", 1], ["x", "1", "req"]), + ("", ["req"]), + ], + ) + def test_caller_tags_are_read_the_way_langfuse_reads_a_raw_tags_value( + self, caller_tags: object, expected: Sequence[str] + ) -> None: + attributes: Final = _emitted( + { + "call_type": "acompletion", + "litellm_params": {"metadata": {"tags": caller_tags}}, + "standard_logging_object": {"request_tags": ["req"]}, + } + ) + + assert json.loads(str(attributes["langfuse.trace.tags"])) == expected + + def test_no_tags_anywhere_leaves_trace_tags_unset(self) -> None: + attributes: Final = _emitted({"call_type": "acompletion", "litellm_params": {"metadata": {}}}) + + assert "langfuse.trace.tags" not in attributes + + def test_empty_string_role_is_omitted_from_output(self) -> None: + response_obj: Final = {"id": "chatcmpl-norole", "choices": [{"message": {"role": "", "content": "hi"}}]} + attributes: Final = _emitted({"call_type": "acompletion", "litellm_params": {"metadata": {}}}, response_obj) + + assert json.loads(str(attributes["langfuse.observation.output"])) == {"content": "hi"} + + def test_no_messages_leaves_trace_input_unset_but_emits_output(self) -> None: + attributes: Final = _emitted( + {"call_type": "acompletion", "litellm_params": {"metadata": {}}}, _chat_response("hi") + ) + + assert "langfuse.trace.input" not in attributes + assert "langfuse.observation.input" not in attributes + assert attributes["langfuse.trace.output"] == attributes["langfuse.observation.output"] + + +def _proxy_span(parent: Context | None = None) -> Span: + return _TRACER.start_span(LITELLM_PROXY_REQUEST_SPAN_NAME, context=parent) + + +def _child_of(parent: Span) -> Span: + return _TRACER.start_span("litellm_request", context=trace.set_span_in_context(parent)) + + +def _carrying(parent: Span, key: str = "metadata") -> Mapping[str, object]: + return {**CHAT_KWARGS, "litellm_params": {key: {"litellm_parent_otel_span": parent}}} + + +class TestDerivedTraceFieldsOnlyOnTracesLitellmStarts: + def test_a_span_under_an_inbound_traceparent_joins_the_caller_trace(self) -> None: + span: Final = _TRACER.start_span( + "litellm_request", context=trace.set_span_in_context(trace.NonRecordingSpan(CALLER)) + ) + + attributes: Final = _stamped(span, {**CHAT_KWARGS, "litellm_params": {"metadata": {}}}, _chat_response("ok")) + + assert _trace_fields(attributes) == {} + assert "langfuse.observation.input" in attributes and "langfuse.observation.output" in attributes + + def test_the_active_app_span_litellm_writes_onto_keeps_its_trace_fields(self) -> None: + with _TRACER.start_as_current_span("checkout") as app_span: + app_span.set_attribute("langfuse.trace.name", "checkout") + + attributes: Final = _stamped( + app_span, {**CHAT_KWARGS, "litellm_params": {"metadata": {}}}, _chat_response("ok") + ) + + assert _trace_fields(attributes) == {"langfuse.trace.name": "checkout"} + + def test_a_litellm_root_span_derives_while_an_app_span_is_current(self) -> None: + with _TRACER.start_as_current_span("checkout"): + span: Final = _TRACER.start_span("litellm_request", context=Context()) + + attributes: Final = _stamped( + span, {**CHAT_KWARGS, "litellm_params": {"metadata": {}}}, _chat_response("ok") + ) + + assert attributes["langfuse.trace.name"] == "litellm-acompletion" + + def test_a_span_under_a_caller_provided_parent_span_joins_the_caller_trace(self) -> None: + caller_span: Final = _TRACER.start_span("caller-root") + + attributes: Final = _stamped(_child_of(caller_span), _carrying(caller_span), _chat_response("ok")) + + assert _trace_fields(attributes) == {} + + @pytest.mark.parametrize("key", ["metadata", "litellm_metadata"]) + def test_a_span_under_litellms_own_unparented_proxy_span_derives(self, key: str) -> None: + proxy_span: Final = _proxy_span() + + attributes: Final = _stamped(_child_of(proxy_span), _carrying(proxy_span, key), _chat_response("ok")) + + assert attributes["langfuse.trace.name"] == "litellm-acompletion" + assert attributes["langfuse.trace.input"] == attributes["langfuse.observation.input"] + assert attributes["langfuse.trace.output"] == attributes["langfuse.observation.output"] + + def test_a_span_under_a_proxy_span_with_an_inbound_traceparent_joins_the_caller_trace(self) -> None: + proxy_span: Final = _proxy_span(trace.set_span_in_context(trace.NonRecordingSpan(CALLER))) + + attributes: Final = _stamped(_child_of(proxy_span), _carrying(proxy_span), _chat_response("ok")) + + assert _trace_fields(attributes) == {} + + def test_a_span_whose_parent_is_not_the_carried_proxy_span_joins_that_parent_trace(self) -> None: + other_parent: Final = _TRACER.start_span("caller-root") + + attributes: Final = _stamped(_child_of(other_parent), _carrying(_proxy_span()), _chat_response("ok")) + + assert _trace_fields(attributes) == {} + + def test_an_inbound_traceparent_still_carries_the_caller_trace_name_and_tags(self) -> None: + span: Final = _TRACER.start_span( + "litellm_request", context=trace.set_span_in_context(trace.NonRecordingSpan(CALLER)) + ) + + attributes: Final = _stamped( + span, + {**CHAT_KWARGS, "litellm_params": {"metadata": {"trace_name": "caller-trace", "tags": ["caller"]}}}, + _chat_response("ok"), + ) + + assert _trace_fields(attributes) == { + "langfuse.trace.name": "caller-trace", + "langfuse.trace.tags": json.dumps(["caller"]), + } + + +ERROR_KEYS: Final = ( + "error.code", + "http.response.status_code", + "error.type", + "error.message", + "error.llm_provider", + "error.stack_trace", +) +SPAN_ATTRIBUTE_LIMIT: Final = 128 +_LIMITED_TRACER: Final = TracerProvider(span_limits=SpanLimits(max_span_attributes=SPAN_ATTRIBUTE_LIMIT)).get_tracer( + "langfuse-otel-limit-tests" +) + + +@dataclass(frozen=True, slots=True) +class ExportedSpan: + keys: frozenset[str] + dropped: int + + +def _exported_full_span(filler: int, *, joins_caller: bool, failed: bool) -> ExportedSpan: + span: Final = _LIMITED_TRACER.start_span( + "litellm_request", + context=trace.set_span_in_context(trace.NonRecordingSpan(CALLER)) if joins_caller else Context(), + ) + span.set_attributes({f"main.{index}": index for index in range(filler)}) + LangfuseOtelLogger._set_langfuse_specific_attributes( + span, {**CHAT_KWARGS, "litellm_params": {"metadata": {}}}, _chat_response("ok") + ) + span.set_attributes(dict.fromkeys(ERROR_KEYS, "scripted failure") if failed else {}) + span.end() + return ExportedSpan(frozenset(getattr(span, "attributes", None) or {}), getattr(span, "dropped_attributes", 0)) + + +class TestDerivedTraceFieldsAtTheSpanAttributeLimit: + @pytest.mark.parametrize("failed", [False, True]) + @pytest.mark.parametrize("filler", range(SPAN_ATTRIBUTE_LIMIT - 30, SPAN_ATTRIBUTE_LIMIT + 1)) + def test_trace_fields_never_evict_or_drop_another_attribute(self, filler: int, failed: bool) -> None: + derived: Final = _exported_full_span(filler, joins_caller=False, failed=failed) + without_trace_fields: Final = _exported_full_span(filler, joins_caller=True, failed=failed) + + assert without_trace_fields.keys <= derived.keys + assert derived.dropped == without_trace_fields.dropped + + def test_a_span_with_room_to_spare_carries_every_trace_field(self) -> None: + derived: Final = _exported_full_span(SPAN_ATTRIBUTE_LIMIT - 30, joins_caller=False, failed=False) + + assert {"langfuse.trace.name", "langfuse.trace.input", "langfuse.trace.output"} <= derived.keys + + LANGFUSE_ENV_ONLY: Final = { key: value for key, value in os.environ.items() diff --git a/tests/unit/integrations/test_prometheus_invalid_key_filtering.py b/tests/unit/integrations/test_prometheus_invalid_key_filtering.py index 9e8348e860a..453fd28636d 100644 --- a/tests/unit/integrations/test_prometheus_invalid_key_filtering.py +++ b/tests/unit/integrations/test_prometheus_invalid_key_filtering.py @@ -2,19 +2,63 @@ Unit tests for Prometheus invalid API key request filtering. Tests the 401 detection helpers, that LLM-level metrics skip invalid API key -requests, and that the proxy-level failed request counter still records them. +requests rejected at the proxy gate while recording a provider's 401, and that +the proxy-level failed request counter still records them. """ +from collections.abc import Iterator +from datetime import datetime +from typing import Final from unittest.mock import Mock, patch import pytest from fastapi import HTTPException from prometheus_client import REGISTRY +from prometheus_client.samples import Sample +import litellm +from litellm.constants import LITELLM_LOGGING_NO_UPSTREAM_LLM_CALL from litellm.integrations.prometheus import PrometheusLogger +from litellm.llms.github_copilot.per_user_auth import GithubCopilotUserSession from litellm.proxy._types import ProxyErrorTypes, ProxyException, UserAPIKeyAuth +PROVIDER_CREDENTIAL_FIELDS = [ + "aws_access_key_id", + "aws_secret_access_key", + "aws_session_token", + "aws_web_identity_token", + "azure_ad_token", + "azure_password", + "azure_scope", + "azure_username", + "client_id", + "client_secret", + "gigachat_access_token", + "oci_fingerprint", + "oci_key", + "oci_key_file", + "oci_tenancy", + "oci_user", + "tenant_id", + "token", + "user_config", + "vertex_ai_credentials", + "vertex_credentials", + "watsonx_credentials", + "wx_credentials", + "zen_api_key", +] +PROVIDER_ENDPOINT_FIELDS = [ + "aws_bedrock_runtime_endpoint", + "aws_sts_endpoint", + "deployment_url", + "s3_endpoint_url", + "sagemaker_base_url", +] +CALLED_THE_PROVIDER: Final = {"api_call_start_time": datetime(2026, 10, 19, 12, 0, 0)} + + @pytest.fixture(scope="function") def prometheus_logger(): """Create a PrometheusLogger instance for testing.""" @@ -48,18 +92,13 @@ class TestExtractStatusCode: (ExceptionWithStatusCode, 401, 401), ], ) - def test_extract_from_exception( - self, prometheus_logger, exception_class, code_value, expected - ): + def test_extract_from_exception(self, prometheus_logger, exception_class, code_value, expected): exception = exception_class(code_value) assert prometheus_logger._extract_status_code(exception=exception) == expected def test_extract_from_kwargs(self, prometheus_logger): exception = ExceptionWithCode("401") - assert ( - prometheus_logger._extract_status_code(kwargs={"exception": exception}) - == 401 - ) + assert prometheus_logger._extract_status_code(kwargs={"exception": exception}) == 401 def test_extract_from_enum_values(self, prometheus_logger): enum_values = Mock(status_code="401") @@ -79,50 +118,271 @@ class TestInvalidAPIKeyDetection: ], ) def test_status_code_detection(self, prometheus_logger, status_code, expected): - assert ( - prometheus_logger._is_invalid_api_key_request(status_code=status_code) - == expected - ) + assert prometheus_logger._is_invalid_api_key_request(status_code=status_code) == expected def test_auth_error_message_detection(self, prometheus_logger): exception = AssertionError( "LiteLLM Virtual Key expected. Received=invalid-key-12345, expected to start with 'sk-'." ) - assert ( - prometheus_logger._is_invalid_api_key_request( - status_code=None, exception=exception - ) - is True - ) + assert prometheus_logger._is_invalid_api_key_request(status_code=None, exception=exception) is True def test_non_auth_exception_not_detected(self, prometheus_logger): exception = ValueError("Some other error") - assert ( - prometheus_logger._is_invalid_api_key_request( - status_code=None, exception=exception - ) - is False - ) + assert prometheus_logger._is_invalid_api_key_request(status_code=None, exception=exception) is False class TestSkipMetricsValidation: """Test high-level validation method that orchestrates detection and extraction.""" - def test_skip_for_401_exception(self, prometheus_logger): - """Test full flow: extraction -> detection -> skip decision.""" - exception = ExceptionWithCode("401") - assert ( - prometheus_logger._should_skip_metrics_for_invalid_key(exception=exception) - is True - ) + @pytest.mark.parametrize( + "exception,proxy_gate,expected", + [ + (ExceptionWithCode("401"), True, True), + (AssertionError("expected to start with 'sk-'"), True, True), + (ExceptionWithStatusCode(429), True, False), + (ExceptionWithCode("401"), False, True), + (AssertionError("expected to start with 'sk-'"), False, True), + ( + litellm.AuthenticationError( + message="Incorrect API key provided: sk-rotat*****", + llm_provider="openai", + model="gpt-4o-mini", + ), + False, + False, + ), + ( + litellm.AuthenticationError( + message="API key not valid. Please pass a valid API key.", + llm_provider="gemini", + model="gemini-2.5-flash", + ), + False, + False, + ), + ( + litellm.AuthenticationError( + message="Authentication Error, Invalid proxy server token passed.", + llm_provider="openai", + model="gpt-4o-mini", + ), + True, + True, + ), + ( + litellm.CallerCredentialAuthenticationError( + message="GitHub Copilot connection is missing for this user", + llm_provider="github_copilot", + model="gpt-4o", + ), + False, + True, + ), + ( + HTTPException(status_code=401, detail="caller did not present a token"), + False, + True, + ), + ( + litellm.BadRequestError( + message="API key not valid. Please pass a valid API key.", + llm_provider="gemini", + model="gemini-2.5-flash", + ), + False, + False, + ), + ], + ids=[ + "proxy-gate-401", + "proxy-gate-auth-message", + "proxy-gate-429", + "unmarked-proxy-401", + "unmarked-auth-message", + "provider-401", + "provider-auth-message", + "proxy-gate-litellm-auth-error", + "caller-credential-401", + "unmarked-http-exception-401", + "provider-400-auth-message", + ], + ) + def test_skip_except_for_provider_errors_the_proxy_did_not_raise( + self, prometheus_logger, exception, proxy_gate, expected + ): + kwargs: Final[dict[str, object]] = {"exception": exception, **CALLED_THE_PROVIDER} + if proxy_gate: + kwargs[LITELLM_LOGGING_NO_UPSTREAM_LLM_CALL] = True + assert prometheus_logger._should_skip_metrics_for_invalid_key(kwargs=kwargs) is expected - def test_skip_for_auth_error_message(self, prometheus_logger): - """Test full flow: exception message -> detection -> skip decision.""" - exception = AssertionError("expected to start with 'sk-'") - assert ( - prometheus_logger._should_skip_metrics_for_invalid_key(exception=exception) - is True + @pytest.mark.parametrize( + "logged_call,expected", + [ + ({"litellm_params": {"proxy_server_request": {"caller_credential_fields": ("api_key",)}}}, True), + ( + { + "litellm_params": { + "github_copilot_user_session": GithubCopilotUserSession( + token="caller-session-token", api_base="https://api.githubcopilot.com" + ) + } + }, + True, + ), + ({"standard_logging_object": {"metadata": {"used_client_oauth_token": True}}}, True), + ({"litellm_params": {"proxy_server_request": {"caller_credential_fields": ("headers",)}}}, True), + ( + { + "litellm_params": { + "proxy_server_request": {"caller_credential_fields": ("provider_specific_header",)} + } + }, + True, + ), + ({"litellm_params": {"proxy_server_request": {"caller_credential_fields": ()}}}, False), + ({"litellm_params": {"proxy_server_request": {"caller_credential_fields": "api_key"}}}, False), + ({"standard_logging_object": {"metadata": {"used_client_oauth_token": False}}}, False), + ({"litellm_params": {"proxy_server_request": {"body": {"azure_ad_token": "caller-token"}}}}, True), + ( + { + "litellm_params": { + "proxy_server_request": {"body": {"extra_body": {"azure_ad_token": "caller-token"}}} + } + }, + True, + ), + ( + { + "litellm_params": { + "azure_ad_token": "deployment-token", + "proxy_server_request": {"body": {"model": "azure-deployment"}}, + } + }, + False, + ), + ({"litellm_params": {"proxy_server_request": {"body": {"extra_body": "azure_ad_token"}}}}, False), + ( + { + "litellm_params": { + "proxy_server_request": {"body": {"litellm_credential_name": "caller-credential"}} + } + }, + True, + ), + ( + { + "litellm_params": { + "litellm_credential_name": "deployment-credential", + "proxy_server_request": {"body": {"model": "openai-deployment"}}, + } + }, + False, + ), + ({"litellm_params": {"proxy_server_request": {"caller_credential_fields": ("extra_headers",)}}}, True), + ({"litellm_params": {"proxy_server_request": {"caller_credential_fields": ("organization",)}}}, True), + ( + { + "litellm_params": { + "proxy_server_request": {"credential_fields": ("headers",), "caller_credential_fields": ()} + } + }, + False, + ), + ( + { + "litellm_params": { + "proxy_server_request": {"body": {"extra_headers": {"Authorization": "Bearer sk-caller"}}} + } + }, + False, + ), + ], + ids=[ + "caller-supplied-api-key", + "caller-copilot-session", + "caller-anthropic-oauth-token", + "caller-supplied-headers", + "caller-supplied-provider-specific-header", + "no-caller-credential-fields", + "malformed-credential-fields", + "deployment-anthropic-key", + "caller-supplied-azure-ad-token", + "caller-supplied-azure-ad-token-in-extra-body", + "deployment-azure-ad-token", + "malformed-extra-body", + "caller-named-credential", + "deployment-named-credential", + "caller-supplied-extra-headers", + "caller-supplied-organization", + "headers-that-cannot-change-provider-auth", + "extra-headers-not-stamped-by-the-proxy", + ], + ) + def test_skip_a_provider_401_on_a_credential_the_caller_owns(self, prometheus_logger, logged_call, expected): + exception: Final = litellm.AuthenticationError( + message="Incorrect API key provided: sk-calle*****", + llm_provider="openai", + model="gpt-4o-mini", ) + kwargs: Final = {"exception": exception, **CALLED_THE_PROVIDER, **logged_call} + assert prometheus_logger._should_skip_metrics_for_invalid_key(kwargs=kwargs) is expected + + @pytest.mark.parametrize( + "logged_call,expected", + [(CALLED_THE_PROVIDER, False), ({}, True), ({"api_call_start_time": None}, True)], + ids=["provider-401", "401-before-the-provider-call", "blank-provider-call-start"], + ) + def test_skip_a_401_raised_before_the_provider_was_called(self, prometheus_logger, logged_call, expected): + exception: Final = litellm.AuthenticationError( + message="Missing Anthropic API Key - A call is being made to anthropic but no key is set", + llm_provider="anthropic", + model="claude-haiku-4-5", + ) + kwargs: Final = {"exception": exception, **logged_call} + assert prometheus_logger._should_skip_metrics_for_invalid_key(kwargs=kwargs) is expected + + @pytest.mark.parametrize("field", PROVIDER_CREDENTIAL_FIELDS + PROVIDER_ENDPOINT_FIELDS) + @pytest.mark.parametrize("inside_extra_body", [False, True], ids=["body", "extra-body"]) + def test_skip_a_provider_401_on_a_provider_credential_field_the_caller_sent( + self, prometheus_logger, field, inside_extra_body + ): + sent: Final = {field: "caller-credential"} + body: Final = {"model": "shared-deployment", **({"extra_body": sent} if inside_extra_body else sent)} + kwargs: Final = { + "exception": litellm.AuthenticationError(message="Unauthorized", llm_provider="azure", model="gpt-4o"), + "litellm_params": {"proxy_server_request": {"body": body}}, + **CALLED_THE_PROVIDER, + } + assert prometheus_logger._should_skip_metrics_for_invalid_key(kwargs=kwargs) is True + + @pytest.mark.parametrize("field", PROVIDER_CREDENTIAL_FIELDS + PROVIDER_ENDPOINT_FIELDS) + def test_count_a_provider_401_on_a_provider_credential_field_the_deployment_owns(self, prometheus_logger, field): + kwargs: Final = { + "exception": litellm.AuthenticationError(message="Unauthorized", llm_provider="azure", model="gpt-4o"), + **CALLED_THE_PROVIDER, + "litellm_params": { + field: "deployment-credential", + "proxy_server_request": {"body": {"model": "shared-deployment"}}, + }, + } + assert prometheus_logger._should_skip_metrics_for_invalid_key(kwargs=kwargs) is False + + @pytest.mark.parametrize( + "token_exchange_endpoint,expected", + [("https://login.example.com/oauth2/v2.0/token", True), ("", False), (None, False)], + ids=["token-exchange-deployment", "blank-endpoint", "no-endpoint"], + ) + def test_skip_a_provider_401_on_a_token_exchange_deployment( + self, prometheus_logger, token_exchange_endpoint, expected + ): + kwargs: Final = { + "exception": litellm.AuthenticationError( + message="Unauthorized", llm_provider="microsoft_365_copilot", model="copilot" + ), + "litellm_params": {"token_exchange_endpoint": token_exchange_endpoint, "client_secret": "deployment"}, + **CALLED_THE_PROVIDER, + } + assert prometheus_logger._should_skip_metrics_for_invalid_key(kwargs=kwargs) is expected def test_no_skip_for_valid_request(self, prometheus_logger): assert prometheus_logger._should_skip_metrics_for_invalid_key() is False @@ -147,19 +407,13 @@ class TestAsyncHooks: ), ], ) - async def test_post_call_failure_hook_counts_401_without_key_hash( - self, prometheus_logger, exception - ): + async def test_post_call_failure_hook_counts_401_without_key_hash(self, prometheus_logger, exception): unauthenticated = UserAPIKeyAuth(request_route="/v1/chat/completions") unauthenticated.api_key = "notakeyatall" with ( - patch.object( - prometheus_logger, "litellm_proxy_failed_requests_metric" - ) as mock_failed, - patch.object( - prometheus_logger, "litellm_proxy_total_requests_metric" - ) as mock_total, + patch.object(prometheus_logger, "litellm_proxy_failed_requests_metric") as mock_failed, + patch.object(prometheus_logger, "litellm_proxy_total_requests_metric") as mock_total, ): await prometheus_logger.async_post_call_failure_hook( request_data={"model": "test-model"}, @@ -176,9 +430,7 @@ class TestAsyncHooks: mock_total.labels.return_value.inc.assert_called_once() @pytest.mark.asyncio - async def test_post_call_failure_hook_keeps_resolved_identity_labels_for_401( - self, prometheus_logger - ): + async def test_post_call_failure_hook_keeps_resolved_identity_labels_for_401(self, prometheus_logger): expired_key = UserAPIKeyAuth( api_key="sk-expired", key_alias="expired-alias", @@ -191,9 +443,7 @@ class TestAsyncHooks: code=401, ) - with patch.object( - prometheus_logger, "litellm_proxy_failed_requests_metric" - ) as mock_failed: + with patch.object(prometheus_logger, "litellm_proxy_failed_requests_metric") as mock_failed: await prometheus_logger.async_post_call_failure_hook( request_data={"model": "test-model"}, original_exception=exception, @@ -207,7 +457,7 @@ class TestAsyncHooks: assert failed_labels["team"] == "team-1" @pytest.mark.asyncio - async def test_log_failure_event_skips_401(self, prometheus_logger): + async def test_log_failure_event_skips_401_rejected_at_the_proxy_gate(self, prometheus_logger): exception = ExceptionWithCode("401") kwargs = { "model": "test-model", @@ -220,20 +470,91 @@ class TestAsyncHooks: }, "exception": exception, "litellm_params": {}, + LITELLM_LOGGING_NO_UPSTREAM_LLM_CALL: True, } with ( - patch.object( - prometheus_logger, "litellm_llm_api_failed_requests_metric" - ) as mock_failed, - patch.object( - prometheus_logger, "set_llm_deployment_failure_metrics" - ) as mock_deployment, + patch.object(prometheus_logger, "litellm_llm_api_failed_requests_metric") as mock_failed, + patch.object(prometheus_logger, "set_llm_deployment_failure_metrics") as mock_deployment, ): - await prometheus_logger.async_log_failure_event( kwargs=kwargs, response_obj=None, start_time=None, end_time=None ) mock_failed.labels.assert_not_called() mock_deployment.assert_not_called() + + +def _provider_auth_failure_kwargs() -> dict[str, object]: + exception: Final = litellm.AuthenticationError( + message="Incorrect API key provided: sk-rotat*****", + llm_provider="openai", + model="gpt-4o-mini", + ) + return { + "model": "gpt-4o-mini", + "standard_logging_object": { + "metadata": { + "user_api_key_hash": "test-key", + "user_api_key_alias": "test-alias", + "user_api_key_user_id": "test-user", + "user_api_key_team_id": "test-team", + "user_api_key_team_alias": "test-team-alias", + }, + "model_group": "rotated-credential", + "model_id": "deployment-1", + "api_base": "https://api.openai.com/v1", + "custom_llm_provider": "openai", + }, + "exception": exception, + "litellm_params": {"custom_llm_provider": "openai", "metadata": {}}, + **CALLED_THE_PROVIDER, + } + + +def _metric_values(name: str, model_id: str) -> list[float]: + return [ + sample.value + for sample in _registry_samples() + if sample.name == name and sample.labels.get("model_id") == model_id + ] + + +def _registry_samples() -> Iterator[Sample]: + for metric in REGISTRY.collect(): + yield from metric.samples + + +class TestProviderAuthFailures: + """A 401 raised by the provider is an upstream failure and is recorded.""" + + @pytest.mark.asyncio + async def test_log_failure_event_records_a_provider_401(self, prometheus_logger): + await prometheus_logger.async_log_failure_event( + kwargs=_provider_auth_failure_kwargs(), + response_obj=None, + start_time=None, + end_time=None, + ) + + assert _metric_values("litellm_llm_api_failed_requests_metric_total", "deployment-1") == [1.0] + assert _metric_values("litellm_deployment_failure_responses_total", "deployment-1") == [1.0] + assert _metric_values("litellm_deployment_state", "deployment-1") == [1.0] + + def test_deployment_failure_metrics_record_a_provider_401(self, prometheus_logger): + prometheus_logger.set_llm_deployment_failure_metrics(_provider_auth_failure_kwargs()) + + failures: Final = [ + sample for sample in _registry_samples() if sample.name == "litellm_deployment_failure_responses_total" + ] + assert [ + ( + sample.labels["model_id"], + sample.labels["exception_status"], + sample.labels["api_provider"], + sample.value, + ) + for sample in failures + ] == [("deployment-1", "401", "openai", 1.0)] + assert _metric_values("litellm_deployment_total_requests_total", "deployment-1") == [1.0] + assert _metric_values("litellm_deployment_state", "deployment-1") == [1.0] diff --git a/tests/unit/integrations/websearch_interception/test_websearch_agentic_loop_cap.py b/tests/unit/integrations/websearch_interception/test_websearch_agentic_loop_cap.py index 64c49f03732..351ca9beb4d 100644 --- a/tests/unit/integrations/websearch_interception/test_websearch_agentic_loop_cap.py +++ b/tests/unit/integrations/websearch_interception/test_websearch_agentic_loop_cap.py @@ -25,7 +25,7 @@ from litellm.integrations.websearch_interception.handler import ( ) from litellm.integrations.websearch_interception.tools import get_litellm_web_search_tool from litellm.litellm_core_utils.agentic_loop_settings import DEFAULT_MAX_AGENTIC_LOOPS -from litellm.llms.anthropic.pass_through.messages.fake_stream_iterator import ( +from litellm.llms.anthropic.messages.native.fake_stream_iterator import ( FakeAnthropicMessagesStreamIterator, ) from litellm.llms.base_llm.search.transformation import SearchResponse, SearchResult diff --git a/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py b/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py index 4fbc78c2f4d..fdc3771e903 100644 --- a/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py +++ b/tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py @@ -238,7 +238,7 @@ class TestShortCircuitEntryPoint: @pytest.mark.asyncio async def test_returns_none_when_no_callbacks(self): """No callbacks configured → returns None""" - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( _try_websearch_short_circuit, ) @@ -255,7 +255,7 @@ class TestShortCircuitEntryPoint: @pytest.mark.asyncio async def test_returns_dict_when_not_streaming(self): """Non-streaming short-circuit → returns dict""" - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( _try_websearch_short_circuit, ) @@ -280,10 +280,10 @@ class TestShortCircuitEntryPoint: @pytest.mark.asyncio async def test_returns_stream_iterator_when_streaming(self): """Streaming short-circuit → returns FakeAnthropicMessagesStreamIterator""" - from litellm.llms.anthropic.pass_through.messages.fake_stream_iterator import ( + from litellm.llms.anthropic.messages.native.fake_stream_iterator import ( FakeAnthropicMessagesStreamIterator, ) - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( _try_websearch_short_circuit, ) @@ -322,7 +322,7 @@ class TestShortCircuitEntryPoint: """Non-WebSearchInterceptionLogger callbacks are ignored""" from unittest.mock import MagicMock - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( _try_websearch_short_circuit, ) @@ -345,10 +345,10 @@ class TestShortCircuitEntryPoint: loop. The short-circuit must use the ORIGINAL stream value so streaming callers get SSE events instead of a plain dict. """ - from litellm.llms.anthropic.pass_through.messages.fake_stream_iterator import ( + from litellm.llms.anthropic.messages.native.fake_stream_iterator import ( FakeAnthropicMessagesStreamIterator, ) - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( _try_websearch_short_circuit, ) @@ -378,7 +378,7 @@ class TestShortCircuitEntryPoint: still fire the short-circuit when the caller propagates the derived provider. """ - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( _try_websearch_short_circuit, ) @@ -410,7 +410,7 @@ class TestShortCircuitSafeguardResults: NO_TOOL_USES_AVAILABLE = [{"type": "dangerous_tool_use", "status": {"type": "available", "tool_uses": {}}}] async def _short_circuit(self, *, stream: bool, kwargs: dict | None): - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( _try_websearch_short_circuit, ) diff --git a/tests/unit/integrations/websearch_interception/test_websearch_streaming_wrap.py b/tests/unit/integrations/websearch_interception/test_websearch_streaming_wrap.py index f4a46efaa1d..1401f260427 100644 --- a/tests/unit/integrations/websearch_interception/test_websearch_streaming_wrap.py +++ b/tests/unit/integrations/websearch_interception/test_websearch_streaming_wrap.py @@ -13,7 +13,7 @@ import pytest from litellm.integrations.custom_logger import CustomLogger from litellm.llms.custom_httpx.llm_http_handler import BaseLLMHTTPHandler -from litellm.llms.anthropic.pass_through.messages.fake_stream_iterator import ( +from litellm.llms.anthropic.messages.native.fake_stream_iterator import ( FakeAnthropicMessagesStreamIterator, ) from litellm.types.integrations.custom_logger import AgenticLoopPlan diff --git a/tests/unit/litellm_core_utils/attribute_forwarder.py b/tests/unit/litellm_core_utils/attribute_forwarder.py new file mode 100644 index 00000000000..3056057fc97 --- /dev/null +++ b/tests/unit/litellm_core_utils/attribute_forwarder.py @@ -0,0 +1,6 @@ +class AttributeForwarder: + def __init__(self, target: object) -> None: + self._target = target + + def __getattr__(self, name: str) -> object: + return getattr(self._target, name) diff --git a/tests/unit/litellm_core_utils/llm_cost_calc/test_guardrail_cost.py b/tests/unit/litellm_core_utils/llm_cost_calc/test_guardrail_cost.py index aa2fc0b9a45..949f55b8a82 100644 --- a/tests/unit/litellm_core_utils/llm_cost_calc/test_guardrail_cost.py +++ b/tests/unit/litellm_core_utils/llm_cost_calc/test_guardrail_cost.py @@ -1,7 +1,11 @@ +import json +from typing import Final import pytest +from pydantic import JsonValue import litellm +from litellm.litellm_core_utils.llm_cost_calc import guardrail_cost from litellm.litellm_core_utils.llm_cost_calc.guardrail_cost import ( bedrock_guardrail_cost, bedrock_guardrail_cost_by_unit, @@ -230,3 +234,118 @@ def test_guardrail_information_cost_skips_malformed_entry_keeps_siblings(): ] assert guardrail_information_cost(entries) == pytest.approx(0.0003) assert guardrail_information_cost({"guardrail_cost": 0.5, "guardrail_cost_in_spend": "maybe"}) == 0.0 + + +_TRACE_USAGE_IN: Final = { + "topicPolicyUnits": 1, + "contentPolicyUnits": 1, + "wordPolicyUnits": 1, + "sensitiveInformationPolicyUnits": 0, + "contextualGroundingPolicyUnits": 0, + "automatedReasoningPolicies": 0, +} +_TRACE_USAGE_OUT: Final = { + **_TRACE_USAGE_IN, + "topicPolicyUnits": 2, + "contentPolicyUnits": 2, + "sensitiveInformationPolicyUnits": 2, +} +_TRACE_PRICING: Final = { + "bedrock/guardrails": { + "litellm_provider": "bedrock", + "mode": "guardrails", + "guardrail_cost_per_unit": { + "topicPolicyUnits": 0.00015, + "contentPolicyUnits": 0.00015, + "wordPolicyUnits": 0.0, + "sensitiveInformationPolicyUnits": 0.0001, + }, + } +} + + +def _converse_trace(action: str = "NONE") -> dict[str, JsonValue]: + return { + "guardrail": { + "inputAssessment": {"gid": {"invocationMetrics": {"usage": _TRACE_USAGE_IN}}}, + "outputAssessments": { + "gid": [ + { + "topicPolicy": {"topics": [{"name": "t", "type": "DENY", "action": action}]}, + "invocationMetrics": {"usage": _TRACE_USAGE_OUT}, + } + ] + }, + } + } + + +def _invoke_trace() -> dict[str, JsonValue]: + return { + "guardrail": { + "input": {"gid": {"invocationMetrics": {"usage": _TRACE_USAGE_IN}}}, + "outputs": [{"gid": {"invocationMetrics": {"usage": _TRACE_USAGE_OUT}}}], + } + } + + +@pytest.mark.parametrize("trace", [_converse_trace(), _invoke_trace()], ids=["converse", "invoke"]) +def test_native_trace_sums_every_assessment_and_prices_it_like_the_proxy_guardrail(monkeypatch, trace) -> None: + monkeypatch.setattr(litellm, "model_cost", _TRACE_PRICING) + entry: Final = guardrail_cost.native_bedrock_guardrail_information( + trace, aws_region_name=None, guardrail_identifier=None + ) + assert entry is not None + assert entry["guardrail_usage"] == { + "topicPolicyUnits": 3, + "contentPolicyUnits": 3, + "wordPolicyUnits": 2, + "sensitiveInformationPolicyUnits": 2, + "contextualGroundingPolicyUnits": 0, + } + assert entry["guardrail_cost"] == pytest.approx(3 * 0.00015 + 3 * 0.00015 + 2 * 0.0001) + assert entry["guardrail_cost_by_unit"]["contextualGroundingPolicyUnits"] is None + assert entry["guardrail_name"] == "gid" + assert entry["guardrail_provider"] == "bedrock" + assert entry["guardrail_status"] == "success" + assert guardrail_cost.guardrail_information_cost([entry]) == pytest.approx(entry["guardrail_cost"]) + + +def test_native_trace_marks_a_blocked_assessment_intervened_and_prefers_the_configured_identifier(monkeypatch) -> None: + monkeypatch.setattr(litellm, "model_cost", _TRACE_PRICING) + entry: Final = guardrail_cost.native_bedrock_guardrail_information( + _converse_trace("BLOCKED"), aws_region_name="us-east-1", guardrail_identifier="configured-id" + ) + assert entry is not None + assert entry["guardrail_status"] == "guardrail_intervened" + assert entry["guardrail_name"] == "configured-id" + + +def test_native_trace_without_usage_is_not_billed(monkeypatch) -> None: + monkeypatch.setattr(litellm, "model_cost", _TRACE_PRICING) + unpriced: Final = {"guardrail": {"inputAssessment": {"gid": {"topicPolicy": {"topics": []}}}}} + assert guardrail_cost.native_bedrock_guardrail_information(unpriced, None, None) is None + assert guardrail_cost.bedrock_guardrail_trace({"usage": {}}) is None + + +def test_with_guardrail_entry_records_the_same_trace_once() -> None: + entry: Final = {"guardrail_name": "gid", "guardrail_cost": 0.001} + metadata: dict = {"standard_logging_guardrail_information": {"guardrail_name": "hook"}} + guardrail_cost.with_guardrail_entry(metadata, entry) # pyright: ignore[reportArgumentType] # partial entry + guardrail_cost.with_guardrail_entry(metadata, entry) # pyright: ignore[reportArgumentType] # partial entry + assert metadata["standard_logging_guardrail_information"] == [{"guardrail_name": "hook"}, entry] + + +def test_native_trace_entry_redacts_the_pii_matches_before_they_reach_spend_logs(monkeypatch) -> None: + monkeypatch.setattr(litellm, "model_cost", _TRACE_PRICING) + trace: Final = _converse_trace() + trace["guardrail"]["inputAssessment"]["gid"]["sensitiveInformationPolicy"] = { + "piiEntities": [{"type": "US_SSN", "match": "123-45-6789", "action": "ANONYMIZED"}] + } + entry: Final = guardrail_cost.native_bedrock_guardrail_information( + trace, aws_region_name=None, guardrail_identifier=None + ) + assert entry is not None + assert entry["guardrail_status"] == "guardrail_intervened" + assert "123-45-6789" not in json.dumps(entry["guardrail_response"]) + assert entry["guardrail_usage"]["sensitiveInformationPolicyUnits"] == 2 diff --git a/tests/unit/litellm_core_utils/llm_cost_calc/test_llm_cost_calc_utils.py b/tests/unit/litellm_core_utils/llm_cost_calc/test_llm_cost_calc_utils.py index c99147d2e63..21b527250c4 100644 --- a/tests/unit/litellm_core_utils/llm_cost_calc/test_llm_cost_calc_utils.py +++ b/tests/unit/litellm_core_utils/llm_cost_calc/test_llm_cost_calc_utils.py @@ -65,8 +65,8 @@ def test_missing_cache_read_rate_resolves_to_input_rate(prompt_tokens, read_rate prompt_cost, _ = generic_cost_per_token( "policy-fixture", usage, "openai", service_tier=service_tier, model_info=info ) - assert billed[4] == pytest.approx(read_rate if read_rate is not None else billed[0]) - assert prompt_cost == pytest.approx((prompt_tokens - 100) * billed[0] + 100 * billed[4]) + assert billed.cache_read_rate == pytest.approx(read_rate if read_rate is not None else billed.input_rate) + assert prompt_cost == pytest.approx((prompt_tokens - 100) * billed.input_rate + 100 * billed.cache_read_rate) def test_generic_cost_per_token_bills_cache_reads_at_input_rate_when_no_cache_read_rate() -> None: @@ -248,7 +248,7 @@ def test_missing_cache_read_uses_off_peak_input_rate(): } when = datetime(2026, 9, 7, 12, tzinfo=timezone.utc) billed = _get_token_base_cost(info, Usage(prompt_tokens=100), current_time=when) - assert billed[0] == billed[4] == 5e-6 + assert billed.input_rate == billed.cache_read_rate == 5e-6 def test_reasoning_tokens_no_price_set(_local_model_cost_map): @@ -324,8 +324,6 @@ def test_reasoning_tokens_gemini(_local_model_cost_map): ) - - def test_image_tokens_with_custom_pricing(): """Test that image_tokens in completion are properly costed with output_cost_per_image_token.""" from unittest.mock import patch @@ -578,7 +576,7 @@ def test_get_token_base_cost_picks_highest_crossed_tier(): } usage = Usage(prompt_tokens=150_000, completion_tokens=10, total_tokens=150_010) - prompt_base_cost = _get_token_base_cost(model_info, usage)[0] + prompt_base_cost = _get_token_base_cost(model_info, usage).input_rate assert prompt_base_cost == 9e-6 @@ -779,12 +777,12 @@ def test_get_token_base_cost_weekend_only_off_peak_rate(): saturday_peak_hours = _get_token_base_cost( model_info, usage, current_time=datetime(2026, 8, 29, 2, 0, tzinfo=timezone.utc) ) - assert saturday_peak_hours[:2] == (5e-7, 1e-6) + assert (saturday_peak_hours.input_rate, saturday_peak_hours.output_rate) == (5e-7, 1e-6) monday_same_hours = _get_token_base_cost( model_info, usage, current_time=datetime(2026, 8, 24, 2, 0, tzinfo=timezone.utc) ) - assert monday_same_hours[:2] == (1e-6, 2e-6) + assert (monday_same_hours.input_rate, monday_same_hours.output_rate) == (1e-6, 2e-6) def test_get_token_base_cost_applies_off_peak_pricing(): @@ -810,14 +808,14 @@ def test_get_token_base_cost_applies_off_peak_pricing(): usage = Usage(prompt_tokens=100, completion_tokens=50, total_tokens=150) off_peak = _get_token_base_cost(model_info, usage, current_time=datetime(2026, 1, 1, 18, 0, tzinfo=timezone.utc)) - assert off_peak[0] == 5e-7 - assert off_peak[1] == 1e-6 - assert off_peak[4] == 5e-8 + assert off_peak.input_rate == 5e-7 + assert off_peak.output_rate == 1e-6 + assert off_peak.cache_read_rate == 5e-8 peak = _get_token_base_cost(model_info, usage, current_time=datetime(2026, 1, 1, 12, 0, tzinfo=timezone.utc)) - assert peak[0] == 1e-6 - assert peak[1] == 2e-6 - assert peak[4] == 1e-7 + assert peak.input_rate == 1e-6 + assert peak.output_rate == 2e-6 + assert peak.cache_read_rate == 1e-7 def test_get_token_base_cost_non_mapping_off_peak_block_bills_standard_rates(): @@ -843,8 +841,8 @@ def test_get_token_base_cost_non_mapping_off_peak_block_bills_standard_rates(): }, ) result = _get_token_base_cost(model_info, usage, current_time=when) - assert result[0] == 1e-6 - assert result[1] == 2e-6 + assert result.input_rate == 1e-6 + assert result.output_rate == 2e-6 def test_get_token_base_cost_off_peak_falls_back_to_standard_when_unset(): @@ -864,8 +862,8 @@ def test_get_token_base_cost_off_peak_falls_back_to_standard_when_unset(): usage = Usage(prompt_tokens=100, completion_tokens=50, total_tokens=150) result = _get_token_base_cost(model_info, usage, current_time=datetime(2026, 1, 1, 18, 0, tzinfo=timezone.utc)) - assert result[0] == 5e-7 - assert result[1] == 2e-6 + assert result.input_rate == 5e-7 + assert result.output_rate == 2e-6 def test_get_token_base_cost_off_peak_wins_over_threshold(): @@ -891,12 +889,12 @@ def test_get_token_base_cost_off_peak_wins_over_threshold(): usage = Usage(prompt_tokens=250000, completion_tokens=250000, total_tokens=500000) off_peak = _get_token_base_cost(model_info, usage, current_time=datetime(2026, 1, 1, 18, 0, tzinfo=timezone.utc)) - assert off_peak[0] == 5e-7 - assert off_peak[1] == 1e-6 + assert off_peak.input_rate == 5e-7 + assert off_peak.output_rate == 1e-6 peak = _get_token_base_cost(model_info, usage, current_time=datetime(2026, 1, 1, 12, 0, tzinfo=timezone.utc)) - assert peak[0] == 3e-6 - assert peak[1] == 4e-6 + assert peak.input_rate == 3e-6 + assert peak.output_rate == 4e-6 def test_get_model_info_propagates_off_peak_fields(): @@ -948,10 +946,10 @@ def test_get_token_base_cost_off_peak_wins_over_tiered_pricing(): usage = Usage(prompt_tokens=1_000, completion_tokens=100, total_tokens=1_100) inside = _get_token_base_cost(info, usage, current_time=datetime(2026, 1, 1, 18, 0, tzinfo=timezone.utc)) - assert inside[:2] == (5e-7, 1e-6) + assert (inside.input_rate, inside.output_rate) == (5e-7, 1e-6) outside = _get_token_base_cost(info, usage, current_time=datetime(2026, 1, 1, 12, 0, tzinfo=timezone.utc)) - assert outside[:2] == (3e-6, 6e-6) + assert (outside.input_rate, outside.output_rate) == (3e-6, 6e-6) def _register_off_peak_reasoning_model( @@ -1153,17 +1151,17 @@ def test_get_token_base_cost_off_peak_cache_creation_rate(): inside_window = datetime(2026, 1, 1, 18, 0, tzinfo=timezone.utc) inside = _get_token_base_cost(model_info, usage, current_time=inside_window) - assert inside[2] == 5e-7 - assert inside[3] == 2e-6 + assert inside.cache_creation_rate == 5e-7 + assert inside.cache_creation_rates_by_ttl["1hr"] == 2e-6 outside = _get_token_base_cost(model_info, usage, current_time=datetime(2026, 1, 1, 12, 0, tzinfo=timezone.utc)) - assert outside[2] == 1.25e-6 + assert outside.cache_creation_rate == 1.25e-6 without_key = cast( ModelInfo, {**model_info, "off_peak_pricing": {"hours_utc": "16:30-00:30", "input_cost_per_token": 5e-7}}, ) - assert _get_token_base_cost(without_key, usage, current_time=inside_window)[2] == 1.25e-6 + assert _get_token_base_cost(without_key, usage, current_time=inside_window).cache_creation_rate == 1.25e-6 def test_get_token_type_cost_breakdown_reflects_off_peak_reasoning_and_cache_creation_rates(): @@ -1583,19 +1581,14 @@ def test_generic_cost_per_token_tier_1hr_cache_rate_preserves_zero_and_fallback( ), ) costs: Final = generic_cost_per_token(model=model, usage=usage, custom_llm_provider="openrouter") - breakdown: Final = get_token_type_cost_breakdown( - model=model, usage=usage, custom_llm_provider="openrouter" - ) + breakdown: Final = get_token_type_cost_breakdown(model=model, usage=usage, custom_llm_provider="openrouter") ordinary_rate: Final = cache_rates.get("cache_creation_input_token_cost") - expected_write_cost: Final = ( - (20 - one_hour_tokens) * (ordinary_rate if ordinary_rate is not None else 1.0) - + one_hour_tokens * expected_write_rate - ) + expected_write_cost: Final = (20 - one_hour_tokens) * ( + ordinary_rate if ordinary_rate is not None else 1.0 + ) + one_hour_tokens * expected_write_rate assert costs == pytest.approx((40 * 1.0 + 40 * 0.1 + expected_write_cost, 10 * 2.0)) assert breakdown.cache_creation_cost == pytest.approx(expected_write_cost) - assert breakdown.rates is not None - assert breakdown.rates.cache_creation_input_token_cost_above_1hr == expected_write_rate finally: litellm.model_cost.pop(model, None) @@ -2020,8 +2013,8 @@ def test_calculate_cache_writing_cost(): result = calculate_cache_writing_cost( cache_creation_tokens=cache_creation_tokens, cache_creation_token_details=cache_creation_token_details, - cache_creation_cost_above_1hr=cache_creation_cost_above_1hr, cache_creation_cost=cache_creation_cost, + cache_creation_cost_by_ttl={"1hr": cache_creation_cost_above_1hr, "12hr": cache_creation_cost_above_1hr}, ) # Expected calculation: @@ -2041,8 +2034,8 @@ def test_calculate_cache_writing_cost(): result_no_details = calculate_cache_writing_cost( cache_creation_tokens=cache_creation_tokens_no_details, cache_creation_token_details=cache_creation_token_details_none, - cache_creation_cost_above_1hr=cache_creation_cost_above_1hr, cache_creation_cost=cache_creation_cost_fallback, + cache_creation_cost_by_ttl={"1hr": cache_creation_cost_above_1hr, "12hr": cache_creation_cost_above_1hr}, ) # Expected calculation when no details: 1000 * 5e-06 = 0.005 @@ -2059,15 +2052,13 @@ def test_calculate_cache_writing_cost(): result_partial = calculate_cache_writing_cost( cache_creation_tokens=500, cache_creation_token_details=cache_creation_token_details_partial, - cache_creation_cost_above_1hr=6e-06, cache_creation_cost=3e-06, + cache_creation_cost_by_ttl={"1hr": 6e-06, "12hr": 6e-06}, ) - # Expected calculation: 0 (for None 5m tokens) + (100 * 6e-06) = 0.0006 - expected_cost_partial = (0.0) + (100 * 6e-06) + expected_cost_partial = (400 * 3e-06) + (100 * 6e-06) assert round(result_partial, 6) == round(expected_cost_partial, 6) - assert round(result_partial, 6) == 0.0006 # Test case 4: Zero costs result_zero = calculate_cache_writing_cost( @@ -2075,13 +2066,161 @@ def test_calculate_cache_writing_cost(): cache_creation_token_details=CacheCreationTokenDetails( ephemeral_5m_input_tokens=50, ephemeral_1h_input_tokens=950 ), - cache_creation_cost_above_1hr=0.0, cache_creation_cost=0.0, + cache_creation_cost_by_ttl={"1hr": 0.0, "12hr": 0.0}, ) assert result_zero == 0.0 +@pytest.mark.parametrize("field", CacheCreationTokenDetails.model_fields) +def test_calculate_cache_writing_cost_bills_every_reported_lifetime(field: str) -> None: + cost = calculate_cache_writing_cost( + cache_creation_tokens=10, + cache_creation_token_details=CacheCreationTokenDetails(**{field: 10}), + cache_creation_cost=2.0, + cache_creation_cost_by_ttl={"1hr": 2.0, "12hr": 2.0}, + ) + assert cost == 20.0 + + +def test_calculate_cache_writing_cost_bills_writes_of_an_unknown_lifetime_at_the_base_rate() -> None: + cost = calculate_cache_writing_cost( + cache_creation_tokens=10, + cache_creation_token_details=CacheCreationTokenDetails( + ephemeral_30m_input_tokens=2, ephemeral_12h_input_tokens=3 + ), + cache_creation_cost=1.0, + cache_creation_cost_by_ttl={"1hr": 4.0, "12hr": 4.0}, + ) + assert cost == 2 * 1.0 + 3 * 4.0 + 5 * 1.0 + + +@pytest.mark.parametrize( + ("prompt_tokens", "service_tier", "write_rate", "twelve_hour_rate"), + [ + (10_000, "default", 2e-6, 4e-6), + (10_000, "flex", 1e-6, 2e-6), + (10_000, "priority", 3e-6, 6e-6), + (300_000, "default", 4e-6, 8e-6), + (300_000, "flex", 2e-6, 4e-6), + (300_000, "priority", 6e-6, 12e-6), + ], +) +def test_generic_cost_per_token_prices_12h_cache_writes_at_prompt_threshold( + prompt_tokens: int, service_tier: str, write_rate: float, twelve_hour_rate: float +) -> None: + model_info: Final[ModelInfo] = { + "input_cost_per_token": 1e-6, + "output_cost_per_token": 2e-6, + "cache_creation_input_token_cost": 2e-6, + "cache_creation_input_token_cost_flex": 1e-6, + "cache_creation_input_token_cost_priority": 3e-6, + "cache_creation_input_token_cost_above_272k_tokens": 4e-6, + "cache_creation_input_token_cost_above_272k_tokens_flex": 2e-6, + "cache_creation_input_token_cost_above_272k_tokens_priority": 6e-6, + "cache_creation_input_token_cost_above_12hr": 4e-6, + "cache_creation_input_token_cost_above_12hr_flex": 2e-6, + "cache_creation_input_token_cost_above_12hr_priority": 6e-6, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 8e-6, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": 4e-6, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": 12e-6, + } + usage: Final = Usage( + prompt_tokens=prompt_tokens, + completion_tokens=0, + total_tokens=prompt_tokens, + prompt_tokens_details=PromptTokensDetailsWrapper( + cache_creation_tokens=5_000, + cache_creation_token_details=CacheCreationTokenDetails( + ephemeral_30m_input_tokens=3_000, ephemeral_12h_input_tokens=2_000 + ), + ), + ) + + result: Final = generic_cost_per_token( + model="test-12h-cache-write", + usage=usage, + custom_llm_provider="openai", + service_tier=None if service_tier == "default" else service_tier, + model_info=model_info, + ) + + assert result[0] == pytest.approx( + (usage.prompt_tokens - usage.prompt_tokens_details.cache_creation_tokens) * model_info["input_cost_per_token"] + + 3_000 * write_rate + + 2_000 * twelve_hour_rate + ) + + +def test_generic_cost_per_token_falls_back_to_default_for_missing_12h_rate() -> None: + model_info: Final[ModelInfo] = { + "input_cost_per_token": 1e-6, + "output_cost_per_token": 2e-6, + "cache_creation_input_token_cost": 3e-6, + } + usage: Final = Usage( + prompt_tokens=100, + completion_tokens=0, + total_tokens=100, + prompt_tokens_details=PromptTokensDetailsWrapper( + cache_creation_tokens=100, + cache_creation_token_details=CacheCreationTokenDetails(ephemeral_12h_input_tokens=100), + ), + ) + + result: Final = generic_cost_per_token( + model="test-12h-cache-write-fallback", + usage=usage, + custom_llm_provider="openai", + model_info=model_info, + ) + + assert result[0] == pytest.approx(100 * model_info["cache_creation_input_token_cost"]) + + +@pytest.mark.parametrize(("prompt_tokens", "twelve_hour_rate"), [(10_000, 7e-6), (300_000, 14e-6)]) +def test_generic_cost_per_token_prices_ultrafast_12h_cache_writes_at_the_ultrafast_rate( + prompt_tokens: int, twelve_hour_rate: float +) -> None: + model_info: Final[ModelInfo] = { + "input_cost_per_token": 1e-6, + "output_cost_per_token": 2e-6, + "input_cost_per_token_ultrafast": 5e-6, + "cache_creation_input_token_cost": 2e-6, + "cache_creation_input_token_cost_ultrafast": 3e-6, + "cache_creation_input_token_cost_above_12hr": 4e-6, + "cache_creation_input_token_cost_above_12hr_ultrafast": 7e-6, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": 8e-6, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_ultrafast": 14e-6, + } + usage: Final = Usage( + prompt_tokens=prompt_tokens, + completion_tokens=0, + total_tokens=prompt_tokens, + prompt_tokens_details=PromptTokensDetailsWrapper( + cache_creation_tokens=5_000, + cache_creation_token_details=CacheCreationTokenDetails( + ephemeral_30m_input_tokens=3_000, ephemeral_12h_input_tokens=2_000 + ), + ), + ) + + prompt_cost, _ = generic_cost_per_token( + model="test-ultrafast-12h-cache-write", + usage=usage, + custom_llm_provider="openai", + service_tier="ultrafast", + model_info=model_info, + ) + + assert prompt_cost == pytest.approx( + (prompt_tokens - 5_000) * model_info["input_cost_per_token_ultrafast"] + + 3_000 * model_info["cache_creation_input_token_cost_ultrafast"] + + 2_000 * twelve_hour_rate + ) + + def test_cache_writing_cost_with_zero_creation_tokens_and_ephemeral_details(): """ Regression test: when cache_creation_tokens is 0 but cache_creation_token_details @@ -2119,7 +2258,7 @@ def test_cache_writing_cost_with_zero_creation_tokens_and_ephemeral_details(): prompt_base_cost=0.0, cache_read_cost=0.0, cache_creation_cost=cache_creation_cost, - cache_creation_cost_above_1hr=cache_creation_cost_above_1hr, + cache_creation_cost_by_ttl={"1hr": cache_creation_cost_above_1hr, "12hr": cache_creation_cost_above_1hr}, ) # Expected: (100 * 3.75e-06) + (200 * 6e-06) = 0.000375 + 0.0012 = 0.001575 @@ -2330,10 +2469,6 @@ def test_vertex_image_generation_cost_falls_back_to_flat_image_pricing(_local_mo assert round(cost, 10) == round(expected_cost, 10) - - - - def test_query_count_is_free_without_a_per_query_price(_local_model_cost_map): usage = Usage( prompt_tokens=0, @@ -2512,8 +2647,6 @@ def test_vertex_global_or_absent_location_no_uplift(vertex_location, _local_mode assert base == located - - def test_vertex_uplift_invalid_multiplier_defaults_to_one(): """A malformed multiplier in the cost map degrades to base pricing, never raises.""" from litellm.litellm_core_utils.llm_cost_calc.utils import ( @@ -2569,10 +2702,10 @@ def test_flat_input_price_keeps_other_token_thresholds(field: str) -> None: model_info=info, usage=Usage(prompt_tokens=300_001, completion_tokens=3, total_tokens=300_004), ) - assert rates[0] == 0.001 - assert rates[1] == (0.005 if field == "output_cost_per_token" else 0.002) - assert rates[2] == (0.005 if field == "cache_creation_input_token_cost" else 0.004) - assert rates[4] == (0.005 if field == "cache_read_input_token_cost" else 0.003) + assert rates.input_rate == 0.001 + assert rates.output_rate == (0.005 if field == "output_cost_per_token" else 0.002) + assert rates.cache_creation_rate == (0.005 if field == "cache_creation_input_token_cost" else 0.004) + assert rates.cache_read_rate == (0.005 if field == "cache_read_input_token_cost" else 0.003) @pytest.mark.parametrize("prompt_tokens", (200_000, 200_001, 512_000, 512_001)) @@ -2599,10 +2732,12 @@ def test_mixed_token_thresholds_preserve_each_crossed_rate(prompt_tokens: int, h model_info=info, usage=Usage(prompt_tokens=prompt_tokens, completion_tokens=3, total_tokens=prompt_tokens + 3), ) - assert rates[0] == (0.005 if prompt_tokens > 200_000 else 0.001) - assert rates[1] == (higher_rate if prompt_tokens > 512_000 else 0.006 if prompt_tokens > 200_000 else 0.002) - assert rates[2] == (0.007 if prompt_tokens > 200_000 else 0.004) - assert rates[4] == (higher_rate if prompt_tokens > 512_000 else 0.003) + assert rates.input_rate == (0.005 if prompt_tokens > 200_000 else 0.001) + assert rates.output_rate == ( + higher_rate if prompt_tokens > 512_000 else 0.006 if prompt_tokens > 200_000 else 0.002 + ) + assert rates.cache_creation_rate == (0.007 if prompt_tokens > 200_000 else 0.004) + assert rates.cache_read_rate == (higher_rate if prompt_tokens > 512_000 else 0.003) def test_threshold_keys_exclude_service_tier_variants(): @@ -2626,8 +2761,7 @@ def test_threshold_keys_exclude_service_tier_variants(): }, ) usage = Usage(prompt_tokens=350_000, completion_tokens=1_000, total_tokens=351_000) - prompt_base, *_ = _get_token_base_cost(model_info=model_info, usage=usage) - assert prompt_base == 3e-6 + assert _get_token_base_cost(model_info=model_info, usage=usage).input_rate == 3e-6 @pytest.mark.parametrize( @@ -2897,7 +3031,7 @@ def test_billed_token_rates_follow_the_token_tier_the_breakdown_bills_at(monkeyp cache_read_input_token_cost=6e-7, cache_read_input_audio_token_cost=6e-7, cache_creation_input_token_cost=7.5e-6, - cache_creation_input_token_cost_above_1hr=7.5e-6, + cache_creation_input_token_cost_by_ttl={"1hr": 7.5e-6, "12hr": 7.5e-6}, output_cost_per_reasoning_token=3e-5, ) assert breakdown.cache_read_cost == pytest.approx(200_000 * rates.cache_read_input_token_cost) @@ -3713,6 +3847,23 @@ def test_generic_cost_per_token_bills_cache_creation_at_the_input_rate_without_a 3e-7, id="no-1h-price-uses-the-off-peak-write-price", ), + pytest.param( + { + "tiered_pricing": [ + { + "range": [0, 128000], + "input_cost_per_token": 2e-7, + "output_cost_per_token": 1.25e-6, + "cache_creation_input_token_cost": 2.5e-7, + } + ], + "off_peak_pricing": {"hours_utc": "00:00-23:59", "cache_creation_input_token_cost": 3e-7}, + }, + datetime(2026, 9, 14, 12, tzinfo=timezone.utc), + 3e-7, + 3e-7, + id="tiered-no-1h-price-uses-the-off-peak-write-price", + ), ), ) def test_get_token_base_cost_resolves_missing_cache_write_rates_like_the_tiered_path( @@ -3724,10 +3875,17 @@ def test_get_token_base_cost_resolves_missing_cache_write_rates_like_the_tiered_ model_info = {"input_cost_per_token": 2e-7, "output_cost_per_token": 1.25e-6, **cache_rates} usage = Usage(prompt_tokens=10, completion_tokens=1, total_tokens=11) - _, _, creation, creation_1h, _ = _get_token_base_cost(model_info, usage, current_time=current_time) + rates = _get_token_base_cost(model_info, usage, current_time=current_time) - assert creation == pytest.approx(expected_creation) - assert creation_1h == pytest.approx(expected_creation_1h) + assert rates.cache_creation_rate == pytest.approx(expected_creation) + assert calculate_cache_writing_cost( + cache_creation_tokens=3, + cache_creation_token_details=CacheCreationTokenDetails( + ephemeral_1h_input_tokens=1, ephemeral_12h_input_tokens=2 + ), + cache_creation_cost=rates.cache_creation_rate, + cache_creation_cost_by_ttl=rates.cache_creation_rates_by_ttl, + ) == pytest.approx(3 * expected_creation_1h) def _image_response(num_images: int = 1, usage: ImageUsage | None = None) -> ImageResponse: @@ -3787,8 +3945,6 @@ def test_route_image_generation_cost_openai_honors_deployment_input_cost_per_ima assert cost == pytest.approx(0.07) - - @pytest.mark.parametrize( ("custom_llm_provider", "model"), [ @@ -3965,6 +4121,44 @@ def test_get_batch_cost_rates_has_no_cache_write_rate_without_a_cache_write_batc assert rates.cache_creation is None +@pytest.mark.parametrize(("prompt_tokens", "expected"), [(1_000, 2.5e-7), (272_000, 2.5e-7), (300_000, 5e-7)]) +def test_get_batch_cost_rates_reads_the_12h_batch_cache_write_rate_for_the_crossed_tier( + prompt_tokens: int, expected: float +) -> None: + from litellm.litellm_core_utils.llm_cost_calc.utils import get_batch_cost_rates + + rates: Final = get_batch_cost_rates( + _batch_rates_model_info( + input_cost_per_token_batches=1e-7, + cache_creation_input_token_cost_batches=1.25e-7, + cache_creation_input_token_cost_above_12hr_batches=2.5e-7, + cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches=5e-7, + ), + Usage(prompt_tokens=prompt_tokens, completion_tokens=1, total_tokens=prompt_tokens + 1), + "openai", + ) + + assert rates.cache_creation == 1.25e-7 + assert rates.cache_creation_rates_by_ttl == {"12hr": expected} + + +def test_get_batch_cost_rates_has_no_12h_cache_write_rate_without_a_12h_batch_key() -> None: + from litellm.litellm_core_utils.llm_cost_calc.utils import get_batch_cost_rates + + rates: Final = get_batch_cost_rates( + _batch_rates_model_info( + input_cost_per_token_batches=1e-7, + cache_creation_input_token_cost_batches=1.25e-7, + cache_creation_input_token_cost_above_12hr=2.5e-7, + cache_creation_input_token_cost_above_12hr_ultrafast=5e-7, + ), + Usage(prompt_tokens=300_000, completion_tokens=1, total_tokens=300_001), + "openai", + ) + + assert rates.cache_creation_rates_by_ttl == {} + + @pytest.mark.parametrize("model_base", ["gpt-6-sol", "gpt-6-luna"]) def test_azure_gpt_6_foundry_price_sheet(_local_model_cost_map, model_base): """Azure Foundry hosts gpt-6-sol and gpt-6-luna at OpenAI's Global rates, with the @@ -4206,17 +4400,28 @@ def test_token_breakdown_uses_supplied_pricing_without_catalog_lookup(rate: floa "cache_creation_input_token_cost": rate, } usage: Final = Usage( - prompt_tokens=20, completion_tokens=3, total_tokens=23, - prompt_tokens_details=PromptTokensDetailsWrapper(cached_tokens=5), cache_creation_input_tokens=5, + prompt_tokens=20, + completion_tokens=3, + total_tokens=23, + prompt_tokens_details=PromptTokensDetailsWrapper(cached_tokens=5), + cache_creation_input_tokens=5, ) prompt_cost, output_cost = generic_cost_per_token( - model="supplied-pricing-test", usage=usage, custom_llm_provider="bedrock", model_info=model_info, + model="supplied-pricing-test", + usage=usage, + custom_llm_provider="bedrock", + model_info=model_info, ) breakdown: Final = get_token_type_cost_breakdown( - model="supplied-pricing-test", usage=usage, custom_llm_provider="bedrock", model_info=model_info, + model="supplied-pricing-test", + usage=usage, + custom_llm_provider="bedrock", + model_info=model_info, ) assert breakdown.cache_read_cost == pytest.approx(5 * rate) assert breakdown.cache_creation_cost == pytest.approx(5 * rate) assert breakdown.rates is not None - assert prompt_cost == pytest.approx(10 * breakdown.rates.input_cost_per_token + breakdown.cache_read_cost + breakdown.cache_creation_cost) + assert prompt_cost == pytest.approx( + 10 * breakdown.rates.input_cost_per_token + breakdown.cache_read_cost + breakdown.cache_creation_cost + ) assert output_cost == pytest.approx(3 * breakdown.rates.output_cost_per_token) diff --git a/tests/unit/litellm_core_utils/llm_cost_calc/test_utils.py b/tests/unit/litellm_core_utils/llm_cost_calc/test_utils.py index 142d49bfff1..b6c18e0da86 100644 --- a/tests/unit/litellm_core_utils/llm_cost_calc/test_utils.py +++ b/tests/unit/litellm_core_utils/llm_cost_calc/test_utils.py @@ -11,6 +11,7 @@ import respx import litellm from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER +from litellm.types.llms.base import CachedTokensDetails from litellm.types.utils import ModelResponse, PromptTokensDetailsWrapper, Usage TIER_MODEL: Final = "tier-priced-test-model" @@ -31,6 +32,20 @@ PROMPT_TOKENS: Final = 1000 CACHED_TOKENS: Final = 200 COMPLETION_TOKENS: Final = 500 TIER_API_BASE: Final = "https://tier-pricing.invalid/v1" +AUDIO_TIER_MODEL: Final = "tier-priced-gemini-audio-test-model" +AUDIO_TIER_ROW: Final[Mapping[str, float]] = MappingProxyType( + { + "input_cost_per_token": 4e-06, + "output_cost_per_token": 8e-06, + "cache_read_input_token_cost": 1e-06, + "input_cost_per_audio_token": 3e-06, + "cache_read_input_audio_token_cost": 2e-06, + "input_cost_per_audio_token_flex": 1e-06, + "input_cost_per_audio_token_priority": 2e-06, + "cache_read_input_audio_token_cost_flex": 4e-07, + "cache_read_input_audio_token_cost_priority": 8e-07, + } +) def _cost_at(prices: Mapping[str, float], column_suffix: str) -> float: @@ -78,6 +93,53 @@ def test_completion_cost_bills_the_price_columns_of_the_service_tier( assert cost == pytest.approx(_cost_at(TIER_ROW, column_suffix)) +@pytest.mark.parametrize( + ("service_tier", "audio_rate_key", "cache_audio_rate_key"), + ( + pytest.param("flex", "input_cost_per_audio_token_flex", "cache_read_input_audio_token_cost_flex"), + pytest.param("priority", "input_cost_per_audio_token_priority", "cache_read_input_audio_token_cost_priority"), + ), +) +def test_gemini_audio_and_cached_audio_use_service_tier_rates( + local_model_cost_map: None, service_tier: str, audio_rate_key: str, cache_audio_rate_key: str +) -> None: + litellm.register_model( + { + AUDIO_TIER_MODEL: { + "litellm_provider": "gemini", + "mode": "chat", + **AUDIO_TIER_ROW, + } + } + ) + usage: Final = Usage( + prompt_tokens=40, + completion_tokens=0, + total_tokens=40, + prompt_tokens_details=PromptTokensDetailsWrapper( + text_tokens=20, + audio_tokens=20, + cached_tokens=10, + cached_tokens_details=CachedTokensDetails(audio_tokens=10), + ), + ) + response: Final = ModelResponse(model=AUDIO_TIER_MODEL, usage=usage) + + cost: Final = litellm.completion_cost( + completion_response=response, + model=AUDIO_TIER_MODEL, + custom_llm_provider="gemini", + service_tier=service_tier, + ) + + expected: Final = ( + 20 * AUDIO_TIER_ROW["input_cost_per_token"] + + 10 * AUDIO_TIER_ROW[audio_rate_key] + + 10 * AUDIO_TIER_ROW[cache_audio_rate_key] + ) + assert cost == pytest.approx(expected) + + LONG_CONTEXT_TIER_MODEL: Final = "long-context-tier-priced-test-model" LONG_CONTEXT_TIER_ROW: Final[Mapping[str, float]] = MappingProxyType( { diff --git a/tests/unit/litellm_core_utils/llm_cost_calc/test_zero_cost_diagnostic.py b/tests/unit/litellm_core_utils/llm_cost_calc/test_zero_cost_diagnostic.py index 921dde8bf7b..bdc14c4934b 100644 --- a/tests/unit/litellm_core_utils/llm_cost_calc/test_zero_cost_diagnostic.py +++ b/tests/unit/litellm_core_utils/llm_cost_calc/test_zero_cost_diagnostic.py @@ -9,6 +9,7 @@ from litellm.litellm_core_utils.llm_cost_calc.zero_cost_diagnostic import ( used_pricing_keys, zero_cost_warning, ) +from litellm.types.llms.base import CachedTokensDetails from litellm.types.utils import CompletionTokensDetailsWrapper, PromptTokensDetailsWrapper, Usage PER_SECOND_ENTRY: Final = {"cost_per_second": 0.00042} @@ -135,6 +136,36 @@ def test_audio_tokens_need_the_audio_rates() -> None: assert diagnostic["missing_pricing_keys"] == ("input_cost_per_audio_token", "output_cost_per_audio_token") +def test_cached_audio_uses_its_cache_rate_in_zero_cost_diagnostic() -> None: + usage: Final = Usage( + prompt_tokens=20, + completion_tokens=0, + total_tokens=20, + prompt_tokens_details=PromptTokensDetailsWrapper( + text_tokens=0, + audio_tokens=20, + cached_tokens=20, + cached_tokens_details=CachedTokensDetails(audio_tokens=20), + ), + ) + pricing_entry: Final = { + "input_cost_per_token": 1e-6, + "input_cost_per_audio_token": 2e-6, + "cache_read_input_audio_token_cost": 0, + } + + assert used_pricing_keys(usage) == ("cache_read_input_audio_token_cost",) + assert ( + diagnose_zero_cost( + usage=usage, + pricing_model="gemini-audio", + pricing_entry=pricing_entry, + calculation_failed=False, + ) + is None + ) + + def test_warning_names_the_request_the_entry_the_missing_keys_and_the_counter() -> None: diagnostic = diagnose_zero_cost( usage=TEXT_USAGE, pricing_model="dep-1", pricing_entry=PER_SECOND_ENTRY, calculation_failed=False diff --git a/tests/unit/litellm_core_utils/test_dot_notation_indexing.py b/tests/unit/litellm_core_utils/test_dot_notation_indexing.py index ae529a71009..7c670f1dac9 100644 --- a/tests/unit/litellm_core_utils/test_dot_notation_indexing.py +++ b/tests/unit/litellm_core_utils/test_dot_notation_indexing.py @@ -2,6 +2,9 @@ Tests for litellm.litellm_core_utils.dot_notation_indexing module. """ +from types import MappingProxyType +from typing import Final + import pytest from litellm.litellm_core_utils.dot_notation_indexing import ( @@ -125,3 +128,14 @@ class TestDeleteNestedValue: data = {"items": [{"a": 1, "b": 2}, {"a": 3, "b": 4}]} result = delete_nested_value(data, "items[0].b") assert result == {"items": [{"a": 1}, {"a": 3, "b": 4}]} + + def test_delete_returns_a_fresh_dict_and_leaves_a_narrowly_typed_input_untouched(self): + payload: Final[dict[str, list[str]]] = {"tags": ["a", "b"], "secret": ["s"]} + result = delete_nested_value(payload, "secret") + assert result == {"tags": ["a", "b"]} + assert payload == {"tags": ["a", "b"], "secret": ["s"]} + assert result["tags"] is not payload["tags"] + + def test_delete_accepts_a_read_only_mapping(self): + payload: Final = MappingProxyType({"tags": ["a"], "secret": ["s"]}) + assert delete_nested_value(payload, "secret") == {"tags": ["a"]} diff --git a/tests/unit/litellm_core_utils/test_fallback_generalizations.py b/tests/unit/litellm_core_utils/test_fallback_generalizations.py index 7807c438503..e59252e1571 100644 --- a/tests/unit/litellm_core_utils/test_fallback_generalizations.py +++ b/tests/unit/litellm_core_utils/test_fallback_generalizations.py @@ -369,7 +369,7 @@ def test_exact_entries_fill_only_missing_fields(restore_generalizations, monkeyp "output_cost_per_token": 2e-6, "litellm_provider": "openai", "mode": "chat", - "max_tokens": 7, + "max_output_tokens": 7, "supports_reasoning": False, }, "acme-bare": { @@ -398,7 +398,7 @@ def test_exact_entries_fill_only_missing_fields(restore_generalizations, monkeyp "name": "acme-backfill", "pattern": r"^acme-", "fill_missing_for_providers": ["openai"], - "model_info": {"supports_reasoning": True, "max_tokens": 5}, + "model_info": {"supports_reasoning": True, "max_output_tokens": 5}, } ] ) @@ -406,10 +406,12 @@ def test_exact_entries_fill_only_missing_fields(restore_generalizations, monkeyp full = litellm.get_model_info("acme-full", custom_llm_provider="openai") assert full["supports_reasoning"] is False + assert full["max_output_tokens"] == 7 assert full["max_tokens"] == 7 bare = litellm.get_model_info("acme-bare", custom_llm_provider="openai") assert bare["supports_reasoning"] is True + assert bare["max_output_tokens"] == 5 assert bare["max_tokens"] == 5 assert bare["input_cost_per_token"] == 3e-6 assert bare["key"] == "acme-bare" @@ -525,7 +527,7 @@ def test_shipped_gemini_chat_baseline_loses_to_exact_entries(shipped_cost_map): model = "gemini-2.5-flash-lite" info = litellm.get_model_info(model, custom_llm_provider="gemini") entry = litellm.model_cost["gemini/gemini-2.5-flash-lite"] - assert info["max_tokens"] == entry["max_tokens"] + assert info["max_tokens"] == entry["max_output_tokens"] assert info["input_cost_per_token"] == entry["input_cost_per_token"] assert entry["input_cost_per_token"] > 0 diff --git a/tests/unit/litellm_core_utils/test_get_llm_provider_logic.py b/tests/unit/litellm_core_utils/test_get_llm_provider_logic.py index 57e66805678..e9e3f7b8174 100644 --- a/tests/unit/litellm_core_utils/test_get_llm_provider_logic.py +++ b/tests/unit/litellm_core_utils/test_get_llm_provider_logic.py @@ -1,5 +1,9 @@ +from collections.abc import Iterator +from pathlib import Path from typing import Final +import respx + import asyncio, httpx, importlib, os import pytest @@ -8,6 +12,7 @@ from litellm import CustomLLM from litellm.litellm_core_utils import get_llm_provider_logic from litellm.litellm_core_utils.get_llm_provider_logic import ( get_llm_provider, + resolve_model_and_provider_for_metadata, get_provider_affinity_header, inferred_provider, is_registered_custom_provider, @@ -715,3 +720,47 @@ def test_opencode_affinity_resolution_preserves_existing_transport(prefix: str) model, provider, _, destination = get_llm_provider(model=f"{prefix}/test-model", api_base=api_base) assert (model, provider, destination) == ("test-model", prefix, api_base) assert get_provider_affinity_header(destination) == "x-opencode-session" + + +@pytest.fixture +def chatgpt_login_tripwire(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> Iterator[None]: + blocked: Final = tmp_path / "blocked" + blocked.write_text("ordinary file") + monkeypatch.setenv("CHATGPT_TOKEN_DIR", str(blocked / "unused")) + monkeypatch.delenv("CHATGPT_AUTH_FILE", raising=False) + with respx.mock as transport: + yield + assert len(transport.calls) == 0 + + +@pytest.mark.parametrize( + ("model", "custom_llm_provider", "expected"), + [ + ("chatgpt/gpt-5.4", None, ("gpt-5.4", "chatgpt")), + ("gpt-5.4", "chatgpt", ("gpt-5.4", "chatgpt")), + ("github_copilot/gpt-4o", None, ("gpt-4o", "github_copilot")), + ("openai/gpt-5.4", None, ("gpt-5.4", "openai")), + ], +) +def test_resolve_model_and_provider_for_metadata_never_logs_in( + chatgpt_login_tripwire: None, model: str, custom_llm_provider: str | None, expected: tuple[str, str] +) -> None: + assert resolve_model_and_provider_for_metadata(model, custom_llm_provider) == expected + + +def test_metadata_callers_never_log_in_for_a_declared_chatgpt_deployment( + chatgpt_login_tripwire: None, monkeypatch: pytest.MonkeyPatch +) -> None: + from litellm.litellm_core_utils.llm_response_utils.get_api_base import get_api_base + from litellm.proxy.spend_tracking.savings import _resolve_model + from litellm.router import Router + from litellm.types.router import LiteLLM_Params + from litellm.utils import supports_native_streaming + + monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True") + + assert supports_native_streaming("chatgpt/gpt-5.4", None) is True + assert get_api_base("chatgpt/gpt-5.4", {"model": "chatgpt/gpt-5.4"}) == "https://chatgpt.com/backend-api/codex" + identity = _resolve_model("chatgpt/gpt-5.4", None) + assert identity is not None and identity.provider == "chatgpt" + assert Router._model_group_llm_provider(LiteLLM_Params(model="chatgpt/gpt-5.4")) == ("gpt-5.4", "chatgpt") diff --git a/tests/unit/litellm_core_utils/test_litellm_logging.py b/tests/unit/litellm_core_utils/test_litellm_logging.py index 8509b1d6f7d..e786753e1a8 100644 --- a/tests/unit/litellm_core_utils/test_litellm_logging.py +++ b/tests/unit/litellm_core_utils/test_litellm_logging.py @@ -76,6 +76,7 @@ import inspect from typing import List, Optional from litellm.types.utils import LiteLLMCommonStrings + @pytest.fixture def logging_obj(): return LitellmLogging( @@ -346,8 +347,10 @@ async def test_mcp_native_structured_replacement_must_match_returned_content( ) logging_obj.dynamic_success_callbacks = [NativeReplacement()] returned = await logging_obj.async_post_mcp_tool_call_hook( - kwargs={"original_response": result}, response_obj=result, - start_time=datetime.datetime.now(), end_time=datetime.datetime.now(), + kwargs={"original_response": result}, + response_obj=result, + start_time=datetime.datetime.now(), + end_time=datetime.datetime.now(), ) assert returned is result assert result.content == [TextContent(type="text", text="native-safe" if same_content else "final-safe")] @@ -356,7 +359,6 @@ async def test_mcp_native_structured_replacement_must_match_returned_content( assert "SECRET-1234" not in result.model_dump_json() - @pytest.mark.asyncio @pytest.mark.parametrize("mode", ["none", "wrapper", "exception"]) @pytest.mark.parametrize("structured", [False, True]) @@ -374,8 +376,10 @@ async def test_mcp_direct_content_edit_invalidates_stale_structured_data(logging ) logging_obj.dynamic_success_callbacks = [DirectRedactor()] returned = await logging_obj.async_post_mcp_tool_call_hook( - kwargs={"original_response": result}, response_obj=result, - start_time=datetime.datetime.now(), end_time=datetime.datetime.now(), + kwargs={"original_response": result}, + response_obj=result, + start_time=datetime.datetime.now(), + end_time=datetime.datetime.now(), ) assert returned is result assert result.content == [TextContent(type="text", text="[REDACTED]")] @@ -2620,7 +2624,6 @@ async def test_completed_success_selects_one_implemented_hook( assert (thread_id == loop_thread) is (kind != "sync") - @pytest.mark.parametrize("for_async_request,split_registries", [(False, False), (True, False), (True, True)]) @pytest.mark.parametrize("private_first", [False, True]) @pytest.mark.parametrize("response_kind", ["responses", "completion"]) @@ -3312,8 +3315,13 @@ async def test_shadow_snapshot_stays_private_and_is_invalidated_before_logging_g class RecordingShadowLogger(ShadowEvalLogger): async def async_log_success_event( - self, kwargs: Mapping[str, object], response_obj: object, start_time: object, - end_time: object, *, guardrail_snapshot: GuardrailRequestSnapshot | None = None, + self, + kwargs: Mapping[str, object], + response_obj: object, + start_time: object, + end_time: object, + *, + guardrail_snapshot: GuardrailRequestSnapshot | None = None, ) -> None: shadow_snapshots.append(guardrail_snapshot) await super().async_log_success_event( @@ -3322,13 +3330,20 @@ async def test_shadow_snapshot_stays_private_and_is_invalidated_before_logging_g class RecordingLogger(CustomLogger): async def async_log_success_event( - self, kwargs: Mapping[str, object], response_obj: object, start_time: object, end_time: object, + self, + kwargs: Mapping[str, object], + response_obj: object, + start_time: object, + end_time: object, ) -> None: other_payloads.append(kwargs) class LoggingGuardrail(CustomGuardrail): async def async_logging_hook( - self, kwargs: dict[str, object], result: object, call_type: str, + self, + kwargs: dict[str, object], + result: object, + call_type: str, ) -> tuple[dict[str, object], object]: hook_snapshots.append(logging_obj.shadow_eval_request_snapshot) if hook_mode == "raises": @@ -3340,26 +3355,36 @@ async def test_shadow_snapshot_stays_private_and_is_invalidated_before_logging_g "user_api_key_hash": "test-key", } snapshot: Final = GuardrailRequestSnapshot.capture( - {"messages": [{"role": "user", "content": "snapshot-only"}]}, metadata, + {"messages": [{"role": "user", "content": "snapshot-only"}]}, + metadata, ) assert snapshot is not None shadow: Final = RecordingShadowLogger(prisma_provider=no_prisma, jobs_cache=InMemoryCache()) guardrail: Final = LoggingGuardrail( - guardrail_name="late-mask", default_on=True, + guardrail_name="late-mask", + default_on=True, event_hook=GuardrailEventHooks.pre_call if hook_mode == "disabled" else GuardrailEventHooks.logging_only, ) monkeypatch.setattr(litellm, "_async_success_callback", []) logging_obj: Final = LitellmLogging( - model="test-model", messages=[], stream=stream, call_type="anthropic_messages", - start_time=datetime.datetime.now(), litellm_call_id="private-snapshot", function_id="private-snapshot", + model="test-model", + messages=[], + stream=stream, + call_type="anthropic_messages", + start_time=datetime.datetime.now(), + litellm_call_id="private-snapshot", + function_id="private-snapshot", dynamic_async_success_callbacks=[shadow, RecordingLogger(), guardrail], ) logging_obj.update_messages([{"role": "user", "content": "logged input"}]) logging_obj.update_environment_variables(litellm_params={"metadata": metadata}, optional_params={}) logging_obj.shadow_eval_request_snapshot = snapshot payload: Final = { - "id": "private-snapshot", "call_type": "anthropic_messages", "metadata": metadata, - "model_group": "test-model", "model_parameters": {}, + "id": "private-snapshot", + "call_type": "anthropic_messages", + "metadata": metadata, + "model_group": "test-model", + "model_parameters": {}, } await logging_obj.async_success_handler(result=ModelResponse(), standard_logging_object=payload) @@ -3495,6 +3520,21 @@ def test_get_request_tags_from_metadata_and_litellm_metadata(): assert "User-Agent: litellm/1.0.0" in tags +@pytest.mark.parametrize("unusable_metadata_tags", [123, "tag", {"tag": True}, []]) +def test_get_request_tags_falls_back_to_litellm_metadata_when_metadata_tags_are_unusable(unusable_metadata_tags): + from litellm.litellm_core_utils.litellm_logging import StandardLoggingPayloadSetup + + tags = StandardLoggingPayloadSetup._get_request_tags( + litellm_params={ + "metadata": {"tags": unusable_metadata_tags}, + "litellm_metadata": {"tags": ["litellm-metadata-tag"]}, + }, + proxy_server_request={}, + ) + + assert tags == ["litellm-metadata-tag"] + + def test_get_request_tags_does_not_mutate_original_tags(): """ Test that _get_request_tags does not mutate the original tags list in metadata. @@ -3647,6 +3687,73 @@ def test_get_extra_header_tags(): delattr(litellm, "extra_spend_tag_headers") +def test_get_extra_header_tags_matches_title_case_config_with_lowercase_request_header( + monkeypatch: pytest.MonkeyPatch, +) -> None: + monkeypatch.setattr(litellm, "extra_spend_tag_headers", ["X-Org-Id"], raising=False) + + assert StandardLoggingPayloadSetup._get_extra_header_tags( + proxy_server_request={"headers": {"x-org-id": "org_1"}} + ) == ["X-Org-Id: org_1"] + + +def test_get_extra_header_tags_matches_mixed_case_request_header_with_lowercase_config( + monkeypatch: pytest.MonkeyPatch, +) -> None: + monkeypatch.setattr(litellm, "extra_spend_tag_headers", ["x-customer-id"], raising=False) + + assert StandardLoggingPayloadSetup._get_extra_header_tags( + proxy_server_request={"headers": {"X-Customer-Id": "v"}} + ) == ["x-customer-id: v"] + + +def test_get_extra_header_tags_keeps_lowercase_label( + monkeypatch: pytest.MonkeyPatch, +) -> None: + monkeypatch.setattr(litellm, "extra_spend_tag_headers", ["x-customer-id"], raising=False) + + assert StandardLoggingPayloadSetup._get_extra_header_tags( + proxy_server_request={"headers": {"x-customer-id": "v"}} + ) == ["x-customer-id: v"] + + +def test_get_extra_header_tags_returns_none_for_absent_or_empty_header( + monkeypatch: pytest.MonkeyPatch, +) -> None: + monkeypatch.setattr(litellm, "extra_spend_tag_headers", ["x-org-id"], raising=False) + + assert StandardLoggingPayloadSetup._get_extra_header_tags(proxy_server_request={"headers": {}}) is None + assert StandardLoggingPayloadSetup._get_extra_header_tags( + proxy_server_request={"headers": {"x-org-id": ""}} + ) is None + + +def test_get_extra_header_tags_preserves_configured_header_order( + monkeypatch: pytest.MonkeyPatch, +) -> None: + monkeypatch.setattr(litellm, "extra_spend_tag_headers", ["x-second", "x-first"], raising=False) + + assert StandardLoggingPayloadSetup._get_extra_header_tags( + proxy_server_request={"headers": {"x-first": "1", "x-second": "2"}} + ) == ["x-second: 2", "x-first: 1"] + + +def test_get_request_tags_includes_extra_header_tag_with_user_agent_tags( + monkeypatch: pytest.MonkeyPatch, +) -> None: + monkeypatch.setattr(litellm, "extra_spend_tag_headers", ["X-Org-Id"], raising=False) + + assert StandardLoggingPayloadSetup.get_request_tags( + litellm_params={}, + proxy_server_request={ + "headers": { + "user-agent": "litellm/1.0", + "x-org-id": "org_1", + } + }, + ) == ["User-Agent: litellm", "User-Agent: litellm/1.0", "X-Org-Id: org_1"] + + def test_response_cost_calculator_with_response_cost_in_hidden_params(logging_obj): from litellm import Router @@ -3816,7 +3923,9 @@ def test_sentry_event_scrubber_initialization(monkeypatch): call_args = mock_init.call_args[1] assert call_args["send_default_pii"] is False assert call_args["event_scrubber"].recursive is True - assert {name.lower() for name in SENTRY_PII_DENYLIST} <= {name.lower() for name in call_args["event_scrubber"].denylist} + assert {name.lower() for name in SENTRY_PII_DENYLIST} <= { + name.lower() for name in call_args["event_scrubber"].denylist + } assert call_args["before_send"] is call_args["before_send_transaction"] @@ -3833,7 +3942,9 @@ def test_sentry_send_default_pii_opt_in(monkeypatch): call_args = mock_init.call_args[1] assert call_args["send_default_pii"] is True - assert not {name.lower() for name in SENTRY_PII_DENYLIST} & {name.lower() for name in call_args["event_scrubber"].denylist} + assert not {name.lower() for name in SENTRY_PII_DENYLIST} & { + name.lower() for name in call_args["event_scrubber"].denylist + } def test_get_masked_values(): @@ -5103,12 +5214,10 @@ def test_reported_cost_respects_configured_pricing_and_additional_charges( else {} ), } - } - } - ) - logging_obj.model_call_details.update( - {"additional_response_cost": additional_cost, "cache_hit": cache_hit} + }, + }, ) + logging_obj.model_call_details.update({"additional_response_cost": additional_cost, "cache_hit": cache_hit}) logging_obj._provider_reported_cost = reported_cost response: Final = ModelResponse( model=pricing_model, @@ -6548,7 +6657,7 @@ def test_handle_anthropic_messages_response_logging_keeps_the_served_response_id def test_handle_anthropic_messages_response_logging_bills_the_bridged_chat_completion_not_the_served_body(): """A chat deployment answers /v1/messages through the chat bridge. The Anthropic body served to the caller has no reasoning token field, so the spend row must come from the recorded chat completion.""" - from litellm.llms.anthropic.pass_through.adapters.transformation import LiteLLMAnthropicMessagesAdapter + from litellm.llms.anthropic.messages.adapters.transformation import LiteLLMAnthropicMessagesAdapter from litellm.types.utils import CompletionTokensDetailsWrapper, Usage chat_completion = ModelResponse( @@ -7055,8 +7164,11 @@ async def test_background_interaction_completion_rebills_after_in_progress_succe class SyncRecorder(CustomLogger): def log_success_event( - self, kwargs: dict[str, object], response_obj: object, - start_time: dt.datetime, end_time: dt.datetime, + self, + kwargs: dict[str, object], + response_obj: object, + start_time: dt.datetime, + end_time: dt.datetime, ) -> None: events.put((response_obj, kwargs.get("response_cost"))) logged.set() @@ -7089,11 +7201,11 @@ async def test_background_interaction_completion_rebills_after_in_progress_succe assert logging_obj.model_call_details["response_cost"] > 0 assert logging_obj.model_call_details["standard_logging_object"]["total_tokens"] == 175 - assert events.qsize() == 2 assert events.get_nowait() == (in_progress, None) assert events.get_nowait() == (completed, logging_obj.model_call_details["response_cost"]) + @pytest.mark.asyncio async def test_background_interaction_completion_prices_the_settled_body_itself(): """ @@ -8127,7 +8239,9 @@ def test_debugging_log_with_json_logs_tolerates_missing_headers(logging_obj, mon logging_obj.litellm_request_debug = True with patch("litellm.litellm_core_utils.litellm_logging.verbose_logger.warning") as warning: - logging_obj._print_llm_call_debugging_log(api_base="https://api.openai.com/v1", headers=None, additional_args={}) + logging_obj._print_llm_call_debugging_log( + api_base="https://api.openai.com/v1", headers=None, additional_args={} + ) assert "https://api.openai.com/v1" in warning.call_args.kwargs["extra"]["api_base"] @@ -10378,8 +10492,13 @@ class TestAzurePTUSpilloverCost: assert payload is not None model_map_value: Final = payload["model_map_information"]["model_map_value"] assert model_map_value is not None - assert model_map_value["input_cost_per_token"] == litellm.model_cost[self.SERVED_MODEL]["input_cost_per_token"] - assert model_map_value["output_cost_per_token"] == litellm.model_cost[self.SERVED_MODEL]["output_cost_per_token"] + assert ( + model_map_value["input_cost_per_token"] == litellm.model_cost[self.SERVED_MODEL]["input_cost_per_token"] + ) + assert ( + model_map_value["output_cost_per_token"] + == litellm.model_cost[self.SERVED_MODEL]["output_cost_per_token"] + ) assert response_cost == pytest.approx( 100 * model_map_value["input_cost_per_token"] + 50 * model_map_value["output_cost_per_token"] ) @@ -10494,8 +10613,6 @@ def test_get_assembled_streaming_response_bills_a_provider_reported_usage_cost() assert logging_obj.response_cost_calculator(result=assembled) == 0.0042 - - def test_response_cost_calculator_prices_terminal_responses_event_from_its_response(): logging_obj: Final = _responses_stream_logging_obj() inner_response: Final = ResponsesAPIResponse( @@ -10725,9 +10842,7 @@ def test_standard_logging_retries(): ] ) - with patch.object( - customHandler, "log_failure_event", new=MagicMock() - ) as mock_client: + with patch.object(customHandler, "log_failure_event", new=MagicMock()) as mock_client: try: router.completion( model="gpt-3.5-turbo", @@ -10739,19 +10854,10 @@ def test_standard_logging_retries(): pass assert mock_client.call_count == 2 + assert mock_client.call_args_list[0].kwargs["kwargs"]["standard_logging_object"]["trace_id"] is not None assert ( - mock_client.call_args_list[0].kwargs["kwargs"]["standard_logging_object"][ - "trace_id" - ] - is not None - ) - assert ( - mock_client.call_args_list[0].kwargs["kwargs"]["standard_logging_object"][ - "trace_id" - ] - == mock_client.call_args_list[1].kwargs["kwargs"][ - "standard_logging_object" - ]["trace_id"] + mock_client.call_args_list[0].kwargs["kwargs"]["standard_logging_object"]["trace_id"] + == mock_client.call_args_list[1].kwargs["kwargs"]["standard_logging_object"]["trace_id"] ) @@ -11018,9 +11124,7 @@ def test_signoz_dispatch_requires_an_endpoint(monkeypatch): custom_logger_init_args={}, ) assert created is None - assert not [ - cb for cb in logging_module._in_memory_loggers if getattr(cb, "callback_name", None) == "signoz" - ] + assert not [cb for cb in logging_module._in_memory_loggers if getattr(cb, "callback_name", None) == "signoz"] finally: logging_module._in_memory_loggers.clear() monkeypatch.delenv("LITELLM_OTEL_V2", raising=False) @@ -11162,7 +11266,11 @@ def test_standard_logging_payload_reports_the_deployment_entry_the_request_was_b } } logging_obj.update_environment_variables( - model="gpt-5.4-nano", user="", optional_params={}, litellm_params=litellm_params, custom_llm_provider="openai" + model="gpt-5.4-nano", + user="", + optional_params={}, + litellm_params=litellm_params, + custom_llm_provider="openai", ) response: Final = ModelResponse( model="gpt-5.4-nano", @@ -11474,10 +11582,7 @@ def test_enterprise_alerting_loggers_falls_back_without_disabling_callback_contr ) logging_module._enterprise_alerting_loggers.cache_clear() for module_name in tuple(sys.modules): - if any( - module_name == prefix or module_name.startswith(f"{prefix}.") - for prefix in module_prefixes - ): + if any(module_name == prefix or module_name.startswith(f"{prefix}.") for prefix in module_prefixes): monkeypatch.delitem(sys.modules, module_name, raising=False) monkeypatch.setattr(sys, "meta_path", [BlockPagerDutyFinder(), *sys.meta_path]) @@ -11597,13 +11702,16 @@ def _vcr_outcome_gate(request, vcr): yield record_vcr_outcome(request, vcr) + @pytest_asyncio.fixture(loop_scope="function") async def drain_logging_worker(isolate_litellm_state: None) -> AsyncIterator[None]: yield await asyncio.wait_for(GLOBAL_LOGGING_WORKER.flush(), timeout=LOGGING_WORKER_DRAIN_TIMEOUT_SECONDS) + LOGGING_WORKER_DRAIN_TIMEOUT_SECONDS: Final = LOGGING_WORKER_MAX_TIME_PER_COROUTINE + 5.0 + @pytest.fixture(scope="function") def isolate_litellm_state(): """ @@ -11641,6 +11749,7 @@ def isolate_litellm_state(): if attr in _DEFAULTS: setattr(litellm, attr, _DEFAULTS[attr]) + _LIST_ATTRS = ( "callbacks", "success_callback", @@ -11668,6 +11777,7 @@ _SCALAR_ATTRS = ( _DEFAULTS: dict = {} + @pytest.fixture(scope="module") def setup_and_teardown(): """ @@ -11690,6 +11800,7 @@ def setup_and_teardown(): litellm.in_memory_llm_clients_cache.flush_cache() yield + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") @pytest.mark.parametrize( "response_obj,expected_values", @@ -11737,6 +11848,7 @@ def test_get_usage(response_obj, expected_values): assert usage.completion_tokens == expected_values[1] assert usage.total_tokens == expected_values[2] + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_get_usage_from_image_generation_response(): """ @@ -11784,6 +11896,7 @@ def test_get_usage_from_image_generation_response(): assert usage.completion_tokens_details.image_tokens == 272 assert usage.completion_tokens_details.text_tokens == 100 + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_get_additional_headers(): additional_headers = { @@ -11824,10 +11937,12 @@ def test_get_additional_headers(): assert additional_logging_headers.get("llm_provider-request-id") == "req_01F6CycZZPSHKRCCctcS1Vto" assert additional_logging_headers.get("llm_provider-anthropic-ratelimit-requests-reset") == "2024-10-29T23:57:40Z" + def all_fields_present(standard_logging_metadata: StandardLoggingMetadata): for field in StandardLoggingMetadata.__annotations__.keys(): assert field in standard_logging_metadata + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") @pytest.mark.parametrize( "metadata_key, metadata_value", @@ -11859,6 +11974,7 @@ def test_get_standard_logging_metadata(metadata_key, metadata_value): # Assert that the specific metadata field is set correctly assert standard_logging_metadata[metadata_key] == metadata_value + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_get_standard_logging_metadata_user_api_key_hash(): valid_hash = "a" * 64 # 64 character string @@ -11866,6 +11982,7 @@ def test_get_standard_logging_metadata_user_api_key_hash(): result = StandardLoggingPayloadSetup.get_standard_logging_metadata(metadata) assert result["user_api_key_hash"] == valid_hash + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_get_standard_logging_metadata_invalid_user_api_key(): invalid_hash = "not_a_valid_hash" @@ -11874,6 +11991,7 @@ def test_get_standard_logging_metadata_invalid_user_api_key(): all_fields_present(result) assert result["user_api_key_hash"] is None + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_get_standard_logging_metadata_non_string_user_api_key(): """Non-string user_api_key should not be set as user_api_key_hash.""" @@ -11882,6 +12000,7 @@ def test_get_standard_logging_metadata_non_string_user_api_key(): all_fields_present(result) assert result["user_api_key_hash"] is None + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_get_standard_logging_metadata_none_user_api_key(): """None user_api_key should not be set as user_api_key_hash.""" @@ -11890,6 +12009,7 @@ def test_get_standard_logging_metadata_none_user_api_key(): all_fields_present(result) assert result["user_api_key_hash"] is None + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_get_standard_logging_metadata_invalid_keys(): metadata = { @@ -11903,6 +12023,7 @@ def test_get_standard_logging_metadata_invalid_keys(): assert "invalid_key" not in result assert "another_invalid_key" not in result + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_cleanup_timestamps(): """Test cleanup_timestamps with different input types""" @@ -11937,6 +12058,7 @@ def test_cleanup_timestamps(): with pytest.raises(ValueError, match="start_time is required, got=invalid of type "): StandardLoggingPayloadSetup.cleanup_timestamps("invalid", end_float, completion_float) + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_get_model_cost_information(): """Test get_model_cost_information with different inputs""" @@ -11969,6 +12091,7 @@ def test_get_model_cost_information(): # assert all fields in StandardLoggingModelInformation are present assert all(field in result for field in StandardLoggingModelInformation.__annotations__) + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_get_model_cost_information_custom_pricing_uses_base_model(): result = StandardLoggingPayloadSetup.get_model_cost_information( @@ -11980,6 +12103,7 @@ def test_get_model_cost_information_custom_pricing_uses_base_model(): assert result["model_map_value"] is not None assert result["model_map_key"] != "invoke_test_claude" + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_standard_logging_payload_uses_deployment_when_no_base_model(): """metadata["deployment"] is used for cost-map lookup when base_model is not set.""" @@ -12037,6 +12161,7 @@ def test_standard_logging_payload_uses_deployment_when_no_base_model(): assert payload["model_map_information"]["model_map_value"] is not None assert payload["model_map_information"]["model_map_key"] != "invoke_test_claude" + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_get_hidden_params(): """Test get_hidden_params with different inputs""" @@ -12072,6 +12197,7 @@ def test_get_hidden_params(): # assert all fields in StandardLoggingHiddenParams are present assert all(field in result for field in StandardLoggingHiddenParams.__annotations__) + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_get_final_response_obj(): """Test get_final_response_obj with different input types and redaction scenarios""" @@ -12103,6 +12229,7 @@ def test_get_final_response_obj(): # Reset litellm.turn_off_message_logging to its original value litellm.turn_off_message_logging = False + def testget_standard_logging_payload_trace_id(): """Test get_standard_logging_payload_trace_id with different input scenarios""" # Test case 1: When litellm_trace_id is provided in litellm_params @@ -12140,6 +12267,7 @@ def testget_standard_logging_payload_trace_id(): assert result == "12345" assert isinstance(result, str) + def testget_standard_logging_payload_trace_id_prioritizes_trace_id_when_flag_on(monkeypatch): """With request_correlation_in_logs on, an explicit litellm_trace_id wins over litellm_session_id.""" from unittest.mock import MagicMock @@ -12154,6 +12282,7 @@ def testget_standard_logging_payload_trace_id_prioritizes_trace_id_when_flag_on( ) assert result == "the-trace-id" + def testget_standard_logging_payload_trace_id_prioritizes_session_id_when_flag_off(monkeypatch): """With request_correlation_in_logs off (default), legacy behavior is preserved: litellm_session_id still wins over litellm_trace_id.""" @@ -12169,6 +12298,7 @@ def testget_standard_logging_payload_trace_id_prioritizes_session_id_when_flag_o ) assert result == "the-session-id" + def testget_standard_logging_payload_session_id_when_flag_on(monkeypatch): """Test get_standard_logging_payload_session_id with different input scenarios, flag enabled""" from unittest.mock import MagicMock @@ -12221,6 +12351,7 @@ def testget_standard_logging_payload_session_id_when_flag_on(monkeypatch): ) assert result == "" + def testget_standard_logging_payload_session_id_empty_when_flag_off(monkeypatch): """When request_correlation_in_logs is off (default), session_id is always empty, even if litellm_session_id was explicitly supplied - preserves the pre-existing @@ -12237,6 +12368,7 @@ def testget_standard_logging_payload_session_id_empty_when_flag_off(monkeypatch) ) assert result == "" + @pytest.fixture def restore_verbose_logger_level() -> Iterator[None]: original_level: Final = verbose_logger.level @@ -12279,6 +12411,7 @@ def test_truncate_standard_logging_payload(): assert len(str(truncated["response"])) < 10_500 assert len(str(truncated["error_str"])) < 10_500 + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_truncate_standard_logging_payload_keeps_a_partial_payload_intact(): """A payload built with only some of its fields comes back with exactly those keys and values""" @@ -12287,12 +12420,14 @@ def test_truncate_standard_logging_payload_keeps_a_partial_payload_intact(): assert _custom_logger.truncate_standard_logging_payload_content(partial_payload) == partial_payload + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_strip_trailing_slash(): common_api_base = "https://api.test.com" assert StandardLoggingPayloadSetup.strip_trailing_slash(common_api_base + "/") == common_api_base assert StandardLoggingPayloadSetup.strip_trailing_slash(common_api_base) == common_api_base + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_get_error_information(): """Test get_error_information with different types of exceptions""" @@ -12329,6 +12464,7 @@ def test_get_error_information(): assert result["llm_provider"] == "openai" assert result["error_message"] == "litellm.RateLimitError: Test error" + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_get_response_time(): """Test get_response_time with different streaming scenarios""" @@ -12364,6 +12500,7 @@ def test_get_response_time(): # For streaming, should return completion_start_time - start_time assert response_time == 2.0 + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") @pytest.mark.parametrize( "metadata, expected_requester_metadata", @@ -12386,6 +12523,7 @@ def test_standard_logging_metadata_requester_metadata(metadata, expected_request result = StandardLoggingPayloadSetup.get_standard_logging_metadata(metadata) assert result["requester_metadata"] == expected_requester_metadata + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_cost_breakdown_in_standard_logging_payload(): """ @@ -12475,6 +12613,7 @@ def test_cost_breakdown_in_standard_logging_payload(): print("✅ Cost breakdown test passed!") + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_cost_breakdown_missing_in_standard_logging_payload(): """ @@ -12535,6 +12674,7 @@ def test_cost_breakdown_missing_in_standard_logging_payload(): print("✅ Cost breakdown missing test passed!") + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") @pytest.mark.parametrize( "use_combined_usage_object", @@ -12622,6 +12762,7 @@ def test_usage_dict_roundtrip_in_payload(use_combined_usage_object): assert usage_obj["completion_tokens"] == 58 assert usage_obj["total_tokens"] == 100 + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_standard_logging_payload_uses_actual_model_for_azure_router(): from litellm.litellm_core_utils.litellm_logging import ( @@ -12670,6 +12811,7 @@ def test_standard_logging_payload_uses_actual_model_for_azure_router(): assert payload is not None assert payload["model"] == "azure_ai/gpt-5-nano-2025-08-07" + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_standard_logging_payload_uses_actual_model_for_azure_router_with_underscore(): from litellm.litellm_core_utils.litellm_logging import ( @@ -12718,6 +12860,7 @@ def test_standard_logging_payload_uses_actual_model_for_azure_router_with_unders assert payload is not None assert payload["model"] == "azure_ai/gpt-5-nano-2025-08-07" + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_merge_litellm_metadata_basic(): """ @@ -12749,6 +12892,7 @@ def test_merge_litellm_metadata_basic(): assert result["model_info"] == {"id": "model-123"} assert result["tags"] == ["tag1", "tag2"] + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_merge_litellm_metadata_precedence(): """ @@ -12775,6 +12919,7 @@ def test_merge_litellm_metadata_precedence(): # litellm_metadata values should only be included if not in metadata assert result["model_group"] == "gpt-4-group" + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_merge_litellm_metadata_skip_non_serializable(): """ @@ -12807,6 +12952,7 @@ def test_merge_litellm_metadata_skip_non_serializable(): assert result["safe_field"] == "safe_value" assert result["model_group"] == "gpt-4-group" + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_merge_litellm_metadata_empty_params(): """ @@ -12842,6 +12988,7 @@ def test_merge_litellm_metadata_empty_params(): result = StandardLoggingPayloadSetup.merge_litellm_metadata(litellm_params) assert result == {} + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_merge_litellm_metadata_bedrock_passthrough_scenario(): """ @@ -12901,8 +13048,10 @@ def test_merge_litellm_metadata_bedrock_passthrough_scenario(): # Verify total number of fields (9 user fields + 4 model fields = 13) assert len(result) == 13 + service_logger = ServiceLogging() + def setup_logging(): return Logging( model="gpt-5.5", @@ -12992,6 +13141,7 @@ def test_get_callback_name(): # Test string callback assert logging._get_callback_name("callback_string") == "callback_string" + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_is_internal_litellm_proxy_callback(): """ @@ -13012,6 +13162,7 @@ def test_is_internal_litellm_proxy_callback(): # Test string callback assert logging._is_internal_litellm_proxy_callback("callback_string") == False + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_should_run_sync_callbacks_for_async_calls(): """ @@ -13037,6 +13188,7 @@ def test_should_run_sync_callbacks_for_async_calls(): litellm.success_callback = [PROXY_MaxIterationsHandler] assert logging._should_run_sync_callbacks_for_async_calls() == False + @pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown") def test_remove_internal_litellm_callbacks(): logging = setup_logging() @@ -13058,6 +13210,7 @@ def test_remove_internal_litellm_callbacks(): assert PROXY_MaxIterationsHandler not in filtered assert PROXY_CacheControlCheck not in filtered + @pytest.mark.asyncio async def test_background_interaction_completion_logs_while_in_progress_handler_is_parked(monkeypatch): """ @@ -13160,14 +13313,9 @@ class CompletionCustomHandler( assert metadata_value is None or isinstance(metadata_value, dict) if metadata_value is not None: if litellm.turn_off_message_logging is True: - assert ( - metadata_value["raw_request"] - is LiteLLMCommonStrings.redacted_by_litellm.value - ) + assert metadata_value["raw_request"] is LiteLLMCommonStrings.redacted_by_litellm.value else: - assert "raw_request" not in metadata_value or isinstance( - metadata_value["raw_request"], str - ) + assert "raw_request" not in metadata_value or isinstance(metadata_value["raw_request"], str) except Exception: print(f"Assertion Error: {traceback.format_exc()}") self.errors.append(traceback.format_exc()) @@ -13216,23 +13364,18 @@ class CompletionCustomHandler( assert isinstance(response_obj, litellm.ModelResponseStream) ## KWARGS assert isinstance(kwargs["model"], str) - assert isinstance(kwargs["messages"], list) and isinstance( - kwargs["messages"][0], dict - ) + assert isinstance(kwargs["messages"], list) and isinstance(kwargs["messages"][0], dict) assert isinstance(kwargs["optional_params"], dict) assert isinstance(kwargs["litellm_params"], dict) assert isinstance(kwargs["start_time"], (datetime, type(None))) assert isinstance(kwargs["stream"], bool) assert isinstance(kwargs["user"], (str, type(None))) - assert ( - isinstance(kwargs["input"], list) - and isinstance(kwargs["input"][0], dict) - ) or isinstance(kwargs["input"], (dict, str)) + assert (isinstance(kwargs["input"], list) and isinstance(kwargs["input"][0], dict)) or isinstance( + kwargs["input"], (dict, str) + ) assert isinstance(kwargs["api_key"], (str, type(None))) assert ( - isinstance( - kwargs["original_response"], (str, litellm.CustomStreamWrapper) - ) + isinstance(kwargs["original_response"], (str, litellm.CustomStreamWrapper)) or inspect.isasyncgen(kwargs["original_response"]) or inspect.iscoroutine(kwargs["original_response"]) ) @@ -13265,9 +13408,7 @@ class CompletionCustomHandler( ) ## KWARGS assert isinstance(kwargs["model"], str) - assert isinstance(kwargs["messages"], list) and isinstance( - kwargs["messages"][0], dict - ) + assert isinstance(kwargs["messages"], list) and isinstance(kwargs["messages"][0], dict) assert isinstance(kwargs["optional_params"], dict) assert isinstance(kwargs["litellm_params"], dict) assert isinstance(kwargs["litellm_params"]["api_base"], str) @@ -13277,10 +13418,7 @@ class CompletionCustomHandler( assert isinstance(kwargs["user"], (str, type(None))) assert ( isinstance(kwargs["input"], list) - and ( - isinstance(kwargs["input"][0], dict) - or isinstance(kwargs["input"][0], str) - ) + and (isinstance(kwargs["input"][0], dict) or isinstance(kwargs["input"][0], str)) ) or isinstance(kwargs["input"], (dict, str)) assert isinstance(kwargs["api_key"], (str, type(None))) assert isinstance( @@ -13308,9 +13446,7 @@ class CompletionCustomHandler( assert response_obj == None ## KWARGS assert isinstance(kwargs["model"], str) - assert isinstance(kwargs["messages"], list) and isinstance( - kwargs["messages"][0], dict - ) + assert isinstance(kwargs["messages"], list) and isinstance(kwargs["messages"][0], dict) assert isinstance(kwargs["optional_params"], dict) assert isinstance(kwargs["litellm_params"], dict) @@ -13318,15 +13454,12 @@ class CompletionCustomHandler( assert isinstance(kwargs["start_time"], (datetime, type(None))) assert isinstance(kwargs["stream"], bool) assert isinstance(kwargs["user"], (str, type(None))) - assert ( - isinstance(kwargs["input"], list) - and isinstance(kwargs["input"][0], dict) - ) or isinstance(kwargs["input"], (dict, str)) + assert (isinstance(kwargs["input"], list) and isinstance(kwargs["input"][0], dict)) or isinstance( + kwargs["input"], (dict, str) + ) assert isinstance(kwargs["api_key"], (str, type(None))) assert ( - isinstance( - kwargs["original_response"], (str, litellm.CustomStreamWrapper) - ) + isinstance(kwargs["original_response"], (str, litellm.CustomStreamWrapper)) or kwargs["original_response"] == None ) assert isinstance(kwargs["additional_args"], (dict, type(None))) @@ -13344,9 +13477,7 @@ class CompletionCustomHandler( assert isinstance(messages, list) and isinstance(messages[0], dict) ## KWARGS assert isinstance(kwargs["model"], str) - assert isinstance(kwargs["messages"], list) and isinstance( - kwargs["messages"][0], dict - ) + assert isinstance(kwargs["messages"], list) and isinstance(kwargs["messages"][0], dict) assert isinstance(kwargs["optional_params"], dict) assert isinstance(kwargs["litellm_params"], dict) assert isinstance(kwargs["start_time"], (datetime, type(None))) @@ -13358,9 +13489,7 @@ class CompletionCustomHandler( async def async_log_success_event(self, kwargs, response_obj, start_time, end_time): try: - print( - "in async_log_success_event", kwargs, response_obj, start_time, end_time - ) + print("in async_log_success_event", kwargs, response_obj, start_time, end_time) self.states.append("async_success") ## START TIME assert isinstance(start_time, datetime) @@ -13389,9 +13518,7 @@ class CompletionCustomHandler( assert isinstance(kwargs["input"], (list, dict, str)) assert isinstance(kwargs["api_key"], (str, type(None))) assert ( - isinstance( - kwargs["original_response"], (str, litellm.CustomStreamWrapper) - ) + isinstance(kwargs["original_response"], (str, litellm.CustomStreamWrapper)) or inspect.isasyncgen(kwargs["original_response"]) or inspect.iscoroutine(kwargs["original_response"]) ) @@ -13423,9 +13550,7 @@ class CompletionCustomHandler( assert isinstance(kwargs["input"], (list, str, dict)) assert isinstance(kwargs["api_key"], (str, type(None))) assert ( - isinstance( - kwargs["original_response"], (str, litellm.CustomStreamWrapper) - ) + isinstance(kwargs["original_response"], (str, litellm.CustomStreamWrapper)) or inspect.isasyncgen(kwargs["original_response"]) or inspect.iscoroutine(kwargs["original_response"]) or kwargs["original_response"] == None @@ -13566,3 +13691,87 @@ def test_legacy_s3_logs_a_streamed_anthropic_messages_call_handed_off_from_the_a assert s3_writer.log_event.call_count == expected_s3_writes if expected_s3_writes: assert s3_writer.log_event.call_args.kwargs["response_obj"] is complete_response + + +_GO_PRICED_MESSAGE: Final = { + "id": "msg_go", + "type": "message", + "role": "assistant", + "model": "claude-haiku-5-5", + "content": [{"type": "text", "text": "answer"}], + "stop_reason": "end_turn", + "stop_sequence": None, + "usage": {"input_tokens": 1200, "output_tokens": 300, "cost": 0, "opencode": {"list_cost": 0.00412}}, +} + + +@pytest.mark.parametrize( + ("usage", "expected_header"), + ( + ({"input_tokens": 1200, "output_tokens": 300, "cost": 0, "opencode": {"list_cost": 0.00412}}, 0.00412), + ({"input_tokens": 1200, "output_tokens": 300}, None), + ), + ids=("list-cost-reported", "no-list-cost-keeps-the-price-map"), +) +def test_native_messages_body_carries_the_reported_list_cost_into_the_priced_response(usage, expected_header): + logging_obj = _anthropic_messages_logging_obj() + logging_obj.stream = False + logging_obj.optional_params = {} + logging_obj.model_call_details["custom_llm_provider"] = "opencode_go" + + priced = logging_obj.billable_result({**_GO_PRICED_MESSAGE, "usage": usage}) + + assert isinstance(priced, ModelResponse) + headers = priced._hidden_params.get("additional_headers") or {} + assert headers.get("llm_provider-x-litellm-response-cost") == expected_header + + +def test_record_native_bedrock_guardrail_bills_when_the_metadata_is_none() -> None: + import datetime + + from litellm.litellm_core_utils.litellm_logging import Logging + + logging_obj = Logging( + model="bedrock/anthropic.claude-sonnet-4-5-20250929-v1:0", + messages=[{"role": "user", "content": "hello"}], + stream=False, + call_type="completion", + start_time=datetime.datetime.now(), + litellm_call_id="call-none-metadata", + function_id="fn", + ) + logging_obj.model_call_details["litellm_params"] = {"metadata": None} + trace = {"guardrail": {"inputAssessment": {"gid": {"invocationMetrics": {"usage": {"contentPolicyUnits": 2}}}}}} + + logging_obj.record_native_bedrock_guardrail({"trace": trace}) + + (entry,) = logging_obj.model_call_details["litellm_params"]["metadata"]["standard_logging_guardrail_information"] + assert entry["guardrail_usage"] == {"contentPolicyUnits": 2} + assert entry["guardrail_cost"] > 0 + + +def test_record_native_bedrock_guardrail_bills_nothing_for_a_response_served_from_cache() -> None: + import datetime + + from litellm.litellm_core_utils.litellm_logging import Logging + + logging_obj = Logging( + model="bedrock/anthropic.claude-sonnet-4-5-20250929-v1:0", + messages=[{"role": "user", "content": "hello"}], + stream=False, + call_type="completion", + start_time=datetime.datetime.now(), + litellm_call_id="call-cache-hit", + function_id="fn", + ) + logging_obj.model_call_details["litellm_params"] = {"metadata": {}} + trace = {"guardrail": {"inputAssessment": {"gid": {"invocationMetrics": {"usage": {"contentPolicyUnits": 2}}}}}} + cached = litellm.ModelResponse(choices=[{"message": {"role": "assistant", "content": "hi"}}], model="x") + setattr(cached, "trace", trace) + cached._hidden_params = {"cache_hit": True} + + logging_obj.record_native_bedrock_guardrail(cached) + logging_obj.model_call_details["cache_hit"] = True + logging_obj.record_native_bedrock_guardrail({"trace": trace}) + + assert "standard_logging_guardrail_information" not in logging_obj.model_call_details["litellm_params"]["metadata"] diff --git a/tests/unit/litellm_core_utils/test_redact_messages.py b/tests/unit/litellm_core_utils/test_redact_messages.py index 6a734ca3b70..5b64e42d8a8 100644 --- a/tests/unit/litellm_core_utils/test_redact_messages.py +++ b/tests/unit/litellm_core_utils/test_redact_messages.py @@ -26,15 +26,16 @@ import litellm from litellm.constants import LOGGING_WORKER_MAX_TIME_PER_COROUTINE from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER -from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler from litellm.litellm_core_utils.redact_messages import ( _redact_responses_api_output, _redacted_responses_api_response, perform_redaction, redacted_model_call_details_for_custom_logger, + redacted_response_obj_for_custom_logger, redacted_standard_logging_payload, should_redact_message_logging, ) +from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler from litellm.responses.main import mock_responses_api_response from litellm.types.router import BaselineRouteStamp from litellm.types.utils import ( @@ -176,7 +177,11 @@ def test_redaction_hides_a_compaction_summary_in_responses_api_output(shape: str object="response", status="completed", output=[ - {"type": "compaction", "id": "cmp_1", "encrypted_content": json.dumps({"type": "compaction", "content": SECRET})} + { + "type": "compaction", + "id": "cmp_1", + "encrypted_content": json.dumps({"type": "compaction", "content": SECRET}), + } ], ) result: Final = response if shape == "object" else response.model_dump() @@ -2041,3 +2046,32 @@ async def test_redaction_with_metadata_completion_api(): response = standard_logging_payload["response"] assert response["choices"][0]["message"]["content"] == "redacted-by-litellm" assert standard_logging_payload["messages"][0]["content"] == "redacted-by-litellm" + + +def test_perform_redaction_strips_the_matched_text_from_the_bedrock_guardrail_traces() -> None: + finding = { + "guardrail": { + "inputAssessment": { + "gid": { + "sensitiveInformationPolicy": { + "piiEntities": [{"type": "US_SSN", "match": "123-45-6789", "action": "ANONYMIZED"}] + } + } + } + } + } + response = litellm.ModelResponse(choices=[{"message": {"role": "assistant", "content": "hi"}}], model="x") + setattr(response, "trace", copy.deepcopy(finding)) + setattr(response, "amazon-bedrock-trace", copy.deepcopy(finding)) + opted_out: Final = CustomLogger(message_logging=False) + + redacted: Final = redacted_response_obj_for_custom_logger(response, opted_out) + redacted_dict: Final = redacted_response_obj_for_custom_logger( + {"choices": [], "trace": copy.deepcopy(finding)}, opted_out + ) + + assert isinstance(redacted, litellm.ModelResponse) + assert "123-45-6789" not in redacted.model_dump_json() + assert "US_SSN" in redacted.model_dump_json(), "the finding stays, only its matched text goes" + assert "123-45-6789" not in str(redacted_dict) + assert "123-45-6789" in response.model_dump_json(), "the caller's own response is not redacted" diff --git a/tests/unit/litellm_core_utils/test_streaming_chunk_builder_utils.py b/tests/unit/litellm_core_utils/test_streaming_chunk_builder_utils.py index 5c56245cf33..59946d54dc7 100644 --- a/tests/unit/litellm_core_utils/test_streaming_chunk_builder_utils.py +++ b/tests/unit/litellm_core_utils/test_streaming_chunk_builder_utils.py @@ -8,17 +8,19 @@ import httpx import pytest import respx - import litellm from litellm import ChatCompletionUsageBlock, stream_chunk_builder -from litellm.types.utils import GenericStreamingChunk -from litellm.litellm_core_utils.streaming_chunk_builder_utils import ChunkProcessor, stream_chunk_builder_text_completion +from litellm.litellm_core_utils.streaming_chunk_builder_utils import ( + ChunkProcessor, + stream_chunk_builder_text_completion, +) from litellm.llms.anthropic.chat.handler import ModelResponseIterator from litellm.types.utils import ( ChatCompletionDeltaToolCall, ChatCompletionMessageToolCall, Delta, Function, + GenericStreamingChunk, ModelResponseStream, PromptTokensDetails, ServerToolUse, @@ -196,11 +198,7 @@ def test_get_combined_thinking_content_preserves_interleaved_blocks(): } ] ), - make_chunk( - thinking_blocks=[ - {"type": "thinking", "thinking": None, "signature": "sig_block1"} - ] - ), + make_chunk(thinking_blocks=[{"type": "thinking", "thinking": None, "signature": "sig_block1"}]), make_chunk( thinking_blocks=[ { @@ -218,16 +216,10 @@ def test_get_combined_thinking_content_preserves_interleaved_blocks(): } ] ), - make_chunk( - thinking_blocks=[ - {"type": "thinking", "thinking": None, "signature": "sig_block2"} - ] - ), + make_chunk(thinking_blocks=[{"type": "thinking", "thinking": None, "signature": "sig_block2"}]), ] - thinking_chunks = [ - chunk for chunk in chunks if chunk["choices"][0]["delta"].get("thinking_blocks") - ] + thinking_chunks = [chunk for chunk in chunks if chunk["choices"][0]["delta"].get("thinking_blocks")] processor = ChunkProcessor(chunks=chunks) result = processor.get_combined_thinking_content(thinking_chunks) @@ -297,9 +289,7 @@ def test_cache_read_input_tokens_retained(): prompt_tokens=11779, total_tokens=11784, completion_tokens_details=None, - prompt_tokens_details=PromptTokensDetails( - audio_tokens=None, cached_tokens=11775 - ), + prompt_tokens_details=PromptTokensDetails(audio_tokens=None, cached_tokens=11775), cache_creation_input_tokens=4, cache_read_input_tokens=11775, ), @@ -333,9 +323,7 @@ def test_cache_read_input_tokens_retained(): prompt_tokens=0, total_tokens=214, completion_tokens_details=None, - prompt_tokens_details=PromptTokensDetails( - audio_tokens=None, cached_tokens=0 - ), + prompt_tokens_details=PromptTokensDetails(audio_tokens=None, cached_tokens=0), cache_creation_input_tokens=0, cache_read_input_tokens=0, ), @@ -395,10 +383,7 @@ def test_streaming_preserves_anthropic_1hr_cache_creation_breakdown(): ) # Sanity: the delta event genuinely lacks the breakdown - this is the input # condition that used to defeat cost calc. - assert ( - getattr(message_delta_usage.prompt_tokens_details, "cache_creation_token_details", None) - is None - ) + assert getattr(message_delta_usage.prompt_tokens_details, "cache_creation_token_details", None) is None def _usage_chunk(usage, finish_reason): return ModelResponseStream( @@ -517,9 +502,7 @@ def test_cache_read_input_tokens_retained_genericstreamingchunk(): prompt_tokens=1234, total_tokens=1239, completion_tokens_details=None, - prompt_tokens_details=PromptTokensDetails( - audio_tokens=None, cached_tokens=543 - ).model_dump(), + prompt_tokens_details=PromptTokensDetails(audio_tokens=None, cached_tokens=543).model_dump(), ), index=2, ) @@ -536,6 +519,7 @@ def test_cache_read_input_tokens_retained_genericstreamingchunk(): assert usage.prompt_tokens_details.cached_tokens == 543 + def test_stream_chunk_builder_litellm_usage_chunks(): """ Validate ChunkProcessor.calculate_usage uses provided usage fields from streaming chunks @@ -609,9 +593,7 @@ def test_stream_chunk_builder_litellm_usage_chunks(): chunks = [chunk1, chunk2] processor = ChunkProcessor(chunks=chunks) - usage = processor.calculate_usage( - chunks=chunks, model="gemini/gemini-2.5-flash-lite", completion_output="" - ) + usage = processor.calculate_usage(chunks=chunks, model="gemini/gemini-2.5-flash-lite", completion_output="") assert usage.prompt_tokens == 50 assert usage.completion_tokens == 27 @@ -655,15 +637,11 @@ def test_calculate_usage_honors_openai_sdk_completion_usage_chunks(): provider_specific_fields=None, stream_options={"include_usage": True}, ) - usage_chunk.usage = CompletionUsage( - prompt_tokens=20, completion_tokens=60, total_tokens=80, cost=0.000704 - ) + usage_chunk.usage = CompletionUsage(prompt_tokens=20, completion_tokens=60, total_tokens=80, cost=0.000704) assert type(usage_chunk.usage) is CompletionUsage chunks = [content_chunk, usage_chunk] - usage = ChunkProcessor(chunks=chunks).calculate_usage( - chunks=chunks, model="mantle-claude", completion_output="" - ) + usage = ChunkProcessor(chunks=chunks).calculate_usage(chunks=chunks, model="mantle-claude", completion_output="") assert usage.prompt_tokens == 20 assert usage.completion_tokens == 60 @@ -686,9 +664,7 @@ def test_get_model_from_chunks_azure_model_router(): {"model": "gpt-4.1-nano-2025-04-14", "id": "chatcmpl-123", "choices": []}, ] - result = ChunkProcessor._get_model_from_chunks( - chunks=chunks, first_chunk_model="azure-model-router" - ) + result = ChunkProcessor._get_model_from_chunks(chunks=chunks, first_chunk_model="azure-model-router") # Should return the actual model, not the request model assert result == "gpt-4.1-nano-2025-04-14" @@ -699,9 +675,7 @@ def test_get_model_from_chunks_azure_model_router(): {"model": "gpt-4", "id": "chatcmpl-456", "choices": []}, ] - result_same = ChunkProcessor._get_model_from_chunks( - chunks=chunks_same_model, first_chunk_model="gpt-4" - ) + result_same = ChunkProcessor._get_model_from_chunks(chunks=chunks_same_model, first_chunk_model="gpt-4") # Should return the first chunk's model when all are the same assert result_same == "gpt-4" @@ -777,9 +751,7 @@ def test_stream_chunk_builder_anthropic_web_search(): chunks = [chunk1, chunk2] processor = ChunkProcessor(chunks=chunks) - usage = processor.calculate_usage( - chunks=chunks, model="claude-sonnet-4-5-20250929", completion_output="" - ) + usage = processor.calculate_usage(chunks=chunks, model="claude-sonnet-4-5-20250929", completion_output="") assert usage.prompt_tokens == 50 assert usage.completion_tokens == 27 @@ -931,15 +903,11 @@ def test_stream_chunk_builder_dict_snapshot_preserves_hidden_provider_fields(): ], ) chunk_dict = chunk.model_dump() - chunk_dict["_hidden_params"] = { - "provider_specific_fields": {"traffic_type": "default"} - } + chunk_dict["_hidden_params"] = {"provider_specific_fields": {"traffic_type": "default"}} response = stream_chunk_builder(chunks=[chunk_dict]) assert response is not None - assert ( - response._hidden_params["provider_specific_fields"]["traffic_type"] == "default" - ) + assert response._hidden_params["provider_specific_fields"]["traffic_type"] == "default" def test_stream_chunk_builder_propagates_vertex_ai_metadata_from_chunks(): @@ -984,10 +952,7 @@ def test_stream_chunk_builder_propagates_vertex_ai_metadata_from_chunks(): assert getattr(response, "vertex_ai_grounding_metadata") == grounding_metadata assert getattr(response, "vertex_ai_url_context_metadata") == url_context_metadata assert response._hidden_params["vertex_ai_grounding_metadata"] == grounding_metadata - assert ( - response._hidden_params["vertex_ai_url_context_metadata"] - == url_context_metadata - ) + assert response._hidden_params["vertex_ai_url_context_metadata"] == url_context_metadata dumped = response.model_dump() assert dumped["vertex_ai_grounding_metadata"] == grounding_metadata @@ -1034,9 +999,7 @@ def test_stream_chunk_builder_uses_assembled_model_for_provider_metadata(): def test_stream_chunk_builder_propagates_vertex_ai_safety_results(): """Assembled response must expose safety data under the non-streaming field name.""" - safety_ratings = [ - [{"category": "HARM_CATEGORY_HATE_SPEECH", "probability": "NEGLIGIBLE"}] - ] + safety_ratings = [[{"category": "HARM_CATEGORY_HATE_SPEECH", "probability": "NEGLIGIBLE"}]] chunk = ModelResponseStream( id="chatcmpl-vertex-safety", @@ -1078,18 +1041,12 @@ def test_stream_chunk_builder_propagates_vertex_ai_metadata_from_dict_chunks(): ) ], ).model_dump() - chunk_dict["_hidden_params"] = { - "vertex_ai_grounding_metadata": [{"webSearchQueries": ["test query"]}] - } + chunk_dict["_hidden_params"] = {"vertex_ai_grounding_metadata": [{"webSearchQueries": ["test query"]}]} response = stream_chunk_builder(chunks=[chunk_dict]) assert response is not None - assert getattr(response, "vertex_ai_grounding_metadata") == [ - {"webSearchQueries": ["test query"]} - ] - assert response.model_dump()["vertex_ai_grounding_metadata"] == [ - {"webSearchQueries": ["test query"]} - ] + assert getattr(response, "vertex_ai_grounding_metadata") == [{"webSearchQueries": ["test query"]}] + assert response.model_dump()["vertex_ai_grounding_metadata"] == [{"webSearchQueries": ["test query"]}] def test_cost_field_in_usage_chunks(): @@ -1098,29 +1055,21 @@ def test_cost_field_in_usage_chunks(): id="chatcmpl-1", created=1745513206, model="openrouter/claude", - choices=[ - StreamingChoices(finish_reason=None, index=0, delta=Delta(content="Hi")) - ], + choices=[StreamingChoices(finish_reason=None, index=0, delta=Delta(content="Hi"))], usage=chunk1_usage, ) - chunk2_usage = Usage( - completion_tokens=5, prompt_tokens=10, total_tokens=15, cost=0.00025 - ) + chunk2_usage = Usage(completion_tokens=5, prompt_tokens=10, total_tokens=15, cost=0.00025) chunk2 = ModelResponseStream( id="chatcmpl-1", created=1745513207, model="openrouter/claude", - choices=[ - StreamingChoices(finish_reason="stop", index=0, delta=Delta(content="")) - ], + choices=[StreamingChoices(finish_reason="stop", index=0, delta=Delta(content=""))], usage=chunk2_usage, ) processor = ChunkProcessor(chunks=[chunk1, chunk2]) - usage = processor.calculate_usage( - chunks=[chunk1, chunk2], model="openrouter/claude", completion_output="Hi" - ) + usage = processor.calculate_usage(chunks=[chunk1, chunk2], model="openrouter/claude", completion_output="Hi") assert hasattr(usage, "cost") assert usage.cost == 0.00025 @@ -1203,25 +1152,19 @@ def test_prompt_tokens_details_survive_later_usage_chunk_without_details(): id="chatcmpl-1", created=1745513206, model="openai/gpt-5.6-sol", - choices=[ - StreamingChoices(finish_reason=None, index=0, delta=Delta(content="Hi")) - ], + choices=[StreamingChoices(finish_reason=None, index=0, delta=Delta(content="Hi"))], usage=Usage( prompt_tokens=6017, completion_tokens=4, total_tokens=6021, - prompt_tokens_details=PromptTokensDetailsWrapper( - cached_tokens=6004, cache_write_tokens=10 - ), + prompt_tokens_details=PromptTokensDetailsWrapper(cached_tokens=6004, cache_write_tokens=10), ), ) chunk_without_details = ModelResponseStream( id="chatcmpl-1", created=1745513207, model="openai/gpt-5.6-sol", - choices=[ - StreamingChoices(finish_reason="stop", index=0, delta=Delta(content="")) - ], + choices=[StreamingChoices(finish_reason="stop", index=0, delta=Delta(content=""))], usage=Usage(prompt_tokens=6017, completion_tokens=4, total_tokens=6021), ) @@ -1559,9 +1502,7 @@ def test_calculate_usage_fills_unknown_split_from_reasoning_estimate( assert usage.completion_tokens_details.text_tokens == expected_text_tokens -def _openai_chunk( - choices: Sequence[Mapping[str, object]], usage: Mapping[str, int] | None = None -) -> dict[str, object]: +def _openai_chunk(choices: Sequence[Mapping[str, object]], usage: Mapping[str, int] | None = None) -> dict[str, object]: base: Final = { "id": "chatcmpl-lit6552", "object": "chat.completion.chunk", @@ -1996,7 +1937,11 @@ def test_stream_chunk_builder_litellm_tool_call(respx_mock: respx.MockRouter) -> ) assert [tool_call.to_dict() for tool_call in response.choices[0].message.tool_calls] == [ - {"function": {"arguments": '{"city":"Boston"}', "name": "get_weather"}, "id": "call_weather", "type": "function"} + { + "function": {"arguments": '{"city":"Boston"}', "name": "get_weather"}, + "id": "call_weather", + "type": "function", + } ] assert (response.usage.prompt_tokens, response.usage.completion_tokens, response.usage.total_tokens) == (5, 3, 8) @@ -2018,7 +1963,9 @@ def test_stream_chunk_builder_litellm_tool_call_regular_message(respx_mock: resp def test_stream_chunk_builder_multiple_tool_calls() -> None: - def tool_call_chunk(*tool_calls: ChatCompletionDeltaToolCall, finish_reason: str | None = None) -> ModelResponseStream: + def tool_call_chunk( + *tool_calls: ChatCompletionDeltaToolCall, finish_reason: str | None = None + ) -> ModelResponseStream: return _legacy_stream_chunk("openai/gpt-4o", tool_calls=tool_calls, finish_reason=finish_reason) chunks: Final = ( @@ -2029,7 +1976,9 @@ def test_stream_chunk_builder_multiple_tool_calls() -> None: ), tool_call_chunk(ChatCompletionDeltaToolCall(index=0, function=Function(arguments='{"base": 3, '))), tool_call_chunk( - ChatCompletionDeltaToolCall(id="call_add", index=1, type="function", function=Function(name="add", arguments="")) + ChatCompletionDeltaToolCall( + id="call_add", index=1, type="function", function=Function(name="add", arguments="") + ) ), tool_call_chunk(ChatCompletionDeltaToolCall(index=0, function=Function(arguments='"exponent": 5}'))), tool_call_chunk( @@ -2043,7 +1992,11 @@ def test_stream_chunk_builder_multiple_tool_calls() -> None: assert response is not None assert response.choices[0].finish_reason == "tool_calls" assert [tool_call.to_dict() for tool_call in response.choices[0].message.tool_calls] == [ - {"function": {"arguments": '{"base": 3, "exponent": 5}', "name": "exponentiate"}, "id": "call_exp", "type": "function"}, + { + "function": {"arguments": '{"base": 3, "exponent": 5}', "name": "exponentiate"}, + "id": "call_exp", + "type": "function", + }, {"function": {"arguments": '{"x": 1, "y": 2}', "name": "add"}, "id": "call_add", "type": "function"}, ] @@ -2077,9 +2030,7 @@ def test_grok_bug() -> None: response: Final = stream_chunk_builder(chunks=chunks) assert response is not None - assert json.loads(response.choices[0].message.tool_calls[0].function.arguments) == { - "location": "Boston" - } + assert json.loads(response.choices[0].message.tool_calls[0].function.arguments) == {"location": "Boston"} def test_stream_chunk_builder_openai_audio_output_usage() -> None: @@ -2196,7 +2147,9 @@ def test_stream_chunk_builder_keeps_usage_dict_set_on_a_typed_text_completion_ch @pytest.mark.parametrize("build", [litellm.stream_chunk_builder, litellm.stream_chunk_builder_text_completion]) -def test_stream_chunk_builder_rebuilds_dict_text_completion_chunks(build: Callable[..., TextCompletionResponse]) -> None: +def test_stream_chunk_builder_rebuilds_dict_text_completion_chunks( + build: Callable[..., TextCompletionResponse], +) -> None: def chunk(choices: list[dict[str, object]], **extra: object) -> dict[str, object]: return { "id": "cmpl-1", @@ -2450,7 +2403,9 @@ def test_stream_chunk_builder_rebuilds_text_completion_choice_indexes_that_are_n ] ) - assert tuple(choice.model_dump(include={"index", "text", "finish_reason"}) for choice in response.choices) == expected + assert ( + tuple(choice.model_dump(include={"index", "text", "finish_reason"}) for choice in response.choices) == expected + ) def test_stream_chunk_builder_text_completion_survives_uncountable_prompt() -> None: @@ -2517,3 +2472,50 @@ def test_stream_chunk_builder_keeps_reasoning_items_on_text_only_replies(): assert response is not None assert response.choices[0].message.content == "Hello world" assert response.choices[0].message.reasoning_items == reasoning_items + + +def test_stream_chunk_builder_carries_the_bedrock_guardrail_trace_and_records_it_on_the_logging_object( + monkeypatch: pytest.MonkeyPatch, +) -> None: + """A Bedrock stream reports its guardrail trace on the last chunk only; the built response carries it like the + non-streaming response and the call bills it as guardrail cost.""" + from litellm.litellm_core_utils.litellm_logging import Logging + from litellm.types.utils import Delta, ModelResponseStream, StreamingChoices + + monkeypatch.setattr( + litellm, + "model_cost", + { + "bedrock/guardrails": { + "litellm_provider": "bedrock", + "mode": "guardrails", + "guardrail_cost_per_unit": {"topicPolicyUnits": 0.00015}, + } + }, + ) + trace = {"guardrail": {"inputAssessment": {"gid": {"invocationMetrics": {"usage": {"topicPolicyUnits": 2}}}}}} + chunks = [ + ModelResponseStream(id="s", model="m", choices=[StreamingChoices(index=0, delta=Delta(content="hi"))]), + ModelResponseStream( + id="s", + model="m", + choices=[StreamingChoices(index=0, delta=Delta(), finish_reason="stop")], + provider_specific_fields={"trace": trace}, + ), + ] + logging_obj = Logging( + model="bedrock/m", + messages=[{"role": "user", "content": "q"}], + stream=True, + call_type="acompletion", + start_time=None, + litellm_call_id="call", + function_id="fn", + ) + logging_obj.model_call_details["litellm_params"] = {"metadata": {}} + built = stream_chunk_builder(chunks=chunks, messages=[{"role": "user", "content": "q"}], logging_obj=logging_obj) + assert built is not None + assert getattr(built, "trace") == trace + (entry,) = logging_obj.model_call_details["litellm_params"]["metadata"]["standard_logging_guardrail_information"] + assert entry["guardrail_usage"] == {"topicPolicyUnits": 2} + assert entry["guardrail_cost"] == pytest.approx(2 * 0.00015) diff --git a/tests/unit/litellm_core_utils/test_streaming_handler.py b/tests/unit/litellm_core_utils/test_streaming_handler.py index c13cea51183..cc1fa1b8803 100644 --- a/tests/unit/litellm_core_utils/test_streaming_handler.py +++ b/tests/unit/litellm_core_utils/test_streaming_handler.py @@ -1,6 +1,7 @@ import asyncio import datetime import json +import queue import sys import threading import time @@ -2819,6 +2820,123 @@ def test_raise_on_model_repetition_tolerates_empty_choices( wrapper.raise_on_model_repetition() +_STUCK_CHUNK: Final = "the model is stuck on this" +_STUCK_PROVIDER_CHUNK_CAP: Final = 10 * litellm.REPEATED_STREAMING_CHUNK_LIMIT + + +class _StuckProvider: + def __init__(self) -> None: + self.closed_early = threading.Event() + self.chunks_sent = 0 + + def _next_chunk(self) -> ModelResponseStream: + self.chunks_sent += 1 + return _make_chunk(_STUCK_CHUNK) + + def sync_stream(self) -> Iterator[ModelResponseStream]: + try: + yield from (self._next_chunk() for _ in range(_STUCK_PROVIDER_CHUNK_CAP)) + except GeneratorExit: + self.closed_early.set() + raise + + async def async_stream(self) -> AsyncIterator[ModelResponseStream]: + try: + for _ in range(_STUCK_PROVIDER_CHUNK_CAP): + yield self._next_chunk() + except GeneratorExit: + self.closed_early.set() + raise + + +class _StuckStreamFailureRecorder(CustomLogger): + def __init__(self) -> None: + super().__init__() + self.failures: Final = queue.SimpleQueue[str]() + + def log_failure_event(self, kwargs: object, response_obj: object, start_time: object, end_time: object) -> None: + self.failures.put(str(cast(Mapping[str, object], kwargs)["exception"])) + + async def async_log_failure_event( + self, kwargs: object, response_obj: object, start_time: object, end_time: object + ) -> None: + self.failures.put(str(cast(Mapping[str, object], kwargs)["exception"])) + + +def _stuck_stream_wrapper( + provider_stream: Iterator[ModelResponseStream] | AsyncIterator[ModelResponseStream], + call_type: Literal["completion", "acompletion"], + recorder: _StuckStreamFailureRecorder, +) -> CustomStreamWrapper: + logging_obj: Final = Logging( + model="test-model", + messages=[{"role": "user", "content": "hi"}], + stream=True, + call_type=call_type, + start_time=datetime.datetime(2026, 1, 1), + litellm_call_id=f"stuck-stream-{call_type}", + function_id=f"stuck-stream-{call_type}", + dynamic_failure_callbacks=[recorder], + dynamic_async_failure_callbacks=[recorder], + ) + logging_obj.update_environment_variables( + model="test-model", + optional_params={}, + litellm_params=get_litellm_params(custom_llm_provider="openai", acompletion=call_type == "acompletion"), + ) + return CustomStreamWrapper( + completion_stream=provider_stream, + model="test-model", + logging_obj=logging_obj, + custom_llm_provider="openai", + ) + + +@pytest.mark.asyncio +async def test_async_stream_stuck_on_one_chunk_closes_the_provider_stream_and_logs_one_failure(): + """https://github.com/BerriAI/litellm/issues/19428 and https://github.com/BerriAI/litellm/issues/13786""" + provider: Final = _StuckProvider() + recorder: Final = _StuckStreamFailureRecorder() + wrapper: Final = _stuck_stream_wrapper(provider.async_stream(), "acompletion", recorder) + + with pytest.raises(Exception, match="repeating the same chunk"): + async for _ in wrapper: + pass + assert provider.closed_early.is_set() + assert provider.chunks_sent <= litellm.REPEATED_STREAMING_CHUNK_LIMIT + 1 + chunks_sent_at_failure: Final = provider.chunks_sent + + with pytest.raises(StopAsyncIteration): + await wrapper.__anext__() + await wrapper.wait_for_failure_logging(timeout=5) + + assert provider.chunks_sent == chunks_sent_at_failure + assert "repeating the same chunk" in recorder.failures.get_nowait() + assert recorder.failures.empty() + + +def test_sync_stream_stuck_on_one_chunk_closes_the_provider_stream_and_logs_one_failure(): + """Sync counterpart of the async test above""" + provider: Final = _StuckProvider() + recorder: Final = _StuckStreamFailureRecorder() + wrapper: Final = _stuck_stream_wrapper(provider.sync_stream(), "completion", recorder) + + with pytest.raises(Exception, match="repeating the same chunk"): + for _ in wrapper: + pass + assert provider.closed_early.is_set() + assert provider.chunks_sent <= litellm.REPEATED_STREAMING_CHUNK_LIMIT + 1 + chunks_sent_at_failure: Final = provider.chunks_sent + assert "repeating the same chunk" in recorder.failures.get(timeout=5) + + with pytest.raises(StopIteration): + next(wrapper) + + assert provider.chunks_sent == chunks_sent_at_failure + with pytest.raises(queue.Empty): + recorder.failures.get(timeout=0.5) + + def test_usage_chunk_after_finish_reason_updates_hidden_params(logging_obj): """ Test that provider-reported usage from a post-finish_reason chunk diff --git a/tests/unit/litellm_core_utils/test_token_counter.py b/tests/unit/litellm_core_utils/test_token_counter.py index 88af656ad2e..9921bbe343a 100644 --- a/tests/unit/litellm_core_utils/test_token_counter.py +++ b/tests/unit/litellm_core_utils/test_token_counter.py @@ -3,6 +3,7 @@ import asyncio import base64 import importlib +import io import json import os import subprocess @@ -13,12 +14,13 @@ from collections.abc import Callable, Mapping from concurrent.futures import Future, ThreadPoolExecutor, wait from itertools import accumulate, chain from pathlib import Path -from typing import Final +from typing import Final, cast from unittest.mock import MagicMock, sentinel import anyio.to_thread import pytest import tiktoken +from PIL import Image from tokenizers import Regex, Tokenizer, models, pre_tokenizers from unittest.mock import AsyncMock, patch @@ -39,7 +41,8 @@ from litellm.litellm_core_utils.token_counter import ( offload_token_count, ) from litellm.litellm_core_utils.token_counter import token_counter as token_counter_new -from litellm.llms.anthropic.pass_through.adapters.transformation import LiteLLMAnthropicMessagesAdapter +from litellm.llms.anthropic.messages.adapters.transformation import LiteLLMAnthropicMessagesAdapter +from litellm.types.llms.openai import AllMessageValues, ChatCompletionToolParam from tests.large_text import text from tests.unit.litellm_core_utils.event_loop_lag import ( assert_loop_stayed_free, @@ -656,6 +659,37 @@ def test_token_counter_tool_choice_adds_nothing_for_deepseek_v4(tool_choice: obj ) == token_counter_new(model="DeepSeek-V4-Flash-0731", messages=list(_USER_MESSAGES), tools=tools) +@pytest.mark.parametrize( + ("tool_choice", "expected_tool_choice"), + [ + pytest.param({"type": "auto"}, None, id="anthropic-auto"), + pytest.param({"type": "any"}, None, id="anthropic-any"), + pytest.param({"type": "none"}, "none", id="anthropic-none"), + pytest.param( + {"type": "tool", "name": "get_weather"}, + {"type": "function", "function": {"name": "get_weather"}}, + id="anthropic-tool", + ), + pytest.param( + {"type": "function", "name": "get_weather"}, + {"type": "function", "function": {"name": "get_weather"}}, + id="responses-function", + ), + ], +) +def test_token_counter_counts_anthropic_tool_choices_like_openai_choices( + tool_choice: Mapping[str, object], expected_tool_choice: str | Mapping[str, object] | None +) -> None: + messages: Final = cast(list[AllMessageValues], list(_USER_MESSAGES)) + tools: Final = cast(list[ChatCompletionToolParam], [_openai_tool(_WEATHER_FUNCTION)]) + + assert token_counter_new( + model="gpt-4", messages=messages, tools=tools, tool_choice=tool_choice + ) == token_counter_new( + model="gpt-4", messages=messages, tools=tools, tool_choice=expected_tool_choice + ) + + @pytest.mark.parametrize("model", ["DeepSeek-V4-Flash-0731", "databricks-qwen35-122b-a10b"]) @pytest.mark.parametrize( "anthropic_tool", @@ -2015,6 +2049,71 @@ def _png_data_url(width: int, height: int) -> str: return "data:image/png;base64," + base64.b64encode(ihdr + b"\x08\x06\x00\x00\x00").decode() +@pytest.mark.parametrize( + ("width", "height", "expected"), [(256, 256, 262), (512, 512, 262), (768, 768, 772), (1024, 1024, 772)] +) +@pytest.mark.parametrize("detail", [None, "auto", "high"]) +def test_inline_auto_images_count_high_detail_tiles(width: int, height: int, expected: int, detail: str | None) -> None: + image_url = {"url": _png_data_url(width, height)} + if detail is not None: + image_url["detail"] = detail + messages = [{"role": "user", "content": [{"type": "image_url", "image_url": image_url}]}] + + assert token_counter_new(model="gpt-4o", messages=messages) == expected + + +@pytest.mark.parametrize("image_format", ["PNG", "JPEG", "GIF", "WEBP"]) +def test_inline_auto_images_read_supported_formats(image_format: str) -> None: + output = io.BytesIO() + Image.new("RGB", (1024, 1024)).save(output, format=image_format) + url = f"data:image/{image_format.lower()};base64," + base64.b64encode(output.getvalue()).decode() + + assert calculate_img_tokens(url) == 765 + + +@pytest.mark.parametrize( + "data", + [ + "https://example.com/image.png", + "http://127.0.0.1/image.png", + "http://169.254.169.254/latest/meta-data/", + "file:///etc/passwd", + "data:application/pdf;base64,JVBERi0xLjQK", + "data:image/png;base64,%%%", + "data:image/png;base64,iVBORw0KGgo=", + "data:image/jpeg;base64,/9j/4AAQ", + "data:image/png,not-base64", + "", + _png_data_url(0, 1024), + _png_data_url(1024, 0), + ], +) +def test_auto_image_fallback_does_not_fetch_urls_or_raise(data: str) -> None: + # The unit suite disables sockets; a fetch must also not be attempted and swallowed. + with patch("httpx.Client.get", side_effect=AssertionError("auto counting must not fetch URLs")) as get: + assert calculate_img_tokens(data) == 85 + get.assert_not_called() + + +def test_auto_image_decode_respects_size_limit(monkeypatch: pytest.MonkeyPatch) -> None: + counter = importlib.import_module("litellm.litellm_core_utils.token_counter") + monkeypatch.setattr(counter, "MAX_IMAGE_URL_DOWNLOAD_SIZE_MB", 24 / (1024 * 1024)) + + with patch("base64.b64decode", side_effect=AssertionError("oversized input must not be decoded")) as decode: + assert calculate_img_tokens(_png_data_url(1024, 1024)) == 85 + decode.assert_not_called() + + +def test_low_and_default_image_counts_skip_inline_decoding() -> None: + with patch("base64.b64decode", side_effect=AssertionError("fixed counts must not decode")) as decode: + assert calculate_img_tokens(_png_data_url(1024, 1024), mode="low") == 85 + assert ( + calculate_img_tokens(_png_data_url(1024, 1024), use_default_image_token_count=True) + == litellm.constants.DEFAULT_IMAGE_TOKEN_COUNT + ) + decode.assert_not_called() + + @pytest.mark.parametrize(("width", "height"), [(1, 1), (768, 768), (2000, 768), (768, 2000), (4096, 4096), (8000, 3072)]) def test_high_detail_image_token_upper_bound_covers_every_image_size(width: int, height: int) -> None: assert calculate_img_tokens(_png_data_url(width, height), mode="high") <= high_detail_image_token_upper_bound() diff --git a/tests/unit/litellm_proxy_extras/test_migration_data_checks.py b/tests/unit/litellm_proxy_extras/test_migration_data_checks.py new file mode 100644 index 00000000000..7897a388474 --- /dev/null +++ b/tests/unit/litellm_proxy_extras/test_migration_data_checks.py @@ -0,0 +1,156 @@ +from pathlib import Path +from typing import Final + +import pytest +from litellm_proxy_extras.migration_data_checks import ( + DEFAULT_MIGRATION_DATA_CHECK_TIMEOUT_SECONDS, + MIGRATION_DATA_CHECK_TIMEOUT_ENV_VAR, + BlockedChange, + Check, + CouldNotVerify, + btree_max_entry_bytes, + checks_for_index, + checks_for_migration, + checks_for_statement, + migration_data_check_timeout_seconds, + report, + statements, +) + +MIGRATIONS: Final = Path(__file__).resolve().parents[3] / "litellm-proxy-extras" / "litellm_proxy_extras" / "migrations" +API_KEY_INDEX_AS_SHIPPED_IN_V1_103_0: Final = 'CREATE INDEX IF NOT EXISTS "LiteLLM_SpendLogs_api_key_startTime_idx" ON "LiteLLM_SpendLogs"("api_key", "startTime")' + + +def _shape(checks: tuple[Check, ...]) -> tuple[tuple[str, str, tuple[str, ...]], ...]: + return tuple((check.kind, check.table, check.columns) for check in checks) + + +@pytest.mark.parametrize( + ("statement", "expected"), + ( + ( + API_KEY_INDEX_AS_SHIPPED_IN_V1_103_0, + (("too_long", "LiteLLM_SpendLogs", ("api_key", "startTime")),), + ), + ( + 'CREATE UNIQUE INDEX CONCURRENTLY "T_a_b_key" ON "public"."T" USING btree ("a", "b" DESC)', + (("too_long", "T", ("a", "b")), ("duplicates", "T", ("a", "b"))), + ), + ('CREATE INDEX "T_a_idx" ON "T" USING gin ("a")', ()), + ('CREATE INDEX "T_a_idx" ON "T" (lower("a"))', ()), + ('ALTER TABLE "T" ALTER COLUMN "a" SET NOT NULL', (("nulls", "T", ("a",)),)), + ('ALTER TABLE "T" ADD COLUMN "a" TEXT NOT NULL', (("any_row", "T", ("a",)),)), + ('ALTER TABLE "T" ADD COLUMN "a" TEXT NOT NULL DEFAULT \'x\'', ()), + ('ALTER TABLE "T" ADD COLUMN "a" TEXT', ()), + ( + 'ALTER TABLE "T" ADD CONSTRAINT "T_r_fkey" FOREIGN KEY ("r") REFERENCES "R"("id") ON DELETE CASCADE', + (("orphans", "T", ("r",)),), + ), + ('ALTER TABLE "T" ADD CONSTRAINT "T_r_fkey" FOREIGN KEY ("r") REFERENCES "R"("id") NOT VALID', ()), + ('ALTER TABLE "T" ADD CONSTRAINT "T_a_key" UNIQUE ("a", "b")', (("duplicates", "T", ("a", "b")),)), + ( + 'ALTER TABLE "T" ADD CONSTRAINT "T_a_check" CHECK ("a" > 0 AND "b" IS NOT NULL)', + (("check_violations", "T", ()),), + ), + ('ALTER TABLE "T" ADD CONSTRAINT "T_a_check" CHECK ("a" > 0) NOT VALID', ()), + ( + 'ALTER TABLE "T" ADD COLUMN "c" TEXT, ALTER COLUMN "b" SET NOT NULL, ADD CONSTRAINT "u" UNIQUE ("c")', + (("nulls", "T", ("b",)), ("duplicates", "T", ("c",))), + ), + ('CREATE TABLE "T" ("id" TEXT NOT NULL, CONSTRAINT "T_pkey" PRIMARY KEY ("id"))', ()), + ('DROP INDEX IF EXISTS "T_a_idx"', ()), + ("SELECT 1", ()), + ), +) +def test_a_statement_gets_one_check_per_way_existing_rows_can_make_it_fail( + statement: str, expected: tuple[tuple[str, str, tuple[str, ...]], ...] +) -> None: + assert _shape(checks_for_statement(statement, "migration x")) == expected + + +def test_a_foreign_key_check_keeps_the_referenced_table_and_columns() -> None: + (check,) = checks_for_statement( + 'ALTER TABLE "T" ADD CONSTRAINT "fk" FOREIGN KEY ("r", "s") REFERENCES "R"("id", "sub")', "migration x" + ) + assert (check.referenced_table, check.referenced_columns) == ("R", ("id", "sub")) + + +def test_a_check_constraint_keeps_its_expression_for_the_count_query() -> None: + (check,) = checks_for_statement('ALTER TABLE "T" ADD CONSTRAINT "c" CHECK ("a" > 0)', "migration x") + assert check.expression == '"a" > 0' + + +def test_comments_and_blank_statements_are_dropped_before_matching() -> None: + migration_sql: Final = "-- CreateIndex\n" + API_KEY_INDEX_AS_SHIPPED_IN_V1_103_0 + ";\n\n-- done; really\n" + assert statements(migration_sql) == (API_KEY_INDEX_AS_SHIPPED_IN_V1_103_0,) + assert _shape(checks_for_migration("x", migration_sql)) == _shape( + checks_for_statement(API_KEY_INDEX_AS_SHIPPED_IN_V1_103_0, "x") + ) + + +def test_every_shipped_migration_is_readable_and_the_later_indexes_on_text_columns_get_a_check() -> None: + derived: Final = { + folder.name: checks_for_migration(folder.name, (folder / "migration.sql").read_text()) + for folder in MIGRATIONS.iterdir() + if folder.is_dir() + } + assert len(derived) > 200 + everywhere: Final = tuple(check for checks in derived.values() for check in checks) # comprehension-ok: flattening + assert any( + check.kind == "too_long" and check.table == "LiteLLM_SpendLogs" and "session_id" in check.columns + for check in everywhere + ) + + +def test_a_request_log_index_gets_one_entry_size_check_over_all_its_columns() -> None: + assert _shape( + checks_for_index("LiteLLM_SpendLogs", "LiteLLM_SpendLogs_api_key_startTime_idx", ("api_key", "startTime")) + ) == (("too_long", "LiteLLM_SpendLogs", ("api_key", "startTime")),) + + +def test_the_btree_entry_limit_on_the_default_page_is_the_number_in_postgres_error() -> None: + # "index row size 2976 exceeds btree version 4 maximum 2704", Postgres 14, 8 KB page (BTMaxItemSize, nbtree.h) + assert btree_max_entry_bytes(8192) == 2704 + + +def test_the_report_names_the_rows_the_statement_and_the_fix_and_says_nothing_was_applied() -> None: + (check,) = checks_for_index( + "LiteLLM_SpendLogs", "LiteLLM_SpendLogs_api_key_startTime_idx", ("api_key", "startTime") + ) + text: Final = report( + (BlockedChange(check, 2, "with an index entry over 2704 bytes, largest 3232 bytes (api_key up to 3207 bytes)"),) + ) + assert ( + '"LiteLLM_SpendLogs".api_key, startTime: 2 row(s) with an index entry over 2704 bytes, largest 3232 bytes ' + "(api_key up to 3207 bytes)" + ) in text + assert 'blocks: CREATE INDEX "LiteLLM_SpendLogs_api_key_startTime_idx" (request-log index)' in text + assert 'UPDATE "LiteLLM_SpendLogs" SET api_key = encode(sha256(' in text + assert text.startswith("Existing rows would make a pending schema change fail:") + assert "No schema change was made" in text + + +def test_a_scan_that_timed_out_is_reported_as_unverified_with_the_knob_to_turn() -> None: + (check,) = checks_for_statement('ALTER TABLE "T" ALTER COLUMN "a" SET NOT NULL', "migration 20270101000000_x") + text: Final = report((CouldNotVerify(check, 600.0),)) + assert '"T".a: could not be checked within 600 s, refusing rather than guessing' in text + assert 'blocks: ALTER TABLE "T" ALTER COLUMN "a" SET NOT NULL (migration 20270101000000_x)' in text + assert MIGRATION_DATA_CHECK_TIMEOUT_ENV_VAR in text + + +@pytest.mark.parametrize( + ("raw", "expected"), + ( + (None, DEFAULT_MIGRATION_DATA_CHECK_TIMEOUT_SECONDS), + ("30", 30.0), + ("nope", DEFAULT_MIGRATION_DATA_CHECK_TIMEOUT_SECONDS), + ), +) +def test_the_scan_timeout_comes_from_the_environment_and_falls_back_on_garbage( + monkeypatch: pytest.MonkeyPatch, raw: str | None, expected: float +) -> None: + if raw is None: + monkeypatch.delenv(MIGRATION_DATA_CHECK_TIMEOUT_ENV_VAR, raising=False) + else: + monkeypatch.setenv(MIGRATION_DATA_CHECK_TIMEOUT_ENV_VAR, raw) + assert migration_data_check_timeout_seconds() == expected diff --git a/tests/unit/llms/anthropic/chat/guardrail_translation/test_anthropic_guardrail_handler.py b/tests/unit/llms/anthropic/chat/guardrail_translation/test_anthropic_guardrail_handler.py index 8218c120153..9e88b59adc9 100644 --- a/tests/unit/llms/anthropic/chat/guardrail_translation/test_anthropic_guardrail_handler.py +++ b/tests/unit/llms/anthropic/chat/guardrail_translation/test_anthropic_guardrail_handler.py @@ -18,7 +18,7 @@ from litellm.llms.base_llm.guardrail_translation.base_translation import Streami from litellm.llms.anthropic.chat.guardrail_translation.handler import ( AnthropicMessagesHandler, ) -from litellm.llms.anthropic.pass_through.adapters.transformation import truncate_tool_name +from litellm.llms.anthropic.messages.adapters.transformation import truncate_tool_name from litellm.types.utils import ChatCompletionMessageToolCall, GenericGuardrailAPIInputs diff --git a/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py b/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py index 32f18b952ac..ef002a73e52 100644 --- a/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py +++ b/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py @@ -26,12 +26,12 @@ from litellm.llms.anthropic.chat import ModelResponseIterator from litellm.llms.anthropic.common_utils import process_anthropic_headers from litellm.llms.anthropic.chat.transformation import AnthropicConfig from litellm.llms.base_llm.base_utils import ResponseFormatSchema, response_format_schema -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) from litellm.llms.azure_ai.anthropic.transformation import AzureAnthropicConfig from litellm.llms.bedrock.claude_platform.transformation import BedrockClaudePlatformConfig -from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformation import ( +from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeConfig, ) from litellm.llms.vertex_ai.vertex_ai_partner_models.anthropic.transformation import ( @@ -2549,18 +2549,6 @@ def test_translate_system_message_preserves_cache_control(): # ============ Dynamic max_tokens Tests ============ -def test_get_max_tokens_for_model_claude_3(): - """ - Test that get_max_tokens_for_model returns correct value for Claude 3 models. - Claude 3 models have max_output_tokens of 4096. - """ - config = AnthropicConfig() - - # Claude 3 Sonnet should return 4096 - max_tokens = config.get_max_tokens_for_model("claude-3-sonnet-20240229") - assert max_tokens == 4096 - - def test_get_max_tokens_for_model_claude_35(): """ Test that get_max_tokens_for_model returns correct value for Claude 3.5 models. @@ -2581,24 +2569,24 @@ def test_get_max_tokens_for_model_claude_35(): def test_get_max_tokens_for_model_unknown(): """ - Test that get_max_tokens_for_model returns 4096 fallback for unknown models. + Test that get_max_tokens_for_model returns 128000 fallback for unknown models. """ config = AnthropicConfig() - # Unknown model should return 4096 as fallback + # Unknown model should return 128000 as fallback max_tokens = config.get_max_tokens_for_model("unknown-model-xyz") - assert max_tokens == 4096 + assert max_tokens == 128000 def test_get_max_tokens_for_model_none(): """ - Test that get_max_tokens_for_model returns 4096 fallback when model is None. + Test that get_max_tokens_for_model returns 128000 fallback when model is None. """ config = AnthropicConfig() - # None model should return 4096 as fallback + # None model should return 128000 as fallback max_tokens = config.get_max_tokens_for_model(None) - assert max_tokens == 4096 + assert max_tokens == 128000 def test_get_config_with_model_uses_dynamic_max_tokens(): @@ -2639,10 +2627,10 @@ def test_get_config_with_model_uses_dynamic_max_tokens(): def test_get_config_without_model_uses_fallback(): """ - Test that get_config without model parameter uses 4096 fallback. + Test that get_config without model parameter uses 128000 fallback. """ config = AnthropicConfig.get_config() - assert config["max_tokens"] == 4096 + assert config["max_tokens"] == 128000 def test_get_config_does_not_leak_module_constants(): @@ -6145,7 +6133,7 @@ def test_anthropic_messages_request_strips_billing_header_for_minimax(): def test_translate_system_message_strips_billing_header_for_bedrock_invoke(): - from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformation import ( + from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeConfig, ) @@ -6164,7 +6152,7 @@ def test_translate_system_message_strips_billing_header_for_bedrock_invoke(): [ ("litellm.llms.anthropic.chat.transformation", "AnthropicConfig", False), ( - "litellm.llms.anthropic.pass_through.messages.transformation", + "litellm.llms.anthropic.messages.native.transformation", "AnthropicMessagesConfig", False, ), @@ -6174,12 +6162,12 @@ def test_translate_system_message_strips_billing_header_for_bedrock_invoke(): True, ), ( - "litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformation", + "litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude_transformation", "AmazonAnthropicClaudeConfig", True, ), ( - "litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude3_transformation", + "litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude_transformation", "AmazonAnthropicClaudeMessagesConfig", True, ), @@ -6206,7 +6194,7 @@ def test_translate_system_message_strips_billing_header_for_bedrock_invoke(): True, ), ( - "litellm.llms.vertex_ai.vertex_ai_partner_models.anthropic.experimental_pass_through.transformation", + "litellm.llms.vertex_ai.vertex_ai_partner_models.anthropic.messages.transformation", "VertexAIPartnerModelsAnthropicMessagesConfig", True, ), diff --git a/tests/unit/llms/anthropic/pass_through/responses_adapters/__init__.py b/tests/unit/llms/anthropic/messages/adapters/__init__.py similarity index 100% rename from tests/unit/llms/anthropic/pass_through/responses_adapters/__init__.py rename to tests/unit/llms/anthropic/messages/adapters/__init__.py diff --git a/tests/unit/llms/anthropic/pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py b/tests/unit/llms/anthropic/messages/adapters/test_anthropic_messages_adapters_transformation.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py rename to tests/unit/llms/anthropic/messages/adapters/test_anthropic_messages_adapters_transformation.py index 658aa009683..4e4b89b764b 100644 --- a/tests/unit/llms/anthropic/pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py +++ b/tests/unit/llms/anthropic/messages/adapters/test_anthropic_messages_adapters_transformation.py @@ -21,14 +21,14 @@ from litellm.litellm_core_utils.prompt_templates.factory import ( THOUGHT_SIGNATURE_SEPARATOR, _bedrock_converse_messages_pt, ) -from litellm.llms.anthropic.pass_through.adapters.transformation import ( +from litellm.llms.anthropic.messages.adapters.transformation import ( OPENAI_MAX_TOOL_NAME_LENGTH, AnthropicAdapter, LiteLLMAnthropicMessagesAdapter, create_tool_name_mapping, truncate_tool_name, ) -from litellm.llms.anthropic.pass_through.messages.mid_conversation_system import ( +from litellm.llms.anthropic.messages.native.mid_conversation_system import ( CONVERTED_SYSTEM_NOTE, ) from litellm.llms.openai.chat.gpt_transformation import OpenAIGPTConfig @@ -3957,7 +3957,7 @@ class TestAnthropicStreamWrapperToolArgs: return [text_chunk, tool_chunk, finish_chunk] def _make_stream_wrapper(self, chunks): - from litellm.llms.anthropic.pass_through.adapters.streaming_iterator import ( + from litellm.llms.anthropic.messages.adapters.streaming_iterator import ( AnthropicStreamWrapper, ) @@ -4072,7 +4072,7 @@ def _make_simple_openai_response( def test_translate_openai_response_to_anthropic_with_polyfill_compaction_block(): """compaction_block from PolyfillResult must be prepended to content at index 0.""" - from litellm.llms.anthropic.pass_through.context_management.result import ( + from litellm.llms.anthropic.messages.context_management.result import ( PolyfillResult, ) @@ -4105,7 +4105,7 @@ def test_translate_openai_response_to_anthropic_with_polyfill_compaction_block() def test_translate_openai_response_to_anthropic_with_polyfill_iterations_usage(): """iterations_usage from PolyfillResult must produce usage['iterations'] with a message entry.""" - from litellm.llms.anthropic.pass_through.context_management.result import ( + from litellm.llms.anthropic.messages.context_management.result import ( PolyfillResult, ) @@ -4160,7 +4160,7 @@ def test_translate_openai_response_to_anthropic_no_polyfill_no_change(): def test_translate_openai_response_to_anthropic_with_polyfill_both_compaction_and_iterations(): """Full summary path: compaction_block and iterations_usage both present simultaneously.""" - from litellm.llms.anthropic.pass_through.context_management.result import ( + from litellm.llms.anthropic.messages.context_management.result import ( PolyfillResult, ) diff --git a/tests/unit/llms/anthropic/pass_through/adapters/test_handler_context_management.py b/tests/unit/llms/anthropic/messages/adapters/test_handler_context_management.py similarity index 95% rename from tests/unit/llms/anthropic/pass_through/adapters/test_handler_context_management.py rename to tests/unit/llms/anthropic/messages/adapters/test_handler_context_management.py index 9b5477e3206..81cc1fbbe02 100644 --- a/tests/unit/llms/anthropic/pass_through/adapters/test_handler_context_management.py +++ b/tests/unit/llms/anthropic/messages/adapters/test_handler_context_management.py @@ -5,8 +5,8 @@ from unittest.mock import patch import pytest import litellm -from litellm.llms.anthropic.pass_through.adapters.handler import LiteLLMMessagesToCompletionTransformationHandler -from litellm.llms.anthropic.pass_through.context_management import AnthropicContextManagementError +from litellm.llms.anthropic.messages.adapters.handler import LiteLLMMessagesToCompletionTransformationHandler +from litellm.llms.anthropic.messages.context_management import AnthropicContextManagementError from litellm.router import Router from litellm.types.utils import Choices, Message, ModelResponse, Usage diff --git a/tests/unit/llms/anthropic/pass_through/adapters/test_handler_output_config_passthrough.py b/tests/unit/llms/anthropic/messages/adapters/test_handler_output_config_passthrough.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/adapters/test_handler_output_config_passthrough.py rename to tests/unit/llms/anthropic/messages/adapters/test_handler_output_config_passthrough.py index 03553e65ad4..c34cb686928 100644 --- a/tests/unit/llms/anthropic/pass_through/adapters/test_handler_output_config_passthrough.py +++ b/tests/unit/llms/anthropic/messages/adapters/test_handler_output_config_passthrough.py @@ -37,7 +37,7 @@ import pytest # where pytest is invoked from. sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../../.."))) -from litellm.llms.anthropic.pass_through.adapters.handler import ( +from litellm.llms.anthropic.messages.adapters.handler import ( ANTHROPIC_ONLY_REQUEST_KEYS, LiteLLMMessagesToCompletionTransformationHandler, ) diff --git a/tests/unit/llms/anthropic/pass_through/adapters/test_handler_prompt_cache_key.py b/tests/unit/llms/anthropic/messages/adapters/test_handler_prompt_cache_key.py similarity index 97% rename from tests/unit/llms/anthropic/pass_through/adapters/test_handler_prompt_cache_key.py rename to tests/unit/llms/anthropic/messages/adapters/test_handler_prompt_cache_key.py index c31d85be0a8..ed6cd6134ff 100644 --- a/tests/unit/llms/anthropic/pass_through/adapters/test_handler_prompt_cache_key.py +++ b/tests/unit/llms/anthropic/messages/adapters/test_handler_prompt_cache_key.py @@ -6,7 +6,7 @@ import pytest sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../../.."))) -from litellm.llms.anthropic.pass_through.adapters.handler import ( +from litellm.llms.anthropic.messages.adapters.handler import ( LiteLLMMessagesToCompletionTransformationHandler, ) diff --git a/tests/unit/llms/anthropic/pass_through/adapters/test_handler_reasoning_effort_normalization.py b/tests/unit/llms/anthropic/messages/adapters/test_handler_reasoning_effort_normalization.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/adapters/test_handler_reasoning_effort_normalization.py rename to tests/unit/llms/anthropic/messages/adapters/test_handler_reasoning_effort_normalization.py index 5a82b9af468..e504513dd36 100644 --- a/tests/unit/llms/anthropic/pass_through/adapters/test_handler_reasoning_effort_normalization.py +++ b/tests/unit/llms/anthropic/messages/adapters/test_handler_reasoning_effort_normalization.py @@ -16,7 +16,7 @@ import pytest import respx import litellm -from litellm.llms.anthropic.pass_through.adapters.handler import ( +from litellm.llms.anthropic.messages.adapters.handler import ( LiteLLMMessagesToCompletionTransformationHandler, ) from litellm.llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini import VertexGeminiConfig diff --git a/tests/unit/llms/anthropic/pass_through/adapters/test_handler_safeguard_results.py b/tests/unit/llms/anthropic/messages/adapters/test_handler_safeguard_results.py similarity index 98% rename from tests/unit/llms/anthropic/pass_through/adapters/test_handler_safeguard_results.py rename to tests/unit/llms/anthropic/messages/adapters/test_handler_safeguard_results.py index 51964a77b67..cbe65b8a4e0 100644 --- a/tests/unit/llms/anthropic/pass_through/adapters/test_handler_safeguard_results.py +++ b/tests/unit/llms/anthropic/messages/adapters/test_handler_safeguard_results.py @@ -11,11 +11,11 @@ import litellm from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.litellm_logging import Logging from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER -from litellm.llms.anthropic.pass_through.adapters.handler import ( +from litellm.llms.anthropic.messages.adapters.handler import ( LiteLLMMessagesToCompletionTransformationHandler, request_safeguards_evaluator, ) -from litellm.llms.anthropic.pass_through.safeguards import ToolUseUnderReview +from litellm.llms.anthropic.messages.safeguards import ToolUseUnderReview from litellm.proxy._types import LiteLLM_TeamTableCachedObj, UserAPIKeyAuth from litellm.router import Router from litellm.types.utils import ( @@ -30,7 +30,7 @@ from litellm.types.utils import ( StreamingChoices, Usage, ) -from tests.unit.llms.anthropic.pass_through.conftest import ProxyAuthState +from tests.unit.llms.anthropic.messages.conftest import ProxyAuthState SAFEGUARDS: Final = [{"type": "dangerous_tool_use", "classifier_context": {"permission_mode": "auto"}}] BASH_TOOL: Final = {"name": "Bash", "description": "run", "input_schema": {"type": "object", "properties": {}}} diff --git a/tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_combined_chunk.py b/tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_combined_chunk.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_combined_chunk.py rename to tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_combined_chunk.py index 7400cd08dd3..d4911427e73 100644 --- a/tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_combined_chunk.py +++ b/tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_combined_chunk.py @@ -22,7 +22,7 @@ from litellm.litellm_core_utils.llm_response_utils.convert_dict_to_response impo convert_to_streaming_response, convert_to_streaming_response_async, ) -from litellm.llms.anthropic.pass_through.adapters.streaming_iterator import ( +from litellm.llms.anthropic.messages.adapters.streaming_iterator import ( AnthropicStreamWrapper, _CombinedChunkSplitter, ) diff --git a/tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_compaction.py b/tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_compaction.py similarity index 98% rename from tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_compaction.py rename to tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_compaction.py index 2610824edf4..1d60f71e196 100644 --- a/tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_compaction.py +++ b/tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_compaction.py @@ -6,7 +6,7 @@ from unittest.mock import MagicMock import pytest -from litellm.llms.anthropic.pass_through.adapters.streaming_iterator import ( +from litellm.llms.anthropic.messages.adapters.streaming_iterator import ( AnthropicStreamWrapper, ) from litellm.types.utils import Delta, StreamingChoices, Usage diff --git a/tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_empty_choices.py b/tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_empty_choices.py similarity index 97% rename from tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_empty_choices.py rename to tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_empty_choices.py index 66825124f25..826c16f6b97 100644 --- a/tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_empty_choices.py +++ b/tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_empty_choices.py @@ -12,7 +12,7 @@ import asyncio import json from typing import Any, AsyncIterator, Dict, List, Optional -from litellm.llms.anthropic.pass_through.adapters.streaming_iterator import ( +from litellm.llms.anthropic.messages.adapters.streaming_iterator import ( AnthropicStreamWrapper, ) from litellm.types.utils import Delta, ModelResponseStream, StreamingChoices, Usage diff --git a/tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_first_delta.py b/tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_first_delta.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_first_delta.py rename to tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_first_delta.py index 92234282bb2..32ec0ffae8e 100644 --- a/tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_first_delta.py +++ b/tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_first_delta.py @@ -27,7 +27,7 @@ from unittest.mock import MagicMock import pytest -from litellm.llms.anthropic.pass_through.adapters.streaming_iterator import ( +from litellm.llms.anthropic.messages.adapters.streaming_iterator import ( AnthropicStreamWrapper, ) from litellm.types.utils import ( diff --git a/tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_message_id.py b/tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_message_id.py new file mode 100644 index 00000000000..985cd38ef3c --- /dev/null +++ b/tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_message_id.py @@ -0,0 +1,301 @@ +""" +Streaming ``/v1/messages`` against a model that is neither Anthropic nor OpenAI is served by +translating the call onto ``/v1/chat/completions``, and the ``msg_`` id the caller is streamed +is minted right here. It is the only request id such a caller ever sees, so the spend row has +to be keyed on that same value rather than on the provider's own completion id. +""" + +import datetime +import json +from collections.abc import AsyncIterator, Iterator, Mapping, Sequence +from typing import Final +from unittest.mock import Mock + +import pytest +import respx +from pydantic import TypeAdapter + +import litellm +from litellm.llms.anthropic.messages.adapters.handler import ( + LiteLLMMessagesToCompletionTransformationHandler, +) +from litellm.llms.anthropic.messages.adapters.streaming_iterator import ( + AnthropicStreamWrapper, +) +from litellm.types.llms.openai import AllMessageValues, ChatCompletionToolParam +from litellm.types.utils import ModelResponseStream + +_EVENT: Final = TypeAdapter(Mapping[str, object]) +_MESSAGES: Final = TypeAdapter(list[AllMessageValues]) +_TOOLS: Final = TypeAdapter(list[ChatCompletionToolParam]) +_BLOCK_PROMPTS: Final[tuple[list[AllMessageValues], ...]] = ( + [{"role": "user", "content": [{"type": "text", "text": "Count every word. " * 100}]}], + [{"role": "tool", "content": [{"type": "text", "text": "Count every word. " * 100}], "tool_call_id": "call_1"}], + [ + { + "role": "user", + "content": [ + {"type": "image_url", "image_url": {"url": "https://image.example/test.png", "detail": "high"}} + ], + } + ], +) + + +def _assert_start_and_provider_final_usage( + raw_events: Sequence[bytes], request_body: bytes, estimate_enabled: bool +) -> None: + request: Final = _EVENT.validate_json(request_body) + events: Final = tuple(_EVENT.validate_json(chunk.decode().split("data: ", 1)[1]) for chunk in raw_events) + start: Final = _EVENT.validate_python( + next(event for event in events if event["type"] == "message_start")["message"] + ) + final: Final = next(event for event in events if event["type"] == "message_delta") + expected: Final = litellm.token_counter( + model="kimi-k2", + messages=_MESSAGES.validate_python(request["messages"]), + tools=_TOOLS.validate_python(request["tools"]), + ) + assert expected > 0 + assert start["usage"] == { + "input_tokens": expected if estimate_enabled else 0, + "output_tokens": 0, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + } + assert final["usage"] == {"input_tokens": 3, "output_tokens": 4} + + +@pytest.mark.parametrize("estimate_enabled", [None, False, True, "false"]) +def test_sync_message_start_opt_in_preserves_provider_final_usage( + respx_mock: respx.MockRouter, monkeypatch: pytest.MonkeyPatch, estimate_enabled: bool | str | None +) -> None: + if estimate_enabled is not None: + monkeypatch.setattr(litellm, "anthropic_messages_estimate_initial_input_tokens", estimate_enabled) + stream: Final = LiteLLMMessagesToCompletionTransformationHandler.anthropic_messages_handler( + max_tokens=16, + messages=MESSAGES, + system="Reply with a short greeting.", + tools=[{"name": "greet", "description": "Greet a person", "input_schema": {"type": "object"}}], + model="groq/kimi-k2", + stream=True, + custom_llm_provider="groq", + ) + _assert_start_and_provider_final_usage( + list(stream), respx_mock.calls.last.request.content, estimate_enabled is True + ) + + +@pytest.mark.asyncio +@pytest.mark.parametrize("estimate_enabled", [None, False, True, "false"]) +async def test_async_message_start_opt_in_preserves_provider_final_usage( + respx_mock: respx.MockRouter, monkeypatch: pytest.MonkeyPatch, estimate_enabled: bool | str | None +) -> None: + if estimate_enabled is not None: + monkeypatch.setattr(litellm, "anthropic_messages_estimate_initial_input_tokens", estimate_enabled) + stream: Final = await LiteLLMMessagesToCompletionTransformationHandler.async_anthropic_messages_handler( + max_tokens=16, + messages=MESSAGES, + system="Reply with a short greeting.", + tools=[{"name": "greet", "description": "Greet a person", "input_schema": {"type": "object"}}], + model="groq/kimi-k2", + stream=True, + custom_llm_provider="groq", + ) + raw: Final = [chunk async for chunk in stream] + _assert_start_and_provider_final_usage(raw, respx_mock.calls.last.request.content, estimate_enabled is True) + + +class _FailingUpstream: + def __iter__(self) -> Iterator[ModelResponseStream]: + raise RuntimeError("upstream failed before its first chunk") + + def __aiter__(self) -> AsyncIterator[ModelResponseStream]: + raise RuntimeError("upstream failed before its first chunk") + + +@pytest.mark.asyncio +@pytest.mark.parametrize("is_async", [False, True]) +async def test_disabled_initial_estimate_skips_token_counting(monkeypatch: pytest.MonkeyPatch, is_async: bool) -> None: + counter: Final = Mock(side_effect=AssertionError("disabled estimation must not count tokens")) + monkeypatch.setattr(litellm, "anthropic_messages_estimate_initial_input_tokens", False) + monkeypatch.setattr(litellm, "token_counter", counter) + wrapper: Final = AnthropicStreamWrapper( + _FailingUpstream(), model="kimi-k2", completion_request={"messages": MESSAGES} + ) + first: Final = _EVENT.validate_python(await anext(wrapper) if is_async else next(wrapper)) + message: Final = _EVENT.validate_python(first["message"]) + assert message["usage"] == { + "input_tokens": 0, + "output_tokens": 0, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + } + counter.assert_not_called() + + +@pytest.mark.parametrize("messages", _BLOCK_PROMPTS) +def test_sync_initial_estimate_counts_content_blocks( + messages: list[AllMessageValues], respx_mock: respx.MockRouter, monkeypatch: pytest.MonkeyPatch +) -> None: + monkeypatch.setattr(litellm, "anthropic_messages_estimate_initial_input_tokens", True) + image: Final = respx_mock.get("https://image.example/test.png").respond(503) + wrapper: Final = AnthropicStreamWrapper(iter([]), model="gpt-4o", completion_request={"messages": messages}) + expected: Final = litellm.token_counter(model="gpt-4o", messages=messages, use_default_image_token_count=True) + first: Final = _EVENT.validate_python(next(wrapper)) + message: Final = _EVENT.validate_python(first["message"]) + assert message["usage"] == { + "input_tokens": expected, + "output_tokens": 0, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + } + assert not image.called + + +@pytest.mark.asyncio +@pytest.mark.parametrize("messages", _BLOCK_PROMPTS) +async def test_async_initial_estimate_counts_content_blocks( + messages: list[AllMessageValues], respx_mock: respx.MockRouter, monkeypatch: pytest.MonkeyPatch +) -> None: + monkeypatch.setattr(litellm, "anthropic_messages_estimate_initial_input_tokens", True) + image: Final = respx_mock.get("https://image.example/test.png").respond(503) + wrapper: Final = AnthropicStreamWrapper(iter([]), model="gpt-4o", completion_request={"messages": messages}) + expected: Final = litellm.token_counter(model="gpt-4o", messages=messages, use_default_image_token_count=True) + first: Final = _EVENT.validate_python(await anext(wrapper)) + message: Final = _EVENT.validate_python(first["message"]) + assert message["usage"] == { + "input_tokens": expected, + "output_tokens": 0, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + } + assert not image.called + + +@pytest.mark.parametrize("prompt", [{}, {"messages": []}, {"messages": "invalid"}]) +def test_sync_initial_estimate_fallback_does_not_consume_upstream( + prompt: Mapping[str, object], monkeypatch: pytest.MonkeyPatch +) -> None: + monkeypatch.setattr(litellm, "anthropic_messages_estimate_initial_input_tokens", True) + wrapper: Final = AnthropicStreamWrapper(_FailingUpstream(), model="kimi-k2", completion_request=prompt) + first: Final = _EVENT.validate_python(next(wrapper)) + message: Final = _EVENT.validate_python(first["message"]) + assert message["usage"] == { + "input_tokens": 0, + "output_tokens": 0, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + } + assert list(wrapper) == [] + + +@pytest.mark.asyncio +@pytest.mark.parametrize("prompt", [{}, {"messages": []}, {"messages": "invalid"}]) +async def test_async_initial_estimate_fallback_does_not_consume_upstream( + prompt: Mapping[str, object], monkeypatch: pytest.MonkeyPatch +) -> None: + monkeypatch.setattr(litellm, "anthropic_messages_estimate_initial_input_tokens", True) + wrapper: Final = AnthropicStreamWrapper(_FailingUpstream(), model="kimi-k2", completion_request=prompt) + first: Final = _EVENT.validate_python(await anext(wrapper)) + message: Final = _EVENT.validate_python(first["message"]) + assert message["usage"] == { + "input_tokens": 0, + "output_tokens": 0, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + } + with pytest.raises(RuntimeError, match="upstream failed before its first chunk"): + [chunk async for chunk in wrapper] + + +MESSAGES = [{"role": "user", "content": "hello"}] + +GROQ_CHAT_URL = "https://api.groq.com/openai/v1/chat/completions" + +CHAT_SSE_BODY = ( + b'data: {"id":"chatcmpl-lit6825","object":"chat.completion.chunk","created":1,' + b'"model":"kimi-k2","choices":[{"index":0,"delta":{"role":"assistant","content":"hi"},' + b'"finish_reason":null}]}\n\n' + b'data: {"id":"chatcmpl-lit6825","object":"chat.completion.chunk","created":1,' + b'"model":"kimi-k2","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],' + b'"usage":{"prompt_tokens":3,"completion_tokens":4,"total_tokens":7}}\n\n' + b"data: [DONE]\n\n" +) + + +def _logging_obj(call_id: str): + from litellm.litellm_core_utils.litellm_logging import Logging + + return Logging( + model="kimi-k2", + messages=MESSAGES, + stream=True, + call_type="anthropic_messages", + start_time=datetime.datetime.now(datetime.timezone.utc), + litellm_call_id=call_id, + function_id="1234", + ) + + +def _streamed_message_id(raw_events: list[bytes]) -> str: + events = [json.loads(chunk.decode().split("data: ", 1)[1]) for chunk in raw_events] + message_start = next(e for e in events if e["type"] == "message_start") + return message_start["message"]["id"] + + +@pytest.fixture(autouse=True) +def _intercept_groq(respx_mock: respx.MockRouter, monkeypatch: pytest.MonkeyPatch): + monkeypatch.setenv("GROQ_API_KEY", "gsk-lit6825-test") + monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") + litellm.in_memory_llm_clients_cache.flush_cache() + respx_mock.post(GROQ_CHAT_URL).respond( + status_code=200, + headers={"Content-Type": "text/event-stream"}, + content=CHAT_SSE_BODY, + ) + + +@pytest.mark.asyncio +async def test_async_streaming_hands_the_logging_object_the_message_id_the_caller_is_streamed(): + logging_obj = _logging_obj("6825beef-0000-4000-8000-000000000010") + + sse = await LiteLLMMessagesToCompletionTransformationHandler.async_anthropic_messages_handler( + max_tokens=1024, + messages=MESSAGES, + model="groq/kimi-k2", + stream=True, + custom_llm_provider="groq", + litellm_logging_obj=logging_obj, + ) + streamed_id = _streamed_message_id([chunk async for chunk in sse]) + + assert streamed_id.startswith("msg_") + assert logging_obj.streamed_anthropic_message_id == streamed_id + + +def test_sync_streaming_hands_the_logging_object_the_message_id_the_caller_is_streamed(): + logging_obj = _logging_obj("6825beef-0000-4000-8000-000000000011") + + sse = LiteLLMMessagesToCompletionTransformationHandler.anthropic_messages_handler( + max_tokens=1024, + messages=MESSAGES, + model="groq/kimi-k2", + stream=True, + custom_llm_provider="groq", + litellm_logging_obj=logging_obj, + ) + streamed_id = _streamed_message_id(list(sse)) + + assert streamed_id.startswith("msg_") + assert logging_obj.streamed_anthropic_message_id == streamed_id + + +def test_concurrent_streams_are_keyed_on_their_own_message_id(): + """Two callers streaming at once must not be handed, or logged under, one another's id.""" + first = AnthropicStreamWrapper(completion_stream=iter([]), model="kimi-k2") + second = AnthropicStreamWrapper(completion_stream=iter([]), model="kimi-k2") + + assert first._message_id != second._message_id + assert _streamed_message_id(list(first.anthropic_sse_wrapper())) == first._message_id + assert _streamed_message_id(list(second.anthropic_sse_wrapper())) == second._message_id diff --git a/tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_mid_stream_error.py b/tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_mid_stream_error.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_mid_stream_error.py rename to tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_mid_stream_error.py index 6951253349e..2cc0d86a3a8 100644 --- a/tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_mid_stream_error.py +++ b/tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_mid_stream_error.py @@ -36,7 +36,7 @@ from litellm.exceptions import MidStreamFallbackError from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapper -from litellm.llms.anthropic.pass_through.adapters.streaming_iterator import ( +from litellm.llms.anthropic.messages.adapters.streaming_iterator import ( AnthropicStreamWrapper, _mid_stream_error_sse_event, ) diff --git a/tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_sse_stream.py b/tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_sse_stream.py similarity index 52% rename from tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_sse_stream.py rename to tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_sse_stream.py index fbbbc579d94..79976564e5a 100644 --- a/tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_sse_stream.py +++ b/tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_sse_stream.py @@ -8,9 +8,12 @@ wrapper's chunks/messages/model so disconnect-time partial billing can read them from typing import Final from unittest.mock import MagicMock +import httpx import pytest -from litellm.llms.anthropic.pass_through.adapters.streaming_iterator import ( +from litellm.litellm_core_utils.litellm_logging import Logging +from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapper +from litellm.llms.anthropic.messages.adapters.streaming_iterator import ( AnthropicSSEStream, AnthropicStreamWrapper, ) @@ -85,3 +88,67 @@ def test_sse_stream_exposes_chunks_messages_and_model(): assert stream.messages == [{"role": "user", "content": "hi"}] chunks: Final = stream.chunks assert isinstance(chunks, list) and len(chunks) == 2 + + +@pytest.mark.asyncio +@pytest.mark.parametrize("started", [False, True]) +async def test_sse_stream_close_releases_http_response_before_upstream_body(started: bool) -> None: + response: Final = httpx.Response(200, stream=httpx.ByteStream(b"unread upstream body")) + upstream: Final = CustomStreamWrapper( + completion_stream=response, + model="test-model", + custom_llm_provider="openai", + logging_obj=Logging( + model="test-model", + messages=[{"role": "user", "content": "hi"}], + stream=True, + call_type="acompletion", + start_time=1.0, + litellm_call_id="disconnect-test", + function_id="test", + ), + ) + stream: Final = AnthropicSSEStream(AnthropicStreamWrapper(completion_stream=upstream, model="test-model")) + if started: + assert (await anext(stream)).startswith(b"event: message_start") + assert not response.is_stream_consumed + assert not response.is_closed + + await stream.aclose() + await stream.aclose() + + assert response.is_closed + assert not response.is_stream_consumed + with pytest.raises(StopAsyncIteration): + await anext(stream) + + +class _CloseableAsyncStream(_AsyncStream): + def __init__(self, items: list[MagicMock]) -> None: + super().__init__(items) + self.close_calls = 0 + + async def aclose(self) -> None: + self.close_calls += 1 + + +@pytest.mark.asyncio +@pytest.mark.parametrize("finish_stream", [False, True]) +async def test_sse_stream_releases_upstream_once_after_content(finish_stream: bool) -> None: + upstream: Final = _CloseableAsyncStream( + [_make_chunk(Delta(content="hello")), _make_chunk(Delta(), finish_reason="stop")] + ) + stream: Final = AnthropicSSEStream(AnthropicStreamWrapper(completion_stream=upstream, model="test-model")) + events: Final[list[bytes]] = [] + async for event in stream: + events.append(event) + if not finish_stream and b"event: content_block_delta" in event: + break + assert any(b'"text":"hello"' in event.replace(b" ", b"") for event in events) + if finish_stream: + assert events[-1].startswith(b"event: message_stop") + + await stream.aclose() + await stream.aclose() + + assert upstream.close_calls == 1 diff --git a/tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_stop_reason.py b/tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_stop_reason.py similarity index 97% rename from tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_stop_reason.py rename to tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_stop_reason.py index 5f5007d52b5..48ffad5a050 100644 --- a/tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_stop_reason.py +++ b/tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_stop_reason.py @@ -12,7 +12,7 @@ bridge emitted ``stop_reason: "end_turn"`` and Anthropic tool-runners import pytest -from litellm.llms.anthropic.pass_through.adapters.streaming_iterator import ( +from litellm.llms.anthropic.messages.adapters.streaming_iterator import ( AnthropicStreamWrapper, ) from litellm.llms.ollama.chat.transformation import ( diff --git a/tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_tool_args.py b/tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_tool_args.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_tool_args.py rename to tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_tool_args.py index 224775ad5b9..d34a978f228 100644 --- a/tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_tool_args.py +++ b/tests/unit/llms/anthropic/messages/adapters/test_streaming_iterator_tool_args.py @@ -17,7 +17,7 @@ from unittest.mock import MagicMock import pytest -from litellm.llms.anthropic.pass_through.adapters.streaming_iterator import ( +from litellm.llms.anthropic.messages.adapters.streaming_iterator import ( AnthropicStreamWrapper, ) from litellm.types.utils import ( diff --git a/tests/unit/llms/anthropic/pass_through/conftest.py b/tests/unit/llms/anthropic/messages/conftest.py similarity index 100% rename from tests/unit/llms/anthropic/pass_through/conftest.py rename to tests/unit/llms/anthropic/messages/conftest.py diff --git a/tests/unit/llms/vertex_ai/vertex_ai_partner_models/llama3/__init__.py b/tests/unit/llms/anthropic/messages/context_management/__init__.py similarity index 100% rename from tests/unit/llms/vertex_ai/vertex_ai_partner_models/llama3/__init__.py rename to tests/unit/llms/anthropic/messages/context_management/__init__.py diff --git a/tests/unit/llms/anthropic/pass_through/context_management/test_clear_tool_uses.py b/tests/unit/llms/anthropic/messages/context_management/test_clear_tool_uses.py similarity index 98% rename from tests/unit/llms/anthropic/pass_through/context_management/test_clear_tool_uses.py rename to tests/unit/llms/anthropic/messages/context_management/test_clear_tool_uses.py index 2ffa73dda21..2567d1b76db 100644 --- a/tests/unit/llms/anthropic/pass_through/context_management/test_clear_tool_uses.py +++ b/tests/unit/llms/anthropic/messages/context_management/test_clear_tool_uses.py @@ -10,17 +10,17 @@ from unittest.mock import AsyncMock, MagicMock import pytest import litellm -from litellm.llms.anthropic.pass_through.adapters.handler import _run_polyfill_if_enabled -from litellm.llms.anthropic.pass_through.context_management import ( +from litellm.llms.anthropic.messages.adapters.handler import _run_polyfill_if_enabled +from litellm.llms.anthropic.messages.context_management import ( AnthropicContextManagementError, PolyfillResult, apply_context_management, ) -from litellm.llms.anthropic.pass_through.context_management.constants import ( +from litellm.llms.anthropic.messages.context_management.constants import ( CLEARED_TOOL_RESULT_PLACEHOLDER, COMPACT_SUMMARY_MODEL_SETTING_KEY, ) -from litellm.llms.anthropic.pass_through.context_management.editors.clear_tool_uses import ( +from litellm.llms.anthropic.messages.context_management.editors.clear_tool_uses import ( apply_clear_tool_uses_20250919, ) from litellm.types.llms.anthropic import AppliedEdit diff --git a/tests/unit/llms/anthropic/pass_through/context_management/test_compact.py b/tests/unit/llms/anthropic/messages/context_management/test_compact.py similarity index 91% rename from tests/unit/llms/anthropic/pass_through/context_management/test_compact.py rename to tests/unit/llms/anthropic/messages/context_management/test_compact.py index 9b3084f0e7c..159c3586c53 100644 --- a/tests/unit/llms/anthropic/pass_through/context_management/test_compact.py +++ b/tests/unit/llms/anthropic/messages/context_management/test_compact.py @@ -21,11 +21,11 @@ import pytest from fastapi import HTTPException import litellm -from litellm.llms.anthropic.pass_through.context_management import ( +from litellm.llms.anthropic.messages.context_management import ( AnthropicContextManagementError, apply_context_management, ) -from litellm.llms.anthropic.pass_through.context_management.editors.compact import ( +from litellm.llms.anthropic.messages.context_management.editors.compact import ( _augment_system_with_summary, _extract_summary_text, _select_last_user_question, @@ -34,7 +34,7 @@ from litellm.llms.anthropic.pass_through.context_management.editors.compact impo apply_client_compaction_block_history, apply_compact_20260112, ) -from litellm.llms.anthropic.pass_through.context_management.result import ( +from litellm.llms.anthropic.messages.context_management.result import ( PolyfillResult, ) from litellm.proxy._types import ( @@ -46,7 +46,7 @@ from litellm.proxy._types import ( UserAPIKeyAuth, ) from litellm.proxy.hooks.parallel_request_limiter_v3 import RateLimitUnverifiableError -from tests.unit.llms.anthropic.pass_through.conftest import ProxyAuthState +from tests.unit.llms.anthropic.messages.conftest import ProxyAuthState MODEL = "openai/gpt-4o" @@ -321,7 +321,7 @@ async def test_trigger_below_minimum_raises(): async def test_trigger_at_minimum_does_not_raise(): """Exactly 50 000 is allowed — only strictly less than 50k is rejected.""" with patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value=None, ): result = await apply_compact_20260112( @@ -346,7 +346,7 @@ async def test_trigger_at_minimum_does_not_raise(): async def test_opt_in_gating_no_summary_model_configured(): messages = _simple_messages() with patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value=None, ): result = await apply_compact_20260112( @@ -373,7 +373,7 @@ async def test_opt_in_gating_no_summary_model_keeps_post_compaction_tail(): messages = _messages_with_compaction("prior summary text") with patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value=None, ): result = await apply_compact_20260112( @@ -455,7 +455,7 @@ async def test_slice_only_path_with_existing_compaction_block(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=500), # well under threshold @@ -492,7 +492,7 @@ async def test_slice_only_no_compaction_block_under_threshold(): messages = _simple_messages() with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=500), @@ -523,12 +523,12 @@ async def test_full_summary_path(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), # over 150k threshold patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", new_callable=AsyncMock, return_value=mock_response, ), @@ -577,7 +577,7 @@ async def test_full_summary_path_uses_router_when_available(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="my-summary-model", ), patch("litellm.token_counter", return_value=200_000), @@ -613,12 +613,12 @@ async def test_litellm_metadata_propagated_to_summary_call(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", new_callable=AsyncMock, return_value=mock_response, ) as mock_call, @@ -650,12 +650,12 @@ async def test_summary_call_failed(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", new_callable=AsyncMock, side_effect=RuntimeError("network error"), ), @@ -686,12 +686,12 @@ async def test_summary_extraction_failed_no_tags(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", new_callable=AsyncMock, return_value=mock_response, ), @@ -718,7 +718,7 @@ async def test_pause_after_compaction_ignored_warning(): """pause_after_compaction: true → warning recorded, request proceeds normally.""" messages = _simple_messages() with patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value=None, ): result = await apply_compact_20260112( @@ -741,7 +741,7 @@ async def test_pause_after_compaction_ignored_warning(): async def test_unsupported_trigger_type_falls_back_to_default(): messages = _simple_messages() with patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value=None, ): result = await apply_compact_20260112( @@ -779,12 +779,12 @@ async def test_custom_instructions_used_verbatim(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", side_effect=_fake_call_summary_model, ), ): @@ -824,12 +824,12 @@ async def test_default_instructions_appended_with_no_tool_suffix_when_no_tools() with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", side_effect=_fake_call_summary_model, ), ): @@ -860,12 +860,12 @@ async def test_default_instructions_with_tools_appends_no_tool_suffix(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", side_effect=_fake_call_summary_model, ), ): @@ -894,12 +894,12 @@ async def test_system_prompt_forwarded_to_summary_call_as_string(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", side_effect=_fake_call_summary_model, ), ): @@ -934,12 +934,12 @@ async def test_system_prompt_forwarded_to_summary_call_as_content_blocks(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", side_effect=_fake_call_summary_model, ), ): @@ -977,12 +977,12 @@ async def test_summary_call_carries_prior_compaction_summary_into_system(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", side_effect=_fake_call_summary_model, ), ): @@ -1014,12 +1014,12 @@ async def test_summary_call_omits_system_message_when_system_is_none(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", side_effect=_fake_call_summary_model, ), ): @@ -1055,12 +1055,12 @@ async def test_summary_call_does_not_emit_consecutive_user_turns(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", side_effect=_fake_call_summary_model, ), ): @@ -1085,10 +1085,10 @@ async def test_summary_call_sends_default_max_tokens(): (which require it) don't reject the request and silently fall back to ``summary_call_failed``. """ - from litellm.llms.anthropic.pass_through.context_management.constants import ( + from litellm.llms.anthropic.messages.context_management.constants import ( COMPACT_SUMMARY_MAX_TOKENS, ) - from litellm.llms.anthropic.pass_through.context_management.editors.compact import ( + from litellm.llms.anthropic.messages.context_management.editors.compact import ( _call_summary_model, ) @@ -1112,7 +1112,7 @@ async def test_summary_call_sends_default_max_tokens(): async def test_summary_call_honors_max_tokens_override(): """Operators can override the default summary ``max_tokens`` via ``general_settings.context_management_summary_max_tokens``.""" - from litellm.llms.anthropic.pass_through.context_management.editors.compact import ( + from litellm.llms.anthropic.messages.context_management.editors.compact import ( _read_summary_max_tokens_setting, ) @@ -1129,7 +1129,7 @@ async def test_summary_call_honors_max_tokens_override(): ): assert _read_summary_max_tokens_setting() == 8192 - from litellm.llms.anthropic.pass_through.context_management.editors.compact import ( + from litellm.llms.anthropic.messages.context_management.editors.compact import ( _call_summary_model, ) @@ -1148,10 +1148,10 @@ def test_summary_max_tokens_setting_falls_back_for_invalid_values(): """Invalid override values (non-int, non-positive, missing) fall back to the compiled default so a typo in ``general_settings`` doesn't break the summary call.""" - from litellm.llms.anthropic.pass_through.context_management.constants import ( + from litellm.llms.anthropic.messages.context_management.constants import ( COMPACT_SUMMARY_MAX_TOKENS, ) - from litellm.llms.anthropic.pass_through.context_management.editors.compact import ( + from litellm.llms.anthropic.messages.context_management.editors.compact import ( _read_summary_max_tokens_setting, ) @@ -1168,10 +1168,10 @@ def test_summary_max_tokens_setting_falls_back_for_invalid_values(): async def test_summary_call_sends_default_timeout(): """``timeout`` is set on the summary call so a slow or unresponsive summary model cannot hang the parent ``/v1/messages`` request indefinitely.""" - from litellm.llms.anthropic.pass_through.context_management.constants import ( + from litellm.llms.anthropic.messages.context_management.constants import ( COMPACT_SUMMARY_TIMEOUT_SECONDS, ) - from litellm.llms.anthropic.pass_through.context_management.editors.compact import ( + from litellm.llms.anthropic.messages.context_management.editors.compact import ( _call_summary_model, ) @@ -1235,12 +1235,12 @@ async def test_summary_model_denied_when_key_not_in_allowlist(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", mock_call, ), ): @@ -1267,12 +1267,12 @@ async def test_summary_model_allowed_when_in_key_allowlist(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", mock_call, ), ): @@ -1298,12 +1298,12 @@ async def test_summary_model_allowed_when_no_user_api_key_auth(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", mock_call, ), ): @@ -1322,12 +1322,12 @@ async def test_summary_model_allowed_when_no_user_api_key_auth(): async def _compact_as(auth: UserAPIKeyAuth, summary_call: AsyncMock) -> PolyfillResult: with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", summary_call, ), ): @@ -1443,12 +1443,12 @@ async def test_summary_model_denied_when_key_over_model_budget(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", mock_call, ), patch("litellm.proxy.proxy_server.model_max_budget_limiter", limiter), @@ -1494,12 +1494,12 @@ async def test_summary_model_denied_when_user_over_model_budget(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", mock_call, ), patch("litellm.proxy.proxy_server.model_max_budget_limiter", limiter), @@ -1537,7 +1537,7 @@ async def test_summary_model_denied_when_user_over_model_budget(): async def test_summary_model_denied_when_team_member_over_model_budget(monkeypatch: pytest.MonkeyPatch): from litellm.caching.dual_cache import DualCache - from litellm.llms.anthropic.pass_through.context_management.constants import COMPACT_SUMMARY_MODEL_SETTING_KEY + from litellm.llms.anthropic.messages.context_management.constants import COMPACT_SUMMARY_MODEL_SETTING_KEY from litellm.models.team_membership import LiteLLM_TeamMembership from litellm.proxy._types import ( LiteLLM_BudgetTable, @@ -1671,12 +1671,12 @@ async def test_summary_model_denied_when_end_user_over_model_budget(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", mock_call, ), patch("litellm.proxy.proxy_server.model_max_budget_limiter", limiter), @@ -1712,12 +1712,12 @@ async def test_summary_model_allowed_when_within_model_budget(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", mock_call, ), patch("litellm.proxy.proxy_server.model_max_budget_limiter", limiter), @@ -1803,12 +1803,12 @@ async def test_summary_model_rate_limit_check_errors(limiter_error, summary_call with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", mock_call, ), patch("litellm.proxy.proxy_server.proxy_logging_obj", proxy_logging), @@ -1845,12 +1845,12 @@ async def test_summary_model_denied_when_over_rate_limit(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", mock_call, ), patch("litellm.proxy.proxy_server.proxy_logging_obj", proxy_logging), @@ -1881,12 +1881,12 @@ async def test_summary_model_allowed_when_within_rate_limit(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", mock_call, ), patch("litellm.proxy.proxy_server.proxy_logging_obj", proxy_logging), @@ -1929,12 +1929,12 @@ async def test_summary_model_allowed_while_the_caller_holds_the_keys_only_parall with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", mock_call, ), patch("litellm.proxy.proxy_server.proxy_logging_obj", _proxy_logging_like_the_live_proxy(limiter)), @@ -1965,12 +1965,12 @@ async def test_summary_model_rate_limit_skipped_for_legacy_limiter(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", mock_call, ), patch("litellm.proxy.proxy_server.proxy_logging_obj", proxy_logging), @@ -2017,12 +2017,12 @@ async def test_summary_model_denied_when_team_over_model_budget(): with ( patch( # test-quality-ok: apply_compact_20260112 reads the summary model setting as a module global, no seam - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), # test-quality-ok: forces the over-threshold branch patch( # test-quality-ok: the summary call is the observable that must NOT happen when the team is over budget - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", mock_call, ), patch( # test-quality-ok: the limiter is a proxy_server module global the editor imports, no injection seam @@ -2073,12 +2073,12 @@ async def test_scoped_budget_metadata_propagated_to_summary_call(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", new_callable=AsyncMock, return_value=mock_response, ) as mock_call, @@ -2101,7 +2101,7 @@ async def test_scoped_budget_metadata_propagated_to_summary_call(): async def test_summary_call_passes_end_user_id_as_top_level_user(): """``_call_summary_model`` forwards the propagated end-user id as the top-level ``user`` kwarg that legacy limiter / prometheus end-user tracking reads.""" - from litellm.llms.anthropic.pass_through.context_management.editors.compact import ( + from litellm.llms.anthropic.messages.context_management.editors.compact import ( _call_summary_model, ) @@ -2124,7 +2124,7 @@ async def test_summary_call_passes_end_user_id_as_top_level_user(): async def test_summary_call_omits_user_when_no_end_user_id(): """No end-user id on the parent request means no ``user`` kwarg is sent.""" - from litellm.llms.anthropic.pass_through.context_management.editors.compact import ( + from litellm.llms.anthropic.messages.context_management.editors.compact import ( _call_summary_model, ) @@ -2158,12 +2158,12 @@ async def test_model_budget_metadata_propagated_to_summary_call(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", new_callable=AsyncMock, return_value=mock_response, ) as mock_call, @@ -2195,12 +2195,12 @@ async def test_summary_call_propagates_allowed_model_region(): with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._call_summary_model", + "litellm.llms.anthropic.messages.context_management.editors.compact._call_summary_model", mock_call, ), ): @@ -2221,7 +2221,7 @@ async def test_summary_call_omits_allowed_model_region_when_unset(): """Callers without a region restriction must not get an ``allowed_model_region=None`` kwarg, which would otherwise force the router to evaluate region filtering. """ - from litellm.llms.anthropic.pass_through.context_management.editors.compact import ( + from litellm.llms.anthropic.messages.context_management.editors.compact import ( _call_summary_model, ) @@ -2244,7 +2244,7 @@ async def test_summary_call_omits_allowed_model_region_when_unset(): async def test_summary_call_forwards_allowed_model_region_when_set(): """When the caller is region-restricted, the kwarg reaches the router.""" - from litellm.llms.anthropic.pass_through.context_management.editors.compact import ( + from litellm.llms.anthropic.messages.context_management.editors.compact import ( _call_summary_model, ) @@ -2275,7 +2275,7 @@ async def test_dispatcher_routes_compact_edit(): """compact_20260112 in the dispatcher resolves to opt-in gate when no model set.""" messages = _simple_messages() with patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value=None, ): result = await apply_context_management( @@ -2317,7 +2317,7 @@ async def test_dispatcher_trigger_below_minimum_raises_through(): async def test_run_polyfill_skipped_when_context_management_in_additional_drop_params(): """additional_drop_params=["context_management"] is the explicit opt-out.""" - from litellm.llms.anthropic.pass_through.adapters.handler import ( + from litellm.llms.anthropic.messages.adapters.handler import ( _run_polyfill_if_enabled, ) @@ -2338,13 +2338,13 @@ async def test_run_polyfill_runs_when_litellm_drop_params_true(monkeypatch): """drop_params must not disable the polyfill: context_management is a LiteLLM-supported param (polyfilled where not native), and drop_params only exists to strip genuinely unsupported params.""" - from litellm.llms.anthropic.pass_through.adapters.handler import ( + from litellm.llms.anthropic.messages.adapters.handler import ( _run_polyfill_if_enabled, ) monkeypatch.setattr(litellm, "drop_params", True) with patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value=None, ): result = await _run_polyfill_if_enabled( @@ -2363,7 +2363,7 @@ async def test_run_polyfill_runs_when_litellm_drop_params_true(monkeypatch): async def test_run_polyfill_skipped_when_spec_empty(): """Empty context_management_spec must also return None (no polyfill work).""" - from litellm.llms.anthropic.pass_through.adapters.handler import ( + from litellm.llms.anthropic.messages.adapters.handler import ( _run_polyfill_if_enabled, ) @@ -2444,7 +2444,7 @@ def _openai_chat_response(): async def _call_async_adapter_handler(**handler_kwargs: Any): - from litellm.llms.anthropic.pass_through.adapters.handler import ( + from litellm.llms.anthropic.messages.adapters.handler import ( LiteLLMMessagesToCompletionTransformationHandler, ) @@ -2503,7 +2503,7 @@ async def test_async_handler_additional_drop_params_strips_context_management(): def _call_sync_adapter_handler(**handler_kwargs: Any): - from litellm.llms.anthropic.pass_through.adapters.handler import ( + from litellm.llms.anthropic.messages.adapters.handler import ( LiteLLMMessagesToCompletionTransformationHandler, ) @@ -2555,7 +2555,7 @@ async def test_prepare_context_managed_request_forwards_proxy_litellm_metadata() Anthropic-shape ``metadata`` arg (which only carries ``user_id``). Otherwise the summary subcall lands on the router with no parent attribution, and those tokens go unbilled to the caller's key/team.""" - from litellm.llms.anthropic.pass_through.adapters.handler import ( + from litellm.llms.anthropic.messages.adapters.handler import ( prepare_context_managed_request, ) @@ -2568,7 +2568,7 @@ async def test_prepare_context_managed_request_forwards_proxy_litellm_metadata() with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="claude-haiku-4-5", ), patch("litellm.token_counter", return_value=200_000), @@ -2759,7 +2759,7 @@ def test_endpoint_runs_failure_hook_on_500_context_management_error(): def test_count_effective_tokens_counts_midturn_system_correction(): - from litellm.llms.anthropic.pass_through.context_management.editors.compact import ( + from litellm.llms.anthropic.messages.context_management.editors.compact import ( _count_effective_tokens, ) @@ -2786,7 +2786,7 @@ def test_count_effective_tokens_counts_midturn_system_correction(): def test_build_summary_messages_keeps_midturn_system_correction_in_place(): - from litellm.llms.anthropic.pass_through.context_management.editors.compact import ( + from litellm.llms.anthropic.messages.context_management.editors.compact import ( _build_summary_messages, ) @@ -2820,7 +2820,7 @@ async def test_threshold_check_counts_tokens_off_the_event_loop(monkeypatch): warm_tokenizer, ) - from litellm.llms.anthropic.pass_through.context_management.constants import ( + from litellm.llms.anthropic.messages.context_management.constants import ( COMPACT_SUMMARY_MODEL_SETTING_KEY, ) from litellm.proxy.proxy_server import general_settings diff --git a/tests/unit/llms/anthropic/pass_through/context_management/test_constants.py b/tests/unit/llms/anthropic/messages/context_management/test_constants.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/context_management/test_constants.py rename to tests/unit/llms/anthropic/messages/context_management/test_constants.py index 680c2b6f79a..da0d9c38791 100644 --- a/tests/unit/llms/anthropic/pass_through/context_management/test_constants.py +++ b/tests/unit/llms/anthropic/messages/context_management/test_constants.py @@ -8,7 +8,7 @@ import pytest import litellm from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER -from litellm.llms.anthropic.pass_through.context_management.constants import ( +from litellm.llms.anthropic.messages.context_management.constants import ( CLEARED_TOOL_RESULT_PLACEHOLDER, ) from litellm.types.utils import ( diff --git a/tests/unit/llms/anthropic/pass_through/context_management/test_dispatcher.py b/tests/unit/llms/anthropic/messages/context_management/test_dispatcher.py similarity index 98% rename from tests/unit/llms/anthropic/pass_through/context_management/test_dispatcher.py rename to tests/unit/llms/anthropic/messages/context_management/test_dispatcher.py index 66957456c95..b79e33b0c3b 100644 --- a/tests/unit/llms/anthropic/pass_through/context_management/test_dispatcher.py +++ b/tests/unit/llms/anthropic/messages/context_management/test_dispatcher.py @@ -2,7 +2,7 @@ Unit tests for the context_management polyfill dispatcher. """ -from litellm.llms.anthropic.pass_through.context_management import ( +from litellm.llms.anthropic.messages.context_management import ( apply_context_management, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/auth/__init__.py b/tests/unit/llms/anthropic/messages/native/__init__.py similarity index 100% rename from tests/unit/proxy/_experimental/mcp_server/auth/__init__.py rename to tests/unit/llms/anthropic/messages/native/__init__.py diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_advisor_integration.py b/tests/unit/llms/anthropic/messages/native/test_advisor_integration.py similarity index 92% rename from tests/unit/llms/anthropic/pass_through/messages/test_advisor_integration.py rename to tests/unit/llms/anthropic/messages/native/test_advisor_integration.py index f5f30fb86c1..8bd36c6564a 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_advisor_integration.py +++ b/tests/unit/llms/anthropic/messages/native/test_advisor_integration.py @@ -70,7 +70,7 @@ async def test_full_dispatch_interceptor_fires_and_loop_completes(): The interceptor must fire, run the loop (1 advisor call), and return a clean final response with no advisor tool_use blocks. """ - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( anthropic_messages, ) @@ -86,7 +86,7 @@ async def test_full_dispatch_interceptor_fires_and_loop_completes(): return _text_resp("def is_prime(n): ...") # executor: final with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", side_effect=mock_handler, ): result = await anthropic_messages( @@ -121,10 +121,10 @@ async def test_max_uses_enforced_through_full_handler(): AdvisorMaxIterationsError propagates out of anthropic_messages() when the executor keeps calling the advisor past max_uses. """ - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( anthropic_messages, ) - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorMaxIterationsError, ) @@ -137,7 +137,7 @@ async def test_max_uses_enforced_through_full_handler(): return _advisor_call_resp() with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", side_effect=mock_handler, ): with pytest.raises(AdvisorMaxIterationsError): @@ -162,7 +162,7 @@ async def test_anthropic_provider_bypasses_interceptor(): With custom_llm_provider='anthropic', the interceptor must NOT fire. The advisor_20260301 tool is forwarded as-is to the underlying handler. """ - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( anthropic_messages, ) @@ -170,7 +170,7 @@ async def test_anthropic_provider_bypasses_interceptor(): # Patch the non-interceptor code path — anthropic_messages_handler with patch( - "litellm.llms.anthropic.pass_through.messages.handler.anthropic_messages_handler", + "litellm.llms.anthropic.messages.native.handler.anthropic_messages_handler", return_value=direct_response, ) as mock_native: result = await anthropic_messages( @@ -209,7 +209,7 @@ async def test_named_params_forwarded_into_advisor_executor_subcall(): them, e.g. Vertex AI rejecting ``clear_thinking_20251015`` context_management edits with: ``strategy requires thinking to be enabled or adaptive``. """ - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( anthropic_messages, ) @@ -238,7 +238,7 @@ async def test_named_params_forwarded_into_advisor_executor_subcall(): return _text_resp("Final answer.") with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", side_effect=mock_handler, ): await anthropic_messages( @@ -289,7 +289,7 @@ async def test_pre_request_hook_override_does_not_collide_with_explicit_kwargs() Regression for Greptile P2 on PR #27810. """ - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( anthropic_messages, ) @@ -326,11 +326,11 @@ async def test_pre_request_hook_override_does_not_collide_with_explicit_kwargs() with ( patch( - "litellm.llms.anthropic.pass_through.messages.handler._execute_pre_request_hooks", + "litellm.llms.anthropic.messages.native.handler._execute_pre_request_hooks", side_effect=fake_pre_request_hooks, ), patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", side_effect=mock_handler, ), ): diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_agentic_streaming_iterator.py b/tests/unit/llms/anthropic/messages/native/test_agentic_streaming_iterator.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/messages/test_agentic_streaming_iterator.py rename to tests/unit/llms/anthropic/messages/native/test_agentic_streaming_iterator.py index 56fa3015d44..90a6ae3a574 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_agentic_streaming_iterator.py +++ b/tests/unit/llms/anthropic/messages/native/test_agentic_streaming_iterator.py @@ -11,7 +11,7 @@ import pytest from litellm.constants import STREAM_SSE_KEEPALIVE_PING_BYTES -from litellm.llms.anthropic.pass_through.messages.agentic_streaming_iterator import ( +from litellm.llms.anthropic.messages.native.agentic_streaming_iterator import ( SERVER_FULFILLED_TOOL_LEAK_ERROR_SSE_BYTES, AgenticAnthropicStreamingIterator, _handle_content_block_delta, diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_effort.py b/tests/unit/llms/anthropic/messages/native/test_anthropic_messages_effort.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_effort.py rename to tests/unit/llms/anthropic/messages/native/test_anthropic_messages_effort.py index 7885cc69b19..94476139313 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_effort.py +++ b/tests/unit/llms/anthropic/messages/native/test_anthropic_messages_effort.py @@ -7,7 +7,7 @@ from litellm.constants import ( DEFAULT_REASONING_EFFORT_XHIGH_THINKING_BUDGET, ) from litellm.llms.anthropic.common_utils import AnthropicError -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) from litellm.llms.openai_like.json_loader import SimpleProviderConfig diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_encrypted_reasoning.py b/tests/unit/llms/anthropic/messages/native/test_anthropic_messages_encrypted_reasoning.py similarity index 96% rename from tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_encrypted_reasoning.py rename to tests/unit/llms/anthropic/messages/native/test_anthropic_messages_encrypted_reasoning.py index ca81147da4c..cd6d2d9be96 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_encrypted_reasoning.py +++ b/tests/unit/llms/anthropic/messages/native/test_anthropic_messages_encrypted_reasoning.py @@ -1,7 +1,7 @@ from litellm.litellm_core_utils.prompt_templates.common_utils import ( encrypted_reasoning_signature, ) -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py b/tests/unit/llms/anthropic/messages/native/test_anthropic_messages_handler.py similarity index 93% rename from tests/unit/llms/anthropic/pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py rename to tests/unit/llms/anthropic/messages/native/test_anthropic_messages_handler.py index f4920505722..c11f58faec4 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py +++ b/tests/unit/llms/anthropic/messages/native/test_anthropic_messages_handler.py @@ -6,6 +6,7 @@ import uuid from typing import Any, Dict, Final, List import httpx +import responses import respx import pytest from fastapi.testclient import TestClient @@ -31,12 +32,63 @@ from litellm.utils import _invalidate_model_cost_lowercase_map import unittest.mock -def test_anthropic_experimental_pass_through_messages_handler(): +@pytest.mark.asyncio +@pytest.mark.parametrize("is_async", [False, True], ids=["sync", "async"]) +@pytest.mark.parametrize("stream", [False, True], ids=["complete", "stream"]) +async def test_openai_messages_forwards_stop_sequences_to_chat_completions( + monkeypatch: pytest.MonkeyPatch, is_async: bool, stream: bool +) -> None: + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + response: Final = ( + httpx.Response( + 200, + json={ + "id": "chatcmpl-stop-sequences", + "object": "chat.completion", + "created": 1, + "model": "gpt-4o-mini", + "choices": [{"index": 0, "message": {"role": "assistant", "content": ""}, "finish_reason": "stop"}], + "usage": {"prompt_tokens": 1, "completion_tokens": 0, "total_tokens": 1}, + }, + ) + if not stream + else httpx.Response( + 200, + headers={"content-type": "text/event-stream"}, + text='data: {"id":"chatcmpl-stop-sequences","object":"chat.completion.chunk","created":1,' + '"model":"gpt-4o-mini","choices":[{"index":0,"delta":{"content":""},"finish_reason":"stop"}]}\n\n' + "data: [DONE]\n\n", + ) + ) + with respx.mock as upstream: + chat: Final = upstream.post("https://api.openai.com/v1/chat/completions").mock(return_value=response) + create: Final = litellm.anthropic.messages.acreate if is_async else litellm.anthropic.messages.create + pending: Final = create( + model="openai/gpt-4o-mini", + max_tokens=80, + messages=[{"role": "user", "content": "hi"}], + stop_sequences=["STOPPROBE", "ENDPROBE"], + stream=stream, + api_key="test-api-key", + ) + result: Final = await pending if is_async else pending + if stream: + chunks: Final = [chunk async for chunk in result] if is_async else list(result) + assert "message_stop" in "".join(chunk.decode() if isinstance(chunk, bytes) else chunk for chunk in chunks) + else: + assert result["content"] == [{"type": "text", "text": ""}] + body: Final = json.loads(chat.calls.last.request.content) + assert body["stop"] == ["STOPPROBE", "ENDPROBE"] + assert "stop_sequences" not in body + + +@pytest.mark.parametrize("stop_sequences", [None, []], ids=["no-stops", "empty-stops"]) +def test_anthropic_messages_handler(stop_sequences): """ Test that api key is passed to litellm.responses for OpenAI models. OpenAI and Azure models are routed directly to the Responses API. """ - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( anthropic_messages_handler, ) @@ -47,6 +99,7 @@ def test_anthropic_experimental_pass_through_messages_handler(): messages=[{"role": "user", "content": "Hello, how are you?"}], model="openai/claude-3-5-sonnet-20240620", api_key="test-api-key", + stop_sequences=stop_sequences, ) except (ValueError, TypeError, AttributeError) as e: print(f"Error: {e}") @@ -116,12 +169,12 @@ async def test_openai_model_does_not_forward_stream_options_to_responses_api(): assert "stream_options" not in request_body -def test_anthropic_experimental_pass_through_messages_handler_dynamic_api_key_and_api_base_and_custom_values(): +def test_anthropic_messages_handler_dynamic_api_key_and_api_base_and_custom_values(): """ Test that api key, api base, and extra kwargs are forwarded to litellm.completion for Azure models. Azure models are routed through chat/completions (not the Responses API). """ - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( anthropic_messages_handler, ) @@ -148,7 +201,7 @@ async def test_anthropic_messages_sanitizes_empty_text_blocks_before_dispatch(): """Regression test for #22930. The unified /v1/messages path must strip empty text blocks before forwarding, otherwise Anthropic returns 400 "text content blocks must be non-empty".""" - from litellm.llms.anthropic.pass_through.messages import handler + from litellm.llms.anthropic.messages.native import handler msgs = [ { @@ -186,7 +239,7 @@ async def test_anthropic_messages_sanitizes_empty_text_blocks_before_dispatch(): @pytest.mark.asyncio async def test_anthropic_messages_sanitizes_tool_use_ids_before_dispatch(): - from litellm.llms.anthropic.pass_through.messages import handler + from litellm.llms.anthropic.messages.native import handler msgs = [ { @@ -230,14 +283,14 @@ async def _async_return(value): return value -def test_anthropic_experimental_pass_through_messages_handler_custom_llm_provider(): +def test_anthropic_messages_handler_custom_llm_provider(): """ Test that litellm.completion is called when a custom LLM provider is given. Provider resolution now happens exactly once, inside litellm.completion itself (BerriAI/litellm#37716), so the handler passes the original unresolved model through. """ - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( anthropic_messages_handler, ) @@ -321,7 +374,7 @@ def test_openai_model_with_thinking_converts_to_reasoning(): OpenAI models are routed directly to the Responses API, so we verify that litellm.responses() is called with `reasoning` properly set. """ - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( anthropic_messages_handler, ) @@ -361,7 +414,7 @@ class TestThinkingParameterTransformation: def test_claude_model_preserves_thinking_with_budget_tokens(self): """Test that Claude models get thinking parameter passed through with exact budget_tokens.""" - from litellm.llms.anthropic.pass_through.adapters.transformation import ( + from litellm.llms.anthropic.messages.adapters.transformation import ( LiteLLMAnthropicMessagesAdapter, ) @@ -376,7 +429,7 @@ class TestThinkingParameterTransformation: def test_non_claude_model_converts_thinking_to_reasoning_effort(self): """Test that non-Claude models convert thinking to reasoning_effort.""" - from litellm.llms.anthropic.pass_through.adapters.transformation import ( + from litellm.llms.anthropic.messages.adapters.transformation import ( LiteLLMAnthropicMessagesAdapter, ) @@ -394,7 +447,7 @@ class TestThinkingParameterTransformation: def test_translate_thinking_for_model_summary_when_enabled(self): """When reasoning_auto_summary is True, summary='detailed' is injected.""" import litellm - from litellm.llms.anthropic.pass_through.adapters.transformation import ( + from litellm.llms.anthropic.messages.adapters.transformation import ( LiteLLMAnthropicMessagesAdapter, ) @@ -412,7 +465,7 @@ class TestThinkingParameterTransformation: def test_translate_thinking_for_model_preserves_user_summary(self): """User-provided summary is always preserved regardless of flag.""" - from litellm.llms.anthropic.pass_through.adapters.transformation import ( + from litellm.llms.anthropic.messages.adapters.transformation import ( LiteLLMAnthropicMessagesAdapter, ) @@ -429,7 +482,7 @@ class TestThinkingSummaryPreservation: def test_thinking_summary_concise_preserved_for_openai(self): """User-provided summary='concise' should not be replaced with 'detailed'.""" - from litellm.llms.anthropic.pass_through.adapters.handler import ( + from litellm.llms.anthropic.messages.adapters.handler import ( LiteLLMMessagesToCompletionTransformationHandler, ) @@ -445,7 +498,7 @@ class TestThinkingSummaryPreservation: def test_thinking_summary_auto_preserved_for_openai(self): """User-provided summary='auto' should be preserved.""" - from litellm.llms.anthropic.pass_through.adapters.handler import ( + from litellm.llms.anthropic.messages.adapters.handler import ( LiteLLMMessagesToCompletionTransformationHandler, ) @@ -462,7 +515,7 @@ class TestThinkingSummaryPreservation: def test_summary_added_when_auto_summary_enabled(self): """When reasoning_auto_summary is True, summary='detailed' is added.""" import litellm - from litellm.llms.anthropic.pass_through.adapters.handler import ( + from litellm.llms.anthropic.messages.adapters.handler import ( LiteLLMMessagesToCompletionTransformationHandler, ) @@ -487,7 +540,7 @@ class TestThinkingSummaryPreservation: def test_no_summary_by_default_string_reasoning(self): """By default (reasoning_auto_summary=False), summary is not added for string reasoning_effort.""" import litellm - from litellm.llms.anthropic.pass_through.adapters.handler import ( + from litellm.llms.anthropic.messages.adapters.handler import ( LiteLLMMessagesToCompletionTransformationHandler, ) @@ -510,7 +563,7 @@ class TestThinkingSummaryPreservation: def test_no_summary_by_default_dict_reasoning(self): """By default (reasoning_auto_summary=False), summary is not injected into dict reasoning_effort.""" import litellm - from litellm.llms.anthropic.pass_through.adapters.handler import ( + from litellm.llms.anthropic.messages.adapters.handler import ( LiteLLMMessagesToCompletionTransformationHandler, ) @@ -533,7 +586,7 @@ class TestThinkingSummaryPreservation: def test_summary_added_when_env_var_set(self, monkeypatch): """When LITELLM_REASONING_AUTO_SUMMARY env var is true, summary is added.""" import litellm - from litellm.llms.anthropic.pass_through.adapters.handler import ( + from litellm.llms.anthropic.messages.adapters.handler import ( LiteLLMMessagesToCompletionTransformationHandler, ) @@ -560,7 +613,7 @@ class TestThinkingSummaryPreservation: def test_user_provided_summary_preserved_even_when_flag_off(self): """When user already set summary in dict reasoning_effort, it's preserved regardless of flag.""" import litellm - from litellm.llms.anthropic.pass_through.adapters.handler import ( + from litellm.llms.anthropic.messages.adapters.handler import ( LiteLLMMessagesToCompletionTransformationHandler, ) @@ -581,7 +634,7 @@ class TestThinkingSummaryPreservation: def test_openai_model_with_thinking_summary_end_to_end(self): """End-to-end: anthropic_messages_handler should preserve thinking.summary for OpenAI models.""" - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( anthropic_messages_handler, ) @@ -610,7 +663,7 @@ class TestThinkingSummaryPreservation: def test_responses_adapter_preserves_summary(self): """translate_thinking_to_reasoning should include summary when user provides it.""" - from litellm.llms.anthropic.pass_through.responses_adapters.transformation import ( + from litellm.llms.anthropic.messages.responses_adapters.transformation import ( LiteLLMAnthropicToResponsesAPIAdapter, ) @@ -621,7 +674,7 @@ class TestThinkingSummaryPreservation: def test_responses_adapter_no_summary_by_default(self): """translate_thinking_to_reasoning should not include summary by default (opt-in).""" import litellm - from litellm.llms.anthropic.pass_through.responses_adapters.transformation import ( + from litellm.llms.anthropic.messages.responses_adapters.transformation import ( LiteLLMAnthropicToResponsesAPIAdapter, ) @@ -637,7 +690,7 @@ class TestThinkingSummaryPreservation: def test_translate_thinking_for_model_preserves_summary(self): """translate_thinking_for_model should include summary in reasoning_effort dict when user provides it.""" - from litellm.llms.anthropic.pass_through.adapters.transformation import ( + from litellm.llms.anthropic.messages.adapters.transformation import ( LiteLLMAnthropicMessagesAdapter, ) @@ -651,7 +704,7 @@ class TestThinkingSummaryPreservation: def test_translate_thinking_for_model_disabled_stays_plain_string_when_auto_summary_enabled(self): """Disabled thinking must stay a plain string even when reasoning_auto_summary is on.""" import litellm - from litellm.llms.anthropic.pass_through.adapters.transformation import ( + from litellm.llms.anthropic.messages.adapters.transformation import ( LiteLLMAnthropicMessagesAdapter, ) @@ -690,7 +743,7 @@ def _empty_block_msgs(): def test_handler_strips_when_no_presanitized_flag(): """Sync entry point (no async wrapper): handler must still sanitize.""" - from litellm.llms.anthropic.pass_through.messages import handler, utils + from litellm.llms.anthropic.messages.native import handler, utils with patch.object( utils, @@ -710,7 +763,7 @@ def test_handler_strips_when_no_presanitized_flag(): def test_handler_skips_strip_when_presanitized(): """Async wrapper already sanitized -> handler must NOT rescan.""" - from litellm.llms.anthropic.pass_through.messages import handler, utils + from litellm.llms.anthropic.messages.native import handler, utils with patch.object( utils, @@ -731,7 +784,7 @@ def test_handler_skips_strip_when_presanitized(): def test_handler_flattens_replayed_unencrypted_web_search_results(): """Synthesized search blocks replayed as history must reach the provider as text.""" - from litellm.llms.anthropic.pass_through.messages import handler + from litellm.llms.anthropic.messages.native import handler captured = {} @@ -786,7 +839,7 @@ def test_handler_flattens_replayed_unencrypted_web_search_results(): def test_presanitized_flag_not_leaked_to_provider_params(): """The private sentinel must be popped, never forwarded as a request param.""" - from litellm.llms.anthropic.pass_through.messages import handler + from litellm.llms.anthropic.messages.native import handler captured = {} @@ -815,7 +868,7 @@ def test_presanitized_flag_not_leaked_to_provider_params(): @pytest.mark.asyncio async def test_async_wrapper_sets_presanitized_and_sanitizes_once(): """End-to-end: wrapper sanitizes (once) AND signals the handler to skip.""" - from litellm.llms.anthropic.pass_through.messages import handler, utils + from litellm.llms.anthropic.messages.native import handler, utils captured = {} @@ -859,7 +912,7 @@ def _gate_stubs(monkeypatch): provider config handed to the native passthrough path and ``translation_calls`` counts hits on the Anthropic->OpenAI translation handlers. """ - from litellm.llms.anthropic.pass_through.messages import handler + from litellm.llms.anthropic.messages.native import handler captured = {} translation_calls = {"count": 0} @@ -889,7 +942,7 @@ def _gate_stubs(monkeypatch): def test_gate_passthrough_when_supported_endpoints_opts_in(monkeypatch): """provider=openai + model_info.supported_endpoints containing /v1/messages must route to the native passthrough config, NOT the translation handlers.""" - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( anthropic_messages_handler, ) from litellm.llms.openai_like.messages.transformation import ( @@ -915,7 +968,7 @@ def test_gate_passthrough_when_supported_endpoints_opts_in(monkeypatch): def test_gate_translates_when_supported_endpoints_absent(monkeypatch): """Default behavior is unchanged: without the /v1/messages opt-in, an openai deployment is translated (Responses API), never passed through natively.""" - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( anthropic_messages_handler, ) @@ -937,7 +990,7 @@ def test_gate_translates_when_supported_endpoints_absent(monkeypatch): def test_gate_passthrough_skipped_when_only_chat_completions_supported(monkeypatch): """A deployment that lists only /v1/chat/completions is still translated; the opt-in is specifically the /v1/messages entry.""" - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( anthropic_messages_handler, ) @@ -970,7 +1023,7 @@ def test_gate_passthrough_forwards_cache_control_ttl_only_when_deployment_opts_i ): """The passthrough config strips cache_control.ttl unless the deployment sets model_info.cache_control_ttl to exactly true.""" - from litellm.llms.anthropic.pass_through.messages.handler import ( + from litellm.llms.anthropic.messages.native.handler import ( anthropic_messages_handler, ) @@ -1321,7 +1374,7 @@ class TestMessagesStreamingSuccessLogging: @pytest.mark.asyncio async def test_responses_bridge_streaming_emits_success_logging(self, capture_success_payloads): """The Responses bridge, which is the default for openai/ deployments.""" - from litellm.llms.anthropic.pass_through.responses_adapters.handler import ( + from litellm.llms.anthropic.messages.responses_adapters.handler import ( LiteLLMMessagesToResponsesAPIHandler, ) @@ -1362,14 +1415,14 @@ class TestMessagesStreamingSuccessLogging: """The chat-completions bridge, reached via litellm.use_chat_completions_url_for_anthropic_messages. Its router lookup is stubbed to what an SDK caller with no proxy running already resolves to.""" - from litellm.llms.anthropic.pass_through.adapters.handler import ( + from litellm.llms.anthropic.messages.adapters.handler import ( LiteLLMMessagesToCompletionTransformationHandler, ) _bind_logging_worker_to_running_loop() with patch( - "litellm.llms.anthropic.pass_through.adapters.handler._proxy_router_fallback", + "litellm.llms.anthropic.messages.adapters.handler._proxy_router_fallback", return_value=None, ): sse_stream = await LiteLLMMessagesToCompletionTransformationHandler.async_anthropic_messages_handler( @@ -1422,7 +1475,7 @@ async def test_anthropic_messages_maps_provider_exception_before_failure_logging The 403 row pins the upstream status on the way through the mapper: Anthropic's documented permission_error must reach the caller as a 403, never as the mapper's APIConnectionError 500 fallthrough.""" - from litellm.llms.anthropic.pass_through.messages import handler + from litellm.llms.anthropic.messages.native import handler capture = _FailureCapture() monkeypatch.setattr(litellm, "callbacks", [capture]) @@ -1464,7 +1517,7 @@ async def test_anthropic_messages_leaves_non_provider_failures_unmapped(): """The mapping boundary is for provider failures only. A request rejected before the provider call (here invalid metadata) must surface as the original exception, not as the mapper's APIConnectionError, whose message embeds a server traceback.""" - from litellm.llms.anthropic.pass_through.messages import handler + from litellm.llms.anthropic.messages.native import handler def upstream_must_not_be_called(request: httpx.Request) -> httpx.Response: raise AssertionError("the provider must not be called for a request rejected locally") @@ -1510,7 +1563,7 @@ def _recording_client(seen_urls: list[str]) -> AsyncHTTPHandler: @pytest.mark.asyncio async def test_provider_messages_api_base_env_is_not_shadowed_by_the_chat_default(monkeypatch): - from litellm.llms.anthropic.pass_through.messages import handler + from litellm.llms.anthropic.messages.native import handler monkeypatch.delenv("DEEPSEEK_API_BASE", raising=False) monkeypatch.setenv("DEEPSEEK_ANTHROPIC_API_BASE", "https://deepseek.internal.example/anthropic") @@ -1530,7 +1583,7 @@ async def test_provider_messages_api_base_env_is_not_shadowed_by_the_chat_defaul @pytest.mark.asyncio async def test_anthropic_messages_forwards_safeguards_and_unknown_beta_to_anthropic(): """Shapes are what Claude Code 2.1.278 sends and api.anthropic.com returns, captured 2026-09-21.""" - from litellm.llms.anthropic.pass_through.messages import handler + from litellm.llms.anthropic.messages.native import handler safeguards = [{"type": "dangerous_tool_use", "classifier_context": {"v": 1, "permission_mode": "auto"}}] client_betas = "dangerous-tool-use-2026-09-03,interleaved-thinking-2025-05-14" @@ -1578,7 +1631,7 @@ async def test_anthropic_messages_forwards_safeguards_and_unknown_beta_to_anthro @pytest.mark.asyncio async def test_anthropic_messages_streaming_forwards_safeguards_and_keeps_safeguard_results(): """Shapes are what Claude Code 2.1.278 sends and api.anthropic.com returns, captured 2026-09-21.""" - from litellm.llms.anthropic.pass_through.messages import handler + from litellm.llms.anthropic.messages.native import handler safeguards = [{"type": "dangerous_tool_use", "classifier_context": {"v": 1, "permission_mode": "auto"}}] tool_verdicts = {"toolu_01": {"type": "evaluated", "outcome": "not_flagged"}} @@ -1683,7 +1736,7 @@ async def test_anthropic_messages_forwards_safeguards_and_dangerous_tool_use_bet local_beta_headers_config, client_headers ): """Bedrock Invoke takes betas in the body's `anthropic_beta` and 400s on `safeguards` without the beta, so the beta rides along with the field.""" - from litellm.llms.anthropic.pass_through.messages import handler + from litellm.llms.anthropic.messages.native import handler safeguards, safeguard_results = _claude_code_auto_mode_request() captured: dict[str, object] = {} @@ -1709,16 +1762,20 @@ async def test_anthropic_messages_forwards_safeguards_and_dangerous_tool_use_bet @pytest.mark.asyncio @pytest.mark.parametrize("client_headers", _CLIENT_BETA_HEADERS) async def test_anthropic_messages_forwards_safeguards_and_dangerous_tool_use_beta_to_vertex( - local_beta_headers_config, client_headers -): + local_beta_headers_config: None, client_headers: dict[str, str] +) -> None: """Vertex rawPredict takes the beta as the `anthropic-beta` header and 400s on `safeguards` without it, so the beta rides along with the field.""" - from litellm.llms.anthropic.pass_through.messages import handler - from litellm.llms.vertex_ai.vertex_llm_base import VertexBase + from litellm.llms.anthropic.messages.native import handler safeguards, safeguard_results = _claude_code_auto_mode_request() captured: dict[str, object] = {} - with patch.object(VertexBase, "_ensure_access_token", return_value=("test-token", "test-project")): + with responses.RequestsMock(assert_all_requests_are_fired=False) as oauth: + oauth.add( + responses.POST, + "https://oauth2.googleapis.com/token", + json={"access_token": "test-token", "expires_in": 3600}, + ) response = await handler.anthropic_messages( max_tokens=16, messages=[{"role": "user", "content": "hi"}], @@ -1726,7 +1783,14 @@ async def test_anthropic_messages_forwards_safeguards_and_dangerous_tool_use_bet custom_llm_provider="vertex_ai", vertex_project="test-project", vertex_location="global", - vertex_credentials="{}", + vertex_credentials=json.dumps( + { + "type": "authorized_user", + "client_id": "synthetic-client", + "client_secret": "synthetic-secret", + "refresh_token": "synthetic-refresh", + } + ), client=_upstream_answering_with(safeguard_results, captured), safeguards=safeguards, extra_headers=client_headers, @@ -1820,7 +1884,7 @@ def _native_upstream(*, stream: bool, model: str, **extra: object) -> AsyncHTTPH async def _native_messages(model: str, upstream: AsyncHTTPHandler, *, stream: bool, **extra: object) -> object: - from litellm.llms.anthropic.pass_through.messages import handler + from litellm.llms.anthropic.messages.native import handler safeguards, _ = _claude_code_auto_mode_request() with patch("litellm.proxy.proxy_server.general_settings", {"safeguards_classifier_model": "classifier"}): @@ -2268,7 +2332,7 @@ async def test_anthropic_messages_bedrock_dynamic_region(): async def test_anthropic_messages_with_safeguards_and_no_classifier_keep_the_upstream_400_for_malformed_messages( malformed_messages: object, ) -> None: - from litellm.llms.anthropic.pass_through.messages import handler + from litellm.llms.anthropic.messages.native import handler def upstream_rejects_the_messages(request: httpx.Request) -> httpx.Response: return httpx.Response( @@ -2298,7 +2362,7 @@ async def test_anthropic_messages_with_safeguards_and_no_classifier_keep_the_ups def test_native_messages_tool_config_point_marks_last_tool_and_drops_the_key(monkeypatch): """LIT-9880 on /v1/messages: the hook wrote the tool_config point back into kwargs and the native path dropped it silently, so the tools went out without any cache breakpoint.""" - from litellm.llms.anthropic.pass_through.messages import handler + from litellm.llms.anthropic.messages.native import handler captured = {} diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_per_turn_control.py b/tests/unit/llms/anthropic/messages/native/test_anthropic_messages_per_turn_control.py similarity index 98% rename from tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_per_turn_control.py rename to tests/unit/llms/anthropic/messages/native/test_anthropic_messages_per_turn_control.py index 05c12c6a285..e29f962ec8c 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_per_turn_control.py +++ b/tests/unit/llms/anthropic/messages/native/test_anthropic_messages_per_turn_control.py @@ -2,7 +2,7 @@ import pytest from litellm import anthropic_beta_headers_manager from litellm.anthropic_beta_headers_manager import update_headers_with_filtered_beta -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) from litellm.llms.openai_like.json_loader import SimpleProviderConfig diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_router.py b/tests/unit/llms/anthropic/messages/native/test_anthropic_messages_router.py similarity index 100% rename from tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_router.py rename to tests/unit/llms/anthropic/messages/native/test_anthropic_messages_router.py diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_service_tier.py b/tests/unit/llms/anthropic/messages/native/test_anthropic_messages_service_tier.py similarity index 92% rename from tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_service_tier.py rename to tests/unit/llms/anthropic/messages/native/test_anthropic_messages_service_tier.py index 6472ccd1b2e..75d5b583cc8 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_service_tier.py +++ b/tests/unit/llms/anthropic/messages/native/test_anthropic_messages_service_tier.py @@ -2,7 +2,7 @@ from typing import Final import pytest -from litellm.llms.anthropic.pass_through.messages.utils import AnthropicMessagesRequestUtils +from litellm.llms.anthropic.messages.native.utils import AnthropicMessagesRequestUtils REQUEST: Final[dict[str, object]] = { "max_tokens": 64, diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_speed.py b/tests/unit/llms/anthropic/messages/native/test_anthropic_messages_speed.py similarity index 96% rename from tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_speed.py rename to tests/unit/llms/anthropic/messages/native/test_anthropic_messages_speed.py index 45c6ebaa39b..9be3cdf55b3 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_speed.py +++ b/tests/unit/llms/anthropic/messages/native/test_anthropic_messages_speed.py @@ -1,9 +1,9 @@ import litellm import pytest -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) -from litellm.llms.anthropic.pass_through.messages.utils import ( +from litellm.llms.anthropic.messages.native.utils import ( AnthropicMessagesRequestUtils, ) diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_structured_outputs.py b/tests/unit/llms/anthropic/messages/native/test_anthropic_messages_structured_outputs.py similarity index 98% rename from tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_structured_outputs.py rename to tests/unit/llms/anthropic/messages/native/test_anthropic_messages_structured_outputs.py index db3ff58d80a..5d9ad409f15 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_anthropic_messages_structured_outputs.py +++ b/tests/unit/llms/anthropic/messages/native/test_anthropic_messages_structured_outputs.py @@ -8,7 +8,7 @@ from typing import Final import pytest import litellm -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) from litellm.types.router import GenericLiteLLMParams diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_anthropic_experimental_pass_through_messages_transformation.py b/tests/unit/llms/anthropic/messages/native/test_anthropic_messages_transformation.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/messages/test_anthropic_experimental_pass_through_messages_transformation.py rename to tests/unit/llms/anthropic/messages/native/test_anthropic_messages_transformation.py index 457d5d5e1c8..aa6625561ba 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_anthropic_experimental_pass_through_messages_transformation.py +++ b/tests/unit/llms/anthropic/messages/native/test_anthropic_messages_transformation.py @@ -10,7 +10,7 @@ from pydantic import JsonValue import litellm from litellm.litellm_core_utils.litellm_logging import Logging -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) from litellm.llms.anthropic.wif import get_anthropic_wif_token diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_content_after_stop_reason.py b/tests/unit/llms/anthropic/messages/native/test_content_after_stop_reason.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/messages/test_content_after_stop_reason.py rename to tests/unit/llms/anthropic/messages/native/test_content_after_stop_reason.py index f57a872c82a..1accce8383b 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_content_after_stop_reason.py +++ b/tests/unit/llms/anthropic/messages/native/test_content_after_stop_reason.py @@ -17,7 +17,7 @@ from typing import List import pytest -from litellm.llms.anthropic.pass_through.adapters.streaming_iterator import ( +from litellm.llms.anthropic.messages.adapters.streaming_iterator import ( AnthropicStreamWrapper, ) from litellm.types.utils import Delta, ModelResponseStream, StreamingChoices, Usage diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_fake_stream_iterator.py b/tests/unit/llms/anthropic/messages/native/test_fake_stream_iterator.py similarity index 97% rename from tests/unit/llms/anthropic/pass_through/messages/test_fake_stream_iterator.py rename to tests/unit/llms/anthropic/messages/native/test_fake_stream_iterator.py index 476cea2833c..233145f2706 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_fake_stream_iterator.py +++ b/tests/unit/llms/anthropic/messages/native/test_fake_stream_iterator.py @@ -2,7 +2,7 @@ import json from collections.abc import Iterable, Mapping from typing import Final -from litellm.llms.anthropic.pass_through.messages.fake_stream_iterator import ( +from litellm.llms.anthropic.messages.native.fake_stream_iterator import ( FakeAnthropicMessagesStreamIterator, ) diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_mcp_handler.py b/tests/unit/llms/anthropic/messages/native/test_mcp_handler.py similarity index 95% rename from tests/unit/llms/anthropic/pass_through/messages/test_mcp_handler.py rename to tests/unit/llms/anthropic/messages/native/test_mcp_handler.py index 3aca6181d12..73c2edbce19 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_mcp_handler.py +++ b/tests/unit/llms/anthropic/messages/native/test_mcp_handler.py @@ -4,13 +4,13 @@ from unittest.mock import AsyncMock, patch import pytest -from litellm.llms.anthropic.pass_through.adapters.transformation import ( +from litellm.llms.anthropic.messages.adapters.transformation import ( LiteLLMAnthropicMessagesAdapter, ) -from litellm.llms.anthropic.pass_through.messages.handler import ( +from litellm.llms.anthropic.messages.native.handler import ( anthropic_messages_handler, ) -from litellm.llms.anthropic.pass_through.messages.mcp_handler import ( +from litellm.llms.anthropic.messages.native.mcp_handler import ( _build_tool_result_message, _extract_tool_use_blocks, ) @@ -39,7 +39,7 @@ def test_anthropic_messages_handler_routes_litellm_proxy_mcp_to_the_gateway(): dispatch makes the whole feature unreachable while every unit test still passes. """ with patch( - "litellm.llms.anthropic.pass_through.messages.mcp_handler.anthropic_messages_with_mcp", + "litellm.llms.anthropic.messages.native.mcp_handler.anthropic_messages_with_mcp", new=AsyncMock(return_value={"routed": True}), ) as routed: result = anthropic_messages_handler( @@ -59,7 +59,7 @@ def test_anthropic_messages_handler_routes_litellm_proxy_mcp_to_the_gateway(): def test_anthropic_messages_handler_skips_the_gateway_on_recursion(): """The gateway's own follow-up call must not re-enter the gateway.""" with patch( - "litellm.llms.anthropic.pass_through.messages.mcp_handler.anthropic_messages_with_mcp", + "litellm.llms.anthropic.messages.native.mcp_handler.anthropic_messages_with_mcp", new=AsyncMock(return_value={"routed": True}), ) as routed: with pytest.raises(ValueError, match="anthropic_messages_handler is not implemented for sync calls"): @@ -78,7 +78,7 @@ def test_anthropic_messages_handler_skips_the_gateway_on_recursion(): def test_anthropic_messages_handler_leaves_native_tools_alone(): """A plain Anthropic tool is not an MCP reference and must not reach the gateway.""" with patch( - "litellm.llms.anthropic.pass_through.messages.mcp_handler.anthropic_messages_with_mcp", + "litellm.llms.anthropic.messages.native.mcp_handler.anthropic_messages_with_mcp", new=AsyncMock(return_value={"routed": True}), ) as routed: with pytest.raises(ValueError, match="anthropic_messages_handler is not implemented for sync calls"): @@ -161,7 +161,7 @@ async def test_anthropic_messages_with_mcp_forwards_the_callers_mcp_credentials( token, per-user env) silently returns nothing while the model claims it has no access. Only a no-auth server would look healthy. """ - from litellm.llms.anthropic.pass_through.messages import mcp_handler + from litellm.llms.anthropic.messages.native import mcp_handler from litellm.responses.mcp.request_context import MCPRequestContext context = MCPRequestContext( @@ -246,7 +246,7 @@ async def test_anthropic_messages_with_mcp_hands_execution_the_requests_served_t """ from mcp.types import Tool - from litellm.llms.anthropic.pass_through.messages import mcp_handler + from litellm.llms.anthropic.messages.native import mcp_handler from litellm.responses.mcp.request_context import MCPRequestContext served = [ @@ -311,7 +311,7 @@ async def test_anthropic_messages_with_mcp_stops_when_every_tool_call_is_skipped Anthropic rejects that, so the caller would get an unhandled 400 from the middle of the loop rather than the model's own answer. """ - from litellm.llms.anthropic.pass_through.messages import mcp_handler + from litellm.llms.anthropic.messages.native import mcp_handler from litellm.responses.mcp.request_context import MCPRequestContext tool_use_response = { @@ -349,7 +349,7 @@ async def test_anthropic_messages_with_mcp_stops_when_every_tool_call_is_skipped @pytest.mark.asyncio async def test_anthropic_messages_with_mcp_classifies_only_the_response_the_client_gets(): - from litellm.llms.anthropic.pass_through.messages import mcp_handler + from litellm.llms.anthropic.messages.native import mcp_handler from litellm.responses.mcp.request_context import MCPRequestContext from litellm.router import Router @@ -409,7 +409,7 @@ async def _mcp_safeguards_turn_recording_beta_map_loads(custom_llm_provider: str import threading from litellm import anthropic_beta_headers_manager - from litellm.llms.anthropic.pass_through.messages import mcp_handler + from litellm.llms.anthropic.messages.native import mcp_handler from litellm.responses.mcp.request_context import MCPRequestContext loader_threads: Final[list[int]] = [] # mutable-ok: records the thread each beta map load ran on diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_mid_conversation_system.py b/tests/unit/llms/anthropic/messages/native/test_mid_conversation_system.py similarity index 97% rename from tests/unit/llms/anthropic/pass_through/messages/test_mid_conversation_system.py rename to tests/unit/llms/anthropic/messages/native/test_mid_conversation_system.py index f527b4912d5..a1615c01d08 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_mid_conversation_system.py +++ b/tests/unit/llms/anthropic/messages/native/test_mid_conversation_system.py @@ -1,6 +1,6 @@ from collections import Counter -from litellm.llms.anthropic.pass_through.messages.mid_conversation_system import ( +from litellm.llms.anthropic.messages.native.mid_conversation_system import ( CONVERTED_SYSTEM_NOTE, convert_mid_conversation_system_turns, ) diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_parallel_tool_calls.py b/tests/unit/llms/anthropic/messages/native/test_parallel_tool_calls.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/messages/test_parallel_tool_calls.py rename to tests/unit/llms/anthropic/messages/native/test_parallel_tool_calls.py index 229eff4275a..5b2e285fed7 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_parallel_tool_calls.py +++ b/tests/unit/llms/anthropic/messages/native/test_parallel_tool_calls.py @@ -2,7 +2,7 @@ from typing import List -from litellm.llms.anthropic.pass_through.adapters.streaming_iterator import ( +from litellm.llms.anthropic.messages.adapters.streaming_iterator import ( AnthropicStreamWrapper, ) from litellm.types.utils import ( diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_reasoning_auto_summary_messages.py b/tests/unit/llms/anthropic/messages/native/test_reasoning_auto_summary_messages.py similarity index 97% rename from tests/unit/llms/anthropic/pass_through/messages/test_reasoning_auto_summary_messages.py rename to tests/unit/llms/anthropic/messages/native/test_reasoning_auto_summary_messages.py index cc951421b10..7334b4eeaa1 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_reasoning_auto_summary_messages.py +++ b/tests/unit/llms/anthropic/messages/native/test_reasoning_auto_summary_messages.py @@ -14,7 +14,7 @@ from unittest.mock import MagicMock, patch import litellm -from litellm.llms.anthropic.pass_through.messages.handler import ( +from litellm.llms.anthropic.messages.native.handler import ( anthropic_messages_handler, ) @@ -30,10 +30,10 @@ def _call_handler_and_capture_optional_params(thinking=None, **extra_kwargs): captured = {} with patch( - "litellm.llms.anthropic.pass_through.messages.handler." + "litellm.llms.anthropic.messages.native.handler." "base_llm_http_handler" ) as mock_handler, patch( - "litellm.llms.anthropic.pass_through.messages.handler." + "litellm.llms.anthropic.messages.native.handler." "ProviderConfigManager" ) as mock_pcm: # Make get_provider_anthropic_messages_config return a non-None config diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_reasoning_effort_translation.py b/tests/unit/llms/anthropic/messages/native/test_reasoning_effort_translation.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/messages/test_reasoning_effort_translation.py rename to tests/unit/llms/anthropic/messages/native/test_reasoning_effort_translation.py index c1295305c7a..50dc0deabfd 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_reasoning_effort_translation.py +++ b/tests/unit/llms/anthropic/messages/native/test_reasoning_effort_translation.py @@ -8,10 +8,10 @@ from litellm.constants import ( DEFAULT_REASONING_EFFORT_XHIGH_THINKING_BUDGET, ) from litellm.llms.anthropic.common_utils import AnthropicError -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) -from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude3_transformation import ( +from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeMessagesConfig, ) diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_request_optional_param_utils.py b/tests/unit/llms/anthropic/messages/native/test_request_optional_param_utils.py similarity index 98% rename from tests/unit/llms/anthropic/pass_through/messages/test_request_optional_param_utils.py rename to tests/unit/llms/anthropic/messages/native/test_request_optional_param_utils.py index 7a4f3aa5f90..d525ccfec37 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_request_optional_param_utils.py +++ b/tests/unit/llms/anthropic/messages/native/test_request_optional_param_utils.py @@ -9,7 +9,7 @@ Regression tests for the /v1/messages request-parse fast paths: import pytest import litellm -from litellm.llms.anthropic.pass_through.messages.utils import ( +from litellm.llms.anthropic.messages.native.utils import ( AnthropicMessagesRequestUtils, anthropic_messages_optional_param_keys, ) diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_response_cache.py b/tests/unit/llms/anthropic/messages/native/test_response_cache.py similarity index 98% rename from tests/unit/llms/anthropic/pass_through/messages/test_response_cache.py rename to tests/unit/llms/anthropic/messages/native/test_response_cache.py index 1df4ccec02c..133bcd96433 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_response_cache.py +++ b/tests/unit/llms/anthropic/messages/native/test_response_cache.py @@ -13,8 +13,8 @@ from litellm.caching.caching_handler import LLMCachingHandler from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER -from litellm.llms.anthropic.pass_through.messages import handler -from litellm.llms.anthropic.pass_through.messages.response_cache import ( +from litellm.llms.anthropic.messages.native import handler +from litellm.llms.anthropic.messages.native.response_cache import ( AnthropicMessagesStreamCacheWriter, CachedAnthropicMessagesStreamIterator, ) @@ -275,7 +275,7 @@ async def test_abandoned_stream_is_not_cached(local_cache, request_kwargs, monke async def test_cached_stream_replay_logs_once_when_polled_after_exhaustion(): from unittest.mock import AsyncMock, MagicMock, patch - from litellm.llms.anthropic.pass_through.messages.response_cache import ( + from litellm.llms.anthropic.messages.native.response_cache import ( CachedAnthropicMessagesStreamIterator, ) from litellm.proxy.pass_through_endpoints.streaming_handler import ( diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_sse_wrapper.py b/tests/unit/llms/anthropic/messages/native/test_sse_wrapper.py similarity index 98% rename from tests/unit/llms/anthropic/pass_through/messages/test_sse_wrapper.py rename to tests/unit/llms/anthropic/messages/native/test_sse_wrapper.py index d22478e16ef..cd6b3fa006d 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_sse_wrapper.py +++ b/tests/unit/llms/anthropic/messages/native/test_sse_wrapper.py @@ -2,7 +2,7 @@ import pytest from fastapi.testclient import TestClient -from litellm.llms.anthropic.pass_through.adapters.streaming_iterator import ( +from litellm.llms.anthropic.messages.adapters.streaming_iterator import ( AnthropicStreamWrapper, ) from litellm.types.utils import Delta, ModelResponseStream, StreamingChoices diff --git a/tests/unit/llms/anthropic/pass_through/messages/test_streaming_iterator.py b/tests/unit/llms/anthropic/messages/native/test_streaming_iterator.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/messages/test_streaming_iterator.py rename to tests/unit/llms/anthropic/messages/native/test_streaming_iterator.py index 4ed9054f3d3..dd50f60250a 100644 --- a/tests/unit/llms/anthropic/pass_through/messages/test_streaming_iterator.py +++ b/tests/unit/llms/anthropic/messages/native/test_streaming_iterator.py @@ -11,8 +11,8 @@ import pytest from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj -from litellm.llms.anthropic.pass_through.messages import streaming_iterator as streaming_iterator_module -from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( +from litellm.llms.anthropic.messages.native import streaming_iterator as streaming_iterator_module +from litellm.llms.anthropic.messages.native.streaming_iterator import ( INCOMPLETE_STREAM_ERROR_MESSAGE, AnthropicMessagesStreamHiddenParams, AnthropicMessagesStreamingResponse, @@ -26,8 +26,8 @@ from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( is_provider_error_chunk, parse_anthropic_error_event, ) -from litellm.llms.anthropic.pass_through.messages.transformation import AnthropicMessagesConfig -from litellm.llms.anthropic.pass_through.safeguards import SafeguardsEvaluator +from litellm.llms.anthropic.messages.native.transformation import AnthropicMessagesConfig +from litellm.llms.anthropic.messages.safeguards import SafeguardsEvaluator from litellm.llms.openai_like.messages.transformation import OpenAILikeAnthropicMessagesConfig from litellm.types.utils import Choices, Message, ModelResponse @@ -1157,7 +1157,7 @@ async def test_abort_upstream_logs_warning_when_aclose_raises(caplog): async def test_enqueue_for_client_returns_false_when_already_detached(): """_enqueue_for_client must return False immediately (without touching the queue) when client_detached is already set before the call.""" - from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( + from litellm.llms.anthropic.messages.native.streaming_iterator import ( BaseAnthropicMessagesStreamingIterator, ) @@ -1174,7 +1174,7 @@ async def test_enqueue_for_client_returns_false_when_already_detached(): async def test_enqueue_for_client_returns_false_when_client_detaches_while_queue_full(): """_enqueue_for_client must return False (and cancel the put) when the queue is full and client_detached fires before space becomes available.""" - from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( + from litellm.llms.anthropic.messages.native.streaming_iterator import ( BaseAnthropicMessagesStreamingIterator, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/faults/__init__.py b/tests/unit/llms/anthropic/messages/responses_adapters/__init__.py similarity index 100% rename from tests/unit/proxy/_experimental/mcp_server/faults/__init__.py rename to tests/unit/llms/anthropic/messages/responses_adapters/__init__.py diff --git a/tests/unit/llms/anthropic/pass_through/responses_adapters/test_responses_adapters_handler.py b/tests/unit/llms/anthropic/messages/responses_adapters/test_responses_adapters_handler.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/responses_adapters/test_responses_adapters_handler.py rename to tests/unit/llms/anthropic/messages/responses_adapters/test_responses_adapters_handler.py index 8fe6bd31082..7de722e1171 100644 --- a/tests/unit/llms/anthropic/pass_through/responses_adapters/test_responses_adapters_handler.py +++ b/tests/unit/llms/anthropic/messages/responses_adapters/test_responses_adapters_handler.py @@ -16,7 +16,7 @@ from litellm.litellm_core_utils.prompt_templates.common_utils import ( TOOL_RESULT_IMAGE_BOUNDARY, TOOL_RESULT_IMAGE_PLACEHOLDER, ) -from litellm.llms.anthropic.pass_through.responses_adapters.handler import ( +from litellm.llms.anthropic.messages.responses_adapters.handler import ( LiteLLMMessagesToResponsesAPIHandler, _build_responses_kwargs, ) diff --git a/tests/unit/llms/anthropic/pass_through/responses_adapters/test_responses_adapters_streaming_iterator.py b/tests/unit/llms/anthropic/messages/responses_adapters/test_responses_adapters_streaming_iterator.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/responses_adapters/test_responses_adapters_streaming_iterator.py rename to tests/unit/llms/anthropic/messages/responses_adapters/test_responses_adapters_streaming_iterator.py index e1dded214bf..5af8e69a0ea 100644 --- a/tests/unit/llms/anthropic/pass_through/responses_adapters/test_responses_adapters_streaming_iterator.py +++ b/tests/unit/llms/anthropic/messages/responses_adapters/test_responses_adapters_streaming_iterator.py @@ -1,6 +1,6 @@ """ Tests for AnthropicResponsesStreamWrapper -(litellm/llms/anthropic/pass_through/responses_adapters/streaming_iterator.py) +(litellm/llms/anthropic/messages/responses_adapters/streaming_iterator.py) """ import asyncio @@ -18,8 +18,8 @@ from litellm.exceptions import MidStreamFallbackError from litellm.litellm_core_utils.prompt_templates.common_utils import ( encrypted_reasoning_signature, ) -from litellm.llms.anthropic.pass_through.messages.utils import INCOMPLETE_STREAM_ERROR_MESSAGE -from litellm.llms.anthropic.pass_through.responses_adapters.streaming_iterator import ( +from litellm.llms.anthropic.messages.native.utils import INCOMPLETE_STREAM_ERROR_MESSAGE +from litellm.llms.anthropic.messages.responses_adapters.streaming_iterator import ( AnthropicResponsesStreamWrapper, ) from litellm.types.llms.openai import ResponseFailedEvent, ResponsesAPIResponse diff --git a/tests/unit/llms/anthropic/pass_through/responses_adapters/test_responses_adapters_transformation.py b/tests/unit/llms/anthropic/messages/responses_adapters/test_responses_adapters_transformation.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/responses_adapters/test_responses_adapters_transformation.py rename to tests/unit/llms/anthropic/messages/responses_adapters/test_responses_adapters_transformation.py index 829000c0c5f..f6fcb9e6f1e 100644 --- a/tests/unit/llms/anthropic/pass_through/responses_adapters/test_responses_adapters_transformation.py +++ b/tests/unit/llms/anthropic/messages/responses_adapters/test_responses_adapters_transformation.py @@ -1,6 +1,6 @@ """ Tests for LiteLLMAnthropicToResponsesAPIAdapter -(litellm/llms/anthropic/pass_through/responses_adapters/transformation.py) +(litellm/llms/anthropic/messages/responses_adapters/transformation.py) """ import json @@ -22,7 +22,7 @@ from litellm.litellm_core_utils.prompt_templates.common_utils import ( TOOL_RESULT_IMAGE_PLACEHOLDER, encrypted_reasoning_signature, ) -from litellm.llms.anthropic.pass_through.responses_adapters.transformation import ( +from litellm.llms.anthropic.messages.responses_adapters.transformation import ( LiteLLMAnthropicToResponsesAPIAdapter, ) from litellm.llms.openai.responses.transformation import OpenAIResponsesAPIConfig @@ -2413,7 +2413,7 @@ class TestPromptCacheBreakpointToResponses: assert log_output == self.LOG_OUTPUT def test_prompt_cache_options_forwarded_to_responses_kwargs(self): - from litellm.llms.anthropic.pass_through.responses_adapters.handler import ( + from litellm.llms.anthropic.messages.responses_adapters.handler import ( _build_responses_kwargs, ) diff --git a/tests/unit/llms/anthropic/messages/test_advisor_orchestration.py b/tests/unit/llms/anthropic/messages/test_advisor_orchestration.py index 5b0f743b836..810dfffaf8b 100644 --- a/tests/unit/llms/anthropic/messages/test_advisor_orchestration.py +++ b/tests/unit/llms/anthropic/messages/test_advisor_orchestration.py @@ -71,7 +71,7 @@ def _make_advisor_tool_use_response( def test_can_handle_edge_cases(): - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorOrchestrationHandler, ) @@ -99,7 +99,7 @@ async def test_anthropic_native_interceptor_skipped(): For provider=anthropic, can_handle() must return False. The interceptor must never call handle(). """ - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorOrchestrationHandler, ) @@ -115,7 +115,7 @@ async def test_anthropic_native_interceptor_skipped(): @pytest.mark.asyncio async def test_loop_no_advisor_call(): """Executor returns text on first try — no advisor call, loop exits immediately.""" - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorOrchestrationHandler, _call_messages_handler, ) @@ -124,7 +124,7 @@ async def test_loop_no_advisor_call(): executor_response = _make_text_response(final_text) with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", new_callable=AsyncMock, return_value=executor_response, ) as mock_call: @@ -157,7 +157,7 @@ async def test_loop_one_advisor_call(): Executor calls advisor once → advisor responds → executor produces final text. Total calls: 3 (executor, advisor, executor-final). """ - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorOrchestrationHandler, ) @@ -185,7 +185,7 @@ async def test_loop_one_advisor_call(): return final_resp # executor: final answer with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", side_effect=mock_call, ): h = AdvisorOrchestrationHandler() @@ -217,7 +217,7 @@ async def test_loop_one_advisor_call(): @pytest.mark.asyncio async def test_loop_max_uses_raises(): """Loop exceeding max_uses must raise AdvisorMaxIterationsError.""" - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorMaxIterationsError, AdvisorOrchestrationHandler, ) @@ -238,7 +238,7 @@ async def test_loop_max_uses_raises(): return advisor_tool_use_resp with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", side_effect=mock_call, ): h = AdvisorOrchestrationHandler() @@ -261,17 +261,17 @@ async def test_loop_max_uses_raises(): @pytest.mark.asyncio async def test_loop_streaming_wraps_response(): """stream=True: final response must be wrapped in FakeAnthropicMessagesStreamIterator.""" - from litellm.llms.anthropic.pass_through.messages.fake_stream_iterator import ( + from litellm.llms.anthropic.messages.native.fake_stream_iterator import ( FakeAnthropicMessagesStreamIterator, ) - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorOrchestrationHandler, ) executor_response = _make_text_response("Hello, world!") with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", new_callable=AsyncMock, return_value=executor_response, ): @@ -307,7 +307,7 @@ async def test_prior_advisor_blocks_replaced_in_history(): History containing server_tool_use + advisor_tool_result blocks gets collapsed to text before forwarding to the executor. """ - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorOrchestrationHandler, ) @@ -340,7 +340,7 @@ async def test_prior_advisor_blocks_replaced_in_history(): return _make_text_response("Here is the efficient version.") with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", side_effect=mock_call, ): h = AdvisorOrchestrationHandler() @@ -380,7 +380,7 @@ async def test_advisor_tool_translated_for_executor(): """ The executor must receive a regular tool definition (not advisor_20260301 type). """ - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorOrchestrationHandler, ) @@ -392,7 +392,7 @@ async def test_advisor_tool_translated_for_executor(): return _make_text_response("Done.") with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", side_effect=mock_call, ): h = AdvisorOrchestrationHandler() @@ -422,7 +422,7 @@ async def test_advisor_tool_translated_for_executor(): @pytest.mark.asyncio async def test_max_uses_zero_raises_on_first_advisor_call(): """max_uses=0 must cause AdvisorMaxIterationsError on the first advisor call.""" - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorMaxIterationsError, AdvisorOrchestrationHandler, ) @@ -434,7 +434,7 @@ async def test_max_uses_zero_raises_on_first_advisor_call(): return advisor_tool_use_resp # executor always tries to call advisor with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", side_effect=mock_call, ): h = AdvisorOrchestrationHandler() @@ -457,7 +457,7 @@ async def test_max_uses_zero_raises_on_first_advisor_call(): @pytest.mark.asyncio async def test_missing_advisor_model_raises_value_error(): """handle() must raise ValueError when the advisor tool has no model field.""" - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorOrchestrationHandler, ) @@ -484,7 +484,7 @@ async def test_missing_advisor_model_raises_value_error(): async def test_max_uses_none_falls_back_to_default(): """When max_uses is absent, the handler uses ADVISOR_MAX_USES from constants.""" import litellm.constants as _c - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorMaxIterationsError, AdvisorOrchestrationHandler, ) @@ -498,7 +498,7 @@ async def test_max_uses_none_falls_back_to_default(): return advisor_tool_use_resp with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", side_effect=mock_call, ): h = AdvisorOrchestrationHandler() @@ -532,7 +532,7 @@ ADVISOR_TOOL_WITH_CREDS = { async def _run_advisor_and_capture_subcall_kwargs(): """Run one advisor turn and return the kwargs of the advisor sub-call.""" - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorOrchestrationHandler, ) @@ -557,11 +557,11 @@ async def _run_advisor_and_capture_subcall_kwargs(): with ( patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", side_effect=mock_call, ), patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor.validate_url", + "litellm.llms.anthropic.messages.native.interceptors.advisor.validate_url", ), ): h = AdvisorOrchestrationHandler() @@ -581,7 +581,7 @@ async def test_advisor_creds_dropped_when_proxy_opt_in_disabled(): """On the proxy without opt-in, the caller's advisor api_base/api_key must NOT reach the sub-call (would redirect it / leak the server key).""" with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._allow_client_side_advisor_credentials", + "litellm.llms.anthropic.messages.native.interceptors.advisor._allow_client_side_advisor_credentials", return_value=False, ): captured = await _run_advisor_and_capture_subcall_kwargs() @@ -593,7 +593,7 @@ async def test_advisor_creds_dropped_when_proxy_opt_in_disabled(): async def test_advisor_creds_honored_when_proxy_opt_in_enabled(): """With the admin opt-in, the documented clientside routing still works.""" with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._allow_client_side_advisor_credentials", + "litellm.llms.anthropic.messages.native.interceptors.advisor._allow_client_side_advisor_credentials", return_value=True, ): captured = await _run_advisor_and_capture_subcall_kwargs() @@ -626,7 +626,7 @@ def test_allow_client_side_advisor_credentials_reads_proxy_flag(): """The gate mirrors the proxy's allow_client_side_credentials opt-in.""" import sys - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( _allow_client_side_advisor_credentials, ) @@ -650,7 +650,7 @@ def test_allow_client_side_advisor_credentials_defaults_true_outside_proxy(): import builtins import sys - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( _allow_client_side_advisor_credentials, ) @@ -674,7 +674,7 @@ def test_advisor_gate_propagates_non_import_errors(): returning True.""" import sys - from litellm.llms.anthropic.pass_through.messages.interceptors import ( + from litellm.llms.anthropic.messages.native.interceptors import ( advisor, ) @@ -733,12 +733,12 @@ async def test_advisor_uses_tool_credentials_when_clientside_enabled(): def test_resolve_advisor_credentials_returns_none_when_gate_closed(): - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( _resolve_advisor_credentials, ) with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._allow_client_side_advisor_credentials", + "litellm.llms.anthropic.messages.native.interceptors.advisor._allow_client_side_advisor_credentials", return_value=False, ): result = _resolve_advisor_credentials(ADVISOR_TOOL_WITH_CREDS) @@ -746,18 +746,18 @@ def test_resolve_advisor_credentials_returns_none_when_gate_closed(): def test_resolve_advisor_credentials_allows_api_key_without_api_base(): - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( _resolve_advisor_credentials, ) tool = {**ADVISOR_TOOL, "api_key": "sk-other"} with ( patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._allow_client_side_advisor_credentials", + "litellm.llms.anthropic.messages.native.interceptors.advisor._allow_client_side_advisor_credentials", return_value=True, ), patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor.validate_url", + "litellm.llms.anthropic.messages.native.interceptors.advisor.validate_url", side_effect=AssertionError("validate_url must not run without an api_base"), ), ): @@ -766,13 +766,13 @@ def test_resolve_advisor_credentials_allows_api_key_without_api_base(): def test_resolve_advisor_credentials_rejects_api_base_without_api_key(): - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( _resolve_advisor_credentials, ) tool = {**ADVISOR_TOOL, "api_base": "https://other.example"} with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._allow_client_side_advisor_credentials", + "litellm.llms.anthropic.messages.native.interceptors.advisor._allow_client_side_advisor_credentials", return_value=True, ): with pytest.raises(ValueError, match="api_base"): @@ -781,7 +781,7 @@ def test_resolve_advisor_credentials_rejects_api_base_without_api_key(): @pytest.mark.parametrize("api_base", [None, "https://other.example"]) def test_resolve_advisor_credentials_rejects_an_oidc_secret_reference_api_key(api_base): - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( _resolve_advisor_credentials, ) @@ -793,17 +793,17 @@ def test_resolve_advisor_credentials_rejects_an_oidc_secret_reference_api_key(ap def test_resolve_advisor_credentials_validates_api_base_before_use(): - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( _resolve_advisor_credentials, ) with ( patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._allow_client_side_advisor_credentials", + "litellm.llms.anthropic.messages.native.interceptors.advisor._allow_client_side_advisor_credentials", return_value=True, ), patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor.validate_url" + "litellm.llms.anthropic.messages.native.interceptors.advisor.validate_url" ) as mock_validate, ): result = _resolve_advisor_credentials(ADVISOR_TOOL_WITH_CREDS) @@ -813,17 +813,17 @@ def test_resolve_advisor_credentials_validates_api_base_before_use(): def test_resolve_advisor_credentials_propagates_ssrf_error(): from litellm.litellm_core_utils.url_utils import SSRFError - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( _resolve_advisor_credentials, ) with ( patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._allow_client_side_advisor_credentials", + "litellm.llms.anthropic.messages.native.interceptors.advisor._allow_client_side_advisor_credentials", return_value=True, ), patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor.validate_url", + "litellm.llms.anthropic.messages.native.interceptors.advisor.validate_url", side_effect=SSRFError("URL targets a blocked address"), ), ): @@ -834,18 +834,18 @@ def test_resolve_advisor_credentials_propagates_ssrf_error(): def test_resolve_advisor_credentials_skips_validation_when_url_validation_disabled(): import litellm - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( _resolve_advisor_credentials, ) with ( patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._allow_client_side_advisor_credentials", + "litellm.llms.anthropic.messages.native.interceptors.advisor._allow_client_side_advisor_credentials", return_value=True, ), patch.object(litellm, "user_url_validation", False), patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor.validate_url", + "litellm.llms.anthropic.messages.native.interceptors.advisor.validate_url", side_effect=AssertionError("validate_url must not run when user_url_validation is disabled"), ), ): @@ -857,7 +857,7 @@ def test_resolve_advisor_credentials_blocks_real_cloud_metadata_address(): """End-to-end (no mocked validate_url): a caller can't redirect the advisor sub-call to the cloud-metadata address even with an api_key.""" from litellm.litellm_core_utils.url_utils import SSRFError - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( _resolve_advisor_credentials, ) @@ -867,7 +867,7 @@ def test_resolve_advisor_credentials_blocks_real_cloud_metadata_address(): "api_base": "https://169.254.169.254/latest/meta-data/", } with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._allow_client_side_advisor_credentials", + "litellm.llms.anthropic.messages.native.interceptors.advisor._allow_client_side_advisor_credentials", return_value=True, ): with pytest.raises(SSRFError): @@ -875,13 +875,13 @@ def test_resolve_advisor_credentials_blocks_real_cloud_metadata_address(): def test_resolve_advisor_credentials_rejects_non_https_api_base(): - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( _resolve_advisor_credentials, ) tool = {**ADVISOR_TOOL, "api_key": "sk-other", "api_base": "http://8.8.8.8"} with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._allow_client_side_advisor_credentials", + "litellm.llms.anthropic.messages.native.interceptors.advisor._allow_client_side_advisor_credentials", return_value=True, ): with pytest.raises(ValueError, match="https"): @@ -891,14 +891,14 @@ def test_resolve_advisor_credentials_rejects_non_https_api_base(): def test_resolve_advisor_credentials_rejects_api_base_when_ssl_verify_disabled(): import litellm - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( _resolve_advisor_credentials, ) tool = {**ADVISOR_TOOL, "api_key": "sk-other", "api_base": "https://8.8.8.8"} with ( patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._allow_client_side_advisor_credentials", + "litellm.llms.anthropic.messages.native.interceptors.advisor._allow_client_side_advisor_credentials", return_value=True, ), patch.object(litellm, "ssl_verify", False), @@ -910,13 +910,13 @@ def test_resolve_advisor_credentials_rejects_api_base_when_ssl_verify_disabled() def test_resolve_advisor_credentials_allows_real_public_ip_address(): """End-to-end (no mocked validate_url): a globally-routable literal IP api_base is honored when paired with an api_key.""" - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( _resolve_advisor_credentials, ) tool = {**ADVISOR_TOOL, "api_key": "sk-other", "api_base": "https://8.8.8.8"} with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._allow_client_side_advisor_credentials", + "litellm.llms.anthropic.messages.native.interceptors.advisor._allow_client_side_advisor_credentials", return_value=True, ): result = _resolve_advisor_credentials(tool) @@ -935,7 +935,7 @@ async def test_advisor_sub_call_failure_is_tagged(): """When the advisor sub-call raises, the exception that propagates out of handle() must be tagged as an advisor orchestration failure.""" import litellm - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorOrchestrationHandler, ) from litellm.router_utils.cooldown_handlers import is_advisor_orchestration_failure @@ -954,7 +954,7 @@ async def test_advisor_sub_call_failure_is_tagged(): ) with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", side_effect=mock_call, ): h = AdvisorOrchestrationHandler() @@ -977,7 +977,7 @@ async def test_advisor_max_iterations_failure_is_tagged(): """When the orchestration loop exceeds max_uses (the executor keeps calling the advisor), the AdvisorMaxIterationsError must be tagged so the healthy executor deployment is not cooled down.""" - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorMaxIterationsError, AdvisorOrchestrationHandler, ) @@ -993,7 +993,7 @@ async def test_advisor_max_iterations_failure_is_tagged(): return _make_advisor_tool_use_response() with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", side_effect=mock_call, ): h = AdvisorOrchestrationHandler() @@ -1015,7 +1015,7 @@ async def test_executor_failure_is_not_tagged(): """A failure of the executor call (not advisor orchestration) must NOT be tagged — the selected deployment genuinely failed and should cool down.""" import litellm - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorOrchestrationHandler, ) from litellm.router_utils.cooldown_handlers import is_advisor_orchestration_failure @@ -1028,7 +1028,7 @@ async def test_executor_failure_is_not_tagged(): ) with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", side_effect=mock_call, ): h = AdvisorOrchestrationHandler() @@ -1084,7 +1084,7 @@ def _router_with_advisor_deployment( @pytest.mark.asyncio async def test_advisor_sub_call_routes_through_proxy_router(): import litellm.proxy.proxy_server as proxy_server - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorOrchestrationHandler, ) @@ -1107,7 +1107,7 @@ async def test_advisor_sub_call_routes_through_proxy_router(): with ( patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", side_effect=mock_call, ), patch.object(proxy_server, "llm_router", router), @@ -1145,7 +1145,7 @@ async def test_advisor_sub_call_routes_through_proxy_router(): async def test_advisor_sub_call_routes_through_router_for_alias_and_wildcard(router_kwargs, advisor_model): """Alias and wildcard advisor models resolve through the router like exact model_list matches.""" import litellm.proxy.proxy_server as proxy_server - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorOrchestrationHandler, ) @@ -1168,7 +1168,7 @@ async def test_advisor_sub_call_routes_through_router_for_alias_and_wildcard(rou with ( patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", side_effect=mock_call, ), patch.object(proxy_server, "llm_router", router), @@ -1194,7 +1194,7 @@ async def test_advisor_sub_call_routes_through_router_for_alias_and_wildcard(rou async def test_advisor_sub_call_bypasses_router_for_unconfigured_model(): """An advisor model the router doesn't know about keeps the SDK-level path.""" import litellm.proxy.proxy_server as proxy_server - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorOrchestrationHandler, ) @@ -1219,7 +1219,7 @@ async def test_advisor_sub_call_bypasses_router_for_unconfigured_model(): with ( patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", side_effect=mock_call, ), patch.object(proxy_server, "llm_router", router), @@ -1243,7 +1243,7 @@ async def test_advisor_sub_call_client_override_bypasses_router(): """A caller-supplied api_key/api_base override must not be re-routed.""" import litellm import litellm.proxy.proxy_server as proxy_server - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorOrchestrationHandler, ) @@ -1274,7 +1274,7 @@ async def test_advisor_sub_call_client_override_bypasses_router(): with ( patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", side_effect=mock_call, ), patch.object(proxy_server, "llm_router", router), @@ -1309,7 +1309,7 @@ async def test_advisor_sub_call_client_override_bypasses_router(): @pytest.mark.asyncio async def test_advisor_context_excludes_in_sequence_system_rows(): - from litellm.llms.anthropic.pass_through.messages.interceptors.advisor import ( + from litellm.llms.anthropic.messages.native.interceptors.advisor import ( AdvisorOrchestrationHandler, ) @@ -1329,7 +1329,7 @@ async def test_advisor_context_excludes_in_sequence_system_rows(): return _make_text_response("Final answer.") with patch( - "litellm.llms.anthropic.pass_through.messages.interceptors.advisor._call_messages_handler", + "litellm.llms.anthropic.messages.native.interceptors.advisor._call_messages_handler", side_effect=mock_call, ): h = AdvisorOrchestrationHandler() diff --git a/tests/unit/llms/anthropic/pass_through/test_anthropic_native_passthrough_spend_logging.py b/tests/unit/llms/anthropic/messages/test_anthropic_native_passthrough_spend_logging.py similarity index 100% rename from tests/unit/llms/anthropic/pass_through/test_anthropic_native_passthrough_spend_logging.py rename to tests/unit/llms/anthropic/messages/test_anthropic_native_passthrough_spend_logging.py diff --git a/tests/unit/llms/anthropic/pass_through/test_caller_model_checks.py b/tests/unit/llms/anthropic/messages/test_caller_model_checks.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/test_caller_model_checks.py rename to tests/unit/llms/anthropic/messages/test_caller_model_checks.py index 5a45221a3ca..751f7cc3934 100644 --- a/tests/unit/llms/anthropic/pass_through/test_caller_model_checks.py +++ b/tests/unit/llms/anthropic/messages/test_caller_model_checks.py @@ -7,7 +7,7 @@ from starlette.requests import Request import litellm from litellm.caching.dual_cache import DualCache -from litellm.llms.anthropic.pass_through.caller_model_checks import ( +from litellm.llms.anthropic.messages.caller_model_checks import ( _caller_within_team_member_model_budget, caller_model_verdict, rate_limit_verdict, @@ -32,7 +32,7 @@ from litellm.proxy.hooks.parallel_request_limiter_v3 import ( from litellm.proxy.utils import InternalUsageCache, hash_token from litellm.router import Router from litellm.types.agents import AgentResponse -from tests.unit.llms.anthropic.pass_through.conftest import ProxyAuthState +from tests.unit.llms.anthropic.messages.conftest import ProxyAuthState CLASSIFIER: Final = "classifier" CLASSIFIER_BUDGET: Final = {CLASSIFIER: {"max_budget": 0.1, "budget_duration": "1d"}} diff --git a/tests/unit/llms/anthropic/pass_through/test_convertible_blocks.py b/tests/unit/llms/anthropic/messages/test_convertible_blocks.py similarity index 97% rename from tests/unit/llms/anthropic/pass_through/test_convertible_blocks.py rename to tests/unit/llms/anthropic/messages/test_convertible_blocks.py index eac75486da4..5fb6cc32dfb 100644 --- a/tests/unit/llms/anthropic/pass_through/test_convertible_blocks.py +++ b/tests/unit/llms/anthropic/messages/test_convertible_blocks.py @@ -6,13 +6,13 @@ from typing import Final import pytest from pydantic import JsonValue, TypeAdapter -from litellm.llms.anthropic.pass_through.adapters.transformation import LiteLLMAnthropicMessagesAdapter -from litellm.llms.anthropic.pass_through.convertible_blocks import ( +from litellm.llms.anthropic.messages.adapters.transformation import LiteLLMAnthropicMessagesAdapter +from litellm.llms.anthropic.messages.convertible_blocks import ( malformed_tool_result_text_error, unconvertible_anthropic_blocks, unconvertible_blocks_error, ) -from litellm.llms.anthropic.pass_through.responses_adapters.transformation import ( +from litellm.llms.anthropic.messages.responses_adapters.transformation import ( LiteLLMAnthropicToResponsesAPIAdapter, ) from litellm.llms.vertex_ai.count_tokens.context import gemini_count_contents diff --git a/tests/unit/llms/anthropic/pass_through/test_reasoning_effort_fields.py b/tests/unit/llms/anthropic/messages/test_reasoning_effort_fields.py similarity index 97% rename from tests/unit/llms/anthropic/pass_through/test_reasoning_effort_fields.py rename to tests/unit/llms/anthropic/messages/test_reasoning_effort_fields.py index e9450d025a6..3432c9503de 100644 --- a/tests/unit/llms/anthropic/pass_through/test_reasoning_effort_fields.py +++ b/tests/unit/llms/anthropic/messages/test_reasoning_effort_fields.py @@ -14,7 +14,7 @@ from typing import Any, Dict import pytest import litellm -from litellm.llms.anthropic.pass_through.utils import ( +from litellm.llms.anthropic.messages.utils import ( normalize_reasoning_effort_value, ) from litellm.router_utils.reasoning_effort_capability import ( @@ -156,7 +156,7 @@ class TestAdapterAdaptiveThinking: def test_messages_adapter_adaptive_returns_medium_default(self): """Adaptive thinking returns 'medium' as default reasoning_effort.""" - from litellm.llms.anthropic.pass_through.adapters.transformation import ( + from litellm.llms.anthropic.messages.adapters.transformation import ( LiteLLMAnthropicMessagesAdapter, ) @@ -168,7 +168,7 @@ class TestAdapterAdaptiveThinking: def test_messages_adapter_adaptive_overridden_by_output_config(self): """For adaptive thinking, output_config.effort overrides reasoning_effort.""" - from litellm.llms.anthropic.pass_through.adapters.transformation import ( + from litellm.llms.anthropic.messages.adapters.transformation import ( LiteLLMAnthropicMessagesAdapter, ) from litellm.types.llms.anthropic import AnthropicMessagesRequest @@ -191,7 +191,7 @@ class TestAdapterAdaptiveThinking: def test_responses_adapter_adaptive_with_output_config(self): """Responses adapter: adaptive thinking + output_config.effort.""" - from litellm.llms.anthropic.pass_through.responses_adapters.transformation import ( + from litellm.llms.anthropic.messages.responses_adapters.transformation import ( LiteLLMAnthropicToResponsesAPIAdapter, ) @@ -204,7 +204,7 @@ class TestAdapterAdaptiveThinking: def test_responses_adapter_adaptive_default_medium(self): """Responses adapter: adaptive thinking without output_config defaults to medium.""" - from litellm.llms.anthropic.pass_through.responses_adapters.transformation import ( + from litellm.llms.anthropic.messages.responses_adapters.transformation import ( LiteLLMAnthropicToResponsesAPIAdapter, ) diff --git a/tests/unit/llms/anthropic/pass_through/test_safeguards.py b/tests/unit/llms/anthropic/messages/test_safeguards.py similarity index 99% rename from tests/unit/llms/anthropic/pass_through/test_safeguards.py rename to tests/unit/llms/anthropic/messages/test_safeguards.py index 8ea9b693139..0537d0fbd38 100644 --- a/tests/unit/llms/anthropic/pass_through/test_safeguards.py +++ b/tests/unit/llms/anthropic/messages/test_safeguards.py @@ -12,11 +12,11 @@ import litellm from litellm.caching.dual_cache import DualCache from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER -from litellm.llms.anthropic.pass_through.caller_model_checks import ( +from litellm.llms.anthropic.messages.caller_model_checks import ( CallerModelVerdict, _caller_within_team_member_model_budget, ) -from litellm.llms.anthropic.pass_through.safeguards import ( +from litellm.llms.anthropic.messages.safeguards import ( CLASSIFIER_MAX_TOKENS, CLASSIFIER_SYSTEM_PROMPT, TOOL_RESULT_CHAR_LIMIT, @@ -32,7 +32,7 @@ from litellm.llms.anthropic.pass_through.safeguards import ( requested_dangerous_tool_use, with_safeguard_results, ) -from litellm.llms.anthropic.pass_through.utils import proxy_sub_call_metadata +from litellm.llms.anthropic.messages.utils import proxy_sub_call_metadata from litellm.proxy._types import LiteLLM_EndUserTable, Litellm_EntityType, UserAPIKeyAuth from litellm.proxy.hooks.model_max_budget_limiter import ( PROXY_VirtualKeyModelMaxBudgetLimiter, @@ -44,7 +44,7 @@ from litellm.router import Router from litellm.types.llms.anthropic import AnthropicResponseContentBlockToolUse from litellm.types.router import RouterErrors from litellm.types.utils import Choices, Message, ModelResponse -from tests.unit.llms.anthropic.pass_through.conftest import ProxyAuthState +from tests.unit.llms.anthropic.messages.conftest import ProxyAuthState DANGEROUS_TOOL_USE_REQUEST: Final = [{"type": "dangerous_tool_use", "classifier_context": {"permission_mode": "auto"}}] LS: Final = ToolUseUnderReview(id="call_ls", name="Bash", input={"command": "ls"}) diff --git a/tests/unit/llms/anthropic/pass_through/test_stream_assembly.py b/tests/unit/llms/anthropic/messages/test_stream_assembly.py similarity index 98% rename from tests/unit/llms/anthropic/pass_through/test_stream_assembly.py rename to tests/unit/llms/anthropic/messages/test_stream_assembly.py index dbd49064e4b..f7d6b8d4f8c 100644 --- a/tests/unit/llms/anthropic/pass_through/test_stream_assembly.py +++ b/tests/unit/llms/anthropic/messages/test_stream_assembly.py @@ -3,7 +3,7 @@ from typing import Final import pytest -from litellm.llms.anthropic.pass_through.stream_assembly import ( +from litellm.llms.anthropic.messages.stream_assembly import ( anthropic_message_delta_fields, assemble_anthropic_sse_stream, is_anthropic_sse_stream, diff --git a/tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_message_id.py b/tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_message_id.py deleted file mode 100644 index a4f851c7753..00000000000 --- a/tests/unit/llms/anthropic/pass_through/adapters/test_streaming_iterator_message_id.py +++ /dev/null @@ -1,111 +0,0 @@ -""" -Streaming ``/v1/messages`` against a model that is neither Anthropic nor OpenAI is served by -translating the call onto ``/v1/chat/completions``, and the ``msg_`` id the caller is streamed -is minted right here. It is the only request id such a caller ever sees, so the spend row has -to be keyed on that same value rather than on the provider's own completion id. -""" - -import datetime -import json - -import pytest -import respx - -import litellm -from litellm.llms.anthropic.pass_through.adapters.handler import ( - LiteLLMMessagesToCompletionTransformationHandler, -) -from litellm.llms.anthropic.pass_through.adapters.streaming_iterator import ( - AnthropicStreamWrapper, -) - -MESSAGES = [{"role": "user", "content": "hello"}] - -GROQ_CHAT_URL = "https://api.groq.com/openai/v1/chat/completions" - -CHAT_SSE_BODY = ( - b'data: {"id":"chatcmpl-lit6825","object":"chat.completion.chunk","created":1,' - b'"model":"kimi-k2","choices":[{"index":0,"delta":{"role":"assistant","content":"hi"},' - b'"finish_reason":null}]}\n\n' - b'data: {"id":"chatcmpl-lit6825","object":"chat.completion.chunk","created":1,' - b'"model":"kimi-k2","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],' - b'"usage":{"prompt_tokens":3,"completion_tokens":4,"total_tokens":7}}\n\n' - b"data: [DONE]\n\n" -) - - -def _logging_obj(call_id: str): - from litellm.litellm_core_utils.litellm_logging import Logging - - return Logging( - model="kimi-k2", - messages=MESSAGES, - stream=True, - call_type="anthropic_messages", - start_time=datetime.datetime.now(datetime.timezone.utc), - litellm_call_id=call_id, - function_id="1234", - ) - - -def _streamed_message_id(raw_events: list[bytes]) -> str: - events = [json.loads(chunk.decode().split("data: ", 1)[1]) for chunk in raw_events] - message_start = next(e for e in events if e["type"] == "message_start") - return message_start["message"]["id"] - - -@pytest.fixture(autouse=True) -def _intercept_groq(respx_mock: respx.MockRouter, monkeypatch: pytest.MonkeyPatch): - monkeypatch.setenv("GROQ_API_KEY", "gsk-lit6825-test") - monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") - litellm.in_memory_llm_clients_cache.flush_cache() - respx_mock.post(GROQ_CHAT_URL).respond( - status_code=200, - headers={"Content-Type": "text/event-stream"}, - content=CHAT_SSE_BODY, - ) - - -@pytest.mark.asyncio -async def test_async_streaming_hands_the_logging_object_the_message_id_the_caller_is_streamed(): - logging_obj = _logging_obj("6825beef-0000-4000-8000-000000000010") - - sse = await LiteLLMMessagesToCompletionTransformationHandler.async_anthropic_messages_handler( - max_tokens=1024, - messages=MESSAGES, - model="groq/kimi-k2", - stream=True, - custom_llm_provider="groq", - litellm_logging_obj=logging_obj, - ) - streamed_id = _streamed_message_id([chunk async for chunk in sse]) - - assert streamed_id.startswith("msg_") - assert logging_obj.streamed_anthropic_message_id == streamed_id - - -def test_sync_streaming_hands_the_logging_object_the_message_id_the_caller_is_streamed(): - logging_obj = _logging_obj("6825beef-0000-4000-8000-000000000011") - - sse = LiteLLMMessagesToCompletionTransformationHandler.anthropic_messages_handler( - max_tokens=1024, - messages=MESSAGES, - model="groq/kimi-k2", - stream=True, - custom_llm_provider="groq", - litellm_logging_obj=logging_obj, - ) - streamed_id = _streamed_message_id(list(sse)) - - assert streamed_id.startswith("msg_") - assert logging_obj.streamed_anthropic_message_id == streamed_id - - -def test_concurrent_streams_are_keyed_on_their_own_message_id(): - """Two callers streaming at once must not be handed, or logged under, one another's id.""" - first = AnthropicStreamWrapper(completion_stream=iter([]), model="kimi-k2") - second = AnthropicStreamWrapper(completion_stream=iter([]), model="kimi-k2") - - assert first._message_id != second._message_id - assert _streamed_message_id(list(first.anthropic_sse_wrapper())) == first._message_id - assert _streamed_message_id(list(second.anthropic_sse_wrapper())) == second._message_id diff --git a/tests/unit/llms/anthropic/pass_through/test_pass_through_shim.py b/tests/unit/llms/anthropic/pass_through/test_pass_through_shim.py new file mode 100644 index 00000000000..4016e5301db --- /dev/null +++ b/tests/unit/llms/anthropic/pass_through/test_pass_through_shim.py @@ -0,0 +1,60 @@ +import importlib +import sys +from typing import Final + +import pytest + +OLD_PACKAGE: Final = "litellm.llms.anthropic.pass_through" +NEW_PACKAGE: Final = "litellm.llms.anthropic.messages" + + +def _forget_old_package(monkeypatch: pytest.MonkeyPatch) -> None: + for name in tuple(sys.modules): + if name == OLD_PACKAGE or name.startswith(OLD_PACKAGE + "."): + monkeypatch.delitem(sys.modules, name) + + +def test_old_deep_import_is_the_new_module_object_and_warns(monkeypatch: pytest.MonkeyPatch) -> None: + _forget_old_package(monkeypatch) + with pytest.warns(DeprecationWarning, match=NEW_PACKAGE): + old_handler: Final = importlib.import_module(f"{OLD_PACKAGE}.messages.handler") + from litellm.llms.anthropic.messages.native import handler as new_handler + + assert old_handler is new_handler + assert sys.modules[f"{OLD_PACKAGE}.messages.handler"] is new_handler + assert importlib.import_module(f"{OLD_PACKAGE}.adapters.transformation") is importlib.import_module( + f"{NEW_PACKAGE}.adapters.transformation" + ) + assert importlib.import_module(f"{OLD_PACKAGE}.safeguards") is importlib.import_module(f"{NEW_PACKAGE}.safeguards") + + +def test_old_package_attribute_access_reaches_renamed_subpackage(monkeypatch: pytest.MonkeyPatch) -> None: + _forget_old_package(monkeypatch) + with pytest.warns(DeprecationWarning, match=NEW_PACKAGE): + old_package: Final = importlib.import_module(OLD_PACKAGE) + + assert old_package.messages is importlib.import_module(f"{NEW_PACKAGE}.native") # pyright: ignore[reportAny] # module attributes are untyped + assert old_package.messages.handler is importlib.import_module(f"{NEW_PACKAGE}.native.handler") # pyright: ignore[reportAny] # module attributes are untyped + with pytest.raises(AttributeError, match="no attribute 'nope'"): + _ = old_package.nope # pyright: ignore[reportAny] # module attributes are untyped + + +def test_old_transformation_import_loads_only_its_new_counterpart(monkeypatch: pytest.MonkeyPatch) -> None: + _forget_old_package(monkeypatch) + monkeypatch.delitem(sys.modules, f"{NEW_PACKAGE}.native.streaming_iterator", raising=False) + with pytest.warns(DeprecationWarning, match=NEW_PACKAGE): + old_transformation: Final = importlib.import_module(f"{OLD_PACKAGE}.messages.transformation") + + assert old_transformation is sys.modules[f"{NEW_PACKAGE}.native.transformation"] + assert f"{NEW_PACKAGE}.native.streaming_iterator" not in sys.modules, "shim imported the streaming iterator" + + +def test_old_subpackage_import_keeps_the_new_package_path_importable(monkeypatch: pytest.MonkeyPatch) -> None: + _forget_old_package(monkeypatch) + monkeypatch.delitem(sys.modules, f"{NEW_PACKAGE}.native.mcp_handler", raising=False) + with pytest.warns(DeprecationWarning, match=NEW_PACKAGE): + native: Final = importlib.import_module(f"{OLD_PACKAGE}.messages") + + assert [path.rsplit("/", 2)[-2:] for path in native.__path__] == [["messages", "native"]] # pyright: ignore[reportAny] # module attributes are untyped + assert native.__spec__ is not None and native.__spec__.name == f"{NEW_PACKAGE}.native" + assert importlib.import_module(f"{NEW_PACKAGE}.native.mcp_handler").__name__ == f"{NEW_PACKAGE}.native.mcp_handler" diff --git a/tests/unit/llms/anthropic/test_anthropic_common_utils.py b/tests/unit/llms/anthropic/test_anthropic_common_utils.py index 093b4d6cce8..eb5c1598c17 100644 --- a/tests/unit/llms/anthropic/test_anthropic_common_utils.py +++ b/tests/unit/llms/anthropic/test_anthropic_common_utils.py @@ -436,7 +436,7 @@ class TestPassthroughOAuth: def test_passthrough_oauth_no_x_api_key(self): """Passthrough endpoint should not add x-api-key for OAuth tokens.""" - from litellm.llms.anthropic.pass_through.messages.transformation import ( + from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) @@ -459,7 +459,7 @@ class TestPassthroughOAuth: def test_passthrough_regular_key_uses_x_api_key(self): """Passthrough endpoint should still use x-api-key for regular API keys.""" - from litellm.llms.anthropic.pass_through.messages.transformation import ( + from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) @@ -1265,7 +1265,7 @@ class TestPassthroughAuthToken: """Passthrough endpoint should use Bearer auth when only ANTHROPIC_AUTH_TOKEN is set.""" from unittest.mock import patch as mock_patch - from litellm.llms.anthropic.pass_through.messages.transformation import ( + from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) @@ -1289,7 +1289,7 @@ class TestPassthroughAuthToken: """Passthrough endpoint should prefer ANTHROPIC_API_KEY over ANTHROPIC_AUTH_TOKEN.""" from unittest.mock import patch as mock_patch - from litellm.llms.anthropic.pass_through.messages.transformation import ( + from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) @@ -1320,7 +1320,7 @@ class TestPassthroughAuthToken: from unittest.mock import patch as mock_patch import litellm - from litellm.llms.anthropic.pass_through.messages.transformation import ( + from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) @@ -1342,7 +1342,7 @@ class TestPassthroughAuthToken: """A client-forwarded x-api-key header, whatever its casing, should satisfy validation without env credentials.""" from unittest.mock import patch as mock_patch - from litellm.llms.anthropic.pass_through.messages.transformation import ( + from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) @@ -1365,7 +1365,7 @@ class TestPassthroughAuthToken: """get_complete_url should use ANTHROPIC_BASE_URL when api_base is None.""" from unittest.mock import patch as mock_patch - from litellm.llms.anthropic.pass_through.messages.transformation import ( + from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) @@ -2043,7 +2043,7 @@ class TestAnthropicThinkingSignatureSelfHeal: def test_anthropic_messages_config_http_retry_helpers(self): import httpx - from litellm.llms.anthropic.pass_through.messages.transformation import ( + from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) @@ -2113,7 +2113,7 @@ class TestAnthropicThinkingSignatureSelfHeal: def test_anthropic_messages_retry_honors_thinking_block_binding( self, thinking: Mapping[str, object], error_message: str, expected: bool ) -> None: - from litellm.llms.anthropic.pass_through.messages.transformation import ( + from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) @@ -2865,7 +2865,7 @@ class TestWifServerOwnedAuthHeaderStrip: """The passthrough surface hands the caller's own credential upstream rather than minting. That check was case-sensitive, so X-Api-Key slipped past it and the caller's key would have travelled beside a minted Bearer.""" - from litellm.llms.anthropic.pass_through.messages.transformation import ( + from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) @@ -3084,7 +3084,7 @@ class TestMessagesEnvAuthBetaMerge: def test_client_beta_survives_env_auth_injection(self, monkeypatch, clean_anthropic_env): """Regression: headers.update(auth_header) silently clobbered the client's anthropic-beta on the native /v1/messages route.""" - from litellm.llms.anthropic.pass_through.messages.transformation import ( + from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) @@ -3166,7 +3166,7 @@ class TestWifLitellmParamsPlumbing: assert len(poster.requests) == 1 def test_messages_mints_from_litellm_params(self, wif_engine): - from litellm.llms.anthropic.pass_through.messages.transformation import ( + from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) @@ -3245,7 +3245,7 @@ class TestWifAsyncSeam: @pytest.mark.asyncio async def test_avalidate_messages_environment_mints_off_loop(self, wif_async_engine, monkeypatch): - from litellm.llms.anthropic.pass_through.messages.transformation import ( + from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) @@ -3268,7 +3268,7 @@ class TestWifAsyncSeam: async def test_avalidate_delegates_to_subclass_sync_override(self): """A provider subclass that only overrides the sync method must keep its behavior when the handler goes through the async variant.""" - from litellm.llms.anthropic.pass_through.messages.transformation import ( + from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) diff --git a/tests/unit/llms/anthropic/test_anthropic_prompt_cache_prediction.py b/tests/unit/llms/anthropic/test_anthropic_prompt_cache_prediction.py index df89774951f..7a6b6534131 100644 --- a/tests/unit/llms/anthropic/test_anthropic_prompt_cache_prediction.py +++ b/tests/unit/llms/anthropic/test_anthropic_prompt_cache_prediction.py @@ -13,7 +13,7 @@ import litellm from litellm.caching.dual_cache import DualCache from litellm.caching.llm_caching_handler import LLMClientCache from litellm.llms.anthropic.count_tokens import handler as count_handler -from litellm.llms.anthropic.pass_through.messages.transformation import DEFAULT_ANTHROPIC_API_VERSION +from litellm.llms.anthropic.messages.native.transformation import DEFAULT_ANTHROPIC_API_VERSION from litellm.llms.anthropic.prompt_cache_prediction import ( CountedPromptCachePlan, NativePredictionTarget, diff --git a/tests/unit/llms/anthropic/test_message_sanitization.py b/tests/unit/llms/anthropic/test_message_sanitization.py index 7afa60baf7e..0afd443d07a 100644 --- a/tests/unit/llms/anthropic/test_message_sanitization.py +++ b/tests/unit/llms/anthropic/test_message_sanitization.py @@ -7,6 +7,8 @@ B. Orphaned tool_result without matching tool_use C. Empty text content """ +import copy +import json import pytest import sys import os @@ -16,6 +18,8 @@ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../. import litellm from litellm.litellm_core_utils.prompt_templates.factory import ( + _EMPTY_TEXT_PLACEHOLDER as PLACEHOLDER, + _sanitize_empty_text_content, sanitize_messages_for_tool_calling, anthropic_messages_pt, ) @@ -24,16 +28,9 @@ from litellm.litellm_core_utils.prompt_templates.factory import ( class TestMessageSanitization: """Test message sanitization for tool calling scenarios""" - def setup_method(self): - """Setup for each test""" - # Save original modify_params value - self.original_modify_params = litellm.modify_params - litellm.modify_params = True - - def teardown_method(self): - """Cleanup after each test""" - # Restore original modify_params value - litellm.modify_params = self.original_modify_params + @pytest.fixture(autouse=True) + def _modify_params_on(self, monkeypatch): + monkeypatch.setattr(litellm, "modify_params", True) def test_case_a_orphaned_tool_call_single(self): """ @@ -255,11 +252,11 @@ class TestMessageSanitization: assert sanitized[3]["content"] == "[System: Empty message content sanitised to satisfy protocol]" assert sanitized[4]["role"] == "assistant" - def test_modify_params_false_no_sanitization(self): + def test_modify_params_false_no_sanitization(self, monkeypatch): """ Test that sanitization is skipped when modify_params=False """ - litellm.modify_params = False + monkeypatch.setattr(litellm, "modify_params", False) messages = [ {"role": "user", "content": ""}, @@ -287,7 +284,6 @@ class TestMessageSanitization: """ Test that sanitization is integrated into anthropic_messages_pt """ - litellm.modify_params = True messages = [ {"role": "user", "content": "What is the weather in Nashik?"}, @@ -316,7 +312,7 @@ class TestMessageSanitization: assert result[0]["role"] == "user" assert result[1]["role"] == "assistant" - def test_empty_string_content_sanitized_without_modify_params(self): + def test_empty_string_content_sanitized_without_modify_params(self, monkeypatch): """ Regression: An empty user message ({"role": "user", "content": ""}) must be rewritten to a non-empty placeholder *before* it reaches Anthropic, @@ -324,7 +320,7 @@ class TestMessageSanitization: "messages: text content blocks must be non-empty" Reproduces a real failure from the pr-review agent (pydantic-ai). """ - litellm.modify_params = False + monkeypatch.setattr(litellm, "modify_params", False) messages = [ {"role": "user", "content": "First message"}, @@ -344,13 +340,13 @@ class TestMessageSanitization: assert block["text"].strip() != "" assert text_blocks[2]["text"] == ("[System: Empty message content sanitised to satisfy protocol]") - def test_empty_text_block_in_list_content_sanitized(self): + def test_empty_text_block_in_list_content_sanitized(self, monkeypatch): """ Same regression for the list-of-blocks form: {"role": "user", "content": [{"type": "text", "text": ""}]} Empty text *blocks* must be rewritten too, regardless of modify_params. """ - litellm.modify_params = False + monkeypatch.setattr(litellm, "modify_params", False) messages = [ { @@ -372,12 +368,12 @@ class TestMessageSanitization: for block in text_blocks[1:]: assert block["text"].strip() != "" - def test_non_empty_content_unchanged_without_modify_params(self): + def test_non_empty_content_unchanged_without_modify_params(self, monkeypatch): """ Sanity check: when nothing is empty, the messages flow through unchanged even with modify_params disabled. """ - litellm.modify_params = False + monkeypatch.setattr(litellm, "modify_params", False) messages = [ {"role": "user", "content": "Hello"}, @@ -393,6 +389,270 @@ class TestMessageSanitization: assert result[1]["content"][0]["text"] == "Hi there" assert result[2]["content"][0]["text"] == "How are you?" + @pytest.mark.parametrize("modify_params", [True, False]) + @pytest.mark.parametrize( + "empty_content", + [None, "", " \n \t ", [], [{"type": "text", "text": ""}]], + ids=["none", "empty_str", "whitespace_str", "empty_list", "empty_text_block"], + ) + def test_tool_call_only_assistant_turn_never_gets_placeholder(self, monkeypatch, modify_params, empty_content): + """ + Regression for the placeholder leaking into tool-call-only assistant turns. + + An OpenAI-format assistant turn that carries tool_calls but no text is the normal + shape emitted by coding agents. Anthropic accepts an assistant turn whose content + is just tool_use, so there is nothing to substitute; injecting the placeholder made + it look like the assistant had said it, and the model echoed it on later turns. + """ + monkeypatch.setattr(litellm, "modify_params", modify_params) + + messages = [ + {"role": "user", "content": "list the files"}, + { + "role": "assistant", + "content": empty_content, + "tool_calls": [ + { + "id": "call_1", + "type": "function", + "function": {"name": "run_bash", "arguments": '{"cmd": "ls"}'}, + } + ], + }, + {"role": "tool", "tool_call_id": "call_1", "content": "a.txt"}, + ] + + result = anthropic_messages_pt(messages=messages, model="claude-sonnet-4-6", llm_provider="anthropic") + + assistant_turns = [m for m in result if m["role"] == "assistant"] + assert len(assistant_turns) == 1 + blocks = assistant_turns[0]["content"] + + assert [b["type"] for b in blocks] == ["tool_use"] + assert blocks[0]["id"] == "call_1" + assert blocks[0]["name"] == "run_bash" + + assert PLACEHOLDER not in json.dumps(result) + + def test_empty_text_dropped_alongside_non_text_blocks(self): + """ + An assistant turn already carrying a non-text block has enough content for + Anthropic once the empty text block is dropped, so the placeholder must not be + substituted in its place. + """ + + message = { + "role": "assistant", + "content": [ + {"type": "text", "text": " "}, + {"type": "thinking", "thinking": "weighing options", "signature": "sig"}, + ], + } + + sanitized = _sanitize_empty_text_content(message) + + assert [b["type"] for b in sanitized["content"]] == ["thinking"] + assert PLACEHOLDER not in json.dumps(sanitized) + + @pytest.mark.parametrize( + "sibling_block", + [ + {"type": "thinking", "thinking": "", "signature": "sig"}, + {"type": "redacted_thinking", "data": "opaque"}, + ], + ids=["signed_empty_thinking", "redacted_thinking"], + ) + def test_empty_text_dropped_alongside_kept_thinking_block(self, sibling_block): + """ + The converter keeps signed thinking blocks even with empty text, and keeps + redacted_thinking blocks, so the turn still reaches Anthropic without the + empty text and the placeholder must not be substituted. + """ + + messages = [ + {"role": "user", "content": "hi"}, + {"role": "assistant", "content": [{"type": "text", "text": " "}, sibling_block]}, + {"role": "user", "content": "and now?"}, + ] + + result = anthropic_messages_pt(messages=messages, model="claude-sonnet-4-6", llm_provider="anthropic") + + assert [m["role"] for m in result] == ["user", "assistant", "user"] + assert [b["type"] for b in result[1]["content"]] == [sibling_block["type"]] + assert PLACEHOLDER not in json.dumps(result) + + def test_placeholder_kept_when_only_tool_call_is_dropped_tool_search(self, monkeypatch): + """ + A tool search call whose result is not replayed is dropped by the converter, so + it does not count as content: the empty text keeps its placeholder instead of + the assistant turn vanishing from the request. modify_params stays off so no + dummy tool result answers the call and keeps it. + """ + monkeypatch.setattr(litellm, "modify_params", False) + + messages = [ + {"role": "user", "content": "find a tool"}, + { + "role": "assistant", + "content": "", + "tool_calls": [ + { + "id": "srvtoolu_1", + "type": "function", + "function": {"name": "tool_search_tool_regex", "arguments": '{"query": "x"}'}, + } + ], + }, + {"role": "user", "content": "go on"}, + ] + + result = anthropic_messages_pt(messages=messages, model="claude-sonnet-4-6", llm_provider="anthropic") + + assert [m["role"] for m in result] == ["user", "assistant", "user"] + assert result[1]["content"] == [{"type": "text", "text": PLACEHOLDER}] + + @pytest.mark.parametrize( + "sibling_block", + [ + {"type": "image_url", "image_url": {"url": "data:image/png;base64,aGk="}}, + {"type": "thinking", "thinking": ""}, + {"type": "redacted_thinking", "data": " "}, + {"type": "unknown_future_block"}, + {"no_type_key": "malformed"}, + ], + ids=["image_url", "unsignable_thinking", "blank_redacted_thinking", "unknown_type", "missing_type"], + ) + def test_empty_text_kept_when_sibling_block_would_not_survive(self, sibling_block): + """ + Dropping empty text is only safe when something else in the turn actually reaches + Anthropic. Blocks the assistant conversion discards (assistant-side images, + signature-less thinking, unrecognised types) would leave an empty turn that gets + dropped from the request entirely, so the placeholder has to stay. + """ + + messages = [ + {"role": "user", "content": "hi"}, + {"role": "assistant", "content": [{"type": "text", "text": " "}, sibling_block]}, + {"role": "user", "content": "and now?"}, + ] + + result = anthropic_messages_pt(messages=messages, model="claude-haiku-4-5", llm_provider="anthropic") + + assert [m["role"] for m in result] == ["user", "assistant", "user"] + assert PLACEHOLDER in json.dumps(result) + + def test_assistant_text_preserved_alongside_tool_calls(self): + """ + Dropping empty text must not drop real text: an assistant turn that says something + *and* calls a tool keeps both blocks. + """ + + messages = [ + {"role": "user", "content": "list the files"}, + { + "role": "assistant", + "content": "Let me check.", + "tool_calls": [ + { + "id": "call_1", + "type": "function", + "function": {"name": "run_bash", "arguments": '{"cmd": "ls"}'}, + } + ], + }, + {"role": "tool", "tool_call_id": "call_1", "content": "a.txt"}, + ] + + result = anthropic_messages_pt(messages=messages, model="claude-sonnet-4-6", llm_provider="anthropic") + + assistant_turns = [m for m in result if m["role"] == "assistant"] + blocks = assistant_turns[0]["content"] + + assert [b["type"] for b in blocks] == ["text", "tool_use"] + assert blocks[0]["text"] == "Let me check." + assert PLACEHOLDER not in json.dumps(result) + + @pytest.mark.parametrize( + "messages", + [ + [{"role": "user", "content": ""}], + [{"role": "user", "content": [{"type": "text", "text": " "}]}], + [{"role": "user", "content": "hi"}, {"role": "assistant", "content": ""}], + ], + ids=["user_str", "user_block", "assistant_without_tool_calls"], + ) + def test_placeholder_still_used_when_turn_would_be_empty(self, messages): + """ + The placeholder is still required where dropping the empty text would leave the + turn with no content at all, which Anthropic also rejects. + """ + + result = anthropic_messages_pt(messages=messages, model="claude-sonnet-4-6", llm_provider="anthropic") + + assert PLACEHOLDER in json.dumps(result) + for message in result: + assert message["content"] + + def test_no_empty_text_block_or_content_reaches_anthropic(self): + """ + The invariant Anthropic actually enforces, over a conversation mixing every shape: + no empty content list and no empty text block may survive the conversion. + """ + + messages = [ + {"role": "user", "content": ""}, + { + "role": "assistant", + "content": "", + "tool_calls": [ + { + "id": "call_1", + "type": "function", + "function": {"name": "run_bash", "arguments": "{}"}, + } + ], + }, + {"role": "tool", "tool_call_id": "call_1", "content": "out"}, + {"role": "assistant", "content": [{"type": "text", "text": " "}]}, + {"role": "user", "content": [{"type": "text", "text": "thanks"}]}, + ] + + result = anthropic_messages_pt(messages=messages, model="claude-sonnet-4-6", llm_provider="anthropic") + + for message in result: + content = message["content"] + assert content + for block in content: + if isinstance(block, dict) and block.get("type") == "text": + assert block["text"].strip() + + def test_sanitization_does_not_mutate_caller_messages(self): + """ + Callers reuse their message list across retries and fallbacks, so sanitization has + to stay copy-on-write. + """ + + messages = [ + {"role": "user", "content": "go"}, + { + "role": "assistant", + "content": "", + "tool_calls": [ + { + "id": "call_1", + "type": "function", + "function": {"name": "run_bash", "arguments": "{}"}, + } + ], + }, + {"role": "tool", "tool_call_id": "call_1", "content": "out"}, + ] + before = copy.deepcopy(messages) + + anthropic_messages_pt(messages=messages, model="claude-sonnet-4-6", llm_provider="anthropic") + + assert messages == before + if __name__ == "__main__": pytest.main([__file__, "-v"]) diff --git a/tests/unit/llms/azure/chat/test_azure_base_model_routing.py b/tests/unit/llms/azure/chat/test_azure_base_model_routing.py index aae2587085f..d9607c6db8c 100644 --- a/tests/unit/llms/azure/chat/test_azure_base_model_routing.py +++ b/tests/unit/llms/azure/chat/test_azure_base_model_routing.py @@ -12,7 +12,7 @@ import openai import pytest import litellm -from litellm.llms.azure.chat.gpt_5_transformation import AzureOpenAIGPT5Config +from litellm.llms.azure.chat.gpt_reasoning_transformation import AzureOpenAIGPT5Config from litellm.llms.azure.chat.o_series_transformation import AzureOpenAIO1Config from litellm.utils import ProviderConfigManager, get_optional_params from tests.unit.llms.bedrock.slow_upstream import STREAM_TIMEOUT_SECONDS, slow_upstream_transport diff --git a/tests/unit/llms/azure/chat/test_azure_chat_gpt_transformation.py b/tests/unit/llms/azure/chat/test_azure_chat_gpt_transformation.py index f753fb6b8f9..53df6610913 100644 --- a/tests/unit/llms/azure/chat/test_azure_chat_gpt_transformation.py +++ b/tests/unit/llms/azure/chat/test_azure_chat_gpt_transformation.py @@ -11,7 +11,7 @@ sys.path.insert( import litellm from litellm.litellm_core_utils.prompt_templates.common_utils import TOOL_RESULT_IMAGE_BOUNDARY -from litellm.llms.azure.chat.gpt_5_transformation import AzureOpenAIGPT5Config +from litellm.llms.azure.chat.gpt_reasoning_transformation import AzureOpenAIGPT5Config from litellm.llms.azure.chat.gpt_transformation import AzureOpenAIConfig from litellm.utils import _invalidate_model_cost_lowercase_map, get_optional_params from datetime import datetime diff --git a/tests/unit/llms/azure/chat/test_azure_gpt5_transformation.py b/tests/unit/llms/azure/chat/test_azure_gpt_reasoning_transformation.py similarity index 99% rename from tests/unit/llms/azure/chat/test_azure_gpt5_transformation.py rename to tests/unit/llms/azure/chat/test_azure_gpt_reasoning_transformation.py index 80328022f61..a82dd98e31d 100644 --- a/tests/unit/llms/azure/chat/test_azure_gpt5_transformation.py +++ b/tests/unit/llms/azure/chat/test_azure_gpt_reasoning_transformation.py @@ -5,7 +5,7 @@ import pytest import litellm from litellm.litellm_core_utils.get_model_cost_map import get_model_cost_map -from litellm.llms.azure.chat.gpt_5_transformation import AzureOpenAIGPT5Config +from litellm.llms.azure.chat.gpt_reasoning_transformation import AzureOpenAIGPT5Config @pytest.fixture() diff --git a/tests/unit/proxy/_experimental/mcp_server/guardrail_translation/__init__.py b/tests/unit/llms/azure/decisions/__init__.py similarity index 100% rename from tests/unit/proxy/_experimental/mcp_server/guardrail_translation/__init__.py rename to tests/unit/llms/azure/decisions/__init__.py diff --git a/tests/unit/llms/azure/decisions/test_transformation.py b/tests/unit/llms/azure/decisions/test_transformation.py new file mode 100644 index 00000000000..b6de6084b9c --- /dev/null +++ b/tests/unit/llms/azure/decisions/test_transformation.py @@ -0,0 +1,226 @@ +import json +import threading +import time +from collections.abc import Iterator, Mapping +from typing import Final +from unittest.mock import Mock + +import pytest +import respx +from azure.core.credentials import AccessToken + +import litellm +from litellm.llms.azure import common_utils +from litellm.llms.azure.decisions.transformation import AzureDecisionsConfig +from litellm.types.decisions import DecisionsResponse, OpenAIDecisionResponse + +_BASE: Final = "https://resource.openai.azure.com" +_URL: Final = f"{_BASE}/openai/v1/decisions" +_RESPONSE: Final = { + "model": "luna-deployment", + "answers": [{"type": "predicate", "name": "defect", "probability": 0.9}], + "usage": {"input_tokens": 10, "output_tokens": 1, "total_tokens": 11}, +} + + +@pytest.fixture(autouse=True) +def clear_credentials(monkeypatch: pytest.MonkeyPatch) -> Iterator[None]: + for name in ( + "AZURE_API_KEY", + "AZURE_OPENAI_API_KEY", + "AZURE_API_BASE", + "AZURE_AD_TOKEN", + "AZURE_CLIENT_ID", + "AZURE_TENANT_ID", + "AZURE_CLIENT_SECRET", + "AZURE_SCOPE", + "AZURE_USERNAME", + "AZURE_PASSWORD", + ): + monkeypatch.delenv(name, raising=False) + monkeypatch.setattr(litellm, "api_key", None) + monkeypatch.setattr(litellm, "azure_key", None) + monkeypatch.setattr(litellm, "api_base", None) + monkeypatch.setattr(litellm, "enable_azure_ad_token_refresh", False) + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + common_utils._cached_azure_ad_token_refresh_provider.cache_clear() + yield + common_utils._cached_azure_ad_token_refresh_provider.cache_clear() + + +async def call_decisions( + is_async: bool, + systemone: bool, + credentials: Mapping[str, object], + api_base: str = _BASE, +) -> DecisionsResponse | OpenAIDecisionResponse: + params = { + "model": "azure/luna-deployment", + "api_base": api_base, + **credentials, + } + if systemone: + params["state"] = "The export job hangs." + params["questions"] = {"defect": {"type": "noul", "instructions": "Is this a defect?"}} + if is_async: + return await litellm.asystemone(**params) + return litellm.systemone(**params) + params["input"] = "The export job hangs." + params["questions"] = [{"type": "predicate", "name": "defect", "instructions": "Is this a defect?"}] + if is_async: + return await litellm.adecisions(**params) + return litellm.decisions(**params) + + +@pytest.mark.parametrize("is_async", (False, True)) +@pytest.mark.parametrize("systemone", (False, True)) +@pytest.mark.parametrize("suffix", ("", "/", "/openai", "/openai/v1/")) +async def test_azure_decisions_uses_entra_token_and_openai_wire_format( + respx_mock: respx.MockRouter, is_async: bool, systemone: bool, suffix: str +) -> None: + route = respx_mock.post(_URL).respond(json=_RESPONSE) + response = await call_decisions(is_async, systemone, {"azure_ad_token": "synthetic-entra"}, _BASE + suffix) + request = route.calls.last.request + assert request.headers["authorization"] == "Bearer synthetic-entra" + assert "api-key" not in request.headers + assert json.loads(request.content) == { + "model": "luna-deployment", + "input": "The export job hangs.", + "questions": [{"type": "predicate", "name": "defect", "instructions": "Is this a defect?"}], + } + if systemone: + assert response.model_dump()["answers"]["defect"]["noul"] == 0.9 + else: + assert response.model_dump()["answers"][0]["probability"] == 0.9 + assert response._hidden_params["custom_llm_provider"] == "azure" + + +@pytest.mark.parametrize("is_async", (False, True)) +@pytest.mark.parametrize("systemone", (False, True)) +async def test_default_credential_refreshes_without_opt_in( + monkeypatch: pytest.MonkeyPatch, + respx_mock: respx.MockRouter, + is_async: bool, + systemone: bool, +) -> None: + credential = Mock(spec=["get_token"]) + credential.get_token.side_effect = [ + AccessToken("synthetic-first", int(time.time()) + 120), + AccessToken("synthetic-refreshed", int(time.time()) + 3600), + ] + factory = Mock(return_value=credential) + monkeypatch.setattr("azure.identity.DefaultAzureCredential", factory) + monkeypatch.setenv("OPENAI_API_KEY", "synthetic-unrelated-openai-key") + route = respx_mock.post(_URL).respond(json=_RESPONSE) + await call_decisions(is_async, systemone, {}) + await call_decisions(is_async, systemone, {}) + assert [call.request.headers["authorization"] for call in route.calls] == [ + "Bearer synthetic-first", + "Bearer synthetic-refreshed", + ] + factory.assert_called_once_with() + assert credential.get_token.call_count == 2 + assert all( + call.args == ("https://cognitiveservices.azure.com/.default",) for call in credential.get_token.call_args_list + ) + + +@pytest.mark.parametrize("kind", ("service-principal", "oidc", "provider")) +async def test_azure_decisions_reuses_existing_azure_credential_resolution( + monkeypatch: pytest.MonkeyPatch, respx_mock: respx.MockRouter, kind: str +) -> None: + provider = Mock(return_value="synthetic-entra") + if kind == "service-principal": + factory = Mock(return_value=provider) + monkeypatch.setattr(common_utils, "get_azure_ad_token_from_entra_id", factory) + credentials = { + "tenant_id": "tenant", + "client_id": "client", + "client_secret": "synthetic-secret", + } + elif kind == "oidc": + monkeypatch.setattr(common_utils, "get_azure_ad_token_from_oidc", provider) + credentials = { + "tenant_id": "tenant", + "client_id": "client", + "azure_ad_token": "oidc/azure/https://cognitiveservices.azure.com/.default", + } + else: + credentials = {"azure_ad_token_provider": provider} + route = respx_mock.post(_URL).respond(json=_RESPONSE) + await call_decisions(True, False, credentials) + assert route.calls.last.request.headers["authorization"] == "Bearer synthetic-entra" + provider.assert_called_once() + if kind == "service-principal": + factory.assert_called_once_with( + tenant_id="tenant", + client_id="client", + client_secret="synthetic-secret", + scope="https://cognitiveservices.azure.com/.default", + ) + if kind == "oidc": + provider.assert_called_once_with( + azure_ad_token=credentials["azure_ad_token"], + azure_client_id="client", + azure_tenant_id="tenant", + scope="https://cognitiveservices.azure.com/.default", + ) + + +@pytest.mark.parametrize("key_source", ("api_key", "AZURE_API_KEY", "AZURE_OPENAI_API_KEY")) +async def test_azure_api_key_takes_precedence_over_entra( + monkeypatch: pytest.MonkeyPatch, respx_mock: respx.MockRouter, key_source: str +) -> None: + provider = Mock(side_effect=AssertionError("API key must bypass Entra")) + credentials = {"azure_ad_token_provider": provider} + if key_source == "api_key": + credentials["api_key"] = "synthetic-key" + else: + monkeypatch.setenv(key_source, "synthetic-key") + route = respx_mock.post(_URL).respond(json=_RESPONSE) + await call_decisions(True, False, credentials) + assert route.calls.last.request.headers["api-key"] == "synthetic-key" + assert "authorization" not in route.calls.last.request.headers + provider.assert_not_called() + + +async def test_azure_credential_lookup_does_not_block_the_event_loop( + respx_mock: respx.MockRouter, +) -> None: + event_loop_thread = threading.get_ident() + + def provider() -> str: + assert threading.get_ident() != event_loop_thread + return "synthetic-entra" + + respx_mock.post(_URL).respond(json=_RESPONSE) + await call_decisions(True, False, {"azure_ad_token_provider": provider}) + + +def test_azure_decisions_requires_azure_endpoint( + monkeypatch: pytest.MonkeyPatch, +) -> None: + monkeypatch.setenv("OPENAI_API_BASE", "https://unrelated.example") + with pytest.raises(litellm.BadRequestError, match="api_base is required"): + litellm.decisions( + model="azure/luna-deployment", + input="Text", + questions=[ + { + "type": "predicate", + "name": "defect", + "instructions": "Is this a defect?", + } + ], + ) + + +def test_azure_decisions_does_not_echo_invalid_credentials() -> None: + with pytest.raises(litellm.BadRequestError) as error: + AzureDecisionsConfig().validate_environment( + {}, + "luna-deployment", + None, + {"azure_ad_token": {"secret": "sensitive-value"}}, + ) + assert "sensitive-value" not in str(error.value) diff --git a/tests/unit/llms/azure/vector_stores/test_azure_vector_stores_transformation.py b/tests/unit/llms/azure/vector_stores/test_azure_vector_stores_transformation.py index 59bec08fca6..3713b1cc895 100644 --- a/tests/unit/llms/azure/vector_stores/test_azure_vector_stores_transformation.py +++ b/tests/unit/llms/azure/vector_stores/test_azure_vector_stores_transformation.py @@ -1,4 +1,7 @@ +from unittest.mock import Mock + from litellm.llms.azure.vector_stores.transformation import AzureOpenAIVectorStoreConfig +from litellm.llms.base_llm.vector_store.transformation import BaseVectorStoreConfig def test_transform_search_vector_store_request_preserves_azure_query_string(): @@ -18,3 +21,29 @@ def test_transform_search_vector_store_request_preserves_azure_query_string(): ) assert url == "https://x.openai.azure.com/openai/vector_stores/vs_1/search?api-version=2024-10-21" + + +def test_get_vector_store_url_puts_id_before_api_version_query(): + config = AzureOpenAIVectorStoreConfig() + api_base = config.get_complete_url( + api_base="https://x.openai.azure.com", + litellm_params={"api_version": "2025-04-01-preview"}, + ) + + url = config.get_vector_store_url(api_base, "vs_abc") + + assert url == "https://x.openai.azure.com/openai/vector_stores/vs_abc?api-version=2025-04-01-preview" + + +def test_get_vector_store_url_without_query_is_plain_path(): + url = AzureOpenAIVectorStoreConfig().get_vector_store_url( + "https://x.openai.azure.com/openai/vector_stores", "vs_abc" + ) + + assert url == "https://x.openai.azure.com/openai/vector_stores/vs_abc" + + +def test_base_get_vector_store_url_appends_id_for_providers_without_query_string(): + url = BaseVectorStoreConfig.get_vector_store_url(Mock(), "https://api.example.test/v1/vector_stores", "vs_abc") + + assert url == "https://api.example.test/v1/vector_stores/vs_abc" diff --git a/tests/unit/llms/base_llm/decisions/test_base_decisions_transformation.py b/tests/unit/llms/base_llm/decisions/test_base_decisions_transformation.py index 3aebf56ee73..798cbe5fe00 100644 --- a/tests/unit/llms/base_llm/decisions/test_base_decisions_transformation.py +++ b/tests/unit/llms/base_llm/decisions/test_base_decisions_transformation.py @@ -355,3 +355,49 @@ def test_invalid_provider_response_is_an_api_error(payload: object, provider: st with pytest.raises(BaseLLMException, match="unexpected response") as error: config.transform_decisions_response("drex-v2.0", provider, httpx.Response(200, json=payload), request) assert error.value.status_code == 500 + + +@pytest.mark.parametrize( + ("probabilities", "expected"), + ( + ({}, ()), + ({"1": 0.8}, ((1, "medium", 0.8),)), + ({"0": 0.0, "1": 0.8}, ((0, "low", 0.0), (1, "medium", 0.8))), + ({"2": 0.0}, ((2, "high", 0.0),)), + ), + ids=("empty", "missing", "explicit_zero", "only_zero"), +) +def test_score_probabilities_preserve_missing_entries_and_explicit_zeros( + probabilities: Mapping[str, float], expected: tuple[tuple[int, str, float], ...] +) -> None: + ir: Final = systemone_request_to_ir( + _SYSTEMONE_BODY.validate_python( + { + "state": "Classify the fixture.", + "questions": {"score": {"type": "score", "criteria": ["low", "medium", "high"]}}, + } + ) + ) + payload: Final = { + "model": "fixture", + "answers": { + "score": { + "type": "score", + "score": 1, + "confidence": 0.8, + "legend": {"0": "low", "1": "medium", "2": "high"}, + "probabilities": probabilities, + } + }, + "usage": {"input_tokens": 0, "output_tokens": 0}, + } + + response: Final = parse_systemone_response(payload, ir) + answer: Final = response.answers[0] + + assert isinstance(answer, DecisionsIRScoreAnswer) + assert tuple((item.value, item.label, item.probability) for item in answer.probabilities) == expected + assert ( + ir_to_systemone_response(response, ir).model_dump(mode="json")["answers"]["score"]["probabilities"] + == probabilities + ) diff --git a/tests/unit/llms/bedrock/chat/invoke_transformations/test_bedrock_chat_invoke_transformations_anthropic_claude3_transformation.py b/tests/unit/llms/bedrock/chat/invoke_transformations/test_bedrock_chat_invoke_transformations_anthropic_claude_transformation.py similarity index 99% rename from tests/unit/llms/bedrock/chat/invoke_transformations/test_bedrock_chat_invoke_transformations_anthropic_claude3_transformation.py rename to tests/unit/llms/bedrock/chat/invoke_transformations/test_bedrock_chat_invoke_transformations_anthropic_claude_transformation.py index bd98e4eb4de..86c4b29eb53 100644 --- a/tests/unit/llms/bedrock/chat/invoke_transformations/test_bedrock_chat_invoke_transformations_anthropic_claude3_transformation.py +++ b/tests/unit/llms/bedrock/chat/invoke_transformations/test_bedrock_chat_invoke_transformations_anthropic_claude_transformation.py @@ -14,7 +14,7 @@ from pydantic import BaseModel, ConfigDict # Ensure the project root is on the import path so `litellm` can be imported when # tests are executed from any working directory. import litellm -from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformation import ( +from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeConfig, ) from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler @@ -188,7 +188,7 @@ def test_output_format_conversion_to_inline_schema(): Bedrock Invoke doesn't support the output_format parameter, so LiteLLM converts it by embedding the schema directly into the user message content. """ - from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude3_transformation import ( + from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeMessagesConfig, ) @@ -265,7 +265,7 @@ def test_output_format_conversion_with_string_content(): """ Test that output_format conversion works when message content is a string (not a list). """ - from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude3_transformation import ( + from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeMessagesConfig, ) @@ -313,7 +313,7 @@ def test_output_format_with_no_schema(): """ Test that if output_format has no schema, the conversion is skipped gracefully. """ - from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude3_transformation import ( + from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeMessagesConfig, ) @@ -352,7 +352,7 @@ def test_opus_4_5_model_detection(): Test that the _is_claude_opus_4_5 method correctly identifies Opus 4.5 models with various naming conventions. """ - from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude3_transformation import ( + from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeMessagesConfig, ) @@ -1526,7 +1526,7 @@ class TestBedrockAnthropicPromptCachingRegression: from litellm.llms.bedrock.chat.converse_transformation import ( AmazonConverseConfig, ) - from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformation import ( + from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeConfig, ) @@ -1610,7 +1610,7 @@ class TestBedrockAnthropicPromptCachingRegression: from litellm.llms.bedrock.chat.converse_transformation import ( AmazonConverseConfig, ) - from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformation import ( + from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeConfig, ) @@ -1688,7 +1688,7 @@ class TestBedrockAnthropic1MContextRegression: from litellm.llms.bedrock.chat.converse_transformation import ( AmazonConverseConfig, ) - from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformation import ( + from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeConfig, ) @@ -1753,7 +1753,7 @@ class TestBedrockAnthropic1MContextRegression: from litellm.llms.bedrock.chat.converse_transformation import ( AmazonConverseConfig, ) - from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformation import ( + from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeConfig, ) @@ -1807,7 +1807,7 @@ class TestBedrockAnthropic1MContextRegression: from litellm.llms.bedrock.chat.converse_transformation import ( AmazonConverseConfig, ) - from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformation import ( + from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeConfig, ) @@ -1867,7 +1867,7 @@ class TestBedrockAnthropicCombinedRegressions: from litellm.llms.bedrock.chat.converse_transformation import ( AmazonConverseConfig, ) - from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformation import ( + from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeConfig, ) diff --git a/tests/unit/llms/bedrock/chat/test_invoke_handler.py b/tests/unit/llms/bedrock/chat/test_invoke_handler.py index f3ceac1d93c..996cfec6e22 100644 --- a/tests/unit/llms/bedrock/chat/test_invoke_handler.py +++ b/tests/unit/llms/bedrock/chat/test_invoke_handler.py @@ -19,6 +19,7 @@ from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLogging from litellm.litellm_core_utils.litellm_logging import _get_provider_request_id from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapper from litellm.llms.bedrock.chat.invoke_handler import ( + AmazonAnthropicClaudeStreamDecoder, AmazonOpenAICompatibleStreamDecoder, AWSEventStreamDecoder, _stream_decoder, @@ -1120,6 +1121,7 @@ async def test_converse_streaming_completion_yields_text_and_finish_reason( ), ) ) + def handle_request(request: httpx.Request) -> httpx.Response: assert request.url.path.endswith("/converse-stream") return httpx.Response(200, content=event_stream_body, headers=_event_stream_headers()) @@ -1179,9 +1181,7 @@ def test_mistral_invoke_stream_yields_text_and_finish_reason( assert "".join(chunk.choices[0].delta.content or "" for chunk in chunks) == ( "A court case moves through the courts." ) - assert [chunk.choices[0].finish_reason for chunk in chunks if chunk.choices[0].finish_reason] == [ - "stop" - ] + assert [chunk.choices[0].finish_reason for chunk in chunks if chunk.choices[0].finish_reason] == ["stop"] def test_converse_streaming_tool_call_arguments_are_valid_json( @@ -1721,6 +1721,7 @@ def test_filter_headers_for_aws_signature(): @pytest.mark.parametrize("missing", ["botocore", "unrelated_dependency"]) def test_invoke_decoder_reports_only_missing_aws_dependency(missing): from unittest.mock import patch + from litellm.llms.bedrock.chat.invoke_handler import AWSEventStreamDecoder failure = ModuleNotFoundError("missing dependency", name=missing) @@ -1835,9 +1836,7 @@ async def test_converse_stream_thinking_merges_into_content_with_think_tags() -> "contentBlockDelta", {"contentBlockIndex": 0, "delta": {"reasoningContent": {"signature": "c2lnbmF0dXJl"}}} ), _converse_event_frame("contentBlockStop", {"contentBlockIndex": 0}), - _converse_event_frame( - "contentBlockDelta", {"contentBlockIndex": 1, "delta": {"text": "Hi I am Anthropic, "}} - ), + _converse_event_frame("contentBlockDelta", {"contentBlockIndex": 1, "delta": {"text": "Hi I am Anthropic, "}}), _converse_event_frame( "contentBlockDelta", {"contentBlockIndex": 1, "delta": {"text": "I am a helpful assistant"}} ), @@ -1919,7 +1918,11 @@ _CUT_JSON_TOOL_STREAM: Final = b"".join( "content_block": {"type": "tool_use", "id": "toolu_cut_1", "name": "json_tool_call", "input": {}}, }, {"type": "content_block_delta", "index": 0, "delta": {"type": "input_json_delta", "partial_json": '{"city"'}}, - {"type": "content_block_delta", "index": 0, "delta": {"type": "input_json_delta", "partial_json": ': "Paris", '}}, + { + "type": "content_block_delta", + "index": 0, + "delta": {"type": "input_json_delta", "partial_json": ': "Paris", '}, + }, { "type": "content_block_delta", "index": 0, @@ -1961,3 +1964,21 @@ async def test_async_anthropic_invoke_stream_cut_before_the_json_tool_block_ends chunks: Final = [chunk async for chunk in _cut_json_tool_stream_decoder().aiter_bytes(_chunks())] assert json.loads(_streamed_content(chunks)) == {"city": "Paris", "country": "France"} + + +def test_invoke_stream_decoder_carries_the_guardrail_trace_of_the_message_stop_chunk() -> None: + """Bedrock Invoke reports the native guardrail trace once, on the final ``message_stop`` chunk, under + ``amazon-bedrock-trace``. The chunk keeps it so the stream builder and the spend log can price it.""" + decoder = AmazonAnthropicClaudeStreamDecoder(model="anthropic.claude-sonnet-5-v1:0", sync_stream=True) + trace = {"guardrail": {"input": {"gid": {"invocationMetrics": {"usage": {"topicPolicyUnits": 1}}}}}} + plain = decoder._chunk_parser({"type": "message_stop", "amazon-bedrock-invocationMetrics": {"inputTokenCount": 3}}) + traced = decoder._chunk_parser( + { + "type": "message_stop", + "amazon-bedrock-invocationMetrics": {"inputTokenCount": 3}, + "amazon-bedrock-trace": trace, + } + ) + assert (plain.provider_specific_fields or {}).get("amazon-bedrock-trace") is None + assert traced.provider_specific_fields is not None + assert traced.provider_specific_fields["amazon-bedrock-trace"] == trace diff --git a/tests/unit/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py b/tests/unit/llms/bedrock/messages/invoke_transformations/test_anthropic_claude_transformation.py similarity index 99% rename from tests/unit/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py rename to tests/unit/llms/bedrock/messages/invoke_transformations/test_anthropic_claude_transformation.py index 6fe32785281..3c0bbadc133 100644 --- a/tests/unit/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py +++ b/tests/unit/llms/bedrock/messages/invoke_transformations/test_anthropic_claude_transformation.py @@ -29,7 +29,7 @@ from litellm.constants import ( # Ensure the project root is on the import path so `litellm` can be imported when # tests are executed from any working directory. from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj -from litellm.llms.anthropic.pass_through.messages.mid_conversation_system import ( +from litellm.llms.anthropic.messages.native.mid_conversation_system import ( as_system_content_blocks, ) from litellm.llms.bedrock.common_utils import ( @@ -37,7 +37,7 @@ from litellm.llms.bedrock.common_utils import ( normalize_custom_field_on_tools, normalize_tool_input_schema_types_for_bedrock_invoke, ) -from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude3_transformation import ( +from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeMessagesConfig, AmazonAnthropicClaudeMessagesStreamDecoder, ) @@ -4169,3 +4169,32 @@ async def test_bedrock_messages_400_is_not_retried_unless_it_rejects_opt_in_nati assert isinstance(raised, litellm.BadRequestError) assert len(bedrock.bodies) == 1 + + +@pytest.mark.parametrize("trace", ["enabled", "disabled"]) +def test_bedrock_messages_applies_the_deployment_guardrail_config_as_invoke_headers(trace: str) -> None: + from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude_transformation import ( + AmazonAnthropicClaudeMessagesConfig, + ) + + headers, _ = AmazonAnthropicClaudeMessagesConfig().validate_anthropic_messages_environment( + headers={}, + model="anthropic.claude-sonnet-5-v1:0", + messages=[], + optional_params={}, + litellm_params={"guardrailConfig": {"guardrailIdentifier": "gid", "guardrailVersion": "2", "trace": trace}}, + ) + assert headers["X-Amzn-Bedrock-GuardrailIdentifier"] == "gid" + assert headers["X-Amzn-Bedrock-GuardrailVersion"] == "2" + assert headers["X-Amzn-Bedrock-Trace"] == trace.upper() + + +def test_bedrock_messages_without_guardrail_config_sends_no_guardrail_headers() -> None: + from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude_transformation import ( + AmazonAnthropicClaudeMessagesConfig, + ) + + headers, _ = AmazonAnthropicClaudeMessagesConfig().validate_anthropic_messages_environment( + headers={}, model="anthropic.claude-sonnet-5-v1:0", messages=[], optional_params={}, litellm_params={} + ) + assert not any(name.startswith("X-Amzn-Bedrock-Guardrail") for name in headers) diff --git a/tests/unit/llms/bedrock/test_anthropic_beta_support.py b/tests/unit/llms/bedrock/test_anthropic_beta_support.py index a20ec94a99d..73d529ae3ba 100644 --- a/tests/unit/llms/bedrock/test_anthropic_beta_support.py +++ b/tests/unit/llms/bedrock/test_anthropic_beta_support.py @@ -11,11 +11,11 @@ from unittest.mock import MagicMock, patch import pytest from litellm.llms.bedrock.chat.converse_transformation import AmazonConverseConfig -from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformation import ( +from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeConfig, ) from litellm.llms.bedrock.common_utils import get_anthropic_beta_from_headers -from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude3_transformation import ( +from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeMessagesConfig, ) diff --git a/tests/unit/llms/bedrock/test_base_aws_llm.py b/tests/unit/llms/bedrock/test_base_aws_llm.py index 4350fdb699b..c220e39f4d1 100644 --- a/tests/unit/llms/bedrock/test_base_aws_llm.py +++ b/tests/unit/llms/bedrock/test_base_aws_llm.py @@ -3228,7 +3228,7 @@ class TestGetBedrockModelIdArnHandling: def test_arn_url_matches_expected(self): """Full URL built from messages config must match expected encoded form.""" import urllib.parse - from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude3_transformation import ( + from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeMessagesConfig, ) diff --git a/tests/unit/llms/bedrock/test_cost_calculation.py b/tests/unit/llms/bedrock/test_cost_calculation.py new file mode 100644 index 00000000000..f4718344e7e --- /dev/null +++ b/tests/unit/llms/bedrock/test_cost_calculation.py @@ -0,0 +1,43 @@ +import json +from importlib.resources import files +from typing import Final + +import pytest + +import litellm +from litellm.types.utils import Usage + +CLAUDE_PLATFORM_PREFIX: Final = "bedrock/claude_platform/" +CLAUDE_PLATFORM_KEYS: Final = tuple( + key + for key in json.loads(files("litellm").joinpath("model_prices_and_context_window_backup.json").read_text()) + if key.startswith(CLAUDE_PLATFORM_PREFIX) +) + + +def test_claude_platform_rows_exist() -> None: + assert CLAUDE_PLATFORM_KEYS + + +@pytest.mark.parametrize("inference_geo", ["global", "us"]) +@pytest.mark.parametrize("key", CLAUDE_PLATFORM_KEYS) +def test_claude_platform_cost_matches_claude_api_cost( + local_model_cost_map: None, key: str, inference_geo: str +) -> None: + usage: Final = Usage( + prompt_tokens=1_000, + completion_tokens=200, + cache_read_input_tokens=300, + cache_creation_input_tokens=250, + inference_geo=inference_geo, + ) + + claude_platform_cost: Final = litellm.cost_per_token( + model=key.removeprefix("bedrock/"), custom_llm_provider="bedrock", usage_object=usage + ) + claude_api_cost: Final = litellm.cost_per_token( + model=key.removeprefix(CLAUDE_PLATFORM_PREFIX), custom_llm_provider="anthropic", usage_object=usage + ) + + assert claude_platform_cost == pytest.approx(claude_api_cost) + assert sum(claude_platform_cost) > 0 diff --git a/tests/unit/llms/bedrock/test_request_metadata.py b/tests/unit/llms/bedrock/test_request_metadata.py index 6b74ad90cff..8f94ad54c3d 100644 --- a/tests/unit/llms/bedrock/test_request_metadata.py +++ b/tests/unit/llms/bedrock/test_request_metadata.py @@ -15,7 +15,7 @@ from litellm.llms.bedrock.chat.invoke_transformations.amazon_openai_transformati from litellm.llms.bedrock.chat.invoke_transformations.base_invoke_transformation import ( AmazonInvokeConfig, ) -from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude3_transformation import ( +from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeMessagesConfig, ) from litellm.llms.bedrock.request_metadata import ( diff --git a/tests/unit/llms/chatgpt/chat/test_chatgpt_chat_transformation.py b/tests/unit/llms/chatgpt/chat/test_chatgpt_chat_transformation.py new file mode 100644 index 00000000000..f9d1dc28d12 --- /dev/null +++ b/tests/unit/llms/chatgpt/chat/test_chatgpt_chat_transformation.py @@ -0,0 +1,638 @@ +from unittest.mock import MagicMock + +import pytest + +from litellm.exceptions import AuthenticationError +from litellm.llms.chatgpt.chat.transformation import ChatGPTConfig +from litellm.llms.chatgpt.common_utils import GetAccessTokenError + +GATEWAY_BASE = "https://chatgpt.example/backend-api/codex" + + +def _gateway_authenticator() -> MagicMock: + authenticator = MagicMock() + authenticator.get_api_base.return_value = GATEWAY_BASE + authenticator.get_access_token.return_value = "gateway-access-token" + return authenticator + + +def _provider_info( + config: ChatGPTConfig, api_base: str | None, api_key: str | None +) -> tuple[str | None, str | None, str]: + return config._get_openai_compatible_provider_info( + model="gpt-5.4", api_base=api_base, api_key=api_key, custom_llm_provider="chatgpt" + ) + + +class TestChatGPTChatProviderInfo: + def test_configured_key_uses_configured_base_without_gateway_login(self): + authenticator = _gateway_authenticator() + config = ChatGPTConfig(authenticator=authenticator) + + assert _provider_info(config, "http://127.0.0.1:9999", "configured-key") == ( + "http://127.0.0.1:9999", + "configured-key", + "chatgpt", + ) + authenticator.get_access_token.assert_not_called() + + def test_configured_key_without_base_uses_gateway_base(self): + config = ChatGPTConfig(authenticator=_gateway_authenticator()) + + assert _provider_info(config, None, "configured-key") == (GATEWAY_BASE, "configured-key", "chatgpt") + + def test_gateway_login_is_never_sent_to_a_custom_base(self): + config = ChatGPTConfig(authenticator=_gateway_authenticator()) + + assert _provider_info(config, "http://attacker.example", None) == ( + GATEWAY_BASE, + "gateway-access-token", + "chatgpt", + ) + + def test_missing_gateway_login_raises_authentication_error(self): + authenticator = _gateway_authenticator() + authenticator.get_access_token.side_effect = GetAccessTokenError(status_code=401, message="not logged in") + config = ChatGPTConfig(authenticator=authenticator) + + with pytest.raises(AuthenticationError, match="not logged in"): + _provider_info(config, None, None) + + +import asyncio +import json +from pathlib import Path +from types import MappingProxyType +from typing import Final + +import httpx +import respx + +import litellm +from litellm.integrations.dotprompt.dotprompt_manager import DotpromptManager +from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider +from litellm.llms.chatgpt.chat.transformation import ChatGPTConfig +from litellm.types.router import GenericLiteLLMParams + + +def _write_auth_record(path: Path, token: str, account_id: str) -> None: + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text( + json.dumps( + { + "access_token": token, + "account_id": account_id, + "expires_at": 4102444800, + } + ) + ) + + +@pytest.fixture +def auth_files(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> tuple[Path, Path]: + monkeypatch.setattr("time.time", lambda: 1700000000) + default_dir: Final = tmp_path / "default" + monkeypatch.setenv("CHATGPT_TOKEN_DIR", str(default_dir)) + monkeypatch.delenv("CHATGPT_AUTH_FILE", raising=False) + _write_auth_record(default_dir / "auth.json", "token-default", "acct-default") + file_a: Final = tmp_path / "account-a" / "auth.json" + file_b: Final = tmp_path / "account-b" / "auth.json" + _write_auth_record(file_a, "token-a", "acct-a") + _write_auth_record(file_b, "token-b", "acct-b") + return file_a, file_b + + +class TestChatGPTMultiAccountChat: + def test_validate_environment_uses_per_model_auth_file(self, auth_files: tuple[Path, Path]) -> None: + file_a, file_b = auth_files + config: Final = ChatGPTConfig() + + headers_a: Final = config.validate_environment( + headers={}, + model="gpt-6.1-sol", + messages=[], + optional_params={}, + litellm_params={"chatgpt_auth_file": str(file_a)}, + api_key="token-default", + ) + headers_b: Final = config.validate_environment( + headers={}, + model="gpt-6.1-sol", + messages=[], + optional_params={}, + litellm_params={"chatgpt_auth_file": str(file_b)}, + api_key="token-default", + ) + + assert headers_a["Authorization"] == "Bearer token-a" + assert headers_a["ChatGPT-Account-Id"] == "acct-a" + assert headers_b["Authorization"] == "Bearer token-b" + assert headers_b["ChatGPT-Account-Id"] == "acct-b" + + def test_validate_environment_defaults_to_global_auth_file(self, auth_files: tuple[Path, Path]) -> None: + config: Final = ChatGPTConfig() + + headers: Final = config.validate_environment( + headers={}, + model="gpt-6.1-sol", + messages=[], + optional_params={}, + litellm_params={}, + api_key="token-default", + ) + + assert headers["Authorization"] == "Bearer token-default" + assert headers["ChatGPT-Account-Id"] == "acct-default" + + def test_provider_info_uses_per_model_auth_file(self, auth_files: tuple[Path, Path]) -> None: + file_a, _ = auth_files + config: Final = ChatGPTConfig() + + _, per_model_key, _ = config._get_openai_compatible_provider_info( + "gpt-6.1-sol", None, None, "chatgpt", {"chatgpt_auth_file": str(file_a)} + ) + _, default_key, _ = config._get_openai_compatible_provider_info("gpt-6.1-sol", None, None, "chatgpt") + + assert per_model_key == "token-a" + assert default_key == "token-default" + + def test_get_llm_provider_threads_auth_file(self, auth_files: tuple[Path, Path]) -> None: + file_a, _ = auth_files + + model, provider, dynamic_api_key, _ = get_llm_provider( + model="chatgpt/gpt-6.1-sol", + litellm_params=GenericLiteLLMParams(chatgpt_auth_file=str(file_a)), + ) + + assert model == "gpt-6.1-sol" + assert provider == "chatgpt" + assert dynamic_api_key == "token-a" + + +def _subscription_response(request: httpx.Request) -> httpx.Response: + account: Final = request.headers["ChatGPT-Account-Id"] + assert request.headers["Authorization"] in ( + f"Bearer token-{account.removeprefix('acct-')}", + f"Bearer {_client_token(account)}", + ) + assert "chatgpt_auth_file" not in request.content.decode() + message: Final = { + "id": "msg_test", + "type": "message", + "role": "assistant", + "status": "completed", + "content": [{"type": "output_text", "text": account, "annotations": []}], + } + response: Final = { + "id": "resp_test", + "object": "response", + "created_at": 1700000000, + "status": "completed", + "model": "gpt-6.1-sol", + "output": [message], + "usage": {"input_tokens": 1, "output_tokens": 1, "total_tokens": 2}, + } + events: Final = ( + {"type": "response.created", "response": {**response, "status": "in_progress", "output": []}}, + { + "type": "response.output_text.delta", + "item_id": "msg_test", + "output_index": 0, + "content_index": 0, + "delta": account, + }, + {"type": "response.output_item.done", "output_index": 0, "item": message}, + {"type": "response.completed", "response": response}, + ) + return httpx.Response( + 200, + text="".join(f"data: {json.dumps(event)}\n\n" for event in events), + headers={"content-type": "text/event-stream"}, + ) + + +@pytest.mark.parametrize("blocked_default", [False, True]) +@pytest.mark.parametrize("with_prompt", [False, True]) +@pytest.mark.parametrize("endpoint", ["chat", "responses"]) +@pytest.mark.parametrize("through_router", [False, True]) +@pytest.mark.asyncio +async def test_requests_use_selected_subscription( + auth_files: tuple[Path, Path], + endpoint: str, + through_router: bool, + with_prompt: bool, + blocked_default: bool, + monkeypatch: pytest.MonkeyPatch, +) -> None: + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + default_dir: Final = auth_files[0].parent / "missing-default" + if blocked_default: + default_dir.write_text("ordinary file") + monkeypatch.setenv("CHATGPT_TOKEN_DIR", str(default_dir / "unused")) + if with_prompt: + monkeypatch.setattr( + litellm, + "callbacks", + [ + DotpromptManager( + prompt_id="account-check", + prompt_data={"content": "Saved account prompt", "metadata": {"model": "chatgpt/gpt-6.1-sol"}}, + ) + ], + ) + router: Final = ( + litellm.Router( + model_list=[ + { + "model_name": f"account-{index}", + "litellm_params": {"model": "chatgpt/gpt-6.1-sol", "chatgpt_auth_file": str(path)}, + } + for index, path in enumerate(auth_files) + ] + ) + if through_router + else None + ) + + async def request(index: int, path: Path) -> str: + params: Final = MappingProxyType( + { + "model": f"account-{index}" if router else "chatgpt/gpt-6.1-sol", + **({"chatgpt_auth_file": str(path)} if router is None else {}), + **({"prompt_id": "account-check"} if with_prompt else {}), + } + ) + if endpoint == "chat": + result: Final = await (router.acompletion if router else litellm.acompletion)( + **params, messages=[{"role": "user", "content": "Hello"}] + ) + return result.choices[0].message.content + response: Final = await (router.aresponses if router else litellm.aresponses)( + **params, input=[{"role": "user", "content": "Hello"}] + ) + return response.output[0].content[0].text + + with respx.mock as transport: + transport.post("https://chatgpt.com/backend-api/codex/responses").mock(side_effect=_subscription_response) + results: Final = await asyncio.gather(*(request(index, path) for index, path in enumerate(auth_files))) + assert results == ["acct-a", "acct-b"] + if with_prompt: + assert all("Saved account prompt" in call.request.content.decode() for call in transport.calls) + + +def _client_token(account: str) -> str: + import base64 + + payload: Final = ( + base64.urlsafe_b64encode(json.dumps({"https://api.openai.com/auth": {"chatgpt_account_id": account}}).encode()) + .rstrip(b"=") + .decode() + ) + return f"header.{payload}.signature" + + +@pytest.mark.parametrize("endpoint", ["chat", "responses"]) +@pytest.mark.parametrize("configured_login", [False, True]) +@pytest.mark.parametrize("with_prompt", [False, True]) +@pytest.mark.parametrize("stream", [False, True]) +@pytest.mark.asyncio +async def test_client_login_keeps_its_account_across_gateway_deployments( + auth_files: tuple[Path, Path], + endpoint: str, + configured_login: bool, + with_prompt: bool, + stream: bool, + monkeypatch: pytest.MonkeyPatch, +) -> None: + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + monkeypatch.setenv("CHATGPT_TOKEN_DIR", str(auth_files[0].parent / "no-gateway-login")) + if with_prompt: + monkeypatch.setattr( + litellm, + "callbacks", + [ + DotpromptManager( + prompt_id="client-account-check", + prompt_data={"content": "Saved client prompt", "metadata": {"model": "chatgpt/gpt-6.1-sol"}}, + ) + ], + ) + router: Final = litellm.Router( + model_list=[ + { + "model_name": "subscriptions", + "litellm_params": { + "model": "chatgpt/gpt-6.1-sol", + **({"chatgpt_auth_file": str(path)} if configured_login else {}), + }, + } + for path in auth_files + ], + num_retries=0, + ) + + def reply(request: httpx.Request) -> httpx.Response: + account: Final = request.headers["ChatGPT-Account-Id"] + assert request.headers["Authorization"] == f"Bearer {_client_token(account)}" + return _subscription_response( + httpx.Request( + "POST", + request.url, + content=request.content, + headers={ + **{key: value for key, value in request.headers.items() if key.lower() != "authorization"}, + "Authorization": f"Bearer token-{account.removeprefix('acct-')}", + }, + ) + ) + + async def call(account: str) -> str: + params: Final = MappingProxyType( + { + "model": "subscriptions", + "stream": stream, + **({"prompt_id": "client-account-check"} if with_prompt else {}), + "provider_specific_header": { + "custom_llm_provider": "chatgpt", + "extra_headers": {"Authorization": f"Bearer {_client_token(account)}"}, + }, + } + ) + response: Final = await ( + router.acompletion(**params, messages=[{"role": "user", "content": "Hello"}]) + if endpoint == "chat" + else router.aresponses(**params, input=[{"role": "user", "content": "Hello"}]) + ) + if stream: + chunks: Final = [part async for part in response] + return ( + "".join(part.choices[0].delta.content or "" for part in chunks) + if endpoint == "chat" + else "".join( + getattr(part, "delta", "") + for part in chunks + if getattr(part, "type", "") == "response.output_text.delta" + ) + ) + return response.choices[0].message.content if endpoint == "chat" else response.output[0].content[0].text + + with respx.mock as transport: + transport.post("https://chatgpt.com/backend-api/codex/responses").mock(side_effect=reply) + results: Final = await asyncio.gather(call("acct-client-a"), call("acct-client-b")) + assert results == ["acct-client-a", "acct-client-b"] + assert len(transport.calls) == 2 + + +@pytest.mark.asyncio +async def test_one_client_limit_does_not_cool_down_other_subscriptions( + auth_files: tuple[Path, Path], monkeypatch: pytest.MonkeyPatch +) -> None: + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + router: Final = litellm.Router( + model_list=[ + {"model_name": "pool", "litellm_params": {"model": "chatgpt/gpt-6.1-sol", "chatgpt_auth_file": str(path)}} + for path in auth_files + ], + num_retries=0, + allowed_fails=0, + cooldown_time=60, + ) + headers: Final = { + "custom_llm_provider": "chatgpt", + "extra_headers": {"Authorization": f"Bearer {_client_token('acct-limited')}"}, + } + with respx.mock as transport: + route: Final = transport.post("https://chatgpt.com/backend-api/codex/responses") + route.respond( + 429, + headers={"retry-after": "60"}, + json={"error": {"message": "Usage limit reached", "type": "rate_limit_error"}}, + ) + for _ in range(2): + with pytest.raises(litellm.RateLimitError): + await router.aresponses(model="pool", input="Hello", provider_specific_header=headers) + await asyncio.sleep(0) + route.mock(side_effect=_subscription_response) + response: Final = await router.aresponses(model="pool", input="Hello") + assert response.output[0].content[0].text in ("acct-a", "acct-b") + + +@pytest.mark.parametrize("endpoint", ["chat", "responses"]) +@pytest.mark.parametrize("async_call", [False, True]) +@pytest.mark.parametrize("direct_headers", [False, True]) +@pytest.mark.parametrize("configured_key", [False, True]) +@pytest.mark.parametrize( + "target", ["https://example.com/v1", "http://chatgpt.com/backend-api/codex", "https://chatgpt.com.example.com/v1"] +) +@pytest.mark.asyncio +async def test_client_login_cannot_be_redirected_to_another_host( + endpoint: str, target: str, async_call: bool, direct_headers: bool, configured_key: bool +) -> None: + headers: Final = {"Authorization": f"Bearer {_client_token('acct-client')}"} + credential: Final = ( + {"extra_headers": headers} + if direct_headers + else {"provider_specific_header": {"custom_llm_provider": "chatgpt", "extra_headers": headers}} + ) + params: Final = MappingProxyType( + { + "model": "chatgpt/gpt-6.1-sol", + "api_base": target, + **({"api_key": "configured-test-key"} if configured_key else {}), + **credential, + } + ) + + async def request() -> None: + if endpoint == "chat": + if async_call: + await litellm.acompletion(**params, messages=[{"role": "user", "content": "Hello"}]) + else: + litellm.completion(**params, messages=[{"role": "user", "content": "Hello"}]) + elif async_call: + await litellm.aresponses(**params, input="Hello") + else: + litellm.responses(**params, input="Hello") + + with respx.mock as transport: + with pytest.raises(litellm.BadRequestError, match="official HTTPS ChatGPT endpoint"): + await request() + assert len(transport.calls) == 0 + + +@pytest.mark.asyncio +async def test_cross_provider_fallback_does_not_receive_the_chatgpt_login( + auth_files: tuple[Path, Path], monkeypatch: pytest.MonkeyPatch +) -> None: + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + router: Final = litellm.Router( + model_list=[ + { + "model_name": "subscription", + "litellm_params": {"model": "chatgpt/gpt-6.1-sol", "chatgpt_auth_file": str(auth_files[0])}, + }, + { + "model_name": "api-fallback", + "litellm_params": {"model": "openai/gpt-6.1-sol", "api_key": "sk-example-fallback"}, + }, + ], + fallbacks=[{"subscription": ["api-fallback"]}], + num_retries=0, + ) + with respx.mock as transport: + transport.post("https://chatgpt.com/backend-api/codex/responses").respond( + 429, json={"error": {"message": "Usage limit reached", "type": "rate_limit_error"}} + ) + fallback: Final = transport.post("https://api.openai.com/v1/responses").respond( + 200, + json={ + "id": "resp_fallback", + "object": "response", + "created_at": 1700000000, + "status": "completed", + "model": "gpt-6.1-sol", + "output": [ + { + "id": "msg_fallback", + "type": "message", + "role": "assistant", + "status": "completed", + "content": [{"type": "output_text", "text": "fallback", "annotations": []}], + } + ], + "usage": {"input_tokens": 1, "output_tokens": 1, "total_tokens": 2}, + }, + ) + response: Final = await router.aresponses( + model="subscription", + input="Hello", + provider_specific_header={ + "custom_llm_provider": "chatgpt", + "extra_headers": { + "Authorization": f"Bearer {_client_token('acct-client')}", + "ChatGPT-Account-Id": "acct-client", + }, + }, + ) + assert response.output[0].content[0].text == "fallback" + assert fallback.calls.last.request.headers["Authorization"] == "Bearer sk-example-fallback" + assert "ChatGPT-Account-Id" not in fallback.calls.last.request.headers + + +@pytest.mark.parametrize("endpoint", ["chat", "responses"]) +@pytest.mark.parametrize("async_call", [False, True]) +@pytest.mark.parametrize("with_prompt", [False, True]) +@pytest.mark.asyncio +async def test_sdk_extra_headers_use_client_login_without_gateway_auth( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch, endpoint: str, async_call: bool, with_prompt: bool +) -> None: + blocked: Final = tmp_path / "blocked" + blocked.write_text("ordinary file") + monkeypatch.setenv("CHATGPT_TOKEN_DIR", str(blocked / "unused")) + monkeypatch.delenv("CHATGPT_AUTH_FILE", raising=False) + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + headers: Final = {"Authorization": f"Bearer {_client_token('acct-client-a')}"} + prompt_params: Final = {"prompt_id": "sdk-client"} if with_prompt else {} + if with_prompt: + monkeypatch.setattr( + litellm, + "callbacks", + [ + DotpromptManager( + prompt_id="sdk-client", + prompt_data={"content": "Hello", "metadata": {"model": "chatgpt/gpt-6-luna"}}, + ) + ], + ) + with respx.mock as transport: + transport.post("https://chatgpt.com/backend-api/codex/responses").mock(side_effect=_subscription_response) + if endpoint == "chat": + params: Final = { + "model": "chatgpt/gpt-6.1-sol", + "messages": [{"role": "user", "content": "Hello"}], + "extra_headers": headers, + **prompt_params, + } + result: Final = await litellm.acompletion(**params) if async_call else litellm.completion(**params) + assert result.choices[0].message.content == "acct-client-a" + else: + response: Final = ( + await litellm.aresponses( + model="chatgpt/gpt-6.1-sol", input="Hello", extra_headers=headers, **prompt_params + ) + if async_call + else litellm.responses( + model="chatgpt/gpt-6.1-sol", input="Hello", extra_headers=headers, **prompt_params + ) + ) + assert response.output[0].content[0].text == "acct-client-a" + assert transport.calls.last.request.headers["Authorization"] == headers["Authorization"] + assert len(transport.calls) == 1 + + +@pytest.mark.parametrize("endpoint", ["chat", "responses"]) +@pytest.mark.parametrize("sync", [False, True]) +@pytest.mark.parametrize("credential_source", ["default", "file", "api_key"]) +@pytest.mark.parametrize("authorization_header", [None, "Authorization", "authorization"]) +@pytest.mark.asyncio +async def test_requests_preserve_gateway_token_and_selected_workspace( + tmp_path: Path, + monkeypatch: pytest.MonkeyPatch, + endpoint: str, + sync: bool, + credential_source: str, + authorization_header: str | None, +) -> None: + monkeypatch.setattr("time.time", lambda: 1700000000) + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + monkeypatch.setenv("CHATGPT_AUTH_FILE", str(tmp_path / "default.json")) + token: Final = _client_token("acct-token-default") + auth_file: Final = tmp_path / ("selected.json" if credential_source == "file" else "default.json") + _write_auth_record(auth_file, token, "acct-saved-workspace") + configured_token: Final = _client_token("acct-configured") + expected_token: Final = configured_token if credential_source == "api_key" else token + expected_account: Final = "acct-configured" if credential_source == "api_key" else "acct-saved-workspace" + + def reply(request: httpx.Request) -> httpx.Response: + assert request.headers.get_list("authorization") == [f"Bearer {expected_token}"] + assert request.headers.get_list("chatgpt-account-id") == [expected_account] + assert request.headers["originator"] == "codex_cli_rs" + return _subscription_response( + httpx.Request( + "POST", + request.url, + content=request.content, + headers={ + "Authorization": f"Bearer token-{expected_account.removeprefix('acct-')}", + "ChatGPT-Account-Id": expected_account, + }, + ) + ) + + params: Final = MappingProxyType( + { + "model": "chatgpt/gpt-6.1-sol", + **({"chatgpt_auth_file": str(auth_file)} if credential_source == "file" else {}), + **({"api_key": configured_token} if credential_source == "api_key" else {}), + "extra_headers": { + "originator": "codex_cli_rs", + **({authorization_header: "Bearer sk-unrelated-example"} if authorization_header else {}), + }, + } + ) + with respx.mock as transport: + transport.post("https://chatgpt.com/backend-api/codex/responses").mock(side_effect=reply) + if endpoint == "chat": + result: Final = ( + await asyncio.to_thread(litellm.completion, **params, messages=[{"role": "user", "content": "Hello"}]) + if sync + else await litellm.acompletion(**params, messages=[{"role": "user", "content": "Hello"}]) + ) + assert result.choices[0].message.content == expected_account + else: + response: Final = ( + await asyncio.to_thread(litellm.responses, **params, input=[{"role": "user", "content": "Hello"}]) + if sync + else await litellm.aresponses(**params, input=[{"role": "user", "content": "Hello"}]) + ) + assert response.output[0].content[0].text == expected_account diff --git a/tests/unit/llms/chatgpt/responses/test_chatgpt_responses_transformation.py b/tests/unit/llms/chatgpt/responses/test_chatgpt_responses_transformation.py index e47d7fc702c..d88bdfc0b41 100644 --- a/tests/unit/llms/chatgpt/responses/test_chatgpt_responses_transformation.py +++ b/tests/unit/llms/chatgpt/responses/test_chatgpt_responses_transformation.py @@ -4,8 +4,10 @@ Tests for ChatGPT subscription Responses API transformation Source: litellm/llms/chatgpt/responses/transformation.py """ +import base64 import json from collections.abc import Generator +from pathlib import Path from typing import Final from unittest.mock import MagicMock, patch @@ -13,6 +15,7 @@ import httpx import pytest import litellm +from litellm.llms.chatgpt.authenticator import Authenticator from litellm.llms.chatgpt.responses.transformation import ChatGPTResponsesAPIConfig from litellm.llms.openai.common_utils import OpenAIError from litellm.main import responses_api_bridge_check @@ -395,3 +398,165 @@ class TestChatGPTResponsesAPITransformation: assert exc_info.value.message == "ChatGPT upstream failed" assert exc_info.value.status_code == 502 + + +def _fake_chatgpt_oauth_token(account_id: str) -> str: + header = base64.urlsafe_b64encode(b'{"alg":"RS256"}').rstrip(b"=").decode() + payload = ( + base64.urlsafe_b64encode( + json.dumps({"https://api.openai.com/auth": {"chatgpt_account_id": account_id}}).encode() + ) + .rstrip(b"=") + .decode() + ) + return f"{header}.{payload}.fake-signature" + + +def _gateway_authenticator() -> MagicMock: + authenticator = MagicMock() + authenticator.get_access_token.return_value = "gateway-access-token" + authenticator.get_account_id.return_value = "acct-gateway" + return authenticator + + +def _config_with(authenticator: MagicMock) -> ChatGPTResponsesAPIConfig: + return ChatGPTResponsesAPIConfig(authenticator=authenticator) + + +class TestChatGPTClientCredentialForwarding: + def test_client_chatgpt_oauth_wins_over_configured_key_and_gateway_login(self): + authenticator = _gateway_authenticator() + token = _fake_chatgpt_oauth_token("acct-alice") + + headers = _config_with(authenticator).validate_environment( + headers={"Authorization": f"Bearer {token}", "originator": "codex_cli_rs"}, + model="gpt-5.4", + litellm_params=GenericLiteLLMParams(api_key="configured-gateway-key", litellm_session_id="session-1"), + ) + + assert headers["Authorization"] == f"Bearer {token}" + assert headers["ChatGPT-Account-Id"] == "acct-alice" + assert headers["originator"] == "codex_cli_rs" + assert headers["accept"] == "text/event-stream" + assert [name for name in headers if name.lower() == "authorization"] == ["Authorization"] + authenticator.get_access_token.assert_not_called() + + def test_explicit_account_header_wins_over_jwt_claim(self): + token = _fake_chatgpt_oauth_token("acct-from-jwt") + + headers = _config_with(_gateway_authenticator()).validate_environment( + headers={"authorization": f"Bearer {token}", "chatgpt-account-id": "acct-from-header"}, + model="gpt-5.4", + litellm_params=GenericLiteLLMParams(), + ) + + assert headers["ChatGPT-Account-Id"] == "acct-from-header" + assert [name for name in headers if name.lower() == "chatgpt-account-id"] == ["ChatGPT-Account-Id"] + + @pytest.mark.parametrize( + "bearer", ["Bearer sk-proj-fake-platform-key", "Bearer not-a-jwt", "Bearer a.bm90LWpzb24.c"] + ) + def test_non_chatgpt_bearer_falls_back_to_configured_key(self, bearer, tmp_path): + authenticator = Authenticator(auth_file=str(tmp_path / "missing-default.json")) + + headers = ChatGPTResponsesAPIConfig(authenticator=authenticator).validate_environment( + headers={"Authorization": bearer}, + model="gpt-5.4", + litellm_params=GenericLiteLLMParams(api_key="configured-gateway-key"), + ) + + assert "ChatGPT-Account-Id" not in headers + assert headers["Authorization"] == "Bearer configured-gateway-key" + + def test_configured_key_is_used_without_client_credential(self): + authenticator = _gateway_authenticator() + + headers = _config_with(authenticator).validate_environment( + headers={}, + model="gpt-5.4", + litellm_params=GenericLiteLLMParams(api_key="configured-gateway-key"), + ) + + assert headers["Authorization"] == "Bearer configured-gateway-key" + authenticator.get_access_token.assert_not_called() + + def test_gateway_login_is_used_without_client_credential_or_configured_key(self): + headers = _config_with(_gateway_authenticator()).validate_environment( + headers={}, + model="gpt-5.4", + litellm_params=GenericLiteLLMParams(), + ) + + assert headers["Authorization"] == "Bearer gateway-access-token" + assert headers["ChatGPT-Account-Id"] == "acct-gateway" + + def test_two_clients_never_share_a_credential(self): + config = _config_with(_gateway_authenticator()) + alice = _fake_chatgpt_oauth_token("acct-alice") + bob = _fake_chatgpt_oauth_token("acct-bob") + + forwarded = [ + config.validate_environment( + headers={"Authorization": f"Bearer {token}"}, model="gpt-5.4", litellm_params=GenericLiteLLMParams() + ) + for token in (alice, bob, alice) + ] + + assert [h["Authorization"] for h in forwarded] == [f"Bearer {alice}", f"Bearer {bob}", f"Bearer {alice}"] + assert [h["ChatGPT-Account-Id"] for h in forwarded] == ["acct-alice", "acct-bob", "acct-alice"] + + +class TestChatGPTResponsesMultiAccount: + @pytest.fixture(autouse=True) + def fixed_clock(self, monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setattr("time.time", lambda: 1700000000) + + @staticmethod + def _write_auth_record(path: Path, token: str, account_id: str) -> None: + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text( + json.dumps( + { + "access_token": token, + "account_id": account_id, + "expires_at": 4102444800, + } + ) + ) + + def test_validate_environment_uses_per_model_auth_file( + self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch + ) -> None: + default_dir: Final = tmp_path / "default" + monkeypatch.setenv("CHATGPT_TOKEN_DIR", str(default_dir)) + monkeypatch.delenv("CHATGPT_AUTH_FILE", raising=False) + self._write_auth_record(default_dir / "auth.json", "token-default", "acct-default") + file_a: Final = tmp_path / "account-a" / "auth.json" + file_b: Final = tmp_path / "account-b" / "auth.json" + self._write_auth_record(file_a, "token-a", "acct-a") + self._write_auth_record(file_b, "token-b", "acct-b") + + config: Final = ChatGPTResponsesAPIConfig() + + headers_a: Final = config.validate_environment( + headers={}, + model="gpt-6.1-sol", + litellm_params=GenericLiteLLMParams(chatgpt_auth_file=str(file_a)), + ) + headers_b: Final = config.validate_environment( + headers={}, + model="gpt-6.1-sol", + litellm_params=GenericLiteLLMParams(chatgpt_auth_file=str(file_b)), + ) + headers_default: Final = config.validate_environment( + headers={}, + model="gpt-6.1-sol", + litellm_params=GenericLiteLLMParams(), + ) + + assert headers_a["Authorization"] == "Bearer token-a" + assert headers_a["ChatGPT-Account-Id"] == "acct-a" + assert headers_b["Authorization"] == "Bearer token-b" + assert headers_b["ChatGPT-Account-Id"] == "acct-b" + assert headers_default["Authorization"] == "Bearer token-default" + assert headers_default["ChatGPT-Account-Id"] == "acct-default" diff --git a/tests/unit/llms/chatgpt/test_chatgpt_authenticator.py b/tests/unit/llms/chatgpt/test_chatgpt_authenticator.py index 43a4c26b6d2..2e9e3462bee 100644 --- a/tests/unit/llms/chatgpt/test_chatgpt_authenticator.py +++ b/tests/unit/llms/chatgpt/test_chatgpt_authenticator.py @@ -2,17 +2,24 @@ import base64 import json import time from concurrent.futures import ThreadPoolExecutor +from pathlib import Path +from typing import Final from unittest.mock import MagicMock, mock_open, patch import pytest +import httpx +import respx import litellm from litellm.constants import DEFAULT_REQUEST_TIMEOUT_SECONDS, HTTP_HANDLER_CONNECT_TIMEOUT_SECONDS from litellm.llms.chatgpt.authenticator import ( TOKEN_REFRESH_TIMEOUT_SECONDS, Authenticator, + get_cached_authenticator, + get_chatgpt_auth_file, ) from litellm.llms.chatgpt.common_utils import GetAccessTokenError +from litellm.types.router import GenericLiteLLMParams def _make_jwt(payload: dict) -> str: @@ -161,3 +168,144 @@ class TestChatGPTAuthenticator: assert account_id == "acct-123" mock_write.assert_called_once() assert mock_write.call_args[0][0]["account_id"] == "acct-123" + + def test_get_account_id_prefers_stored_value_without_rewriting_file(self, authenticator): + id_token = _make_jwt({"https://api.openai.com/auth": {"chatgpt_account_id": "acct-from-token"}}) + auth_data = json.dumps({"account_id": "acct-stored", "id_token": id_token}) + + with ( + patch("builtins.open", mock_open(read_data=auth_data)), + patch.object(authenticator, "_write_auth_file") as mock_write, + ): + assert authenticator.get_account_id() == "acct-stored" + mock_write.assert_not_called() + + def test_get_account_id_without_login_returns_none(self, authenticator): + with ( + patch("builtins.open", mock_open(read_data="{}")), + patch.object(authenticator, "_write_auth_file") as mock_write, + ): + assert authenticator.get_account_id() is None + mock_write.assert_not_called() + + +def _write_auth_record(path: Path, token: str, account_id: str) -> None: + path.write_text( + json.dumps( + { + "access_token": token, + "account_id": account_id, + "expires_at": 4102444800, + } + ) + ) + + +class TestChatGPTMultiAccountAuthenticator: + @pytest.fixture(autouse=True) + def fixed_clock(self, monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setattr("time.time", lambda: 1700000000) + + def test_explicit_auth_file_overrides_env(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("CHATGPT_TOKEN_DIR", str(tmp_path / "env-dir")) + monkeypatch.setenv("CHATGPT_AUTH_FILE", "env.json") + custom_file: Final = tmp_path / "account-a" / "auth.json" + + authenticator: Final = Authenticator(auth_file=str(custom_file)) + + assert authenticator.auth_file == str(custom_file) + assert authenticator.token_dir == str(custom_file.parent) + assert not custom_file.parent.exists() + authenticator._write_auth_file({"access_token": "token-a"}) + assert json.loads(custom_file.read_text())["access_token"] == "token-a" + + def test_default_auth_file_from_env(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("CHATGPT_TOKEN_DIR", str(tmp_path / "env-dir")) + monkeypatch.setenv("CHATGPT_AUTH_FILE", "env.json") + + authenticator: Final = Authenticator() + + assert authenticator.auth_file == str(tmp_path / "env-dir" / "env.json") + + def test_bare_filename_auth_file_resolves_against_cwd( + self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch + ) -> None: + monkeypatch.chdir(tmp_path) + + authenticator: Final = Authenticator(auth_file="auth.json") + + assert authenticator.auth_file == str(tmp_path / "auth.json") + assert authenticator.token_dir == str(tmp_path) + + def test_two_auth_files_are_isolated(self, tmp_path: Path) -> None: + file_a: Final = tmp_path / "account-a.json" + file_b: Final = tmp_path / "account-b.json" + _write_auth_record(file_a, "token-a", "acct-a") + _write_auth_record(file_b, "token-b", "acct-b") + + authenticator_a: Final = Authenticator(auth_file=str(file_a)) + authenticator_b: Final = Authenticator(auth_file=str(file_b)) + + assert authenticator_a.get_access_token() == "token-a" + assert authenticator_a.get_account_id() == "acct-a" + assert authenticator_b.get_access_token() == "token-b" + assert authenticator_b.get_account_id() == "acct-b" + + def test_get_cached_authenticator_reuses_instance_per_path(self, tmp_path: Path) -> None: + file_a: Final = tmp_path / "account-a.json" + file_b: Final = tmp_path / "account-b.json" + + authenticator_a: Final = get_cached_authenticator(str(file_a)) + + assert get_cached_authenticator(str(file_a)) is authenticator_a + assert get_cached_authenticator(str(file_b)) is not authenticator_a + + def test_get_chatgpt_auth_file(self) -> None: + assert get_chatgpt_auth_file(None) is None + assert get_chatgpt_auth_file({}) is None + assert get_chatgpt_auth_file({"chatgpt_auth_file": ""}) is None + assert get_chatgpt_auth_file({"chatgpt_auth_file": "/a/auth.json"}) == "/a/auth.json" + assert get_chatgpt_auth_file(GenericLiteLLMParams()) is None + assert get_chatgpt_auth_file(GenericLiteLLMParams(chatgpt_auth_file="/b/auth.json")) == "/b/auth.json" + + def test_relative_and_absolute_auth_file_share_cached_authenticator( + self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch + ) -> None: + monkeypatch.chdir(tmp_path) + get_cached_authenticator.cache_clear() + auth_file: Final = tmp_path / "x" / "auth.json" + auth_file.parent.mkdir(parents=True) + auth_file.write_text("{}") + + relative_key: Final = get_chatgpt_auth_file({"chatgpt_auth_file": "x/auth.json"}) + absolute_key: Final = get_chatgpt_auth_file({"chatgpt_auth_file": str(auth_file)}) + assert relative_key is not None and absolute_key is not None + + assert get_cached_authenticator(relative_key) is get_cached_authenticator(absolute_key) + + +def test_refresh_keeps_saved_workspace(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setattr("time.time", lambda: 1700000000) + auth_file: Final = tmp_path / "selected.json" + auth_file.write_text( + json.dumps( + { + "access_token": "expired-example-token", + "refresh_token": "example-refresh-token", + "expires_at": 1, + "account_id": "acct-selected-workspace", + } + ) + ) + token: Final = _make_jwt({"exp": 4102444800, "https://api.openai.com/auth": {"chatgpt_account_id": "acct-default"}}) + authenticator: Final = Authenticator(auth_file=str(auth_file)) + with respx.mock as transport: + transport.post("https://auth.openai.com/oauth/token").mock( + return_value=httpx.Response( + 200, + json={"access_token": token, "id_token": token, "refresh_token": "example-rotated-refresh"}, + ) + ) + assert authenticator.get_access_token() == token + assert authenticator.get_account_id(token) == "acct-selected-workspace" + assert json.loads(auth_file.read_text())["refresh_token"] == "example-rotated-refresh" diff --git a/tests/unit/llms/chatgpt/test_chatgpt_common_utils.py b/tests/unit/llms/chatgpt/test_chatgpt_common_utils.py new file mode 100644 index 00000000000..6b280d97089 --- /dev/null +++ b/tests/unit/llms/chatgpt/test_chatgpt_common_utils.py @@ -0,0 +1,90 @@ +import base64 +import json + +import pytest + +from litellm.llms.chatgpt.common_utils import ( + extract_chatgpt_account_id, + get_chatgpt_client_credential, + is_chatgpt_oauth_key, + select_chatgpt_client_credential_headers, +) + + +def _make_jwt(payload: dict) -> str: + def _b64(obj: dict) -> str: + raw = json.dumps(obj, separators=(",", ":")).encode("utf-8") + return base64.urlsafe_b64encode(raw).decode("utf-8").rstrip("=") + + return f"{_b64({'alg': 'none', 'typ': 'JWT'})}.{_b64(payload)}." + + +CHATGPT_JWT = _make_jwt({"https://api.openai.com/auth": {"chatgpt_account_id": "acct-alice"}}) +CHATGPT_JWT_WITHOUT_ACCOUNT = _make_jwt({"https://api.openai.com/auth": {"user_id": "user-1"}}) +NON_CHATGPT_JWT = _make_jwt({"sub": "someone", "https://api.openai.com/auth": "not-an-object"}) + + +class TestExtractChatGPTAccountId: + def test_reads_account_id_from_auth_claim(self): + assert extract_chatgpt_account_id(CHATGPT_JWT) == "acct-alice" + + @pytest.mark.parametrize( + "token", + [None, "", "sk-proj-not-a-jwt", "header.only", NON_CHATGPT_JWT, CHATGPT_JWT_WITHOUT_ACCOUNT], + ) + def test_returns_none_without_a_usable_account_claim(self, token): + assert extract_chatgpt_account_id(token) is None + + +class TestIsChatGPTOAuthKey: + def test_recognizes_bearer_and_raw_chatgpt_jwt(self): + assert is_chatgpt_oauth_key(CHATGPT_JWT) + assert is_chatgpt_oauth_key(f"Bearer {CHATGPT_JWT}") + assert is_chatgpt_oauth_key(f"Bearer {CHATGPT_JWT_WITHOUT_ACCOUNT}") + + @pytest.mark.parametrize( + "value", [None, "", "Bearer sk-proj-platform-key", "Bearer not.a.jwt", _make_jwt({"sub": "x"})] + ) + def test_rejects_non_chatgpt_credentials(self, value): + assert not is_chatgpt_oauth_key(value) + + +class TestSelectChatGPTClientCredentialHeaders: + def test_account_header_alone_is_not_forwarded(self): + selected = select_chatgpt_client_credential_headers( + {"chatgpt-account-id": "acct-alice", "authorization": "Bearer sk-proj-platform-key"} + ) + assert dict(selected) == {} + assert get_chatgpt_client_credential({"chatgpt-account-id": "acct-alice"}) is None + + def test_forwards_only_bearer_and_account_context(self): + selected = select_chatgpt_client_credential_headers( + { + "Authorization": f"Bearer {CHATGPT_JWT}", + "ChatGPT-Account-Id": "acct-explicit", + "x-litellm-api-key": "sk-gateway", + "user-agent": "codex", + } + ) + assert dict(selected) == {"Authorization": f"Bearer {CHATGPT_JWT}", "ChatGPT-Account-Id": "acct-explicit"} + credential = get_chatgpt_client_credential(selected) + assert credential is not None + assert credential.access_token == CHATGPT_JWT + assert credential.account_id == "acct-explicit" + + def test_account_id_falls_back_to_jwt_claim(self): + credential = get_chatgpt_client_credential({"authorization": f"Bearer {CHATGPT_JWT}"}) + assert credential is not None + assert credential.account_id == "acct-alice" + + +@pytest.mark.parametrize("scheme", ["Bearer", "bearer", "BEARER"]) +def test_bearer_scheme_is_case_insensitive(scheme): + credential = get_chatgpt_client_credential({"authorization": f"{scheme} {CHATGPT_JWT}"}) + assert credential is not None + assert credential.access_token == CHATGPT_JWT + assert credential.account_id == "acct-alice" + + +def test_other_authentication_schemes_are_not_chatgpt_logins(): + assert not is_chatgpt_oauth_key(f"Basic {CHATGPT_JWT}") diff --git a/tests/unit/llms/compactifai/test_compactifai.py b/tests/unit/llms/compactifai/test_compactifai.py index 1367c703fda..56d5374f383 100644 --- a/tests/unit/llms/compactifai/test_compactifai.py +++ b/tests/unit/llms/compactifai/test_compactifai.py @@ -2,7 +2,7 @@ import json import os import sys from unittest.mock import AsyncMock, patch -from typing import Optional +from typing import Final, Optional import httpx import pytest @@ -271,3 +271,38 @@ async def test_compactifai_async_completion(respx_mock): assert response.choices[0].message.content == "Async response from CompactifAI" assert response.usage.total_tokens == 23 + + +@pytest.mark.parametrize( + ("body", "json_mode", "error", "message"), + [ + ([], None, TypeError, r"argument after \*\* must be a mapping, not list"), + ({"choices": None}, True, TypeError, "'NoneType' object is not iterable"), + ({"choices": [{"message": "hi"}]}, True, AttributeError, "'str' object has no attribute 'get'"), + ({"choices": [{"message": {"tool_calls": [5]}}]}, True, TypeError, "'int' object is not subscriptable"), + ], +) +def test_compactifai_malformed_response_body_raises_the_error_of_the_failing_lookup(body, json_mode, error, message): + from unittest.mock import MagicMock + + from litellm.llms.compactifai.chat.transformation import CompactifAIChatConfig + + raw_response: Final = httpx.Response( + 200, json=body, request=httpx.Request("POST", "https://api.compactif.ai/v1/chat/completions") + ) + + with pytest.raises(error, match=message) as raised: + CompactifAIChatConfig().transform_response( + model="cai-llama-3-1-8b-slim", + raw_response=raw_response, + model_response=ModelResponse(), + logging_obj=MagicMock(), + request_data={}, + messages=[], + optional_params={}, + litellm_params={}, + encoding=None, + json_mode=json_mode, + ) + + assert raised.type is error diff --git a/tests/unit/llms/custom_httpx/test_aiohttp_transport.py b/tests/unit/llms/custom_httpx/test_aiohttp_transport.py index 0765371dc4a..c7d5518ef5b 100644 --- a/tests/unit/llms/custom_httpx/test_aiohttp_transport.py +++ b/tests/unit/llms/custom_httpx/test_aiohttp_transport.py @@ -1,8 +1,10 @@ import aiohttp as aiohttp_aiohttp_handler, asyncio, importlib, litellm import concurrent.futures +import gc import socket import sys import struct +import threading from typing import Final import aiohttp @@ -1310,3 +1312,74 @@ async def test_reset_after_request_is_not_replayed(monkeypatch: pytest.MonkeyPat assert len(received_requests) == 1 finally: await handler.close() + + +async def _new_session() -> aiohttp.ClientSession: + return aiohttp.ClientSession() + + +async def _until_closed(session: aiohttp.ClientSession) -> None: + while not session.closed: + await asyncio.sleep(0) + + +@pytest.mark.asyncio +async def test_a_collected_transport_closes_the_session_it_owns(): + """An SDK client evicted from the cache is collected long before the closer's grace window ends.""" + session = aiohttp.ClientSession() + transport = LiteLLMAiohttpTransport(client=session) + + del transport + gc.collect() + await asyncio.gather(*LiteLLMAiohttpTransport._background_close_tasks) + + assert session.closed, "the owned session outlived the transport that was collected before closing it" + + +@pytest.mark.asyncio +async def test_a_collected_transport_leaves_a_shared_session_open(): + session = aiohttp.ClientSession() + try: + transport = LiteLLMAiohttpTransport(client=session, owns_session=False) + + del transport + gc.collect() + await asyncio.gather(*LiteLLMAiohttpTransport._background_close_tasks) + + assert not session.closed, "a transport closed a session it does not own" + finally: + await session.close() + + +def test_a_transport_collected_after_its_loop_closed_still_closes_its_session(caplog: pytest.LogCaptureFixture): + """asyncio.run() closes the loop the session lives on before the evicted client is collected.""" + loop = asyncio.new_event_loop() + session = loop.run_until_complete(_new_session()) + loop.close() + transport = LiteLLMAiohttpTransport(client=session) + + del transport + gc.collect() + + assert session.closed, "the owned session stayed open after its transport was collected on a closed loop" + del session + gc.collect() + assert "Unclosed client session" not in caplog.text, caplog.text + + +def test_a_transport_collected_while_its_loop_runs_elsewhere_closes_its_session_on_that_loop(): + loop = asyncio.new_event_loop() + thread = threading.Thread(target=loop.run_forever, daemon=True) + thread.start() + session = asyncio.run_coroutine_threadsafe(_new_session(), loop).result(timeout=10) + transport = LiteLLMAiohttpTransport(client=session) + try: + del transport + gc.collect() + asyncio.run_coroutine_threadsafe(_until_closed(session), loop).result(timeout=10) + + assert session.closed, "the owned session stayed open after its transport was collected from another thread" + finally: + loop.call_soon_threadsafe(loop.stop) + thread.join(timeout=10) + loop.close() diff --git a/tests/unit/llms/custom_httpx/test_http_handler.py b/tests/unit/llms/custom_httpx/test_http_handler.py index bd4ed4c99cc..1607447f7bf 100644 --- a/tests/unit/llms/custom_httpx/test_http_handler.py +++ b/tests/unit/llms/custom_httpx/test_http_handler.py @@ -2172,3 +2172,86 @@ async def test_async_ollama_ssl_verify_false_builds_a_client_that_skips_certific assert route.call_count == 1 assert text == "Sunny" assert _cached_clients_verify_modes(client_cache, AsyncHTTPHandler) == (ssl.CERT_NONE,) + + +_TIMEOUT_CLIENT_LIMITS: Final = httpx.Timeout(42.0, connect=7.0) +_TIMEOUT_PHASES: Final = ( + (httpx.ConnectTimeout, "Connection timed out", "Timeout passed=7.0"), + (httpx.ReadTimeout, "Read timed out", "Timeout passed=42.0"), + (httpx.WriteTimeout, "Write timed out", "Timeout passed=42.0"), + (httpx.PoolTimeout, "Connection pool timed out", "Timeout passed=42.0"), +) + + +def _timing_out(kind: type[httpx.TimeoutException]) -> httpx.MockTransport: + def _raise(request: httpx.Request) -> httpx.Response: + raise kind("simulated", request=request) + + return httpx.MockTransport(_raise) + + +@pytest.mark.parametrize("verb", ["post", "put", "patch", "delete"]) +@pytest.mark.parametrize(("kind", "label", "limit"), _TIMEOUT_PHASES) +def test_sync_timeout_without_a_per_call_timeout_names_the_phase_and_the_limit_that_fired( + verb: str, kind: type[httpx.TimeoutException], label: str, limit: str +) -> None: + """Issue #14635: the handler used to print the caller's absent argument as 'after None seconds'.""" + handler: Final = HTTPHandler() + handler.client.close() + handler.client = httpx.Client(transport=_timing_out(kind), timeout=_TIMEOUT_CLIENT_LIMITS) + try: + with pytest.raises(LitellmTimeout) as raised: + getattr(handler, verb)("https://example.com/v1/embeddings", json={"input": "hi"}) + finally: + handler.close() + + message: Final = str(raised.value) + assert label in message, message + assert limit in message, message + assert "None" not in message, message + + +@pytest.mark.parametrize("verb", ["post", "put", "patch"]) +@pytest.mark.parametrize(("kind", "label", "limit"), _TIMEOUT_PHASES) +async def test_async_timeout_without_a_per_call_timeout_names_the_phase_and_the_limit_that_fired( + verb: str, kind: type[httpx.TimeoutException], label: str, limit: str +) -> None: + handler: Final = AsyncHTTPHandler(timeout=_TIMEOUT_CLIENT_LIMITS) + await handler.client.aclose() + handler.client = httpx.AsyncClient(transport=_timing_out(kind), timeout=_TIMEOUT_CLIENT_LIMITS) + try: + with pytest.raises(LitellmTimeout) as raised: + await getattr(handler, verb)("https://example.com/v1/embeddings", json={"input": "hi"}) + finally: + await handler.close() + + message: Final = str(raised.value) + assert label in message, message + assert limit in message, message + assert "None" not in message, message + + +def test_sync_timeout_reports_the_per_call_timeout_as_a_float_when_one_is_given() -> None: + handler: Final = HTTPHandler() + handler.client.close() + handler.client = httpx.Client(transport=_timing_out(httpx.ReadTimeout), timeout=_TIMEOUT_CLIENT_LIMITS) + try: + with pytest.raises(LitellmTimeout) as raised: + handler.post("https://example.com/v1/embeddings", json={"input": "hi"}, timeout=30) + finally: + handler.close() + + assert "Read timed out. Timeout passed=30.0, time taken=" in str(raised.value), str(raised.value) + + +async def test_async_timeout_reports_the_per_call_timeout_as_a_float_when_one_is_given() -> None: + handler: Final = AsyncHTTPHandler(timeout=_TIMEOUT_CLIENT_LIMITS) + await handler.client.aclose() + handler.client = httpx.AsyncClient(transport=_timing_out(httpx.ReadTimeout), timeout=_TIMEOUT_CLIENT_LIMITS) + try: + with pytest.raises(LitellmTimeout) as raised: + await handler.post("https://example.com/v1/embeddings", json={"input": "hi"}, timeout=30) + finally: + await handler.close() + + assert "Read timed out. Timeout passed=30.0, time taken=" in str(raised.value), str(raised.value) diff --git a/tests/unit/llms/custom_httpx/test_llm_http_handler.py b/tests/unit/llms/custom_httpx/test_llm_http_handler.py index 8b32ab2e6b8..297e64629a8 100644 --- a/tests/unit/llms/custom_httpx/test_llm_http_handler.py +++ b/tests/unit/llms/custom_httpx/test_llm_http_handler.py @@ -24,6 +24,7 @@ from litellm.integrations.code_interpreter_interception.handler import ( from litellm.integrations.custom_logger import CustomLogger from litellm.integrations.websearch_interception.handler import WebSearchInterceptionLogger from litellm.llms.azure.responses.transformation import AzureOpenAIResponsesAPIConfig +from litellm.llms.azure.vector_stores.transformation import AzureOpenAIVectorStoreConfig from litellm.llms.base_llm.audio_transcription.transformation import ( AudioTranscriptionRequestData, BaseAudioTranscriptionConfig, @@ -48,7 +49,7 @@ from litellm.llms.custom_httpx.llm_http_handler import ( _rust_responses_websocket_enabled, ) from litellm.llms.azure.videos.transformation import AzureVideoConfig -from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude3_transformation import ( +from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeMessagesConfig, ) from litellm.llms.bedrock.files.transformation import BedrockFilesConfig @@ -978,7 +979,7 @@ async def test_async_anthropic_messages_handler_streaming_forwards_provider_resp """ from collections.abc import AsyncIterator as ABCAsyncIterator - from litellm.llms.anthropic.pass_through.messages.transformation import ( + from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) @@ -1041,10 +1042,10 @@ async def test_async_anthropic_messages_handler_agentic_streaming_forwards_provi from collections.abc import AsyncIterator as ABCAsyncIterator from litellm.integrations.custom_logger import CustomLogger - from litellm.llms.anthropic.pass_through.messages.agentic_streaming_iterator import ( + from litellm.llms.anthropic.messages.native.agentic_streaming_iterator import ( AgenticAnthropicStreamingIterator, ) - from litellm.llms.anthropic.pass_through.messages.transformation import ( + from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) @@ -1112,7 +1113,7 @@ async def test_anthropic_messages_streaming_response_aclose_closes_upstream_stre the upstream stream so provider connections are released on client disconnect instead of lingering until garbage collection. """ - from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( + from litellm.llms.anthropic.messages.native.streaming_iterator import ( AnthropicMessagesStreamingResponse, ) @@ -1144,10 +1145,10 @@ async def test_anthropic_messages_streaming_response_aclose_closes_upstream_stre @pytest.mark.asyncio async def test_anthropic_messages_streaming_response_aclose_closes_agentic_upstream_stream(): - from litellm.llms.anthropic.pass_through.messages.agentic_streaming_iterator import ( + from litellm.llms.anthropic.messages.native.agentic_streaming_iterator import ( AgenticAnthropicStreamingIterator, ) - from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( + from litellm.llms.anthropic.messages.native.streaming_iterator import ( AnthropicMessagesStreamingResponse, ) @@ -2095,7 +2096,7 @@ async def test_anthropic_post_skips_the_thinking_strip_retry_when_block_binding_ ) -> None: """A caller that pinned ``prefix_mismatch_behavior: error`` asked for the 400, so the handler must surface it instead of stripping the bound blocks and retrying.""" - from litellm.llms.anthropic.pass_through.messages.transformation import AnthropicMessagesConfig + from litellm.llms.anthropic.messages.native.transformation import AnthropicMessagesConfig handler = BaseLLMHTTPHandler() thinking_block = {"type": "thinking", "thinking": "", "signature": "sig"} @@ -3172,7 +3173,7 @@ async def test_anthropic_invalid_thinking_signature_retry_resigns_bedrock_reques """Regression: after Bedrock rejects a replayed thinking block (400 invalid signature), the strip-and-retry re-sign must not inherit attempt 1's SigV4 Authorization/X-Amz-Date; reusing them over the new stripped body makes AWS return 403 SignatureDoesNotMatch.""" - from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude3_transformation import ( + from litellm.llms.bedrock.messages.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeMessagesConfig, ) @@ -5624,3 +5625,73 @@ async def test_messages_opencode_session_header( "stream": stream, } assert received.empty() + + +def test_vector_store_retrieve_handler_sends_id_before_azure_api_version_query() -> None: + received: Final[list[httpx.Request]] = [] + + def answer(request: httpx.Request) -> httpx.Response: + received.append(request) + return httpx.Response(200, json={"id": "vs_abc", "object": "vector_store"}) + + handler: Final = BaseLLMHTTPHandler() + client: Final = HTTPHandler(client=httpx.Client(transport=httpx.MockTransport(answer))) + + handler.vector_store_retrieve_handler( + vector_store_id="vs_abc", + vector_store_provider_config=AzureOpenAIVectorStoreConfig(), + custom_llm_provider="azure", + litellm_params=GenericLiteLLMParams( + api_base="https://x.openai.azure.com", + api_key="azure-test-key", + api_version="2025-04-01-preview", + ), + logging_obj=Mock(), + client=client, + _is_async=False, + ) + + sent: Final = received[0] + assert str(sent.url) == "https://x.openai.azure.com/openai/vector_stores/vs_abc?api-version=2025-04-01-preview" + assert len(received) == 1 + + +@pytest.mark.asyncio +@pytest.mark.parametrize("is_async", (False, True)) +@pytest.mark.parametrize("provider", ("openai", "azure")) +async def test_non_chatgpt_responses_preserves_caller_headers_after_validation( + is_async: bool, provider: str, respx_mock: respx.MockRouter, +) -> None: + route: Final = respx_mock.post(url__regex=r"https://responses\.example\.com/.*").respond( + 200, + json={ + "id": "resp_headers", "object": "response", "created_at": 1, + "model": "gpt-6-luna", "status": "completed", "output": [], + "parallel_tool_calls": False, "tool_choice": "auto", "tools": [], + }, + ) + client: Final = AsyncHTTPHandler(transport=httpx.AsyncHTTPTransport()) if is_async else HTTPHandler(client=httpx.Client()) + kwargs: Final = { + "model": f"{provider}/gpt-6-luna", + "input": "hello", + "api_key": "fake-configured-key", + "api_base": "https://responses.example.com/v1", + "api_version": "2025-04-01-preview", + "extra_headers": {"Authorization": "Bearer fake-caller-key", "content-type": "application/vnd.example+json"}, + "client": client, + } + try: + response: Final = await litellm.aresponses(**kwargs) if is_async else litellm.responses(**kwargs) + assert response.status == "completed" + assert route.calls[0].request.headers["authorization"] == "Bearer fake-caller-key" + expected_content_types: Final = ( + ["application/json", "application/vnd.example+json"] + if provider == "openai" + else ["application/vnd.example+json"] + ) + assert route.calls[0].request.headers.get_list("content-type") == expected_content_types + finally: + if isinstance(client, AsyncHTTPHandler): + await client.close() + else: + client.client.close() diff --git a/tests/unit/llms/databricks/decisions/test_transformation.py b/tests/unit/llms/databricks/decisions/test_transformation.py index f6ea3444db1..121c952cda9 100644 --- a/tests/unit/llms/databricks/decisions/test_transformation.py +++ b/tests/unit/llms/databricks/decisions/test_transformation.py @@ -1,6 +1,7 @@ from typing import Final import pytest +import responses from litellm.llms.databricks.decisions.transformation import DatabricksDecisionsConfig from litellm.types.decisions import ( @@ -21,6 +22,40 @@ _REQUEST: Final = DecisionsIRRequest( _QUESTIONS: Final = {"is_defect": {"type": "noul", "instructions": "Is this a defect?"}} +@responses.activate +def test_should_resolve_oauth_credentials_without_a_static_key(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("DATABRICKS_CLIENT_ID", "synthetic-client") + monkeypatch.setenv("DATABRICKS_CLIENT_SECRET", "synthetic-secret") + token: Final = responses.post(f"{_HOST}/oidc/v1/token", json={"access_token": "oauth-token", "expires_in": 3600}) + + assert DatabricksDecisionsConfig().resolve_credential(None, _BASE, {}) == "oauth-token" + assert token.call_count == 1 + + +@responses.activate +@pytest.mark.parametrize("key_source", ("argument", "DATABRICKS_API_KEY", "DATABRICKS_TOKEN")) +def test_should_preserve_static_key_precedence(monkeypatch: pytest.MonkeyPatch, key_source: str) -> None: + monkeypatch.setenv("DATABRICKS_CLIENT_ID", "synthetic-client") + monkeypatch.setenv("DATABRICKS_CLIENT_SECRET", "synthetic-secret") + if key_source != "argument": + monkeypatch.setenv(key_source, "static-key") + config: Final = DatabricksDecisionsConfig() + base, key = config.resolve_connection(_BASE, "static-key" if key_source == "argument" else None) + + assert base == _BASE + assert config.resolve_credential(key, _BASE, {}) == "static-key" + assert len(responses.calls) == 0 + + +@pytest.mark.parametrize("missing", ("DATABRICKS_CLIENT_ID", "DATABRICKS_CLIENT_SECRET")) +def test_should_leave_incomplete_oauth_credentials_unresolved(monkeypatch: pytest.MonkeyPatch, missing: str) -> None: + monkeypatch.setenv("DATABRICKS_CLIENT_ID", "synthetic-client") + monkeypatch.setenv("DATABRICKS_CLIENT_SECRET", "synthetic-secret") + monkeypatch.delenv(missing) + + assert DatabricksDecisionsConfig().resolve_credential(None, _BASE, {}) is None + + @pytest.mark.parametrize("api_base", [_BASE, f"{_BASE}/"]) def test_a_serving_endpoint_name_is_called_on_its_invocations_route(api_base: str) -> None: assert _CONFIG.get_complete_url(api_base, "openjev") == f"{_BASE}/openjev/invocations" diff --git a/tests/unit/llms/databricks/test_databricks_common_utils.py b/tests/unit/llms/databricks/test_databricks_common_utils.py index 8f2d87a6d25..58aae2c1056 100644 --- a/tests/unit/llms/databricks/test_databricks_common_utils.py +++ b/tests/unit/llms/databricks/test_databricks_common_utils.py @@ -1,19 +1,21 @@ import json import sys +from functools import partial from types import ModuleType, SimpleNamespace from typing import Final +from unittest.mock import MagicMock, Mock, patch import httpx import pytest +import responses import respx from fastapi.testclient import TestClient -from unittest.mock import MagicMock, patch - import litellm from litellm._version import version +from litellm.caching.in_memory_cache import InMemoryCache from litellm.exceptions import BadRequestError -from litellm.llms.databricks.common_utils import DatabricksBase +from litellm.llms.databricks.common_utils import DatabricksBase, DatabricksException def test_databricks_validate_environment(): @@ -195,3 +197,79 @@ def test_embeddings_uses_databricks_sdk_if_api_key_and_base_not_specified( {"model": "bge-large-en-v1.5", "input": inputs, "extraparam": "testpassingextraparam"}, ) assert response.to_dict() == upstream_response + + +@responses.activate +def test_should_reuse_the_token_until_its_refresh_margin() -> None: + clock: Final = Mock(return_value=1000.0) + get_token: Final = partial( + DatabricksBase().get_cached_oauth_m2m_token, + client_id="synthetic-client", + client_secret="synthetic-secret", + token_cache=InMemoryCache(clock=clock), + ) + responses.post(f"{SDK_HOST}/oidc/v1/token", json={"access_token": "first-token", "expires_in": 3600}) + responses.post(f"{SDK_HOST}/oidc/v1/token", json={"access_token": "refreshed-token", "expires_in": 3600}) + + assert get_token(SDK_HOST) == "first-token" + clock.return_value = 4539.0 + assert get_token(f"{SDK_HOST}/serving-endpoints/") == "first-token" + assert len(responses.calls) == 1 + clock.return_value = 4541.0 + assert get_token(SDK_HOST) == "refreshed-token" + assert len(responses.calls) == 2 + + +@responses.activate +@pytest.mark.parametrize("expires_in", (0, 30, 60)) +def test_should_not_cache_a_token_within_the_refresh_margin(expires_in: int) -> None: + get_token: Final = partial( + DatabricksBase().get_cached_oauth_m2m_token, + SDK_HOST, + "synthetic-client", + "synthetic-secret", + token_cache=InMemoryCache(), + ) + token: Final = responses.post( + f"{SDK_HOST}/oidc/v1/token", json={"access_token": "short-lived-token", "expires_in": expires_in} + ) + + assert get_token() == "short-lived-token" + assert get_token() == "short-lived-token" + assert token.call_count == 2 + + +@responses.activate +@pytest.mark.parametrize("changed", ("workspace", "client_id", "client_secret")) +def test_should_not_reuse_a_token_for_a_different_workspace_or_credentials(changed: str) -> None: + base: Final = DatabricksBase() + cache: Final = InMemoryCache() + responses.post(f"{SDK_HOST}/oidc/v1/token", json={"access_token": "original-token", "expires_in": 3600}) + assert ( + base.get_cached_oauth_m2m_token(SDK_HOST, "synthetic-client", "synthetic-secret", token_cache=cache) + == "original-token" + ) + + next_host: Final = "https://other-workspace.example" if changed == "workspace" else SDK_HOST + client_id: Final = "rotated-client" if changed == "client_id" else "synthetic-client" + client_secret: Final = "rotated-secret" if changed == "client_secret" else "synthetic-secret" + responses.post(f"{next_host}/oidc/v1/token", json={"access_token": "new-token", "expires_in": 3600}) + assert base.get_cached_oauth_m2m_token(next_host, client_id, client_secret, token_cache=cache) == "new-token" + assert len(responses.calls) == 2 + + +@responses.activate +def test_should_propagate_oauth_failure_and_retry_the_next_request() -> None: + get_token: Final = partial( + DatabricksBase().get_cached_oauth_m2m_token, + SDK_HOST, + "synthetic-client", + "synthetic-secret", + token_cache=InMemoryCache(), + ) + responses.post(f"{SDK_HOST}/oidc/v1/token", status=401, json={"error": "invalid_client"}) + responses.post(f"{SDK_HOST}/oidc/v1/token", json={"access_token": "valid-token", "expires_in": 3600}) + + with pytest.raises(DatabricksException, match="OAuth M2M token request failed"): + get_token() + assert get_token() == "valid-token" diff --git a/tests/unit/llms/deepgram/audio_transcription/test_deepgram_audio_transcription_transformation.py b/tests/unit/llms/deepgram/audio_transcription/test_deepgram_audio_transcription_transformation.py index aff90549a7b..0951ba6ba92 100644 --- a/tests/unit/llms/deepgram/audio_transcription/test_deepgram_audio_transcription_transformation.py +++ b/tests/unit/llms/deepgram/audio_transcription/test_deepgram_audio_transcription_transformation.py @@ -1,6 +1,7 @@ import io import os import pathlib +from typing import Final from unittest.mock import MagicMock import httpx @@ -594,3 +595,24 @@ def test_transform_response_wraps_malformed_words_with_the_raw_body(words: objec DeepgramAudioTranscriptionConfig().transform_audio_transcription_response(raw_response) assert str(exc_info.value).endswith(f"\nResponse: {raw_response.text}") + + +@pytest.mark.parametrize( + ("payload", "error"), + [ + ({"results": None}, "'NoneType' object is not subscriptable"), + (_deepgram_payload({"transcript": "hello", "words": 5}, {}), "object of type 'int' has no len()"), + ( + {**_deepgram_payload({"transcript": "hello"}, {}), "metadata": None}, + "'NoneType' object is not subscriptable", + ), + ], +) +def test_transform_response_wraps_the_error_of_the_failing_lookup_in_a_malformed_body(payload: object, error: str): + raw_response: Final = httpx.Response(200, json=payload) + + with pytest.raises(ValueError, match="Error transforming Deepgram response: ") as exc_info: + DeepgramAudioTranscriptionConfig().transform_audio_transcription_response(raw_response) + + assert exc_info.type is ValueError + assert str(exc_info.value) == f"Error transforming Deepgram response: {error}\nResponse: {raw_response.text}" diff --git a/tests/unit/llms/deepseek/chat/test_deepseek_chat_transformation.py b/tests/unit/llms/deepseek/chat/test_deepseek_chat_transformation.py index dd99ad8bf91..3fbb12881da 100644 --- a/tests/unit/llms/deepseek/chat/test_deepseek_chat_transformation.py +++ b/tests/unit/llms/deepseek/chat/test_deepseek_chat_transformation.py @@ -511,6 +511,54 @@ class TestDeepSeekVisionMultimodalContent: assert any(block.get("type") == "image_url" for block in content) +@pytest.mark.usefixtures("_deepseek_httpx_transport") +@pytest.mark.parametrize("stream", (False, True)) +@pytest.mark.parametrize("model", ("deepseek-flash", "deepseek-v4-pro", "deepseek-chat", "deepseek-reasoner")) +@pytest.mark.parametrize("effort", ("minimal", "low", "medium", "high", "xhigh", "max", "ultra")) +@pytest.mark.parametrize("thinking", (None, "enabled")) +@pytest.mark.respx(assert_all_called=True) +async def test_deepseek_forwards_native_effort( + respx_mock: respx.MockRouter, model: str, effort: str, thinking: str | None, stream: bool +) -> None: + route: Final = respx_mock.post(DEEPSEEK_CHAT_COMPLETIONS_URL).mock(return_value=_deepseek_response(stream)) + response: Final = await litellm.acompletion( + model=f"deepseek/{model}", + messages=[{"role": "user", "content": "Hello"}], + api_key=DEEPSEEK_API_KEY, + reasoning_effort=effort, + stream=stream, + **({"thinking": {"type": thinking}} if thinking is not None else {}), + ) + if stream: + async for _ in response: + pass + body: Final = json.loads(route.calls[0].request.content) + assert body["reasoning_effort"] == effort + assert body["thinking"] == {"type": "enabled"} + + +@pytest.mark.parametrize( + "thinking,effort,expected_thinking", + ( + (None, None, None), + (None, "none", "disabled"), + ("enabled", "none", "enabled"), + ("disabled", "max", "disabled"), + ("enabled", None, "enabled"), + (None, "default", "enabled"), + (None, "bogus", "enabled"), + (None, {"effort": "high"}, "enabled"), + ), +) +def test_deepseek_preserves_toggle_without_forwarding_unsupported_effort( + thinking: str | None, effort: str | dict[str, str] | None, expected_thinking: str | None +) -> None: + params: Final = {"reasoning_effort": effort, **({"thinking": {"type": thinking}} if thinking is not None else {})} + result: Final = DeepSeekChatConfig().map_openai_params(params, {}, "deepseek-flash", False) + assert "reasoning_effort" not in result + assert result.get("thinking") == ({"type": expected_thinking} if expected_thinking else None) + + class TestDeepSeekThinkingParams: """Test thinking and reasoning_effort parameter handling for DeepSeek.""" @@ -735,9 +783,7 @@ async def test_deepseek_provider_async_completion(stream): messages = [{"role": "user", "content": "Hello, world!"}] # Mock AsyncHTTPHandler.post method for async test - with patch( - "litellm.llms.custom_httpx.llm_http_handler.AsyncHTTPHandler.post" - ) as mock_post: + with patch("litellm.llms.custom_httpx.llm_http_handler.AsyncHTTPHandler.post") as mock_post: mock_response_data = litellm.ModelResponse( choices=[ litellm.Choices( @@ -775,9 +821,7 @@ async def test_deepseek_provider_async_completion(stream): # Check request body request_body = json.loads(call_args.kwargs["data"]) assert call_args.kwargs["url"] == "https://api.deepseek.com/beta/chat/completions" - assert ( - request_body["model"] == "deepseek-reasoner" - ) # Model name should be stripped of provider prefix + assert request_body["model"] == "deepseek-reasoner" # Model name should be stripped of provider prefix assert request_body["messages"] == messages assert request_body["stream"] == stream diff --git a/tests/unit/llms/deepseek/messages/test_deepseek_anthropic_messages_transformation.py b/tests/unit/llms/deepseek/messages/test_deepseek_anthropic_messages_transformation.py index 0afe57a001f..316b8576ac4 100644 --- a/tests/unit/llms/deepseek/messages/test_deepseek_anthropic_messages_transformation.py +++ b/tests/unit/llms/deepseek/messages/test_deepseek_anthropic_messages_transformation.py @@ -1,5 +1,5 @@ import litellm -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) from litellm.llms.deepseek.messages.transformation import ( diff --git a/tests/unit/llms/edenai/chat/test_edenai_chat_transformation.py b/tests/unit/llms/edenai/chat/test_edenai_chat_transformation.py index 4f1e2c11a51..739ad144277 100644 --- a/tests/unit/llms/edenai/chat/test_edenai_chat_transformation.py +++ b/tests/unit/llms/edenai/chat/test_edenai_chat_transformation.py @@ -440,14 +440,3 @@ class TestDashboardRegistration: entry = json.loads(matrix_path.read_text())["providers"]["edenai"] assert entry["url"] == "https://docs.litellm.ai/docs/providers/edenai" - served = {name for name, flag in entry["endpoints"].items() if flag} - assert served == { - "chat_completions", - "messages", - "responses", - "embeddings", - "image_generations", - "audio_transcriptions", - "audio_speech", - "video_generations", - } diff --git a/tests/unit/llms/edenai/embedding/test_edenai_embedding_transformation.py b/tests/unit/llms/edenai/embedding/test_edenai_embedding_transformation.py index efdb428db32..ee6ee187d64 100644 --- a/tests/unit/llms/edenai/embedding/test_edenai_embedding_transformation.py +++ b/tests/unit/llms/edenai/embedding/test_edenai_embedding_transformation.py @@ -98,6 +98,12 @@ class TestEmbedding: class TestErrors: + def test_a_non_object_body_fails_as_an_invalid_response_object(self, eden_key, respx_mock): + respx_mock.post(EDEN_EMBEDDINGS_URL).mock(return_value=httpx.Response(200, json=["unexpected"])) + + with pytest.raises(litellm.APIConnectionError, match="Invalid response object"): + litellm.embedding(model=MODEL, input="hello") + def test_middleware_401_maps_to_authentication_error(self, eden_key, respx_mock): respx_mock.post(EDEN_EMBEDDINGS_URL).mock(return_value=httpx.Response(401, json={"detail": "Invalid token."})) diff --git a/tests/unit/llms/edenai/image_generation/test_edenai_image_generation_transformation.py b/tests/unit/llms/edenai/image_generation/test_edenai_image_generation_transformation.py index d7b32affc70..4e0673b8c27 100644 --- a/tests/unit/llms/edenai/image_generation/test_edenai_image_generation_transformation.py +++ b/tests/unit/llms/edenai/image_generation/test_edenai_image_generation_transformation.py @@ -117,6 +117,12 @@ class TestImageGeneration: class TestErrors: + def test_a_non_object_body_fails_as_an_invalid_response_object(self, eden_key, respx_mock): + respx_mock.post(EDEN_IMAGES_URL).mock(return_value=httpx.Response(200, json=["unexpected"])) + + with pytest.raises(litellm.APIConnectionError, match="Invalid response object"): + litellm.image_generation(model=MODEL, prompt="a red square") + def test_middleware_401_maps_to_authentication_error(self, eden_key, respx_mock): respx_mock.post(EDEN_IMAGES_URL).mock(return_value=httpx.Response(401, json={"detail": "Invalid token."})) diff --git a/tests/unit/llms/elevenlabs/audio_transcription/test_transformation.py b/tests/unit/llms/elevenlabs/audio_transcription/test_transformation.py index 86252a1a95d..f55644eccae 100644 --- a/tests/unit/llms/elevenlabs/audio_transcription/test_transformation.py +++ b/tests/unit/llms/elevenlabs/audio_transcription/test_transformation.py @@ -314,4 +314,4 @@ class TestElevenLabsTextToSpeechTransformation: ) assert voice_id in url - assert "output_format=pcm_44100" in url + assert "output_format=pcm_24000" in url diff --git a/tests/unit/llms/elevenlabs/test_elevenlabs_text_to_speech_transformation.py b/tests/unit/llms/elevenlabs/test_elevenlabs_text_to_speech_transformation.py index d05371d7df9..88f0ae1d524 100644 --- a/tests/unit/llms/elevenlabs/test_elevenlabs_text_to_speech_transformation.py +++ b/tests/unit/llms/elevenlabs/test_elevenlabs_text_to_speech_transformation.py @@ -55,3 +55,31 @@ def test_speech_keeps_an_internal_prefixed_kwarg_out_of_the_elevenlabs_request(r sent: Final = json.loads(respx_mock.calls[0].request.content) assert "_litellm_undeclared_sentinel" not in sent, sent assert sent["text"] == "hi" + + +@pytest.mark.parametrize( + ("response_format", "expected_output_format"), + [("wav", "wav_24000"), ("pcm", "pcm_24000")], +) +def test_speech_maps_wav_and_pcm_to_elevenlabs_output_formats( + respx_mock: respx.MockRouter, + response_format: str, + expected_output_format: str, +) -> None: + api_base: Final = "http://localhost:12346" + mock_route: Final = respx_mock.post(url__regex=rf"{api_base}/v1/text-to-speech/.*").mock( + return_value=httpx.Response(status_code=200, content=b"audio", headers={"content-type": "audio/mpeg"}) + ) + + litellm.speech( + model="elevenlabs/eleven_multilingual_v2", + input="hi", + voice="21m00Tcm4TlvDq8ikWAM", + response_format=response_format, + api_base=api_base, + api_key="fake_elevenlabs_api_key", + ) + + assert mock_route.called + request_url: Final = httpx.URL(str(respx_mock.calls[0].request.url)) + assert request_url.params["output_format"] == expected_output_format diff --git a/tests/unit/llms/gemini/google_genai/test_google_genai_transformation.py b/tests/unit/llms/gemini/google_genai/test_google_genai_transformation.py index da8ab138416..175ce040d9f 100644 --- a/tests/unit/llms/gemini/google_genai/test_google_genai_transformation.py +++ b/tests/unit/llms/gemini/google_genai/test_google_genai_transformation.py @@ -106,6 +106,26 @@ def test_generate_content_response_parses_function_call() -> None: } +@pytest.mark.parametrize( + ("body", "message"), + [ + ([], r"argument after \*\* must be a mapping, not list"), + (["candidates"], "list indices must be integers or slices, not str"), + ], +) +def test_generate_content_response_non_object_body_raises_the_error_of_the_failing_lookup( + body: JsonValue, message: str +) -> None: + with pytest.raises(TypeError, match=message) as raised: + GoogleGenAIConfig().transform_generate_content_response( + model="gemini-2.5-flash", + raw_response=httpx.Response(200, json=body), + logging_obj=SimpleNamespace(model_call_details={}), + ) + + assert raised.type is TypeError + + def test_generate_content_request_preserves_tool_declarations() -> None: tools: Final = [ { diff --git a/tests/unit/llms/gemini/image_edit/test_gemini_image_edit_transformation.py b/tests/unit/llms/gemini/image_edit/test_gemini_image_edit_transformation.py index bd9b7006e58..c21dec9b6bb 100644 --- a/tests/unit/llms/gemini/image_edit/test_gemini_image_edit_transformation.py +++ b/tests/unit/llms/gemini/image_edit/test_gemini_image_edit_transformation.py @@ -241,6 +241,26 @@ class TestGeminiImageEditTransformation: ) assert logging_usage["completion_tokens_details"]["image_tokens"] == 1716 + @pytest.mark.parametrize( + ("body", "error", "message"), + [ + (["not", "an", "object"], AttributeError, "'list' object has no attribute 'get'"), + ({"candidates": None}, TypeError, "'NoneType' object is not iterable"), + ({"candidates": [{"content": {"parts": None}}]}, TypeError, "'NoneType' object is not iterable"), + ], + ) + def test_transform_image_edit_response_malformed_body_raises_the_error_of_the_failing_lookup( + self, body: object, error: type[Exception], message: str + ) -> None: + with pytest.raises(error, match=message) as raised: + self.config.transform_image_edit_response( + model=self.model, + raw_response=httpx.Response(200, json=body), + logging_obj=self.logging_obj, + ) + + assert raised.type is error + def test_transform_image_edit_request_without_image_raises(self) -> None: optional_params = {} diff --git a/tests/unit/llms/gemini/test_gemini_common_utils.py b/tests/unit/llms/gemini/test_gemini_common_utils.py index 196b912752b..20c36878fef 100644 --- a/tests/unit/llms/gemini/test_gemini_common_utils.py +++ b/tests/unit/llms/gemini/test_gemini_common_utils.py @@ -355,6 +355,25 @@ class TestGeminiModelInfo: assert result == expected +@pytest.mark.parametrize( + ("body", "error", "message"), + [ + ([], TypeError, "list indices must be integers or slices, not str"), + ({"models": None}, TypeError, "'NoneType' object is not iterable"), + ({"models": [{"name": 1}]}, AttributeError, "'int' object has no attribute 'replace'"), + ], +) +def test_get_models_malformed_listing_raises_the_error_of_the_failing_lookup( + body: JsonValue, error: type[Exception], message: str, respx_mock: respx.MockRouter +) -> None: + respx_mock.get("https://models.test/v1beta/models").respond(200, json=body) + + with pytest.raises(error, match=message) as raised: + GeminiModelInfo().get_models(api_key="test-key", api_base="https://models.test") + + assert raised.type is error + + class TestGoogleAIStudioTokenCounter: """Test suite for GoogleAIStudioTokenCounter class""" diff --git a/tests/unit/llms/github_copilot/messages/test_github_copilot_messages_transformation.py b/tests/unit/llms/github_copilot/messages/test_github_copilot_messages_transformation.py index 46062f16c9a..20ff65f11d9 100644 --- a/tests/unit/llms/github_copilot/messages/test_github_copilot_messages_transformation.py +++ b/tests/unit/llms/github_copilot/messages/test_github_copilot_messages_transformation.py @@ -334,7 +334,7 @@ def test_github_copilot_config_does_not_handle_web_search_natively(): interception handler short-circuiting Copilot instead of routing to it, even though Copilot now has a BaseAnthropicMessagesConfig. The base Anthropic config (bedrock/vertex/anthropic path) must report True.""" - from litellm.llms.anthropic.pass_through.messages.transformation import ( + from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) diff --git a/tests/unit/llms/groq/chat/test_groq_chat_transformation.py b/tests/unit/llms/groq/chat/test_groq_chat_transformation.py index 95611e344dc..7aa8c65215e 100644 --- a/tests/unit/llms/groq/chat/test_groq_chat_transformation.py +++ b/tests/unit/llms/groq/chat/test_groq_chat_transformation.py @@ -1,4 +1,5 @@ import logging +from typing import Final from unittest.mock import patch import httpx @@ -523,3 +524,68 @@ def test_tool_search_reply_sent_to_groq_drops_litellm_response_fields(): } ], } + + +@pytest.mark.asyncio +@pytest.mark.parametrize("is_async", [False, True]) +@pytest.mark.parametrize("with_tool_call", [False, True]) +async def test_streamed_reasoning_reply_can_be_replayed(is_async: bool, with_tool_call: bool) -> None: + tool_calls: Final = [ + { + "index": 0, + "id": "call_weather", + "type": "function", + "function": {"name": "get_weather", "arguments": '{"city":"Paris"}'}, + } + ] + handler: Final = GroqChatCompletionStreamingHandler(streaming_response=iter(()), sync_stream=True) + chunk: Final = handler.chunk_parser( + { + "id": "chatcmpl-reasoning", + "object": "chat.completion.chunk", + "created": 1769511767, + "model": "openai/gpt-oss-20b", + "choices": [ + { + "index": 0, + "delta": { + "role": "assistant", + "reasoning": "I should check the weather.", + "content": "" if with_tool_call else "Hello there!", + **({"tool_calls": tool_calls} if with_tool_call else {}), + }, + "finish_reason": "tool_calls" if with_tool_call else "stop", + } + ], + } + ) + reply: Final = litellm.stream_chunk_builder([chunk]).choices[0].message + assert reply.reasoning_content == "I should check the weather." + history: Final = [reply.model_dump(exclude_none=True)] + config: Final = GroqChatConfig() + + if is_async: + replayed = await config._transform_messages(messages=history, model="openai/gpt-oss-20b", is_async=True) + else: + replayed = config._transform_messages(messages=history, model="openai/gpt-oss-20b", is_async=False) + + assert replayed == [ + { + "role": "assistant", + "content": "" if with_tool_call else "Hello there!", + **( + { + "tool_calls": [ + { + "id": "call_weather", + "type": "function", + "function": {"name": "get_weather", "arguments": '{"city":"Paris"}'}, + } + ] + } + if with_tool_call + else {} + ), + } + ] + assert reply.reasoning_content == "I should check the weather." diff --git a/tests/unit/llms/litellm_proxy/skills/test_skill_search.py b/tests/unit/llms/litellm_proxy/skills/test_skill_search.py index c0754f6f1af..0647b203aff 100644 --- a/tests/unit/llms/litellm_proxy/skills/test_skill_search.py +++ b/tests/unit/llms/litellm_proxy/skills/test_skill_search.py @@ -456,7 +456,7 @@ class TestHandleSkillSearchMCP: self, accessible_skills: AsyncMock, embedding_router: MagicMock ) -> None: from litellm.llms.litellm_proxy.skills.skill_search import MAX_SKILL_SEARCH_TOP_K - from litellm.proxy._experimental.mcp_server.tool_search import handle_skill_search + from litellm.proxy.mcp_server.tool_search import handle_skill_search many_skills: Final = tuple( LiteLLM_SkillsTable( @@ -476,7 +476,7 @@ class TestHandleSkillSearchMCP: async def test_top_k_below_one_is_raised_to_one( self, accessible_skills: AsyncMock, embedding_router: MagicMock ) -> None: - from litellm.proxy._experimental.mcp_server.tool_search import handle_skill_search + from litellm.proxy.mcp_server.tool_search import handle_skill_search result = await handle_skill_search( query="language translation", top_k=0, user_api_key_dict=UserAPIKeyAuth(user_id="u") diff --git a/tests/unit/llms/microsoft_365_copilot/chat/test_transformation.py b/tests/unit/llms/microsoft_365_copilot/chat/test_transformation.py index 22cb8da3aed..aab3c82a389 100644 --- a/tests/unit/llms/microsoft_365_copilot/chat/test_transformation.py +++ b/tests/unit/llms/microsoft_365_copilot/chat/test_transformation.py @@ -5,7 +5,7 @@ import pytest from pydantic import TypeAdapter import litellm -from litellm.llms.anthropic.pass_through.adapters.transformation import LiteLLMAnthropicMessagesAdapter +from litellm.llms.anthropic.messages.adapters.transformation import LiteLLMAnthropicMessagesAdapter from litellm.llms.microsoft_365_copilot.chat.transformation import ( Microsoft365CopilotChatConfig, build_chat_request, diff --git a/tests/unit/llms/openai/chat/test_openai_gpt_transformation.py b/tests/unit/llms/openai/chat/test_openai_gpt_transformation.py index 76faf338307..3e96995621e 100644 --- a/tests/unit/llms/openai/chat/test_openai_gpt_transformation.py +++ b/tests/unit/llms/openai/chat/test_openai_gpt_transformation.py @@ -12,7 +12,7 @@ from httpx import Response import litellm from litellm.litellm_core_utils.prompt_templates.common_utils import TOOL_RESULT_IMAGE_BOUNDARY from litellm.litellm_core_utils.prompt_templates.image_handling import in_memory_cache -from litellm.llms.openai.chat.gpt_5_transformation import OpenAIGPT5Config +from litellm.llms.openai.chat.gpt_reasoning_transformation import OpenAIGPT5Config from litellm.llms.openai.chat.gpt_transformation import ( OpenAIChatCompletionStreamingHandler, OpenAIGPTConfig, diff --git a/tests/unit/llms/openai/decisions/test_openai_decisions_transformation.py b/tests/unit/llms/openai/decisions/test_openai_decisions_transformation.py index 2a07462fe81..eddfe578256 100644 --- a/tests/unit/llms/openai/decisions/test_openai_decisions_transformation.py +++ b/tests/unit/llms/openai/decisions/test_openai_decisions_transformation.py @@ -299,3 +299,55 @@ def test_an_openai_response_becomes_systemone_answers_with_the_callers_score_lab } assert response.usage is not None assert (response.usage.cached_tokens, response.usage.cache_write_tokens) == (256, 64) + + +@pytest.mark.parametrize( + ("choice_probabilities", "score_probabilities"), + ( + ((), ()), + ( + ({"value": True, "probability": 0.8},), + ({"value": 1, "label": "major", "probability": 0.8},), + ), + ( + ( + {"value": True, "probability": 0.0}, + {"value": "escalate", "probability": 0.8}, + ), + ( + {"value": 0, "label": "minor", "probability": 0.0}, + {"value": 1, "label": "major", "probability": 0.8}, + ), + ), + ( + ({"value": True, "probability": 0.0},), + ({"value": 1, "label": "major", "probability": 0.0},), + ), + ), + ids=("empty", "missing", "explicit_zero", "only_zero"), +) +def test_openai_probabilities_preserve_missing_entries_and_explicit_zeros( + choice_probabilities: tuple[Mapping[str, object], ...], + score_probabilities: tuple[Mapping[str, object], ...], +) -> None: + ir: Final = _openai_ir(_OPENAI_REQUEST) + payload: Final = { + **_OPENAI_RESPONSE, + "answers": [ + _PREDICATE_ANSWER, + {**_CHOICE_ANSWER, "probabilities": choice_probabilities}, + { + "type": "score", + "name": "severity", + "score": 1, + "confidence": 0.8, + "probabilities": score_probabilities, + }, + _REFUSAL_ANSWER, + ], + } + + response: Final = ir_to_openai_response(OpenAIDecisionsConfig().parse_response(payload, ir), ir, "requested") + + assert response.answers[1].model_dump(mode="json")["probabilities"] == list(choice_probabilities) + assert response.answers[2].model_dump(mode="json")["probabilities"] == list(score_probabilities) diff --git a/tests/unit/llms/openai/responses/test_openai_count_tokens_transformation.py b/tests/unit/llms/openai/responses/test_openai_count_tokens_transformation.py index 0a5039791ee..d5e7bb4f93b 100644 --- a/tests/unit/llms/openai/responses/test_openai_count_tokens_transformation.py +++ b/tests/unit/llms/openai/responses/test_openai_count_tokens_transformation.py @@ -2,12 +2,13 @@ from typing import Final import pytest -from litellm.llms.anthropic.pass_through.responses_adapters.transformation import ( +from litellm.llms.anthropic.messages.responses_adapters.transformation import ( LiteLLMAnthropicToResponsesAPIAdapter, ) from litellm.llms.openai.responses.count_tokens.transformation import ( OpenAICountTokensConfig, ) +from tests.unit.litellm_core_utils.attribute_forwarder import AttributeForwarder def test_transform_basic_request(): @@ -207,6 +208,23 @@ def test_messages_to_responses_input_with_tool(): } +def test_messages_to_responses_input_reads_a_tool_call_that_forwards_its_fields(): + tool_call: Final = {"id": "call_123", "function": {"name": "get_weather", "arguments": '{"city": "Paris"}'}} + messages: Final = [ + {"role": "user", "content": "What's the weather?"}, + {"role": "assistant", "content": None, "tool_calls": [AttributeForwarder(tool_call)]}, + ] + + input_items, _ = OpenAICountTokensConfig.messages_to_responses_input(messages) + + assert input_items[1] == { + "type": "function_call", + "call_id": "call_123", + "name": "get_weather", + "arguments": '{"city": "Paris"}', + } + + def test_messages_to_responses_input_preserves_images(): """An image block must survive the round trip, or OpenAI counts only the text. diff --git a/tests/unit/llms/openai/responses/test_openai_responses_guardrail_handler.py b/tests/unit/llms/openai/responses/test_openai_responses_guardrail_handler.py index 2f10fd6fd0d..0d1b1aca9bc 100644 --- a/tests/unit/llms/openai/responses/test_openai_responses_guardrail_handler.py +++ b/tests/unit/llms/openai/responses/test_openai_responses_guardrail_handler.py @@ -47,6 +47,7 @@ from litellm.types.responses.main import ( OutputToolSearchCall, ) from litellm.types.utils import CallTypes, GenericGuardrailAPIInputs +from tests.unit.litellm_core_utils.attribute_forwarder import AttributeForwarder class MockGuardrail(CustomGuardrail): @@ -1783,6 +1784,22 @@ class TestOpenAIResponsesHandlerStreamingOutputProcessing: assert events[4]["item"]["content"][0]["text"] == "hello [MASKED]" assert events[5]["response"]["output"][0]["content"][0]["text"] == "hello [MASKED]" + @pytest.mark.asyncio + async def test_deliver_ended_stream_rewrites_syncs_events_that_forward_their_fields(self): + handler: Final = OpenAIResponsesHandler() + plain_events: Final = self._ended_stream_events() + forwarded_delta: Final = AttributeForwarder(plain_events[0]) + events: Final = [forwarded_delta, *plain_events[1:]] + + await handler.process_output_streaming_response( + responses_so_far=events, + guardrail_to_apply=self._masking_guardrail(), + litellm_logging_obj=None, + deliver_ended_stream_rewrites=True, + ) + + assert forwarded_delta.delta == "hello [MASKED]" + @staticmethod def _ended_function_call_stream_events() -> List[dict]: def item(arguments: str, status: str) -> dict: diff --git a/tests/unit/llms/openai/test_gpt5_transformation.py b/tests/unit/llms/openai/test_gpt_reasoning_transformation.py similarity index 99% rename from tests/unit/llms/openai/test_gpt5_transformation.py rename to tests/unit/llms/openai/test_gpt_reasoning_transformation.py index 7b10411ba20..4cdc674c774 100644 --- a/tests/unit/llms/openai/test_gpt5_transformation.py +++ b/tests/unit/llms/openai/test_gpt_reasoning_transformation.py @@ -7,7 +7,7 @@ import pytest import litellm import litellm.main as litellm_main from litellm.litellm_core_utils.get_model_cost_map import get_model_cost_map -from litellm.llms.openai.chat.gpt_5_transformation import OpenAIGPT5Config +from litellm.llms.openai.chat.gpt_reasoning_transformation import OpenAIGPT5Config from litellm.llms.openai.openai import OpenAIConfig from litellm.utils import ( is_explicitly_disabled_factory, diff --git a/tests/unit/llms/openai/test_is_model_gpt_5_model.py b/tests/unit/llms/openai/test_is_model_gpt_5_model.py index f6fef92fc6a..39d7c9da2ce 100644 --- a/tests/unit/llms/openai/test_is_model_gpt_5_model.py +++ b/tests/unit/llms/openai/test_is_model_gpt_5_model.py @@ -35,8 +35,8 @@ from typing import Final import pytest import litellm -from litellm.llms.azure.chat.gpt_5_transformation import AzureOpenAIGPT5Config -from litellm.llms.openai.chat.gpt_5_transformation import OpenAIGPT5Config +from litellm.llms.azure.chat.gpt_reasoning_transformation import AzureOpenAIGPT5Config +from litellm.llms.openai.chat.gpt_reasoning_transformation import OpenAIGPT5Config from litellm.llms.openai.responses.transformation import OpenAIResponsesAPIConfig # --------------------------------------------------------------------------- diff --git a/tests/unit/llms/openai_like/messages/test_openai_like_anthropic_messages_transformation.py b/tests/unit/llms/openai_like/messages/test_openai_like_anthropic_messages_transformation.py index 1d5ef50ca3a..935e3e4a21d 100644 --- a/tests/unit/llms/openai_like/messages/test_openai_like_anthropic_messages_transformation.py +++ b/tests/unit/llms/openai_like/messages/test_openai_like_anthropic_messages_transformation.py @@ -396,7 +396,7 @@ def test_request_defaults_missing_cache_control_type_and_drops_non_dict(config): def test_native_anthropic_config_keeps_cache_control_ttl(): """Anthropic itself accepts ttl, so the normalization must stay scoped to the OpenAI-like passthrough and never reach the native Anthropic path.""" - from litellm.llms.anthropic.pass_through.messages.transformation import ( + from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) diff --git a/tests/unit/llms/openai_like/test_abliteration_provider.py b/tests/unit/llms/openai_like/test_abliteration_provider.py index 33ad8abf62c..74bb5f89781 100644 --- a/tests/unit/llms/openai_like/test_abliteration_provider.py +++ b/tests/unit/llms/openai_like/test_abliteration_provider.py @@ -2,12 +2,18 @@ Unit tests for the Abliteration OpenAI-like provider. """ +import json import os import sys +from typing import Final -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../..")) -) +import pytest +import respx + +import litellm +from litellm.utils import trim_messages + +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../.."))) from litellm.llms.openai_like.dynamic_config import create_config_class from litellm.llms.openai_like.json_loader import JSONProviderRegistry @@ -48,3 +54,79 @@ def test_abliteration_complete_url_appends_endpoint(): stream=False, ) assert url == f"{ABLITERATION_BASE_URL}/chat/completions" + + +def test_abliteration_chat_forwards_reasoning_and_accounts_for_cache(local_model_cost_map: None) -> None: + with respx.mock() as upstream: + route: Final = upstream.post("https://api.abliteration.ai/v1/chat/completions").respond( + 200, + json={ + "id": "chatcmpl-test", + "object": "chat.completion", + "created": 1, + "model": "abliterated-model-large-v2", + "choices": [ + {"index": 0, "message": {"role": "assistant", "content": "hello"}, "finish_reason": "stop"} + ], + "usage": { + "prompt_tokens": 100, + "completion_tokens": 5, + "total_tokens": 105, + "prompt_tokens_details": {"cached_tokens": 80}, + }, + }, + ) + response: Final = litellm.completion( + model="abliteration/abliterated-model-large-v2", + api_key="fake-test-key", + messages=[{"role": "user", "content": "Say hello"}], + reasoning_effort="low", + ) + request: Final = route.calls.last.request + body: Final = json.loads(request.content) + assert request.headers["authorization"] == "Bearer fake-test-key" + assert body["model"] == "abliterated-model-large-v2" + assert body["reasoning_effort"] == "low" + assert response.choices[0].message.content == "hello" + rates: Final = litellm.model_cost["abliteration/abliterated-model-large-v2"] + expected: Final = ( + 20 * rates["input_cost_per_token"] + + 80 * rates["cache_read_input_token_cost"] + + 5 * rates["output_cost_per_token"] + ) + assert litellm.completion_cost(completion_response=response) == pytest.approx(expected) + + +def test_large_v2_model_group_does_not_offer_disabled_reasoning(local_model_cost_map: None) -> None: + """Large v2 cannot disable reasoning per https://docs.abliteration.ai/capabilities/thinking (2026-10-26).""" + router: Final = litellm.Router( + model_list=[ + { + "model_name": "large-v2", + "litellm_params": { + "model": "abliteration/abliterated-model-large-v2", + "api_key": "fake-test-key", + }, + } + ] + ) + info: Final = router.get_model_group_info(model_group="large-v2") + assert info is not None + assert info.supported_reasoning_efforts + assert "none" not in info.supported_reasoning_efforts + assert "low" in info.supported_reasoning_efforts + + +def test_abliteration_models_trim_to_their_input_budget(local_model_cost_map: None) -> None: + model_names: Final = tuple(model for model in litellm.model_cost if model.startswith("abliteration/")) + assert model_names + messages: Final = [{"role": "user", "content": "hello " * 500}] + budget: Final = 100 + for model in model_names: + trimmed: Final = trim_messages( + messages, + model=model, + trim_ratio=budget / litellm.model_cost[model]["max_input_tokens"], + ) + assert litellm.token_counter(model=model, messages=messages) > budget + assert litellm.token_counter(model=model, messages=trimmed) <= budget diff --git a/tests/unit/llms/openai_like/test_cortecs_provider.py b/tests/unit/llms/openai_like/test_cortecs_provider.py index 142bb1b7588..c5a6160784a 100644 --- a/tests/unit/llms/openai_like/test_cortecs_provider.py +++ b/tests/unit/llms/openai_like/test_cortecs_provider.py @@ -58,26 +58,6 @@ def test_cortecs_is_available_in_add_model_form(): } -def test_cortecs_supported_endpoints(): - matrix_path = Path(litellm.__file__).parent / "provider_endpoints_support_backup.json" - providers = json.loads(matrix_path.read_text())["providers"] - - assert providers["cortecs"]["endpoints"] == { - "chat_completions": True, - "messages": True, - "responses": True, - "embeddings": False, - "image_generations": False, - "audio_transcriptions": False, - "audio_speech": False, - "moderations": False, - "batches": False, - "rerank": False, - "a2a": False, - "interactions": False, - } - - def test_cortecs_chat_completion_request(): with respx.mock() as upstream: route: Final = upstream.post("https://api.cortecs.ai/v1/chat/completions").respond( diff --git a/tests/unit/llms/openai_like/test_libertai_provider.py b/tests/unit/llms/openai_like/test_libertai_provider.py index c17eaf7c87f..7553efb1341 100644 --- a/tests/unit/llms/openai_like/test_libertai_provider.py +++ b/tests/unit/llms/openai_like/test_libertai_provider.py @@ -91,10 +91,3 @@ class TestLibertAIProviderConfig: matrix = json.loads(backup_path.read_text()) assert "libertai" in matrix["providers"] - endpoints = matrix["providers"]["libertai"]["endpoints"] - assert endpoints["chat_completions"] is True - # embeddings is advertised false: the JSON-configured-provider path only - # wires chat routing (the OpenAILike embedding handler is reached solely - # for the literal openai_like/llamafile/lm_studio providers), matching - # the llamagate precedent. bge-m3 stays in the cost map for metadata. - assert endpoints["embeddings"] is False diff --git a/tests/unit/llms/openai_like/test_openinfer_provider.py b/tests/unit/llms/openai_like/test_openinfer_provider.py index 7bcc489fcf8..6e6e957df0b 100644 --- a/tests/unit/llms/openai_like/test_openinfer_provider.py +++ b/tests/unit/llms/openai_like/test_openinfer_provider.py @@ -11,9 +11,7 @@ from litellm.proxy.auth.model_checks import get_provider_models _REPO_ROOT: Final = Path(__file__).resolve().parents[4] _PRIMARY_PRICES: Final = json.loads((_REPO_ROOT / "model_prices_and_context_window.json").read_text()) -_BACKUP_PRICES: Final = json.loads( - (_REPO_ROOT / "litellm" / "model_prices_and_context_window_backup.json").read_text() -) +_BACKUP_PRICES: Final = json.loads((_REPO_ROOT / "litellm" / "model_prices_and_context_window_backup.json").read_text()) _CATALOG_MODELS: Final = tuple( key for key, row in _PRIMARY_PRICES.items() if isinstance(row, dict) and row.get("litellm_provider") == "openinfer" ) @@ -31,7 +29,9 @@ _CHAT_RESPONSE: Final = { "object": "chat.completion", "created": 1_792_000_000, "model": "@oi/Qwen3.5-27B", - "choices": [{"index": 0, "message": {"role": "assistant", "content": "Hello from OpenInfer"}, "finish_reason": "stop"}], + "choices": [ + {"index": 0, "message": {"role": "assistant", "content": "Hello from OpenInfer"}, "finish_reason": "stop"} + ], "usage": {"prompt_tokens": 4, "completion_tokens": 3, "total_tokens": 7}, } @@ -228,7 +228,6 @@ def test_catalog_row_matches_its_backup_and_fits_its_context(model: str): assert row == _BACKUP_PRICES[model] assert row["mode"] == "chat" - assert row["max_tokens"] == row["max_output_tokens"] assert 0 < row["max_output_tokens"] <= row["max_input_tokens"] assert row["input_cost_per_token"] > 0 assert row["output_cost_per_token"] > 0 diff --git a/tests/unit/llms/openai_like/test_prism_provider.py b/tests/unit/llms/openai_like/test_prism_provider.py index c1775c63dc9..9bf5cdbbbb4 100644 --- a/tests/unit/llms/openai_like/test_prism_provider.py +++ b/tests/unit/llms/openai_like/test_prism_provider.py @@ -99,25 +99,6 @@ def test_prism_is_available_in_add_model_form(): } -def test_prism_supported_endpoints(): - matrix_path = Path(litellm.__file__).parent / "provider_endpoints_support_backup.json" - providers = json.loads(matrix_path.read_text())["providers"] - - assert providers["prism"]["endpoints"] == { - "chat_completions": True, - "messages": True, - "responses": True, - "embeddings": False, - "image_generations": False, - "audio_transcriptions": False, - "audio_speech": False, - "moderations": False, - "batches": False, - "rerank": False, - "a2a": False, - } - - def test_prism_responses_request(): with respx.mock() as upstream: route: Final = upstream.post("https://api.prisminference.com/v1/responses").respond( diff --git a/tests/unit/llms/openai_like/test_refuseless_provider.py b/tests/unit/llms/openai_like/test_refuseless_provider.py new file mode 100644 index 00000000000..4961f100709 --- /dev/null +++ b/tests/unit/llms/openai_like/test_refuseless_provider.py @@ -0,0 +1,111 @@ +import json +from typing import Final + +import pytest +import respx + +import litellm +from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider +from litellm.utils import trim_messages + + +def test_refuseless_resolves_environment_and_explicit_credentials(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("REFUSELESS_API_KEY", "fake-environment-key") + assert get_llm_provider(model="refuseless/glm-5.3-abliterated") == ( + "glm-5.3-abliterated", + "refuseless", + "fake-environment-key", + "https://api.refuseless.com/v1", + ) + assert get_llm_provider( + model="refuseless/glm-5.3-abliterated", api_key="fake-explicit-key", api_base="https://gateway.example/v1" + ) == ("glm-5.3-abliterated", "refuseless", "fake-explicit-key", "https://gateway.example/v1") + + +def test_refuseless_chat_forwards_reasoning_and_accounts_for_cache(local_model_cost_map: None) -> None: + with respx.mock() as upstream: + route: Final = upstream.post("https://api.refuseless.com/v1/chat/completions").respond( + 200, + json={ + "id": "chatcmpl-test", + "object": "chat.completion", + "created": 1, + "model": "glm-5.3-abliterated", + "choices": [ + {"index": 0, "message": {"role": "assistant", "content": "hello"}, "finish_reason": "stop"} + ], + "usage": { + "prompt_tokens": 100, + "completion_tokens": 5, + "total_tokens": 105, + "prompt_tokens_details": {"cached_tokens": 80}, + }, + }, + ) + response: Final = litellm.completion( + model="refuseless/glm-5.3-abliterated", + api_key="fake-test-key", + messages=[{"role": "user", "content": "Say hello"}], + reasoning_effort="low", + ) + request: Final = route.calls.last.request + body: Final = json.loads(request.content) + assert request.headers["authorization"] == "Bearer fake-test-key" + assert body["model"] == "glm-5.3-abliterated" + assert body["reasoning_effort"] == "low" + assert response.choices[0].message.content == "hello" + rates: Final = litellm.model_cost["refuseless/glm-5.3-abliterated"] + expected: Final = ( + 20 * rates["input_cost_per_token"] + + 80 * rates["cache_read_input_token_cost"] + + 5 * rates["output_cost_per_token"] + ) + assert litellm.completion_cost(completion_response=response) == pytest.approx(expected) + + +def test_refuseless_uses_native_responses_endpoint() -> None: + with respx.mock() as upstream: + route: Final = upstream.post("https://api.refuseless.com/v1/responses").respond( + 200, + json={ + "id": "resp-test", + "object": "response", + "created_at": 1, + "model": "glm-5.3-abliterated", + "status": "completed", + "output": [ + { + "id": "msg-test", + "type": "message", + "role": "assistant", + "status": "completed", + "content": [{"type": "output_text", "text": "hello", "annotations": []}], + } + ], + "usage": {"input_tokens": 4, "output_tokens": 3, "total_tokens": 7}, + }, + ) + response: Final = litellm.responses( + model="refuseless/glm-5.3-abliterated", + api_key="fake-test-key", + input="Say hello", + store=False, + ) + assert route.calls.last.request.headers["authorization"] == "Bearer fake-test-key" + assert json.loads(route.calls.last.request.content)["model"] == "glm-5.3-abliterated" + assert response.output[0].content[0].text == "hello" + + +def test_refuseless_models_trim_to_their_input_budget(local_model_cost_map: None) -> None: + model_names: Final = tuple(model for model in litellm.model_cost if model.startswith("refuseless/")) + assert model_names + messages: Final = [{"role": "user", "content": "hello " * 500}] + budget: Final = 100 + for model in model_names: + trimmed: Final = trim_messages( + messages, + model=model, + trim_ratio=budget / litellm.model_cost[model]["max_input_tokens"], + ) + assert litellm.token_counter(model=model, messages=messages) > budget + assert litellm.token_counter(model=model, messages=trimmed) <= budget diff --git a/tests/unit/llms/openai_like/test_reka_provider.py b/tests/unit/llms/openai_like/test_reka_provider.py index 3b482f23641..5ba7a2f6680 100644 --- a/tests/unit/llms/openai_like/test_reka_provider.py +++ b/tests/unit/llms/openai_like/test_reka_provider.py @@ -115,28 +115,6 @@ def test_reka_is_available_in_add_model_form(): } -def test_reka_supported_endpoints(): - expected: Final = { - "chat_completions": True, - "messages": True, - "responses": True, - "embeddings": False, - "image_generations": False, - "audio_transcriptions": False, - "audio_speech": False, - "moderations": False, - "batches": False, - "rerank": False, - "a2a": False, - "interactions": False, - } - backup_path = Path(litellm.__file__).parent / "provider_endpoints_support_backup.json" - root_path = Path(litellm.__file__).parent.parent / "provider_endpoints_support.json" - - assert json.loads(backup_path.read_text())["providers"]["reka"]["endpoints"] == expected - assert json.loads(root_path.read_text())["providers"]["reka"]["endpoints"] == expected - - def test_reka_chat_completion_request(): with respx.mock() as upstream: route: Final = upstream.post("https://api.reka.ai/v1/chat/completions").respond(200, json=_CHAT_COMPLETION) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/__init__.py b/tests/unit/llms/opencode/chat/__init__.py similarity index 100% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/__init__.py rename to tests/unit/llms/opencode/chat/__init__.py diff --git a/tests/unit/llms/opencode/chat/test_transformation.py b/tests/unit/llms/opencode/chat/test_transformation.py new file mode 100644 index 00000000000..0a5e49ca1b2 --- /dev/null +++ b/tests/unit/llms/opencode/chat/test_transformation.py @@ -0,0 +1,582 @@ +import asyncio +import json +from collections.abc import Mapping +from datetime import datetime +from typing import Final + +import httpx +import pytest +import respx +from pydantic import TypeAdapter + +import litellm +from litellm.integrations.custom_logger import CustomLogger +from litellm.litellm_core_utils.core_helpers import RESPONSE_COST_HEADER +from litellm.litellm_core_utils.litellm_logging import Logging +from litellm.llms.custom_httpx.llm_http_handler import BaseLLMHTTPHandler +from litellm.llms.opencode.common_utils import go_headers + + +@pytest.fixture +def go_catalog(monkeypatch: pytest.MonkeyPatch) -> None: + for route in ("chat/completions", "messages", "responses", "gemini"): + monkeypatch.setitem( + litellm.model_cost, + f"opencode_go/fixture-{route.split('/')[0]}", + { + "litellm_provider": "opencode_go", + "mode": "responses" if route == "responses" else "chat", + "supported_endpoints": ["/v1beta/models" if route == "gemini" else f"/v1/{route}"], + "max_output_tokens": 128000, + "max_input_tokens": 1000000, + "input_cost_per_token": 0.000002, + "output_cost_per_token": 0.000005, + "supports_function_calling": True, + }, + ) + monkeypatch.delenv("OPENCODE_GO_API_BASE", raising=False) + + +def upstream_reply(route: str, model: str) -> Mapping[str, object]: + if route == "gemini": + return { + "candidates": [{"content": {"role": "model", "parts": [{"text": "hello"}]}, "finishReason": "STOP"}], + "usageMetadata": {"promptTokenCount": 10, "candidatesTokenCount": 5, "totalTokenCount": 15}, + } + if route == "messages": + return { + "id": "msg_test", + "type": "message", + "role": "assistant", + "model": model, + "content": [{"type": "text", "text": "hello"}], + "stop_reason": "end_turn", + "usage": {"input_tokens": 10, "output_tokens": 5}, + } + if route == "responses": + return { + "id": "resp_test", + "object": "response", + "created_at": 1700000000, + "model": model, + "status": "completed", + "output": [ + { + "type": "message", + "id": "msg_test", + "status": "completed", + "role": "assistant", + "content": [{"type": "output_text", "text": "hello", "annotations": []}], + } + ], + "usage": {"input_tokens": 10, "output_tokens": 5, "total_tokens": 15}, + } + return { + "id": "chatcmpl-test", + "object": "chat.completion", + "created": 1700000000, + "model": model, + "choices": [{"index": 0, "finish_reason": "stop", "message": {"role": "assistant", "content": "hello"}}], + "usage": {"prompt_tokens": 10, "completion_tokens": 5, "total_tokens": 15}, + } + + +@pytest.mark.asyncio +@pytest.mark.parametrize("upstream", ["chat/completions", "messages", "responses", "gemini"]) +@pytest.mark.parametrize("ingress", ["chat", "responses", "messages"]) +async def test_all_routes_use_model_protocol_and_preserve_session( + go_catalog: None, upstream: str, ingress: str +) -> None: + model: Final = f"fixture-{upstream.split('/')[0]}" + + def respond(request: httpx.Request) -> httpx.Response: + family: Final = "anthropic" if upstream == "messages" else "openai" + expected_path: Final = ( + f"/inference/go/google/v1beta/models/{model}:generateContent" + if upstream == "gemini" + else f"/inference/go/{family}/v1/{upstream}" + ) + assert request.url.path == expected_path + assert request.headers["authorization"] == "Bearer fake-go-key" + assert request.headers["x-opencode-session"] == "conversation-1" + body: Final = json.loads(request.content) + if upstream == "gemini": + assert body["contents"][0]["parts"][0]["text"] == "hello" + else: + assert body["model"] == model + assert "input" in body if upstream == "responses" else "messages" in body + if upstream == "messages": + assert body["max_tokens"] == 128000 + return httpx.Response(200, json=upstream_reply(upstream, model)) + + with respx.mock(using="httpx") as transport: + transport.post().mock(side_effect=respond) + kwargs: Final = { + "model": f"opencode_go/{model}", + "api_key": "fake-go-key", + "litellm_session_id": "conversation-1", + } + if ingress == "chat": + response: Final = await litellm.acompletion(messages=[{"role": "user", "content": "hello"}], **kwargs) + assert response.choices[0].message.content == "hello" + assert response.usage.total_tokens == 15 + elif ingress == "responses": + response_api: Final = await litellm.aresponses(input="hello", **kwargs) + assert response_api.output[0].content[0].text == "hello" + assert response_api.usage.total_tokens == 15 + else: + message: Final = await litellm.anthropic.messages.acreate( + messages=[{"role": "user", "content": "hello"}], + max_tokens=128000, + **kwargs, + ) + assert message["content"][0]["text"] == "hello" + assert message["usage"]["output_tokens"] == 5 + + +def test_go_never_falls_back_to_other_provider_credentials(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.delenv("OPENCODE_API_KEY", raising=False) + monkeypatch.delenv("OPENCODE_GO_API_KEY", raising=False) + monkeypatch.setenv("OPENAI_API_KEY", "fake-openai-key") + monkeypatch.setenv("ANTHROPIC_API_KEY", "fake-anthropic-key") + with pytest.raises(litellm.AuthenticationError, match="OPENCODE_API_KEY"): + go_headers({}, {}, None, "fixture-model") + + +@pytest.mark.parametrize("input_tokens,expected", [(100, 0.00025), (101, 0.000504)]) +def test_go_uses_registered_context_tiers_not_underlying_provider_prices( + monkeypatch: pytest.MonkeyPatch, + input_tokens: int, + expected: float, +) -> None: + monkeypatch.setitem( + litellm.model_cost, + "opencode_go/fixture-priced", + { + "litellm_provider": "opencode_go", + "mode": "chat", + "input_cost_per_token": 0.000002, + "output_cost_per_token": 0.000005, + "tiered_pricing": [ + {"range": [0, 100], "input_cost_per_token": 0.000002, "output_cost_per_token": 0.000005}, + {"range": [100, 1000], "input_cost_per_token": 0.000004, "output_cost_per_token": 0.000010}, + ], + }, + ) + cost: Final = litellm.cost_per_token( + model="opencode_go/fixture-priced", + prompt_tokens=input_tokens, + completion_tokens=10, + ) + assert sum(cost) == pytest.approx(expected) + + +@pytest.mark.parametrize("suffix", ["", "/v1", "/v1/messages", "/v1/messages/"]) +def test_messages_custom_base_does_not_duplicate_version_or_route(go_catalog: None, suffix: str) -> None: + from litellm.llms.opencode.messages.transformation import OpenCodeGoMessagesConfig + + assert ( + OpenCodeGoMessagesConfig().get_complete_url( + f"https://gateway.example/go{suffix}", + None, + "fixture-messages", + {}, + {}, + ) + == "https://gateway.example/go/v1/messages" + ) + + +@pytest.mark.parametrize("base", [None, "https://gateway.example/go/v1"]) +def test_discovery_returns_qualified_ids_and_accepts_response_metadata(base: str | None) -> None: + url: Final = "https://gateway.example/go/v1/models" if base else "https://opencode.ai/inference/go/v1/models" + with respx.mock(using="httpx") as transport: + transport.get(url).respond( + json={ + "object": "list", + "data": [ + {"id": "fixture-chat", "object": "model"}, + {"id": "fixture-messages", "object": "model"}, + ], + } + ) + assert litellm.get_valid_models( + check_provider_endpoint=True, + custom_llm_provider="opencode_go", + api_key="fake-go-key", + api_base=base, + ) == [ + "opencode_go/fixture-chat", + "opencode_go/fixture-messages", + ] + + +@pytest.mark.parametrize("explicit_base", [None, "https://explicit-gateway.example/go/v1"]) +def test_discovery_honors_environment_base_and_explicit_override( + monkeypatch: pytest.MonkeyPatch, explicit_base: str | None +) -> None: + from litellm.llms.opencode.chat.transformation import OpenCodeGoChatConfig + + monkeypatch.setenv("OPENCODE_GO_API_BASE", "https://env-gateway.example/go/v1/") + expected_base: Final = explicit_base or "https://env-gateway.example/go/v1" + with respx.mock(using="httpx") as transport: + transport.get(f"{expected_base}/models").respond(json={"data": [{"id": "gateway-only-model"}]}) + assert OpenCodeGoChatConfig().get_models(api_key="fake-go-key", api_base=explicit_base) == [ + "opencode_go/gateway-only-model" + ] + + +@pytest.mark.asyncio +@pytest.mark.parametrize("ingress", ["chat", "responses", "messages"]) +async def test_gemini_streams_text_and_usage_through_all_routes(go_catalog: None, ingress: str) -> None: + def respond(request: httpx.Request) -> httpx.Response: + assert request.url.path == "/inference/go/google/v1beta/models/fixture-gemini:streamGenerateContent" + assert request.url.query == b"alt=sse" + assert "stream" not in json.loads(request.content) + return httpx.Response( + 200, + headers={"content-type": "text/event-stream"}, + text="data: " + json.dumps(upstream_reply("gemini", "fixture-gemini")) + "\n\n", + ) + + with respx.mock(using="httpx") as transport: + transport.post().mock(side_effect=respond) + kwargs: Final = {"model": "opencode_go/fixture-gemini", "api_key": "fake-go-key", "stream": True} + if ingress == "chat": + stream: Final = await litellm.acompletion( + messages=[{"role": "user", "content": "hello"}], stream_options={"include_usage": True}, **kwargs + ) + chunks: Final = [chunk async for chunk in stream] + assert "".join(chunk.choices[0].delta.content or "" for chunk in chunks if chunk.choices) == "hello" + assert chunks[-1].usage.total_tokens == 15 + elif ingress == "responses": + responses_stream: Final = await litellm.aresponses(input="hello", **kwargs) + events: Final = [event async for event in responses_stream] + assert "".join(event.delta for event in events if event.type == "response.output_text.delta") == "hello" + assert events[-1].response.usage.total_tokens == 15 + else: + messages_stream: Final = await litellm.anthropic.messages.acreate( + messages=[{"role": "user", "content": "hello"}], max_tokens=128000, **kwargs + ) + wire_events: Final = b"".join([event async for event in messages_stream]).decode() + message_events: Final = [ + json.loads(line[6:]) for line in wire_events.splitlines() if line.startswith("data: ") + ] + assert ( + "".join( + event["delta"].get("text", "") for event in message_events if event["type"] == "content_block_delta" + ) + == "hello" + ) + assert ( + next(event["usage"]["output_tokens"] for event in message_events if event["type"] == "message_delta") + == 5 + ) + + +@pytest.mark.asyncio +@pytest.mark.parametrize("factory_path", [False, True]) +@pytest.mark.parametrize("async_stream", [False, True]) +async def test_gemini_streams_with_dispatcher_and_factory_configs( + go_catalog: None, factory_path: bool, async_stream: bool +) -> None: + messages: Final = [{"role": "user", "content": "hello"}] + logging_obj: Final = Logging( + model="fixture-gemini", + messages=messages, + stream=True, + call_type="acompletion" if async_stream else "completion", + start_time=datetime(2026, 1, 1), + litellm_call_id="go-stream-regression", + function_id="go-stream-regression", + ) + logging_obj.update_environment_variables( + model="fixture-gemini", + user="", + optional_params={"stream_options": {"include_usage": True}}, + litellm_params={}, + custom_llm_provider="opencode_go", + stream_options={"include_usage": True}, + ) + with respx.mock(using="httpx") as transport: + transport.post( + "https://opencode.ai/inference/go/google/v1beta/models/fixture-gemini:streamGenerateContent?alt=sse" + ).respond( + headers={"content-type": "text/event-stream"}, + text="data: " + json.dumps(upstream_reply("gemini", "fixture-gemini")) + "\n\n", + ) + if factory_path: + result: Final = BaseLLMHTTPHandler().completion( + model="fixture-gemini", + messages=messages, + api_base=None, + custom_llm_provider="opencode_go", + model_response=litellm.ModelResponse(), + encoding=None, + logging_obj=logging_obj, + optional_params={"stream_options": {"include_usage": True}}, + timeout=30, + litellm_params={}, + acompletion=async_stream, + stream=True, + api_key="fake-go-key", + ) + else: + completion: Final = litellm.acompletion if async_stream else litellm.completion + result: Final = completion( + model="opencode_go/fixture-gemini", + messages=messages, + stream=True, + stream_options={"include_usage": True}, + api_key="fake-go-key", + ) + if async_stream: + stream: Final = await result + chunks: Final = [chunk async for chunk in stream] + else: + chunks: Final = tuple(result) + assert "".join(chunk.choices[0].delta.content or "" for chunk in chunks if chunk.choices) == "hello" + assert chunks[-1].usage.total_tokens == 15 + + +@pytest.mark.parametrize("suffix", ["", "/v1beta", "/v1beta/models", "/v1beta/models/"]) +def test_gemini_custom_base_normalizes_version_and_models(go_catalog: None, suffix: str) -> None: + with respx.mock(using="httpx") as transport: + transport.post("https://gateway.example/google/v1beta/models/fixture-gemini:generateContent").respond( + json=upstream_reply("gemini", "fixture-gemini") + ) + response: Final = litellm.completion( + model="opencode_go/fixture-gemini", + api_key="fake-go-key", + api_base=f"https://gateway.example/google{suffix}", + messages=[{"role": "user", "content": "hello"}], + ) + assert response.choices[0].message.content == "hello" + + +def test_gemini_sync_stream_preserves_tool_calls_and_usage(go_catalog: None) -> None: + chunk: Final = { + "candidates": [ + { + "content": { + "role": "model", + "parts": [ + { + "functionCall": {"name": "get_weather", "args": {"city": "Paris"}}, + "thoughtSignature": "synthetic-signature", + } + ], + }, + "finishReason": "STOP", + } + ], + "usageMetadata": {"promptTokenCount": 10, "candidatesTokenCount": 5, "totalTokenCount": 15}, + } + with respx.mock(using="httpx") as transport: + transport.post( + "https://opencode.ai/inference/go/google/v1beta/models/fixture-gemini:streamGenerateContent?alt=sse" + ).respond(headers={"content-type": "text/event-stream"}, text="data: " + json.dumps(chunk) + "\n\n") + stream: Final = litellm.completion( + model="opencode_go/fixture-gemini", + api_key="fake-go-key", + stream=True, + messages=[{"role": "user", "content": "Weather in Paris?"}], + tools=[ + { + "type": "function", + "function": { + "name": "get_weather", + "parameters": { + "type": "object", + "properties": {"city": {"type": "string"}}, + "required": ["city"], + }, + }, + } + ], + stream_options={"include_usage": True}, + ) + chunks: Final = tuple(stream) + tool: Final = next( + c.choices[0].delta.tool_calls[0] for c in chunks if c.choices and c.choices[0].delta.tool_calls + ) + assert tool.function.name == "get_weather" + assert json.loads(tool.function.arguments) == {"city": "Paris"} + assert any(c.choices[0].finish_reason == "tool_calls" for c in chunks if c.choices) + assert chunks[-1].usage.total_tokens == 15 + + +GO_REPORTED_USAGE: Final = { + "cost": 0, + "opencode": {"billing_source": "go", "list_cost": 0.00412, "allowance": 0.00412}, +} +ROW_PRICE_FOR_FIXTURE_USAGE: Final = 10 * 0.000002 + 5 * 0.000005 + + +def go_priced_reply(route: str, model: str, usage_extra: Mapping[str, object]) -> Mapping[str, object]: + reply: Final = upstream_reply(route, model) + key: Final = "usageMetadata" if route == "gemini" else "usage" + usage: Final = TypeAdapter(Mapping[str, object]).validate_python(reply[key]) + return {**reply, key: {**usage, **usage_extra}} + + +class CostRecorder(CustomLogger): + def __init__(self) -> None: + super().__init__() + self.costs: list[float | None] = [] # mutable-ok: test probe accumulates logged costs + + async def async_log_success_event(self, kwargs, response_obj, start_time, end_time) -> None: # noqa: ANN001 + self.costs.append(kwargs.get("response_cost")) + + +async def logged_cost(recorder: CostRecorder) -> float | None: + for _ in range(50): + if recorder.costs: + return recorder.costs[-1] + await asyncio.sleep(0.05) + raise AssertionError("success callback never ran") + + +@pytest.fixture +def cost_recorder(monkeypatch: pytest.MonkeyPatch) -> CostRecorder: + recorder: Final = CostRecorder() + monkeypatch.setattr(litellm, "callbacks", [recorder]) + return recorder + + +@pytest.mark.asyncio +@pytest.mark.parametrize("upstream", ["chat/completions", "messages", "responses", "gemini"]) +@pytest.mark.parametrize("ingress", ["chat", "responses"]) +async def test_reported_list_cost_is_billed_instead_of_rows( + go_catalog: None, cost_recorder: CostRecorder, upstream: str, ingress: str +) -> None: + model: Final = f"fixture-{upstream.split('/')[0]}" + with respx.mock(using="httpx") as transport: + transport.post().mock( + return_value=httpx.Response(200, json=go_priced_reply(upstream, model, GO_REPORTED_USAGE)) + ) + kwargs: Final = {"model": f"opencode_go/{model}", "api_key": "fake-go-key"} + if ingress == "chat": + response: Final = await litellm.acompletion(messages=[{"role": "user", "content": "hello"}], **kwargs) + else: + response = await litellm.aresponses(input="hello", **kwargs) + assert response._hidden_params["additional_headers"][RESPONSE_COST_HEADER] == pytest.approx(0.00412) + assert await logged_cost(cost_recorder) == pytest.approx(0.00412) + + +@pytest.mark.asyncio +@pytest.mark.parametrize("usage_extra", [{}, {"cost": 0}, {"opencode": {"billing_source": "go"}}]) +async def test_rows_price_the_request_when_no_list_cost_is_reported( + go_catalog: None, cost_recorder: CostRecorder, usage_extra: Mapping[str, object] +) -> None: + with respx.mock(using="httpx") as transport: + transport.post().mock( + return_value=httpx.Response(200, json=go_priced_reply("chat/completions", "fixture-chat", usage_extra)) + ) + response: Final = await litellm.acompletion( + model="opencode_go/fixture-chat", api_key="fake-go-key", messages=[{"role": "user", "content": "hello"}] + ) + assert RESPONSE_COST_HEADER not in response._hidden_params.get("additional_headers", {}) + assert await logged_cost(cost_recorder) == pytest.approx(ROW_PRICE_FOR_FIXTURE_USAGE) + + +def sse(*events: Mapping[str, object]) -> str: + return "".join(f"data: {json.dumps(event)}\n\n" for event in events) + "data: [DONE]\n\n" + + +@pytest.mark.asyncio +async def test_chat_stream_bills_the_final_usage_chunks_list_cost( + go_catalog: None, cost_recorder: CostRecorder +) -> None: + chunk: Final = { + "id": "chatcmpl-test", + "object": "chat.completion.chunk", + "created": 1700000000, + "model": "fixture-chat", + } + with respx.mock(using="httpx") as transport: + transport.post().mock( + return_value=httpx.Response( + 200, + headers={"content-type": "text/event-stream"}, + text=sse( + {**chunk, "choices": [{"index": 0, "delta": {"role": "assistant", "content": "hello"}}]}, + {**chunk, "choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}]}, + { + **chunk, + "choices": [], + "usage": {"prompt_tokens": 10, "completion_tokens": 5, "total_tokens": 15, **GO_REPORTED_USAGE}, + }, + ), + ) + ) + stream: Final = await litellm.acompletion( + model="opencode_go/fixture-chat", + api_key="fake-go-key", + messages=[{"role": "user", "content": "hello"}], + stream=True, + stream_options={"include_usage": True}, + ) + chunks: Final = [piece async for piece in stream] + assert "".join(piece.choices[0].delta.content or "" for piece in chunks if piece.choices) == "hello" + assert await logged_cost(cost_recorder) == pytest.approx(0.00412) + + +@pytest.mark.asyncio +async def test_responses_stream_bills_the_completed_events_list_cost( + go_catalog: None, cost_recorder: CostRecorder +) -> None: + completed: Final = go_priced_reply("responses", "fixture-responses", GO_REPORTED_USAGE) + with respx.mock(using="httpx") as transport: + transport.post().mock( + return_value=httpx.Response( + 200, + headers={"content-type": "text/event-stream"}, + text=sse( + { + "type": "response.output_text.delta", + "delta": "hello", + "item_id": "msg_test", + "output_index": 0, + "content_index": 0, + "sequence_number": 1, + }, + {"type": "response.completed", "response": completed, "sequence_number": 2}, + ), + ) + ) + stream: Final = await litellm.aresponses( + model="opencode_go/fixture-responses", api_key="fake-go-key", input="hello", stream=True + ) + events: Final = [event async for event in stream] + assert events[-1].type == "response.completed" + assert events[-1].response._hidden_params["additional_headers"][RESPONSE_COST_HEADER] == pytest.approx(0.00412) + assert await logged_cost(cost_recorder) == pytest.approx(0.00412) + + +def test_stream_chunk_builder_reads_list_cost_from_dict_chunks(): + from litellm.litellm_core_utils.litellm_logging import Logging + + logging_obj = Logging( + model="opencode_go/glm-5.3", + messages=[{"role": "user", "content": "hi"}], + stream=True, + call_type="completion", + start_time=datetime.now(), + litellm_call_id="dict-chunks", + function_id="1", + ) + logging_obj.model_call_details["custom_llm_provider"] = "opencode_go" + chunk = { + "id": "chatcmpl-go", + "object": "chat.completion.chunk", + "created": 1, + "model": "glm-5.3", + "choices": [{"index": 0, "delta": {"role": "assistant", "content": "ok"}, "finish_reason": "stop"}], + } + final_usage = {**chunk, "choices": [], "usage": dict(GO_REPORTED_USAGE)} + + assembled = litellm.stream_chunk_builder(chunks=[chunk, final_usage], logging_obj=logging_obj) + + assert assembled is not None + assert assembled._hidden_params["response_cost"] == GO_REPORTED_USAGE["opencode"]["list_cost"] diff --git a/tests/unit/llms/pass_through/guardrail_translation/test_handler.py b/tests/unit/llms/pass_through/guardrail_translation/test_handler.py index 0dba0d7b90f..7cbabb95931 100644 --- a/tests/unit/llms/pass_through/guardrail_translation/test_handler.py +++ b/tests/unit/llms/pass_through/guardrail_translation/test_handler.py @@ -19,6 +19,22 @@ def test_full_payload_guardrail_text_excludes_the_server_streaming_marker(): assert json.loads(text) == body, text +def test_full_payload_guardrail_text_excludes_the_injected_litellm_metadata(): + body: Final = {"model": "m", "messages": [{"role": "user", "content": "hi"}], "guardrails": ["g"]} + litellm_metadata: Final = { + "user_api_key_token": "hashed-key", + "user_api_key_user_email": "someone@example.com", + "user_api_key_user_role": "proxy_admin", + } + + text: Final = PassThroughEndpointHandler()._extract_text_for_guardrail( + {**body, "litellm_metadata": litellm_metadata}, + None, + ) + + assert json.loads(text) == body, text + + @pytest.mark.parametrize( "marker", [ diff --git a/tests/unit/proxy/experimental/__init__.py b/tests/unit/llms/runwayml/image_generation/__init__.py similarity index 100% rename from tests/unit/proxy/experimental/__init__.py rename to tests/unit/llms/runwayml/image_generation/__init__.py diff --git a/tests/unit/llms/runwayml/image_generation/test_runway_image_generation_transformation.py b/tests/unit/llms/runwayml/image_generation/test_runway_image_generation_transformation.py new file mode 100644 index 00000000000..7eec9541b98 --- /dev/null +++ b/tests/unit/llms/runwayml/image_generation/test_runway_image_generation_transformation.py @@ -0,0 +1,87 @@ +from typing import Final +from unittest.mock import MagicMock + +import httpx +import pytest + +from litellm.llms.runwayml.image_generation.transformation import RunwayMLImageGenerationConfig +from litellm.types.utils import ImageResponse + +TASK_URL = "https://api.dev.runwayml.com/v1/tasks/task_1" + + +@pytest.mark.respx() +def test_output_dict_with_non_string_values_still_yields_the_image(respx_mock): + respx_mock.get(TASK_URL).respond( + json={ + "id": "task_1", + "status": "SUCCEEDED", + "output": [{"url": "https://cdn.example/image.png", "b64_json": None, "width": 1024}], + }, + status_code=200, + ) + created: Final = httpx.Response( + 200, + json={"id": "task_1", "status": "PENDING"}, + request=httpx.Request( + "POST", "https://api.dev.runwayml.com/v1/text_to_image", headers={"Authorization": "Bearer k"} + ), + ) + + image_response: Final = RunwayMLImageGenerationConfig().transform_image_generation_response( + model="gen4_image", + raw_response=created, + model_response=ImageResponse(), + logging_obj=MagicMock(), + request_data={}, + optional_params={}, + litellm_params={}, + encoding=None, + ) + + assert [image.url for image in image_response.data] == ["https://cdn.example/image.png"] + + +def test_non_object_task_body_raises_the_base_error_class(): + created: Final = httpx.Response( + 200, + json=["unexpected"], + request=httpx.Request( + "POST", "https://api.dev.runwayml.com/v1/text_to_image", headers={"Authorization": "Bearer k"} + ), + ) + + with pytest.raises(AttributeError): + RunwayMLImageGenerationConfig().transform_image_generation_response( + model="gen4_image", + raw_response=created, + model_response=ImageResponse(), + logging_obj=MagicMock(), + request_data={}, + optional_params={}, + litellm_params={}, + encoding=None, + ) + + +@pytest.mark.asyncio +async def test_async_non_object_task_body_raises_the_base_error_class(): + created: Final = httpx.Response( + 200, + json=["unexpected"], + request=httpx.Request( + "POST", "https://api.dev.runwayml.com/v1/text_to_image", headers={"Authorization": "Bearer k"} + ), + ) + + with pytest.raises(AttributeError): + await RunwayMLImageGenerationConfig().async_transform_image_generation_response( + model="gen4_image", + raw_response=created, + model_response=ImageResponse(), + logging_obj=MagicMock(), + request_data={}, + optional_params={}, + litellm_params={}, + encoding=None, + ) diff --git a/tests/unit/llms/tencent/messages/test_tencent_anthropic_messages_transformation.py b/tests/unit/llms/tencent/messages/test_tencent_anthropic_messages_transformation.py index e5bdce9d3e0..b737ad3e9c1 100644 --- a/tests/unit/llms/tencent/messages/test_tencent_anthropic_messages_transformation.py +++ b/tests/unit/llms/tencent/messages/test_tencent_anthropic_messages_transformation.py @@ -1,5 +1,5 @@ import litellm -from litellm.llms.anthropic.pass_through.messages.transformation import ( +from litellm.llms.anthropic.messages.native.transformation import ( AnthropicMessagesConfig, ) from litellm.llms.tencent.messages.transformation import ( diff --git a/tests/unit/llms/test_get_complete_url_trailing_slash.py b/tests/unit/llms/test_get_complete_url_trailing_slash.py index 9118498c2c2..cd778c20d9b 100644 --- a/tests/unit/llms/test_get_complete_url_trailing_slash.py +++ b/tests/unit/llms/test_get_complete_url_trailing_slash.py @@ -145,7 +145,7 @@ API_BASE_IS_THE_FULL_URL: Final[Mapping[str, str]] = MappingProxyType( "searchapi.search.transformation.SearchAPIConfig", "tinyfish.search.transformation.TinyfishSearchConfig", "vertex_ai.text_to_speech.transformation.VertexAITextToSpeechConfig", - "vertex_ai.vertex_ai_partner_models.anthropic.experimental_pass_through.transformation." + "vertex_ai.vertex_ai_partner_models.anthropic.messages.transformation." "VertexAIPartnerModelsAnthropicMessagesConfig", ) } diff --git a/tests/unit/llms/vertex_ai/count_tokens/test_context.py b/tests/unit/llms/vertex_ai/count_tokens/test_context.py index a1643f0f699..b2a0b735b0f 100644 --- a/tests/unit/llms/vertex_ai/count_tokens/test_context.py +++ b/tests/unit/llms/vertex_ai/count_tokens/test_context.py @@ -14,7 +14,7 @@ import pytest from pydantic import JsonValue, TypeAdapter import litellm -from litellm.llms.anthropic.pass_through.adapters.transformation import ( +from litellm.llms.anthropic.messages.adapters.transformation import ( LiteLLMAnthropicMessagesAdapter, truncate_tool_name, ) @@ -622,7 +622,7 @@ async def test_anthropic_view_applies_clear_edits_without_calling_the_compaction with ( patch( - "litellm.llms.anthropic.pass_through.context_management.editors.compact._read_summary_model_setting", + "litellm.llms.anthropic.messages.context_management.editors.compact._read_summary_model_setting", return_value="gemini/gemini-2.5-flash", ), patch.object(litellm, "acompletion", side_effect=AssertionError("count_tokens must not summarize")) as summary, diff --git a/tests/unit/llms/vertex_ai/files/test_vertex_ai_files_handler.py b/tests/unit/llms/vertex_ai/files/test_vertex_ai_files_handler.py index 9b7cd127b83..39310836bf2 100644 --- a/tests/unit/llms/vertex_ai/files/test_vertex_ai_files_handler.py +++ b/tests/unit/llms/vertex_ai/files/test_vertex_ai_files_handler.py @@ -260,87 +260,3 @@ class TestVertexAIFilesHandler: ) assert service_account == '{"type": "service_account", "project_id": "p"}' - - @pytest.mark.asyncio - async def test_afile_content_honors_per_model_bucket_over_env(self, monkeypatch): - """ - Regression for #32640: a batch output written to a per-model gcs_bucket_name must be - readable even when the global GCS_BUCKET_NAME points at a different bucket. Before the - fix the read path resolved the bucket from env only and raised - "file_id bucket does not match the configured storage bucket". - """ - monkeypatch.setenv("GCS_BUCKET_NAME", "env-default-bucket") - monkeypatch.delenv("GCS_PATH_SERVICE_ACCOUNT", raising=False) - - file_id = "gs%3A%2F%2Fmy-model-bucket%2Flitellm-vertex-files%2Fuploads%2Fabc-batch-output.jsonl" - file_content_request = FileContentRequest(file_id=file_id, extra_headers=None, extra_body=None) - - with ( - patch.object(self.handler, "download_gcs_object", new_callable=AsyncMock) as mock_download, - patch.object( - self.handler, - "get_or_create_vertex_instance", - new_callable=AsyncMock, - return_value=object(), - ), - ): - mock_download.return_value = b"batch output" - - result = await self.handler.afile_content( - file_content_request=file_content_request, - vertex_credentials="/model/sa.json", - vertex_project="test-project", - vertex_location="us-central1", - timeout=60.0, - max_retries=0, - litellm_params={ - "gcs_bucket_name": "my-model-bucket", - "vertex_credentials": "/model/sa.json", - }, - ) - - assert isinstance(result, HttpxBinaryResponseContent) - assert result.response.content == b"batch output" - - dynamic_params = mock_download.call_args.kwargs["standard_callback_dynamic_params"] - assert dynamic_params["gcs_bucket_name"] == "my-model-bucket" - assert dynamic_params["gcs_path_service_account"] == "/model/sa.json" - assert mock_download.call_args.kwargs["object_name"] == "litellm-vertex-files/uploads/abc-batch-output.jsonl" - - @pytest.mark.asyncio - async def test_afile_content_reads_without_global_env_bucket(self, monkeypatch): - """ - Regression for #32640: with no global GCS_BUCKET_NAME set, a model-group-level - deployment (per-model gcs_bucket_name) must still be readable. Before the fix the read - path raised "GCS_BUCKET_NAME is not set in the environment". - """ - monkeypatch.delenv("GCS_BUCKET_NAME", raising=False) - monkeypatch.delenv("GCS_PATH_SERVICE_ACCOUNT", raising=False) - - file_id = "gs%3A%2F%2Fmy-model-bucket%2Flitellm-vertex-files%2Fuploads%2Fabc-batch-output.jsonl" - file_content_request = FileContentRequest(file_id=file_id, extra_headers=None, extra_body=None) - - with ( - patch.object(self.handler, "download_gcs_object", new_callable=AsyncMock) as mock_download, - patch.object( - self.handler, - "get_or_create_vertex_instance", - new_callable=AsyncMock, - return_value=object(), - ), - ): - mock_download.return_value = b"batch output" - - result = await self.handler.afile_content( - file_content_request=file_content_request, - vertex_credentials="/model/sa.json", - vertex_project="test-project", - vertex_location="us-central1", - timeout=60.0, - max_retries=0, - litellm_params={"gcs_bucket_name": "my-model-bucket"}, - ) - - assert isinstance(result, HttpxBinaryResponseContent) - dynamic_params = mock_download.call_args.kwargs["standard_callback_dynamic_params"] - assert dynamic_params["gcs_bucket_name"] == "my-model-bucket" diff --git a/tests/unit/llms/vertex_ai/gemini/test_vertex_ai_gemini_transformation.py b/tests/unit/llms/vertex_ai/gemini/test_vertex_ai_gemini_transformation.py index b97724319c7..f3741d2667a 100644 --- a/tests/unit/llms/vertex_ai/gemini/test_vertex_ai_gemini_transformation.py +++ b/tests/unit/llms/vertex_ai/gemini/test_vertex_ai_gemini_transformation.py @@ -2,7 +2,7 @@ import base64 from collections.abc import Sequence from itertools import chain from pathlib import Path -from typing import Final +from typing import Final, Literal import httpx import pytest @@ -1650,10 +1650,28 @@ def test_convert_tool_response_with_base64_image(): assert inline_data["data"] == test_image_base64 -def test_gemini_history_nests_multimodal_tool_response_parts(): - """Full history conversion should not emit sibling inline_data tool result parts.""" - test_image_base64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==" - messages = [ +@pytest.mark.parametrize("provider", ["gemini", "vertex_ai", "vertex_ai_beta"]) +@pytest.mark.parametrize( + "model,nested", + [ + (None, True), + ("gemini-2.5-pro", False), + ("gemini/gemini-2.5-flash", False), + ("vertex_ai/gemini-2.5-flash-lite", False), + ("123456789", False), + ("gemini-3.8-flash", True), + ("gemini/gemini-3.8-flash", True), + ("vertex_ai/gemini-3.8-flash", True), + ("gemini-flash-latest", True), + ], +) +def test_gemini_history_places_tool_media_for_model( + model: str | None, + nested: bool, + provider: Literal["gemini", "vertex_ai", "vertex_ai_beta"], +) -> None: + test_image_base64: Final = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==" + messages: Final = [ {"role": "user", "content": "Get me an image"}, { "role": "assistant", @@ -1679,24 +1697,53 @@ def test_gemini_history_nests_multimodal_tool_response_parts(): "data": test_image_base64, }, }, + { + "type": "file", + "file": {"file_data": "data:application/pdf;base64,JVBERi0xLjQ="}, + }, ], }, + {"role": "user", "content": "Describe the image and file again"}, ] - contents = gemini_convert_messages_with_history(messages=messages) - - tool_response_parts = contents[-1]["parts"] - assert len(tool_response_parts) == 1 - assert "inline_data" not in tool_response_parts[0] - function_response = tool_response_parts[0]["function_response"] - assert function_response["parts"] == [ + contents: Final = ( + gemini_convert_messages_with_history(messages=messages) + if model is None + else transform_request_body( + messages=messages, + model=model, + custom_llm_provider=provider, + optional_params={}, + litellm_params={}, + cached_content=None, + )["contents"] + ) + media_parts: Final = [ { "inline_data": { "data": test_image_base64, "mime_type": "image/png", } - } + }, + {"inline_data": {"data": "JVBERi0xLjQ=", "mime_type": "application/pdf"}}, ] + function_response: Final = { + "name": "get_image", + "response": {"image_ref": "inline"}, + **({"id": "call_get_image"} if model is not None and nested else {}), + **({"parts": media_parts} if nested else {}), + } + assert contents[-2] == { + "role": "user", + "parts": [ + {"function_response": function_response}, + *([] if nested else media_parts), + ], + } + assert contents[-1] == { + "role": "user", + "parts": [{"text": "Describe the image and file again"}], + } def test_convert_tool_response_text_only(): @@ -2795,7 +2842,7 @@ def test_thinking_block_signature_is_not_forwarded_to_gemini() -> None: def test_anthropic_messages_history_replays_to_gemini_without_claude_signature() -> None: from litellm.litellm_core_utils.prompt_templates.factory import _get_dummy_thought_signature - from litellm.llms.anthropic.pass_through.adapters.transformation import LiteLLMAnthropicMessagesAdapter + from litellm.llms.anthropic.messages.adapters.transformation import LiteLLMAnthropicMessagesAdapter thinking: Final = "I should look the weather up before answering." anthropic_messages: Final = [ diff --git a/tests/unit/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py b/tests/unit/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py index 4c3ee9e7ca5..0f5c21d08c7 100644 --- a/tests/unit/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py +++ b/tests/unit/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py @@ -16,9 +16,11 @@ from pydantic import BaseModel import litellm from litellm import ModelResponse, completion, embedding, image_generation from litellm._logging import verbose_logger +from litellm.cost_calculator import batch_cost_calculator from litellm.litellm_core_utils.exception_mapping_utils import exception_type from litellm.litellm_core_utils.get_model_cost_map import GetModelCostMap -from litellm.llms.anthropic.pass_through.messages import handler as anthropic_messages_handler +from litellm.litellm_core_utils.llm_cost_calc.utils import generic_cost_per_token, parse_prompt_tokens_details +from litellm.llms.anthropic.messages.native import handler as anthropic_messages_handler from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler from litellm.llms.gemini.chat.transformation import GoogleAIStudioGeminiConfig from litellm.llms.vertex_ai.common_utils import GEMINI_MAX_ENUM_CHARACTERS, VertexAIError @@ -30,8 +32,9 @@ from litellm.llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini import ( normalize_gemini_speech_config, reject_unknown_gemini_tts_voice_keys, ) +from litellm.types.llms.base import CachedTokensDetails from litellm.types.llms.vertex_ai import GeminiFinishReason, RequestBody, UsageMetadata -from litellm.types.utils import ChoiceLogprobs, Usage +from litellm.types.utils import ChoiceLogprobs, ModelInfo, Usage from litellm.utils import _invalidate_model_cost_lowercase_map, CustomStreamWrapper from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER from litellm.integrations.custom_logger import CustomLogger @@ -1515,6 +1518,7 @@ def test_vertex_ai_usage_metadata_accumulates_duplicate_modalities(): v = VertexGeminiConfig() usage_metadata = { "promptTokenCount": 210, + "cachedContentTokenCount": 54, "candidatesTokenCount": 50, "totalTokenCount": 260, "promptTokensDetails": [ @@ -1536,9 +1540,10 @@ def test_vertex_ai_usage_metadata_accumulates_duplicate_modalities(): usage_metadata = UsageMetadata(**usage_metadata) result = v.calculate_usage(completion_response={"usageMetadata": usage_metadata}) - # prompt details are total - cached per modality - assert result.prompt_tokens_details.text_tokens == 16 # 20 - 4 - assert result.prompt_tokens_details.image_tokens == 140 # (90 + 100) - (40 + 10) + assert result.prompt_tokens_details.text_tokens == 20 + assert result.prompt_tokens_details.image_tokens == 190 + assert result.prompt_tokens_details.cached_tokens == 54 + assert result.prompt_tokens_details.cached_tokens_details == CachedTokensDetails(text_tokens=4, image_tokens=50) # candidates details accumulate duplicate modalities assert result.completion_tokens_details.text_tokens == 20 # 15 + 5 @@ -1546,6 +1551,118 @@ def test_vertex_ai_usage_metadata_accumulates_duplicate_modalities(): assert result.completion_tokens == 50 +def _gemini_usage_with_cached_audio(cached_audio_tokens: int) -> Usage: + cache_tokens_details: Final = ( + ( + {"modality": "TEXT", "tokenCount": 5}, + {"modality": "AUDIO", "tokenCount": cached_audio_tokens}, + ) + if cached_audio_tokens > 0 + else ({"modality": "TEXT", "tokenCount": 5},) + ) + completion_response: Final = { + "usageMetadata": { + "promptTokenCount": 40, + "cachedContentTokenCount": 5 + cached_audio_tokens, + "promptTokensDetails": ( + {"modality": "TEXT", "tokenCount": 20}, + {"modality": "AUDIO", "tokenCount": 20}, + ), + "cacheTokensDetails": cache_tokens_details, + "candidatesTokenCount": 7, + "totalTokenCount": 47, + } + } + return VertexGeminiConfig.calculate_usage(completion_response=completion_response) + + +def test_gemini_raw_usage_metadata_prices_cached_audio_at_its_batch_rate() -> None: + model_info: Final[ModelInfo] = { + "input_cost_per_token": 2e-6, + "input_cost_per_token_batches": 1e-6, + "input_cost_per_audio_token": 6e-6, + "input_cost_per_audio_token_batches": 3e-6, + "cache_read_input_token_cost": 8e-7, + "cache_read_input_token_cost_batches": 4e-7, + "cache_read_input_audio_token_cost": 5e-7, + "cache_read_input_audio_token_cost_batches": 2e-7, + } + usage: Final = _gemini_usage_with_cached_audio(5) + expected_prompt_cost: Final = ( + 15 * model_info["input_cost_per_token_batches"] + + 15 * model_info["input_cost_per_audio_token_batches"] + + 5 * model_info["cache_read_input_token_cost_batches"] + + 5 * model_info["cache_read_input_audio_token_cost_batches"] + ) + + prompt_cost, _ = batch_cost_calculator( + usage=usage, + model="gemini-audio-batch-test-model", + custom_llm_provider="gemini", + model_info=model_info, + ) + + assert prompt_cost == pytest.approx(expected_prompt_cost) + + +def test_gemini_raw_usage_metadata_prices_cached_audio_at_its_standard_rate() -> None: + model_info: Final[ModelInfo] = { + "input_cost_per_token": 2e-6, + "input_cost_per_audio_token": 6e-6, + "cache_read_input_token_cost": 8e-7, + "cache_read_input_audio_token_cost": 5e-7, + } + usage: Final = _gemini_usage_with_cached_audio(5) + expected_prompt_cost: Final = ( + 15 * model_info["input_cost_per_token"] + + 15 * model_info["input_cost_per_audio_token"] + + 5 * model_info["cache_read_input_token_cost"] + + 5 * model_info["cache_read_input_audio_token_cost"] + ) + + prompt_cost, _ = generic_cost_per_token( + model="gemini-audio-standard-test-model", + usage=usage, + custom_llm_provider="gemini", + model_info=model_info, + ) + + assert prompt_cost == pytest.approx(expected_prompt_cost) + + +def test_gemini_usage_totals_are_subtracted_once_and_audio_cache_rate_matches_audio_rate() -> None: + model_info: Final[ModelInfo] = { + "input_cost_per_token": 2e-6, + "input_cost_per_audio_token": 6e-6, + "cache_read_input_token_cost": 8e-7, + "cache_read_input_audio_token_cost": 6e-6, + } + cached_usage: Final = _gemini_usage_with_cached_audio(5) + uncached_usage: Final = _gemini_usage_with_cached_audio(0) + cached_details: Final = parse_prompt_tokens_details(cached_usage) + cached_prompt_cost, _ = generic_cost_per_token( + model="gemini-audio-standard-test-model", + usage=cached_usage, + custom_llm_provider="gemini", + model_info=model_info, + ) + uncached_prompt_cost, _ = generic_cost_per_token( + model="gemini-audio-standard-test-model", + usage=uncached_usage, + custom_llm_provider="gemini", + model_info=model_info, + ) + + assert cached_usage.prompt_tokens_details.text_tokens == 20 + assert cached_usage.prompt_tokens_details.audio_tokens == 20 + assert cached_usage.prompt_tokens_details.cached_tokens_details == CachedTokensDetails( + text_tokens=5, audio_tokens=5 + ) + assert cached_details["text_tokens"] == 15 + assert cached_details["audio_tokens"] == 15 + assert cached_prompt_cost == pytest.approx(uncached_prompt_cost) + + def test_vertex_ai_map_thinking_param_with_budget_tokens_0(): """ If budget_tokens is 0, do not set includeThoughts to True @@ -6150,7 +6267,7 @@ def test_vertex_ai_usage_metadata_with_document_tokens_in_prompt(): def test_vertex_ai_usage_metadata_with_document_tokens_cached(): - """Test that cached DOCUMENT tokens are correctly subtracted from prompt text tokens.""" + """Test cached DOCUMENT token details and unchanged prompt cost.""" v = VertexGeminiConfig() usage_metadata_dict = { @@ -6174,10 +6291,24 @@ def test_vertex_ai_usage_metadata_with_document_tokens_cached(): completion_response = {"usageMetadata": usage_metadata_dict} result = v.calculate_usage(completion_response=completion_response) - # DOCUMENT cached tokens map to cached_text_tokens, so: - # text_tokens = (8 TEXT + 774 DOCUMENT) - 400 cached = 382 - assert result.prompt_tokens_details.text_tokens == 382, "text_tokens should be (8 + 774) - 400 cached = 382" + assert result.prompt_tokens_details.text_tokens == 782 assert result.prompt_tokens_details.cached_tokens == 400 + assert result.prompt_tokens_details.cached_tokens_details.text_tokens == 400 + + model_info: Final[ModelInfo] = { + "input_cost_per_token": 2e-6, + "cache_read_input_token_cost": 5e-7, + } + prompt_cost, _ = generic_cost_per_token( + model="gemini-document-cache-test-model", + usage=result, + custom_llm_provider="gemini", + model_info=model_info, + ) + + assert prompt_cost == pytest.approx( + 382 * model_info["input_cost_per_token"] + 400 * model_info["cache_read_input_token_cost"] + ) def test_async_streaming_uses_custom_client(): @@ -7413,7 +7544,7 @@ def test_gemini_candidate_with_finish_reason_no_content_chat_completion(): def test_gemini_candidate_with_finish_reason_no_content_anthropic_messages(): - from litellm.llms.anthropic.pass_through.adapters.transformation import ( + from litellm.llms.anthropic.messages.adapters.transformation import ( LiteLLMAnthropicMessagesAdapter, ) @@ -7486,7 +7617,7 @@ def test_gemini_candidate_with_finish_reason_no_content_responses_api(): def test_gemini_candidate_other_finish_reasons_no_content(): - from litellm.llms.anthropic.pass_through.adapters.transformation import ( + from litellm.llms.anthropic.messages.adapters.transformation import ( LiteLLMAnthropicMessagesAdapter, ) from litellm.responses.litellm_completion_transformation.transformation import ( diff --git a/tests/unit/llms/vertex_ai/rerank/test_vertex_ai_rerank_transformation.py b/tests/unit/llms/vertex_ai/rerank/test_vertex_ai_rerank_transformation.py index 630b2e1eb34..8abd012f9d8 100644 --- a/tests/unit/llms/vertex_ai/rerank/test_vertex_ai_rerank_transformation.py +++ b/tests/unit/llms/vertex_ai/rerank/test_vertex_ai_rerank_transformation.py @@ -5,13 +5,19 @@ Based on the test patterns from other rerank providers and the current Vertex AI import json import os +from datetime import datetime, timedelta +from typing import Final from unittest.mock import MagicMock, patch import httpx import pytest +import responses +import respx +import litellm from litellm.llms.vertex_ai.rerank.transformation import VertexAIRerankConfig from litellm.types.rerank import RerankResponse +from litellm.utils import ProviderConfigManager class TestVertexAIRerankTransform: @@ -646,3 +652,83 @@ class TestVertexAIRerankTransform: second_call = mock_ensure_access_token.call_args_list[1] assert first_call.kwargs["credentials"] == "path/to/credentials.json" assert second_call.kwargs["credentials"] == "path/to/credentials.json" + + +@pytest.fixture +def clear_vertex_rerank_cache(request: pytest.FixtureRequest) -> None: + ProviderConfigManager._get_vertex_ai_rerank_config_cached.cache_clear() + request.addfinalizer( + ProviderConfigManager._get_vertex_ai_rerank_config_cached.cache_clear + ) + + +@pytest.mark.asyncio +@pytest.mark.usefixtures("clear_vertex_rerank_cache") +@pytest.mark.parametrize("is_async", [False, True], ids=["sync", "async"]) +async def test_rerank_reuses_scoped_credentials_and_refreshes_expired_tokens( + is_async: bool, +) -> None: + now: Final = datetime(2025, 1, 1) + credentials: Final = tuple( + json.dumps( + { + "type": "authorized_user", + "client_id": identity, + "client_secret": "synthetic-client-secret", + "refresh_token": f"synthetic-refresh-{identity}", + } + ) + for identity in ("first-principal", "second-principal") + ) + with ( + patch("litellm.disable_aiohttp_transport", True), + patch("google.auth._helpers.utcnow", return_value=now) as clock, + responses.RequestsMock(assert_all_requests_are_fired=False) as token_http, + respx.mock as rank_http, + ): + for token in ("initial", "other-credential", "other-project", "renewed"): + token_http.post( + "https://oauth2.googleapis.com/token", + json={"access_token": token, "expires_in": 3600, "token_type": "Bearer"}, + ) + rank_http.post( + url__regex=r"https://discoveryengine\.googleapis\.com/v1/projects/[^/]+/" + r"locations/global/rankingConfigs/default_ranking_config:rank" + ).respond(200, json={"records": [{"id": "0", "score": 0.9}]}) + + async def rank( + credential: str, project: str, expected_token: str, refresh_count: int + ) -> None: + params: Final = { + "model": "vertex_ai/semantic-ranker-default@latest", + "query": f"Query for {expected_token}", + "documents": ["A relevant document"], + "vertex_credentials": credential, + "vertex_project": project, + "caching": False, + "num_retries": 0, + } + result: Final = ( + await litellm.arerank(**params) + if is_async + else litellm.rerank(**params) + ) + assert isinstance(result, RerankResponse) + assert result.results[0]["index"] == 0 + assert len(token_http.calls) == refresh_count + request: Final = rank_http.calls.last.request + assert request.headers["Authorization"] == f"Bearer {expected_token}" + assert request.headers["X-Goog-User-Project"] == project + assert str(request.url) == ( + f"https://discoveryengine.googleapis.com/v1/projects/{project}/" + "locations/global/rankingConfigs/default_ranking_config:rank" + ) + assert json.loads(request.content)["query"] == params["query"] + + await rank(credentials[0], "first-project", "initial", 1) + await rank(credentials[0], "first-project", "initial", 1) + await rank(credentials[1], "first-project", "other-credential", 2) + await rank(credentials[0], "second-project", "other-project", 3) + await rank(credentials[0], "first-project", "initial", 3) + clock.return_value = now + timedelta(hours=2) + await rank(credentials[0], "first-project", "renewed", 4) diff --git a/tests/unit/llms/vertex_ai/test_vertex.py b/tests/unit/llms/vertex_ai/test_vertex.py index 04cf391c700..7e0baaf9e10 100644 --- a/tests/unit/llms/vertex_ai/test_vertex.py +++ b/tests/unit/llms/vertex_ai/test_vertex.py @@ -2461,7 +2461,7 @@ async def test_anthropic_message_via_anthropic_messages( monkeypatch: pytest.MonkeyPatch, ) -> None: monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) - from litellm.llms.vertex_ai.vertex_ai_partner_models.anthropic.experimental_pass_through.transformation import ( + from litellm.llms.vertex_ai.vertex_ai_partner_models.anthropic.messages.transformation import ( VertexAIPartnerModelsAnthropicMessagesConfig, ) from litellm.utils import ProviderConfigManager diff --git a/tests/unit/llms/vertex_ai/test_vertex_llm_base.py b/tests/unit/llms/vertex_ai/test_vertex_llm_base.py index dd2b86b6f81..fa332cef5d8 100644 --- a/tests/unit/llms/vertex_ai/test_vertex_llm_base.py +++ b/tests/unit/llms/vertex_ai/test_vertex_llm_base.py @@ -6,13 +6,17 @@ import os import pathlib import re import traceback -from typing import Final +from datetime import datetime, timedelta +from threading import Event +from typing import Final, Literal from unittest.mock import MagicMock, call, patch import google.auth.exceptions import pytest +import requests +import responses -from litellm.constants import DEFAULT_MAX_RECURSE_DEPTH +from litellm.constants import DEFAULT_MAX_LRU_CACHE_SIZE, DEFAULT_MAX_RECURSE_DEPTH import litellm @@ -2589,3 +2593,120 @@ def test_get_access_token_reraises_malformed_service_account_credentials_without assert [record.getMessage().split(". Error: ")[0] for record in caplog.records] == [ "Failed to load vertex credentials. Check to see if credentials containing partial/invalid information" ] + + +def _authorized_user_cache_credentials(identity: str) -> str: + return json.dumps( + { + "type": "authorized_user", + "client_id": identity, + "client_secret": "synthetic-secret", + "refresh_token": identity, + "quota_project_id": identity, + } + ) + + +@pytest.mark.parametrize("is_async", [False, True], ids=["sync", "async"]) +@pytest.mark.parametrize("inferred_project", [False, True], ids=["explicit", "inferred"]) +@pytest.mark.asyncio +async def test_credential_cache_bounds_retention_and_reloads_least_recently_used( + is_async: bool, inferred_project: bool +) -> None: + vertex: Final = VertexBase() + limit: Final = max(0, DEFAULT_MAX_LRU_CACHE_SIZE) + with ( + patch("google.auth._helpers.utcnow", return_value=datetime(2025, 1, 1)), + responses.RequestsMock() as oauth, + ): + def token_response(request: requests.PreparedRequest) -> tuple[int, dict[str, str], str]: + return 200, {}, json.dumps({"access_token": f"token-{len(oauth.calls) + 1}", "expires_in": 3600}) + + oauth.add_callback(responses.POST, "https://oauth2.googleapis.com/token", callback=token_response) + + async def access(index: int, infer: bool = False) -> tuple[str, str]: + identity: Final = f"project-{index}" + credentials: Final = _authorized_user_cache_credentials(identity) + project: Final = None if infer else identity + result: Final = ( + await vertex.get_access_token_async(credentials, project) + if is_async + else vertex.get_access_token(credentials, project) + ) + assert result[1] == identity + assert len(vertex._credentials_project_mapping) <= limit + return result + + if limit == 0: + assert await access(0, inferred_project) == ("token-1", "project-0") + assert await access(0, inferred_project) == ("token-2", "project-0") + return + + for index in range(limit): + assert await access(index) == (f"token-{index + 1}", f"project-{index}") + assert await access(0) == ("token-1", "project-0") + assert len(oauth.calls) == limit + assert await access(limit, inferred_project) == (f"token-{limit + 1}", f"project-{limit}") + assert len(oauth.calls) == limit + 1 + if limit > (2 if inferred_project else 1): + assert await access(0) == ("token-1", "project-0") + assert len(oauth.calls) == limit + 1 + evicted: Final = 1 if limit > 1 else 0 + assert await access(evicted) == (f"token-{limit + 2}", f"project-{evicted}") + assert len(oauth.calls) == limit + 2 + + +@pytest.mark.parametrize("mode", ["sync", "async", "background"]) +@pytest.mark.skipif(DEFAULT_MAX_LRU_CACHE_SIZE < 2, reason="Eviction during refresh requires two retained entries") +@pytest.mark.asyncio +async def test_evicted_credentials_finish_refresh_without_being_readmitted( + mode: Literal["sync", "async", "background"], +) -> None: + vertex: Final = VertexBase() + limit: Final = DEFAULT_MAX_LRU_CACHE_SIZE + now: Final = datetime(2025, 1, 1) + refresh_started: Final = Event() + release_refresh: Final = Event() + donor: Final = _authorized_user_cache_credentials("donor") + target: Final = _authorized_user_cache_credentials("target") + with patch("google.auth._helpers.utcnow", return_value=now) as clock, responses.RequestsMock() as oauth: + def token_response(request: requests.PreparedRequest) -> tuple[int, dict[str, str], str]: + body: Final = request.body.decode() if isinstance(request.body, bytes) else request.body + assert isinstance(body, str) + is_target: Final = "refresh_token=target" in body + if is_target and len(oauth.calls) == limit: + refresh_started.set() + assert release_refresh.wait(5), "OAuth refresh was not released" + return 200, {}, json.dumps( + {"access_token": f"token-{len(oauth.calls) + 1}", "expires_in": 3600 if is_target else 86400} + ) + + oauth.add_callback(responses.POST, "https://oauth2.googleapis.com/token", callback=token_response) + assert vertex.get_access_token(donor, None) == ("token-1", "donor") + assert vertex.get_access_token(donor, None) == ("token-1", "donor") + for index in range(limit - 2): + assert vertex.get_access_token(donor, f"filler-{index}") == (f"token-{index + 2}", f"filler-{index}") + assert vertex.get_access_token(target, "target") == (f"token-{limit}", "target") + clock.return_value = now + timedelta(seconds=3550 if mode == "background" else 7200) + refresh: Final = asyncio.create_task( + asyncio.to_thread(vertex.get_access_token, target, "target") + if mode == "sync" + else vertex.get_access_token_async(target, "target") + ) + try: + assert await asyncio.to_thread(refresh_started.wait, 5), "OAuth refresh did not start" + for index in range(limit - 2): + assert vertex.get_access_token(donor, f"filler-{index}") == (f"token-{index + 2}", f"filler-{index}") + assert vertex.get_access_token(donor, None) == ("token-1", "donor") + assert len(vertex._credentials_project_mapping) == limit + assert (target, "target") not in vertex._credentials_project_mapping + finally: + release_refresh.set() + completed: Final = await refresh + await asyncio.gather(*tuple(vertex._background_refresh_tasks.values())) + expected_token: Final = f"token-{limit if mode == 'background' else limit + 1}" + assert completed == (expected_token, "target") + assert len(oauth.calls) == limit + 1 + assert (target, "target") not in vertex._credentials_project_mapping + assert vertex.get_access_token(target, "target") == (f"token-{limit + 2}", "target") + assert len(vertex._credentials_project_mapping) == limit diff --git a/tests/unit/proxy/experimental/mcp_server/__init__.py b/tests/unit/llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/__init__.py similarity index 100% rename from tests/unit/proxy/experimental/mcp_server/__init__.py rename to tests/unit/llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/__init__.py diff --git a/tests/unit/llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/test_experimental_pass_through_shim.py b/tests/unit/llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/test_experimental_pass_through_shim.py new file mode 100644 index 00000000000..4860b5dbe7e --- /dev/null +++ b/tests/unit/llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/test_experimental_pass_through_shim.py @@ -0,0 +1,20 @@ +import importlib +import sys +from typing import Final + +import pytest + +OLD_PACKAGE: Final = "litellm.llms.vertex_ai.vertex_ai_partner_models.anthropic.experimental_pass_through" +NEW_PACKAGE: Final = "litellm.llms.vertex_ai.vertex_ai_partner_models.anthropic.messages" + + +def test_old_deep_import_is_the_new_module_object_and_warns(monkeypatch: pytest.MonkeyPatch) -> None: + for name in tuple(sys.modules): + if name == OLD_PACKAGE or name.startswith(OLD_PACKAGE + "."): + monkeypatch.delitem(sys.modules, name) + with pytest.warns(DeprecationWarning, match=NEW_PACKAGE): + old_transformation = importlib.import_module(f"{OLD_PACKAGE}.transformation") + from litellm.llms.vertex_ai.vertex_ai_partner_models.anthropic.messages import transformation + + assert old_transformation is transformation + assert sys.modules[f"{OLD_PACKAGE}.transformation"] is sys.modules[f"{NEW_PACKAGE}.transformation"] diff --git a/tests/unit/llms/vertex_ai/vertex_ai_partner_models/anthropic/test_vertex_ai_partner_models_anthropic_messages_config.py b/tests/unit/llms/vertex_ai/vertex_ai_partner_models/anthropic/test_vertex_ai_partner_models_anthropic_messages_config.py index ae9b9684f2d..6c10d524531 100644 --- a/tests/unit/llms/vertex_ai/vertex_ai_partner_models/anthropic/test_vertex_ai_partner_models_anthropic_messages_config.py +++ b/tests/unit/llms/vertex_ai/vertex_ai_partner_models/anthropic/test_vertex_ai_partner_models_anthropic_messages_config.py @@ -2,18 +2,98 @@ import copy import json import os from collections.abc import Mapping +from datetime import datetime, timedelta +from queue import SimpleQueue +from threading import get_ident from typing import Final from unittest.mock import MagicMock, patch import pytest +import requests +import responses -from litellm.llms.vertex_ai.vertex_ai_partner_models.anthropic.experimental_pass_through.transformation import ( +from litellm.llms.vertex_ai.vertex_ai_partner_models.anthropic.messages.transformation import ( VertexAIPartnerModelsAnthropicMessagesConfig, ) from litellm.llms.vertex_ai.vertex_ai_partner_models.main import VertexAIPartnerModels +from litellm.types.llms.anthropic import ANTHROPIC_BETA_HEADER_VALUES, ANTHROPIC_HOSTED_TOOLS from litellm.types.router import GenericLiteLLMParams +@pytest.mark.parametrize("stream", (False, True)) +@pytest.mark.parametrize("infer_project", (False, True), ids=("explicit-project", "credential-project")) +@pytest.mark.asyncio +async def test_messages_auth_load_and_refresh_leave_the_event_loop(stream: bool, infer_project: bool) -> None: + config: Final = VertexAIPartnerModelsAnthropicMessagesConfig() + loop_thread: Final = get_ident() + token_threads: Final[SimpleQueue[int]] = SimpleQueue() + now: Final = datetime(2025, 1, 1) + model: Final = "claude-sonnet-5" + headers: Final = {"Authorization": "Bearer incoming", "anthropic-beta": "retained-beta", "x-request-id": "req-1"} + optional_params: Final = { + "stream": stream, + "tools": [{"type": ANTHROPIC_HOSTED_TOOLS.WEB_SEARCH.value, "name": "web_search"}], + } + litellm_params: Final = { + "vertex_ai_project": None if infer_project else "auth-project", + "vertex_ai_location": "global", + "vertex_credentials": json.dumps( + { + "type": "authorized_user", + "client_id": "synthetic-client", + "client_secret": "synthetic-secret", + "refresh_token": "synthetic-refresh", + "quota_project_id": "auth-project", + } + ), + } + + async def validate() -> tuple[Mapping[str, object], str | None]: + return await config.avalidate_anthropic_messages_environment( + headers=headers, model=model, messages=[], optional_params=optional_params, litellm_params=litellm_params + ) + + with patch("google.auth._helpers.utcnow", return_value=now) as clock, responses.RequestsMock() as oauth: + + def token_response(_request: requests.PreparedRequest) -> tuple[int, dict[str, str], str]: + token_threads.put(get_ident()) + return 200, {}, json.dumps({"access_token": f"token-{len(oauth.calls) + 1}", "expires_in": 3600}) + + oauth.add_callback(responses.POST, "https://oauth2.googleapis.com/token", callback=token_response) + cold_headers, cold_url = await validate() + assert token_threads.get_nowait() != loop_thread + assert cold_headers["Authorization"] == "Bearer token-1" + assert await validate() == (cold_headers, cold_url) + assert len(oauth.calls) == 1 + + clock.return_value = now + timedelta(hours=2) + refreshed_headers, refreshed_url = await validate() + assert token_threads.get_nowait() != loop_thread + assert refreshed_headers["Authorization"] == "Bearer token-2" + assert refreshed_url == cold_url + assert len(oauth.calls) == 2 + assert config.validate_anthropic_messages_environment( + headers=headers, model=model, messages=[], optional_params=optional_params, litellm_params=litellm_params + ) == (refreshed_headers, refreshed_url) + assert len(oauth.calls) == 2 + + endpoint: Final = "streamRawPredict" if stream else "rawPredict" + assert cold_url == ( + "https://aiplatform.googleapis.com/v1/projects/auth-project/locations/global/" + f"publishers/anthropic/models/{model}:{endpoint}" + ) + assert refreshed_headers == { + "Authorization": "Bearer token-2", + "anthropic-beta": cold_headers["anthropic-beta"], + "x-request-id": "req-1", + "content-type": "application/json", + } + beta_header: Final = cold_headers["anthropic-beta"] + assert isinstance(beta_header, str) + assert set(beta_header.split(",")) == {"retained-beta", ANTHROPIC_BETA_HEADER_VALUES.WEB_SEARCH_2025_03_05.value} + assert headers == {"Authorization": "Bearer incoming", "anthropic-beta": "retained-beta", "x-request-id": "req-1"} + + def test_validate_environment_uses_vertex_ai_location(): config = VertexAIPartnerModelsAnthropicMessagesConfig() headers = {} diff --git a/tests/unit/llms/vertex_ai/vertex_ai_partner_models/llama/__init__.py b/tests/unit/llms/vertex_ai/vertex_ai_partner_models/llama/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/unit/llms/vertex_ai/vertex_ai_partner_models/llama3/test_vertex_ai_partner_models_llama3_transformation.py b/tests/unit/llms/vertex_ai/vertex_ai_partner_models/llama/test_vertex_ai_partner_models_llama_transformation.py similarity index 98% rename from tests/unit/llms/vertex_ai/vertex_ai_partner_models/llama3/test_vertex_ai_partner_models_llama3_transformation.py rename to tests/unit/llms/vertex_ai/vertex_ai_partner_models/llama/test_vertex_ai_partner_models_llama_transformation.py index 05e4e36edd7..72efd7b66b0 100644 --- a/tests/unit/llms/vertex_ai/vertex_ai_partner_models/llama3/test_vertex_ai_partner_models_llama3_transformation.py +++ b/tests/unit/llms/vertex_ai/vertex_ai_partner_models/llama/test_vertex_ai_partner_models_llama_transformation.py @@ -5,7 +5,7 @@ import httpx import pytest -from litellm.llms.vertex_ai.vertex_ai_partner_models.llama3.transformation import ( +from litellm.llms.vertex_ai.vertex_ai_partner_models.llama.transformation import ( VertexAILlama3Config, VertexAILlama3StreamingHandler, ) diff --git a/tests/unit/mcp_client/__init__.py b/tests/unit/mcp_client/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/unit/experimental_mcp_client/test_mcp_client.py b/tests/unit/mcp_client/test_mcp_client.py similarity index 97% rename from tests/unit/experimental_mcp_client/test_mcp_client.py rename to tests/unit/mcp_client/test_mcp_client.py index b4485bcc5f1..43021d248a9 100644 --- a/tests/unit/experimental_mcp_client/test_mcp_client.py +++ b/tests/unit/mcp_client/test_mcp_client.py @@ -49,8 +49,8 @@ from starlette.responses import Response from starlette.types import ASGIApp, Message, Receive, Scope, Send # Add the parent directory to the path so we can import litellm -import litellm.experimental_mcp_client.client as mcp_client_module -from litellm.experimental_mcp_client.client import ( +import litellm.mcp_client.client as mcp_client_module +from litellm.mcp_client.client import ( MCPClient, MCPSigV4Auth, PersistentMCPSession, @@ -61,16 +61,16 @@ from litellm.experimental_mcp_client.client import ( as_mcp_read_timeout, strip_auth_scheme, ) -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( +from litellm.proxy.mcp_server.faults.list_outcomes import ( ServerListFault, classify_list_exception, list_fault_http_status, upstream_rate_limit, ) -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( +from litellm.proxy.mcp_server.mcp_server_manager import ( _format_byok_openapi_auth_header, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth +from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth from litellm.types.mcp import MCPAuth, MCPStdioConfig, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer from tests._support.clock_loops import AutojumpClockLoop, ManualClockLoop @@ -163,7 +163,7 @@ async def test_modern_input_request_uses_existing_elicitation_callback( TextContent, ) - from litellm.proxy._experimental.mcp_server.interactions import BoundInputRequiredResult + from litellm.proxy.mcp_server.interactions import BoundInputRequiredResult observed: Final[SimpleQueue[str]] = SimpleQueue() sampled: Final = CreateMessageResult( @@ -379,8 +379,8 @@ class TestMCPClient: await client.run_with_session(_noop) @pytest.mark.asyncio - @patch("litellm.experimental_mcp_client.client.stdio_client") - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.stdio_client") + @patch("litellm.mcp_client.client.ClientSession") async def test_mcp_client_stdio_connect_success(self, mock_session, mock_stdio_client): """Test successful stdio connection""" # Setup mocks - create proper async context manager @@ -432,7 +432,7 @@ class TestMCPClient: mock_streamable_http_client.return_value = mock_http_ctx # Mock the session - with patch("litellm.experimental_mcp_client.client.ClientSession") as mock_session: + with patch("litellm.mcp_client.client.ClientSession") as mock_session: mock_session_instance = AsyncMock() mock_session_instance.initialize = AsyncMock(return_value=_initialized()) mock_session_ctx = AsyncMock() @@ -478,7 +478,7 @@ class TestMCPClient: mock_sse_client.return_value = mock_sse_ctx # Mock the session - with patch("litellm.experimental_mcp_client.client.ClientSession") as mock_session: + with patch("litellm.mcp_client.client.ClientSession") as mock_session: mock_session_instance = AsyncMock() mock_session_instance.initialize = AsyncMock(return_value=_initialized()) mock_session_ctx = AsyncMock() @@ -530,7 +530,7 @@ class TestMCPClient: mock_streamable_http_client.return_value = mock_http_ctx # Mock the session - with patch("litellm.experimental_mcp_client.client.ClientSession") as mock_session: + with patch("litellm.mcp_client.client.ClientSession") as mock_session: mock_session_instance = AsyncMock() mock_session_instance.initialize = AsyncMock(return_value=_initialized()) mock_session_ctx = AsyncMock() @@ -670,7 +670,7 @@ class TestMCPClientInstructionsCapture: assert client._last_initialize_instructions is None @pytest.mark.asyncio - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_captures_instructions_from_initialize(self, mock_session_cls): """Instructions from upstream initialize() are captured and stripped.""" client = MCPClient( @@ -698,7 +698,7 @@ class TestMCPClientInstructionsCapture: assert client._last_initialize_instructions == "upstream says hello" @pytest.mark.asyncio - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_none_instructions_stays_none(self, mock_session_cls): """When upstream returns no instructions the field stays None.""" client = MCPClient( @@ -787,7 +787,7 @@ class TestExecuteSessionOperationSurfacesTransportError: return transport_ctx @pytest.mark.asyncio - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_surfaces_connect_error_over_cancelled(self, mock_session_cls): client = MCPClient(server_url="http://example.com/mcp", transport_type="http") self._make_session( @@ -804,7 +804,7 @@ class TestExecuteSessionOperationSurfacesTransportError: await client._execute_session_operation(transport_ctx, _op) @pytest.mark.asyncio - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_genuine_cancellation_is_not_replaced(self, mock_session_cls): client = MCPClient(server_url="http://example.com/mcp", transport_type="http") self._make_session(mock_session_cls, AsyncMock(side_effect=asyncio.CancelledError())) @@ -818,7 +818,7 @@ class TestExecuteSessionOperationSurfacesTransportError: @pytest.mark.asyncio @pytest.mark.parametrize("failure_phase", ("early", "late", "mixed")) - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_response_close_preserves_cancellation_and_original_errors(self, session_class, failure_phase): closed: Final = asyncio.Event() close_error: Final = httpx2.ReadError("response close failed") @@ -863,7 +863,7 @@ class TestExecuteSessionOperationSurfacesTransportError: assert closed.is_set() @pytest.mark.asyncio - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_cleanup_error_after_success_is_swallowed(self, mock_session_cls): client = MCPClient(server_url="http://example.com/mcp", transport_type="http") init_result = _initialized() @@ -877,7 +877,7 @@ class TestExecuteSessionOperationSurfacesTransportError: assert result == "done" @pytest.mark.asyncio - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_session_entry_failure_still_closes_transport(self, session_class): failure: Final = RuntimeError("session dispatcher did not start") session_class.return_value.__aenter__ = AsyncMock(side_effect=failure) @@ -896,7 +896,7 @@ class TestExecuteSessionOperationSurfacesTransportError: @pytest.mark.asyncio @pytest.mark.parametrize("original_error", (False, True)) - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_session_exit_cancellation_preserves_original_failure(self, session_class, original_error): self._make_session(session_class, AsyncMock(return_value=_initialized())) cancelled: Final = asyncio.CancelledError("cancelled while closing session") @@ -918,7 +918,7 @@ class TestExecuteSessionOperationSurfacesTransportError: @pytest.mark.asyncio @pytest.mark.parametrize("signal_type", (SystemExit, KeyboardInterrupt)) @pytest.mark.parametrize("phase", ("session", "transport")) - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_cleanup_preserves_process_exit(self, session_class, phase, signal_type): self._make_session(session_class, AsyncMock(return_value=_initialized())) signal: Final = signal_type("process stopping") @@ -932,7 +932,7 @@ class TestExecuteSessionOperationSurfacesTransportError: transport.__aexit__.assert_awaited_once() @pytest.mark.asyncio - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_session_and_termination_share_one_cleanup_deadline(self, session_class): self._make_session(session_class, AsyncMock(return_value=_initialized())) deleting: Final = asyncio.Event() @@ -1835,7 +1835,7 @@ def test_a_differently_cased_injected_header_cannot_shadow_the_slot() -> None: async def test_invalid_http_response_surfaces_without_waiting_for_timeout( content_type: str, body: bytes, expected_type: type[Exception] ) -> None: - from litellm.proxy._experimental.mcp_server.rest_endpoints import _connection_error_message + from litellm.proxy.mcp_server.rest_endpoints import _connection_error_message def respond(request: httpx2.Request) -> httpx2.Response: if expected_type is ValidationError: @@ -1921,9 +1921,65 @@ async def test_list_tools_classifies_upstream_status_for_post_failures(failure_m assert rate_limit is None +@pytest.mark.asyncio +@pytest.mark.parametrize("paginated", (False, True)) +async def test_sse_catalog_limit_reports_the_failure_and_allows_smaller_pages(paginated: bool) -> None: + from mcp.types import Tool + + limit: Final = 1024 + tools: Final = tuple( + Tool(name=f"tool_{index}", description="private-upstream-secret " * 25, input_schema={"type": "object"}) + for index in range(2) + ) + catalog: Final = tuple(tool.model_dump(by_alias=True, exclude_none=True) for tool in tools) + assert len(json.dumps({"tools": catalog}).encode()) > limit + + def respond(request: httpx2.Request) -> httpx2.Response: + if request.method != "POST": + return httpx2.Response(200) + payload: Final = _JSONRPC_MESSAGE_ADAPTER.validate_json(request.content) + assert isinstance(payload, (JSONRPCRequest, JSONRPCNotification)) + if isinstance(payload, JSONRPCNotification): + return httpx2.Response(202) + if payload.method == "initialize": + return httpx2.Response(200, json={ + "jsonrpc": "2.0", "id": payload.id, "result": { + "protocolVersion": LATEST_HANDSHAKE_VERSION, + "capabilities": {"tools": {}}, "serverInfo": {"name": "catalog", "version": "1"}, + }, + }) + assert payload.method == "tools/list" + cursor: Final = (payload.params or {}).get("cursor") + page: Final = catalog[1:] if cursor == "next-page" else catalog[:1] if paginated else catalog + result: Final = { + "tools": page, + **({"nextCursor": "next-page"} if paginated and cursor is None else {}), + } + event: Final = f"data: {json.dumps({'jsonrpc': '2.0', 'id': payload.id, 'result': result})}\n\n" + assert (len(event.encode()) < limit) == paginated + return httpx2.Response(200, headers={"content-type": "text/event-stream"}, content=event) + + def transport_context(url: str, http_client: httpx2.AsyncClient) -> _TransportContext: + return streamable_http_client(url, http_client=http_client, max_sse_event_size=limit) + + client: Final = _MockTransportClient( + respond, server_url="https://upstream.example/mcp", transport_context=transport_context, + ) + if paginated: + assert await client.list_tools(raise_on_error=True) == list(tools) + return + with pytest.raises(MCPError) as caught: + await client.list_tools(raise_on_error=True) + fault: Final = classify_list_exception(caught.value) + assert fault == ServerListFault(tag="upstream_error", sse_event_limit_bytes=limit) + assert list_fault_http_status(fault) == 502 + assert fault.public_message is not None + assert "private-upstream-secret" not in fault.public_message + + @pytest.mark.asyncio async def test_http_status_check_allows_auth_refresh_before_rejecting() -> None: - from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.client_credentials import ( ClientCredentialsBearerAuth, ) @@ -1937,7 +1993,7 @@ async def test_http_status_check_allows_auth_refresh_before_rejecting() -> None: seen.append(request.headers["authorization"]) return httpx2.Response(401 if len(seen) == 1 else 200, json={"ok": True}) - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ClientCredentialsConfig + from litellm.proxy.mcp_server.outbound_credentials.types import ClientCredentialsConfig auth = ClientCredentialsBearerAuth("stale", refresh, ClientCredentialsConfig()) client = MCPClient(server_url="https://example.com/mcp", resolved_auth=auth) @@ -2001,7 +2057,7 @@ async def test_http_response_handler_preserves_notifications_and_tool_listing() @pytest.mark.asyncio async def test_invalid_tool_list_schema_is_identified_as_an_upstream_response() -> None: - from litellm.proxy._experimental.mcp_server.rest_endpoints import _connection_error_message + from litellm.proxy.mcp_server.rest_endpoints import _connection_error_message def respond(request: httpx2.Request) -> httpx2.Response: if request.method == "DELETE": @@ -2193,7 +2249,7 @@ async def test_transport_completion_and_normal_messages( ) -> None: from mcp import ClientSession - from litellm.proxy._experimental.mcp_server.rest_endpoints import _connection_error_message + from litellm.proxy.mcp_server.rest_endpoints import _connection_error_message logging_callback: Final = AsyncMock() read_timeout: Final = 0.2 if mode == "silent" else 30 @@ -2791,7 +2847,7 @@ def test_standalone_client_request_does_not_require_proxy_dependencies(): for name in ("fastapi", "orjson", "email_validator", "annotated_doc"): sys.modules[name] = None import httpx2 - from litellm.experimental_mcp_client.client import MCPClient + from litellm.mcp_client.client import MCPClient async def request(): upstream = MCPClient(server_url="https://upstream.example/mcp") @@ -2816,7 +2872,7 @@ def test_client_import_before_proxy_credentials_succeeds_in_fresh_process(): [ sys.executable, "-c", - "import litellm.experimental_mcp_client.client; from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager; print(MCPServerManager.__name__)", + "import litellm.mcp_client.client; from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager; print(MCPServerManager.__name__)", ], capture_output=True, text=True, @@ -2830,7 +2886,7 @@ def test_client_import_before_proxy_credentials_succeeds_in_fresh_process(): @pytest.mark.asyncio @pytest.mark.parametrize("resolved", (False, True)) async def test_discovery_auth_fingerprint_tracks_effective_credentials(resolved: bool) -> None: - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth def client(token: str) -> MCPClient: return MCPClient( @@ -2876,7 +2932,7 @@ async def test_discovery_auth_fingerprint_tracks_aws_sigv4_credential_identity() @pytest.mark.asyncio async def test_request_auth_preview_uses_the_same_effective_headers_as_egress() -> None: - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth client: Final = MCPClient( server_url="https://upstream.example/mcp", @@ -2971,11 +3027,11 @@ async def test_404_before_session_initialization_preserves_method_not_found() -> def test_public_mcp_import_missing_dependency(missing_module: str) -> None: with patch.dict(sys.modules): for name in tuple(sys.modules): - if name.startswith(("litellm.experimental_mcp_client", "mcp.", "mcp_types.")) or name == "mcp": + if name.startswith(("litellm.mcp_client", "mcp.", "mcp_types.")) or name == "mcp": del sys.modules[name] with patch.dict(sys.modules, {missing_module: None}): with pytest.raises(ImportError) as caught: - importlib.import_module("litellm.experimental_mcp_client.client") + importlib.import_module("litellm.mcp_client.client") if missing_module in ("mcp", "httpx2"): assert "pip install 'litellm[mcp]'" in str(caught.value) @@ -2991,11 +3047,11 @@ def test_public_mcp_import_missing_dependency(missing_module: str) -> None: def test_public_mcp_import_preserves_incompatible_sdk_error() -> None: with patch.dict(sys.modules): for name in tuple(sys.modules): - if name.startswith("litellm.experimental_mcp_client"): + if name.startswith("litellm.mcp_client"): del sys.modules[name] with patch.dict(sys.modules, {"mcp": ModuleType("mcp")}): with pytest.raises(ImportError, match="cannot import name 'ClientSession'") as caught: - importlib.import_module("litellm.experimental_mcp_client.client") + importlib.import_module("litellm.mcp_client.client") assert not isinstance(caught.value, ModuleNotFoundError) assert caught.value.__cause__ is None @@ -3579,7 +3635,7 @@ async def test_modern_call_requires_schema_from_bounded_listing( from mcp.types import ToolsCapability - monkeypatch.setattr("litellm.experimental_mcp_client.tools.MCP_TOOL_LISTING_MAX_PAGES", 2) + monkeypatch.setattr("litellm.mcp_client.tools.MCP_TOOL_LISTING_MAX_PAGES", 2) methods: Final[SimpleQueue[str]] = SimpleQueue() def respond(request: httpx2.Request) -> httpx2.Response: @@ -4991,7 +5047,7 @@ async def test_persistent_session_reports_an_upstream_cancellation_as_a_runtime_ @pytest.mark.asyncio async def test_closing_persistent_session_fails_a_caller_blocked_on_a_full_queue_instead_of_hanging() -> None: - from litellm.experimental_mcp_client.client import _MAX_PENDING_OPERATIONS + from litellm.mcp_client.client import _MAX_PENDING_OPERATIONS app: Final = _stateful_upstream() async with app.router.lifespan_context(app): @@ -5033,8 +5089,9 @@ async def test_persistent_session_ends_after_a_broken_stream_so_the_next_call_ge @pytest.mark.parametrize("session_started_in_request", [True, False]) async def test_persistent_session_releases_the_current_requests_scope_response(session_started_in_request) -> None: from mcp.server.context import ServerRequestContext - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var - from litellm.proxy._experimental.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse + + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse app = _stateful_upstream() async with app.router.lifespan_context(app): @@ -5149,8 +5206,8 @@ async def test_cancelling_persistent_operation_stops_work_and_keeps_session_usab @pytest.mark.asyncio @pytest.mark.parametrize("header_name", ["Authorization", "x-upstream-token"]) async def test_subscription_fingerprint_preserves_context_across_managed_renewal(header_name): - from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import ClientCredentialsBearerAuth - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ClientCredentialsConfig + from litellm.proxy.mcp_server.outbound_credentials.client_credentials import ClientCredentialsBearerAuth + from litellm.proxy.mcp_server.outbound_credentials.types import ClientCredentialsConfig async def refetch(token: str) -> str | None: return None @@ -5178,7 +5235,7 @@ async def test_subscription_fingerprint_preserves_context_across_managed_renewal @pytest.mark.asyncio async def test_notification_callback_keeps_stream_errors_separate_from_protocol_errors() -> None: - from litellm.experimental_mcp_client.client import _receive_session_message + from litellm.mcp_client.client import _receive_session_message stream_error = asyncio.get_running_loop().create_future() receiver = AsyncMock() diff --git a/tests/unit/experimental_mcp_client/test_tools.py b/tests/unit/mcp_client/test_tools.py similarity index 96% rename from tests/unit/experimental_mcp_client/test_tools.py rename to tests/unit/mcp_client/test_tools.py index ac7afe4c74b..ca3cf29bd90 100644 --- a/tests/unit/experimental_mcp_client/test_tools.py +++ b/tests/unit/mcp_client/test_tools.py @@ -2,8 +2,6 @@ import json from unittest.mock import AsyncMock, MagicMock import pytest - - from mcp.types import ( CallToolRequestParams, CallToolResult, @@ -13,14 +11,14 @@ from mcp.types import ( ) from mcp.types import Tool as MCPTool -from litellm.experimental_mcp_client.tools import ( - list_tools_with_pagination, - transform_mcp_tool_to_anthropic_tool, +from litellm.mcp_client.tools import ( _get_function_arguments, _normalize_mcp_input_schema, call_mcp_tool, call_openai_tool, + list_tools_with_pagination, load_mcp_tools, + transform_mcp_tool_to_anthropic_tool, transform_mcp_tool_to_openai_responses_api_tool, transform_mcp_tool_to_openai_tool, transform_openai_tool_call_request_to_mcp_tool_call_request, @@ -131,7 +129,7 @@ async def test_load_mcp_tools_follows_pagination(mock_session): @pytest.mark.asyncio() @pytest.mark.parametrize("require_complete", [False, True]) async def test_pagination_walk_stops_at_page_cap(mock_session, monkeypatch, require_complete): - monkeypatch.setattr("litellm.experimental_mcp_client.tools.MCP_TOOL_LISTING_MAX_PAGES", 2) + monkeypatch.setattr("litellm.mcp_client.tools.MCP_TOOL_LISTING_MAX_PAGES", 2) mock_session.list_tools.side_effect = [ ListToolsResult( tools=[MCPTool(name="tool_0", description="0", inputSchema={})], @@ -189,10 +187,10 @@ async def test_pagination_walk_treats_empty_cursor_as_terminal(mock_session): async def test_pagination_walk_stops_at_whole_walk_deadline(mock_session, monkeypatch, require_complete): import anyio - from litellm.experimental_mcp_client.tools import list_tools_with_pagination + from litellm.mcp_client.tools import list_tools_with_pagination - monkeypatch.setattr("litellm.experimental_mcp_client.tools.MCP_CLIENT_TIMEOUT", 0.2) - monkeypatch.setattr("litellm.experimental_mcp_client.tools.MCP_TOOL_LISTING_TIMEOUT", 0.2) + monkeypatch.setattr("litellm.mcp_client.tools.MCP_CLIENT_TIMEOUT", 0.2) + monkeypatch.setattr("litellm.mcp_client.tools.MCP_TOOL_LISTING_TIMEOUT", 0.2) async def slow_page(params=None): await anyio.sleep(0.15) @@ -218,10 +216,10 @@ async def test_pagination_walk_stops_at_whole_walk_deadline(mock_session, monkey async def test_pagination_walk_honors_explicit_deadline_over_globals(mock_session, monkeypatch): import anyio - from litellm.experimental_mcp_client.tools import list_tools_with_pagination + from litellm.mcp_client.tools import list_tools_with_pagination - monkeypatch.setattr("litellm.experimental_mcp_client.tools.MCP_CLIENT_TIMEOUT", 0.1) - monkeypatch.setattr("litellm.experimental_mcp_client.tools.MCP_TOOL_LISTING_TIMEOUT", 0.1) + monkeypatch.setattr("litellm.mcp_client.tools.MCP_CLIENT_TIMEOUT", 0.1) + monkeypatch.setattr("litellm.mcp_client.tools.MCP_TOOL_LISTING_TIMEOUT", 0.1) async def slow_page(params=None): await anyio.sleep(0.15) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_init.py b/tests/unit/proxy/_experimental/mcp_server/test_init.py new file mode 100644 index 00000000000..5ecb79b9813 --- /dev/null +++ b/tests/unit/proxy/_experimental/mcp_server/test_init.py @@ -0,0 +1,79 @@ +import importlib +import sys +from collections.abc import Mapping +from typing import Final + +import pytest + +import litellm.proxy.mcp_server.auth.user_api_key_auth_mcp +import litellm.proxy.mcp_server.server +import litellm.proxy.mcp_server.utils + +OLD_PACKAGE = "litellm.proxy._experimental.mcp_server" + + +def test_old_package_warns_and_deep_imports_resolve_to_proxy_mcp_server(monkeypatch: pytest.MonkeyPatch) -> None: + for name in tuple(sys.modules): + if name.startswith(OLD_PACKAGE): + monkeypatch.delitem(sys.modules, name) + + monkeypatch.delattr(litellm.proxy.mcp_server.auth, "user_api_key_auth_mcp") + monkeypatch.delitem(sys.modules, "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp") + + with pytest.warns(DeprecationWarning, match="litellm.proxy.mcp_server"): + old = importlib.import_module(OLD_PACKAGE) + + assert old.server is litellm.proxy.mcp_server.server + assert old.auth is litellm.proxy.mcp_server.auth + assert old.auth.user_api_key_auth_mcp is importlib.import_module( + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp" + ) + assert importlib.import_module(f"{OLD_PACKAGE}.server") is litellm.proxy.mcp_server.server + assert importlib.import_module(f"{OLD_PACKAGE}.utils") is litellm.proxy.mcp_server.utils + assert ( + importlib.import_module(f"{OLD_PACKAGE}.auth.user_api_key_auth_mcp") + is litellm.proxy.mcp_server.auth.user_api_key_auth_mcp + ) + attrs: Mapping[str, object] = vars(old) + assert attrs["server"] is litellm.proxy.mcp_server.server + assert attrs["auth"] is litellm.proxy.mcp_server.auth + + +def test_old_stdio_helper_import_works_without_optional_mcp_dependency(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.delattr(litellm.proxy, "mcp_server") + old_parent: Final = importlib.import_module("litellm.proxy._experimental") + monkeypatch.delattr(old_parent, "mcp_server", raising=False) + monkeypatch.delattr(litellm, "mcp_client", raising=False) + prefixes: Final = (OLD_PACKAGE, "litellm.proxy.mcp_server", "litellm.mcp_client", "mcp") + for name in tuple(sys.modules): + if any(name == prefix or name.startswith(f"{prefix}.") for prefix in prefixes): + monkeypatch.delitem(sys.modules, name) + monkeypatch.setitem(sys.modules, "mcp", None) + + with pytest.warns(DeprecationWarning, match="litellm.proxy.mcp_server"): + old: Final = importlib.import_module(f"{OLD_PACKAGE}.stdio_gate") + new: Final = importlib.import_module("litellm.proxy.mcp_server.stdio_gate") + + monkeypatch.setenv("LITELLM_ENABLE_MCP_STDIO", "true") + assert old.is_mcp_stdio_enabled() is True + monkeypatch.setenv("LITELLM_ENABLE_MCP_STDIO", "false") + assert old.is_mcp_stdio_enabled() is False + assert old is new + + +def test_legacy_child_import_keeps_canonical_module_reload_working(monkeypatch: pytest.MonkeyPatch) -> None: + for name in tuple(sys.modules): + if name.startswith(OLD_PACKAGE): + monkeypatch.delitem(sys.modules, name) + + helper: Final = importlib.import_module("litellm.proxy.mcp_server.stdio_gate") + with pytest.warns(DeprecationWarning, match="litellm.proxy.mcp_server"): + old: Final = importlib.import_module(f"{OLD_PACKAGE}.stdio_gate") + + monkeypatch.setattr(helper, "MCP_STDIO_ENABLED_ENV_VAR", "RELOAD_PROBE") + monkeypatch.setenv("LITELLM_ENABLE_MCP_STDIO", "true") + monkeypatch.setenv("RELOAD_PROBE", "false") + importlib.reload(helper) + + assert old is helper + assert old.is_mcp_stdio_enabled() is True diff --git a/tests/unit/proxy/agent_endpoints/auth/test_managed_authorization.py b/tests/unit/proxy/agent_endpoints/auth/test_managed_authorization.py index fb676ae9a61..2b682fda982 100644 --- a/tests/unit/proxy/agent_endpoints/auth/test_managed_authorization.py +++ b/tests/unit/proxy/agent_endpoints/auth/test_managed_authorization.py @@ -588,6 +588,6 @@ def test_registered_inference_routes_have_an_explicit_managed_access_decision(ro "/vector_stores", "/vector_store/", "/search", "/containers", "/skills", "/claude-code/", "/interactions", "/agents", "/responses/{", "/responses/input_tokens", "/realtime/client_secrets", "/realtime/calls", "/realtime/transcription_sessions", - )) or normalized in ("/models", "/cursor/models", "/cursor/v1/models") + )) or normalized in ("/models", "/cursor/models", "/cursor/v1/models", "/claude_code_gateway/v1/models") concrete: Final = route.split("?")[0].replace("{model}", "model").replace("{model_name:path}", "model") assert managed_agent_route_allowed(concrete, None) is not unsupported, route diff --git a/tests/unit/proxy/anthropic_endpoints/test_gateway_endpoints.py b/tests/unit/proxy/anthropic_endpoints/test_gateway_endpoints.py index 8ac0e2a6f6d..0f064622f2d 100644 --- a/tests/unit/proxy/anthropic_endpoints/test_gateway_endpoints.py +++ b/tests/unit/proxy/anthropic_endpoints/test_gateway_endpoints.py @@ -20,21 +20,6 @@ from fastapi import FastAPI from fastapi.testclient import TestClient from litellm.caching.dual_cache import DualCache -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( - MintedProxyCredential, - ProxyCredentialMintFailure, -) -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credentials import ( - SessionRefreshOpened, - open_session_refresh_bearer, - session_keys_from_master_key, -) -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import ( - SESSION_REFRESH_PREFIX, - MintedSessionToken, - SessionPrincipal, - mint_session_refresh_token, -) from litellm.proxy._types import ProxyException from litellm.proxy.anthropic_endpoints import gateway_endpoints from litellm.proxy.management_endpoints.ui_sso import ( @@ -42,6 +27,21 @@ from litellm.proxy.management_endpoints.ui_sso import ( _hash_cli_sso_secret, _set_cli_sso_flow, ) +from litellm.proxy.mcp_server.gateway_dcr_flow import ( + MintedProxyCredential, + ProxyCredentialMintFailure, +) +from litellm.proxy.mcp_server.outbound_credentials.session_credentials import ( + SessionRefreshOpened, + open_session_refresh_bearer, + session_keys_from_master_key, +) +from litellm.proxy.mcp_server.outbound_credentials.session_token import ( + SESSION_REFRESH_PREFIX, + MintedSessionToken, + SessionPrincipal, + mint_session_refresh_token, +) from litellm.proxy.middleware.prometheus_auth_middleware import PrometheusAuthMiddleware _DEVICE_CODE_GRANT: Final = "urn:ietf:params:oauth:grant-type:device_code" @@ -813,3 +813,95 @@ def test_messages_gated_by_enable_flag(): with _gateway_env(enabled=False) as (client, _): resp = client.post("/claude_code_gateway/v1/messages", json={"model": "claude-sonnet-4-5", "messages": []}) assert resp.status_code == 404 + + +@pytest.mark.parametrize("headers", [{}, {"anthropic-version": "2023-06-01"}]) +def test_gateway_model_discovery_preserves_grants_and_format( + monkeypatch: pytest.MonkeyPatch, headers: dict[str, str] +) -> None: + from litellm import Router + from litellm.proxy import proxy_server + from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth + + model_router: Final = Router( + model_list=[ + { + "model_name": name, + "litellm_params": {"model": f"openai/{name}", "api_key": "local-placeholder"}, + } + for name in ("discovery-example", "restricted-example") + ] + ) + monkeypatch.setattr(proxy_server, "llm_router", model_router) + monkeypatch.setattr(proxy_server, "llm_model_list", model_router.model_list) + monkeypatch.setattr(proxy_server, "prisma_client", None) + monkeypatch.setattr(proxy_server, "user_model", None) + monkeypatch.setattr(proxy_server, "general_settings", {"enable_claude_code_gateway": True}) + caller: Final = UserAPIKeyAuth( + user_role=LitellmUserRoles.INTERNAL_USER, + models=["discovery-example"], + ) + app: Final = FastAPI() + app.include_router(proxy_server.router) + app.include_router(gateway_endpoints.router) + app.dependency_overrides[gateway_endpoints.user_api_key_auth] = lambda: caller + with TestClient(app) as client: + standard: Final = client.get("/v1/models", headers=headers) + gateway: Final = client.get("/claude_code_gateway/v1/models", headers=headers) + assert standard.status_code == 200, standard.text + assert gateway.status_code == 200, gateway.text + assert gateway.json() == standard.json() + assert [model["id"] for model in gateway.json()["data"]] == ["discovery-example"] + invalid_scope: Final = client.get("/claude_code_gateway/v1/models?scope=invalid", headers=headers) + assert invalid_scope.status_code == 400 + + +def test_gateway_model_discovery_requires_authentication() -> None: + with _gateway_env(real_auth=True) as (client, _), pytest.raises(ProxyException) as exc_info: + client.get("/claude_code_gateway/v1/models") + assert exc_info.value.code == "401" + + +@pytest.mark.parametrize("settings", [{}, {"enable_claude_code_gateway": False}]) +def test_gateway_model_discovery_disabled(monkeypatch: pytest.MonkeyPatch, settings: dict[str, bool]) -> None: + from litellm.proxy import proxy_server + + with _gateway_env(real_auth=True) as (client, _): + monkeypatch.setattr(proxy_server, "general_settings", settings) + response: Final = client.get( + "/claude_code_gateway/v1/models", headers={"Authorization": f"Bearer {_MASTER_KEY}"} + ) + assert response.status_code == 404, response.text + + +@pytest.mark.asyncio +@pytest.mark.parametrize("route", ["/models", "/v1/models", "/claude_code_gateway/v1/models"]) +async def test_gateway_model_discovery_preserves_route_exemptions(monkeypatch: pytest.MonkeyPatch, route: str) -> None: + from litellm_enterprise.proxy.auth.route_checks import EnterpriseRouteChecks + + import litellm + from litellm.proxy._types import LiteLLM_TeamTable, UserAPIKeyAuth + from litellm.proxy.auth.auth_checks import common_checks + from litellm.proxy.auth.route_checks import RouteChecks + + monkeypatch.setattr(litellm, "max_budget", 1.0) + result: Final = await common_checks( + request_body={}, + team_object=LiteLLM_TeamTable(team_id="test-team", spend=150.0, max_budget=100.0), + user_object=None, + end_user_object=None, + global_proxy_spend=2.0, + general_settings={}, + route=route, + llm_router=None, + proxy_logging_obj=MagicMock(), + valid_token=UserAPIKeyAuth(team_id="test-team"), + request=MagicMock(), + ) + assert result is True + assert RouteChecks.is_unbilled_route(route) + assert RouteChecks.is_llm_api_route(route) + monkeypatch.setenv("DISABLE_LLM_API_ENDPOINTS", "true") + monkeypatch.setenv("DISABLE_ADMIN_ENDPOINTS", "true") + monkeypatch.setattr("litellm.proxy.proxy_server.premium_user", True) + EnterpriseRouteChecks.should_call_route(route) diff --git a/tests/unit/proxy/auth/test_auth_exception_handler.py b/tests/unit/proxy/auth/test_auth_exception_handler.py index d83a8aa2fcd..92b4c93118f 100644 --- a/tests/unit/proxy/auth/test_auth_exception_handler.py +++ b/tests/unit/proxy/auth/test_auth_exception_handler.py @@ -1,5 +1,7 @@ import asyncio import json +from collections.abc import Mapping +from typing import Final from unittest.mock import AsyncMock, MagicMock, patch import httpx @@ -29,6 +31,7 @@ import litellm from litellm._logging import verbose_proxy_logger from litellm.constants import INVALID_VIRTUAL_KEY_ERROR_MARKER from litellm.exceptions import BudgetExceededError +from litellm.integrations.custom_logger import CustomLogger from litellm.proxy._types import ( ModelAccessDeniedProxyException, ProxyErrorTypes, @@ -665,7 +668,7 @@ async def test_expired_key_error_log_names_the_key_owner( ): verbose_proxy_logger.propagate = True try: - with caplog.at_level("ERROR", logger="LiteLLM Proxy"), pytest.raises(ProxyException): + with caplog.at_level("WARNING", logger="LiteLLM Proxy"), pytest.raises(ProxyException): await handler.handle_authentication_error( expired_key_error, MagicMock(), @@ -711,8 +714,8 @@ async def test_expired_key_error_log_names_the_key_owner( async def test_unknown_key_error_log_keeps_the_operator_wording_the_401_hides( looked_up, logged_fragment, absent_fragment, caplog ): - """A wrong key gets a generic 401, while the one auth failure log line keeps the - operator wording and the hash that was looked up, next to the requester IP.""" + """A wrong key gets a generic 401, while the one auth failure log line, a WARNING with no + traceback, keeps the operator wording and the hash that was looked up, next to the requester IP.""" from litellm.constants import INVALID_API_KEY_ERROR_MESSAGE from litellm.proxy.auth.resolvers.exceptions import KeyNotFoundError @@ -730,7 +733,7 @@ async def test_unknown_key_error_log_keeps_the_operator_wording_the_401_hides( ): verbose_proxy_logger.propagate = True try: - with caplog.at_level("ERROR", logger="LiteLLM Proxy"), pytest.raises(ProxyException) as exc_info: + with caplog.at_level("WARNING", logger="LiteLLM Proxy"), pytest.raises(ProxyException) as exc_info: await UserAPIKeyAuthExceptionHandler().handle_authentication_error( KeyNotFoundError(looked_up), MagicMock(), @@ -745,6 +748,7 @@ async def test_unknown_key_error_log_keeps_the_operator_wording_the_401_hides( assert exc_info.value.message == INVALID_API_KEY_ERROR_MESSAGE records = [r for r in caplog.records if "user_api_key_auth(): Exception occured" in r.getMessage()] assert len(records) == 1, [r.getMessage() for r in caplog.records] + assert records[0].levelname == "WARNING" and records[0].exc_info is None logged = records[0].getMessage() assert "Requester IP Address:" in logged and logged_fragment in logged, logged if absent_fragment is not None: @@ -812,6 +816,65 @@ def _http_request(client_host: str | None = "10.1.2.3", headers: dict[str, str] ) +class _AuthFailureRecorder(CustomLogger): + def __init__(self) -> None: + super().__init__() + self.data: dict[str, object] | None = None + self.error: Exception | None = None + + async def async_post_call_failure_hook( + self, + request_data: dict[str, object], + original_exception: Exception, + user_api_key_dict: UserAPIKeyAuth, + traceback_str: str | None = None, + ) -> HTTPException | None: + self.data = dict(request_data) + self.error = original_exception + return None + + +@pytest.mark.asyncio +@pytest.mark.parametrize("request_data", [[], None, "metadata", 1, True]) +@pytest.mark.parametrize("error_kind", ["auth", "budget", "database"]) +async def test_auth_error_preserves_classification_with_non_object_context( + monkeypatch: pytest.MonkeyPatch, request_data: object, error_kind: str +) -> None: + import litellm.proxy.proxy_server as proxy_server + + monkeypatch.setattr(litellm, "budget_exceeded_status_code", 429) + errors: Final = { + "auth": HTTPException(status_code=401, detail="Invalid API key"), + "budget": BudgetExceededError(current_cost=2, max_budget=1), + "database": httpx.ConnectError("Database unavailable"), + } + error: Final = errors[error_kind] + expected: Final = _as_proxy_exception(error) + recorder: Final = _AuthFailureRecorder() + monkeypatch.setattr(litellm, "callbacks", [recorder]) + monkeypatch.setattr(proxy_server, "general_settings", {"allow_requests_on_db_unavailable": False}) + + with pytest.raises(ProxyException) as exc_info: + await UserAPIKeyAuthExceptionHandler.handle_authentication_error( + error, + _http_request(headers={"user-agent": "shape-regression"}), + request_data, + "/key/info", + None, + "sk-test", + ) + + assert exc_info.value.code == expected.code + assert exc_info.value.type == expected.type + assert exc_info.value.message == expected.message + assert recorder.error is error + assert recorder.data is not None + metadata: Final = recorder.data["metadata"] + assert isinstance(metadata, Mapping) + assert metadata["requester_ip_address"] == "10.1.2.3" + assert metadata["user_agent"] == "shape-regression" + + @pytest.mark.asyncio @pytest.mark.parametrize( "auth_error, general_settings, request_kwargs, expected_ip", @@ -1086,10 +1149,16 @@ def _marked_malformed_key_error() -> HTTPException: message="Authentication Error", type=ProxyErrorTypes.auth_error, param=None, code=401 ), False, - "ERROR", - id="expected_401_no_traceback", + "WARNING", + id="proxy_exception_401_warning_no_traceback", ), pytest.param(ValueError("unexpected internal error"), True, "ERROR", id="unexpected_error_keeps_traceback"), + pytest.param( + Exception("No api key passed in."), + True, + "ERROR", + id="bare_exception_coerced_to_401_still_keeps_traceback", + ), pytest.param( _marked_malformed_key_error(), False, @@ -1099,8 +1168,14 @@ def _marked_malformed_key_error() -> HTTPException: pytest.param( HTTPException(status_code=401, detail="LiteLLM Virtual Key expected. Received=test"), False, + "WARNING", + id="http_exception_401_warning_no_traceback", + ), + pytest.param( + ProxyException(message="Forbidden", type=ProxyErrorTypes.auth_error, param=None, code=403), + False, "ERROR", - id="phrase_without_marker_stays_loud", + id="403_stays_error_without_traceback", ), ], ) @@ -1127,7 +1202,7 @@ async def test_handle_authentication_error_traceback_only_for_unexpected_errors( try: try: raise auth_error - except (ProxyException, ValueError, HTTPException) as caught: + except Exception as caught: with caplog.at_level(expect_level, logger="LiteLLM Proxy"), pytest.raises((ProxyException, HTTPException)): await handler.handle_authentication_error( caught, diff --git a/tests/unit/proxy/auth/test_auth_utils.py b/tests/unit/proxy/auth/test_auth_utils.py index ee1ae43fd3a..10a0f974a42 100644 --- a/tests/unit/proxy/auth/test_auth_utils.py +++ b/tests/unit/proxy/auth/test_auth_utils.py @@ -3626,6 +3626,18 @@ class TestIsRequestBodySafeBlocksEndpointTargetingFields: ) +@pytest.mark.parametrize("allow_client_side_credentials", [False, True]) +@pytest.mark.parametrize("nested", [False, True]) +def test_request_cannot_select_chatgpt_auth_file(allow_client_side_credentials: bool, nested: bool) -> None: + selector: Final = {"chatgpt_auth_file": "/tokens/account-b/auth.json"} + with pytest.raises(ValueError, match="chatgpt_auth_file"): + is_request_body_safe( + request_body={"model": "chatgpt-account-a", **({"extra_body": selector} if nested else selector)}, + general_settings={"allow_client_side_credentials": allow_client_side_credentials}, + llm_router=None, + model="chatgpt-account-a", + ) + class TestIsRequestBodySafeBlocksBedrockProjectOverride: """``aws_bedrock_project_id`` pins a deployment to a Bedrock project so that project's data-retention policy applies to its requests. A @@ -5304,3 +5316,27 @@ async def test_a_non_numeric_max_request_size_mb_is_ignored_without_premium(): patch("litellm.proxy.proxy_server.premium_user", False), ): assert await check_if_request_size_is_safe(request=_request_with_content_length(1024)) is True + + +@pytest.mark.parametrize("allow_client_side_credentials", [False, True]) +@pytest.mark.parametrize("route", ["/model/new", "/model/update", "/model/account-a/update", "/health/test_connection"]) +def test_chatgpt_model_configuration_reaches_role_authorization( + allow_client_side_credentials: bool, route: str +) -> None: + body: Final = {"litellm_params": {"model": "chatgpt/gpt-6-luna", "chatgpt_auth_file": "/tokens/account-a/auth.json"}} + assert is_request_body_safe( + request_body=body, + general_settings={"allow_client_side_credentials": allow_client_side_credentials}, + llm_router=None, + model="", + route=route, + ) + for inference_route in ("/v1/chat/completions", "/v1/responses"): + with pytest.raises(ValueError, match="chatgpt_auth_file"): + is_request_body_safe( + request_body=body, + general_settings={"allow_client_side_credentials": allow_client_side_credentials}, + llm_router=None, + model="", + route=inference_route, + ) diff --git a/tests/unit/proxy/auth/test_login_utils.py b/tests/unit/proxy/auth/test_login_utils.py index ec9b9a04f72..37ea05f8ba9 100644 --- a/tests/unit/proxy/auth/test_login_utils.py +++ b/tests/unit/proxy/auth/test_login_utils.py @@ -9,8 +9,8 @@ import hashlib import os from collections.abc import Mapping from contextlib import ExitStack -from typing import TYPE_CHECKING, Final from datetime import datetime, timedelta, timezone +from typing import TYPE_CHECKING, Final from unittest.mock import AsyncMock, MagicMock, patch import httpx @@ -638,10 +638,10 @@ class TestEncodeUiSessionJwt: this helper must now be accepted.""" from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( + from litellm.proxy.auth.login_utils import encode_ui_session_jwt + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( user_id_from_session_cookie, ) - from litellm.proxy.auth.login_utils import encode_ui_session_jwt token_object = {"user_id": "cornell-user", "key": "sk-abc", "login_method": "sso"} with patch("litellm.proxy.auth.login_utils.LITELLM_UI_SESSION_DURATION", "24h"): diff --git a/tests/unit/proxy/auth/test_mcp_ip_filtering.py b/tests/unit/proxy/auth/test_mcp_ip_filtering.py index 4c219760762..b28dd8bbab5 100644 --- a/tests/unit/proxy/auth/test_mcp_ip_filtering.py +++ b/tests/unit/proxy/auth/test_mcp_ip_filtering.py @@ -6,6 +6,7 @@ external callers only see servers with available_on_public_internet=True. """ import logging +from typing import Final from unittest.mock import MagicMock, patch import pytest @@ -35,7 +36,7 @@ def _make_server(server_id, available_on_public_internet=False): def _make_manager(servers): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -176,6 +177,19 @@ class TestMCPClientIPExtraction: assert result == "203.0.113.5" + def test_non_boolean_use_x_forwarded_for_never_trusts_xff(self): + request: Final = _make_request("10.0.0.5", "203.0.113.9, 10.0.0.5") + + result: Final = IPAddressUtils.get_mcp_client_ip( + request, + general_settings={ + "use_x_forwarded_for": "false", + "mcp_trusted_proxy_ranges": ["10.0.0.0/8"], + }, + ) + + assert result == "10.0.0.5" + def _make_request(client_host, xff): request = MagicMock(spec=Request) diff --git a/tests/unit/proxy/auth/test_route_checks.py b/tests/unit/proxy/auth/test_route_checks.py index 6de54aa4af6..b2c67b4e009 100644 --- a/tests/unit/proxy/auth/test_route_checks.py +++ b/tests/unit/proxy/auth/test_route_checks.py @@ -3742,7 +3742,7 @@ def test_team_spend_by_user_reachable_by_non_admin(user_role): return "allowed" assert outcome("/team/spend/by_user") == "allowed" - assert outcome("/team/spend/by_key").startswith("denied: Only proxy admin") + assert outcome("/team/spend/by_key").startswith("denied: Authentication Error, Only proxy admin") def test_user_daily_activity_aggregated_not_covered_by_prefix_match(): diff --git a/tests/unit/proxy/auth/test_search_tool_deny_by_default.py b/tests/unit/proxy/auth/test_search_tool_deny_by_default.py index cd285e0386f..da036795889 100644 --- a/tests/unit/proxy/auth/test_search_tool_deny_by_default.py +++ b/tests/unit/proxy/auth/test_search_tool_deny_by_default.py @@ -1,8 +1,9 @@ from collections.abc import Mapping -from typing import Final, TypedDict +from typing import Final, TypedDict, cast from unittest.mock import AsyncMock, MagicMock import pytest +from fastapi import HTTPException from litellm.constants import LITELLM_PROXY_MASTER_KEY_ALIAS from litellm.proxy import proxy_server @@ -78,6 +79,14 @@ def _team_loader(team_tools: list[str] | None | str) -> TeamObjectLoader: return load +def _missing_dashboard_team_loader() -> tuple[TeamObjectLoader, AsyncMock]: + missing_team: Final = HTTPException( + status_code=404, detail="Team doesn't exist in db. Team=litellm-dashboard" + ) + load_team: Final = AsyncMock(side_effect=missing_team) + return cast(TeamObjectLoader, load_team), load_team + + async def _no_team() -> None: return None @@ -194,9 +203,6 @@ async def test_search_tool_access_is_unchanged_without_search_tool_deny_by_defau id="proxy admin virtual key not exempt", ), pytest.param(CallerFields(api_key=LITELLM_PROXY_MASTER_KEY_ALIAS), None, None, None, id="master key exempt"), - pytest.param( - CallerFields(team_id=UI_TEAM_ID, virtual_key=False), None, None, None, id="dashboard session exempt" - ), ], ) @pytest.mark.asyncio @@ -248,6 +254,79 @@ async def test_search_tool_deny_by_default_does_not_load_the_user_when_off( get_user_object.assert_not_awaited() +@pytest.mark.parametrize( + "general_settings", + [{}, {"search_tool_deny_by_default": False}], + ids=["omitted", "false"], +) +@pytest.mark.parametrize( + "user_role", + [LitellmUserRoles.PROXY_ADMIN, LitellmUserRoles.INTERNAL_USER], + ids=["admin", "internal-user"], +) +@pytest.mark.parametrize( + "key_tools, expected", + [ + pytest.param(None, None, id="unrestricted-key"), + pytest.param(["search-a"], None, id="key-grants-search-a"), + pytest.param(["search-b"], _LEGACY, id="key-excludes-search-a"), + ], +) +@pytest.mark.asyncio +async def test_dashboard_search_tool_grants_without_deny_by_default( + general_settings: Mapping[str, object], + user_role: LitellmUserRoles, + key_tools: list[str] | None, + expected: ProxyErrorTypes | None, +) -> None: + caller: Final = _caller( + virtual_key=False, + key_tools=key_tools, + team_id=UI_TEAM_ID, + user_role=user_role, + ) + load_team, load_team_mock = _missing_dashboard_team_loader() + assert await _denied_by(general_settings, caller, load_team) == expected + load_team_mock.assert_not_awaited() + + +@pytest.mark.parametrize( + "user_role", + [LitellmUserRoles.PROXY_ADMIN, LitellmUserRoles.PROXY_ADMIN_VIEW_ONLY], + ids=["admin", "admin-view-only"], +) +@pytest.mark.asyncio +async def test_admin_dashboard_search_tool_grants_with_deny_by_default(user_role: LitellmUserRoles) -> None: + caller: Final = _caller(virtual_key=False, team_id=UI_TEAM_ID, user_role=user_role) + load_team, load_team_mock = _missing_dashboard_team_loader() + assert await _denied_by(_DENY_ON, caller, load_team) is None + load_team_mock.assert_not_awaited() + + +@pytest.mark.parametrize( + "user_id, user_tools, expected", + [ + pytest.param("user-1", ["search-a"], None, id="user-grants-search-a"), + pytest.param("user-1", ["search-b"], _USER, id="user-grants-another-tool"), + pytest.param("user-1", None, _USER, id="user-grant-null"), + pytest.param("user-2", None, _USER, id="no-user-row"), + ], +) +@pytest.mark.asyncio +async def test_internal_dashboard_search_tool_requires_the_user_grant_with_deny_by_default( + cache: UserApiKeyCache, + user_id: str, + user_tools: list[str] | None, + expected: ProxyErrorTypes | None, +) -> None: + if user_id == "user-1": + _cache_user(cache, user_tools) + caller: Final = _caller(virtual_key=False, team_id=UI_TEAM_ID, user_id=user_id) + load_team, load_team_mock = _missing_dashboard_team_loader() + assert await _denied_by(_DENY_ON, caller, load_team) == expected + load_team_mock.assert_not_awaited() + + @pytest.mark.parametrize( "general_settings, caller, expected", [ @@ -257,6 +336,24 @@ async def test_search_tool_deny_by_default_does_not_load_the_user_when_off( pytest.param(_DENY_ON, _caller(virtual_key=False), _USER, id="keyless user"), pytest.param(_DENY_ON, _caller(user_role=LitellmUserRoles.PROXY_ADMIN), _KEY, id="proxy admin key"), pytest.param(_DENY_ON, _caller(api_key=LITELLM_PROXY_MASTER_KEY_ALIAS), None, id="master key"), + pytest.param( + _DENY_ON, + _caller(virtual_key=False, team_id=UI_TEAM_ID, user_role=LitellmUserRoles.INTERNAL_USER), + _USER, + id="internal dashboard user", + ), + pytest.param( + _DENY_ON, + _caller(virtual_key=False, team_id=UI_TEAM_ID, user_role=LitellmUserRoles.PROXY_ADMIN), + None, + id="admin dashboard", + ), + pytest.param( + _DENY_ON, + _caller(virtual_key=False, team_id=UI_TEAM_ID, user_role=LitellmUserRoles.PROXY_ADMIN_VIEW_ONLY), + None, + id="admin view-only dashboard", + ), ], ) def test_unregistered_search_fallback_follows_search_tool_deny_by_default( @@ -268,3 +365,12 @@ def test_unregistered_search_fallback_follows_search_tool_deny_by_default( with pytest.raises(ProxyException) as exc_info: check_unregistered_search_fallback(caller, general_settings) assert (exc_info.value.type, exc_info.value.code) == (expected, "403") + + +@pytest.mark.asyncio +async def test_search_preserves_missing_real_team_error_without_deny_by_default() -> None: + missing_team: Final = HTTPException(status_code=404, detail="Team doesn't exist in db. Team=team-1") + load_team: Final = AsyncMock(side_effect=missing_team) + with pytest.raises(HTTPException) as exc_info: + await can_caller_call_search_tool("search-a", _caller(team_id="team-1"), {}, load_team) + assert exc_info.value is missing_team diff --git a/tests/unit/proxy/auth/test_team_member_budget.py b/tests/unit/proxy/auth/test_team_member_budget.py index b38a953d189..6055e4f0356 100644 --- a/tests/unit/proxy/auth/test_team_member_budget.py +++ b/tests/unit/proxy/auth/test_team_member_budget.py @@ -3,8 +3,11 @@ Unit tests for team member budget checks in common_checks. These tests verify the team member budget enforcement without requiring a proxy server. """ -import pytest +from datetime import datetime, timezone +from typing import Final from unittest.mock import AsyncMock, MagicMock, patch + +import pytest from fastapi import Request import litellm @@ -15,7 +18,10 @@ from litellm.proxy._types import ( LiteLLM_UserTable, UserAPIKeyAuth, ) -from litellm.proxy.auth.auth_checks import common_checks, get_team_membership +from litellm.proxy.auth.auth_checks import ( + common_checks, + resolve_effective_team_member_budget, +) @pytest.mark.asyncio @@ -436,3 +442,48 @@ async def test_team_member_budget_check_personal_key_not_team(): # Should pass and get_team_membership should not be called assert result is True mock_get_team_membership.assert_not_called() + + +def test_resolve_effective_team_member_budget_preserves_member_and_default_precedence() -> None: + now: Final = datetime(2030, 1, 1, tzinfo=timezone.utc) + member_budget: Final = LiteLLM_BudgetTable( + max_budget=100, + temp_budget_increase=10, + temp_budget_expiry=datetime(2030, 1, 2, tzinfo=timezone.utc), + ) + expired_member_budget: Final = LiteLLM_BudgetTable( + max_budget=100, + temp_budget_increase=10, + temp_budget_expiry=datetime(2029, 12, 31, tzinfo=timezone.utc), + ) + active_inherited_increase: Final = LiteLLM_BudgetTable( + max_budget=None, + temp_budget_increase=10, + temp_budget_expiry=datetime(2030, 1, 2, tzinfo=timezone.utc), + ) + expired_inherited_increase: Final = LiteLLM_BudgetTable( + max_budget=None, + temp_budget_increase=10, + temp_budget_expiry=datetime(2029, 12, 31, tzinfo=timezone.utc), + ) + + assert resolve_effective_team_member_budget(member_budget, None, now) == 110 + assert resolve_effective_team_member_budget(expired_member_budget, None, now) == 100 + assert resolve_effective_team_member_budget( + active_inherited_increase, + LiteLLM_BudgetTable(max_budget=50), + now, + ) == 60 + assert resolve_effective_team_member_budget( + expired_inherited_increase, + LiteLLM_BudgetTable(max_budget=50), + now, + ) == 50 + assert resolve_effective_team_member_budget( + LiteLLM_BudgetTable(max_budget=0), + LiteLLM_BudgetTable(max_budget=50), + now, + ) == 0 + assert resolve_effective_team_member_budget(None, LiteLLM_BudgetTable(max_budget=50), now) == 50 + assert resolve_effective_team_member_budget(None, LiteLLM_BudgetTable(max_budget=0), now) is None + assert resolve_effective_team_member_budget(None, None, now) is None diff --git a/tests/unit/proxy/auth/test_user_api_key_auth.py b/tests/unit/proxy/auth/test_user_api_key_auth.py index 60a8dd73a34..092805a9cac 100644 --- a/tests/unit/proxy/auth/test_user_api_key_auth.py +++ b/tests/unit/proxy/auth/test_user_api_key_auth.py @@ -2031,9 +2031,9 @@ async def test_user_api_key_auth_websocket_rejection_adds_no_traceback_for_other assert rejection.value.status_code == 403 assert "expired key" in str(rejection.value.detail).lower() assert sent == [{"type": "websocket.close", "code": status.WS_1008_POLICY_VIOLATION, "reason": ""}] - proxy_records: Final = [record for record in caplog.records if record.name == verbose_proxy_logger.name] + proxy_records: Final = [record for record in caplog.records if record.name.startswith(verbose_proxy_logger.name)] assert [record.getMessage() for record in proxy_records if record.exc_info is not None] == [] - assert [record.levelno for record in proxy_records if record.levelno >= logging.WARNING] == [logging.ERROR] + assert [record.levelno for record in proxy_records if record.levelno >= logging.WARNING] == [logging.WARNING] @pytest.mark.asyncio diff --git a/tests/unit/proxy/auth/test_user_api_key_auth_request_flow.py b/tests/unit/proxy/auth/test_user_api_key_auth_request_flow.py index 108f7ce2983..2d9c781b0d1 100644 --- a/tests/unit/proxy/auth/test_user_api_key_auth_request_flow.py +++ b/tests/unit/proxy/auth/test_user_api_key_auth_request_flow.py @@ -7724,7 +7724,8 @@ async def test_user_api_key_auth_does_not_overwrite_end_user_id_set_by_builder() @pytest.mark.asyncio -async def test_user_api_key_auth_authenticates_before_raising_malformed_body_error(): +@pytest.mark.parametrize("body", [b'{}{"model": "gpt-4o"}', b"[]", b"null", b"[1e400]"]) +async def test_user_api_key_auth_authenticates_before_raising_malformed_body_error(body: bytes) -> None: """Regression (LIT-4780): a body that fails to parse must still be authenticated first, so the rejected request's trace carries the caller's key / team / user identity instead of an anonymous root span. The parse error is re-raised @@ -7742,10 +7743,11 @@ async def test_user_api_key_auth_authenticates_before_raising_malformed_body_err "headers": [(b"content-type", b"application/json")], "method": "POST", "path": "/chat/completions", + "query_string": b"probe=1", } ) request._url = URL(url="/chat/completions") - request._body = b'{}{"model": "gpt-4o"}' + request._body = body attrs = _proxy_attrs_for_centralized_checks(user_custom_auth=None) originals = {a: getattr(_proxy_server_mod, a, None) for a in attrs} diff --git a/tests/unit/proxy/client/cli/test_debug_commands.py b/tests/unit/proxy/client/cli/test_debug_commands.py index 419fd821cfb..311edde0af9 100644 --- a/tests/unit/proxy/client/cli/test_debug_commands.py +++ b/tests/unit/proxy/client/cli/test_debug_commands.py @@ -1,6 +1,8 @@ import json import os +import re import time +from urllib.parse import unquote import pytest import requests @@ -114,6 +116,22 @@ def test_recent_bodies_fetches_latest_turns_even_when_successful(): assert _called_paths() == ["/spend/logs/session/ui", "/spend/logs/ui/req-ok"] +@pytest.mark.parametrize("request_id", ["req#a1", "req?a=1", "req%41b", "req a&b"]) +@responses.activate +def test_bodies_are_fetched_for_request_ids_with_url_special_characters(request_id): + def payload_for_stored_id(request): + stored_id = unquote(request.path_url.split("?")[0].removeprefix("/spend/logs/ui/")) + found = stored_id == request_id + return 200, {}, json.dumps({"response": {"id": "msg_special"}} if found else None) + + _mock_proxy([{**OK_ROW, "request_id": request_id}], {}) + responses.add_callback(responses.GET, re.compile(f"{PROXY}/spend/logs/ui/.*"), callback=payload_for_stored_id) + result = CliRunner().invoke(cli, ["debug", "claude", "--session-id", SESSION, "--no-save"]) + + assert result.exit_code == 0, result.output + assert "msg_special" in result.output + + @responses.activate def test_bodies_are_truncated_to_max_chars(): _mock_proxy([OK_ROW], {"req-ok": {"proxy_server_request": {"body": "a" * 5000}, "response": None}}) diff --git a/tests/unit/proxy/client/cli/test_encryption_commands.py b/tests/unit/proxy/client/cli/test_encryption_commands.py index 3a86eb82593..6685d29fb7e 100644 --- a/tests/unit/proxy/client/cli/test_encryption_commands.py +++ b/tests/unit/proxy/client/cli/test_encryption_commands.py @@ -5,6 +5,8 @@ check vs POST migrate, dry-run param) and its residual-state messaging without a live proxy. """ +from typing import Final + import pytest from click.testing import CliRunner @@ -69,3 +71,20 @@ def test_migrate_reports_residual_legacy(runner): result = runner.invoke(cli_main.cli, ["encryption", "migrate", "--check"]) assert result.exit_code == 0, result.output assert "Residual legacy values remaining: 3" in result.output + + +@pytest.mark.parametrize("residual", [-1, float("nan")]) +def test_migrate_prints_no_residual_status_for_a_residual_below_zero_or_nan(runner, residual): + _FakeHTTPClient.response = {"status": "success", "report": {"residual_legacy": residual}} + result: Final = runner.invoke(cli_main.cli, ["encryption", "migrate", "--check"]) + assert result.exit_code == 0, result.output + assert "No legacy values remaining" not in result.output + assert "Residual legacy values remaining" not in result.output + + +@pytest.mark.parametrize("report", [None, "done", {"residual_legacy": "3"}]) +def test_migrate_malformed_report_fails(runner, report): + _FakeHTTPClient.response = {"status": "success", "report": report} + result: Final = runner.invoke(cli_main.cli, ["encryption", "migrate", "--check"]) + assert result.exit_code != 0 + assert "Unexpected" in result.output diff --git a/tests/unit/proxy/common_utils/test_check_batch_cost.py b/tests/unit/proxy/common_utils/test_check_batch_cost.py index 33b8085e082..d7fc844171d 100644 --- a/tests/unit/proxy/common_utils/test_check_batch_cost.py +++ b/tests/unit/proxy/common_utils/test_check_batch_cost.py @@ -4259,6 +4259,17 @@ class TestCreatorTurnedOffMessageLogging: assert await instance._creator_turned_off_message_logging(self._job()) is expected + @pytest.mark.asyncio + async def test_a_job_without_creator_fields_falls_back_to_the_proxy_setting(self, monkeypatch): + from types import SimpleNamespace + + import litellm + + monkeypatch.setattr(litellm, "turn_off_message_logging", False) + instance: Final = self._instance() + + assert await instance._creator_turned_off_message_logging(SimpleNamespace(id="job-1")) is False + @pytest.mark.asyncio async def test_a_team_that_turned_off_message_logging_covers_its_keys(self, monkeypatch): from types import SimpleNamespace diff --git a/tests/unit/proxy/common_utils/test_http_parsing_utils.py b/tests/unit/proxy/common_utils/test_http_parsing_utils.py index cd5820fa2fd..354feb0bab1 100644 --- a/tests/unit/proxy/common_utils/test_http_parsing_utils.py +++ b/tests/unit/proxy/common_utils/test_http_parsing_utils.py @@ -64,6 +64,100 @@ def _starlette_request( return Request(scope, receive) +@pytest.mark.asyncio +@pytest.mark.parametrize( + "body", + [b"[]", b'[["model", "test"]]', b"null", b'"s"', b"1", b"true", b"false"], +) +@pytest.mark.parametrize("path", ["/v1/messages", "/vertex_ai/v1/messages", "/lens/datasets"]) +async def test_read_request_body_rejects_non_object_json(body: bytes, path: str) -> None: + request: Final = _starlette_request(body, "application/json", path) + + for _ in range(2): + with pytest.raises(ProxyException) as exc_info: + await read_request_body(request) + assert exc_info.value.code == "400" + assert exc_info.value.type == "invalid_request_error" + assert exc_info.value.param == "request_body" + assert exc_info.value.message == "Invalid JSON payload: expected an object" + assert _safe_get_request_parsed_body(request) is None + assert await request.body() == body + + +@pytest.mark.asyncio +@pytest.mark.parametrize("body", [b"[1e400]", b"1e400", b"[NaN]"]) +async def test_read_request_body_rejects_non_objects_from_json_fallback(body: bytes) -> None: + with pytest.raises(ProxyException) as exc_info: + await read_request_body(_starlette_request(body, "application/json")) + assert exc_info.value.code == "400" + assert exc_info.value.message == "Invalid JSON payload: expected an object" + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + "body, invalid_unicode", + [ + (b"[]", False), + (b"null", False), + (b'"value"', False), + (b"[1e400]", False), + (b'"\\ud800"', True), + (b'["\\ud800"]', True), + (b'{"value":"\\ud800"}', True), + ], +) +@pytest.mark.parametrize("dispatch", ["custom", "provider", "lens"]) +async def test_pass_through_body_validation_preserves_bytes(dispatch: str, body: bytes, invalid_unicode: bool) -> None: + from fastapi.routing import APIRoute + from litellm.proxy.lens.adapter import lens_request + from litellm.proxy.lens.buffering import LensRoute + from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import vertex_proxy_route + from litellm.proxy.pass_through_endpoints.pass_through_endpoints import create_pass_through_route + + path: Final = {"custom": "/v1/messages", "provider": "/vertex_ai/predict", "lens": "/lens/datasets"}[dispatch] + route: Final = { + "custom": APIRoute(path, create_pass_through_route(path, "https://upstream.test"), methods=["POST"]), + "provider": APIRoute("/vertex_ai/{endpoint:path}", vertex_proxy_route, methods=["POST"]), + "lens": LensRoute("/lens/{path:path}", lens_request, methods=["POST"]), + }[dispatch] + incoming: Final = _starlette_request(body, "application/json", path) + _, dispatched_scope = route.matches(incoming.scope) + request: Final = Request({**incoming.scope, **dispatched_scope}, incoming.receive) + + for _ in range(2): + if invalid_unicode: + with pytest.raises(ProxyException) as exc_info: + await read_request_body(request) + assert exc_info.value.code == "400" + else: + assert await read_request_body(request) == {} + assert await request.body() == body + + +@pytest.mark.asyncio +@pytest.mark.parametrize("optional", [False, True]) +@pytest.mark.parametrize("body", [b"null", b" \nnull\t", b"[]", b'"value"']) +async def test_null_body_respects_the_dispatched_body_requirement(optional: bool, body: bytes) -> None: + from fastapi.routing import APIRoute + from litellm.proxy.management_endpoints.key_management_endpoints import generate_key_fn + from litellm.proxy.spend_tracking.spend_management_endpoints import global_spend_end_users + + endpoint: Final = global_spend_end_users if optional else generate_key_fn + route: Final = APIRoute("/audit", endpoint, methods=["POST"]) + incoming: Final = _starlette_request(body, "application/json", "/audit") + _, dispatched_scope = route.matches(incoming.scope) + request: Final = Request({**incoming.scope, **dispatched_scope}, incoming.receive) + + if optional and body.strip() == b"null": + assert await read_request_body(request) == {} + assert await request.json() is None + else: + with pytest.raises(ProxyException) as exc_info: + await read_request_body(request) + assert exc_info.value.code == "400" + assert await request.body() == body + + @pytest.mark.asyncio async def test_read_request_body_marks_body_received_once_with_its_size(monkeypatch: pytest.MonkeyPatch): events: list[tuple[str, dict[str, str | int]]] = [] # mutable-ok: recorder for the injected phase_event double @@ -131,14 +225,20 @@ async def test_read_raw_json_body_is_none_for_form_bodies(): @pytest.mark.asyncio @pytest.mark.parametrize("content_type", ["application/x-protobuf", "application/protobuf; charset=binary"]) -async def test_protobuf_body_is_not_parsed_as_json(content_type): - # OTLP trace exports (POST /v1/traces) are binary protobuf; arbitrary bytes like these - # used to hit the JSON surrogate-repair path and fail auth with a 400. - body = b"\n\xa2\x01\n\x1c\n\x0cservice.name\x12\x0c\n\nswarm\xed\xa0\x80\xff" - request = _starlette_request(body, content_type) +@pytest.mark.parametrize( + "body", + [ + b"\n\xa2\x01\n\x1c\n\x0cservice.name\x12\x0c\n\nswarm\xed\xa0\x80\xff", + pytest.param(b"100000000", id="protobuf-also-json-number"), + ], +) +async def test_protobuf_body_is_not_parsed_as_json(content_type: str, body: bytes) -> None: + request: Final = _starlette_request(body, content_type) assert await read_request_body(request) == {} - assert await request.body() == body # body is still readable by the endpoint + assert await read_request_body(request) == {} + assert await read_raw_json_body(request) == body + assert await request.body() == body @pytest.mark.asyncio diff --git a/tests/unit/proxy/common_utils/test_reset_budget_job.py b/tests/unit/proxy/common_utils/test_reset_budget_job.py index 70f7774e691..183dd7919c1 100644 --- a/tests/unit/proxy/common_utils/test_reset_budget_job.py +++ b/tests/unit/proxy/common_utils/test_reset_budget_job.py @@ -113,6 +113,9 @@ class MockBatcher: self.litellm_projecttable = _Table("project", self) self.litellm_endusertable = _Table("enduser", self) + def execute_raw(self, query: str, *args: object) -> None: + self.calls.append({"table": "raw", "op": "execute_raw", "query": query, "args": args}) + async def commit(self): self.committed = True return self.calls @@ -2112,6 +2115,7 @@ def test_budget_cascade_writes_land_in_a_single_transaction(reset_budget_job, mo assert {(call["table"], call["op"]) for call in enduser_page.calls} == {("enduser", "update_many")} assert batcher.committed is True assert {(call["table"], call["op"]) for call in batcher.calls} == { + ("raw", "execute_raw"), ("team_membership", "update_many"), ("key", "update_many"), ("org", "update_many"), @@ -3393,6 +3397,35 @@ def test_budget_cascade_carries_overage_per_tier_when_rollover_enabled( counter_cache.in_memory_cache.delete_cache.assert_any_call(key="spend:team_member:member-1:team-1") +def test_budget_cascade_floors_membership_total_spend_before_zeroing_spend( + rollover_enabled: None, + reset_budget_job: ResetBudgetJob, + mock_prisma_client: MockPrismaClient, + monkeypatch: pytest.MonkeyPatch, +) -> None: + """Membership rows written before total_spend existed hold their history only in + spend. The cascade lifts total_spend to spend for the expiring tier's rows, in the + same batch and ahead of the zero/decrement, so the reset cannot erase it.""" + _make_counter_invalidation_job(monkeypatch) + budget: Final = _budget_row(budget_id="budget-legacy", budget_duration="7d", max_budget=10.0) + mock_prisma_client.data["budget"] = [budget] + membership: Final = type( + "Membership", + (), + {"user_id": "member-1", "team_id": "team-1", "spend": 15.0, "budget_id": "budget-legacy"}, + ) + mock_prisma_client.db.litellm_teammembership.set_find_many_results([membership]) + + asyncio.run(reset_budget_job.reset_budget_for_litellm_budget_table()) + + writes: Final = mock_prisma_client.db.batch_calls + repair_index: Final = next(i for i, call in enumerate(writes) if call["op"] == "execute_raw") + first_membership_reset: Final = next(i for i, call in enumerate(writes) if call["table"] == "team_membership") + assert repair_index < first_membership_reset, writes + assert writes[repair_index]["args"] == (["budget-legacy"],) + assert mock_prisma_client.db.batchers[-1].committed + + def test_budget_cascade_carries_enduser_overage_when_rollover_enabled( rollover_enabled, reset_budget_job, mock_prisma_client, monkeypatch ): diff --git a/tests/unit/proxy/common_utils/test_token_count_settings.py b/tests/unit/proxy/common_utils/test_token_count_settings.py index d7314f1a6d3..366d8b010d0 100644 --- a/tests/unit/proxy/common_utils/test_token_count_settings.py +++ b/tests/unit/proxy/common_utils/test_token_count_settings.py @@ -183,7 +183,7 @@ def test_every_shipped_token_count_model_resolves_to_a_mapped_aws_model() -> Non for name, count_model in count_models.items(): model: Final = count_model["model"] assert get_bedrock_base_model(model) in aws_models - assert cost_map[name]["litellm_provider"] in ("bedrock", "bedrock_converse") + assert cost_map[name]["litellm_provider"] in ("bedrock", "bedrock_converse", "bedrock_mantle") assert "region" not in count_model or count_model["region"].strip() diff --git a/tests/unit/proxy/common_utils/test_upsert_budget_membership.py b/tests/unit/proxy/common_utils/test_upsert_budget_membership.py index 1f7154f0a74..4aa1a7f7cb1 100644 --- a/tests/unit/proxy/common_utils/test_upsert_budget_membership.py +++ b/tests/unit/proxy/common_utils/test_upsert_budget_membership.py @@ -267,10 +267,17 @@ async def test_create_from_temp_pair_never_snapshots_team_default(mock_tx, fake_ @pytest.mark.asyncio -async def test_temp_pair_on_shared_default_member_creates_bare_row(mock_tx, fake_user): +async def test_temp_pair_on_shared_default_member_clones_default_with_its_reset_schedule(mock_tx, fake_user): expiry = datetime(2100, 1, 1, tzinfo=timezone.utc) + default_reset_at = datetime(2026, 11, 1, tzinfo=timezone.utc) mock_tx.litellm_budgettable.find_unique = AsyncMock( - return_value=budget_row(budget_id="team-default-budget-1", max_budget=0.4, rpm_limit=10) + return_value=budget_row( + budget_id="team-default-budget-1", + max_budget=0.4, + rpm_limit=10, + budget_duration="30d", + budget_reset_at=default_reset_at, + ) ) await upsert_budget_and_membership( mock_tx, @@ -282,10 +289,14 @@ async def test_temp_pair_on_shared_default_member_creates_bare_row(mock_tx, fake team_default_budget_id="team-default-budget-1", ) - mock_tx.litellm_budgettable.find_unique.assert_not_awaited() mock_tx.litellm_budgettable.update.assert_not_called() + mock_tx.litellm_teammembership.update.assert_not_called() assert stored_budget_row(mock_tx) == { "model_max_budget": "{}", + "max_budget": 0.4, + "rpm_limit": 10, + "budget_duration": "30d", + "budget_reset_at": default_reset_at, "temp_budget_increase": 1.0, "temp_budget_expiry": expiry, } diff --git a/tests/unit/proxy/db/db_transaction_queue/test_redis_update_buffer.py b/tests/unit/proxy/db/db_transaction_queue/test_redis_update_buffer.py index f30606ac2f1..24c12e06c9c 100644 --- a/tests/unit/proxy/db/db_transaction_queue/test_redis_update_buffer.py +++ b/tests/unit/proxy/db/db_transaction_queue/test_redis_update_buffer.py @@ -5,7 +5,6 @@ from unittest.mock import AsyncMock, MagicMock, patch import pytest - from litellm.constants import REDIS_DAILY_TAG_SPEND_UPDATE_BUFFER_KEY from litellm.litellm_core_utils.safe_json_dumps import safe_dumps from litellm.proxy._types import DailyTagSpendTransaction @@ -769,3 +768,18 @@ async def test_store_spend_logs_in_redis_is_off_unless_transaction_buffering_is_ assert await buffer.store_spend_logs_in_redis([{"request_id": "a"}]) is False assert redis.rows == [] + + +@pytest.mark.asyncio +async def test_tool_discoveries_go_back_on_the_queue_when_the_redis_push_fails(): + from litellm.proxy.db.db_transaction_queue.tool_discovery_queue import ToolDiscoveryQueue + + redis_cache = MagicMock() + redis_cache.async_rpush_pipeline = AsyncMock(side_effect=ConnectionError("redis down")) + queue = ToolDiscoveryQueue() + queue.add_update({"tool_name": "get_weather", "origin": "user_defined"}) + queue.add_update({"tool_name": "get_weather", "origin": "user_defined"}) + + await RedisUpdateBuffer(redis_cache=redis_cache).store_tool_discoveries_in_redis(queue) + + assert queue.flush() == [{"tool_name": "get_weather", "origin": "user_defined", "call_count": 2}] diff --git a/tests/unit/proxy/db/db_transaction_queue/test_tool_discovery_queue.py b/tests/unit/proxy/db/db_transaction_queue/test_tool_discovery_queue.py index e400ad16e84..0a015255f2e 100644 --- a/tests/unit/proxy/db/db_transaction_queue/test_tool_discovery_queue.py +++ b/tests/unit/proxy/db/db_transaction_queue/test_tool_discovery_queue.py @@ -5,9 +5,9 @@ Unit tests for ToolDiscoveryQueue. import pytest - from litellm.proxy.db.db_transaction_queue.tool_discovery_queue import ( ToolDiscoveryQueue, + aggregate_tool_discoveries, ) @@ -16,57 +16,50 @@ def queue(): return ToolDiscoveryQueue() -def test_add_single_tool(queue): +def test_a_tool_seen_once_flushes_with_call_count_one(queue): queue.add_update({"tool_name": "my_tool", "origin": "user_defined"}) - items = queue.flush() - assert len(items) == 1 - assert items[0]["tool_name"] == "my_tool" - assert items[0]["origin"] == "user_defined" + assert queue.flush() == [{"tool_name": "my_tool", "origin": "user_defined", "call_count": 1}] -def test_deduplication_same_name(queue): - """Adding the same tool_name twice should only keep the first.""" - queue.add_update({"tool_name": "tool_a", "origin": "mcp_server"}) - queue.add_update({"tool_name": "tool_a", "origin": "user_defined"}) - items = queue.flush() - assert len(items) == 1 - assert items[0]["origin"] == "mcp_server" # first wins +def test_repeated_sightings_fold_into_one_row_counting_every_call(queue): + queue.add_update({"tool_name": "tool_a", "origin": "mcp_server", "created_by": "alice"}) + queue.add_update({"tool_name": "tool_a", "origin": "user_defined", "created_by": "bob"}) + queue.add_update({"tool_name": "tool_a"}) + assert queue.flush() == [{"tool_name": "tool_a", "origin": "mcp_server", "created_by": "alice", "call_count": 3}] -def test_deduplication_different_names(queue): +def test_distinct_tools_each_get_their_own_row(queue): queue.add_update({"tool_name": "tool_a"}) queue.add_update({"tool_name": "tool_b"}) - items = queue.flush() - assert len(items) == 2 - names = {i["tool_name"] for i in items} - assert names == {"tool_a", "tool_b"} - - -def test_flush_clears_pending(queue): - queue.add_update({"tool_name": "tool_x"}) - items1 = queue.flush() - assert len(items1) == 1 - items2 = queue.flush() - assert len(items2) == 0 - - -def test_seen_names_reset_after_flush(queue): - """Seen-set is cleared on flush so the same tool can re-enter the next cycle.""" queue.add_update({"tool_name": "tool_a"}) - queue.flush() - queue.add_update({"tool_name": "tool_a"}) # same tool, new cycle - items = queue.flush() - assert len(items) == 1 - assert items[0]["tool_name"] == "tool_a" + assert queue.flush() == [ + {"tool_name": "tool_a", "call_count": 2}, + {"tool_name": "tool_b", "call_count": 1}, + ] + + +def test_flush_clears_pending_and_the_next_cycle_counts_from_zero(queue): + queue.add_update({"tool_name": "tool_x"}) + queue.add_update({"tool_name": "tool_x"}) + assert queue.flush() == [{"tool_name": "tool_x", "call_count": 2}] + assert queue.flush() == [] + queue.add_update({"tool_name": "tool_x"}) + assert queue.flush() == [{"tool_name": "tool_x", "call_count": 1}] def test_empty_tool_name_ignored(queue): queue.add_update({"tool_name": ""}) queue.add_update({"tool_name": None}) # type: ignore[arg-type] - items = queue.flush() - assert len(items) == 0 + assert queue.flush() == [] -def test_flush_returns_list(queue): - result = queue.flush() - assert isinstance(result, list) +def test_aggregate_sums_call_counts_across_workers_flushes(): + worker_a = [{"tool_name": "get_weather", "origin": "user_defined", "call_count": 3}] + worker_b = [ + {"tool_name": "get_weather", "origin": "mcp_server", "call_count": 2}, + {"tool_name": "search", "call_count": 1}, + ] + assert aggregate_tool_discoveries([*worker_a, *worker_b]) == ( + {"tool_name": "get_weather", "origin": "user_defined", "call_count": 5}, + {"tool_name": "search", "call_count": 1}, + ) diff --git a/tests/unit/proxy/db/mcp_server/test_db.py b/tests/unit/proxy/db/mcp_server/test_db.py index e2440e49f19..51c350dc1ce 100644 --- a/tests/unit/proxy/db/mcp_server/test_db.py +++ b/tests/unit/proxy/db/mcp_server/test_db.py @@ -3,8 +3,7 @@ from unittest.mock import AsyncMock, MagicMock import pytest - -from litellm.proxy._experimental.mcp_server.db import ( +from litellm.proxy.mcp_server.db import ( approve_mcp_server, get_mcp_servers_by_team, reject_mcp_server, diff --git a/tests/unit/proxy/db/test_db_spend_update_writer.py b/tests/unit/proxy/db/test_db_spend_update_writer.py index 7437042e4bd..a42b6404278 100644 --- a/tests/unit/proxy/db/test_db_spend_update_writer.py +++ b/tests/unit/proxy/db/test_db_spend_update_writer.py @@ -19,7 +19,7 @@ from redis.exceptions import DataError import litellm from litellm._logging import verbose_proxy_logger from litellm._service_logger import ServiceTypes -from litellm.constants import DB_SPEND_UPDATE_JOB_NAME, REDIS_UPDATE_BUFFER_KEY, SPEND_ROLLUP_LOCK_TIMEOUT_MS +from litellm.constants import SPEND_ROLLUP_LOCK_TIMEOUT_MS from litellm.proxy._types import DailyTagSpendTransaction, Litellm_EntityType, SpendUpdateQueueItem from litellm.proxy.db.db_spend_update_writer import ( _TEAM_ADVISORY_LOCK_SQL, @@ -29,13 +29,13 @@ from litellm.proxy.db.db_spend_update_writer import ( _SpendTableName, ) from litellm.proxy.db.db_transaction_queue.daily_spend_update_queue import DailySpendUpdateQueue -from litellm.proxy.db.db_transaction_queue.pod_lock_manager import PodLockManager from litellm.proxy.db.db_transaction_queue.redis_update_buffer import RedisUpdateBuffer from litellm.proxy.db.db_transaction_queue.spend_update_queue import SpendUpdateQueue from litellm.proxy.db.db_transaction_queue.window_spend_update_queue import ( build_window_spend_transaction, ) from litellm.proxy.db.rollup_lock_timeout import ROLLUP_LOCK_TIMEOUT_SQL +from litellm.responses.streaming_iterator import drain_logging_tasks from litellm.types.caching import RedisPipelineLpopOperation, RedisPipelineRpushOperation from tests.unit.proxy.db.fake_prisma_engine import engine_call @@ -1128,7 +1128,10 @@ async def test_commit_spend_updates_to_db_writes_team_member_spend_in_one_roster assert "members_with_roles @> jsonb_build_array(jsonb_build_object('user_id', member.user_id))" in statement assert "ON CONFLICT (user_id, team_id) DO UPDATE" in statement assert 'spend = "LiteLLM_TeamMembership".spend + EXCLUDED.spend' in statement - assert 'total_spend = "LiteLLM_TeamMembership".total_spend + EXCLUDED.total_spend' in statement + assert ( + 'total_spend = GREATEST("LiteLLM_TeamMembership".total_spend, "LiteLLM_TeamMembership".spend)' + " + EXCLUDED.total_spend" + ) in statement @pytest.mark.asyncio @@ -2158,46 +2161,122 @@ async def test_commit_spend_updates_to_db_increments_key_total_spend_alongside_s @pytest.mark.asyncio -async def test_update_database_creates_single_task(): +async def test_shutdown_drain_finishes_the_rollups_update_database_started(): """ - Test that update_database() fires exactly 1 asyncio.create_task() call - (the batched task) instead of the previous 11. + Regression for LIT-6027. The key, team and daily rollups ran in an unreferenced asyncio task, + so the shutdown sequence (flush, drain_logging_tasks, flush) never waited for them and spend + logs landed without matching daily rows. Once update_database returns, drain_logging_tasks + must leave every rollup for that request in its queue. """ - db_writer = DBSpendUpdateWriter() - - # Mock all helpers so nothing real runs + db_writer: Final = DBSpendUpdateWriter() db_writer._insert_spend_log_to_db = AsyncMock() - db_writer._batch_database_updates = AsyncMock() - + prisma: Final = MagicMock() + prisma.get_request_status = MagicMock(return_value="success") + fake_payload: Final = { + "request_id": "req-lit-6027", + "api_key": "hashed-key", + "user": "test-user", + "team_id": "test-team", + "agent_id": None, + "startTime": "2024-01-01T00:00:00", + "endTime": "2024-01-01T00:00:01", + "model": "gpt-4o-mini", + "custom_llm_provider": "openai", + "model_group": "gpt-4o-mini", + "prompt_tokens": 10, + "completion_tokens": 5, + "spend": 0.0, + "metadata": '{"usage_object": {}}', + } with ( patch("litellm.proxy.proxy_server.disable_spend_logs", False), - patch("litellm.proxy.proxy_server.prisma_client", MagicMock()), + patch("litellm.proxy.proxy_server.prisma_client", prisma), patch("litellm.proxy.proxy_server.user_api_key_cache", MagicMock()), patch("litellm.proxy.proxy_server.litellm_proxy_budget_name", "test-budget"), - patch("litellm.proxy.db.db_spend_update_writer.asyncio.create_task") as mock_create_task, + patch("litellm.proxy.spend_tracking.spend_tracking_utils.get_logging_payload", return_value=fake_payload), ): await db_writer.update_database( token="test-token", user_id="test-user", - end_user_id="test-end-user", + end_user_id=None, + team_id="test-team", + org_id=None, + kwargs={"model": "gpt-4o-mini", "custom_llm_provider": "openai"}, + completion_response=MagicMock(), start_time=datetime.now(), end_time=datetime.now(), - team_id="test-team", - org_id="test-org", - completion_response=MagicMock(), response_cost=0.1, - kwargs={"model": "gpt-4", "custom_llm_provider": "openai"}, ) + await drain_logging_tasks() - # Exactly 1 create_task call (the batch), not 11 - assert mock_create_task.call_count == 1 + spend: Final = await db_writer.spend_update_queue.flush_and_get_aggregated_db_spend_update_transactions() + assert spend["key_list_transactions"] == {"test-token": 0.1} + assert spend["team_list_transactions"] == {"test-team": 0.1} + daily_user: Final = ( + await db_writer.daily_spend_update_queue.flush_and_get_aggregated_daily_spend_update_transactions() + ) + daily_team: Final = ( + await db_writer.daily_team_spend_update_queue.flush_and_get_aggregated_daily_spend_update_transactions() + ) + assert daily_user is not None and daily_team is not None + (user_row,) = daily_user.values() + (team_row,) = daily_team.values() + assert (user_row["api_requests"], user_row["spend"]) == (1, 0.1) + assert (team_row["api_requests"], team_row["spend"]) == (1, 0.1) @pytest.mark.asyncio -async def test_batch_database_updates_isolation_on_failure(): +async def test_shutdown_drain_waits_for_an_in_flight_rollup_enqueue(): + """ + Regression for LIT-6027. A rollup enqueue that is still in flight when the shutdown drain + starts (here: blocked on a full spend queue) must be finished by the time drain_logging_tasks + returns, so the second shutdown flush commits it. + """ + enqueue_started: Final = asyncio.Event() + release_enqueue: Final = asyncio.Event() + + class _BlockedSpendQueue(SpendUpdateQueue): + async def add_update(self, update: SpendUpdateQueueItem): + enqueue_started.set() + await release_enqueue.wait() + await super().add_update(update) + + db_writer: Final = DBSpendUpdateWriter() + db_writer.spend_update_queue = _BlockedSpendQueue() + db_writer._insert_spend_log_to_db = AsyncMock() + with ( + patch("litellm.proxy.proxy_server.disable_spend_logs", True), + patch("litellm.proxy.proxy_server.prisma_client", MagicMock()), + patch("litellm.proxy.proxy_server.user_api_key_cache", MagicMock()), + patch("litellm.proxy.proxy_server.litellm_proxy_budget_name", "test-budget"), + ): + await db_writer.update_database( + token="t1", + user_id=None, + end_user_id=None, + team_id="team-1", + org_id=None, + kwargs={"model": "gpt-4o-mini", "custom_llm_provider": "openai"}, + completion_response=MagicMock(), + start_time=datetime.now(), + end_time=datetime.now(), + response_cost=0.1, + ) + await enqueue_started.wait() + drain: Final = asyncio.create_task(drain_logging_tasks()) + release_enqueue.set() + await drain + spend: Final = await db_writer.spend_update_queue.flush_and_get_aggregated_db_spend_update_transactions() + + assert spend["key_list_transactions"] == {"t1": 0.1} + assert spend["team_list_transactions"] == {"team-1": 0.1} + + +@pytest.mark.asyncio +async def test_batch_database_updates_isolation_on_failure(caplog: pytest.LogCaptureFixture): """ Test that if one helper inside _batch_database_updates raises, - all other helpers still execute. + all other helpers still execute and the failure is reported at ERROR with the request id. """ db_writer = DBSpendUpdateWriter() @@ -2217,6 +2296,7 @@ async def test_batch_database_updates_isolation_on_failure(): db_writer.add_spend_log_transaction_to_daily_org_transaction = AsyncMock() db_writer.add_spend_log_transaction_to_daily_tag_transaction = AsyncMock() + caplog.set_level(logging.ERROR, logger=verbose_proxy_logger.name) await db_writer._batch_database_updates( response_cost=0.1, user_id="u1", @@ -2226,7 +2306,7 @@ async def test_batch_database_updates_isolation_on_failure(): end_user_id="eu1", prisma_client=MagicMock(), litellm_proxy_budget_name="budget", - payload={"key": "value"}, + payload={"request_id": "req-iso", "key": "value"}, ) # _update_key_db raised, but all others should still have been called @@ -2242,6 +2322,48 @@ async def test_batch_database_updates_isolation_on_failure(): db_writer.add_spend_log_transaction_to_daily_team_transaction.assert_awaited_once() db_writer.add_spend_log_transaction_to_daily_org_transaction.assert_awaited_once() db_writer.add_spend_log_transaction_to_daily_tag_transaction.assert_awaited_once() + assert any( + "_update_key_db" in record.getMessage() and "req-iso" in record.getMessage() + for record in caplog.records + if record.levelno >= logging.ERROR + ) + + +@pytest.mark.asyncio +async def test_malformed_metadata_keeps_the_daily_rollup_row_and_is_reported(caplog: pytest.LogCaptureFixture): + """ + Regression for LIT-6027. A spend log whose metadata is not JSON used to vanish from every + daily rollup while the spend log itself persisted, with nothing above debug in the logs. + """ + writer: Final = DBSpendUpdateWriter() + prisma: Final = MagicMock() + prisma.get_request_status = MagicMock(return_value="success") + payload: Final = { + "request_id": "req-bad-metadata", + "user": "test-user", + "startTime": "2024-01-01T00:00:00", + "endTime": "2024-01-01T00:00:01", + "api_key": "test-key", + "model": "gpt-4o-mini", + "custom_llm_provider": "openai", + "model_group": "gpt-4o-mini", + "prompt_tokens": 100, + "completion_tokens": 50, + "spend": 0.05, + "metadata": "{not-json", + } + caplog.set_level(logging.ERROR, logger=verbose_proxy_logger.name) + + await writer.add_spend_log_transaction_to_daily_user_transaction( # pyright: ignore[reportUnknownMemberType] # prisma_client param is untyped on the writer + payload=payload, prisma_client=prisma + ) + + daily: Final = await writer.daily_spend_update_queue.flush_and_get_aggregated_daily_spend_update_transactions() + (row,) = daily.values() + assert (row["api_requests"], row["spend"], row["prompt_tokens"]) == (1, 0.05, 100) + assert any( + "req-bad-metadata" in record.getMessage() for record in caplog.records if record.levelno >= logging.ERROR + ) @pytest.mark.asyncio @@ -2394,31 +2516,6 @@ class _InMemoryRedis: return [self.lists.pop(op["key"], None) for op in lpop_list] -@pytest.mark.asyncio -@pytest.mark.parametrize("lock_held_by_another_pod", [False, True]) -async def test_commit_with_redis_writes_discovered_tools_on_leader_and_non_leader(lock_held_by_another_pod: bool): - redis = _InMemoryRedis() - if lock_held_by_another_pod: - assert await PodLockManager(redis_cache=redis).acquire_lock(cronjob_id=DB_SPEND_UPDATE_JOB_NAME) - db_writer = DBSpendUpdateWriter(redis_cache=redis) - db_writer.pod_lock_manager.redis_cache = redis - db_writer.tool_discovery_queue.add_update({"tool_name": "get_weather", "origin": "user_defined"}) - prisma_client = MagicMock() - prisma_client.db.litellm_tooltable.upsert = AsyncMock() - - await db_writer._commit_spend_updates_to_db_with_redis( - prisma_client=prisma_client, - n_retry_times=0, - proxy_logging_obj=MagicMock(), - ) - - upserted = [c.kwargs["where"] for c in prisma_client.db.litellm_tooltable.upsert.await_args_list] - assert upserted == [{"tool_name": "get_weather"}] - assert (REDIS_UPDATE_BUFFER_KEY in redis.lists) is lock_held_by_another_pod, ( - f"spend buffer left in redis={list(redis.lists)}, only the lock holder may drain it" - ) - - @pytest.mark.asyncio async def test_commit_with_redis_requeues_all_on_db_failure(): """ @@ -2775,12 +2872,12 @@ async def test_update_database_does_not_deepcopy_on_request_path(): """ Regression for LIT-4088: copy.deepcopy must not run while the caller awaits update_database(). The deepcopy used to isolate the daily-spend helpers is - relocated into the _batch_database_updates background task, and the spend-log + relocated into the _batch_database_updates logging task, and the spend-log insert receives the payload directly (all consumers are read-only). Asserts: - zero copy.deepcopy calls happen on the awaited request path - - the batch background task still hands the daily helpers an isolated copy + - the tracked rollup task still hands the daily helpers an isolated copy (mutating the original after the task ran does not bleed into it) - the spend-log insert receives the payload on the request path with the correct content @@ -2856,16 +2953,13 @@ async def test_update_database_does_not_deepcopy_on_request_path(): response_cost=0.1, ) - # Request path is clean: nothing was deepcopied while the caller awaited. assert len(deepcopy_calls) == 0 # The spend-log insert ran inline on the request path with the real payload. assert captured_spend_log["ref"] is fake_payload assert captured_spend_log["model_at_call"] == "gpt-4" assert fake_payload["spend"] == 0.1 - - # Now let the batch background task run; the deepcopy happens here. - await asyncio.sleep(0) + await drain_logging_tasks() assert len(deepcopy_calls) >= 1 assert len(captured_batch_payloads) == 1 @@ -3267,7 +3361,6 @@ async def test_failed_window_spend_commit_requeues_the_increments_and_continues_ await db_writer.window_spend_update_queue.add_update(transaction) db = _WindowSpendFakeDB() db.query_raw = AsyncMock(side_effect=Exception("connection reset")) - db_writer._flush_tool_discovery_queue = AsyncMock() await db_writer._commit_spend_updates_to_db_without_redis_buffer( prisma_client=_WindowSpendFakePrisma(db), @@ -3275,7 +3368,6 @@ async def test_failed_window_spend_commit_requeues_the_increments_and_continues_ proxy_logging_obj=MagicMock(), ) - db_writer._flush_tool_discovery_queue.assert_called_once() requeued = await db_writer.window_spend_update_queue.flush_and_get_aggregated_window_spend_transactions() assert requeued == (transaction,) @@ -3351,7 +3443,6 @@ async def test_failed_daily_spend_commit_is_requeued_only_when_the_rows_are_prov db_writer = DBSpendUpdateWriter() await db_writer.daily_spend_update_queue.add_update({"user-key": _daily_txn(user_id="user-1")}) db = _DailySpendFakeDB(failing_table="LiteLLM_DailyUserSpend", failure=failure) - db_writer._flush_tool_discovery_queue = AsyncMock() proxy_logging_obj = MagicMock() proxy_logging_obj.failure_handler = AsyncMock() @@ -3377,7 +3468,6 @@ async def test_failed_daily_spend_commit_drops_only_the_batch_that_was_sent(): {f"user-{i:03d}": _daily_txn(user_id=f"user-{i:03d}") for i in range(150)} ) db = _DailySpendFakeDB(failing_table="LiteLLM_DailyUserSpend", failure=httpx.ReadTimeout("no reply")) - db_writer._flush_tool_discovery_queue = AsyncMock() proxy_logging_obj = MagicMock() proxy_logging_obj.failure_handler = AsyncMock() @@ -3405,7 +3495,6 @@ async def test_failed_daily_spend_commit_requeues_the_rows_and_flushes_the_other team_txn = {key: value for key, value in _daily_txn().items() if key != "user_id"} | {"team_id": "team-1"} await db_writer.daily_team_spend_update_queue.add_update({"team-key": team_txn}) db = _DailySpendFakeDB(failing_table="LiteLLM_DailyUserSpend") - db_writer._flush_tool_discovery_queue = AsyncMock() proxy_logging_obj = MagicMock() proxy_logging_obj.failure_handler = AsyncMock() @@ -3416,7 +3505,6 @@ async def test_failed_daily_spend_commit_requeues_the_rows_and_flushes_the_other assert _daily_upserts(db, "LiteLLM_DailyUserSpend") == [] (team_upsert,) = _daily_upserts(db, "LiteLLM_DailyTeamSpend") assert _row_values(team_upsert, "team_id") == ["team-1"] - db_writer._flush_tool_discovery_queue.assert_called_once() db.failing_table = None await db_writer._commit_spend_updates_to_db_without_redis_buffer( @@ -3643,7 +3731,6 @@ async def test_failed_window_spend_commit_is_requeued_only_when_the_rows_are_pro ) await db_writer.window_spend_update_queue.add_update(transaction) db = _WindowSpendFailureDB(failure) - db_writer._flush_tool_discovery_queue = AsyncMock() await db_writer._commit_spend_updates_to_db_without_redis_buffer( prisma_client=_WindowSpendFakePrisma(db), diff --git a/tests/unit/proxy/db/test_tool_registry_writer.py b/tests/unit/proxy/db/test_tool_registry_writer.py index c9df665741d..76898b0eeab 100644 --- a/tests/unit/proxy/db/test_tool_registry_writer.py +++ b/tests/unit/proxy/db/test_tool_registry_writer.py @@ -3,22 +3,28 @@ Unit tests for tool_registry_writer.py — uses a mock prisma client that exposes litellm_tooltable.upsert / find_many / find_unique. """ +import json from datetime import datetime, timezone from unittest.mock import AsyncMock, MagicMock import pytest -from prisma.errors import PrismaError - +from prisma.errors import PrismaError, RawQueryError +from litellm.constants import DB_SPEND_UPDATE_JOB_NAME, REDIS_TOOL_DISCOVERY_BUFFER_KEY, TOOL_DISCOVERY_COMMIT_JOB_NAME +from litellm.proxy.db.db_transaction_queue.pod_lock_manager import PodLockManager +from litellm.proxy.db.db_transaction_queue.redis_update_buffer import RedisUpdateBuffer +from litellm.proxy.db.db_transaction_queue.tool_discovery_queue import ToolDiscoveryQueue from litellm.proxy.db.tool_registry_writer import ( ToolPolicyRegistry, batch_upsert_tools, + commit_tool_discoveries, get_tool, get_tool_policy_registry, get_tools_by_names, list_tools, update_tool_policy, ) +from litellm.types.caching import RedisPipelineLpopOperation, RedisPipelineRpushOperation def _mock_row(**kwargs): @@ -62,6 +68,7 @@ def _make_prisma( prisma = MagicMock() prisma.db.litellm_tooltable = MagicMock() prisma.db.litellm_tooltable.upsert = AsyncMock(return_value=upsert_return) + prisma.db.execute_raw = AsyncMock(return_value=1) prisma.db.litellm_tooltable.find_many = AsyncMock( return_value=find_many_rows if find_many_rows is not None else [] ) @@ -73,28 +80,32 @@ def _make_prisma( return prisma +def _statement(prisma) -> tuple[str, tuple[object, ...]]: + prisma.db.execute_raw.assert_awaited_once() + sql, *params = prisma.db.execute_raw.call_args.args + return sql, tuple(params) + + @pytest.mark.asyncio -async def test_batch_upsert_tools_calls_upsert(): +async def test_batch_upsert_tools_inserts_a_new_tool_with_the_batch_call_count_and_adds_it_on_conflict(): prisma = _make_prisma() - items = [{"tool_name": "tool_a", "origin": "mcp_server", "created_by": None}] - await batch_upsert_tools(prisma, items) - prisma.db.litellm_tooltable.upsert.assert_awaited_once() - call_kw = prisma.db.litellm_tooltable.upsert.call_args.kwargs - assert call_kw["where"] == {"tool_name": "tool_a"} - assert call_kw["data"]["create"]["tool_name"] == "tool_a" - assert call_kw["data"]["create"]["origin"] == "mcp_server" - assert call_kw["data"]["create"]["input_policy"] == "untrusted" - assert call_kw["data"]["create"]["output_policy"] == "untrusted" - assert call_kw["data"]["create"]["call_count"] == 1 - assert call_kw["data"]["update"]["call_count"] == {"increment": 1} - assert "updated_at" in call_kw["data"]["update"] + await batch_upsert_tools( + prisma, [{"tool_name": "tool_a", "origin": "mcp_server", "created_by": None, "call_count": 4}] + ) + sql, params = _statement(prisma) + assert sql.startswith('INSERT INTO "LiteLLM_ToolTable"') + assert 'ON CONFLICT ("tool_name") DO UPDATE SET' in sql + assert '"call_count" = "LiteLLM_ToolTable"."call_count" + EXCLUDED."call_count"' in sql + assert '"input_policy"' not in sql, "policies come from the table defaults and are never overwritten" + assert params[1:] == ("tool_a", "mcp_server", 4, "system", "system", None, None, None, None) + prisma.db.litellm_tooltable.upsert.assert_not_awaited() @pytest.mark.asyncio async def test_batch_upsert_tools_empty_list(): prisma = _make_prisma() await batch_upsert_tools(prisma, []) - prisma.db.litellm_tooltable.upsert.assert_not_awaited() + prisma.db.execute_raw.assert_not_awaited() @pytest.mark.asyncio @@ -102,21 +113,22 @@ async def test_batch_upsert_tools_skips_empty_names(): prisma = _make_prisma() items = [{"tool_name": "", "origin": None}, {"tool_name": None}] # type: ignore[list-item] await batch_upsert_tools(prisma, items) - prisma.db.litellm_tooltable.upsert.assert_not_awaited() + prisma.db.execute_raw.assert_not_awaited() @pytest.mark.asyncio -async def test_batch_upsert_multiple_tools_calls_upsert_per_tool(): +async def test_batch_upsert_many_tools_is_one_statement_with_one_row_per_distinct_tool(): prisma = _make_prisma() items = [ - {"tool_name": "tool_a", "origin": "mcp_server", "created_by": None}, - {"tool_name": "tool_b", "origin": "user_defined", "created_by": "alice"}, + {"tool_name": "tool_a", "origin": "mcp_server", "created_by": None, "call_count": 2}, + {"tool_name": "tool_b", "origin": "user_defined", "created_by": "alice", "call_count": 1}, + {"tool_name": "tool_a", "origin": "user_defined", "created_by": "bob", "call_count": 5}, ] await batch_upsert_tools(prisma, items) - assert prisma.db.litellm_tooltable.upsert.await_count == 2 - calls = prisma.db.litellm_tooltable.upsert.call_args_list - assert calls[0].kwargs["where"]["tool_name"] == "tool_a" - assert calls[1].kwargs["where"]["tool_name"] == "tool_b" + sql, params = _statement(prisma) + assert sql.count("$1::text") == 1 and "$11::text" in sql and "$21::text" not in sql + assert params[1:10] == ("tool_a", "mcp_server", 7, "system", "system", None, None, None, None) + assert params[11:20] == ("tool_b", "user_defined", 1, "alice", "alice", None, None, None, None) @pytest.mark.asyncio @@ -264,20 +276,14 @@ async def test_update_tool_policy_calls_upsert_then_get_tool(): assert call_kw["where"] == {"tool_name": "my_tool"} assert call_kw["data"]["update"]["input_policy"] == "blocked" assert call_kw["data"]["update"]["updated_by"] == "admin" - prisma.db.litellm_tooltable.find_unique.assert_awaited_with( - where={"tool_name": "my_tool"} - ) + prisma.db.litellm_tooltable.find_unique.assert_awaited_with(where={"tool_name": "my_tool"}) @pytest.mark.asyncio async def test_get_tools_by_names_returns_policy_map(): rows = [ - _mock_row( - tool_name="tool_a", input_policy="trusted", output_policy="untrusted" - ), - _mock_row( - tool_name="tool_b", input_policy="blocked", output_policy="untrusted" - ), + _mock_row(tool_name="tool_a", input_policy="trusted", output_policy="untrusted"), + _mock_row(tool_name="tool_b", input_policy="blocked", output_policy="untrusted"), ] prisma = _make_prisma(find_many_rows=rows) result = await get_tools_by_names(prisma, ["tool_a", "tool_b"]) @@ -285,9 +291,7 @@ async def test_get_tools_by_names_returns_policy_map(): "tool_a": ("trusted", "untrusted"), "tool_b": ("blocked", "untrusted"), } - prisma.db.litellm_tooltable.find_many.assert_awaited_once_with( - where={"tool_name": {"in": ["tool_a", "tool_b"]}} - ) + prisma.db.litellm_tooltable.find_many.assert_awaited_once_with(where={"tool_name": {"in": ["tool_a", "tool_b"]}}) @pytest.mark.asyncio @@ -382,12 +386,8 @@ async def test_sync_tool_policy_from_db_retries_on_transport_error_first_read(): return [] mock_prisma_client = MagicMock() - mock_prisma_client.db.litellm_tooltable.find_many = AsyncMock( - side_effect=_flaky_find_many - ) - mock_prisma_client.db.litellm_objectpermissiontable.find_many = AsyncMock( - return_value=[] - ) + mock_prisma_client.db.litellm_tooltable.find_many = AsyncMock(side_effect=_flaky_find_many) + mock_prisma_client.db.litellm_objectpermissiontable.find_many = AsyncMock(return_value=[]) mock_prisma_client.attempt_db_reconnect = AsyncMock(return_value=True) mock_prisma_client._db_auth_reconnect_timeout_seconds = 2.0 mock_prisma_client._db_auth_reconnect_lock_timeout_seconds = 0.1 @@ -397,10 +397,7 @@ async def test_sync_tool_policy_from_db_retries_on_transport_error_first_read(): assert len(invocations) == 2 mock_prisma_client.attempt_db_reconnect.assert_awaited_once() reconnect_kwargs = mock_prisma_client.attempt_db_reconnect.await_args.kwargs - assert ( - reconnect_kwargs["reason"] - == "sync_tool_policy_from_db_tools_lookup_failure" - ) + assert reconnect_kwargs["reason"] == "sync_tool_policy_from_db_tools_lookup_failure" assert registry.is_initialized() @@ -421,9 +418,7 @@ async def test_sync_tool_policy_from_db_retries_on_transport_error_second_read() mock_prisma_client = MagicMock() mock_prisma_client.db.litellm_tooltable.find_many = AsyncMock(return_value=[]) - mock_prisma_client.db.litellm_objectpermissiontable.find_many = AsyncMock( - side_effect=_flaky_perms_find_many - ) + mock_prisma_client.db.litellm_objectpermissiontable.find_many = AsyncMock(side_effect=_flaky_perms_find_many) mock_prisma_client.attempt_db_reconnect = AsyncMock(return_value=True) mock_prisma_client._db_auth_reconnect_timeout_seconds = 2.0 mock_prisma_client._db_auth_reconnect_lock_timeout_seconds = 0.1 @@ -433,7 +428,142 @@ async def test_sync_tool_policy_from_db_retries_on_transport_error_second_read() assert len(perms_invocations) == 2 mock_prisma_client.attempt_db_reconnect.assert_awaited_once() reconnect_kwargs = mock_prisma_client.attempt_db_reconnect.await_args.kwargs - assert ( - reconnect_kwargs["reason"] - == "sync_tool_policy_from_db_perms_lookup_failure" + assert reconnect_kwargs["reason"] == "sync_tool_policy_from_db_perms_lookup_failure" + + +class _InMemoryRedis: + def __init__(self) -> None: + self.store: dict[str, str] = {} + self.lists: dict[str, list[object]] = {} + + async def async_set_cache(self, key: str, value: str, nx: bool = False, **kwargs: object) -> bool | None: + if nx and key in self.store: + return None + self.store[key] = json.dumps(value) + return True + + async def async_get_cache(self, key: str, **kwargs: object) -> str | None: + raw = self.store.get(key) + return json.loads(raw) if raw is not None else None + + async def async_delete_cache(self, key: str) -> int: + return 1 if self.store.pop(key, None) is not None else 0 + + async def async_rpush_pipeline(self, rpush_list: list[RedisPipelineRpushOperation]) -> list[int]: + for op in rpush_list: + self.lists.setdefault(op["key"], []).extend(op["values"]) + return [len(self.lists[op["key"]]) for op in rpush_list] + + async def async_lpop_pipeline(self, lpop_list: list[RedisPipelineLpopOperation]) -> list[list[object] | None]: + return [self.lists.pop(op["key"], None) for op in lpop_list] + + +def _postgres_rejection(sqlstate: str) -> RawQueryError: + return RawQueryError( + data={"user_facing_error": {"error_code": "P2010", "meta": {"code": sqlstate, "message": "db error"}}} ) + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + "lock_held_by_another_pod", + [None, DB_SPEND_UPDATE_JOB_NAME, TOOL_DISCOVERY_COMMIT_JOB_NAME], + ids=["free", "spend_lock_held", "tool_lock_held"], +) +async def test_commit_with_redis_writes_every_workers_tools_in_one_statement_from_the_tool_lock_holder_only( + lock_held_by_another_pod: str | None, +): + redis = _InMemoryRedis() + if lock_held_by_another_pod is not None: + assert await PodLockManager(redis_cache=redis).acquire_lock(cronjob_id=lock_held_by_another_pod) + other_worker = ToolDiscoveryQueue() + other_worker.add_update({"tool_name": "get_weather", "origin": "mcp_server"}) + other_worker.add_update({"tool_name": "search", "origin": "user_defined"}) + await RedisUpdateBuffer(redis_cache=redis).store_tool_discoveries_in_redis(other_worker) + + queue = ToolDiscoveryQueue() + queue.add_update({"tool_name": "get_weather", "origin": "user_defined"}) + queue.add_update({"tool_name": "get_weather", "origin": "user_defined"}) + prisma_client = MagicMock() + prisma_client.db.execute_raw = AsyncMock(return_value=2) + prisma_client.db.litellm_tooltable.upsert = AsyncMock() + + await commit_tool_discoveries( + prisma_client=prisma_client, + tool_discovery_queue=queue, + redis_update_buffer=RedisUpdateBuffer(redis_cache=redis), + pod_lock_manager=PodLockManager(redis_cache=redis), + use_redis_buffer=True, + ) + + assert queue.flush() == [], "every worker hands its tools to redis each tick" + prisma_client.db.litellm_tooltable.upsert.assert_not_awaited() + if lock_held_by_another_pod == TOOL_DISCOVERY_COMMIT_JOB_NAME: + prisma_client.db.execute_raw.assert_not_awaited() + assert len(redis.lists[REDIS_TOOL_DISCOVERY_BUFFER_KEY]) == 2, "non-holders leave their tools for the holder" + return + assert REDIS_TOOL_DISCOVERY_BUFFER_KEY not in redis.lists, "the spend lock must not gate the tool drain" + prisma_client.db.execute_raw.assert_awaited_once() + sql, *params = prisma_client.db.execute_raw.call_args.args + assert sql.startswith('INSERT INTO "LiteLLM_ToolTable"') and 'ON CONFLICT ("tool_name")' in sql + rows = {params[i + 1]: params[i + 3] for i in range(0, len(params), 10)} + assert rows == {"get_weather": 3, "search": 1}, f"one row per tool summed across workers, got {params}" + + +@pytest.mark.asyncio +async def test_commit_without_redis_writes_only_this_workers_tools_in_one_statement_and_never_touches_redis(): + redis = _InMemoryRedis() + queue = ToolDiscoveryQueue() + queue.add_update({"tool_name": "get_weather", "origin": "user_defined"}) + queue.add_update({"tool_name": "get_weather", "origin": "user_defined"}) + queue.add_update({"tool_name": "search", "origin": "user_defined"}) + prisma_client = MagicMock() + prisma_client.db.execute_raw = AsyncMock(return_value=2) + + await commit_tool_discoveries( + prisma_client=prisma_client, + tool_discovery_queue=queue, + redis_update_buffer=RedisUpdateBuffer(redis_cache=redis), + pod_lock_manager=PodLockManager(redis_cache=redis), + use_redis_buffer=False, + ) + + assert redis.lists == {}, "without the buffer flag nothing goes through redis" + assert queue.flush() == [] + prisma_client.db.execute_raw.assert_awaited_once() + sql, *params = prisma_client.db.execute_raw.call_args.args + assert 'ON CONFLICT ("tool_name")' in sql + rows = {params[i + 1]: params[i + 3] for i in range(0, len(params), 10)} + assert rows == {"get_weather": 2, "search": 1}, f"got {params}" + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + ("failure", "requeued"), + [ + (Exception("connection reset"), True), + (_postgres_rejection("23502"), False), + ], + ids=["connection_error_goes_back_to_redis", "rejected_row_is_dropped"], +) +async def test_failed_tool_table_write_requeues_the_rows_only_when_they_provably_did_not_apply( + failure: Exception, requeued: bool +): + redis = _InMemoryRedis() + queue = ToolDiscoveryQueue() + queue.add_update({"tool_name": "get_weather", "origin": "user_defined"}) + prisma_client = MagicMock() + prisma_client.db.execute_raw = AsyncMock(side_effect=failure) + + await commit_tool_discoveries( + prisma_client=prisma_client, + tool_discovery_queue=queue, + redis_update_buffer=RedisUpdateBuffer(redis_cache=redis), + pod_lock_manager=PodLockManager(redis_cache=redis), + use_redis_buffer=True, + ) + + prisma_client.db.execute_raw.assert_awaited_once() + left_in_redis = [json.loads(entry) for entry in redis.lists.get(REDIS_TOOL_DISCOVERY_BUFFER_KEY, [])] + expected = [[{"tool_name": "get_weather", "origin": "user_defined", "call_count": 1}]] if requeued else [] + assert left_in_redis == expected, f"requeued={requeued} but redis holds {left_in_redis}" diff --git a/tests/unit/proxy/db/test_tool_table_bulk_upsert.py b/tests/unit/proxy/db/test_tool_table_bulk_upsert.py new file mode 100644 index 00000000000..d1e79030f9d --- /dev/null +++ b/tests/unit/proxy/db/test_tool_table_bulk_upsert.py @@ -0,0 +1,38 @@ +"""Tests for the single-statement LiteLLM_ToolTable upsert (LIT-9997).""" + +from litellm.proxy.db.tool_table_bulk_upsert import build_tool_bulk_upsert + + +def test_one_row_per_item_and_the_conflict_update_only_moves_the_counters(): + sql, params = build_tool_bulk_upsert( + [ + {"tool_name": "tool_a", "origin": "mcp_server", "created_by": None, "call_count": 4}, + { + "tool_name": "tool_b", + "origin": "user_defined", + "created_by": "alice", + "call_count": 1, + "key_hash": "hash", + "team_id": "team", + "key_alias": "alias", + "user_agent": "agent", + }, + ] + ) + assert sql.startswith('INSERT INTO "LiteLLM_ToolTable"') + assert sql.count("$1::text") == 1 and "$11::text" in sql and "$21::text" not in sql + assert "$4::integer" in sql and "$14::integer" in sql + assert 'ON CONFLICT ("tool_name") DO UPDATE SET' in sql + assert '"call_count" = "LiteLLM_ToolTable"."call_count" + EXCLUDED."call_count"' in sql + assert '"last_used_at" = EXCLUDED."last_used_at"' in sql + assert '"input_policy"' not in sql and '"output_policy"' not in sql, "policies stay on the table defaults" + assert '"origin" =' not in sql and '"key_hash" =' not in sql, "an existing row keeps who discovered it" + assert len(params) == 20 + assert params[1:10] == ("tool_a", "mcp_server", 4, "system", "system", None, None, None, None) + assert params[11:20] == ("tool_b", "user_defined", 1, "alice", "alice", "hash", "team", "alias", "agent") + assert params[0] != params[10], "each row gets its own tool_id" + + +def test_defaults_fill_origin_created_by_and_call_count(): + _, params = build_tool_bulk_upsert([{"tool_name": "tool_a"}]) + assert params[1:6] == ("tool_a", "user_defined", 1, "system", "system") diff --git a/tests/unit/proxy/decisions_endpoints/test_endpoints.py b/tests/unit/proxy/decisions_endpoints/test_endpoints.py index 4384507e841..a0a79f9b7cf 100644 --- a/tests/unit/proxy/decisions_endpoints/test_endpoints.py +++ b/tests/unit/proxy/decisions_endpoints/test_endpoints.py @@ -1784,3 +1784,53 @@ def test_a_whole_number_request_size_limit_is_named_as_configured_in_the_413( assert response.status_code == 413, response.text assert response.json() == {"error": "Request size is too large. Max size is 1 MB"} assert not upstream.called + + +@pytest.mark.parametrize("endpoint", ("/v1/systemone", "/v1/decisions")) +@pytest.mark.parametrize("api_key", (None, "deployment-key")) +def test_proxy_routes_lm_studio_decisions_with_optional_authentication( + client: TestClient, + monkeypatch: pytest.MonkeyPatch, + respx_mock: respx.MockRouter, + endpoint: str, + api_key: str | None, +) -> None: + monkeypatch.delenv("LM_STUDIO_API_KEY", raising=False) + deployment_router: Final = litellm.Router( + model_list=[ + { + "model_name": "local-decision", + "litellm_params": { + "model": "lm_studio/served-decision", + "api_base": "http://lmstudio.local:1234/v1", + "api_key": api_key, + }, + } + ] + ) + monkeypatch.setattr(litellm.proxy.proxy_server, "llm_router", deployment_router) + upstream: Final = respx_mock.post("http://lmstudio.local:1234/v1/systemone").respond(json=_RESPONSE) + fields: Final = ( + {"state": "review", "questions": {"is_defect": {"type": "noul", "instructions": "Is this a defect?"}}} + if endpoint.endswith("systemone") + else { + "input": "review", + "questions": [{"type": "predicate", "name": "is_defect", "instructions": "Is this a defect?"}], + } + ) + + response: Final = client.post(endpoint, json={"model": "local-decision", **fields}) + + assert response.status_code == 200, response.text + assert json.loads(upstream.calls.last.request.content) == { + "model": "served-decision", + "state": "review", + "questions": {"is_defect": {"type": "noul", "instructions": "Is this a defect?"}}, + } + assert upstream.calls.last.request.headers.get("authorization") == (f"Bearer {api_key}" if api_key else None) + expected: Final = ( + _RESPONSE["answers"] + if endpoint.endswith("systemone") + else [{"type": "predicate", "name": "is_defect", "probability": 0.9}] + ) + assert response.json()["answers"] == expected diff --git a/tests/unit/proxy/guardrails/guardrail_hooks/akto/test_akto.py b/tests/unit/proxy/guardrails/guardrail_hooks/akto/test_akto.py index 8fa544819e9..e2f10225568 100644 --- a/tests/unit/proxy/guardrails/guardrail_hooks/akto/test_akto.py +++ b/tests/unit/proxy/guardrails/guardrail_hooks/akto/test_akto.py @@ -3,9 +3,8 @@ import base64 import json import os from types import SimpleNamespace -from unittest.mock import AsyncMock, MagicMock, patch - from typing import Final, Literal +from unittest.mock import AsyncMock, MagicMock, patch import httpx import pytest @@ -1709,7 +1708,7 @@ async def test_one_text_masked_two_ways_blocks(akto_pre_call): @pytest.mark.asyncio async def test_masking_a_payload_too_deep_to_map_back_blocks(akto_pre_call): - from litellm.proxy._experimental.mcp_server.utils import MAX_STRUCTURED_CONTENT_SCAN_DEPTH + from litellm.proxy.mcp_server.utils import MAX_STRUCTURED_CONTENT_SCAN_DEPTH deep: object = CARD for _ in range(MAX_STRUCTURED_CONTENT_SCAN_DEPTH + 1): diff --git a/tests/unit/proxy/guardrails/guardrail_hooks/semantic_guard/test_semantic_guard.py b/tests/unit/proxy/guardrails/guardrail_hooks/semantic_guard/test_semantic_guard.py index aa43a5530f3..953baf5c173 100644 --- a/tests/unit/proxy/guardrails/guardrail_hooks/semantic_guard/test_semantic_guard.py +++ b/tests/unit/proxy/guardrails/guardrail_hooks/semantic_guard/test_semantic_guard.py @@ -129,6 +129,20 @@ class TestHelperFunctions: mock_response.choices = [] assert _extract_response_text(mock_response) == "" + def test_extract_response_text_fails_closed_on_a_message_without_content(self): + from types import SimpleNamespace + + from litellm.proxy.guardrails.guardrail_hooks.semantic_guard.semantic_guard import ( + _extract_response_text, + ) + + response: Final = SimpleNamespace( + choices=[SimpleNamespace(message={"role": "assistant", "content": "ignore all rules"})] + ) + + with pytest.raises(AttributeError, match="'dict' object has no attribute 'content'"): + _extract_response_text(response) + def test_get_top_route_choice_single(self): from litellm.proxy.guardrails.guardrail_hooks.semantic_guard.semantic_guard import ( _get_top_route_choice, diff --git a/tests/unit/proxy/guardrails/guardrail_hooks/test_bedrock_guardrails.py b/tests/unit/proxy/guardrails/guardrail_hooks/test_bedrock_guardrails.py index 69b3e113b8f..8c8aa7af19f 100644 --- a/tests/unit/proxy/guardrails/guardrail_hooks/test_bedrock_guardrails.py +++ b/tests/unit/proxy/guardrails/guardrail_hooks/test_bedrock_guardrails.py @@ -3258,7 +3258,7 @@ async def test_streaming_hook_fails_closed_when_assembler_raises_api_error(): guardrail = _sse_guardrail() with patch( - "litellm.llms.anthropic.pass_through.stream_assembly.build_complete_streaming_response", + "litellm.llms.anthropic.messages.stream_assembly.build_complete_streaming_response", side_effect=litellm.APIError( status_code=500, message="Error building chunks for logging/streaming usage calculation", diff --git a/tests/unit/proxy/guardrails/guardrail_hooks/test_headroom.py b/tests/unit/proxy/guardrails/guardrail_hooks/test_headroom.py index 5bdcdddf4b7..3336b20f5eb 100644 --- a/tests/unit/proxy/guardrails/guardrail_hooks/test_headroom.py +++ b/tests/unit/proxy/guardrails/guardrail_hooks/test_headroom.py @@ -2711,7 +2711,7 @@ async def test_retrieved_content_protected_when_mcp_tool_name_is_truncated(guard the OpenAI-translated view the guardrail scans, dropping the suffix. The call id read from the request's own Anthropic tool_use (never truncated) still pairs the retrieved row so it is held back.""" - from litellm.llms.anthropic.pass_through.adapters.transformation import ( + from litellm.llms.anthropic.messages.adapters.transformation import ( truncate_tool_name, ) diff --git a/tests/unit/proxy/guardrails/guardrail_hooks/test_llm_shield_proxy.py b/tests/unit/proxy/guardrails/guardrail_hooks/test_llm_shield_proxy.py index df2fc8e1da2..3da77a8707e 100644 --- a/tests/unit/proxy/guardrails/guardrail_hooks/test_llm_shield_proxy.py +++ b/tests/unit/proxy/guardrails/guardrail_hooks/test_llm_shield_proxy.py @@ -1238,6 +1238,23 @@ class TestFailClosed: class TestStreamingRehydration: + @pytest.mark.asyncio + async def test_held_text_behind_a_chunk_that_cannot_be_copied_fails_closed(self): + guardrail: Final = _guardrail(event_hook="post_call") + _mock_post(guardrail, {"text": "", "carry": "[EMAIL"}, {"text": "a@b.com", "carry": ""}) + + async def stream(): + yield SimpleNamespace( + choices=[SimpleNamespace(index=0, delta=SimpleNamespace(content="[EMAIL"), finish_reason=None)] + ) + + with pytest.raises(AttributeError, match="model_copy"): + await _drain( + guardrail.async_post_call_streaming_iterator_hook( + user_api_key_dict=None, response=stream(), request_data={"messages": []} + ) + ) + @pytest.mark.asyncio async def test_split_placeholder_is_not_emitted_in_fragments(self): """The window holds back a partial placeholder and releases it once complete.""" diff --git a/tests/unit/proxy/guardrails/guardrail_hooks/test_mcp_security.py b/tests/unit/proxy/guardrails/guardrail_hooks/test_mcp_security.py index e4c7bcba951..0e6670c26e7 100644 --- a/tests/unit/proxy/guardrails/guardrail_hooks/test_mcp_security.py +++ b/tests/unit/proxy/guardrails/guardrail_hooks/test_mcp_security.py @@ -63,7 +63,7 @@ class TestExtractMCPServerNames: class TestMCPSecurityGuardrailPreCall: @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) async def test_blocks_unregistered_server_chat_completions( self, mock_manager, guardrail @@ -93,7 +93,7 @@ class TestMCPSecurityGuardrailPreCall: @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) async def test_blocks_unregistered_server_responses_api( self, mock_manager, guardrail @@ -122,7 +122,7 @@ class TestMCPSecurityGuardrailPreCall: @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) async def test_allows_registered_servers(self, mock_manager, guardrail): """All MCP servers are registered - request passes through.""" @@ -211,8 +211,9 @@ class TestInitializeGuardrail: @pytest.mark.parametrize("call_type", ["acompletion", "aresponses"]) async def test_guardrail_observes_saved_server_creation_and_deletion_on_another_worker(guardrail, call_type): from unittest.mock import AsyncMock + from litellm.proxy._types import LiteLLM_MCPServerTable - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager = MCPServerManager() row = LiteLLM_MCPServerTable(server_id="peer-server", alias="peer_server", transport="http", @@ -226,7 +227,7 @@ async def test_guardrail_observes_saved_server_creation_and_deletion_on_another_ with ( patch("litellm.proxy.proxy_server.prisma_client", prisma), patch("litellm.proxy.proxy_server.general_settings", {}), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", manager), + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager), ): result = await guardrail.async_pre_call_hook(UserAPIKeyAuth(), MagicMock(), data, call_type) assert result == data diff --git a/tests/unit/proxy/guardrails/guardrail_hooks/test_panw_prisma_airs.py b/tests/unit/proxy/guardrails/guardrail_hooks/test_panw_prisma_airs.py index a5c543528c2..83301db5d86 100644 --- a/tests/unit/proxy/guardrails/guardrail_hooks/test_panw_prisma_airs.py +++ b/tests/unit/proxy/guardrails/guardrail_hooks/test_panw_prisma_airs.py @@ -3243,7 +3243,7 @@ class TestPanwAirsMcpToolEventScan: with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_manager, patch.object(handler, "_call_panw_api", new_callable=AsyncMock) as mock_api, ): diff --git a/tests/unit/proxy/guardrails/guardrail_hooks/test_presidio.py b/tests/unit/proxy/guardrails/guardrail_hooks/test_presidio.py index bd1e9ae4068..e312378969a 100644 --- a/tests/unit/proxy/guardrails/guardrail_hooks/test_presidio.py +++ b/tests/unit/proxy/guardrails/guardrail_hooks/test_presidio.py @@ -15,27 +15,25 @@ from typing import Final, Literal from unittest.mock import MagicMock, patch import aiohttp +import pytest from aiohttp import web from aiohttp.client_proto import ResponseHandler from aiohttp.test_utils import TestServer -import pytest from pydantic import TypeAdapter from typing_extensions import ReadOnly, TypedDict - import litellm from litellm import mock_completion from litellm.caching.caching import DualCache +from litellm.exceptions import BlockedPiiEntityError, GuardrailRaisedException from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.guardrails.guardrail_hooks.presidio import ( - PresidioPerRequestConfig, OPTIONAL_PresidioPIIMasking, + PresidioPerRequestConfig, ) -from litellm.exceptions import GuardrailRaisedException from litellm.types.guardrails import LitellmParams, PiiAction, PiiEntityType from litellm.types.proxy.guardrails.guardrail_hooks.presidio import PresidioAnalyzeRequest, PresidioAnalyzeResponseItem from litellm.types.utils import Choices, Delta, Message, ModelResponse, StreamingChoices -from litellm.exceptions import BlockedPiiEntityError def _make_mock_session_iterator(json_response, status=200, content_type="application/json", text_response=""): @@ -4434,9 +4432,9 @@ async def test_pii_masking_replays_a_byte_identical_prefix_across_turns(mock_use async def test_initialized_presidio_scans_selected_surface(surface: str, action: PiiAction, has_tokens: bool) -> None: from mcp.types import CallToolResult, TextContent - from litellm.proxy._experimental.mcp_server.guardrail_translation.handler import MCPGuardrailTranslationHandler from litellm.proxy.guardrails.guardrail_hooks.unified_guardrail.unified_guardrail import UnifiedLLMGuardrails from litellm.proxy.guardrails.guardrail_initializers import initialize_presidio + from litellm.proxy.mcp_server.guardrail_translation.handler import MCPGuardrailTranslationHandler params: Final = LitellmParams( guardrail="presidio", diff --git a/tests/unit/proxy/guardrails/guardrail_hooks/test_reco.py b/tests/unit/proxy/guardrails/guardrail_hooks/test_reco.py new file mode 100644 index 00000000000..9a7670dbe97 --- /dev/null +++ b/tests/unit/proxy/guardrails/guardrail_hooks/test_reco.py @@ -0,0 +1,285 @@ +""" +Tests for the Reco guardrail integration. +""" + +from collections.abc import Mapping +from typing import Final +from unittest.mock import MagicMock, patch + +import httpx +import pytest +from pydantic import ValidationError + +from litellm.exceptions import GuardrailRaisedException +from litellm.proxy.guardrails.guardrail_hooks.reco import ( + RecoGuardrail, + initialize_guardrail, +) +from litellm.types.guardrails import GuardrailEventHooks, LitellmParams +from litellm.types.proxy.guardrails.guardrail_hooks.reco import ( + RecoConfigModel, + RecoOptionalParams, +) +from litellm.types.utils import GenericGuardrailAPIInputs + + +@pytest.fixture +def reco_guardrail() -> RecoGuardrail: + return RecoGuardrail( + reco_tenant_id="11111111-1111-1111-1111-111111111111", + api_base="https://edge1.us.reco.ai", + guardrail_name="my-reco-guardrail", + event_hook="pre_call", + default_on=True, + ) + + +class TestRecoGuardrailConfiguration: + def test_tenant_id_forwarded_as_header(self, reco_guardrail: RecoGuardrail) -> None: + assert reco_guardrail.headers == {"X-Reco-Tenant-Id": "11111111-1111-1111-1111-111111111111"} + + def test_tenant_header_merged_with_existing_headers(self) -> None: + guardrail: Final = RecoGuardrail( + reco_tenant_id="11111111-1111-1111-1111-111111111111", + api_base="https://edge1.us.reco.ai", + headers={"X-Custom": "value"}, + ) + assert guardrail.headers == { + "X-Custom": "value", + "X-Reco-Tenant-Id": "11111111-1111-1111-1111-111111111111", + } + + def test_missing_reco_tenant_id_raises(self) -> None: + with pytest.raises(ValueError, match="reco_tenant_id"): + RecoGuardrail(reco_tenant_id=None, api_base="https://edge1.us.reco.ai") + + def test_missing_api_base_raises(self) -> None: + with pytest.raises(ValueError, match="api_base"): + RecoGuardrail(reco_tenant_id="11111111-1111-1111-1111-111111111111", api_base=None) + + def test_non_uuid_reco_tenant_id_raises(self) -> None: + with pytest.raises(ValueError, match="UUID"): + RecoGuardrail(reco_tenant_id="tenant-123", api_base="https://edge1.us.reco.ai") + + def test_optional_params_rejects_non_uuid_tenant_id(self) -> None: + with pytest.raises(ValidationError, match="UUID"): + RecoOptionalParams(reco_tenant_id="tenant-123", api_base="https://edge1.us.reco.ai") + + def test_get_supported_event_hooks_returns_pre_call_only(self) -> None: + assert RecoGuardrail.get_supported_event_hooks() == [GuardrailEventHooks.pre_call] + + def test_get_config_model_returns_reco_config_model(self) -> None: + assert RecoGuardrail.get_config_model() is RecoConfigModel + + def test_config_model_ui_friendly_name(self) -> None: + assert RecoConfigModel.ui_friendly_name() == "Reco" + + def test_litellm_params_stay_assignable_for_registry_secret_resolution(self) -> None: + litellm_params: Final = LitellmParams(guardrail="reco", mode="pre_call") + + litellm_params.api_base = "https://edge1.us.reco.ai" + + assert litellm_params.api_base == "https://edge1.us.reco.ai" + + +class TestRecoGuardrailInitializer: + def test_initialize_guardrail_wires_optional_params(self) -> None: + litellm_params: Final = LitellmParams( + guardrail="reco", + mode="pre_call", + optional_params={ + "reco_tenant_id": "22222222-2222-2222-2222-222222222222", + "api_base": "https://edge2.eu.reco.ai", + }, + ) + + guardrail: Final = initialize_guardrail(litellm_params, {"guardrail_name": "prod-reco"}) + + assert isinstance(guardrail, RecoGuardrail) + assert guardrail.guardrail_name == "prod-reco" + assert guardrail.headers == {"X-Reco-Tenant-Id": "22222222-2222-2222-2222-222222222222"} + assert guardrail.api_base == "https://edge2.eu.reco.ai/beta/litellm_basic_guardrail_api" + + def test_initialize_guardrail_reads_plain_dict_optional_params(self) -> None: + """Guardrails reconciled from the DB can carry `optional_params` as a + plain dict rather than a pydantic object; attribute-only access would + silently read None for every field.""" + litellm_params: Final = LitellmParams.model_construct( + guardrail="reco", + optional_params={ + "reco_tenant_id": "33333333-3333-3333-3333-333333333333", + "api_base": "https://edge3.eu.reco.ai", + }, + mode="pre_call", + default_on=True, + ) + + guardrail: Final = initialize_guardrail(litellm_params, {"guardrail_name": "prod-reco"}) + + assert guardrail.headers == {"X-Reco-Tenant-Id": "33333333-3333-3333-3333-333333333333"} + assert guardrail.api_base == "https://edge3.eu.reco.ai/beta/litellm_basic_guardrail_api" + + def test_initialize_guardrail_resolves_env_var_reference(self, monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("RECO_TEST_TENANT_ID", "44444444-4444-4444-4444-444444444444") + litellm_params: Final = LitellmParams( + guardrail="reco", + optional_params={ + "reco_tenant_id": "os.environ/RECO_TEST_TENANT_ID", + "api_base": "https://edge4.eu.reco.ai", + }, + mode="pre_call", + default_on=True, + ) + + guardrail: Final = initialize_guardrail(litellm_params, {"guardrail_name": "prod-reco"}) + + assert guardrail.headers == {"X-Reco-Tenant-Id": "44444444-4444-4444-4444-444444444444"} + + +def _litellm_params(top_level: Mapping[str, object], nested: Mapping[str, object]) -> LitellmParams: + return LitellmParams( + guardrail="reco", + mode="pre_call", + optional_params={ + "reco_tenant_id": "22222222-2222-2222-2222-222222222222", + "api_base": "https://edge2.eu.reco.ai", + **nested, + }, + **top_level, + ) + + +async def _apply_with_reco_unreachable(guardrail: RecoGuardrail) -> GenericGuardrailAPIInputs: + with patch.object(guardrail.async_handler, "post", side_effect=httpx.ConnectError("connection refused")): + return await guardrail.apply_guardrail( + inputs={"texts": ["hello"]}, + request_data={"metadata": {}}, + input_type="request", + ) + + +class TestRecoGuardrailFailureModes: + @pytest.mark.asyncio + async def test_unreachable_reco_blocks_request_by_default(self, reco_guardrail: RecoGuardrail) -> None: + with pytest.raises(Exception, match="connection refused"): + await _apply_with_reco_unreachable(reco_guardrail) + + @pytest.mark.asyncio + async def test_fail_open_lets_request_through_when_reco_unreachable(self) -> None: + guardrail: Final = RecoGuardrail( + reco_tenant_id="11111111-1111-1111-1111-111111111111", + api_base="https://edge1.us.reco.ai", + fail_on_error=False, + ) + + result: Final = await _apply_with_reco_unreachable(guardrail) + + assert result["texts"] == ["hello"] + + @pytest.mark.asyncio + async def test_fail_closed_blocks_request_when_reco_unreachable(self) -> None: + guardrail: Final = RecoGuardrail( + reco_tenant_id="11111111-1111-1111-1111-111111111111", + api_base="https://edge1.us.reco.ai", + unreachable_fallback="fail_closed", + fail_on_error=True, + ) + + with pytest.raises(Exception, match="connection refused"): + await _apply_with_reco_unreachable(guardrail) + + @pytest.mark.asyncio + @pytest.mark.parametrize( + ("top_level", "nested"), + [ + pytest.param({}, {}, id="defaults"), + pytest.param({}, {"unreachable_fallback": "fail_closed", "fail_on_error": True}, id="optional-params"), + pytest.param({"unreachable_fallback": "fail_closed", "fail_on_error": True}, {}, id="top-level"), + ], + ) + async def test_initialize_guardrail_fails_closed_when_configured( + self, top_level: Mapping[str, object], nested: Mapping[str, object] + ) -> None: + guardrail: Final = initialize_guardrail(_litellm_params(top_level, nested), {"guardrail_name": "prod-reco"}) + + with pytest.raises(Exception, match="connection refused"): + await _apply_with_reco_unreachable(guardrail) + + @pytest.mark.asyncio + @pytest.mark.parametrize( + ("top_level", "nested"), + [ + pytest.param({}, {"fail_on_error": False}, id="optional-params"), + pytest.param({"fail_on_error": False}, {}, id="top-level"), + pytest.param( + {"unreachable_fallback": "fail_closed", "fail_on_error": True}, + {"fail_on_error": False}, + id="optional-params-wins-over-top-level", + ), + ], + ) + async def test_initialize_guardrail_fails_open_when_configured( + self, top_level: Mapping[str, object], nested: Mapping[str, object] + ) -> None: + guardrail: Final = initialize_guardrail(_litellm_params(top_level, nested), {"guardrail_name": "prod-reco"}) + + result: Final = await _apply_with_reco_unreachable(guardrail) + + assert result["texts"] == ["hello"] + + @pytest.mark.asyncio + async def test_initialize_guardrail_keeps_top_level_fail_open_when_nested_params_are_a_model(self) -> None: + nested: Final = RecoOptionalParams( + reco_tenant_id="22222222-2222-2222-2222-222222222222", api_base="https://edge2.eu.reco.ai" + ) + litellm_params: Final = LitellmParams.model_construct( + guardrail="reco", mode="pre_call", optional_params=nested, fail_on_error=False + ) + + guardrail: Final = initialize_guardrail(litellm_params, {"guardrail_name": "prod-reco"}) + result: Final = await _apply_with_reco_unreachable(guardrail) + + assert result["texts"] == ["hello"] + + +class TestRecoGuardrailBlocking: + @pytest.mark.asyncio + async def test_action_blocked_raises_exception_with_configured_guardrail_name( + self, reco_guardrail: RecoGuardrail + ) -> None: + mock_response: Final = MagicMock() + mock_response.json.return_value = { + "action": "BLOCKED", + "blocked_reason": "Sensitive data detected", + } + mock_response.raise_for_status = MagicMock() + + with patch.object(reco_guardrail.async_handler, "post", return_value=mock_response) as mock_post: + with pytest.raises(GuardrailRaisedException) as exc_info: + await reco_guardrail.apply_guardrail( + inputs={"texts": ["some sensitive prompt"]}, + request_data={"metadata": {}}, + input_type="request", + ) + + assert exc_info.value.guardrail_name == "my-reco-guardrail" + assert str(exc_info.value) == "Sensitive data detected" + assert exc_info.value.blocked_content is True + + _, call_kwargs = mock_post.call_args + assert call_kwargs["headers"]["X-Reco-Tenant-Id"] == "11111111-1111-1111-1111-111111111111" + + @pytest.mark.asyncio + async def test_action_none_allows_content(self, reco_guardrail: RecoGuardrail) -> None: + mock_response: Final = MagicMock() + mock_response.json.return_value = {"action": "NONE", "texts": ["hello"]} + mock_response.raise_for_status = MagicMock() + + with patch.object(reco_guardrail.async_handler, "post", return_value=mock_response): + result: Final = await reco_guardrail.apply_guardrail( + inputs={"texts": ["hello"]}, + request_data={"metadata": {}}, + input_type="request", + ) + + assert result["texts"] == ["hello"] diff --git a/tests/unit/proxy/guardrails/guardrail_hooks/unified_guardrails/test_unified_guardrail.py b/tests/unit/proxy/guardrails/guardrail_hooks/unified_guardrails/test_unified_guardrail.py index 3efbe6475b2..a6177ff9e3a 100644 --- a/tests/unit/proxy/guardrails/guardrail_hooks/unified_guardrails/test_unified_guardrail.py +++ b/tests/unit/proxy/guardrails/guardrail_hooks/unified_guardrails/test_unified_guardrail.py @@ -3,6 +3,7 @@ import asyncio import contextlib import io +import json import logging from collections.abc import AsyncGenerator, AsyncIterable, AsyncIterator from types import SimpleNamespace @@ -35,9 +36,7 @@ from litellm.llms.openai.chat.guardrail_translation.handler import ( from litellm.llms.openai.responses.guardrail_translation.handler import ( OpenAIResponsesHandler, ) -from litellm.proxy._experimental.mcp_server.guardrail_translation.handler import ( - MCPGuardrailTranslationHandler, -) +from litellm.llms.pass_through.guardrail_translation.handler import PassThroughEndpointHandler from litellm.proxy._types import LiteLLMRoutes, UserAPIKeyAuth from litellm.proxy.guardrails.guardrail_hooks.unified_guardrail import ( unified_guardrail as unified_module, @@ -45,6 +44,9 @@ from litellm.proxy.guardrails.guardrail_hooks.unified_guardrail import ( from litellm.proxy.guardrails.guardrail_hooks.unified_guardrail.unified_guardrail import ( UnifiedLLMGuardrails, ) +from litellm.proxy.mcp_server.guardrail_translation.handler import ( + MCPGuardrailTranslationHandler, +) from litellm.types.guardrails import GuardrailEventHooks from litellm.types.llms.openai import ResponsesAPIResponse from litellm.types.utils import ( @@ -3053,3 +3055,34 @@ async def test_pre_call_hook_skips_attachment_scan_when_guardrail_has_none(): ) assert len(guardrail.apply_calls) == 1 + + +@pytest.mark.parametrize("hook", ["async_pre_call_hook", "async_moderation_hook"]) +@pytest.mark.asyncio +async def test_pass_through_guardrail_text_is_the_client_body_without_the_injected_key_metadata( + monkeypatch: pytest.MonkeyPatch, hook: str +) -> None: + _patch_translation_mappings(monkeypatch, {CallTypes.pass_through: PassThroughEndpointHandler}) + guardrail: Final = RecordingGuardrail() + body: Final = { + "model": "gpt-4o", + "messages": [{"role": "user", "content": "Say hi in one word"}], + "guardrails": ["recording-guardrail"], + } + data: Final = {**body, "guardrail_to_apply": guardrail} + user_api_key_dict: Final = UserAPIKeyAuth( + token="hashed-key", user_email="someone@example.com", team_id="team-1", user_role="proxy_admin" + ) + + if hook == "async_pre_call_hook": + await UnifiedLLMGuardrails().async_pre_call_hook( + user_api_key_dict=user_api_key_dict, cache=DualCache(), data=data, call_type=CallTypes.pass_through.value + ) + else: + await UnifiedLLMGuardrails().async_moderation_hook( + data=data, user_api_key_dict=user_api_key_dict, call_type=CallTypes.pass_through.value + ) + + texts: Final = [call["inputs"]["texts"] for call in guardrail.apply_calls] + assert [[json.loads(text) for text in call_texts] for call_texts in texts] == [[body]], texts + assert data["litellm_metadata"]["user_api_key_user_email"] == "someone@example.com", data["litellm_metadata"] diff --git a/tests/unit/proxy/health_endpoints/test_health_endpoints.py b/tests/unit/proxy/health_endpoints/test_health_endpoints.py index 950d1742d49..67b280eb379 100644 --- a/tests/unit/proxy/health_endpoints/test_health_endpoints.py +++ b/tests/unit/proxy/health_endpoints/test_health_endpoints.py @@ -5437,3 +5437,64 @@ async def test_health_services_endpoint_langfuse_missing_keys_errors(monkeypatch with pytest.raises(ProxyException, match="auth_check failed") as raised: await health_services_endpoint(service="langfuse") assert "connection refused by lf.internal.example" in str(raised.value.message) + + +@pytest.mark.asyncio +@pytest.mark.parametrize("admin", [False, True]) +async def test_unsaved_chatgpt_account_probe_requires_proxy_admin( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch, admin: bool +) -> None: + from starlette.requests import Request + from litellm.proxy import proxy_server + + monkeypatch.setenv("CHATGPT_AUTH_FILE", str(tmp_path / "missing-default-auth.json")) + auth_file: Final = tmp_path / "auth.json" + auth_file.write_text( + json.dumps({"access_token": "token-probe", "account_id": "acct-probe", "expires_at": 4102444800}) + ) + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + monkeypatch.setattr(proxy_server, "prisma_client", MagicMock()) + monkeypatch.setattr(proxy_server, "llm_router", None) + monkeypatch.setattr(proxy_server, "general_settings", {}) + output: Final = { + "id": "msg_probe", + "type": "message", + "role": "assistant", + "status": "completed", + "content": [{"type": "output_text", "text": "ok", "annotations": []}], + } + response: Final = { + "id": "resp_probe", + "object": "response", + "created_at": 1700000000, + "status": "completed", + "model": "gpt-6.1-sol", + "output": [output], + "usage": {"input_tokens": 1, "output_tokens": 1, "total_tokens": 2}, + } + with respx.mock(assert_all_called=False) as upstream: + upstream.post("https://chatgpt.com/backend-api/codex/responses").respond( + 200, + text="data: " + json.dumps({"type": "response.completed", "response": response}) + "\n\n", + headers={"content-type": "text/event-stream"}, + ) + call: Final = health_test_model_connection( + request=Request({"type": "http", "headers": []}), + mode="responses", + litellm_params={"model": "chatgpt/gpt-6.1-sol", "chatgpt_auth_file": str(auth_file)}, + model_info={}, + user_api_key_dict=UserAPIKeyAuth( + user_role=LitellmUserRoles.PROXY_ADMIN if admin else LitellmUserRoles.INTERNAL_USER, token="test-key" + ), + ) + if admin: + result: Final = await call + assert result["status"] == "success" + assert upstream.calls.last.request.headers["Authorization"] == "Bearer token-probe" + assert upstream.calls.last.request.headers["ChatGPT-Account-Id"] == "acct-probe" + assert isinstance(json.loads(upstream.calls.last.request.content)["input"], list) + else: + with pytest.raises(ProxyException) as error: + await call + assert error.value.code == "403" + assert len(upstream.calls) == 0 diff --git a/tests/unit/proxy/hooks/test_parallel_request_limiter_v3.py b/tests/unit/proxy/hooks/test_parallel_request_limiter_v3.py index 1ec505362dd..b8dba5e1e68 100644 --- a/tests/unit/proxy/hooks/test_parallel_request_limiter_v3.py +++ b/tests/unit/proxy/hooks/test_parallel_request_limiter_v3.py @@ -7,7 +7,7 @@ import contextvars import logging import sys import time -from collections.abc import Iterator, Sequence +from collections.abc import AsyncGenerator, Iterator, Sequence from contextlib import contextmanager from datetime import datetime, timedelta, timezone from typing import Any, Dict, Final, List, Optional @@ -4000,10 +4000,10 @@ async def test_billed_personal_key_auth_produces_team_rpm_descriptors(monkeypatc from litellm.models.budget import LiteLLM_BudgetTable from litellm.models.team_membership import LiteLLM_TeamMembership from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy.auth import auth_checks from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable + from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server: Final = MCPServer( server_id="math_a", @@ -4644,6 +4644,140 @@ async def test_success_event_releases_parallel_slot_v3(monkeypatch): ) +_SSE_KEEPALIVE_CALLBACK_TIME: Final = datetime(2026, 1, 1) + + +@pytest.mark.asyncio +@pytest.mark.parametrize("after_ping", [False, True], ids=["fast", "pinged"]) +@pytest.mark.parametrize("fails", [False, True], ids=["success", "failure"]) +@pytest.mark.parametrize("preadmitted", [False, True], ids=["producer-admission", "existing-admission"]) +async def test_sse_keepalive_releases_parallel_capacity( + after_ping: bool, fails: bool, preadmitted: bool +) -> None: + from fastapi.responses import StreamingResponse + + from litellm.proxy.common_request_processing import open_sse_before_first_byte + from litellm.proxy.common_utils.sse_keepalive import SSE_COMMENT_PING_BYTES + + cache: Final = DualCache() + handler: Final = _PROXY_MaxParallelRequestsHandler(internal_usage_cache=InternalUsageCache(cache)) + api_key: Final = hash_token("sk-keepalive-release") + auth: Final = UserAPIKeyAuth(api_key=api_key, max_parallel_requests=1) + counter: Final = f"{{api_key:{api_key}}}:max_parallel_requests" + + async def request(call_id: str) -> None: + data: Final = {"model": "test-model", "litellm_call_id": call_id} + upstream_answers: Final = asyncio.Event() + if not after_ping: + upstream_answers.set() + + async def admit() -> None: + await handler.async_pre_call_hook( + user_api_key_dict=auth, cache=cache, data=data, call_type="acompletion" + ) + + async def failure(exc: Exception) -> None: + await handler.async_post_call_failure_hook( + request_data=data, original_exception=exc, user_api_key_dict=auth + ) + + async def stream() -> AsyncGenerator[bytes, None]: + yield b"data: [DONE]\n\n" + await handler.async_log_success_event( + kwargs={ + "litellm_call_id": call_id, + "standard_logging_object": {"metadata": {"user_api_key_hash": api_key}}, + }, + response_obj=ModelResponse(usage=Usage(prompt_tokens=1, completion_tokens=1, total_tokens=2)), + start_time=_SSE_KEEPALIVE_CALLBACK_TIME, + end_time=_SSE_KEEPALIVE_CALLBACK_TIME, + ) + + async def produce() -> StreamingResponse: + if not preadmitted: + await admit() + await upstream_answers.wait() + if fails: + raise HTTPException(status_code=502, detail="upstream failed") + return StreamingResponse(stream()) + + if preadmitted: + await admit() + response_call: Final = open_sse_before_first_byte( + produce(), 0.001 if after_ping else 60.0, on_late_failure=failure + ) + if fails and not after_ping: + with pytest.raises(HTTPException) as rejected: + await response_call + assert rejected.value.status_code == 502 + await failure(rejected.value) + return + response: Final = await response_call + first: Final = await anext(response.body_iterator) + if after_ping: + upstream_answers.set() + rest: Final = tuple([chunk async for chunk in response.body_iterator]) + assert first == (SSE_COMMENT_PING_BYTES if after_ping else b"data: [DONE]\n\n") + if fails: + error_frame: Final = rest[-2] + assert isinstance(error_frame, bytes) and b"upstream failed" in error_frame + assert rest[-1] == b"data: [DONE]\n\n" + elif after_ping: + assert rest[-1] == b"data: [DONE]\n\n" + else: + assert rest == () + + for index in range(3): + await contextvars.Context().run(asyncio.create_task, request(f"keepalive-{index}")) + assert handler._gauge_in_flight_from_cache_value(await cache.async_get_cache(counter)) == 0 + + +@pytest.mark.asyncio +async def test_sse_keepalive_rejects_overlap_and_reuses_completed_capacity() -> None: + from fastapi.responses import StreamingResponse + + from litellm.proxy.common_request_processing import open_sse_before_first_byte + + cache: Final = DualCache() + handler: Final = _PROXY_MaxParallelRequestsHandler(internal_usage_cache=InternalUsageCache(cache)) + api_key: Final = hash_token("sk-keepalive-overlap") + auth: Final = UserAPIKeyAuth(api_key=api_key, max_parallel_requests=1) + admitted: Final = asyncio.Event() + finish: Final = asyncio.Event() + + async def request(call_id: str) -> None: + async def stream() -> AsyncGenerator[bytes, None]: + await finish.wait() + yield b"data: [DONE]\n\n" + await handler.async_post_call_success_hook( + data={"litellm_call_id": call_id}, user_api_key_dict=auth, response=ModelResponse() + ) + + async def produce() -> StreamingResponse: + await handler.async_pre_call_hook( + user_api_key_dict=auth, + cache=cache, + data={"model": "test-model", "litellm_call_id": call_id}, + call_type="acompletion", + ) + admitted.set() + return StreamingResponse(stream()) + + response: Final = await open_sse_before_first_byte(produce(), 60.0) + assert tuple([chunk async for chunk in response.body_iterator]) == (b"data: [DONE]\n\n",) + + first: Final = contextvars.Context().run(asyncio.create_task, request("first")) + await admitted.wait() + try: + with pytest.raises(HTTPException) as rejected: + await contextvars.Context().run(asyncio.create_task, request("overlapping")) + assert rejected.value.status_code == 429 + finally: + finish.set() + await first + await contextvars.Context().run(asyncio.create_task, request("after-completion")) + + @pytest.mark.asyncio async def test_read_only_gauge_check_counts_without_acquiring_v3(): """ diff --git a/tests/unit/proxy/hooks/test_proxy_track_cost_callback.py b/tests/unit/proxy/hooks/test_proxy_track_cost_callback.py index 76ad1e08e28..79193d37b04 100644 --- a/tests/unit/proxy/hooks/test_proxy_track_cost_callback.py +++ b/tests/unit/proxy/hooks/test_proxy_track_cost_callback.py @@ -1,35 +1,42 @@ import asyncio import json import logging +from collections.abc import Mapping from datetime import datetime, timedelta, timezone from types import SimpleNamespace -from typing import Final +from typing import Final, cast from unittest.mock import AsyncMock, MagicMock, create_autospec, patch import httpx import pytest +from fastapi import HTTPException import litellm from litellm._logging import verbose_proxy_logger from litellm.litellm_core_utils.internal_call_metadata import MODEL_ACCESS_GROUP_METADATA_KEY -from litellm.proxy._types import SpendLogsPayload, UserAPIKeyAuth +from litellm.proxy._types import ProxyException, SpendLogsPayload, UserAPIKeyAuth from litellm.proxy.collector import SpendEventConsumer from litellm.proxy.db.db_lookup_gate import DBLookupDeadlineExceeded from litellm.proxy.db.db_spend_update_writer import DBSpendUpdateWriter from litellm.proxy.db.model_usage_rollup import build_model_usage_transaction from litellm.proxy.db.spend_log_tool_index import response_tool_call_names from litellm.proxy.hooks.proxy_track_cost_callback import ( - _get_budget_reservation_from_metadata, ProxyDBLogger, + _get_budget_reservation_from_metadata, _should_track_cost_callback, _update_database_and_spend_counters, + is_pre_routing_rejection, run_spend_event, ) from litellm.proxy.route_llm_request import ProxyModelNotFoundError -from litellm.proxy.utils import ProxyUpdateSpend from litellm.proxy.spend_tracking.spend_event import SpendEventDecodeError, build_spend_event, decode_spend_event from litellm.proxy.spend_tracking.spend_event_producer import SpendEventProducer, UnixAddress from litellm.proxy.spend_tracking.spend_tracking_utils import get_logging_payload +from litellm.proxy.utils import ( + REJECTED_BEFORE_REQUEST_SETUP, + REJECTED_BEFORE_REQUEST_SETUP_KEY, + ProxyUpdateSpend, +) from litellm.types.router import Deployment, LiteLLM_Params from litellm.types.utils import CallTypes, LiteLLMBatch, ModelResponse, PromptTokensDetailsWrapper, Usage @@ -3559,3 +3566,103 @@ async def test_batch_accounting_does_not_retry_after_a_search_allowance_update(m assert sum(counter.totals.values()) == 5 assert outcome.failed is True assert outcome.retryable_failure is False + + +_ROUTED_REQUEST: Final[Mapping[str, object]] = { + "model": "anthropic-haiku-4-5", + "messages": [{"role": "user", "content": "hi"}], + "proxy_server_request": {"request_id": "req-1"}, + "litellm_call_id": "call-1", +} +_PRE_ROUTING_REQUEST: Final[Mapping[str, object]] = { + **_ROUTED_REQUEST, + REJECTED_BEFORE_REQUEST_SETUP_KEY: REJECTED_BEFORE_REQUEST_SETUP, +} +_SPOOFED_REQUEST: Final[Mapping[str, object]] = {**_ROUTED_REQUEST, REJECTED_BEFORE_REQUEST_SETUP_KEY: True} +_INVALID_REQUEST_400: Final = ProxyException( + message="Violated guardrail policy", type="invalid_request_error", param=None, code=400 +) +_PROVIDER_AUTH_ERROR: Final = litellm.AuthenticationError( + message="bad key", llm_provider="anthropic", model="claude-haiku-4-5" +) + + +@pytest.mark.parametrize( + ("exception", "request_data", "expected"), + [ + (_INVALID_REQUEST_400, _PRE_ROUTING_REQUEST, True), + (litellm.BudgetExceededError(current_cost=1.0, max_budget=0.0), _PRE_ROUTING_REQUEST, True), + (ProxyModelNotFoundError(route="/chat/completions", model_name="4.6"), _ROUTED_REQUEST, True), + (_INVALID_REQUEST_400, _ROUTED_REQUEST, False), + (_INVALID_REQUEST_400, _SPOOFED_REQUEST, False), + (_PROVIDER_AUTH_ERROR, _ROUTED_REQUEST, False), + ( + litellm.RateLimitError(message="slow down", llm_provider="anthropic", model="claude-haiku-4-5"), + _ROUTED_REQUEST, + False, + ), + (HTTPException(status_code=429, detail="Max parallel request limit reached"), _ROUTED_REQUEST, False), + ], + ids=[ + "bad-body", + "budget", + "unknown-model", + "guardrail-block", + "guardrail-block-with-client-spoofed-marker", + "provider-auth", + "provider-429", + "proxy-429", + ], +) +def test_is_pre_routing_rejection_is_decided_by_pipeline_stage_not_exception_type( + exception: Exception, request_data: Mapping[str, object], expected: bool +) -> None: + assert is_pre_routing_rejection(exception, request_data) is expected + + +class _RecordingSpendWriter: + def __init__(self) -> None: + self.rows: list[Mapping[str, object]] = [] # mutable-ok: test double records the spend rows written + + async def update_database(self, **kwargs: object) -> None: + self.rows.append(kwargs) + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + ("flag_enabled", "exception", "request_data", "rows_written"), + [ + (True, _INVALID_REQUEST_400, _PRE_ROUTING_REQUEST, 0), + (True, litellm.BudgetExceededError(current_cost=1.0, max_budget=0.0), _PRE_ROUTING_REQUEST, 0), + (True, ProxyModelNotFoundError(route="/chat/completions", model_name="4.6"), _ROUTED_REQUEST, 0), + (True, _INVALID_REQUEST_400, _ROUTED_REQUEST, 1), + (True, _INVALID_REQUEST_400, _SPOOFED_REQUEST, 1), + (True, _PROVIDER_AUTH_ERROR, _ROUTED_REQUEST, 1), + (False, _INVALID_REQUEST_400, _PRE_ROUTING_REQUEST, 1), + (False, litellm.BudgetExceededError(current_cost=1.0, max_budget=0.0), _PRE_ROUTING_REQUEST, 1), + ], + ids=[ + "flag-bad-body", + "flag-budget", + "flag-unknown-model", + "flag-guardrail-block-kept", + "flag-guardrail-block-with-spoofed-marker-kept", + "flag-provider-error-kept", + "off-bad-body", + "off-budget", + ], +) +async def test_async_post_call_failure_hook_disable_pre_routing_error_logs( + flag_enabled: bool, exception: Exception, request_data: Mapping[str, object], rows_written: int +) -> None: + writer: Final = _RecordingSpendWriter() + user_api_key_dict: Final = UserAPIKeyAuth( + api_key="test_api_key", user_id="u", team_id="t", request_route="/chat/completions" + ) + with patch("litellm.proxy.proxy_server.general_settings", {"disable_pre_routing_error_logs": flag_enabled}): + await ProxyDBLogger(spend_writer=lambda: cast(DBSpendUpdateWriter, writer)).async_post_call_failure_hook( + request_data={**request_data, "metadata": dict[str, object]()}, + original_exception=exception, + user_api_key_dict=user_api_key_dict, + ) + assert len(writer.rows) == rows_written diff --git a/tests/unit/proxy/lens/test_buffering.py b/tests/unit/proxy/lens/test_buffering.py index b544b70d36b..2b868e72096 100644 --- a/tests/unit/proxy/lens/test_buffering.py +++ b/tests/unit/proxy/lens/test_buffering.py @@ -249,7 +249,10 @@ async def test_admission_releases_upload_on_disconnect_or_cancellation(cancel: b @pytest.mark.asyncio @pytest.mark.parametrize("reject_auth", [False, True]) -async def test_admitted_bytes_survive_auth_parsing_and_remain_reserved_until_sent(reject_auth: bool) -> None: +@pytest.mark.parametrize("body", [b" {} ", b"[]", b"null", b'"s"']) +async def test_admitted_bytes_survive_auth_parsing_and_remain_reserved_until_sent( + reject_auth: bool, body: bytes +) -> None: app: Final = FastAPI() router: Final = APIRouter(route_class=LensRoute) @@ -264,9 +267,11 @@ async def test_admitted_bytes_survive_auth_parsing_and_remain_reserved_until_sen if reject_auth: raise HTTPException(401, "Invalid key") - async with httpx.AsyncClient( - transport=httpx.MockTransport(lambda _: httpx.Response(200, content=b"result")) - ) as upstream: + def upstream_response(incoming: httpx.Request) -> httpx.Response: + assert incoming.content == body + return httpx.Response(200, content=b"result") + + async with httpx.AsyncClient(transport=httpx.MockTransport(upstream_response)) as upstream: @router.post("/lens/datasets") async def endpoint(request: Request, auth: Annotated[None, Depends(auth_reader)]) -> Response: @@ -284,14 +289,14 @@ async def test_admitted_bytes_survive_auth_parsing_and_remain_reserved_until_sen sending.set() await finish.wait() - incoming: Final = request(b" {} ") + incoming: Final = request(body) task: Final = asyncio.create_task(app(incoming.scope, incoming.receive, send)) try: await asyncio.wait_for(sending.wait(), 2) async with httpx.AsyncClient( transport=httpx.ASGITransport(app=app), base_url="http://gateway.test" ) as client: - blocked: Final = await client.post("/lens/datasets", content=b" {} " * 2) + blocked: Final = await client.post("/lens/datasets", content=b" " * (11 - len(body))) unrelated: Final = await client.post("/ordinary", content=b"ordinary body") assert blocked.status_code == 503 assert unrelated.content == b"ordinary body" diff --git a/tests/unit/proxy/management_endpoints/test_key_budget_change.py b/tests/unit/proxy/management_endpoints/test_key_budget_change.py index baf8d870117..484f8638513 100644 --- a/tests/unit/proxy/management_endpoints/test_key_budget_change.py +++ b/tests/unit/proxy/management_endpoints/test_key_budget_change.py @@ -45,6 +45,7 @@ def _key( max_budget: float | None = None, budget_limits: Sequence[Mapping[str, object]] | None = None, budget_id: str | None = None, + budget_duration: str | None = None, ) -> LiteLLM_VerificationToken: return LiteLLM_VerificationToken( token="hashed-owner-key", @@ -54,6 +55,7 @@ def _key( max_budget=max_budget, budget_limits=None if budget_limits is None else [dict(window) for window in budget_limits], budget_id=budget_id, + budget_duration=budget_duration, metadata={}, ) @@ -127,6 +129,56 @@ def _window(duration: str, cap: float) -> Mapping[str, object]: (UpdateKeyRequest(key="sk-1", spend=0.0), _key(), KeyBudgetAdminOnly()), (UpdateKeyRequest(key="sk-1", soft_budget=1.0), _key(), KeyBudgetAdminOnly()), (UpdateKeyRequest(key="sk-1", soft_budget=None, max_budget=5.0), _key(max_budget=10.0), KeyBudgetAdminOnly()), + ( + UpdateKeyRequest(key="sk-1", budget_duration="1s"), + _key(max_budget=10.0, budget_duration="30d"), + KeyBudgetLoosened(), + ), + ( + UpdateKeyRequest(key="sk-1", budget_duration="60d"), + _key(max_budget=10.0, budget_duration="30d"), + KeyBudgetLoosened(), + ), + (UpdateKeyRequest(key="sk-1", budget_duration="1d"), _key(max_budget=10.0), KeyBudgetLoosened()), + ( + UpdateKeyRequest(key="sk-1", budget_duration=None), + _key(max_budget=10.0, budget_duration="30d"), + KeyBudgetTightened(), + ), + ( + UpdateKeyRequest(key="sk-1", budget_duration="30d"), + _key(max_budget=10.0, budget_duration="30d"), + KeyBudgetUnchanged(), + ), + ( + UpdateKeyRequest(key="sk-1", budget_duration="30d"), + _key(max_budget=10.0, budget_duration="Monthly"), + KeyBudgetUnchanged(), + ), + (UpdateKeyRequest(key="sk-1", budget_duration="1s"), _key(budget_duration="30d"), KeyBudgetUnchanged()), + (UpdateKeyRequest(key="sk-1", max_budget=5.0, budget_duration="1s"), _key(), KeyBudgetTightened()), + ( + UpdateKeyRequest(key="sk-1", budget_duration="1s"), + _key(budget_id="shared-tier-10", budget_duration="30d"), + KeyBudgetAdminOnly(), + ), + ( + UpdateKeyRequest(key="sk-1", budget_duration=None), + _key(budget_id="shared-tier-10", budget_duration="30d"), + KeyBudgetAdminOnly(), + ), + ( + UpdateKeyRequest(key="sk-1", budget_id="shared-tier-100"), + _key(budget_id="shared-tier-10"), + KeyBudgetAdminOnly(), + ), + (UpdateKeyRequest(key="sk-1", budget_id=None), _key(budget_id="shared-tier-10"), KeyBudgetAdminOnly()), + (UpdateKeyRequest(key="sk-1", budget_id="shared-tier-10"), _key(), KeyBudgetAdminOnly()), + ( + UpdateKeyRequest(key="sk-1", budget_id="shared-tier-10"), + _key(budget_id="shared-tier-10"), + KeyBudgetUnchanged(), + ), ], ) def test_classify_key_budget_change( @@ -465,3 +517,60 @@ async def test_owner_cannot_clear_max_budget_by_default(monkeypatch: pytest.Monk existing=_key(max_budget=10.0), ) assert exc.value.status_code == 403 + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + ("policy", "data", "existing"), + [ + (None, UpdateKeyRequest(key="sk-1", budget_duration="1s"), _key(max_budget=10.0, budget_duration="30d")), + ( + "lower_only", + UpdateKeyRequest(key="sk-1", budget_duration="1s"), + _key(max_budget=10.0, budget_duration="30d"), + ), + ("ceiling", UpdateKeyRequest(key="sk-1", budget_id="shared-tier-100"), _key(budget_id="shared-tier-10")), + ("ceiling", UpdateKeyRequest(key="sk-1", budget_duration="1s"), _key(budget_id="shared-tier-10")), + ], +) +async def test_owner_cannot_restart_or_relink_a_key_budget_without_admin( + monkeypatch: pytest.MonkeyPatch, policy: str | None, data: UpdateKeyRequest, existing: LiteLLM_VerificationToken +) -> None: + with pytest.raises(HTTPException) as exc: + await _update(monkeypatch, policy=policy, data=data, existing=existing) + assert exc.value.status_code == 403 + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + ("policy", "data", "existing"), + [ + (None, UpdateKeyRequest(key="sk-1", budget_duration="1d"), _key(budget_duration="30d")), + (None, UpdateKeyRequest(key="sk-1", budget_duration="24h"), _key(max_budget=10.0, budget_duration="daily")), + ( + "lower_only", + UpdateKeyRequest(key="sk-1", budget_duration=None), + _key(max_budget=10.0, budget_duration="30d"), + ), + ("ceiling", UpdateKeyRequest(key="sk-1", budget_duration="1s"), _key(max_budget=10.0, budget_duration="30d")), + ], +) +async def test_owner_changes_budget_duration_when_it_cannot_restart_a_cap_or_policy_allows( + monkeypatch: pytest.MonkeyPatch, policy: str | None, data: UpdateKeyRequest, existing: LiteLLM_VerificationToken +) -> None: + assert await _denial(monkeypatch, policy=policy, data=data, existing=existing) is None + + +@pytest.mark.asyncio +async def test_team_member_cannot_restart_a_team_key_budget_created_by_someone_else( + monkeypatch: pytest.MonkeyPatch, +) -> None: + with pytest.raises(HTTPException) as exc: + await _update( + monkeypatch, + policy=None, + data=UpdateKeyRequest(key="sk-1", budget_duration="1s"), + existing=_key(created_by=_TEAM_ADMIN, team_id=_TEAM, max_budget=10.0, budget_duration="30d"), + team=_team(["/key/update"]), + ) + assert exc.value.status_code == 403 diff --git a/tests/unit/proxy/management_endpoints/test_key_management_endpoints.py b/tests/unit/proxy/management_endpoints/test_key_management_endpoints.py index d6ee9b1d29e..9634f1efce8 100644 --- a/tests/unit/proxy/management_endpoints/test_key_management_endpoints.py +++ b/tests/unit/proxy/management_endpoints/test_key_management_endpoints.py @@ -1,30 +1,30 @@ import asyncio +import inspect +import json from collections.abc import Mapping from contextlib import ExitStack -from typing import Final -from types import SimpleNamespace -import json from datetime import datetime, timedelta, timezone +from types import SimpleNamespace +from typing import Final +from unittest.mock import AsyncMock, MagicMock, patch from uuid import UUID -import litellm import pytest import yaml -from fastapi.testclient import TestClient - -from unittest.mock import AsyncMock, MagicMock, patch - from fastapi import HTTPException +from fastapi.testclient import TestClient from pydantic import JsonValue -import inspect - +import litellm +from litellm.constants import PROXY_DB_LOOKUP_STALL_WINDOW_SECONDS +from litellm.litellm_core_utils.duration_parser import duration_in_seconds +from litellm.models.object_permission import LiteLLM_ObjectPermissionTable from litellm.models.project import LiteLLM_ProjectTable from litellm.proxy._types import ( - GenerateKeyResponse, + CommonProxyErrors, GenerateKeyRequest, + GenerateKeyResponse, KeyManagementRoutes, - NewUserRequest, LiteLLM_BudgetTable, LiteLLM_ObjectPermissionBase, LiteLLM_OrganizationTable, @@ -36,46 +36,42 @@ from litellm.proxy._types import ( LiteLLMKeyType, LitellmUserRoles, Member, + NewUserRequest, ProxyException, RegenerateKeyRequest, ResetSpendRequest, UpdateKeyRequest, ) -from litellm.models.object_permission import LiteLLM_ObjectPermissionTable from litellm.proxy.auth.auth_checks import ( delete_cache_key_object, jwt_key_mapping_cache_key, ) from litellm.proxy.auth.user_api_key_auth import UserAPIKeyAuth from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache, project_cache_key -from litellm.constants import PROXY_DB_LOOKUP_STALL_WINDOW_SECONDS from litellm.proxy.db.db_lookup_gate import db_lookup_stall_tracker -from litellm.litellm_core_utils.duration_parser import duration_in_seconds from litellm.proxy.management_endpoints.key_management_endpoints import ( + KeyProjectBindingError, _check_key_project_team, _check_key_project_team_on_mutation, _check_org_key_limits, _check_project_key_limits, _check_team_key_limits, - _is_team_key, - _key_generation_required_param_check, - _personal_key_generation_check, - _team_key_generation_check, _common_key_generation_helper, - _member_key_request, - _team_admin_requests_member_key, - KeyProjectBindingError, _effective_key_after_update, _effective_key_for_generate, _enforce_custom_key_policy, _enforce_upperbound_key_params, _execute_virtual_key_regeneration, _get_and_validate_existing_key, - list_key_helper, - persist_deleted_verification_tokens, + _is_team_key, + _key_generation_required_param_check, + _member_key_request, + _personal_key_generation_check, _process_single_key_update, _requested_end_user_budget_id, _save_deleted_verification_token_records, + _team_admin_requests_member_key, + _team_key_generation_check, _transform_verification_tokens_to_deleted_records, _validate_end_user_budget_id_change, _validate_max_budget, @@ -90,7 +86,9 @@ from litellm.proxy.management_endpoints.key_management_endpoints import ( generate_service_account_key_fn, key_aliases, key_generation_check, + list_key_helper, list_keys, + persist_deleted_verification_tokens, prepare_key_update_data, prepare_metadata_fields, reset_key_spend_fn, @@ -837,7 +835,7 @@ async def test_update_key_grandfathers_existing_mcp_servers(monkeypatch): } mock_mgr.get_allow_all_keys_server_ids.return_value = [] monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_mgr, ) @@ -10955,10 +10953,10 @@ class TestValidateKeyAliasFormat: _validate_key_alias_format("team/user@example.com") def test_validate_key_alias_format_invalid(self, monkeypatch): + from litellm.proxy._types import ProxyException from litellm.proxy.management_endpoints.key_management_endpoints import ( _validate_key_alias_format, ) - from litellm.proxy._types import ProxyException monkeypatch.setattr(litellm, "enable_key_alias_format_validation", True) invalid_aliases = [ @@ -12798,14 +12796,14 @@ class TestKeyAliasSkipValidationOnUnchanged: Updating a key without changing its key_alias should skip format validation — even if the alias wouldn't pass current rules. """ + # Temporarily make the regex reject '@' to simulate stricter rules + import re + + from litellm.proxy.management_endpoints import key_management_endpoints as mod from litellm.proxy.management_endpoints.key_management_endpoints import ( _validate_key_alias_format, ) - # Temporarily make the regex reject '@' to simulate stricter rules - import re - from litellm.proxy.management_endpoints import key_management_endpoints as mod - original_pattern = mod._KEY_ALIAS_PATTERN mod._KEY_ALIAS_PATTERN = re.compile( r"^[a-zA-Z0-9][a-zA-Z0-9_\-/\.]{0,253}[a-zA-Z0-9]$" @@ -20431,7 +20429,6 @@ async def test_regenerate_key_repoints_access_group_assigned_key_ids(monkeypatch from litellm.proxy.management_endpoints.key_management_endpoints import ( _execute_virtual_key_regeneration, ) - from litellm.proxy.utils import hash_token new_token_hash = hash_token("sk-newtoken1234ab12") @@ -21358,8 +21355,9 @@ async def test_key_generation_premium_permission_error_precedes_project_ownershi team_table=None, ) - assert error.value.status_code == 500 - assert error.value.detail == {"error": "Internal Server Error."} + assert error.value.status_code == 403 + assert "get_spend_routes" in str(error.value.detail) + assert CommonProxyErrors.not_premium_user.value in str(error.value.detail).replace("\\n", "\n") mock_prisma_client.insert_data.assert_not_awaited() @@ -23214,6 +23212,76 @@ def test_key_info_unexpected_database_exception_sanitized( proxy_server.app.dependency_overrides.pop(user_api_key_auth, None) +@pytest.fixture +def spend_permission_client(monkeypatch: pytest.MonkeyPatch) -> TestClient: + from litellm.proxy import proxy_server + from litellm.proxy.auth.user_api_key_auth import user_api_key_auth + + prisma_client: Final = _configure_key_endpoints(monkeypatch, UserApiKeyCache()) + prisma_client.db.litellm_usertable = MagicMock() + prisma_client.db.litellm_usertable.count = AsyncMock(return_value=0) + monkeypatch.setattr(litellm, "default_key_generate_params", None) + monkeypatch.setattr(proxy_server, "premium_user", False) + monkeypatch.setitem( + proxy_server.app.dependency_overrides, + user_api_key_auth, + lambda: UserAPIKeyAuth(user_role=LitellmUserRoles.PROXY_ADMIN, api_key="sk-admin"), + ) + return TestClient(proxy_server.app) + + +@pytest.mark.parametrize("route", ("/key/generate", "/user/new")) +@pytest.mark.parametrize("permission", ("true", "false", False), ids=("string_true", "string_false", "bool_false")) +def test_spend_permission_enterprise_error_regression( + spend_permission_client: TestClient, + route: str, + permission: str | bool, +) -> None: + response: Final = spend_permission_client.post(route, json={"permissions": {"get_spend_routes": permission}}) + + assert response.status_code == 403, response.text + assert "get_spend_routes" in response.text + assert CommonProxyErrors.not_premium_user.value in response.json()["error"]["message"].replace("\\n", "\n") + + +@pytest.mark.parametrize( + "permissions", + ({}, {"other": True}, {"other": "get_spend_routes"}, {"get_spend_routes_extra": True}), + ids=("empty", "unrelated", "permission_in_value", "permission_in_other_key"), +) +def test_non_enterprise_permissions_guard( + spend_permission_client: TestClient, + permissions: dict[str, str | bool], +) -> None: + response: Final = spend_permission_client.post("/key/generate", json={"permissions": permissions}) + + assert response.status_code == 200, response.text + assert response.json()["permissions"] == permissions + assert response.json()["key"].startswith("sk-") + + +def test_enterprise_spend_permission_guard( + spend_permission_client: TestClient, + monkeypatch: pytest.MonkeyPatch, +) -> None: + monkeypatch.setattr("litellm.proxy.proxy_server.premium_user", True) + response: Final = spend_permission_client.post( + "/key/generate", json={"permissions": {"get_spend_routes": True}} + ) + + assert response.status_code == 200, response.text + assert response.json()["permissions"] == {"get_spend_routes": True} + assert response.json()["key"].startswith("sk-") + + +def test_guardrails_enterprise_error_guard(spend_permission_client: TestClient) -> None: + response: Final = spend_permission_client.post("/key/generate", json={"guardrails": ["g"]}) + + assert response.status_code == 403, response.text + assert "guardrails" in response.text + assert CommonProxyErrors.not_premium_user.value in response.json()["error"]["message"].replace("\\n", "\n") + + def test_key_info_missing_key_preserves_404( monkeypatch: pytest.MonkeyPatch, ) -> None: @@ -23304,6 +23372,3 @@ def test_key_info_database_not_connected_sanitized_500( assert "Database not connected" in caplog.text finally: proxy_server.app.dependency_overrides.pop(user_api_key_auth, None) - - - diff --git a/tests/unit/proxy/management_endpoints/test_mcp_management_endpoints.py b/tests/unit/proxy/management_endpoints/test_mcp_management_endpoints.py index 65c4a8faeb7..4b1415c8879 100644 --- a/tests/unit/proxy/management_endpoints/test_mcp_management_endpoints.py +++ b/tests/unit/proxy/management_endpoints/test_mcp_management_endpoints.py @@ -1,14 +1,11 @@ -from contextlib import nullcontext - - import asyncio +import json +import logging import os import sys import types -import json -import logging from collections.abc import Iterator, Mapping -from contextlib import ExitStack, contextmanager +from contextlib import ExitStack, contextmanager, nullcontext from dataclasses import dataclass, field from datetime import datetime, timedelta from types import SimpleNamespace @@ -17,28 +14,23 @@ from unittest.mock import AsyncMock, MagicMock, patch import httpx import pytest -from pydantic import BaseModel, TypeAdapter, ValidationError -from respx import MockRouter from fastapi import FastAPI, HTTPException, Request from fastapi.testclient import TestClient +from pydantic import BaseModel, TypeAdapter, ValidationError +from respx import MockRouter import litellm from litellm._uuid import uuid from litellm.caching.caching import DualCache -from litellm.integrations.custom_guardrail import CustomGuardrail -from litellm.proxy.utils import ProxyLogging from litellm.constants import UI_SESSION_TOKEN_TEAM_ID +from litellm.integrations.custom_guardrail import CustomGuardrail from litellm.models.access_group import LiteLLM_AccessGroupTable from litellm.models.organization import LiteLLM_OrganizationTable from litellm.models.team import LiteLLM_TeamTable from litellm.models.user import LiteLLM_UserTable -from litellm.proxy.management_endpoints import ( - mcp_management_endpoints as mgmt_endpoints, -) - from litellm.proxy._types import ( - LiteLLM_ObjectPermissionTable, LiteLLM_MCPServerTable, + LiteLLM_ObjectPermissionTable, LitellmUserRoles, MakeMCPServersPublicRequest, MCPTransport, @@ -47,7 +39,11 @@ from litellm.proxy._types import ( UpdateMCPServerRequest, UserAPIKeyAuth, ) -from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerConfig, MCPServerManager +from litellm.proxy.management_endpoints import ( + mcp_management_endpoints as mgmt_endpoints, +) +from litellm.proxy.mcp_server.mcp_server_manager import MCPServerConfig, MCPServerManager +from litellm.proxy.utils import ProxyLogging from litellm.types.mcp import MCPAuth, MCPCredentials from litellm.types.mcp_server.mcp_server_manager import MCPServer, PinnedMCPTool @@ -173,7 +169,7 @@ def patch_proxy_general_settings(settings: dict): async def test_mcp_publication_list_and_detail_derive_current_status( from_db: bool, strict: bool, explicit: bool, expected_public: bool ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager: Final = MCPServerManager() server: Final = MCPServer( @@ -227,7 +223,7 @@ async def test_mcp_publication_list_and_detail_derive_current_status( def test_mcp_publication_projection_excludes_unregistered_lifecycle_records( approval_status: str, strict: bool ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager record: Final = LiteLLM_MCPServerTable( server_id="unregistered-server", @@ -275,7 +271,7 @@ async def test_mcp_publication_updates_runtime_only_after_successful_save( error_status: int | None, ) -> None: import litellm - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager: Final = MCPServerManager() server: Final = generate_mock_mcp_server_config_record(server_id="new-server") @@ -299,7 +295,7 @@ async def test_mcp_publication_updates_runtime_only_after_successful_save( patch("litellm.public_mcp_servers", previous_ids), patch("litellm.proxy.proxy_server.proxy_config", proxy_config), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager, ), ): @@ -1537,11 +1533,11 @@ class TestListMCPServers: mock_manager, ), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_servers_by_verificationtoken", + "litellm.proxy.mcp_server.db.get_mcp_servers_by_verificationtoken", AsyncMock(return_value=["env-server"]), ), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_servers", + "litellm.proxy.mcp_server.db.get_mcp_servers", AsyncMock(return_value=[generate_mock_mcp_server_db_record(server_id="env-server")]), ), patch( @@ -2343,7 +2339,7 @@ class TestTemporaryMCPSessionEndpoints: """The edit form authorizes against a saved server's own id, so a draft write would collide on the primary key. That row is already visible to every worker, so it is returned untouched and no draft is created.""" - from litellm.proxy._experimental.mcp_server.db import create_draft_mcp_server + from litellm.proxy.mcp_server.db import create_draft_mcp_server real_row = generate_mock_mcp_server_db_record(server_id="already-saved") real_row.approval_status = "active" @@ -2352,15 +2348,15 @@ class TestTemporaryMCPSessionEndpoints: with ( patch( - "litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_row", + "litellm.proxy.mcp_server.db._db_find_mcp_server_row", AsyncMock(return_value=real_row), ), patch( - "litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_rows", + "litellm.proxy.mcp_server.db._db_find_mcp_server_rows", AsyncMock(return_value=[]), ), - patch("litellm.proxy._experimental.mcp_server.db.create_mcp_server", create_call), - patch("litellm.proxy._experimental.mcp_server.db.delete_mcp_server", delete_call), + patch("litellm.proxy.mcp_server.db.create_mcp_server", create_call), + patch("litellm.proxy.mcp_server.db.delete_mcp_server", delete_call), ): result = await create_draft_mcp_server( MagicMock(), @@ -2381,7 +2377,7 @@ class TestTemporaryMCPSessionEndpoints: live two-worker proxy. The loser's session is in fact ready, because the winner wrote a draft for it, so it adopts that row instead of failing the caller. """ - from litellm.proxy._experimental.mcp_server.db import create_draft_mcp_server + from litellm.proxy.mcp_server.db import create_draft_mcp_server winner_draft = generate_mock_mcp_server_db_record(server_id="raced") winner_draft.approval_status = "draft" @@ -2389,13 +2385,13 @@ class TestTemporaryMCPSessionEndpoints: lookups = AsyncMock(side_effect=[None, winner_draft]) with ( - patch("litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_row", lookups), + patch("litellm.proxy.mcp_server.db._db_find_mcp_server_row", lookups), patch( - "litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_rows", + "litellm.proxy.mcp_server.db._db_find_mcp_server_rows", AsyncMock(return_value=[]), ), patch( - "litellm.proxy._experimental.mcp_server.db.create_mcp_server", + "litellm.proxy.mcp_server.db.create_mcp_server", AsyncMock(side_effect=Exception("duplicate key value violates unique constraint")), ), ): @@ -2412,19 +2408,19 @@ class TestTemporaryMCPSessionEndpoints: @pytest.mark.asyncio async def test_create_draft_mcp_server_reraises_when_the_create_failure_was_not_a_race(self): """A genuine database error must not be swallowed by the race-adoption path.""" - from litellm.proxy._experimental.mcp_server.db import create_draft_mcp_server + from litellm.proxy.mcp_server.db import create_draft_mcp_server with ( patch( - "litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_row", + "litellm.proxy.mcp_server.db._db_find_mcp_server_row", AsyncMock(side_effect=[None, None]), ), patch( - "litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_rows", + "litellm.proxy.mcp_server.db._db_find_mcp_server_rows", AsyncMock(return_value=[]), ), patch( - "litellm.proxy._experimental.mcp_server.db.create_mcp_server", + "litellm.proxy.mcp_server.db.create_mcp_server", AsyncMock(side_effect=Exception("connection refused")), ), pytest.raises(Exception, match="connection refused"), @@ -2440,10 +2436,10 @@ class TestTemporaryMCPSessionEndpoints: async def test_create_draft_mcp_server_prunes_drafts_past_their_lifetime(self): """Regression: abandoned OAuth sessions accumulated forever. Verified against a live proxy, where 12 drafts aged past the lifetime were still present and a 13th was added.""" - from litellm.proxy._experimental.mcp_server.db import create_draft_mcp_server - from datetime import timezone + from litellm.proxy.mcp_server.db import create_draft_mcp_server + now = datetime.now(timezone.utc) stale_one = generate_mock_mcp_server_db_record(server_id="stale-1") stale_one.updated_at = now - timedelta(hours=1) @@ -2456,14 +2452,14 @@ class TestTemporaryMCPSessionEndpoints: delete_call = AsyncMock() with ( - patch("litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_rows", find_rows), + patch("litellm.proxy.mcp_server.db._db_find_mcp_server_rows", find_rows), patch( - "litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_row", + "litellm.proxy.mcp_server.db._db_find_mcp_server_row", AsyncMock(return_value=None), ), - patch("litellm.proxy._experimental.mcp_server.db.delete_mcp_server", delete_call), + patch("litellm.proxy.mcp_server.db.delete_mcp_server", delete_call), patch( - "litellm.proxy._experimental.mcp_server.db.create_mcp_server", + "litellm.proxy.mcp_server.db.create_mcp_server", AsyncMock(return_value=generate_mock_mcp_server_db_record(server_id="fresh")), ), ): @@ -2483,11 +2479,11 @@ class TestTemporaryMCPSessionEndpoints: """Drafts are addressable only by their own id and must never appear in a listing, but a bare inequality would also drop pre-approval-workflow rows, since SQL evaluates NULL != 'draft' as NULL.""" - from litellm.proxy._experimental.mcp_server.db import get_all_mcp_servers + from litellm.proxy.mcp_server.db import get_all_mcp_servers find_rows = AsyncMock(return_value=[]) with patch( - "litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_rows", + "litellm.proxy.mcp_server.db._db_find_mcp_server_rows", find_rows, ): await get_all_mcp_servers(MagicMock()) @@ -2499,11 +2495,11 @@ class TestTemporaryMCPSessionEndpoints: async def test_get_all_mcp_servers_propagates_read_failures(self): """Regression: a swallowed read failure returned [] and silently disabled the bulk-import dedupe, so a flaky DB read turned a re-import into duplicate servers.""" - from litellm.proxy._experimental.mcp_server.db import get_all_mcp_servers + from litellm.proxy.mcp_server.db import get_all_mcp_servers find_rows = AsyncMock(side_effect=RuntimeError("db down")) with patch( # test-quality-ok: the helper takes its row reader from module scope, matching the suite's pattern - "litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_rows", + "litellm.proxy.mcp_server.db._db_find_mcp_server_rows", find_rows, ): with pytest.raises(RuntimeError, match="db down"): @@ -2681,7 +2677,7 @@ class TestTemporaryMCPSessionEndpoints: mock_manager, ), patch( - "litellm.proxy._experimental.mcp_server.ui_session_utils.build_effective_auth_contexts", + "litellm.proxy.mcp_server.ui_session_utils.build_effective_auth_contexts", AsyncMock(return_value=[non_admin]), ) as effective_contexts, patch.object(mgmt_endpoints, "build_effective_auth_contexts", effective_contexts), @@ -2769,7 +2765,7 @@ class TestTemporaryMCPSessionEndpoints: mock_manager, ), patch( - "litellm.proxy._experimental.mcp_server.ui_session_utils.build_effective_auth_contexts", + "litellm.proxy.mcp_server.ui_session_utils.build_effective_auth_contexts", AsyncMock(return_value=[ui_session_auth, team_context]), ) as effective_contexts, patch.object(mgmt_endpoints, "build_effective_auth_contexts", effective_contexts), @@ -3027,7 +3023,7 @@ class TestTemporaryMCPSessionEndpoints: with ( patch.dict(sys.modules, {"litellm.proxy.proxy_server": fake_proxy_server}), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch( @@ -3081,7 +3077,7 @@ class TestTemporaryMCPSessionEndpoints: with ( patch.dict(sys.modules, {"litellm.proxy.proxy_server": fake_proxy_server}), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch( @@ -3139,8 +3135,8 @@ class TestTemporaryMCPSessionEndpoints: from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy.management_endpoints.mcp_management_endpoints import mcp_authorize + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager row: Final = LiteLLM_MCPServerTable( server_id="saved-server", @@ -3269,7 +3265,7 @@ class TestTemporaryMCPSessionEndpoints: if mint_mock is not None: patches.append( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.mint_ephemeral_dcr_client", + "litellm.proxy.mcp_server.discoverable_endpoints.mint_ephemeral_dcr_client", mint_mock, ) ) @@ -3324,7 +3320,7 @@ class TestTemporaryMCPSessionEndpoints: through to a gateway-side DCR mint and proceed with the minted client instead of dead-ending on a 400 missing_client_id. Both modes share the caller-held-client contract, so both get the fall-through.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( EphemeralDcrClient, ) @@ -3367,7 +3363,7 @@ class TestTemporaryMCPSessionEndpoints: return_value=nullcontext(server), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.mint_ephemeral_dcr_client", + "litellm.proxy.mcp_server.discoverable_endpoints.mint_ephemeral_dcr_client", mint_mock, ), ): @@ -3448,7 +3444,7 @@ class TestTemporaryMCPSessionEndpoints: one (the minted flow runs the bridge short-circuit arm) instead of dead-ending on missing_client_id. The relay front door stays reserved for clients that present their own client_id.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( EphemeralDcrClient, ) @@ -3492,12 +3488,12 @@ class TestTemporaryMCPSessionEndpoints: callback forwarded, so the token endpoint recovers the ephemeral client and the real upstream code from it and authenticates the exchange with them, with no client_id supplied by the caller and none stored on the server.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( - seal_passthrough_authorization_code, - ) from litellm.proxy.management_endpoints.mcp_management_endpoints import ( mcp_token, ) + from litellm.proxy.mcp_server.discoverable_endpoints import ( + seal_passthrough_authorization_code, + ) request = MagicMock() request.base_url = "https://litellm.example.com/" @@ -3549,13 +3545,13 @@ class TestTemporaryMCPSessionEndpoints: async def test_mcp_token_prefers_sealed_client_when_server_has_shared_client( self: "TestTemporaryMCPSessionEndpoints", ) -> None: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( - seal_passthrough_authorization_code, - ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.management_endpoints.mcp_management_endpoints import ( mcp_token, ) + from litellm.proxy.mcp_server.discoverable_endpoints import ( + seal_passthrough_authorization_code, + ) + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager request: Final = MagicMock() request.base_url = "https://litellm.example.com/" @@ -3590,7 +3586,7 @@ class TestTemporaryMCPSessionEndpoints: return_value=prisma_client, ), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch.object( @@ -3599,7 +3595,7 @@ class TestTemporaryMCPSessionEndpoints: new=mock_update_server, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), ): @@ -3640,12 +3636,12 @@ class TestTemporaryMCPSessionEndpoints: contract: a refresh_token grant that echoes a leftover sealed passthrough code (plus any verifier) must not recover the minted credentials, so a clientless server answers missing_client_id and the client re-runs authorize instead.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( - seal_passthrough_authorization_code, - ) from litellm.proxy.management_endpoints.mcp_management_endpoints import ( mcp_token, ) + from litellm.proxy.mcp_server.discoverable_endpoints import ( + seal_passthrough_authorization_code, + ) request = MagicMock() request.base_url = "https://litellm.example.com/" @@ -3696,12 +3692,12 @@ class TestTemporaryMCPSessionEndpoints: """A sealed code is minted only for S256 PKCE flows, so redeeming one without the corresponding verifier is refused at the gateway rather than trusting the upstream to enforce the binding.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( - seal_passthrough_authorization_code, - ) from litellm.proxy.management_endpoints.mcp_management_endpoints import ( mcp_token, ) + from litellm.proxy.mcp_server.discoverable_endpoints import ( + seal_passthrough_authorization_code, + ) request = MagicMock() server = generate_mock_mcp_server_config_record(server_id="server-1") @@ -3746,12 +3742,12 @@ class TestTemporaryMCPSessionEndpoints: """A sealed passthrough code is bound to the server it was minted for: presenting it at another server's token endpoint is a 400 before any upstream exchange, so a code cannot be replayed across a server boundary.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( - seal_passthrough_authorization_code, - ) from litellm.proxy.management_endpoints.mcp_management_endpoints import ( mcp_token, ) + from litellm.proxy.mcp_server.discoverable_endpoints import ( + seal_passthrough_authorization_code, + ) request = MagicMock() server = generate_mock_mcp_server_config_record(server_id="server-1") @@ -4790,8 +4786,8 @@ async def test_health_discovery_respects_route_restricted_key_grants( ) -> None: from typing import Final - from litellm.proxy._experimental.mcp_server import mcp_server_manager from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server import mcp_server_manager monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") manager: Final = mcp_server_manager.MCPServerManager() @@ -4865,8 +4861,8 @@ async def test_health_checks_probe_shared_servers_once_across_auth_contexts( expected: tuple[str, ...], include_reachability: bool, ) -> None: - from litellm.proxy._experimental.mcp_server import mcp_server_manager from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server import mcp_server_manager monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") manager: Final = mcp_server_manager.MCPServerManager() @@ -4934,8 +4930,8 @@ async def test_health_reachability_requires_explicit_api_opt_in( detail: bool, flag: str | None, ) -> None: - from litellm.proxy._experimental.mcp_server import mcp_server_manager from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server import mcp_server_manager class HealthResponse(BaseModel): server_id: str @@ -5770,10 +5766,10 @@ async def test_store_mcp_oauth_user_credential_blocked_when_identity_binding_enf if not mgmt_endpoints.MCP_AVAILABLE: pytest.skip("MCP module not installed") - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module from litellm.proxy.management_endpoints.mcp_management_endpoints import ( store_mcp_oauth_user_credential, ) + from litellm.proxy.mcp_server import mcp_server_manager as manager_module server_id = "srv-binding-1" bound_server = MCPServer( @@ -5875,10 +5871,10 @@ async def test_store_mcp_oauth_user_credential_invalidates_cached_token(): if not mgmt_endpoints.MCP_AVAILABLE: pytest.skip("MCP module not installed") - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module from litellm.proxy.management_endpoints.mcp_management_endpoints import ( store_mcp_oauth_user_credential, ) + from litellm.proxy.mcp_server import mcp_server_manager as manager_module server_id = "srv-inv-1" user_id = "user-inv-1" @@ -5927,10 +5923,10 @@ async def test_delete_mcp_oauth_user_credential_invalidates_cached_token(): if not mgmt_endpoints.MCP_AVAILABLE: pytest.skip("MCP module not installed") - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module from litellm.proxy.management_endpoints.mcp_management_endpoints import ( delete_mcp_oauth_user_credential, ) + from litellm.proxy.mcp_server import mcp_server_manager as manager_module server_id = "srv-inv-2" user_id = "user-inv-2" @@ -5971,10 +5967,10 @@ async def test_delete_mcp_oauth_user_credential_invalidates_when_record_already_ if not mgmt_endpoints.MCP_AVAILABLE: pytest.skip("MCP module not installed") - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module from litellm.proxy.management_endpoints.mcp_management_endpoints import ( delete_mcp_oauth_user_credential, ) + from litellm.proxy.mcp_server import mcp_server_manager as manager_module server_id = "srv-inv-3" user_id = "user-inv-3" @@ -6018,10 +6014,10 @@ async def test_admin_revokes_another_users_byok_credential(): if not mgmt_endpoints.MCP_AVAILABLE: pytest.skip("MCP module not installed") - from litellm.proxy._experimental.mcp_server import server as mcp_server from litellm.proxy.management_endpoints.mcp_management_endpoints import ( delete_mcp_user_credential, ) + from litellm.proxy.mcp_server import server as mcp_server delete_mock = AsyncMock(return_value=None) invalidate_mock = AsyncMock() @@ -6087,10 +6083,10 @@ async def test_user_naming_themselves_still_deletes_own_byok_credential(): if not mgmt_endpoints.MCP_AVAILABLE: pytest.skip("MCP module not installed") - from litellm.proxy._experimental.mcp_server import server as mcp_server from litellm.proxy.management_endpoints.mcp_management_endpoints import ( delete_mcp_user_credential, ) + from litellm.proxy.mcp_server import server as mcp_server deleted_rows: list[tuple[str, str]] = [] # mutable-ok: test-local recorder for the fake delete boundary @@ -6126,10 +6122,10 @@ async def test_admin_revokes_another_users_oauth_credential(): if not mgmt_endpoints.MCP_AVAILABLE: pytest.skip("MCP module not installed") - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module from litellm.proxy.management_endpoints.mcp_management_endpoints import ( delete_mcp_oauth_user_credential, ) + from litellm.proxy.mcp_server import mcp_server_manager as manager_module get_mock = AsyncMock(return_value={"type": "oauth2", "access_token": "mallory-tok"}) delete_mock = AsyncMock(return_value=None) @@ -7427,7 +7423,7 @@ class TestMCPUserEnvVarsAccessControl: def test_oauth2_flow_accepted_on_create_request(): """NewMCPServerRequest carries oauth2_flow through to the persisted dict.""" - from litellm.proxy._experimental.mcp_server.db import _prepare_mcp_server_data + from litellm.proxy.mcp_server.db import _prepare_mcp_server_data payload = NewMCPServerRequest( server_name="m2m-server", @@ -7506,8 +7502,8 @@ def test_dcr_bridge_rejected_on_create_when_auth_type_omitted(): @pytest.mark.parametrize("auth_type", ["true_passthrough", "oauth_delegate"]) def test_dcr_bridge_accepted_on_create_for_client_forwarded_modes(auth_type): - from litellm.proxy._experimental.mcp_server.db import _prepare_mcp_server_data from litellm.proxy._types import NewMCPServerRequest + from litellm.proxy.mcp_server.db import _prepare_mcp_server_data payload = NewMCPServerRequest( server_name="bridge-server", @@ -8037,7 +8033,7 @@ class TestConnectedAppViewAnnotation: AsyncMock(return_value=[caller_auth]), ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", reload_mock, ), ): @@ -8069,7 +8065,7 @@ class TestConnectedAppViewAnnotation: mock_manager, ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", AsyncMock(return_value=UserAPIKeyAuth(user_id="test_user_id")), ), ): @@ -8108,11 +8104,11 @@ class TestConnectedAppViewAnnotation: mock_manager, ), patch( - "litellm.proxy._experimental.mcp_server.ui_session_utils.resolve_ui_session_team_ids", + "litellm.proxy.mcp_server.ui_session_utils.resolve_ui_session_team_ids", AsyncMock(return_value=[]), ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", AsyncMock(return_value=admitted_auth), ), ): @@ -8140,7 +8136,7 @@ class TestConnectedAppViewAnnotation: AsyncMock(return_value=[caller_auth]), ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", AsyncMock(side_effect=HTTPException(status_code=401, detail="expired")), ), ): @@ -8168,7 +8164,7 @@ class TestConnectedAppViewAnnotation: AsyncMock(return_value=[caller_auth]), ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", reload_mock, ), ): @@ -8202,7 +8198,7 @@ class TestConnectedAppViewAnnotation: AsyncMock(return_value=[caller_auth]), ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", reload_mock, ), ): @@ -8233,7 +8229,7 @@ class TestConnectedAppViewAnnotation: AsyncMock(return_value=[caller_auth]), ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", reload_mock, ), ): @@ -8433,10 +8429,10 @@ class TestGetMCPGatewaySessions: async def test_admin_roles_receive_live_session_report(self, role): from mcp.types import Implementation - from litellm.proxy._experimental.mcp_server import server as mcp_server from litellm.proxy.management_endpoints.mcp_management_endpoints import ( get_mcp_gateway_sessions, ) + from litellm.proxy.mcp_server import server as mcp_server from litellm.types.mcp import MCPGatewaySessionsResponse session_id = "gateway-sessions-endpoint-1" @@ -8470,7 +8466,7 @@ class TestGetMCPGatewaySessions: class TestDeleteMCPGatewaySessions: @pytest.fixture(autouse=True) def _forget_admin_terminated_ids(self): - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server yield mcp_server._admin_terminated_session_ids.clear() @@ -8478,10 +8474,10 @@ class TestDeleteMCPGatewaySessions: @pytest.mark.asyncio @pytest.mark.parametrize("role", [LitellmUserRoles.INTERNAL_USER, LitellmUserRoles.PROXY_ADMIN_VIEW_ONLY]) async def test_non_full_admin_forbidden_before_any_session_is_touched(self, role): - from litellm.proxy._experimental.mcp_server import server as mcp_server from litellm.proxy.management_endpoints.mcp_management_endpoints import ( delete_mcp_gateway_sessions, ) + from litellm.proxy.mcp_server import server as mcp_server session_id = "gateway-terminate-forbidden-1" transport = MagicMock(terminate=AsyncMock()) @@ -8522,10 +8518,10 @@ class TestDeleteMCPGatewaySessions: @pytest.mark.asyncio async def test_admin_terminates_only_the_selected_session(self): - from litellm.proxy._experimental.mcp_server import server as mcp_server from litellm.proxy.management_endpoints.mcp_management_endpoints import ( delete_mcp_gateway_sessions, ) + from litellm.proxy.mcp_server import server as mcp_server from litellm.types.mcp import MCPGatewaySessionsTerminateResponse target_id = "11111111-target-session" @@ -8569,10 +8565,10 @@ class TestDeleteMCPGatewaySessions: @pytest.mark.asyncio async def test_admin_terminates_every_session_of_the_selected_user(self): - from litellm.proxy._experimental.mcp_server import server as mcp_server from litellm.proxy.management_endpoints.mcp_management_endpoints import ( delete_mcp_gateway_sessions, ) + from litellm.proxy.mcp_server import server as mcp_server def auth_user(user_id: str): return mcp_server.MCPAuthenticatedUser( @@ -8620,7 +8616,7 @@ class TestGetMcpToolsWireShape: tools=[Tool(name="add", description="Add", inputSchema=add_schema, outputSchema={"type": "integer"})] ) with patch( - "litellm.proxy._experimental.mcp_server.server._list_mcp_tools", + "litellm.proxy.mcp_server.server._list_mcp_tools", AsyncMock(return_value=listed), ): result = await mgmt_endpoints.get_mcp_tools(user_api_key_dict=generate_mock_user_api_key_auth()) @@ -8641,7 +8637,7 @@ class TestGetMcpToolsWireShape: ], ) async def test_config_server_edit_preserves_api_contract_without_creating_rows(role, expected_status): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager = MCPServerManager() server = generate_mock_mcp_server_config_record(server_id="read-only-config") @@ -8675,7 +8671,7 @@ async def test_config_server_edit_preserves_api_contract_without_creating_rows(r @pytest.mark.asyncio async def test_saved_server_authorize_denial_does_not_dispatch_upstream(): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager: Final = MCPServerManager() row: Final = LiteLLM_MCPServerTable(server_id="denied-peer", alias="denied_peer", transport=MCPTransport.http, @@ -8715,7 +8711,7 @@ class TestDuplicateIdentifierRejection: @staticmethod def _conflict(field: str, value: str, server_id: str = "existing-1"): - from litellm.proxy._experimental.mcp_server.db import McpIdentifierConflict + from litellm.proxy.mcp_server.db import McpIdentifierConflict return McpIdentifierConflict(field=field, value=value, server_id=server_id) @@ -8963,7 +8959,7 @@ class TestPinMCPServerTools: ), patch("litellm.proxy.management_endpoints.mcp_management_endpoints.set_mcp_server_pinned_tools", store_mock), patch("litellm.proxy.management_endpoints.mcp_management_endpoints.global_mcp_server_manager", manager), - patch("litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager", manager), + patch("litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager", manager), patch.dict( sys.modules, { @@ -9171,9 +9167,9 @@ class _ResolutionEffects: patch.object(mgmt_endpoints, "merge_user_env_vars", self.env_merge), patch.object(mgmt_endpoints, "delete_user_env_vars", self.env_delete), patch.object(manager, "invalidate_user_oauth_token_cache", self.oauth_invalidate), - patch("litellm.proxy._experimental.mcp_server.server._invalidate_byok_cred_cache", self.byok_invalidate), + patch("litellm.proxy.mcp_server.server._invalidate_byok_cred_cache", self.byok_invalidate), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.invalidate_user_env_vars_cache", + "litellm.proxy.mcp_server.mcp_server_manager.invalidate_user_env_vars_cache", self.env_invalidate, ), ): @@ -10182,7 +10178,7 @@ class TestMCPServerResolutionCharacterization: with ( patch.object(mgmt_endpoints, "get_prisma_client_or_throw", return_value=prisma), patch.object(mgmt_endpoints, "global_mcp_server_manager", manager), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", manager), + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager), patch("litellm.proxy.proxy_server.prisma_client", prisma), patch("litellm.proxy.proxy_server.user_api_key_cache", _mock_mcp_resolution_cache()), patch("litellm.proxy.proxy_server.general_settings", {}), @@ -10293,7 +10289,7 @@ class TestMCPServerResolutionCharacterization: patch.object(mgmt_endpoints, "get_prisma_client_or_throw", return_value=prisma), patch.object(mgmt_endpoints, "global_mcp_server_manager", manager), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager, ), patch.object(manager, "add_server", add_server), @@ -10477,7 +10473,7 @@ class TestMCPServerResolutionCharacterization: patch.object(mgmt_endpoints, "get_prisma_client_or_throw", return_value=prisma), patch.object(mgmt_endpoints, "global_mcp_server_manager", manager), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager, ), patch.object(manager, "invalidate_user_oauth_token_cache", invalidate), @@ -11268,7 +11264,7 @@ class TestMCPServerResolutionCharacterization: MockRouter(assert_all_called=False) as httpx_mock, patch.object(mgmt_endpoints, "get_prisma_client_or_throw", return_value=prisma), patch.object(mgmt_endpoints, "global_mcp_server_manager", manager), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", manager), + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager), patch.object(manager, "add_server", add_server), patch.object(manager, "health_check_server", health_check), patch("litellm.proxy.proxy_server.prisma_client", prisma), diff --git a/tests/unit/proxy/management_endpoints/test_mcp_servers.py b/tests/unit/proxy/management_endpoints/test_mcp_servers.py index 77afe510267..4c0288f0e6f 100644 --- a/tests/unit/proxy/management_endpoints/test_mcp_servers.py +++ b/tests/unit/proxy/management_endpoints/test_mcp_servers.py @@ -9,14 +9,14 @@ from litellm.proxy._types import ( MCPTransport, NewMCPServerRequest, ) -from litellm.proxy._experimental.mcp_server.db import McpIdentifierConflict -from litellm.proxy._experimental.mcp_server.utils import validate_mcp_server_name from litellm.proxy.management_endpoints.mcp_management_endpoints import ( _redact_mcp_credentials, does_mcp_server_exist, raise_mcp_identifier_conflict, validate_and_normalize_mcp_server_payload, ) +from litellm.proxy.mcp_server.db import McpIdentifierConflict +from litellm.proxy.mcp_server.utils import validate_mcp_server_name def test_does_mcp_server_exist() -> None: diff --git a/tests/unit/proxy/management_endpoints/test_model_management_endpoints.py b/tests/unit/proxy/management_endpoints/test_model_management_endpoints.py index 303b8e060ed..9ff2a6de9dd 100644 --- a/tests/unit/proxy/management_endpoints/test_model_management_endpoints.py +++ b/tests/unit/proxy/management_endpoints/test_model_management_endpoints.py @@ -3672,6 +3672,23 @@ class TestUpdateDBModelKeepsLegacyDropParams: assert decrypt_value_helper(value=stored["drop_params"], key="drop_params") == "true" +@pytest.mark.parametrize( + "payload", + [ + {"litellm_params_to_remove": ["model"]}, + {"litellm_params_to_remove": ["temperature"], "litellm_params": {"temperature": 0}}, + {"litellm_params_to_remove": ["temperature"], "litellm_params": {"temperature": None}}, + ], +) +def test_model_param_removal_rejects_required_and_conflicting_fields(payload: Mapping[str, object]) -> None: + from pydantic import ValidationError + + from litellm.types.proxy.management_endpoints.model_management_endpoints import PatchModelRequest + + with pytest.raises(ValidationError): + PatchModelRequest.model_validate(payload) + + def _build_db_model_with_pricing(): """Wildcard deployment with custom pricing in litellm_params; Deployment.__init__ mirrors SPECIAL_MODEL_INFO_PARAMS into model_info, so both blobs hold the rate.""" @@ -7843,6 +7860,55 @@ class TestTeamMemberAutoRouterWrites: "jev_classifier_config" if legacy else "opensource_classifier_config": classifier, } + @pytest.mark.asyncio + @pytest.mark.parametrize( + "stored_params,removed,denied_param", + [ + ({"litellm_credential_name": "stored-credential"}, "litellm_credential_name", "litellm_credential_name"), + ({"aws_session_tags": [{"Key": "scope", "Value": "restricted"}]}, "aws_session_tags", "aws_session_tags"), + ({"api_key": "oidc/file//var/run/token", "api_base": "https://provider.test"}, "api_base", "api_key"), + ({"anthropic_issuer_url": "https://issuer.test"}, "anthropic_issuer_url", "anthropic_issuer_url"), + ], + ) + async def test_team_admin_cannot_remove_admin_owned_model_params( + self, stored_params: Mapping[str, object], removed: str, denied_param: str + ) -> None: + from litellm.types.proxy.management_endpoints.model_management_endpoints import PatchModelRequest + + row: Final = self._row().model_copy( + update={"litellm_params": {"model": "openai/test-model", **stored_params}} + ) + team: Final = self._team().model_copy(update={"members_with_roles": [Member(user_id="owner", role="admin")]}) + database: Final = self._database(team, row) + database.db.litellm_credentialstable.find_unique = AsyncMock(return_value=None) + actor: Final = UserAPIKeyAuth(user_id="owner", user_role=LitellmUserRoles.INTERNAL_USER) + + with self._environment(database, row), pytest.raises(ProxyException) as denied: + await patch_model(row.model_id, PatchModelRequest(litellm_params_to_remove=(removed,)), actor) + + assert denied.value.code == "403" + assert denied.value.param == denied_param + database.db.litellm_proxymodeltable.update.assert_not_awaited() + + @pytest.mark.asyncio + async def test_param_removal_cannot_leave_a_strategy_router_without_required_configuration(self) -> None: + from litellm.types.proxy.management_endpoints.model_management_endpoints import PatchModelRequest + + row: Final = self._row() + database: Final = self._database(self._team(), row) + actor: Final = UserAPIKeyAuth(user_id="admin", user_role=LitellmUserRoles.PROXY_ADMIN) + + with self._environment(database, row), pytest.raises(ProxyException) as denied: + await patch_model( + row.model_id, + PatchModelRequest(litellm_params_to_remove=("complexity_router_config", "complexity_router_default_model")), + actor, + ) + + assert denied.value.code == "400" + assert "requires" in denied.value.message + database.db.litellm_proxymodeltable.update.assert_not_awaited() + @pytest.mark.asyncio @pytest.mark.parametrize("team_id", [None, "member-team"]) @pytest.mark.parametrize( @@ -8933,7 +8999,14 @@ class TestNonAdminCannotPersistWifFieldsOnModel: mock_prisma.db.litellm_proxymodeltable.update.assert_not_called() @pytest.mark.asyncio - async def test_patch_model_non_admin_cannot_set_wif_field(self): + @pytest.mark.parametrize( + "field,value", + [ + ("anthropic_keycloak_token_url", "https://identity.example.com/token"), + ("chatgpt_auth_file", "/tokens/account-b/auth.json"), + ], + ) + async def test_patch_model_non_admin_cannot_set_wif_field(self, field: str, value: str) -> None: from litellm.proxy.management_endpoints.model_management_endpoints import ( patch_model, ) @@ -8979,13 +9052,13 @@ class TestNonAdminCannotPersistWifFieldsOnModel: model_id="m1", patch_data=updateDeployment( litellm_params=updateLiteLLMParams( - anthropic_keycloak_token_url="https://attacker.example/token", + **{field: value}, ) ), user_api_key_dict=non_admin, ) err = exc_info.value - assert getattr(err, "param", "") == "anthropic_keycloak_token_url" + assert getattr(err, "param", "") == field mock_prisma.db.litellm_proxymodeltable.update.assert_not_called() @pytest.mark.asyncio @@ -9044,7 +9117,14 @@ class TestNonAdminCannotPersistWifFieldsOnModel: mock_prisma.db.litellm_proxymodeltable.update.assert_not_called() @pytest.mark.asyncio - async def test_patch_model_admin_can_set_wif_field(self): + @pytest.mark.parametrize( + "field,value", + [ + ("anthropic_keycloak_token_url", "https://identity.example.com/token"), + ("chatgpt_auth_file", "/tokens/account-b/auth.json"), + ], + ) + async def test_patch_model_admin_can_set_wif_field(self, field: str, value: str) -> None: from litellm.proxy.management_endpoints.model_management_endpoints import ( patch_model, ) @@ -9095,7 +9175,7 @@ class TestNonAdminCannotPersistWifFieldsOnModel: model_id="m1", patch_data=updateDeployment( litellm_params=updateLiteLLMParams( - anthropic_keycloak_token_url="https://keycloak.internal/token", + **{field: value}, ) ), user_api_key_dict=admin, diff --git a/tests/unit/proxy/management_endpoints/test_organization_endpoints.py b/tests/unit/proxy/management_endpoints/test_organization_endpoints.py index a5cae02ea10..16c59aa20b9 100644 --- a/tests/unit/proxy/management_endpoints/test_organization_endpoints.py +++ b/tests/unit/proxy/management_endpoints/test_organization_endpoints.py @@ -1615,3 +1615,68 @@ async def test_delete_organization_is_refused_while_one_of_its_teams_holds_a_ptu prisma_client.db.litellm_teamtable.delete_many.assert_not_called() prisma_client.db.litellm_verificationtoken.delete_many.assert_not_called() prisma_client.db.litellm_organizationtable.delete.assert_not_called() + + +@pytest.mark.asyncio +@pytest.mark.parametrize("budget_duration", ["30d", None]) +async def test_new_organization_schedules_budget_reset_from_duration(monkeypatch, budget_duration): + """/organization/new with an inline budget_duration must write budget_reset_at on the auto-created + budget row, the way team create and /budget/new do, or the org budget never resets and the UI + cannot show the current budget period.""" + from datetime import datetime + + from litellm.proxy._types import LitellmUserRoles, NewOrganizationRequest, UserAPIKeyAuth + from litellm.proxy.management_endpoints.organization_endpoints import new_organization + from litellm.proxy.utils import PrismaClient + + prisma_client = MagicMock() + prisma_client.jsonify_object = MagicMock(side_effect=lambda data: PrismaClient.jsonify_object(prisma_client, data)) + prisma_client.db.litellm_usertable.find_unique = AsyncMock(return_value=None) + prisma_client.db.litellm_budgettable.create = AsyncMock(return_value=MagicMock(budget_id="budget-1")) + prisma_client.db.litellm_organizationtable.create = AsyncMock(return_value={"organization_id": "org-1"}) + monkeypatch.setattr("litellm.proxy.proxy_server.prisma_client", prisma_client) + monkeypatch.setattr("litellm.proxy.proxy_server.llm_router", MagicMock()) + monkeypatch.setattr("litellm.proxy.proxy_server.premium_user", True, raising=False) + + await new_organization( + data=NewOrganizationRequest(organization_alias="org", max_budget=100, budget_duration=budget_duration), + user_api_key_dict=UserAPIKeyAuth(user_id="admin", user_role=LitellmUserRoles.PROXY_ADMIN), + ) + + budget_write = prisma_client.db.litellm_budgettable.create.await_args.kwargs["data"] + if budget_duration is None: + assert "budget_reset_at" not in budget_write, budget_write + return + reset_at = budget_write["budget_reset_at"] + assert isinstance(reset_at, datetime) and reset_at.tzinfo is not None, budget_write + assert budget_write["budget_duration"] == budget_duration + + +def test_organization_info_response_keeps_budget_reset_at(): + """/organization/info must return the budget row's budget_reset_at so the dashboard can show + which budget period the org's spend covers.""" + from datetime import datetime, timezone + + from litellm.proxy._types import LiteLLM_OrganizationTableWithMembers + + reset_at = datetime(2026, 11, 1, tzinfo=timezone.utc) + created_at = datetime(2026, 10, 1, tzinfo=timezone.utc) + response = LiteLLM_OrganizationTableWithMembers( + organization_id="org-1", + organization_alias="org", + budget_id="budget-1", + models=[], + created_by="admin", + updated_by="admin", + created_at=created_at, + updated_at=created_at, + litellm_budget_table={ + "budget_id": "budget-1", + "max_budget": 100.0, + "budget_duration": "30d", + "budget_reset_at": reset_at, + "created_at": created_at, + }, + ) + + assert response.model_dump()["litellm_budget_table"]["budget_reset_at"] == reset_at diff --git a/tests/unit/proxy/management_endpoints/test_ptu_consumption.py b/tests/unit/proxy/management_endpoints/test_ptu_consumption.py index a446afbd809..065ec93dcd0 100644 --- a/tests/unit/proxy/management_endpoints/test_ptu_consumption.py +++ b/tests/unit/proxy/management_endpoints/test_ptu_consumption.py @@ -232,14 +232,10 @@ def test_rows_keyed_by_a_name_a_wildcard_route_serves_are_sized_by_its_shared_de assert attached.results[0].breakdown.model_groups["ptu-chat"].metrics.ptu_hours == pytest.approx(1.0) -@pytest.mark.parametrize( - ("catch_all_routes", "expected_ptu_hours"), [(False, 1.0), (True, 0.0)], ids=["team-wildcard", "behind-catch-all"] -) -def test_a_teams_wildcard_reservation_reads_ptu_hours_only_while_the_router_serves_from_it( - monkeypatch, catch_all_routes, expected_ptu_hours -): - """The router tries the proxy-wide wildcards before a team's own, so a team's `ptu-*` - reservation behind an open `*` route never serves `ptu-chat`, and its row reads no PTU-hours.""" +@pytest.mark.parametrize("catch_all_routes", [False, True], ids=["team-wildcard", "beside-catch-all"]) +def test_a_teams_wildcard_reservation_reads_ptu_hours_even_beside_a_proxy_wide_catch_all(monkeypatch, catch_all_routes): + """The router tries a team's own wildcard before the proxy-wide ones, so a team's `ptu-*` + reservation serves `ptu-chat` whether or not an open `*` route exists, and its row reads its PTU-hours.""" monkeypatch.setenv("LITELLM_ENABLE_PTU_COST_ATTRIBUTION", "True") reservation: Final = { "model_name": "ptu-team-r", @@ -264,9 +260,7 @@ def test_a_teams_wildcard_reservation_reads_ptu_hours_only_while_the_router_serv attached: Final = with_ptu_consumption(_response(_day("2026-09-23", {"ptu-chat": one_hour})), router, "team-r") - assert attached.results[0].breakdown.model_groups["ptu-chat"].metrics.ptu_hours == pytest.approx( - expected_ptu_hours - ) + assert attached.results[0].breakdown.model_groups["ptu-chat"].metrics.ptu_hours == pytest.approx(1.0) def _mixed_ptu_router() -> Router: diff --git a/tests/unit/proxy/management_endpoints/test_ptu_model_settings.py b/tests/unit/proxy/management_endpoints/test_ptu_model_settings.py index a319797a618..efb84ee8f3a 100644 --- a/tests/unit/proxy/management_endpoints/test_ptu_model_settings.py +++ b/tests/unit/proxy/management_endpoints/test_ptu_model_settings.py @@ -40,6 +40,7 @@ from litellm.proxy.management_endpoints.model_management_endpoints import ( from litellm.proxy.spend_tracking.ptu_feature_flag import PTU_COST_ATTRIBUTION_ENV_VAR from litellm.repositories.chunked_in import IN_LIST_CHUNK_SIZE from litellm.router import Router +from litellm.types.proxy.management_endpoints.model_management_endpoints import PatchModelRequest from litellm.types.router import ( SPECIAL_MODEL_INFO_PARAMS, Deployment, @@ -1205,6 +1206,80 @@ class TestPtuDeploymentsAreNotBilledPerToken: for blob in ("model_info", "litellm_params"): assert json.loads(written[blob])["input_cost_per_token"] == 0, blob + @pytest.mark.parametrize("field,activating", [ + ("input_cost_per_token", False), ("cache_read_input_token_cost", False), + ("input_cost_per_second", False), ("tiered_pricing", False), ("search_context_cost_per_query", False), + ("input_cost_per_token", True), ("cache_read_input_token_cost", True), + ("tiered_pricing", True), ("search_context_cost_per_query", True), + ]) + def test_removing_ptu_managed_pricing_is_rejected(self, field: str, activating: bool) -> None: + original: Final = _deployment_without_ptu() if activating else _deployment_with_stored_ptu() + configured: Final = original.model_copy(update={ + "litellm_params": original.litellm_params.model_copy(update={"input_cost_per_second": 0.0}), + }) + with pytest.raises(HTTPException) as exc: + update_db_model( + db_model=configured if activating else _ptu_priced_deployment(configured), + updated_patch=PatchModelRequest( + litellm_params_to_remove=(field,), + model_info=_deployment_with_stored_ptu().model_info if activating else None, + ), + ) + assert exc.value.status_code == 400 + assert field in exc.value.detail + assert "ptu_count and cost_per_ptu_per_hour" in exc.value.detail + + @pytest.mark.parametrize("mode,field", [ + ("extra", "temperature"), ("disabled", "input_cost_per_token"), + ("disabled", "input_cost_per_second"), ("cleared", "input_cost_per_token"), + ("cleared", "input_cost_per_second"), ("activating", "input_cost_per_second"), + ("ordinary", "input_cost_per_second"), + ("ordinary", "input_cost_per_token_above_123k_tokens"), + ("ordinary", "regional_endpoint_uplift_multiplier"), + ]) + def test_allowed_ptu_removals_stay_absent_after_another_save( + self, monkeypatch: pytest.MonkeyPatch, mode: str, field: str + ) -> None: + original: Final = ( + _deployment_without_ptu() if mode in ("activating", "ordinary") + else _ptu_priced_deployment(_deployment_with_stored_ptu()) + ) + rate: Final = 0.5 if mode in ("activating", "ordinary") else 0.0 + price_field: Final = field if mode == "ordinary" else "input_cost_per_second" + configured: Final = original.model_copy(update={ + "litellm_params": original.litellm_params.model_copy(update={ + "temperature": 0.4, price_field: rate, + }), + "model_info": original.model_info.model_copy(update={price_field: rate}), + }) + if mode == "disabled": + monkeypatch.delenv(PTU_COST_ATTRIBUTION_ENV_VAR) + incoming_info: Final = ( + ModelInfo(ptu_count=None, cost_per_ptu_per_hour=None) if mode == "cleared" + else _deployment_with_stored_ptu().model_info if mode == "activating" else ModelInfo() + ) + patch: Final = PatchModelRequest( + litellm_params_to_remove=(field,), + model_info=incoming_info.model_copy(update={price_field: rate}), + ) + written: Final = update_db_model(db_model=configured, updated_patch=patch) + assert json.loads(written["model_info"]).get("ptu_count") == ( + None if mode in ("cleared", "ordinary") else 15 + ) + reloaded: Final = Deployment.model_validate({ + "model_name": written["model_name"], "litellm_params": json.loads(written["litellm_params"]), + "model_info": json.loads(written["model_info"]), + }) + saved_again: Final = update_db_model( + db_model=reloaded, updated_patch=updateDeployment( + model_name="renamed", model_info=ModelInfo.model_validate({price_field: rate}), + ) + ) + retried: Final = update_db_model(db_model=reloaded, updated_patch=patch) + for result in (written, saved_again, retried): + assert field not in json.loads(result["litellm_params"]) + assert field not in json.loads(result["model_info"]) + def test_a_patch_pricing_a_ptu_deployment_is_refused(self): with pytest.raises(HTTPException) as exc: update_db_model( diff --git a/tests/unit/proxy/management_endpoints/test_saml_sso.py b/tests/unit/proxy/management_endpoints/test_saml_sso.py index 181c5e65dae..ff2117ea533 100644 --- a/tests/unit/proxy/management_endpoints/test_saml_sso.py +++ b/tests/unit/proxy/management_endpoints/test_saml_sso.py @@ -31,7 +31,6 @@ from starlette.datastructures import URL from litellm.caching.dual_cache import DualCache from litellm.caching.in_memory_cache import InMemoryCache from litellm.caching.redis_cache import RedisCache -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import SSOIdentityAssertion from litellm.proxy._types import LitellmUserRoles from litellm.proxy.management_endpoints.sso.saml_sso import ( _SAML_AUTHN_REQUEST_CACHE_PREFIX, @@ -42,6 +41,7 @@ from litellm.proxy.management_endpoints.sso.saml_sso import ( SAMLAuthHandler, ) from litellm.proxy.management_endpoints.types import CustomOpenID +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import SSOIdentityAssertion def _shared_cache(store: InMemoryCache | None = None) -> DualCache: diff --git a/tests/unit/proxy/management_endpoints/test_team_endpoints.py b/tests/unit/proxy/management_endpoints/test_team_endpoints.py index 37028558af3..f727448f3ac 100644 --- a/tests/unit/proxy/management_endpoints/test_team_endpoints.py +++ b/tests/unit/proxy/management_endpoints/test_team_endpoints.py @@ -54,6 +54,8 @@ from litellm.proxy.management_endpoints.team_endpoints import ( _LOCK_DELETED_TEAM_MEMBERS_SQL, _STRIP_DELETED_TEAMS_FROM_USERS_SQL, DeletedTeams, + _enrich_team_list_with_caller_membership, + _TeamListCallerIdentity, GetTeamMemberPermissionsResponse, UpdateTeamMemberPermissionsRequest, _build_team_list_where_conditions, @@ -91,6 +93,8 @@ from litellm.router import Router from litellm.types.proxy.management_endpoints.team_endpoints import ( BulkTeamMemberAddRequest, BulkTeamMemberAddResponse, + TeamListCallerMembership, + TeamListItem, TeamMemberAddResult, ) from litellm.types.utils import StandardAuditLogPayload @@ -4172,6 +4176,7 @@ async def test_list_team_v2_security_check_non_admin_user_own_teams(): ] mock_db.litellm_teamtable.find_many = AsyncMock(return_value=mock_teams) mock_db.litellm_teamtable.count = AsyncMock(return_value=2) + mock_db.litellm_teammembership.find_many = AsyncMock(return_value=[]) mock_db.litellm_verificationtoken.group_by = AsyncMock(return_value=[]) with patch( @@ -4191,9 +4196,8 @@ async def test_list_team_v2_security_check_non_admin_user_own_teams(): ) # Should return results without error - assert "teams" in result - assert "total" in result - assert result["total"] == 2 + assert len(result.teams) == 2 + assert result.total == 2 @pytest.mark.asyncio @@ -4229,6 +4233,7 @@ async def test_list_team_v2_security_check_admin_user(): ] mock_db.litellm_teamtable.find_many = AsyncMock(return_value=mock_teams) mock_db.litellm_teamtable.count = AsyncMock(return_value=2) + mock_db.litellm_teammembership.find_many = AsyncMock(return_value=[]) mock_db.litellm_verificationtoken.group_by = AsyncMock(return_value=[]) # Should NOT raise an exception @@ -4242,9 +4247,8 @@ async def test_list_team_v2_security_check_admin_user(): ) # Should return results without error - assert "teams" in result - assert "total" in result - assert result["total"] == 2 + assert len(result.teams) == 2 + assert result.total == 2 @pytest.mark.asyncio @@ -4310,10 +4314,8 @@ async def test_list_team_v2_with_status_deleted(): mock_db.litellm_teamtable.count.assert_not_called() # Should return results without error - assert "teams" in result - assert "total" in result - assert result["total"] == 2 - assert len(result["teams"]) == 2 + assert len(result.teams) == 2 + assert result.total == 2 @pytest.mark.asyncio @@ -4372,6 +4374,7 @@ async def test_list_team_v2_includes_litellm_model_table(): side_effect=lambda **kw: [_team_row("team_1", kw.get("include"))] ) mock_db.litellm_teamtable.count = AsyncMock(return_value=1) + mock_db.litellm_teammembership.find_many = AsyncMock(return_value=[]) mock_db.litellm_verificationtoken.group_by = AsyncMock(return_value=[]) result = await list_team_v2( @@ -4383,8 +4386,8 @@ async def test_list_team_v2_includes_litellm_model_table(): status=None, ) - assert result["teams"][0].litellm_model_table is not None - assert result["teams"][0].litellm_model_table.model_aliases == {"my-fast-model": "fake-model"} + assert result.teams[0].litellm_model_table is not None + assert result.teams[0].litellm_model_table.model_aliases == {"my-fast-model": "fake-model"} mock_db.litellm_deletedteamtable.find_many = AsyncMock( side_effect=lambda **kw: [_team_row("team_2", kw.get("include"))] @@ -4465,6 +4468,7 @@ async def test_list_team_v2_org_admin_sees_org_teams(): } mock_db.litellm_teamtable.find_many = AsyncMock(return_value=[mock_team]) mock_db.litellm_teamtable.count = AsyncMock(return_value=1) + mock_db.litellm_teammembership.find_many = AsyncMock(return_value=[]) mock_db.litellm_verificationtoken.group_by = AsyncMock(return_value=[]) mock_db.litellm_usertable.find_unique = AsyncMock(return_value=mock_user) @@ -4482,9 +4486,9 @@ async def test_list_team_v2_org_admin_sees_org_teams(): status=None, ) - assert result["total"] == 1 - assert len(result["teams"]) == 1 - assert result["teams"][0].members_count == 1 + assert result.total == 1 + assert len(result.teams) == 1 + assert result.teams[0].members_count == 1 # Verify org-scoped where clause where = mock_db.litellm_teamtable.find_many.call_args.kwargs["where"] @@ -4565,6 +4569,7 @@ async def test_list_team_v2_org_admin_own_user_id_sees_all_org_teams(): return_value=[mock_team_1, mock_team_2] ) mock_db.litellm_teamtable.count = AsyncMock(return_value=2) + mock_db.litellm_teammembership.find_many = AsyncMock(return_value=[]) mock_db.litellm_verificationtoken.group_by = AsyncMock(return_value=[]) mock_db.litellm_usertable.find_unique = AsyncMock(return_value=mock_user) @@ -4583,8 +4588,8 @@ async def test_list_team_v2_org_admin_own_user_id_sees_all_org_teams(): status=None, ) - assert result["total"] == 2 - assert len(result["teams"]) == 2 + assert result.total == 2 + assert len(result.teams) == 2 # Verify the where clause scopes by org OR own membership — no # top-level team_id filter that would hide org teams they aren't in @@ -4689,6 +4694,7 @@ async def test_list_team_v2_org_admin_own_query_keeps_memberships_in_other_orgs( prisma_client = MagicMock() prisma_client.db.litellm_teamtable.find_many = AsyncMock(side_effect=find_many) prisma_client.db.litellm_teamtable.count = AsyncMock(side_effect=count) + prisma_client.db.litellm_teammembership.find_many = AsyncMock(return_value=[]) prisma_client.db.litellm_verificationtoken.group_by = AsyncMock(return_value=[]) prisma_client.writer_db.litellm_usertable.find_unique = AsyncMock( return_value=LiteLLM_UserTable( @@ -4721,8 +4727,8 @@ async def test_list_team_v2_org_admin_own_query_keeps_memberships_in_other_orgs( sort_order="asc", status=None, ) - assert result["total"] == len(result["teams"]) - return [t.team_id for t in result["teams"]] + assert result.total == len(result.teams) + return [t.team_id for t in result.teams] own_view = ["team_in_org_A", "other_team_in_org_A", "team_in_org_B"] assert await list_teams("org_admin_user") == own_view @@ -4950,6 +4956,7 @@ async def test_list_team_v2_org_admin_with_user_id_returns_user_teams(): } mock_db.litellm_teamtable.find_many = AsyncMock(return_value=[mock_team]) mock_db.litellm_teamtable.count = AsyncMock(return_value=1) + mock_db.litellm_teammembership.find_many = AsyncMock(return_value=[]) mock_db.litellm_verificationtoken.group_by = AsyncMock(return_value=[]) result = await list_team_v2( @@ -4966,7 +4973,7 @@ async def test_list_team_v2_org_admin_with_user_id_returns_user_teams(): status=None, ) - assert result["total"] == 1 + assert result.total == 1 # Verify the where clause filters by user's teams AND org scope where = mock_db.litellm_teamtable.find_many.call_args.kwargs["where"] @@ -5219,6 +5226,7 @@ async def test_list_team_v2_populates_keys_count(): mock_db.litellm_teamtable.find_many = AsyncMock(return_value=[team_a, team_b]) mock_db.litellm_teamtable.count = AsyncMock(return_value=2) + mock_db.litellm_teammembership.find_many = AsyncMock(return_value=[]) mock_db.litellm_verificationtoken.group_by = AsyncMock( return_value=[ {"team_id": "team_a", "_count": {"team_id": 3}}, @@ -5235,16 +5243,391 @@ async def test_list_team_v2_populates_keys_count(): status=None, ) - assert result["total"] == 2 - by_id = {t.team_id: t for t in result["teams"]} + assert result.total == 2 + by_id = {t.team_id: t for t in result.teams} assert by_id["team_a"].keys_count == 3 assert by_id["team_b"].keys_count == 0 - # The aggregate is one batched query, filtered by the page's team IDs. group_by_kwargs = mock_db.litellm_verificationtoken.group_by.call_args.kwargs assert group_by_kwargs["by"] == ["team_id"] assert group_by_kwargs["where"] == {"team_id": {"in": ["team_a", "team_b"]}} assert group_by_kwargs["count"] == {"team_id": True} + membership_where: Final = mock_db.litellm_teammembership.find_many.call_args.kwargs["where"] + assert membership_where == { + "team_id": {"in": ("team_a", "team_b")}, + "user_id": "admin_user_123", + } + + +def _team_list_prisma( + membership_rows: Sequence[LiteLLM_TeamMembership], + budget_rows: Sequence[LiteLLM_BudgetTableFull], +) -> tuple[MagicMock, AsyncMock, AsyncMock]: + prisma_client: Final = MagicMock() + membership_query: Final = AsyncMock(return_value=tuple(membership_rows)) + budget_query: Final = AsyncMock(return_value=tuple(budget_rows)) + prisma_client.db.litellm_teammembership.find_many = membership_query + prisma_client.db.litellm_budgettable.find_many = budget_query + return prisma_client, membership_query, budget_query + + +def _team_list_member( + team_id: str, + user_id: str = "caller", + default_budget_id: str | None = None, +) -> TeamListItem: + metadata: Final = {"team_member_budget_id": default_budget_id} if default_budget_id is not None else None + return TeamListItem( + team_id=team_id, + metadata=metadata, + members_with_roles=[Member(user_id=user_id, role="user")], + ) + + +def _team_list_caller_identity( + user_id: str | None = "caller", + user_email: str | None = None, +) -> _TeamListCallerIdentity: + return _TeamListCallerIdentity(user_id=user_id, user_email=user_email) + + +def _budget_table( + budget_id: str, + max_budget: float | None, + budget_reset_at: datetime | None = None, + temp_budget_increase: float | None = None, + temp_budget_expiry: datetime | None = None, +) -> LiteLLM_BudgetTableFull: + return LiteLLM_BudgetTableFull( + budget_id=budget_id, + max_budget=max_budget, + budget_reset_at=budget_reset_at, + created_at=datetime(2026, 1, 1, tzinfo=timezone.utc), + temp_budget_increase=temp_budget_increase, + temp_budget_expiry=temp_budget_expiry, + ) + + +@pytest.mark.asyncio +async def test_team_list_caller_membership_uses_member_spend_budget_and_reset_date() -> None: + reset_at: Final = datetime(2026, 10, 20, tzinfo=timezone.utc) + member_budget: Final = _budget_table("member-budget", 100, reset_at) + membership: Final = LiteLLM_TeamMembership( + user_id="caller", + team_id="team-a", + spend=50, + litellm_budget_table=member_budget, + ) + prisma_client, _, budget_query = _team_list_prisma([membership], []) + + teams: Final = await _enrich_team_list_with_caller_membership( + prisma_client, + [_team_list_member("team-a")], + _team_list_caller_identity(), + datetime(2026, 10, 1, tzinfo=timezone.utc), + ) + + assert teams[0].caller_membership == TeamListCallerMembership( + spend=50, + max_budget=100, + budget_reset_at=reset_at, + ) + budget_query.assert_not_awaited() + + +@pytest.mark.asyncio +async def test_team_list_caller_membership_includes_roster_members_without_membership_rows() -> None: + reset_at: Final = datetime(2026, 10, 20, tzinfo=timezone.utc) + prisma_client, membership_query, budget_query = _team_list_prisma( + (), + [_budget_table("team-budget", 50, reset_at)], + ) + + teams: Final = await _enrich_team_list_with_caller_membership( + prisma_client, + [_team_list_member("team-a", default_budget_id="team-budget")], + _team_list_caller_identity(), + datetime(2026, 10, 1, tzinfo=timezone.utc), + ) + + assert teams[0].caller_membership == TeamListCallerMembership( + spend=0.0, + max_budget=50, + budget_reset_at=None, + ) + membership_query.assert_awaited_once() + budget_query.assert_awaited_once() + + +@pytest.mark.asyncio +async def test_team_list_caller_membership_matches_email_only_roster_member() -> None: + reset_at: Final = datetime(2026, 10, 20, tzinfo=timezone.utc) + team: Final = TeamListItem( + team_id="team-a", + metadata={"team_member_budget_id": "team-budget"}, + members_with_roles=[Member(user_id=None, user_email="caller@x.com", role="user")], + ) + prisma_client, membership_query, budget_query = _team_list_prisma( + (), + [_budget_table("team-budget", 50, reset_at)], + ) + + teams: Final = await _enrich_team_list_with_caller_membership( + prisma_client, + [team], + _team_list_caller_identity(user_email="caller@x.com"), + datetime(2026, 10, 1, tzinfo=timezone.utc), + ) + + assert teams[0].caller_membership == TeamListCallerMembership( + spend=0.0, + max_budget=50, + budget_reset_at=None, + ) + membership_query.assert_awaited_once() + budget_query.assert_awaited_once() + + +@pytest.mark.parametrize("caller_user_email", ("other@x.com", None)) +@pytest.mark.asyncio +async def test_team_list_caller_membership_ignores_email_only_roster_member_without_matching_email( + caller_user_email: str | None, +) -> None: + team: Final = TeamListItem( + team_id="team-a", + metadata={"team_member_budget_id": "team-budget"}, + members_with_roles=[Member(user_id=None, user_email="caller@x.com", role="user")], + ) + prisma_client, membership_query, budget_query = _team_list_prisma( + (), + [_budget_table("team-budget", 50)], + ) + + teams: Final = await _enrich_team_list_with_caller_membership( + prisma_client, + [team], + _team_list_caller_identity(user_email=caller_user_email), + datetime(2026, 10, 1, tzinfo=timezone.utc), + ) + + assert teams[0].caller_membership is None + membership_query.assert_awaited_once() + budget_query.assert_not_awaited() + + +@pytest.mark.asyncio +async def test_team_list_caller_membership_uses_team_default_without_member_reset_date() -> None: + reset_at: Final = datetime(2026, 10, 20, tzinfo=timezone.utc) + membership: Final = LiteLLM_TeamMembership(user_id="caller", team_id="team-a", spend=12) + prisma_client, _, budget_query = _team_list_prisma( + [membership], + [_budget_table("team-budget", 50, reset_at)], + ) + + teams: Final = await _enrich_team_list_with_caller_membership( + prisma_client, + [_team_list_member("team-a", default_budget_id="team-budget")], + _team_list_caller_identity(), + datetime(2026, 10, 1, tzinfo=timezone.utc), + ) + + assert teams[0].caller_membership == TeamListCallerMembership( + spend=12, + max_budget=50, + budget_reset_at=None, + ) + budget_query.assert_awaited_once() + + +@pytest.mark.asyncio +async def test_team_list_caller_membership_uses_reset_date_from_member_linked_default_budget() -> None: + reset_at: Final = datetime(2026, 10, 20, tzinfo=timezone.utc) + member_budget: Final = _budget_table("team-budget", 50, reset_at) + membership: Final = LiteLLM_TeamMembership( + user_id="caller", + team_id="team-a", + litellm_budget_table=member_budget, + ) + prisma_client, _, budget_query = _team_list_prisma([membership], []) + + teams: Final = await _enrich_team_list_with_caller_membership( + prisma_client, + [_team_list_member("team-a", default_budget_id="team-budget")], + _team_list_caller_identity(), + datetime(2026, 10, 1, tzinfo=timezone.utc), + ) + + assert teams[0].caller_membership == TeamListCallerMembership( + spend=0.0, + max_budget=50, + budget_reset_at=reset_at, + ) + budget_query.assert_not_awaited() + + +@pytest.mark.asyncio +async def test_team_list_caller_membership_ignores_zero_team_default_budget() -> None: + membership: Final = LiteLLM_TeamMembership(user_id="caller", team_id="team-a") + prisma_client, _, _ = _team_list_prisma( + [membership], + [_budget_table("team-budget", 0, datetime(2026, 10, 20, tzinfo=timezone.utc))], + ) + + teams: Final = await _enrich_team_list_with_caller_membership( + prisma_client, + [_team_list_member("team-a", default_budget_id="team-budget")], + _team_list_caller_identity(), + datetime(2026, 10, 1, tzinfo=timezone.utc), + ) + + assert teams[0].caller_membership == TeamListCallerMembership(spend=0.0, max_budget=None, budget_reset_at=None) + + +@pytest.mark.parametrize( + ("expiry", "expected_budget"), + ( + (datetime(2030, 1, 2, tzinfo=timezone.utc), 110), + (datetime(2029, 12, 31, tzinfo=timezone.utc), 100), + ), +) +@pytest.mark.asyncio +async def test_team_list_caller_membership_applies_only_active_temporary_increases( + expiry: datetime, + expected_budget: float, +) -> None: + member_budget: Final = _budget_table( + "member-budget", + 100, + datetime(2030, 2, 1, tzinfo=timezone.utc), + temp_budget_increase=10, + temp_budget_expiry=expiry, + ) + membership: Final = LiteLLM_TeamMembership( + user_id="caller", + team_id="team-a", + litellm_budget_table=member_budget, + ) + prisma_client, _, _ = _team_list_prisma([membership], []) + + teams: Final = await _enrich_team_list_with_caller_membership( + prisma_client, + [_team_list_member("team-a")], + _team_list_caller_identity(), + datetime(2030, 1, 1, tzinfo=timezone.utc), + ) + + assert teams[0].caller_membership is not None + assert teams[0].caller_membership.max_budget == expected_budget + assert teams[0].caller_membership.budget_reset_at == datetime(2030, 2, 1, tzinfo=timezone.utc) + + +@pytest.mark.parametrize( + "member_reset_at", + ( + datetime(2030, 1, 15, tzinfo=timezone.utc), + None, + ), +) +@pytest.mark.asyncio +async def test_team_list_caller_membership_uses_private_row_reset_with_inherited_budget( + member_reset_at: datetime | None, +) -> None: + team_reset_at: Final = datetime(2030, 2, 1, tzinfo=timezone.utc) + member_budget: Final = _budget_table( + "member-budget", + None, + member_reset_at, + temp_budget_increase=10, + temp_budget_expiry=datetime(2030, 1, 2, tzinfo=timezone.utc), + ) + membership: Final = LiteLLM_TeamMembership( + user_id="caller", + team_id="team-a", + litellm_budget_table=member_budget, + ) + prisma_client, _, _ = _team_list_prisma( + [membership], + [_budget_table("team-budget", 50, team_reset_at)], + ) + + teams: Final = await _enrich_team_list_with_caller_membership( + prisma_client, + [_team_list_member("team-a", default_budget_id="team-budget")], + _team_list_caller_identity(), + datetime(2030, 1, 1, tzinfo=timezone.utc), + ) + + assert teams[0].caller_membership == TeamListCallerMembership( + spend=0.0, + max_budget=60, + budget_reset_at=member_reset_at, + ) + + +@pytest.mark.asyncio +async def test_team_list_caller_membership_is_null_for_nonmember_admins() -> None: + prisma_client, membership_query, budget_query = _team_list_prisma([], []) + team: Final = TeamListItem( + team_id="team-a", + metadata={"team_member_budget_id": "team-budget"}, + members_with_roles=[Member(user_id="another-user", role="user")], + ) + + teams: Final = await _enrich_team_list_with_caller_membership( + prisma_client, + [team], + _team_list_caller_identity(), + datetime(2026, 10, 1, tzinfo=timezone.utc), + ) + + assert teams[0].caller_membership is None + membership_query.assert_awaited_once() + budget_query.assert_not_awaited() + + +@pytest.mark.asyncio +async def test_team_list_caller_membership_skips_queries_without_caller_user_id() -> None: + prisma_client, membership_query, budget_query = _team_list_prisma((), ()) + + teams: Final = await _enrich_team_list_with_caller_membership( + prisma_client, + [_team_list_member("team-a")], + _team_list_caller_identity(user_id=None), + datetime(2026, 10, 1, tzinfo=timezone.utc), + ) + + assert teams[0].caller_membership is None + membership_query.assert_not_awaited() + budget_query.assert_not_awaited() + + +@pytest.mark.asyncio +async def test_team_list_caller_membership_batches_page_membership_and_budget_queries() -> None: + memberships: Final = ( + LiteLLM_TeamMembership(user_id="caller", team_id="team-a"), + LiteLLM_TeamMembership(user_id="caller", team_id="team-b"), + ) + prisma_client, membership_query, budget_query = _team_list_prisma( + memberships, + [_budget_table("budget-a", 50), _budget_table("budget-b", 75)], + ) + + teams: Final = await _enrich_team_list_with_caller_membership( + prisma_client, + [ + _team_list_member("team-a", default_budget_id="budget-a"), + _team_list_member("team-b", default_budget_id="budget-b"), + ], + _team_list_caller_identity(), + datetime(2026, 10, 1, tzinfo=timezone.utc), + ) + + assert [team.caller_membership for team in teams] == [ + TeamListCallerMembership(spend=0.0, max_budget=50, budget_reset_at=None), + TeamListCallerMembership(spend=0.0, max_budget=75, budget_reset_at=None), + ] + membership_query.assert_awaited_once() + budget_query.assert_awaited_once() @pytest.mark.asyncio @@ -5282,8 +5665,8 @@ async def test_list_team_v2_keys_count_skipped_for_empty_page(): status=None, ) - assert result["total"] == 0 - assert result["teams"] == [] + assert result.total == 0 + assert result.teams == [] mock_db.litellm_verificationtoken.group_by.assert_not_called() @@ -5332,7 +5715,7 @@ async def test_list_team_v2_keys_count_skipped_for_deleted_status(): status="deleted", ) - assert result["total"] == 1 + assert result.total == 1 mock_db.litellm_verificationtoken.group_by.assert_not_called() @@ -12178,6 +12561,36 @@ async def test_team_member_me_returns_caller_membership(mock_db_client): assert call_kwargs["team_id"] == team_id +@pytest.mark.asyncio +@pytest.mark.parametrize( + "spend, stored_total, reported_total", + [(612.4, 148.1, 612.4), (12.25, 97.8, 97.8)], + ids=["legacy_row_floors_to_cycle_spend", "healthy_row_keeps_its_total"], +) +async def test_team_member_me_reports_total_spend_no_lower_than_cycle_spend( + mock_db_client, spend, stored_total, reported_total +): + from fastapi import Request + + from litellm.proxy.management_endpoints.team_endpoints import team_member_me + + team_id = "team-me-floor" + caller_id = "alice@example.com" + team = _build_team_for_me(team_id, [{"user_id": caller_id, "user_email": None, "role": "user"}]) + membership = _build_membership_for_me(caller_id, team_id, spend=spend).model_copy( + update={"total_spend": stored_total} + ) + p_team, p_membership, p_user = _patch_member_me_helpers(team=team, membership=membership, user=None) + with p_team, p_membership, p_user: + response = await team_member_me( + http_request=MagicMock(spec=Request), + team_id=team_id, + user_api_key_dict=UserAPIKeyAuth(user_role=LitellmUserRoles.INTERNAL_USER, user_id=caller_id), + ) + + assert (response.spend, response.total_spend) == (spend, reported_total) + + @pytest.mark.asyncio async def test_team_member_me_matches_email_only_member(mock_db_client): """ @@ -16225,7 +16638,7 @@ async def test_reset_team_member_spend_fn_success(monkeypatch): litellm_budget_table=LiteLLM_BudgetTable(budget_id="b1", max_budget=50.0), ) mock_prisma_client.db.litellm_teammembership.find_unique = AsyncMock(return_value=membership_row) - mock_prisma_client.db.litellm_teammembership.update = AsyncMock(return_value=membership_row) + mock_prisma_client.db.execute_raw = AsyncMock(return_value=1) monkeypatch.setattr("litellm.proxy.proxy_server.prisma_client", mock_prisma_client) monkeypatch.setattr("litellm.proxy.proxy_server.user_api_key_cache", real_cache) @@ -16248,15 +16661,76 @@ async def test_reset_team_member_spend_fn_success(monkeypatch): assert response["spend"] == 0.0 assert response["previous_spend"] == 10.0 assert response["max_budget"] == 50.0 - mock_prisma_client.db.litellm_teammembership.update.assert_awaited_once_with( - where={"user_id_team_id": {"user_id": "member-1", "team_id": "team-1"}}, - data={"spend": 0.0}, - ) + statement, reset_user_id, reset_team_id, reset_to = mock_prisma_client.db.execute_raw.await_args.args + assert (reset_user_id, reset_team_id, reset_to) == ("member-1", "team-1", 0.0) + assert "total_spend = GREATEST(total_spend, spend)" in statement + assert "spend >= $3" in statement assert await real_cache.async_get_cache(key="team-1_member-1") is None assert await real_cache.async_get_cache(key="team_membership:member-1:team-1") is None assert real_spend_counter_cache.in_memory_cache.get_cache(key="spend:team_member:member-1:team-1") == 0.0 +@pytest.mark.asyncio +async def test_reset_team_member_spend_fn_stale_spend_returns_409_and_keeps_caches(monkeypatch): + """The reset validates reset_to against a spend it read a moment ago. If the row moved + underneath it (a flush landed, another admin reset first) the guarded UPDATE matches no + row, and the endpoint must say so instead of reporting a reset that never happened.""" + from litellm.caching.dual_cache import DualCache + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + + mock_prisma_client = MagicMock() + real_cache = UserApiKeyCache() + await real_cache.async_set_cache(key="team_membership:member-1:team-1", value="cached-membership") + real_spend_counter_cache = DualCache() + real_spend_counter_cache.in_memory_cache.set_cache(key="spend:team_member:member-1:team-1", value=999.0) + + membership_row = LiteLLM_TeamMembership(user_id="member-1", team_id="team-1", spend=10.0) + mock_prisma_client.db.litellm_teammembership.find_unique = AsyncMock(return_value=membership_row) + mock_prisma_client.db.execute_raw = AsyncMock(return_value=0) + + monkeypatch.setattr("litellm.proxy.proxy_server.prisma_client", mock_prisma_client) + monkeypatch.setattr("litellm.proxy.proxy_server.user_api_key_cache", real_cache) + monkeypatch.setattr("litellm.proxy.proxy_server.proxy_logging_obj", MagicMock()) + monkeypatch.setattr("litellm.proxy.proxy_server.spend_counter_cache", real_spend_counter_cache) + + with patch( # test-quality-ok: no live DB here; matches this file's established convention for endpoint-logic unit tests + "litellm.proxy.management_endpoints.team_endpoints.get_team_object", + AsyncMock(return_value=LiteLLM_TeamTable(team_id="team-1")), + ), pytest.raises(HTTPException) as exc_info: + await reset_team_member_spend_fn( + team_id="team-1", + user_id="member-1", + data=ResetSpendRequest(reset_to=5.0), + user_api_key_dict=UserAPIKeyAuth( + user_role=LitellmUserRoles.PROXY_ADMIN, api_key="sk-admin", user_id="admin-user" + ), + ) + + assert exc_info.value.status_code == 409 + assert await real_cache.async_get_cache(key="team_membership:member-1:team-1") == "cached-membership" + assert real_spend_counter_cache.in_memory_cache.get_cache(key="spend:team_member:member-1:team-1") == 999.0 + + +@pytest.mark.asyncio +async def test_get_all_team_memberships_floors_total_spend_at_current_cycle_spend(): + """Rows written before total_spend existed carry their history only in spend. /team/info + and /team/list both read through this helper, so a legacy row reports its lifetime spend + as at least the current cycle, while a healthy row keeps its own total.""" + from litellm.proxy.management_endpoints.team_endpoints import get_all_team_memberships + + legacy_row = MagicMock() + legacy_row.model_dump = lambda: {"user_id": "legacy", "team_id": "team-1", "spend": 612.4, "total_spend": 148.1} + healthy_row = MagicMock() + healthy_row.model_dump = lambda: {"user_id": "healthy", "team_id": "team-1", "spend": 12.25, "total_spend": 97.8} + mock_prisma_client = MagicMock() + mock_prisma_client.db.litellm_teammembership.find_many = AsyncMock(return_value=[legacy_row, healthy_row]) + + legacy, healthy = await get_all_team_memberships(mock_prisma_client, ["team-1"]) + + assert (legacy.spend, legacy.total_spend) == (612.4, 612.4) + assert (healthy.spend, healthy.total_spend) == (12.25, 97.8) + + @pytest.mark.asyncio async def test_reset_team_member_spend_fn_membership_not_found(monkeypatch): mock_prisma_client = MagicMock() @@ -16372,7 +16846,7 @@ async def test_reset_team_member_spend_fn_proxy_admin_can_reset_own_spend(monkey membership_row = LiteLLM_TeamMembership(user_id="admin-user", team_id="team-1", spend=10.0) mock_prisma_client.db.litellm_teammembership.find_unique = AsyncMock(return_value=membership_row) - mock_prisma_client.db.litellm_teammembership.update = AsyncMock(return_value=membership_row) + mock_prisma_client.db.execute_raw = AsyncMock(return_value=1) with patch( # test-quality-ok: no live DB here; matches this file's established convention for endpoint-logic unit tests "litellm.proxy.management_endpoints.team_endpoints.get_team_object", @@ -17611,6 +18085,7 @@ async def test_update_team_team_admin_resending_stored_member_defaults_is_not_an disable_audit_logging_for_mocked_team, ): import contextlib + from litellm.models.budget import LiteLLM_BudgetTable with contextlib.ExitStack() as stack: diff --git a/tests/unit/proxy/management_endpoints/test_ui_sso.py b/tests/unit/proxy/management_endpoints/test_ui_sso.py index e1a939273ae..4135e9be6f6 100644 --- a/tests/unit/proxy/management_endpoints/test_ui_sso.py +++ b/tests/unit/proxy/management_endpoints/test_ui_sso.py @@ -10,9 +10,9 @@ from unittest.mock import AsyncMock, MagicMock, patch import httpx import pytest -from pydantic import SecretStr import respx from fastapi import HTTPException, Request +from pydantic import SecretStr import litellm from litellm._uuid import uuid @@ -4119,7 +4119,7 @@ class TestCLIKeyRegenerationFlow: cli_state = f"{LITELLM_CLI_SESSION_TOKEN_PREFIX}:cli-new-session-key-456" # Mock the CLI callback and required proxy server components - from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( + from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( assertion_from_sso_login, ) @@ -9625,7 +9625,7 @@ async def test_redirect_from_openid_persists_assertion_under_canonical_user_id() """The browser funnel persists the captured assertion AFTER canonical user resolution, keyed by the user_id admission will later resolve (the key-generation response user_id), not the raw IdP subject.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( + from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( assertion_from_sso_login, ) @@ -9696,7 +9696,7 @@ async def test_redirect_from_openid_persists_the_login_exchanged_assertion(): """A server with ``id_jag_subject_source: refresh_token`` needs the refresh token the login assertion was exchanged for, so the funnel persists what the login-time exchange returns, not the raw capture.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( + from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( assertion_from_sso_login, ) @@ -9921,12 +9921,12 @@ async def test_microsoft_login_asks_for_offline_access_only_while_an_id_jag_serv @pytest.mark.asyncio async def test_cli_completion_persists_assertion_under_db_user_id(): """The CLI funnel persists the captured assertion under the DB-resolved user_id.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( - assertion_from_sso_login, - ) from litellm.proxy.management_endpoints.ui_sso import ( _complete_cli_sso_callback_session, ) + from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( + assertion_from_sso_login, + ) assertion = assertion_from_sso_login(_ema_id_token(), None) assert assertion is not None @@ -10041,12 +10041,12 @@ async def test_a_capturing_provider_that_returned_no_id_token_still_warns(monkey @pytest.mark.asyncio async def test_no_warning_when_the_assertion_was_captured(monkeypatch, caplog): - from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( - assertion_from_sso_login, - ) from litellm.proxy.management_endpoints.ui_sso import ( warn_if_id_jag_assertion_uncaptured, ) + from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( + assertion_from_sso_login, + ) monkeypatch.setenv("GOOGLE_CLIENT_ID", "cid") assertion = assertion_from_sso_login(_ema_id_token(), None) diff --git a/tests/unit/proxy/management_helpers/test_object_permission_utils.py b/tests/unit/proxy/management_helpers/test_object_permission_utils.py index 33557713162..5814d8d2a97 100644 --- a/tests/unit/proxy/management_helpers/test_object_permission_utils.py +++ b/tests/unit/proxy/management_helpers/test_object_permission_utils.py @@ -19,9 +19,9 @@ from litellm.proxy.management_helpers.object_permission_utils import ( _extract_requested_mcp_access_groups, _extract_requested_mcp_server_ids, _resolve_team_allowed_mcp_servers, - set_object_permission, enforce_all_proxy_mcp_servers_grant_is_admin_only, prepare_object_permission_upsert, + set_object_permission, validate_key_mcp_servers_against_team, validate_key_search_tools_against_team, validate_key_vector_stores_against_team, @@ -277,7 +277,7 @@ def _make_mock_mcp_manager(*existing_ids: str, servers=None): return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -291,7 +291,7 @@ async def test_validate_no_object_permission(mock_access_groups, mock_allow_all) @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("server-1", "server-2"), ) @patch( @@ -299,7 +299,7 @@ async def test_validate_no_object_permission(mock_access_groups, mock_allow_all) return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -316,7 +316,7 @@ async def test_validate_key_servers_within_team_scope( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("server-1", "server-outside"), ) @patch( @@ -324,7 +324,7 @@ async def test_validate_key_servers_within_team_scope( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -344,7 +344,7 @@ async def test_validate_key_servers_outside_team_scope_raises( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("server-1", "global-server"), ) @patch( @@ -352,7 +352,7 @@ async def test_validate_key_servers_outside_team_scope_raises( return_value={"global-server"}, ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -369,7 +369,7 @@ async def test_validate_allow_all_keys_servers_always_allowed( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("global-server"), ) @patch( @@ -377,7 +377,7 @@ async def test_validate_allow_all_keys_servers_always_allowed( return_value={"global-server"}, ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -391,7 +391,7 @@ async def test_validate_no_team_only_allow_all_keys(mock_access_groups, mock_all @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("private-server"), ) @patch( @@ -399,7 +399,7 @@ async def test_validate_no_team_only_allow_all_keys(mock_access_groups, mock_all return_value={"global-server"}, ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -418,7 +418,7 @@ async def test_validate_no_team_non_global_server_raises( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("private-server"), ) @patch( @@ -426,7 +426,7 @@ async def test_validate_no_team_non_global_server_raises( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -444,7 +444,7 @@ async def test_validate_no_team_proxy_admin_can_assign_private_server( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("private-server"), ) @patch( @@ -452,7 +452,7 @@ async def test_validate_no_team_proxy_admin_can_assign_private_server( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -475,7 +475,7 @@ async def test_validate_no_team_non_admin_private_server_still_raises( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -493,7 +493,7 @@ async def test_validate_no_team_proxy_admin_can_assign_access_group( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("server-1", "server-outside"), ) @patch( @@ -501,7 +501,7 @@ async def test_validate_no_team_proxy_admin_can_assign_access_group( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -522,7 +522,7 @@ async def test_validate_proxy_admin_still_bounded_by_team_scope( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("some-server"), ) @patch( @@ -530,7 +530,7 @@ async def test_validate_proxy_admin_still_bounded_by_team_scope( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -569,7 +569,7 @@ def unified_mcp_prisma() -> Iterator[MagicMock]: manager.get_allow_all_keys_server_ids.return_value = [] with ( patch( # test-quality-ok: management helpers read this module singleton without a registry injection seam - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=manager, ), patch( # test-quality-ok: unified group resolver obtains its cache from the proxy singleton @@ -675,7 +675,7 @@ async def test_team_unified_access_group_without_servers_preserves_direct_grants @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("server-outside"), ) @patch( @@ -683,7 +683,7 @@ async def test_team_unified_access_group_without_servers_preserves_direct_grants return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -703,7 +703,7 @@ async def test_validate_tool_permissions_validated_against_team( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager(), # empty registry — all IDs are stale ) @patch( @@ -711,7 +711,7 @@ async def test_validate_tool_permissions_validated_against_team( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -735,7 +735,7 @@ async def test_validate_stale_mcp_server_ids_are_silently_dropped( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager(), # empty registry — all IDs are stale ) @patch( @@ -743,7 +743,7 @@ async def test_validate_stale_mcp_server_ids_are_silently_dropped( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -765,7 +765,7 @@ async def test_validate_stale_ids_in_mcp_tool_permissions_silently_dropped( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager(), # empty registry — all IDs are stale ) @patch( @@ -773,7 +773,7 @@ async def test_validate_stale_ids_in_mcp_tool_permissions_silently_dropped( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -791,7 +791,7 @@ async def test_validate_stale_mcp_server_ids_are_removed_from_object_permission( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager( "team-server", servers=[ @@ -808,7 +808,7 @@ async def test_validate_stale_mcp_server_ids_are_removed_from_object_permission( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -827,7 +827,7 @@ async def test_validate_mcp_server_alias_outside_team_scope_raises( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager( servers=[ _make_mock_mcp_server( @@ -843,7 +843,7 @@ async def test_validate_mcp_server_alias_outside_team_scope_raises( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -878,7 +878,7 @@ def test_alias_grant_expands_on_other_region_after_save(): _drop_stale_object_permission_mcp_servers(object_permission, {"github-mcp": {"west-id"}}) assert object_permission["mcp_servers"] == ["github-mcp"] - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager expand = MCPServerManager.expand_permission_list assert expand(west_mgr, object_permission["mcp_servers"]) == ["west-id"] @@ -887,7 +887,7 @@ def test_alias_grant_expands_on_other_region_after_save(): @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager(), ) @patch( @@ -895,7 +895,7 @@ def test_alias_grant_expands_on_other_region_after_save(): return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -929,7 +929,7 @@ async def test_validate_db_mcp_server_alias_outside_team_scope_raises_when_regis return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -950,7 +950,7 @@ async def test_validate_access_groups_within_team_scope( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -974,7 +974,7 @@ async def test_validate_access_groups_outside_team_scope_raises( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -997,7 +997,7 @@ async def test_validate_access_groups_no_team_raises( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=["server-from-group"], ) @@ -1018,7 +1018,7 @@ async def test_validate_team_access_groups_resolve_to_servers( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -1037,7 +1037,7 @@ async def test_resolve_team_allowed_mcp_servers_string_tool_permissions( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -1059,7 +1059,7 @@ async def test_resolve_team_allowed_mcp_servers_dict_tool_permissions( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -1081,7 +1081,7 @@ async def test_resolve_team_all_proxy_sentinel_resolves_dynamically(mock_access_ team_perm.mcp_tool_permissions = {} with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_mgr, ): assert await _resolve_team_allowed_mcp_servers(team_perm) == {"srv-x", "srv-y"} @@ -1096,7 +1096,7 @@ async def test_resolve_team_all_proxy_sentinel_resolves_dynamically(mock_access_ @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("srv-x", "srv-y", "srv-z"), ) @patch( @@ -1104,7 +1104,7 @@ async def test_resolve_team_all_proxy_sentinel_resolves_dynamically(mock_access_ return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -1127,7 +1127,7 @@ async def test_validate_key_scoped_to_server_added_after_team_all_proxy( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("srv-x", "srv-z"), ) @patch( @@ -1135,7 +1135,7 @@ async def test_validate_key_scoped_to_server_added_after_team_all_proxy( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -1278,7 +1278,7 @@ async def test_validate_search_tools_raises_when_not_subset(): return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -1301,7 +1301,7 @@ async def test_personal_non_admin_cannot_assign_mcp_toolsets( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -1403,7 +1403,7 @@ def _make_grandfather_fixtures(mcp_servers=None, mcp_tool_permissions=None): def _patch_grandfather_env(monkeypatch, mock_mgr): monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_mgr, ) monkeypatch.setattr( diff --git a/tests/unit/proxy/mcp_server/__init__.py b/tests/unit/proxy/mcp_server/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/unit/proxy/mcp_server/auth/__init__.py b/tests/unit/proxy/mcp_server/auth/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/unit/proxy/_experimental/mcp_server/auth/test_managed_agent_access.py b/tests/unit/proxy/mcp_server/auth/test_managed_agent_access.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/auth/test_managed_agent_access.py rename to tests/unit/proxy/mcp_server/auth/test_managed_agent_access.py index 1524aad5b66..fa4f80a2b96 100644 --- a/tests/unit/proxy/_experimental/mcp_server/auth/test_managed_agent_access.py +++ b/tests/unit/proxy/mcp_server/auth/test_managed_agent_access.py @@ -5,10 +5,10 @@ import pytest from fastapi import HTTPException from litellm.proxy import proxy_server -from litellm.proxy._experimental.mcp_server import mcp_server_manager -from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable, LiteLLM_UserTable, UserAPIKeyAuth from litellm.proxy.auth import auth_checks +from litellm.proxy.mcp_server import mcp_server_manager +from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler from litellm.types.agents import AgentResponse from litellm.types.proxy.agent_identity import ManagedAgentContext @@ -219,7 +219,7 @@ async def test_autonomous_agent_toolset_and_access_group_revocations_bind_on_the writer revokes a tool or drops the server from the group, the next managed request must be denied even though the legacy cache still holds the warm grant and the replica still shows the old rows""" from litellm.caching.caching import DualCache - from litellm.proxy._experimental.mcp_server import toolset_db + from litellm.proxy.mcp_server import toolset_db warm_toolset: Final = _toolset_row("slack", "read") list_toolsets: Final = AsyncMock(return_value=[warm_toolset]) @@ -285,7 +285,7 @@ async def test_delegated_mcp_uses_explicit_team_grants_even_for_dashboard_admins ) for name in ("slack", "linear") } - from litellm.proxy._experimental.mcp_server import db + from litellm.proxy.mcp_server import db monkeypatch.setattr( db, @@ -322,7 +322,7 @@ async def test_delegated_mcp_uses_explicit_team_grants_even_for_dashboard_admins async def test_explicit_grants_never_fall_back_to_open_servers_on_resolution_failure( monkeypatch: pytest.MonkeyPatch, ) -> None: - from litellm.proxy._experimental.mcp_server import db + from litellm.proxy.mcp_server import db from litellm.types.mcp_server.mcp_server_manager import MCPServer manager: Final = mcp_server_manager.global_mcp_server_manager @@ -339,7 +339,7 @@ async def test_explicit_grants_never_fall_back_to_open_servers_on_resolution_fai @pytest.mark.asyncio async def test_absent_agent_policy_and_missing_delegated_subject_grant_no_servers() -> None: - from litellm.proxy._experimental.mcp_server.auth.managed_agent_access import managed_agent_servers + from litellm.proxy.mcp_server.auth.managed_agent_access import managed_agent_servers assert await managed_agent_servers(UserAPIKeyAuth()) == () auth: Final = actor(None, delegated=True) @@ -367,8 +367,8 @@ async def test_tool_policy_outage_after_server_admission_fails_closed(monkeypatc async def test_manager_preserves_managed_server_grants_across_open_channels( monkeypatch: pytest.MonkeyPatch, role: str | None, scoped: bool ) -> None: - from litellm.proxy._experimental.mcp_server import db - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess + from litellm.proxy.mcp_server import db + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess from litellm.types.mcp_server.mcp_server_manager import MCPServer manager: Final = mcp_server_manager.global_mcp_server_manager diff --git a/tests/unit/proxy/_experimental/mcp_server/auth/test_token_endpoint_auth.py b/tests/unit/proxy/mcp_server/auth/test_token_endpoint_auth.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/auth/test_token_endpoint_auth.py rename to tests/unit/proxy/mcp_server/auth/test_token_endpoint_auth.py index 47b5fac23eb..c65e7d4db26 100644 --- a/tests/unit/proxy/_experimental/mcp_server/auth/test_token_endpoint_auth.py +++ b/tests/unit/proxy/mcp_server/auth/test_token_endpoint_auth.py @@ -4,7 +4,7 @@ import base64 import pytest -from litellm.proxy._experimental.mcp_server.auth.token_endpoint_auth import ( +from litellm.proxy.mcp_server.auth.token_endpoint_auth import ( TokenEndpointAuthConfigError, build_token_endpoint_client_auth, normalize_token_endpoint_auth_method, diff --git a/tests/unit/proxy/_experimental/mcp_server/auth/test_user_api_key_auth_mcp.py b/tests/unit/proxy/mcp_server/auth/test_user_api_key_auth_mcp.py similarity index 95% rename from tests/unit/proxy/_experimental/mcp_server/auth/test_user_api_key_auth_mcp.py rename to tests/unit/proxy/mcp_server/auth/test_user_api_key_auth_mcp.py index f73a8547158..b7795b4d2f0 100644 --- a/tests/unit/proxy/_experimental/mcp_server/auth/test_user_api_key_auth_mcp.py +++ b/tests/unit/proxy/mcp_server/auth/test_user_api_key_auth_mcp.py @@ -16,12 +16,6 @@ from starlette.datastructures import Headers from litellm.caching.caching import DualCache from litellm.constants import MCP_ALL_TOOLS_WILDCARD from litellm.models.access_group import LiteLLM_AccessGroupTable -from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( - MCPRequestHandler, - UnloadableEntitlementError, - _agent_capped_servers, - is_mcp_admitted_user_subject, -) from litellm.proxy._types import ( UI_TEAM_ID, LiteLLM_ObjectPermissionTable, @@ -32,6 +26,12 @@ from litellm.proxy._types import ( SpecialMCPServerNames, UserAPIKeyAuth, ) +from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( + MCPRequestHandler, + UnloadableEntitlementError, + _agent_capped_servers, + is_mcp_admitted_user_subject, +) from litellm.types.agents import AgentCaller @@ -376,7 +376,7 @@ class TestMCPRequestHandler: def _real_manager_with_toolsets(self, toolset_perms): """A real MCPServerManager so the real expand_tool_permissions runs; only the DB-backed toolset lookup is stubbed""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager = MCPServerManager() manager.resolve_toolset_tool_permissions = AsyncMock(return_value=toolset_perms) @@ -392,7 +392,7 @@ class TestMCPRequestHandler: with ( patch.object(MCPRequestHandler, "_get_key_object_permission", return_value=key_object_permission), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object(MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[])), @@ -413,7 +413,7 @@ class TestMCPRequestHandler: with ( patch.object(MCPRequestHandler, "_get_key_object_permission", return_value=key_object_permission), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object(MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[])), @@ -433,7 +433,7 @@ class TestMCPRequestHandler: with ( patch.object(MCPRequestHandler, "_get_key_object_permission", return_value=key_object_permission), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object(MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[])), @@ -458,7 +458,7 @@ class TestMCPRequestHandler: with ( patch.object(MCPRequestHandler, "_get_key_object_permission", return_value=key_object_permission), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object(MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[])), @@ -483,7 +483,7 @@ class TestMCPRequestHandler: patch.object(MCPRequestHandler, "_get_key_object_permission", return_value=key_object_permission), patch.object(MCPRequestHandler, "_get_team_object_permission", AsyncMock(return_value=None)), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -507,7 +507,7 @@ class TestMCPRequestHandler: patch.object(MCPRequestHandler, "_get_key_object_permission", return_value=key_object_permission), patch.object(MCPRequestHandler, "_get_team_object_permission", AsyncMock(return_value=None)), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -539,7 +539,7 @@ class TestMCPRequestHandler: patch.object(MCPRequestHandler, "_get_key_object_permission", return_value=key_object_permission), patch.object(MCPRequestHandler, "_get_team_object_permission", AsyncMock(return_value=None)), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -620,7 +620,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "_get_team_object_permission", AsyncMock(return_value=team_object_permission) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager, ), ): @@ -654,7 +654,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "_get_team_object_permission", AsyncMock(return_value=team_object_permission) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager, ), ): @@ -706,7 +706,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "_get_team_object_permission", AsyncMock(return_value=team_object_permission) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -740,7 +740,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "_get_team_object_permission", AsyncMock(return_value=team_object_permission) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -760,7 +760,7 @@ class TestMCPRequestHandler: with ( patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object( # test-quality-ok: access-group lookup hits the DB, not under test here @@ -798,7 +798,7 @@ class TestMCPRequestHandler: AsyncMock(return_value=[]), ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object( # test-quality-ok: access-group lookup hits the DB, not under test here @@ -835,7 +835,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[]) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object( # test-quality-ok: stub the level's perm loader; the resolver reads module globals with no injection seam @@ -872,7 +872,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[]) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object( # test-quality-ok: stub the level's perm loader; the resolver reads module globals with no injection seam @@ -915,7 +915,7 @@ class TestMCPRequestHandler: AsyncMock(return_value=[]), ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object( # test-quality-ok: access-group lookup hits the DB, not under test here @@ -944,7 +944,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "_get_org_object_permission", AsyncMock(return_value=org_object_permission) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -974,7 +974,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[]) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -995,7 +995,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "_get_user_object_permission", AsyncMock(return_value=user_object_permission) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -1026,7 +1026,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[]) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -1054,7 +1054,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "_get_team_object_permission", AsyncMock(return_value=team_object_permission) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -1079,7 +1079,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[]) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -1101,7 +1101,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[]) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -1254,7 +1254,7 @@ class TestMCPRequestHandler: "litellm.proxy.auth.auth_checks.get_mcp_server_ids_from_access_groups", new=AsyncMock(return_value=[]), ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): result = await MCPRequestHandler._get_key_access_group_mcp_server_extras(auth) assert result == [] @@ -1269,7 +1269,7 @@ class TestMCPRequestHandler: "litellm.proxy.auth.auth_checks.get_mcp_server_ids_from_access_groups", new=AsyncMock(return_value=["alias-a", "srv-b"]), ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.expand_permission_list.return_value = ["srv-a", "srv-b"] result = await MCPRequestHandler._get_key_access_group_mcp_server_extras(auth) @@ -1426,7 +1426,7 @@ class TestMCPRequestHandler: ) with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth, ): # Call the method @@ -1600,7 +1600,7 @@ class TestMCPRequestHandler: ) with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth" + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth" ) as mock_user_api_key_auth: mock_user_api_key_auth.return_value = mock_auth_result @@ -1686,11 +1686,11 @@ class TestMCPOAuth2AuthFlow: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, return_value=UserAPIKeyAuth(user_id="admitted-user"), ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = oauth2_server ( @@ -1726,7 +1726,7 @@ class TestMCPOAuth2AuthFlow: return UserAPIKeyAuth(api_key=api_key, user_id="test-user") with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth, ) as mock_auth: ( @@ -1765,7 +1765,7 @@ class TestMCPOAuth2AuthFlow: with ( patch( # test-quality-ok: capturing the exact api_key handed to key validation is the regression under test - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth, ) as mock_auth ): @@ -1793,7 +1793,7 @@ class TestMCPOAuth2AuthFlow: return UserAPIKeyAuth(api_key=api_key, user_id="test-user") with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth, ) as mock_auth: ( @@ -1831,7 +1831,7 @@ class TestMCPOAuth2AuthFlow: raise HTTPException(status_code=500, detail="Internal server error") with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_server_error, ): with pytest.raises(HTTPException) as exc_info: @@ -1882,10 +1882,10 @@ class TestMCPOAuth2AuthFlow: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_proxy_exception, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = oauth2_server with pytest.raises(HTTPException) as exc_info: @@ -1921,7 +1921,7 @@ class TestMCPOAuth2AuthFlow: ) with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_500, ): with pytest.raises(ProxyException): @@ -1956,10 +1956,10 @@ class TestMCPPublicRouteGuard: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): # Explicit unresolvable target — proves auth still fails even # when the registry has no info to fall back to. @@ -1987,10 +1987,10 @@ class TestMCPPublicRouteGuard: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = None with pytest.raises(HTTPException) as exc_info: @@ -2011,7 +2011,7 @@ class TestMCPPublicRouteGuard: # No mock needed — public path should not call user_api_key_auth at all with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", ) as mock_auth: auth_result, *_rest = await MCPRequestHandler.process_mcp_request(scope) mock_auth.assert_not_called() @@ -2041,12 +2041,12 @@ class TestMCPPassthroughColdStartAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp._is_mcp_passthrough_cold_start" + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp._is_mcp_passthrough_cold_start" ) as mock_cold_start, ): mock_mgr.get_mcp_server_by_name.return_value = ( @@ -2081,10 +2081,10 @@ class TestMCPPassthroughColdStartAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = ( TestMCPPassthroughColdStartAdmission._make_passthrough_server() @@ -2109,10 +2109,10 @@ class TestMCPPassthroughColdStartAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = ( TestMCPPassthroughColdStartAdmission._make_passthrough_server() @@ -2137,14 +2137,14 @@ class TestMCPPassthroughColdStartAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.IPAddressUtils.get_mcp_client_ip", return_value="203.0.113.10", ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = None with pytest.raises(HTTPException) as exc_info: @@ -2168,10 +2168,10 @@ class TestMCPPassthroughColdStartAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_forbidden, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = ( TestMCPPassthroughColdStartAdmission._make_passthrough_server() @@ -2201,10 +2201,10 @@ class TestMCPPassthroughColdStartAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_server_error, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = ( TestMCPPassthroughColdStartAdmission._make_passthrough_server() @@ -2227,10 +2227,10 @@ class TestMCPPassthroughColdStartAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = ( TestMCPPassthroughColdStartAdmission._make_passthrough_server() @@ -2260,10 +2260,10 @@ class TestMCPPassthroughColdStartAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = ( TestMCPPassthroughColdStartAdmission._make_passthrough_server() @@ -2312,10 +2312,10 @@ class TestMCPOAuth2FallbackTargetGating: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPOAuth2FallbackTargetGating._make_server( MCPAuth.api_key @@ -2343,10 +2343,10 @@ class TestMCPOAuth2FallbackTargetGating: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = None with pytest.raises(HTTPException) as exc_info: @@ -2381,10 +2381,10 @@ class TestMCPOAuth2FallbackTargetGating: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPOAuth2FallbackTargetGating._make_server( MCPAuth.oauth2 @@ -2418,10 +2418,10 @@ class TestMCPOAuth2FallbackTargetGating: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPOAuth2FallbackTargetGating._make_server( auth_type=MCPAuth.none, @@ -2446,14 +2446,14 @@ class TestMCPOAuth2FallbackTargetGating: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.IPAddressUtils.get_mcp_client_ip", return_value="203.0.113.10", ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = None with pytest.raises(HTTPException) as exc_info: @@ -2497,10 +2497,10 @@ class TestMCPOAuth2FallbackTargetGating: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.side_effect = mock_lookup with pytest.raises(HTTPException) as exc_info: @@ -2533,7 +2533,7 @@ class TestMCPOAuth2FallbackTargetGating: ) with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_no_code, ): with pytest.raises(ProxyException): @@ -2563,7 +2563,7 @@ class TestMCPDelegateAuthToUpstream: ) def test_legacy_delegate_cold_start_fails_closed_without_targets(self): - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( _is_legacy_delegate_cold_start, ) @@ -2571,7 +2571,7 @@ class TestMCPDelegateAuthToUpstream: def test_build_mcp_server_table_preserves_delegate_auth_to_upstream(self): """Registry → API list rows must expose delegate_auth_to_upstream for the UI.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp import MCPAuth @@ -2598,7 +2598,7 @@ class TestMCPDelegateAuthToUpstream: distinct from ``delegate_auth_to_upstream`` (oauth2-only). Both must round-trip independently so neither flag silently implies the other. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp import MCPAuth @@ -2638,11 +2638,11 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, side_effect=HTTPException(status_code=401, detail="No key provided"), ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPDelegateAuthToUpstream._make_server( auth_type=MCPAuth.oauth2, @@ -2668,11 +2668,11 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, side_effect=HTTPException(status_code=401, detail="Invalid API key"), ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPDelegateAuthToUpstream._make_server( auth_type=MCPAuth.oauth2, @@ -2705,10 +2705,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPDelegateAuthToUpstream._make_server( auth_type=MCPAuth.oauth2, @@ -2740,10 +2740,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPDelegateAuthToUpstream._make_server( auth_type=MCPAuth.api_key, @@ -2788,10 +2788,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.side_effect = mock_lookup with pytest.raises(HTTPException) as exc_info: @@ -2818,10 +2818,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = None with pytest.raises(HTTPException) as exc_info: @@ -2846,11 +2846,11 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, return_value=UserAPIKeyAuth(user_id="real-user"), ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPDelegateAuthToUpstream._make_server( auth_type=MCPAuth.oauth2, @@ -2878,11 +2878,11 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, return_value=UserAPIKeyAuth(user_id="real-user"), ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPDelegateAuthToUpstream._make_server( auth_type=MCPAuth.oauth2, @@ -2936,10 +2936,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_auth_raises, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = m2m_server # No delegate bypass → normal auth is attempted → 401 raised @@ -2987,10 +2987,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_auth_raises, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = legacy_m2m_server with pytest.raises(HTTPException) as exc_info: @@ -3029,10 +3029,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_auth_raises, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = pkce_server auth, *_rest = await MCPRequestHandler.process_mcp_request(scope) @@ -3069,10 +3069,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_auth_raises, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = internal_server auth, *_rest = await MCPRequestHandler.process_mcp_request(scope) @@ -3081,7 +3081,7 @@ class TestMCPDelegateAuthToUpstream: async def test_get_allowed_servers_excludes_legacy_delegates(self): """Legacy delegated servers are never added to anonymous access.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp import MCPAuth @@ -3134,10 +3134,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPDelegateAuthToUpstream._make_server( auth_type=MCPAuth.true_passthrough, @@ -3180,10 +3180,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.side_effect = mock_lookup with pytest.raises(HTTPException) as exc_info: @@ -3192,7 +3192,7 @@ class TestMCPDelegateAuthToUpstream: async def test_get_allowed_servers_includes_true_passthrough(self): """Anonymous callers can reach true_passthrough servers; admission is delegated upstream.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp import MCPAuth @@ -3230,7 +3230,7 @@ class TestMCPDelegateAuthToUpstream: allow-list which can include ``allow_all_keys`` servers that normally require a LiteLLM key. """ - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_mcp_servers_in_path, ) @@ -3307,10 +3307,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_auth_raises, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.side_effect = lookup_by_name with pytest.raises(HTTPException) as exc_info: @@ -3370,10 +3370,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_auth_raises, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.side_effect = lookup_by_name # Bypass MUST NOT fire — path-derived target is the non-delegate @@ -3568,7 +3568,7 @@ class TestMCPCustomHeaderName: ) with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth, ) as mock_auth: # Call the method @@ -3737,7 +3737,7 @@ class TestMCPAccessGroupsE2E: ) with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth, ) as mock_auth: # Call the method @@ -3786,7 +3786,7 @@ class TestMCPAccessGroupsE2E: ) with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth, ) as mock_auth: # Call the method @@ -3811,7 +3811,7 @@ class TestMCPAccessGroupsE2E: def test_mcp_path_based_server_segregation(monkeypatch): # Import the MCP server FastAPI app and context getter - from litellm.proxy._experimental.mcp_server.server import app, get_auth_context + from litellm.proxy.mcp_server.server import app, get_auth_context captured_mcp_servers = {} @@ -3848,21 +3848,21 @@ def test_mcp_path_based_server_segregation(monkeypatch): ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.server.session_manager_stateless", + "litellm.proxy.mcp_server.server.session_manager_stateless", MagicMock(handle_request=dummy_handle_request), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.server.session_manager_stateful", + "litellm.proxy.mcp_server.server.session_manager_stateful", MagicMock(handle_request=dummy_handle_request), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.server.initialize_session_managers", + "litellm.proxy.mcp_server.server.initialize_session_managers", AsyncMock(), ) # Patch user_api_key_auth to always return a dummy user monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", AsyncMock(return_value=UserAPIKeyAuth(api_key="test", user_id="user")), ) @@ -4121,10 +4121,10 @@ async def test_get_allowed_mcp_servers_for_team_uses_helper(): object_permission fields (mcp_servers, mcp_access_groups) and the unified team.access_group_ids → access_mcp_server_ids path. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -4309,10 +4309,10 @@ async def test_get_allowed_mcp_servers_for_key_returns_empty_when_db_returns_non async def test_get_allowed_mcp_servers_for_key_prefers_in_memory_permission(): """Ensure in-memory object_permission is used without hitting the DB.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -4597,8 +4597,8 @@ class TestAgentMCPPermissions: mock_agent.assert_called_once_with(user_api_key_auth) async def test_agent_access_group_server_ceiling_expands_group_servers(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.agent_endpoints.auth.agent_access_groups import AgentAccessGroupCeiling + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -4733,7 +4733,7 @@ class TestAgentMCPPermissions: MCPRequestHandler, "_get_agent_object_permission", AsyncMock(return_value=agent_object_permission) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling toolset tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object( # test-quality-ok: access-group lookup hits the DB, not under test here @@ -4945,7 +4945,7 @@ async def test_tool_permission_servers_included_in_allowed_servers(): Regression test for https://github.com/BerriAI/litellm/issues/21954 """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) from litellm.types.mcp import MCPTransport @@ -5101,7 +5101,7 @@ class TestOrgMCPPermissions: async def test_get_org_object_permission_no_prisma(self): auth = self._make_auth(org_id="org-123") with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler._get_org_object_permission", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler._get_org_object_permission", new_callable=AsyncMock, return_value=None, ): @@ -5326,7 +5326,7 @@ async def test_mcp_key_access_group_extras_when_team_authorized(): return_value=fake_ag, ), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_mgr, ), ] @@ -5363,7 +5363,7 @@ async def test_mcp_key_access_group_extras_when_key_directly_authorized(): return_value=fake_ag, ), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_mgr, ), ] @@ -5599,10 +5599,10 @@ async def test_team_access_group_ids_resolve_to_mcp_servers(): async def test_team_access_group_ids_union_with_object_permission(): """When both legacy object_permission and unified team.access_group_ids grant MCP servers, the final list is their union.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5760,10 +5760,10 @@ async def test_allowed_mcp_servers_for_key_uses_object_permission_not_access_gro also carries access_group_ids that would resolve to other servers, those grants do NOT enter this (intersected) scope — only the object_permission server comes back. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5841,10 +5841,10 @@ def test_expand_permission_list_does_not_honor_all_proxy_sentinel(): downstream). Concrete ids still resolve normally. If the sentinel were expanded here, any stored key/org/end_user permission holding it would silently gain every server.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import SpecialMCPServerName + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import SpecialMCPServerName from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5874,14 +5874,14 @@ async def test_get_allowed_mcp_servers_for_team_expands_all_proxy_sentinel_dynam registry without any change to its stored permission. Reverting the team-side expansion collapses this to the inert literal and the result no longer contains the real servers.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - global_mcp_server_manager, - ) from litellm.proxy._types import ( LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable, SpecialMCPServerName, ) + from litellm.proxy.mcp_server.mcp_server_manager import ( + global_mcp_server_manager, + ) from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5952,13 +5952,13 @@ async def test_key_with_all_proxy_sentinel_does_not_grant_all_servers(): teamless key with the sentinel resolves to no real server — never srv-secret or the full registry. On the pre-hardening code the key path expanded the sentinel and this key would reach srv-secret.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - global_mcp_server_manager, - ) from litellm.proxy._types import ( LiteLLM_ObjectPermissionTable, SpecialMCPServerName, ) + from litellm.proxy.mcp_server.mcp_server_manager import ( + global_mcp_server_manager, + ) from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -6000,14 +6000,14 @@ async def test_get_allowed_mcp_servers_team_all_proxy_key_scoped_to_one_end_to_e exactly that server (key ∩ all-servers == key). If the sentinel branch is reverted the team ceiling collapses to the literal marker, the intersection empties, and the result is [] instead of ["srv-x"].""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - global_mcp_server_manager, - ) from litellm.proxy._types import ( LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable, SpecialMCPServerName, ) + from litellm.proxy.mcp_server.mcp_server_manager import ( + global_mcp_server_manager, + ) from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -6121,10 +6121,10 @@ class TestMCPDcrBridgeDelegateAdmission: ): from pydantic import SecretStr - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( envelope_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( SealedEnvelope, UpstreamTokenGrant, key_hash_identity, @@ -6281,7 +6281,7 @@ class TestMCPDcrBridgeDelegateAdmission: server.alias = None with patch( # test-quality-ok: isolate the MCP registry when testing target selection - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr: mock_mgr.get_mcp_server_by_name.return_value = server assert ( @@ -6303,11 +6303,11 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( # test-quality-ok: observe the auth boundary while testing admission orchestration - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, patch( # test-quality-ok: isolate the MCP registry used by request admission - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = self._bridge_delegate_server() @@ -6342,12 +6342,12 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( # test-quality-ok: force credential rejection through request admission - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, side_effect=HTTPException(status_code=401, detail="Invalid key"), ) as mock_auth, patch( # test-quality-ok: isolate the MCP registry used by request admission - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = self._bridge_delegate_server() @@ -6372,10 +6372,10 @@ class TestMCPDcrBridgeDelegateAdmission: } with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload(return_value=self._reloaded_key()) as get_key_object, ): @@ -6418,10 +6418,10 @@ class TestMCPDcrBridgeDelegateAdmission: } with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_user_reload( return_value=MagicMock( @@ -6461,10 +6461,10 @@ class TestMCPDcrBridgeDelegateAdmission: } with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_user_reload( return_value=MagicMock( @@ -6497,7 +6497,7 @@ class TestMCPDcrBridgeDelegateAdmission: "headers": [(b"authorization", f"Bearer {envelope}".encode("latin-1"))], } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_user_reload(side_effect=self._wrapped_user_lookup_error(Exception())), ): @@ -6521,7 +6521,7 @@ class TestMCPDcrBridgeDelegateAdmission: "headers": [(b"authorization", f"Bearer {envelope}".encode("latin-1"))], } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_user_reload( side_effect=self._wrapped_user_lookup_error(ConnectionError("auth database unreachable")) @@ -6552,7 +6552,7 @@ class TestMCPDcrBridgeDelegateAdmission: } with ( patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling admission tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, patch( # test-quality-ok: the envelope opener reads master_key off the proxy module, no injection seam "litellm.proxy.proxy_server.master_key", self._MASTER_KEY @@ -6583,7 +6583,7 @@ class TestMCPDcrBridgeDelegateAdmission: "headers": [(b"authorization", f"Bearer {envelope}".encode("latin-1"))], } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_user_reload( return_value=MagicMock(user_id="offboarded-user", organization_id=None, metadata={"scim_active": False}) @@ -6617,10 +6617,10 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), revoked, ): @@ -6642,7 +6642,7 @@ class TestMCPDcrBridgeDelegateAdmission: "headers": [(b"authorization", f"Bearer {envelope}".encode("latin-1"))], } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload(return_value=self._reloaded_key(blocked=True)), ): @@ -6665,7 +6665,7 @@ class TestMCPDcrBridgeDelegateAdmission: expired_at = datetime.now(timezone.utc) - timedelta(hours=1) with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload(return_value=self._reloaded_key(expires=expired_at)), ): @@ -6688,7 +6688,7 @@ class TestMCPDcrBridgeDelegateAdmission: } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload(return_value=self._reloaded_key(), team_blocked=True), ): @@ -6712,7 +6712,7 @@ class TestMCPDcrBridgeDelegateAdmission: } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload( return_value=self._reloaded_key(), @@ -6738,7 +6738,7 @@ class TestMCPDcrBridgeDelegateAdmission: } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload( return_value=self._reloaded_key(), @@ -6765,7 +6765,7 @@ class TestMCPDcrBridgeDelegateAdmission: } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload( return_value=self._reloaded_key(project_id="project-restricted"), @@ -6778,7 +6778,7 @@ class TestMCPDcrBridgeDelegateAdmission: assert exc_info.value.status_code == 401 - _POLICY_GATE = "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.run_centralized_common_checks" + _POLICY_GATE = "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.run_centralized_common_checks" async def _enforce_with_gate_error(self, error): """Drive _enforce_admitted_live_policy with the centralized gate raising ``error`` and return @@ -6820,7 +6820,7 @@ class TestMCPDcrBridgeDelegateAdmission: "headers": [(b"authorization", f"Bearer {envelope}".encode("latin-1"))], } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload(side_effect=ConnectionError("could not reach database server")), ): @@ -6864,9 +6864,9 @@ class TestMCPDcrBridgeDelegateAdmission: [(True, "scoped", []), (False, "scoped", ["public"]), (True, "unscoped", ["public"])], ) async def test_master_envelope_respects_allow_all_scope(self, flag_enabled, scope, expected): - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import hash_token + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager = MCPServerManager() with patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY): @@ -6902,7 +6902,7 @@ class TestMCPDcrBridgeDelegateAdmission: "headers": [(b"authorization", f"Bearer {envelope}".encode("latin-1"))], } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload(return_value=self._reloaded_key(allowed_routes=["/chat/completions"])), ): @@ -6926,7 +6926,7 @@ class TestMCPDcrBridgeDelegateAdmission: "headers": [(b"authorization", f"Bearer {envelope}".encode("latin-1"))], } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), patch("litellm.proxy.proxy_server.general_settings", {"allowed_routes": ["/chat/completions"]}), ): @@ -6961,10 +6961,10 @@ class TestMCPDcrBridgeDelegateAdmission: } with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload(return_value=self._reloaded_key()), ): @@ -7015,7 +7015,7 @@ class TestMCPDcrBridgeDelegateAdmission: ``lookup_mcp_server_auth_in_headers`` called the way egress calls it (alias first, then server_name) must recover exactly that token. This pins the agreement between the two key hierarchies so neither side can drift and silently drop the forwarded token.""" - from litellm.proxy._experimental.mcp_server.utils import lookup_mcp_server_auth_in_headers + from litellm.proxy.mcp_server.utils import lookup_mcp_server_auth_in_headers envelope = self._mint_bridge_envelope() server = self._bridge_delegate_server(server_name=server_name, alias=alias) @@ -7054,11 +7054,11 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, side_effect=HTTPException(status_code=401, detail="Invalid key"), ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), ): mock_mgr.get_mcp_server_by_name.return_value = self._bridge_delegate_server(server_name=None, alias=None) @@ -7086,10 +7086,10 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), ): mock_mgr.get_mcp_server_by_name.return_value = self._bridge_delegate_server() @@ -7122,10 +7122,10 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), ): mock_mgr.get_mcp_server_by_name.return_value = self._bridge_delegate_server() @@ -7157,10 +7157,10 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), ): mock_mgr.get_mcp_server_by_name.return_value = self._bridge_delegate_server() @@ -7194,11 +7194,11 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( # test-quality-ok: prove standard admission is never consulted for an envelope bearer - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling challenge tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, patch( # test-quality-ok: envelope keys derive from the proxy master_key module global "litellm.proxy.proxy_server.master_key", self._MASTER_KEY @@ -7233,11 +7233,11 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, side_effect=HTTPException(status_code=401, detail="Invalid key"), ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), ): mock_mgr.get_mcp_server_by_name.return_value = self._bridge_delegate_server() @@ -7264,12 +7264,12 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( # test-quality-ok: supply standard key admission through the auth boundary - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, return_value=admitted, ) as mock_auth, patch( # test-quality-ok: isolate the MCP registry used by request admission - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, patch( # test-quality-ok: configure key classification for the orchestration test "litellm.proxy.proxy_server.master_key", self._MASTER_KEY @@ -7299,12 +7299,12 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( # test-quality-ok: force a non-401 auth result through request admission - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, side_effect=HTTPException(status_code=403, detail="Key blocked"), ), patch( # test-quality-ok: isolate the MCP registry used by request admission - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, patch( # test-quality-ok: configure key classification for the orchestration test "litellm.proxy.proxy_server.master_key", self._MASTER_KEY @@ -7339,10 +7339,10 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), ): mock_mgr.get_mcp_server_by_name.return_value = self._bridge_delegate_server() @@ -7379,10 +7379,10 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), ): mock_mgr.get_mcp_server_by_name.return_value = self._bridge_delegate_server( @@ -7421,10 +7421,10 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), ): mock_mgr.get_mcp_server_by_name.side_effect = mock_lookup @@ -7554,7 +7554,7 @@ class TestMCPDcrBridgeDualCredential: ) with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new=AsyncMock(return_value=self._DELEGATE._reloaded_key()), ), patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), @@ -7583,11 +7583,11 @@ class TestMCPDcrBridgeDualCredential: presented_token = "aaa.bbb.ccc" if mapped_jwt else "sk-explicit-key" with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, return_value=explicit_auth, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._DELEGATE._patch_key_reload() as get_key_object, ): @@ -7618,11 +7618,11 @@ class TestMCPDcrBridgeDualCredential: envelope = self._DELEGATE._mint_bridge_envelope(key_hash=self._KEY_HASH) with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, return_value=self._DELEGATE._reloaded_key(api_key="a-different-key-hash"), ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._DELEGATE._patch_key_reload(), ): @@ -7640,12 +7640,12 @@ class TestMCPDcrBridgeDualCredential: envelope = self._DELEGATE._mint_bridge_envelope(user_id="sso-user-7") with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, return_value=UserAPIKeyAuth(user_id=presented_user, api_key="any-hash"), ), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), ): @@ -7677,11 +7677,11 @@ class TestMCPDcrBridgeDualCredential: tampered = envelope[:-4] + "AAAA" with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, return_value=self._DELEGATE._reloaded_key(), ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._DELEGATE._patch_key_reload(), ): @@ -7693,6 +7693,47 @@ class TestMCPDcrBridgeDualCredential: assert "invalid_token" in str(exc_info.value.headers) +@pytest.mark.parametrize("public_path", ["/toolset/analysis/mcp", "/analysis/mcp", "/mcp", "/mcp/", "/mcp/proxy"]) +@pytest.mark.parametrize("root_path", ["", "/litellm"]) +@pytest.mark.parametrize("invalid_token", [False, True]) +def test_gateway_challenge_metadata_contains_the_public_resource( + public_path: str, root_path: str, invalid_token: bool, +) -> None: + from mcp.shared.auth_utils import check_resource_allowed + from starlette.requests import Request + from starlette.types import Scope + + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import _gateway_dcr_challenge + from litellm.proxy.mcp_server.discoverable_endpoints import ( + _build_aggregate_protected_resource_response, + oauth_protected_resource_root, + ) + + scope: Final[Scope] = { + "type": "http", "method": "POST", "scheme": "https", "path": "/mcp", + "root_path": root_path, "_original_path": f"{root_path}{public_path}", + "headers": [(b"host", b"gateway.example.com")], + } + request: Final = Request(scope) + challenge: Final = _gateway_dcr_challenge(request, "/mcp", None, invalid_token) + header: Final = (challenge.headers or {})["WWW-Authenticate"] + metadata_url: Final = header.split('resource_metadata="', 1)[1].split('"', 1)[0] + toolset: Final = public_path in ("/toolset/analysis/mcp", "/analysis/mcp") + assert metadata_url == ( + f"https://gateway.example.com{root_path}/.well-known/oauth-protected-resource" + + ("" if toolset else "/mcp") + ) + metadata: Final = ( + oauth_protected_resource_root(request) if toolset else _build_aggregate_protected_resource_response(request) + ) + assert check_resource_allowed( + requested_resource=f"https://gateway.example.com{root_path}{public_path}", + configured_resource=metadata["resource"], + ) + assert challenge.status_code == 401 + assert ('error="invalid_token"' in header) is invalid_token + + @pytest.mark.asyncio class TestAggregateGatewayDcrChallenge: """The mcp_gateway_dcr front door: a 401 on the aggregate /mcp scope must @@ -7700,7 +7741,7 @@ class TestAggregateGatewayDcrChallenge: own protected-resource metadata, and must NOT fire for named-server targets, explicit litellm keys, or non-401 failures.""" - _AUTH_PATCH_TARGET = "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth" + _AUTH_PATCH_TARGET = "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth" _EXPECTED_RESOURCE_METADATA = 'resource_metadata="http://testserver/.well-known/oauth-protected-resource/mcp"' def _scope(self, path="/mcp", extra_headers=()): @@ -7839,7 +7880,7 @@ class TestAggregateGatewayDcrChallenge: ) with ( patch(self._AUTH_PATCH_TARGET, side_effect=self._auth_401()), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, ): manager.get_mcp_server_by_identifier.side_effect = lambda identifier, client_ip=None: { "alpha": alpha, @@ -7884,7 +7925,7 @@ class TestAggregateGatewayDcrChallenge: with ( patch(self._AUTH_PATCH_TARGET, side_effect=self._auth_401()), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = server @@ -7932,7 +7973,7 @@ class TestAggregateGatewayDcrChallenge: patch.dict(os.environ, {"SERVER_ROOT_PATH": "/litellm"}), patch(self._AUTH_PATCH_TARGET, side_effect=self._auth_401()), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = server @@ -7965,7 +8006,7 @@ class TestAggregateGatewayDcrChallenge: with ( patch(self._AUTH_PATCH_TARGET, side_effect=self._auth_401()), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = resolved @@ -7977,7 +8018,7 @@ class TestAggregateGatewayDcrChallenge: def test_challenge_target_excludes_every_non_gateway_managed_mode(self): """Gateway challenges exclude unresolved, delegated, and client-forwarded targets.""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( _gateway_dcr_challenge_target, ) from litellm.types.mcp import MCPAuth @@ -8012,13 +8053,13 @@ class TestAggregateGatewayDcrChallenge: ] for resolved, expected in cases: with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr: mock_mgr.get_mcp_server_by_identifier.return_value = resolved assert _gateway_dcr_challenge_target("/mcp/srv", None, None) == expected, resolved assert _gateway_dcr_challenge_target("/mcp/a,b", None, None) is None assert _gateway_dcr_challenge_target("/mcp", None, None) is None - with patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr: + with patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr: mock_mgr.get_mcp_server_by_identifier.return_value = _server(MCPAuth.oauth2) assert _gateway_dcr_challenge_target("/mcp/srv", ["other"], None) is None @@ -8067,10 +8108,10 @@ class TestGatewaySessionAdmission: _MASTER_KEY = "sk-gateway-session-admission-master-key" def _session_bearer(self, user_id="sso-user-42", client_id="llm_dcrc_abc"): - from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.session_credentials import ( session_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import ( + from litellm.proxy.mcp_server.outbound_credentials.session_token import ( SessionPrincipal, mint_session_refresh_token, mint_session_token, @@ -8127,7 +8168,7 @@ class TestGatewaySessionAdmission: with ( patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ), self._patch_user_reload(user_id="org-user", organization_id="org-123"), @@ -8144,7 +8185,7 @@ class TestGatewaySessionAdmission: with ( patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ), self._patch_user_reload(user_id="rl-user", tpm_limit=1000, rpm_limit=50), @@ -8158,7 +8199,7 @@ class TestGatewaySessionAdmission: with ( patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, self._patch_user_reload(user_id="sso-user-42") as get_user_object, @@ -8209,7 +8250,7 @@ class TestGatewaySessionAdmission: with ( patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ), self._patch_user_reload(user_id="offboarded-user", active=False), @@ -8227,7 +8268,7 @@ class TestGatewaySessionAdmission: with ( patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ), self._patch_user_reload(user_id="sso-user-42"), @@ -8260,7 +8301,7 @@ class TestGatewaySessionAdmission: with ( patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, self._patch_user_reload(user_id="sso-user-42"), @@ -8292,7 +8333,7 @@ class TestGatewaySessionAdmission: ) with ( patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = server with pytest.raises(HTTPException) as exc_info: @@ -8312,7 +8353,7 @@ class TestGatewaySessionAdmission: with ( patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ), self._patch_user_reload(user_id="sso-user-42"), @@ -8400,7 +8441,7 @@ class TestUserSubjectTeamUnion: async def test_toolsets_of_a_team_that_dropped_the_user_from_its_roster_are_not_granted(self): """The user's cached team list still names team-revoked, but its live roster no longer lists the user, so its toolset is withheld exactly as its servers are on the aggregate /mcp.""" - from litellm.proxy._experimental.mcp_server.ui_session_utils import granted_toolset_ids + from litellm.proxy.mcp_server.ui_session_utils import granted_toolset_ids teams = { "team-kept": _make_team("team-kept", [], toolsets=["ts-kept"]), @@ -8414,7 +8455,7 @@ class TestUserSubjectTeamUnion: async def test_a_pinned_toolset_narrows_every_source_to_the_toolset_servers_and_tools(self): """On /toolset/{name}/mcp the admitted subject carries mcp_toolset_id; team-a's grant on srv1 and srv2 with every tool collapses to the toolset's srv1 and its one tool, and team-b's srv3 drops.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager teams = {"team-a": _make_team("team-a", ["srv1", "srv2"]), "team-b": _make_team("team-b", ["srv3"])} auth = _make_admitted_subject("sso-user") @@ -8437,7 +8478,7 @@ class TestUserSubjectTeamUnion: async def test_a_fresh_policy_pinned_toolset_bypasses_the_toolset_permission_cache(self): """A session admitted under requires_fresh_policy reads the pinned toolset from the writer, so a tool revoked from the toolset is gone on the very next request (Devin Review 4150024092).""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager teams = {"team-a": _make_team("team-a", ["srv1", "srv2"])} auth = _make_admitted_subject("sso-user") @@ -8605,7 +8646,7 @@ class TestUserSubjectTeamUnion: assert billed is None, "and billing agrees: the user is billed, not a team" def _manager_with(self, server_ids, allow_all=()): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -8647,7 +8688,7 @@ class TestUserSubjectTeamUnion: server = MagicMock(server_id="srv1") with self._patch(teams_by_id={"t-grant": t_grant}, user_teams=["t-grant"]): with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager.get_mcp_server_from_tool_name", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager.get_mcp_server_from_tool_name", MagicMock(return_value=server), ): billed = await MCPRequestHandler.billing_auth_for_tool_call( @@ -8703,7 +8744,7 @@ class TestUserSubjectTeamUnion: boom = AsyncMock(side_effect=RuntimeError("toolset resolution exploded")) with self._patch(teams_by_id=teams, user_teams=["t1"]): with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager.resolve_toolset_tool_permissions", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager.resolve_toolset_tool_permissions", boom, ): tools = await MCPRequestHandler.get_allowed_tools_for_server("srv1", auth) @@ -8826,7 +8867,7 @@ class TestUserSubjectTeamUnion: plain = _make_admitted_subject("plain-user") with self._patch(teams_by_id={}, user_teams=[]): with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager.operator_open_server_ids", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager.operator_open_server_ids", AsyncMock(return_value=set()), ): admin_tools = await MCPRequestHandler.get_allowed_tools_for_server("srv-any", admin) @@ -8871,7 +8912,7 @@ class TestUserSubjectTeamUnion: open_ids = AsyncMock(return_value={"srv-open"}) with self._patch(teams_by_id={}, user_teams=[]): with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager.operator_open_server_ids", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager.operator_open_server_ids", open_ids, ): tools = await MCPRequestHandler.get_allowed_tools_for_server("srv-open", auth) @@ -8886,7 +8927,7 @@ class TestUserSubjectTeamUnion: open_ids = AsyncMock(return_value={"srv-open"}) with self._patch(teams_by_id={}, user_teams=[]): with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager.operator_open_server_ids", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager.operator_open_server_ids", open_ids, ): open_tools = await MCPRequestHandler.get_allowed_tools_for_server("srv-open", auth) @@ -9249,7 +9290,7 @@ class TestAdmittedSubjectPerTeamOrgCap: patch("litellm.proxy.proxy_server.proxy_logging_obj", MagicMock()), ] if registry is not None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -9544,10 +9585,10 @@ class TestSessionBearerEgressScrub: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = ttp_server (_auth, _mah, _srv, _sah, oauth2_headers, raw_headers) = await MCPRequestHandler.process_mcp_request(scope) @@ -9572,10 +9613,10 @@ class TestSessionBearerEgressScrub: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = ttp_server (_auth, _mah, _srv, _sah, oauth2_headers, _raw) = await MCPRequestHandler.process_mcp_request(scope) @@ -10255,7 +10296,7 @@ class TestUserMCPEntitlement: async def test_tool_call_is_rejected_at_call_time(self): """The end-to-end contract: a tool the human is not entitled to is refused when INVOKED, not merely hidden from the advertised list.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) from litellm.types.mcp import MCPTransport @@ -10307,7 +10348,7 @@ class TestUserMCPEntitlement: async def test_servers_named_only_under_tool_permissions_are_entitled(self): """Granting one tool on a server entitles the human to that server, so an admin never has to name it twice.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) from litellm.types.mcp import MCPTransport @@ -10737,10 +10778,10 @@ class TestScopedSessionAdmission: def _bearer(self, resource_server_ids): from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.session_credentials import ( session_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import ( + from litellm.proxy.mcp_server.outbound_credentials.session_token import ( SessionPrincipal, mint_session_token, ) @@ -10817,7 +10858,7 @@ async def test_fresh_mcp_user_permission_link_ignores_cached_and_replica_grants( @pytest.mark.asyncio @pytest.mark.parametrize("operation", ["servers", "tools"]) async def test_managed_agent_permission_resolution_outage_is_not_an_unrestricted_grant(monkeypatch, operation): - from litellm.proxy._experimental.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server import mcp_server_manager from litellm.types.agents import AgentResponse auth = UserAPIKeyAuth(agent_id="managed") @@ -10906,7 +10947,19 @@ async def test_catalog_refresh_reads_current_user_org_without_losing_resource_sc @pytest.mark.asyncio @pytest.mark.parametrize("current_groups", [[], ["replacement-group"]]) async def test_catalog_refresh_uses_current_virtual_key_policy_and_keeps_session_scope(monkeypatch, current_groups): - permission = LiteLLM_ObjectPermissionTable(object_permission_id="current-policy", mcp_servers=["current-server"]) + from litellm.proxy import proxy_server + from litellm.types.mcp_server.mcp_toolset import MCPToolset + + permission = LiteLLM_ObjectPermissionTable( + object_permission_id="current-policy", mcp_toolsets=["session-toolset"] + ) + toolset: Final = MCPToolset( + toolset_id="session-toolset", toolset_name="session-toolset", + tools=[{"server_id": "current-server", "tool_name": "read"}], + ) + tables: Final = SimpleNamespace(litellm_mcptoolsettable=SimpleNamespace(find_many=AsyncMock(return_value=[toolset]))) + monkeypatch.setattr(proxy_server, "prisma_client", SimpleNamespace(db=tables, writer_db=tables)) + monkeypatch.setattr(proxy_server, "user_api_key_cache", DualCache()) current = UserAPIKeyAuth( object_permission=permission, object_permission_id="current-policy", @@ -10931,7 +10984,10 @@ async def test_catalog_refresh_uses_current_virtual_key_policy_and_keeps_session caller.mcp_toolset_id = "session-toolset" refreshed = await MCPRequestHandler.refresh_catalog_authority(caller) reload_key.assert_awaited_once_with("owned-key-hash", check_db_only=True) - assert refreshed.object_permission == permission + assert refreshed.object_permission == permission.model_copy(update={ + "mcp_servers": ["current-server"], "mcp_toolsets": [], + "mcp_tool_permissions": {"current-server": ["read"]}, + }) assert refreshed.object_permission_id == "current-policy" assert (refreshed.team_id, refreshed.org_id, refreshed.project_id, refreshed.user_id) == ( "new-team", @@ -10950,7 +11006,7 @@ async def test_catalog_refresh_uses_current_virtual_key_policy_and_keeps_session @pytest.mark.asyncio async def test_admission_request_body_serves_stashed_peek_callable(): from litellm.constants import MCP_PEEKED_BODY_SCOPE_KEY - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import _admission_request + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import _admission_request admission_body: Final = b'{"method":"tools/list"}' @@ -11366,7 +11422,7 @@ class TestAccessGroupToolOwnershipAndFaults: assert await MCPRequestHandler.get_allowed_tools_for_server("srv", auth) == ["read"] async def test_legacy_tag_carried_by_the_server_keeps_the_key_unrestricted(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -11628,11 +11684,11 @@ async def test_token_minted_credential_lists_tools_for_every_scope_shape(monkeyp from mcp.types import ListToolsRequest, ListToolsResult, Tool from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.id_jag_grant import SubjectTokenRefusal, granted_scope - from litellm.proxy._experimental.mcp_server.operations import GatewayOperations, prepare_context from litellm.proxy._types import MCPTransport from litellm.proxy.auth.auth_checks import ExperimentalUIJWTToken + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.id_jag_grant import SubjectTokenRefusal, granted_scope + from litellm.proxy.mcp_server.operations import GatewayOperations, prepare_context from litellm.types.mcp_server.mcp_server_manager import MCPServer monkeypatch.setenv("LITELLM_SALT_KEY", "sk-session-credential-tools-list") @@ -11712,9 +11768,9 @@ def personal_key_owner_teams(monkeypatch: pytest.MonkeyPatch, request: pytest.Fi srv-open (``allow_all_keys``, granted to no team).""" import litellm from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import LiteLLM_UserTable from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -11765,8 +11821,8 @@ async def test_personal_key_mcp_servers_are_the_union_of_its_owner_team_grants( async def test_personal_key_mcp_listing_applies_agent_caller_ceiling( personal_key_owner_teams: UserAPIKeyAuth, ) -> None: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess from litellm.proxy.agent_endpoints.auth.agent_caller import agent_caller_from_headers + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess auth: Final = personal_key_owner_teams.model_copy(update={"agent_id": "agent-1"}) caller: Final = agent_caller_from_headers( @@ -11807,9 +11863,9 @@ async def test_personal_key_tool_call_bills_granting_team( ) -> None: from litellm.models.budget import LiteLLM_BudgetTable from litellm.models.team_membership import LiteLLM_TeamMembership - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy._experimental.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR, get_server_prefix from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR, get_server_prefix team_membership: Final = LiteLLM_TeamMembership( user_id=personal_key_owner_teams.user_id, @@ -11867,9 +11923,9 @@ async def test_personal_key_mcp_billing_preserves_key_organization( team_org_id: str | None, expected_org_id: str, ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy._experimental.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR, get_server_prefix from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR, get_server_prefix async def _get_team_object(team_id: str, **_: object) -> LiteLLM_TeamTable: return LiteLLM_TeamTable( @@ -11902,8 +11958,8 @@ async def test_personal_key_mcp_billing_preserves_key_organization( async def test_personal_key_display_name_billing_uses_original_tool_grant( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server: Final = global_mcp_server_manager.registry["srv-a"].model_copy( update={ @@ -11930,8 +11986,8 @@ async def test_personal_key_display_name_billing_uses_allowed_servers( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth ) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -11979,9 +12035,9 @@ async def test_personal_key_display_name_billing_uses_allowed_servers( async def test_personal_key_tool_call_bills_lowest_team_when_both_allow( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy._experimental.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR, get_server_prefix from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR, get_server_prefix async def _get_team_object(team_id: str, **_: object) -> LiteLLM_TeamTable: return _personal_key_team_granting_tools(team_id, ("multiply",)) @@ -12000,8 +12056,8 @@ async def test_personal_key_tool_call_bills_lowest_team_when_both_allow( async def test_personal_key_attribution_preserves_hyphenated_native_tool_names( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async def _get_team_object(team_id: str, **_: object) -> LiteLLM_TeamTable: return _personal_key_team_granting_tools( @@ -12031,8 +12087,8 @@ async def test_personal_key_guardrail_auth_preserves_native_tool_name_matching_s monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth, ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async def _get_team_object(team_id: str, **_: object) -> LiteLLM_TeamTable: return _personal_key_team_granting_tools( @@ -12061,9 +12117,9 @@ async def test_personal_key_mcp_billing_inherits_adopted_organization_limits( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth ) -> None: from litellm.models.budget import LiteLLM_BudgetTable - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy.auth import auth_checks from litellm.proxy._types import LiteLLM_OrganizationTable + from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager organization: Final = LiteLLM_OrganizationTable( organization_id="org-1", @@ -12111,9 +12167,9 @@ async def test_personal_key_mcp_billing_keeps_key_organization_limits( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth ) -> None: from litellm.models.budget import LiteLLM_BudgetTable - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy.auth import auth_checks from litellm.proxy._types import LiteLLM_OrganizationTable + from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager organization: Final = LiteLLM_OrganizationTable( organization_id="org-1", @@ -12148,10 +12204,10 @@ async def test_personal_key_mcp_billing_keeps_key_organization_limits( async def test_personal_key_mcp_billing_keeps_team_controls_when_org_lookup_fails( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy import proxy_server from litellm.proxy.auth import auth_checks from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async def _get_team_object(team_id: str, **_: object) -> LiteLLM_TeamTable: return _personal_key_team_granting_tools(team_id, ("divide",)).model_copy( @@ -12197,10 +12253,10 @@ async def test_personal_key_mcp_billing_keeps_team_id_when_membership_lookup_fai monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth, ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy import proxy_server from litellm.proxy.auth import auth_checks from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async def _get_team_object(team_id: str, **_: object) -> LiteLLM_TeamTable: return _personal_key_team_granting_tools(team_id, ("divide",)) @@ -12251,9 +12307,9 @@ async def test_personal_key_mcp_billing_uses_fresh_team_and_membership_for_stric from litellm.models.budget import LiteLLM_BudgetTable from litellm.models.team_membership import LiteLLM_TeamMembership from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.auth import auth_checks from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async def _get_team_object(team_id: str, **kwargs: object) -> LiteLLM_TeamTable: database_value: Final = bool(kwargs.get("check_db_only")) @@ -12305,12 +12361,12 @@ async def test_personal_key_mcp_billing_uses_fresh_team_and_membership_for_stric async def test_personal_key_team_mcp_rpm_limit_charges_granting_team( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.auth import auth_checks from litellm.proxy.hooks.parallel_request_limiter_v3 import ( PROXY_MaxParallelRequestsHandler_v3, RateLimitDescriptor, ) + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async def _get_team_object(team_id: str, **_: object) -> LiteLLM_TeamTable: team: Final = _personal_key_team_granting_tools(team_id, ("divide",) if team_id == "team-a" else ("multiply",)) @@ -12476,8 +12532,8 @@ async def test_personal_key_unreadable_team_permission_is_not_a_server_or_billin monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth, ) -> None: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess async def _unreadable_team(team_id: str, **_: object) -> LiteLLM_TeamTable: return LiteLLM_TeamTable( @@ -12502,8 +12558,8 @@ async def test_personal_key_team_server_access_group_read_fault_stays_scoped( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth, ) -> None: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess async def _team_with_access_group(team_id: str, **_: object) -> LiteLLM_TeamTable: return LiteLLM_TeamTable(team_id=team_id, access_group_ids=["unreadable-group"]) @@ -12527,9 +12583,9 @@ async def test_personal_key_scoped_bare_tool_name_bills_granting_team( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth, ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy import proxy_server from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async def _get_team_object(team_id: str, **_: object) -> LiteLLM_TeamTable: return _personal_key_team(team_id).model_copy( @@ -12568,8 +12624,8 @@ async def test_personal_key_prefixed_tool_billing_resolves_server_without_loaded personal_key_owner_teams: UserAPIKeyAuth, ) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -12618,8 +12674,8 @@ async def test_personal_key_scoped_tool_billing_prefers_scoped_server( personal_key_owner_teams: UserAPIKeyAuth, ) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async def _get_team_object(team_id: str, **_: object) -> LiteLLM_TeamTable: server_id: Final = "srv-a" if team_id == "team-a" else "srv-b" diff --git a/tests/unit/proxy/_experimental/mcp_server/conftest.py b/tests/unit/proxy/mcp_server/conftest.py similarity index 93% rename from tests/unit/proxy/_experimental/mcp_server/conftest.py rename to tests/unit/proxy/mcp_server/conftest.py index de7ed4d45e8..da5b7d8d9a3 100644 --- a/tests/unit/proxy/_experimental/mcp_server/conftest.py +++ b/tests/unit/proxy/mcp_server/conftest.py @@ -70,7 +70,7 @@ def pytest_collection_modifyitems(config, items): @pytest.fixture def config_only_mcp_manager_factory(): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager class ConfigOnlyManager(MCPServerManager): def initialize_tool_name_to_mcp_server_name_mapping(self): @@ -81,13 +81,11 @@ def config_only_mcp_manager_factory(): @pytest.fixture(autouse=True) def _hermetic_mcp_server_registry(): - from litellm.proxy._experimental.mcp_server.catalog import CatalogSnapshots - - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.catalog import CatalogSnapshots + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry saved_tools = global_mcp_tool_registry.published_tools global_mcp_tool_registry.published_tools = {} diff --git a/tests/unit/proxy/mcp_server/faults/__init__.py b/tests/unit/proxy/mcp_server/faults/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/unit/proxy/_experimental/mcp_server/faults/test_classify.py b/tests/unit/proxy/mcp_server/faults/test_classify.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/faults/test_classify.py rename to tests/unit/proxy/mcp_server/faults/test_classify.py index 30107db4055..33b5632cf23 100644 --- a/tests/unit/proxy/_experimental/mcp_server/faults/test_classify.py +++ b/tests/unit/proxy/mcp_server/faults/test_classify.py @@ -3,19 +3,19 @@ code and whose credentials the gateway presented, never on the upstream's HTTP s from typing import Final -import pytest import httpx +import pytest -from litellm.proxy._experimental.mcp_server.faults.classify import ( +from litellm.proxy.mcp_server.faults.classify import ( classify_upstream_dcr_rejection, classify_upstream_token_rejection, ) -from litellm.proxy._experimental.mcp_server.faults.types import ( +from litellm.proxy.mcp_server.faults.types import ( CallerRejected, GatewayRejected, UpstreamProtocolFault, - UpstreamReportedFault, UpstreamRegistrationRefused, + UpstreamReportedFault, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/faults/test_list_outcomes.py b/tests/unit/proxy/mcp_server/faults/test_list_outcomes.py similarity index 81% rename from tests/unit/proxy/_experimental/mcp_server/faults/test_list_outcomes.py rename to tests/unit/proxy/mcp_server/faults/test_list_outcomes.py index f6902c778e5..df016d38ada 100644 --- a/tests/unit/proxy/_experimental/mcp_server/faults/test_list_outcomes.py +++ b/tests/unit/proxy/mcp_server/faults/test_list_outcomes.py @@ -9,22 +9,23 @@ if sys.version_info < (3, 11): # BaseExceptionGroup is a builtin only from 3.11 from exceptiongroup import BaseExceptionGroup import httpx +import httpx2 import pytest from mcp import MCPError -from mcp.types import ErrorData +from mcp.types import CONNECTION_CLOSED, ErrorData -from litellm.proxy._experimental.mcp_server.exceptions import ( +from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError +from litellm.proxy.mcp_server.exceptions import ( MCPServerListError, MCPUpstreamAuthError, ) -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( +from litellm.proxy.mcp_server.faults.list_outcomes import ( ServerListFault, ServerListOk, classify_list_exception, list_fault_http_status, outcome_wire_value, ) -from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError def test_carried_fault_passes_through(): @@ -102,6 +103,68 @@ def test_unknown_exception_is_internal(): assert classify_list_exception(ValueError("who knows")).tag == "internal" +@pytest.mark.parametrize("sdk_wrapped", (False, True)) +@pytest.mark.parametrize("nested", (False, True)) +def test_sse_event_limit_is_a_safe_upstream_fault(sdk_wrapped: bool, nested: bool) -> None: + limit: Final = 1024 + decoder_message: Final = f"Server-sent event exceeded the {limit} byte limit." + failure: Final = ( + MCPError(code=CONNECTION_CLOSED, message=f"SSE stream failed: {decoder_message}") + if sdk_wrapped else httpx2.SSEError(decoder_message) + ) + wrapped: Final = BaseExceptionGroup("private-upstream-secret", [failure]) if nested else failure + fault: Final = classify_list_exception(wrapped) + message: Final = ( + f"Upstream MCP SSE event exceeded the {limit} byte per-event limit. " + "Paginate tools/list responses so each event stays below the limit." + ) + assert fault == ServerListFault(tag="upstream_error", sse_event_limit_bytes=limit) + assert fault.public_message == message + assert list_fault_http_status(fault) == 502 + assert outcome_wire_value(fault) == { + "status": "upstream_error", "reason": "sse_event_too_large", "limit_bytes": limit, "message": message, + } + + +@pytest.mark.parametrize( + "failure", + ( + MCPError(code=CONNECTION_CLOSED, message="Connection closed"), + MCPError(code=-32603, message="SSE stream failed: Server-sent event exceeded the 1024 byte limit."), + MCPError(code=CONNECTION_CLOSED, message="SSE stream failed: Server-sent event exceeded the 0 byte limit."), + MCPError(code=CONNECTION_CLOSED, message="SSE stream failed: Server-sent event exceeded the -1 byte limit."), + MCPError(code=CONNECTION_CLOSED, message=( + "SSE stream failed: Server-sent event exceeded the 10000000000000000000 byte limit." + )), + MCPError(code=CONNECTION_CLOSED, message=( + "SSE stream failed: Server-sent event exceeded the 1024 byte limit. private-secret" + )), + httpx2.SSEError("private-secret Server-sent event exceeded the 1024 byte limit."), + httpx2.SSEError("Expected response with content type 'text/event-stream', got 'private-secret'."), + RuntimeError("SSE stream failed: Server-sent event exceeded the 1024 byte limit."), + ), +) +def test_unrelated_errors_do_not_claim_an_sse_event_limit(failure: Exception) -> None: + fault: Final = classify_list_exception(failure) + assert fault.sse_event_limit_bytes is None + assert fault.public_message is None + assert "private-secret" not in str(outcome_wire_value(fault)) + + +@pytest.mark.parametrize("status_code", (401, 403)) +def test_upstream_auth_takes_precedence_over_sse_event_limit(status_code: int) -> None: + request: Final = httpx2.Request("POST", "https://upstream.example/mcp") + response: Final = httpx2.Response(status_code, request=request) + failure: Final = BaseExceptionGroup("upstream errors", [ + httpx2.SSEError("Server-sent event exceeded the 1024 byte limit."), + httpx2.HTTPStatusError("private-secret", request=request, response=response), + ]) + fault: Final = classify_list_exception(failure) + assert fault.tag == ("auth_required" if status_code == 401 else "forbidden") + assert list_fault_http_status(fault) == status_code + assert fault.sse_event_limit_bytes is None + + def test_wire_value_carries_no_prose(): fault = ServerListFault(tag="upstream_error", status_code=500) assert outcome_wire_value(fault) == {"status": "upstream_error", "http_status": 500} @@ -139,7 +202,7 @@ async def test_cancelled_fetch_propagates_instead_of_masquerading_as_a_healthy_e import asyncio from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager = MCPServerManager() client = MagicMock() @@ -167,8 +230,8 @@ async def test_client_side_cancelled_error_is_a_classified_fault_not_a_cancellat import asyncio from unittest.mock import AsyncMock, MagicMock - from litellm.experimental_mcp_client.client import SESSION_CLEANUP_TIMEOUT_MESSAGE - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.mcp_client.client import SESSION_CLEANUP_TIMEOUT_MESSAGE + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager = MCPServerManager() client = MagicMock() @@ -184,7 +247,7 @@ def test_auth_challenge_and_status_come_from_the_causal_response(): """An incidental 403 raised while handling the causal 401 (context chain) must not shadow it: the carrier channel and the challenge both derive from the response on the explicit causal chain, so the caller is challenged to authenticate rather than told it is forbidden.""" - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import upstream_auth_challenge + from litellm.proxy.mcp_server.faults.list_outcomes import upstream_auth_challenge causal = httpx.HTTPStatusError( "auth", @@ -214,7 +277,7 @@ def test_auth_challenge_and_status_come_from_the_causal_response(): def test_raise_classified_list_failure_routes_auth_to_upstream_auth_error(): """The single choice-point sends 401/403 through MCPUpstreamAuthError with the upstream's own challenge and everything else through MCPServerListError, so fetch sites cannot drift.""" - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import raise_classified_list_failure + from litellm.proxy.mcp_server.faults.list_outcomes import raise_classified_list_failure auth_exc = httpx.HTTPStatusError( "auth", @@ -239,7 +302,7 @@ def test_causal_auth_behind_unrelated_response_is_still_found(): """The auth scan must not end at the first response of any status: a causal 401 sitting deeper in the tree than an unrelated 5xx (retry attempts, multi-stream task groups) must still surface with its challenge, or the client is told upstream_error and never re-authenticates.""" - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import upstream_auth_challenge + from litellm.proxy.mcp_server.faults.list_outcomes import upstream_auth_challenge deep_auth = httpx.HTTPStatusError( "auth", @@ -318,7 +381,7 @@ def test_pure_non_auth_response_still_classifies_upstream_error(): def test_managed_scope_step_up_only_accepts_unambiguous_bearer_challenges(status, challenge, expected, client): import httpx2 - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import upstream_insufficient_scope + from litellm.proxy.mcp_server.faults.list_outcomes import upstream_insufficient_scope transport = httpx if client == "httpx" else httpx2 response = transport.Response(status, headers={"www-authenticate": challenge}, request=transport.Request("POST", "https://peer.test/mcp")) @@ -340,7 +403,7 @@ def _rate_limited_error(retry_after: str | None = None) -> httpx.HTTPStatusError @pytest.mark.asyncio async def test_retry_upstream_rate_limit_backs_off_then_reraises() -> None: - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import retry_upstream_rate_limit + from litellm.proxy.mcp_server.faults.list_outcomes import retry_upstream_rate_limit sleeps: Final[list[float]] = [] calls: Final[list[httpx.HTTPStatusError]] = [] @@ -372,7 +435,7 @@ async def test_retry_upstream_rate_limit_backs_off_then_reraises() -> None: @pytest.mark.asyncio async def test_retry_upstream_rate_limit_honors_retry_after_up_to_cap() -> None: - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import retry_upstream_rate_limit + from litellm.proxy.mcp_server.faults.list_outcomes import retry_upstream_rate_limit sleeps: Final[list[float]] = [] @@ -401,7 +464,7 @@ async def test_retry_upstream_rate_limit_parses_http_date_retry_after() -> None: import email.utils import time - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import retry_upstream_rate_limit + from litellm.proxy.mcp_server.faults.list_outcomes import retry_upstream_rate_limit sleeps: Final[list[float]] = [] attempts: Final[list[None]] = [] @@ -432,7 +495,7 @@ async def test_retry_upstream_rate_limit_parses_http_date_retry_after() -> None: @pytest.mark.asyncio async def test_retry_upstream_rate_limit_passes_through_non_429() -> None: - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import retry_upstream_rate_limit + from litellm.proxy.mcp_server.faults.list_outcomes import retry_upstream_rate_limit sleeps: Final[list[float]] = [] calls = 0 @@ -459,7 +522,7 @@ async def test_retry_upstream_rate_limit_passes_through_non_429() -> None: @pytest.mark.asyncio async def test_retry_upstream_rate_limit_negative_max_retries_is_a_single_attempt() -> None: - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import retry_upstream_rate_limit + from litellm.proxy.mcp_server.faults.list_outcomes import retry_upstream_rate_limit sleeps: Final[list[float]] = [] calls = 0 @@ -492,7 +555,7 @@ async def test_retry_upstream_rate_limit_negative_max_retries_is_a_single_attemp @pytest.mark.asyncio async def test_retry_deadline_skips_sleep_that_would_pass_deadline() -> None: - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import retry_upstream_rate_limit + from litellm.proxy.mcp_server.faults.list_outcomes import retry_upstream_rate_limit now: Final[list[float]] = [100.0] sleeps: Final[list[float]] = [] @@ -530,7 +593,7 @@ async def test_retry_deadline_skips_sleep_that_would_pass_deadline() -> None: async def test_retry_attempt_is_interrupted_at_deadline() -> None: import anyio - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import retry_upstream_rate_limit + from litellm.proxy.mcp_server.faults.list_outcomes import retry_upstream_rate_limit calls = 0 failure: Final = _rate_limited_error("0") @@ -556,7 +619,7 @@ async def test_retry_attempt_is_interrupted_at_deadline() -> None: async def test_retry_deadline_does_not_bound_first_attempt() -> None: import anyio - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import retry_upstream_rate_limit + from litellm.proxy.mcp_server.faults.list_outcomes import retry_upstream_rate_limit async def slow() -> str: await anyio.sleep(0.15) @@ -573,7 +636,7 @@ async def test_retry_deadline_does_not_bound_first_attempt() -> None: async def test_retry_upstream_rate_limit_never_retries_cancellation() -> None: import asyncio - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import retry_upstream_rate_limit + from litellm.proxy.mcp_server.faults.list_outcomes import retry_upstream_rate_limit sleeps: Final[list[float]] = [] calls = 0 @@ -596,7 +659,7 @@ async def test_retry_upstream_rate_limit_never_retries_cancellation() -> None: def test_listing_failed_outright_only_when_every_server_faulted_non_auth() -> None: - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.mcp_server.faults.list_outcomes import ( ServerListOk, listing_failed_outright, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/faults/test_render_oauth.py b/tests/unit/proxy/mcp_server/faults/test_render_oauth.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/faults/test_render_oauth.py rename to tests/unit/proxy/mcp_server/faults/test_render_oauth.py index a6807ae1454..49d7c14c285 100644 --- a/tests/unit/proxy/_experimental/mcp_server/faults/test_render_oauth.py +++ b/tests/unit/proxy/mcp_server/faults/test_render_oauth.py @@ -6,16 +6,16 @@ from typing import Final, Literal import pytest -from litellm.proxy._experimental.mcp_server.faults.render_oauth import ( +from litellm.proxy.mcp_server.faults.render_oauth import ( dcr_fault_detail, render_token_fault, ) -from litellm.proxy._experimental.mcp_server.faults.types import ( +from litellm.proxy.mcp_server.faults.types import ( CallerRejected, GatewayRejected, UpstreamProtocolFault, - UpstreamReportedFault, UpstreamRegistrationRefused, + UpstreamReportedFault, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/faults/test_traversal.py b/tests/unit/proxy/mcp_server/faults/test_traversal.py similarity index 95% rename from tests/unit/proxy/_experimental/mcp_server/faults/test_traversal.py rename to tests/unit/proxy/mcp_server/faults/test_traversal.py index b8bf4da1dc4..a2ba75058f3 100644 --- a/tests/unit/proxy/_experimental/mcp_server/faults/test_traversal.py +++ b/tests/unit/proxy/mcp_server/faults/test_traversal.py @@ -7,7 +7,7 @@ import sys if sys.version_info < (3, 11): # BaseExceptionGroup is a builtin only from 3.11 from exceptiongroup import BaseExceptionGroup -from litellm.proxy._experimental.mcp_server.faults import iter_exception_tree +from litellm.proxy.mcp_server.faults import iter_exception_tree def test_yields_the_root_itself_first(): diff --git a/tests/unit/proxy/mcp_server/guardrail_translation/__init__.py b/tests/unit/proxy/mcp_server/guardrail_translation/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/unit/proxy/_experimental/mcp_server/guardrail_translation/test_mcp_guardrail_handler.py b/tests/unit/proxy/mcp_server/guardrail_translation/test_mcp_guardrail_handler.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/guardrail_translation/test_mcp_guardrail_handler.py rename to tests/unit/proxy/mcp_server/guardrail_translation/test_mcp_guardrail_handler.py index f3e1bcf979f..a6f94cbd961 100644 --- a/tests/unit/proxy/_experimental/mcp_server/guardrail_translation/test_mcp_guardrail_handler.py +++ b/tests/unit/proxy/mcp_server/guardrail_translation/test_mcp_guardrail_handler.py @@ -11,11 +11,11 @@ import litellm.llms as litellm_llms from litellm.caching.caching import DualCache from litellm.exceptions import BlockedPiiEntityError from litellm.integrations.custom_guardrail import CustomGuardrail -from litellm.proxy._experimental.mcp_server.guardrail_translation.handler import ( +from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server.guardrail_translation.handler import ( MCPGuardrailTranslationHandler, ) -from litellm.proxy._experimental.mcp_server.utils import MAX_STRUCTURED_CONTENT_SCAN_DEPTH -from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server.utils import MAX_STRUCTURED_CONTENT_SCAN_DEPTH from litellm.proxy.utils import ProxyLogging from litellm.types.utils import GenericGuardrailAPIInputs @@ -698,7 +698,7 @@ async def test_structured_content_nested_too_deeply_is_blocked(): """Too deep to walk must block rather than pass the deeper values unscanned.""" from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server.utils import MAX_STRUCTURED_CONTENT_SCAN_DEPTH + from litellm.proxy.mcp_server.utils import MAX_STRUCTURED_CONTENT_SCAN_DEPTH handler = MCPGuardrailTranslationHandler() guardrail = SubstitutingGuardrail("jane@example.com", "") @@ -727,7 +727,7 @@ def test_too_deep_json_returns_a_sentinel_rather_than_raising(): the helper so this pins the contract without reloading the module and leaking that reload into other tests. """ - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( MAX_STRUCTURED_CONTENT_SCAN_DEPTH, json_string_leaves, ) diff --git a/tests/unit/proxy/mcp_server/outbound_credentials/__init__.py b/tests/unit/proxy/mcp_server/outbound_credentials/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_adapter.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_adapter.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_adapter.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_adapter.py index 9cd19e9a1c9..c39fb215ef3 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_adapter.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_adapter.py @@ -13,9 +13,9 @@ import pytest from fastapi import HTTPException from pydantic import ValidationError -from litellm.experimental_mcp_client.client import MCPClient -from litellm.proxy._experimental.mcp_server.exceptions import MCPServerURLCredentialsError -from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( +from litellm.mcp_client.client import MCPClient +from litellm.proxy.mcp_server.exceptions import MCPServerURLCredentialsError +from litellm.proxy.mcp_server.outbound_credentials.adapter import ( oauth_protected_resource_path, raise_public, raise_user_oauth_challenge, @@ -23,8 +23,8 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import to_subject, validate_static_credential, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error, Ok -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.result import Error, Ok +from litellm.proxy.mcp_server.outbound_credentials.types import ( ApiKeyConfig, AuthorizationCodeConfig, ClientCredentialsConfig, @@ -601,7 +601,7 @@ def test_raise_user_oauth_challenge_per_request_prefix_is_routable(monkeypatch): def test_raise_token_exchange_challenge_is_rfc9728_invalid_token(): - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( raise_token_exchange_challenge, ) @@ -621,7 +621,7 @@ def test_raise_token_exchange_challenge_is_rfc9728_invalid_token(): def test_raise_token_exchange_challenge_includes_server_root_path(monkeypatch): - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( raise_token_exchange_challenge, ) @@ -633,7 +633,7 @@ def test_raise_token_exchange_challenge_includes_server_root_path(monkeypatch): def test_raise_token_exchange_challenge_per_request_prefix_is_routable(monkeypatch): - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( raise_token_exchange_challenge, ) @@ -645,7 +645,7 @@ def test_raise_token_exchange_challenge_per_request_prefix_is_routable(monkeypat def test_raise_token_exchange_challenge_static_form_is_unchanged_without_step_up(): - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( raise_token_exchange_challenge, ) @@ -661,7 +661,7 @@ def test_raise_token_exchange_challenge_static_form_is_unchanged_without_step_up def test_raise_token_exchange_challenge_uses_insufficient_claims_with_claims_present(): # Per the Microsoft claims-challenge format, a claims challenge MUST use error=insufficient_claims # (the value MSAL-family clients key on), and the claims ride base64-encoded, never raw. - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( raise_token_exchange_challenge, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_authz_code_refresher.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_authz_code_refresher.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_authz_code_refresher.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_authz_code_refresher.py index 3068e5a0116..3a1bb024464 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_authz_code_refresher.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_authz_code_refresher.py @@ -2,10 +2,10 @@ import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.authz_code_refresher import ( +from litellm.proxy.mcp_server.outbound_credentials.authz_code_refresher import ( AuthorizationCodeRefresher, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) @@ -374,7 +374,7 @@ async def test_cimd_refresh_on_fresh_replica_preserves_user_and_client_identity( @pytest.mark.asyncio async def test_saved_cimd_identity_refreshes_without_discovery(monkeypatch): - from litellm.proxy._experimental.mcp_server.outbound_credentials.v2_token_store import V2PerUserTokenStore + from litellm.proxy.mcp_server.outbound_credentials.v2_token_store import V2PerUserTokenStore from litellm.types.mcp_server.mcp_server_manager import MCPServer monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_bridge_credentials.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_bridge_credentials.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_bridge_credentials.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_bridge_credentials.py index f8fb22469f1..47b6c3c2fa9 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_bridge_credentials.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_bridge_credentials.py @@ -13,7 +13,7 @@ from datetime import datetime, timedelta, timezone import pytest from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( BridgeEnvelopeAdmitted, BridgeEnvelopeInvalid, BridgeRefreshInvalid, @@ -26,7 +26,7 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credenti open_bridge_refresh_envelope, resolve_bridge_envelope, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( +from litellm.proxy.mcp_server.outbound_credentials.envelope import ( ENVELOPE_PREFIX, EnvelopeIdentity, EnvelopeKeys, @@ -117,7 +117,7 @@ def test_refresh_jwt_wearing_the_access_prefix_is_rejected_at_the_edge(): """Belt-and-suspenders against a swapped wire prefix: a refresh JWT re-prefixed as an access envelope opens far enough to hit the signed kind claim, which rejects it, so admission fails closed rather than forwarding a refresh credential's contents upstream.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import REFRESH_ENVELOPE_PREFIX + from litellm.proxy.mcp_server.outbound_credentials.envelope import REFRESH_ENVELOPE_PREFIX keys = envelope_keys_from_master_key(_MASTER_KEY) swapped = ENVELOPE_PREFIX + _sealed_refresh(keys).removeprefix(REFRESH_ENVELOPE_PREFIX) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_client_credentials.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_client_credentials.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_client_credentials.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_client_credentials.py index 77cbd8fa464..1086c374622 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_client_credentials.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_client_credentials.py @@ -10,7 +10,7 @@ import httpx2 import pytest from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials.client_credentials import ( ClientCredentialsBearerAuth, ClientCredentialsTokenSource, TokenEndpointDenied, @@ -18,8 +18,8 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credenti TokenEndpointSuccess, TokenEndpointUnreachable, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error, Ok -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.result import Error, Ok +from litellm.proxy.mcp_server.outbound_credentials.types import ( ClientCredentialsConfig, ) @@ -486,8 +486,9 @@ async def test_bearer_auth_advertises_the_header_it_will_occupy(): async def test_token_exchange_failure_diagnostics(mode, monkeypatch, caplog): import asyncio import logging + from litellm.llms.custom_httpx import http_handler - from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import post_client_credentials_grant + from litellm.proxy.mcp_server.outbound_credentials.client_credentials import post_client_credentials_grant class Poster: async def post(self, url, headers, data): @@ -557,7 +558,7 @@ def test_subscription_identity_tracks_grant_configuration(changed): def test_subscription_identity_requires_managed_grant_metadata(): - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import HeaderCarrier + from litellm.proxy.mcp_server.outbound_credentials.types import HeaderCarrier async def refetch(token: str) -> str | None: return None diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_dual_cache_token_backend.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_dual_cache_token_backend.py similarity index 95% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_dual_cache_token_backend.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_dual_cache_token_backend.py index f27bc987434..00db27a60b8 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_dual_cache_token_backend.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_dual_cache_token_backend.py @@ -2,13 +2,13 @@ import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.dual_cache_token_backend import ( +from litellm.proxy.mcp_server.outbound_credentials.dual_cache_token_backend import ( DualCacheTokenCacheBackend, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_cache_codec import ( +from litellm.proxy.mcp_server.outbound_credentials.token_cache_codec import ( OAuthTokenCacheCodec, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_envelope.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_envelope.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_envelope.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_envelope.py index bd310339a1d..6da509a0d37 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_envelope.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_envelope.py @@ -19,7 +19,8 @@ import pytest from cryptography.hazmat.primitives.asymmetric import rsa from pydantic import SecretStr, ValidationError -from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( +from litellm.proxy.common_utils.encrypt_decrypt_utils import decrypt_value, encrypt_value +from litellm.proxy.mcp_server.outbound_credentials.envelope import ( ENVELOPE_ISSUER, ENVELOPE_PREFIX, MAX_ENVELOPE_BYTES, @@ -50,7 +51,6 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import open_refresh_envelope, user_identity, ) -from litellm.proxy.common_utils.encrypt_decrypt_utils import decrypt_value, encrypt_value _NOW = datetime(2026, 7, 9, 12, 0, 0, tzinfo=timezone.utc) _SIGNING_KEY = "unit-test-signing-key-0123456789abcdef0123456789abcdef" @@ -480,7 +480,7 @@ def test_open_size_guard_measures_bytes_not_characters(): _decode_claims to fail loudly proves the guard short-circuits before decode.""" from unittest.mock import patch - from litellm.proxy._experimental.mcp_server.outbound_credentials import envelope + from litellm.proxy.mcp_server.outbound_credentials import envelope multibyte_body = "é" * 7000 # 7000 chars, 14000 UTF-8 bytes candidate = ENVELOPE_PREFIX + multibyte_body @@ -500,7 +500,7 @@ def test_open_size_guard_rejects_oversize_character_count_before_decode(): character precheck makes this O(1) since UTF-8 byte length is never below character length.""" from unittest.mock import patch - from litellm.proxy._experimental.mcp_server.outbound_credentials import envelope + from litellm.proxy.mcp_server.outbound_credentials import envelope candidate = ENVELOPE_PREFIX + ("a" * (MAX_ENVELOPE_BYTES + 1)) assert len(candidate) > MAX_ENVELOPE_BYTES diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_httpx_auth.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_httpx_auth.py similarity index 95% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_httpx_auth.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_httpx_auth.py index 5a5eea60fce..aa75f52b540 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_httpx_auth.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_httpx_auth.py @@ -6,7 +6,7 @@ pin the header emission the api_key family and passthrough depend on. import httpx2 -from litellm.proxy._experimental.mcp_server.outbound_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials import ( NoOpAuth, StaticHeaderAuth, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_login_assertion_exchange.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_login_assertion_exchange.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_login_assertion_exchange.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_login_assertion_exchange.py index ab2b5b3d966..754a56c2f00 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_login_assertion_exchange.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_login_assertion_exchange.py @@ -7,22 +7,23 @@ from datetime import datetime, timedelta, timezone import pytest from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.outbound_credentials.login_assertion_exchange import ( +from litellm.proxy._types import LiteLLM_MCPServerTable +from litellm.proxy.mcp_server.outbound_credentials.login_assertion_exchange import ( exchange_login_assertion_for_refresh_token, login_exchange_servers, refresh_token_exchange_targets, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error, Ok, Result -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_refresher import SSOClientConfig -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( +from litellm.proxy.mcp_server.outbound_credentials.result import Error, Ok, Result +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_refresher import SSOClientConfig +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( SAML2_SUBJECT_TOKEN_TYPE, SSOIdentityAssertion, assertion_from_saml_login, login_refresh_token_expired, with_login_refresh_token, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_endpoint import ExchangedToken -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.token_endpoint import ExchangedToken +from litellm.proxy.mcp_server.outbound_credentials.types import ( ClientAuth, ClientSecretAuth, CredError, @@ -32,7 +33,6 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( NoneConfig, ServerSpec, ) -from litellm.proxy._types import LiteLLM_MCPServerTable from litellm.types.mcp import MCPAuth, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_oauth_token_store.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_oauth_token_store.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_oauth_token_store.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_oauth_token_store.py index d72afaf46b6..88d095e53ab 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_oauth_token_store.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_oauth_token_store.py @@ -5,7 +5,7 @@ from typing import Dict, List, Optional, Tuple import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( CachedOAuthTokenStore, OAuthToken, RefreshingTokenStore, diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_per_user_oauth_store.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_per_user_oauth_store.py similarity index 92% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_per_user_oauth_store.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_per_user_oauth_store.py index 5e2bb0f3722..621e206b74c 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_per_user_oauth_store.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_per_user_oauth_store.py @@ -2,11 +2,11 @@ import asyncio import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( InvalidatableOAuthTokenStore, OAuthToken, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.per_user_oauth_store import ( +from litellm.proxy.mcp_server.outbound_credentials.per_user_oauth_store import ( LazyPerUserOAuthTokenStore, ServerLookup, ) @@ -43,8 +43,8 @@ def credential_database(monkeypatch): @pytest.mark.asyncio @pytest.mark.parametrize("scopes, expected", [(None, None), ((), []), (("read",), ["read"])]) async def test_credential_persistence_preserves_known_and_unknown_scopes(credential_database, scopes, expected): - from litellm.proxy._experimental.mcp_server.db import decode_oauth_payload - from litellm.proxy._experimental.mcp_server.outbound_credentials.per_user_oauth_store import _persist_credential + from litellm.proxy.mcp_server.db import decode_oauth_payload + from litellm.proxy.mcp_server.outbound_credentials.per_user_oauth_store import _persist_credential await _persist_credential("alice", "srv", "access", "refresh", 60, scopes) row = credential_database.upsert.call_args.kwargs["data"]["create"] @@ -61,9 +61,9 @@ async def test_credential_persistence_preserves_known_and_unknown_scopes(credent async def test_native_refresh_persists_actual_grant_through_storage_adapter( credential_database, prior_scopes, response_scope, expected, ): - from litellm.proxy._experimental.mcp_server.db import decode_oauth_payload - from litellm.proxy._experimental.mcp_server.outbound_credentials.authz_code_refresher import AuthorizationCodeRefresher - from litellm.proxy._experimental.mcp_server.outbound_credentials.per_user_oauth_store import _persist_credential + from litellm.proxy.mcp_server.db import decode_oauth_payload + from litellm.proxy.mcp_server.outbound_credentials.authz_code_refresher import AuthorizationCodeRefresher + from litellm.proxy.mcp_server.outbound_credentials.per_user_oauth_store import _persist_credential from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -337,8 +337,8 @@ async def test_enforcement_invalidates_cached_legacy_credentials_before_use(): async def test_enforced_cache_hit_avoids_credential_read_and_rejects_changed_policy(monkeypatch): from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server.oauth_identity_binding import current_binding_proof - from litellm.proxy._experimental.mcp_server.outbound_credentials import per_user_oauth_store as module + from litellm.proxy.mcp_server.oauth_identity_binding import current_binding_proof + from litellm.proxy.mcp_server.outbound_credentials import per_user_oauth_store as module from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -373,7 +373,7 @@ async def test_enforced_cache_hit_avoids_credential_read_and_rejects_changed_pol async def test_expired_unverified_credential_never_reaches_refresh(monkeypatch): from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server.outbound_credentials import per_user_oauth_store as module + from litellm.proxy.mcp_server.outbound_credentials import per_user_oauth_store as module from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_presented_token_store.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_presented_token_store.py similarity index 73% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_presented_token_store.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_presented_token_store.py index 8b715fa717b..cc7f2236e6f 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_presented_token_store.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_presented_token_store.py @@ -2,10 +2,10 @@ import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.presented_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.presented_token_store import ( PresentedOAuthTokenStore, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_redis_distributed_lock.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_redis_distributed_lock.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_redis_distributed_lock.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_redis_distributed_lock.py index e06f3bcd5cf..d50ef6d6ba6 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_redis_distributed_lock.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_redis_distributed_lock.py @@ -2,10 +2,10 @@ import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.redis_distributed_lock import ( +from litellm.proxy.mcp_server.outbound_credentials.redis_distributed_lock import ( RedisDistributedLock, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.redis_refresh_coordinator import ( +from litellm.proxy.mcp_server.outbound_credentials.redis_refresh_coordinator import ( LockAcquisition, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_redis_refresh_coordinator.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_redis_refresh_coordinator.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_redis_refresh_coordinator.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_redis_refresh_coordinator.py index a6831562018..18bd4a66b65 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_redis_refresh_coordinator.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_redis_refresh_coordinator.py @@ -4,10 +4,10 @@ import asyncio import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.redis_refresh_coordinator import ( +from litellm.proxy.mcp_server.outbound_credentials.redis_refresh_coordinator import ( LockAcquisition, RedisRefreshCoordinator, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_resolver.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_resolver.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_resolver.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_resolver.py index 527475b86a9..f832f9560bd 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_resolver.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_resolver.py @@ -19,7 +19,7 @@ import jwt as pyjwt import pytest from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.outbound_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials import ( ApiKeyConfig, AuthConfig, AuthorizationCodeConfig, @@ -46,23 +46,23 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials import ( TokenExchangeConfig, UpstreamCredentialProvider, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, TokenStoreUnavailable, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_refresher import ( +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_refresher import ( RefreshingSSOAssertionStore, SSOAssertionRefresher, SSOClientConfig, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( SAML2_SUBJECT_TOKEN_TYPE, AssertionStoreUnavailable, SSOIdentityAssertion, assertion_from_saml_login, with_login_refresh_token, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_endpoint import ( +from litellm.proxy.mcp_server.outbound_credentials.token_endpoint import ( ExchangedToken, ) @@ -1314,7 +1314,7 @@ async def test_passthrough_ignores_the_carrier_and_keeps_the_callers_slot(): async def test_resolved_source_matches_the_credential_sent_upstream( config: AuthConfig, subject: Subject, expected_source: str, expected_header: str | None ) -> None: - from litellm.proxy._experimental.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source + from litellm.proxy.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source store = _FakeTokenStore({("alice", "s"): OAuthToken(access_token="stored-alice")}) provider = UpstreamCredentialProvider(oauth_token_store=store) @@ -1328,7 +1328,7 @@ async def test_resolved_source_matches_the_credential_sent_upstream( @pytest.mark.asyncio async def test_resolved_source_preserves_missing_user_token_error() -> None: - from litellm.proxy._experimental.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source + from litellm.proxy.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source result = await resolve_credentials_with_source( UpstreamCredentialProvider(), _SUBJECT, _spec(AuthorizationCodeConfig()) @@ -1339,7 +1339,7 @@ async def test_resolved_source_preserves_missing_user_token_error() -> None: @pytest.mark.asyncio async def test_minted_token_sources_match_egress_and_do_not_fetch_twice() -> None: - from litellm.proxy._experimental.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source + from litellm.proxy.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source source = _FakeM2MSource(Ok(OAuthToken(access_token="m2m-at"))) m2m = await resolve_credentials_with_source( @@ -1363,7 +1363,7 @@ async def test_minted_token_sources_match_egress_and_do_not_fetch_twice() -> Non @pytest.mark.asyncio async def test_id_jag_source_describes_final_token_after_both_exchanges() -> None: - from litellm.proxy._experimental.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source + from litellm.proxy.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source endpoint = _FakeTokenEndpoint(_two_leg_ok("resource-token")) provider = UpstreamCredentialProvider(token_endpoint=endpoint) @@ -1382,7 +1382,7 @@ async def test_client_credentials_subscription_identity_preserves_resolved_grant _SUBJECT, _spec(_M2M) ) assert isinstance(result, Ok) - from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.client_credentials import ( ClientCredentialsBearerAuth, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_result.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_result.py similarity index 90% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_result.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_result.py index 5d26a530214..96288a62c9a 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_result.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_result.py @@ -6,7 +6,7 @@ the runtime contract consumers rely on: each arm carries its payload and discrim type. The union is exercised for real where it is used (see PR2's parse_auth_spec_kind). """ -from litellm.proxy._experimental.mcp_server.outbound_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials import ( Error, Ok, Result, diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_session_credentials.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_session_credentials.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_session_credentials.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_session_credentials.py index a49c43bedb5..f084d5c7d1d 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_session_credentials.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_session_credentials.py @@ -8,10 +8,10 @@ from cryptography.hazmat.primitives.asymmetric import rsa from jwt.utils import base64url_decode, base64url_encode from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( envelope_keys_from_master_key, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials.session_credentials import ( NotSessionBearer, SessionBearerAdmitted, SessionBearerInvalid, @@ -24,7 +24,7 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credent resolve_session_signing_keys, session_keys_from_master_key, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import ( +from litellm.proxy.mcp_server.outbound_credentials.session_token import ( SESSION_TTL_SECONDS, AsymmetricSessionKeys, MintedSessionToken, diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_session_token.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_session_token.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_session_token.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_session_token.py index 641aca2446e..2e648fb86ed 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_session_token.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_session_token.py @@ -9,7 +9,7 @@ from cryptography.hazmat.primitives.asymmetric import rsa from jwt.utils import base64url_decode, base64url_encode from pydantic import SecretStr, ValidationError -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import ( +from litellm.proxy.mcp_server.outbound_credentials.session_token import ( MAX_SESSION_TOKEN_BYTES, SESSION_ISSUER, SESSION_REFRESH_PREFIX, diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_sso_assertion_refresher.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_sso_assertion_refresher.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_sso_assertion_refresher.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_sso_assertion_refresher.py index 53d0d82a7f2..38d203bd77d 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_sso_assertion_refresher.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_sso_assertion_refresher.py @@ -20,12 +20,12 @@ import jwt as pyjwt import pytest from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( +from litellm.proxy.mcp_server.outbound_credentials.result import ( Error, Ok, Result, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_refresher import ( +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_refresher import ( HttpxTokenEndpointTransport, RefreshFailure, RefreshingSSOAssertionStore, @@ -34,11 +34,11 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_r default_sso_assertion_store, sso_client_config, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( - with_login_refresh_token, +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( AssertionStoreUnavailable, SSOIdentityAssertion, assertion_from_saml_login, + with_login_refresh_token, ) SIGNING_KEY = "test-idp-signing-key-32-bytes-long-xxxx" diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_sso_assertion_store.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_sso_assertion_store.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_sso_assertion_store.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_sso_assertion_store.py index 3c8e7a9b448..8bcd802d497 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_sso_assertion_store.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_sso_assertion_store.py @@ -18,7 +18,8 @@ from unittest.mock import AsyncMock, MagicMock, patch import jwt as pyjwt import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( +from litellm.proxy.common_utils.encrypt_decrypt_utils import decrypt_value_helper, encrypt_value_helper +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( _ASSERTION_CACHE, SAML2_SUBJECT_TOKEN_TYPE, AssertionStoreUnavailable, @@ -35,7 +36,6 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_s rotate_sso_identity_assertions_master_key, with_login_refresh_token, ) -from litellm.proxy.common_utils.encrypt_decrypt_utils import decrypt_value_helper, encrypt_value_helper from litellm.types.mcp import MCPAuth SALT_KEY = "test-salt-key-for-sso-assertion-tests-1234" @@ -184,7 +184,7 @@ def test_assertion_without_exp_or_iss_still_retained(): @pytest.mark.asyncio async def test_retention_gate_requires_an_id_jag_server(): with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, patch("litellm.proxy.proxy_server.prisma_client", _make_prisma({}, db_has_id_jag_server=False)), ): manager.config_mcp_servers = { @@ -203,7 +203,7 @@ async def test_retention_gate_requires_an_id_jag_server(): async def test_retention_gate_reads_the_db_when_config_declares_no_id_jag_server(): """A DB-backed server added on another pod (or before this pod's DB load) must still enable retention off the authoritative DB row; False only when neither authority knows one.""" - with patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager: + with patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager: manager.config_mcp_servers = {"s1": _server_with_auth(MCPAuth.oauth2)} db_backed = _make_prisma({}, db_has_id_jag_server=True) with patch("litellm.proxy.proxy_server.prisma_client", db_backed): @@ -223,7 +223,7 @@ async def test_retention_gate_never_consults_the_registry_snapshot(): judge only the config declaration and the DB row, so a stale snapshot listing an id_jag server changes nothing.""" with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, patch("litellm.proxy.proxy_server.prisma_client", _make_prisma({}, db_has_id_jag_server=False)), ): manager.config_mcp_servers = {} @@ -237,7 +237,7 @@ async def test_retain_persists_when_only_the_db_knows_the_id_jag_server(): stored = {} prisma = _make_prisma(stored, db_has_id_jag_server=True) with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, patch("litellm.proxy.proxy_server.prisma_client", prisma), ): manager.config_mcp_servers = {} @@ -460,7 +460,7 @@ async def test_retain_noop_when_no_id_jag_server(): stored = {} prisma = _make_prisma(stored) with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, patch("litellm.proxy.proxy_server.prisma_client", prisma), ): manager.config_mcp_servers = {"s1": _server_with_auth(MCPAuth.oauth2)} @@ -476,7 +476,7 @@ async def test_retain_persists_when_id_jag_server_registered(): stored = {} prisma = _make_prisma(stored) with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, patch("litellm.proxy.proxy_server.prisma_client", prisma), ): manager.config_mcp_servers = {"s1": _server_with_auth(MCPAuth.oauth2_id_jag)} @@ -490,7 +490,7 @@ async def test_retain_persists_when_id_jag_server_registered(): async def test_retain_none_assertion_never_consults_gate_or_store(): gate = MagicMock() with patch( - "litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store.ema_assertion_retention_enabled", + "litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store.ema_assertion_retention_enabled", gate, ): await retain_sso_identity_assertion_for_ema(user_id="user-a", assertion=None) @@ -502,7 +502,7 @@ async def test_retain_swallows_store_failure(): prisma = MagicMock() prisma.db.litellm_ssoidentityassertion.upsert = AsyncMock(side_effect=RuntimeError("db down")) with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, patch("litellm.proxy.proxy_server.prisma_client", prisma), ): manager.config_mcp_servers = {"s1": _server_with_auth(MCPAuth.oauth2_id_jag)} diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_cache_codec.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_token_cache_codec.py similarity index 93% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_cache_codec.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_token_cache_codec.py index 12a04c4b4dc..d3cb701df33 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_cache_codec.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_token_cache_codec.py @@ -1,9 +1,9 @@ """Tests for the cache codec: encrypt on encode, drop the refresh_token, round-trip the bearer.""" -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_cache_codec import ( +from litellm.proxy.mcp_server.outbound_credentials.token_cache_codec import ( OAuthTokenCacheCodec, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_endpoint.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_token_endpoint.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_endpoint.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_token_endpoint.py index db3a1a386a3..e9b2b8ba589 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_endpoint.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_token_endpoint.py @@ -13,31 +13,31 @@ from unittest.mock import AsyncMock, MagicMock, patch import httpx import jwt -import litellm import pytest from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa +from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( +import litellm +from litellm.proxy.mcp_server.outbound_credentials.result import ( Error, Ok, Result, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_endpoint import ( +from litellm.proxy.mcp_server.outbound_credentials.token_endpoint import ( CLIENT_ASSERTION_TYPE, ExchangedToken, ExchangedTokenCache, TokenEndpointClient, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.types import ( ClientSecretAuth, CredError, PrivateKeyJwtAuth, ) -from pydantic import SecretStr _PATCH_TARGET = ( - "litellm.proxy._experimental.mcp_server.outbound_credentials." + "litellm.proxy.mcp_server.outbound_credentials." "token_endpoint.get_async_httpx_client" ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_exchange_provider.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_token_exchange_provider.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_exchange_provider.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_token_exchange_provider.py index cf15fdb3e26..40a10053dd2 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_exchange_provider.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_token_exchange_provider.py @@ -8,11 +8,11 @@ from unittest.mock import patch import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchange_provider import ( +from litellm.proxy.mcp_server.outbound_credentials.token_exchange_provider import ( _post_exchange_endpoint, build_token_exchanger, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchanger import ( +from litellm.proxy.mcp_server.outbound_credentials.token_exchanger import ( OboTokenExchanger, SubjectTokenRejected, TokenExchangeClientError, diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_exchanger.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_token_exchanger.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_exchanger.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_token_exchanger.py index f2750cc3632..e1930931b03 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_exchanger.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_token_exchanger.py @@ -9,15 +9,15 @@ import asyncio import pytest from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.outbound_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials import ( Error, Ok, ServerSpec, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchanger import ( +from litellm.proxy.mcp_server.outbound_credentials.token_exchanger import ( OboTokenExchanger, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.types import ( TokenExchangeConfig, ) @@ -127,7 +127,7 @@ async def test_client_secret_post_keeps_creds_in_body_with_no_auth_header(): async def test_exchange_maps_idp_rejection_to_unauthorized(): """An IdP 4xx (surfaced as SubjectTokenRejected by the post adapter) is non-retryable: it maps to ``unauthorized`` (the 401 OBO challenge), not the retryable ``upstream_unavailable`` (503).""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchanger import ( + from litellm.proxy.mcp_server.outbound_credentials.token_exchanger import ( SubjectTokenRejected, ) @@ -144,7 +144,7 @@ async def test_exchange_maps_gateway_fault_to_misconfigured(): """A gateway-fault RFC 6749 code (invalid_client / invalid_target / ..., surfaced as TokenExchangeClientError) is the gateway's problem, not the caller's, so it maps to misconfigured (500) rather than the retryable 503 or the 401 OBO challenge the caller can't act on.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchanger import ( + from litellm.proxy.mcp_server.outbound_credentials.token_exchanger import ( TokenExchangeClientError, ) @@ -298,7 +298,7 @@ async def test_non_bearer_token_type_is_logged(): post = _RecordingPost({"access_token": "x", "token_type": "N_A", "expires_in": 3600}) with patch( - "litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchanger.verbose_logger" + "litellm.proxy.mcp_server.outbound_credentials.token_exchanger.verbose_logger" ) as mock_logger: await OboTokenExchanger(post, clock=_Clock()).exchange("jwt", _SERVER, _CONFIG) assert mock_logger.warning.called @@ -542,7 +542,7 @@ async def test_distributed_coordinator_refresh_and_reread_use_the_cache(): @pytest.mark.asyncio async def test_step_up_rejection_threads_claims_into_unauthorized(): - from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchanger import ( + from litellm.proxy.mcp_server.outbound_credentials.token_exchanger import ( SubjectTokenRejected, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_types.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_types.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_types.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_types.py index 7f5c17de8b4..1f50444f09e 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_types.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_types.py @@ -10,7 +10,7 @@ corresponding guarantee is mutated away. import pytest from pydantic import SecretStr, TypeAdapter, ValidationError -from litellm.proxy._experimental.mcp_server.outbound_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials import ( Ambient, ApiKeyConfig, AuthConfig, diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_v2_token_store.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_v2_token_store.py similarity index 95% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_v2_token_store.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_v2_token_store.py index 97d14b65f5a..f531491cfa3 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_v2_token_store.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_v2_token_store.py @@ -2,7 +2,7 @@ import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.v2_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.v2_token_store import ( V2PerUserTokenStore, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_byok_credential_cache.py b/tests/unit/proxy/mcp_server/test_byok_credential_cache.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/test_byok_credential_cache.py rename to tests/unit/proxy/mcp_server/test_byok_credential_cache.py index 0ec4b431276..7ca169366a6 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_byok_credential_cache.py +++ b/tests/unit/proxy/mcp_server/test_byok_credential_cache.py @@ -2,15 +2,15 @@ import json import pytest -from litellm.proxy._experimental.mcp_server.byok_credential_cache import ( +from litellm.proxy.common_utils.auth_cache_invalidation_pubsub import AuthCacheInvalidationSubscriber +from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache +from litellm.proxy.mcp_server.byok_credential_cache import ( CachedByokCredential, byok_credential_cache, byok_credential_cache_key, cache_byok_credential, get_cached_byok_credential, ) -from litellm.proxy.common_utils.auth_cache_invalidation_pubsub import AuthCacheInvalidationSubscriber -from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache class _FakeRedisCache: diff --git a/tests/unit/proxy/_experimental/mcp_server/test_byok_oauth_endpoints.py b/tests/unit/proxy/mcp_server/test_byok_oauth_endpoints.py similarity index 92% rename from tests/unit/proxy/_experimental/mcp_server/test_byok_oauth_endpoints.py rename to tests/unit/proxy/mcp_server/test_byok_oauth_endpoints.py index b2364647e53..37da00ab2ba 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_byok_oauth_endpoints.py +++ b/tests/unit/proxy/mcp_server/test_byok_oauth_endpoints.py @@ -1,4 +1,5 @@ -from litellm.proxy._experimental.mcp_server import operations as mcp_operations +from litellm.proxy.mcp_server import operations as mcp_operations + """ Unit tests for the BYOK OAuth 2.1 authorization server endpoints. @@ -23,12 +24,12 @@ import pytest from fastapi import HTTPException from fastapi.testclient import TestClient -from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( +from litellm.proxy._types import MCPTransport +from litellm.proxy.mcp_server.byok_oauth_endpoints import ( _byok_auth_codes, _verify_pkce, router, ) -from litellm.proxy._types import MCPTransport # --------------------------------------------------------------------------- # _verify_pkce @@ -64,10 +65,10 @@ def test_verify_pkce_tampered_challenge(): from fastapi import FastAPI -from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( +from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server.byok_oauth_endpoints import ( _byok_session_auth, ) -from litellm.proxy._types import UserAPIKeyAuth _test_app = FastAPI() _test_app.include_router(router) @@ -101,8 +102,8 @@ def unauthenticated_client(): @pytest.mark.parametrize("byok_first", [True, False]) def test_byok_challenge_discovers_api_key_flow(monkeypatch, byok_first): - from litellm.proxy._experimental.mcp_server import byok_oauth_endpoints, discoverable_endpoints - from litellm.proxy._experimental.mcp_server.oauth_utils import get_byok_www_authenticate + from litellm.proxy.mcp_server import byok_oauth_endpoints, discoverable_endpoints + from litellm.proxy.mcp_server.oauth_utils import get_byok_www_authenticate monkeypatch.delenv("PROXY_BASE_URL", raising=False) monkeypatch.delenv("SERVER_ROOT_PATH", raising=False) @@ -137,7 +138,7 @@ def test_byok_challenge_discovers_api_key_flow(monkeypatch, byok_first): ], ) def test_byok_challenge_preserves_external_base(monkeypatch, base_url, root_path, expected): - from litellm.proxy._experimental.mcp_server.oauth_utils import get_byok_www_authenticate + from litellm.proxy.mcp_server.oauth_utils import get_byok_www_authenticate monkeypatch.setenv("PROXY_BASE_URL", base_url) monkeypatch.setenv("SERVER_ROOT_PATH", root_path) @@ -147,7 +148,7 @@ def test_byok_challenge_preserves_external_base(monkeypatch, base_url, root_path def test_byok_discovery_preserves_per_request_prefixes(monkeypatch): from fastapi import FastAPI - from litellm.proxy._experimental.mcp_server.server import _check_byok_credential + from litellm.proxy.mcp_server.server import _check_byok_credential from litellm.proxy.middleware.per_request_root_path_middleware import PerRequestRootPathMiddleware from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -385,25 +386,25 @@ async def test_token_endpoint_success(): with ( patch( - "litellm.proxy._experimental.mcp_server.byok_oauth_endpoints.store_user_credential", + "litellm.proxy.mcp_server.byok_oauth_endpoints.store_user_credential", mock_store, ), patch( - "litellm.proxy._experimental.mcp_server.byok_oauth_endpoints.router", + "litellm.proxy.mcp_server.byok_oauth_endpoints.router", ), ): # Import the actual handler function directly - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( byok_token, ) mock_request = MagicMock() # Patch module-level globals in the function's module with patch( - "litellm.proxy._experimental.mcp_server.byok_oauth_endpoints.store_user_credential", + "litellm.proxy.mcp_server.byok_oauth_endpoints.store_user_credential", mock_store, ): - import litellm.proxy._experimental.mcp_server.byok_oauth_endpoints as mod + import litellm.proxy.mcp_server.byok_oauth_endpoints as mod original_prisma = None original_master_key = None @@ -454,7 +455,7 @@ async def test_token_endpoint_success(): @pytest.mark.asyncio async def test_token_endpoint_invalid_code(): - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import byok_token + from litellm.proxy.mcp_server.byok_oauth_endpoints import byok_token mock_request = MagicMock() with ( @@ -486,7 +487,7 @@ async def test_token_endpoint_expired_code(): ttl=-10, # already expired ) - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import byok_token + from litellm.proxy.mcp_server.byok_oauth_endpoints import byok_token mock_request = MagicMock() with ( @@ -517,7 +518,7 @@ async def test_token_endpoint_wrong_verifier(): redirect_uri="http://127.0.0.1:3000/cb", ) - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import byok_token + from litellm.proxy.mcp_server.byok_oauth_endpoints import byok_token mock_request = MagicMock() with ( @@ -538,7 +539,7 @@ async def test_token_endpoint_wrong_verifier(): @pytest.mark.asyncio async def test_token_endpoint_unsupported_grant_type(): - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import byok_token + from litellm.proxy.mcp_server.byok_oauth_endpoints import byok_token mock_request = MagicMock() with ( @@ -565,7 +566,7 @@ async def test_token_endpoint_unsupported_grant_type(): @pytest.mark.asyncio async def test_check_byok_credential_not_byok(): """Non-BYOK servers should pass through without any DB check.""" - from litellm.proxy._experimental.mcp_server.server import _check_byok_credential + from litellm.proxy.mcp_server.server import _check_byok_credential from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -581,7 +582,7 @@ async def test_check_byok_credential_not_byok(): @pytest.mark.asyncio async def test_check_byok_credential_no_user_id(): """BYOK server with no user identity → 401.""" - from litellm.proxy._experimental.mcp_server.server import _check_byok_credential + from litellm.proxy.mcp_server.server import _check_byok_credential from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -601,8 +602,8 @@ async def test_check_byok_credential_no_user_id(): @pytest.mark.asyncio async def test_check_byok_credential_missing_credential(monkeypatch): """BYOK server with a known user but no stored credential → 401.""" - from litellm.proxy._experimental.mcp_server.server import _check_byok_credential from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import _check_byok_credential from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -613,7 +614,7 @@ async def test_check_byok_credential_missing_credential(monkeypatch): ) user_auth = UserAPIKeyAuth(user_id="user-99", api_key="sk-test") - from litellm.proxy._experimental.mcp_server import server as server_module + from litellm.proxy.mcp_server import server as server_module monkeypatch.delenv("PROXY_BASE_URL", raising=False) monkeypatch.delenv("SERVER_ROOT_PATH", raising=False) @@ -622,7 +623,7 @@ async def test_check_byok_credential_missing_credential(monkeypatch): with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_user_credential", + "litellm.proxy.mcp_server.db.get_user_credential", new=AsyncMock(return_value=None), ), patch("litellm.proxy.proxy_server.prisma_client", mock_prisma), @@ -647,9 +648,9 @@ async def test_check_byok_credential_missing_credential(monkeypatch): async def test_execute_byok_tool_missing_credential_advertises_api_key_flow(monkeypatch): from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server import server as mcp_module from litellm.proxy import proxy_server from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server import server as mcp_module from litellm.types.mcp_server.mcp_server_manager import MCPServer monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com/proxy") @@ -680,8 +681,8 @@ async def test_execute_byok_tool_missing_credential_advertises_api_key_flow(monk @pytest.mark.asyncio async def test_check_byok_credential_has_credential(): """BYOK server with a valid stored credential → no error raised.""" - from litellm.proxy._experimental.mcp_server.server import _check_byok_credential from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import _check_byok_credential from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -696,7 +697,7 @@ async def test_check_byok_credential_has_credential(): with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_user_credential", + "litellm.proxy.mcp_server.db.get_user_credential", new=AsyncMock(return_value="some-credential-value"), ), patch("litellm.proxy.proxy_server.prisma_client", mock_prisma), @@ -708,9 +709,9 @@ async def test_check_byok_credential_has_credential(): @pytest.mark.asyncio async def test_invalidate_byok_cred_cache_evicts_locally_and_broadcasts_the_same_key(): """A revoked credential must stop being served here and on every peer worker within the TTL.""" - from litellm.proxy._experimental.mcp_server import server as server_module - from litellm.proxy._experimental.mcp_server.byok_credential_cache import byok_credential_cache_key from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server import server as server_module + from litellm.proxy.mcp_server.byok_credential_cache import byok_credential_cache_key from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer(server_id="byok-revoke", name="byok-server", transport=MCPTransport.http, is_byok=True) @@ -721,7 +722,7 @@ async def test_invalidate_byok_cred_cache_evicts_locally_and_broadcasts_the_same with ( patch( # test-quality-ok: the DB row lookup is the only seam below the credential resolver; no Prisma fake exists - "litellm.proxy._experimental.mcp_server.db.get_user_credential", new=db_lookup + "litellm.proxy.mcp_server.db.get_user_credential", new=db_lookup ), patch( # test-quality-ok: the resolver reads the module-level prisma_client singleton; the suite's only seam "litellm.proxy.proxy_server.prisma_client", MagicMock() @@ -746,8 +747,8 @@ async def test_check_byok_credential_db_unavailable_fails_closed(): Regression for GHSA-6762: previously returned silently, bypassing the ownership check during DB outage windows. """ - from litellm.proxy._experimental.mcp_server.server import _check_byok_credential from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import _check_byok_credential from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -859,7 +860,7 @@ async def test_token_endpoint_rejects_missing_user_id_in_code_record(): """Defense in depth: if a code record somehow lacks user_id (older format / manual DB write), /token must reject rather than fall back to the form's client_id.""" - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( byok_token, ) @@ -1050,7 +1051,7 @@ def test_authorize_post_rejects_non_loopback_redirect_uri(client): async def test_token_endpoint_rejects_redirect_uri_mismatch(): """RFC 6749 §4.1.3 / OAuth 2.1 §4.1.3: if redirect_uri was sent at /authorize, the /token redirect_uri MUST match exactly.""" - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( byok_token, ) @@ -1104,7 +1105,7 @@ async def test_token_endpoint_accepts_spec_compliant_client_id(): identifier, not the user. It must not be cross-checked against the record's user_id — that cross-check would break spec-compliant MCP clients that pass e.g. client_id="claude-desktop".""" - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( byok_token, ) @@ -1122,7 +1123,7 @@ async def test_token_endpoint_accepts_spec_compliant_client_id(): with ( patch( - "litellm.proxy._experimental.mcp_server.byok_oauth_endpoints.store_user_credential", + "litellm.proxy.mcp_server.byok_oauth_endpoints.store_user_credential", new=AsyncMock(), ), patch("litellm.proxy.proxy_server.master_key", "test-master"), @@ -1146,7 +1147,7 @@ async def test_token_endpoint_rejects_client_id_mismatch(): client_id, the token request must submit the same value. An attacker who steals a code from another client (different native app) can't redeem it.""" - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( byok_token, ) @@ -1220,7 +1221,7 @@ async def test_token_endpoint_missing_master_key_preserves_code_and_db(): code or writing the credential — otherwise a misconfigured deploy burns the code and persists the key with no way for the user to retrieve a session token without restarting the flow.""" - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( byok_token, ) @@ -1240,7 +1241,7 @@ async def test_token_endpoint_missing_master_key_preserves_code_and_db(): mock_store = AsyncMock() with ( patch( - "litellm.proxy._experimental.mcp_server.byok_oauth_endpoints.store_user_credential", + "litellm.proxy.mcp_server.byok_oauth_endpoints.store_user_credential", mock_store, ), patch("litellm.proxy.proxy_server.prisma_client", MagicMock()), @@ -1308,7 +1309,7 @@ async def test_token_endpoint_accepts_oauth21_client_omitting_redirect_uri(): Enforcement still fires when the client DOES submit a value that disagrees with the record (see test_token_endpoint_rejects_redirect_uri_mismatch). """ - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( byok_token, ) @@ -1327,7 +1328,7 @@ async def test_token_endpoint_accepts_oauth21_client_omitting_redirect_uri(): with ( patch( - "litellm.proxy._experimental.mcp_server.byok_oauth_endpoints.store_user_credential", + "litellm.proxy.mcp_server.byok_oauth_endpoints.store_user_credential", new=AsyncMock(), ), patch("litellm.proxy.proxy_server.master_key", "test-master"), @@ -1345,7 +1346,7 @@ async def test_token_endpoint_accepts_oauth21_client_omitting_redirect_uri(): def test_validate_loopback_redirect_uri_rejects_fragment(): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_loopback_redirect_uri, ) @@ -1357,7 +1358,7 @@ def test_validate_loopback_redirect_uri_rejects_fragment(): def test_validate_loopback_redirect_uri_rejects_malformed_cleanly(): """Malformed / unparseable URIs should surface as 400 invalid_request, not a 500 from an unhandled exception inside ip_address().""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_loopback_redirect_uri, ) @@ -1388,7 +1389,7 @@ def _make_trusted_request(base_url: str = "https://llm.example.com/"): def test_validate_trusted_redirect_uri_accepts_same_origin(): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1401,7 +1402,7 @@ def test_validate_trusted_redirect_uri_same_origin_normalizes_default_port(): otherwise produce a proxy_base of ``https://llm.example.com:443`` which wouldn't literally match the browser's port-less ``llm.example.com`` redirect_uri even though both represent the same origin.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1415,7 +1416,7 @@ def test_validate_trusted_redirect_uri_same_origin_normalizes_default_port(): def test_validate_trusted_redirect_uri_accepts_loopback(): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1432,7 +1433,7 @@ def test_validate_trusted_redirect_uri_accepts_loopback(): def test_validate_trusted_redirect_uri_rejects_cross_origin_by_default( monkeypatch, ): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1444,7 +1445,7 @@ def test_validate_trusted_redirect_uri_rejects_cross_origin_by_default( def test_validate_trusted_redirect_uri_rejects_fragment_and_bad_scheme(): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1460,7 +1461,7 @@ def test_validate_trusted_redirect_uri_rejects_fragment_and_bad_scheme(): def test_validate_trusted_redirect_uri_accepts_cursor_native_callback(): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1471,14 +1472,14 @@ def test_validate_trusted_redirect_uri_accepts_cursor_native_callback(): def test_validate_trusted_redirect_uri_rejects_unlisted_native_callback( monkeypatch, ): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) monkeypatch.setenv("MCP_TRUSTED_NATIVE_REDIRECT_URIS", "") # Clear defaults by patching — env-only path for this test monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", + "litellm.proxy.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", [], ) req = _make_trusted_request("http://localhost:4000/") @@ -1492,12 +1493,12 @@ def test_validate_trusted_redirect_uri_rejects_unlisted_native_callback( def test_validate_trusted_redirect_uri_accepts_env_native_redirect_uri( monkeypatch, ): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", + "litellm.proxy.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", [], ) monkeypatch.setenv( @@ -1509,7 +1510,7 @@ def test_validate_trusted_redirect_uri_accepts_env_native_redirect_uri( def test_validate_trusted_redirect_uri_rejects_native_callback_with_fragment(): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1522,7 +1523,7 @@ def test_validate_trusted_redirect_uri_rejects_native_callback_with_fragment(): def test_validate_trusted_redirect_uri_rejects_native_callback_with_query(): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1536,12 +1537,12 @@ def test_validate_trusted_redirect_uri_rejects_native_callback_with_query(): def test_validate_trusted_redirect_uri_native_path_case_insensitive(monkeypatch): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", + "litellm.proxy.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", [], ) monkeypatch.setenv( @@ -1555,12 +1556,12 @@ def test_validate_trusted_redirect_uri_native_path_case_insensitive(monkeypatch) def test_validate_trusted_redirect_uri_native_wildcard_respects_path_boundary( monkeypatch, ): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", + "litellm.proxy.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", [], ) monkeypatch.setenv( @@ -1580,12 +1581,12 @@ def test_validate_trusted_redirect_uri_native_wildcard_respects_path_boundary( def test_validate_trusted_redirect_uri_native_wildcard_directory_prefix( monkeypatch, ): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", + "litellm.proxy.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", [], ) monkeypatch.setenv( @@ -1600,7 +1601,7 @@ def test_validate_trusted_redirect_uri_rejects_scheme_mismatch_on_same_host(): """Regression: an attacker who can serve http on the proxy's own host (e.g. by MITMing an unencrypted LAN hop) must not be able to pass same-origin validation — scheme must match as well as host.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1622,7 +1623,7 @@ def test_validate_trusted_redirect_uri_rejects_userinfo(monkeypatch): allowlist, and wildcard allowlist — so the bypass is closed on every path through the validator. """ - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1675,7 +1676,7 @@ def test_validate_trusted_redirect_uri_rejects_backslash_in_netloc(monkeypatch): exact-entry, and wildcard — by bouncing the netloc before any matching runs. """ - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1709,7 +1710,7 @@ def test_validate_trusted_redirect_uri_allowlist_entry_with_default_port(monkeyp away for the same-origin compare; the allowlist side has to apply the same normalization or the comparison is asymmetric and silently fails.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( _parse_trusted_redirect_origins, validate_trusted_redirect_uri, ) @@ -1729,7 +1730,7 @@ def test_validate_trusted_redirect_uri_allowlist_entry_with_default_port(monkeyp def test_validate_trusted_redirect_uri_accepts_exact_allowlisted_host(monkeypatch): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1754,7 +1755,7 @@ def test_validate_trusted_redirect_uri_allowlist_rejects_http_even_on_listed_hos """An attacker must not be able to elevate to the allowlist by serving http:// on the listed host — only https is accepted for non-loopback allowlist entries.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1769,7 +1770,7 @@ def test_validate_trusted_redirect_uri_wildcard_allowlist(monkeypatch): """``*.suffix`` entries match any strictly-deeper subdomain of ``suffix`` but must not match the bare suffix, nor unrelated domains that happen to end with the same characters.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1794,7 +1795,7 @@ def test_validate_trusted_redirect_uri_wildcard_allowlist(monkeypatch): def test_validate_trusted_redirect_uri_wildcard_rejects_http(monkeypatch): """The https-only gate applies to wildcard entries too.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1810,7 +1811,7 @@ def test_validate_trusted_redirect_uri_wildcard_host_with_port_still_matches( ): """Wildcard entries don't express port constraints — an allowlisted subdomain should match regardless of explicit port on the URL.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1822,7 +1823,7 @@ def test_validate_trusted_redirect_uri_wildcard_host_with_port_still_matches( def test_validate_trusted_redirect_uri_accepts_ipv6_loopback_with_default_port(): """IPv6 loopback with explicit ``:443`` on an ``https`` URL should still match — exercises ``_strip_default_port``'s IPv6 branch.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1835,7 +1836,7 @@ def test_validate_trusted_redirect_uri_tolerates_malformed_env_entries(monkeypat ``*.``, non-numeric ports). None of those should raise; unmatched entries must simply fail to grant access while well-formed entries in the same list continue to work.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1863,7 +1864,7 @@ def test_validate_trusted_redirect_uri_rejects_wildcard_entry_with_dot_leading_s whose own leading ``.`` makes it look like a deeper subdomain. Operators who mistype an extra dot should get an ignored entry, not a broader match than they intended.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1885,7 +1886,7 @@ def test_validate_trusted_redirect_uri_falls_through_when_origin_lookup_fails(): """If ``get_request_base_url`` can't determine the proxy's origin, same-origin is skipped silently but loopback + allowlist paths are still reachable.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1905,7 +1906,7 @@ def test_strip_default_port_empty_netloc(): """``_strip_default_port("", "")`` should round-trip — validator rejects empty-netloc URLs upstream so this is purely a defensive contract on the helper itself.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import _strip_default_port + from litellm.proxy.mcp_server.oauth_utils import _strip_default_port assert _strip_default_port("https", "") == "" @@ -1914,7 +1915,7 @@ def test_strip_default_port_handles_non_numeric_port(): """Raw netloc with a non-numeric port is returned unchanged. Reached in practice when a malformed ``Host`` header survives upstream parsing — we stay out of its way rather than 500ing.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import _strip_default_port + from litellm.proxy.mcp_server.oauth_utils import _strip_default_port assert _strip_default_port("https", "foo.com:bar") == "foo.com:bar" assert _strip_default_port("https", "[::1]:bar") == "[::1]:bar" @@ -1923,7 +1924,7 @@ def test_strip_default_port_handles_non_numeric_port(): def test_validate_trusted_redirect_uri_rejects_public_ip_without_allowlist(): """A redirect_uri whose host is a public IP (parseable by ``ip_address`` but not loopback) must fail all three tiers and 400.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1937,7 +1938,7 @@ def test_parse_trusted_redirect_origins_drops_bare_path_entries(monkeypatch): """``/foo`` has a scheme-less leading slash and would strip to the empty string — drop silently rather than allowlisting empty origins.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( _parse_trusted_redirect_origins, ) @@ -1965,12 +1966,14 @@ async def test_authenticated_browser_identity_checks_embedded_session( monkeypatch: pytest.MonkeyPatch, case: str, expected: str | None ) -> None: from datetime import datetime, timezone + import jwt from starlette.requests import Request + from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import get_authenticated_browser_user_id - from litellm.proxy.common_utils.encrypt_decrypt_utils import encrypt_bearer_token from litellm.proxy.auth.auth_checks import LITELLM_SESSION_TOKEN_PREFIX + from litellm.proxy.common_utils.encrypt_decrypt_utils import encrypt_bearer_token + from litellm.proxy.mcp_server.byok_oauth_endpoints import get_authenticated_browser_user_id monkeypatch.setenv("LITELLM_SALT_KEY", "local-test-encryption-key") monkeypatch.setattr(proxy_server, "master_key", "local-test-cookie-signing-key-32-bytes") diff --git a/tests/unit/proxy/_experimental/mcp_server/test_callback_oauth_error_responses.py b/tests/unit/proxy/mcp_server/test_callback_oauth_error_responses.py similarity index 94% rename from tests/unit/proxy/_experimental/mcp_server/test_callback_oauth_error_responses.py rename to tests/unit/proxy/mcp_server/test_callback_oauth_error_responses.py index 11ef40b9961..5a66689a5bb 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_callback_oauth_error_responses.py +++ b/tests/unit/proxy/mcp_server/test_callback_oauth_error_responses.py @@ -27,7 +27,7 @@ def _mock_mcp_client_ip(): from unittest.mock import patch with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", return_value=None, ): yield @@ -45,7 +45,7 @@ def callback_test_client(monkeypatch): monkeypatch.setenv("LITELLM_SALT_KEY", "sk-test-salt-for-LIT-2750") - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( router, ) @@ -100,7 +100,7 @@ class TestCallbackOAuthErrorResponses: """When state decodes to a trusted (loopback) redirect_uri, propagate the error back so the MCP client's OAuth library can surface it instead of timing out waiting on the loopback.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( encode_state_with_base_url, ) @@ -136,7 +136,7 @@ class TestCallbackOAuthErrorResponses: """If the state minted earlier carries a redirect_uri that the proxy no longer trusts, we must surface the error inline rather than 302-ing to an attacker-controlled URL (open-redirect).""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( encode_state_with_base_url, ) @@ -188,7 +188,7 @@ class TestCallbackOAuthErrorResponses: """Regression: the successful (``code``+``state``) flow must still redirect back to the trusted client redirect_uri with the original state preserved.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( encode_state_with_base_url, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_capabilities.py b/tests/unit/proxy/mcp_server/test_capabilities.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_capabilities.py rename to tests/unit/proxy/mcp_server/test_capabilities.py index e5104e7941f..55d338e64aa 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_capabilities.py +++ b/tests/unit/proxy/mcp_server/test_capabilities.py @@ -15,7 +15,7 @@ from mcp.types import ( ) from mcp_types.version import HANDSHAKE_PROTOCOL_VERSIONS -from litellm.proxy._experimental.mcp_server.capabilities import ( +from litellm.proxy.mcp_server.capabilities import ( GATEWAY_OPERATIONS, REVISION_SUPPORT, TRANSLATION_PAIRS, @@ -130,6 +130,7 @@ async def test_version_policy_gates_the_actual_sdk_handshake(versions, accepted) def test_modern_discovery_requires_opt_in_and_keeps_unsupported_features_disabled() -> None: from pydantic import TypeAdapter + from litellm.types.mcp import MCPAdvertisedVersions configured: Final = TypeAdapter(MCPAdvertisedVersions).validate_python(["2026-07-28"]) @@ -154,7 +155,7 @@ def test_modern_discovery_requires_opt_in_and_keeps_unsupported_features_disable @pytest.mark.parametrize("path", ["/mcp/sse", "/mcp/example/sse/"]) def test_modern_protocol_is_rejected_on_legacy_sse_paths(path: str, monkeypatch: pytest.MonkeyPatch) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.server import unsupported_protocol_version + from litellm.proxy.mcp_server.server import unsupported_protocol_version monkeypatch.setitem(proxy_server.general_settings, "mcp_advertised_versions", ["2025-11-25", "2026-07-28"]) assert unsupported_protocol_version({"path": "/mcp", "headers": [(b"mcp-protocol-version", b"2026-07-28")]}) is None @@ -194,8 +195,9 @@ def test_subscription_flags_require_a_supported_protocol_pair(revision, upstream async def test_subscription_discovery_never_probes_unsupported_targets(mode, monkeypatch): from types import SimpleNamespace from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server import subscriptions - from litellm.proxy._experimental.mcp_server.contracts import OperationContext + + from litellm.proxy.mcp_server import subscriptions + from litellm.proxy.mcp_server.contracts import OperationContext probe = AsyncMock() target = SimpleNamespace( diff --git a/tests/unit/proxy/_experimental/mcp_server/test_catalog.py b/tests/unit/proxy/mcp_server/test_catalog.py similarity index 83% rename from tests/unit/proxy/_experimental/mcp_server/test_catalog.py rename to tests/unit/proxy/mcp_server/test_catalog.py index b383078c0ed..45c648b81d2 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_catalog.py +++ b/tests/unit/proxy/mcp_server/test_catalog.py @@ -1,5 +1,5 @@ import asyncio -from collections.abc import Sequence +from collections.abc import Mapping, Sequence from types import SimpleNamespace from typing import Final, Literal from unittest.mock import AsyncMock @@ -13,20 +13,21 @@ from mcp.types import ( ListResourcesResult, ListResourceTemplatesRequest, ListResourceTemplatesResult, + ListToolsRequest, ListToolsResult, PaginatedRequestParams, Tool, ) -from litellm.proxy._experimental.mcp_server import catalog -from litellm.proxy._experimental.mcp_server.contracts import OperationContext -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( +from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError +from litellm.proxy.mcp_server import catalog +from litellm.proxy.mcp_server.contracts import OperationContext +from litellm.proxy.mcp_server.faults.list_outcomes import ( SERVER_OUTCOMES_META_KEY, AggregateToolListing, ServerListOk, ) -from litellm.proxy._types import UserAPIKeyAuth -from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -34,6 +35,104 @@ CatalogKind = Literal["tools", "prompts", "resources", "templates"] OptionalCatalogResult = ListPromptsResult | ListResourcesResult | ListResourceTemplatesResult +@pytest.mark.asyncio +@pytest.mark.parametrize( + "selected,revoked,expected", + [ + ("narrow", False, ("alpha-read_item",)), + ("full", False, ("alpha-read_item", "alpha-write_item", "beta-read_item", "beta-write_item")), + (None, False, ("alpha-read_item", "alpha-write_item", "beta-read_item", "beta-write_item")), + ("narrow", True, ()), + ], +) +async def test_catalog_refresh_keeps_selected_toolset_with_current_grants_and_contents( + monkeypatch: pytest.MonkeyPatch, + selected: str | None, + revoked: bool, + expected: tuple[str, ...], +) -> None: + from fastapi import HTTPException + + from litellm.caching.dual_cache import DualCache + from litellm.proxy import proxy_server + from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.types.mcp_server.mcp_toolset import MCPToolset, MCPToolsetTool + + grants: Final = LiteLLM_ObjectPermissionTable( + object_permission_id="catalog-grants", mcp_toolsets=["narrow", "full"] + ) + live_grants: Final = grants.model_copy(update={"mcp_toolsets": ["full"]}) if revoked else grants + tools: Final[tuple[MCPToolsetTool, ...]] = ( + {"server_id": "alpha", "tool_name": "read_item"}, + {"server_id": "alpha", "tool_name": "write_item"}, + {"server_id": "beta", "tool_name": "read_item"}, + {"server_id": "beta", "tool_name": "write_item"}, + ) + toolsets: Final = ( + MCPToolset(toolset_id="narrow", toolset_name="narrow", tools=[tools[0]]), + MCPToolset(toolset_id="full", toolset_name="full", tools=list(tools)), + ) + + async def read_toolsets(where: Mapping[str, Mapping[str, Sequence[str]]]) -> tuple[MCPToolset, ...]: + return tuple(toolset for toolset in toolsets if toolset.toolset_id in where["toolset_id"]["in"]) + + tables: Final = SimpleNamespace( + litellm_objectpermissiontable=SimpleNamespace(find_unique=AsyncMock(return_value=live_grants)), + litellm_mcptoolsettable=SimpleNamespace(find_many=read_toolsets), + ) + database: Final = SimpleNamespace( + db=tables, + writer_db=tables, + get_data=AsyncMock(return_value=UserAPIKeyAuth(object_permission_id=grants.object_permission_id)), + ) + cache: Final = DualCache() + monkeypatch.setattr(proxy_server, "prisma_client", database) + monkeypatch.setattr(proxy_server, "user_api_key_cache", cache) + monkeypatch.setattr(proxy_server, "general_settings", {"supported_db_objects": []}) + await cache.async_set_cache(key="toolset_perms:narrow", value={"alpha": ["read_item", "write_item"]}) + manager: Final = operations.global_mcp_server_manager + for server_id in ("alpha", "beta"): + monkeypatch.setitem( + manager.registry, + server_id, + MCPServer(server_id=server_id, name=server_id, transport=MCPTransport.http, spec_path="/catalog.yaml"), + ) + + async def tool_handler() -> str: + return "ok" + + for tool in tools: + global_mcp_tool_registry.register_tool( + name=f"{tool['server_id']}-{tool['tool_name']}", + description=tool["tool_name"], + input_schema={"type": "object"}, + handler=tool_handler, + ) + original: Final = UserAPIKeyAuth( + api_key="catalog-key-hash", object_permission=grants, + object_permission_id=grants.object_permission_id, + ) + original.via_virtual_key = True + caller: Final = await apply_toolset_scope(original, selected) if selected is not None else original + before: Final = caller.model_dump() + context: Final = operations.prepare_context(user_api_key_auth=caller) + if revoked: + with pytest.raises(HTTPException, match="does not have access to toolset") as denied: + await catalog.list_gateway_catalog(context, ListToolsRequest(), log_list_tools_to_spendlogs=False) + assert denied.value.status_code == 403 + else: + result: Final = await catalog.list_gateway_catalog( + context, ListToolsRequest(), log_list_tools_to_spendlogs=False + ) + assert isinstance(result, ListToolsResult) + assert tuple(sorted(tool.name for tool in result.tools)) == expected + assert caller.model_dump() == before + assert original.object_permission == grants + + def page(name: str, cursor: str | None = None, revision: str = "stable") -> ListToolsResult: return ListToolsResult( tools=[Tool(name=name, input_schema={"type": "object"})], @@ -46,7 +145,7 @@ def rate_limit_catalog_setup( monkeypatch: pytest.MonkeyPatch, rejected_server_ids: frozenset[str] ) -> tuple[tuple[MCPServer, MCPServer], OperationContext, AsyncMock]: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import operations + from litellm.proxy.mcp_server import operations monkeypatch.setenv("LITELLM_SALT_KEY", "catalog-rate-limit-test-key") servers: Final = ( @@ -223,7 +322,7 @@ async def test_changed_upstream_revision_requires_restart(monkeypatch): @pytest.mark.asyncio async def test_failed_upstream_remains_visible_when_other_sources_continue(monkeypatch): - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY + from litellm.proxy.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY monkeypatch.setenv("LITELLM_SALT_KEY", "shared-test-key") @@ -267,8 +366,8 @@ async def test_cursor_cannot_be_reused_for_a_different_catalog_kind(monkeypatch) @pytest.mark.asyncio async def test_authenticated_state_with_invalid_catalog_schema_is_rejected(monkeypatch): - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok - from litellm.proxy._experimental.mcp_server.state_tokens import seal_state + from litellm.proxy.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.state_tokens import seal_state monkeypatch.setenv("LITELLM_SALT_KEY", "shared-test-key") token = seal_state({"not": "catalog state"}, purpose="mcp.catalog.list.v1:tools/list", expires_at=200, now=100) @@ -327,8 +426,8 @@ async def test_page_limit_rejects_an_unending_upstream(monkeypatch): def test_caller_binding_covers_identity_scope_and_forwarded_credentials(change): from dataclasses import replace - from litellm.proxy._experimental.mcp_server.contracts import OperationContext from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.contracts import OperationContext original = OperationContext(_caller=UserAPIKeyAuth(api_key="synthetic-key", user_id="owner")) assert catalog._caller_scope(original, ()) != catalog._caller_scope(replace(original, **change), ()) @@ -337,8 +436,8 @@ def test_caller_binding_covers_identity_scope_and_forwarded_credentials(change): def test_caller_binding_ignores_transport_headers_and_header_case(): from dataclasses import replace - from litellm.proxy._experimental.mcp_server.contracts import OperationContext from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.contracts import OperationContext original = OperationContext( _caller=UserAPIKeyAuth(user_id="owner"), raw_headers={"Authorization": "Bearer synthetic"} @@ -411,8 +510,8 @@ async def test_gateway_tools_continuation_rejects_an_upstream_failure(monkeypatc from mcp.types import PaginatedRequestParams from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ServerListOk, classify_list_exception + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.faults.list_outcomes import ServerListOk, classify_list_exception from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -447,8 +546,8 @@ async def test_optional_gateway_catalog_reports_initial_failure_and_rejects_fail from mcp import types from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -630,6 +729,7 @@ async def test_discovery_cache_uses_upstream_freshness_and_configured_cap( upstream_ttl: int, limit: float, expected_ttl: int ) -> None: from unittest.mock import AsyncMock + from mcp.types import ListPromptsResult, Prompt from pydantic import TypeAdapter @@ -660,7 +760,8 @@ async def test_discovery_cache_uses_upstream_freshness_and_configured_cap( def test_partial_optional_catalog_never_advertises_freshness() -> None: from mcp.types import ListPromptsRequest, ListPromptsResult - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY + + from litellm.proxy.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY result: Final = catalog.combine_optional_catalog( ListPromptsRequest(), diff --git a/tests/unit/proxy/_experimental/mcp_server/test_client_allowlist.py b/tests/unit/proxy/mcp_server/test_client_allowlist.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_client_allowlist.py rename to tests/unit/proxy/mcp_server/test_client_allowlist.py index d1f852e504e..e05f23cbf33 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_client_allowlist.py +++ b/tests/unit/proxy/mcp_server/test_client_allowlist.py @@ -3,7 +3,7 @@ from typing import Final import pytest -from litellm.proxy._experimental.mcp_server.client_allowlist import ( +from litellm.proxy.mcp_server.client_allowlist import ( MCP_ALLOWED_CLIENTS_SETTING, MCP_CLIENT_ID_HEADER_SETTING, MCP_CLIENT_ID_JWT_FIELD_SETTING, diff --git a/tests/unit/proxy/_experimental/mcp_server/test_contracts.py b/tests/unit/proxy/mcp_server/test_contracts.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_contracts.py rename to tests/unit/proxy/mcp_server/test_contracts.py index adb17590d74..db30f2a4af9 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_contracts.py +++ b/tests/unit/proxy/mcp_server/test_contracts.py @@ -4,8 +4,8 @@ from typing import Final import pytest from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.operations import prepare_context from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server.operations import prepare_context def test_guardrail_bearer_stays_out_of_egress_and_context_representations() -> None: diff --git a/tests/unit/proxy/_experimental/mcp_server/test_db_credentials.py b/tests/unit/proxy/mcp_server/test_db_credentials.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/test_db_credentials.py rename to tests/unit/proxy/mcp_server/test_db_credentials.py index ce31a83075c..db2572ef954 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_db_credentials.py +++ b/tests/unit/proxy/mcp_server/test_db_credentials.py @@ -18,7 +18,15 @@ from unittest.mock import AsyncMock, MagicMock import pytest from prisma.models import LiteLLM_MCPServerTable as PrismaMCPServer -from litellm.proxy._experimental.mcp_server.db import ( +from litellm.proxy._types import LiteLLM_MCPServerTable, NewMCPServerRequest, UpdateMCPServerRequest +from litellm.proxy.common_utils.encrypt_decrypt_utils import ( + SecretMapDecodeError, + decode_secret_map, + decrypt_value_helper, + encrypt_secret_map, + encrypt_value_helper, +) +from litellm.proxy.mcp_server.db import ( _decode_user_credential, _prepare_mcp_server_data, create_mcp_server, @@ -39,14 +47,6 @@ from litellm.proxy._experimental.mcp_server.db import ( store_user_oauth_credential, update_mcp_server, ) -from litellm.proxy._types import LiteLLM_MCPServerTable, NewMCPServerRequest, UpdateMCPServerRequest -from litellm.proxy.common_utils.encrypt_decrypt_utils import ( - SecretMapDecodeError, - decode_secret_map, - decrypt_value_helper, - encrypt_secret_map, - encrypt_value_helper, -) from litellm.types.mcp import MCPAuth, MCPTransport SALT_KEY = "test-salt-key-for-byok-credential-tests-1234" @@ -121,7 +121,7 @@ def _identity_server(**overrides): ], ) def test_mcp_oauth_token_identity_changes_on_mint_relevant_fields(overrides): - from litellm.proxy._experimental.mcp_server.db import mcp_oauth_token_identity + from litellm.proxy.mcp_server.db import mcp_oauth_token_identity assert mcp_oauth_token_identity(_identity_server()) != mcp_oauth_token_identity(_identity_server(**overrides)) @@ -134,13 +134,13 @@ def test_mcp_oauth_token_identity_changes_on_mint_relevant_fields(overrides): ], ) def test_mcp_oauth_token_identity_stable_on_non_mint_fields(overrides): - from litellm.proxy._experimental.mcp_server.db import mcp_oauth_token_identity + from litellm.proxy.mcp_server.db import mcp_oauth_token_identity assert mcp_oauth_token_identity(_identity_server()) == mcp_oauth_token_identity(_identity_server(**overrides)) def _encrypted_creds_json(client_id: str = "cid", client_secret: str = "csec") -> str: - from litellm.proxy._experimental.mcp_server.db import encrypt_credentials + from litellm.proxy.mcp_server.db import encrypt_credentials encrypted = encrypt_credentials( credentials={"client_id": client_id, "client_secret": client_secret, "scopes": ["a"]}, @@ -154,7 +154,7 @@ def test_mcp_oauth_token_identity_stable_across_reencryption(): saves of the SAME plaintext produce different ciphertext. The identity must compare decrypted values; comparing ciphertext would flag every routine save as a mint-relevant change and purge per-user tokens that are still valid.""" - from litellm.proxy._experimental.mcp_server.db import mcp_oauth_token_identity + from litellm.proxy.mcp_server.db import mcp_oauth_token_identity first = _encrypted_creds_json() second = _encrypted_creds_json() @@ -166,7 +166,7 @@ def test_mcp_oauth_token_identity_stable_across_reencryption(): def test_mcp_oauth_token_identity_detects_change_under_encryption(): - from litellm.proxy._experimental.mcp_server.db import mcp_oauth_token_identity + from litellm.proxy.mcp_server.db import mcp_oauth_token_identity unchanged = _identity_server(credentials=_encrypted_creds_json()) changed = _identity_server(credentials=_encrypted_creds_json(client_id="other")) @@ -174,7 +174,7 @@ def test_mcp_oauth_token_identity_detects_change_under_encryption(): def test_mcp_oauth_token_identity_reads_client_and_scopes_from_json_string_credentials(): - from litellm.proxy._experimental.mcp_server.db import mcp_oauth_token_identity + from litellm.proxy.mcp_server.db import mcp_oauth_token_identity credentials: Final = json.dumps( {"client_id": "cid", "client_secret": "csec", "scopes": ["a"], "upstream_resource": "api://audience"} @@ -198,7 +198,7 @@ def test_mcp_oauth_token_identity_reads_client_and_scopes_from_json_string_crede @pytest.mark.parametrize("credentials", ["[]", '["client_id"]', '"cid"', "5", "null", "not json"]) def test_mcp_oauth_token_identity_treats_stored_credentials_that_are_not_a_json_object_as_empty(credentials): - from litellm.proxy._experimental.mcp_server.db import mcp_oauth_token_identity + from litellm.proxy.mcp_server.db import mcp_oauth_token_identity assert mcp_oauth_token_identity(_identity_server(credentials=credentials)) == ( "https://up.example.com/mcp", @@ -235,7 +235,7 @@ def _byok_row(user_id: str, server_id: str = "srv-1"): @pytest.mark.asyncio async def test_purge_user_oauth_credentials_for_server_invalidates_each_user(): """The purge must route each (user, server) row through the invalidator exactly once.""" - from litellm.proxy._experimental.mcp_server.db import purge_user_oauth_credentials_for_server + from litellm.proxy.mcp_server.db import purge_user_oauth_credentials_for_server prisma = MagicMock() prisma.db.litellm_mcpusercredentials.find_many = AsyncMock(return_value=[_oauth_row("alice"), _oauth_row("bob")]) @@ -259,7 +259,7 @@ async def test_purge_user_oauth_credentials_for_server_invalidates_each_user(): async def test_list_server_user_credentials_types_each_row_without_leaking_the_secret(): """The admin view of one server's stored credentials names the user and the kind of credential (OAuth2 vs BYOK) and echoes OAuth expiry, but never the token or key itself.""" - from litellm.proxy._experimental.mcp_server.db import list_server_user_credentials + from litellm.proxy.mcp_server.db import list_server_user_credentials oauth_row = _legacy_row( json.dumps( @@ -307,7 +307,7 @@ async def test_purge_user_oauth_credentials_for_server_spares_byok_rows(): """Regression: the purge used to delete_many on server_id alone, wiping BYOK API keys that share the LiteLLM_MCPUserCredentials table. Only rows holding an OAuth2 payload may be deleted (one batched query filtered to their user_ids), and only their users' token caches invalidated.""" - from litellm.proxy._experimental.mcp_server.db import purge_user_oauth_credentials_for_server + from litellm.proxy.mcp_server.db import purge_user_oauth_credentials_for_server prisma = MagicMock() prisma.db.litellm_mcpusercredentials.find_many = AsyncMock(return_value=[_byok_row("carol"), _oauth_row("alice")]) @@ -330,7 +330,7 @@ async def test_purge_user_oauth_credentials_for_server_spares_byok_rows(): @pytest.mark.asyncio async def test_purge_user_oauth_credentials_for_server_all_byok_is_noop(): """An api_key (BYOK-only) server whose identity tuple changes (e.g. its url) must purge nothing.""" - from litellm.proxy._experimental.mcp_server.db import purge_user_oauth_credentials_for_server + from litellm.proxy.mcp_server.db import purge_user_oauth_credentials_for_server prisma = MagicMock() prisma.db.litellm_mcpusercredentials.find_many = AsyncMock(return_value=[_byok_row("carol"), _byok_row("dave")]) @@ -348,8 +348,8 @@ async def test_purge_user_oauth_credentials_for_server_defaults_to_manager_inval invalidate_user_oauth_token_cache, the single point covering both the legacy per-user token cache and the v2 per-user OAuth token store; a wrong or no-op default silently leaves every cache serving tokens minted for the superseded config.""" - from litellm.proxy._experimental.mcp_server import mcp_server_manager - from litellm.proxy._experimental.mcp_server.db import purge_user_oauth_credentials_for_server + from litellm.proxy.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server.db import purge_user_oauth_credentials_for_server prisma = MagicMock() prisma.db.litellm_mcpusercredentials.find_many = AsyncMock(return_value=[_oauth_row("alice")]) @@ -370,8 +370,8 @@ async def test_purge_user_oauth_credentials_for_server_defaults_to_manager_inval @pytest.mark.asyncio async def test_purge_user_oauth_credentials_for_server_logs_raced_rows(monkeypatch): - from litellm.proxy._experimental.mcp_server import db as db_module - from litellm.proxy._experimental.mcp_server.db import purge_user_oauth_credentials_for_server + from litellm.proxy.mcp_server import db as db_module + from litellm.proxy.mcp_server.db import purge_user_oauth_credentials_for_server prisma = MagicMock() prisma.db.litellm_mcpusercredentials.find_many = AsyncMock(return_value=[_oauth_row("alice")]) @@ -390,7 +390,7 @@ async def test_delete_mcp_server_invalidates_cached_tokens_for_enumerated_users( """Deleting a server must invalidate each enumerated user's cached per-user token: the caches are keyed by (user_id, server_id), so a re-created server reusing the same server_id would otherwise serve tokens minted for the deleted server until TTL.""" - from litellm.proxy._experimental.mcp_server.db import delete_mcp_server + from litellm.proxy.mcp_server.db import delete_mcp_server prisma = MagicMock() prisma.db.litellm_mcpservertable.delete = AsyncMock(return_value=MagicMock(server_id="srv-1")) @@ -411,7 +411,7 @@ async def test_delete_mcp_server_invalidates_cached_tokens_for_enumerated_users( @pytest.mark.asyncio async def test_delete_mcp_server_returns_none_without_cleanup_when_server_missing(): - from litellm.proxy._experimental.mcp_server.db import delete_mcp_server + from litellm.proxy.mcp_server.db import delete_mcp_server prisma = MagicMock() prisma.db.litellm_mcpservertable.delete = AsyncMock(return_value=None) @@ -425,7 +425,7 @@ async def test_delete_mcp_server_returns_none_without_cleanup_when_server_missin @pytest.mark.asyncio async def test_purge_user_oauth_credentials_for_server_noop_when_empty(): - from litellm.proxy._experimental.mcp_server.db import purge_user_oauth_credentials_for_server + from litellm.proxy.mcp_server.db import purge_user_oauth_credentials_for_server prisma = MagicMock() prisma.db.litellm_mcpusercredentials.find_many = AsyncMock(return_value=[]) @@ -1164,7 +1164,7 @@ def test_expiry_missing_expires_at_is_never_expired(): @pytest.mark.asyncio async def test_resolve_returns_valid_token_without_refreshing(monkeypatch): # A token good for 10 minutes must be returned as-is, with no refresh call. - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod refresh = AsyncMock() monkeypatch.setattr(db_mod, "refresh_user_oauth_token", refresh) @@ -1183,7 +1183,7 @@ async def test_resolve_returns_valid_token_without_refreshing(monkeypatch): async def test_resolve_refreshes_expired_token_with_refresh_token(monkeypatch): # The core regression: an expired OBO cred with a refresh_token must mint a # new token rather than returning None (which left the UI tool list empty). - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod refreshed = _oauth_cred(access_token="at-fresh", refresh_token="rt-2", expires_in_seconds=3600) refresh = AsyncMock(return_value=refreshed) @@ -1202,7 +1202,7 @@ async def test_resolve_refreshes_expired_token_with_refresh_token(monkeypatch): async def test_resolve_refreshes_token_expiring_within_buffer(monkeypatch): # A token still technically valid (30s left) but inside the 60s buffer must # be proactively refreshed, not handed back. - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod refreshed = _oauth_cred(access_token="at-fresh", expires_in_seconds=3600) refresh = AsyncMock(return_value=refreshed) @@ -1220,7 +1220,7 @@ async def test_resolve_refreshes_token_expiring_within_buffer(monkeypatch): @pytest.mark.asyncio async def test_resolve_returns_none_when_expired_without_refresh_token(monkeypatch): # No refresh_token means nothing to refresh with — return None, never call refresh. - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod refresh = AsyncMock() monkeypatch.setattr(db_mod, "refresh_user_oauth_token", refresh) @@ -1237,7 +1237,7 @@ async def test_resolve_returns_none_when_expired_without_refresh_token(monkeypat @pytest.mark.asyncio async def test_resolve_returns_none_when_refresh_fails(monkeypatch): # A failed refresh (provider returns nothing usable) must surface as None. - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod refresh = AsyncMock(return_value=None) monkeypatch.setattr(db_mod, "refresh_user_oauth_token", refresh) @@ -1253,7 +1253,7 @@ async def test_resolve_returns_none_when_refresh_fails(monkeypatch): @pytest.mark.asyncio async def test_resolve_returns_none_for_missing_credential(monkeypatch): - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod refresh = AsyncMock() monkeypatch.setattr(db_mod, "refresh_user_oauth_token", refresh) @@ -1301,7 +1301,7 @@ def _refresh_server(**overrides): async def _run_refresh(monkeypatch, server, response_body=None): - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod captured: dict = {} @@ -1411,7 +1411,7 @@ async def test_rotate_user_env_vars_skips_undecryptable_rows(): async def test_refresh_user_oauth_token_uses_client_secret_basic(monkeypatch): """LIT-4091: a per-user refresh against a server with token_endpoint_auth_method=client_secret_basic sends HTTP Basic and keeps the secret out of the body.""" - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod server = MagicMock(oauth_identity_binding=None) server.token_url = "https://idp.example.com/oauth2/token" @@ -1450,7 +1450,7 @@ async def test_refresh_user_oauth_token_uses_client_secret_basic(monkeypatch): async def test_refresh_user_oauth_token_defaults_to_client_secret_post(monkeypatch): """Backward compatibility: with no token_endpoint_auth_method the refresh keeps credentials in the body (client_secret_post) and sends no Authorization header.""" - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod server = MagicMock(oauth_identity_binding=None) server.token_url = "https://idp.example.com/oauth2/token" @@ -1537,7 +1537,7 @@ async def test_master_key_rotation_reencrypts_oauth_client_store(monkeypatch): force a full re-authorization.""" import litellm.proxy.common_utils.encrypt_decrypt_utils as enc from litellm.litellm_core_utils.safe_json_dumps import safe_dumps - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( decrypt_credentials, encrypt_credentials, rotate_mcp_server_credentials_master_key, @@ -1580,7 +1580,7 @@ async def test_delete_mcp_server_cleans_oauth_client_store(): """Deleting a server must remove its server-scoped DCR client store entry alongside the per-user credential and env-var rows, or a re-created server reusing the same server_id would inherit the deleted server's OAuth client.""" - from litellm.proxy._experimental.mcp_server.db import delete_mcp_server + from litellm.proxy.mcp_server.db import delete_mcp_server prisma = MagicMock() prisma.db.litellm_mcpservertable.delete = AsyncMock(return_value=SimpleNamespace(server_id="s1")) @@ -1603,7 +1603,7 @@ def test_mcp_oauth_token_identity_changes_when_only_upstream_resource_is_edited( calling tools with the previous audience's token until it expires, which is the token-reuse RFC 8707 exists to stop. """ - from litellm.proxy._experimental.mcp_server.db import mcp_oauth_token_identity + from litellm.proxy.mcp_server.db import mcp_oauth_token_identity creds = {"client_id": "cid", "client_secret": "csec", "scopes": ["a"]} unset = _identity_server(credentials=dict(creds)) @@ -1736,7 +1736,8 @@ async def test_enforcement_rejects_preexisting_unverified_credential(): @pytest.mark.asyncio async def test_refresh_identity_rejection_returns_reauthentication_without_persisting(monkeypatch): from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import db as module + + from litellm.proxy.mcp_server import db as module validator = AsyncMock(side_effect=HTTPException(status_code=403, detail="oauth_principal_mismatch")) monkeypatch.setattr(module, "enforce_oauth_identity_binding", validator) @@ -1752,9 +1753,9 @@ async def test_refresh_identity_rejection_returns_reauthentication_without_persi async def test_verified_legacy_cache_reads_avoid_database_and_reject_policy_changes(monkeypatch): from litellm.caching.caching import DualCache from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import db as module - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import mcp_per_user_token_cache - from litellm.proxy._experimental.mcp_server.oauth_identity_binding import current_binding_proof + from litellm.proxy.mcp_server import db as module + from litellm.proxy.mcp_server.oauth2_token_cache import mcp_per_user_token_cache + from litellm.proxy.mcp_server.oauth_identity_binding import current_binding_proof from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -1789,8 +1790,8 @@ async def test_verified_legacy_cache_reads_avoid_database_and_reject_policy_chan async def test_unverified_legacy_cache_cannot_bypass_enforcement(monkeypatch): from litellm.caching.caching import DualCache from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import db as module - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import mcp_per_user_token_cache + from litellm.proxy.mcp_server import db as module + from litellm.proxy.mcp_server.oauth2_token_cache import mcp_per_user_token_cache from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -1815,9 +1816,9 @@ async def test_saved_cimd_grant_refreshes_from_encrypted_storage_on_a_fresh_repl from urllib.parse import parse_qs from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import db as db_module - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import _store_per_user_token_server_side - from litellm.proxy._experimental.mcp_server.outbound_credentials.per_user_oauth_store import ( + from litellm.proxy.mcp_server import db as db_module + from litellm.proxy.mcp_server.discoverable_endpoints import _store_per_user_token_server_side + from litellm.proxy.mcp_server.outbound_credentials.per_user_oauth_store import ( LazyPerUserOAuthTokenStore, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -1869,7 +1870,7 @@ async def test_saved_cimd_grant_refreshes_from_encrypted_storage_on_a_fresh_repl @pytest.mark.asyncio @pytest.mark.parametrize("provider_scope, expected", [(None, ["a"]), ("b", ["b"]), ("", [])]) async def test_silent_refresh_preserves_omitted_scope_but_accepts_explicit_grant(monkeypatch, provider_scope, expected): - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod await _run_refresh(monkeypatch, _refresh_server(), { "access_token": "new-access", diff --git a/tests/unit/proxy/_experimental/mcp_server/test_discoverable_endpoints.py b/tests/unit/proxy/mcp_server/test_discoverable_endpoints.py similarity index 90% rename from tests/unit/proxy/_experimental/mcp_server/test_discoverable_endpoints.py rename to tests/unit/proxy/mcp_server/test_discoverable_endpoints.py index a43dacaf100..c17f4b392cd 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_discoverable_endpoints.py +++ b/tests/unit/proxy/mcp_server/test_discoverable_endpoints.py @@ -63,8 +63,8 @@ def _stored_grant(access_token="access-token", refresh_token=None, expires_in_se ], ) async def test_vendor_credential_state_agrees_with_egress_token_resolution(monkeypatch, fields, egress_has_token): - from litellm.proxy._experimental.mcp_server import db as mcp_db - from litellm.proxy._experimental.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server import db as mcp_db + from litellm.proxy.mcp_server import discoverable_endpoints monkeypatch.setattr(mcp_db, "MCP_PER_USER_TOKEN_EXPIRY_BUFFER_SECONDS", 60) credential = _stored_grant(**fields) if fields is not None else None @@ -97,7 +97,7 @@ def mock_mcp_client_ip(): have proper client IP context. """ with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", return_value=None, ): yield @@ -111,8 +111,8 @@ def isolate_global_mcp_registry(monkeypatch): restore, entries leak into other test modules sharing the same worker and break assertions over the full registry contents. """ - from litellm.proxy._experimental.mcp_server.catalog import CatalogSnapshots - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.catalog import CatalogSnapshots + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager monkeypatch.setattr(global_mcp_server_manager, "catalog", CatalogSnapshots(global_mcp_server_manager)) snapshot = dict(global_mcp_server_manager.registry) @@ -169,8 +169,8 @@ def _resolved_oauth_metadata(): async def test_authorize_resolves_cold_oauth_metadata(monkeypatch): """The route hands the registered server to the flow, whose deferred-discovery join resolves the cold metadata; the redirect must land on the discovered authorization endpoint.""" - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager monkeypatch.setenv("LITELLM_SALT_KEY", "sk-test-salt-for-lit-6255") server = _unresolved_oauth_server() @@ -199,8 +199,8 @@ async def test_authorize_resolves_cold_oauth_metadata(monkeypatch): async def test_token_resolves_cold_oauth_metadata(): """The route hands the registered server to the exchange, whose deferred-discovery join resolves the cold metadata; the exchange must post to the discovered token endpoint.""" - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _unresolved_oauth_server() global_mcp_server_manager.registry[server.server_id] = server @@ -241,8 +241,8 @@ async def test_token_resolves_cold_oauth_metadata(): async def test_register_resolves_cold_oauth_metadata(): """The route hands the registered server to the registration flow, whose deferred-discovery join resolves the cold metadata; DCR must post to the discovered registration endpoint.""" - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _unresolved_oauth_server().model_copy(update={"client_id": None}) global_mcp_server_manager.registry[server.server_id] = server @@ -281,9 +281,9 @@ async def test_register_route_bridge_missing_registration_url_joins_discovery(): endpoint instead of short-circuiting to dummy credentials because authorization resolves.""" import json - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -340,9 +340,9 @@ async def test_token_route_bridge_missing_registration_url_joins_discovery(): registration endpoint must rejoin discovery at the exchange: the relay-vs-callback arm hinges on the registration url, so skipping discovery would swap the client's own redirect_uri for the gateway callback and the upstream would reject the code.""" - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -402,7 +402,7 @@ def trust_xff(): ``test_get_request_base_url_xff_trust_gate``. """ with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.is_request_from_trusted_proxy", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.is_request_from_trusted_proxy", return_value=True, ): yield @@ -414,13 +414,13 @@ async def test_authorize_endpoint_includes_response_type(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -451,7 +451,7 @@ async def test_authorize_endpoint_includes_response_type(): mock_request.headers = {} # Mock the encryption functions to avoid needing a signing key - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: mock_encrypt.return_value = "mocked_encrypted_state" # Call authorize endpoint @@ -481,13 +481,13 @@ async def test_authorize_endpoint_allows_client_forwarded_modes(auth_type_value) try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -512,7 +512,7 @@ async def test_authorize_endpoint_allows_client_forwarded_modes(auth_type_value) mock_request.base_url = "https://litellm.example.com/" mock_request.headers = {} - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: mock_encrypt.return_value = "mocked_encrypted_state" response = await authorize( @@ -534,13 +534,13 @@ async def test_authorize_endpoint_preserves_existing_query_params(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -568,7 +568,7 @@ async def test_authorize_endpoint_preserves_existing_query_params(): mock_request.base_url = "https://litellm.example.com/" mock_request.headers = {} - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: mock_encrypt.return_value = "mocked_encrypted_state" response = await authorize( @@ -610,7 +610,7 @@ async def test_authorize_preserves_contract_with_provider_defaults( ) -> None: from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import authorize_with_server + from litellm.proxy.mcp_server.discoverable_endpoints import authorize_with_server monkeypatch.setenv("LITELLM_SALT_KEY", "isolated-oauth-test-salt") is_bridge: Final = auth_mode != "direct" @@ -655,13 +655,13 @@ async def test_authorize_endpoint_forwards_pkce_parameters(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -692,7 +692,7 @@ async def test_authorize_endpoint_forwards_pkce_parameters(): mock_request.headers = {} # Mock the encryption function - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: mock_encrypt.return_value = "mocked_encrypted_state_with_pkce" # Call authorize endpoint with PKCE parameters @@ -724,13 +724,13 @@ async def test_token_endpoint_forwards_code_verifier(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( token_endpoint, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -774,7 +774,7 @@ async def test_token_endpoint_forwards_code_verifier(): from unittest.mock import AsyncMock with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client" + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client" ) as mock_get_client: mock_async_client = MagicMock() # Use AsyncMock for the async post method @@ -819,10 +819,10 @@ async def test_register_client_without_mcp_server_name_returns_dummy(server_name try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -835,7 +835,7 @@ async def test_register_client_without_mcp_server_name_returns_dummy(server_name mock_request.base_url = "https://proxy.litellm.example/" mock_request.headers = {} with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value={}), ): result = await register_client(request=mock_request, mcp_server_name=server_name) @@ -853,13 +853,13 @@ async def test_register_client_returns_existing_server_credentials(use_root): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -886,7 +886,7 @@ async def test_register_client_returns_existing_server_credentials(use_root): try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value={}), ): result = await register_client( @@ -907,13 +907,13 @@ async def test_register_client_remote_registration_success(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -958,11 +958,11 @@ async def test_register_client_remote_registration_success(): try: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value=request_payload), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), ): @@ -997,9 +997,9 @@ async def test_register_client_non_bridge_returns_client_redirect_not_gateway_ca verbatim makes a spec-compliant DCR client adopt /callback as its own redirect and loop.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import register_client - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import register_client + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -1044,11 +1044,11 @@ async def test_register_client_non_bridge_returns_client_redirect_not_gateway_ca try: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value=request_payload), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), ): @@ -1071,9 +1071,9 @@ async def test_register_client_admin_client_id_echoes_client_redirect_uris(): the gateway /callback and self-redirect loop (#33699).""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import register_client - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import register_client + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -1100,7 +1100,7 @@ async def test_register_client_admin_client_id_echoes_client_redirect_uris(): try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value={"redirect_uris": [client_redirect]}), ): result = await register_client(request=mock_request, mcp_server_name=oauth2_server.server_name) @@ -1126,14 +1126,14 @@ async def test_dcr_full_loop_lands_on_client_redirect_not_gateway_callback(monke from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _oauth_state_cookie_name, authorize_with_server, callback, register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -1176,7 +1176,7 @@ async def test_dcr_full_loop_lands_on_client_redirect_not_gateway_callback(monke try: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock( return_value={ "client_name": "Open WebUI", @@ -1187,7 +1187,7 @@ async def test_dcr_full_loop_lands_on_client_redirect_not_gateway_callback(monke ), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), ): @@ -1249,9 +1249,9 @@ async def test_authorize_rejects_untrusted_cross_origin_redirect_with_allowlist_ the mechanism a legitimate separate-origin DCR client needs, not only to PROXY_BASE_URL.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import authorize - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import authorize + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -1310,9 +1310,9 @@ async def test_register_client_malformed_redirect_uris_falls_back_to_gateway_cal callback so downstream never iterates a string as URIs or leaks non-string element types (#33699).""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import register_client - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import register_client + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -1337,7 +1337,7 @@ async def test_register_client_malformed_redirect_uris_falls_back_to_gateway_cal try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value={"redirect_uris": malformed_redirect_uris}), ): result = await register_client(request=mock_request, mcp_server_name=oauth2_server.server_name) @@ -1353,9 +1353,9 @@ async def test_register_client_valid_multi_redirect_uris_all_echoed(): unchanged, so the element-type guard does not narrow a legitimate multi-entry list (#33699).""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import register_client - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import register_client + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -1381,7 +1381,7 @@ async def test_register_client_valid_multi_redirect_uris_all_echoed(): client_redirects = ["https://app.example/cb", "http://127.0.0.1:6274/callback"] try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value={"redirect_uris": client_redirects}), ): result = await register_client(request=mock_request, mcp_server_name=oauth2_server.server_name) @@ -1405,13 +1405,13 @@ async def test_register_client_persists_dcr_client_identity(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -1452,11 +1452,11 @@ async def test_register_client_persists_dcr_client_identity(): with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=prisma), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=mock_update), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update), patch.object(global_mcp_server_manager, "update_server", new=mock_update_server), ): response = await register_client_with_server( @@ -1502,13 +1502,13 @@ async def _register_persistence_attempted_for_auth_type(auth_type: MCPAuth) -> b to the browser either way, since the caller needs the minted client to run its own flow.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -1545,11 +1545,11 @@ async def _register_persistence_attempted_for_auth_type(auth_type: MCPAuth) -> b with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=prisma), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=mock_update), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update), patch.object(global_mcp_server_manager, "update_server", new=AsyncMock()), ): response = await register_client_with_server( @@ -1601,13 +1601,13 @@ async def test_register_client_persists_only_to_its_own_row_when_another_server_ upstream registration (adopting the sibling's client) or persist onto the wrong row.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer shared_url = "https://provider.example/mcp" @@ -1648,12 +1648,12 @@ async def test_register_client_persists_only_to_its_own_row_when_another_server_ with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), - patch("litellm.proxy._experimental.mcp_server.db.get_mcp_server", new=AsyncMock(side_effect=_get_row)), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=mock_update), + patch("litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(side_effect=_get_row)), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update), patch.object(global_mcp_server_manager, "update_server", new=AsyncMock()), ): response = await register_client_with_server( @@ -1684,13 +1684,13 @@ async def test_register_client_does_not_clobber_token_url_when_absent(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -1727,11 +1727,11 @@ async def test_register_client_does_not_clobber_token_url_when_absent(): with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=prisma), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=mock_update), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update), patch.object(global_mcp_server_manager, "update_server", new=mock_update_server), ): await register_client_with_server( @@ -1755,13 +1755,13 @@ async def test_register_client_reuses_persisted_client_id_for_non_admin_when_reg try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -1795,16 +1795,16 @@ async def test_register_client_reuses_persisted_client_id_for_non_admin_when_reg with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch( - "litellm.proxy._experimental.mcp_server.db.update_mcp_server", + "litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update_mcp_server, ), patch.object(global_mcp_server_manager, "update_server", new=mock_update_server), @@ -1831,13 +1831,13 @@ async def test_register_client_reuse_refreshes_request_server_when_manager_updat try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -1874,12 +1874,12 @@ async def test_register_client_reuse_refreshes_request_server_when_manager_updat with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch.object(global_mcp_server_manager, "update_server", new=mock_update_server), @@ -1908,13 +1908,13 @@ async def test_register_client_returns_reused_client_when_concurrent_persist_win try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -1955,16 +1955,16 @@ async def test_register_client_returns_reused_client_when_concurrent_persist_win with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch( - "litellm.proxy._experimental.mcp_server.db.update_mcp_server", + "litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update_mcp_server, ), patch.object(global_mcp_server_manager, "update_server", new=mock_update_server), @@ -2020,10 +2020,10 @@ async def test_register_client_re_registers_when_persisted_redirect_uri_no_longe try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -2057,16 +2057,16 @@ async def test_register_client_re_registers_when_persisted_redirect_uri_no_longe with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch( - "litellm.proxy._experimental.mcp_server.db.update_mcp_server", + "litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update_mcp_server, ), patch.object(global_mcp_server_manager, "update_server", new=mock_update_server), @@ -2106,7 +2106,7 @@ async def test_register_client_grandfathers_persisted_client_without_recorded_re try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) except ImportError: @@ -2128,16 +2128,16 @@ async def test_register_client_grandfathers_persisted_client_without_recorded_re with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch( - "litellm.proxy._experimental.mcp_server.db.update_mcp_server", + "litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update_mcp_server, ), ): @@ -2164,7 +2164,7 @@ async def test_register_client_keeps_persisted_client_when_recorded_redirect_uri try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) except ImportError: @@ -2189,16 +2189,16 @@ async def test_register_client_keeps_persisted_client_when_recorded_redirect_uri with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch( - "litellm.proxy._experimental.mcp_server.db.update_mcp_server", + "litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update_mcp_server, ), ): @@ -2226,10 +2226,10 @@ async def test_register_client_non_admin_reuses_persisted_client_despite_redirec try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -2254,12 +2254,12 @@ async def test_register_client_non_admin_reuses_persisted_client_despite_redirec with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch.object(global_mcp_server_manager, "update_server", new=mock_update_server), @@ -2288,8 +2288,8 @@ async def test_register_client_without_replace_authority_adopts_concurrently_per try: from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -2310,23 +2310,23 @@ async def test_register_client_without_replace_authority_adopts_concurrently_per with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch.object(global_mcp_server_manager, "is_config_declared_server", return_value=True), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), - patch("litellm.proxy._experimental.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=AsyncMock(return_value=None)), + patch("litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=AsyncMock(return_value=None)), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.get_mcp_server_oauth_client_credentials", new=AsyncMock(side_effect=[None, winner]), ), patch( - "litellm.proxy._experimental.mcp_server.db.create_mcp_server_oauth_client_credentials_if_absent", + "litellm.proxy.mcp_server.db.create_mcp_server_oauth_client_credentials_if_absent", new=AsyncMock(return_value=False), ), patch( - "litellm.proxy._experimental.mcp_server.db.upsert_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.upsert_mcp_server_oauth_client_credentials", new=mock_upsert, ), ): @@ -2351,7 +2351,7 @@ async def test_persist_without_replace_authority_never_overwrites_a_row_client_i """A DB-declared server already holds a shared DCR client that this process cannot adopt (it was bound to another server URL). A caller without replace authority must get a failure, not fall through to update_mcp_server and overwrite the client every signed-in user depends on.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _persist_dcr_client_registration, ) @@ -2362,8 +2362,8 @@ async def test_persist_without_replace_authority_never_overwrites_a_row_client_i with ( patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), - patch("litellm.proxy._experimental.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=row)), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=mock_update), + patch("litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=row)), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update), ): result = await _persist_dcr_client_registration( server, {"client_id": "my-client"}, "https://proxy.litellm.example/callback", replace_stale_client=False @@ -2383,13 +2383,13 @@ async def test_register_client_reuses_existing_client_id_without_re_dcr(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -2428,11 +2428,11 @@ async def test_register_client_reuses_existing_client_id_without_re_dcr(): try: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value=request_payload), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), ): @@ -2483,10 +2483,10 @@ async def test_public_register_route_persists_first_dcr_client_when_origin_is_co registers: the caller's grant types, response types, auth method and name are not sent upstream, so an anonymous caller cannot shape or phish the shared client.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -2511,20 +2511,20 @@ async def test_public_register_route_persists_first_dcr_client_when_origin_is_co try: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value=request_payload), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=persisted_row), ), patch.object(global_mcp_server_manager, "update_server", new=mock_update_server), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=mock_update), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update), ): response = await register_client(request=mock_request, mcp_server_name=oauth2_server.server_name) finally: @@ -2548,10 +2548,10 @@ async def test_public_register_route_persists_first_dcr_client_for_config_server must reach the server-scoped OAuth client store, so a token refresh has a client_id and a second connect reuses the same client instead of minting another.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -2578,27 +2578,27 @@ async def test_public_register_route_persists_first_dcr_client_for_config_server try: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value=request_payload), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch.object(global_mcp_server_manager, "is_config_declared_server", return_value=True), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), - patch("litellm.proxy._experimental.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=AsyncMock(return_value=None)), + patch("litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=AsyncMock(return_value=None)), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.get_mcp_server_oauth_client_credentials", new=AsyncMock(side_effect=lambda **kwargs: store.get("blob")), ), patch( - "litellm.proxy._experimental.mcp_server.db.create_mcp_server_oauth_client_credentials_if_absent", + "litellm.proxy.mcp_server.db.create_mcp_server_oauth_client_credentials_if_absent", new=mock_create, ), patch( - "litellm.proxy._experimental.mcp_server.db.upsert_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.upsert_mcp_server_oauth_client_credentials", new=mock_upsert, ), ): @@ -2623,10 +2623,10 @@ async def test_public_register_route_without_configured_origin_does_not_pin_the_ the body it sent, echo the upstream response, and persist nothing. An admin's Connect (or setting PROXY_BASE_URL) is what establishes the shared client.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -2644,27 +2644,27 @@ async def test_public_register_route_without_configured_origin_does_not_pin_the_ try: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value=request_payload), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch.object(global_mcp_server_manager, "is_config_declared_server", return_value=True), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), - patch("litellm.proxy._experimental.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=mock_update), + patch("litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.get_mcp_server_oauth_client_credentials", new=AsyncMock(return_value=None), ), patch( - "litellm.proxy._experimental.mcp_server.db.create_mcp_server_oauth_client_credentials_if_absent", + "litellm.proxy.mcp_server.db.create_mcp_server_oauth_client_credentials_if_absent", new=mock_create, ), patch( - "litellm.proxy._experimental.mcp_server.db.upsert_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.upsert_mcp_server_oauth_client_credentials", new=mock_upsert, ), ): @@ -2688,13 +2688,13 @@ async def test_authorize_endpoint_respects_x_forwarded_proto(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -2725,7 +2725,7 @@ async def test_authorize_endpoint_respects_x_forwarded_proto(): mock_request.headers = {"X-Forwarded-Proto": "https"} # Behind HTTPS proxy # Mock the encryption functions - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: mock_encrypt.return_value = "mocked_encrypted_state" # Call authorize endpoint @@ -2754,13 +2754,13 @@ async def test_token_endpoint_respects_x_forwarded_proto(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( token_endpoint, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -2804,7 +2804,7 @@ async def test_token_endpoint_respects_x_forwarded_proto(): mock_async_client.post = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client" + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client" ) as mock_get_client: mock_get_client.return_value = mock_async_client @@ -2830,13 +2830,13 @@ async def test_oauth_protected_resource_respects_x_forwarded_proto(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( oauth_protected_resource_mcp, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -2883,13 +2883,13 @@ async def test_oauth_authorization_server_respects_x_forwarded_proto(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( oauth_authorization_server_mcp, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -2939,10 +2939,10 @@ async def test_register_client_respects_x_forwarded_proto(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -2957,7 +2957,7 @@ async def test_register_client_respects_x_forwarded_proto(): mock_request.headers = {"X-Forwarded-Proto": "https"} # Behind HTTPS proxy with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value={}), ): result = await register_client(request=mock_request) @@ -2977,13 +2977,13 @@ async def test_authorize_endpoint_respects_x_forwarded_host(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -3019,7 +3019,7 @@ async def test_authorize_endpoint_respects_x_forwarded_host(): } # Mock the encryption functions - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: mock_encrypt.return_value = "mocked_encrypted_state" # Call authorize endpoint @@ -3048,13 +3048,13 @@ async def test_token_endpoint_respects_x_forwarded_host(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( token_endpoint, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -3101,7 +3101,7 @@ async def test_token_endpoint_respects_x_forwarded_host(): mock_async_client.post = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client" + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client" ) as mock_get_client: mock_get_client.return_value = mock_async_client @@ -3279,7 +3279,7 @@ def test_get_request_base_url_comprehensive( try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( get_request_base_url, ) except ImportError: @@ -3302,7 +3302,7 @@ def test_get_request_base_url_comprehensive( mock_request.headers.get = mock_get with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.is_request_from_trusted_proxy", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.is_request_from_trusted_proxy", return_value=True, ): result = get_request_base_url(mock_request) @@ -3363,7 +3363,7 @@ def test_get_request_base_url_xff_trust_gate(general_settings, direct_ip, expect try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( get_request_base_url, ) except ImportError: @@ -3403,10 +3403,10 @@ def test_xff_misconfig_warning_emitted_once(caplog): from fastapi import Request from litellm.proxy import auth as proxy_auth_pkg # noqa: F401 - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.auth import ip_address_utils + from litellm.proxy.mcp_server.discoverable_endpoints import ( get_request_base_url, ) - from litellm.proxy.auth import ip_address_utils except ImportError: pytest.skip("MCP discoverable endpoints not available") @@ -3441,7 +3441,7 @@ def test_get_request_base_url_honors_proxy_base_url_env(monkeypatch): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( get_request_base_url, ) except ImportError: @@ -3469,7 +3469,7 @@ def test_validate_trusted_redirect_uri_logs_diagnostic_on_rejection(caplog, monk try: from fastapi import HTTPException, Request - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) except ImportError: @@ -3531,7 +3531,7 @@ def test_validate_trusted_redirect_uri_follows_the_xff_trust_gate(direct_ip, exp try: from fastapi import HTTPException, Request - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) except ImportError: @@ -3584,8 +3584,8 @@ def test_get_request_base_url_rejects_malformed_proxy_base_url(bad_value, monkey try: from fastapi import Request - from litellm.proxy._experimental.mcp_server import oauth_utils - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server import oauth_utils + from litellm.proxy.mcp_server.oauth_utils import ( get_request_base_url, ) except ImportError: @@ -3623,8 +3623,8 @@ def test_get_request_base_url_malformed_proxy_base_url_warning_is_one_shot(monke try: from fastapi import Request - from litellm.proxy._experimental.mcp_server import oauth_utils - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server import oauth_utils + from litellm.proxy.mcp_server.oauth_utils import ( get_request_base_url, ) except ImportError: @@ -3667,13 +3667,13 @@ async def test_oauth_protected_resource_returns_empty_scopes_when_none(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_protected_resource_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -3724,13 +3724,13 @@ async def test_oauth_protected_resource_gateway_managed_oauth2_advertises_gatewa try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_protected_resource_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -3808,9 +3808,9 @@ def test_root_protected_resource_discovers_gateway(monkeypatch, server_count, by from fastapi import FastAPI from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server import byok_oauth_endpoints, discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server import byok_oauth_endpoints, discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp_server.mcp_server_manager import MCPServer monkeypatch.setenv("PROXY_BASE_URL", base_url) @@ -3858,7 +3858,7 @@ def test_root_protected_resource_discovers_gateway(monkeypatch, server_count, by async def test_unnamed_protected_resource_builder_uses_gateway_origin(monkeypatch): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_protected_resource_response, ) @@ -3883,13 +3883,13 @@ async def test_oauth_authorization_server_returns_empty_scopes_when_none(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_authorization_server_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -3977,8 +3977,8 @@ def _create_id_lookup_oauth2_server(): async def test_authorize_resolves_server_by_id_when_name_lookup_fails(): from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _create_id_lookup_oauth2_server() request = MagicMock(spec=Request) @@ -4014,8 +4014,8 @@ async def test_authorize_resolves_server_by_id_when_name_lookup_fails(): async def test_token_endpoint_resolves_server_by_id_when_name_lookup_fails(): from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _create_id_lookup_oauth2_server() request = MagicMock(spec=Request) @@ -4057,8 +4057,8 @@ async def test_token_endpoint_resolves_server_by_id_when_name_lookup_fails(): async def test_register_client_resolves_server_by_id_when_name_lookup_fails(): from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _create_id_lookup_oauth2_server().model_copy( update={"client_id": None, "client_secret": None, "registration_url": "https://provider.com/oauth/register"} @@ -4097,8 +4097,8 @@ async def test_register_client_resolves_server_by_id_when_name_lookup_fails(): async def test_protected_resource_metadata_resolves_server_by_id_when_name_lookup_fails(): from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _create_id_lookup_oauth2_server() request = MagicMock(spec=Request) @@ -4128,8 +4128,8 @@ async def test_protected_resource_metadata_resolves_server_by_id_when_name_looku def test_authorization_server_metadata_resolves_server_by_id_when_name_lookup_fails(): from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _create_id_lookup_oauth2_server() request = MagicMock(spec=Request) @@ -4161,10 +4161,10 @@ async def test_authorize_root_resolves_single_oauth2_server(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -4180,7 +4180,7 @@ async def test_authorize_root_resolves_single_oauth2_server(): try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper" + "litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper" ) as mock_encrypt: mock_encrypt.return_value = "mocked_encrypted_state" @@ -4208,10 +4208,10 @@ async def test_authorize_root_fails_with_multiple_oauth2_servers(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -4248,10 +4248,10 @@ async def test_authorize_root_does_not_resolve_private_server_for_external_clien try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -4267,7 +4267,7 @@ async def test_authorize_root_does_not_resolve_private_server_for_external_clien try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", return_value="198.51.100.10", ): with pytest.raises(HTTPException) as exc_info: @@ -4289,10 +4289,10 @@ async def test_token_root_resolves_single_oauth2_server(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( token_endpoint, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -4319,7 +4319,7 @@ async def test_token_root_resolves_single_oauth2_server(): try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client" + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client" ) as mock_get_client: mock_get_client.return_value = mock_async_client @@ -4354,10 +4354,10 @@ async def test_token_root_does_not_resolve_private_server_for_external_client(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( token_endpoint, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -4373,7 +4373,7 @@ async def test_token_root_does_not_resolve_private_server_for_external_client(): try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", return_value="198.51.100.10", ): with pytest.raises(HTTPException) as exc_info: @@ -4401,10 +4401,10 @@ async def test_register_root_does_aggregate_dcr_not_single_server_resolution(): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -4419,7 +4419,7 @@ async def test_register_root_does_aggregate_dcr_not_single_server_resolution(): try: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value={"redirect_uris": ["https://claude.ai/cb"]}), ), patch("litellm.proxy.proxy_server.master_key", "sk-test-salt-for-lit3637"), @@ -4442,10 +4442,10 @@ async def test_register_root_does_not_leak_a_private_server(): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -4460,11 +4460,11 @@ async def test_register_root_does_not_leak_a_private_server(): try: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value={"redirect_uris": ["https://claude.ai/cb"]}), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", return_value="198.51.100.10", ), patch("litellm.proxy.proxy_server.master_key", "sk-test-salt-for-lit3637"), @@ -4484,10 +4484,10 @@ async def test_discovery_root_includes_server_name_prefix(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_authorization_server_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -4523,11 +4523,11 @@ async def test_discovery_root_does_not_expose_private_server_for_external_client try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_authorization_server_response, _build_oauth_protected_resource_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -4543,7 +4543,7 @@ async def test_discovery_root_does_not_expose_private_server_for_external_client try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", return_value="198.51.100.10", ): authorization_response = _build_oauth_authorization_server_response( @@ -4570,7 +4570,7 @@ async def test_discovery_root_does_not_expose_private_server_for_external_client async def test_oauth_callback_redirects_with_state(): """Test OAuth callback endpoint properly decodes state and redirects to client callback URL.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( callback, ) except ImportError: @@ -4585,7 +4585,7 @@ async def test_oauth_callback_redirects_with_state(): "client_redirect_uri": "http://localhost:3000/ui/mcp/oauth/callback", } - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: mock_decode.return_value = mock_state_data # Call callback endpoint with code and state @@ -4611,13 +4611,13 @@ async def test_oauth_callback_preserves_client_redirect_uri_query(): try: from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( callback, ) except ImportError: pytest.skip("MCP discoverable endpoints not available") - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: mock_decode.return_value = { "base_url": "http://localhost:3000/ui/mcp/oauth/callback", "original_state": "test-uuid-state-123", @@ -4644,14 +4644,14 @@ async def test_oauth_callback_preserves_client_redirect_uri_query(): async def test_oauth_callback_handles_invalid_state(): """Test OAuth callback returns error page when state decryption fails.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( callback, ) except ImportError: pytest.skip("MCP discoverable endpoints not available") # Mock state decoding to raise an exception - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: mock_decode.side_effect = Exception("Failed to decrypt state") # Call callback endpoint with invalid state @@ -4670,11 +4670,11 @@ async def test_oauth_callback_handles_invalid_state(): async def test_oauth_callback_accepts_same_origin_ui_redirect(): """UI OAuth flow: the callback should redirect to the proxy's own UI origin when the encrypted state carries a same-origin client_redirect_uri.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( callback, ) - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: mock_decode.return_value = { "base_url": "https://proxy.example.com/ui/mcp/oauth/callback", "original_state": "state-123", @@ -4707,13 +4707,13 @@ async def test_authorize_forwards_short_state_and_round_trips_via_cookie(monkeyp from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _oauth_state_cookie_name, authorize_with_server, callback, decode_state_hash, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -4806,7 +4806,7 @@ async def test_callback_error_path_reads_cookie_and_clears_it(monkeypatch): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _oauth_state_cookie_name, callback, encode_state_with_base_url, @@ -4879,7 +4879,7 @@ async def _authorize_then_callback(server, iss, monkeypatch, expected_issuer_ove from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _oauth_state_cookie_name, authorize_with_server, callback, @@ -5026,10 +5026,10 @@ async def test_oauth_authorize_includes_scopes_from_server_config(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -5052,7 +5052,7 @@ async def test_oauth_authorize_includes_scopes_from_server_config(): mock_request.base_url = "https://litellm.example.com/" mock_request.headers = {} - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: mock_encrypt.return_value = "encrypted_state" # Call authorize without explicit scope parameter @@ -5082,10 +5082,10 @@ async def test_oauth_authorize_prefers_request_scope_over_server_config(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -5107,7 +5107,7 @@ async def test_oauth_authorize_prefers_request_scope_over_server_config(): mock_request.base_url = "https://litellm.example.com/" mock_request.headers = {} - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: mock_encrypt.return_value = "encrypted_state" # Call authorize WITH explicit scope parameter @@ -5138,13 +5138,13 @@ async def test_token_endpoint_refresh_token_grant(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( token_endpoint, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -5187,7 +5187,7 @@ async def test_token_endpoint_refresh_token_grant(): mock_async_client.post = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client" + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client" ) as mock_get_client: mock_get_client.return_value = mock_async_client @@ -5225,13 +5225,13 @@ async def test_token_endpoint_refresh_token_grant(): async def test_token_endpoint_authorization_code_missing_code(): """Test that authorization_code grant rejects missing code param.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -5278,13 +5278,13 @@ async def test_authorize_endpoint_rejects_non_loopback_redirect_uri(): primitive — reject with 400 before encoding anything into state.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5325,13 +5325,13 @@ async def test_authorize_endpoint_accepts_ipv4_loopback_range_and_ipv6_full_form would miss ``127.0.0.2`` and ``0:0:0:0:0:0:0:1``.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5360,7 +5360,7 @@ async def test_authorize_endpoint_accepts_ipv4_loopback_range_and_ipv6_full_form "http://localhost:3000/cb", ): with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper" + "litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper" ) as mock_encrypt: mock_encrypt.return_value = "mocked_encrypted_state" response = await authorize( @@ -5380,11 +5380,11 @@ async def test_callback_revalidates_loopback_on_decoded_base_url(): valid. /callback must re-validate the decoded base_url so those stale states can't be used as an open-redirect + code-theft primitive.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( callback, ) - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: mock_decode.return_value = { "base_url": "https://attacker.example.com/cb", "original_state": "s", @@ -5404,11 +5404,11 @@ async def test_callback_revalidates_loopback_on_decoded_base_url(): @pytest.mark.asyncio async def test_callback_revalidates_loopback_on_decoded_client_redirect_uri(): """If a state contains a full client_redirect_uri, validate that exact sink.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( callback, ) - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: mock_decode.return_value = { "base_url": "http://localhost:3000/cb", "original_state": "s", @@ -5428,11 +5428,11 @@ async def test_callback_revalidates_loopback_on_decoded_client_redirect_uri(): @pytest.mark.asyncio async def test_callback_rejects_state_missing_redirect_uri(): """Malformed state without a redirect target should fail with a structured 400.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( callback, ) - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: mock_decode.return_value = { "original_state": "s", "code_challenge": None, @@ -5454,10 +5454,10 @@ async def test_token_endpoint_sets_no_store_cache_control(): NOT be cached by intermediaries or the client.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5488,7 +5488,7 @@ async def test_token_endpoint_sets_no_store_cache_control(): fake_http_client.post = AsyncMock(return_value=fake_http_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ): response = await exchange_token_with_server( @@ -5509,10 +5509,10 @@ async def test_token_endpoint_sets_no_store_cache_control(): async def _exchange_with_upstream_token_response(upstream_body): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5539,7 +5539,7 @@ async def _exchange_with_upstream_token_response(upstream_body): fake_http_client.post = AsyncMock(return_value=fake_http_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ): response = await exchange_token_with_server( @@ -5599,12 +5599,13 @@ def _bridge_server(**overrides): return MCPServer(**fields) -def _bridge_mock_request(): +def _bridge_mock_request(cookie: str | None = None) -> MagicMock: from fastapi import Request - mock_request = MagicMock(spec=Request) + mock_request: Final = MagicMock(spec=Request) mock_request.base_url = "https://litellm.example.com/" mock_request.headers = {} + mock_request.cookies = {"token": cookie} if cookie else {} return mock_request @@ -5617,7 +5618,7 @@ async def test_authorize_bridge_relay_passes_client_params_verbatim(auth_type_va and applies no gateway-side redirect trust (the upstream enforces its registered binding).""" from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) from litellm.types.mcp import MCPAuth @@ -5654,7 +5655,7 @@ async def test_authorize_bridge_requires_s256_pkce(code_challenge, code_challeng """Bridge servers serve unauthenticated public clients, so the PKCE downgrade paths (missing challenge, or a method that is not S256; RFC 7636 defaults a missing method to plain) are rejected at the gateway on both bridge arms.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) @@ -5681,7 +5682,7 @@ async def test_authorize_bridge_short_circuit_keeps_callback_and_redirect_trust( through the gateway callback with the state cookie.""" from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) @@ -5700,7 +5701,7 @@ async def test_authorize_bridge_short_circuit_keeps_callback_and_redirect_trust( assert exc.value.status_code in (400, 403) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper", + "litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper", return_value="mocked_encrypted_state", ): response = await authorize_with_server( @@ -5724,12 +5725,12 @@ async def test_authorize_non_bridge_client_forwarded_keeps_pre_bridge_contract() requirement and the gateway /callback relay (this is the browser-only Authorize path).""" from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper", + "litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper", return_value="mocked_encrypted_state", ): response = await authorize_with_server( @@ -5746,7 +5747,7 @@ async def test_authorize_non_bridge_client_forwarded_keeps_pre_bridge_contract() async def _bridge_token_post_data(server, redirect_uri): - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) @@ -5757,7 +5758,7 @@ async def _bridge_token_post_data(server, redirect_uri): fake_http_client.post = AsyncMock(return_value=fake_http_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ): await exchange_token_with_server( @@ -5787,7 +5788,7 @@ async def test_token_bridge_relay_posts_client_redirect_uri(): @pytest.mark.asyncio async def test_token_bridge_relay_requires_redirect_uri(): - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) @@ -5817,10 +5818,10 @@ async def test_token_non_bridge_keeps_gateway_callback(): def _named_as_metadata_response(server): - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_authorization_server_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -5828,7 +5829,7 @@ def _named_as_metadata_response(server): global_mcp_server_manager.registry[server.server_id] = server try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", return_value=None, ): return _build_oauth_authorization_server_response( @@ -5864,7 +5865,7 @@ async def _bridge_register_response( replace_stale_client: bool = False, database_connected: bool = True, ) -> tuple[Response, MagicMock, AsyncMock]: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) @@ -5881,15 +5882,15 @@ async def _bridge_register_response( with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._persist_dcr_client_registration", + "litellm.proxy.mcp_server.discoverable_endpoints._persist_dcr_client_registration", new_callable=AsyncMock, ) as mock_persist, patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", + "litellm.proxy.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", new_callable=AsyncMock, return_value=False, ), @@ -5948,7 +5949,7 @@ async def test_register_bridge_relay_surfaces_upstream_error_not_500(): RFC 7591 error body to the client, not a bare 500 that hides the real reason.""" import httpx - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) @@ -5966,11 +5967,11 @@ async def test_register_bridge_relay_surfaces_upstream_error_not_500(): with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", + "litellm.proxy.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", new_callable=AsyncMock, return_value=False, ), @@ -5997,7 +5998,7 @@ async def test_register_non_bridge_upstream_error_relays_status_not_500(): opaque 500 that hides the real reason from the create-flow UI.""" import httpx - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) @@ -6015,11 +6016,11 @@ async def test_register_non_bridge_upstream_error_relays_status_not_500(): with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", + "litellm.proxy.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", new_callable=AsyncMock, return_value=False, ), @@ -6150,8 +6151,8 @@ async def test_authorize_clientless_bridge_loads_shared_client_before_choosing_t kept one), the caller keeps its own upstream binding through the relay.""" from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import authorize_with_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.discoverable_endpoints import authorize_with_server + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager monkeypatch.setenv("PROXY_BASE_URL", "https://litellm.example.com") monkeypatch.setenv("LITELLM_SALT_KEY", "test-registration-binding") @@ -6166,7 +6167,7 @@ async def test_authorize_clientless_bridge_loads_shared_client_before_choosing_t return_value=prisma_client, ), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch.object( @@ -6175,7 +6176,7 @@ async def test_authorize_clientless_bridge_loads_shared_client_before_choosing_t new=mock_update_server, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper", + "litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper", return_value="mocked_encrypted_state", ), ): @@ -6212,7 +6213,7 @@ async def test_token_clientless_bridge_loads_shared_client_before_choosing_the_a ) -> None: """The token leg mirrors authorize: with the shared client persisted it redeems the code with that client and the gateway /callback, and with none yet it relays the caller's own client and redirect.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager monkeypatch.setenv("PROXY_BASE_URL", "https://litellm.example.com") monkeypatch.setenv("LITELLM_SALT_KEY", "test-registration-binding") @@ -6224,7 +6225,7 @@ async def test_token_clientless_bridge_loads_shared_client_before_choosing_the_a with ( patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=prisma_client), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch.object( @@ -6250,10 +6251,10 @@ async def test_persist_dcr_client_for_client_forwarded_server_only_when_it_is_a_ ) -> None: """A DCR bridge keeps the shared gateway client on the server row (without stamping oauth2_flow on a client-forwarded row), while a client-forwarded server without the bridge still stores nothing.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _persist_dcr_client_registration, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) from litellm.types.mcp import MCPAuth @@ -6264,7 +6265,7 @@ async def test_persist_dcr_client_for_client_forwarded_server_only_when_it_is_a_ mock_update: Final = AsyncMock(return_value=MagicMock()) with ( patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=prisma), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=mock_update), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update), patch.object(global_mcp_server_manager, "update_server", new=AsyncMock()), patch.object(global_mcp_server_manager, "is_config_declared_server", return_value=False), ): @@ -6292,8 +6293,8 @@ async def test_token_sealed_ephemeral_client_is_not_replaced_by_persisted_gatewa server_has_shared_client: bool, ) -> None: """The token leg must use the sealed ephemeral client even if this worker's catalog has a shared client.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import exchange_token_with_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.discoverable_endpoints import exchange_token_with_server + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager monkeypatch.setenv("PROXY_BASE_URL", "https://litellm.example.com") monkeypatch.setenv("LITELLM_SALT_KEY", "test-registration-binding") @@ -6319,7 +6320,7 @@ async def test_token_sealed_ephemeral_client_is_not_replaced_by_persisted_gatewa return_value=prisma_client, ), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch.object( @@ -6328,7 +6329,7 @@ async def test_token_sealed_ephemeral_client_is_not_replaced_by_persisted_gatewa new=mock_update_server, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), ): @@ -6358,8 +6359,8 @@ _BRIDGE_MASTER_KEY = "sk-bridge-producer-master-key-0123456789abcdef" async def _exchange_for_bridge_server(server, upstream_body, key_hash, code="auth-code", fake_client_out=None): - from litellm.proxy._experimental.mcp_server.bridge_token_flow import _ResolvedKey - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import exchange_token_with_server + from litellm.proxy.mcp_server.bridge_token_flow import _ResolvedKey + from litellm.proxy.mcp_server.discoverable_endpoints import exchange_token_with_server fake_http_response = MagicMock() fake_http_response.json.return_value = upstream_body @@ -6375,11 +6376,11 @@ async def _exchange_for_bridge_server(server, upstream_body, key_hash, code="aut with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._resolve_active_litellm_key", + "litellm.proxy.mcp_server.bridge_token_flow._resolve_active_litellm_key", new=key_resolver, ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -6394,7 +6395,7 @@ async def _exchange_for_bridge_server(server, upstream_body, key_hash, code="aut client_secret=None, code_verifier="verifier", ) - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import is_bridge_authorization_code + from litellm.proxy.mcp_server.discoverable_endpoints import is_bridge_authorization_code # The key_hash path resolves the presented litellm key; the interactive SSO path recovers identity # from the gateway authorization code instead, so it never awaits the resolver. @@ -6413,7 +6414,7 @@ async def test_oauth_delegate_bridge_token_exchange_mints_envelope_not_raw_token never appears in the bearer the client receives.""" from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( BridgeEnvelopeAdmitted, envelope_keys_from_master_key, resolve_bridge_envelope, @@ -6444,7 +6445,7 @@ def test_bridge_authorization_code_round_trips_and_rejects_hostile_input(): """The gateway authorization code seals and recovers the upstream code and the SSO user, and is total over hostile input: a raw upstream code (scripted path) opens to None, and a tampered or non-gateway value opens to None rather than raising.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( is_bridge_authorization_code, open_bridge_authorization_code, seal_bridge_authorization_code, @@ -6472,10 +6473,10 @@ async def test_interactive_bridge_token_exchange_mints_user_subject_envelope(): gateway code, not the sealed wrapper.""" from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( seal_bridge_authorization_code, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( BridgeEnvelopeAdmitted, envelope_keys_from_master_key, resolve_bridge_envelope, @@ -6507,7 +6508,7 @@ async def test_interactive_bridge_token_exchange_mints_user_subject_envelope(): async def test_interactive_bridge_gateway_code_for_another_server_is_rejected_400(): """A gateway authorization code is bound to the server it was minted for: presenting it at another server's token endpoint is a 400, so a code cannot be replayed across a server boundary.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( seal_bridge_authorization_code, ) from litellm.types.mcp import MCPAuth @@ -6524,22 +6525,23 @@ async def test_interactive_bridge_gateway_code_for_another_server_is_rejected_40 @pytest.mark.asyncio -async def test_interactive_bridge_authorize_seals_sso_user_into_state(): +async def test_interactive_bridge_authorize_seals_sso_user_into_state(monkeypatch: pytest.MonkeyPatch) -> None: """On the short-circuit bridge oauth_delegate arm, authorize captures the SSO user from the UI session cookie and seals it (and the target server) into the encrypted OAuth state, so the callback can later mint a user-bound gateway code; it still proceeds to the upstream redirect. The access gate runs for real against a granted resolver, so its interface stays exercised.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import authorize_with_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.discoverable_endpoints import authorize_with_server + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import UserAPIKeyAuth from litellm.types.mcp import MCPAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate, client_id="admin-client", registration_url=None) admitted = UserAPIKeyAuth(user_id="sso-user-42") admitted.mcp_admitted_user_subject = True captured: dict = {} + cookie: Final = _browser_session_cookie(monkeypatch, "sso-user-42") def _capture(**kwargs): captured.update(kwargs) @@ -6547,11 +6549,7 @@ async def test_interactive_bridge_authorize_seals_sso_user_into_state(): with ( patch( - "litellm.proxy._experimental.mcp_server.byok_oauth_endpoints.user_id_from_session_cookie", - return_value="sso-user-42", - ), - patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", new=AsyncMock(return_value=admitted), ), patch.object( @@ -6560,12 +6558,12 @@ async def test_interactive_bridge_authorize_seals_sso_user_into_state(): new=AsyncMock(return_value=[server.server_id]), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.encode_state_with_base_url", + "litellm.proxy.mcp_server.discoverable_endpoints.encode_state_with_base_url", side_effect=_capture, ), ): response = await authorize_with_server( - request=_bridge_mock_request(), + request=_bridge_mock_request(cookie), mcp_server=server, client_id="ignored", redirect_uri="http://127.0.0.1:60108/callback", @@ -6581,7 +6579,9 @@ async def test_interactive_bridge_authorize_seals_sso_user_into_state(): @pytest.mark.asyncio @pytest.mark.parametrize("user_can_reach_server", [True, False]) -async def test_bridge_authorize_gates_on_the_egress_server_access_resolver(user_can_reach_server): +async def test_bridge_authorize_gates_on_the_egress_server_access_resolver( + monkeypatch: pytest.MonkeyPatch, user_can_reach_server: bool +) -> None: """The interactive dcr_bridge oauth_delegate authorize admits the signed-in user the way MCP egress will and refuses with an RFC 6749 access_denied redirect when that admitted subject cannot reach the target server, instead of minting an envelope whose every tool request would @@ -6590,11 +6590,11 @@ async def test_bridge_authorize_gates_on_the_egress_server_access_resolver(user_ from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import authorize - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.discoverable_endpoints import authorize + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import UserAPIKeyAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate, client_id="upstream-app", registration_url=None) global_mcp_server_manager.registry.clear() @@ -6607,16 +6607,13 @@ async def test_bridge_authorize_gates_on_the_egress_server_access_resolver(user_ mock_request = MagicMock(spec=Request) mock_request.base_url = "https://litellm.example.com/" mock_request.headers = {} + mock_request.cookies = {"token": _browser_session_cookie(monkeypatch, "bridge-user-1")} client_redirect = "http://127.0.0.1:60108/callback" try: with ( patch( - "litellm.proxy._experimental.mcp_server.byok_oauth_endpoints.user_id_from_session_cookie", - return_value="bridge-user-1", - ), - patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", new=AsyncMock(return_value=admitted), ) as mock_reload, patch.object( @@ -6625,7 +6622,7 @@ async def test_bridge_authorize_gates_on_the_egress_server_access_resolver(user_ new=AsyncMock(return_value=allowed), ) as mock_allowed, patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper", + "litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper", return_value="mocked_encrypted_state", ), ): @@ -6660,15 +6657,17 @@ async def test_bridge_authorize_gates_on_the_egress_server_access_resolver(user_ @pytest.mark.asyncio @pytest.mark.parametrize("reload_status,expect_denial", [(401, True), (500, False), (503, False)]) -async def test_bridge_authorize_reload_failure_denies_or_stays_retryable(reload_status, expect_denial): +async def test_bridge_authorize_reload_failure_denies_or_stays_retryable( + monkeypatch: pytest.MonkeyPatch, reload_status: int, expect_denial: bool +) -> None: """An unknown or deactivated signed-in user denies like a missing grant (fail closed); a DB outage keeps its retryable 503 instead of masquerading as an access denial.""" from urllib.parse import parse_qs, urlparse from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import authorize - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.discoverable_endpoints import authorize + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6679,15 +6678,12 @@ async def test_bridge_authorize_reload_failure_denies_or_stays_retryable(reload_ mock_request = MagicMock(spec=Request) mock_request.base_url = "https://litellm.example.com/" mock_request.headers = {} + mock_request.cookies = {"token": _browser_session_cookie(monkeypatch, "bridge-user-1")} try: with ( patch( - "litellm.proxy._experimental.mcp_server.byok_oauth_endpoints.user_id_from_session_cookie", - return_value="bridge-user-1", - ), - patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", new=AsyncMock(side_effect=HTTPException(status_code=reload_status, detail="x")), ), ): @@ -6724,23 +6720,19 @@ async def test_bridge_authorize_reload_failure_denies_or_stays_retryable(reload_ async def test_interactive_bridge_authorize_without_session_redirects_to_login(): """Without a UI session there is no identity to bind, so the short-circuit bridge oauth_delegate authorize sends the browser through litellm login instead of proceeding to the upstream.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import authorize_with_server + from litellm.proxy.mcp_server.discoverable_endpoints import authorize_with_server from litellm.types.mcp import MCPAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate, client_id="admin-client", registration_url=None) - with patch( - "litellm.proxy._experimental.mcp_server.byok_oauth_endpoints.user_id_from_session_cookie", - return_value=None, - ): - response = await authorize_with_server( - request=_bridge_mock_request(), - mcp_server=server, - client_id="ignored", - redirect_uri="http://127.0.0.1:60108/callback", - state="s", - code_challenge="chal", - code_challenge_method="S256", - ) + response = await authorize_with_server( + request=_bridge_mock_request(), + mcp_server=server, + client_id="ignored", + redirect_uri="http://127.0.0.1:60108/callback", + state="s", + code_challenge="chal", + code_challenge_method="S256", + ) assert "/sso/key/generate" in response.headers["location"] @@ -6751,7 +6743,7 @@ async def test_interactive_bridge_callback_seals_user_into_gateway_code(): code, so the client's later token call can prove who signed in.""" from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( callback, is_bridge_authorization_code, ) @@ -6765,15 +6757,15 @@ async def test_interactive_bridge_callback_seals_user_into_gateway_code(): } with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._resolve_encoded_oauth_state", + "litellm.proxy.mcp_server.discoverable_endpoints._resolve_encoded_oauth_state", return_value="enc", ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash", + "litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash", return_value=state_data, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._get_validated_client_redirect_uri", + "litellm.proxy.mcp_server.discoverable_endpoints._get_validated_client_redirect_uri", return_value="http://127.0.0.1:60108/cb", ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -6850,10 +6842,10 @@ async def test_bridge_access_envelope_never_carries_upstream_refresh_token(): refresh envelope returned as the response's refresh_token, encrypted, never in plaintext.""" from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( envelope_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( OpenedEnvelope, open_envelope, ) @@ -6885,7 +6877,7 @@ async def test_bridge_refresh_grant_with_non_envelope_is_invalid_grant_before_up token, so a refresh_token grant carrying a bare (non-envelope) value is invalid_grant, rejected in _prepare_bridge_refresh BEFORE any upstream exchange. Rejecting before the exchange means a bad refresh request can never consume or rotate an upstream refresh token.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import exchange_token_with_server + from litellm.proxy.mcp_server.discoverable_endpoints import exchange_token_with_server from litellm.types.mcp import MCPAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate) @@ -6893,7 +6885,7 @@ async def test_bridge_refresh_grant_with_non_envelope_is_invalid_grant_before_up fake_http_client.post = AsyncMock() with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -6929,11 +6921,11 @@ def _mint_test_refresh_envelope( from pydantic import SecretStr - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( build_bridge_refresh_token_response, envelope_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( RefreshCredential, SealedEnvelope, key_hash_identity, @@ -6960,7 +6952,7 @@ async def _refresh_for_bridge_server( ``upstream_body``. Patching the single subject-revalidation dispatch covers both a key_hash and a user_id refresh envelope. Returns the response; the captured client exposes the POST call so a test can assert what refresh token was actually sent upstream.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import exchange_token_with_server + from litellm.proxy.mcp_server.discoverable_endpoints import exchange_token_with_server fake_http_response = MagicMock() fake_http_response.json.return_value = upstream_body @@ -6972,11 +6964,11 @@ async def _refresh_for_bridge_server( with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._revalidate_active_subject", + "litellm.proxy.mcp_server.bridge_token_flow._revalidate_active_subject", new=AsyncMock(return_value=revalidate_result), ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -7001,10 +6993,10 @@ async def test_bridge_mint_returns_refresh_envelope_that_opens_to_upstream_refre (under the same keys and server_id) to the upstream refresh token, so the client can renew later.""" from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( envelope_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( OpenedRefreshEnvelope, open_refresh_envelope, ) @@ -7068,10 +7060,10 @@ async def test_bridge_refresh_grant_rotates_refresh_envelope_wrapping_new_upstre that wraps the NEW upstream refresh token, so the rotation is carried through faithfully.""" from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( envelope_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( OpenedRefreshEnvelope, open_refresh_envelope, ) @@ -7140,12 +7132,12 @@ async def test_bridge_refresh_grant_renews_a_user_subject_envelope(): exchange received the real upstream refresh token, not the client's envelope.""" from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( BridgeEnvelopeAdmitted, envelope_keys_from_master_key, resolve_bridge_envelope, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import user_identity + from litellm.proxy.mcp_server.outbound_credentials.envelope import user_identity from litellm.types.mcp import MCPAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate) @@ -7198,10 +7190,10 @@ async def test_bridge_refresh_re_seals_scope_when_upstream_omits_it_so_the_chain the upstream response had none, and a second refresh off it still re-requests the scope.""" from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( envelope_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( OpenedRefreshEnvelope, open_refresh_envelope, ) @@ -7237,7 +7229,7 @@ async def test_bridge_refresh_grant_with_deactivated_user_is_invalid_grant_befor the user no longer exists) cannot keep refreshing: subject re-validation reports no_active_key and the refresh is invalid_grant, returned BEFORE the upstream exchange. Revocation kills renewal for the user subject exactly as it does for the key subject.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import user_identity + from litellm.proxy.mcp_server.outbound_credentials.envelope import user_identity from litellm.types.mcp import MCPAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate) @@ -7256,19 +7248,19 @@ async def test_bridge_refresh_grant_with_deactivated_user_is_invalid_grant_befor async def test_revalidate_active_subject_dispatches_on_subject_type(): """Subject re-validation routes a key_hash envelope to the key reload and a user_id envelope to the user reload, so revocation gates renewal for either identity source through one dispatch point.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy.mcp_server.bridge_token_flow import ( _ResolvedKey, _revalidate_active_subject, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import key_hash_identity, user_identity + from litellm.proxy.mcp_server.outbound_credentials.envelope import key_hash_identity, user_identity with ( patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._reload_active_key_by_hash", + "litellm.proxy.mcp_server.bridge_token_flow._reload_active_key_by_hash", new=AsyncMock(return_value=_ResolvedKey(key_hash="kh", key=MagicMock())), ) as key_reload, patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow.reload_active_user_by_id", + "litellm.proxy.mcp_server.bridge_token_flow.reload_active_user_by_id", new=AsyncMock(return_value=None), ) as user_reload, ): @@ -7278,11 +7270,11 @@ async def test_revalidate_active_subject_dispatches_on_subject_type(): with ( patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._reload_active_key_by_hash", + "litellm.proxy.mcp_server.bridge_token_flow._reload_active_key_by_hash", new=AsyncMock(), ) as key_reload2, patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow.reload_active_user_by_id", + "litellm.proxy.mcp_server.bridge_token_flow.reload_active_user_by_id", new=AsyncMock(return_value="no_active_key"), ) as user_reload2, ): @@ -7296,7 +7288,7 @@ def test_upstream_refresh_credential_expired_refresh_token_is_not_sealed(): not be sealed: _upstream_refresh_credential returns None so the exchange degrades to an access-only response, mirroring how the access grant refuses an already-elapsed access token rather than capping a dead token to the full refresh TTL. A live or unspecified lifetime still yields a credential.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import _upstream_refresh_credential + from litellm.proxy.mcp_server.bridge_token_flow import _upstream_refresh_credential assert _upstream_refresh_credential({"access_token": "A", "refresh_token": "R", "refresh_expires_in": 0}) is None assert _upstream_refresh_credential({"refresh_token": "R", "refresh_expires_in": -5}) is None @@ -7313,7 +7305,7 @@ async def test_bridge_refresh_upstream_invalid_grant_maps_to_invalid_grant(): client re-runs authorization_code, rather than surfacing the opaque upstream error it cannot act on.""" import httpx - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import exchange_token_with_server + from litellm.proxy.mcp_server.discoverable_endpoints import exchange_token_with_server from litellm.types.mcp import MCPAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate) @@ -7333,11 +7325,11 @@ async def test_bridge_refresh_upstream_invalid_grant_maps_to_invalid_grant(): with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._revalidate_active_subject", + "litellm.proxy.mcp_server.bridge_token_flow._revalidate_active_subject", new=AsyncMock(return_value=None), ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -7366,7 +7358,7 @@ async def test_bridge_refresh_upstream_error_detection_parses_json_not_substring as the classified upstream rejection rather than triggering a spurious authorization_code re-run.""" import httpx - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import exchange_token_with_server + from litellm.proxy.mcp_server.discoverable_endpoints import exchange_token_with_server from litellm.types.mcp import MCPAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate) @@ -7386,11 +7378,11 @@ async def test_bridge_refresh_upstream_error_detection_parses_json_not_substring with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._revalidate_active_subject", + "litellm.proxy.mcp_server.bridge_token_flow._revalidate_active_subject", new=AsyncMock(return_value=None), ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -7417,9 +7409,9 @@ async def test_revalidate_key_subject_revoked_when_owner_scim_deactivated(proxy_ """A key_hash refresh envelope whose key is still active but whose OWNING user was SCIM-deactivated must fail closed to no_active_key, mirroring how admission's _reject_if_admitted_owner_scim_deactivated revokes an offboarded owner's key. Without this, an offboarded user keeps renewing a live key.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import _ResolvedKey, _revalidate_active_subject - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import key_hash_identity from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import _ResolvedKey, _revalidate_active_subject + from litellm.proxy.mcp_server.outbound_credentials.envelope import key_hash_identity proxy_globals.user_api_key_cache = UserApiKeyCache() proxy_globals.prisma_client = object() @@ -7427,7 +7419,7 @@ async def test_revalidate_key_subject_revoked_when_owner_scim_deactivated(proxy_ resolved = _ResolvedKey(key_hash="kh", key=MagicMock(user_id="offboarded-owner")) with ( patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._reload_active_key_by_hash", + "litellm.proxy.mcp_server.bridge_token_flow._reload_active_key_by_hash", new=AsyncMock(return_value=resolved), ), patch( @@ -7445,9 +7437,9 @@ async def test_revalidate_key_subject_active_owner_renews_and_missing_owner_fail """The key-owner SCIM gate blocks only an explicit scim_active False: an active owner renews (None), and a missing owner (get_user_object's wrapped ValueError) fails OPEN, since a key may outlive its owner record and a transient blip must not revoke a live key.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import _ResolvedKey, _revalidate_active_subject - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import key_hash_identity from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import _ResolvedKey, _revalidate_active_subject + from litellm.proxy.mcp_server.outbound_credentials.envelope import key_hash_identity proxy_globals.user_api_key_cache = UserApiKeyCache() proxy_globals.prisma_client = object() @@ -7456,7 +7448,7 @@ async def test_revalidate_key_subject_active_owner_renews_and_missing_owner_fail with ( patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._reload_active_key_by_hash", + "litellm.proxy.mcp_server.bridge_token_flow._reload_active_key_by_hash", new=AsyncMock(return_value=resolved), ), patch( @@ -7468,7 +7460,7 @@ async def test_revalidate_key_subject_active_owner_renews_and_missing_owner_fail with ( patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._reload_active_key_by_hash", + "litellm.proxy.mcp_server.bridge_token_flow._reload_active_key_by_hash", new=AsyncMock(return_value=resolved), ), patch( @@ -7485,7 +7477,7 @@ async def test_bridge_mint_fails_closed_before_upstream_when_master_key_unset(): misconfigured gateway returns a 500 server_error without consuming the single-use code, avoiding the burn-then-fail the pre-exchange phase exists to prevent. The failure is returned as an RFC 6749 error body, not raised.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import exchange_token_with_server + from litellm.proxy.mcp_server.discoverable_endpoints import exchange_token_with_server from litellm.types.mcp import MCPAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate) @@ -7493,11 +7485,11 @@ async def test_bridge_mint_fails_closed_before_upstream_when_master_key_unset(): fake_http_client.post = AsyncMock() with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._resolve_active_litellm_key", + "litellm.proxy.mcp_server.bridge_token_flow._resolve_active_litellm_key", new=AsyncMock(return_value="no_active_key"), ), patch("litellm.proxy.proxy_server.master_key", None), @@ -7522,7 +7514,7 @@ async def _prepare_only_bridge_exchange(resolver_result): """Drive exchange_token_with_server for a bridge oauth_delegate authorization_code request with the identity resolver stubbed to a given tagged result, returning (response, post_mock) so a test can assert the mapped status and that the single-use code was never exchanged.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import exchange_token_with_server + from litellm.proxy.mcp_server.discoverable_endpoints import exchange_token_with_server from litellm.types.mcp import MCPAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate) @@ -7530,11 +7522,11 @@ async def _prepare_only_bridge_exchange(resolver_result): fake_http_client.post = AsyncMock() with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._resolve_active_litellm_key", + "litellm.proxy.mcp_server.bridge_token_flow._resolve_active_litellm_key", new=AsyncMock(return_value=resolver_result), ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -7597,7 +7589,7 @@ async def _exchange_for_bridge_server_with_jwt(jwt_auth_result, upstream_body=No presented credential is JWT-shaped, with _resolve_jwt_auth stubbed to a given result. Returns (response, post_mock) so a test can assert the minted envelope's sealed identity or the mapped error status.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import exchange_token_with_server + from litellm.proxy.mcp_server.discoverable_endpoints import exchange_token_with_server from litellm.types.mcp import MCPAuth request = _bridge_mock_request() @@ -7614,11 +7606,11 @@ async def _exchange_for_bridge_server_with_jwt(jwt_auth_result, upstream_body=No server = _bridge_server(auth_type=MCPAuth.oauth_delegate) with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._resolve_jwt_auth", + "litellm.proxy.mcp_server.bridge_token_flow._resolve_jwt_auth", new=AsyncMock(return_value=jwt_auth_result), ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -7652,12 +7644,12 @@ async def test_bridge_mint_unmapped_jwt_is_rejected_before_upstream(): async def test_bridge_mint_jwt_mapped_to_virtual_key_seals_key_hash_subject(): from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( BridgeEnvelopeAdmitted, envelope_keys_from_master_key, resolve_bridge_envelope, ) - from litellm.proxy._types import UserAPIKeyAuth response, _post = await _exchange_for_bridge_server_with_jwt( UserAPIKeyAuth(token="mapped-key-hash-99", user_id="mapped-user") @@ -7756,7 +7748,7 @@ def _jwt_auth_patches(mapped_key): stack.enter_context(patch("litellm.proxy.proxy_server.user_api_key_cache", cache)) stack.enter_context( patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._key_owner_scim_deactivated", + "litellm.proxy.mcp_server.bridge_token_flow._key_owner_scim_deactivated", new=AsyncMock(return_value=False), ) ) @@ -7768,8 +7760,8 @@ async def test_jwt_mapped_to_service_account_key_without_user_id_resolves(): """A JWT mapped to a team or service-account virtual key (no user_id) is still an active credential: _resolve_jwt_auth returns the mapped key, and the mint seals a key_hash-subject envelope rather than 400ing with no_identity.""" - from litellm.proxy._experimental.mcp_server import bridge_token_flow from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server import bridge_token_flow from litellm.types.mcp import MCPAuth mapped_key = UserAPIKeyAuth(user_id=None, token="svc-key-hash-1") @@ -7798,8 +7790,8 @@ async def test_jwt_mapped_to_service_account_key_without_user_id_resolves(): async def test_jwt_mapped_to_blocked_key_is_rejected(): """The relaxed gate is still active-state gated: a JWT mapped to a blocked virtual key resolves to None, so the mint cannot seal an envelope under it.""" - from litellm.proxy._experimental.mcp_server import bridge_token_flow from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server import bridge_token_flow mapped_key = UserAPIKeyAuth(user_id=None, token="blocked-key-hash-1", blocked=True) request = _bridge_mock_request() @@ -7824,8 +7816,8 @@ async def test_master_key_at_token_endpoint_mints_key_hash_envelope(): credential: presented at the bridge /token endpoint it must mint a key_hash-subject envelope (sealed under hash_token(master_key)) even with no database connection at all. A presented key that is NOT the master key still hits the unresolvable gate when prisma is down, unchanged.""" - from litellm.proxy._experimental.mcp_server import bridge_token_flow from litellm.proxy._types import hash_token + from litellm.proxy.mcp_server import bridge_token_flow from litellm.types.mcp import MCPAuth master = "sk-test-master-key-mint-0000" @@ -7928,14 +7920,14 @@ def test_bridge_reported_expires_in_can_be_zero_at_jwt_exp_boundary(): from fastapi.responses import JSONResponse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _BridgeMintReady, finish_bridge_mint, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( envelope_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import key_hash_identity + from litellm.proxy.mcp_server.outbound_credentials.envelope import key_hash_identity from litellm.types.mcp import MCPAuth ready = _BridgeMintReady( @@ -7959,7 +7951,7 @@ def test_classify_upstream_lifetime(): oversized) is "unspecified" so the envelope caps it, while a parseable non-positive value is "expired": the upstream reporting an already-dead token, which the mint must reject rather than silently give the 1h cap.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import _classify_upstream_lifetime + from litellm.proxy.mcp_server.bridge_token_flow import _classify_upstream_lifetime assert _classify_upstream_lifetime(300) == 300 assert _classify_upstream_lifetime(300.0) == 300 @@ -7992,7 +7984,7 @@ def test_bridge_grant_honors_and_rejects_upstream_lifetime(): """The grant validator honors a positive lifetime, leaves an unknown one None for the envelope to cap, and rejects an explicitly-expired one with "expired_lifetime" so a dead upstream token is never sealed into an hour-long envelope.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import _bridge_grant_from_token_response + from litellm.proxy.mcp_server.bridge_token_flow import _bridge_grant_from_token_response def grant(v): return _bridge_grant_from_token_response({"access_token": "x", "expires_in": v}) @@ -8073,10 +8065,10 @@ async def _exchange_persistence_attempted_for_auth_type(auth_type) -> bool: their contract is that the upstream token stays browser-held, minted/stored/refreshed nowhere.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -8103,21 +8095,21 @@ async def _exchange_persistence_attempted_for_auth_type(auth_type) -> bool: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.extract_user_id_from_request", + "litellm.proxy.mcp_server.discoverable_endpoints.extract_user_id_from_request", new_callable=AsyncMock, return_value="admin-user", ), patch( # test-quality-ok: this control tests persistence by auth mode; write-policy behavior is covered separately - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.authorize_oauth_credential_request", + "litellm.proxy.mcp_server.discoverable_endpoints.authorize_oauth_credential_request", new_callable=AsyncMock, return_value="admin-user", ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._store_per_user_token_server_side", + "litellm.proxy.mcp_server.discoverable_endpoints._store_per_user_token_server_side", new_callable=AsyncMock, ) as mock_store, ): @@ -8155,7 +8147,7 @@ async def test_token_exchange_persists_for_oauth2(): # ------------------------------------------------------------------- _OBO_RESOURCE = "https://litellm.example.com/mcp/obo_mcp" -_PATCH_ISSUERS = "litellm.proxy._experimental.mcp_server.discoverable_endpoints._jwt_auth_issuers" +_PATCH_ISSUERS = "litellm.proxy.mcp_server.discoverable_endpoints._jwt_auth_issuers" def _obo_server(scopes=None): @@ -8177,7 +8169,7 @@ def _obo_server(scopes=None): def test_obo_protected_resource_response_names_jwt_issuers(): """An OBO server's PRM points authorization_servers at the configured JWT issuers (the IdP that mints and validates the subject token), with the gateway resource echoed back.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _obo_protected_resource_response, ) @@ -8192,7 +8184,7 @@ def test_obo_protected_resource_response_names_jwt_issuers(): def test_obo_protected_resource_response_scopes_default_empty(): """A scopeless OBO server reports scopes_supported as [] rather than None.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _obo_protected_resource_response, ) @@ -8204,7 +8196,7 @@ def test_obo_protected_resource_response_scopes_default_empty(): def test_obo_protected_resource_response_falls_back_when_no_issuer(): """With no JWT issuer configured, the OBO branch returns None so the caller falls back to the gateway-default PRM (discovery still works, it just can't name the IdP).""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _obo_protected_resource_response, ) @@ -8214,10 +8206,10 @@ def test_obo_protected_resource_response_falls_back_when_no_issuer(): def test_obo_protected_resource_response_ignores_non_obo_server(): """Non-OBO servers are not handled by this branch (returns None -> gateway default).""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _obo_protected_resource_response, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -8236,10 +8228,10 @@ async def test_build_oauth_protected_resource_response_obo_end_to_end(): authorization_servers, proving the extracted branch is wired into the public discovery path.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_protected_resource_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -8290,11 +8282,11 @@ async def test_extract_user_id_reads_x_litellm_api_key_header(proxy_globals): """The LiteLLM key arrives on x-litellm-api-key (what Claude Desktop/Code send), not Authorization. Reading only Authorization dropped the identity, so the per-user token was never stored and the egress 401'd forever. Resolution must honor x-litellm-api-key.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( - extract_user_id_from_request, - ) from litellm.proxy._types import UserAPIKeyAuth, hash_token from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( + extract_user_id_from_request, + ) key = "sk-alice-key" cache = UserApiKeyCache() @@ -8315,11 +8307,11 @@ async def test_extract_user_id_rehydrates_cross_replica_dict_cache(proxy_globals """Cross-replica, async_get_cache hands back a serialized dict, not a UserAPIKeyAuth. Resolution must rehydrate it; the old getattr(cached, "user_id") returned None on a dict, which is exactly why a multi-replica gateway never found the stored token.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( - extract_user_id_from_request, - ) from litellm.proxy._types import hash_token from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( + extract_user_id_from_request, + ) key = "sk-alice-key" cache = UserApiKeyCache() @@ -8336,11 +8328,11 @@ async def test_extract_user_id_falls_back_to_db_on_cache_miss(proxy_globals): """A cache miss must read the key from the DB rather than returning None; the old code did a cache-only peek and skipped the DB, so any replica that hadn't just authenticated the key failed to store the token.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( - extract_user_id_from_request, - ) from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( + extract_user_id_from_request, + ) key = "sk-bob-key" @@ -8358,10 +8350,10 @@ async def test_extract_user_id_falls_back_to_db_on_cache_miss(proxy_globals): @pytest.mark.asyncio async def test_extract_user_id_none_without_litellm_key(proxy_globals): """No LiteLLM key on the request resolves to None without consulting the resolver.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( extract_user_id_from_request, ) - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache proxy_globals.user_api_key_cache = UserApiKeyCache() proxy_globals.prisma_client = object() @@ -8375,11 +8367,11 @@ async def test_extract_user_id_rejects_blocked_key(proxy_globals): """A blocked LiteLLM key must not resolve an identity. get_key_object returns the DB row without checking blocked/expiry (the main auth pipeline does, and the public token endpoint bypasses it), so a revoked key could otherwise overwrite the stored per-user OAuth token for its user.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( - extract_user_id_from_request, - ) from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( + extract_user_id_from_request, + ) class _FakePrisma: async def get_data(self, token, table_name, parent_otel_span=None, proxy_logging_obj=None): @@ -8397,11 +8389,11 @@ async def test_extract_user_id_rejects_expired_key(proxy_globals): """An expired LiteLLM key must not resolve an identity, for the same reason as a blocked key.""" from datetime import datetime, timedelta, timezone - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( - extract_user_id_from_request, - ) from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( + extract_user_id_from_request, + ) expired = (datetime.now(timezone.utc) - timedelta(hours=1)).isoformat() @@ -8422,12 +8414,12 @@ async def test_resolve_active_litellm_key_returns_resolved_key_for_active_key(pr record. For an active key the resolver returns exactly hash_token(key), the same value get_key_object and the whole cache/DB layer key the record by, so the sealed reference resolves back to this key at admission.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy._types import UserAPIKeyAuth, hash_token + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( _resolve_active_litellm_key, _ResolvedKey, ) - from litellm.proxy._types import UserAPIKeyAuth, hash_token - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache key = "sk-alice-key" cache = UserApiKeyCache() @@ -8452,13 +8444,13 @@ async def test_resolve_active_litellm_key_resolves_key_without_user_id(proxy_glo presence wrongly rejected these keys with invalid_request; the active-state gate now checks only blocked and expiry, and the key hash (not the user) is what the mint seals. The per-user token store still gets no user for such a key, since there is none to key a stored credential by.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy._types import UserAPIKeyAuth, hash_token + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( _resolve_active_litellm_key, _ResolvedKey, extract_user_id_from_request, ) - from litellm.proxy._types import UserAPIKeyAuth, hash_token - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache key = "sk-team-scoped-key" cache = UserApiKeyCache() @@ -8481,11 +8473,11 @@ async def test_resolve_active_litellm_key_resolves_key_without_user_id(proxy_glo async def test_resolve_active_litellm_key_rejects_blocked_key(proxy_globals): """A blocked key must not yield a hash, so no gateway-bound envelope is minted for a revoked key; the mint fails closed with invalid_request instead.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( - _resolve_active_litellm_key, - ) from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( + _resolve_active_litellm_key, + ) class _FakePrisma: async def get_data(self, token, table_name, parent_otel_span=None, proxy_logging_obj=None): @@ -8504,11 +8496,11 @@ async def test_resolve_active_litellm_key_fails_closed_on_malformed_expiry(proxy returns invalid_request), not surface an unhandled 500. The active-state check runs outside the resolver's try, so it must be total over a bad expires rather than letting datetime.fromisoformat raise. Before the fix this raised a ValueError instead of returning None.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( - _resolve_active_litellm_key, - ) from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( + _resolve_active_litellm_key, + ) class _FakePrisma: async def get_data(self, token, table_name, parent_otel_span=None, proxy_logging_obj=None): @@ -8524,10 +8516,10 @@ async def test_resolve_active_litellm_key_fails_closed_on_malformed_expiry(proxy @pytest.mark.asyncio async def test_resolve_active_litellm_key_no_active_key_without_litellm_key(proxy_globals): """No LiteLLM key on the request yields no hash without consulting the resolver.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( _resolve_active_litellm_key, ) - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache proxy_globals.user_api_key_cache = UserApiKeyCache() proxy_globals.prisma_client = object() @@ -8542,10 +8534,10 @@ async def test_resolve_active_litellm_key_db_outage_is_unavailable(proxy_globals the caller's fault, so the resolver reports "unavailable" (the mint statuses it 503) rather than collapsing it to the same value as a missing credential. is_database_service_unavailable_error classifies a connection error (an OSError) as an outage, matching admission's egress-side handling.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( _resolve_active_litellm_key, ) - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache class _OutagePrisma: async def get_data(self, token, table_name, parent_otel_span=None, proxy_logging_obj=None): @@ -8565,10 +8557,10 @@ async def test_resolve_active_litellm_key_permanent_engine_fault_is_faulted(prox whose wording promises the outage is transient and asks the client to retry.""" from prisma.engine.errors import BinaryNotFoundError - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( _resolve_active_litellm_key, ) - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache class _FaultedPrisma: async def get_data(self, token, table_name, parent_otel_span=None, proxy_logging_obj=None): @@ -8589,10 +8581,10 @@ async def test_resolve_active_litellm_key_transport_error_over_permanent_fault_i import httpx from prisma.engine.errors import BinaryNotFoundError - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( _resolve_active_litellm_key, ) - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache class _ReconnectFailedPrisma: async def get_data(self, token, table_name, parent_otel_span=None, proxy_logging_obj=None): @@ -8613,10 +8605,10 @@ async def test_resolve_active_litellm_key_no_database_is_unresolvable(proxy_glob """With no database connection configured the gateway cannot verify the presented key at all, so the resolver reports "unresolvable" (the mint statuses it 500) instead of blaming the caller. Mirrors admission, which 500s a missing prisma_client on the egress side.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( _resolve_active_litellm_key, ) - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache proxy_globals.user_api_key_cache = UserApiKeyCache() proxy_globals.prisma_client = None @@ -8647,8 +8639,8 @@ async def test_reload_active_user_by_id_missing_user_is_no_active_key(proxy_glob refresh path maps it to invalid_grant), not unresolvable/500. get_user_object catches the missing row and re-raises a bare ValueError, so a missing user must not be misclassified as a DB outage or an opaque gateway fault.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import reload_active_user_by_id from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import reload_active_user_by_id proxy_globals.user_api_key_cache = UserApiKeyCache() proxy_globals.prisma_client = object() @@ -8666,8 +8658,8 @@ async def test_reload_active_user_by_id_db_outage_is_unavailable(proxy_globals): a missing user, so the refresh path surfaces "unavailable" (a 503) rather than blaming the caller. get_user_object wraps the outage in a bare ValueError, so this exercises the chain-aware classifier; a raw ConnectionError would falsely pass even a chain-blind check because it is an OSError.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import reload_active_user_by_id from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import reload_active_user_by_id proxy_globals.user_api_key_cache = UserApiKeyCache() proxy_globals.prisma_client = object() @@ -8686,8 +8678,8 @@ async def test_reload_active_user_by_id_permanent_engine_fault_is_faulted(proxy_ wraps the fault in a bare ValueError, so the classification has to read the wrapped cause.""" from prisma.engine.errors import MismatchedVersionsError - from litellm.proxy._experimental.mcp_server.bridge_token_flow import reload_active_user_by_id from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import reload_active_user_by_id proxy_globals.user_api_key_cache = UserApiKeyCache() proxy_globals.prisma_client = object() @@ -8707,9 +8699,9 @@ async def test_load_active_user_by_id_reads_the_row_from_the_database_not_the_ca member never evicts the cached row, so a credential minted off the cached row refused the very first token exchange as not a member. The database source has to read the row from the database and leave the fresh row in the cache for the requests the credential makes next.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import load_active_user_by_id from litellm.proxy._types import LiteLLM_UserTable from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import load_active_user_by_id cache = UserApiKeyCache() await cache.async_set_cache( @@ -8736,12 +8728,12 @@ async def test_load_active_user_by_id_serves_a_cached_row_without_a_database_rea """Introspection and refresh revalidation run per call, so the loader's default source is the cache: a cached row answers without a database read, and only a caller that asks for the database row pays for one.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy._types import LiteLLM_UserTable + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( load_active_user_by_id, reload_active_user_by_id, ) - from litellm.proxy._types import LiteLLM_UserTable - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache cache = UserApiKeyCache() await cache.async_set_cache( @@ -8774,13 +8766,13 @@ async def test_token_endpoint_uses_client_secret_basic_when_configured(): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( token_endpoint, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -8813,7 +8805,7 @@ async def test_token_endpoint_uses_client_secret_basic_when_configured(): mock_response.raise_for_status = MagicMock() with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client" + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client" ) as mock_get_client: mock_async_client = MagicMock() mock_async_client.post = AsyncMock(return_value=mock_response) @@ -8845,13 +8837,13 @@ async def test_token_endpoint_client_secret_basic_without_secret_returns_400(): inbound /token endpoint surfaces it as a 400 rather than silently posting a downgraded request.""" from fastapi import HTTPException, Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( token_endpoint, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -8911,10 +8903,10 @@ async def test_authorize_endpoint_rejects_non_oauth2_server(): """authorize() against a none-auth server returns an accurate 'does not use OAuth' 400, not the misleading 'client_id is required' that fired before the auth_type was checked.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -8950,10 +8942,10 @@ async def test_token_endpoint_rejects_non_oauth2_server(): """token_endpoint() against a none-auth server returns 'does not use OAuth' 400 instead of the misleading 'token url is not set'.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( token_endpoint, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -8992,10 +8984,10 @@ async def test_register_client_rejects_non_oauth2_server(): """register_client() against a named none-auth server returns 'does not use OAuth' 400 instead of the misleading 'authorization url is not set'.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -9012,7 +9004,7 @@ async def test_register_client_rejects_non_oauth2_server(): try: with pytest.raises(HTTPException) as exc_info: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value={}), ): await register_client(request=mock_request, mcp_server_name="access_group_server") @@ -9032,10 +9024,10 @@ async def test_register_client_rejects_non_oauth2_server(): async def test_oauth_protected_resource_for_gateway_owned_auth(auth_type, use_standard_pattern): from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_protected_resource_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -9063,10 +9055,10 @@ async def test_oauth_protected_resource_for_gateway_owned_auth(auth_type, use_st async def test_oauth_authorization_server_404_for_non_oauth2_server(): """Discovery must not advertise a none-auth server as an OAuth authorization server.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_authorization_server_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -9098,13 +9090,13 @@ async def test_oauth_protected_resource_passthrough_none_auth_not_404(): server that opted into OAuth pass-through must still proxy upstream metadata, it must NOT be 404'd. The gate has to sit after the pass-through branch.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_protected_resource_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -9130,7 +9122,7 @@ async def test_oauth_protected_resource_passthrough_none_auth_not_404(): try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.fetch_upstream_oauth_protected_resource", + "litellm.proxy.mcp_server.discoverable_endpoints.fetch_upstream_oauth_protected_resource", new=AsyncMock(return_value={"authorization_servers": ["https://upstream-idp.example.com"]}), ): response = await _build_oauth_protected_resource_response( @@ -9148,10 +9140,10 @@ async def test_oauth_protected_resource_passthrough_none_auth_not_404(): async def test_oauth_protected_resource_404_for_unknown_server_name(): """Unknown server names must not produce metadata advertising nonexistent resources.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_protected_resource_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -9176,10 +9168,10 @@ async def test_oauth_authorization_server_404_for_unknown_server_name(): """A named authorization-server discovery request for an unknown server returns 404, not a 200 metadata document pointing at non-existent /{name}/authorize and /{name}/token.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_authorization_server_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -9203,8 +9195,8 @@ async def test_store_per_user_token_server_side_invalidates_v2_token_cache(): """A token stored by the OAuth callback (code exchange or refresh) drops the v2 per-user token cache entry, so egress stops serving the replaced token immediately instead of until its TTL.""" - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server import mcp_server_manager as manager_module + from litellm.proxy.mcp_server.discoverable_endpoints import ( _store_per_user_token_server_side, ) from litellm.types.mcp import MCPAuth @@ -9226,11 +9218,11 @@ async def test_store_per_user_token_server_side_invalidates_v2_token_cache(): return_value=MagicMock(), ), patch( - "litellm.proxy._experimental.mcp_server.db.store_user_oauth_credential", + "litellm.proxy.mcp_server.db.store_user_oauth_credential", new=AsyncMock(return_value=None), ), patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.mcp_per_user_token_cache.set", + "litellm.proxy.mcp_server.oauth2_token_cache.mcp_per_user_token_cache.set", new=cache_set_mock, ), patch.object( @@ -9253,8 +9245,8 @@ async def test_store_per_user_token_server_side_invalidates_v2_token_cache(): async def test_store_per_user_token_server_side_skips_invalidate_when_db_write_fails(): """A failed DB write neither warms the v1 cache nor drops the v2 cache entry; the previously stored token is still the truth.""" - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server import mcp_server_manager as manager_module + from litellm.proxy.mcp_server.discoverable_endpoints import ( _store_per_user_token_server_side, ) from litellm.types.mcp import MCPAuth @@ -9276,11 +9268,11 @@ async def test_store_per_user_token_server_side_skips_invalidate_when_db_write_f return_value=MagicMock(), ), patch( - "litellm.proxy._experimental.mcp_server.db.store_user_oauth_credential", + "litellm.proxy.mcp_server.db.store_user_oauth_credential", new=AsyncMock(side_effect=RuntimeError("db down")), ), patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.mcp_per_user_token_cache.set", + "litellm.proxy.mcp_server.oauth2_token_cache.mcp_per_user_token_cache.set", new=cache_set_mock, ), patch.object( @@ -9308,10 +9300,10 @@ async def test_token_exchange_pairs_client_secret_with_server_client_id(): placeholder makes the IdP reject the exchange with 401 on every re-auth.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -9339,7 +9331,7 @@ async def test_token_exchange_pairs_client_secret_with_server_client_id(): mock_async_client.post = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ): await exchange_token_with_server( @@ -9362,11 +9354,11 @@ async def test_token_exchange_pairs_client_secret_with_server_client_id(): async def test_token_exchange_refresh_passes_presented_refresh_ownership(): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) - from litellm.proxy._experimental.mcp_server.oauth_identity_binding import RefreshTokenPresented - from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.oauth_identity_binding import RefreshTokenPresented from litellm.types.mcp_server.mcp_server_manager import MCPOAuthIdentityBinding, MCPServer server = MCPServer( @@ -9394,15 +9386,15 @@ async def test_token_exchange_refresh_passes_presented_refresh_ownership(): with ( patch( # test-quality-ok: no injection seam exists for the exchange's HTTP and identity collaborators - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=client, ), patch( # test-quality-ok: no injection seam exists for request identity extraction - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.extract_user_id_from_request", + "litellm.proxy.mcp_server.discoverable_endpoints.extract_user_id_from_request", new=AsyncMock(return_value="user-a"), ), patch( # test-quality-ok: captures the ownership value at the exchange boundary - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.enforce_oauth_identity_binding", + "litellm.proxy.mcp_server.discoverable_endpoints.enforce_oauth_identity_binding", new=enforce, ), ): @@ -9427,11 +9419,11 @@ async def test_token_exchange_refresh_passes_presented_refresh_ownership(): async def test_token_exchange_authorization_code_passes_no_refresh_ownership(monkeypatch): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, seal_bridge_authorization_code, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPOAuthIdentityBinding, MCPServer monkeypatch.setenv("LITELLM_SALT_KEY", "identity-binding-test-salt") @@ -9460,15 +9452,15 @@ async def test_token_exchange_authorization_code_passes_no_refresh_ownership(mon with ( patch( # test-quality-ok: no injection seam exists for the exchange's HTTP and identity collaborators - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=client, ), patch( # test-quality-ok: no injection seam exists for request identity extraction - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.extract_user_id_from_request", + "litellm.proxy.mcp_server.discoverable_endpoints.extract_user_id_from_request", new=AsyncMock(return_value="user-a"), ), patch( # test-quality-ok: captures the ownership value at the exchange boundary - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.enforce_oauth_identity_binding", + "litellm.proxy.mcp_server.discoverable_endpoints.enforce_oauth_identity_binding", new=enforce, ), ): @@ -9506,10 +9498,10 @@ async def _exchange_with_upstream_response( caller-supplied-credentials flow (no stored client on the server).""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -9531,7 +9523,7 @@ async def _exchange_with_upstream_response( mock_async_client.post = AsyncMock(return_value=upstream_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ): return await exchange_token_with_server( @@ -9679,10 +9671,10 @@ async def test_token_exchange_relays_rejection_when_http_client_raises(): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -9702,7 +9694,7 @@ async def test_token_exchange_relays_rejection_when_http_client_raises(): mock_request.headers = {} with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=raising_client, ): response = await exchange_token_with_server( @@ -9728,7 +9720,7 @@ async def test_register_relays_rejection_when_http_client_raises(): so the register relay must catch it there, not only from the explicit raise_for_status.""" import httpx - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) @@ -9748,11 +9740,11 @@ async def test_register_relays_rejection_when_http_client_raises(): with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=raising_client, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", + "litellm.proxy.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", new_callable=AsyncMock, return_value=False, ), @@ -9791,7 +9783,7 @@ async def test_register_never_relays_out_of_contract_body_to_client(): client detail names only the status.""" import httpx - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) @@ -9809,11 +9801,11 @@ async def test_register_never_relays_out_of_contract_body_to_client(): with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=raising_client, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", + "litellm.proxy.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", new_callable=AsyncMock, return_value=False, ), @@ -9862,13 +9854,13 @@ async def test_persist_dcr_client_for_config_server_uses_side_store(): server so refresh can authenticate this process, and never call update_server(None) (which previously raised AttributeError on .approval_status, was swallowed, and reported a 200 that persisted nothing).""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _persist_dcr_client_registration, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer config_server = MCPServer( @@ -9891,19 +9883,19 @@ async def test_persist_dcr_client_for_config_server_uses_side_store(): patch.object(global_mcp_server_manager, "is_config_declared_server", return_value=True), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.update_mcp_server", + "litellm.proxy.mcp_server.db.update_mcp_server", new=AsyncMock(return_value=None), ), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None), ), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.get_mcp_server_oauth_client_credentials", new=AsyncMock(return_value=None), ), patch( - "litellm.proxy._experimental.mcp_server.db.upsert_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.upsert_mcp_server_oauth_client_credentials", new=mock_upsert, ), patch.object(global_mcp_server_manager, "update_server", new=mock_update_server), @@ -9943,11 +9935,11 @@ async def test_hydrate_config_server_applies_stored_dcr_client(monkeypatch, lega refresh_token grant can authenticate as the registered client instead of re-authenticating.""" import litellm.proxy.common_utils.encrypt_decrypt_utils as enc from litellm.litellm_core_utils.safe_json_dumps import safe_dumps - from litellm.proxy._experimental.mcp_server.db import encrypt_credentials - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.db import encrypt_credentials + from litellm.proxy.mcp_server.discoverable_endpoints import ( hydrate_config_server_dcr_client, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -9983,7 +9975,7 @@ async def test_hydrate_config_server_applies_stored_dcr_client(monkeypatch, lega with ( patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.get_mcp_server_oauth_client_credentials", new=AsyncMock(return_value=stored_blob), ), ): @@ -10002,14 +9994,14 @@ async def test_reuse_config_server_reads_store_with_real_crypto(monkeypatch): a re-authorize reuses the client instead of re-minting one.""" import litellm.proxy.common_utils.encrypt_decrypt_utils as enc from litellm.litellm_core_utils.safe_json_dumps import safe_dumps - from litellm.proxy._experimental.mcp_server.db import encrypt_credentials - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.db import encrypt_credentials + from litellm.proxy.mcp_server.discoverable_endpoints import ( _reuse_persisted_dcr_client_if_available, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -10041,9 +10033,9 @@ async def test_reuse_config_server_reads_store_with_real_crypto(monkeypatch): with ( patch.object(global_mcp_server_manager, "is_config_declared_server", return_value=True), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), - patch("litellm.proxy._experimental.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), + patch("litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.get_mcp_server_oauth_client_credentials", new=store_lookup, ), ): @@ -10059,14 +10051,14 @@ async def test_temp_server_is_not_persisted_to_store(): """A rowless server that is NOT config-declared (a throwaway /server/oauth/session server) must not leave a permanent store row on persist, and the read must never consult the store for it. Its minted client is overlaid in memory for the session only.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _persist_dcr_client_registration, _reuse_persisted_dcr_client_if_available, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer temp = MCPServer( @@ -10086,11 +10078,11 @@ async def test_temp_server_is_not_persisted_to_store(): with ( patch.object(global_mcp_server_manager, "is_config_declared_server", return_value=False), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=AsyncMock(return_value=None)), - patch("litellm.proxy._experimental.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), - patch("litellm.proxy._experimental.mcp_server.db.upsert_mcp_server_oauth_client_credentials", new=upsert), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=AsyncMock(return_value=None)), + patch("litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), + patch("litellm.proxy.mcp_server.db.upsert_mcp_server_oauth_client_credentials", new=upsert), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.get_mcp_server_oauth_client_credentials", new=store_read, ), patch.object(global_mcp_server_manager, "update_server", new=AsyncMock()), @@ -10121,10 +10113,10 @@ async def test_temp_server_is_not_persisted_to_store(): async def test_hydrate_does_not_overwrite_explicit_config_client_id(): """An explicit client_id set in config.yaml wins: hydration must not overwrite it with a stale persisted store client, and must not even read the store when config already supplied a client.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( hydrate_config_server_dcr_client, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -10139,7 +10131,7 @@ async def test_hydrate_does_not_overwrite_explicit_config_client_id(): with ( patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.get_mcp_server_oauth_client_credentials", new=store_read, ), ): @@ -10157,10 +10149,10 @@ async def test_reuse_does_not_inherit_store_client_when_a_row_exists(): server whose id collides with a config-declared server must not be able to load that config server's client from the store and send it to its own token endpoint. A row that exists but has no client_id yields no reusable client and must not fall back to the store.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _reuse_persisted_dcr_client_if_available, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer submitted = MCPServer( @@ -10181,11 +10173,11 @@ async def test_reuse_does_not_inherit_store_client_when_a_row_exists(): with ( patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=row_without_client), ), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.get_mcp_server_oauth_client_credentials", new=store_lookup, ), ): @@ -10201,7 +10193,7 @@ async def test_load_servers_from_config_hydrates_dcr_clients(): """load_servers_from_config must invoke DCR-client hydration so config servers pick up their persisted client on startup; deleting the call site leaves a restarted server with no client_id and forces re-authentication on every token expiry.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -10218,7 +10210,7 @@ async def test_reload_servers_from_database_hydrates_dcr_clients(): reload_servers_from_database runs after the DB connects and must hydrate config servers' persisted DCR clients too, or a fresh pod has no client_id for a config server and forces re-authentication on the first token refresh.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -10248,8 +10240,8 @@ def test_aggregate_wellknown_routes_serve_gateway_metadata(): from fastapi import FastAPI from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -10281,8 +10273,8 @@ def test_as_aggregate_route_reserves_mcp_for_the_aggregate(): from fastapi import FastAPI from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -10319,7 +10311,7 @@ def test_well_known_root_suffix_reflects_server_root_path(): import os from unittest.mock import patch - from litellm.proxy._experimental.mcp_server.oauth_utils import well_known_root_suffix + from litellm.proxy.mcp_server.oauth_utils import well_known_root_suffix with patch.dict(os.environ, {"SERVER_ROOT_PATH": ""}): assert well_known_root_suffix() == "" @@ -10333,11 +10325,11 @@ def test_well_known_root_suffix_reflects_server_root_path(): async def test_root_resource_uses_gateway_without_changing_authorization_relay(): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_authorization_server_response, _build_oauth_protected_resource_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -10368,11 +10360,11 @@ async def test_named_discovery_issuer_matches_protected_resource_authorization_s resolved the metadata from, which is the protected-resource authorization_servers entry.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_authorization_server_response, _build_oauth_protected_resource_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -10403,10 +10395,10 @@ async def test_openid_configuration_issuer_stays_bare_origin_for_single_oauth2_s bare origin even when root discovery resolves the one configured OAuth2 server.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( openid_configuration, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -10432,8 +10424,8 @@ def test_gateway_dcr_flow_routing_engages_only_for_llm_dcrc_clients(monkeypatch) from fastapi import FastAPI from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -10489,7 +10481,7 @@ async def test_authorize_wall_names_the_fix_for_urlless_servers(): """LIT-4629: the authorize wall previously said only "authorization url is not set" with no hint that spec-only servers never discover; the detail must now name both remedies (manual Authorization URL + Token URL, or an Issuer for RFC 8414 discovery).""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10526,7 +10518,7 @@ async def test_token_wall_names_the_fix_for_urlless_servers(): """The /token wall is the second stop on the same misconfiguration (LIT-4629): after an admin fills only the Authorization URL, the code exchange dies here; the detail must name the remedies like the authorize wall does.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10567,7 +10559,7 @@ async def test_token_wall_names_the_fix_for_urlless_servers(): async def test_register_wall_names_the_fix_for_urlless_servers(): """The /register wall serves the same missing-authorization-url 400 as authorize; its detail must carry the same actionable remedies.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10607,7 +10599,7 @@ async def test_authorize_wall_points_at_discovery_failure_for_url_servers(): discovery against that url failed (typically a misconfigured url); the old detail blamed "servers with no url", sending the operator down the wrong path. The detail must now name the discovery failure and point at the proxy logs where LIT-4658's warnings carry the reason.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10642,7 +10634,7 @@ async def test_authorize_wall_points_at_discovery_failure_for_url_servers(): @pytest.mark.asyncio async def test_token_wall_points_at_discovery_failure_for_url_servers(): - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10681,7 +10673,7 @@ async def test_token_wall_points_at_discovery_failure_for_url_servers(): @pytest.mark.asyncio async def test_authorize_wall_names_the_issuer_for_anchored_servers(): - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10721,7 +10713,7 @@ async def test_authorize_uses_admin_entered_github_oauth_urls_after_issuer_yield the resolved authorization_url when a leftover issuer is treated as a pin (RFC 8414 yield). The UI authorize must still redirect to the admin-entered GitHub authorize URL instead of 400ing that discovery against api.githubcopilot.com failed.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10765,7 +10757,7 @@ async def test_authorize_uses_admin_entered_github_oauth_urls_after_issuer_yield def test_oauth_endpoints_count_admin_entered_urls_as_resolved(): """A leftover issuer empties the resolved authorize/token fields but must not keep the server on the deferred-discovery retry path when the admin already stored those URLs.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( oauth_endpoints_unresolved, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10791,11 +10783,11 @@ async def test_token_exchange_with_configured_token_url_never_joins_discovery(mo """A server can hold an admin-entered Token URL while its Authorization URL is absent. The token exchange must post to that stored endpoint without awaiting deferred discovery, which can 503 against an unreachable issuer even though nothing it resolves is needed here.""" - from litellm.proxy._experimental.mcp_server import ( + from litellm.proxy.mcp_server import ( discoverable_endpoints, mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10860,7 +10852,7 @@ async def test_root_token_route_with_configured_token_url_never_joins_discovery( """A root POST /token that falls back to the sole OAuth2 server must reach the exchange's endpoint-gated discovery join instead of awaiting full discovery at the route: with the token url admin-entered, a failing or slow discovery must not turn the exchange into a 503.""" - from litellm.proxy._experimental.mcp_server import ( + from litellm.proxy.mcp_server import ( discoverable_endpoints, mcp_server_manager, ) @@ -10925,8 +10917,8 @@ async def test_bridge_authorize_relays_with_registration_url_resolved_by_deferre relay-vs-short-circuit call must read the resolved server: a client that registered itself through the front door keeps its own redirect binding instead of being routed through the gateway callback the upstream never granted it.""" - from litellm.proxy._experimental.mcp_server import mcp_server_manager - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10986,7 +10978,7 @@ def test_passthrough_authorization_code_round_trips_and_rejects_hostile_input(): and is total over hostile input: a raw upstream code opens to None, and a tampered or non-gateway value opens to None rather than raising, so every existing caller-supplied-client flow is untouched.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( open_passthrough_authorization_code, seal_passthrough_authorization_code, ) @@ -11009,7 +11001,7 @@ def test_passthrough_authorization_code_round_trips_and_rejects_hostile_input(): assert open_passthrough_authorization_code("raw-upstream-code") is None assert open_passthrough_authorization_code(sealed[:-4] + "aaaa") is None - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _BRIDGE_AUTH_CODE_PREFIX, _PASSTHROUGH_AUTH_CODE_PREFIX, open_bridge_authorization_code, @@ -11030,7 +11022,7 @@ async def test_authorize_with_ephemeral_dcr_client_seals_client_into_state(): """When mcp_authorize fell through to a gateway-side DCR mint, authorize_with_server seals the minted client and the target server into the encrypted OAuth state, so the callback can bind them into the forwarded authorization code while the gateway stores nothing.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( EphemeralDcrClient, authorize_with_server, ) @@ -11044,7 +11036,7 @@ async def test_authorize_with_ephemeral_dcr_client_seals_client_into_state(): return "mocked_encrypted_state" with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.encode_state_with_base_url", + "litellm.proxy.mcp_server.discoverable_endpoints.encode_state_with_base_url", side_effect=_capture, ): response = await authorize_with_server( @@ -11075,7 +11067,7 @@ async def test_callback_wraps_code_into_passthrough_code_for_ephemeral_dcr_state gateway never stored.""" from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( callback, open_passthrough_authorization_code, ) @@ -11091,15 +11083,15 @@ async def test_callback_wraps_code_into_passthrough_code_for_ephemeral_dcr_state } with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._resolve_encoded_oauth_state", + "litellm.proxy.mcp_server.discoverable_endpoints._resolve_encoded_oauth_state", return_value="enc", ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash", + "litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash", return_value=state_data, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._get_validated_client_redirect_uri", + "litellm.proxy.mcp_server.discoverable_endpoints._get_validated_client_redirect_uri", return_value="http://127.0.0.1:60108/cb", ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -11125,7 +11117,7 @@ async def test_authorize_bridge_server_with_ephemeral_client_takes_short_circuit to an IdP that has the gateway callback registered, stranding the flow.""" from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( EphemeralDcrClient, authorize_with_server, ) @@ -11159,7 +11151,7 @@ async def test_callback_forwards_raw_code_when_dcr_state_lacks_server_binding(): one.""" from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import callback + from litellm.proxy.mcp_server.discoverable_endpoints import callback state_data = { "original_state": "client-state", @@ -11169,15 +11161,15 @@ async def test_callback_forwards_raw_code_when_dcr_state_lacks_server_binding(): } with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._resolve_encoded_oauth_state", + "litellm.proxy.mcp_server.discoverable_endpoints._resolve_encoded_oauth_state", return_value="enc", ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash", + "litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash", return_value=state_data, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._get_validated_client_redirect_uri", + "litellm.proxy.mcp_server.discoverable_endpoints._get_validated_client_redirect_uri", return_value="http://127.0.0.1:60108/cb", ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -11214,7 +11206,7 @@ async def test_resolve_ephemeral_dcr_client_mint_set_is_exact(auth_type_value, d oauth_delegate dcr_bridge sign-in is left to its own browser-front-door flow. The UI gatewayMintsClientFor helper mirrors this exact set; ui/.../mcp_tools/types.test.tsx pins the frontend side against the same table, so a divergence fails on one side or the other.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( EphemeralDcrClient, resolve_ephemeral_dcr_client, ) @@ -11230,7 +11222,7 @@ async def test_resolve_ephemeral_dcr_client_mint_set_is_exact(auth_type_value, d mint_mock = AsyncMock(return_value=EphemeralDcrClient(client_id="minted", client_secret=None)) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.mint_ephemeral_dcr_client", + "litellm.proxy.mcp_server.discoverable_endpoints.mint_ephemeral_dcr_client", mint_mock, ): result = await resolve_ephemeral_dcr_client( @@ -11253,7 +11245,7 @@ async def test_resolve_ephemeral_dcr_client_mint_set_is_exact(auth_type_value, d async def test_mint_ephemeral_dcr_client_returns_none_without_registration_endpoint(): """A server whose upstream exposes no RFC 7591 registration endpoint cannot mint, so the fall-through reports None and the caller keeps its existing missing_client_id failure.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( mint_ephemeral_dcr_client, ) from litellm.types.mcp import MCPAuth @@ -11266,7 +11258,7 @@ async def test_mint_ephemeral_dcr_client_returns_none_without_registration_endpo async def test_mint_ephemeral_dcr_client_posts_rfc7591_and_returns_client(): """The mint POSTs a public-client RFC 7591 registration bound to the gateway /callback and hands back the upstream's client without persisting it anywhere.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( mint_ephemeral_dcr_client, ) from litellm.types.mcp import MCPAuth @@ -11283,7 +11275,7 @@ async def test_mint_ephemeral_dcr_client_posts_rfc7591_and_returns_client(): mock_async_client.post = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ): minted = await mint_ephemeral_dcr_client(_bridge_mock_request(), server) @@ -11303,7 +11295,7 @@ async def test_mint_ephemeral_dcr_client_reuses_minted_client_within_flow_ttl(): """Reloading the authorize page must not spam the upstream registration endpoint with orphan clients: within the OAuth state's lifetime a second mint for the same server and gateway origin reuses the cached client and performs no second upstream POST.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( mint_ephemeral_dcr_client, ) from litellm.types.mcp import MCPAuth @@ -11318,7 +11310,7 @@ async def test_mint_ephemeral_dcr_client_reuses_minted_client_within_flow_ttl(): mock_async_client.post = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ): first = await mint_ephemeral_dcr_client(_bridge_mock_request(), server) @@ -11336,7 +11328,7 @@ async def test_mint_ephemeral_dcr_client_single_flights_concurrent_mints(): POST happens.""" import asyncio - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( mint_ephemeral_dcr_client, ) from litellm.types.mcp import MCPAuth @@ -11359,7 +11351,7 @@ async def test_mint_ephemeral_dcr_client_single_flights_concurrent_mints(): mock_async_client.post = AsyncMock(side_effect=_slow_post) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ): first, second = await asyncio.gather( @@ -11384,7 +11376,7 @@ async def test_mint_ephemeral_dcr_client_unusable_registration_response_is_502(p """An upstream registration response without a usable client_id, whether the field is missing or an empty string, surfaces as a loud 502 instead of letting the authorize proceed with an empty client and fail opaquely at the IdP.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( mint_ephemeral_dcr_client, ) from litellm.types.mcp import MCPAuth @@ -11399,7 +11391,7 @@ async def test_mint_ephemeral_dcr_client_unusable_registration_response_is_502(p mock_async_client.post = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ): with pytest.raises(HTTPException) as exc: @@ -11428,7 +11420,7 @@ async def test_token_exchange_authenticates_with_the_sealed_clients_own_auth_met import httpx - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) from litellm.types.mcp import MCPAuth @@ -11442,7 +11434,7 @@ async def test_token_exchange_authenticates_with_the_sealed_clients_own_auth_met mock_async_client.post = AsyncMock(return_value=upstream_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ): await exchange_token_with_server( @@ -11537,7 +11529,7 @@ def test_resolve_upstream_resource_tristate_and_canonicalization(url, configured hygiene), and drop a trailing slash, while preserving a non-default port and the path case. An explicit value is never canonicalized, because it has to match what the authorization server expects byte for byte.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import resolve_upstream_resource + from litellm.proxy.mcp_server.oauth_utils import resolve_upstream_resource assert resolve_upstream_resource(_resource_server(url=url, upstream_resource=configured)) == expected @@ -11556,7 +11548,7 @@ def test_build_upstream_oauth2_token_request_bundles_resource_with_client_auth(c mandatory client authentication and no leg can authenticate without also naming the resource its sibling legs named. A leg that reverted to hand-building its body would drop the resource and diverge from the authorize leg, which a strict authorization server rejects as invalid_target.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import build_upstream_oauth2_token_request + from litellm.proxy.mcp_server.oauth_utils import build_upstream_oauth2_token_request req = build_upstream_oauth2_token_request( _resource_server(url=url, upstream_resource=configured), @@ -11574,7 +11566,7 @@ def test_build_upstream_oauth2_token_request_client_secret_basic_keeps_secret_ou also appear in the body, while the RFC 8707 resource still rides in the body.""" import base64 - from litellm.proxy._experimental.mcp_server.oauth_utils import build_upstream_oauth2_token_request + from litellm.proxy.mcp_server.oauth_utils import build_upstream_oauth2_token_request req = build_upstream_oauth2_token_request( _resource_server(upstream_resource="api://audience"), @@ -11593,7 +11585,7 @@ async def _authorize_query(server) -> dict: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) @@ -11601,7 +11593,7 @@ async def _authorize_query(server) -> dict: mock_request.base_url = "https://litellm.example.com/" mock_request.headers = {} - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: mock_encrypt.return_value = "encrypted_state" response = await authorize_with_server( request=mock_request, @@ -11620,7 +11612,7 @@ async def _authorize_query(server) -> dict: async def _token_body(server, grant_type: str) -> dict: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) @@ -11635,7 +11627,7 @@ async def _token_body(server, grant_type: str) -> dict: mock_async_client.post = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ): await exchange_token_with_server( @@ -11719,7 +11711,7 @@ def test_upstream_resource_auto_keeps_the_path_because_it_identifies_the_server( it would collide them onto one resource identifier and bind each token to the wrong audience, which is the exact confusion RFC 8707 exists to prevent. An operator whose path embeds a secret sets ``upstream_resource`` explicitly instead of using ``auto``.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import resolve_upstream_resource + from litellm.proxy.mcp_server.oauth_utils import resolve_upstream_resource first = resolve_upstream_resource( _resource_server(url="https://gw.example.com/team-a/mcp", upstream_resource="auto") @@ -11748,7 +11740,7 @@ async def test_upstream_resource_sent_on_dcr_bridge_relay_authorize(): """The DCR-bridge relay arm builds its own upstream authorize params, so it needs the resource too. Without it the relayed authorize would omit the resource while the gateway's token leg still sent one, which is itself an invalid_target.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _dcr_bridge_relays_client_registration, ) from litellm.types.mcp import MCPAuth @@ -11789,7 +11781,7 @@ def _no_proxy_base_url(monkeypatch): def _isolated_mcp_registry(): """Fixture-owned registry state: snapshot the shared registry, hand the test an empty one, restore afterwards so nothing leaks between cases.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -11806,7 +11798,7 @@ def _prefixed_discovery_client(prefixes): from fastapi import FastAPI from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.discoverable_endpoints import router from litellm.proxy.middleware.per_request_root_path_middleware import ( PerRequestRootPathMiddleware, ) @@ -11825,7 +11817,7 @@ class TestPerRequestRootPathDiscovery: from fastapi import FastAPI from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.discoverable_endpoints import router server = _create_oauth2_server(server_id="srv_a", name="server_a", server_name="server_a", alias="server_a") _isolated_mcp_registry[server.server_id] = server @@ -11899,7 +11891,7 @@ class TestPerRequestRootPathDiscovery: """The WWW-Authenticate resource_metadata URL a 401 advertises must land under the request's prefix, or the client is bounced to a document whose ``resource`` cannot match the URL it called.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( get_passthrough_resource_metadata_url, ) @@ -11943,8 +11935,8 @@ class TestPerRequestRootPathDiscovery: from fastapi import FastAPI, HTTPException, Request from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( + from litellm.proxy.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( raise_user_oauth_challenge, ) from litellm.proxy.middleware.per_request_root_path_middleware import ( @@ -11997,16 +11989,103 @@ def _s256(verifier: str) -> str: _NATIVE_CLIENT_MASTER_KEY = "sk-test-salt-for-LIT-5874" +def _browser_session_cookie( + monkeypatch: pytest.MonkeyPatch, + user_id: str, + *, + signing_key: str = _NATIVE_CLIENT_MASTER_KEY, + session_key: str | None = None, + expired_session: bool = False, + expired_cookie: bool = False, +) -> str: + import jwt + + from litellm.proxy import proxy_server + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.auth.auth_checks import LITELLM_SESSION_TOKEN_PREFIX + from litellm.proxy.common_utils.encrypt_decrypt_utils import encrypt_bearer_token + + monkeypatch.setattr(proxy_server, "master_key", signing_key) + if proxy_server.prisma_client is None: + monkeypatch.setattr(proxy_server, "prisma_client", object()) + monkeypatch.setattr(proxy_server, "general_settings", {**proxy_server.general_settings, "supported_db_objects": []}) + session: Final = UserAPIKeyAuth( + user_id=user_id, + expires=datetime(2000 if expired_session else 2099, 1, 1, tzinfo=timezone.utc), + ) + key: Final = ( + encrypt_bearer_token(session.model_dump_json(exclude_none=True), LITELLM_SESSION_TOKEN_PREFIX) + if session_key is None + else session_key + ) + return jwt.encode( + {"user_id": user_id, "key": key, "login_method": "sso", "exp": 946684800 if expired_cookie else 9999999999}, + signing_key, + algorithm="HS256", + ) + + +class _BrowserSessionDatabase: + def __init__(self) -> None: + from litellm.proxy._types import UserAPIKeyAuth, hash_token + + self.row: UserAPIKeyAuth | None = UserAPIKeyAuth( + token=hash_token("sk-browser-session"), + user_id="u1", + expires=datetime(2099, 1, 1, tzinfo=timezone.utc), + ) + self.litellm_deprecatedverificationtoken = self + + def __call__(self, **kwargs: object) -> "_BrowserSessionDatabase": + return self + + async def query_first(self, query: str, *args: object) -> dict[str, object] | None: + if self.row is None: + return None + return { + **self.row.model_dump(exclude={"last_refreshed_at"}), + "team_models": None, + "team_blocked": None, + "team_members_with_roles": None, + } + + async def find_first(self, **kwargs: object) -> None: + return None + + +@pytest.fixture +def browser_session_database(monkeypatch: pytest.MonkeyPatch) -> _BrowserSessionDatabase: + import prisma + + from litellm.proxy import proxy_server + from litellm.proxy._types import hash_token + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.utils import PrismaClient + + database: Final = _BrowserSessionDatabase() + monkeypatch.setattr(prisma, "Prisma", database) + for name in ("DATABASE_URL_READ_REPLICA", "IAM_TOKEN_DB_AUTH", "AZURE_POSTGRESQL_AUTH"): + monkeypatch.delenv(name, raising=False) + monkeypatch.setattr( + proxy_server, + "prisma_client", + PrismaClient("postgresql://local-test@localhost/browser-session", proxy_server.proxy_logging_obj), + ) + cache: Final = UserApiKeyCache() + cache.set_cache(hash_token("sk-browser-session"), database.row) + monkeypatch.setattr(proxy_server, "user_api_key_cache", cache) + return database + + def _native_client_app(monkeypatch): """The unauthenticated discoverable router served over TestClient with a signed UI session cookie available, plus fakes for the two database-backed hooks the native-client flow calls.""" - import jwt from fastapi import FastAPI from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ConsentTeam, MintedProxyCredential - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.gateway_dcr_flow import ConsentTeam, MintedProxyCredential + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager monkeypatch.setenv("LITELLM_SALT_KEY", _NATIVE_CLIENT_MASTER_KEY) monkeypatch.setattr("litellm.proxy.proxy_server.master_key", _NATIVE_CLIENT_MASTER_KEY, raising=False) @@ -12020,31 +12099,125 @@ def _native_client_app(monkeypatch): return (ConsentTeam(team_id="team-a", team_alias="Team A"), ConsentTeam(team_id="team-b")) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.mint_proxy_credential", fake_mint + "litellm.proxy.mcp_server.discoverable_endpoints.mint_proxy_credential", fake_mint ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.lookup_consent_teams", fake_lookup + "litellm.proxy.mcp_server.discoverable_endpoints.lookup_consent_teams", fake_lookup ) global_mcp_server_manager.registry.clear() app = FastAPI() app.include_router(router) client = TestClient(app) - session_cookie = jwt.encode( - {"user_id": "u1", "login_method": "username_password", "exp": int(time.time()) + 600}, - _NATIVE_CLIENT_MASTER_KEY, - algorithm="HS256", - ) + session_cookie: Final = _browser_session_cookie(monkeypatch, "u1") return client, session_cookie, minted +@pytest.mark.parametrize( + "authorize_path,resource", + [("/authorize", None), ("/authorize/mcp-session", None), ("/authorize", "http://testserver")], +) +@pytest.mark.parametrize( + "session_state", ["valid", "revoked", "blocked", "expired", "wrong_owner", "missing_key", "no_database"] +) +def test_gateway_authorize_requires_live_browser_session( + monkeypatch: pytest.MonkeyPatch, + browser_session_database: _BrowserSessionDatabase, + authorize_path: str, + resource: str | None, + session_state: str, +) -> None: + from urllib.parse import urlparse + + from litellm.proxy import proxy_server + + client, _, _ = _native_client_app(monkeypatch) + database: Final = browser_session_database + assert database.row is not None + database.row = None if session_state == "revoked" else database.row.model_copy( + update={ + "blocked": session_state == "blocked", + "expires": datetime(2000 if session_state == "expired" else 2099, 1, 1, tzinfo=timezone.utc), + "user_id": "another-user" if session_state == "wrong_owner" else "u1", + } + ) + cookie: Final = _browser_session_cookie( + monkeypatch, "u1", session_key="" if session_state == "missing_key" else "sk-browser-session" + ) + client.cookies.set("token", cookie) + if session_state == "no_database": + monkeypatch.setattr(proxy_server, "prisma_client", None) + registered: Final = client.post("/register", json={"redirect_uris": ["http://127.0.0.1/callback"]}) + assert registered.status_code == 201, registered.text + response: Final = client.get( + authorize_path, + params={ + "client_id": registered.json()["client_id"], + "redirect_uri": "http://127.0.0.1/callback", + "response_type": "code", + "code_challenge": _s256("v" * 43), + "code_challenge_method": "S256", + **({"resource": resource} if resource else {}), + }, + follow_redirects=False, + ) + if session_state == "valid" and resource: + assert response.status_code == 200 and 'name="decision"' in response.text, response.text + else: + assert response.status_code == 303, response.text + assert urlparse(response.headers["location"]).path == ( + "/ui/connect" if session_state == "valid" else "/sso/key/generate" + ) + + +@pytest.mark.parametrize("endpoint", ["flow", "complete"]) +@pytest.mark.parametrize("revoked", [False, True]) +def test_gateway_connect_rechecks_session_after_authorize( + monkeypatch: pytest.MonkeyPatch, + browser_session_database: _BrowserSessionDatabase, + endpoint: str, + revoked: bool, +) -> None: + from urllib.parse import parse_qs, urlparse + + client, _, _ = _native_client_app(monkeypatch) + client.cookies.set("token", _browser_session_cookie(monkeypatch, "u1", session_key="sk-browser-session")) + registered: Final = client.post("/register", json={"redirect_uris": ["http://127.0.0.1/callback"]}) + assert registered.status_code == 201, registered.text + authorized: Final = client.get( + "/authorize/mcp-session", + params={ + "client_id": registered.json()["client_id"], + "redirect_uri": "http://127.0.0.1/callback", + "response_type": "code", + "code_challenge": _s256("v" * 43), + "code_challenge_method": "S256", + }, + follow_redirects=False, + ) + flow: Final = parse_qs(urlparse(authorized.headers["location"]).query)["connect_flow"][0] + if revoked: + browser_session_database.row = None + response: Final = ( + client.get("/authorize/flow", params={"flow": flow}) + if endpoint == "flow" + else client.post("/authorize/complete", data={"flow": flow}, follow_redirects=False) + ) + assert response.status_code == (401 if revoked else 200 if endpoint == "flow" else 303), response.text + if revoked: + assert response.json()["error"] == "login_required" + assert "location" not in response.headers + elif endpoint == "complete": + assert parse_qs(urlparse(response.headers["location"]).query)["code"] + + @pytest.mark.parametrize("authorize_path", ["/authorize/mcp-session", "/authorize"]) def test_gateway_authorize_routes_forward_server_scope(monkeypatch: pytest.MonkeyPatch, authorize_path: str) -> None: from http.cookies import SimpleCookie from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import CONNECT_FLOW_COOKIE_PREFIX - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.common_utils.encrypt_decrypt_utils import decrypt_value_helper + from litellm.proxy.mcp_server.gateway_dcr_flow import CONNECT_FLOW_COOKIE_PREFIX + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager monkeypatch.setattr( global_mcp_server_manager, @@ -12380,8 +12553,8 @@ def test_introspect_route_requires_virtual_key_auth_and_is_advertised(): from fastapi.routing import APIRoute from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router from litellm.proxy.auth.user_api_key_auth import user_api_key_auth + from litellm.proxy.mcp_server.discoverable_endpoints import router route = next(r for r in router.routes if isinstance(r, APIRoute) and r.path == "/introspect") assert route.methods == {"POST"} @@ -12411,16 +12584,16 @@ def test_introspect_route_answers_for_authenticated_caller(monkeypatch): from fastapi import FastAPI from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router - from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credentials import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.auth.user_api_key_auth import user_api_key_auth + from litellm.proxy.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.outbound_credentials.session_credentials import ( session_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import ( + from litellm.proxy.mcp_server.outbound_credentials.session_token import ( SessionPrincipal, mint_session_token, ) - from litellm.proxy._types import UserAPIKeyAuth - from litellm.proxy.auth.user_api_key_auth import user_api_key_auth introspect_master_key = "sk-introspect-route-test" monkeypatch.setattr("litellm.proxy.proxy_server.master_key", introspect_master_key, raising=False) @@ -12429,7 +12602,7 @@ def test_introspect_route_answers_for_authenticated_caller(monkeypatch): return None monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.reload_active_user_by_id", fake_reload + "litellm.proxy.mcp_server.discoverable_endpoints.reload_active_user_by_id", fake_reload ) app = FastAPI() app.include_router(router) @@ -12458,7 +12631,7 @@ async def test_identity_bound_authorization_carries_nonce_and_caller_through_cal from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _oauth_state_cookie_name, authorize_with_server, callback, @@ -12494,11 +12667,11 @@ async def test_identity_bound_authorization_carries_nonce_and_caller_through_cal ) with ( patch( # test-quality-ok: isolate authenticated request resolution from the real encrypted OAuth round trip - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.authorize_oauth_credential_request", + "litellm.proxy.mcp_server.discoverable_endpoints.authorize_oauth_credential_request", new=AsyncMock(return_value="alice"), ), patch( # test-quality-ok: isolate user access lookup while testing nonce and caller preservation - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._user_can_reach_mcp_server", + "litellm.proxy.mcp_server.discoverable_endpoints._user_can_reach_mcp_server", new=AsyncMock(return_value=True), ), ): @@ -12535,18 +12708,18 @@ async def test_enforced_login_warms_verified_token_readable_without_database_loo from litellm.caching.caching import DualCache from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import db, mcp_server_manager - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import _store_per_user_token_server_side - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import mcp_per_user_token_cache - from litellm.proxy._experimental.mcp_server.oauth_identity_binding import current_binding_proof - from litellm.proxy._experimental.mcp_server.outbound_credentials.dual_cache_token_backend import ( + from litellm.proxy.mcp_server import db, mcp_server_manager + from litellm.proxy.mcp_server.discoverable_endpoints import _store_per_user_token_server_side + from litellm.proxy.mcp_server.oauth2_token_cache import mcp_per_user_token_cache + from litellm.proxy.mcp_server.oauth_identity_binding import current_binding_proof + from litellm.proxy.mcp_server.outbound_credentials.dual_cache_token_backend import ( DualCacheTokenCacheBackend, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import CachedOAuthTokenStore - from litellm.proxy._experimental.mcp_server.outbound_credentials.per_user_oauth_store import ( + from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import CachedOAuthTokenStore + from litellm.proxy.mcp_server.outbound_credentials.per_user_oauth_store import ( LazyPerUserOAuthTokenStore, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.v2_token_store import V2PerUserTokenStore + from litellm.proxy.mcp_server.outbound_credentials.v2_token_store import V2PerUserTokenStore from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -12605,7 +12778,7 @@ async def test_dcr_refusal_is_actionable_without_upstream_body( import httpx - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( mint_ephemeral_dcr_client, register_client_with_server, ) @@ -12700,7 +12873,7 @@ def _gateway_root_path_discovery_router(monkeypatch: pytest.MonkeyPatch) -> "Ite (a second reload would hand earlier importers a different ``router`` object).""" import importlib - from litellm.proxy._experimental.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server import discoverable_endpoints snapshot: Final = dict(vars(discoverable_endpoints)) monkeypatch.setenv("SERVER_ROOT_PATH", "/gateway") @@ -12818,13 +12991,13 @@ async def test_oauth_exchange_stores_token_for_validated_jwt_user( ) -> None: import httpx - from litellm.proxy._experimental.mcp_server import discoverable_endpoints from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server import discoverable_endpoints from litellm.types.mcp_server.mcp_server_manager import MCPServer handler, signing_key = jwt_oauth_identity handler.litellm_jwtauth.custom_validate = lambda claims: policy_allowed - from litellm.proxy._experimental.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server import mcp_server_manager manager: Final = MagicMock() manager.get_allowed_mcp_servers = AsyncMock(return_value=["jwt-oauth-server"] if server_allowed else []) @@ -12939,8 +13112,8 @@ async def test_oauth_jwt_identity_rejects_untrusted_or_inactive_owner( from litellm.models.user import LiteLLM_UserTable from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import mcp_server_manager - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server.bridge_token_flow import ( authorize_oauth_credential_request, extract_user_id_from_request, ) @@ -12986,8 +13159,8 @@ async def test_oauth_jwt_cannot_override_explicit_litellm_key( jwt_oauth_identity: tuple["JWTHandler", "RSAPrivateKey"], blocked: bool, ) -> None: - from litellm.proxy._experimental.mcp_server.bridge_token_flow import extract_user_id_from_request from litellm.proxy._types import UserAPIKeyAuth, hash_token + from litellm.proxy.mcp_server.bridge_token_flow import extract_user_id_from_request handler, signing_key = jwt_oauth_identity key: Final = "sk-explicit-key" @@ -13010,9 +13183,9 @@ async def test_oauth_jwt_uses_configured_virtual_key_owner( mapping: str, ) -> None: from litellm.models.user import LiteLLM_UserTable - from litellm.proxy._experimental.mcp_server.bridge_token_flow import extract_user_id_from_request from litellm.proxy._types import UnregisteredJWTClientBehavior, UserAPIKeyAuth, hash_token from litellm.proxy.auth.auth_checks import jwt_key_mapping_cache_key + from litellm.proxy.mcp_server.bridge_token_flow import extract_user_id_from_request handler, signing_key = jwt_oauth_identity handler.litellm_jwtauth.virtual_key_claim_field = "sub" @@ -13047,7 +13220,7 @@ async def test_oauth_jwt_respects_custom_validation_and_email_policy( jwt_oauth_identity: tuple["JWTHandler", "RSAPrivateKey"], allowed_domain: str | None, ) -> None: - from litellm.proxy._experimental.mcp_server.bridge_token_flow import extract_user_id_from_request + from litellm.proxy.mcp_server.bridge_token_flow import extract_user_id_from_request handler, signing_key = jwt_oauth_identity handler.litellm_jwtauth.custom_validate = lambda claims: True @@ -13064,9 +13237,9 @@ async def test_oauth_jwt_identity_preserves_separate_mcp_route_authorization( route_allowed: bool, ) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.bridge_token_flow import extract_user_id_from_request from litellm.proxy._types import LitellmUserRoles, RoleBasedPermissions, RoleMapping from litellm.proxy.auth.handle_jwt import JWTAuthManager + from litellm.proxy.mcp_server.bridge_token_flow import extract_user_id_from_request handler, signing_key = jwt_oauth_identity handler.litellm_jwtauth.user_id_jwt_field = "sub" @@ -13125,8 +13298,8 @@ async def test_oauth_jwt_resolves_canonical_owner_without_cached_identity( ) -> None: from litellm.models.user import LiteLLM_UserTable from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.bridge_token_flow import extract_user_id_from_request from litellm.proxy.auth.handle_jwt import JWTAuthManager + from litellm.proxy.mcp_server.bridge_token_flow import extract_user_id_from_request handler, signing_key = jwt_oauth_identity external_id: Final = f"external-{identity}-{inactive}-{admin}" @@ -13172,7 +13345,7 @@ async def test_oauth_jwt_identity_does_not_provision_or_synchronize_teams( ) -> None: from litellm.models.user import LiteLLM_UserTable from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.bridge_token_flow import extract_user_id_from_request + from litellm.proxy.mcp_server.bridge_token_flow import extract_user_id_from_request handler, signing_key = jwt_oauth_identity handler.litellm_jwtauth.enforce_team_based_model_access = True @@ -13200,7 +13373,7 @@ async def test_oauth_refresh_revalidates_the_same_active_user_rule( ) -> None: from litellm.models.user import LiteLLM_UserTable from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.bridge_token_flow import reload_active_user_by_id + from litellm.proxy.mcp_server.bridge_token_flow import reload_active_user_by_id handler, _ = jwt_oauth_identity user_id: Final = f"jwt-owner-{state}" @@ -13229,10 +13402,10 @@ async def test_oauth_credential_write_keeps_virtual_key_permissions( ) -> None: import asyncio - from litellm.proxy._experimental.mcp_server import mcp_server_manager - from litellm.proxy._experimental.mcp_server.bridge_token_flow import authorize_oauth_credential_request from litellm.proxy._types import UserAPIKeyAuth, hash_token from litellm.proxy.auth.auth_checks import OrganizationNotFoundError, jwt_key_mapping_cache_key + from litellm.proxy.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server.bridge_token_flow import authorize_oauth_credential_request handler, signing_key = jwt_oauth_identity monkeypatch.setattr( @@ -13298,9 +13471,9 @@ async def test_oauth_writer_preserves_claimed_team_instead_of_expanding_user_ros ) -> None: from litellm.models.user import LiteLLM_UserTable from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import mcp_server_manager - from litellm.proxy._experimental.mcp_server.bridge_token_flow import authorize_oauth_credential_request from litellm.proxy._types import LiteLLM_TeamTable, Member + from litellm.proxy.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server.bridge_token_flow import authorize_oauth_credential_request handler, signing_key = jwt_oauth_identity handler.litellm_jwtauth.team_id_jwt_field = "team" @@ -13336,8 +13509,8 @@ async def test_oauth_write_denial_does_not_erase_identity_binding( jwt_oauth_identity: tuple["JWTHandler", "RSAPrivateKey"], monkeypatch: pytest.MonkeyPatch, ) -> None: - from litellm.proxy._experimental.mcp_server import discoverable_endpoints, mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server import discoverable_endpoints, mcp_server_manager from litellm.types.mcp_server.mcp_server_manager import MCPOAuthIdentityBinding, MCPServer _, signing_key = jwt_oauth_identity @@ -13397,8 +13570,8 @@ async def test_signed_oauth_callback_honors_credential_write_policy( from litellm.caching.llm_caching_handler import LLMClientCache from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import discoverable_endpoints, mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server import discoverable_endpoints, mcp_server_manager from litellm.types.llms.custom_http import httpxSpecialProvider from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -13516,9 +13689,9 @@ async def test_identity_bound_authorize_preserves_presented_jwt_permissions( from litellm.models.user import LiteLLM_UserTable from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import discoverable_endpoints, mcp_server_manager from litellm.proxy._types import JWTIssuerConfig, MCPTransport, UserAPIKeyAuth, hash_token from litellm.proxy.auth.auth_checks import ExperimentalUIJWTToken + from litellm.proxy.mcp_server import discoverable_endpoints, mcp_server_manager from litellm.types.mcp_server.mcp_server_manager import MCPOAuthIdentityBinding, MCPServer handler, signing_key = jwt_oauth_identity @@ -13605,11 +13778,7 @@ async def test_identity_bound_authorize_preserves_presented_jwt_permissions( else "https://idp.example.test", ) ) - cookie: Final = jwt.encode( - {"user_id": "cookie-owner", "login_method": "sso", "exp": int(time.time()) + 300}, - master, - algorithm="HS256", - ) + cookie: Final = _browser_session_cookie(monkeypatch, "cookie-owner", signing_key=master) response: Final = await discoverable_endpoints.authorize_with_server( request=_token_request( { @@ -13645,7 +13814,7 @@ async def test_identity_bound_authorize_preserves_presented_jwt_permissions( @pytest.mark.asyncio @pytest.mark.parametrize("credential", ["none", "opaque", "foreign_jwt"]) -@pytest.mark.parametrize("cookie_state", ["allowed", "server_denied", "expired", "missing"]) +@pytest.mark.parametrize("cookie_state", ["allowed", "server_denied", "expired", "missing", "session_expired"]) async def test_identity_bound_authorize_unrelated_bearer_uses_browser_session( jwt_oauth_identity: tuple["JWTHandler", "RSAPrivateKey"], monkeypatch: pytest.MonkeyPatch, @@ -13654,12 +13823,10 @@ async def test_identity_bound_authorize_unrelated_bearer_uses_browser_session( ) -> None: from urllib.parse import parse_qs, urlparse - import jwt - from litellm.models.user import LiteLLM_UserTable from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import discoverable_endpoints, mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server import discoverable_endpoints, mcp_server_manager from litellm.types.mcp_server.mcp_server_manager import MCPOAuthIdentityBinding, MCPServer handler, signing_key = jwt_oauth_identity @@ -13694,14 +13861,12 @@ async def test_identity_bound_authorize_unrelated_bearer_uses_browser_session( if credential == "foreign_jwt" else "unrelated-upstream-bearer" ) - cookie: Final = jwt.encode( - { - "user_id": "cookie-owner", - "login_method": "sso", - "exp": int(time.time()) + (-60 if cookie_state == "expired" else 300), - }, - master, - algorithm="HS256", + cookie: Final = _browser_session_cookie( + monkeypatch, + "cookie-owner", + signing_key=master, + expired_cookie=cookie_state == "expired", + expired_session=cookie_state == "session_expired", ) response: Final = await discoverable_endpoints.authorize_with_server( request=_token_request( @@ -13744,9 +13909,9 @@ async def test_authorize_observes_committed_peer_server_changes(monkeypatch, cha from fastapi import HTTPException, Request from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import LiteLLM_MCPServerTable + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager monkeypatch.setenv("LITELLM_SALT_KEY", "catalog-consistency-test-key") stamp = datetime.now(timezone.utc) @@ -13801,9 +13966,9 @@ async def test_authorize_observes_committed_peer_server_changes(monkeypatch, cha @pytest.mark.asyncio async def test_update_server_drops_cached_upstream_oauth_metadata(): - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import LiteLLM_MCPServerTable, MCPTransport + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp_server.mcp_server_manager import MCPServer manager = MCPServerManager() @@ -13838,12 +14003,12 @@ async def test_update_server_drops_cached_upstream_oauth_metadata(): async def test_metadata_fetched_before_invalidation_does_not_repopulate_the_cache(): import asyncio - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.discoverable_endpoints import ( fetch_upstream_oauth_protected_resource, invalidate_oauth_metadata_cache, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -13863,7 +14028,7 @@ async def test_metadata_fetched_before_invalidation_does_not_repopulate_the_cach discoverable_endpoints._OAUTH_METADATA_CACHE.pop(cache_key, None) try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=client, ): in_flight: Final = asyncio.create_task(fetch_upstream_oauth_protected_resource(server)) @@ -13883,12 +14048,12 @@ async def test_metadata_fetched_before_invalidation_does_not_repopulate_the_cach async def test_fetch_waiting_on_a_lock_handoff_stays_tracked_through_invalidation(): import asyncio - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.discoverable_endpoints import ( fetch_upstream_oauth_protected_resource, invalidate_oauth_metadata_cache, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -13908,7 +14073,7 @@ async def test_fetch_waiting_on_a_lock_handoff_stays_tracked_through_invalidatio discoverable_endpoints._OAUTH_METADATA_CACHE.pop(cache_key, None) try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=client, ): async with discoverable_endpoints._oauth_metadata_fetch_slot(cache_key): @@ -13934,8 +14099,8 @@ async def test_fetch_waiting_on_a_lock_handoff_stays_tracked_through_invalidatio def test_invalidating_an_idle_server_leaves_no_generation_behind(): - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import invalidate_oauth_metadata_cache + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.discoverable_endpoints import invalidate_oauth_metadata_cache server_ids: Final = tuple(f"churned-server-{i}" for i in range(50)) try: @@ -13964,7 +14129,7 @@ async def test_callback_rejects_missing_advertised_issuer(monkeypatch): ], ) def test_persisted_client_is_not_applied_to_another_upstream(issuer, url): - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _apply_persisted_dcr_credentials, _PersistedDcrCredentials, ) @@ -13989,7 +14154,7 @@ async def test_registration_does_not_write_client_after_upstream_edit(monkeypatc from prisma import models from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import _persist_dcr_client_registration + from litellm.proxy.mcp_server.discoverable_endpoints import _persist_dcr_client_registration server = _issuer_anchored_oauth_server().model_copy( update={"url": "https://resource.example/mcp", "client_id": None} @@ -14022,7 +14187,7 @@ async def test_registration_does_not_write_client_after_upstream_edit(monkeypatc "response_issuer", ["https://IDP.example.com", "https://idp.example.com/", "https://idp.example.com:443"] ) def test_issuer_validation_uses_exact_identifier(response_issuer): - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import _authorization_response_issuer_is_trusted + from litellm.proxy.mcp_server.discoverable_endpoints import _authorization_response_issuer_is_trusted assert ( _authorization_response_issuer_is_trusted(response_issuer, {"expected_issuer": "https://idp.example.com"}) @@ -14038,7 +14203,7 @@ def test_issuer_validation_uses_exact_identifier(response_issuer): ], ) def test_persisted_client_remains_usable_for_its_issuer(issuer, url, monkeypatch): - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _apply_persisted_dcr_credentials, _PersistedDcrCredentials, ) @@ -14075,7 +14240,7 @@ async def test_callback_does_not_forward_error_from_another_issuer(monkeypatch): async def test_bound_client_cannot_be_sent_to_a_different_issuer(monkeypatch, operation): from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -14122,7 +14287,7 @@ async def test_bound_client_cannot_be_sent_to_a_different_issuer(monkeypatch, op async def test_failed_registration_preserves_cached_credentials(monkeypatch): from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints server = _dcr_redirect_test_server("old-client").model_copy( update={ @@ -14168,7 +14333,7 @@ async def test_registration_without_database_keeps_client_in_temporary_server(mo from fastapi import Request from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setattr(proxy_server, "prisma_client", None) server = _dcr_redirect_test_server(None).model_copy( @@ -14202,9 +14367,9 @@ async def test_registration_without_database_keeps_client_in_temporary_server(mo @pytest.mark.parametrize("config_store", [False, True]) async def test_registration_does_not_overwrite_credentials_after_failed_identity_read(monkeypatch, config_store): from litellm.proxy import utils - from litellm.proxy._experimental.mcp_server import db - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import db + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _dcr_redirect_test_server(None) monkeypatch.setattr(utils, "get_prisma_client_or_throw", lambda _: MagicMock()) @@ -14234,9 +14399,9 @@ async def test_registration_does_not_overwrite_credentials_after_failed_identity @pytest.mark.parametrize("winner_available", [False, True]) async def test_registration_losing_conditional_write_reuses_only_a_matching_winner(monkeypatch, winner_available): from litellm.proxy import utils - from litellm.proxy._experimental.mcp_server import db - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints from litellm.proxy._types import LiteLLM_MCPServerTable + from litellm.proxy.mcp_server import db + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints server = _dcr_redirect_test_server(None).model_copy(update={"url": "https://upstream.example/mcp"}) row = LiteLLM_MCPServerTable.model_validate(server.model_dump(exclude_none=True)) @@ -14279,8 +14444,8 @@ async def test_register_preserves_client_application_type_only_for_bridge_relay( import respx from fastapi import FastAPI - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server: Final = _bridge_server(auth_type=auth_type, server_id="application-client", alias="application-client") app: Final = FastAPI() @@ -14322,8 +14487,8 @@ async def test_register_rejects_invalid_application_type_before_upstream( import respx from fastapi import FastAPI - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server: Final = _bridge_server(server_id="invalid-application-client", alias="invalid-application-client") app: Final = FastAPI() @@ -14355,8 +14520,8 @@ async def test_register_application_type_keeps_no_registration_endpoint_fallback import respx from fastapi import FastAPI - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server: Final = _bridge_server( auth_type=MCPAuth.oauth2, @@ -14421,7 +14586,7 @@ def _cimd_request(): @pytest.mark.asyncio async def test_cimd_registration_returns_https_identity_without_dcr(monkeypatch, respx_mock): - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") response = await endpoints.register_client_with_server( @@ -14437,7 +14602,7 @@ async def test_cimd_registration_returns_https_identity_without_dcr(monkeypatch, async def test_cimd_authorization_uses_metadata_identity_and_s256(monkeypatch): from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") monkeypatch.setenv("LITELLM_SALT_KEY", "cimd-test-state-signing-key") @@ -14459,7 +14624,7 @@ async def test_cimd_authorization_uses_metadata_identity_and_s256(monkeypatch): async def test_cimd_authorization_rejects_missing_pkce(monkeypatch): from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") monkeypatch.setenv("LITELLM_SALT_KEY", "cimd-test-state-signing-key") @@ -14471,7 +14636,7 @@ async def test_cimd_authorization_rejects_missing_pkce(monkeypatch): def test_cimd_refresh_request_uses_same_identity_without_caller_secret(monkeypatch): - from litellm.proxy._experimental.mcp_server.oauth_utils import build_upstream_oauth2_token_request + from litellm.proxy.mcp_server.oauth_utils import build_upstream_oauth2_token_request monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") request = build_upstream_oauth2_token_request( @@ -14489,7 +14654,7 @@ def test_cimd_refresh_request_uses_same_identity_without_caller_secret(monkeypat async def test_cimd_without_stable_https_origin_reports_actionable_error(monkeypatch, base, respx_mock): from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.delenv("PROXY_BASE_URL", raising=False) if base is not None: @@ -14504,7 +14669,7 @@ async def test_cimd_without_stable_https_origin_reports_actionable_error(monkeyp @pytest.mark.parametrize("base", [None, "http://gateway.example.com"]) @pytest.mark.asyncio async def test_cimd_without_https_origin_falls_back_to_available_dcr(monkeypatch, base, respx_mock): - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.delenv("PROXY_BASE_URL", raising=False) if base is not None: @@ -14519,8 +14684,8 @@ async def test_cimd_without_https_origin_falls_back_to_available_dcr(monkeypatch @pytest.mark.asyncio async def test_cimd_yields_to_dynamic_registration_when_the_authorization_server_offers_both(monkeypatch, respx_mock): - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints - from litellm.proxy._experimental.mcp_server.oauth_utils import get_cimd_client_id + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server.oauth_utils import get_cimd_client_id monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") @@ -14535,7 +14700,7 @@ async def test_cimd_yields_to_dynamic_registration_when_the_authorization_server @pytest.mark.asyncio async def test_cimd_is_preferred_over_dynamic_registration_when_the_deployment_opts_in(monkeypatch, respx_mock): from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") @@ -14564,7 +14729,7 @@ async def test_cimd_is_preferred_over_dynamic_registration_when_the_deployment_o ], ) def test_cimd_preserves_existing_identity_and_other_auth_modes(monkeypatch, updates): - from litellm.proxy._experimental.mcp_server.oauth_utils import get_cimd_client_id + from litellm.proxy.mcp_server.oauth_utils import get_cimd_client_id monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") assert get_cimd_client_id(_cimd_oauth_server().model_copy(update=updates)) is None @@ -14575,7 +14740,7 @@ async def test_cimd_document_is_public_and_binds_configured_origin(monkeypatch): import httpx from fastapi import FastAPI - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com/proxy") app = FastAPI() @@ -14595,7 +14760,7 @@ async def test_cimd_document_is_public_and_binds_configured_origin(monkeypatch): async def test_cimd_document_is_unavailable_without_configured_https_origin(monkeypatch, base): from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.delenv("PROXY_BASE_URL", raising=False) if base is not None: @@ -14607,7 +14772,7 @@ async def test_cimd_document_is_unavailable_without_configured_https_origin(monk @pytest.mark.asyncio async def test_cimd_upstream_client_rejection_is_gateway_fault(monkeypatch, respx_mock): - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") @@ -14638,8 +14803,8 @@ async def test_optional_cimd_discovery_preserves_the_callers_configured_endpoint ) -> None: from urllib.parse import parse_qs - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import mcp_server_manager as manager_module monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") monkeypatch.setenv("LITELLM_MCP_OAUTH_DISCOVERY_ON_STARTUP", "0") @@ -14709,8 +14874,8 @@ async def test_token_route_preserves_saved_cimd_grant_after_origin_change( from urllib.parse import parse_qs from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import db, mcp_server_manager - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import db, mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") monkeypatch.setenv("LITELLM_SALT_KEY", "saved-cimd-route-test-salt") @@ -14781,8 +14946,8 @@ async def test_saved_refresh_metadata_is_bound_to_the_callers_stored_grant( from types import SimpleNamespace from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import db - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import db + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setenv("LITELLM_SALT_KEY", "saved-cimd-owner-test-salt") server: Final = _cimd_oauth_server() @@ -14842,9 +15007,9 @@ async def test_managed_authorize_retains_the_callers_previous_grant( from urllib.parse import parse_qs, urlsplit from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import db - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import db + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager _, signing_key = jwt_oauth_identity monkeypatch.setenv("LITELLM_SALT_KEY", "scope-grant-test-salt") @@ -14888,9 +15053,9 @@ async def test_managed_code_exchange_preserves_requested_scope_only_when_omitted from urllib.parse import parse_qs, urlsplit from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import db - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import db + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager _, signing_key = jwt_oauth_identity monkeypatch.setenv("LITELLM_SALT_KEY", "requested-scope-test-salt") @@ -14952,7 +15117,7 @@ async def test_managed_authorize_requests_only_selected_scope_and_supported_refr from mcp.shared.auth import OAuthMetadata - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setenv("LITELLM_SALT_KEY", "metadata-scope-test-salt") metadata = OAuthMetadata( @@ -14978,7 +15143,7 @@ async def test_managed_authorize_requests_only_selected_scope_and_supported_refr @pytest.mark.asyncio @pytest.mark.parametrize("mismatch", ["server", "issuer", "user", "mode", "tampered", "invalid_payload"]) async def test_managed_scope_code_cannot_cross_oauth_boundaries(jwt_oauth_identity, monkeypatch, respx_mock, mismatch): - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints _, signing_key = jwt_oauth_identity monkeypatch.setenv("LITELLM_SALT_KEY", "scope-boundary-test-salt") @@ -15033,9 +15198,9 @@ async def test_managed_refresh_retains_only_the_actual_grant( from types import SimpleNamespace from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import db - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import db + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager _, signing_key = jwt_oauth_identity monkeypatch.setenv("LITELLM_SALT_KEY", "refresh-scope-test-salt") @@ -15091,8 +15256,8 @@ async def test_managed_refresh_retains_only_the_actual_grant( @pytest.mark.asyncio @pytest.mark.parametrize("per_server_relay", [False, True]) async def test_managed_resource_metadata_excludes_refresh_permission(monkeypatch, per_server_relay): - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _cimd_oauth_server().model_copy( update={ @@ -15116,8 +15281,8 @@ async def test_managed_resource_metadata_excludes_refresh_permission(monkeypatch ], ) async def test_connect_requires_the_requested_vendor_grant(monkeypatch, granted, required, expected): - from litellm.proxy._experimental.mcp_server import db - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import db + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints credential = {**_stored_grant(), "scopes": granted} read = AsyncMock(return_value=credential) @@ -15143,8 +15308,8 @@ def test_aggregate_protected_resource_advertises_header_server_scopes( ) -> None: """A client that re-authenticates from cached discovery never sees the 401 challenge, so the aggregate PRM carries the x-mcp-servers selection as scopes_supported instead.""" - from litellm.proxy._experimental.mcp_server import mcp_server_manager - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_aggregate_protected_resource_response, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -15186,9 +15351,9 @@ async def test_token_endpoint_routes_the_jwt_bearer_grant_to_the_aggregate_gatew """A requesting app presents its identity provider's client_id, never a gateway DCR one, so the aggregate dispatch keys on the grant type for RFC 7523 and hands the assertion to the ID-JAG redeemer. A per-server token endpoint never serves that grant.""" - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import JWT_BEARER_GRANT_TYPE - from litellm.proxy._experimental.mcp_server.id_jag_grant import IdJagPrerequisites + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.gateway_dcr_flow import JWT_BEARER_GRANT_TYPE + from litellm.proxy.mcp_server.id_jag_grant import IdJagPrerequisites request = _mock_callback_request("https://litellm.example.com/") with patch("litellm.proxy.proxy_server.master_key", "sk-test-salt-for-lit9670"): @@ -15230,8 +15395,8 @@ async def test_token_endpoint_takes_the_client_id_from_http_basic_when_the_form_ header the request is a 400 invalid_request, not a 422.""" from base64 import b64encode - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import JWT_BEARER_GRANT_TYPE + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.gateway_dcr_flow import JWT_BEARER_GRANT_TYPE request = _mock_callback_request("https://litellm.example.com/") request.headers = {"authorization": "Basic " + b64encode(b"0oa-requesting-app:app-secret").decode()} @@ -15262,9 +15427,9 @@ def test_root_metadata_is_the_gateways_own_and_lists_the_jwt_bearer_grant_when_i exactly when the gateway serves it, under the same gates as the aggregate ``/mcp`` document.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import JWT_BEARER_GRANT_TYPE - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.gateway_dcr_flow import JWT_BEARER_GRANT_TYPE + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager global_mcp_server_manager.registry.clear() request = MagicMock(spec=Request) @@ -15290,9 +15455,9 @@ def test_root_metadata_owned_by_a_resolved_oauth2_server_never_lists_the_gateway ``/.well-known/oauth-authorization-server/mcp`` document in that deployment.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import JWT_BEARER_GRANT_TYPE - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.gateway_dcr_flow import JWT_BEARER_GRANT_TYPE + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _create_oauth2_server() global_mcp_server_manager.registry.clear() diff --git a/tests/unit/proxy/_experimental/mcp_server/test_gateway_dcr_flow.py b/tests/unit/proxy/mcp_server/test_gateway_dcr_flow.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_gateway_dcr_flow.py rename to tests/unit/proxy/mcp_server/test_gateway_dcr_flow.py index 530667fdfdd..a426cea131a 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_gateway_dcr_flow.py +++ b/tests/unit/proxy/mcp_server/test_gateway_dcr_flow.py @@ -14,7 +14,8 @@ from starlette.requests import Request from starlette.responses import Response from litellm.caching.caching import DualCache -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( +from litellm.proxy.common_utils.encrypt_decrypt_utils import encrypt_value_helper +from litellm.proxy.mcp_server.gateway_dcr_flow import ( _AUTH_CODE_DEBUG_KEY, ACCESS_TOKEN_TOKEN_TYPE, CONNECT_FLOW_COOKIE_PREFIX, @@ -48,21 +49,20 @@ from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( revoke_refresh_token, supported_grant_types, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials.session_credentials import ( SessionBearerAdmitted, SessionRefreshOpened, open_session_refresh_bearer, resolve_session_bearer, session_keys_from_master_key, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import ( +from litellm.proxy.mcp_server.outbound_credentials.session_token import ( SESSION_ISSUER, SESSION_REFRESH_PREFIX, SessionPrincipal, mint_session_refresh_token, mint_session_token, ) -from litellm.proxy.common_utils.encrypt_decrypt_utils import encrypt_value_helper MASTER_KEY = "sk-gateway-dcr-flow-tests" REDIRECT_URI = "https://claude.ai/api/mcp/auth_callback" @@ -205,7 +205,7 @@ def test_pkce_mismatched_challenge_returns_false_never_raises(code_challenge): two str with non-ASCII content, but on bytes of unequal length it simply returns False. A review flagged this as an unhandled 500 on length mismatch; encoding both sides to bytes is exactly what makes that impossible, so the claim is pinned here rather than in a comment.""" - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import _pkce_verifier_matches + from litellm.proxy.mcp_server.gateway_dcr_flow import _pkce_verifier_matches assert _pkce_verifier_matches("a" * 43, code_challenge) is False @@ -563,7 +563,7 @@ def test_permanent_db_fault_503_does_not_promise_a_retry_will_help(): """Both DB failures are 503 temporarily_unavailable (the only OAuth error a client reads as a server-side outage), so the description is the one place the two are told apart: a transient outage says retry, a fault that never heals must say retrying will not help and point at the deployment.""" - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( + from litellm.proxy.mcp_server.gateway_dcr_flow import ( _consent_lookup_failure_response, _mint_failure_response, _reload_failure_response, @@ -682,7 +682,7 @@ async def test_non_ascii_code_challenge_fails_grant_not_500(): async def test_single_use_guard_in_memory_is_single_use_within_process(): """No Redis configured (single-replica): the in-memory increment is authoritative — the first claim wins, a replay of the same id loses.""" - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import _SingleUseGuard + from litellm.proxy.mcp_server.gateway_dcr_flow import _SingleUseGuard guard = _SingleUseGuard(DualCache()) # redis_cache is None assert await guard.claim("jti-inmem", 60) == "first" @@ -695,7 +695,7 @@ async def test_single_use_guard_uses_redis_as_sole_authority_when_configured(): first caller, >1 → replay), and the per-worker in-memory count is never consulted.""" from unittest.mock import AsyncMock, MagicMock - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import _SingleUseGuard + from litellm.proxy.mcp_server.gateway_dcr_flow import _SingleUseGuard cache = DualCache() cache.redis_cache = MagicMock() @@ -716,7 +716,7 @@ async def test_single_use_guard_fails_closed_when_redis_errors(): Cursor/Veria replay-across-workers finding).""" from unittest.mock import AsyncMock, MagicMock - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import _SingleUseGuard + from litellm.proxy.mcp_server.gateway_dcr_flow import _SingleUseGuard cache = DualCache() cache.redis_cache = MagicMock() @@ -734,7 +734,7 @@ async def test_single_use_guard_peek_fails_closed_when_redis_errors(): look unclaimed for exactly as long as Redis is down.""" from unittest.mock import AsyncMock, MagicMock - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import _SingleUseGuard + from litellm.proxy.mcp_server.gateway_dcr_flow import _SingleUseGuard cache = DualCache() cache.redis_cache = MagicMock() @@ -756,7 +756,7 @@ async def test_single_use_guard_peek_reads_the_key_under_the_namespace_claim_wro peeked at the bare key would never be seen, and the revoked chain would keep renewing.""" from unittest.mock import AsyncMock, MagicMock - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import _SingleUseGuard + from litellm.proxy.mcp_server.gateway_dcr_flow import _SingleUseGuard stored: dict[str, int] = {} # mutable-ok: the fake Redis store the test inspects @@ -1003,7 +1003,7 @@ def _scoped_mcp_server(name="github", auth_type="oauth2", **kw): SCOPED_RESOURCE = "https://llm.example.com/mcp/github" -_MANAGER_PATCH = "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" +_MANAGER_PATCH = "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" def _scoped_authorize( @@ -1475,7 +1475,7 @@ async def test_unknown_server_scope_redirects_with_invalid_scope_and_state() -> ], ) def test_gateway_server_scope_accepts_only_rfc6749_scope_tokens(server_name: str, expected: str | None) -> None: - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import gateway_server_scope + from litellm.proxy.mcp_server.gateway_dcr_flow import gateway_server_scope assert gateway_server_scope(server_name) == expected @@ -1728,7 +1728,7 @@ async def test_resolve_scoped_resource_server_matrix(): modes all return None so nothing outside the served set can enter the scoped flow.""" from unittest.mock import patch - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import resolve_scoped_resource_server + from litellm.proxy.mcp_server.gateway_dcr_flow import resolve_scoped_resource_server request = _request() github = _scoped_mcp_server() @@ -1757,7 +1757,7 @@ async def test_resource_resolution_is_identity_not_ip_filtered_access(): between authorize and token would turn a matching redemption into invalid_target.""" from unittest.mock import patch - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import resolve_scoped_resource_server + from litellm.proxy.mcp_server.gateway_dcr_flow import resolve_scoped_resource_server with patch(_MANAGER_PATCH) as manager: manager.get_mcp_server_by_identifier.return_value = _scoped_mcp_server() @@ -2666,7 +2666,7 @@ async def test_introspect_accepts_rs256_signed_tokens_under_configured_signing(m from pydantic import SecretStr from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import AsymmetricSessionKeys + from litellm.proxy.mcp_server.outbound_credentials.session_token import AsymmetricSessionKeys private_pem = ( rsa.generate_private_key(public_exponent=65537, key_size=2048) @@ -3024,7 +3024,7 @@ async def test_aggregate_step_up_rejects_malformed_permissions(scope): async def test_step_up_validates_every_target_before_credential_reads_and_preserves_each_grant(): from unittest.mock import AsyncMock, patch - from litellm.proxy._experimental.mcp_server.oauth_utils import encode_upstream_scope + from litellm.proxy.mcp_server.oauth_utils import encode_upstream_scope client_id = (await _register([REDIRECT_URI]))["client_id"] first, second = _scoped_mcp_server("first"), _scoped_mcp_server("second") @@ -3075,7 +3075,7 @@ async def test_step_up_validates_every_target_before_credential_reads_and_preser async def test_named_resource_rejects_another_upstreams_permission_before_consent(): from unittest.mock import patch - from litellm.proxy._experimental.mcp_server.oauth_utils import encode_upstream_scope + from litellm.proxy.mcp_server.oauth_utils import encode_upstream_scope client_id = (await _register([REDIRECT_URI]))["client_id"] with patch(_MANAGER_PATCH) as manager: @@ -3094,7 +3094,7 @@ async def test_named_resource_rejects_another_upstreams_permission_before_consen ], ) def test_upstream_permission_scope_round_trip_preserves_identity_and_permission(identity, permission): - from litellm.proxy._experimental.mcp_server.oauth_utils import decode_upstream_scope, encode_upstream_scope + from litellm.proxy.mcp_server.oauth_utils import decode_upstream_scope, encode_upstream_scope encoded = encode_upstream_scope(identity, permission) decoded = decode_upstream_scope(encoded) @@ -3108,7 +3108,7 @@ def test_upstream_permission_scope_round_trip_preserves_identity_and_permission( async def test_upstream_step_up_cannot_finish_with_an_unproven_grant(state, expected): from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server.oauth_utils import encode_upstream_scope + from litellm.proxy.mcp_server.oauth_utils import encode_upstream_scope client_id = (await _register([REDIRECT_URI]))["client_id"] server = _scoped_mcp_server() @@ -3133,11 +3133,11 @@ async def test_sdk_completes_aggregate_step_up_discovery_consent_and_pkce(route) from mcp.client.auth import OAuthClientProvider from mcp.shared.auth import AuthorizationCodeResult, OAuthClientMetadata - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_aggregate_authorization_server_response, oauth_protected_resource_root, ) - from litellm.proxy._experimental.mcp_server.exceptions import MCPUpstreamAuthError + from litellm.proxy.mcp_server.exceptions import MCPUpstreamAuthError server = _scoped_mcp_server() storage = AsyncMock() @@ -3209,7 +3209,7 @@ async def test_sdk_completes_aggregate_step_up_discovery_consent_and_pkce(route) ["tools.write", "litellm:mcp_scope::7772697465", "litellm:mcp_scope:6964:5A", "litellm:mcp_scope:6964:7772 697465"], ) def test_upstream_permission_rejects_noncanonical_tokens(scope): - from litellm.proxy._experimental.mcp_server.oauth_utils import decode_upstream_scope + from litellm.proxy.mcp_server.oauth_utils import decode_upstream_scope assert decode_upstream_scope(scope) is None @@ -3218,7 +3218,7 @@ def test_upstream_permission_rejects_noncanonical_tokens(scope): async def test_named_step_up_finish_describes_and_retains_its_single_server_ceiling(): from unittest.mock import AsyncMock, patch - from litellm.proxy._experimental.mcp_server.oauth_utils import encode_upstream_scope + from litellm.proxy.mcp_server.oauth_utils import encode_upstream_scope client_id = (await _register([REDIRECT_URI]))["client_id"] server = _scoped_mcp_server() @@ -3244,7 +3244,7 @@ async def test_named_step_up_finish_describes_and_retains_its_single_server_ceil async def test_upstream_step_up_inside_multi_server_scope_describes_every_sealed_server() -> None: from unittest.mock import AsyncMock, patch - from litellm.proxy._experimental.mcp_server.oauth_utils import encode_upstream_scope + from litellm.proxy.mcp_server.oauth_utils import encode_upstream_scope client_id: Final = (await _register([REDIRECT_URI]))["client_id"] alpha: Final = _scoped_mcp_server(name="alpha") @@ -3490,7 +3490,7 @@ def test_aggregate_metadata_advertises_basic_client_auth_only_with_the_grant_tha ``client_secret`` from the form, so ``client_secret_basic`` is advertised only when that grant is on. A client following the document otherwise sends Basic alone and authenticates with no secret.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_aggregate_authorization_server_response, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_id_jag_grant.py b/tests/unit/proxy/mcp_server/test_id_jag_grant.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_id_jag_grant.py rename to tests/unit/proxy/mcp_server/test_id_jag_grant.py index f4fa51d57ba..f5d7a07ddb4 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_id_jag_grant.py +++ b/tests/unit/proxy/mcp_server/test_id_jag_grant.py @@ -10,14 +10,22 @@ import pytest from fastapi import HTTPException from litellm.caching.caching import DualCache -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( +from litellm.proxy._types import IdJagRequestingApp, LiteLLM_JWTAuth, LiteLLMRoutes +from litellm.proxy.auth.handle_jwt import ( + ID_JAG_TYP, + AssertionRejection, + JWKSUnreachableError, + JWTHandler, + jwks_unavailable_exception, +) +from litellm.proxy.mcp_server.gateway_dcr_flow import ( AssertionIdentity, ConsentTeam, ReloadUserFailure, SubjectIdentity, SubjectTokenRefusal, ) -from litellm.proxy._experimental.mcp_server.id_jag_grant import ( +from litellm.proxy.mcp_server.id_jag_grant import ( ID_JAG_REQUIRED_CLAIMS, REJECTED_ASSERTION, TEAM_HEADER, @@ -37,14 +45,6 @@ from litellm.proxy._experimental.mcp_server.id_jag_grant import ( select_team, subject_resolver, ) -from litellm.proxy._types import IdJagRequestingApp, LiteLLM_JWTAuth, LiteLLMRoutes -from litellm.proxy.auth.handle_jwt import ( - ID_JAG_TYP, - AssertionRejection, - JWKSUnreachableError, - JWTHandler, - jwks_unavailable_exception, -) ISSUER = "https://idp.example.com" GATEWAY = "https://gateway.example.com" diff --git a/tests/unit/proxy/_experimental/mcp_server/test_idp_token_exchange.py b/tests/unit/proxy/mcp_server/test_idp_token_exchange.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_idp_token_exchange.py rename to tests/unit/proxy/mcp_server/test_idp_token_exchange.py index e94371a6056..036ee4a332b 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_idp_token_exchange.py +++ b/tests/unit/proxy/mcp_server/test_idp_token_exchange.py @@ -7,8 +7,10 @@ from prisma.engine.errors import BinaryNotFoundError from prisma.errors import DataError from litellm.caching.caching import DualCache -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import SubjectIdentity, SubjectTokenRefusal -from litellm.proxy._experimental.mcp_server.idp_token_exchange import ( +from litellm.proxy._types import JWTIssuerConfig, LiteLLM_JWTAuth, ProxyException +from litellm.proxy.auth.handle_jwt import JWKSUnreachableError, JWTHandler, jwks_unavailable_exception +from litellm.proxy.mcp_server.gateway_dcr_flow import SubjectIdentity, SubjectTokenRefusal +from litellm.proxy.mcp_server.idp_token_exchange import ( REJECTED_SUBJECT_TOKEN, SUBJECT_TOKEN_CHECK_FAULTED, SUBJECT_TOKEN_CHECK_UNAVAILABLE, @@ -16,8 +18,6 @@ from litellm.proxy._experimental.mcp_server.idp_token_exchange import ( identity_from_subject_token, token_exchange_available, ) -from litellm.proxy._types import JWTIssuerConfig, LiteLLM_JWTAuth, ProxyException -from litellm.proxy.auth.handle_jwt import JWKSUnreachableError, JWTHandler, jwks_unavailable_exception IDP_JWT = "eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJ1MSJ9.idp-signature" REQUEST_HEADERS = {"x-litellm-team-id": "team-b", "user-agent": "lite/0.1"} diff --git a/tests/unit/proxy/_experimental/mcp_server/test_interactions.py b/tests/unit/proxy/mcp_server/test_interactions.py similarity index 94% rename from tests/unit/proxy/_experimental/mcp_server/test_interactions.py rename to tests/unit/proxy/mcp_server/test_interactions.py index 8286269525a..aa4c00b1f07 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_interactions.py +++ b/tests/unit/proxy/mcp_server/test_interactions.py @@ -4,9 +4,9 @@ import pytest from mcp import MCPError from mcp.types import CallToolRequest, CallToolRequestParams, InputRequiredResult -from litellm.proxy._experimental.mcp_server.contracts import OperationContext -from litellm.proxy._experimental.mcp_server.interactions import bind_target, open_continuation, seal_continuation from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server.contracts import OperationContext +from litellm.proxy.mcp_server.interactions import bind_target, open_continuation, seal_continuation from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -130,7 +130,8 @@ def test_altered_continuations_are_rejected(change: str, monkeypatch: pytest.Mon def test_input_responses_without_state_and_unbound_results_are_rejected(monkeypatch: pytest.MonkeyPatch) -> None: from mcp.types import ElicitResult - from litellm.proxy._experimental.mcp_server.interactions import BoundInputRequiredResult + + from litellm.proxy.mcp_server.interactions import BoundInputRequiredResult monkeypatch.setenv("LITELLM_SALT_KEY", "test-salt") context: Final = OperationContext(_caller=UserAPIKeyAuth(user_id="alice")) @@ -144,8 +145,8 @@ def test_input_responses_without_state_and_unbound_results_are_rejected(monkeypa def test_authenticated_but_invalid_state_payload_is_rejected(monkeypatch: pytest.MonkeyPatch) -> None: - from litellm.proxy._experimental.mcp_server.state_tokens import seal_state - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.state_tokens import seal_state monkeypatch.setenv("LITELLM_SALT_KEY", "test-salt") sealed: Final = seal_state( @@ -169,7 +170,8 @@ async def test_modern_sampling_errors_abort_without_relaying_form_input() -> Non ElicitRequestFormParams, ErrorData, ) - from litellm.proxy._experimental.mcp_server.interactions import ModernClientInteraction + + from litellm.proxy.mcp_server.interactions import ModernClientInteraction async def sampling(context: object, params: CreateMessageRequestParams) -> ErrorData: return ErrorData(code=-32603, message="Sampling refused by gateway policy") @@ -204,10 +206,12 @@ async def test_gateway_rejects_invalid_interaction_boundaries( invalid_response: Literal["legacy_state", "gateway_override", "unbound_result"], monkeypatch: pytest.MonkeyPatch ) -> None: from unittest.mock import AsyncMock, patch + from mcp.types import CreateMessageResult, ElicitResult, TextContent - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.contracts import WireCompat - from litellm.proxy._experimental.mcp_server.interactions import BoundInputRequiredResult + + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.contracts import WireCompat + from litellm.proxy.mcp_server.interactions import BoundInputRequiredResult monkeypatch.setenv("LITELLM_SALT_KEY", "test-salt") context: Final = OperationContext( diff --git a/tests/unit/proxy/_experimental/mcp_server/test_is_tool_name_prefixed.py b/tests/unit/proxy/mcp_server/test_is_tool_name_prefixed.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_is_tool_name_prefixed.py rename to tests/unit/proxy/mcp_server/test_is_tool_name_prefixed.py index 8f09e2410c4..f8dea399067 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_is_tool_name_prefixed.py +++ b/tests/unit/proxy/mcp_server/test_is_tool_name_prefixed.py @@ -6,8 +6,7 @@ Verifies fix for https://github.com/BerriAI/litellm/issues/25081 import pytest -from litellm.proxy._experimental.mcp_server.utils import is_tool_name_prefixed - +from litellm.proxy.mcp_server.utils import is_tool_name_prefixed # --------------------------------------------------------------------------- # Legacy behaviour (no known_server_prefixes passed) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_jwt_mcp_enforcement.py b/tests/unit/proxy/mcp_server/test_jwt_mcp_enforcement.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_jwt_mcp_enforcement.py rename to tests/unit/proxy/mcp_server/test_jwt_mcp_enforcement.py index eddfdc4f884..ea275373f2f 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_jwt_mcp_enforcement.py +++ b/tests/unit/proxy/mcp_server/test_jwt_mcp_enforcement.py @@ -8,20 +8,21 @@ Scenario: 4. EXPECTED: Team MCP permissions should be enforced """ -import pytest from unittest.mock import AsyncMock, MagicMock, patch +import pytest + from litellm.proxy._types import ( LiteLLM_JWTAuth, - LiteLLM_TeamTable, LiteLLM_ObjectPermissionTable, + LiteLLM_TeamTable, UserAPIKeyAuth, ) from litellm.proxy.auth.handle_jwt import JWTAuthManager, JWTHandler -from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( +from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) -from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager +from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager @pytest.mark.asyncio diff --git a/tests/unit/proxy/_experimental/mcp_server/test_jwt_mcp_simple.py b/tests/unit/proxy/mcp_server/test_jwt_mcp_simple.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_jwt_mcp_simple.py rename to tests/unit/proxy/mcp_server/test_jwt_mcp_simple.py index 7ee340a69f4..f258ba8b7e9 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_jwt_mcp_simple.py +++ b/tests/unit/proxy/mcp_server/test_jwt_mcp_simple.py @@ -2,13 +2,14 @@ Simple test to validate MCP permissions are enforced when calling MCP routes with JWT. """ -import pytest from unittest.mock import AsyncMock, MagicMock, patch +import pytest + from litellm.proxy._types import ( LiteLLM_JWTAuth, - LiteLLM_TeamTable, LiteLLM_ObjectPermissionTable, + LiteLLM_TeamTable, UserAPIKeyAuth, ) @@ -24,7 +25,7 @@ async def test_simple_jwt_mcp_permissions_enforced(): Expected: Only ["github-mcp", "slack-mcp"] should be allowed """ - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -86,7 +87,7 @@ async def test_simple_jwt_no_team_no_mcp_servers(): """ Simple test: JWT user with no team should get no MCP servers. """ - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -111,7 +112,7 @@ async def test_simple_jwt_team_id_required_for_mcp_permissions(): This is the key insight - if JWT auth doesn't set team_id, team MCP permissions won't be enforced. """ - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -176,8 +177,8 @@ async def test_jwt_auth_sets_team_id_for_mcp_route(): This is the critical test - when user calls /mcp/tools/list with JWT, the team_id from JWT groups must be set on UserAPIKeyAuth. """ - from litellm.proxy.auth.handle_jwt import JWTAuthManager, JWTHandler from litellm.caching import DualCache + from litellm.proxy.auth.handle_jwt import JWTAuthManager, JWTHandler from litellm.proxy.utils import ProxyLogging # Setup @@ -245,8 +246,8 @@ async def test_mcp_route_without_model_still_returns_team_id(): 4. Route check passes because "mcp_routes" is in team_allowed_routes 5. team_id is returned and set on UserAPIKeyAuth """ - from litellm.proxy.auth.handle_jwt import JWTAuthManager, JWTHandler from litellm.caching import DualCache + from litellm.proxy.auth.handle_jwt import JWTAuthManager, JWTHandler from litellm.proxy.utils import ProxyLogging # Setup diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_auth_header_extraction.py b/tests/unit/proxy/mcp_server/test_mcp_auth_header_extraction.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_auth_header_extraction.py rename to tests/unit/proxy/mcp_server/test_mcp_auth_header_extraction.py index b652a6d457e..bb47c1fdfe3 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_auth_header_extraction.py +++ b/tests/unit/proxy/mcp_server/test_mcp_auth_header_extraction.py @@ -6,14 +6,15 @@ Tests the fixes for: 2. Case-insensitive matching for server-specific auth headers in _call_regular_mcp_tool """ -import pytest from unittest.mock import AsyncMock, MagicMock + +import pytest from starlette.datastructures import Headers -from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( +from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) -from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager +from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp import MCPAuth, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_auth_priority.py b/tests/unit/proxy/mcp_server/test_mcp_auth_priority.py similarity index 91% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_auth_priority.py rename to tests/unit/proxy/mcp_server/test_mcp_auth_priority.py index 21a89d7ffcc..675848b0869 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_auth_priority.py +++ b/tests/unit/proxy/mcp_server/test_mcp_auth_priority.py @@ -7,8 +7,9 @@ Validates that: """ import pytest -from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager -from litellm.types.mcp import MCPAuth, MCPTransport, MCPSpecVersion + +from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager +from litellm.types.mcp import MCPAuth, MCPSpecVersion, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -53,7 +54,7 @@ async def test_mcp_server_config_auth_value_header_used(token_key, config_only_m """ import httpx2 - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_block_recording.py b/tests/unit/proxy/mcp_server/test_mcp_block_recording.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_block_recording.py rename to tests/unit/proxy/mcp_server/test_mcp_block_recording.py index 746130fb892..c59c37b2f37 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_block_recording.py +++ b/tests/unit/proxy/mcp_server/test_mcp_block_recording.py @@ -1,6 +1,7 @@ -from litellm.proxy._experimental.mcp_server import operations as mcp_operations +from litellm.proxy.mcp_server import operations as mcp_operations + """Tests for guardrail-block recording in -``litellm.proxy._experimental.mcp_server.operations.call_mcp_tool``. +``litellm.proxy.mcp_server.operations.call_mcp_tool``. A pre-call MCP guardrail block *raises* into ``call_mcp_tool``'s ``except Exception``. The failure spend-log row that the Guardrails Monitor's @@ -34,7 +35,7 @@ from unittest import mock import pytest from fastapi import HTTPException -from litellm.proxy._experimental.mcp_server import server +from litellm.proxy.mcp_server import server class _RecordingLoggingObj: diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_chat_completions.py b/tests/unit/proxy/mcp_server/test_mcp_chat_completions.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_chat_completions.py rename to tests/unit/proxy/mcp_server/test_mcp_chat_completions.py index 32cd883c1f7..e5fd50e832e 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_chat_completions.py +++ b/tests/unit/proxy/mcp_server/test_mcp_chat_completions.py @@ -206,7 +206,7 @@ async def test_completion_mcp_with_streaming_no_timeout_error(monkeypatch): ) # Create a mock streaming response - from unittest.mock import MagicMock, AsyncMock + from unittest.mock import AsyncMock, MagicMock logging_obj = MagicMock() logging_obj.model_call_details = {} @@ -281,18 +281,18 @@ async def test_completion_mcp_with_streaming_no_timeout_error(monkeypatch): acompletion_calls = [] # Create mock streaming response for initial call - from unittest.mock import MagicMock, AsyncMock + from unittest.mock import AsyncMock, MagicMock logging_obj = MagicMock() logging_obj.model_call_details = {} logging_obj.async_failure_handler = AsyncMock() from litellm.types.utils import ( + ChatCompletionDeltaToolCall, + Delta, + Function, ModelResponseStream, StreamingChoices, - Delta, - ChatCompletionDeltaToolCall, - Function, ) # Create initial streaming chunks with tool_calls @@ -471,19 +471,19 @@ async def test_mcp_metadata_in_streaming_final_chunk(monkeypatch): from types import SimpleNamespace from unittest.mock import patch + from litellm.litellm_core_utils.litellm_logging import Logging from litellm.responses.mcp.litellm_proxy_mcp_handler import ( LiteLLM_Proxy_MCP_Handler, ) from litellm.responses.utils import ResponsesAPIRequestUtils - from litellm.utils import CustomStreamWrapper from litellm.types.utils import ( + ChatCompletionDeltaToolCall, + Delta, + Function, ModelResponseStream, StreamingChoices, - Delta, - ChatCompletionDeltaToolCall, - Function, ) - from litellm.litellm_core_utils.litellm_logging import Logging + from litellm.utils import CustomStreamWrapper dummy_tool = SimpleNamespace( name="local_search", @@ -568,7 +568,7 @@ async def test_mcp_metadata_in_streaming_final_chunk(monkeypatch): ] # Create a proper CustomStreamWrapper with logging_obj - from unittest.mock import MagicMock, AsyncMock + from unittest.mock import AsyncMock, MagicMock logging_obj = MagicMock() logging_obj.model_call_details = {} @@ -831,14 +831,14 @@ async def test_mcp_streaming_metadata_ordering(monkeypatch): LiteLLM_Proxy_MCP_Handler, ) from litellm.responses.utils import ResponsesAPIRequestUtils - from litellm.utils import CustomStreamWrapper from litellm.types.utils import ( + ChatCompletionDeltaToolCall, + Delta, + Function, ModelResponseStream, StreamingChoices, - Delta, - ChatCompletionDeltaToolCall, - Function, ) + from litellm.utils import CustomStreamWrapper dummy_tool = SimpleNamespace( name="local_search", @@ -923,7 +923,7 @@ async def test_mcp_streaming_metadata_ordering(monkeypatch): ] # Create a proper CustomStreamWrapper with logging_obj - from unittest.mock import MagicMock, AsyncMock + from unittest.mock import AsyncMock, MagicMock logging_obj = MagicMock() logging_obj.model_call_details = {} diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_client_unit.py b/tests/unit/proxy/mcp_server/test_mcp_client_unit.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_client_unit.py rename to tests/unit/proxy/mcp_server/test_mcp_client_unit.py index a270ea16a39..1f804f3b425 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_client_unit.py +++ b/tests/unit/proxy/mcp_server/test_mcp_client_unit.py @@ -3,22 +3,22 @@ Unit tests for the MCPClient class - critical functionality only. """ import base64 +from unittest.mock import ANY, AsyncMock, MagicMock, patch + import pytest -from unittest.mock import AsyncMock, MagicMock, patch, ANY - -# Add the project root to the path - -import litellm.experimental_mcp_client.client as mcp_client_module -from litellm.experimental_mcp_client.client import MCPClient -from litellm.types.mcp import MCPAuth, MCPTransport from mcp.types import CallToolResult as MCPCallToolResult from mcp.types import Implementation, InitializeResult, ListToolsResult, PaginatedRequestParams, ServerCapabilities from mcp.types import Tool as MCPTool +# Add the project root to the path +import litellm.mcp_client.client as mcp_client_module +from litellm.mcp_client.client import MCPClient +from litellm.types.mcp import MCPAuth, MCPTransport + def test_mcp_client_uses_configurable_default_timeout(): """MCPClient should use MCP_CLIENT_TIMEOUT constant when no timeout is passed.""" - with patch("litellm.experimental_mcp_client.client.MCP_CLIENT_TIMEOUT", 120.0): + with patch("litellm.mcp_client.client.MCP_CLIENT_TIMEOUT", 120.0): # Client reads constant at runtime when timeout is None client = MCPClient( server_url="http://example.com", diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_cost_calculator.py b/tests/unit/proxy/mcp_server/test_mcp_cost_calculator.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_cost_calculator.py rename to tests/unit/proxy/mcp_server/test_mcp_cost_calculator.py index 5357e0dce9e..368080f55a5 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_cost_calculator.py +++ b/tests/unit/proxy/mcp_server/test_mcp_cost_calculator.py @@ -6,8 +6,7 @@ import pytest from fastapi import Request from fastapi.testclient import TestClient - -from litellm.proxy._experimental.mcp_server.cost_calculator import MCPCostCalculator +from litellm.proxy.mcp_server.cost_calculator import MCPCostCalculator class TestMCPCostCalculator: diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_custom_fields.py b/tests/unit/proxy/mcp_server/test_mcp_custom_fields.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_custom_fields.py rename to tests/unit/proxy/mcp_server/test_mcp_custom_fields.py index e3437bf16f6..78dde8f75df 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_custom_fields.py +++ b/tests/unit/proxy/mcp_server/test_mcp_custom_fields.py @@ -4,15 +4,16 @@ Test suite for MCP server custom fields functionality. Tests that mcp_info can accept arbitrary custom fields in addition to predefined ones. """ -import pytest +from typing import Any, Dict from unittest.mock import Mock, patch -from typing import Dict, Any + +import pytest + +from litellm.proxy._types import LiteLLM_MCPServerTable # Add the path to find the modules - -from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager +from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp import MCPAuth -from litellm.proxy._types import LiteLLM_MCPServerTable class TestMCPCustomFields: diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_debug.py b/tests/unit/proxy/mcp_server/test_mcp_debug.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_debug.py rename to tests/unit/proxy/mcp_server/test_mcp_debug.py index ed1ae0bb4fe..4f88aaa1d67 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_debug.py +++ b/tests/unit/proxy/mcp_server/test_mcp_debug.py @@ -9,13 +9,13 @@ import httpx import pytest from starlette.types import Message -from litellm.proxy._experimental.mcp_server.mcp_debug import ( +from litellm.proxy.mcp_server.mcp_debug import ( MCP_DEBUG_REQUEST_HEADER, MCPAuthDiagnostics, MCPDebug, describe_upstream_http_failure, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import AuthResolution +from litellm.proxy.mcp_server.outbound_credentials.types import AuthResolution class TestIsDebugEnabled: @@ -290,7 +290,7 @@ def test_failure_log_omits_unstructured_body(): @pytest.mark.asyncio @pytest.mark.parametrize("mode", ["error", "empty", "large", "timeout", "read_failure", "closed", "success", "cancel"]) async def test_error_capture_is_bounded_and_preserves_success_and_cancellation(mode): - from litellm.proxy._experimental.mcp_server.mcp_debug import capture_upstream_error_response + from litellm.proxy.mcp_server.mcp_debug import capture_upstream_error_response class Stream(httpx.AsyncByteStream): def __init__(self): @@ -349,7 +349,7 @@ def test_failure_preview_handles_empty_scalar_control_and_long_bodies(body): @pytest.mark.asyncio @pytest.mark.parametrize("slow_error", [False, True]) async def test_error_capture_preserves_httpx_auth_retry(slow_error): - from litellm.proxy._experimental.mcp_server.mcp_debug import capture_upstream_error_response + from litellm.proxy.mcp_server.mcp_debug import capture_upstream_error_response class RetryAuth(httpx.Auth): def auth_flow(self, request): @@ -467,8 +467,8 @@ async def test_concurrent_mcp_messages_record_on_their_own_http_scope(_mcp_reque from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var - from litellm.proxy._experimental.mcp_server.mcp_debug import ( + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server.mcp_debug import ( MCP_AUTH_DIAGNOSTICS_SCOPE_KEY, record_auth_resolution, ) @@ -540,7 +540,8 @@ def test_oversized_request_omits_potentially_reflected_response_credentials(): @pytest.mark.asyncio async def test_streamed_error_redacts_reflected_credentials_before_capture(): import json - from litellm.proxy._experimental.mcp_server.mcp_debug import capture_upstream_error_response + + from litellm.proxy.mcp_server.mcp_debug import capture_upstream_error_response secret = "generic-credential-123" request = httpx.Request("POST", "https://upstream/token", data={"client_secret":secret}) @@ -566,7 +567,7 @@ def test_failure_diagnostics_omit_credential_bearing_url_paths(path): def test_deep_request_omits_response_when_credentials_cannot_be_inspected(): - from litellm.proxy._experimental.mcp_server.utils import MAX_STRUCTURED_CONTENT_SCAN_DEPTH + from litellm.proxy.mcp_server.utils import MAX_STRUCTURED_CONTENT_SCAN_DEPTH raw = "[" * (MAX_STRUCTURED_CONTENT_SCAN_DEPTH + 1) + '{"client_secret":"nested-credential"}' + "]" * (MAX_STRUCTURED_CONTENT_SCAN_DEPTH + 1) request = httpx.Request("POST", "https://upstream/token", content=raw, headers={"Content-Type": "application/json"}) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_discovery.py b/tests/unit/proxy/mcp_server/test_mcp_discovery.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_discovery.py rename to tests/unit/proxy/mcp_server/test_mcp_discovery.py index d35cb7234dc..35fc7440f99 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_discovery.py +++ b/tests/unit/proxy/mcp_server/test_mcp_discovery.py @@ -5,7 +5,6 @@ from typing import Final import pytest - class TestMCPRegistryFile: """Tests for the curated MCP registry JSON file.""" @@ -17,7 +16,6 @@ class TestMCPRegistryFile: "..", "..", "..", - "..", "litellm", "proxy", "mcp_registry.json", diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_elicitation_handler.py b/tests/unit/proxy/mcp_server/test_mcp_elicitation_handler.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_elicitation_handler.py rename to tests/unit/proxy/mcp_server/test_mcp_elicitation_handler.py index dd8dddf106e..08e3903ece4 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_elicitation_handler.py +++ b/tests/unit/proxy/mcp_server/test_mcp_elicitation_handler.py @@ -12,21 +12,20 @@ from types import SimpleNamespace from unittest.mock import AsyncMock import pytest - from mcp.types import ( + REQUEST_TIMEOUT, ClientCapabilities, ElicitationCapability, - FormElicitationCapability, - UrlElicitationCapability, - REQUEST_TIMEOUT, ElicitRequestFormParams, ElicitRequestURLParams, ElicitResult, ErrorData, + FormElicitationCapability, + UrlElicitationCapability, ) -from litellm.proxy._experimental.mcp_server import elicitation_handler -from litellm.proxy._experimental.mcp_server.elicitation_handler import ( +from litellm.proxy.mcp_server import elicitation_handler +from litellm.proxy.mcp_server.elicitation_handler import ( _relay_elicitation_to_downstream, handle_elicitation_request, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_env_vars.py b/tests/unit/proxy/mcp_server/test_mcp_env_vars.py similarity index 93% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_env_vars.py rename to tests/unit/proxy/mcp_server/test_mcp_env_vars.py index 807061c946f..57ac6c0be2d 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_env_vars.py +++ b/tests/unit/proxy/mcp_server/test_mcp_env_vars.py @@ -1,7 +1,7 @@ """Tests for MCP env-var interpolation utilities. These cover the pure helpers in -``litellm.proxy._experimental.mcp_server.utils`` and do not require a DB +``litellm.proxy.mcp_server.utils`` and do not require a DB connection. The DB-backed per-user flow is exercised in higher-level tests in tests/integration/mcp. """ @@ -12,8 +12,6 @@ from unittest.mock import AsyncMock import pytest from respx import MockRouter -from litellm.types.mcp_server.mcp_server_manager import MCPServer - # Look up these names lazily on every access. Tests in this directory call # ``importlib.reload`` on the utils module to exercise registration logic, # which replaces ``MCPMissingUserEnvVarsError`` with a freshly-constructed @@ -21,7 +19,8 @@ from litellm.types.mcp_server.mcp_server_manager import MCPServer # old class object and ``pytest.raises(_u("MCPMissingUserEnvVarsError"))`` would # stop matching the new class. Accessing the attribute through the module # always picks up the current version. -import litellm.proxy._experimental.mcp_server.utils as _mcp_utils +import litellm.proxy.mcp_server.utils as _mcp_utils +from litellm.types.mcp_server.mcp_server_manager import MCPServer def _u(name: str): @@ -191,7 +190,7 @@ def mock_server(): async def test_resolve_static_headers_interpolates_globals_and_user( mock_server, monkeypatch ): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -216,7 +215,7 @@ async def test_resolve_static_headers_interpolates_globals_and_user( async def test_resolve_static_headers_raises_when_user_vars_missing( mock_server, monkeypatch ): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -250,7 +249,7 @@ async def test_resolve_static_headers_rechecks_db_before_raising_412( MCPMissingUserEnvVarsError the resolver must re-read with force_refresh and honor the fresh DB values. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -288,7 +287,7 @@ async def test_resolve_static_headers_missing_is_non_blocking_for_listing( """With raise_on_missing=False (the tool-list path), missing per-user vars must NOT raise. Available vars interpolate; unfilled ${NAME} refs are left untouched so the server's tools still appear in the listing.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -317,7 +316,7 @@ async def test_resolve_static_headers_propagates_db_error_on_tool_call( ): """A DB failure on the tool-call path must surface as a real error, not be masked as a "missing credentials" MCPMissingUserEnvVarsError (412).""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -340,7 +339,7 @@ async def test_resolve_static_headers_swallows_db_error_on_listing( ): """On the listing path a DB failure is non-blocking: globals interpolate and unfilled per-user ${NAME} refs are left untouched.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -363,7 +362,7 @@ async def test_resolve_static_headers_swallows_db_error_on_listing( @pytest.mark.asyncio async def test_resolve_static_headers_passthrough_when_no_env_vars(): """Servers without env_vars should keep static_headers untouched.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -388,7 +387,7 @@ async def test_resolve_static_headers_unreferenced_user_var_is_not_blocking( """A per-user var declared by the admin but never referenced in static_headers must not block the request — only blocking-by-use is enforced.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -423,7 +422,7 @@ async def test_resolve_static_headers_stale_user_value_cannot_override_global( """A var that used to be user-scoped (so the user has a stored value) but is now global must resolve to the admin's global value, not the stale per-user row. Otherwise a user could override admin-configured headers indefinitely.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -460,7 +459,7 @@ async def test_resolve_static_headers_dual_scope_var_uses_global_without_412( global value (globals win in the merge), so the tool-call path must resolve it from the global instead of raising a 412 when the user hasn't filled it in. This happens during a global-to-user (or user-to-global) migration.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -504,7 +503,7 @@ async def test_resolve_static_headers_empty_global_does_not_cover_user_var( global carries no usable value, so the tool-call path still raises a 412 when the user hasn't supplied one, instead of silently interpolating an empty string into the header.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -543,7 +542,7 @@ async def test_resolve_static_headers_user_value_wins_over_empty_global( """When a global is empty, a value the user did supply must win the merge rather than being clobbered by the empty global. The header resolves to the user's value, not an empty string.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -603,7 +602,7 @@ def test_references_per_user_env_var(static_headers, env_vars, expected): """Only headers that actually reference a *per-user* var count: globals and declared-but-unreferenced user vars do not, since the userless probe can still resolve (or simply not need) them.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -624,7 +623,7 @@ def test_references_per_user_env_var(static_headers, env_vars, expected): async def test_health_check_reaches_servers_without_forwarding_per_user_env_vars( mock_server: MCPServer, monkeypatch: pytest.MonkeyPatch, respx_mock: MockRouter ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -650,7 +649,7 @@ async def test_health_check_reaches_servers_without_forwarding_per_user_env_vars @pytest.mark.asyncio async def test_load_user_env_vars_returns_empty_without_user(): """No user auth → no per-user lookup is attempted.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -667,7 +666,7 @@ async def test_load_user_env_vars_returns_empty_without_user_id(): """User auth without a user_id (e.g. anonymous virtual key) → empty dict.""" from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -689,7 +688,7 @@ async def test_load_user_env_vars_raises_when_db_unavailable(monkeypatch): satisfy (per-user env vars are unusable without a DB).""" from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -715,7 +714,7 @@ async def test_resolve_static_headers_db_unavailable_is_not_missing_412( was None, making a DB outage look like "user has no credentials".""" from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -736,8 +735,8 @@ async def test_load_user_env_vars_caches_within_ttl(env_vars_salt_key, monkeypat keeping the hot tool-call/tool-listing path off the DB.""" from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server import mcp_server_manager as mgr_mod - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server import mcp_server_manager as mgr_mod + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -773,8 +772,8 @@ async def test_load_user_env_vars_force_refresh_bypasses_cache( process-local stale value cannot mask credentials stored on another worker.""" from unittest.mock import AsyncMock, MagicMock - from litellm.proxy._experimental.mcp_server import mcp_server_manager as mgr_mod - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server import mcp_server_manager as mgr_mod + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -818,8 +817,8 @@ async def test_load_user_env_vars_invalidation_forces_refetch( instead of serving the stale cached value.""" from unittest.mock import AsyncMock, MagicMock - from litellm.proxy._experimental.mcp_server import mcp_server_manager as mgr_mod - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server import mcp_server_manager as mgr_mod + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, invalidate_user_env_vars_cache, ) @@ -973,7 +972,7 @@ def _transactional_env_vars_prisma(read_delay: float = 0.0): async def test_merge_user_env_vars_does_not_persist_plaintext(env_vars_salt_key): """The per-user write path must encrypt values at rest; ``values_b64`` must never hold plaintext personal credentials, but must still round-trip.""" - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( _decode_user_env_vars, merge_user_env_vars, ) @@ -997,7 +996,7 @@ async def test_merge_user_env_vars_does_not_persist_plaintext(env_vars_salt_key) async def test_get_user_env_vars_round_trip(env_vars_salt_key): from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server.db import get_user_env_vars + from litellm.proxy.mcp_server.db import get_user_env_vars payload = {"CORP_USERNAME": "alice", "CORP_PASSWORD": "s3cret"} row = MagicMock() @@ -1010,7 +1009,7 @@ async def test_get_user_env_vars_round_trip(env_vars_salt_key): @pytest.mark.asyncio async def test_get_user_env_vars_returns_empty_for_missing_row(): - from litellm.proxy._experimental.mcp_server.db import get_user_env_vars + from litellm.proxy.mcp_server.db import get_user_env_vars prisma = _mock_env_vars_prisma(row=None) assert await get_user_env_vars(prisma, "alice", "srv-1") == {} @@ -1020,7 +1019,7 @@ async def test_get_user_env_vars_returns_empty_for_missing_row(): async def test_get_user_env_vars_stringifies_non_string_json_values(env_vars_salt_key): from types import SimpleNamespace - from litellm.proxy._experimental.mcp_server.db import get_user_env_vars + from litellm.proxy.mcp_server.db import get_user_env_vars row: Final = SimpleNamespace(values_b64=_encrypted_user_env_blob({"PORT": 8080, "DEBUG": True, "EMPTY": None})) @@ -1036,8 +1035,8 @@ async def test_get_user_env_vars_stringifies_non_string_json_values(env_vars_sal async def test_get_user_env_vars_treats_a_blob_that_is_not_a_json_object_as_unset(env_vars_salt_key, stored_json): from types import SimpleNamespace - from litellm.proxy._experimental.mcp_server.db import get_user_env_vars from litellm.proxy.common_utils.encrypt_decrypt_utils import encrypt_value_helper + from litellm.proxy.mcp_server.db import get_user_env_vars row: Final = SimpleNamespace(values_b64=encrypt_value_helper(stored_json)) @@ -1054,8 +1053,8 @@ async def test_decode_user_env_vars_warns_when_undecryptable( credentials" 412 for values they already stored.""" from unittest.mock import MagicMock - import litellm.proxy._experimental.mcp_server.db as mcp_db - from litellm.proxy._experimental.mcp_server.db import _decode_user_env_vars + import litellm.proxy.mcp_server.db as mcp_db + from litellm.proxy.mcp_server.db import _decode_user_env_vars blob = _encrypted_user_env_blob({"CORP_PASSWORD": "s3cret"}) @@ -1071,7 +1070,7 @@ async def test_decode_user_env_vars_warns_when_undecryptable( async def test_get_user_env_vars_bulk_distributes_results(env_vars_salt_key): from unittest.mock import AsyncMock, MagicMock - from litellm.proxy._experimental.mcp_server.db import get_user_env_vars_bulk + from litellm.proxy.mcp_server.db import get_user_env_vars_bulk blob1 = _encrypted_user_env_blob({"A": "1"}) blob2 = _encrypted_user_env_blob({"B": "2"}) @@ -1091,7 +1090,7 @@ async def test_get_user_env_vars_bulk_distributes_results(env_vars_salt_key): @pytest.mark.asyncio async def test_get_user_env_vars_bulk_empty_ids_short_circuits(): - from litellm.proxy._experimental.mcp_server.db import get_user_env_vars_bulk + from litellm.proxy.mcp_server.db import get_user_env_vars_bulk prisma = _mock_env_vars_prisma() assert await get_user_env_vars_bulk(prisma, "alice", []) == {} @@ -1103,7 +1102,7 @@ async def test_get_user_env_vars_bulk_empty_ids_short_circuits(): async def test_delete_user_env_vars_is_idempotent_delete_many(): """Delete must use ``delete_many`` so a missing row is a no-op rather than raising RecordNotFound; real DB errors are left to propagate.""" - from litellm.proxy._experimental.mcp_server.db import delete_user_env_vars + from litellm.proxy.mcp_server.db import delete_user_env_vars prisma = _mock_env_vars_prisma() await delete_user_env_vars(prisma, "alice", "srv-1") @@ -1118,7 +1117,7 @@ async def test_merge_user_env_vars_preserves_existing_and_prunes_disallowed( ): """Merging one update keeps the user's other stored values and drops any name the admin no longer declares as user-scoped.""" - from litellm.proxy._experimental.mcp_server.db import merge_user_env_vars + from litellm.proxy.mcp_server.db import merge_user_env_vars prisma = _transactional_env_vars_prisma() await merge_user_env_vars( @@ -1149,7 +1148,7 @@ async def test_merge_user_env_vars_serializes_concurrent_writes(env_vars_salt_ke both distinct values survive.""" import asyncio - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( get_user_env_vars, merge_user_env_vars, ) @@ -1178,7 +1177,7 @@ async def test_merge_user_env_vars_acquires_lock_without_deserializing_void( from prisma.errors import RawQueryError - from litellm.proxy._experimental.mcp_server.db import merge_user_env_vars + from litellm.proxy.mcp_server.db import merge_user_env_vars class _Tx: def __init__(self): @@ -1231,7 +1230,7 @@ async def test_delete_mcp_server_removes_orphaned_user_env_vars(): it; there is no FK cascade, so skipping this leaves orphaned credentials.""" from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server.db import delete_mcp_server + from litellm.proxy.mcp_server.db import delete_mcp_server prisma = _mock_env_vars_prisma() prisma.db.litellm_mcpservertable.delete = AsyncMock(return_value=object()) @@ -1248,7 +1247,7 @@ async def test_delete_mcp_server_skips_env_var_cleanup_when_server_missing(): """A no-op delete (server not found) must not touch the env var table.""" from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server.db import delete_mcp_server + from litellm.proxy.mcp_server.db import delete_mcp_server prisma = _mock_env_vars_prisma() prisma.db.litellm_mcpservertable.delete = AsyncMock(return_value=None) @@ -1267,7 +1266,7 @@ async def test_delete_mcp_server_succeeds_when_orphan_cleanup_fails(): is already gone.""" from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server.db import delete_mcp_server + from litellm.proxy.mcp_server.db import delete_mcp_server deleted = object() prisma = _mock_env_vars_prisma() @@ -1289,7 +1288,7 @@ async def test_delete_mcp_server_removes_orphaned_user_credentials(): pointing at a now-missing server.""" from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server.db import delete_mcp_server + from litellm.proxy.mcp_server.db import delete_mcp_server prisma = _mock_env_vars_prisma() prisma.db.litellm_mcpservertable.delete = AsyncMock(return_value=object()) @@ -1306,7 +1305,7 @@ async def test_delete_mcp_server_skips_credential_cleanup_when_server_missing(): """A no-op delete (server not found) must not touch the credential table.""" from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server.db import delete_mcp_server + from litellm.proxy.mcp_server.db import delete_mcp_server prisma = _mock_env_vars_prisma() prisma.db.litellm_mcpservertable.delete = AsyncMock(return_value=None) @@ -1324,7 +1323,7 @@ async def test_delete_mcp_server_credential_cleanup_failure_still_cleans_env_var still succeed for the caller.""" from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server.db import delete_mcp_server + from litellm.proxy.mcp_server.db import delete_mcp_server deleted = object() prisma = _mock_env_vars_prisma() @@ -1361,11 +1360,11 @@ def test_prepare_mcp_server_data_encrypts_global_env_var_values(env_vars_salt_ke column, while ``scope="user"`` placeholders (not secrets) stay verbatim.""" import json - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy._types import MCPEnvVar + from litellm.proxy.mcp_server.db import ( _prepare_mcp_server_data, decrypt_global_env_var_values, ) - from litellm.proxy._types import MCPEnvVar req = _global_env_var_server_request( [ @@ -1400,8 +1399,8 @@ def test_prepare_mcp_server_data_skips_unset_env_vars_on_partial_update(): be written, even when the request object carries a non-None env_vars that was never marked as set. Otherwise a partial update could silently overwrite the stored values.""" - from litellm.proxy._experimental.mcp_server.db import _prepare_mcp_server_data from litellm.proxy._types import MCPEnvVar, UpdateMCPServerRequest + from litellm.proxy.mcp_server.db import _prepare_mcp_server_data data = UpdateMCPServerRequest.model_construct( _fields_set={"server_id"}, @@ -1420,8 +1419,8 @@ def test_prepare_mcp_server_data_writes_env_vars_when_set_on_partial_update( """A partial update that does set env_vars must serialize and encrypt them.""" import json - from litellm.proxy._experimental.mcp_server.db import _prepare_mcp_server_data from litellm.proxy._types import MCPEnvVar, UpdateMCPServerRequest + from litellm.proxy.mcp_server.db import _prepare_mcp_server_data data = UpdateMCPServerRequest( server_id="srv-1", @@ -1443,11 +1442,11 @@ async def test_build_mcp_server_from_table_decrypts_global_env_vars(env_vars_sal headers interpolate to the real secret instead of forwarding ciphertext.""" import json - from litellm.proxy._experimental.mcp_server.db import _prepare_mcp_server_data - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import LiteLLM_MCPServerTable, MCPEnvVar + from litellm.proxy.mcp_server.db import _prepare_mcp_server_data + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) - from litellm.proxy._types import LiteLLM_MCPServerTable, MCPEnvVar req = _global_env_var_server_request( [MCPEnvVar(name="DB_PASSWORD", value="s3cr3t-p@ss", scope="global")] @@ -1481,14 +1480,14 @@ async def test_add_server_does_not_double_decrypt_global_env_vars(env_vars_salt_ upstream instead of the interpolated secret.""" import json - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy._types import LiteLLM_MCPServerTable, MCPEnvVar + from litellm.proxy.mcp_server.db import ( _prepare_mcp_server_data, decrypt_global_env_var_values, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) - from litellm.proxy._types import LiteLLM_MCPServerTable, MCPEnvVar req = _global_env_var_server_request( [MCPEnvVar(name="DB_PASSWORD", value="s3cr3t-p@ss", scope="global")] @@ -1529,16 +1528,16 @@ async def test_create_mcp_server_decrypts_env_vars_when_prisma_returns_json_stri (timestamps match), so headers forward ciphertext upstream.""" from unittest.mock import AsyncMock, MagicMock - from litellm.proxy._experimental.mcp_server.db import ( - _prepare_mcp_server_data, - create_mcp_server, - update_mcp_server, - ) from litellm.proxy._types import ( MCPEnvVar, NewMCPServerRequest, UpdateMCPServerRequest, ) + from litellm.proxy.mcp_server.db import ( + _prepare_mcp_server_data, + create_mcp_server, + update_mcp_server, + ) req = _global_env_var_server_request( [MCPEnvVar(name="DB_PASSWORD", value="s3cr3t-p@ss", scope="global")] @@ -1598,11 +1597,11 @@ def test_reencrypt_global_env_var_values_handles_json_string(env_vars_salt_key): helper must parse it instead of failing on ``dict(v)`` over a string.""" import json - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy._types import MCPEnvVar + from litellm.proxy.mcp_server.db import ( _prepare_mcp_server_data, _reencrypt_global_env_var_values, ) - from litellm.proxy._types import MCPEnvVar req = _global_env_var_server_request( [MCPEnvVar(name="DB_PASSWORD", value="s3cr3t-p@ss", scope="global")] @@ -1630,11 +1629,11 @@ async def test_rotate_mcp_user_env_vars_logs_rotated_and_skipped_counts( left untouched and counted as skipped.""" from unittest.mock import AsyncMock, MagicMock - import litellm.proxy._experimental.mcp_server.db as mcp_db - from litellm.proxy._experimental.mcp_server.db import ( + import litellm.proxy.mcp_server.db as mcp_db + from litellm.proxy.common_utils.encrypt_decrypt_utils import encrypt_value_helper + from litellm.proxy.mcp_server.db import ( rotate_mcp_user_env_vars_master_key, ) - from litellm.proxy.common_utils.encrypt_decrypt_utils import encrypt_value_helper def _row(user_id, server_id, blob): row = MagicMock() @@ -1693,12 +1692,12 @@ def test_decrypt_global_env_var_drops_undecryptable_value( import json from unittest.mock import MagicMock - import litellm.proxy._experimental.mcp_server.db as mcp_db - from litellm.proxy._experimental.mcp_server.db import ( + import litellm.proxy.mcp_server.db as mcp_db + from litellm.proxy._types import MCPEnvVar + from litellm.proxy.mcp_server.db import ( _prepare_mcp_server_data, decrypt_global_env_var_values, ) - from litellm.proxy._types import MCPEnvVar req = _global_env_var_server_request( [MCPEnvVar(name="DB_PASSWORD", value="s3cr3t-p@ss", scope="global")] diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_guardrail_usage_monitor.py b/tests/unit/proxy/mcp_server/test_mcp_guardrail_usage_monitor.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_guardrail_usage_monitor.py rename to tests/unit/proxy/mcp_server/test_mcp_guardrail_usage_monitor.py index 8d5e36e9795..765771de633 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_guardrail_usage_monitor.py +++ b/tests/unit/proxy/mcp_server/test_mcp_guardrail_usage_monitor.py @@ -21,7 +21,7 @@ from unittest import mock import pytest from litellm.exceptions import GuardrailRaisedException -from litellm.proxy._experimental.mcp_server import mcp_server_manager as MOD +from litellm.proxy.mcp_server import mcp_server_manager as MOD class _FakeLoggingObj: diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_header_alias_utils.py b/tests/unit/proxy/mcp_server/test_mcp_header_alias_utils.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_header_alias_utils.py rename to tests/unit/proxy/mcp_server/test_mcp_header_alias_utils.py index 6c24205c258..80c79505205 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_header_alias_utils.py +++ b/tests/unit/proxy/mcp_server/test_mcp_header_alias_utils.py @@ -1,6 +1,6 @@ """Tests for MCP header alias sanitization and auth header lookup.""" -from litellm.proxy._experimental.mcp_server.utils import ( +from litellm.proxy.mcp_server.utils import ( lookup_mcp_server_auth_in_headers, sanitize_mcp_alias_for_header, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_hook_extra_headers.py b/tests/unit/proxy/mcp_server/test_mcp_hook_extra_headers.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_hook_extra_headers.py rename to tests/unit/proxy/mcp_server/test_mcp_hook_extra_headers.py index c477a8d34cb..d0cf0199233 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_hook_extra_headers.py +++ b/tests/unit/proxy/mcp_server/test_mcp_hook_extra_headers.py @@ -19,8 +19,8 @@ from unittest.mock import AsyncMock, MagicMock, patch import pytest from mcp.types import CallToolResult -from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy.utils import ProxyLogging from litellm.types.mcp import MCPAuth, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -412,7 +412,7 @@ class TestCallToolFlowsHookHeaders: new_callable=AsyncMock, return_value=CallToolResult(content=[], isError=False), ): - import litellm.proxy._experimental.mcp_server.mcp_server_manager as mgr_mod + import litellm.proxy.mcp_server.mcp_server_manager as mgr_mod proxy_logging = MagicMock(spec=ProxyLogging) @@ -1059,7 +1059,7 @@ class TestOpenApiByokCallTool: @pytest.mark.asyncio async def test_call_tool_openapi_byok_injects_request_auth_contextvar(self): """Playground/responses call call_tool directly; BYOK must reach OpenAPI handlers.""" - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( request_auth_header, ) @@ -1083,7 +1083,7 @@ class TestOpenApiByokCallTool: with patch.object(manager, "_resolve_mcp_server_for_tool_call", return_value=server): with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager._resolve_byok_mcp_auth_header", + "litellm.proxy.mcp_server.mcp_server_manager._resolve_byok_mcp_auth_header", new=AsyncMock(return_value="fc-test-key"), ): with patch.object( @@ -1113,21 +1113,21 @@ class TestFormatByokOpenapiAuthHeader: ) def test_api_key_auth_type(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _format_byok_openapi_auth_header, ) assert _format_byok_openapi_auth_header(self._server(MCPAuth.api_key), "secret") == "ApiKey secret" def test_basic_auth_type(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _format_byok_openapi_auth_header, ) assert _format_byok_openapi_auth_header(self._server(MCPAuth.basic), "secret") == "Basic secret" def test_defaults_to_bearer(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _format_byok_openapi_auth_header, ) @@ -1146,7 +1146,7 @@ class TestOpenapiForwardedExtraHeaders: ) def test_returns_none_without_extra_headers_config(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _openapi_forwarded_extra_headers, ) @@ -1154,7 +1154,7 @@ class TestOpenapiForwardedExtraHeaders: assert _openapi_forwarded_extra_headers(server, {"X-Custom": "v"}, None) is None def test_returns_none_without_raw_headers(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _openapi_forwarded_extra_headers, ) @@ -1162,7 +1162,7 @@ class TestOpenapiForwardedExtraHeaders: assert _openapi_forwarded_extra_headers(server, None, None) is None def test_forwards_configured_header_case_insensitively(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _openapi_forwarded_extra_headers, ) @@ -1171,7 +1171,7 @@ class TestOpenapiForwardedExtraHeaders: assert result == {"X-Custom": "v"} def test_returns_none_when_no_configured_header_is_present(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _openapi_forwarded_extra_headers, ) @@ -1179,7 +1179,7 @@ class TestOpenapiForwardedExtraHeaders: assert _openapi_forwarded_extra_headers(server, {"x-custom": "v"}, None) is None def test_skips_authorization_when_caller_header_must_be_stripped(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _openapi_forwarded_extra_headers, ) @@ -1189,7 +1189,7 @@ class TestOpenapiForwardedExtraHeaders: assert result is None def test_skips_non_string_header_entries(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _openapi_forwarded_extra_headers, ) @@ -1212,7 +1212,7 @@ class TestResolveByokMcpAuthHeader: @pytest.mark.asyncio async def test_non_byok_server_passes_header_through_unchanged(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _resolve_byok_mcp_auth_header, ) @@ -1222,7 +1222,7 @@ class TestResolveByokMcpAuthHeader: @pytest.mark.asyncio async def test_byok_server_uses_stored_credential_when_no_header_supplied(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _resolve_byok_mcp_auth_header, ) @@ -1230,7 +1230,7 @@ class TestResolveByokMcpAuthHeader: user_auth = UserAPIKeyAuth(user_id="user-1", api_key="sk-dashboard") with patch( - "litellm.proxy._experimental.mcp_server.operations._get_byok_credential", + "litellm.proxy.mcp_server.operations._get_byok_credential", new=AsyncMock(return_value="stored-cred"), ): result = await _resolve_byok_mcp_auth_header(server, user_auth, None) @@ -1241,7 +1241,7 @@ class TestResolveByokMcpAuthHeader: async def test_byok_server_raises_401_when_no_credential_stored(self, monkeypatch): from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _resolve_byok_mcp_auth_header, ) @@ -1250,7 +1250,7 @@ class TestResolveByokMcpAuthHeader: user_auth = UserAPIKeyAuth(user_id="user-1", api_key="sk-dashboard") with patch( - "litellm.proxy._experimental.mcp_server.operations._get_byok_credential", + "litellm.proxy.mcp_server.operations._get_byok_credential", new=AsyncMock(return_value=None), ): with pytest.raises(HTTPException) as exc_info: @@ -1264,7 +1264,7 @@ class TestResolveByokMcpAuthHeader: @pytest.mark.asyncio async def test_byok_server_checks_credential_and_keeps_caller_header_when_supplied(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _resolve_byok_mcp_auth_header, ) @@ -1273,7 +1273,7 @@ class TestResolveByokMcpAuthHeader: check_mock = AsyncMock(return_value=None) with patch( - "litellm.proxy._experimental.mcp_server.operations._check_byok_credential", + "litellm.proxy.mcp_server.operations._check_byok_credential", new=check_mock, ): result = await _resolve_byok_mcp_auth_header(server, user_auth, "caller-header") @@ -1304,13 +1304,13 @@ class TestOpenApiResolvedUpstreamAuth: async def test_call_tool_openapi_injects_v2_resolved_token_contextvar(self): """The managed spec_path arm resolves the v2 credential and sets the ContextVar; kills the mutant that drops the resolve_openapi_upstream_auth call in call_tool.""" - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( request_resolved_auth_headers, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok manager = MCPServerManager() server = self._oauth_server() diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_logging.py b/tests/unit/proxy/mcp_server/test_mcp_logging.py similarity index 95% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_logging.py rename to tests/unit/proxy/mcp_server/test_mcp_logging.py index 44ba40afdd1..9548135b530 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_logging.py +++ b/tests/unit/proxy/mcp_server/test_mcp_logging.py @@ -11,14 +11,14 @@ from mcp.types import Tool as MCPTool import litellm from litellm.integrations.custom_logger import CustomLogger -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( +from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth +from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) -from litellm.proxy._experimental.mcp_server.server import ( +from litellm.proxy.mcp_server.server import ( mcp_server_tool_call, set_auth_context, ) -from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth from litellm.types.mcp import MCPPostCallResponseObject @@ -111,7 +111,7 @@ async def test_mcp_cost_tracking(): local_mcp_server_manager = MCPServerManager() with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Load the server config @@ -138,11 +138,11 @@ async def test_mcp_cost_tracking(): # Patch the global manager in both modules where it's used with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", local_mcp_server_manager, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", local_mcp_server_manager, ), ): @@ -244,7 +244,7 @@ async def test_mcp_cost_tracking_per_tool(): local_mcp_server_manager = MCPServerManager() with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Load the server config with per-tool costs @@ -289,11 +289,11 @@ async def test_mcp_cost_tracking_per_tool(): # Patch the global manager in both modules where it's used with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", local_mcp_server_manager, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", local_mcp_server_manager, ), ): @@ -417,7 +417,7 @@ async def test_mcp_tool_call_hook(): local_mcp_server_manager = MCPServerManager() with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Load the server config @@ -447,11 +447,11 @@ async def test_mcp_tool_call_hook(): # Patch the global manager in both modules where it's used with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", local_mcp_server_manager, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", local_mcp_server_manager, ), ): diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_max_concurrent_requests.py b/tests/unit/proxy/mcp_server/test_mcp_max_concurrent_requests.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_max_concurrent_requests.py rename to tests/unit/proxy/mcp_server/test_mcp_max_concurrent_requests.py index 8497d7bb7c4..f1896757874 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_max_concurrent_requests.py +++ b/tests/unit/proxy/mcp_server/test_mcp_max_concurrent_requests.py @@ -2,16 +2,16 @@ import asyncio from collections.abc import Awaitable, Callable from typing import Dict, Final, Optional, TypeVar, cast from unittest.mock import AsyncMock, patch + +import pytest from mcp import ClientSession from mcp.server.context import ServerRequestContext from mcp.types import CallToolRequestParams as MCPCallToolRequestParams -from litellm.experimental_mcp_client.client import MCPClient, PersistentMCPSession -from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var - -import pytest from mcp.types import CallToolResult, TextContent -from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager +from litellm.mcp_client.client import MCPClient, PersistentMCPSession +from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var +from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp import MCPAuth, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_metadata_preservation.py b/tests/unit/proxy/mcp_server/test_mcp_metadata_preservation.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_metadata_preservation.py rename to tests/unit/proxy/mcp_server/test_mcp_metadata_preservation.py index 86748d99063..118a4a9f17b 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_metadata_preservation.py +++ b/tests/unit/proxy/mcp_server/test_mcp_metadata_preservation.py @@ -9,11 +9,10 @@ which is critical for ChatGPT UI widget rendering. import pytest # Add the parent directory to the path so we can import litellm - from mcp.types import Tool as MCPTool -from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import MCPTransport +from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp_server.mcp_server_manager import MCPServer diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough.py b/tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough.py rename to tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough.py index 1c59b7b87e0..80b4ea3c287 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough.py +++ b/tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough.py @@ -15,15 +15,13 @@ import httpx import pytest from fastapi import HTTPException, Request - - -from litellm.proxy._experimental.mcp_server import discoverable_endpoints -from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( +from litellm.proxy._types import MCPTransport +from litellm.proxy.mcp_server import discoverable_endpoints +from litellm.proxy.mcp_server.discoverable_endpoints import ( _OAUTH_METADATA_CACHE, _OAUTH_METADATA_FETCH_LOCKS, _build_oauth_protected_resource_response, ) -from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -32,7 +30,7 @@ from litellm.types.mcp_server.mcp_server_manager import MCPServer def _mock_mcp_client_ip(): """Bypass IP-based access control in tests.""" with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", return_value=None, ): yield @@ -208,7 +206,7 @@ def test_is_oauth_passthrough_false_when_only_delegate_auth_to_upstream_set(): @pytest.mark.asyncio async def test_oauth_protected_resource_passthrough_proxies_upstream_metadata(): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -253,7 +251,7 @@ async def test_oauth_protected_resource_passthrough_proxies_upstream_metadata(): @pytest.mark.asyncio async def test_oauth_protected_resource_passthrough_cache_hit(): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -380,7 +378,7 @@ async def test_oauth_metadata_cache_expired_entry_is_refetched(): @pytest.mark.asyncio async def test_oauth_protected_resource_passthrough_network_error_returns_502(): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -444,7 +442,7 @@ async def test_oauth_protected_resource_gateway_managed_unchanged(): never fetch upstream metadata. Since LIT-4864 the advertised document is the gateway's own aggregate authorization server ({base}/mcp), which serves the keyless DCR flow for per-server URLs; the per-server relay endpoints remain for the keyed flow.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -505,7 +503,7 @@ async def test_oauth_protected_resource_oauth_delegate_returns_upstream_metadata gateway would make a strict IdP refuse to mint it or the upstream reject it. A regression that dropped oauth_delegate from the pass-through predicate would fall through to the gateway-AS branch and advertise LiteLLM as the AS.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -543,7 +541,7 @@ async def test_oauth_protected_resource_true_passthrough_returns_upstream_metada resource included, so the client treats the upstream as the resource and authorizes directly against it. A regression that rewrote resource (the gateway-proxied behavior) would break the transparent-proxy contract.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -582,7 +580,7 @@ async def test_oauth_protected_resource_dcr_bridge_returns_gateway_facade(auth_t facade: resource is the gateway URL the client dialed and authorization_servers names the gateway's per-server AS, so DCR-only clients (which enforce the RFC 9728 resource match) can register and sign in through the gateway. No upstream metadata fetch happens.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough_cold_start.py b/tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough_cold_start.py similarity index 90% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough_cold_start.py rename to tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough_cold_start.py index 67663448d65..3f6a44b0300 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough_cold_start.py +++ b/tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough_cold_start.py @@ -3,7 +3,6 @@ import pytest - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -40,11 +39,11 @@ def test_passthrough_cold_start_emits_401_with_matching_resource_metadata( route, expected_metadata_path ): """No auth headers on a passthrough server route emits matching metadata.""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( _is_mcp_passthrough_cold_start, _parse_mcp_server_names_from_path, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -93,10 +92,10 @@ def test_passthrough_cold_start_emits_401_with_matching_resource_metadata( def test_is_mcp_passthrough_cold_start_false_for_oauth2_server(): """Gateway-managed OAuth2 servers must not trigger the cold-start bypass.""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( _is_mcp_passthrough_cold_start, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -122,7 +121,7 @@ def test_is_mcp_passthrough_cold_start_false_for_oauth2_server(): def test_is_mcp_passthrough_cold_start_false_for_empty_servers(): """Aggregate /mcp route (no server list) must not trigger bypass.""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( _is_mcp_passthrough_cold_start, ) @@ -147,7 +146,7 @@ def test_is_mcp_passthrough_cold_start_false_for_empty_servers(): ], ) def test_parse_mcp_server_names_from_path(path, expected): - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( _parse_mcp_server_names_from_path, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough_tools.py b/tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough_tools.py similarity index 83% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough_tools.py rename to tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough_tools.py index b0d53f9c93b..03a7373c908 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough_tools.py +++ b/tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough_tools.py @@ -1,30 +1,30 @@ -from litellm.proxy._experimental.mcp_server import operations as mcp_operations +from litellm.proxy.mcp_server import operations as mcp_operations """Unit tests for MCP OAuth passthrough tool-fetch behavior.""" import asyncio import logging import sys +from typing import Final from unittest.mock import AsyncMock, MagicMock import httpx import pytest - if sys.version_info < (3, 11): from exceptiongroup import ExceptionGroup -from litellm.proxy._experimental.mcp_server.exceptions import ( +from litellm.proxy._types import MCPTransport +from litellm.proxy.mcp_server.exceptions import ( TOKEN_EXCHANGE_SUBJECT_ERROR, MCPServerListError, MCPUpstreamAuthError, ) -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( +from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, _extract_upstream_auth_failure, ) -from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -340,8 +340,8 @@ async def test_aggregate_list_tools_absorbs_one_unauthenticated_server(): from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server import server as mcp_server from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server import server as mcp_server delegate = _http_server( "s1", "delegate_docs", auth_type=MCPAuth.oauth2, delegate_auth_to_upstream=True @@ -383,9 +383,9 @@ async def test_single_server_route_also_absorbs_upstream_auth_error(): re-auth surfacing is handled by a request-scope preemptive check, tracked separately.""" from unittest.mock import patch - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.mcp_context import mcp_gateway_server_name from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.mcp_context import mcp_gateway_server_name delegate = _http_server( "s1", "delegate_docs", auth_type=MCPAuth.oauth2, delegate_auth_to_upstream=True @@ -424,8 +424,8 @@ async def test_aggregate_with_single_accessible_server_still_absorbs(): permission sets.""" from unittest.mock import patch - from litellm.proxy._experimental.mcp_server import server as mcp_server from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server import server as mcp_server delegate = _http_server( "s1", "delegate_docs", auth_type=MCPAuth.oauth2, delegate_auth_to_upstream=True @@ -505,7 +505,7 @@ async def test_client_creation_failure_logs_sanitized_exchange(monkeypatch, capl ], ) def test_passthrough_admission_recognizes_only_matching_authorization(oauth_headers, server_headers, authorized): - from litellm.proxy._experimental.mcp_server.operations import _client_has_passthrough_authorization + from litellm.proxy.mcp_server.operations import _client_has_passthrough_authorization from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -527,16 +527,16 @@ def test_managed_step_up_challenge_uses_only_the_gateway_metadata(base_url, requ @pytest.mark.asyncio async def test_scope_challenge_replaces_pending_stream_headers_once(): - from litellm.proxy._experimental.mcp_server.scope_challenge import OAuthScopeResponse + from litellm.proxy.mcp_server.scope_challenge import OAuthScopeResponse send = AsyncMock() response = OAuthScopeResponse(send, "https://gateway.example", "/docs/mcp") - await response({"type": "http.response.start", "status": 200, "headers": []}) + headers: Final = asyncio.create_task(response({"type": "http.response.start", "status": 200, "headers": []})) body = asyncio.create_task(response({"type": "http.response.body", "body": b"event: message\n"})) await asyncio.sleep(0) send.assert_not_awaited() response.deny(MCPUpstreamAuthError(403, None, "docs", required_scope="tools.write")) - await asyncio.wait_for(body, 1) + await asyncio.wait_for(asyncio.gather(headers, body), 1) await response({"type": "http.response.body", "body": b"private tool error"}) assert send.await_count == 2 start, result = [call.args[0] for call in send.await_args_list] @@ -553,21 +553,20 @@ async def test_scope_authorization_releases_progress_without_waiting_for_tool_re from mcp.server.context import ServerRequestContext from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var - from litellm.proxy._experimental.mcp_server.scope_challenge import ( + from litellm.proxy.mcp_server.legacy_callbacks import get_scope_response, record_upstream_tool_authorization + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server.scope_challenge import ( SCOPE_RESPONSE_KEY, OAuthScopeResponse, ) - from litellm.proxy._experimental.mcp_server.legacy_callbacks import get_scope_response, record_upstream_tool_authorization - send = AsyncMock() gate = OAuthScopeResponse(send, "https://gateway.example", "/mcp/docs") request = Request({"type": "http", SCOPE_RESPONSE_KEY: gate}) context = ServerRequestContext(session=MagicMock(), lifespan_context={}, protocol_version="2025-11-25", method="tools/call", request=request) token = active_mcp_request_ctx_var.set(context) try: - await gate({"type": "http.response.start", "status": 200, "headers": []}) + headers: Final = asyncio.create_task(gate({"type": "http.response.start", "status": 200, "headers": []})) progress = asyncio.create_task(gate({"type": "http.response.body", "body": b"progress", "more_body": True})) await asyncio.sleep(0) for method, status in [("initialize", 200), ("tools/list", 200), ("tools/call", 403)]: @@ -577,12 +576,12 @@ async def test_scope_authorization_releases_progress_without_waiting_for_tool_re await record_upstream_tool_authorization(httpx2.Response(200, request=unread), pending=get_scope_response()) assert gate.pending # Use the actual HTTP response hook contract, before reading the tool response body. - from litellm.experimental_mcp_client.client import MCPClient + from litellm.mcp_client.client import MCPClient upstream = MCPClient(server_url="https://upstream.example/mcp") async with upstream._create_httpx_client_factory(transport=httpx2.MockTransport(lambda request: httpx2.Response(200, content=b"tool result")))() as client: async with client.stream("POST", "https://upstream.example/mcp", json={"method": "tools/call"}): - await asyncio.wait_for(progress, 1) + await asyncio.wait_for(asyncio.gather(headers, progress), 1) assert send.await_args_list[-1].args[0]["body"] == b"progress" gate.deny(MCPUpstreamAuthError(403, None, "docs", required_scope="tools.write")) await gate({"type": "http.response.body", "body": b"result"}) @@ -594,26 +593,110 @@ async def test_scope_authorization_releases_progress_without_waiting_for_tool_re @pytest.mark.asyncio @pytest.mark.parametrize("failure", [ValueError, asyncio.CancelledError]) -async def test_scope_middleware_releases_waiting_response_on_validation_or_cancellation(failure): +@pytest.mark.parametrize("fail_send", [False, True]) +async def test_scope_middleware_releases_waiting_response_on_validation_or_cancellation( + failure: type[BaseException], fail_send: bool, +) -> None: from mcp.server.context import ServerRequestContext from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse, finish_scope_response + from litellm.proxy.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse, finish_scope_response - send = AsyncMock() - gate = OAuthScopeResponse(send, "https://gateway.example", "/mcp/docs") - context = ServerRequestContext(session=MagicMock(), lifespan_context={}, protocol_version="2025-11-25", method="tools/call", request=Request({"type": "http", SCOPE_RESPONSE_KEY: gate})) + send: Final = AsyncMock(side_effect=BrokenPipeError("peer disconnected") if fail_send else None) + gate: Final = OAuthScopeResponse(send, "https://gateway.example", "/mcp/docs") + context: Final = ServerRequestContext(session=MagicMock(), lifespan_context={}, protocol_version="2025-11-25", method="tools/call", request=Request({"type": "http", SCOPE_RESPONSE_KEY: gate})) + headers: Final = asyncio.create_task(gate({"type": "http.response.start", "status": 200, "headers": []})) + await asyncio.sleep(0) with pytest.raises(failure): await finish_scope_response(context, AsyncMock(side_effect=failure)) - await gate({"type": "http.response.start", "status": 200, "headers": []}) + if fail_send: + with pytest.raises(BrokenPipeError, match="peer disconnected"): + await headers + else: + await headers await gate({"type": "http.response.body", "body": b"error"}) assert not gate.pending - assert send.await_args_list[-1].args[0]["body"] == b"error" + assert send.await_args_list[-1].args[0]["type"] == ("http.response.start" if fail_send else "http.response.body") + + +@pytest.mark.asyncio +@pytest.mark.parametrize("fail_send", [False, True]) +async def test_scope_transport_owns_header_send_cancellation_and_errors(fail_send: bool) -> None: + import httpx2 + from starlette.types import Message + + from litellm.proxy.mcp_server.legacy_callbacks import record_upstream_tool_authorization + from litellm.proxy.mcp_server.scope_challenge import OAuthScopeResponse + + send_started: Final = asyncio.Event() + send_stopped: Final = asyncio.Event() + writable: Final = asyncio.Event() + sent: Final[list[Message]] = [] + + async def send(message: Message) -> None: + sent.append(message) + assert message["type"] == "http.response.start" + send_started.set() + try: + if fail_send: + raise BrokenPipeError("peer disconnected") + await writable.wait() + finally: + send_stopped.set() + + gate: Final = OAuthScopeResponse(send, "https://gateway.example", "/mcp/docs") + headers: Final = asyncio.create_task(gate({"type": "http.response.start", "status": 200, "headers": []})) + body: Final = asyncio.create_task(gate({"type": "http.response.body", "body": b"result"})) + await asyncio.sleep(0) + assert not send_started.is_set() + response: Final = httpx2.Response(200, request=httpx2.Request( + "POST", "https://upstream.example/mcp", json={"method": "tools/call"}, + )) + try: + await record_upstream_tool_authorization(response, pending=gate) + await send_started.wait() + if fail_send: + with pytest.raises(BrokenPipeError, match="peer disconnected"): + await headers + else: + headers.cancel() + with pytest.raises(asyncio.CancelledError): + await headers + await body + assert len(sent) == 1 + assert send_stopped.is_set() + finally: + writable.set() + await send_stopped.wait() + + +@pytest.mark.asyncio +@pytest.mark.parametrize("allowed_before_start", [False, True]) +async def test_scope_authorization_sends_stream_headers_before_the_first_body_chunk(allowed_before_start: bool) -> None: + from starlette.types import Message + + from litellm.proxy.mcp_server.scope_challenge import OAuthScopeResponse + + send: Final = AsyncMock() + gate: Final = OAuthScopeResponse(send, "https://gateway.example", "/mcp/docs") + start: Final[Message] = {"type": "http.response.start", "status": 200, "headers": [(b"content-type", b"text/event-stream")]} + if allowed_before_start: + gate.allow() + headers: Final = asyncio.create_task(gate(start)) + await asyncio.sleep(0) + if not allowed_before_start: + send.assert_not_awaited() + gate.allow() + await headers + send.assert_awaited_once_with(start) + await gate({"type": "http.response.body", "body": b"event: message\n", "more_body": True}) + assert send.await_args_list[-1].args[0]["body"] == b"event: message\n" + assert send.await_count == 2 @pytest.mark.asyncio async def test_scope_response_preserves_transport_validation_errors(): - from litellm.proxy._experimental.mcp_server.scope_challenge import OAuthScopeResponse + from litellm.proxy.mcp_server.scope_challenge import OAuthScopeResponse send = AsyncMock() gate = OAuthScopeResponse(send, "https://gateway.example", "/mcp/docs") @@ -633,9 +716,9 @@ async def test_streamable_sdk_relays_scope_challenge_before_committing_http_resp from mcp.server.streamable_http_manager import StreamableHTTPSessionManager from mcp.types import CallToolResult, TextContent - from litellm.proxy._experimental.mcp_server.legacy_callbacks import get_scope_response - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var - from litellm.proxy._experimental.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse, finish_scope_response + from litellm.proxy.mcp_server.legacy_callbacks import get_scope_response + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse, finish_scope_response async def call_tool(context, params): token = active_mcp_request_ctx_var.set(context) @@ -687,9 +770,9 @@ async def test_scope_challenges_are_isolated_between_concurrent_requests(): from mcp.server.context import ServerRequestContext from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.legacy_callbacks import get_scope_response, record_upstream_tool_authorization - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var - from litellm.proxy._experimental.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse + from litellm.proxy.mcp_server.legacy_callbacks import get_scope_response, record_upstream_tool_authorization + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse async def request_scope(denied): send = AsyncMock() @@ -697,13 +780,14 @@ async def test_scope_challenges_are_isolated_between_concurrent_requests(): context = ServerRequestContext(session=MagicMock(), lifespan_context={}, protocol_version="2025-11-25", method="tools/call", request=Request({"type": "http", SCOPE_RESPONSE_KEY: gate})) token = active_mcp_request_ctx_var.set(context) try: - await gate({"type": "http.response.start", "status": 200, "headers": []}) + headers: Final = asyncio.create_task(gate({"type": "http.response.start", "status": 200, "headers": []})) await asyncio.sleep(0) assert get_scope_response() is gate if denied: gate.deny(MCPUpstreamAuthError(403, None, "docs", required_scope="tools.write")) else: await record_upstream_tool_authorization(httpx2.Response(200, request=httpx2.Request("POST", "https://upstream.example/mcp", json={"method": "tools/call"})), pending=get_scope_response()) + await headers await gate({"type": "http.response.body", "body": b"done"}) return send.await_args_list[0].args[0]["status"] finally: @@ -715,7 +799,7 @@ async def test_scope_challenges_are_isolated_between_concurrent_requests(): @pytest.mark.parametrize("body", [b"", b"{", b"[]", b'{"method":"initialize"}']) def test_non_tool_payloads_do_not_hold_response_headers(body): - from litellm.proxy._experimental.mcp_server.scope_challenge import is_tool_call_request, scope_response_from_request + from litellm.proxy.mcp_server.scope_challenge import is_tool_call_request, scope_response_from_request assert not is_tool_call_request(body) assert scope_response_from_request(None) is None @@ -726,7 +810,7 @@ async def test_scope_middleware_preserves_non_http_requests(): from mcp.server.context import ServerRequestContext from mcp.types import CallToolResult, TextContent - from litellm.proxy._experimental.mcp_server.scope_challenge import finish_scope_response + from litellm.proxy.mcp_server.scope_challenge import finish_scope_response context = ServerRequestContext(session=MagicMock(), lifespan_context={}, protocol_version="2025-11-25", method="tools/call") async def call_next(request): @@ -738,9 +822,10 @@ async def test_scope_middleware_preserves_non_http_requests(): @pytest.mark.parametrize("path", ["/mcp", "/toolset/demo/mcp"]) def test_managed_step_up_metadata_matches_the_sdk_configured_resource(path): - from mcp.shared.auth_utils import check_resource_allowed from urllib.parse import urlsplit + from mcp.shared.auth_utils import check_resource_allowed + error = MCPUpstreamAuthError(403, None, "docs", required_scope="tools.write") response = error.to_http_exception("https://gateway.test", path) challenge = response.headers["www-authenticate"] diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_partial_update.py b/tests/unit/proxy/mcp_server/test_mcp_partial_update.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_partial_update.py rename to tests/unit/proxy/mcp_server/test_mcp_partial_update.py index d6894979906..8e24e4fca80 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_partial_update.py +++ b/tests/unit/proxy/mcp_server/test_mcp_partial_update.py @@ -12,16 +12,16 @@ import json from unittest.mock import AsyncMock, MagicMock import pytest -from prisma import Json, models from fastapi import HTTPException +from prisma import Json, models -from litellm.proxy._experimental.mcp_server.db import ( +from litellm.proxy._types import NewMCPServerRequest, UpdateMCPServerRequest +from litellm.proxy.mcp_server.db import ( create_mcp_server, decrypt_credentials, set_mcp_server_pinned_tools, update_mcp_server, ) -from litellm.proxy._types import NewMCPServerRequest, UpdateMCPServerRequest from litellm.types.mcp_server.mcp_server_manager import PinnedMCPTool @@ -883,7 +883,7 @@ def _mock_toolset_prisma(): async def _run_toolset_update(payload: dict) -> dict: """The columns PUT /v1/mcp/toolset writes for this payload, minus the audit stamp every write carries. The prisma double is injected, so nothing is patched.""" - from litellm.proxy._experimental.mcp_server.toolset_db import update_mcp_toolset + from litellm.proxy.mcp_server.toolset_db import update_mcp_toolset from litellm.types.mcp_server.mcp_toolset import UpdateMCPToolsetRequest mock_prisma = _mock_toolset_prisma() @@ -943,7 +943,7 @@ async def test_find_identifier_conflict_reports_alias_hit(): Case-insensitive and cross-field matching is exercised end to end against real Postgres by test_duplicate_alias_is_rejected_so_tool_prefixes_cannot_collide. """ - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( find_mcp_server_identifier_conflict, ) @@ -964,7 +964,7 @@ async def test_find_identifier_conflict_reports_alias_hit(): async def test_find_identifier_conflict_reports_server_name_when_alias_is_free(): """alias is checked first so the reported field is deterministic; a clean alias does not mask a colliding server_name.""" - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( find_mcp_server_identifier_conflict, ) @@ -981,7 +981,7 @@ async def test_find_identifier_conflict_reports_server_name_when_alias_is_free() @pytest.mark.asyncio async def test_find_identifier_conflict_returns_none_when_free(): - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( find_mcp_server_identifier_conflict, ) @@ -994,7 +994,7 @@ async def test_find_identifier_conflict_returns_none_when_free(): @pytest.mark.asyncio async def test_update_writing_alias_returns_conflict_instead_of_row(): - from litellm.proxy._experimental.mcp_server.db import McpIdentifierConflict + from litellm.proxy.mcp_server.db import McpIdentifierConflict mock_prisma = _mock_prisma() mock_prisma.db.litellm_mcpservertable.find_first = AsyncMock(return_value=_conflict_row()) @@ -1038,7 +1038,7 @@ async def test_update_writing_free_alias_returns_the_row(): async def test_clearing_alias_conflicts_on_the_fallback_server_name(): """alias: null drops the tool prefix to the stored server_name, which may already belong to another row, so that name goes through the conflict check.""" - from litellm.proxy._experimental.mcp_server.db import McpIdentifierConflict + from litellm.proxy.mcp_server.db import McpIdentifierConflict mock_prisma = _mock_prisma() existing = MagicMock() @@ -1061,7 +1061,7 @@ async def test_clearing_alias_conflicts_on_the_fallback_server_name(): async def test_clearing_alias_to_empty_string_conflicts_on_the_fallback_server_name(): """alias: "" publishes the stored server_name as the tool prefix, just like alias: null, so the fallback name must go through the conflict check too.""" - from litellm.proxy._experimental.mcp_server.db import McpIdentifierConflict + from litellm.proxy.mcp_server.db import McpIdentifierConflict mock_prisma = _mock_prisma() existing = MagicMock() @@ -1254,7 +1254,8 @@ async def test_url_edit_preserves_client_bound_to_previous_known_issuer_without_ @pytest.mark.parametrize("changed", [0, 1]) async def test_registration_write_requires_unchanged_server_revision(changed): from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.db import _update_mcp_server_row + + from litellm.proxy.mcp_server.db import _update_mcp_server_row prisma = _mock_prisma() table = prisma.db.litellm_mcpservertable diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_proxy_mode.py b/tests/unit/proxy/mcp_server/test_mcp_proxy_mode.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_proxy_mode.py rename to tests/unit/proxy/mcp_server/test_mcp_proxy_mode.py index 7dadfc6493a..8d6a92a12a7 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_proxy_mode.py +++ b/tests/unit/proxy/mcp_server/test_mcp_proxy_mode.py @@ -1,4 +1,3 @@ -from litellm.proxy._experimental.mcp_server import operations as mcp_operations import asyncio import json import logging @@ -14,15 +13,16 @@ from pydantic import AnyUrl import litellm from litellm.integrations.custom_logger import CustomLogger -from litellm.proxy._experimental.mcp_server import server -from litellm.proxy._experimental.mcp_server.mcp_context import _mcp_proxy_mode -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ListedToolsCaller -from litellm.proxy._experimental.mcp_server.tool_search import ( +from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth +from litellm.proxy.mcp_server import operations as mcp_operations +from litellm.proxy.mcp_server import server +from litellm.proxy.mcp_server.mcp_context import _mcp_proxy_mode +from litellm.proxy.mcp_server.mcp_server_manager import ListedToolsCaller +from litellm.proxy.mcp_server.tool_search import ( handle_mcp_proxy_tool, mcp_proxy_tool_id, with_mcp_proxy_identity, ) -from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_completion_flow.py b/tests/unit/proxy/mcp_server/test_mcp_sampling_completion_flow.py similarity index 85% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_completion_flow.py rename to tests/unit/proxy/mcp_server/test_mcp_sampling_completion_flow.py index d17b407a1be..e838b8b088d 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_completion_flow.py +++ b/tests/unit/proxy/mcp_server/test_mcp_sampling_completion_flow.py @@ -11,10 +11,9 @@ from types import SimpleNamespace from unittest.mock import AsyncMock, MagicMock, patch import pytest - from mcp.types import CreateMessageResult, ErrorData -from litellm.proxy._experimental.mcp_server.sampling_handler import ( +from litellm.proxy.mcp_server.sampling_handler import ( _build_completion_kwargs, _run_guardrails_and_call_llm, handle_sampling_create_message, @@ -146,26 +145,26 @@ class TestHandleSamplingCreateMessagePipeline: ) with ( patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._resolve_model_from_preferences", + "litellm.proxy.mcp_server.sampling_handler._resolve_model_from_preferences", return_value="gpt-4o", ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._check_model_access", + "litellm.proxy.mcp_server.sampling_handler._check_model_access", new_callable=AsyncMock, return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._run_budget_checks", + "litellm.proxy.mcp_server.sampling_handler._run_budget_checks", new_callable=AsyncMock, return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._build_completion_kwargs", + "litellm.proxy.mcp_server.sampling_handler._build_completion_kwargs", new_callable=AsyncMock, return_value={"model": "gpt-4o", "messages": []}, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._run_guardrails_and_call_llm", + "litellm.proxy.mcp_server.sampling_handler._run_guardrails_and_call_llm", new_callable=AsyncMock, return_value=response, ), @@ -187,21 +186,21 @@ class TestHandleSamplingCreateMessagePipeline: auth = SimpleNamespace(user_id="u1", api_key="sk-test", token="tok") with ( patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._resolve_model_from_preferences", + "litellm.proxy.mcp_server.sampling_handler._resolve_model_from_preferences", return_value="gpt-4o", ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._check_model_access", + "litellm.proxy.mcp_server.sampling_handler._check_model_access", new_callable=AsyncMock, return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._run_budget_checks", + "litellm.proxy.mcp_server.sampling_handler._run_budget_checks", new_callable=AsyncMock, return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._build_completion_kwargs", + "litellm.proxy.mcp_server.sampling_handler._build_completion_kwargs", new_callable=AsyncMock, side_effect=RateLimitError( "rate limited", llm_provider="openai", model="gpt-4o" @@ -220,21 +219,21 @@ class TestHandleSamplingCreateMessagePipeline: auth = SimpleNamespace(user_id="u1", api_key="sk-test", token="tok") with ( patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._resolve_model_from_preferences", + "litellm.proxy.mcp_server.sampling_handler._resolve_model_from_preferences", return_value="gpt-4o", ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._check_model_access", + "litellm.proxy.mcp_server.sampling_handler._check_model_access", new_callable=AsyncMock, return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._run_budget_checks", + "litellm.proxy.mcp_server.sampling_handler._run_budget_checks", new_callable=AsyncMock, return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._build_completion_kwargs", + "litellm.proxy.mcp_server.sampling_handler._build_completion_kwargs", new_callable=AsyncMock, side_effect=RuntimeError("kaboom"), ), diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_model_access.py b/tests/unit/proxy/mcp_server/test_mcp_sampling_model_access.py similarity index 92% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_model_access.py rename to tests/unit/proxy/mcp_server/test_mcp_sampling_model_access.py index 8975f42387b..7111638da29 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_model_access.py +++ b/tests/unit/proxy/mcp_server/test_mcp_sampling_model_access.py @@ -7,10 +7,11 @@ calls, preventing a malicious upstream MCP server from requesting inference on models the caller's API key is not authorized to use. """ -import pytest from unittest.mock import AsyncMock, MagicMock, patch -from litellm.proxy._experimental.mcp_server.sampling_handler import ( +import pytest + +from litellm.proxy.mcp_server.sampling_handler import ( _check_model_access, ) @@ -207,7 +208,7 @@ class TestSamplingAuthAndBudgetGating: @pytest.mark.asyncio async def test_should_deny_when_no_auth_context(self): """Sampling must reject calls with no user_api_key_auth.""" - from litellm.proxy._experimental.mcp_server.sampling_handler import ( + from litellm.proxy.mcp_server.sampling_handler import ( handle_sampling_create_message, ) @@ -236,7 +237,7 @@ class TestSamplingAuthAndBudgetGating: @pytest.mark.asyncio async def test_should_run_budget_checks(self): """Sampling must call _run_budget_checks after model access check.""" - from litellm.proxy._experimental.mcp_server.sampling_handler import ( + from litellm.proxy.mcp_server.sampling_handler import ( handle_sampling_create_message, ) @@ -254,17 +255,17 @@ class TestSamplingAuthAndBudgetGating: with ( patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._check_model_access", + "litellm.proxy.mcp_server.sampling_handler._check_model_access", new_callable=AsyncMock, return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._run_budget_checks", + "litellm.proxy.mcp_server.sampling_handler._run_budget_checks", new_callable=AsyncMock, return_value=None, ) as mock_budget, patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._resolve_model_from_preferences", + "litellm.proxy.mcp_server.sampling_handler._resolve_model_from_preferences", return_value="gpt-4o", ), patch( @@ -298,7 +299,8 @@ class TestSamplingAuthAndBudgetGating: async def test_should_deny_over_budget_caller(self): """When _run_budget_checks returns ErrorData, sampling must return it.""" from mcp.types import ErrorData - from litellm.proxy._experimental.mcp_server.sampling_handler import ( + + from litellm.proxy.mcp_server.sampling_handler import ( handle_sampling_create_message, ) @@ -318,17 +320,17 @@ class TestSamplingAuthAndBudgetGating: with ( patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._check_model_access", + "litellm.proxy.mcp_server.sampling_handler._check_model_access", new_callable=AsyncMock, return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._run_budget_checks", + "litellm.proxy.mcp_server.sampling_handler._run_budget_checks", new_callable=AsyncMock, return_value=budget_error, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._resolve_model_from_preferences", + "litellm.proxy.mcp_server.sampling_handler._resolve_model_from_preferences", return_value="gpt-4o", ), ): diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_model_resolution.py b/tests/unit/proxy/mcp_server/test_mcp_sampling_model_resolution.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_model_resolution.py rename to tests/unit/proxy/mcp_server/test_mcp_sampling_model_resolution.py index 0c8f7bd4814..a0280abbae7 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_model_resolution.py +++ b/tests/unit/proxy/mcp_server/test_mcp_sampling_model_resolution.py @@ -12,7 +12,7 @@ from unittest.mock import MagicMock, patch import pytest -from litellm.proxy._experimental.mcp_server.sampling_handler import ( +from litellm.proxy.mcp_server.sampling_handler import ( _resolve_model_from_preferences, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_priority_selection.py b/tests/unit/proxy/mcp_server/test_mcp_sampling_priority_selection.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_priority_selection.py rename to tests/unit/proxy/mcp_server/test_mcp_sampling_priority_selection.py index 24309ed0460..b6426ca88d6 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_priority_selection.py +++ b/tests/unit/proxy/mcp_server/test_mcp_sampling_priority_selection.py @@ -9,7 +9,7 @@ per the MCP spec. from types import SimpleNamespace from unittest.mock import patch -from litellm.proxy._experimental.mcp_server.sampling_handler import ( +from litellm.proxy.mcp_server.sampling_handler import ( _has_priorities, _resolve_model_from_preferences, _select_model_by_priority, diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_request_builder.py b/tests/unit/proxy/mcp_server/test_mcp_sampling_request_builder.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_request_builder.py rename to tests/unit/proxy/mcp_server/test_mcp_sampling_request_builder.py index d5c636baead..3d1b2072ae5 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_request_builder.py +++ b/tests/unit/proxy/mcp_server/test_mcp_sampling_request_builder.py @@ -7,7 +7,7 @@ so that header-dependent guardrails, routing hooks, and trace correlation function correctly. """ -from litellm.proxy._experimental.mcp_server.sampling_handler import ( +from litellm.proxy.mcp_server.sampling_handler import ( _build_sampling_request, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_response_conversion.py b/tests/unit/proxy/mcp_server/test_mcp_sampling_response_conversion.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_response_conversion.py rename to tests/unit/proxy/mcp_server/test_mcp_sampling_response_conversion.py index ba130f34964..de9c600b5c4 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_response_conversion.py +++ b/tests/unit/proxy/mcp_server/test_mcp_sampling_response_conversion.py @@ -18,7 +18,7 @@ from mcp.types import ( ToolUseContent, ) -from litellm.proxy._experimental.mcp_server.sampling_handler import ( +from litellm.proxy.mcp_server.sampling_handler import ( _convert_mcp_content_to_openai, _convert_mcp_tool_choice_to_openai, _convert_mcp_tools_to_openai, diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_tool_conversion.py b/tests/unit/proxy/mcp_server/test_mcp_sampling_tool_conversion.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_tool_conversion.py rename to tests/unit/proxy/mcp_server/test_mcp_sampling_tool_conversion.py index 167847afe1f..e537f03aeff 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_tool_conversion.py +++ b/tests/unit/proxy/mcp_server/test_mcp_sampling_tool_conversion.py @@ -12,12 +12,11 @@ from typing import Any, Dict from mcp.types import TextContent, ToolResultContent -from litellm.proxy._experimental.mcp_server.sampling_handler import ( +from litellm.proxy.mcp_server.sampling_handler import ( _convert_mcp_messages_to_openai, _convert_single_content, ) - # --------------------------------------------------------------------------- # Helpers — lightweight MCP type stand-ins # --------------------------------------------------------------------------- diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server.py b/tests/unit/proxy/mcp_server/test_mcp_server.py similarity index 92% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_server.py rename to tests/unit/proxy/mcp_server/test_mcp_server.py index de711d737d0..884c82760ea 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server.py +++ b/tests/unit/proxy/mcp_server/test_mcp_server.py @@ -2,24 +2,21 @@ import asyncio import json import os +from contextlib import asynccontextmanager, nullcontext from typing import Final +from unittest.mock import ANY, AsyncMock, MagicMock, patch import pytest -from unittest.mock import ANY, AsyncMock, MagicMock, patch -from contextlib import asynccontextmanager, nullcontext - +from mcp.types import CallToolResult, ListToolsResult, TextContent +from mcp.types import Tool as MCPTool from starlette.types import Receive, Scope, Send - -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - MCPServerManager, +from litellm.proxy._types import LiteLLM_ObjectPermissionTable +from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServer, + MCPServerManager, MCPTransport, ) -from litellm.proxy._types import LiteLLM_ObjectPermissionTable -from mcp.types import Tool as MCPTool, CallToolResult, ListToolsResult -from mcp.types import TextContent - mcp_server_manager = MCPServerManager() @@ -77,7 +74,7 @@ async def test_mcp_server_manager_https_server(): return mock_client with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): await mcp_server_manager.load_servers_from_config( @@ -185,7 +182,7 @@ async def test_mcp_http_transport_list_tools_mock(): return mock_client with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Load server config with HTTP transport @@ -262,7 +259,7 @@ async def test_mcp_http_transport_call_tool_mock(): return mock_client with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Load server config with HTTP transport @@ -328,7 +325,7 @@ async def test_mcp_http_transport_call_tool_error_mock(): return mock_client with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Load server config with HTTP transport @@ -426,26 +423,26 @@ async def test_streamable_http_mcp_handler_mock(): with ( patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server.session_manager_stateless", + "litellm.proxy.mcp_server.server.session_manager_stateless", mock_session_manager_stateless, ), patch( - "litellm.proxy._experimental.mcp_server.server.session_manager_stateful", + "litellm.proxy.mcp_server.server.session_manager_stateful", mock_session_manager_stateful, ), patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", AsyncMock(return_value=mock_auth_context), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), ): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, ) @@ -495,32 +492,32 @@ async def test_sse_mcp_handler_mock(): ) with ( - patch("litellm.proxy._experimental.mcp_server.server.serve_loop", serve), + patch("litellm.proxy.mcp_server.server.serve_loop", serve), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server.sse", + "litellm.proxy.mcp_server.server.sse", mock_sse, ), patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new=AsyncMock(return_value=mock_auth_result), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", + "litellm.proxy.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", new=AsyncMock(), ), patch( - "litellm.proxy._experimental.mcp_server.server._check_passthrough_upstream_auth", + "litellm.proxy.mcp_server.server._check_passthrough_upstream_auth", new=AsyncMock(), ), ): - from litellm.proxy._experimental.mcp_server.server import handle_sse_mcp + from litellm.proxy.mcp_server.server import handle_sse_mcp # Call the handler await handle_sse_mcp(mock_scope, mock_receive, mock_send) @@ -560,33 +557,33 @@ async def test_sse_mcp_handler_propagates_passthrough_401(): with ( patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server.sse", + "litellm.proxy.mcp_server.server.sse", ) as transport, patch( - "litellm.proxy._experimental.mcp_server.server.server.run", + "litellm.proxy.mcp_server.server.server.run", AsyncMock(), ), patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new=AsyncMock(return_value=mock_auth_result), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", + "litellm.proxy.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", new=AsyncMock(), ), patch( - "litellm.proxy._experimental.mcp_server.server._check_passthrough_upstream_auth", + "litellm.proxy.mcp_server.server._check_passthrough_upstream_auth", new=AsyncMock(side_effect=challenge), ), ): - from litellm.proxy._experimental.mcp_server.server import handle_sse_mcp + from litellm.proxy.mcp_server.server import handle_sse_mcp with pytest.raises(HTTPException) as excinfo: await handle_sse_mcp(mock_scope, mock_receive, mock_send) @@ -751,12 +748,13 @@ def test_generate_stable_server_id(): @pytest.mark.asyncio async def test_list_tools_rest_api_server_not_found(): """Test the list_tools REST API when server is not found""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( - list_tool_rest_api, - global_mcp_server_manager, - ) from fastapi import Query + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.rest_endpoints import ( + global_mcp_server_manager, + list_tool_rest_api, + ) # Mock UserAPIKeyAuth with explicit permission to access the requested server id mock_user_auth = UserAPIKeyAuth( @@ -776,7 +774,7 @@ async def test_list_tools_rest_api_server_not_found(): # Mock the global_mcp_server_manager to allow the server ID but return None for the server with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager" + "litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager" ) as mock_manager: # Allow the server ID in permissions mock_manager.get_allowed_mcp_servers = AsyncMock( @@ -805,14 +803,15 @@ async def test_list_tools_rest_api_server_not_found(): @pytest.mark.asyncio async def test_list_tools_rest_api_success(): """Test the list_tools REST API successful case""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from fastapi import Query + + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.rest_endpoints import ( list_tool_rest_api, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( ListMCPToolsRestAPIResponseObject, ) - from fastapi import Query - from litellm.proxy._types import UserAPIKeyAuth # Mock successful tools mock_tools = [ @@ -849,7 +848,7 @@ async def test_list_tools_rest_api_success(): # Mock the global_mcp_server_manager with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager" + "litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager" ) as mock_manager: mock_manager.get_allowed_mcp_servers = AsyncMock( return_value=["test-server-123"] @@ -862,7 +861,7 @@ async def test_list_tools_rest_api_success(): # Mock the _get_tools_for_single_server function with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_tools_for_single_server" + "litellm.proxy.mcp_server.rest_endpoints._get_tools_for_single_server" ) as mock_get_tools: mock_get_tools.return_value = mock_tools @@ -881,14 +880,14 @@ async def test_list_tools_rest_api_success(): @pytest.mark.asyncio async def test_get_tools_from_mcp_servers(): """Test _get_tools_from_mcp_servers function with both specific and no server filters""" - from litellm.proxy._experimental.mcp_server.server import ( - _get_tools_from_mcp_servers, - ) from litellm.proxy._types import UserAPIKeyAuth - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServer, MCPTransport, ) + from litellm.proxy.mcp_server.server import ( + _get_tools_from_mcp_servers, + ) # Mock data mock_user_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user") @@ -946,7 +945,7 @@ async def test_get_tools_from_mcp_servers(): ) with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): # Test with specific servers @@ -995,7 +994,7 @@ async def test_get_tools_from_mcp_servers(): ) with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager_2, ): result = await _get_tools_from_mcp_servers( @@ -1028,11 +1027,11 @@ async def test_get_tools_from_mcp_servers(): ) with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", AsyncMock(return_value=["server3_id"]), ): # Test with specific servers @@ -1112,7 +1111,7 @@ async def test_list_tools_only_returns_allowed_servers(monkeypatch): return mock_client with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Call list_tools @@ -1158,13 +1157,12 @@ async def test_mcp_server_manager_access_groups_from_config(config_only_mcp_mana assert config_server is not None assert set(config_server.access_groups) == {"group-a", "group-b"} # Check that the lookup logic finds the correct server ids - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( - MCPRequestHandler, - ) - # Patch global_mcp_server_manager for this test and restore afterwards to # avoid leaking state into other tests (e.g. the proxy MCP e2e suite). - import litellm.proxy._experimental.mcp_server.mcp_server_manager as mcp_server_manager_mod + import litellm.proxy.mcp_server.mcp_server_manager as mcp_server_manager_mod + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( + MCPRequestHandler, + ) original_manager = mcp_server_manager_mod.global_mcp_server_manager mcp_server_manager_mod.global_mcp_server_manager = test_manager @@ -1204,6 +1202,7 @@ async def test_mcp_server_manager_config_integration_with_database(config_only_m specifically testing access_groups and description fields. """ import datetime + from litellm.proxy._types import LiteLLM_MCPServerTable test_manager = config_only_mcp_manager_factory() @@ -1310,7 +1309,7 @@ def test_get_server_prefix_with_alias(): """ Test that get_server_prefix returns alias when present. """ - from litellm.proxy._experimental.mcp_server.utils import get_server_prefix + from litellm.proxy.mcp_server.utils import get_server_prefix # Create a mock server with alias mock_server = MagicMock() @@ -1326,7 +1325,7 @@ def test_get_server_prefix_without_alias(): """ Test that get_server_prefix falls back to server_name when alias is not present. """ - from litellm.proxy._experimental.mcp_server.utils import get_server_prefix + from litellm.proxy.mcp_server.utils import get_server_prefix # Create a mock server without alias mock_server = MagicMock() @@ -1342,7 +1341,7 @@ def test_get_server_prefix_fallback_to_server_id(): """ Test that get_server_prefix falls back to server_id when neither alias nor server_name are present. """ - from litellm.proxy._experimental.mcp_server.utils import get_server_prefix + from litellm.proxy.mcp_server.utils import get_server_prefix # Create a mock server without alias or server_name mock_server = MagicMock() @@ -1358,7 +1357,7 @@ def test_get_server_prefix_empty_strings(): """ Test that get_server_prefix handles empty strings correctly. """ - from litellm.proxy._experimental.mcp_server.utils import get_server_prefix + from litellm.proxy.mcp_server.utils import get_server_prefix # Create a mock server with empty strings mock_server = MagicMock() @@ -1409,7 +1408,7 @@ async def test_mcp_server_manager_alias_tool_prefixing(): return mock_client with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Get tools from server @@ -1469,7 +1468,7 @@ async def test_mcp_server_manager_server_name_tool_prefixing(): return mock_client with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Get tools from server @@ -1529,7 +1528,7 @@ async def test_mcp_server_manager_server_id_tool_prefixing(): return mock_client with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Get tools from server @@ -1748,7 +1747,7 @@ def test_normalize_server_name(): """ Test that normalize_server_name correctly replaces spaces with underscores. """ - from litellm.proxy._experimental.mcp_server.utils import normalize_server_name + from litellm.proxy.mcp_server.utils import normalize_server_name # Test basic space replacement assert normalize_server_name("My Server Name") == "My_Server_Name" @@ -1768,7 +1767,7 @@ def test_normalize_server_name(): def test_add_server_prefix_to_name(): """Ensure add_server_prefix_to_name correctly formats resource names.""" - from litellm.proxy._experimental.mcp_server.utils import add_server_prefix_to_name + from litellm.proxy.mcp_server.utils import add_server_prefix_to_name # Test basic prefixing result = add_server_prefix_to_name("send_email", "My Server") @@ -1789,7 +1788,7 @@ def test_add_server_prefix_to_name(): def test_get_server_auth_header_with_alias(): """Test _get_server_auth_header function with server alias.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from litellm.proxy.mcp_server.rest_endpoints import ( _get_server_auth_header, ) @@ -1824,7 +1823,7 @@ def test_get_server_auth_header_with_alias(): def test_get_server_auth_header_with_server_name(): """Test _get_server_auth_header function with server name (no alias).""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from litellm.proxy.mcp_server.rest_endpoints import ( _get_server_auth_header, ) @@ -1859,7 +1858,7 @@ def test_get_server_auth_header_with_server_name(): def test_get_server_auth_header_fallback_to_default(): """Test _get_server_auth_header function fallback to default auth header.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from litellm.proxy.mcp_server.rest_endpoints import ( _get_server_auth_header, ) @@ -1887,7 +1886,7 @@ def test_get_server_auth_header_fallback_to_default(): def test_get_server_auth_header_hyphenated_alias_sanitized_header_key(): """Header keys use sanitized alias; lookup must match legacy hyphenated aliases.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from litellm.proxy.mcp_server.rest_endpoints import ( _get_server_auth_header, ) @@ -1907,7 +1906,7 @@ def test_get_server_auth_header_hyphenated_alias_sanitized_header_key(): def test_get_server_auth_header_no_auth_headers(): """Test _get_server_auth_header function with no auth headers.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from litellm.proxy.mcp_server.rest_endpoints import ( _get_server_auth_header, ) @@ -1926,11 +1925,12 @@ def test_get_server_auth_header_no_auth_headers(): def test_create_tool_response_objects(): """Test _create_tool_response_objects enriches mcp_info with server_id and alias.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from mcp.types import Tool as MCPTool + + from litellm.proxy.mcp_server.rest_endpoints import ( _create_tool_response_objects, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer - from mcp.types import Tool as MCPTool # Create mock tools mock_tools = [ @@ -1977,10 +1977,11 @@ def test_create_tool_response_objects(): @pytest.mark.asyncio async def test_get_tools_for_single_server(): """Test _get_tools_for_single_server function.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from mcp.types import Tool as MCPTool + + from litellm.proxy.mcp_server.rest_endpoints import ( _get_tools_for_single_server, ) - from mcp.types import Tool as MCPTool # Create a mock server (pin allowlist fields; MagicMock auto-attrs are truthy) mock_server = MagicMock() @@ -2001,7 +2002,7 @@ async def test_get_tools_for_single_server(): # Mock the global_mcp_server_manager with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager" + "litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager" ) as mock_manager: mock_manager.get_tools_from_server = AsyncMock(return_value=mock_tools) @@ -2033,10 +2034,11 @@ async def test_get_tools_for_single_server(): @pytest.mark.asyncio async def test_get_tools_for_single_server_applies_disallowed_tools_without_allowlist(): """REST listing must honor disallowed_tools even when no allowlist is set.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from mcp.types import Tool as MCPTool + + from litellm.proxy.mcp_server.rest_endpoints import ( _get_tools_for_single_server, ) - from mcp.types import Tool as MCPTool mock_server = MagicMock() mock_server.mcp_info = {"server_name": "zapier"} @@ -2062,7 +2064,7 @@ async def test_get_tools_for_single_server_applies_disallowed_tools_without_allo ] with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager" + "litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager" ) as mock_manager: mock_manager.get_tools_from_server = AsyncMock(return_value=mock_tools) @@ -2080,14 +2082,15 @@ async def test_rest_listing_hides_key_grants_dispatch_would_refuse(): therefore grants nothing, and REST listing that matched the prefixed spelling would advertise a tool the very next call refuses. """ - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from mcp.types import Tool as MCPTool + + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from litellm.proxy.mcp_server.rest_endpoints import ( _get_tools_for_single_server, ) - from litellm.proxy._types import UserAPIKeyAuth - from mcp.types import Tool as MCPTool server_id = "3c6f6617-d23c-4f48-bfb0-f205e3b27bab" mock_server = MagicMock() @@ -2110,9 +2113,9 @@ async def test_rest_listing_hides_key_grants_dispatch_would_refuse(): ] with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager" + "litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager" ) as mock_manager, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager" + "litellm.proxy.mcp_server.operations.global_mcp_server_manager" ) as mock_server_manager, patch.object( MCPRequestHandler, "get_allowed_tools_for_server", @@ -2133,11 +2136,11 @@ async def test_rest_listing_hides_key_grants_dispatch_would_refuse(): @pytest.mark.asyncio async def test_list_tool_rest_api_with_server_specific_auth(): """Test list_tool_rest_api with server-specific auth headers.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import list_tool_rest_api - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.rest_endpoints import list_tool_rest_api # Create mock request with server-specific auth headers mock_request = MagicMock() @@ -2162,7 +2165,7 @@ async def test_list_tool_rest_api_with_server_specific_auth(): # Mock the global_mcp_server_manager with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager" + "litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager" ) as mock_manager: mock_manager.get_allowed_mcp_servers = AsyncMock( return_value=["test-server-123"] @@ -2191,9 +2194,9 @@ async def test_list_tool_rest_api_with_server_specific_auth(): # Mock the _get_tools_for_single_server function with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_tools_for_single_server" + "litellm.proxy.mcp_server.rest_endpoints._get_tools_for_single_server" ) as mock_get_tools: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( ListMCPToolsRestAPIResponseObject, ) @@ -2231,11 +2234,11 @@ async def test_list_tool_rest_api_with_server_specific_auth(): @pytest.mark.asyncio async def test_list_tool_rest_api_with_default_auth(): """Test list_tool_rest_api with default auth header when no server-specific header is found.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import list_tool_rest_api - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.rest_endpoints import list_tool_rest_api # Create mock request with default auth header only mock_request = MagicMock() @@ -2256,7 +2259,7 @@ async def test_list_tool_rest_api_with_default_auth(): # Mock the global_mcp_server_manager with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager" + "litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager" ) as mock_manager: mock_manager.get_allowed_mcp_servers = AsyncMock( return_value=["test-server-123"] @@ -2285,9 +2288,9 @@ async def test_list_tool_rest_api_with_default_auth(): # Mock the _get_tools_for_single_server function with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_tools_for_single_server" + "litellm.proxy.mcp_server.rest_endpoints._get_tools_for_single_server" ) as mock_get_tools: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( ListMCPToolsRestAPIResponseObject, ) @@ -2325,11 +2328,11 @@ async def test_list_tool_rest_api_with_default_auth(): @pytest.mark.asyncio async def test_list_tool_rest_api_all_servers_with_auth(): """Test list_tool_rest_api for all servers with server-specific auth headers.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import list_tool_rest_api - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.rest_endpoints import list_tool_rest_api # Create mock request with server-specific auth headers mock_request = MagicMock() @@ -2354,7 +2357,7 @@ async def test_list_tool_rest_api_all_servers_with_auth(): # Mock the global_mcp_server_manager with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager" + "litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager" ) as mock_manager: # Create mock servers mock_zapier_server = MagicMock() @@ -2395,9 +2398,9 @@ async def test_list_tool_rest_api_all_servers_with_auth(): # Mock the _get_tools_for_single_server function with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_tools_for_single_server" + "litellm.proxy.mcp_server.rest_endpoints._get_tools_for_single_server" ) as mock_get_tools: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( ListMCPToolsRestAPIResponseObject, ) @@ -2452,11 +2455,12 @@ async def test_list_tool_rest_api_all_servers_with_auth(): @pytest.mark.asyncio async def test_filter_tools_by_allowed_tools_integration(): """Test that filter_tools_by_allowed_tools works correctly via _get_tools_from_mcp_servers""" - from litellm.proxy._experimental.mcp_server.server import ( + from mcp.types import Tool as MCPTool + + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, ) - from litellm.proxy._types import UserAPIKeyAuth - from mcp.types import Tool as MCPTool # Create a mock user auth mock_user_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user") @@ -2509,7 +2513,7 @@ async def test_filter_tools_by_allowed_tools_integration(): # Mock the global MCP server manager with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager" + "litellm.proxy.mcp_server.operations.global_mcp_server_manager" ) as mock_manager: # Mock manager methods mock_manager.get_allowed_mcp_servers = AsyncMock( @@ -2526,7 +2530,7 @@ async def test_filter_tools_by_allowed_tools_integration(): # Mock the MCPClient constructor with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Call _get_tools_from_mcp_servers which should apply the filtering @@ -2567,11 +2571,12 @@ async def test_filter_tools_by_allowed_tools_integration(): @pytest.mark.asyncio async def test_filter_tools_by_disallowed_tools_integration(): """Test that filter_tools_by_allowed_tools works correctly with disallowed_tools via _get_tools_from_mcp_servers""" - from litellm.proxy._experimental.mcp_server.server import ( + from mcp.types import Tool as MCPTool + + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, ) - from litellm.proxy._types import UserAPIKeyAuth - from mcp.types import Tool as MCPTool # Create a mock user auth mock_user_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user") @@ -2624,7 +2629,7 @@ async def test_filter_tools_by_disallowed_tools_integration(): # Mock the global MCP server manager with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager" + "litellm.proxy.mcp_server.operations.global_mcp_server_manager" ) as mock_manager: # Mock manager methods mock_manager.get_allowed_mcp_servers = AsyncMock( @@ -2640,7 +2645,7 @@ async def test_filter_tools_by_disallowed_tools_integration(): # Mock the MCPClient constructor with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Call _get_tools_from_mcp_servers which should apply the filtering @@ -2681,11 +2686,12 @@ async def test_filter_tools_by_disallowed_tools_integration(): @pytest.mark.asyncio async def test_filter_tools_no_restrictions_integration(): """Test that filter_tools_by_allowed_tools returns all tools when no restrictions are set""" - from litellm.proxy._experimental.mcp_server.server import ( + from mcp.types import Tool as MCPTool + + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, ) - from litellm.proxy._types import UserAPIKeyAuth - from mcp.types import Tool as MCPTool # Create a mock user auth mock_user_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user") @@ -2725,7 +2731,7 @@ async def test_filter_tools_no_restrictions_integration(): # Mock the global MCP server manager with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager" + "litellm.proxy.mcp_server.operations.global_mcp_server_manager" ) as mock_manager: # Mock manager methods mock_manager.get_allowed_mcp_servers = AsyncMock( @@ -2742,7 +2748,7 @@ async def test_filter_tools_no_restrictions_integration(): # Mock the MCPClient constructor with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Call _get_tools_from_mcp_servers which should apply the filtering @@ -2766,10 +2772,10 @@ async def test_filter_tools_no_restrictions_integration(): @pytest.mark.asyncio async def test_mcp_access_group_permission_inheritance_integration(): """Integration test for MCP access group permission inheritance""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._types import UserAPIKeyAuth # Test scenario: team has access groups, key has no permissions -> should inherit # Use direct mocking of the helper functions instead of complex database mocking @@ -2806,10 +2812,10 @@ async def test_mcp_access_group_permission_inheritance_integration(): @pytest.mark.asyncio async def test_mcp_access_group_permission_intersection_integration(): """Integration test for MCP access group permission intersection""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._types import UserAPIKeyAuth # Test scenario: both team and key have access groups -> should intersect # Use direct mocking of the helper functions instead of complex database mocking @@ -2849,11 +2855,11 @@ async def test_mcp_access_group_permission_intersection_integration(): @pytest.mark.asyncio async def test_mcp_server_manager_with_access_groups_integration(config_only_mcp_manager_factory): """Integration test for MCPServerManager with access group filtering""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, MCPServerAccess, ) - from litellm.proxy._types import UserAPIKeyAuth # Create a test manager test_manager = config_only_mcp_manager_factory() @@ -2901,7 +2907,7 @@ async def test_mcp_server_manager_with_access_groups_integration(config_only_mcp @pytest.mark.asyncio async def test_get_allowed_mcp_servers_returns_registry_for_admin(config_only_mcp_manager_factory): from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -2936,7 +2942,7 @@ async def test_get_allowed_mcp_servers_returns_registry_for_admin(config_only_mc @pytest.mark.asyncio async def test_get_allowed_mcp_servers_returns_empty_for_non_admin_without_permissions(config_only_mcp_manager_factory): from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, MCPServerAccess, ) @@ -2972,7 +2978,7 @@ async def test_get_allowed_mcp_servers_returns_empty_for_non_admin_without_permi @pytest.mark.asyncio async def test_call_mcp_tool_uses_manager_permission_lookup(): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( call_mcp_tool, global_mcp_server_manager, ) @@ -3002,14 +3008,14 @@ async def test_call_mcp_tool_uses_manager_permission_lookup(): ), patch.object(global_mcp_server_manager, "server_exposes_tool", return_value=True), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_tool_registry" + "litellm.proxy.mcp_server.operations.global_mcp_tool_registry" ) as mock_tool_registry, patch( - "litellm.proxy._experimental.mcp_server.operations._handle_managed_mcp_tool", + "litellm.proxy.mcp_server.operations._handle_managed_mcp_tool", new_callable=AsyncMock, ) as mock_handle_managed, patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ), ): @@ -3038,7 +3044,7 @@ async def test_call_mcp_tool_resolves_unprefixed_tool_name_and_checks_permission Ensure `call_mcp_tool` resolves an unprefixed tool name on a request scoped to one server against that server and enforces server-level permissions with it. """ - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( call_mcp_tool, global_mcp_server_manager, ) @@ -3068,14 +3074,14 @@ async def test_call_mcp_tool_resolves_unprefixed_tool_name_and_checks_permission ), patch.object(global_mcp_server_manager, "server_exposes_tool", return_value=True), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_tool_registry" + "litellm.proxy.mcp_server.operations.global_mcp_tool_registry" ) as mock_tool_registry, patch( - "litellm.proxy._experimental.mcp_server.operations._handle_managed_mcp_tool", + "litellm.proxy.mcp_server.operations._handle_managed_mcp_tool", new_callable=AsyncMock, ) as mock_handle_managed, patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ) as mock_is_allowed, ): @@ -3103,7 +3109,7 @@ async def test_call_mcp_tool_resolves_unprefixed_tool_name_and_checks_permission @pytest.mark.asyncio async def test_mcp_admission_body_peek_times_out_without_losing_the_body(monkeypatch: pytest.MonkeyPatch) -> None: try: - from litellm.proxy._experimental.mcp_server import server + from litellm.proxy.mcp_server import server except ImportError: pytest.skip("MCP server not available") @@ -3127,16 +3133,16 @@ async def test_mcp_admission_body_peek_times_out_without_losing_the_body(monkeyp @pytest.mark.parametrize("method", ["tools/list", "tools/call", ["tools/list"]]) async def test_mcp_routing_stashes_only_method_for_auth_and_replays_full_body(method: str | list[str]): try: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.common_utils.http_parsing_utils import _read_request_body + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCP_PEEKED_BODY_SCOPE_KEY, _admission_request, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, session_manager_stateless, ) - from litellm.proxy.common_utils.http_parsing_utils import _read_request_body except ImportError: pytest.skip("MCP server not available") @@ -3172,17 +3178,17 @@ async def test_mcp_routing_stashes_only_method_for_auth_and_replays_full_body(me with ( patch( # test-quality-ok: the ASGI handler reads auth from a module-level helper; the suite's only seam - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(MagicMock(), None, None, None, None, None), ), patch( # test-quality-ok: registry is empty in unit tests; key owns one server - "litellm.proxy._experimental.mcp_server.server._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.server._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[MagicMock()], ), patch( # test-quality-ok: init flag is a module global; no injection seam - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( # test-quality-ok: session managers are module-level singletons; the suite's only seam @@ -3206,15 +3212,15 @@ async def test_mcp_routing_stashes_only_method_for_auth_and_replays_full_body(me @pytest.mark.asyncio async def test_mcp_routing_batch_body_is_not_stashed_for_auth(): try: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.common_utils.http_parsing_utils import _read_request_body + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCP_PEEKED_BODY_SCOPE_KEY, _admission_request, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) - from litellm.proxy.common_utils.http_parsing_utils import _read_request_body except ImportError: pytest.skip("MCP server not available") @@ -3233,17 +3239,17 @@ async def test_mcp_routing_batch_body_is_not_stashed_for_auth(): with ( patch( # test-quality-ok: the ASGI handler reads auth from a module-level helper; the suite's only seam - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(MagicMock(), None, None, None, None, None), ), patch( # test-quality-ok: registry is empty in unit tests; key owns one server - "litellm.proxy._experimental.mcp_server.server._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.server._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[MagicMock()], ), patch( # test-quality-ok: init flag is a module global; no injection seam - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( # test-quality-ok: session managers are module-level singletons; the suite's only seam @@ -3262,15 +3268,15 @@ async def test_mcp_routing_batch_body_is_not_stashed_for_auth(): @pytest.mark.asyncio async def test_mcp_routing_truncated_json_body_is_not_stashed_for_auth(): try: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.common_utils.http_parsing_utils import _read_request_body + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCP_PEEKED_BODY_SCOPE_KEY, _admission_request, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) - from litellm.proxy.common_utils.http_parsing_utils import _read_request_body except ImportError: pytest.skip("MCP server not available") @@ -3289,17 +3295,17 @@ async def test_mcp_routing_truncated_json_body_is_not_stashed_for_auth(): with ( patch( # test-quality-ok: the ASGI handler reads auth from a module-level helper; the suite's only seam - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(MagicMock(), None, None, None, None, None), ), patch( # test-quality-ok: registry is empty in unit tests; key owns one server - "litellm.proxy._experimental.mcp_server.server._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.server._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[MagicMock()], ), patch( # test-quality-ok: init flag is a module global; no injection seam - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( # test-quality-ok: session managers are module-level singletons; the suite's only seam diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_identity_env.py b/tests/unit/proxy/mcp_server/test_mcp_server_identity_env.py similarity index 95% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_server_identity_env.py rename to tests/unit/proxy/mcp_server/test_mcp_server_identity_env.py index 1c65adac4c6..7b3472d32c2 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_identity_env.py +++ b/tests/unit/proxy/mcp_server/test_mcp_server_identity_env.py @@ -2,7 +2,7 @@ ``LITELLM_MCP_SERVER_NAME`` and ``LITELLM_MCP_SERVER_DESCRIPTION`` are read from the environment at import time in -``litellm.proxy._experimental.mcp_server.utils`` and must flow through to every +``litellm.proxy.mcp_server.utils`` and must flow through to every consumer, including the well-known registry entry built in ``mcp_management_endpoints``. The env values are reloaded into the modules and restored afterwards so the override does not leak into other tests. @@ -16,7 +16,7 @@ import pytest pytest.importorskip("mcp") -UTILS_MODULE = "litellm.proxy._experimental.mcp_server.utils" +UTILS_MODULE = "litellm.proxy.mcp_server.utils" MGMT_MODULE = "litellm.proxy.management_endpoints.mcp_management_endpoints" diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py b/tests/unit/proxy/mcp_server/test_mcp_server_manager.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py rename to tests/unit/proxy/mcp_server/test_mcp_server_manager.py index 7315315a619..c76326c51f6 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py +++ b/tests/unit/proxy/mcp_server/test_mcp_server_manager.py @@ -1,13 +1,14 @@ -from litellm.proxy._experimental.mcp_server.upstream import resolve_upstream_auth -import importlib import asyncio + +# Add the parent directory to the path so we can import litellm +import contextlib import functools +import importlib import json import logging import os import sys import time -import anyio from collections.abc import AsyncIterator, Awaitable, Callable, Iterator from datetime import datetime from pathlib import Path @@ -15,27 +16,17 @@ from types import SimpleNamespace from typing import Any, Dict, Final, Literal, Optional, TypeVar, cast from unittest.mock import AsyncMock, MagicMock, patch -import pytest -from fastapi import HTTPException -from respx import MockRouter - -from litellm.proxy._experimental.mcp_server.exceptions import ( - MCPServerListError, - MCPUpstreamAuthError, -) -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ServerListFault - -# Add the parent directory to the path so we can import litellm - - -import contextlib - +import anyio import httpx import httpx2 +import pytest +from fastapi import HTTPException from mcp import ClientSession, ReadResourceResult, Resource from mcp.server.context import ServerRequestContext from mcp.types import ( CallToolRequestParams as MCPCallToolRequestParams, +) +from mcp.types import ( CallToolResult, GetPromptResult, ListToolsResult, @@ -46,30 +37,17 @@ from mcp.types import ( ) from mcp.types import Tool as MCPTool from pydantic import AnyUrl, TypeAdapter +from respx import MockRouter +import litellm +import litellm.llms as litellm_llms +from litellm.caching.caching import DualCache +from litellm.caching.llm_caching_handler import LLMClientCache from litellm.constants import MCP_METADATA_TIMEOUT, MCP_UPSTREAM_RATE_LIMIT_MAX_RETRIES -from litellm.proxy._experimental.mcp_server import discoverable_endpoints -from litellm.proxy._experimental.mcp_server.legacy_callbacks import ElicitationCallback -from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var -from litellm.proxy._experimental.mcp_server.tool_outcome import TextResult -from litellm.experimental_mcp_client.client import MCPClient, PersistentMCPSession -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - ListedToolsCaller, - MCPServerManager, - global_mcp_server_manager, - _deserialize_json_dict, - _flow_endpoints_missing, - _mcp_oauth_discovery_on_startup_enabled, - oauth_endpoints_unresolved, - _deserialize_json_list, - _normalize_mcp_server_cost_info, - _obo_retry_applies, - resolve_openapi_tool_auth, - should_strip_caller_authorization, - listed_tools_caller_for, -) +from litellm.integrations.custom_guardrail import CustomGuardrail +from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler +from litellm.mcp_client.client import MCPClient, PersistentMCPSession from litellm.proxy import proxy_server -from litellm.proxy.auth import auth_checks from litellm.proxy._types import ( LiteLLM_MCPServerTable, LiteLLM_ObjectPermissionTable, @@ -82,25 +60,45 @@ from litellm.proxy._types import ( MCPTransport, UserAPIKeyAuth, ) -from litellm.types.llms.custom_http import httpxSpecialProvider -from litellm.types.mcp import MCPAuth, MCPAuthType, MCPUpstreamProtocol -from litellm.types.mcp_server.mcp_server_manager import MCPOAuthMetadata, MCPServer, PinnedMCPTool -from litellm.caching.caching import DualCache -from litellm.caching.llm_caching_handler import LLMClientCache -from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler -import litellm -from litellm.integrations.custom_guardrail import CustomGuardrail -import litellm.llms as litellm_llms +from litellm.proxy.auth import auth_checks +from litellm.proxy.mcp_server import discoverable_endpoints +from litellm.proxy.mcp_server.exceptions import ( + MCPServerListError, + MCPUpstreamAuthError, +) +from litellm.proxy.mcp_server.faults.list_outcomes import ServerListFault +from litellm.proxy.mcp_server.legacy_callbacks import ElicitationCallback +from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var +from litellm.proxy.mcp_server.mcp_server_manager import ( + ListedToolsCaller, + MCPServerManager, + _deserialize_json_dict, + _deserialize_json_list, + _flow_endpoints_missing, + _mcp_oauth_discovery_on_startup_enabled, + _normalize_mcp_server_cost_info, + _obo_retry_applies, + global_mcp_server_manager, + listed_tools_caller_for, + oauth_endpoints_unresolved, + resolve_openapi_tool_auth, + should_strip_caller_authorization, +) +from litellm.proxy.mcp_server.tool_outcome import TextResult +from litellm.proxy.mcp_server.upstream import resolve_upstream_auth from litellm.proxy.utils import ProxyLogging from litellm.types.guardrails import GuardrailEventHooks from litellm.types.integrations.slack_alerting import AlertType +from litellm.types.llms.custom_http import httpxSpecialProvider +from litellm.types.mcp import MCPAuth, MCPAuthType, MCPUpstreamProtocol +from litellm.types.mcp_server.mcp_server_manager import MCPOAuthMetadata, MCPServer, PinnedMCPTool _TSessionResult = TypeVar("_TSessionResult") @pytest.mark.asyncio async def test_manager_sampling_preserves_explicit_headers_without_ambient_context(): - from litellm.proxy._experimental.mcp_server import server as legacy_server + from litellm.proxy.mcp_server import server as legacy_server caller = UserAPIKeyAuth(user_id="sampling-caller") upstream = MCPServer( @@ -115,8 +113,8 @@ async def test_manager_sampling_preserves_explicit_headers_without_ambient_conte client.call_tool = AsyncMock(return_value=CallToolResult(content=[])) assert legacy_server.get_active_auth_context() is None with ( - patch("litellm.proxy._experimental.mcp_server.upstream.MCPClient", return_value=client) as factory, - patch("litellm.proxy._experimental.mcp_server.sampling_handler.handle_sampling_create_message", sampling), + patch("litellm.proxy.mcp_server.upstream.MCPClient", return_value=client) as factory, + patch("litellm.proxy.mcp_server.sampling_handler.handle_sampling_create_message", sampling), ): await MCPServerManager()._call_regular_mcp_tool( mcp_server=upstream, @@ -140,8 +138,8 @@ async def test_manager_sampling_preserves_explicit_headers_without_ambient_conte async def test_sampling_callback_keeps_creation_context_after_caller_switch(): from mcp.server.auth.middleware.auth_context import auth_context_var - from litellm.proxy._experimental.mcp_server import server as legacy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _create_sampling_callback + from litellm.proxy.mcp_server import server as legacy_server + from litellm.proxy.mcp_server.mcp_server_manager import _create_sampling_callback token = auth_context_var.set(None) recorder = AsyncMock() @@ -154,7 +152,7 @@ async def test_sampling_callback_keeps_creation_context_after_caller_switch(): original.models.append("bravo-model") headers["x-caller"] = "bravo" legacy_server.set_auth_context(UserAPIKeyAuth(user_id="bravo"), raw_headers={"x-caller": "bravo"}) - with patch("litellm.proxy._experimental.mcp_server.sampling_handler.handle_sampling_create_message", recorder): + with patch("litellm.proxy.mcp_server.sampling_handler.handle_sampling_create_message", recorder): await callback(None, None) observed = recorder.await_args.kwargs assert observed["user_api_key_auth"].user_id == "alpha" @@ -168,18 +166,19 @@ async def test_sampling_callback_keeps_creation_context_after_caller_switch(): @pytest.mark.asyncio async def test_elicitation_callback_keeps_initiating_session(): - from litellm.proxy._experimental.mcp_server import server as legacy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _create_elicitation_callback - from types import SimpleNamespace + from mcp.types import ( ClientCapabilities, ElicitationCapability, - FormElicitationCapability, ElicitRequestFormParams, ElicitResult, + FormElicitationCapability, ) - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var + + from litellm.proxy.mcp_server import server as legacy_server + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server.mcp_server_manager import _create_elicitation_callback capabilities = ClientCapabilities(elicitation=ElicitationCapability(form=FormElicitationCapability())) accepted = ElicitResult(action="accept") @@ -206,7 +205,7 @@ async def test_elicitation_callback_keeps_initiating_session(): async def test_sampling_callbacks_isolate_callers_and_cancellation(): from mcp.types import ErrorData - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _create_sampling_callback + from litellm.proxy.mcp_server.mcp_server_manager import _create_sampling_callback started = asyncio.Event() cancelled = asyncio.Event() @@ -230,7 +229,7 @@ async def test_sampling_callbacks_isolate_callers_and_cancellation(): for label in ("alpha", "bravo", "cancelled") ) with patch( - "litellm.proxy._experimental.mcp_server.sampling_handler.handle_sampling_create_message", record_sampling + "litellm.proxy.mcp_server.sampling_handler.handle_sampling_create_message", record_sampling ): tasks = tuple(asyncio.create_task(callback(None, None)) for callback in callbacks) await asyncio.wait_for(started.wait(), timeout=2) @@ -243,12 +242,12 @@ async def test_sampling_callbacks_isolate_callers_and_cancellation(): def _reload_mcp_manager_module(): - utils_module = sys.modules["litellm.proxy._experimental.mcp_server.utils"] - manager_module = sys.modules["litellm.proxy._experimental.mcp_server.mcp_server_manager"] + utils_module = sys.modules["litellm.proxy.mcp_server.utils"] + manager_module = sys.modules["litellm.proxy.mcp_server.mcp_server_manager"] importlib.reload(utils_module) reloaded = importlib.reload(manager_module) for name, module in tuple(sys.modules.items()): - if name.startswith("litellm.proxy._experimental.mcp_server.") and hasattr(module, "global_mcp_server_manager"): + if name.startswith("litellm.proxy.mcp_server.") and hasattr(module, "global_mcp_server_manager"): module.global_mcp_server_manager = reloaded.global_mcp_server_manager return reloaded @@ -265,7 +264,7 @@ def restore_mcp_manager_singleton(): bound: Final = tuple( (module, module.global_mcp_server_manager) for name, module in tuple(sys.modules.items()) - if name.startswith("litellm.proxy._experimental.mcp_server.") and hasattr(module, "global_mcp_server_manager") + if name.startswith("litellm.proxy.mcp_server.") and hasattr(module, "global_mcp_server_manager") ) yield for module, manager in bound: @@ -285,8 +284,8 @@ def restore_mcp_manager_singleton(): ) @pytest.mark.parametrize("explicit_key", [False, True]) def test_validated_admission_jwt_is_not_forwarded_as_an_extra_header(auth_type: MCPAuth, explicit_key: bool) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers - from litellm.proxy._experimental.mcp_server.operations import _prepare_mcp_server_headers + from litellm.proxy.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers + from litellm.proxy.mcp_server.operations import _prepare_mcp_server_headers server: Final = MCPServer( server_id="header-boundary", @@ -325,8 +324,8 @@ def test_admission_authorization_is_not_forwarded_for_any_auth_type( auth_type: MCPAuth, monkeypatch: pytest.MonkeyPatch ) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers - from litellm.proxy._experimental.mcp_server.operations import _prepare_mcp_server_headers + from litellm.proxy.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers + from litellm.proxy.mcp_server.operations import _prepare_mcp_server_headers monkeypatch.setattr(proxy_server, "master_key", "test-master-key") server: Final = MCPServer( @@ -379,8 +378,8 @@ def test_no_master_key_preserves_caller_authorization_unless_auth_is_enabled( auth_type: MCPAuth, monkeypatch: pytest.MonkeyPatch ) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers - from litellm.proxy._experimental.mcp_server.operations import _prepare_mcp_server_headers + from litellm.proxy.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers + from litellm.proxy.mcp_server.operations import _prepare_mcp_server_headers monkeypatch.setattr(proxy_server, "master_key", None) monkeypatch.setattr(proxy_server, "general_settings", {}) @@ -423,8 +422,8 @@ def test_custom_auth_is_stripped_in_no_auth_dev_mode( auth_type: MCPAuth, monkeypatch: pytest.MonkeyPatch ) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers - from litellm.proxy._experimental.mcp_server.operations import _prepare_mcp_server_headers + from litellm.proxy.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers + from litellm.proxy.mcp_server.operations import _prepare_mcp_server_headers monkeypatch.setattr(proxy_server, "master_key", None) monkeypatch.setattr(proxy_server, "general_settings", {}) @@ -489,8 +488,8 @@ def test_custom_admission_header_controls_authorization_forwarding( monkeypatch: pytest.MonkeyPatch, ) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers - from litellm.proxy._experimental.mcp_server.operations import _prepare_mcp_server_headers + from litellm.proxy.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers + from litellm.proxy.mcp_server.operations import _prepare_mcp_server_headers monkeypatch.setattr(proxy_server, "master_key", "test-master-key") monkeypatch.setattr(proxy_server, "general_settings", {"litellm_key_header_name": "x-company-key"}) @@ -639,10 +638,10 @@ class TestMCPServerManager: """A caller-supplied per-request override must not substitute the stored authorization_code token: _create_mcp_client keeps the v2 spec and resolves through the injected provider rather than deferring to the v1 caller-override path.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( + from litellm.proxy.mcp_server.outbound_credentials.result import ( Ok, ) from litellm.types.mcp import MCPAuth @@ -674,10 +673,10 @@ class TestMCPServerManager: """A caller-supplied per-request override must not disable the ID-JAG exchange and forward an arbitrary bearer upstream: _create_mcp_client keeps the v2 spec and resolves through the injected provider rather than deferring to the v1 caller-override path.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( + from litellm.proxy.mcp_server.outbound_credentials.result import ( Ok, ) from litellm.types.mcp import MCPAuth @@ -1226,7 +1225,7 @@ class TestMCPServerManager: patch.object(manager, "_discover_oauth_metadata_for_server", new=discovery), patch.object(manager, "initialize_tool_name_to_mcp_server_name_mapping"), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager._oauth_discovery_now", + "litellm.proxy.mcp_server.mcp_server_manager._oauth_discovery_now", new=discovery_clock, ), ): @@ -1279,7 +1278,7 @@ class TestMCPServerManager: with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.MCP_METADATA_TIMEOUT", + "litellm.proxy.mcp_server.mcp_server_manager.MCP_METADATA_TIMEOUT", 0.01, ), patch.object(manager, "_discover_oauth_metadata_for_server", side_effect=never_returns) as discovery, @@ -1446,7 +1445,7 @@ class TestMCPServerManager: with ( patch( - "litellm.proxy._experimental.mcp_server.db.MCPServerRepository", + "litellm.proxy.mcp_server.db.MCPServerRepository", return_value=repository, ), patch( @@ -1509,7 +1508,7 @@ class TestMCPServerManager: with ( patch( - "litellm.proxy._experimental.mcp_server.db.MCPServerRepository", + "litellm.proxy.mcp_server.db.MCPServerRepository", return_value=repository, ), patch( @@ -1651,7 +1650,7 @@ class TestMCPServerManager: "ensure_oauth_metadata_discovered", new=ensure_oauth_metadata_discovered, ), - patch("litellm.proxy._experimental.mcp_server.upstream.MCPClient"), + patch("litellm.proxy.mcp_server.upstream.MCPClient"), ): await manager._create_mcp_client(server) @@ -2568,7 +2567,7 @@ class TestMCPServerManager: won't help) and a genuine non-auth failure (e.g. 503) both keep the default isError degradation and stay a visible warning, mirroring the list path, rather than being relayed as a re-auth challenge.""" - from litellm.experimental_mcp_client.client import MCPClient + from litellm.mcp_client.client import MCPClient server = self._passthrough_call_server(MCPAuth.true_passthrough, server_id=f"pt-{status_code}") manager = MCPServerManager() @@ -2577,7 +2576,7 @@ class TestMCPServerManager: mock_client.error_tool_result = MCPClient.error_tool_result manager.create_mcp_client = AsyncMock(return_value=mock_client) - import litellm.proxy._experimental.mcp_server.mcp_server_manager as _mgr_mod + import litellm.proxy.mcp_server.mcp_server_manager as _mgr_mod with patch.object(_mgr_mod, "verbose_logger") as mock_log: result = await self._run_call_regular(manager, server) @@ -2637,8 +2636,8 @@ class TestMCPServerManager: # must reconstruct it onto the MCPServer, and the v2 adapter must map it onto the resolver # config. Without threading it through, an entra_obo server persisted via the API silently # falls back to rfc8693 and posts the wrong grant to the IdP. - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import to_server_spec - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import TokenExchangeConfig + from litellm.proxy.mcp_server.outbound_credentials.adapter import to_server_spec + from litellm.proxy.mcp_server.outbound_credentials.types import TokenExchangeConfig manager = MCPServerManager() row = LiteLLM_MCPServerTable( @@ -3239,10 +3238,10 @@ class TestMCPServerManager: """A caller-supplied per-server header (x-mcp-*) must NOT disable the OBO exchange: _create_mcp_client keeps the v2 spec and runs the resolver (which exchanges the subject), rather than deferring to v1 and forwarding the caller's header verbatim upstream.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok exchanged_subjects = [] @@ -3269,10 +3268,10 @@ class TestMCPServerManager: """A guardrail/static Authorization (e.g. MCPJWTSigner) must NOT shadow the exchanged OBO token. The resolver-owned credential is authoritative: the conflicting header is dropped and the minted token is what reaches the upstream, not the injected JWT.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok class _FakeProvider: async def resolve_credentials(self, subject, server): @@ -3297,10 +3296,10 @@ class TestMCPServerManager: the gateway-minted client_credentials bearer. Dropping the resolved auth here would also drop the one-shot 401 refetch that rides on it, so the resolver-owned credential is authoritative exactly as for token_exchange and authorization_code.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok class _FakeProvider: async def resolve_credentials(self, subject, server): @@ -3348,10 +3347,10 @@ class TestMCPServerManager: """The dual-credential case: an ESB wants the gateway-minted token on its own header while a separate static Authorization passes through to the origin. Dropping Authorization here (the old name-blind behavior) deletes the second credential and the upstream 401s.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok class _FakeProvider: async def resolve_credentials(self, subject, server): @@ -3371,10 +3370,10 @@ class TestMCPServerManager: """The negative class of the test above: when the two DO collide the resolver-owned credential is still authoritative, so the knob cannot be used to smuggle a second credential into the same slot.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok class _FakeProvider: async def resolve_credentials(self, subject, server): @@ -3399,10 +3398,10 @@ class TestMCPServerManager: downstream consumer of that dict. httpx happens to collapse the two on the wire, which is exactly why this needs pinning rather than being left to luck. """ - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok class _FakeProvider: async def resolve_credentials(self, subject, server): @@ -3430,8 +3429,8 @@ class TestMCPServerManager: """A subject the IdP rejects must raise the RFC 9728 401 challenge from the preflight, so a single-server route fails observably at the transport edge instead of the old behavior of the session opening and list_tools masking the failed exchange as an empty tool list.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import CredError + from litellm.proxy.mcp_server.outbound_credentials.result import Error + from litellm.proxy.mcp_server.outbound_credentials.types import CredError class _FakeProvider: async def resolve_credentials(self, subject, server): @@ -3455,8 +3454,8 @@ class TestMCPServerManager: async def test_preflight_token_exchange_maps_gateway_fault_to_public_status(self): """A gateway-fault CredError (e.g. invalid_client) must surface its public status (500) from the preflight, not the OBO 401 challenge and not an empty-success session.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import CredError + from litellm.proxy.mcp_server.outbound_credentials.result import Error + from litellm.proxy.mcp_server.outbound_credentials.types import CredError class _FakeProvider: async def resolve_credentials(self, subject, server): @@ -3477,10 +3476,10 @@ class TestMCPServerManager: async def test_preflight_token_exchange_noop_on_success_and_without_subject(self): """A successful exchange returns without raising, and a request with no bearer never reaches the resolver (the no-subject case is the existing preemptive challenge's job).""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok resolved = [] @@ -3525,8 +3524,8 @@ class TestMCPServerManager: gets a 200 with an empty tool list and then 'tool not found', which is not what happened. 412 is a precondition, not an RFC 9728 discovery challenge, so it carries no WWW-Authenticate: there is nothing for the client to discover and retry against.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import CredError + from litellm.proxy.mcp_server.outbound_credentials.result import Error + from litellm.proxy.mcp_server.outbound_credentials.types import CredError summary = ( "ID-JAG requires an IdP identity assertion for this user and none is stored. " @@ -3553,8 +3552,8 @@ class TestMCPServerManager: async def test_preflight_id_jag_surfaces_assertion_store_outage_as_503(self): """A store outage is the other failure the session would swallow, and it is a different answer than 412: the user has nothing to fix by signing in again.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import CredError + from litellm.proxy.mcp_server.outbound_credentials.result import Error + from litellm.proxy.mcp_server.outbound_credentials.types import CredError class _FakeProvider: async def resolve_credentials(self, subject, server): @@ -3574,10 +3573,10 @@ class TestMCPServerManager: async def test_preflight_id_jag_preflights_litellm_key_and_skips_identity_bearer(self): """ID-JAG preflights when Authorization carries a LiteLLM key, but skips a caller identity bearer that the session passes through unchanged.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok subjects = [] @@ -3635,8 +3634,8 @@ class TestMCPServerManager: other mode itself. The single-server call site no longer tests the mode before calling, so a mode that falls through here would start resolving its credential a second time, at connect, for flows that never had a connect-time resolution at all.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import CredError + from litellm.proxy.mcp_server.outbound_credentials.result import Error + from litellm.proxy.mcp_server.outbound_credentials.types import CredError calls = [] @@ -3677,11 +3676,11 @@ class TestMCPServerManager: ) async def test_preflight_token_exchange_strips_inbound_authorization_scheme(self, authorization): """The resolver posts inbound_token verbatim as subject_token.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import CredError, ServerSpec, Subject + from litellm.proxy.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.types import CredError, ServerSpec, Subject resolved: Final[list[str | None]] = [] @@ -3705,11 +3704,11 @@ class TestMCPServerManager: @pytest.mark.asyncio async def test_preflight_token_exchange_preserves_authorization_without_separator(self): - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import CredError, ServerSpec, Subject + from litellm.proxy.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.types import CredError, ServerSpec, Subject resolved: Final[list[str | None]] = [] @@ -4320,10 +4319,10 @@ class TestMCPServerManager: ) with ( patch( - "litellm.proxy._experimental.mcp_server.upstream.resolve_mcp_auth", + "litellm.proxy.mcp_server.upstream.resolve_mcp_auth", new_callable=AsyncMock, ) as mock_resolve, - patch("litellm.proxy._experimental.mcp_server.upstream.MCPClient") as mock_client_cls, + patch("litellm.proxy.mcp_server.upstream.MCPClient") as mock_client_cls, ): await manager._create_mcp_client(server=server, extra_headers={"Authorization": "Bearer upstream-token"}) mock_resolve.assert_not_awaited() @@ -4340,13 +4339,13 @@ class TestMCPServerManager: """A configured OBO server is owned end to end by the v2 token_exchange arm, even when the caller supplies an x-mcp-* override. This is what makes the v1 OBO handler unreachable, so if it ever defers to v1 again the deleted handler is silently needed back.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( + from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.resolver import ( + from litellm.proxy.mcp_server.outbound_credentials.resolver import ( UpstreamCredentialProvider, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok class _StubExchanger: def __init__(self): @@ -4373,10 +4372,10 @@ class TestMCPServerManager: ) with ( patch( - "litellm.proxy._experimental.mcp_server.upstream.resolve_mcp_auth", + "litellm.proxy.mcp_server.upstream.resolve_mcp_auth", new_callable=AsyncMock, ) as mock_resolve, - patch("litellm.proxy._experimental.mcp_server.upstream.MCPClient") as mock_client_cls, + patch("litellm.proxy.mcp_server.upstream.MCPClient") as mock_client_cls, ): await manager._create_mcp_client( server=server, @@ -4416,10 +4415,10 @@ class TestMCPServerManager: ) with ( patch( - "litellm.proxy._experimental.mcp_server.upstream.resolve_mcp_auth", + "litellm.proxy.mcp_server.upstream.resolve_mcp_auth", new_callable=AsyncMock, ) as mock_resolve, - patch("litellm.proxy._experimental.mcp_server.upstream.MCPClient") as mock_client_cls, + patch("litellm.proxy.mcp_server.upstream.MCPClient") as mock_client_cls, ): await manager._create_mcp_client( server=server, @@ -4432,7 +4431,7 @@ class TestMCPServerManager: assert not kwargs["extra_headers"] or "authorization" not in {k.lower() for k in kwargs["extra_headers"]} def test_consumes_caller_authorization_per_mode(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _consumes_caller_authorization, ) @@ -4468,7 +4467,7 @@ class TestMCPServerManager: ) def test_caller_authorization_fans_out_only_with_second_consumer(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( caller_authorization_fans_out, ) @@ -4743,7 +4742,7 @@ class TestMCPServerManager: mock_client.get = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): servers, scopes = await manager._fetch_oauth_metadata_from_resource( @@ -4778,7 +4777,7 @@ class TestMCPServerManager: with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ) as get_client, patch.object( @@ -4833,7 +4832,7 @@ class TestMCPServerManager: with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ), patch.object( @@ -4880,7 +4879,7 @@ class TestMCPServerManager: mock_client.get = AsyncMock(side_effect=build_response) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): # The Azure issuer is cross-origin against the server_url — use @@ -4930,7 +4929,7 @@ class TestMCPServerManager: mock_client = MagicMock() mock_client.get = AsyncMock(side_effect=build_response) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): result = await manager._fetch_single_authorization_server_metadata(issuer, issuer, require_issuer=issuer) @@ -4967,7 +4966,7 @@ class TestMCPServerManager: mock_client = MagicMock() mock_client.get = AsyncMock(side_effect=build_response) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): result = await manager._fetch_single_authorization_server_metadata(issuer, issuer, require_issuer=issuer) @@ -4992,7 +4991,7 @@ class TestMCPServerManager: mock_client.get = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): result = await manager._fetch_single_authorization_server_metadata(issuer, issuer) @@ -5020,7 +5019,7 @@ class TestMCPServerManager: mock_client.get = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): azure = await manager._fetch_single_authorization_server_metadata(issuer, issuer, require_issuer=issuer) @@ -5061,7 +5060,7 @@ class TestMCPServerManager: with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ), patch.object( @@ -5155,9 +5154,9 @@ class TestMCPServerManager: assert server.scopes is None # And the exchange precondition now fails closed before any IdP call. - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import to_server_spec - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error - from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchanger import ( + from litellm.proxy.mcp_server.outbound_credentials.adapter import to_server_spec + from litellm.proxy.mcp_server.outbound_credentials.result import Error + from litellm.proxy.mcp_server.outbound_credentials.token_exchanger import ( OboTokenExchanger, ) @@ -5220,7 +5219,7 @@ class TestMCPServerManager: assert minimal.subject_token_type == DEFAULT_SUBJECT_TOKEN_TYPE assert minimal.token_exchange_profile == "rfc8693" - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import to_server_spec + from litellm.proxy.mcp_server.outbound_credentials.adapter import to_server_spec spec = to_server_spec(full) assert spec is not None @@ -5390,7 +5389,7 @@ class TestMCPServerManager: @pytest.mark.asyncio @pytest.mark.parametrize("cancel", [False, True]) async def test_openapi_health_timeout_and_cancellation_cleanup(self, respx_mock, monkeypatch, cancel): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _openapi_spec_health + from litellm.proxy.mcp_server.mcp_server_manager import _openapi_spec_health monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") started = asyncio.Event() @@ -5742,7 +5741,7 @@ class TestMCPServerManager: self, respx_mock: MockRouter, monkeypatch: pytest.MonkeyPatch, cancel: bool ) -> None: monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") - monkeypatch.setattr("litellm.proxy._experimental.mcp_server.mcp_server_manager.MCP_HEALTH_CHECK_TIMEOUT", 0.1) + monkeypatch.setattr("litellm.proxy.mcp_server.mcp_server_manager.MCP_HEALTH_CHECK_TIMEOUT", 0.1) manager: Final = MCPServerManager() server: Final = MCPServer( server_id="slow-health", @@ -6154,15 +6153,15 @@ class TestMCPServerManager: with ( patch( - "litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator.create_tool_function", + "litellm.proxy.mcp_server.openapi_to_mcp_generator.create_tool_function", side_effect=fake_create_tool_function, ), patch( - "litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator.build_input_schema", + "litellm.proxy.mcp_server.openapi_to_mcp_generator.build_input_schema", return_value={"type": "object", "properties": {}, "required": []}, ), patch( - "litellm.proxy._experimental.mcp_server.tool_registry.global_mcp_tool_registry.register_tool", + "litellm.proxy.mcp_server.tool_registry.global_mcp_tool_registry.register_tool", return_value=None, ), ): @@ -6244,15 +6243,15 @@ class TestMCPServerManager: return tool_func monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator.create_tool_function", + "litellm.proxy.mcp_server.openapi_to_mcp_generator.create_tool_function", fake_create_tool_function, ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator.build_input_schema", + "litellm.proxy.mcp_server.openapi_to_mcp_generator.build_input_schema", lambda *args, **kwargs: {"type": "object", "properties": {}, "required": []}, ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.tool_registry.global_mcp_tool_registry.register_tool", + "litellm.proxy.mcp_server.tool_registry.global_mcp_tool_registry.register_tool", lambda *args, **kwargs: None, ) await manager._register_openapi_tools( @@ -6851,7 +6850,7 @@ class TestMCPServerManager: stored = {"Authorization": "Bearer stored-user-token"} with patch( - "litellm.proxy._experimental.mcp_server.operations._get_user_oauth_extra_headers_from_db", + "litellm.proxy.mcp_server.operations._get_user_oauth_extra_headers_from_db", new=AsyncMock(return_value=stored), ) as mock_lookup: result = await manager._resolve_oauth2_headers_for_tool_call( @@ -6878,7 +6877,7 @@ class TestMCPServerManager: user_auth = UserAPIKeyAuth(api_key="sk-test", user_id="alice") with patch( - "litellm.proxy._experimental.mcp_server.operations._get_user_oauth_extra_headers_from_db", + "litellm.proxy.mcp_server.operations._get_user_oauth_extra_headers_from_db", new=AsyncMock(return_value={"Authorization": "Bearer should-not-be-used"}), ) as mock_lookup: result = await manager._resolve_oauth2_headers_for_tool_call( @@ -6904,7 +6903,7 @@ class TestMCPServerManager: user_auth = UserAPIKeyAuth(api_key="sk-test", user_id="alice") with patch( - "litellm.proxy._experimental.mcp_server.operations._get_user_oauth_extra_headers_from_db", + "litellm.proxy.mcp_server.operations._get_user_oauth_extra_headers_from_db", new=AsyncMock(side_effect=RuntimeError("redis down")), ): result = await manager._resolve_oauth2_headers_for_tool_call( @@ -7060,7 +7059,7 @@ class TestMCPServerManager: user_auth = UserAPIKeyAuth(api_key="sk-test") with patch( - "litellm.proxy._experimental.mcp_server.operations._get_user_oauth_extra_headers_from_db", + "litellm.proxy.mcp_server.operations._get_user_oauth_extra_headers_from_db", new=AsyncMock(return_value={"Authorization": "Bearer x"}), ) as mock_lookup: result = await manager._resolve_oauth2_headers_for_tool_call( @@ -7139,7 +7138,7 @@ class TestMCPServerManager: @pytest.mark.asyncio async def test_rest_endpoint_filters_by_allowed_tools(self): """Test that REST endpoint _get_tools_for_single_server respects allowed_tools configuration""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from litellm.proxy.mcp_server.rest_endpoints import ( _get_tools_for_single_server, ) @@ -7160,7 +7159,7 @@ class TestMCPServerManager: tool3 = MCPTool(name="allowed_tool_2", description="This tool is also allowed", inputSchema={}) # Mock the global_mcp_server_manager._get_tools_from_server - from litellm.proxy._experimental.mcp_server import rest_endpoints + from litellm.proxy.mcp_server import rest_endpoints with patch.object( rest_endpoints.global_mcp_server_manager, @@ -7180,7 +7179,7 @@ class TestMCPServerManager: @pytest.mark.asyncio async def test_rest_endpoint_shows_all_when_allowed_tools_is_none(self): """Test that REST endpoint shows all tools when allowed_tools is None (backwards compatibility)""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from litellm.proxy.mcp_server.rest_endpoints import ( _get_tools_for_single_server, ) @@ -7201,7 +7200,7 @@ class TestMCPServerManager: tool3 = MCPTool(name="tool_3", description="Tool 3", inputSchema={}) # Mock the global_mcp_server_manager._get_tools_from_server - from litellm.proxy._experimental.mcp_server import rest_endpoints + from litellm.proxy.mcp_server import rest_endpoints with patch.object( rest_endpoints.global_mcp_server_manager, @@ -7221,7 +7220,7 @@ class TestMCPServerManager: @pytest.mark.asyncio async def test_rest_endpoint_shows_all_when_allowed_tools_is_empty_list(self): """Test that REST endpoint shows all tools when allowed_tools is empty list (backwards compatibility)""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from litellm.proxy.mcp_server.rest_endpoints import ( _get_tools_for_single_server, ) @@ -7240,7 +7239,7 @@ class TestMCPServerManager: tool2 = MCPTool(name="tool_2", description="Tool 2", inputSchema={}) # Mock the global_mcp_server_manager._get_tools_from_server - from litellm.proxy._experimental.mcp_server import rest_endpoints + from litellm.proxy.mcp_server import rest_endpoints with patch.object( rest_endpoints.global_mcp_server_manager, @@ -7656,8 +7655,8 @@ class TestMCPServerManager: from mcp.server.context import ServerRequestContext from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var - from litellm.proxy._experimental.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse auth = self._unrestricted_auth() manager, logging = self._manager_ready_for_call_tool( @@ -7681,7 +7680,7 @@ class TestMCPServerManager: request=Request({"type": "http", SCOPE_RESPONSE_KEY: gate}), ) token = active_mcp_request_ctx_var.set(context) - await gate({"type": "http.response.start", "status": 200, "headers": []}) + headers: Final = asyncio.create_task(gate({"type": "http.response.start", "status": 200, "headers": []})) progress = asyncio.create_task(gate({"type": "http.response.body", "body": b"progress", "more_body": True})) async def upstream_call(*args, **kwargs): @@ -7701,7 +7700,7 @@ class TestMCPServerManager: assert not result.is_error finally: gate.allow() - await asyncio.wait_for(progress, 1) + await asyncio.wait_for(asyncio.gather(headers, progress), 1) active_mcp_request_ctx_var.reset(token) @pytest.mark.asyncio @@ -8130,7 +8129,7 @@ class TestMCPServerManager: with ( patch("litellm.proxy.proxy_server.prisma_client", MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_user_credential", + "litellm.proxy.mcp_server.db.get_user_credential", AsyncMock(side_effect=RuntimeError("DB DOWN")), ), ): @@ -8156,11 +8155,11 @@ class TestMCPServerManager: """A REST listing records under the header the client sent (none here). tools/call then swaps the stored credential in, either before reaching ``call_tool`` (``execute_mcp_tool``) or inside it (the Responses API), and must still read that slot rather than one keyed by the credential.""" - from litellm.proxy._experimental.mcp_server.byok_credential_cache import ( + from litellm.proxy.mcp_server.byok_credential_cache import ( byok_credential_cache_key, cache_byok_credential, ) - from litellm.proxy._experimental.mcp_server.operations import byok_credential_cache + from litellm.proxy.mcp_server.operations import byok_credential_cache manager = MCPServerManager() server = MCPServer( @@ -8264,11 +8263,11 @@ class TestMCPServerManager: reads, even with the stored BYOK secret at hand in the cache, and tools/list sends upstream exactly what the caller supplied, so the static token, the M2M mint and MCPJWTSigner all behave as they did before the catalog existed, whatever the auth_type.""" - from litellm.proxy._experimental.mcp_server.byok_credential_cache import ( + from litellm.proxy.mcp_server.byok_credential_cache import ( byok_credential_cache_key, cache_byok_credential, ) - from litellm.proxy._experimental.mcp_server.operations import byok_credential_cache + from litellm.proxy.mcp_server.operations import byok_credential_cache manager = MCPServerManager() server = MCPServer( @@ -8531,7 +8530,7 @@ class TestMCPServerManager: ) def test_per_caller_listed_tools_evict_oldest_caller_and_keep_shared(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _LISTED_TOOLS_CALLERS_PER_SERVER + from litellm.proxy.mcp_server.mcp_server_manager import _LISTED_TOOLS_CALLERS_PER_SERVER manager = MCPServerManager() server = MCPServer( @@ -8566,7 +8565,7 @@ class TestMCPServerManager: @pytest.mark.asyncio @pytest.mark.parametrize("add_prefix", [True, False]) async def test_openapi_listing_records_listed_tools(self, add_prefix): - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry server = MCPServer( server_id="petstore-id", @@ -8601,7 +8600,7 @@ class TestMCPServerManager: @pytest.mark.asyncio async def test_openapi_listing_ignores_overlapping_server_prefix(self): - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry server = MCPServer( server_id="pet-id", @@ -8647,7 +8646,7 @@ class TestMCPServerManager: async def test_get_tools_from_server_records_the_catalog_only_when_asked_to(self, openapi): """The startup fill, the implicit pre-call listing and the pin snapshot reuse this fetch without serving its result, so only a listing that asks to be recorded sets what tools/call hooks see.""" - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry if openapi: server = MCPServer( @@ -8720,11 +8719,11 @@ class TestMCPServerManager: when called. This verifies the fix where user_api_key_auth is passed through litellm_metadata from responses API. """ - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, MCPServerAccess, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth manager = MCPServerManager() @@ -8777,10 +8776,10 @@ class TestMCPServerManager: async def test_no_mcp_servers_sentinel_blocks_allow_all_keys(self): """A key scoped to no-mcp-servers gets zero servers even when allow_all_keys servers exist, and the inner resolver is never consulted.""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth manager = MCPServerManager() object_permission = LiteLLM_ObjectPermissionTable( @@ -8812,10 +8811,10 @@ class TestMCPServerManager: @pytest.mark.asyncio async def test_no_mcp_servers_sentinel_excludes_submitted_byom_servers(self): from litellm.proxy import proxy_server as proxy_server_module - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth class _Cache: async def async_get_cache(self, key: str): @@ -8860,10 +8859,10 @@ class TestMCPServerManager: @pytest.mark.asyncio async def test_explicitly_scoped_key_excludes_submitted_byom_servers(self): from litellm.proxy import proxy_server as proxy_server_module - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth cache = MagicMock() cache.async_get_cache = AsyncMock(return_value=["submitted-server"]) @@ -8912,14 +8911,14 @@ class TestMCPServerManager: @pytest.mark.asyncio async def test_toolset_scope_excludes_submitted_byom_servers(self): from litellm.proxy import proxy_server as proxy_server_module - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, MCPServerAccess, ) - from litellm.proxy._experimental.mcp_server.mcp_context import ( + from litellm.proxy.mcp_server.mcp_context import ( mcp_active_toolset_id, ) - from litellm.proxy._types import UserAPIKeyAuth cache = MagicMock() cache.async_get_cache = AsyncMock(return_value=["submitted-server"]) @@ -8998,7 +8997,7 @@ class TestMCPServerManager: patch.object(proxy_server_module, "user_api_key_cache", cache), patch.object(proxy_server_module, "prisma_client", MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_active_submitted_mcp_server_ids_for_user", + "litellm.proxy.mcp_server.db.get_active_submitted_mcp_server_ids_for_user", AsyncMock(return_value=["submitted-server", "unknown-server"]), ), ): @@ -9014,10 +9013,10 @@ class TestMCPServerManager: @pytest.mark.asyncio async def test_get_allowed_mcp_servers_fallback_keeps_submitted_byom_servers(self): from litellm.proxy import proxy_server as proxy_server_module - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._types import UserAPIKeyAuth class _Cache: async def async_get_cache(self, key: str): @@ -9099,7 +9098,7 @@ class TestMCPServerManager: submitted_server_ids, expected_server_ids, ): # test-quality-ok: parameterized matrix covers the scope state machine - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess manager = MCPServerManager() auth = UserAPIKeyAuth(api_key="sk-test", user_id="user-123") @@ -9131,7 +9130,7 @@ class TestMCPServerManager: when extracting server name from prefixed tool name (second case). This ensures the fix for using server_name instead of name works correctly. """ - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( add_server_prefix_to_name, ) @@ -9317,9 +9316,9 @@ class TestMCPServerTimestamps: repo_instance = MagicMock() repo_instance.table.update = AsyncMock() with ( - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=update_mcp_server_mock), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=update_mcp_server_mock), patch( - "litellm.proxy._experimental.mcp_server.db.MCPServerRepository", + "litellm.proxy.mcp_server.db.MCPServerRepository", return_value=repo_instance, ), patch("litellm.proxy.proxy_server.prisma_client", MagicMock()), @@ -9493,7 +9492,7 @@ class TestMCPServerTimestamps: build_mock = AsyncMock(return_value=previous_entry) with ( patch( - "litellm.proxy._experimental.mcp_server.db.MCPServerRepository", + "litellm.proxy.mcp_server.db.MCPServerRepository", return_value=repo_instance, ), patch( @@ -9585,7 +9584,7 @@ class TestMCPServerTimestamps: def test_carry_forward_skips_when_url_or_auth_type_changed(self): """Stale endpoints from a different upstream or auth mode must not carry forward.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( carry_forward_resolved_oauth_endpoints, ) @@ -9624,7 +9623,7 @@ class TestMCPServerTimestamps: this, re-pointing authorize to server B while the same MCP url keeps serving A's token endpoint recreates the RFC 9700 mix-up, durably, and the discovery gate alone cannot catch it because the stale endpoint comes from the registry, not from discovery.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( carry_forward_resolved_oauth_endpoints, ) @@ -9658,7 +9657,7 @@ class TestMCPServerTimestamps: endpoint) adopts the previous authorize endpoint AND its token endpoint together as a consistent group, and a rebuild that re-pins the same authorize endpoint (formatting aside) keeps carrying the corroborated token endpoint.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( carry_forward_resolved_oauth_endpoints, ) @@ -9720,7 +9719,7 @@ class TestMCPServerTimestamps: endpoint the issuer anchor distrusts would keep being served across rebuilds. Resource-driven scopes still carry as last-known-good. Anchoring is keyed on the explicit issuer_is_anchored flag, not on issuer truthiness, so a discovered issuer does not trip this fail-closed branch.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( carry_forward_resolved_oauth_endpoints, ) @@ -9760,7 +9759,7 @@ class TestMCPServerTimestamps: must still carry forward as last-known-good, the same as any resource-rooted server. This is the regression the explicit issuer_is_anchored flag prevents: keying fail-closed on issuer truthiness alone would drop the working endpoints the moment the server learned its issuer.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( carry_forward_resolved_oauth_endpoints, ) @@ -9799,7 +9798,7 @@ class TestMCPServerTimestamps: """The corroboration check must not fail on formatting-only differences an IdP legitimately emits: default port, trailing slash, host case, and query string are not identity, but a non-default port is.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _normalized_authorize_endpoint, ) @@ -9813,7 +9812,7 @@ class TestMCPServerTimestamps: """Issuer equality tolerates only URL-insignificant differences (scheme/host case, default port, a trailing slash). A different host, a non-string, an empty string, or a None issuer never matches, so a document that omits issuer fails closed under issuer-anchored discovery.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _issuer_matches + from litellm.proxy.mcp_server.mcp_server_manager import _issuer_matches assert _issuer_matches("https://mcp.slack.com", "https://mcp.slack.com") assert not _issuer_matches("https://MCP.slack.com/", "https://mcp.slack.com") @@ -10340,7 +10339,7 @@ class TestLegacyDelegateAuthWarningLog: def test_warn_skipped_for_client_credentials(self, caplog): caplog.set_level(logging.WARNING, logger="LiteLLM") - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _warn_legacy_delegate_auth_if_applicable, ) @@ -10795,7 +10794,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock() with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): result = await manager._fetch_single_authorization_server_metadata( @@ -10823,7 +10822,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): servers, scopes = await manager._fetch_oauth_metadata_from_resource( @@ -10846,7 +10845,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock() with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): servers, scopes = await manager._fetch_oauth_metadata_from_resource( @@ -10865,7 +10864,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock() with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): servers, scopes = await manager._fetch_oauth_metadata_from_resource( @@ -10893,7 +10892,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock() with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): servers, scopes = await manager._fetch_oauth_metadata_from_resource( @@ -10916,7 +10915,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock() with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): servers, scopes = await manager._fetch_oauth_metadata_from_resource( @@ -10942,7 +10941,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock() with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): servers, scopes = await manager._fetch_oauth_metadata_from_resource( @@ -10973,7 +10972,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock(return_value=redirect_response) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): result = await manager._fetch_single_authorization_server_metadata( @@ -11007,7 +11006,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock(side_effect=fake_get) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): await manager._fetch_oauth_metadata_from_resource( @@ -11038,7 +11037,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock(side_effect=fake_get) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): await manager._fetch_single_authorization_server_metadata( @@ -11057,7 +11056,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock() with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): result = await manager._fetch_single_authorization_server_metadata( @@ -11130,10 +11129,10 @@ class TestApprovalStatusGate: async def test_update_server_eviction_clears_openapi_routing_artifacts(self, tmp_path): """Rejecting a server must remove its OpenAPI tools and name mappings.""" - from litellm.proxy._experimental.mcp_server.tool_registry import ( + from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( add_server_prefix_to_name, get_server_prefix, ) @@ -11315,7 +11314,7 @@ class TestUserEnvVarsCacheEviction: @staticmethod def _patch_cache(monkeypatch, max_size): - from litellm.proxy._experimental.mcp_server import mcp_server_manager as m + from litellm.proxy.mcp_server import mcp_server_manager as m cache: Dict[Any, Any] = {} monkeypatch.setattr(m, "_user_env_vars_cache", cache) @@ -11553,7 +11552,7 @@ class TestCreateMcpClientV2Graft: return MCPServer(**base) async def test_none_mode_resolves_to_noop_auth(self): - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( NoOpAuth, ) @@ -11590,7 +11589,7 @@ class TestCreateMcpClientV2Graft: ], ) async def test_static_family_emits_expected_header(self, auth_type, token, expected_name, expected_value): - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) @@ -11606,7 +11605,7 @@ class TestCreateMcpClientV2Graft: async def test_basic_mode_base64_encodes(self): import base64 - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) @@ -11622,16 +11621,16 @@ class TestCreateMcpClientV2Graft: async def test_m2m_client_credentials_resolves_via_v2(self): # M2M (oauth2 client_credentials) is migrated: to_server_spec owns the server and the # v2 arm mints the token through the injected source; nothing flows to v1's auth_value. - from litellm.proxy._experimental.mcp_server.outbound_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials import ( UpstreamCredentialProvider, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.client_credentials import ( ClientCredentialsBearerAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( + from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok class _FakeM2MSource: async def get(self, server_id, config): @@ -11699,8 +11698,8 @@ class TestCreateMcpClientV2Graft: assert client._mcp_auth_value == "k-stdio" async def test_resolver_error_maps_to_http_exception(self): - from litellm.proxy._experimental.mcp_server.outbound_credentials import Error - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( + from litellm.proxy.mcp_server.outbound_credentials import Error + from litellm.proxy.mcp_server.outbound_credentials.types import ( CredError, ) @@ -11740,7 +11739,7 @@ class TestCreateMcpClientV2Graft: assert client._get_auth_headers()["Authorization"] == "Bearer hook-jwt" async def test_none_with_extra_header_stays_v2_without_clobbering(self): - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( NoOpAuth, ) @@ -11780,7 +11779,7 @@ class TestMCPToolsListAuthSurfacing: @pytest.mark.asyncio async def test_fetch_tools_with_timeout_surfaces_upstream_401(self): - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) @@ -11832,7 +11831,7 @@ class TestMCPToolsListAuthSurfacing: @pytest.mark.asyncio async def test_get_tools_from_server_surfaces_unusable_user_token(self): - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) @@ -11884,7 +11883,7 @@ class TestMCPToolsListAuthSurfacing: answered 401 without the WWW-Authenticate the client needs to start the OAuth flow.""" import httpx - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) @@ -11916,7 +11915,7 @@ class TestMCPToolsListAuthSurfacing: would fail the RFC 9728 resource match against the gateway URL it dialed.""" import httpx - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) from litellm.types.mcp import MCPAuth @@ -11954,7 +11953,7 @@ class TestMCPToolsListAuthSurfacing: clients at the upstream protected-resource metadata, which fails the RFC 9728 resource match against the gateway URL they dialed. Stripping it makes the single-server route fabricate the gateway well-known challenge, whose content is the bridge facade.""" - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) from litellm.types.mcp import MCPAuth @@ -11982,7 +11981,7 @@ class TestMCPToolsListAuthSurfacing: @pytest.mark.asyncio async def test_get_tools_from_server_suppresses_resolver_challenge_for_dcr_bridge(self): """The client-build-time HTTPException conversion path applies the same suppression.""" - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) from litellm.types.mcp import MCPAuth @@ -12011,7 +12010,7 @@ class TestMCPToolsListAuthSurfacing: @pytest.mark.asyncio async def test_aggregate_list_tools_absorbs_unauthenticated_server(self): - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) @@ -12096,7 +12095,7 @@ class _RetryFakeClient: """A fake MCPClient whose call_tool fails on the first attempt and (optionally) succeeds after.""" def __init__(self, *, raises=None, result=None) -> None: - from litellm.experimental_mcp_client.client import MCPClient + from litellm.mcp_client.client import MCPClient self._raises = raises self._result = result @@ -12175,7 +12174,7 @@ class TestOBOCallToolRetry: async def test_upstream_401_on_id_jag_evicts_the_cached_bearer_and_retries(self): """The retry path must invalidate the ID-JAG leg-2 bearer too: without eviction the rebuilt client resolves the same rejected token from the cache and the retry 401s identically.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( + from litellm.proxy.mcp_server.outbound_credentials.types import ( IdJagConfig, ) @@ -12300,7 +12299,7 @@ class TestOBOCallToolRetry: @pytest.mark.asyncio async def test_session_closed_by_a_peers_refresh_retries_on_a_fresh_session_without_invalidating(self) -> None: - from litellm.experimental_mcp_client.client import UpstreamSessionClosedError + from litellm.mcp_client.client import UpstreamSessionClosedError manager: Final = self._manager() success: Final = CallToolResult(content=[], isError=False) @@ -12608,7 +12607,7 @@ class TestOBOEndpointDiscovery: with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ), patch.object(manager, "_fetch_oauth_metadata_from_resource", AsyncMock(return_value=([], None))), @@ -12633,8 +12632,8 @@ async def test_preflight_challenge_carries_step_up_error_and_claims(): claims in the single-server 401 challenge, so an MSAL-family client can drive the step-up and retry.""" import base64 - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import CredError + from litellm.proxy.mcp_server.outbound_credentials.result import Error + from litellm.proxy.mcp_server.outbound_credentials.types import CredError claims = '{"access_token":{"acrs":{"essential":true,"value":"c1"}}}' @@ -12671,7 +12670,7 @@ async def test_preflight_challenge_carries_step_up_error_and_claims(): async def test_aggregate_list_still_absorbs_step_up_challenged_server(): """A step-up (claims-bearing) 401 from one server must not change the aggregate contract: the multi-server listing still absorbs it and returns the healthy servers' tools.""" - from litellm.proxy._experimental.mcp_server.exceptions import MCPUpstreamAuthError + from litellm.proxy.mcp_server.exceptions import MCPUpstreamAuthError manager = MCPServerManager() good = MCPServer(server_id="good", name="good", transport=MCPTransport.http) @@ -13093,7 +13092,7 @@ async def test_resolve_toolset_tool_permissions_single_db_fetch_across_checks(): key's toolsets during one request; the shared cache must dedupe the DB fetch so the request costs a single toolset query however many checks run""" from litellm.caching.caching import DualCache - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -13104,7 +13103,7 @@ async def test_resolve_toolset_tool_permissions_single_db_fetch_across_checks(): with ( patch( - "litellm.proxy._experimental.mcp_server.toolset_db.list_mcp_toolsets", + "litellm.proxy.mcp_server.toolset_db.list_mcp_toolsets", list_toolsets_mock, ), patch("litellm.proxy.proxy_server.prisma_client", MagicMock()), @@ -13124,7 +13123,7 @@ async def test_resolve_toolset_tool_permissions_fresh_policy_sees_writer_revocat request even though the legacy cache still holds the old grant, and the fresh read must go to the writer, not the replica""" from litellm.caching.caching import DualCache - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -13137,7 +13136,7 @@ async def test_resolve_toolset_tool_permissions_fresh_policy_sees_writer_revocat with ( patch( - "litellm.proxy._experimental.mcp_server.toolset_db.list_mcp_toolsets", + "litellm.proxy.mcp_server.toolset_db.list_mcp_toolsets", list_toolsets_mock, ), patch("litellm.proxy.proxy_server.prisma_client", MagicMock()), @@ -13162,7 +13161,7 @@ async def test_resolve_toolset_tool_permissions_fresh_policy_propagates_db_fault """A fresh read that fails must raise so the managed-agent boundary fails closed; the legacy path keeps its swallow-to-empty behaviour""" from litellm.caching.caching import DualCache - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -13171,7 +13170,7 @@ async def test_resolve_toolset_tool_permissions_fresh_policy_propagates_db_fault with ( patch( - "litellm.proxy._experimental.mcp_server.toolset_db.list_mcp_toolsets", + "litellm.proxy.mcp_server.toolset_db.list_mcp_toolsets", list_toolsets_mock, ), patch("litellm.proxy.proxy_server.prisma_client", MagicMock()), @@ -13191,10 +13190,10 @@ class TestMaterializeAuthHeaders: @pytest.mark.asyncio async def test_static_header_auth_materializes_its_header(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _materialize_auth_headers, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) @@ -13203,13 +13202,13 @@ class TestMaterializeAuthHeaders: @pytest.mark.asyncio async def test_client_credentials_bearer_auth_materializes_bearer(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _materialize_auth_headers, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.client_credentials import ( ClientCredentialsBearerAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( + from litellm.proxy.mcp_server.outbound_credentials.types import ( ClientCredentialsConfig, ) @@ -13224,13 +13223,13 @@ class TestMaterializeAuthHeaders: async def test_materialize_follows_the_minted_token_to_a_custom_header(self): # The OpenAPI arm reads header_name off the auth object rather than assuming Authorization, # so it carries the knob with no per-arm change. This pins that it stays that way. - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _materialize_auth_headers, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.client_credentials import ( ClientCredentialsBearerAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( + from litellm.proxy.mcp_server.outbound_credentials.types import ( ClientCredentialsConfig, ) @@ -13243,10 +13242,10 @@ class TestMaterializeAuthHeaders: @pytest.mark.asyncio async def test_noop_and_none_materialize_to_none(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _materialize_auth_headers, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( NoOpAuth, ) @@ -13367,7 +13366,7 @@ class TestDiscoveryFailureLogging: secret_url = "https://typo-host.example.com/mcp/s/PATHSECRET/mcp" with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=self._connect_error_client(secret_url), ), caplog.at_level(logging.WARNING, logger="LiteLLM"), @@ -13387,7 +13386,7 @@ class TestDiscoveryFailureLogging: url = "https://typo-host.example.com/mcp" with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=self._connect_error_client(url), ), caplog.at_level(logging.WARNING, logger="LiteLLM"), @@ -13404,7 +13403,7 @@ class TestDiscoveryFailureLogging: client.get = AsyncMock(return_value=httpx.Response(404, request=httpx.Request("GET", url))) with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=client, ), caplog.at_level(logging.WARNING, logger="LiteLLM"), @@ -13731,7 +13730,7 @@ class TestServerToolListsHonorThePrefixBoundary: @pytest.mark.asyncio async def test_wire_form_allowlist_entry_follows_a_non_default_separator(self): - from litellm.proxy._experimental.mcp_server import utils as mcp_utils + from litellm.proxy.mcp_server import utils as mcp_utils server = self._aliased_server(allowed_tools=["petstore__getpetbyid"]) @@ -13885,7 +13884,7 @@ class TestOpenAPIRegistryKeyMatchesRegistration: @staticmethod def _register(server: MCPServer, base_tool_name: str) -> str: - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( add_server_prefix_to_name, get_server_prefix, ) @@ -13893,7 +13892,7 @@ class TestOpenAPIRegistryKeyMatchesRegistration: return add_server_prefix_to_name(base_tool_name, get_server_prefix(server)) async def _call(self, server: MCPServer, registered_key: str, bare_tool_name: str) -> CallToolResult: - from litellm.proxy._experimental.mcp_server.tool_registry import ( + from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) @@ -13967,7 +13966,7 @@ class TestOpenAPIRegistryKeyMatchesRegistration: @pytest.mark.asyncio async def test_dispatch_follows_a_non_default_prefix_separator(self): - from litellm.proxy._experimental.mcp_server import utils as mcp_utils + from litellm.proxy.mcp_server import utils as mcp_utils server = MCPServer( server_id="dd7f2b9e-2c4a-4f1b-9e0a-8d3c6b5a4f21", @@ -14092,20 +14091,20 @@ class TestSessionResourceScopeIntersect: return auth def test_scope_reader_is_none_for_keys_and_unscoped_subjects(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager assert MCPServerManager._admitted_session_resource_scope(None) is None assert MCPServerManager._admitted_session_resource_scope(UserAPIKeyAuth(user_id="u")) is None assert MCPServerManager._admitted_session_resource_scope(self._admitted_auth(None)) is None def test_scope_reader_returns_sealed_scope_for_admitted_subjects(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager assert MCPServerManager._admitted_session_resource_scope(self._admitted_auth("b")) == frozenset({"b"}) def test_scope_reader_returns_all_sealed_server_ids(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager auth = self._admitted_auth("first") auth.mcp_session_resource_server_ids = ("first", "second") @@ -14119,8 +14118,8 @@ class TestSessionResourceScopeIntersect: single-exit shape, the old early return would hand a per-server bearer the registry.""" from unittest.mock import AsyncMock, patch - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import LitellmUserRoles + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -14148,8 +14147,8 @@ class TestSessionResourceScopeIntersect: async def test_admin_registry_seed_keeps_both_servers_in_a_multi_server_session(self): from unittest.mock import AsyncMock, patch - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import LitellmUserRoles + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -14184,14 +14183,14 @@ class TestSessionResourceScopeIntersect: than the whole set.""" from unittest.mock import AsyncMock, patch - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager = MCPServerManager() auth = self._admitted_auth("granted-id") with ( patch.object(MCPServerManager, "get_allow_all_keys_server_ids", return_value=["open-id", "granted-id"]), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_allowed_mcp_servers", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_allowed_mcp_servers", new_callable=AsyncMock, return_value=["granted-id", "other-id"], ), @@ -14208,7 +14207,7 @@ class TestSessionResourceScopeIntersect: with ( patch.object(MCPServerManager, "get_allow_all_keys_server_ids", return_value=["open-id", "granted-id"]), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_allowed_mcp_servers", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_allowed_mcp_servers", new_callable=AsyncMock, side_effect=RuntimeError("resolver down"), ), @@ -14281,7 +14280,7 @@ class TestClientForwardedDiscoveryFailureIsNotFatal: {"new": AsyncMock(return_value=None)} if failure == "incomplete" else {"side_effect": never_returns} ) with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.MCP_METADATA_TIMEOUT", 0.01), + patch("litellm.proxy.mcp_server.mcp_server_manager.MCP_METADATA_TIMEOUT", 0.01), patch.object(manager, "_discover_oauth_metadata_for_server", **discovery_patch), ): if not serves_without_endpoints: @@ -14506,8 +14505,8 @@ class TestOpenApiHandlerRelaysUpstreamAuth: @pytest.mark.asyncio async def test_upstream_auth_error_keeps_its_type(self): - from litellm.proxy._experimental.mcp_server.exceptions import MCPUpstreamAuthError - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.exceptions import MCPUpstreamAuthError + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry manager = MCPServerManager() server = self._server() @@ -14526,7 +14525,7 @@ class TestOpenApiHandlerRelaysUpstreamAuth: @pytest.mark.asyncio async def test_other_failures_still_become_an_error_result(self): - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry manager = MCPServerManager() @@ -14556,8 +14555,8 @@ class TestOpenApiHandlerRelaysUpstreamAuth: async def test_json_bodies_keep_verbatim_text_and_gain_structured_content(self, body, compat, expected_structured): """The OpenAPI arm used to stringify the response; now the text block is the upstream body byte for byte, exactly once, and JSON bodies carry structuredContent when the caller's revision admits it.""" - from litellm.proxy._experimental.mcp_server.tool_outcome import WireCompat, parse_http_body - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_outcome import WireCompat, parse_http_body + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry manager = MCPServerManager() @@ -14747,7 +14746,7 @@ class TestConfigServerIdPinning: ) with ( patch( # test-quality-ok: the db reload path has no seam but its own repository - "litellm.proxy._experimental.mcp_server.db.MCPServerRepository", + "litellm.proxy.mcp_server.db.MCPServerRepository", return_value=repository, ), patch( # test-quality-ok: same, the prisma client is fetched inside the reload @@ -15203,8 +15202,8 @@ class TestLitellmAdmissionKeyIsNeverTheSubjectToken: @staticmethod def _recording_provider() -> MagicMock: - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth + from litellm.proxy.mcp_server.outbound_credentials.result import Ok provider: Final = MagicMock() provider.resolve_credentials = AsyncMock( @@ -15504,8 +15503,7 @@ async def test_pre_call_tool_check_honors_guardrail_attached_to_key(monkeypatch, @pytest.mark.asyncio async def test_pre_call_tool_check_stamps_personal_key_team_rpm_limits(monkeypatch: pytest.MonkeyPatch) -> None: import litellm - - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler manager: Final = MCPServerManager() server: Final = MCPServer( @@ -15544,7 +15542,7 @@ async def test_pre_call_tool_check_stamps_personal_key_team_rpm_limits(monkeypat @pytest.mark.asyncio async def test_pre_call_tool_check_uses_inherited_team_auth_for_guardrails(monkeypatch: pytest.MonkeyPatch) -> None: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler server: Final = MCPServer( server_id="srv-guardrails", @@ -15610,7 +15608,7 @@ async def test_pre_call_tool_check_uses_inherited_team_auth_for_guardrails(monke @pytest.mark.asyncio async def test_pre_call_tool_check_keeps_native_name_for_team_attribution(monkeypatch: pytest.MonkeyPatch) -> None: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler server: Final = MCPServer( server_id="math-a", @@ -15711,10 +15709,10 @@ async def test_pre_call_tool_check_keeps_original_auth_for_team_key(monkeypatch: @pytest.mark.asyncio async def test_call_tool_passes_attributed_auth_to_guardrail_hooks(monkeypatch: pytest.MonkeyPatch) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy._experimental.mcp_server.operations import _run_post_mcp_call_guardrails - from litellm.proxy.auth import auth_checks from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable, LiteLLM_UserTable + from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.operations import _run_post_mcp_call_guardrails original_auth: Final = UserAPIKeyAuth(api_key="sk-personal", user_id="alice") team: Final = LiteLLM_TeamTable( @@ -15826,13 +15824,12 @@ async def test_call_tool_passes_attributed_auth_to_guardrail_hooks(monkeypatch: async def test_virtual_mcp_calls_use_attributed_auth_for_logging_and_hooks(monkeypatch: pytest.MonkeyPatch) -> None: from mcp.types import CallToolResult, Tool - from litellm.proxy._experimental.mcp_server import operations, tool_search - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry from litellm.proxy import proxy_server + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable, LiteLLM_UserTable from litellm.proxy.auth import auth_checks - from litellm.proxy._types import LiteLLM_ObjectPermissionTable - from litellm.proxy._types import LiteLLM_TeamTable, LiteLLM_UserTable + from litellm.proxy.mcp_server import operations, tool_search + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry from litellm.types.mcp_server.tool_registry import MCPTool original_auth: Final = UserAPIKeyAuth( @@ -15971,13 +15968,13 @@ async def test_debug_resolution_matches_final_header_conflict_winner( expected_source: str, expected_authorization: str | None, ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var - from starlette.requests import Request from pydantic import SecretStr + from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.auth.litellm_auth_handler import MCPAuthenticatedUser - from litellm.proxy._experimental.mcp_server.mcp_debug import MCP_AUTH_DIAGNOSTICS_SCOPE_KEY, MCPAuthDiagnostics - from litellm.proxy._experimental.mcp_server.outbound_credentials import ( + from litellm.proxy.mcp_server.auth.litellm_auth_handler import MCPAuthenticatedUser + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server.mcp_debug import MCP_AUTH_DIAGNOSTICS_SCOPE_KEY, MCPAuthDiagnostics + from litellm.proxy.mcp_server.outbound_credentials import ( ApiKeyConfig, AuthorizationCodeConfig, NoneConfig, @@ -15985,7 +15982,7 @@ async def test_debug_resolution_matches_final_header_conflict_winner( SharedKey, UpstreamCredentialProvider, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import OAuthToken + from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import OAuthToken from litellm.types.mcp_server.mcp_server_manager import MCPServer class Store: @@ -16041,10 +16038,10 @@ async def test_debug_reports_legacy_signing_and_non_http_transport( _mcp_request_ctx, monkeypatch, transport: Literal["http", "stdio"] ) -> None: monkeypatch.setenv("LITELLM_ENABLE_MCP_STDIO", "true") - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.mcp_debug import MCP_AUTH_DIAGNOSTICS_SCOPE_KEY, MCPAuthDiagnostics + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server.mcp_debug import MCP_AUTH_DIAGNOSTICS_SCOPE_KEY, MCPAuthDiagnostics from litellm.types.mcp_server.mcp_server_manager import MCPServer diagnostics = MCPAuthDiagnostics() @@ -16255,7 +16252,7 @@ async def test_openapi_health_coalesces_concurrent_checks_and_reuses_results(res @pytest.mark.asyncio async def test_openapi_health_cache_expires_at_thirty_seconds(respx_mock, monkeypatch): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _OpenAPIHealthProbe + from litellm.proxy.mcp_server.mcp_server_manager import _OpenAPIHealthProbe monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") clock = iter([0.0, 29.0, 30.0, 30.0]) @@ -16350,8 +16347,8 @@ class _DiscoveryClock: return self.now -from pydantic import TypeAdapter from mcp.types import JSONRPCMessage, ListPromptsResult, ListResourcesResult, ListResourceTemplatesResult +from pydantic import TypeAdapter _JSONRPC_ADAPTER = TypeAdapter(JSONRPCMessage) @@ -16359,7 +16356,7 @@ _JSONRPC_ADAPTER = TypeAdapter(JSONRPCMessage) @contextlib.contextmanager def _mcp_upstream(respond): """Drive the SDK's streamable-HTTP transport off an httpx2 MockTransport; respx only sees httpx.""" - from litellm.experimental_mcp_client.client import MCPClient + from litellm.mcp_client.client import MCPClient def make_client(self, *args, **kwargs): return httpx2.AsyncClient( @@ -16792,7 +16789,7 @@ async def test_discovery_cache_can_be_disabled(monkeypatch: pytest.MonkeyPatch) "value,expected", (("invalid", 60.0), ("nan", 60.0), ("inf", 60.0), ("-1", 60.0), ("12.5", 12.5)) ) def test_discovery_cache_ttl_validation(value: str, expected: float, monkeypatch: pytest.MonkeyPatch) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _mcp_discovery_cache_ttl + from litellm.proxy.mcp_server.mcp_server_manager import _mcp_discovery_cache_ttl monkeypatch.setenv("LITELLM_MCP_DISCOVERY_CACHE_TTL", value) assert _mcp_discovery_cache_ttl() == expected @@ -16811,7 +16808,7 @@ def test_discovery_cache_keys_isolate_user_dependent_auth(auth_type: MCPAuth) -> def _register_local_tool(name: str, description: str) -> None: - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry async def _handler(**kwargs): return None @@ -16829,7 +16826,7 @@ def _openapi_server(name: str) -> MCPServer: @pytest.mark.asyncio async def test_openapi_listing_ignores_overlapping_server_prefix() -> None: - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry manager: Final = MCPServerManager() manager.create_mcp_client = AsyncMock(return_value=AsyncMock()) @@ -16850,7 +16847,7 @@ async def test_openapi_listing_ignores_overlapping_server_prefix() -> None: @pytest.mark.asyncio async def test_openapi_listing_finds_tools_registered_under_the_normalized_prefix() -> None: - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry manager: Final = MCPServerManager() manager.create_mcp_client = AsyncMock(return_value=AsyncMock()) @@ -16866,7 +16863,7 @@ async def test_openapi_listing_finds_tools_registered_under_the_normalized_prefi @pytest.mark.asyncio async def test_discovery_cache_retries_cancelled_fetches() -> None: - from litellm.proxy._experimental.mcp_server.catalog import _DiscoveryCache + from litellm.proxy.mcp_server.catalog import _DiscoveryCache cache: Final = _DiscoveryCache[ListPromptsResult](60, _DiscoveryClock(), TypeAdapter(ListPromptsResult)) @@ -16883,7 +16880,7 @@ async def test_discovery_cache_retries_cancelled_fetches() -> None: @pytest.mark.asyncio async def test_discovery_cache_cancels_fetch_when_last_waiter_leaves() -> None: - from litellm.proxy._experimental.mcp_server.catalog import _DiscoveryCache + from litellm.proxy.mcp_server.catalog import _DiscoveryCache cache: Final = _DiscoveryCache[ListPromptsResult](60, _DiscoveryClock(), TypeAdapter(ListPromptsResult)) entered: Final = asyncio.Event() @@ -16912,7 +16909,7 @@ async def test_discovery_cache_cancels_fetch_when_last_waiter_leaves() -> None: @pytest.mark.asyncio async def test_discovery_cache_bounds_detached_fetches_without_dropping_results() -> None: - from litellm.proxy._experimental.mcp_server.catalog import _DiscoveryCache + from litellm.proxy.mcp_server.catalog import _DiscoveryCache cache: Final = _DiscoveryCache[ListPromptsResult](60, _DiscoveryClock(), TypeAdapter(ListPromptsResult)) entered: Final[asyncio.Queue[None]] = asyncio.Queue() @@ -16944,10 +16941,11 @@ async def test_discovery_cache_bounds_detached_fetches_without_dropping_results( @pytest.mark.asyncio async def test_discovery_cache_tracks_resolved_credentials_across_workers() -> None: import respx - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth - from litellm.proxy._experimental.mcp_server.outbound_credentials.resolver import UpstreamCredentialProvider - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error, Ok, Result - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import CredError, ServerSpec, Subject + + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth + from litellm.proxy.mcp_server.outbound_credentials.resolver import UpstreamCredentialProvider + from litellm.proxy.mcp_server.outbound_credentials.result import Error, Ok, Result + from litellm.proxy.mcp_server.outbound_credentials.types import CredError, ServerSpec, Subject class CredentialSource(UpstreamCredentialProvider): def __init__(self) -> None: @@ -17020,7 +17018,8 @@ async def test_discovery_cache_tracks_resolved_credentials_across_workers() -> N @pytest.mark.asyncio async def test_discovery_resolves_stored_oauth_for_the_requesting_user() -> None: import respx - from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import OAuthToken + + from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import OAuthToken class TokenStore: def __init__(self) -> None: @@ -17058,7 +17057,7 @@ async def test_discovery_resolves_stored_oauth_for_the_requesting_user() -> None @pytest.mark.asyncio async def test_discovery_cache_evicts_results_at_capacity() -> None: - from litellm.proxy._experimental.mcp_server.catalog import _DiscoveryCache + from litellm.proxy.mcp_server.catalog import _DiscoveryCache cache: Final = _DiscoveryCache[ListPromptsResult](60, _DiscoveryClock(), TypeAdapter(ListPromptsResult)) @@ -17076,7 +17075,7 @@ async def test_discovery_cache_evicts_results_at_capacity() -> None: @pytest.mark.asyncio async def test_discovery_cache_invalidation_preserves_other_servers_and_pending_fetches() -> None: - from litellm.proxy._experimental.mcp_server.catalog import _DiscoveryCache + from litellm.proxy.mcp_server.catalog import _DiscoveryCache cache: Final = _DiscoveryCache[ListPromptsResult](60, _DiscoveryClock(), TypeAdapter(ListPromptsResult)) entered: Final = asyncio.Event() @@ -17108,7 +17107,7 @@ async def test_discovery_cache_invalidation_preserves_other_servers_and_pending_ @pytest.mark.asyncio @pytest.mark.parametrize("description", ("x" * 96_000, "é" * 40_000), ids=("ascii", "unicode")) async def test_discovery_cache_returns_oversized_results_without_retaining_them(description: str) -> None: - from litellm.proxy._experimental.mcp_server.catalog import _DiscoveryCache + from litellm.proxy.mcp_server.catalog import _DiscoveryCache cache: Final = _DiscoveryCache[ListPromptsResult](60, _DiscoveryClock(), TypeAdapter(ListPromptsResult)) fetch: Final = AsyncMock( @@ -17141,9 +17140,9 @@ class TestProtectedCredentialPreparation: credential: str | None, dispatch: str, ) -> None: - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.server import _handle_local_mcp_tool - from litellm.proxy._experimental.mcp_server.utils import add_server_prefix_to_name, get_server_prefix + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.server import _handle_local_mcp_tool + from litellm.proxy.mcp_server.utils import add_server_prefix_to_name, get_server_prefix spec_path: Final = tmp_path / "openapi.json" spec_path.write_text( @@ -17433,7 +17432,7 @@ class TestProtectedCredentialPreparation: forwarded: dict[str, str] | None, caller: str | None, ) -> None: - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( create_tool_function, request_auth_header, request_extra_headers, @@ -17465,8 +17464,9 @@ class TestProtectedCredentialPreparation: @pytest.mark.asyncio async def test_static_resolution_cancellation_closes_flow(self) -> None: from collections.abc import AsyncGenerator - from litellm.experimental_mcp_client.client import MCPClient - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import prepare_mcp_client + + from litellm.mcp_client.client import MCPClient + from litellm.proxy.mcp_server.outbound_credentials.adapter import prepare_mcp_client class CancelledAuth(httpx.Auth): closed = False @@ -17730,8 +17730,8 @@ class TestProtectedCredentialPreparation: @pytest.mark.asyncio @pytest.mark.parametrize("selected", [False, True]) async def test_request_selected_during_guardrail_runs_concurrently_with_tool(monkeypatch, selected): + from litellm.proxy.mcp_server import tool_registry from litellm.responses.mcp.request_context import MCPRequestContext - from litellm.proxy._experimental.mcp_server import tool_registry tool_started = asyncio.Event() guardrail_started = asyncio.Event() @@ -17809,8 +17809,9 @@ async def test_server_response_identifies_read_only_config(in_config, in_db, exp @pytest.mark.parametrize("with_caller,legacy_factory", [(True, False), (False, False), (True, True)]) async def test_client_sampling_does_not_fill_explicit_context_from_another_ambient_caller(with_caller, legacy_factory): from mcp.server.auth.middleware.auth_context import auth_context_var - from litellm.proxy._experimental.mcp_server import server as legacy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _create_sampling_callback + + from litellm.proxy.mcp_server import server as legacy_server + from litellm.proxy.mcp_server.mcp_server_manager import _create_sampling_callback upstream = MCPServer( server_id="explicit-empty", @@ -17828,8 +17829,8 @@ async def test_client_sampling_does_not_fill_explicit_context_from_another_ambie client_ip="192.0.2.99", ) with ( - patch("litellm.proxy._experimental.mcp_server.upstream.MCPClient") as factory, - patch("litellm.proxy._experimental.mcp_server.sampling_handler.handle_sampling_create_message", sampling), + patch("litellm.proxy.mcp_server.upstream.MCPClient") as factory, + patch("litellm.proxy.mcp_server.sampling_handler.handle_sampling_create_message", sampling), ): if legacy_factory: callback = _create_sampling_callback(user_api_key_auth=UserAPIKeyAuth(user_id="explicit")) @@ -18106,6 +18107,7 @@ async def test_catalog_delete_drops_derived_tool_mapping(monkeypatch): @pytest.mark.parametrize("rediscover", [False, True]) async def test_catalog_publishes_rediscovered_routes_despite_concurrent_owner_change(monkeypatch, rediscover): from mcp.types import Tool + from litellm.proxy import proxy_server monkeypatch.setattr(proxy_server, "prisma_client", None) @@ -18165,7 +18167,7 @@ async def test_catalog_reload_preserves_concurrent_config_discovery_and_routes(a with ( patch("litellm.proxy.proxy_server.prisma_client", prisma), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.hydrate_config_server_dcr_client", + "litellm.proxy.mcp_server.discoverable_endpoints.hydrate_config_server_dcr_client", side_effect=hydrate, ), ): @@ -18247,7 +18249,7 @@ async def test_catalog_operation_retains_routes_only_for_same_configured_target( @pytest.mark.parametrize("change", ["concurrent", "staged", "deleted", "staged_after_delete", "staged_with_concurrent"]) @pytest.mark.parametrize("mapped", [False, True]) async def test_catalog_reload_keeps_new_route_owner_over_earlier_route(change, mapped, monkeypatch): - from litellm.proxy._experimental.mcp_server import tool_registry + from litellm.proxy.mcp_server import tool_registry manager: Final = MCPServerManager() registry: Final = tool_registry.MCPToolRegistry() @@ -18377,7 +18379,8 @@ async def test_catalog_reload_retains_routes_discovered_for_a_late_server(change from datetime import timedelta from mcp.types import Tool - from litellm.proxy._experimental.mcp_server import tool_registry + + from litellm.proxy.mcp_server import tool_registry row: Final = LiteLLM_MCPServerTable( server_id="late-routes", @@ -18453,7 +18456,7 @@ async def test_catalog_reload_retains_routes_discovered_for_a_late_server(change async def test_catalog_openapi_refresh_does_not_restore_removed_operations( tmp_path, monkeypatch, respx_mock, retain_operation ): - from litellm.proxy._experimental.mcp_server import tool_registry + from litellm.proxy.mcp_server import tool_registry monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") manager: Final = MCPServerManager() @@ -18493,7 +18496,7 @@ async def test_catalog_openapi_refresh_does_not_restore_removed_operations( if retain_operation: assert manager.server_exposes_tool(manager.registry[row.server_id], "spec_refresh-retained") assert retained is not None - from litellm.proxy._experimental.mcp_server.tool_outcome import JsonResult + from litellm.proxy.mcp_server.tool_outcome import JsonResult retained_result = await retained.handler() assert isinstance(retained_result, JsonResult) @@ -18609,7 +18612,8 @@ async def test_catalog_background_lookup_after_operation_exit_observes_deletion( @pytest.mark.asyncio async def test_catalog_cancelled_openapi_refresh_retains_tools_and_discovery(monkeypatch): from datetime import timedelta - from litellm.proxy._experimental.mcp_server import tool_registry + + from litellm.proxy.mcp_server import tool_registry manager: Final = MCPServerManager() stamp: Final = datetime.now() @@ -18697,7 +18701,7 @@ async def test_catalog_snapshot_identity_is_independent_of_worker_oauth_discover @pytest.mark.asyncio async def test_catalog_failed_openapi_row_does_not_publish_partial_handlers(monkeypatch): - from litellm.proxy._experimental.mcp_server import tool_registry + from litellm.proxy.mcp_server import tool_registry manager: Final = MCPServerManager() registry: Final = tool_registry.MCPToolRegistry() @@ -18744,7 +18748,7 @@ async def test_catalog_unchanged_read_preserves_derived_initialize_instructions( @pytest.mark.asyncio async def test_catalog_reuses_openapi_tools_until_configuration_or_background_refresh(monkeypatch, tmp_path): - from litellm.proxy._experimental.mcp_server import openapi_to_mcp_generator, tool_registry + from litellm.proxy.mcp_server import openapi_to_mcp_generator, tool_registry registry = tool_registry.MCPToolRegistry() monkeypatch.setattr(tool_registry, "global_mcp_tool_registry", registry) @@ -18793,7 +18797,7 @@ async def test_catalog_rejects_configuration_switch_before_client_creation(monke admitted = manager.get_mcp_server_by_id("catalog-server") read_rows.return_value = [_catalog_row("updated")] if change == "edit" else [] await asyncio.create_task(manager.reload_servers_from_database()) - with patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.MCPClient") as factory: + with patch("litellm.proxy.mcp_server.mcp_server_manager.MCPClient") as factory: with pytest.raises(HTTPException) as exc: await manager._create_mcp_client(admitted) assert exc.value.status_code == 503 @@ -18804,8 +18808,8 @@ async def test_catalog_rejects_configuration_switch_before_client_creation(monke @pytest.mark.asyncio @pytest.mark.parametrize("dispatch", ["managed", "local"]) async def test_catalog_changed_openapi_handler_never_dispatches(monkeypatch, tmp_path, respx_mock, dispatch): - from litellm.proxy._experimental.mcp_server import operations, tool_registry - from litellm.proxy._experimental.mcp_server.utils import add_server_prefix_to_name, get_server_prefix + from litellm.proxy.mcp_server import operations, tool_registry + from litellm.proxy.mcp_server.utils import add_server_prefix_to_name, get_server_prefix registry = tool_registry.MCPToolRegistry() monkeypatch.setattr(tool_registry, "global_mcp_tool_registry", registry) @@ -18912,7 +18916,7 @@ async def test_catalog_cancelled_config_hydration_preserves_published_credential raise asyncio.CancelledError() with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.hydrate_config_server_dcr_client", + "litellm.proxy.mcp_server.discoverable_endpoints.hydrate_config_server_dcr_client", side_effect=cancelled_hydration, ): with pytest.raises(asyncio.CancelledError): @@ -19029,7 +19033,7 @@ async def test_catalog_fresh_lookup_does_not_fall_back_to_stale_grants_when_data @pytest.mark.asyncio async def test_catalog_cancelled_registration_does_not_publish_partial_handlers(monkeypatch): - from litellm.proxy._experimental.mcp_server import tool_registry + from litellm.proxy.mcp_server import tool_registry manager = MCPServerManager() registry = tool_registry.MCPToolRegistry() @@ -19681,7 +19685,7 @@ async def test_close_all_upstream_sessions_logs_when_waiting_times_out( await self._never_close.wait() monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.MCP_UPSTREAM_SESSION_SHUTDOWN_TIMEOUT_SECONDS", + "litellm.proxy.mcp_server.mcp_server_manager.MCP_UPSTREAM_SESSION_SHUTDOWN_TIMEOUT_SECONDS", 0.05, ) caplog.set_level(logging.WARNING, logger="LiteLLM") @@ -19776,7 +19780,7 @@ class TestSharedIdentifierPrefixWarning: with ( patch("litellm.proxy.proxy_server.prisma_client", prisma), patch( - "litellm.proxy._experimental.mcp_server.db.MCPServerRepository", + "litellm.proxy.mcp_server.db.MCPServerRepository", return_value=repository, ), patch( @@ -19826,7 +19830,7 @@ async def test_reload_warns_once_about_a_blocked_stdio_row_that_is_rebuilt_every with ( patch("litellm.proxy.proxy_server.prisma_client", prisma), patch( - "litellm.proxy._experimental.mcp_server.db.MCPServerRepository", + "litellm.proxy.mcp_server.db.MCPServerRepository", return_value=repository, ), patch( @@ -20378,7 +20382,7 @@ class TestToolCatalogGuard: @pytest.mark.asyncio @pytest.mark.parametrize("add_prefix", [False, True]) async def test_openapi_catalog_is_scanned_and_pinned_like_an_upstream_listing(self, catalog_guardrail, add_prefix): - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry _, proxy_logging_obj = catalog_guardrail server = MCPServer( @@ -20495,7 +20499,7 @@ async def test_upstream_preparation_preserves_windows_command_and_caller_environ @pytest.mark.asyncio async def test_upstream_preparation_honors_case_sensitive_extra_command(monkeypatch: pytest.MonkeyPatch) -> None: - from litellm.proxy._experimental.mcp_server import upstream + from litellm.proxy.mcp_server import upstream monkeypatch.setenv("LITELLM_ENABLE_MCP_STDIO", "true") monkeypatch.setattr(upstream, "MCP_STDIO_ALLOWED_COMMANDS", frozenset({"CustomRunner"})) @@ -20560,8 +20564,8 @@ async def test_cached_discovery_cannot_authorize_another_servers_local_handler(m from fastapi import HTTPException from mcp.types import Tool - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry _catalog_database(monkeypatch, AsyncMock(return_value=[]), AsyncMock(return_value=_revision_row(7))) manager = MCPServerManager() @@ -20600,7 +20604,7 @@ async def test_cached_discovery_cannot_authorize_another_servers_local_handler(m def test_discovery_preserves_registered_tool_namespaces(monkeypatch, local_handler): from mcp.types import Tool - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry manager = MCPServerManager() allowed = MCPServer(server_id="allowed", name="allowed", transport=MCPTransport.http) @@ -20644,8 +20648,8 @@ async def test_overlapping_server_prefix_cannot_authorize_registered_openapi_han from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry manager = MCPServerManager() private = MCPServer(server_id="private", name="billing", alias="billing", transport=MCPTransport.http) @@ -20735,8 +20739,8 @@ async def test_catalog_revision_failure_preserves_state_and_recovers(monkeypatch @pytest.mark.asyncio @pytest.mark.parametrize("groups", [[], ["catalog-group"]]) async def test_access_group_resolution_uses_the_operation_catalog(monkeypatch, groups): - from litellm.proxy._experimental.mcp_server import mcp_server_manager - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler row = _catalog_row().model_copy(update={"mcp_access_groups": groups}) _catalog_database(monkeypatch, AsyncMock(return_value=[row])) @@ -20771,9 +20775,9 @@ async def test_empty_access_group_scope_cannot_inherit_unrelated_server( ): from types import SimpleNamespace - from litellm.proxy._experimental.mcp_server import mcp_server_manager - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth + from litellm.proxy.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler row = _catalog_row() _catalog_database(monkeypatch, AsyncMock(return_value=[row])) @@ -20935,7 +20939,7 @@ async def test_paginated_listing_keeps_earlier_tool_metadata_and_caller_isolatio from mcp.types import ListToolsResult, PaginatedRequestParams from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import catalog, operations + from litellm.proxy.mcp_server import catalog, operations monkeypatch.setenv("LITELLM_SALT_KEY", "listed-tools-test") monkeypatch.setattr(proxy_server, "prisma_client", None) @@ -21026,9 +21030,9 @@ async def test_aggregate_bounds_each_paginated_server_by_its_own_listing_deadlin from mcp.types import JSONRPCRequest, PaginatedRequestParams from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import catalog, operations - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module - from litellm.proxy._experimental.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR, get_server_prefix + from litellm.proxy.mcp_server import catalog, operations + from litellm.proxy.mcp_server import mcp_server_manager as manager_module + from litellm.proxy.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR, get_server_prefix monkeypatch.setenv("LITELLM_SALT_KEY", "paginated-listing-deadline-test") monkeypatch.setattr(proxy_server, "prisma_client", None) @@ -21093,7 +21097,7 @@ async def test_failed_aggregate_continuation_preserves_only_delivered_tool_metad from mcp.types import ListToolsResult, PaginatedRequestParams from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import catalog, operations + from litellm.proxy.mcp_server import catalog, operations monkeypatch.setenv("LITELLM_SALT_KEY", "failed-listing-test") monkeypatch.setattr(proxy_server, "prisma_client", None) @@ -21136,7 +21140,7 @@ async def test_aggregate_publishes_complete_bare_routes_only_after_delivering_a_ from mcp.types import ListToolsResult, PaginatedRequestParams from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import catalog, operations + from litellm.proxy.mcp_server import catalog, operations monkeypatch.delenv("LITELLM_SALT_KEY", raising=False) if can_seal: @@ -21202,7 +21206,7 @@ def test_discovery_keys_bind_static_auth_to_caller_and_configuration() -> None: @pytest.mark.parametrize("advertised", [False, True]) def test_untrusted_metadata_cannot_enable_cimd_without_matching_authorization_endpoint(advertised): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _restrict_discovery_to_corroborated_authorization_server, ) @@ -21224,8 +21228,8 @@ async def test_manual_oauth_endpoints_discover_client_metadata_once( ) -> None: from starlette.requests import Request - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module - from litellm.proxy._experimental.mcp_server.oauth_utils import get_cimd_client_id + from litellm.proxy.mcp_server import mcp_server_manager as manager_module + from litellm.proxy.mcp_server.oauth_utils import get_cimd_client_id monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") monkeypatch.setenv("LITELLM_MCP_OAUTH_DISCOVERY_ON_STARTUP", "1" if startup else "0") @@ -21347,7 +21351,7 @@ async def test_optional_client_metadata_discovery_failure_preserves_manual_endpo @pytest.mark.parametrize("capability", [True, False]) @pytest.mark.parametrize("rebuild", ["same", "repointed", "fresh_discovery", "anchored"]) def test_oauth_rebuild_retains_only_corroborated_cimd_capability(capability: bool, rebuild: str) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import carry_forward_resolved_oauth_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import carry_forward_resolved_oauth_endpoints previous: Final = MCPServer( server_id="cimd-rebuild", @@ -21437,10 +21441,12 @@ def test_openapi_extra_headers_exclude_gateway_admission_key(header_name: str) - @pytest.mark.asyncio async def test_legacy_upstream_elicitation_rejects_modern_downstream_without_consent() -> None: from types import SimpleNamespace + from mcp.types import ElicitRequestFormParams, ErrorData - from litellm.proxy._experimental.mcp_server import server as legacy_server - from litellm.proxy._experimental.mcp_server.legacy_callbacks import create_elicitation_callback - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var + + from litellm.proxy.mcp_server import server as legacy_server + from litellm.proxy.mcp_server.legacy_callbacks import create_elicitation_callback + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var session: Final = SimpleNamespace(client_params=None) session_token: Final = legacy_server.active_mcp_session_var.set(session) @@ -21450,7 +21456,7 @@ async def test_legacy_upstream_elicitation_rejects_modern_downstream_without_con relay: Final = AsyncMock() try: callback: Final = create_elicitation_callback() - with patch("litellm.proxy._experimental.mcp_server.elicitation_handler.handle_elicitation_request", relay): + with patch("litellm.proxy.mcp_server.elicitation_handler.handle_elicitation_request", relay): result: Final = await callback( None, ElicitRequestFormParams(message="Confirm", requested_schema={"type": "object"}) ) @@ -21536,7 +21542,7 @@ class TestMCPUpstreamRateLimitRetry: self, monkeypatch: pytest.MonkeyPatch ) -> None: monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.MCP_TOOL_LISTING_TIMEOUT", 0.5 + "litellm.proxy.mcp_server.mcp_server_manager.MCP_TOOL_LISTING_TIMEOUT", 0.5 ) manager: Final = MCPServerManager() client: Final = MagicMock() @@ -21579,7 +21585,7 @@ class TestMCPUpstreamRateLimitRetry: self, monkeypatch: pytest.MonkeyPatch ) -> None: monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.MCP_TOOL_LISTING_TIMEOUT", 0.05 + "litellm.proxy.mcp_server.mcp_server_manager.MCP_TOOL_LISTING_TIMEOUT", 0.05 ) manager: Final = MCPServerManager() server: Final = MCPServer(server_id="notes", name="notes", transport=MCPTransport.http) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_tool_calls_and_headers.py b/tests/unit/proxy/mcp_server/test_mcp_server_tool_calls_and_headers.py similarity index 91% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_server_tool_calls_and_headers.py rename to tests/unit/proxy/mcp_server/test_mcp_server_tool_calls_and_headers.py index b8e28c3f9b8..aa61deaf554 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_tool_calls_and_headers.py +++ b/tests/unit/proxy/mcp_server/test_mcp_server_tool_calls_and_headers.py @@ -1,4 +1,3 @@ -from litellm.proxy._experimental.mcp_server import operations as mcp_operations import asyncio import contextlib import contextvars @@ -33,14 +32,15 @@ from mcp_types.version import HANDSHAKE_PROTOCOL_VERSIONS, LATEST_HANDSHAKE_VERS from pydantic import JsonValue, TypeAdapter from starlette.types import Message, Receive, Scope, Send -from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ListedToolsCaller -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import AggregateToolListing from litellm.proxy._types import ( LiteLLM_MCPServerTable, MCPTransport, UserAPIKeyAuth, ) +from litellm.proxy.mcp_server import operations as mcp_operations +from litellm.proxy.mcp_server.faults.list_outcomes import AggregateToolListing +from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var +from litellm.proxy.mcp_server.mcp_server_manager import ListedToolsCaller from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPOAuthMetadata, MCPServer, PinnedMCPTool @@ -50,7 +50,7 @@ def test_mcp_available_on_sdk2(): from packaging.version import Version - from litellm.proxy._experimental.mcp_server.server import MCP_AVAILABLE + from litellm.proxy.mcp_server.server import MCP_AVAILABLE assert Version("2.2.0") <= Version(version("mcp")) < Version("3") assert MCP_AVAILABLE is True @@ -71,7 +71,7 @@ def cleanup_mcp_global_state(): can leak between tests causing mock assertion failures. """ try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -109,7 +109,7 @@ def _paged_params(): async def test_mcp_server_tool_call_body_contains_request_data(_mcp_request_ctx): """Test that proxy_server_request body contains name and arguments""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( mcp_server_tool_call, set_auth_context, ) @@ -147,7 +147,7 @@ async def test_mcp_server_tool_call_body_contains_request_data(_mcp_request_ctx) mock_add_litellm_data_to_request, ): with patch( - "litellm.proxy._experimental.mcp_server.operations.call_mcp_tool", + "litellm.proxy.mcp_server.operations.call_mcp_tool", mock_call_mcp_tool, ): with patch( @@ -171,7 +171,7 @@ async def test_mcp_server_tool_call_forwards_client_headers_to_logging(_mcp_requ """The MCP protocol path must hand the connection's client headers to the pre-call pipeline, so logging callbacks and guardrails see them the way the REST path does.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( mcp_server_tool_call, set_auth_context, ) @@ -203,7 +203,7 @@ async def test_mcp_server_tool_call_forwards_client_headers_to_logging(_mcp_requ mock_add_litellm_data_to_request, ): with patch( - "litellm.proxy._experimental.mcp_server.operations.call_mcp_tool", + "litellm.proxy.mcp_server.operations.call_mcp_tool", mock_call_mcp_tool, ): with patch("litellm.proxy.proxy_server.proxy_config", MagicMock()): @@ -221,11 +221,11 @@ async def test_mcp_server_tool_call_strips_custom_litellm_key_header(_mcp_reques The pre-call pipeline only knows that name if it is passed in, so without it the virtual key reaches metadata.headers and proxy_server_request.headers in plaintext.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.litellm_pre_call_utils import add_litellm_data_to_request + from litellm.proxy.mcp_server.server import ( mcp_server_tool_call, set_auth_context, ) - from litellm.proxy.litellm_pre_call_utils import add_litellm_data_to_request except ImportError: pytest.skip("MCP server not available") @@ -250,7 +250,7 @@ async def test_mcp_server_tool_call_strips_custom_litellm_key_header(_mcp_reques capturing_add_litellm_data_to_request, ): with patch( - "litellm.proxy._experimental.mcp_server.operations.call_mcp_tool", + "litellm.proxy.mcp_server.operations.call_mcp_tool", mock_call_mcp_tool, ): with patch("litellm.proxy.proxy_server.proxy_config", MagicMock()): @@ -274,16 +274,16 @@ async def test_mcp_server_tool_call_relays_upstream_auth_error_as_iserror( ): from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse + from litellm.proxy.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse status_code = 403 if required_scope is not None else 401 send = AsyncMock() response = OAuthScopeResponse(send, "https://gateway.example", "/mcp/pt") request = Request({"type": "http", "headers": [], SCOPE_RESPONSE_KEY: response}) - await response({"type": "http.response.start", "status": 200, "headers": []}) + headers: Final = asyncio.create_task(response({"type": "http.response.start", "status": 200, "headers": []})) try: - from litellm.proxy._experimental.mcp_server.exceptions import MCPUpstreamAuthError - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.exceptions import MCPUpstreamAuthError + from litellm.proxy.mcp_server.server import ( mcp_server_tool_call, set_auth_context, ) @@ -306,11 +306,11 @@ async def test_mcp_server_tool_call_relays_upstream_auth_error_as_iserror( mock_add_litellm_data_to_request, ): with patch( - "litellm.proxy._experimental.mcp_server.operations.call_mcp_tool", + "litellm.proxy.mcp_server.operations.call_mcp_tool", mock_call_mcp_tool, ): with patch("litellm.proxy.proxy_server.proxy_config", MagicMock()): - with patch("litellm.proxy._experimental.mcp_server.operations.verbose_logger", mock_logger): + with patch("litellm.proxy.mcp_server.operations.verbose_logger", mock_logger): result = await mcp_server_tool_call( _mcp_request_ctx(request=request if http_transport else None), _call_tool_params("test_tool", {"param": "value"}), @@ -328,6 +328,7 @@ async def test_mcp_server_tool_call_relays_upstream_auth_error_as_iserror( info_calls = [str(c.args[0]) for c in mock_logger.info.call_args_list if c.args] assert any("Upstream auth failure" in m for m in info_calls) response.allow() + await headers await response({"type": "http.response.body", "body": b"tool error"}) start = send.await_args_list[0].args[0] assert start["status"] == (403 if required_scope is not None else 200) @@ -337,7 +338,7 @@ async def test_mcp_server_tool_call_relays_upstream_auth_error_as_iserror( def test_prepare_mcp_server_headers_case_insensitive_extra_headers(): try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) except ImportError: @@ -367,7 +368,7 @@ def test_prepare_mcp_server_headers_case_insensitive_extra_headers(): def test_prepare_mcp_server_headers_group_header_defaults_for_members_only(): try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) except ImportError: @@ -404,7 +405,7 @@ def test_prepare_mcp_server_headers_group_header_defaults_for_members_only(): def test_prepare_mcp_server_headers_passthrough_strips_authorization_without_admission_header(): try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) except ImportError: @@ -440,7 +441,7 @@ def test_prepare_mcp_server_headers_passthrough_forwards_authorization_for_anony (``user_api_key_auth.api_key is None``) and the ``Authorization`` bearer is the upstream OAuth token — it must be forwarded, not stripped.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) except ImportError: @@ -482,7 +483,7 @@ def test_prepare_mcp_server_headers_passthrough_strips_authorization_for_authent the bearer must still be stripped to avoid leaking the gateway key upstream.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) except ImportError: @@ -518,7 +519,7 @@ def test_prepare_mcp_server_headers_passthrough_strips_authorization_for_authent def test_prepare_mcp_server_headers_oauth2_m2m_omits_litellm_caller_authorization(): """M2M OAuth must not put caller Bearer (LiteLLM API key) into extra_headers (#23652).""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) except ImportError: @@ -552,7 +553,7 @@ def test_prepare_mcp_server_headers_oauth2_interactive_drops_caller_authorizatio caller-supplied bearer must not override another user's stored credential. Non-auth headers are still carried; only the credential is dropped.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) except ImportError: @@ -582,10 +583,10 @@ def test_prepare_mcp_server_headers_oauth2_interactive_drops_caller_authorizatio def test_prepare_mcp_server_headers_legacy_delegate_strips_admission_authorization(): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) - from litellm.proxy._types import UserAPIKeyAuth server = MCPServer( server_id="legacy-delegate-admission", @@ -609,10 +610,10 @@ def test_prepare_mcp_server_headers_legacy_delegate_strips_admission_authorizati def test_prepare_mcp_server_headers_legacy_delegate_preserves_separate_upstream_authorization(): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) - from litellm.proxy._types import UserAPIKeyAuth server = MCPServer( server_id="legacy-delegate-dual-credential", @@ -639,10 +640,10 @@ def test_prepare_mcp_server_headers_legacy_delegate_preserves_separate_upstream_ def test_prepare_mcp_server_headers_legacy_delegate_strips_repeated_admission_key(): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) - from litellm.proxy._types import UserAPIKeyAuth server = MCPServer( server_id="legacy-delegate-repeated-key", @@ -671,7 +672,7 @@ def test_prepare_mcp_server_headers_legacy_delegate_strips_repeated_admission_ke def test_prepare_mcp_server_headers_m2m_skips_authorization_from_raw_extra_headers(): """M2M must not merge caller Authorization from raw_headers when extra_headers lists it.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) except ImportError: @@ -714,7 +715,7 @@ def _client_forwarded_mode_server(server_id: str, auth_type) -> MCPServer: def _prepare_headers_in_scope(server: MCPServer, scope_servers): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) @@ -824,7 +825,7 @@ def test_prepare_mcp_server_headers_sole_consumer_still_forwards_via_extra_heade async def test_call_tool_m2m_skips_authorization_headers(): """M2M call_tool must not forward caller Authorization in oauth2/raw headers.""" try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) except ImportError: @@ -869,7 +870,7 @@ async def test_call_tool_m2m_skips_authorization_headers(): @pytest.mark.asyncio async def test_get_prompts_from_mcp_servers_success(): try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_prompts_from_mcp_servers, ) except ImportError: @@ -895,15 +896,15 @@ async def test_get_prompts_from_mcp_servers_success(): with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", AsyncMock(return_value=[server_a, server_b]), ) as mock_allowed, patch( - "litellm.proxy._experimental.mcp_server.operations._prepare_mcp_server_headers", + "litellm.proxy.mcp_server.operations._prepare_mcp_server_headers", return_value=(None, None), ) as mock_headers, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, ): mock_manager.get_prompts_from_server = AsyncMock( @@ -929,7 +930,7 @@ async def test_get_prompts_from_mcp_servers_success(): @pytest.mark.asyncio async def test_get_resources_from_mcp_servers_success(): try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_resources_from_mcp_servers, ) except ImportError: @@ -955,15 +956,15 @@ async def test_get_resources_from_mcp_servers_success(): with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", AsyncMock(return_value=[server_a, server_b]), ) as mock_allowed, patch( - "litellm.proxy._experimental.mcp_server.operations._prepare_mcp_server_headers", + "litellm.proxy.mcp_server.operations._prepare_mcp_server_headers", return_value=(None, None), ) as mock_headers, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, ): mock_manager.get_resources_from_server = AsyncMock( @@ -1002,7 +1003,7 @@ async def test_get_resources_from_mcp_servers_success(): @pytest.mark.asyncio async def test_get_resource_templates_from_mcp_servers_success(): try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_resource_templates_from_mcp_servers, ) except ImportError: @@ -1020,15 +1021,15 @@ async def test_get_resource_templates_from_mcp_servers_success(): with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", AsyncMock(return_value=[server]), ) as mock_allowed, patch( - "litellm.proxy._experimental.mcp_server.operations._prepare_mcp_server_headers", + "litellm.proxy.mcp_server.operations._prepare_mcp_server_headers", return_value=(None, None), ) as mock_headers, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, ): mock_manager.get_resource_templates_from_server = AsyncMock( @@ -1057,7 +1058,7 @@ async def test_get_resource_templates_from_mcp_servers_success(): @pytest.mark.asyncio async def test_mcp_get_prompt_success(): try: - from litellm.proxy._experimental.mcp_server.server import mcp_get_prompt + from litellm.proxy.mcp_server.server import mcp_get_prompt except ImportError: pytest.skip("MCP server not available") @@ -1070,15 +1071,15 @@ async def test_mcp_get_prompt_success(): with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", AsyncMock(return_value=[server]), ) as mock_allowed, patch( - "litellm.proxy._experimental.mcp_server.operations._prepare_mcp_server_headers", + "litellm.proxy.mcp_server.operations._prepare_mcp_server_headers", return_value=({"Authorization": "token"}, {"X-Test": "1"}), ) as mock_headers, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, ): mock_manager.get_prompt_from_server = AsyncMock(return_value=prompt_result) @@ -1117,7 +1118,7 @@ async def test_mcp_get_prompt_success(): @pytest.mark.asyncio async def test_mcp_read_resource_success(): try: - from litellm.proxy._experimental.mcp_server.server import mcp_read_resource + from litellm.proxy.mcp_server.server import mcp_read_resource except ImportError: pytest.skip("MCP server not available") @@ -1138,15 +1139,15 @@ async def test_mcp_read_resource_success(): with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", AsyncMock(return_value=[server]), ) as mock_allowed, patch( - "litellm.proxy._experimental.mcp_server.operations._prepare_mcp_server_headers", + "litellm.proxy.mcp_server.operations._prepare_mcp_server_headers", return_value=({"Authorization": "token"}, {"X-Test": "1"}), ) as mock_headers, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, ): mock_manager.read_resource_from_server = AsyncMock(return_value=read_result) @@ -1187,7 +1188,8 @@ async def test_mcp_read_resource_success(): ) async def test_read_resource_preserves_content_metadata(_mcp_request_ctx, kind, metadata): from mcp.types import ReadResourceRequestParams - from litellm.proxy._experimental.mcp_server import operations, server + + from litellm.proxy.mcp_server import operations, server uri: Final = "https://example.com/resource" caller: Final = UserAPIKeyAuth(user_id="resource-caller") @@ -1230,7 +1232,7 @@ async def test_read_resource_preserves_content_metadata(_mcp_request_ctx, kind, @pytest.mark.asyncio async def test_mcp_read_resource_multiple_servers_error(): try: - from litellm.proxy._experimental.mcp_server.server import mcp_read_resource + from litellm.proxy.mcp_server.server import mcp_read_resource except ImportError: pytest.skip("MCP server not available") @@ -1242,7 +1244,7 @@ async def test_mcp_read_resource_multiple_servers_error(): server_b.name = "server_b" with patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", AsyncMock(return_value=[server_a, server_b]), ) as mock_allowed: with pytest.raises(HTTPException) as exc_info: @@ -1260,7 +1262,7 @@ async def test_mcp_read_resource_multiple_servers_error(): async def test_get_tools_from_mcp_servers_continues_when_one_server_fails(): """Test that _get_tools_from_mcp_servers continues when one server fails""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) @@ -1332,14 +1334,14 @@ async def test_get_tools_from_mcp_servers_continues_when_one_server_fails(): mock_manager.get_tools_from_server = mock_get_tools_from_server with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): with ( patch( - "litellm.proxy._experimental.mcp_server.catalog.verbose_logger", + "litellm.proxy.mcp_server.catalog.verbose_logger", ) as mock_logger, - patch("litellm.proxy._experimental.mcp_server.operations.verbose_logger", mock_logger), + patch("litellm.proxy.mcp_server.operations.verbose_logger", mock_logger), ): # Test with server-specific auth headers mcp_server_auth_headers = { @@ -1373,7 +1375,7 @@ async def test_get_tools_from_mcp_servers_continues_when_one_server_fails(): async def test_get_tools_from_mcp_servers_handles_all_servers_failing(): """Test that _get_tools_from_mcp_servers handles all servers failing gracefully""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) @@ -1431,14 +1433,14 @@ async def test_get_tools_from_mcp_servers_handles_all_servers_failing(): mock_manager.get_tools_from_server = mock_get_tools_from_server with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): with ( patch( - "litellm.proxy._experimental.mcp_server.catalog.verbose_logger", + "litellm.proxy.mcp_server.catalog.verbose_logger", ) as mock_logger, - patch("litellm.proxy._experimental.mcp_server.operations.verbose_logger", mock_logger), + patch("litellm.proxy.mcp_server.operations.verbose_logger", mock_logger), ): # Test with server-specific auth headers mcp_server_auth_headers = { @@ -1504,15 +1506,15 @@ async def _denied_scoped_list( mock_manager: MagicMock, resolver: AsyncMock, ) -> HTTPException: - from litellm.proxy._experimental.mcp_server.server import _get_tools_from_mcp_servers + from litellm.proxy.mcp_server.server import _get_tools_from_mcp_servers with ( patch( # test-quality-ok: the permission resolver is a module-level function; the suite's only seam - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", resolver, ), patch( # test-quality-ok: the server registry is a module-level singleton; the suite's only seam - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ), ): @@ -1528,7 +1530,7 @@ async def _denied_scoped_list( @pytest.mark.asyncio async def test_scoped_list_denied_by_agent_binding_raises_403_naming_agent(): """The agent-binding veto must raise a 403 naming the agent, never a silent 200 with no tools.""" - pytest.importorskip("litellm.proxy._experimental.mcp_server.server") + pytest.importorskip("litellm.proxy.mcp_server.server") user_api_key_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user", agent_id="agent-123") resolver = _scope_resolver(resolved_without_agent={"github": "srv-github"}) @@ -1551,19 +1553,19 @@ async def test_scoped_list_denied_by_agent_binding_raises_403_naming_agent(): @pytest.mark.asyncio async def test_empty_scope_lists_nothing_instead_of_raising_a_nameless_denial(): """An empty ``x-mcp-servers`` header scopes to no servers; that is an empty listing, not a 403.""" - pytest.importorskip("litellm.proxy._experimental.mcp_server.server") - from litellm.proxy._experimental.mcp_server.server import _get_tools_from_mcp_servers + pytest.importorskip("litellm.proxy.mcp_server.server") + from litellm.proxy.mcp_server.server import _get_tools_from_mcp_servers user_api_key_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user") resolver = AsyncMock(return_value=[]) with ( patch( # test-quality-ok: the permission resolver is a module-level function; the suite's only seam - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", resolver, ), patch( # test-quality-ok: the server registry is a module-level singleton; the suite's only seam - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", _denied_scope_manager({"github": "srv-github"}), ), ): @@ -1578,7 +1580,7 @@ async def test_empty_scope_lists_nothing_instead_of_raising_a_nameless_denial(): @pytest.mark.asyncio async def test_scoped_list_denied_for_non_agent_key_raises_generic_403(): """A denial for a key with no agent binding stays generic and skips the agent-stripped rerun.""" - pytest.importorskip("litellm.proxy._experimental.mcp_server.server") + pytest.importorskip("litellm.proxy.mcp_server.server") user_api_key_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user") resolver = AsyncMock(return_value=[]) @@ -1598,7 +1600,7 @@ async def test_scoped_list_denied_for_non_agent_key_raises_generic_403(): async def test_scoped_list_unknown_name_raises_same_generic_403_as_unauthorized(): """Unknown and registered-but-unauthorized names raise byte-identical generic 403s, so a caller cannot probe which server names exist.""" - pytest.importorskip("litellm.proxy._experimental.mcp_server.server") + pytest.importorskip("litellm.proxy.mcp_server.server") user_api_key_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user", agent_id="agent-123") @@ -1622,7 +1624,7 @@ async def test_scoped_list_unknown_name_raises_same_generic_403_as_unauthorized( async def test_scoped_list_access_group_vetoed_by_agent_names_agent_and_group(): """An access-group scope vetoed by the agent binding raises the 403 naming the agent and the group instead of the silent empty list.""" - pytest.importorskip("litellm.proxy._experimental.mcp_server.server") + pytest.importorskip("litellm.proxy.mcp_server.server") user_api_key_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user", agent_id="agent-123") @@ -1645,7 +1647,7 @@ async def test_scoped_list_mixed_unknown_and_vetoed_group_names_the_group_that_r """With an unknown name ahead of the agent-vetoed group in the scope, the 403 must name the group whose servers the key can reach, never the unknown name, or the admin is told to grant a group that does not exist.""" - pytest.importorskip("litellm.proxy._experimental.mcp_server.server") + pytest.importorskip("litellm.proxy.mcp_server.server") user_api_key_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user", agent_id="agent-123") @@ -1667,7 +1669,7 @@ async def test_scoped_list_mixed_unknown_and_vetoed_group_names_the_group_that_r async def test_scoped_list_agent_key_denied_by_key_grants_raises_generic_403(): """When the agent-stripped rerun still resolves nothing, the 403 stays generic instead of blaming the agent binding.""" - pytest.importorskip("litellm.proxy._experimental.mcp_server.server") + pytest.importorskip("litellm.proxy.mcp_server.server") user_api_key_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user", agent_id="agent-123") resolver = _scope_resolver(resolved_without_agent={}) @@ -1687,7 +1689,7 @@ async def test_scoped_list_agent_key_denied_by_key_grants_raises_generic_403(): async def test_scoped_list_agent_veto_attributed_for_differently_cased_server_name(): """The scope filter matches `/mcp/GitHub` to a server named `github` case-insensitively, so the agent-attributed 403 must match the same way instead of falling back to the generic denial.""" - pytest.importorskip("litellm.proxy._experimental.mcp_server.server") + pytest.importorskip("litellm.proxy.mcp_server.server") user_api_key_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user", agent_id="agent-123") @@ -1710,7 +1712,7 @@ async def test_handle_list_tools_converts_permission_httpexception_to_mcp_error( """The MCP protocol handler surfaces a permission HTTPException as a clean JSON-RPC error (MCPError, INVALID_REQUEST) carrying the denial message, instead of a raw 500.""" try: - from litellm.proxy._experimental.mcp_server.server import handle_list_tools + from litellm.proxy.mcp_server.server import handle_list_tools except ImportError: pytest.skip("MCP server not available") @@ -1722,13 +1724,13 @@ async def test_handle_list_tools_converts_permission_httpexception_to_mcp_error( with ( patch( # test-quality-ok: the protocol handler reads auth from module context; no injection seam - "litellm.proxy._experimental.mcp_server.server.get_or_extract_auth_context", + "litellm.proxy.mcp_server.server.get_or_extract_auth_context", new=AsyncMock( return_value=(None, None, None, None, None, None, None), side_effect=denial if denial_at_auth else None ), ), patch( # test-quality-ok: the listing helper is the handler's only collaborator; the suite's seam - "litellm.proxy._experimental.mcp_server.operations._list_mcp_tools", + "litellm.proxy.mcp_server.operations._list_mcp_tools", new=AsyncMock(side_effect=denial), ), ): @@ -1792,7 +1794,7 @@ async def test_rate_limited_catalog_lists_return_mcp_errors(handler_name): @pytest.mark.asyncio async def test_mcp_server_tool_call_renders_denial_message_not_detail_dict(_mcp_request_ctx): try: - from litellm.proxy._experimental.mcp_server.server import mcp_server_tool_call + from litellm.proxy.mcp_server.server import mcp_server_tool_call except ImportError: pytest.skip("MCP server not available") @@ -1801,11 +1803,11 @@ async def test_mcp_server_tool_call_renders_denial_message_not_detail_dict(_mcp_ with ( patch( # test-quality-ok: the protocol handler reads auth from module context; no injection seam - "litellm.proxy._experimental.mcp_server.server.get_or_extract_auth_context", + "litellm.proxy.mcp_server.server.get_or_extract_auth_context", new=AsyncMock(return_value=(None, None, None, None, None, None, None)), ), patch( # test-quality-ok: the tool-call helper is the handler's only collaborator; the suite's seam - "litellm.proxy._experimental.mcp_server.operations.call_mcp_tool", + "litellm.proxy.mcp_server.operations.call_mcp_tool", new=AsyncMock(side_effect=denial), ), ): @@ -1819,7 +1821,7 @@ async def test_mcp_server_tool_call_renders_denial_message_not_detail_dict(_mcp_ async def test_mcp_server_tool_call_body_with_none_arguments(_mcp_request_ctx): """Test that proxy_server_request body handles None arguments correctly""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( mcp_server_tool_call, set_auth_context, ) @@ -1856,7 +1858,7 @@ async def test_mcp_server_tool_call_body_with_none_arguments(_mcp_request_ctx): mock_add_litellm_data_to_request, ): with patch( - "litellm.proxy._experimental.mcp_server.operations.call_mcp_tool", + "litellm.proxy.mcp_server.operations.call_mcp_tool", mock_call_mcp_tool, ): with patch( @@ -1879,14 +1881,14 @@ async def test_mcp_server_tool_call_body_with_none_arguments(_mcp_request_ctx): async def test_concurrent_initialize_session_managers(): """Test that concurrent calls to initialize_session_managers don't cause race conditions.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( initialize_session_managers, ) except ImportError: pytest.skip("MCP server not available") # Import the module to reset state - import litellm.proxy._experimental.mcp_server.server as mcp_server + import litellm.proxy.mcp_server.server as mcp_server # Reset state before test original_initialized = mcp_server._SESSION_MANAGERS_INITIALIZED @@ -1919,7 +1921,7 @@ async def test_concurrent_initialize_session_managers(): "run", return_value=mock_cm_stateful, ) as mock_stateful_run, - patch("litellm.proxy._experimental.mcp_server.operations.verbose_logger"), + patch("litellm.proxy.mcp_server.operations.verbose_logger"), ): # Create multiple concurrent tasks that call initialize_session_managers async def init_task(): @@ -1980,7 +1982,7 @@ async def test_streamable_http_session_manager_is_stateless(): - stateful manager for clients with session IDs (Claude Code, Cursor, VSCode) """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( session_manager_stateful, session_manager_stateless, ) @@ -2020,9 +2022,9 @@ async def test_mcp_routing_initialize_to_stateful_no_session_to_stateless( from starlette.requests import Request from starlette.types import Message, Receive, Scope, Send - from litellm.proxy._experimental.mcp_server import server as mcp_module - from litellm.proxy._experimental.mcp_server.mcp_debug import record_auth_resolution - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import AuthResolution + from litellm.proxy.mcp_server import server as mcp_module + from litellm.proxy.mcp_server.mcp_debug import record_auth_resolution + from litellm.proxy.mcp_server.outbound_credentials.types import AuthResolution scope: Final[Scope] = {"type": "http", "method": method, "path": "/mcp", "headers": []} receive: Final = AsyncMock(return_value={"type": "http.request", "body": request_body, "more_body": False}) @@ -2045,7 +2047,7 @@ async def test_mcp_routing_initialize_to_stateful_no_session_to_stateless( stateful_handle: Final = AsyncMock(side_effect=handle_request) with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=( UserAPIKeyAuth(user_id="debug-user"), @@ -2056,13 +2058,13 @@ async def test_mcp_routing_initialize_to_stateful_no_session_to_stateless( {"x-litellm-mcp-debug": "true"} if debug else {}, ), ), - patch("litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True), + patch("litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True), patch( - "litellm.proxy._experimental.mcp_server.server.session_manager_stateless", + "litellm.proxy.mcp_server.server.session_manager_stateless", SimpleNamespace(handle_request=stateless_handle), ), patch( - "litellm.proxy._experimental.mcp_server.server.session_manager_stateful", + "litellm.proxy.mcp_server.server.session_manager_stateful", SimpleNamespace(handle_request=stateful_handle), ), ): @@ -2113,14 +2115,14 @@ def _client_allowlist_patches( stack: Final = contextlib.ExitStack() stack.enter_context( patch( # test-quality-ok: the ASGI handler resolves auth through a module-level function; no injection seam - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(UserAPIKeyAuth(user_id="allowlist-user", jwt_claims=jwt_claims), None, None, None, None, {}), ) ) stack.enter_context( patch( # test-quality-ok: module flag guarding lazy session-manager startup; no injection seam - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True ) ) stack.enter_context( @@ -2153,7 +2155,7 @@ async def test_streamable_http_rejects_unlisted_client_before_any_session_work( request_body: bytes, expected_fragment: str, ) -> None: - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module scope: Final[Scope] = {"type": "http", "method": "POST", "path": "/mcp", "headers": headers} receive: Final = AsyncMock(return_value={"type": "http.request", "body": request_body, "more_body": False}) @@ -2165,15 +2167,15 @@ async def test_streamable_http_rejects_unlisted_client_before_any_session_work( with ( _client_allowlist_patches(_ALLOWLIST_SETTINGS, jwt_claims), patch( # test-quality-ok: session managers are module singletons; the downstream call is the observable - "litellm.proxy._experimental.mcp_server.server.session_manager_stateful", + "litellm.proxy.mcp_server.server.session_manager_stateful", SimpleNamespace(handle_request=stateful_handle), ), patch( # test-quality-ok: session managers are module singletons; the downstream call is the observable - "litellm.proxy._experimental.mcp_server.server.session_manager_stateless", + "litellm.proxy.mcp_server.server.session_manager_stateless", SimpleNamespace(handle_request=stateless_handle), ), patch( # test-quality-ok: module-level cap check; asserting it is never reached is the point - "litellm.proxy._experimental.mcp_server.server._enforce_stateful_session_cap_for_owner", session_cap + "litellm.proxy.mcp_server.server._enforce_stateful_session_cap_for_owner", session_cap ), pytest.raises(HTTPException) as denied, ): @@ -2205,7 +2207,7 @@ async def test_streamable_http_rejects_unlisted_client_before_any_session_work( async def test_streamable_http_admits_listed_or_unrestricted_clients_and_hands_the_body_downstream( settings: dict[str, object], jwt_claims: dict[str, object] | None, headers: list[tuple[bytes, bytes]] ) -> None: - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module scope: Final[Scope] = {"type": "http", "method": "POST", "path": "/mcp", "headers": headers} receive: Final = AsyncMock( @@ -2226,11 +2228,11 @@ async def test_streamable_http_admits_listed_or_unrestricted_clients_and_hands_t with ( _client_allowlist_patches(settings, jwt_claims), patch( # test-quality-ok: session managers are module singletons; the downstream call is the observable - "litellm.proxy._experimental.mcp_server.server.session_manager_stateful", + "litellm.proxy.mcp_server.server.session_manager_stateful", SimpleNamespace(handle_request=stateful_handle), ), patch( # test-quality-ok: session managers are module singletons; the downstream call is the observable - "litellm.proxy._experimental.mcp_server.server.session_manager_stateless", + "litellm.proxy.mcp_server.server.session_manager_stateless", SimpleNamespace(handle_request=stateless_handle), ), ): @@ -2255,7 +2257,7 @@ async def test_streamable_http_admits_listed_or_unrestricted_clients_and_hands_t async def test_sse_endpoint_applies_the_same_client_allowlist( jwt_claims: dict[str, object] | None, headers: list[tuple[bytes, bytes]], admitted: bool ) -> None: - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module scope: Final[Scope] = {"type": "http", "method": "POST", "path": "/mcp/sse", "headers": headers} receive: Final = AsyncMock(return_value={"type": "http.request", "body": _INITIALIZE, "more_body": False}) @@ -2268,11 +2270,11 @@ async def test_sse_endpoint_applies_the_same_client_allowlist( with ( _client_allowlist_patches(_ALLOWLIST_SETTINGS, jwt_claims), patch( # test-quality-ok: module-level pre-auth probe unrelated to the allowlist under test; no injection seam - "litellm.proxy._experimental.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", + "litellm.proxy.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", new_callable=AsyncMock, ), patch( # test-quality-ok: module-level upstream auth probe unrelated to the allowlist under test; no injection seam - "litellm.proxy._experimental.mcp_server.server._check_passthrough_upstream_auth", + "litellm.proxy.mcp_server.server._check_passthrough_upstream_auth", new_callable=AsyncMock, ), patch.object( # test-quality-ok: SSE manager is a module singleton; the downstream call is the observable @@ -2301,7 +2303,7 @@ async def test_mcp_routing_chunked_initialize_to_stateful(): Test that chunked initialize requests route to the stateful manager. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, session_manager_stateless, @@ -2343,20 +2345,20 @@ async def test_mcp_routing_chunked_initialize_to_stateful(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(UserAPIKeyAuth(), None, ["progress_test"], None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( # test-quality-ok: registry is empty in unit tests; key owns one server - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[MagicMock()], ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -2397,8 +2399,8 @@ async def test_mcp_routing_caps_body_peek_for_oversized_chunked_body(): receive into the downstream handler. """ try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, session_manager_stateless, @@ -2455,13 +2457,13 @@ async def test_mcp_routing_caps_body_peek_for_oversized_chunked_body(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(UserAPIKeyAuth(), None, ["progress_test"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object(session_manager_stateless, "handle_request", side_effect=stateless_handle), @@ -2495,8 +2497,8 @@ async def test_mcp_routing_peek_survives_multibyte_char_split_at_cap( ) -> None: from starlette.requests import Request - from litellm.proxy._experimental.mcp_server import server as mcp_module - from litellm.proxy._experimental.mcp_server.scope_challenge import finish_scope_response + from litellm.proxy.mcp_server import server as mcp_module + from litellm.proxy.mcp_server.scope_challenge import finish_scope_response params: Final = ( { @@ -2537,11 +2539,11 @@ async def test_mcp_routing_peek_survives_multibyte_char_split_at_cap( with ( _client_allowlist_patches({}, None), patch( - "litellm.proxy._experimental.mcp_server.server.session_manager_stateless", + "litellm.proxy.mcp_server.server.session_manager_stateless", SimpleNamespace(handle_request=stateless_handle), ), patch( - "litellm.proxy._experimental.mcp_server.server.session_manager_stateful", + "litellm.proxy.mcp_server.server.session_manager_stateful", SimpleNamespace(handle_request=stateful_handle), ), ): @@ -2561,8 +2563,8 @@ async def test_enforce_stateful_session_cap_evicts_oldest_idle_then_rejects(): every one of its sessions is in flight (nothing safe to evict). """ try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( session_manager_stateful, ) except ImportError: @@ -2634,8 +2636,8 @@ async def test_mcp_routing_initialize_rejected_when_owner_at_session_cap(): and must not reach the stateful session manager. """ try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, session_manager_stateless, @@ -2674,13 +2676,13 @@ async def test_mcp_routing_initialize_rejected_when_owner_at_session_cap(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(UserAPIKeyAuth(), None, ["progress_test"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object(mcp_server, "_owner_fingerprint_for", return_value="owner-X"), @@ -2714,8 +2716,8 @@ async def test_stateful_mcp_requests_refresh_session_auth_context(): stored auth object must be refreshed for each mcp-session-id request. """ try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( get_auth_context, handle_streamable_http_mcp, session_manager_stateful, @@ -2766,7 +2768,7 @@ async def test_stateful_mcp_requests_refresh_session_auth_context(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=( current_auth, @@ -2778,7 +2780,7 @@ async def test_stateful_mcp_requests_refresh_session_auth_context(): ), ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -2809,7 +2811,7 @@ async def test_stateful_mcp_requests_refresh_session_auth_context(): @pytest.mark.asyncio async def test_initialize_response_capture_accepts_str_headers_and_sets_auth_context(): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server except ImportError: pytest.skip("MCP server not available") @@ -2857,8 +2859,8 @@ async def test_initialize_response_capture_accepts_str_headers_and_sets_auth_con @pytest.mark.asyncio async def test_initialize_request_tracks_active_session_after_response_header(): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, session_manager_stateless, @@ -2906,17 +2908,17 @@ async def test_initialize_request_tracks_active_session_after_response_header(): try: with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(owner_auth, None, None, None, None, None), ), patch( # test-quality-ok: registry is empty in unit tests; key owns one server - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[MagicMock()], ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -2959,7 +2961,7 @@ _INITIALIZE_WITH_CLIENT_INFO: Final = ( ) def test_extract_initialize_client_info_reads_client_name_and_version(body, expected_name, expected_version): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server except ImportError: pytest.skip("MCP server not available") @@ -2981,7 +2983,7 @@ def test_extract_initialize_client_info_reads_client_name_and_version(body, expe ) def test_extract_initialize_client_info_returns_none_without_client_info(body): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server except ImportError: pytest.skip("MCP server not available") @@ -2993,7 +2995,7 @@ def test_oversized_initialize_peek_neither_routes_stateful_nor_attributes_client an initialize larger than the peek can never become a tracked session that then reports an unknown client.""" try: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server except ImportError: pytest.skip("MCP server not available") @@ -3015,8 +3017,8 @@ async def test_initialize_request_records_client_name_in_gateway_sessions_report """The real initialize body's clientInfo is attributed to the session the stateful manager creates, together with the authenticated user.""" try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, session_manager_stateless, @@ -3059,17 +3061,17 @@ async def test_initialize_request_records_client_name_in_gateway_sessions_report try: with ( patch( # test-quality-ok: admission auth is resolved by a module-level function; the suite's only seam - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(owner_auth, None, None, None, None, None), ), patch( # test-quality-ok: registry is empty in unit tests; key owns one server - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[MagicMock()], ), patch( # test-quality-ok: session manager init is a module-level flag; the suite's only seam - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( # test-quality-ok: the transports are module-level singletons; the suite's only seam @@ -3116,8 +3118,8 @@ async def test_initialize_request_records_client_name_in_gateway_sessions_report def test_gateway_sessions_report_groups_live_sessions_by_client_and_user(): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import session_manager_stateful + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import session_manager_stateful except ImportError: pytest.skip("MCP server not available") from mcp.types import Implementation @@ -3186,7 +3188,7 @@ def test_gateway_sessions_report_groups_live_sessions_by_client_and_user(): def test_remove_stateful_session_tracking_drops_client_info(): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server except ImportError: pytest.skip("MCP server not available") from mcp.types import Implementation @@ -3224,8 +3226,8 @@ def _admin_terminate_fixture(mcp_server): @pytest.mark.asyncio async def test_terminate_mcp_gateway_sessions_by_user_closes_every_live_session_of_that_user(): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import session_manager_stateful + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import session_manager_stateful except ImportError: pytest.skip("MCP server not available") @@ -3283,8 +3285,8 @@ async def test_terminate_mcp_gateway_sessions_by_user_closes_every_live_session_ @pytest.mark.asyncio async def test_terminate_mcp_gateway_sessions_prefix_and_user_must_both_match(): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import session_manager_stateful + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import session_manager_stateful except ImportError: pytest.skip("MCP server not available") @@ -3321,8 +3323,8 @@ async def test_admin_terminated_session_id_gets_404_instead_of_a_fresh_stateless try: from starlette.types import Scope - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import session_manager_stateful + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import session_manager_stateful except ImportError: pytest.skip("MCP server not available") @@ -3387,8 +3389,8 @@ async def test_admin_terminated_session_id_stays_refused_while_replayed_and_is_f try: from starlette.types import Scope - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import session_manager_stateful + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import session_manager_stateful except ImportError: pytest.skip("MCP server not available") @@ -3453,8 +3455,8 @@ async def test_admin_terminated_session_id_stays_refused_while_replayed_and_is_f @pytest.mark.asyncio async def test_initialize_request_with_existing_session_tracks_new_session(): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, session_manager_stateless, @@ -3527,7 +3529,7 @@ async def test_initialize_request_with_existing_session_tracks_new_session(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=( owner_auth, @@ -3539,7 +3541,7 @@ async def test_initialize_request_with_existing_session_tracks_new_session(): ), ), patch( # test-quality-ok: registry is empty in unit tests; key owns one server - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[ MCPServer( @@ -3552,7 +3554,7 @@ async def test_initialize_request_with_existing_session_tracks_new_session(): ], ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -3588,7 +3590,7 @@ async def test_initialize_request_with_existing_session_tracks_new_session(): async def test_stateful_mcp_auth_contexts_expire_with_idle_sessions(): """Expired session auth contexts should not remain in memory indefinitely.""" try: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server except ImportError: pytest.skip("MCP server not available") @@ -3619,7 +3621,7 @@ async def test_stateful_mcp_auth_contexts_expire_with_idle_sessions(): async def test_stateful_mcp_auth_contexts_do_not_expire_active_sessions(): """Active stateful sessions should not be terminated by idle cleanup.""" try: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server except ImportError: pytest.skip("MCP server not available") @@ -3656,7 +3658,7 @@ async def test_stateful_mcp_auth_contexts_do_not_expire_active_sessions(): async def test_stateful_mcp_auth_context_cleanup_respects_zero_now(): """Explicit now=0 should be used as-is instead of falling back to monotonic.""" try: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server except ImportError: pytest.skip("MCP server not available") @@ -3695,7 +3697,7 @@ async def test_stateful_mcp_auth_context_cleanup_respects_zero_now(): async def test_stateful_mcp_cleanup_loop_survives_purge_errors(): """Cleanup loop should keep running after one purge attempt fails.""" try: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server except ImportError: pytest.skip("MCP server not available") @@ -3720,7 +3722,7 @@ async def test_owner_fingerprint_distinguishes_oauth_callers(): user could hijack another's mcp-session-id. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _owner_fingerprint_for, ) except ImportError: @@ -3756,7 +3758,7 @@ async def test_owner_fingerprint_distinguishes_oauth_callers(): async def test_owner_fingerprint_hashes_custom_api_keys(): """Custom API key formats should not appear in owner fingerprints.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _owner_fingerprint_for, ) except ImportError: @@ -3787,8 +3789,8 @@ async def test_stateful_mcp_session_owner_mismatch_returns_403(body: bytes): with 403, and the stateful manager must never be invoked. """ try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -3828,12 +3830,12 @@ async def test_stateful_mcp_session_owner_mismatch_returns_403(body: bytes): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(intruder_auth, None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -3865,8 +3867,8 @@ async def test_stateful_mcp_session_serializes_concurrent_requests(): MCPAuthenticatedUser while in-flight callbacks are still running. """ try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -3911,12 +3913,12 @@ async def test_stateful_mcp_session_serializes_concurrent_requests(): try: with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(owner_auth, None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object(session_manager_stateful, "handle_request", side_effect=slow_handle), @@ -3948,8 +3950,8 @@ async def test_stateful_mcp_lock_does_not_leak_when_auth_context_missing(): leaked lock would otherwise live forever. """ try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -3979,12 +3981,12 @@ async def test_stateful_mcp_lock_does_not_leak_when_auth_context_missing(): try: with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(owner_auth, None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object(session_manager_stateful, "handle_request", side_effect=handle), @@ -4015,8 +4017,8 @@ async def test_stateful_mcp_get_stream_does_not_block_post(): same mcp-session-id hang for the lifetime of the stream. """ try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -4058,12 +4060,12 @@ async def test_stateful_mcp_get_stream_does_not_block_post(): try: with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(owner_auth, None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object(session_manager_stateful, "handle_request", side_effect=handle), @@ -4098,7 +4100,7 @@ def test_jsonrpc_text_has_top_level_method_ignores_nested_method(): """The top-level-key scan must not be fooled by a ``method`` field nested inside a JSON-RPC response's ``result`` payload — a flat substring search would, and that misread is what deadlocks the session lock.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _jsonrpc_text_has_top_level_method, ) @@ -4130,8 +4132,8 @@ async def test_truncated_jsonrpc_response_with_nested_method_skips_lock( deadlock behind the in-flight request POST that is holding the lock while it awaits this very response (e.g. sampling/createMessage).""" try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -4206,12 +4208,12 @@ async def test_truncated_jsonrpc_response_with_nested_method_skips_lock( try: with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(owner_auth, None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object(session_manager_stateful, "handle_request", side_effect=handle), @@ -4264,14 +4266,14 @@ async def test_mcp_routing_with_conflicting_alias_and_group_name(): conflicts with an access group name (e.g., "group"). """ try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_mcp_servers_in_path, _get_tools_from_mcp_servers, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: pytest.skip("MCP server not available") @@ -4309,15 +4311,15 @@ async def test_mcp_routing_with_conflicting_alias_and_group_name(): with ( patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_allowed_mcp_servers", mock_get_allowed, ), patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.server.MCPRequestHandler.get_mcp_servers_from_access_groups", mock_db_lookup, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_tools_from_server", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_tools_from_server", mock_get_tools_spy, ), ): @@ -4345,14 +4347,14 @@ async def test_oauth2_caller_headers_not_forwarded_for_migrated_server(): caller's oauth2 Authorization to the MCP client — the resolver injects the stored per-user token, so a caller-supplied bearer cannot override another user's credential.""" try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -4426,16 +4428,16 @@ async def test_oauth2_caller_headers_not_forwarded_for_migrated_server(): side_effect=mock_fetch_tools_with_timeout, ), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", AsyncMock(return_value=[oauth2_server]), ), patch( - "litellm.proxy._experimental.mcp_server.operations._prefetch_oauth_creds_for_user", + "litellm.proxy.mcp_server.operations._prefetch_oauth_creds_for_user", new_callable=AsyncMock, return_value={}, ), patch( - "litellm.proxy._experimental.mcp_server.operations._get_user_oauth_extra_headers_from_db", + "litellm.proxy.mcp_server.operations._get_user_oauth_extra_headers_from_db", new_callable=AsyncMock, return_value=None, ), @@ -4468,7 +4470,7 @@ async def test_oauth2_caller_headers_not_forwarded_for_migrated_server(): async def test_list_tools_single_server_unprefixed_names(): """When only one MCP server is allowed, list tools should return prefixed names (server prefix is always added).""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) @@ -4517,7 +4519,7 @@ async def test_list_tools_single_server_unprefixed_names(): mock_manager.get_tools_from_server = mock_get_tools_from_server with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): listing = await _get_tools_from_mcp_servers( @@ -4536,7 +4538,7 @@ async def test_list_tools_single_server_unprefixed_names(): async def test_list_tools_multiple_servers_prefixed_names(): """When multiple MCP servers are allowed, list tools should return prefixed names.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) @@ -4596,7 +4598,7 @@ async def test_list_tools_multiple_servers_prefixed_names(): mock_manager.get_tools_from_server = mock_get_tools_from_server with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): listing = await _get_tools_from_mcp_servers( @@ -4614,10 +4616,10 @@ async def test_list_tools_multiple_servers_prefixed_names(): @pytest.mark.asyncio async def test_mcp_manager_allows_public_servers_without_permissions(): try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: pytest.skip("MCP server not available") @@ -4637,7 +4639,7 @@ async def test_mcp_manager_allows_public_servers_without_permissions(): return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.MCPRequestHandler.get_allowed_mcp_servers", + "litellm.proxy.mcp_server.mcp_server_manager.MCPRequestHandler.get_allowed_mcp_servers", AsyncMock(return_value=[]), ), ): @@ -4649,10 +4651,10 @@ async def test_mcp_manager_allows_public_servers_without_permissions(): @pytest.mark.asyncio async def test_mcp_manager_returns_public_when_permission_lookup_fails(): try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: pytest.skip("MCP server not available") @@ -4672,7 +4674,7 @@ async def test_mcp_manager_returns_public_when_permission_lookup_fails(): return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.MCPRequestHandler.get_allowed_mcp_servers", + "litellm.proxy.mcp_server.mcp_server_manager.MCPRequestHandler.get_allowed_mcp_servers", AsyncMock(side_effect=Exception("boom")), ), ): @@ -4684,11 +4686,11 @@ async def test_mcp_manager_returns_public_when_permission_lookup_fails(): @pytest.mark.asyncio async def test_mcp_manager_merges_public_and_restricted_servers(): try: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: pytest.skip("MCP server not available") @@ -4716,7 +4718,7 @@ async def test_mcp_manager_merges_public_and_restricted_servers(): return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.MCPRequestHandler.get_mcp_server_access", + "litellm.proxy.mcp_server.mcp_server_manager.MCPRequestHandler.get_mcp_server_access", AsyncMock(return_value=MCPServerAccess(server_ids=("restricted",), scope="scoped")), ), ): @@ -4730,8 +4732,8 @@ async def test_call_mcp_tool_user_unauthorized_access(): """Test that a user cannot call a tool from a server they don't have access to""" from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server.server import call_mcp_tool from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import call_mcp_tool # Create a mock user without access to the server mock_user_auth = UserAPIKeyAuth( @@ -4772,11 +4774,11 @@ async def test_call_mcp_tool_user_unauthorized_access(): with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_allowed_mcp_servers", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_allowed_mcp_servers", AsyncMock(return_value=["allowed_server", "another_server"]), ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_id", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_id", side_effect=mock_get_server_by_id, ), ): @@ -4800,17 +4802,17 @@ async def test_call_mcp_tool_user_unauthorized_access(): @pytest.mark.asyncio async def test_call_mcp_tool_scoped_denial_names_the_binding_agent(): - from litellm.proxy._experimental.mcp_server.server import call_mcp_tool + from litellm.proxy.mcp_server.server import call_mcp_tool agent_bound_key = UserAPIKeyAuth(api_key="test-key", user_id="test-user", agent_id="agent-123") with ( patch( # test-quality-ok: the server registry is a module-level singleton; the suite's only seam - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_allowed_mcp_servers", AsyncMock(return_value=[]), ), patch( # test-quality-ok: the permission resolver is a module-level function; the suite's only seam - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", _scope_resolver({"github": "srv-github"}), ), ): @@ -4839,8 +4841,8 @@ async def test_call_mcp_tool_unauthorized_403_does_not_leak_server_credentials() """ from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server.server import call_mcp_tool from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import call_mcp_tool from litellm.types.mcp_server.mcp_server_manager import MCPServer mock_user_auth = UserAPIKeyAuth( @@ -4878,11 +4880,11 @@ async def test_call_mcp_tool_unauthorized_403_does_not_leak_server_credentials() with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_allowed_mcp_servers", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_allowed_mcp_servers", AsyncMock(return_value=["allowed_server"]), ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_id", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_id", side_effect=mock_get_server_by_id, ), ): @@ -4946,11 +4948,11 @@ def test_mcpserver_repr_and_str_mask_credentials(): async def test_list_tools_filters_by_key_team_permissions(): """Test that list_tools filters tools based on key/team mcp_tool_permissions""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth except ImportError: pytest.skip("MCP server not available") @@ -5025,7 +5027,7 @@ async def test_list_tools_filters_by_key_team_permissions(): mock_manager.get_tools_from_server = mock_get_tools_from_server with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): listing = await _get_tools_from_mcp_servers( @@ -5045,14 +5047,14 @@ async def test_list_tools_filters_by_key_team_permissions(): async def test_list_tools_with_team_tool_permissions_inheritance(): """Test that list_tools correctly applies key/team tool permissions inheritance logic""" try: - from litellm.proxy._experimental.mcp_server.server import ( - _get_tools_from_mcp_servers, - set_auth_context, - ) from litellm.proxy._types import ( LiteLLM_ObjectPermissionTable, UserAPIKeyAuth, ) + from litellm.proxy.mcp_server.server import ( + _get_tools_from_mcp_servers, + set_auth_context, + ) except ImportError: pytest.skip("MCP server not available") @@ -5136,12 +5138,12 @@ async def test_list_tools_with_team_tool_permissions_inheritance(): mock_manager.get_tools_from_server = mock_get_tools_from_server with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): # Mock the team object permission retrieval with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler._get_team_object_permission", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler._get_team_object_permission", AsyncMock(return_value=team_object_permission), ): listing = await _get_tools_from_mcp_servers( @@ -5161,11 +5163,11 @@ async def test_list_tools_with_team_tool_permissions_inheritance(): async def test_list_tools_with_no_tool_permissions_shows_all(): """Test that list_tools shows all tools when no mcp_tool_permissions are set""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) - from litellm.proxy._types import UserAPIKeyAuth except ImportError: pytest.skip("MCP server not available") @@ -5228,7 +5230,7 @@ async def test_list_tools_with_no_tool_permissions_shows_all(): mock_manager.get_tools_from_server = mock_get_tools_from_server with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): listing = await _get_tools_from_mcp_servers( @@ -5254,11 +5256,11 @@ async def test_list_tools_strips_prefix_when_matching_permissions(): The filtering should strip the prefix before comparing. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth except ImportError: pytest.skip("MCP server not available") @@ -5334,7 +5336,7 @@ async def test_list_tools_strips_prefix_when_matching_permissions(): mock_manager.get_tools_from_server = mock_get_tools_from_server with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): listing = await _get_tools_from_mcp_servers( @@ -5358,7 +5360,7 @@ def test_filter_tools_by_allowed_tools(): """Test that filter_tools_by_allowed_tools filters tools correctly""" from mcp.types import Tool - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_allowed_tools, ) from litellm.types.mcp import MCPTransport @@ -5430,7 +5432,7 @@ def test_filter_tools_by_allowed_tools(): def test_apply_display_name_overrides_leaves_descriptions_to_the_catalog_guard(): from mcp.types import Tool - from litellm.proxy._experimental.mcp_server.server import apply_display_name_overrides + from litellm.proxy.mcp_server.server import apply_display_name_overrides from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5471,7 +5473,7 @@ def test_apply_display_name_overrides_leaves_descriptions_to_the_catalog_guard() def test_apply_display_name_overrides_no_overrides(): from mcp.types import Tool - from litellm.proxy._experimental.mcp_server.server import apply_display_name_overrides + from litellm.proxy.mcp_server.server import apply_display_name_overrides from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5513,7 +5515,7 @@ class TestMCPServerManagerReload: @pytest.mark.asyncio async def test_reuses_existing_server_when_updated_at_matches(self): try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) except ImportError: @@ -5550,7 +5552,7 @@ class TestMCPServerManagerReload: @pytest.mark.asyncio async def test_rebuilds_server_when_updated_at_changes(self): try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) except ImportError: @@ -5598,7 +5600,7 @@ class TestMCPServerManagerReload: @pytest.mark.asyncio async def test_skips_server_when_build_from_database_fails(self, caplog): try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) except ImportError: @@ -5659,7 +5661,7 @@ class TestMCPServerManagerReload: @pytest.mark.asyncio async def test_skips_server_when_openapi_registration_fails(self, caplog): try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) except ImportError: @@ -5743,11 +5745,11 @@ async def test_call_mcp_tool_logs_failure_via_post_call_failure_hook(): Ensure proxy-side `call_mcp_tool` logs failures via `proxy_logging_obj.post_call_failure_hook`. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import MCPTransport, UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( call_mcp_tool, global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport, UserAPIKeyAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: pytest.skip("MCP server not available") @@ -5780,12 +5782,12 @@ async def test_call_mcp_tool_logs_failure_via_post_call_failure_hook(): return_value=mock_server, ), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers_from_mcp_server_names", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers_from_mcp_server_names", new_callable=AsyncMock, return_value=[mock_server], ), patch( - "litellm.proxy._experimental.mcp_server.operations.execute_mcp_tool", + "litellm.proxy.mcp_server.operations.execute_mcp_tool", new_callable=AsyncMock, side_effect=Exception("boom"), ), @@ -5815,10 +5817,10 @@ async def test_get_tools_from_mcp_servers_logs_list_tools_to_spendlogs_when_enab try: from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, ) - from litellm.proxy._types import UserAPIKeyAuth except ImportError: pytest.skip("MCP server not available") @@ -5849,26 +5851,26 @@ async def test_get_tools_from_mcp_servers_logs_list_tools_to_spendlogs_when_enab with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[server_a]), ), patch( - "litellm.proxy._experimental.mcp_server.operations._prepare_mcp_server_headers", + "litellm.proxy.mcp_server.operations._prepare_mcp_server_headers", return_value=(None, None), ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, patch( - "litellm.proxy._experimental.mcp_server.operations.filter_tools_by_allowed_tools", + "litellm.proxy.mcp_server.operations.filter_tools_by_allowed_tools", side_effect=lambda tools, _server: tools, ), patch( - "litellm.proxy._experimental.mcp_server.operations.filter_tools_by_key_team_permissions", + "litellm.proxy.mcp_server.operations.filter_tools_by_key_team_permissions", new=AsyncMock(side_effect=lambda tools, **_: tools), ), patch( - "litellm.proxy._experimental.mcp_server.operations.function_setup", + "litellm.proxy.mcp_server.operations.function_setup", side_effect=_capture_function_setup, ), ): @@ -5927,21 +5929,21 @@ async def test_get_tools_from_mcp_servers_all_failed_listing_never_runs_proxy_fa with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=servers), ), patch( - "litellm.proxy._experimental.mcp_server.operations._prepare_mcp_server_headers", + "litellm.proxy.mcp_server.operations._prepare_mcp_server_headers", return_value=(None, None), ), - patch("litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", manager), - patch("litellm.proxy._experimental.mcp_server.operations.filter_tools_by_allowed_tools", return_value=[]), + patch("litellm.proxy.mcp_server.operations.global_mcp_server_manager", manager), + patch("litellm.proxy.mcp_server.operations.filter_tools_by_allowed_tools", return_value=[]), patch( - "litellm.proxy._experimental.mcp_server.operations.filter_tools_by_key_team_permissions", + "litellm.proxy.mcp_server.operations.filter_tools_by_key_team_permissions", new=AsyncMock(return_value=[]), ), patch( - "litellm.proxy._experimental.mcp_server.operations.function_setup", + "litellm.proxy.mcp_server.operations.function_setup", return_value=(logging_obj, None), ), patch("litellm.proxy.proxy_server.proxy_logging_obj", proxy_logging_obj), @@ -5973,10 +5975,10 @@ async def test_get_tools_from_mcp_servers_returns_tools_when_success_logging_fai async_success_handler raises (e.g. serialization errors in logging path). """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, ) - from litellm.proxy._types import UserAPIKeyAuth except ImportError: pytest.skip("MCP server not available") @@ -6001,26 +6003,26 @@ async def test_get_tools_from_mcp_servers_returns_tools_when_success_logging_fai with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[server_a]), ), patch( - "litellm.proxy._experimental.mcp_server.operations._prepare_mcp_server_headers", + "litellm.proxy.mcp_server.operations._prepare_mcp_server_headers", return_value=(None, None), ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, patch( - "litellm.proxy._experimental.mcp_server.operations.filter_tools_by_allowed_tools", + "litellm.proxy.mcp_server.operations.filter_tools_by_allowed_tools", side_effect=lambda tools, _server: tools, ), patch( - "litellm.proxy._experimental.mcp_server.operations.filter_tools_by_key_team_permissions", + "litellm.proxy.mcp_server.operations.filter_tools_by_key_team_permissions", new=AsyncMock(side_effect=lambda tools, **_: tools), ), patch( - "litellm.proxy._experimental.mcp_server.operations.function_setup", + "litellm.proxy.mcp_server.operations.function_setup", return_value=(dummy_logging_obj, None), ), ): @@ -6050,7 +6052,7 @@ def test_tool_name_matches_case_insensitive(): Without case-insensitive matching, all tools would be filtered out. """ try: - from litellm.proxy._experimental.mcp_server.server import _tool_name_matches + from litellm.proxy.mcp_server.server import _tool_name_matches except ImportError: pytest.skip("MCP server not available") @@ -6094,7 +6096,7 @@ def test_filter_tools_by_allowed_tools_case_insensitive(): camelCase allowed_tools configuration from the OpenAPI spec. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_allowed_tools, ) from litellm.types.mcp_server.tool_registry import MCPTool @@ -6157,7 +6159,7 @@ def test_filter_tools_by_allowed_tools_case_insensitive(): def test_filter_tools_by_allowed_tools_no_filter(): """Test that filter_tools_by_allowed_tools returns all tools when no filter is set.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_allowed_tools, ) from litellm.types.mcp_server.tool_registry import MCPTool @@ -6200,7 +6202,7 @@ def test_filter_tools_by_allowed_tools_no_filter(): def test_filter_tools_enforced_empty_allowlist_blocks_all(): from mcp.types import Tool - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_allowed_tools, ) from litellm.types.mcp import MCPTransport @@ -6230,7 +6232,7 @@ def test_filter_tools_enforced_empty_allowlist_blocks_all(): def test_filter_tools_legacy_empty_allowlist_allows_all(): from mcp.types import Tool - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_allowed_tools, ) from litellm.types.mcp import MCPTransport @@ -6258,7 +6260,7 @@ def test_filter_tools_legacy_empty_allowlist_allows_all(): def test_check_allowed_or_banned_tools_enforced_empty_denies_calls(): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp import MCPTransport @@ -6291,10 +6293,10 @@ async def test_get_tools_from_mcp_servers_injects_stored_oauth2_token(): API because the stored credential was never injected. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, ) - from litellm.proxy._types import UserAPIKeyAuth from litellm.types.mcp import MCPAuth except ImportError: pytest.skip("MCP server not available") @@ -6321,23 +6323,23 @@ async def test_get_tools_from_mcp_servers_injects_stored_oauth2_token(): with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[oauth2_server]), ), patch( # Patch the bulk prefetch so no real DB connection is needed - "litellm.proxy._experimental.mcp_server.operations._prefetch_oauth_creds_for_user", + "litellm.proxy.mcp_server.operations._prefetch_oauth_creds_for_user", new=AsyncMock(return_value=prefetched_creds), ) as mock_prefetch, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, patch( - "litellm.proxy._experimental.mcp_server.operations.filter_tools_by_allowed_tools", + "litellm.proxy.mcp_server.operations.filter_tools_by_allowed_tools", side_effect=lambda tools, _server: tools, ), patch( - "litellm.proxy._experimental.mcp_server.operations.filter_tools_by_key_team_permissions", + "litellm.proxy.mcp_server.operations.filter_tools_by_key_team_permissions", new=AsyncMock(side_effect=lambda tools, **_: tools), ), ): @@ -6394,7 +6396,7 @@ class TestMergeGatewayInitializeInstructions: def _merge(self, servers): try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _merge_gateway_initialize_instructions, ) except ImportError: @@ -6417,7 +6419,7 @@ class TestMergeGatewayInitializeInstructions: def test_yaml_override_beats_upstream_cache(self): """YAML/DB instructions take precedence over upstream cache.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6430,7 +6432,7 @@ class TestMergeGatewayInitializeInstructions: def test_upstream_cache_used_when_no_yaml(self): """Upstream cached instructions are used when no YAML override is set.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6470,7 +6472,7 @@ class TestMergeGatewayInitializeInstructions: def test_mixed_yaml_cache_specpath(self): """YAML, upstream-cache, and spec_path servers are handled correctly together.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6492,7 +6494,7 @@ class TestEnsureUpstreamInitializeInstructionsCached: async def test_skips_when_yaml_instructions_set(self): from unittest.mock import AsyncMock, patch - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6505,7 +6507,7 @@ class TestEnsureUpstreamInitializeInstructionsCached: async def test_skips_when_already_cached(self): from unittest.mock import AsyncMock, patch - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6522,7 +6524,7 @@ class TestEnsureUpstreamInitializeInstructionsCached: async def test_skips_when_spec_path_set(self): from unittest.mock import AsyncMock, patch - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6535,7 +6537,7 @@ class TestEnsureUpstreamInitializeInstructionsCached: async def test_runs_upstream_session_and_caches(self): from unittest.mock import AsyncMock, MagicMock, patch - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6564,7 +6566,7 @@ class TestEnsureUpstreamInitializeInstructionsCached: """Upstream returns no instructions → next call within cooldown must not reconnect.""" from unittest.mock import AsyncMock, MagicMock, patch - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6589,7 +6591,7 @@ class TestEnsureUpstreamInitializeInstructionsCached: """run_with_session raises → cooldown applies, no immediate retry.""" from unittest.mock import AsyncMock, MagicMock, patch - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6612,7 +6614,7 @@ class TestEnsureUpstreamInitializeInstructionsCached: @pytest.mark.asyncio async def test_reload_resets_probe_cooldown(self): """load_servers_from_config clears the negative-cache map so reloads re-probe.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6630,11 +6632,11 @@ class TestGatewayCreateInitializationOptions: def test_no_contextvar_returns_default_options(self): """When ContextVar is None, instructions are absent.""" try: - from litellm.proxy._experimental.mcp_server.mcp_context import ( + from litellm.proxy.mcp_server.mcp_context import ( mcp_gateway_initialize_instructions, mcp_gateway_server_name, ) - from litellm.proxy._experimental.mcp_server.server import server + from litellm.proxy.mcp_server.server import server except ImportError: pytest.skip("MCP server not available") @@ -6651,7 +6653,7 @@ class TestGatewayCreateInitializationOptions: @pytest.mark.asyncio async def test_scoped_request_uses_configured_server_alias(self): try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _gateway_initialize_instructions_request_scope, global_mcp_server_manager, server, @@ -6669,7 +6671,7 @@ class TestGatewayCreateInitializationOptions: with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[scoped_server], ), @@ -6693,13 +6695,13 @@ class TestGatewayCreateInitializationOptions: async def test_initialize_with_no_granted_servers_returns_403(self): from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _gateway_initialize_instructions_request_scope, ) - from litellm.proxy._types import UserAPIKeyAuth with patch( # test-quality-ok: grant resolution is the input under test - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[], ): @@ -6719,13 +6721,13 @@ class TestGatewayCreateInitializationOptions: async def test_initialize_with_no_granted_scoped_servers_returns_scoped_denial(self): from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _gateway_initialize_instructions_request_scope, ) - from litellm.proxy._types import UserAPIKeyAuth with patch( # test-quality-ok: grant resolution is the input under test - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[], ): @@ -6743,14 +6745,14 @@ class TestGatewayCreateInitializationOptions: @pytest.mark.asyncio async def test_non_initialize_request_with_no_granted_servers_is_not_rejected_here(self): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _gateway_initialize_instructions_request_scope, mcp_gateway_initialize_instructions, ) - from litellm.proxy._types import UserAPIKeyAuth with patch( # test-quality-ok: grant resolution is the input under test - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[], ): @@ -6764,8 +6766,8 @@ class TestGatewayCreateInitializationOptions: @pytest.mark.asyncio async def test_sse_handler_scopes_server_name_from_single_server_path(self): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( global_mcp_server_manager, handle_sse_mcp, server, @@ -6806,7 +6808,7 @@ class TestGatewayCreateInitializationOptions: with ( patch.object(mcp_server.sse, "connect_sse", connect_sse), patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=( UserAPIKeyAuth(api_key="sk-test"), @@ -6818,7 +6820,7 @@ class TestGatewayCreateInitializationOptions: ), ), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[scoped_server], ), @@ -6828,15 +6830,15 @@ class TestGatewayCreateInitializationOptions: new_callable=AsyncMock, ), patch( - "litellm.proxy._experimental.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", + "litellm.proxy.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", new_callable=AsyncMock, ), patch( - "litellm.proxy._experimental.mcp_server.server._check_passthrough_upstream_auth", + "litellm.proxy.mcp_server.server._check_passthrough_upstream_auth", new_callable=AsyncMock, ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -6853,10 +6855,10 @@ class TestGatewayCreateInitializationOptions: def test_contextvar_set_injects_instructions(self): """When ContextVar has a value, it appears in InitializationOptions.""" try: - from litellm.proxy._experimental.mcp_server.mcp_context import ( + from litellm.proxy.mcp_server.mcp_context import ( mcp_gateway_initialize_instructions, ) - from litellm.proxy._experimental.mcp_server.server import server + from litellm.proxy.mcp_server.server import server except ImportError: pytest.skip("MCP server not available") @@ -6870,10 +6872,10 @@ class TestGatewayCreateInitializationOptions: def test_contextvar_reset_removes_instructions(self): """After resetting the ContextVar, instructions disappear.""" try: - from litellm.proxy._experimental.mcp_server.mcp_context import ( + from litellm.proxy.mcp_server.mcp_context import ( mcp_gateway_initialize_instructions, ) - from litellm.proxy._experimental.mcp_server.server import server + from litellm.proxy.mcp_server.server import server except ImportError: pytest.skip("MCP server not available") @@ -6893,10 +6895,10 @@ async def test_list_tools_with_legacy_db_m2m_server_resolves_oauth2_flow(): Authorization header is forwarded upstream instead of being blocked. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, ) - from litellm.proxy._types import UserAPIKeyAuth from litellm.types.mcp import MCPAuth except ImportError: pytest.skip("MCP server not available") @@ -6953,14 +6955,14 @@ async def test_list_tools_with_legacy_db_m2m_server_resolves_oauth2_flow(): with ( patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, patch( - "litellm.proxy._experimental.mcp_server.operations.filter_tools_by_allowed_tools", + "litellm.proxy.mcp_server.operations.filter_tools_by_allowed_tools", side_effect=lambda tools, _server: tools, ), patch( - "litellm.proxy._experimental.mcp_server.operations.filter_tools_by_key_team_permissions", + "litellm.proxy.mcp_server.operations.filter_tools_by_key_team_permissions", new=AsyncMock(side_effect=lambda tools, **_: tools), ), ): @@ -6997,7 +6999,7 @@ async def test_call_tool_empty_extra_headers_returns_none(): differently if an empty dict is passed instead. """ try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp import MCPAuth @@ -7072,7 +7074,7 @@ async def test_call_tool_empty_extra_headers_returns_none(): @pytest.mark.asyncio async def test_probe_upstream_auth_returns_upstream_status(): """_probe_upstream_auth forwards the status code from the upstream server.""" - from litellm.proxy._experimental.mcp_server.server import _probe_upstream_auth + from litellm.proxy.mcp_server.server import _probe_upstream_auth mock_response = MagicMock() mock_response.status_code = 401 @@ -7082,7 +7084,7 @@ async def test_probe_upstream_auth_returns_upstream_status(): mock_client.post = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.server.get_async_httpx_client", + "litellm.proxy.mcp_server.server.get_async_httpx_client", return_value=mock_client, ): status, www_auth = await _probe_upstream_auth("http://upstream/mcp", "Bearer some-token") @@ -7105,7 +7107,7 @@ async def test_probe_upstream_auth_surfaces_httpx_status_error(): fail-open `except Exception`) so the auth check is not silently defeated. """ - from litellm.proxy._experimental.mcp_server.server import _probe_upstream_auth + from litellm.proxy.mcp_server.server import _probe_upstream_auth mock_response = MagicMock() mock_response.status_code = 401 @@ -7117,7 +7119,7 @@ async def test_probe_upstream_auth_surfaces_httpx_status_error(): mock_client.post = AsyncMock(side_effect=error) with patch( - "litellm.proxy._experimental.mcp_server.server.get_async_httpx_client", + "litellm.proxy.mcp_server.server.get_async_httpx_client", return_value=mock_client, ): status, www_auth = await _probe_upstream_auth("http://upstream/mcp", "Bearer some-token") @@ -7129,13 +7131,13 @@ async def test_probe_upstream_auth_surfaces_httpx_status_error(): @pytest.mark.asyncio async def test_probe_upstream_auth_fails_open_on_network_error(): """_probe_upstream_auth returns (200, None) when the network call fails.""" - from litellm.proxy._experimental.mcp_server.server import _probe_upstream_auth + from litellm.proxy.mcp_server.server import _probe_upstream_auth mock_client = MagicMock() mock_client.post = AsyncMock(side_effect=Exception("connection refused")) with patch( - "litellm.proxy._experimental.mcp_server.server.get_async_httpx_client", + "litellm.proxy.mcp_server.server.get_async_httpx_client", return_value=mock_client, ): status, www_auth = await _probe_upstream_auth("http://upstream/mcp", "Bearer some-token") @@ -7146,7 +7148,7 @@ async def test_probe_upstream_auth_fails_open_on_network_error(): def test_get_forwarded_auth_from_scope_extracts_header(): """Returns Authorization value when x-litellm-api-key is also present.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_forwarded_auth_from_scope, ) @@ -7161,7 +7163,7 @@ def test_get_forwarded_auth_from_scope_extracts_header(): def test_get_forwarded_auth_from_scope_returns_none_when_missing(): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_forwarded_auth_from_scope, ) @@ -7176,7 +7178,7 @@ def test_get_forwarded_auth_from_scope_skips_when_no_litellm_key_header(): leak the proxy key, so the helper must return None and the probe must not fire. """ - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_forwarded_auth_from_scope, ) @@ -7222,7 +7224,7 @@ def _patch_delegate_resolver(server: MCPServer, *resolvable_names: str): return server if name in resolvable_names else None return patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", side_effect=_resolve, ) @@ -7230,10 +7232,10 @@ def _patch_delegate_resolver(server: MCPServer, *resolvable_names: str): @pytest.mark.asyncio async def test_legacy_delegate_bare_token_is_not_probed_upstream(): # test-quality-ok: this removed security-sensitive egress has no return value; non-invocation is the contract """A bare bearer is an admission credential and must never reach upstream.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _check_passthrough_upstream_auth, ) - from litellm.proxy._types import UserAPIKeyAuth server = _delegate_auth_mcp_server() scope = _delegate_scope([(b"authorization", b"Bearer bogus-token")]) @@ -7241,11 +7243,11 @@ async def test_legacy_delegate_bare_token_is_not_probed_upstream(): # test-qual with ( _patch_delegate_resolver(server, "delegate_test"), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[server]), ), patch( - "litellm.proxy._experimental.mcp_server.server._probe_upstream_auth", + "litellm.proxy.mcp_server.server._probe_upstream_auth", new=AsyncMock(return_value=(401, 'Bearer realm="upstream", error="invalid_token"')), ) as probe, ): @@ -7265,10 +7267,10 @@ async def test_legacy_delegate_bare_token_is_not_probed_upstream(): # test-qual @pytest.mark.asyncio async def test_legacy_delegate_dual_credentials_are_not_probed_upstream(): # test-quality-ok: this removed security-sensitive egress has no return value; non-invocation is the contract """A separate upstream bearer never triggers the removed legacy probe.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _check_passthrough_upstream_auth, ) - from litellm.proxy._types import UserAPIKeyAuth server = _delegate_auth_mcp_server() scope = _delegate_scope( @@ -7280,11 +7282,11 @@ async def test_legacy_delegate_dual_credentials_are_not_probed_upstream(): # te with ( patch( # test-quality-ok: isolate authorized-server resolution so this test targets the preflight boundary - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[server]), ), patch( # test-quality-ok: the removed probe call is the security regression under test - "litellm.proxy._experimental.mcp_server.server._probe_upstream_auth", + "litellm.proxy.mcp_server.server._probe_upstream_auth", new=AsyncMock(), ) as probe, ): @@ -7307,10 +7309,10 @@ async def test_legacy_delegate_dual_credentials_are_not_probed_upstream(): # te ) @pytest.mark.asyncio async def test_oauth_passthrough_preflight_preserves_status_contract(probe_status, expected_status): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _check_passthrough_upstream_auth, ) - from litellm.proxy._types import UserAPIKeyAuth server = MCPServer( server_id="passthrough-id", @@ -7330,11 +7332,11 @@ async def test_oauth_passthrough_preflight_preserves_status_contract(probe_statu with ( patch( # test-quality-ok: isolate authorized-server resolution so this test exercises the preflight contract - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[server]), ), patch( # test-quality-ok: the upstream transport boundary is the behavior being mapped to an HTTP response - "litellm.proxy._experimental.mcp_server.server._probe_upstream_auth", + "litellm.proxy.mcp_server.server._probe_upstream_auth", new=AsyncMock(return_value=(probe_status, None)), ) as probe, ): @@ -7371,10 +7373,10 @@ async def test_oauth_passthrough_preflight_preserves_status_contract(probe_statu async def test_delegate_tokenless_request_not_probed(): """Tokenless delegate requests are the preemptive challenge's job; the preflight must not probe upstream with an empty credential.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _check_passthrough_upstream_auth, ) - from litellm.proxy._types import UserAPIKeyAuth server = _delegate_auth_mcp_server() scope = _delegate_scope([(b"content-type", b"application/json")]) @@ -7382,11 +7384,11 @@ async def test_delegate_tokenless_request_not_probed(): with ( _patch_delegate_resolver(server, "delegate_test"), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[server]), ), patch( - "litellm.proxy._experimental.mcp_server.server._probe_upstream_auth", + "litellm.proxy.mcp_server.server._probe_upstream_auth", new=AsyncMock(return_value=(401, None)), ) as probe, ): @@ -7407,10 +7409,10 @@ async def test_delegate_tokenless_request_not_probed(): async def test_delegate_preflight_skipped_on_multi_server_routes(): """The delegate probe is gated to single-server routes so one rejected token cannot 401 a multi-server aggregate connect (matching the OBO preflight).""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _check_passthrough_upstream_auth, ) - from litellm.proxy._types import UserAPIKeyAuth servers = [_delegate_auth_mcp_server("delegate-1"), _delegate_auth_mcp_server("delegate-2")] scope = _delegate_scope([(b"authorization", b"Bearer bogus-token")]) @@ -7418,11 +7420,11 @@ async def test_delegate_preflight_skipped_on_multi_server_routes(): with ( _patch_delegate_resolver(servers[0], "delegate_test", "other_server"), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=servers), ), patch( - "litellm.proxy._experimental.mcp_server.server._probe_upstream_auth", + "litellm.proxy.mcp_server.server._probe_upstream_auth", new=AsyncMock(return_value=(401, None)), ) as probe, ): @@ -7445,10 +7447,10 @@ async def test_bare_authorization_never_probes_passthrough_servers(): only delegate servers (where admission classified it as an upstream token) may be probed with it; ``is_oauth_passthrough`` servers still require the unambiguous ``x-litellm-api-key`` + ``Authorization`` pair.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _check_passthrough_upstream_auth, ) - from litellm.proxy._types import UserAPIKeyAuth passthrough_server = MCPServer( server_id="pt-1", @@ -7464,11 +7466,11 @@ async def test_bare_authorization_never_probes_passthrough_servers(): with ( _patch_delegate_resolver(passthrough_server, "pt_server"), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[passthrough_server]), ), patch( - "litellm.proxy._experimental.mcp_server.server._probe_upstream_auth", + "litellm.proxy.mcp_server.server._probe_upstream_auth", new=AsyncMock(return_value=(401, None)), ) as probe, ): @@ -7493,10 +7495,10 @@ async def test_delegate_not_probed_when_named_only_via_server_id(): so the bare ``Authorization`` header is that LiteLLM key. The probe must resolve the target through the SAME resolver and therefore skip it, never forwarding the key upstream, even though the widened allowed-server set still contains it.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _check_passthrough_upstream_auth, ) - from litellm.proxy._types import UserAPIKeyAuth server = _delegate_auth_mcp_server(server_id="delegate-secret-id") # Admission's resolver matches alias/server_name/name only, never server_id: the @@ -7513,11 +7515,11 @@ async def test_delegate_not_probed_when_named_only_via_server_id(): with ( _patch_delegate_resolver(server, "delegate_test"), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[server]), ), patch( - "litellm.proxy._experimental.mcp_server.server._probe_upstream_auth", + "litellm.proxy.mcp_server.server._probe_upstream_auth", new=AsyncMock(return_value=(401, None)), ) as probe, ): @@ -7539,21 +7541,21 @@ async def test_delegate_probe_not_fanned_out_to_access_group_members(): """A single access-group name passes the one-target route gate but must not fan the delegate probe out to group-expanded member servers; the group name resolves to no server under admission's resolver, so no probe fires.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _check_passthrough_upstream_auth, ) - from litellm.proxy._types import UserAPIKeyAuth group_member = _delegate_auth_mcp_server() with ( _patch_delegate_resolver(group_member, "delegate_test"), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[group_member]), ), patch( - "litellm.proxy._experimental.mcp_server.server._probe_upstream_auth", + "litellm.proxy.mcp_server.server._probe_upstream_auth", new=AsyncMock(return_value=(401, None)), ) as probe, ): @@ -7573,7 +7575,7 @@ async def test_delegate_probe_not_fanned_out_to_access_group_members(): @pytest.mark.asyncio async def test_create_mcp_client_sampling_disabled_by_default(): """Sampling callback must be None when allow_sampling is not set (default False).""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -7592,7 +7594,7 @@ async def test_create_mcp_client_sampling_disabled_by_default(): @pytest.mark.asyncio async def test_create_mcp_client_sampling_enabled(): """Sampling callback must be set when allow_sampling=True.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -7614,7 +7616,7 @@ async def test_execute_mcp_tool_rest_server_id_authoritative_for_unprefixed_tool """REST server_id + unprefixed tool name must not use global tool-name mapping.""" from mcp.types import TextContent - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module api_key_server = MCPServer( server_id="api-key-server-id", @@ -7711,7 +7713,7 @@ def _worker_that_never_listed(server: MCPServer, upstream_tools: tuple[str, ...] tools/list with ``upstream_tools`` and a managed dispatch that records what reaches it.""" from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module mcp_operations.global_mcp_server_manager.registry[server.server_id] = server dispatched: dict[str, object] = {} @@ -7745,7 +7747,7 @@ def _worker_that_never_listed(server: MCPServer, upstream_tools: tuple[str, ...] async def test_execute_mcp_tool_lists_never_listed_passthrough_server_with_caller_token_first(): """A prefixed tools/call on a worker that has not served tools/list must list that server once with the caller's own credentials and then dispatch, instead of answering 404.""" - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module server = _never_listed_passthrough_server() with _worker_that_never_listed(server, upstream_tools=("add",)) as worker: @@ -7766,7 +7768,7 @@ async def test_execute_mcp_tool_lists_never_listed_passthrough_server_with_calle @pytest.mark.asyncio async def test_execute_mcp_tool_rest_server_id_lists_never_listed_server_first(): - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module server = _never_listed_passthrough_server() with _worker_that_never_listed(server, upstream_tools=("add",)) as worker: @@ -7786,7 +7788,7 @@ async def test_execute_mcp_tool_rest_server_id_lists_never_listed_server_first() @pytest.mark.asyncio async def test_execute_mcp_tool_unknown_tool_on_never_listed_server_lists_once_then_404s(): - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module server = _never_listed_passthrough_server() with ( @@ -7810,7 +7812,7 @@ async def test_execute_mcp_tool_unknown_tool_on_never_listed_server_lists_once_t async def test_execute_mcp_tool_does_not_relist_a_server_this_worker_already_listed(): from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module server = _never_listed_passthrough_server() with _worker_that_never_listed(server, upstream_tools=("add",)) as worker: @@ -7833,7 +7835,7 @@ async def test_execute_mcp_tool_lists_a_tool_this_worker_has_not_yet_seen_on_a_l for a different tool it has not cached, so callers with wider upstream catalogs are not 404ed.""" from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module server = _never_listed_passthrough_server() with _worker_that_never_listed(server, upstream_tools=("add", "multiply")) as worker: @@ -7853,7 +7855,7 @@ async def test_execute_mcp_tool_lists_a_tool_this_worker_has_not_yet_seen_on_a_l @pytest.mark.asyncio async def test_execute_mcp_tool_never_lists_a_server_the_caller_cannot_access(): - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module server = _never_listed_passthrough_server() other_server = MCPServer(server_id="other-1", name="other", transport=MCPTransport.http) @@ -7884,7 +7886,7 @@ async def test_execute_mcp_tool_strips_a_prefix_that_contains_the_separator(): """ from mcp.types import TextContent - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module server_id = "117c814c-1a2b-4c4d-8e8f-0a1b2c3d4e5f" alias_less_server = MCPServer( @@ -7943,7 +7945,7 @@ async def test_execute_mcp_tool_rest_server_id_injects_requested_server_credenti """REST server_id must inject the requested server's auth, not a URL-collision peer's.""" from mcp.types import TextContent - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module requested_server = MCPServer( server_id="requested-server-id", @@ -8027,7 +8029,7 @@ async def test_execute_mcp_tool_rest_server_id_injects_requested_server_credenti @pytest.mark.asyncio async def test_execute_mcp_tool_rest_prefixed_tool_still_validates_server_id(): """Prefixed REST tool names must still match the requested server_id.""" - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module api_key_server = MCPServer( server_id="api-key-server-id", @@ -8091,7 +8093,7 @@ async def test_execute_mcp_tool_rest_prefixed_tool_still_validates_server_id(): @pytest.mark.asyncio async def test_execute_mcp_tool_rest_unauthorized_prefix_still_mismatches(): """Prefixed name for a registry server the caller cannot access must 403.""" - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module api_key_server = MCPServer( server_id="api-key-server-id", @@ -8155,7 +8157,7 @@ async def test_execute_mcp_tool_rest_hyphenated_upstream_tool_name_routes_to_req """REST server_id + hyphenated upstream tool name (no registry prefix) must route, not 400.""" from mcp.types import TextContent - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module api_key_server = MCPServer( server_id="api-key-server-id", @@ -8226,8 +8228,8 @@ async def test_execute_mcp_tool_sets_model_in_model_call_details(): import uuid from datetime import timezone - from litellm.proxy._experimental.mcp_server import server as mcp_module from litellm.proxy._types import LitellmUserRoles + from litellm.proxy.mcp_server import server as mcp_module from litellm.utils import Rules, function_setup user = UserAPIKeyAuth( @@ -8281,11 +8283,11 @@ async def test_execute_mcp_tool_sets_model_in_model_call_details(): return_value=fake_tool, ), patch( - "litellm.proxy._experimental.mcp_server.operations._handle_local_mcp_tool", + "litellm.proxy.mcp_server.operations._handle_local_mcp_tool", new=AsyncMock(return_value=CallToolResult(content=[], is_error=False)), ), patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ), ): @@ -8308,7 +8310,7 @@ async def test_execute_mcp_tool_hands_openapi_hooks_the_listed_entry_and_nothing only, as before this metadata existed, so a pre_mcp_call policy never scans a description the caller was not served. Once the caller has listed, the same call hands the entry that listing served.""" from litellm.caching.caching import DualCache - from litellm.proxy._experimental.mcp_server import operations as mcp_module + from litellm.proxy.mcp_server import operations as mcp_module from litellm.proxy.utils import ProxyLogging petstore = MCPServer( @@ -8368,7 +8370,7 @@ async def test_execute_mcp_tool_hands_openapi_hooks_the_listed_entry_and_nothing async def test_execute_mcp_tool_hands_openapi_hooks_the_guarded_catalog_entry_clients_saw(): """When tools/list pinned the schema and masked the description of an OpenAPI tool, the local-registry call path must hand the pre-call hooks that served entry, not the raw registry one.""" - from litellm.proxy._experimental.mcp_server import operations as mcp_module + from litellm.proxy.mcp_server import operations as mcp_module petstore = MCPServer( server_id="petstore-id", @@ -8422,7 +8424,7 @@ async def test_execute_mcp_tool_hands_openapi_hooks_the_guarded_catalog_entry_cl async def test_execute_mcp_tool_hands_openapi_hooks_each_callers_own_listed_entry(): """Two keys can be shown differently guarded OpenAPI catalogs. The call path must evaluate each key against the entry its own tools/list served, not the entry the most recent listing left behind.""" - from litellm.proxy._experimental.mcp_server import operations as mcp_module + from litellm.proxy.mcp_server import operations as mcp_module petstore = MCPServer( server_id="petstore-id", @@ -8478,7 +8480,7 @@ async def test_execute_mcp_tool_hands_openapi_hooks_each_callers_own_listed_entr async def test_execute_mcp_tool_runs_the_longer_colliding_operation_and_hands_hooks_no_registry_metadata(): """An OpenAPI operation whose name starts with its own server prefix runs instead of the shorter one, and with no prior listing the pre-call hooks get name and arguments only, never either registry entry.""" - from litellm.proxy._experimental.mcp_server import operations as mcp_module + from litellm.proxy.mcp_server import operations as mcp_module petstore = MCPServer( server_id="petstore-id", @@ -8522,7 +8524,7 @@ async def test_execute_mcp_tool_runs_the_longer_colliding_operation_and_hands_ho async def test_execute_mcp_tool_hands_hooks_nothing_for_a_never_listed_operation_named_after_a_listed_one(): """After the caller listed ``get_pet``, a call to the never-listed ``petstore-get_pet`` operation hands the pre-call hooks name and arguments only, not the listed sibling's description and schema.""" - from litellm.proxy._experimental.mcp_server import operations as mcp_module + from litellm.proxy.mcp_server import operations as mcp_module petstore = MCPServer( server_id="petstore-id", @@ -8612,7 +8614,7 @@ async def test_fetch_pinnable_tool_catalog_records_no_listed_catalog_for_the_adm """The pin snapshot lists the raw upstream catalog, without the catalog guard or the admin's description overrides, so it must not become what the admin's own later tools/call is evaluated against.""" from litellm.caching.caching import DualCache - from litellm.proxy._experimental.mcp_server.rest_endpoints import fetch_pinnable_tool_catalog + from litellm.proxy.mcp_server.rest_endpoints import fetch_pinnable_tool_catalog from litellm.proxy.utils import ProxyLogging manager = mcp_operations.global_mcp_server_manager @@ -8655,7 +8657,7 @@ async def test_execute_mcp_tool_rest_unresolved_prefixed_name_routes_to_requeste """ from mcp.types import TextContent - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module requested_server = MCPServer( server_id="rest-target-id", @@ -8739,7 +8741,7 @@ async def test_execute_mcp_tool_rest_unresolved_prefixed_name_routes_to_requeste @pytest.mark.asyncio async def test_execute_mcp_tool_rest_prefix_retry_resolution_still_enforces_server_id(): """A managed tool resolved via the requested server's prefix must still honor the server_id guard.""" - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module requested_server = MCPServer( server_id="api-key-server-id", @@ -8831,7 +8833,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_unknown_name_fails_ NOT silently fall back to the caller's full allowed-server set. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_allowed_mcp_servers_from_mcp_server_names, ) except ImportError: @@ -8843,7 +8845,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_unknown_name_fails_ ] with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp." + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp." "MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], @@ -8864,7 +8866,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_none_returns_all(): path that the fail-closed fix must not break. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_allowed_mcp_servers_from_mcp_server_names, ) except ImportError: @@ -8890,7 +8892,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_known_alias_returns server. Guards against the fix accidentally narrowing the happy path. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_allowed_mcp_servers_from_mcp_server_names, ) except ImportError: @@ -8902,7 +8904,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_known_alias_returns ] with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp." + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp." "MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], @@ -8923,7 +8925,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_mixed_known_and_unk when NOTHING resolves. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_allowed_mcp_servers_from_mcp_server_names, ) except ImportError: @@ -8935,7 +8937,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_mixed_known_and_unk ] with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp." + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp." "MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], @@ -8956,7 +8958,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_access_group_resolv as unresolved). """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_allowed_mcp_servers_from_mcp_server_names, ) except ImportError: @@ -8968,7 +8970,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_access_group_resolv ] with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp." + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp." "MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=["id-b"], @@ -8988,7 +8990,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_empty_list_fails_cl explicit filter request. Fail closed rather than returning everything. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_allowed_mcp_servers_from_mcp_server_names, ) except ImportError: @@ -9016,10 +9018,10 @@ class TestProxyExceptionToHttpException: """ def test_preserves_401_status_and_www_authenticate_header(self): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import ProxyException + from litellm.proxy.mcp_server.server import ( _proxy_exception_to_http_exception, ) - from litellm.proxy._types import ProxyException exc = ProxyException( message="Authentication Error, invalid token", @@ -9036,10 +9038,10 @@ class TestProxyExceptionToHttpException: assert http_exc.headers["WWW-Authenticate"] == 'Bearer resource_metadata="/x"' def test_preserves_403_status(self): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import ProxyException + from litellm.proxy.mcp_server.server import ( _proxy_exception_to_http_exception, ) - from litellm.proxy._types import ProxyException http_exc = _proxy_exception_to_http_exception( ProxyException(message="Forbidden", type="auth_error", param="key", code=403) @@ -9048,10 +9050,10 @@ class TestProxyExceptionToHttpException: assert http_exc.status_code == 403 def test_non_numeric_code_falls_back_to_500(self): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import ProxyException + from litellm.proxy.mcp_server.server import ( _proxy_exception_to_http_exception, ) - from litellm.proxy._types import ProxyException # ProxyException normalises code to the string "None" when unset. http_exc = _proxy_exception_to_http_exception( @@ -9069,8 +9071,8 @@ class TestStreamableHttpAuthErrorMapping: @pytest.mark.asyncio async def test_streamable_http_propagates_proxy_exception_as_401(self): - from litellm.proxy._experimental.mcp_server import server as mcp_module from litellm.proxy._types import ProxyException + from litellm.proxy.mcp_server import server as mcp_module scope = { "type": "http", @@ -9110,8 +9112,8 @@ class TestStreamableHttpAuthErrorMapping: @pytest.mark.asyncio async def test_sse_propagates_proxy_exception_as_401(self): - from litellm.proxy._experimental.mcp_server import server as mcp_module from litellm.proxy._types import ProxyException + from litellm.proxy.mcp_server import server as mcp_module scope = { "type": "http", @@ -9166,7 +9168,7 @@ class TestMCPMetaTraceCarrier: from mcp.types import CallToolRequestParams - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _mcp_meta_trace_carrier, ) @@ -9194,7 +9196,7 @@ class TestMCPMetaTraceCarrier: from mcp.types import CallToolRequestParams - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _mcp_meta_trace_carrier, ) @@ -9216,15 +9218,15 @@ async def test_stateful_mcp_tool_call_uses_current_requests_otel_destinations(_m reset_request_destinations, set_request_destinations, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _MCP_DESTINATIONS_SCOPE_KEY, mcp_server_tool_call, set_auth_context, ) - from litellm.proxy._experimental.mcp_server.tool_registry import ( + from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) @@ -9270,10 +9272,10 @@ async def test_stateful_mcp_tool_call_uses_current_requests_otel_destinations(_m @pytest.mark.asyncio async def test_get_allowed_mcp_servers_includes_active_servers_submitted_by_user(): """BYOM submitters can see approved servers they submitted without allow_all_keys.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth submitted_server = _make_mcp_server_for_scope_filter("submitted-1", "user_mcp") submitter = UserAPIKeyAuth( @@ -9297,13 +9299,13 @@ async def test_get_allowed_mcp_servers_includes_active_servers_submitted_by_user return_value={"submitted-1": submitted_server}, ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp." + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp." "MCPRequestHandler.get_allowed_mcp_servers", AsyncMock(return_value=[]), ), patch("litellm.proxy.proxy_server.prisma_client", MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_active_submitted_mcp_server_ids_for_user", + "litellm.proxy.mcp_server.db.get_active_submitted_mcp_server_ids_for_user", side_effect=_submitted_ids, ), ): @@ -9316,10 +9318,10 @@ async def test_get_allowed_mcp_servers_includes_active_servers_submitted_by_user @pytest.mark.asyncio async def test_get_active_submitted_mcp_server_ids_for_user_queries_active_rows(): - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy._types import MCPApprovalStatus + from litellm.proxy.mcp_server.db import ( get_active_submitted_mcp_server_ids_for_user, ) - from litellm.proxy._types import MCPApprovalStatus row = MagicMock() row.server_id = "submitted-1" @@ -9340,7 +9342,7 @@ async def test_get_active_submitted_mcp_server_ids_for_user_queries_active_rows( @pytest.mark.asyncio async def test_get_active_submitted_mcp_server_ids_for_user_empty_user_id_skips_db(): - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( get_active_submitted_mcp_server_ids_for_user, ) @@ -9380,7 +9382,7 @@ def _mock_mcp_proxy_logging() -> MagicMock: def test_extract_mcp_tool_result_error_message(): - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( extract_mcp_tool_result_error_message, ) @@ -9403,8 +9405,8 @@ async def test_fire_mcp_tool_call_logging_iserror_logs_failure(): """Regression test: a CallToolResult with is_error=True must go down the failure logging path (async_failure_handler + post_call_failure_hook), never async_success_handler.""" - from litellm.proxy._experimental.mcp_server.exceptions import MCPToolResultError - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.exceptions import MCPToolResultError + from litellm.proxy.mcp_server.server import ( _fire_mcp_tool_call_logging, ) @@ -9442,7 +9444,7 @@ async def test_fire_mcp_tool_call_logging_iserror_logs_failure(): async def test_fire_mcp_tool_call_logging_success_path_unchanged(): """is_error=False must keep today's behavior: success handler fires, no failure logging, no post_call_failure_hook.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _fire_mcp_tool_call_logging, ) @@ -9471,7 +9473,7 @@ async def test_fire_mcp_tool_call_logging_success_path_unchanged(): async def test_fire_mcp_tool_call_logging_applies_hook_content(): from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.litellm_logging import Logging - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _fire_mcp_tool_call_logging, ) from litellm.types.mcp import MCPPostCallResponseObject @@ -9529,7 +9531,7 @@ async def test_fire_mcp_tool_call_logging_applies_hook_content(): async def test_fire_mcp_tool_call_logging_iserror_without_auth_skips_failure_hook(): """Without a UserAPIKeyAuth the failure handlers still fire but the proxy post_call_failure_hook (which requires one) is skipped.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _fire_mcp_tool_call_logging, ) @@ -9555,7 +9557,7 @@ async def test_fire_mcp_tool_call_logging_strips_credentials_from_failure_hook() """Credential-bearing request_data fields (raw request headers, upstream MCP auth headers, OAuth tokens) must never reach post_call_failure_hook callbacks; non-credential fields must survive untouched.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _fire_mcp_tool_call_logging, ) @@ -9621,7 +9623,7 @@ async def test_fire_mcp_tool_call_logging_iserror_builds_failure_payload(monkeyp status='failure' with the tool's error text, so OTel (whose _parse_error keys off status) marks the MCP span ERROR.""" import litellm - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _fire_mcp_tool_call_logging, ) @@ -9650,7 +9652,7 @@ async def test_fire_mcp_tool_call_logging_iserror_builds_failure_payload(monkeyp async def test_fire_mcp_tool_call_logging_success_builds_success_payload(monkeypatch): """is_error=False still produces a status='success' payload.""" import litellm - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _fire_mcp_tool_call_logging, ) @@ -9687,7 +9689,7 @@ async def test_fire_mcp_tool_call_logging_iserror_emits_otel_error_span(monkeypa from litellm.integrations.otel import OpenTelemetryV2Config from litellm.integrations.otel.logger import OpenTelemetryV2 from litellm.integrations.otel.plumbing import providers - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _fire_mcp_tool_call_logging, ) @@ -9728,8 +9730,8 @@ async def test_call_tool_with_legacy_db_m2m_server_resolves_oauth2_flow(): call path was not). """ try: - from litellm.proxy._experimental.mcp_server.server import call_mcp_tool from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import call_mcp_tool from litellm.types.mcp import MCPAuth except ImportError: pytest.skip("MCP server not available") @@ -9758,14 +9760,14 @@ async def test_call_tool_with_legacy_db_m2m_server_resolves_oauth2_flow(): with ( patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, patch( - "litellm.proxy._experimental.mcp_server.operations.execute_mcp_tool", + "litellm.proxy.mcp_server.operations.execute_mcp_tool", side_effect=capture_execute, ), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers_from_mcp_server_names", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers_from_mcp_server_names", new=AsyncMock(side_effect=lambda mcp_servers, allowed_mcp_servers: allowed_mcp_servers), ), ): @@ -9803,7 +9805,7 @@ def test_redact_mcp_resource_url_strips_credentials(url, expected): """The MCP tool-call log records the upstream resource, so the URL must be redacted to scheme+host+path: userinfo, query string, and fragment (which can carry embedded tokens or secret parameters) must never reach spend-log metadata or logging callbacks.""" - from litellm.proxy._experimental.mcp_server.server import redact_mcp_resource_url + from litellm.proxy.mcp_server.server import redact_mcp_resource_url assert redact_mcp_resource_url(url) == expected @@ -9814,12 +9816,12 @@ async def test_call_mcp_tool_skips_failure_hook_for_upstream_auth_error(): caller-must-reauth signal, not a failed call, so call_mcp_tool must re-raise it WITHOUT firing post_call_failure_hook (which records a failure and can trip LLM exception alerts). The streamable handler downgrades it to an informational isError result afterward.""" - from litellm.proxy._experimental.mcp_server.exceptions import MCPUpstreamAuthError - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import MCPTransport, UserAPIKeyAuth + from litellm.proxy.mcp_server.exceptions import MCPUpstreamAuthError + from litellm.proxy.mcp_server.server import ( call_mcp_tool, global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport, UserAPIKeyAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer mock_server = MCPServer( @@ -9843,12 +9845,12 @@ async def test_call_mcp_tool_skips_failure_hook_for_upstream_auth_error(): ), patch.object(global_mcp_server_manager, "get_mcp_server_by_id", return_value=mock_server), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers_from_mcp_server_names", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers_from_mcp_server_names", new_callable=AsyncMock, return_value=[mock_server], ), patch( - "litellm.proxy._experimental.mcp_server.operations.execute_mcp_tool", + "litellm.proxy.mcp_server.operations.execute_mcp_tool", new_callable=AsyncMock, side_effect=MCPUpstreamAuthError(status_code=401, www_authenticate="Bearer", server_name="test_server"), ), @@ -9884,7 +9886,7 @@ def _interim_input_required_result(): @contextlib.contextmanager def _managed_tool_returning(server, upstream_result, proxy_logging_mock): - from litellm.proxy._experimental.mcp_server.server import global_mcp_server_manager + from litellm.proxy.mcp_server.server import global_mcp_server_manager with ( patch.object( @@ -9897,20 +9899,20 @@ def _managed_tool_returning(server, upstream_result, proxy_logging_mock): patch.object(global_mcp_server_manager, "get_mcp_server_from_tool_name", return_value=server), patch.object(global_mcp_server_manager, "server_owning_tool_name_prefix", return_value=server), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers_from_mcp_server_names", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers_from_mcp_server_names", new_callable=AsyncMock, return_value=[server], ), patch( - "litellm.proxy._experimental.mcp_server.operations._list_tools_before_first_call", + "litellm.proxy.mcp_server.operations._list_tools_before_first_call", new_callable=AsyncMock, ), patch( - "litellm.proxy._experimental.mcp_server.operations._prepare_mcp_server_headers", + "litellm.proxy.mcp_server.operations._prepare_mcp_server_headers", return_value=(None, None), ), patch( - "litellm.proxy._experimental.mcp_server.operations._handle_managed_mcp_tool", + "litellm.proxy.mcp_server.operations._handle_managed_mcp_tool", new_callable=AsyncMock, return_value=upstream_result, ) as managed_call, @@ -9925,12 +9927,12 @@ async def test_call_mcp_tool_legacy_interim_result_is_rejected_into_failure_acco must come back as isError and go through the same failure accounting as any other errored call.""" from mcp.types import CallToolResult - from litellm.proxy._experimental.mcp_server.result_conversion import ( + from litellm.proxy._types import MCPTransport, UserAPIKeyAuth + from litellm.proxy.mcp_server.result_conversion import ( INPUT_REQUIRED_UNSUPPORTED_MESSAGE, WireCompat, ) - from litellm.proxy._experimental.mcp_server.server import call_mcp_tool - from litellm.proxy._types import MCPTransport, UserAPIKeyAuth + from litellm.proxy.mcp_server.server import call_mcp_tool from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -9969,9 +9971,9 @@ async def test_call_mcp_tool_modern_interim_result_passes_through_without_comple logged as a completed success nor run through the post-call guardrail and success hooks.""" from mcp.types import InputRequiredResult - from litellm.proxy._experimental.mcp_server.result_conversion import WireCompat - from litellm.proxy._experimental.mcp_server.server import call_mcp_tool from litellm.proxy._types import MCPTransport, UserAPIKeyAuth + from litellm.proxy.mcp_server.result_conversion import WireCompat + from litellm.proxy.mcp_server.server import call_mcp_tool from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -10016,15 +10018,15 @@ async def test_aggregate_listing_reports_per_server_outcomes(): """A failed server must contribute a classified outcome, not just silently shrink the list: without the outcome a broken upstream is indistinguishable from a healthy server with no tools.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) except ImportError: pytest.skip("MCP server not available") - from litellm.proxy._experimental.mcp_server.exceptions import MCPServerListError - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ServerListFault + from litellm.proxy.mcp_server.exceptions import MCPServerListError + from litellm.proxy.mcp_server.faults.list_outcomes import ServerListFault user_api_key_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user") set_auth_context(user_api_key_auth) @@ -10074,7 +10076,7 @@ async def test_aggregate_listing_reports_per_server_outcomes(): mock_manager.get_tools_from_server = mock_get_tools_from_server with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): listing = await _get_tools_from_mcp_servers( @@ -10099,7 +10101,7 @@ async def test_outcome_keys_use_display_prefix_never_canonical_names(): the caller already sees on tool names: keying them by canonical server_name would let any authenticated caller enumerate internal server names the alias scheme deliberately hides.""" try: - from litellm.proxy._experimental.mcp_server.server import _aggregate_server_key + from litellm.proxy.mcp_server.server import _aggregate_server_key except ImportError: pytest.skip("MCP server not available") @@ -10120,13 +10122,13 @@ async def test_handle_list_tools_attaches_outcome_meta(_mcp_request_ctx): """The protocol handler returns a ListToolsResult whose _meta carries the per-server outcomes, so MCP clients can tell a degraded listing from a genuinely empty one.""" try: - from litellm.proxy._experimental.mcp_server.server import handle_list_tools + from litellm.proxy.mcp_server.server import handle_list_tools except ImportError: pytest.skip("MCP server not available") from mcp.types import ListToolsResult, Tool - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.mcp_server.faults.list_outcomes import ( SERVER_OUTCOMES_META_KEY, AggregateToolListing, ServerListFault, @@ -10144,11 +10146,11 @@ async def test_handle_list_tools_attaches_outcome_meta(_mcp_request_ctx): with ( patch( - "litellm.proxy._experimental.mcp_server.server.get_or_extract_auth_context", + "litellm.proxy.mcp_server.server.get_or_extract_auth_context", new=AsyncMock(return_value=(None, None, None, None, None, None, None)), ), patch( - "litellm.proxy._experimental.mcp_server.operations._list_mcp_tools", + "litellm.proxy.mcp_server.operations._list_mcp_tools", new=AsyncMock(return_value=listing), ), ): @@ -10167,17 +10169,17 @@ async def _list_tools_with_listing( params: PaginatedRequestParams, ) -> ListToolsResult: try: - from litellm.proxy._experimental.mcp_server.server import handle_list_tools + from litellm.proxy.mcp_server.server import handle_list_tools except ImportError: pytest.skip("MCP server not available") with ( patch( - "litellm.proxy._experimental.mcp_server.server.get_or_extract_auth_context", + "litellm.proxy.mcp_server.server.get_or_extract_auth_context", new=AsyncMock(return_value=(None, None, None, None, None, None, None)), ), patch( - "litellm.proxy._experimental.mcp_server.operations._list_mcp_tools", + "litellm.proxy.mcp_server.operations._list_mcp_tools", new=AsyncMock(return_value=listing), ), ): @@ -10191,7 +10193,7 @@ async def test_handle_list_tools_errors_when_every_server_failed( from mcp.shared.exceptions import MCPError from mcp.types import INTERNAL_ERROR - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.mcp_server.faults.list_outcomes import ( SERVER_OUTCOMES_META_KEY, AggregateToolListing, ServerListFault, @@ -10222,7 +10224,7 @@ async def test_handle_list_tools_auth_fault_keeps_degraded_result( ) -> None: from mcp.types import ListToolsResult - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.mcp_server.faults.list_outcomes import ( SERVER_OUTCOMES_META_KEY, AggregateToolListing, ServerListFault, @@ -10247,7 +10249,7 @@ async def test_handle_list_tools_all_faults_on_continuation_stays_degraded( ) -> None: from mcp.types import ListToolsResult, PaginatedRequestParams - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.mcp_server.faults.list_outcomes import ( SERVER_OUTCOMES_META_KEY, AggregateToolListing, ServerListFault, @@ -10274,7 +10276,7 @@ async def test_handle_list_tools_empty_outcomes_is_a_clean_empty_result( ) -> None: from mcp.types import ListToolsResult - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import AggregateToolListing + from litellm.proxy.mcp_server.faults.list_outcomes import AggregateToolListing listing: Final = AggregateToolListing(tools=[], outcomes={}) @@ -10335,7 +10337,7 @@ class TestPreemptive401ModeAware: return {"type": "http", "method": "POST", "path": f"/mcp/{alias}", "headers": []} async def _run(self, server, oauth2_headers, has_stored_token: bool): - from litellm.proxy._experimental.mcp_server import server as server_module + from litellm.proxy.mcp_server import server as server_module with ( patch.object( @@ -10361,7 +10363,7 @@ class TestPreemptive401ModeAware: @pytest.mark.asyncio async def test_deferred_discovery_runs_before_delegate_challenge(self): - from litellm.proxy._experimental.mcp_server import server as server_module + from litellm.proxy.mcp_server import server as server_module manager = mcp_operations.global_mcp_server_manager server = _make_oauth2_server( @@ -10393,7 +10395,7 @@ class TestPreemptive401ModeAware: @pytest.mark.asyncio async def test_stamped_m2m_challenge_skips_deferred_discovery(self): - from litellm.proxy._experimental.mcp_server import server as server_module + from litellm.proxy.mcp_server import server as server_module manager = mcp_operations.global_mcp_server_manager server = _make_oauth2_server("stamped_m2m", oauth2_flow="client_credentials") @@ -10426,7 +10428,7 @@ class TestPreemptive401ModeAware: async def test_gateway_as_metadata_challenge_under_server_root_path(self, original_path, expected_as_path): """Under SERVER_ROOT_PATH the challenge must keep the spelling the client called and point at a route the proxy registered, so it has to compare a route-relative path and carry the root suffix.""" - from litellm.proxy._experimental.mcp_server import server as server_module + from litellm.proxy.mcp_server import server as server_module server = _make_oauth2_server("interactive", oauth2_flow="authorization_code") scope = { @@ -10541,7 +10543,7 @@ class TestSingleServerPreflightReachesIdJag: ) async def _run(self, server: MCPServer, mcp_servers: list[str], preflight: AsyncMock) -> None: - from litellm.proxy._experimental.mcp_server import server as server_module + from litellm.proxy.mcp_server import server as server_module with ( patch.object( # test-quality-ok: route wiring must use the manager's configured server @@ -10586,7 +10588,7 @@ class TestSingleServerPreflightReachesIdJag: RFC 9728 discovery challenge from the block above and the preflight is never reached; pushing a subject-less exchange through the resolver would turn that challenge into some other status and strand a client that only had to SSO and retry.""" - from litellm.proxy._experimental.mcp_server import server as server_module + from litellm.proxy.mcp_server import server as server_module token_exchange = MCPServer( server_id="id-obo", @@ -10665,7 +10667,7 @@ class TestOboPreflightScopedToAllowedServers: SUBJECT_HEADERS = {"Authorization": "Bearer upstream-subject-token"} async def _run(self, requested: MCPServer, allowed: list[MCPServer], user_api_key_auth: UserAPIKeyAuth | None): - from litellm.proxy._experimental.mcp_server import server as server_module + from litellm.proxy.mcp_server import server as server_module allowed_lookup = AsyncMock(return_value=allowed) preflight = AsyncMock() @@ -10719,7 +10721,7 @@ class TestOboPreflightScopedToAllowedServers: @pytest.mark.asyncio async def test_post_mcp_call_guardrails_return_the_rewritten_result(): """The result a post_mcp_call guardrail rewrote must be what the caller sends back.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _run_post_mcp_call_guardrails, ) @@ -10753,7 +10755,7 @@ async def test_post_mcp_call_guardrails_run_without_a_logging_object(): caller that omits it) would otherwise skip the guardrail entirely and return the unscanned tool output to the client. """ - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _run_post_mcp_call_guardrails, ) @@ -10781,7 +10783,7 @@ async def test_post_mcp_call_guardrails_run_without_a_logging_object(): async def test_post_mcp_call_guardrails_propagate_a_block(): """A post_mcp_call guardrail rejection must propagate instead of returning the result.""" from litellm.exceptions import BlockedPiiEntityError - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _run_post_mcp_call_guardrails, ) @@ -10805,8 +10807,8 @@ async def test_post_mcp_call_guardrails_propagate_a_block(): async def test_post_mcp_call_guardrails_preserve_and_deduplicate_mapping_entries( monkeypatch: pytest.MonkeyPatch, ) -> None: - from litellm.proxy._experimental.mcp_server.server import _run_post_mcp_call_guardrails from litellm.proxy import proxy_server + from litellm.proxy.mcp_server.server import _run_post_mcp_call_guardrails monkeypatch.setattr("litellm.proxy.utils.premium_user_check", MagicMock()) monkeypatch.setattr(proxy_server, "premium_user", True, raising=False) @@ -10857,7 +10859,7 @@ class TestListFiltersHonorThePrefixBoundary: @staticmethod def _alias_less_server(**overrides): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServer + from litellm.proxy.mcp_server.mcp_server_manager import MCPServer return MCPServer( server_id=TestListFiltersHonorThePrefixBoundary.SERVER_ID, @@ -10876,7 +10878,7 @@ class TestListFiltersHonorThePrefixBoundary: ] def test_bare_allowlist_entry_keeps_the_published_tool(self): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_allowed_tools, ) @@ -10888,7 +10890,7 @@ class TestListFiltersHonorThePrefixBoundary: assert [tool.name for tool in kept] == [f"{self.SERVER_ID}-read_wiki_contents"] def test_bare_blocklist_entry_excludes_the_published_tool(self): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_allowed_tools, ) @@ -10900,7 +10902,7 @@ class TestListFiltersHonorThePrefixBoundary: assert [tool.name for tool in kept] == [f"{self.SERVER_ID}-read_wiki_contents"] def test_unrelated_entry_does_not_match(self): - from litellm.proxy._experimental.mcp_server.server import _tool_name_matches + from litellm.proxy.mcp_server.server import _tool_name_matches server = self._alias_less_server() @@ -10911,7 +10913,7 @@ class TestListFiltersHonorThePrefixBoundary: # folding recovers a spec-spelled entry on an OpenAPI server. A native server # gets none of it: routing dispatches two names differing only in case as two # tools, so one policy must not decide both. - from litellm.proxy._experimental.mcp_server.server import _tool_name_matches + from litellm.proxy.mcp_server.server import _tool_name_matches native = self._alias_less_server() openapi = self._alias_less_server(spec_path="/specs/petstore.yaml") @@ -10924,8 +10926,8 @@ class TestListFiltersHonorThePrefixBoundary: # Routing accepts the alias form, so an entry stored before short # prefixes were turned on still governs the tool. Matching only the # published spelling left it advertised while dispatch refused it. - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServer - from litellm.proxy._experimental.mcp_server.server import _tool_name_matches + from litellm.proxy.mcp_server.mcp_server_manager import MCPServer + from litellm.proxy.mcp_server.server import _tool_name_matches monkeypatch.setenv("LITELLM_USE_SHORT_MCP_TOOL_PREFIX", "true") server = MCPServer( @@ -10951,11 +10953,11 @@ class TestListFiltersHonorThePrefixBoundary: """ from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServer, MCPServerManager, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_allowed_tools, ) @@ -11016,13 +11018,13 @@ class TestListFiltersHonorThePrefixBoundary: """ from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_key_team_permissions, ) - from litellm.proxy._types import UserAPIKeyAuth server = MCPServer( server_id=self.SERVER_ID, @@ -11035,7 +11037,7 @@ class TestListFiltersHonorThePrefixBoundary: with ( patch.object(MCPRequestHandler, "get_allowed_tools_for_server", AsyncMock(return_value=grants)), - patch("litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager") as mock_manager, + patch("litellm.proxy.mcp_server.operations.global_mcp_server_manager") as mock_manager, ): mock_manager.get_mcp_server_by_id.return_value = server @@ -11057,7 +11059,7 @@ async def test_list_tools_injects_byok_credential_for_non_oauth2_auth_types(auth """Regression for BYOK servers on a non-oauth2 auth_type: the stored per-user credential must be attached when listing tools, otherwise the upstream 401 is absorbed and the server lists nothing.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) @@ -11098,11 +11100,11 @@ async def test_list_tools_injects_byok_credential_for_non_oauth2_auth_types(auth with ( patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ), patch( - "litellm.proxy._experimental.mcp_server.operations._get_byok_credential", + "litellm.proxy.mcp_server.operations._get_byok_credential", AsyncMock(return_value="personal-api-key"), ), ): @@ -11119,7 +11121,7 @@ async def test_list_tools_injects_byok_credential_for_non_oauth2_auth_types(auth @pytest.mark.asyncio async def test_active_request_ctx_var_feeds_get_current_session(_mcp_request_ctx) -> None: - from litellm.proxy._experimental.mcp_server.server import _get_current_session + from litellm.proxy.mcp_server.server import _get_current_session session = SimpleNamespace() ctx = _mcp_request_ctx(session=session) @@ -11170,7 +11172,7 @@ async def test_mcp_origin_admission_precedes_authentication( ) -> None: import httpx - from litellm.proxy._experimental.mcp_server import server + from litellm.proxy.mcp_server import server authenticate: Final = AsyncMock(side_effect=HTTPException(status_code=401, detail="authentication required")) with ( @@ -11195,12 +11197,12 @@ async def test_mcp_origin_admission_precedes_authentication( async def test_active_request_ctx_var_feeds_auth_resolution_recording(_mcp_request_ctx) -> None: from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.mcp_debug import ( + from litellm.proxy.mcp_server.mcp_debug import ( MCP_AUTH_DIAGNOSTICS_SCOPE_KEY, MCPAuthDiagnostics, record_auth_resolution, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import AuthResolution + from litellm.proxy.mcp_server.outbound_credentials.types import AuthResolution diagnostics = MCPAuthDiagnostics() ctx = _mcp_request_ctx(request=Request({"type": "http", MCP_AUTH_DIAGNOSTICS_SCOPE_KEY: diagnostics})) @@ -11227,8 +11229,8 @@ async def test_active_request_ctx_var_feeds_auth_resolution_recording(_mcp_reque async def test_streamable_http_rejects_modern_protocol_version( header_value: str, expected_rejected: bool, handler: str, monkeypatch: pytest.MonkeyPatch ) -> None: - from litellm.proxy._experimental.mcp_server import server as mcp_module - from litellm.proxy._experimental.mcp_server.server import unsupported_protocol_version + from litellm.proxy.mcp_server import server as mcp_module + from litellm.proxy.mcp_server.server import unsupported_protocol_version monkeypatch.setattr("litellm.proxy.proxy_server.general_settings", {}) scope: Scope = { @@ -11272,7 +11274,7 @@ async def test_streamable_http_rejects_modern_protocol_version( ], ) async def test_native_listing_preserves_empty_result_on_auth_failure(_mcp_request_ctx, handler_name, field): - from litellm.proxy._experimental.mcp_server import server + from litellm.proxy.mcp_server import server with patch.object(server, "get_or_extract_auth_context", AsyncMock(side_effect=RuntimeError("auth failure"))): result = await getattr(server, handler_name)(_mcp_request_ctx(), _paged_params()) @@ -11282,8 +11284,8 @@ async def test_native_listing_preserves_empty_result_on_auth_failure(_mcp_reques @pytest.mark.asyncio @pytest.mark.parametrize("failure_hook_raises", [False, True]) async def test_tool_listing_preserves_permission_denial_when_failure_logging_fails(failure_hook_raises): - from litellm.proxy._experimental.mcp_server import operations from litellm.proxy import proxy_server + from litellm.proxy.mcp_server import operations auth = UserAPIKeyAuth(user_id="denied-caller") denial = HTTPException(status_code=403, detail="scope denied") @@ -11319,8 +11321,9 @@ async def test_legacy_sse_mount_emits_message_endpoint( ) -> None: from starlette.applications import Starlette from starlette.routing import Mount - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import AggregateToolListing - from litellm.proxy._experimental.mcp_server import server as mcp_server + + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.faults.list_outcomes import AggregateToolListing app: Final = Starlette(routes=[Mount("/mcp", app=mcp_server.app)]) incoming: Final[asyncio.Queue[Message]] = asyncio.Queue() @@ -11468,7 +11471,7 @@ async def test_legacy_sse_mount_emits_message_endpoint( @pytest.mark.parametrize("revision,rejected", [("2024-11-05", False), ("2025-11-25", True), ("2026-07-28", True)]) def test_protocol_header_respects_configured_advertisement(revision, rejected): from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.server import unsupported_protocol_version + from litellm.proxy.mcp_server.server import unsupported_protocol_version with patch.dict(proxy_server.general_settings, {"mcp_advertised_versions": ["2024-11-05"]}): result = unsupported_protocol_version({"headers": [(b"mcp-protocol-version", revision.encode())]}) @@ -11478,7 +11481,8 @@ def test_protocol_header_respects_configured_advertisement(revision, rejected): @pytest.mark.asyncio async def test_discovery_adapter_preserves_authenticated_context(_mcp_request_ctx): from mcp.types import DiscoverResult, RequestParams, ServerCapabilities - from litellm.proxy._experimental.mcp_server import server + + from litellm.proxy.mcp_server import server expected = DiscoverResult(supported_versions=["2025-11-25"], capabilities=ServerCapabilities()) dispatched = AsyncMock(return_value=expected) @@ -11521,11 +11525,13 @@ async def test_modern_oauth_challenge_follows_continuation_authorization( monkeypatch: pytest.MonkeyPatch, ) -> None: import time - from pydantic import TypeAdapter - from litellm.proxy._experimental.mcp_server import server - from litellm.proxy._experimental.mcp_server.contracts import OperationContext - from litellm.proxy._experimental.mcp_server.interactions import InteractionOperation, bind_target, seal_continuation + from mcp.types import InputRequiredResult + from pydantic import TypeAdapter + + from litellm.proxy.mcp_server import server + from litellm.proxy.mcp_server.contracts import OperationContext + from litellm.proxy.mcp_server.interactions import InteractionOperation, bind_target, seal_continuation monkeypatch.setenv("LITELLM_SALT_KEY", "challenge-test-salt") monkeypatch.setattr("litellm.proxy.proxy_server.general_settings", {"mcp_advertised_versions": ["2026-07-28"]}) @@ -11673,7 +11679,7 @@ async def test_modern_oauth_challenge_follows_continuation_authorization( async def test_modern_preflight_enforces_sdk_body_limit( method: str, size_delta: int, chunked: bool, monkeypatch: pytest.MonkeyPatch ) -> None: - from litellm.proxy._experimental.mcp_server import server + from litellm.proxy.mcp_server import server monkeypatch.setattr("litellm.proxy.proxy_server.general_settings", {"mcp_advertised_versions": ["2026-07-28"]}) limit: Final = server.session_manager_stateless.max_request_body_size @@ -11746,8 +11752,8 @@ async def test_modern_preflight_enforces_sdk_body_limit( async def test_modern_preflight_leaves_invalid_envelopes_to_sdk_without_upstream_work( invalid_request: Literal["malformed", "other_method", "header_mismatch", "duplicate_header"], ) -> None: - from litellm.proxy._experimental.mcp_server import server - from litellm.proxy._experimental.mcp_server.contracts import OperationContext + from litellm.proxy.mcp_server import server + from litellm.proxy.mcp_server.contracts import OperationContext envelope: Final = { "jsonrpc": "2.0", @@ -11786,9 +11792,10 @@ async def test_modern_preflight_leaves_invalid_envelopes_to_sdk_without_upstream @pytest.mark.parametrize("forwarded_token", (False, True)) async def test_modern_passthrough_probe_uses_scrubbed_server_credential(binding: str, forwarded_token: bool): import respx + from litellm.proxy._types import LiteLLM_ObjectPermissionTable - from litellm.proxy._experimental.mcp_server import server - from litellm.proxy._experimental.mcp_server.contracts import OperationContext + from litellm.proxy.mcp_server import server + from litellm.proxy.mcp_server.contracts import OperationContext target: Final = MCPServer( server_id="probe-id", @@ -11859,8 +11866,9 @@ async def test_modern_passthrough_probe_uses_scrubbed_server_credential(binding: @pytest.mark.parametrize("header_shape", ("mapping", "non_authorization")) async def test_passthrough_probes_bind_each_token_to_its_authorized_server(allowed: bool, header_shape: str): import respx + from litellm.proxy._types import LiteLLM_ObjectPermissionTable - from litellm.proxy._experimental.mcp_server import server + from litellm.proxy.mcp_server import server targets: Final = [ MCPServer( @@ -11912,7 +11920,7 @@ async def test_passthrough_probes_bind_each_token_to_its_authorized_server(allow @pytest.mark.asyncio async def test_streamable_http_admission_auth_sees_only_peeked_jsonrpc_method() -> None: from litellm.constants import MCP_PEEKED_BODY_SCOPE_KEY - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module scope: Final[Scope] = {"type": "http", "method": "POST", "path": "/mcp", "headers": []} receive: Final = AsyncMock( @@ -11937,22 +11945,22 @@ async def test_streamable_http_admission_auth_sees_only_peeked_jsonrpc_method() with ( patch( # test-quality-ok: the ASGI handler resolves auth through a module-level function; no injection seam - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, side_effect=extract, ), patch( # test-quality-ok: module flag guarding lazy session-manager startup; no injection seam - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True ), patch( # test-quality-ok: the allowlist is read off this module global; no injection seam "litellm.proxy.proxy_server.general_settings", _ALLOWLIST_SETTINGS ), patch( # test-quality-ok: session managers are module singletons; the downstream call is the observable - "litellm.proxy._experimental.mcp_server.server.session_manager_stateful", + "litellm.proxy.mcp_server.server.session_manager_stateful", SimpleNamespace(handle_request=stateful_handle), ), patch( # test-quality-ok: session managers are module singletons; the downstream call is the observable - "litellm.proxy._experimental.mcp_server.server.session_manager_stateless", + "litellm.proxy.mcp_server.server.session_manager_stateless", SimpleNamespace(handle_request=stateless_handle), ), ): @@ -11979,7 +11987,7 @@ async def test_streamable_http_admission_auth_sees_only_peeked_jsonrpc_method() ], ) async def test_stateful_cancellation_does_not_wait_for_call_or_change_its_auth(payload, valid): - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server session_id = "cancellation-isolation-session" owner = UserAPIKeyAuth(api_key="owner-key", user_id="owner") @@ -12047,11 +12055,10 @@ async def test_stateful_cancellation_does_not_wait_for_call_or_change_its_auth(p @pytest.mark.parametrize("selected", [False, True]) async def test_progress_text_obeys_request_output_guardrails(monkeypatch, action, message, selected): import litellm - from litellm.caching.caching import DualCache from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.operations import _guarded_progress_callback from litellm.proxy.guardrails.guardrail_hooks.litellm_content_filter.content_filter import ContentFilterGuardrail + from litellm.proxy.mcp_server.operations import _guarded_progress_callback from litellm.proxy.utils import ProxyLogging from litellm.types.guardrails import BlockedWord, ContentFilterAction, GuardrailEventHooks @@ -12083,7 +12090,7 @@ async def test_progress_text_obeys_request_output_guardrails(monkeypatch, action async def test_progress_callback_preserves_absence_and_cancellation(): import asyncio - from litellm.proxy._experimental.mcp_server.operations import _guarded_progress_callback + from litellm.proxy.mcp_server.operations import _guarded_progress_callback assert _guarded_progress_callback(None, None, None, None, {}) is None callback = _guarded_progress_callback(AsyncMock(side_effect=asyncio.CancelledError), None, None, None, {}) @@ -12097,13 +12104,12 @@ async def test_execute_mcp_tool_derives_team_guardrail_auth_for_personal_keys( monkeypatch: pytest.MonkeyPatch, ) -> None: import litellm - from litellm.caching.caching import DualCache from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy._experimental.mcp_server.utils import get_server_prefix - from litellm.proxy.auth import auth_checks from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable, LiteLLM_UserTable + from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.utils import get_server_prefix from litellm.proxy.utils import ProxyLogging user_api_key_auth: Final = UserAPIKeyAuth(api_key="sk-personal", user_id="owner") diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_session_logging.py b/tests/unit/proxy/mcp_server/test_mcp_session_logging.py similarity index 91% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_session_logging.py rename to tests/unit/proxy/mcp_server/test_mcp_session_logging.py index 790937cc1de..83bd4a29908 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_session_logging.py +++ b/tests/unit/proxy/mcp_server/test_mcp_session_logging.py @@ -1,7 +1,7 @@ """The MCP ``mcp-session-id`` is captured for tool-call logging so the otel span can carry ``mcp.session.id``. Guards the header read against casing and absence.""" -from litellm.proxy._experimental.mcp_server.server import _mcp_session_id_from_headers +from litellm.proxy.mcp_server.server import _mcp_session_id_from_headers def test_reads_session_id_case_insensitively(): diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sigv4_auth.py b/tests/unit/proxy/mcp_server/test_mcp_sigv4_auth.py similarity index 93% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_sigv4_auth.py rename to tests/unit/proxy/mcp_server/test_mcp_sigv4_auth.py index 7b9fc17840a..5350e8a9f41 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sigv4_auth.py +++ b/tests/unit/proxy/mcp_server/test_mcp_sigv4_auth.py @@ -15,7 +15,7 @@ import httpx2 import pytest from prisma import models -from litellm.experimental_mcp_client.client import MCPClient, MCPSigV4Auth +from litellm.mcp_client.client import MCPClient, MCPSigV4Auth from litellm.types.mcp import MCPAuth, MCPTransport _FUTURE_EXPIRATION: Final = datetime.now(timezone.utc) + timedelta(hours=1) @@ -444,7 +444,7 @@ class TestMCPServerManagerSigV4: @pytest.mark.asyncio async def test_create_mcp_client_with_sigv4(self): """_create_mcp_client creates client with SigV4 auth when auth_type is aws_sigv4.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -471,7 +471,7 @@ class TestMCPServerManagerSigV4: @pytest.mark.asyncio async def test_create_mcp_client_without_sigv4(self): """_create_mcp_client does not create SigV4 auth for non-SigV4 servers.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -494,7 +494,7 @@ class TestMCPServerManagerSigV4: @pytest.mark.asyncio async def test_load_config_with_aws_role_name(self): """Config loading correctly parses aws_role_name and aws_session_name.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -519,7 +519,7 @@ class TestMCPServerManagerSigV4: @pytest.mark.asyncio async def test_create_mcp_client_with_role_assumption(self): """_create_mcp_client passes aws_role_name to MCPSigV4Auth.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -555,7 +555,7 @@ class TestMCPServerManagerSigV4: def test_extract_aws_credentials_includes_role_fields(self): """_extract_aws_credentials extracts aws_role_name and aws_session_name.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -577,7 +577,7 @@ class TestSigV4CredentialEncryption: def test_encrypt_credentials_handles_aws_fields(self): """AWS credential fields are encrypted in the credentials dict.""" - from litellm.proxy._experimental.mcp_server.db import encrypt_credentials + from litellm.proxy.mcp_server.db import encrypt_credentials creds = { "aws_access_key_id": "AKIAIOSFODNN7EXAMPLE", @@ -588,7 +588,7 @@ class TestSigV4CredentialEncryption: } with patch( - "litellm.proxy._experimental.mcp_server.db.encrypt_value_helper", + "litellm.proxy.mcp_server.db.encrypt_value_helper", side_effect=lambda value, new_encryption_key: f"enc:{value}", ): result = encrypt_credentials(credentials=creds, encryption_key="test-key") @@ -603,12 +603,12 @@ class TestSigV4CredentialEncryption: def test_encrypt_credentials_skips_absent_aws_fields(self): """encrypt_credentials does not fail when AWS fields are absent.""" - from litellm.proxy._experimental.mcp_server.db import encrypt_credentials + from litellm.proxy.mcp_server.db import encrypt_credentials creds = {"auth_value": "some-token"} with patch( - "litellm.proxy._experimental.mcp_server.db.encrypt_value_helper", + "litellm.proxy.mcp_server.db.encrypt_value_helper", side_effect=lambda value, new_encryption_key: f"enc:{value}", ): result = encrypt_credentials(credentials=creds, encryption_key="test-key") @@ -623,8 +623,8 @@ class TestCredentialMergeOnUpdate: @pytest.mark.asyncio async def test_partial_update_preserves_existing_credentials(self): """Updating only aws_region_name should not wipe aws_secret_access_key.""" - from litellm.proxy._experimental.mcp_server.db import update_mcp_server from litellm.proxy._types import UpdateMCPServerRequest + from litellm.proxy.mcp_server.db import update_mcp_server existing_record = MagicMock() existing_record.auth_type = "aws_sigv4" @@ -648,11 +648,11 @@ class TestCredentialMergeOnUpdate: with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_salt_key", + "litellm.proxy.mcp_server.db.get_salt_key", return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.db.encrypt_value_helper", + "litellm.proxy.mcp_server.db.encrypt_value_helper", side_effect=lambda value, new_encryption_key: value, ), ): @@ -673,8 +673,8 @@ class TestCredentialMergeOnUpdate: @pytest.mark.asyncio async def test_update_without_credentials_preserves_all(self): """Update with no credentials field should not touch existing credentials.""" - from litellm.proxy._experimental.mcp_server.db import update_mcp_server from litellm.proxy._types import UpdateMCPServerRequest + from litellm.proxy.mcp_server.db import update_mcp_server mock_prisma = MagicMock() mock_prisma.db.litellm_mcpservertable.update = AsyncMock(return_value=_updated_row()) @@ -685,7 +685,7 @@ class TestCredentialMergeOnUpdate: ) with patch( - "litellm.proxy._experimental.mcp_server.db.get_salt_key", + "litellm.proxy.mcp_server.db.get_salt_key", return_value=None, ): await update_mcp_server(mock_prisma, data, "test-user") @@ -696,8 +696,8 @@ class TestCredentialMergeOnUpdate: @pytest.mark.asyncio async def test_update_new_server_no_merge(self): """Update with credentials on a server that has no existing credentials.""" - from litellm.proxy._experimental.mcp_server.db import update_mcp_server from litellm.proxy._types import UpdateMCPServerRequest + from litellm.proxy.mcp_server.db import update_mcp_server existing_record = MagicMock() existing_record.auth_type = "aws_sigv4" @@ -715,11 +715,11 @@ class TestCredentialMergeOnUpdate: with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_salt_key", + "litellm.proxy.mcp_server.db.get_salt_key", return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.db.encrypt_value_helper", + "litellm.proxy.mcp_server.db.encrypt_value_helper", side_effect=lambda value, new_encryption_key: value, ), ): @@ -732,8 +732,8 @@ class TestCredentialMergeOnUpdate: @pytest.mark.asyncio async def test_auth_type_change_replaces_credentials_entirely(self): """Switching auth_type should replace credentials, not merge.""" - from litellm.proxy._experimental.mcp_server.db import update_mcp_server from litellm.proxy._types import UpdateMCPServerRequest + from litellm.proxy.mcp_server.db import update_mcp_server existing_record = MagicMock() existing_record.auth_type = "aws_sigv4" @@ -757,11 +757,11 @@ class TestCredentialMergeOnUpdate: with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_salt_key", + "litellm.proxy.mcp_server.db.get_salt_key", return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.db.encrypt_value_helper", + "litellm.proxy.mcp_server.db.encrypt_value_helper", side_effect=lambda value, new_encryption_key: f"enc:{value}", ), ): @@ -775,8 +775,8 @@ class TestCredentialMergeOnUpdate: @pytest.mark.asyncio async def test_same_auth_type_merges_credentials(self): """Same auth_type should merge credentials (preserve untouched fields).""" - from litellm.proxy._experimental.mcp_server.db import update_mcp_server from litellm.proxy._types import UpdateMCPServerRequest + from litellm.proxy.mcp_server.db import update_mcp_server existing_record = MagicMock() existing_record.auth_type = "oauth2" @@ -800,11 +800,11 @@ class TestCredentialMergeOnUpdate: with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_salt_key", + "litellm.proxy.mcp_server.db.get_salt_key", return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.db.encrypt_value_helper", + "litellm.proxy.mcp_server.db.encrypt_value_helper", side_effect=lambda value, new_encryption_key: value, ), ): @@ -823,7 +823,7 @@ class TestSigV4BuildFromTable: @pytest.mark.asyncio async def test_build_mcp_server_from_table_with_sigv4_credentials(self): """SigV4 credentials from DB are decrypted and mapped to MCPServer fields.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -878,7 +878,7 @@ class TestSigV4BuildFromTable: manager = MCPServerManager() with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.decrypt_value_helper", + "litellm.proxy.mcp_server.mcp_server_manager.decrypt_value_helper", side_effect=lambda value, key, exception_type, return_original_value: value.replace("enc:", ""), ): server = await manager.build_mcp_server_from_table(table_record) @@ -893,7 +893,7 @@ class TestSigV4BuildFromTable: @pytest.mark.asyncio async def test_build_mcp_server_from_table_without_sigv4_credentials(self): """Non-SigV4 servers still work — AWS fields default to None.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -940,7 +940,7 @@ class TestSigV4BuildFromTable: manager = MCPServerManager() with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.decrypt_value_helper", + "litellm.proxy.mcp_server.mcp_server_manager.decrypt_value_helper", side_effect=lambda value, key, exception_type, return_original_value: value.replace("enc:", ""), ): server = await manager.build_mcp_server_from_table(table_record) @@ -958,7 +958,7 @@ class TestDecryptCredentials: def test_decrypt_credentials_handles_all_secret_fields(self): """All secret fields are decrypted; non-secret fields are left as-is.""" - from litellm.proxy._experimental.mcp_server.db import decrypt_credentials + from litellm.proxy.mcp_server.db import decrypt_credentials creds = { "auth_value": "enc:tok", @@ -972,7 +972,7 @@ class TestDecryptCredentials: } with patch( - "litellm.proxy._experimental.mcp_server.db.decrypt_value_helper", + "litellm.proxy.mcp_server.db.decrypt_value_helper", side_effect=lambda value, key, exception_type="error", return_original_value=False: value.replace( "enc:", "" ), @@ -991,12 +991,12 @@ class TestDecryptCredentials: def test_decrypt_credentials_skips_absent_fields(self): """Absent fields are not touched.""" - from litellm.proxy._experimental.mcp_server.db import decrypt_credentials + from litellm.proxy.mcp_server.db import decrypt_credentials creds = {"aws_access_key_id": "enc:AKI"} with patch( - "litellm.proxy._experimental.mcp_server.db.decrypt_value_helper", + "litellm.proxy.mcp_server.db.decrypt_value_helper", side_effect=lambda value, key, exception_type="error", return_original_value=False: value.replace( "enc:", "" ), @@ -1013,7 +1013,7 @@ class TestRotateCredentials: @pytest.mark.asyncio async def test_rotation_decrypts_then_reencrypts(self): """Key rotation should decrypt with old key then encrypt with new key.""" - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( rotate_mcp_server_credentials_master_key, ) @@ -1034,17 +1034,17 @@ class TestRotateCredentials: with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_salt_key", + "litellm.proxy.mcp_server.db.get_salt_key", return_value="old-key", ), patch( - "litellm.proxy._experimental.mcp_server.db.decrypt_value_helper", + "litellm.proxy.mcp_server.db.decrypt_value_helper", side_effect=lambda value, key, exception_type="error", return_original_value=False: value.replace( "enc_old:", "" ), ), patch( - "litellm.proxy._experimental.mcp_server.db.encrypt_value_helper", + "litellm.proxy.mcp_server.db.encrypt_value_helper", side_effect=lambda value, new_encryption_key: f"enc_new:{value}", ), ): @@ -1063,7 +1063,7 @@ class TestRotateCredentials: async def test_rotation_reencrypts_global_env_vars(self): """Global env var values are re-encrypted under the new key; user-scope placeholders are left untouched.""" - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( rotate_mcp_server_credentials_master_key, ) @@ -1083,17 +1083,17 @@ class TestRotateCredentials: with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_salt_key", + "litellm.proxy.mcp_server.db.get_salt_key", return_value="old-key", ), patch( - "litellm.proxy._experimental.mcp_server.db.decrypt_value_helper", + "litellm.proxy.mcp_server.db.decrypt_value_helper", side_effect=lambda value, key, exception_type="error", return_original_value=False: value.replace( "enc_old:", "" ), ), patch( - "litellm.proxy._experimental.mcp_server.db.encrypt_value_helper", + "litellm.proxy.mcp_server.db.encrypt_value_helper", side_effect=lambda value, new_encryption_key: f"enc_new:{value}", ), ): @@ -1116,8 +1116,8 @@ class TestAuthTypeSwitchClearsCredentials: @pytest.mark.asyncio async def test_auth_type_change_without_credentials_clears_stale(self): """Changing auth_type without providing credentials should clear old ones.""" - from litellm.proxy._experimental.mcp_server.db import update_mcp_server from litellm.proxy._types import UpdateMCPServerRequest + from litellm.proxy.mcp_server.db import update_mcp_server existing_record = MagicMock() existing_record.auth_type = "oauth2" @@ -1134,7 +1134,7 @@ class TestAuthTypeSwitchClearsCredentials: ) with patch( - "litellm.proxy._experimental.mcp_server.db.get_salt_key", + "litellm.proxy.mcp_server.db.get_salt_key", return_value=None, ): await update_mcp_server(mock_prisma, data, "test-user") diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_stale_session.py b/tests/unit/proxy/mcp_server/test_mcp_stale_session.py similarity index 84% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_stale_session.py rename to tests/unit/proxy/mcp_server/test_mcp_stale_session.py index 66d853bdd44..88f18b609a4 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_stale_session.py +++ b/tests/unit/proxy/mcp_server/test_mcp_stale_session.py @@ -25,7 +25,7 @@ class TestHandleStaleMcpSession: async def test_strips_stale_session_id_for_non_delete(self): """Non-DELETE requests should have stale session IDs stripped.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _handle_stale_mcp_session, ) except ImportError: @@ -55,7 +55,7 @@ class TestHandleStaleMcpSession: async def test_delete_stale_session_returns_success(self): """DELETE requests for non-existent sessions should return success (idempotent).""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _handle_stale_mcp_session, _stateful_session_active_request_counts, _stateful_session_auth_context_last_seen, @@ -111,7 +111,7 @@ class TestHandleStaleMcpSession: async def test_preserves_valid_session_id(self): """Valid session IDs should not be modified.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _handle_stale_mcp_session, ) except ImportError: @@ -141,7 +141,7 @@ class TestHandleStaleMcpSession: async def test_no_op_when_no_session_header(self): """No session header should result in no-op.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _handle_stale_mcp_session, ) except ImportError: @@ -167,7 +167,7 @@ class TestHandleStaleMcpSession: async def test_no_op_when_server_instances_missing(self): """If _server_instances attr doesn't exist, don't crash.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _handle_stale_mcp_session, ) except ImportError: @@ -194,7 +194,7 @@ class TestHandleStaleMcpSession: async def test_delete_valid_session_not_handled(self): """DELETE requests for existing sessions should not be intercepted.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _handle_stale_mcp_session, ) except ImportError: @@ -227,7 +227,7 @@ async def test_stale_mcp_session_id_is_stripped(): request to the session manager so a fresh session is created. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, session_manager_stateless, @@ -263,15 +263,15 @@ async def test_stale_mcp_session_id_is_stripped(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(UserAPIKeyAuth(), None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -312,7 +312,7 @@ async def test_delete_stale_mcp_session_returns_success(): without forwarding to the session manager (idempotent DELETE). """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager, ) @@ -340,15 +340,15 @@ async def test_delete_stale_mcp_session_returns_success(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(UserAPIKeyAuth(), None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -378,7 +378,7 @@ async def test_failed_delete_preserves_stateful_session_tracking(): owner/auth tracking so the session cannot be hijacked or hidden from cleanup. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _owner_fingerprint_for, _stateful_session_auth_context_last_seen, _stateful_session_auth_contexts, @@ -419,12 +419,12 @@ async def test_failed_delete_preserves_stateful_session_tracking(): try: with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -461,7 +461,7 @@ async def test_valid_mcp_session_id_is_preserved(): handle_streamable_http_mcp should NOT strip the header. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -494,15 +494,15 @@ async def test_valid_mcp_session_id_is_preserved(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(UserAPIKeyAuth(), None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -530,7 +530,7 @@ async def test_no_mcp_session_id_header_works_normally(): handle_streamable_http_mcp should work without any issues. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager, ) @@ -557,15 +557,15 @@ async def test_no_mcp_session_id_header_works_normally(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(UserAPIKeyAuth(), None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -596,7 +596,7 @@ async def test_per_user_oauth_missing_stored_token_returns_preemptive_401(): from fastapi import HTTPException try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) @@ -627,29 +627,29 @@ async def test_per_user_oauth_missing_stored_token_returns_preemptive_401(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["repro_oauth_server"], None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", new_callable=AsyncMock, return_value=False, ) as mock_has_token, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=oauth_server, ), patch.object( @@ -683,7 +683,7 @@ async def test_admitted_subject_missing_stored_token_challenged_with_resource_me from fastapi import HTTPException try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) @@ -715,29 +715,29 @@ async def test_admitted_subject_missing_stored_token_challenged_with_resource_me with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["repro_oauth_server"], None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", new_callable=AsyncMock, return_value=False, ) as mock_has_token, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=oauth_server, ), patch.object( @@ -781,11 +781,11 @@ async def test_client_credentials_server_is_not_preemptively_challenged(m2m_fiel never look for. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: pytest.skip("MCP server not available") @@ -826,23 +826,23 @@ async def test_client_credentials_server_is_not_preemptively_challenged(m2m_fiel with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["m2m_server"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), - patch("litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True), + patch("litellm.proxy.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", new_callable=AsyncMock, ) as mock_has_token, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=m2m_server, ), patch.object(session_manager_stateless, "handle_request", new_callable=AsyncMock) as mock_handle_request, @@ -866,10 +866,10 @@ async def test_handle_streamable_http_mcp_delegated_server_surfaces_upstream_cha from fastapi import HTTPException try: - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -912,7 +912,7 @@ async def test_handle_streamable_http_mcp_delegated_server_surfaces_upstream_cha with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=( user_auth, @@ -923,27 +923,27 @@ async def test_handle_streamable_http_mcp_delegated_server_surfaces_upstream_cha None, ), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.operations._get_user_oauth_extra_headers_from_db", + "litellm.proxy.mcp_server.operations._get_user_oauth_extra_headers_from_db", new_callable=AsyncMock, return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=delegated_server, ), patch( # test-quality-ok: registry is empty in unit tests; key owns the delegated server - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[delegated_server], ), @@ -973,7 +973,7 @@ async def test_per_user_oauth_with_stored_token_skips_preemptive_401(): 401 and continue to session manager request handling. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) @@ -1010,29 +1010,29 @@ async def test_per_user_oauth_with_stored_token_skips_preemptive_401(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["repro_oauth_server"], None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", new_callable=AsyncMock, return_value=True, ) as mock_has_token, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=oauth_server, ), patch.object( @@ -1068,7 +1068,7 @@ async def test_handle_streamable_http_mcp_delegated_server_without_token_returns from fastapi import HTTPException try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -1107,7 +1107,7 @@ async def test_handle_streamable_http_mcp_delegated_server_without_token_returns with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=( user_auth, @@ -1119,23 +1119,23 @@ async def test_handle_streamable_http_mcp_delegated_server_without_token_returns ), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", new_callable=AsyncMock, ) as mock_has_token, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=delegated_server, ), patch.object( @@ -1168,7 +1168,7 @@ async def test_handle_streamable_http_mcp_token_exchange_without_subject_returns from fastapi import HTTPException try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -1208,22 +1208,22 @@ async def test_handle_streamable_http_mcp_token_exchange_without_subject_returns with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["obo_server"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=obo_server, ), patch.object( @@ -1290,7 +1290,7 @@ async def test_handle_streamable_http_mcp_oauth_delegate_without_token_returns_g from fastapi import HTTPException try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -1312,17 +1312,17 @@ async def test_handle_streamable_http_mcp_oauth_delegate_without_token_returns_g with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["od_server"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=od_server, ), patch.object( @@ -1349,7 +1349,7 @@ async def test_handle_streamable_http_mcp_oauth_delegate_with_forwarded_token_sk re-challenge. Guards the ``_get_forwarded_auth_from_scope(...) is None`` condition: dropping it would 401 even a fully-authenticated request.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) @@ -1377,26 +1377,26 @@ async def test_handle_streamable_http_mcp_oauth_delegate_with_forwarded_token_sk with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["od_server"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.server._check_passthrough_upstream_auth", + "litellm.proxy.mcp_server.server._check_passthrough_upstream_auth", new_callable=AsyncMock, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=od_server, ), patch.object( @@ -1422,7 +1422,7 @@ async def _run_passthrough_connect( challenged (raised) or forwarded to the session manager. Returns (challenged, www_authenticate).""" from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) @@ -1442,23 +1442,23 @@ async def _run_passthrough_connect( with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, server_names, mcp_server_auth_headers, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), - patch("litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True), + patch("litellm.proxy.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.server._check_passthrough_upstream_auth", + "litellm.proxy.mcp_server.server._check_passthrough_upstream_auth", new_callable=AsyncMock, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=server, ), patch.object(session_manager_stateless, "handle_request", new_callable=AsyncMock) as mock_handle_request, @@ -1478,7 +1478,7 @@ async def test_handle_streamable_http_mcp_per_server_header_skips_preemptive_cha connect gate must recognize it and forward instead of spuriously 401-ing, since egress already honors it. Without this, the mandatory multi-server binding is unusable at connect.""" try: - from litellm.proxy._experimental.mcp_server.server import handle_streamable_http_mcp # noqa: F401 + from litellm.proxy.mcp_server.server import handle_streamable_http_mcp # noqa: F401 except ImportError: pytest.skip("MCP server not available") @@ -1497,7 +1497,7 @@ async def test_handle_streamable_http_mcp_sanitized_per_server_header_skips_pree alias 'pt-server' arrives as the header key 'pt_server'. Egress resolves that via the sanitized alias, so the connect gate must too, or it 401s a token egress would forward.""" try: - from litellm.proxy._experimental.mcp_server.server import handle_streamable_http_mcp # noqa: F401 + from litellm.proxy.mcp_server.server import handle_streamable_http_mcp # noqa: F401 except ImportError: pytest.skip("MCP server not available") @@ -1515,7 +1515,7 @@ async def test_handle_streamable_http_mcp_aggregate_does_not_preemptively_challe """A multi-server aggregate must degrade gracefully: the preemptive 401 is single-server only, so one server missing a token cannot 401 the whole connect (the listing absorbs per-server failures).""" try: - from litellm.proxy._experimental.mcp_server.server import handle_streamable_http_mcp # noqa: F401 + from litellm.proxy.mcp_server.server import handle_streamable_http_mcp # noqa: F401 except ImportError: pytest.skip("MCP server not available") @@ -1536,7 +1536,7 @@ async def test_handle_streamable_http_mcp_true_passthrough_without_token_surface from fastapi import HTTPException try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -1565,21 +1565,21 @@ async def test_handle_streamable_http_mcp_true_passthrough_without_token_surface with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["tp_server"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server.get_async_httpx_client", + "litellm.proxy.mcp_server.server.get_async_httpx_client", return_value=probe_client, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=tp_server, ), patch.object( @@ -1606,7 +1606,7 @@ async def test_handle_streamable_http_mcp_true_passthrough_dcr_bridge_challenges from fastapi import HTTPException try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -1633,21 +1633,21 @@ async def test_handle_streamable_http_mcp_true_passthrough_dcr_bridge_challenges with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["tp_bridge_server"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server.get_async_httpx_client", + "litellm.proxy.mcp_server.server.get_async_httpx_client", return_value=probe_client, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=bridge_server, ), patch.object( @@ -1674,7 +1674,7 @@ async def test_handle_streamable_http_mcp_true_passthrough_with_token_skips_prob ``not _scope_has_authorization_header(scope)`` condition and the no-probe fast path.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) @@ -1702,30 +1702,30 @@ async def test_handle_streamable_http_mcp_true_passthrough_with_token_skips_prob with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["tp_server"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.server._check_passthrough_upstream_auth", + "litellm.proxy.mcp_server.server._check_passthrough_upstream_auth", new_callable=AsyncMock, ), patch( - "litellm.proxy._experimental.mcp_server.server.get_async_httpx_client", + "litellm.proxy.mcp_server.server.get_async_httpx_client", return_value=probe_client, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=tp_server, ), patch.object( @@ -1806,7 +1806,7 @@ async def test_streamable_http_skips_preflight_for_disabled_methods( # test-qua monkeypatch: pytest.MonkeyPatch, ) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) @@ -1838,39 +1838,39 @@ async def test_streamable_http_skips_preflight_for_disabled_methods( # test-qua with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["tp_server"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", + "litellm.proxy.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", new_callable=AsyncMock, ) as mock_preemptive_401, patch( - "litellm.proxy._experimental.mcp_server.server._check_passthrough_upstream_auth", + "litellm.proxy.mcp_server.server._check_passthrough_upstream_auth", new_callable=AsyncMock, ) as mock_passthrough_auth, patch( - "litellm.proxy._experimental.mcp_server.server._preflight_modern_interaction", + "litellm.proxy.mcp_server.server._preflight_modern_interaction", new_callable=AsyncMock, return_value=None, ) as mock_modern_preflight, patch( - "litellm.proxy._experimental.mcp_server.server.get_async_httpx_client", + "litellm.proxy.mcp_server.server.get_async_httpx_client", return_value=probe_client, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=tp_server, ), patch.object( diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_tool_search.py b/tests/unit/proxy/mcp_server/test_mcp_tool_search.py similarity index 90% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_tool_search.py rename to tests/unit/proxy/mcp_server/test_mcp_tool_search.py index ea0dd70cd22..b21202ba227 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_tool_search.py +++ b/tests/unit/proxy/mcp_server/test_mcp_tool_search.py @@ -1,4 +1,5 @@ -from litellm.proxy._experimental.mcp_server import operations as mcp_operations +from litellm.proxy.mcp_server import operations as mcp_operations + """ Tests for MCP tool search feature. @@ -20,14 +21,16 @@ from typing import Any, Final from unittest.mock import AsyncMock, MagicMock, patch import pytest -from pydantic import JsonValue from mcp.types import Tool +from pydantic import JsonValue import litellm from litellm.models.object_permission import LiteLLM_ObjectPermissionTable -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import AggregateToolListing -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ListedToolsCaller -from litellm.proxy._experimental.mcp_server.tool_search import ( +from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth +from litellm.proxy.common_utils.semantic_text_index import EmbeddingFailed, SemanticTextIndex, Vector +from litellm.proxy.mcp_server.faults.list_outcomes import AggregateToolListing +from litellm.proxy.mcp_server.mcp_server_manager import ListedToolsCaller +from litellm.proxy.mcp_server.tool_search import ( AGENT_SEARCH_TOOL_NAME, MCP_TOOL_CALL_TOOL_NAME, MCP_TOOL_SEARCH_TOOL_NAME, @@ -41,8 +44,6 @@ from litellm.proxy._experimental.mcp_server.tool_search import ( search_mcp_tools, search_tools, ) -from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth -from litellm.proxy.common_utils.semantic_text_index import EmbeddingFailed, SemanticTextIndex, Vector from litellm.types.mcp import MCPToolSearchSettings, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -97,7 +98,7 @@ SAMPLE_TOOLS = _make_tools( def test_offline_schema_validation_preserves_supported_constraints( schema: Mapping[str, JsonValue], arguments: Mapping[str, JsonValue], error: str | None ) -> None: - from litellm.proxy._experimental.mcp_server.tool_search import _validate_tool_arguments + from litellm.proxy.mcp_server.tool_search import _validate_tool_arguments result: Final = _validate_tool_arguments(schema, arguments) if error is None: @@ -108,7 +109,7 @@ def test_offline_schema_validation_preserves_supported_constraints( @pytest.mark.parametrize(("count", "allowed"), ((4_999, True), (5_000, False))) def test_validation_node_limit(count: int, allowed: bool) -> None: - from litellm.proxy._experimental.mcp_server.tool_search import _validation_limit_error + from litellm.proxy.mcp_server.tool_search import _validation_limit_error result: Final = _validation_limit_error({}, {str(index): None for index in range(count)}) assert (result is None) is allowed @@ -116,7 +117,7 @@ def test_validation_node_limit(count: int, allowed: bool) -> None: @pytest.mark.parametrize(("size", "allowed"), ((1_048_575, True), (1_048_576, False))) def test_validation_text_limit(size: int, allowed: bool) -> None: - from litellm.proxy._experimental.mcp_server.tool_search import _validation_limit_error + from litellm.proxy.mcp_server.tool_search import _validation_limit_error assert (_validation_limit_error({}, {"x": "a" * size}) is None) is allowed @@ -125,7 +126,7 @@ def test_validation_text_limit(size: int, allowed: bool) -> None: def test_validation_depth_limit(depth: int, allowed: bool) -> None: from functools import reduce - from litellm.proxy._experimental.mcp_server.tool_search import _validation_limit_error + from litellm.proxy.mcp_server.tool_search import _validation_limit_error nested: Final = reduce(lambda value, _: {"x": value}, range(depth), {}) assert (_validation_limit_error({}, nested) is None) is allowed @@ -133,7 +134,7 @@ def test_validation_depth_limit(depth: int, allowed: bool) -> None: @pytest.mark.asyncio async def test_oversized_arguments_are_rejected_before_worker_submission() -> None: - from litellm.proxy._experimental.mcp_server.tool_search import _tool_argument_validation_error + from litellm.proxy.mcp_server.tool_search import _tool_argument_validation_error with patch("anyio.to_process.run_sync", new_callable=AsyncMock) as submit: result: Final = await _tool_argument_validation_error({}, {"value": "x" * 1_048_576}) @@ -145,7 +146,7 @@ async def test_oversized_arguments_are_rejected_before_worker_submission() -> No async def test_failed_validation_worker_returns_tool_error() -> None: from anyio import BrokenWorkerProcess - from litellm.proxy._experimental.mcp_server.tool_search import _tool_argument_validation_error + from litellm.proxy.mcp_server.tool_search import _tool_argument_validation_error with patch("anyio.to_process.run_sync", side_effect=BrokenWorkerProcess): result: Final = await _tool_argument_validation_error({}, {}) @@ -472,7 +473,7 @@ class TestGetVirtualToolDefinitions: class TestListToolRestApiWithToolSearch: @pytest.mark.asyncio async def test_returns_only_virtual_tools_when_flag_enabled(self) -> None: - from litellm.proxy._experimental.mcp_server.rest_endpoints import router + from litellm.proxy.mcp_server.rest_endpoints import router user_api_key_dict = UserAPIKeyAuth( api_key="test_key", @@ -509,7 +510,7 @@ class TestListToolRestApiWithToolSearch: @pytest.mark.asyncio async def test_returns_full_catalog_when_flag_disabled(self) -> None: - from litellm.proxy._experimental.mcp_server.rest_endpoints import router + from litellm.proxy.mcp_server.rest_endpoints import router user_api_key_dict = UserAPIKeyAuth( api_key="test_key", @@ -538,32 +539,32 @@ class TestListToolRestApiWithToolSearch: with ( patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.build_effective_auth_contexts", + "litellm.proxy.mcp_server.rest_endpoints.build_effective_auth_contexts", new_callable=AsyncMock, return_value=[user_api_key_dict], ), - patch("litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager") as mock_manager, + patch("litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager") as mock_manager, patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_tools_for_single_server", + "litellm.proxy.mcp_server.rest_endpoints._get_tools_for_single_server", new_callable=AsyncMock, return_value=fake_tools, ), - patch("litellm.proxy._experimental.mcp_server.rest_endpoints.IPAddressUtils"), + patch("litellm.proxy.mcp_server.rest_endpoints.IPAddressUtils"), patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._prefetch_user_oauth_creds", + "litellm.proxy.mcp_server.rest_endpoints._prefetch_user_oauth_creds", new_callable=AsyncMock, return_value={}, ), patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._v1_resolved_oauth2_server_ids", + "litellm.proxy.mcp_server.rest_endpoints._v1_resolved_oauth2_server_ids", return_value=[], ), patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_server_auth_header", + "litellm.proxy.mcp_server.rest_endpoints._get_server_auth_header", return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_user_oauth_extra_headers", + "litellm.proxy.mcp_server.rest_endpoints._get_user_oauth_extra_headers", new_callable=AsyncMock, return_value=None, ), @@ -587,7 +588,7 @@ class TestListToolRestApiWithToolSearch: """Regression: an admin listing with include_disabled_tools must see the real catalog (to configure allowlists) even when mcp_tool_search_enabled is set, instead of the two virtual tools.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import router + from litellm.proxy.mcp_server.rest_endpoints import router user_api_key_dict = UserAPIKeyAuth( api_key="admin_key", @@ -617,32 +618,32 @@ class TestListToolRestApiWithToolSearch: with ( patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.build_effective_auth_contexts", + "litellm.proxy.mcp_server.rest_endpoints.build_effective_auth_contexts", new_callable=AsyncMock, return_value=[user_api_key_dict], ), - patch("litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager") as mock_manager, + patch("litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager") as mock_manager, patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_tools_for_single_server", + "litellm.proxy.mcp_server.rest_endpoints._get_tools_for_single_server", new_callable=AsyncMock, return_value=fake_tools, ), - patch("litellm.proxy._experimental.mcp_server.rest_endpoints.IPAddressUtils"), + patch("litellm.proxy.mcp_server.rest_endpoints.IPAddressUtils"), patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._prefetch_user_oauth_creds", + "litellm.proxy.mcp_server.rest_endpoints._prefetch_user_oauth_creds", new_callable=AsyncMock, return_value={}, ), patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._v1_resolved_oauth2_server_ids", + "litellm.proxy.mcp_server.rest_endpoints._v1_resolved_oauth2_server_ids", return_value=[], ), patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_server_auth_header", + "litellm.proxy.mcp_server.rest_endpoints._get_server_auth_header", return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_user_oauth_extra_headers", + "litellm.proxy.mcp_server.rest_endpoints._get_user_oauth_extra_headers", new_callable=AsyncMock, return_value=None, ), @@ -672,7 +673,7 @@ class TestCallToolRestApiVirtualTools: return mock_request def _get_call_fn(self) -> Any: - from litellm.proxy._experimental.mcp_server.rest_endpoints import router + from litellm.proxy.mcp_server.rest_endpoints import router return next( r.endpoint @@ -698,7 +699,7 @@ class TestCallToolRestApiVirtualTools: mock_tool.input_schema = {"type": "object", "properties": {}} with patch( - "litellm.proxy._experimental.mcp_server.operations._list_mcp_tools", + "litellm.proxy.mcp_server.operations._list_mcp_tools", new_callable=AsyncMock, return_value=AggregateToolListing(tools=[mock_tool], outcomes={}), ): @@ -742,17 +743,17 @@ class TestCallToolRestApiVirtualTools: with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[MagicMock()], ), patch( - "litellm.proxy._experimental.mcp_server.operations.execute_mcp_tool", + "litellm.proxy.mcp_server.operations.execute_mcp_tool", new_callable=AsyncMock, return_value=fake_result, ) as mock_execute, patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._fire_mcp_tool_call_logging", + "litellm.proxy.mcp_server.rest_endpoints._fire_mcp_tool_call_logging", new_callable=AsyncMock, side_effect=RuntimeError("logging failed"), ) as mock_fire_logging, @@ -791,16 +792,16 @@ class TestCallToolRestApiVirtualTools: with ( patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.rest_endpoints.IPAddressUtils.get_mcp_client_ip", return_value="203.0.113.7", ), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[MagicMock()], ) as mock_allowed, patch( - "litellm.proxy._experimental.mcp_server.operations.execute_mcp_tool", + "litellm.proxy.mcp_server.operations.execute_mcp_tool", new_callable=AsyncMock, return_value=fake_result, ), @@ -821,11 +822,11 @@ class TestCallToolRestApiVirtualTools: with ( patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.rest_endpoints.IPAddressUtils.get_mcp_client_ip", return_value="203.0.113.7", ), patch( - "litellm.proxy._experimental.mcp_server.operations._list_mcp_tools", + "litellm.proxy.mcp_server.operations._list_mcp_tools", new_callable=AsyncMock, return_value=AggregateToolListing(tools=[], outcomes={}), ) as mock_list, @@ -893,7 +894,7 @@ class TestCallToolRestApiVirtualTools: ) fake_result = CallToolResult(content=[TextContent(type="text", text="[]")], isError=False) with patch( # test-quality-ok: the embedding router only resolves via proxy_server globals, no injection seam - "litellm.proxy._experimental.mcp_server.tool_search.handle_skill_search", + "litellm.proxy.mcp_server.tool_search.handle_skill_search", new_callable=AsyncMock, return_value=fake_result, ) as mock_search: @@ -958,7 +959,7 @@ class TestCallToolRestApiVirtualTools: "litellm.proxy.proxy_server.proxy_logging_obj", key_limits ), patch( # test-quality-ok: the authorized catalog is the seam every virtual tool shares; the ranking under test stays real - "litellm.proxy._experimental.mcp_server.operations._list_mcp_tools", + "litellm.proxy.mcp_server.operations._list_mcp_tools", new_callable=AsyncMock, return_value=AggregateToolListing(tools=list(CATALOG), outcomes={}), ) as mock_list, @@ -1027,7 +1028,7 @@ class TestDispatchVirtualMcpTool: @pytest.mark.asyncio async def test_returns_none_for_non_virtual_tool(self) -> None: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _dispatch_virtual_mcp_tool, ) @@ -1041,7 +1042,7 @@ class TestDispatchVirtualMcpTool: @pytest.mark.asyncio async def test_rejects_when_flag_disabled(self) -> None: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _dispatch_virtual_mcp_tool, ) @@ -1057,11 +1058,11 @@ class TestDispatchVirtualMcpTool: @pytest.mark.asyncio async def test_routes_search_with_client_ip(self) -> None: - from litellm.proxy._experimental.mcp_server import server as srv + from litellm.proxy.mcp_server import server as srv uak = UserAPIKeyAuth(api_key="k", object_permission=_make_perm(mcp_tool_search_enabled=True)) with patch( - "litellm.proxy._experimental.mcp_server.tool_search.handle_mcp_tool_search", + "litellm.proxy.mcp_server.tool_search.handle_mcp_tool_search", new_callable=AsyncMock, return_value="SEARCH_RESULT", ) as mock_search: @@ -1079,11 +1080,11 @@ class TestDispatchVirtualMcpTool: @pytest.mark.asyncio async def test_routes_agent_search_to_its_handler(self) -> None: - from litellm.proxy._experimental.mcp_server import server as srv + from litellm.proxy.mcp_server import server as srv uak = UserAPIKeyAuth(api_key="k", object_permission=_make_perm(mcp_tool_search_enabled=True)) with patch( # test-quality-ok: dispatch routing is the subject; the handler is faked like its siblings here - "litellm.proxy._experimental.mcp_server.tool_search.handle_agent_search", + "litellm.proxy.mcp_server.tool_search.handle_agent_search", new_callable=AsyncMock, return_value="AGENT_RESULT", ) as mock_agent_search: @@ -1103,7 +1104,7 @@ class TestDispatchVirtualMcpTool: @pytest.mark.asyncio async def test_agent_search_rejected_when_flag_disabled(self) -> None: - from litellm.proxy._experimental.mcp_server.server import _dispatch_virtual_mcp_tool + from litellm.proxy.mcp_server.server import _dispatch_virtual_mcp_tool uak = UserAPIKeyAuth(api_key="k", object_permission=_make_perm(mcp_tool_search_enabled=False)) result = await _dispatch_virtual_mcp_tool( @@ -1114,11 +1115,11 @@ class TestDispatchVirtualMcpTool: @pytest.mark.asyncio async def test_routes_call_with_client_ip(self) -> None: - from litellm.proxy._experimental.mcp_server import server as srv + from litellm.proxy.mcp_server import server as srv uak = UserAPIKeyAuth(api_key="k", object_permission=_make_perm(mcp_tool_search_enabled=True)) with patch( - "litellm.proxy._experimental.mcp_server.tool_search.handle_mcp_tool_call", + "litellm.proxy.mcp_server.tool_search.handle_mcp_tool_call", new_callable=AsyncMock, return_value="CALL_RESULT", ) as mock_call: @@ -1147,7 +1148,7 @@ class TestDispatchVirtualMcpTool: """Regression: the SSE dispatch must run the pre-call pipeline and forward the resulting logging object to handle_mcp_tool_call, otherwise mcp_tool_call over /mcp/ skips spend logging and guardrails (unlike the REST path).""" - from litellm.proxy._experimental.mcp_server import server as srv + from litellm.proxy.mcp_server import server as srv uak = UserAPIKeyAuth(api_key="k", object_permission=_make_perm(mcp_tool_search_enabled=True)) sentinel_logging_obj = object() @@ -1158,7 +1159,7 @@ class TestDispatchVirtualMcpTool: return_value=sentinel_logging_obj, ) as mock_build, patch( - "litellm.proxy._experimental.mcp_server.tool_search.handle_mcp_tool_call", + "litellm.proxy.mcp_server.tool_search.handle_mcp_tool_call", new_callable=AsyncMock, return_value="CALL_RESULT", ) as mock_call, @@ -1177,11 +1178,11 @@ class TestDispatchVirtualMcpTool: async def test_search_coerces_non_int_top_k(self) -> None: """Regression: a non-integer top_k from an MCP client must not raise; it falls back to the default instead of ValueError propagating out.""" - from litellm.proxy._experimental.mcp_server import server as srv + from litellm.proxy.mcp_server import server as srv uak = UserAPIKeyAuth(api_key="k", object_permission=_make_perm(mcp_tool_search_enabled=True)) with patch( - "litellm.proxy._experimental.mcp_server.tool_search.handle_mcp_tool_search", + "litellm.proxy.mcp_server.tool_search.handle_mcp_tool_search", new_callable=AsyncMock, return_value="SEARCH_RESULT", ) as mock_search: @@ -1200,7 +1201,7 @@ class TestDispatchVirtualMcpTool: upstream MCP servers needing pass-through auth can be called.""" from mcp.types import CallToolResult, TextContent - from litellm.proxy._experimental.mcp_server.tool_search import ( + from litellm.proxy.mcp_server.tool_search import ( handle_mcp_tool_call, ) @@ -1208,12 +1209,12 @@ class TestDispatchVirtualMcpTool: fake = CallToolResult(content=[TextContent(type="text", text="ok")], isError=False) with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[MagicMock()], ) as mock_allowed, patch( - "litellm.proxy._experimental.mcp_server.operations.execute_mcp_tool", + "litellm.proxy.mcp_server.operations.execute_mcp_tool", new_callable=AsyncMock, return_value=fake, ) as mock_exec, @@ -1248,19 +1249,19 @@ class TestDispatchVirtualMcpTool: run via the local registry without a server permission check.""" from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server.tool_search import ( + from litellm.proxy.mcp_server.tool_search import ( handle_mcp_tool_call, ) uak = UserAPIKeyAuth(api_key="k", object_permission=_make_perm(mcp_tool_search_enabled=True)) with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[], ), patch( - "litellm.proxy._experimental.mcp_server.operations.execute_mcp_tool", + "litellm.proxy.mcp_server.operations.execute_mcp_tool", new_callable=AsyncMock, ) as mock_exec, ): @@ -1278,7 +1279,7 @@ class TestDispatchVirtualMcpTool: class TestCaptureHostProgressCallback: @pytest.mark.parametrize("meta", [None, {}, {"traceparent": "trace"}]) def test_returns_none_without_progress(self, _mcp_request_ctx, meta) -> None: - from litellm.proxy._experimental.mcp_server.server import _capture_host_progress_callback + from litellm.proxy.mcp_server.server import _capture_host_progress_callback assert _capture_host_progress_callback(_mcp_request_ctx(meta=meta)) is None @@ -1292,7 +1293,7 @@ class TestCaptureHostProgressCallback: from mcp.shared.dispatcher import DispatchContext from mcp.types import CallToolRequestParams - from litellm.proxy._experimental.mcp_server.server import _capture_host_progress_callback + from litellm.proxy.mcp_server.server import _capture_host_progress_callback params = CallToolRequestParams.model_validate( {"name": "tool", "_meta": {"progressToken": token}}, by_name=False @@ -1312,11 +1313,11 @@ class TestHandleListToolsVirtual: @pytest.mark.asyncio async def test_returns_virtual_tools_when_flag_enabled(self, _mcp_request_ctx) -> None: - from litellm.proxy._experimental.mcp_server import server as srv + from litellm.proxy.mcp_server import server as srv uak = UserAPIKeyAuth(api_key="k", object_permission=_make_perm(mcp_tool_search_enabled=True)) with patch( - "litellm.proxy._experimental.mcp_server.server.get_or_extract_auth_context", + "litellm.proxy.mcp_server.server.get_or_extract_auth_context", new_callable=AsyncMock, return_value=(uak, None, None, None, None, None, None), ): @@ -1338,17 +1339,17 @@ class TestMcpServerToolCallErrorHandling: async def test_virtual_tool_error_returns_iserror_not_raised(self, _mcp_request_ctx) -> None: from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import server as srv + from litellm.proxy.mcp_server import server as srv uak = UserAPIKeyAuth(api_key="k", object_permission=_make_perm(mcp_tool_search_enabled=True)) with ( patch( - "litellm.proxy._experimental.mcp_server.server.get_or_extract_auth_context", + "litellm.proxy.mcp_server.server.get_or_extract_auth_context", new_callable=AsyncMock, return_value=(uak, None, None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.operations._dispatch_virtual_mcp_tool", + "litellm.proxy.mcp_server.operations._dispatch_virtual_mcp_tool", new_callable=AsyncMock, side_effect=HTTPException(status_code=403, detail="User not allowed to call this tool"), ), @@ -1371,7 +1372,7 @@ class TestMcpServerToolCallErrorHandling: async def test_handle_mcp_tool_call_scoped_denial_names_the_binding_agent() -> None: from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server.tool_search import handle_mcp_tool_call + from litellm.proxy.mcp_server.tool_search import handle_mcp_tool_call agent_bound_key = UserAPIKeyAuth(api_key="test_key", agent_id="agent-123") @@ -1385,7 +1386,7 @@ async def test_handle_mcp_tool_call_scoped_denial_names_the_binding_agent() -> N ] with patch( # test-quality-ok: the permission resolver is a module-level function; the suite's only seam - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(side_effect=resolve), ): with pytest.raises(HTTPException) as exc_info: @@ -1435,7 +1436,7 @@ async def test_mcp_tool_search_leaves_the_listed_tools_slot_empty(monkeypatch: p async def test_cold_concurrent_schema_validation_accepts_valid_arguments() -> None: import psutil - from litellm.proxy._experimental.mcp_server.tool_search import ( + from litellm.proxy.mcp_server.tool_search import ( _MAX_VALIDATION_WORKERS, _tool_argument_validation_error, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_toolset_scope.py b/tests/unit/proxy/mcp_server/test_mcp_toolset_scope.py similarity index 88% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_toolset_scope.py rename to tests/unit/proxy/mcp_server/test_mcp_toolset_scope.py index b9eebca3baa..f3cc38eacf9 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_toolset_scope.py +++ b/tests/unit/proxy/mcp_server/test_mcp_toolset_scope.py @@ -34,7 +34,7 @@ def _make_auth( def _granted_through_team(*team_toolset_ids: str) -> Callable[[UserAPIKeyAuth], Awaitable[frozenset[str]]]: """The real grant resolver over a team that holds ``team_toolset_ids``, with no key access rule.""" - from litellm.proxy._experimental.mcp_server.ui_session_utils import granted_toolset_ids + from litellm.proxy.mcp_server.ui_session_utils import granted_toolset_ids async def team_permission(context: UserAPIKeyAuth) -> LiteLLM_ObjectPermissionTable: return LiteLLM_ObjectPermissionTable(object_permission_id="team-op", mcp_toolsets=list(team_toolset_ids)) @@ -50,14 +50,14 @@ class TestApplyToolsetScope: @pytest.mark.asyncio async def test_restricts_to_toolset_servers_and_tools(self): - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope toolset_perms = { "server-a": ["tool1", "tool2"], "server-b": ["tool3"], } with patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "global_mcp_server_manager.resolve_toolset_tool_permissions", new=AsyncMock(return_value=toolset_perms), ): @@ -73,8 +73,8 @@ class TestApplyToolsetScope: assert set(op.mcp_servers or []) == {"server-a", "server-b"} assert op.mcp_tool_permissions == toolset_perms - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager - from litellm.proxy._experimental.mcp_server.operations import prepare_context + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.operations import prepare_context manager = MCPServerManager() unscoped_open = await manager.operator_open_server_ids( @@ -92,11 +92,11 @@ class TestApplyToolsetScope: @pytest.mark.asyncio async def test_admin_creates_object_permission_when_none(self): """Admin key with object_permission=None can access any toolset.""" - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope toolset_perms = {"server-a": ["tool1"]} with patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "global_mcp_server_manager.resolve_toolset_tool_permissions", new=AsyncMock(return_value=toolset_perms), ): @@ -116,12 +116,12 @@ class TestApplyToolsetScope: async def test_team_granted_toolset_is_served_to_a_key_without_its_own_grant(self): """A team key whose own row carries no toolset grant is admitted to the toolset its team holds (LIT-6029), scoped to that toolset's servers and tools.""" - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope toolset_perms = {"server-a": ["tool1"]} auth = UserAPIKeyAuth(api_key="sk-test", team_id="team-a", object_permission=None) with patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "global_mcp_server_manager.resolve_toolset_tool_permissions", new=AsyncMock(return_value=toolset_perms), ): @@ -138,7 +138,7 @@ class TestApplyToolsetScope: team-granted toolset is not capped by the user's own row: the row stays intact and the toolset rides along as mcp_toolset_id (LIT-6029).""" from litellm.constants import UI_SESSION_TOKEN_TEAM_ID - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope session = UserAPIKeyAuth(team_id=UI_SESSION_TOKEN_TEAM_ID, user_id="user-1") own_row = LiteLLM_ObjectPermissionTable(object_permission_id="user-op", mcp_servers=["server-own"]) @@ -147,7 +147,7 @@ class TestApplyToolsetScope: granted = AsyncMock(return_value=frozenset({"toolset-123"})) resolve = AsyncMock(return_value={"server-team": ["tool1"]}) with patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "global_mcp_server_manager.resolve_toolset_tool_permissions", new=resolve, ): @@ -163,7 +163,7 @@ class TestApplyToolsetScope: @pytest.mark.asyncio async def test_a_gateway_admitted_user_without_the_toolset_in_any_source_is_denied(self): - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope admitted = UserAPIKeyAuth(user_id="user-1", object_permission=None) admitted.mcp_admitted_user_subject = True @@ -178,7 +178,7 @@ class TestApplyToolsetScope: async def test_a_resource_scoped_admitted_user_is_denied_a_team_toolset_on_another_server(self): """A gateway bearer scoped to server-own (RFC 8707 resource) cannot open a team toolset whose servers lie outside that resource, even though the team grants it (Devin Review 4150024267).""" - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope admitted = UserAPIKeyAuth(user_id="user-1", object_permission=None) admitted.mcp_admitted_user_subject = True @@ -187,7 +187,7 @@ class TestApplyToolsetScope: granted = AsyncMock(return_value=frozenset({"toolset-123"})) resolve = AsyncMock(return_value={"server-team": ["tool1"]}) with patch( - "litellm.proxy._experimental.mcp_server.server.global_mcp_server_manager.resolve_toolset_tool_permissions", + "litellm.proxy.mcp_server.server.global_mcp_server_manager.resolve_toolset_tool_permissions", new=resolve, ): with pytest.raises(HTTPException) as exc_info: @@ -198,7 +198,7 @@ class TestApplyToolsetScope: @pytest.mark.asyncio async def test_a_resource_scoped_admitted_user_opens_a_toolset_inside_its_resource(self): - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope admitted = UserAPIKeyAuth(user_id="user-1", object_permission=None) admitted.mcp_admitted_user_subject = True @@ -206,7 +206,7 @@ class TestApplyToolsetScope: granted = AsyncMock(return_value=frozenset({"toolset-123"})) resolve = AsyncMock(return_value={"server-team": ["tool1"], "server-other": ["tool2"]}) with patch( - "litellm.proxy._experimental.mcp_server.server.global_mcp_server_manager.resolve_toolset_tool_permissions", + "litellm.proxy.mcp_server.server.global_mcp_server_manager.resolve_toolset_tool_permissions", new=resolve, ): result = await apply_toolset_scope(admitted, "toolset-123", granted=granted) @@ -217,7 +217,7 @@ class TestApplyToolsetScope: @pytest.mark.asyncio async def test_team_grant_for_another_toolset_does_not_admit_a_key_to_this_one(self): - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope auth = _make_auth(mcp_toolsets=[]) auth.team_id = "team-a" @@ -231,7 +231,7 @@ class TestApplyToolsetScope: """Non-admin key with object_permission=None is denied (no grants configured).""" from starlette.exceptions import HTTPException - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope auth = UserAPIKeyAuth(api_key="sk-test", object_permission=None) with pytest.raises(HTTPException) as exc_info: @@ -246,7 +246,7 @@ class TestApplyToolsetScope: toolset path, which replaces mcp_servers and would drop the sentinel.""" from starlette.exceptions import HTTPException - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope op = LiteLLM_ObjectPermissionTable( object_permission_id="test", @@ -259,7 +259,7 @@ class TestApplyToolsetScope: resolve = AsyncMock(return_value={"server-a": ["tool1"]}) with patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "global_mcp_server_manager.resolve_toolset_tool_permissions", new=resolve, ): @@ -382,12 +382,12 @@ class TestFetchMCPToolsetsAccess: @pytest.mark.asyncio async def test_team_granted_toolsets_are_listed_for_a_key_without_its_own_grant(self): """GET /v1/mcp/toolset for a team key lists the team's toolsets (LIT-6029).""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( - MCPRequestHandler, - ) from litellm.proxy.management_endpoints.mcp_management_endpoints import ( fetch_mcp_toolsets, ) + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( + MCPRequestHandler, + ) auth = UserAPIKeyAuth(api_key="sk-test", team_id="team-a", object_permission=None) team_permission = LiteLLM_ObjectPermissionTable(object_permission_id="team-op", mcp_toolsets=["ts-team"]) @@ -417,12 +417,12 @@ class TestFetchMCPToolsetsAccess: @pytest.mark.asyncio async def test_admin_with_own_grants_is_not_narrowed_by_a_team_lookup(self): """An admin's own grant list is the only filter; no team lookup runs for admins.""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( - MCPRequestHandler, - ) from litellm.proxy.management_endpoints.mcp_management_endpoints import ( fetch_mcp_toolsets, ) + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( + MCPRequestHandler, + ) auth = _make_auth(mcp_toolsets=["ts-1"]) auth.user_role = LitellmUserRoles.PROXY_ADMIN @@ -454,12 +454,12 @@ class TestFetchMCPToolsetAccess: @staticmethod async def _fetch(auth: UserAPIKeyAuth, toolset_id: str, team_toolsets: list[str] | None): - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( - MCPRequestHandler, - ) from litellm.proxy.management_endpoints.mcp_management_endpoints import ( fetch_mcp_toolset, ) + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( + MCPRequestHandler, + ) team_permission = ( LiteLLM_ObjectPermissionTable(object_permission_id="team-op", mcp_toolsets=team_toolsets) @@ -542,10 +542,10 @@ class TestToolsetPrefixResolution: ): from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_key_team_permissions, ) - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( add_server_prefix_to_name, get_server_prefix, ) @@ -564,12 +564,12 @@ class TestToolsetPrefixResolution: with ( patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "MCPRequestHandler.get_allowed_tools_for_server", new=AsyncMock(return_value=allowed), ), patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "global_mcp_server_manager.get_mcp_server_by_id", return_value=server, ), @@ -606,7 +606,7 @@ class TestToolsetPrefixResolution: async def test_resolve_keeps_a_name_that_looks_like_its_own_server_prefix( self, alias, server_name, server_id ): - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( add_server_prefix_to_name, get_server_prefix, ) @@ -624,7 +624,7 @@ class TestToolsetPrefixResolution: async def _resolve(server, server_id, stored): from types import SimpleNamespace - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -635,14 +635,14 @@ class TestToolsetPrefixResolution: ) with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager." + "litellm.proxy.mcp_server.mcp_server_manager." "global_mcp_server_manager.get_mcp_server_by_id", return_value=server, ), patch("litellm.proxy.proxy_server.prisma_client", MagicMock()), patch("litellm.proxy.proxy_server.user_api_key_cache", cache), patch( - "litellm.proxy._experimental.mcp_server.toolset_db.list_mcp_toolsets", + "litellm.proxy.mcp_server.toolset_db.list_mcp_toolsets", new=AsyncMock(return_value=[toolset]), ), ): @@ -661,10 +661,10 @@ class TestToolsetPrefixResolution: """ from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_key_team_permissions, ) - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( add_server_prefix_to_name, get_server_prefix, strip_known_server_prefix, @@ -691,12 +691,12 @@ class TestToolsetPrefixResolution: with ( patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "MCPRequestHandler.get_allowed_tools_for_server", new=AsyncMock(return_value=resolved["srv-collide"]), ), patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "global_mcp_server_manager.get_mcp_server_by_id", return_value=server, ), @@ -725,10 +725,10 @@ class TestToolsetPrefixResolution: """ from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_key_team_permissions, ) - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( add_server_prefix_to_name, get_server_prefix, ) @@ -748,12 +748,12 @@ class TestToolsetPrefixResolution: with ( patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "MCPRequestHandler.get_allowed_tools_for_server", new=AsyncMock(return_value=resolved["srv-lonely"]), ), patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "global_mcp_server_manager.get_mcp_server_by_id", return_value=server, ), @@ -770,7 +770,7 @@ class TestToolsetPrefixResolution: async def test_bare_stored_name_without_collision_grants_only_that_tool(self): """The ordinary row must stay exact; accepting both readings of an ambiguous row must not widen an unambiguous one.""" - from litellm.proxy._experimental.mcp_server.utils import get_server_prefix + from litellm.proxy.mcp_server.utils import get_server_prefix server = self._server("deepwiki", None, "srv-clean") assert get_server_prefix(server) == "deepwiki" @@ -784,12 +784,12 @@ class TestMCPActiveToolsetContextVar: """Tests for _mcp_active_toolset_id ContextVar — clients cannot inject it.""" def test_contextvar_default_is_none(self): - from litellm.proxy._experimental.mcp_server.server import mcp_active_toolset_id + from litellm.proxy.mcp_server.server import mcp_active_toolset_id assert mcp_active_toolset_id.get() is None def test_contextvar_set_and_reset(self): - from litellm.proxy._experimental.mcp_server.server import mcp_active_toolset_id + from litellm.proxy.mcp_server.server import mcp_active_toolset_id token = mcp_active_toolset_id.set("toolset-abc") assert mcp_active_toolset_id.get() == "toolset-abc" @@ -799,7 +799,7 @@ class TestMCPActiveToolsetContextVar: @pytest.mark.asyncio async def test_client_header_is_stripped_in_scope(self): """handle_streamable_http_mcp strips x-mcp-toolset-id from scope before passing to session manager.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, ) @@ -824,35 +824,35 @@ class TestMCPActiveToolsetContextVar: with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new=AsyncMock( return_value=(mock_auth, None, [], {}, {}, scope["headers"]) ), ), patch( - "litellm.proxy._experimental.mcp_server.server.IPAddressUtils", + "litellm.proxy.mcp_server.server.IPAddressUtils", MagicMock(get_mcp_client_ip=MagicMock(return_value="127.0.0.1")), ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", MagicMock(get_mcp_server_by_name=MagicMock(return_value=None)), ), patch( - "litellm.proxy._experimental.mcp_server.server.MCPDebug", + "litellm.proxy.mcp_server.server.MCPDebug", MagicMock( maybe_build_debug_headers=MagicMock(return_value=None), ), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", MagicMock(), ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new=AsyncMock(return_value=True), ), ): diff --git a/tests/unit/proxy/_experimental/mcp_server/test_oauth2_flow_backfill.py b/tests/unit/proxy/mcp_server/test_oauth2_flow_backfill.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_oauth2_flow_backfill.py rename to tests/unit/proxy/mcp_server/test_oauth2_flow_backfill.py index ce079878328..7a7e1cf390a 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_oauth2_flow_backfill.py +++ b/tests/unit/proxy/mcp_server/test_oauth2_flow_backfill.py @@ -17,7 +17,7 @@ from unittest.mock import AsyncMock, MagicMock import pytest -from litellm.proxy._experimental.mcp_server.oauth2_flow_backfill import ( +from litellm.proxy.mcp_server.oauth2_flow_backfill import ( backfill_null_oauth2_flows, classify_null_flow_row, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_oauth2_mcp_config.yaml b/tests/unit/proxy/mcp_server/test_oauth2_mcp_config.yaml similarity index 100% rename from tests/unit/proxy/_experimental/mcp_server/test_oauth2_mcp_config.yaml rename to tests/unit/proxy/mcp_server/test_oauth2_mcp_config.yaml diff --git a/tests/unit/proxy/_experimental/mcp_server/test_oauth2_token_cache.py b/tests/unit/proxy/mcp_server/test_oauth2_token_cache.py similarity index 90% rename from tests/unit/proxy/_experimental/mcp_server/test_oauth2_token_cache.py rename to tests/unit/proxy/mcp_server/test_oauth2_token_cache.py index 6eb93b090e9..f455096d390 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_oauth2_token_cache.py +++ b/tests/unit/proxy/mcp_server/test_oauth2_token_cache.py @@ -10,12 +10,12 @@ from unittest.mock import AsyncMock, MagicMock, patch import httpx import pytest -from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( +from litellm.proxy._types import MCPTransport +from litellm.proxy.mcp_server.oauth2_token_cache import ( MCPOAuth2TokenCache, resolve_mcp_auth, resolved_token_header, ) -from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -55,7 +55,7 @@ async def test_resolve_mcp_auth_fetches_oauth2_token(): mock_client.post.return_value = _token_response("m2m-token-1") with patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ): result = await resolve_mcp_auth(server) @@ -78,11 +78,11 @@ async def test_token_cached_across_calls(): with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ), patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.mcp_oauth2_token_cache", + "litellm.proxy.mcp_server.oauth2_token_cache.mcp_oauth2_token_cache", cache, ), ): @@ -107,11 +107,11 @@ async def test_m2m_token_not_shared_across_server_ids_with_identical_config(): with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ), patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.mcp_oauth2_token_cache", + "litellm.proxy.mcp_server.oauth2_token_cache.mcp_oauth2_token_cache", cache, ), ): @@ -178,7 +178,7 @@ async def test_http_error_raises_value_error(): with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ), pytest.raises(ValueError, match="failed with status 401"), @@ -198,7 +198,7 @@ async def test_non_dict_response_raises_value_error(): with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ), pytest.raises(ValueError, match="non-object JSON"), @@ -217,7 +217,7 @@ async def test_client_credentials_uses_client_secret_basic_when_configured(): mock_client.post.return_value = _token_response("m2m-basic") with patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ): result = await resolve_mcp_auth(server) @@ -236,7 +236,7 @@ def test_storage_ttl_capped_at_token_lifetime(): Redis fast path (which never re-checks expires_at) kept serving the dead token until eviction, while the stored refresh_token sat unused because refresh only runs on the DB read-through.""" from litellm.constants import MCP_PER_USER_TOKEN_EXPIRY_BUFFER_SECONDS - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( + from litellm.proxy.mcp_server.oauth2_token_cache import ( compute_per_user_token_ttl, ) @@ -247,7 +247,7 @@ def test_storage_ttl_capped_at_token_lifetime(): def test_storage_ttl_shorter_than_token_lifetime_wins(): """A configured TTL below the token lifetime is the operative value: the knob's purpose is to force earlier DB re-checks (staleness backstop), so the shorter side must win the min().""" - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( + from litellm.proxy.mcp_server.oauth2_token_cache import ( compute_per_user_token_ttl, ) @@ -258,7 +258,7 @@ def test_storage_ttl_shorter_than_token_lifetime_wins(): def test_storage_ttl_verbatim_when_token_lifetime_unknown(): """With no expires_in from the upstream there is nothing to cap against, so the configured TTL applies as-is (matching the pre-cap behavior for lifetime-less tokens).""" - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( + from litellm.proxy.mcp_server.oauth2_token_cache import ( compute_per_user_token_ttl, ) @@ -269,7 +269,7 @@ def test_storage_ttl_verbatim_when_token_lifetime_unknown(): def test_storage_ttl_floors_at_one_second_for_nearly_dead_token(): """A token already inside the expiry buffer yields the 1-second floor, not zero or a negative TTL, mirroring the floor the default (unconfigured) path has always had.""" - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( + from litellm.proxy.mcp_server.oauth2_token_cache import ( compute_per_user_token_ttl, ) @@ -284,7 +284,7 @@ def test_default_ttl_paths_unchanged_without_storage_ttl(): MCP_PER_USER_TOKEN_DEFAULT_TTL, MCP_PER_USER_TOKEN_EXPIRY_BUFFER_SECONDS, ) - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( + from litellm.proxy.mcp_server.oauth2_token_cache import ( compute_per_user_token_ttl, ) @@ -311,7 +311,7 @@ async def test_client_credentials_sends_rfc8707_resource(configured, expected): mock_client.post.return_value = _token_response("m2m-tok") with patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ): await resolve_mcp_auth(server) @@ -340,7 +340,7 @@ async def test_token_cache_mints_afresh_when_the_token_request_changes(changed): mock_client.post.side_effect = [_token_response("tok-before"), _token_response("tok-after")] with patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ): before = await cache.async_get_token(_server()) @@ -360,7 +360,7 @@ async def test_token_cache_still_reuses_a_token_when_nothing_changed(): mock_client.post.return_value = _token_response("tok-reused") with patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ): first = await cache.async_get_token(_server(upstream_resource="auto")) @@ -383,7 +383,7 @@ async def test_invalidate_clears_every_identity_for_a_server(): ] with patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ): await cache.async_get_token(_server()) @@ -399,8 +399,8 @@ async def test_invalidate_clears_every_identity_for_a_server(): async def test_per_user_token_delete_evicts_locally_and_broadcasts_to_peer_workers(): """Revoking a user's OAuth token must not leave peer workers serving it from their in-memory layer.""" from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import MCPPerUserTokenCache from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.oauth2_token_cache import MCPPerUserTokenCache local_cache = UserApiKeyCache() publish = AsyncMock() @@ -433,7 +433,7 @@ async def test_m2m_mint_uses_admin_entered_token_url_when_issuer_yield_empties_r mock_client.post.return_value = _token_response("m2m-token-configured") with patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ): result = await cache.async_get_token(server) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_oauth_identity_binding.py b/tests/unit/proxy/mcp_server/test_oauth_identity_binding.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_oauth_identity_binding.py rename to tests/unit/proxy/mcp_server/test_oauth_identity_binding.py index 0036035f448..15c80abf576 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_oauth_identity_binding.py +++ b/tests/unit/proxy/mcp_server/test_oauth_identity_binding.py @@ -11,7 +11,7 @@ from cryptography.hazmat.primitives.asymmetric import rsa from fastapi import HTTPException from pydantic import ValidationError -from litellm.proxy._experimental.mcp_server.oauth_identity_binding import ( +from litellm.proxy.mcp_server.oauth_identity_binding import ( RefreshOwnershipProven, RefreshTokenPresented, VerifiedRefreshToken, @@ -101,7 +101,7 @@ async def test_fetch_issuer_jwks_fetches_and_caches_keys(): client.get = AsyncMock(return_value=response) with patch( # test-quality-ok: no HTTP dependency injection seam exists for JWKS fetching - "litellm.proxy._experimental.mcp_server.oauth_identity_binding.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth_identity_binding.get_async_httpx_client", return_value=client, ): first: Final = await _fetch_issuer_jwks(binding) @@ -121,7 +121,7 @@ async def test_fetch_issuer_jwks_rejects_malformed_document(): client.get = AsyncMock(return_value=response) with patch( # test-quality-ok: no HTTP dependency injection seam exists for JWKS fetching - "litellm.proxy._experimental.mcp_server.oauth_identity_binding.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth_identity_binding.get_async_httpx_client", return_value=client, ): with pytest.raises(TypeError, match="has no 'keys' array"): @@ -136,7 +136,7 @@ async def test_discover_jwks_url_returns_provider_uri(): client.get = AsyncMock(return_value=response) with patch( # test-quality-ok: no HTTP dependency injection seam exists for OIDC discovery - "litellm.proxy._experimental.mcp_server.oauth_identity_binding.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth_identity_binding.get_async_httpx_client", return_value=client, ): result: Final = await _discover_jwks_url("https://idp.example.com/") @@ -153,7 +153,7 @@ async def test_discover_jwks_url_rejects_missing_provider_uri(): client.get = AsyncMock(return_value=response) with patch( # test-quality-ok: no HTTP dependency injection seam exists for OIDC discovery - "litellm.proxy._experimental.mcp_server.oauth_identity_binding.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth_identity_binding.get_async_httpx_client", return_value=client, ): with pytest.raises(ValueError, match="returned no jwks_uri"): @@ -177,7 +177,7 @@ async def test_load_caller_principal_supports_user_id_and_database_email(): assert await _load_caller_principal("user-a", user_id_binding) == "user-a" with patch( # test-quality-ok: caller loading is a lazy database boundary without injection - "litellm.proxy._experimental.mcp_server.bridge_token_flow.load_active_user_by_id", + "litellm.proxy.mcp_server.bridge_token_flow.load_active_user_by_id", new=AsyncMock(side_effect=["no_active_key", SimpleNamespace(user_email="alice@example.com")]), ): assert await _load_caller_principal("user-a", _server().oauth_identity_binding) is None @@ -191,7 +191,7 @@ async def test_load_stored_refresh_token_returns_credential_and_fails_closed(): get_credential: Final = AsyncMock(return_value={"refresh_token": "rt-1", "identity_binding_proof": proof}) with ( patch( # test-quality-ok: stored-token loading is a lazy database boundary without injection - "litellm.proxy._experimental.mcp_server.db.get_user_oauth_credential", + "litellm.proxy.mcp_server.db.get_user_oauth_credential", new=get_credential, ), patch( # test-quality-ok: stored-token loading is a lazy database boundary without injection @@ -627,7 +627,7 @@ async def test_authorization_code_rejects_missing_or_foreign_nonce(nonce): @pytest.mark.asyncio async def test_binding_proof_rejects_changed_user_or_policy(): - from litellm.proxy._experimental.mcp_server.oauth_identity_binding import credential_binding_matches + from litellm.proxy.mcp_server.oauth_identity_binding import credential_binding_matches binding = _server(caller_field="user_id", principal_claim="sub").oauth_identity_binding proof = await current_binding_proof(binding, "alice", "srv-1") diff --git a/tests/unit/proxy/_experimental/mcp_server/test_oauth_issuer_stamp_backfill.py b/tests/unit/proxy/mcp_server/test_oauth_issuer_stamp_backfill.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_oauth_issuer_stamp_backfill.py rename to tests/unit/proxy/mcp_server/test_oauth_issuer_stamp_backfill.py index a576bcbb3e2..4f0e91a2c1f 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_oauth_issuer_stamp_backfill.py +++ b/tests/unit/proxy/mcp_server/test_oauth_issuer_stamp_backfill.py @@ -9,10 +9,10 @@ import pytest from litellm._service_logger import ServiceTypes from litellm.proxy import proxy_server -from tests.unit.proxy.db.fake_prisma_engine import engine_call -from litellm.proxy._experimental.mcp_server.oauth_issuer_stamp_backfill import ( +from litellm.proxy.mcp_server.oauth_issuer_stamp_backfill import ( backfill_discovery_stamped_issuers, ) +from tests.unit.proxy.db.fake_prisma_engine import engine_call def _row(**overrides): diff --git a/tests/unit/proxy/_experimental/mcp_server/test_openapi_spec_path_url.py b/tests/unit/proxy/mcp_server/test_openapi_spec_path_url.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_openapi_spec_path_url.py rename to tests/unit/proxy/mcp_server/test_openapi_spec_path_url.py index 17a0022046e..aac85160eba 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_openapi_spec_path_url.py +++ b/tests/unit/proxy/mcp_server/test_openapi_spec_path_url.py @@ -5,7 +5,7 @@ from typing import Any, Dict import httpx import pytest -from litellm.proxy._experimental.mcp_server import openapi_to_mcp_generator as gen +from litellm.proxy.mcp_server import openapi_to_mcp_generator as gen class _FakeAsyncHTTPHandler: diff --git a/tests/unit/proxy/_experimental/mcp_server/test_openapi_to_mcp_generator.py b/tests/unit/proxy/mcp_server/test_openapi_to_mcp_generator.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_openapi_to_mcp_generator.py rename to tests/unit/proxy/mcp_server/test_openapi_to_mcp_generator.py index 9f3db632db1..adb185e4242 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_openapi_to_mcp_generator.py +++ b/tests/unit/proxy/mcp_server/test_openapi_to_mcp_generator.py @@ -17,12 +17,11 @@ import pytest from fastapi import HTTPException from respx import MockRouter -from litellm.types.mcp import MCPAuth, MCPAuthType - -from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( - request_auth_header, - request_extra_headers, - request_resolved_auth_headers, +from litellm.proxy.mcp_server.exceptions import ( + MCPOpenApiUpstreamError, + MCPUpstreamAuthError, +) +from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( _request_upstream_url, _resolve_param_list, _resolve_ref, @@ -30,16 +29,15 @@ from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( create_tool_function, extract_parameters, get_base_url, + request_auth_header, + request_extra_headers, + request_resolved_auth_headers, resolve_operation_params, ) -from litellm.proxy._experimental.mcp_server.tool_outcome import JsonResult, TextResult +from litellm.proxy.mcp_server.tool_outcome import JsonResult, TextResult +from litellm.types.mcp import MCPAuth, MCPAuthType -from litellm.proxy._experimental.mcp_server.exceptions import ( - MCPOpenApiUpstreamError, - MCPUpstreamAuthError, -) - -GET_ASYNC_CLIENT_TARGET = "litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator.get_async_httpx_client" +GET_ASYNC_CLIENT_TARGET = "litellm.proxy.mcp_server.openapi_to_mcp_generator.get_async_httpx_client" @pytest.mark.asyncio @@ -1065,7 +1063,7 @@ class TestResolveOperationParams: class TestSanitizeOpenAPIToolName: def test_replaces_slashes(self): - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( sanitize_openapi_tool_name, ) @@ -1075,35 +1073,35 @@ class TestSanitizeOpenAPIToolName: ) def test_replaces_other_punctuation(self): - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( sanitize_openapi_tool_name, ) assert sanitize_openapi_tool_name("foo.bar:baz qux") == "foo_bar_baz_qux" def test_lowercases(self): - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( sanitize_openapi_tool_name, ) assert sanitize_openapi_tool_name("Pulls/List-Files") == "pulls_list-files" def test_already_valid_passes_through(self): - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( sanitize_openapi_tool_name, ) assert sanitize_openapi_tool_name("plain-tool_name") == "plain-tool_name" def test_empty_string(self): - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( sanitize_openapi_tool_name, ) assert sanitize_openapi_tool_name("") == "" def test_caps_at_128_chars(self): - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( sanitize_openapi_tool_name, ) @@ -1117,7 +1115,7 @@ class TestRegisterToolsFromOpenAPI: def test_github_style_operation_ids_are_sanitized(self, monkeypatch): import re - from litellm.proxy._experimental.mcp_server import openapi_to_mcp_generator + from litellm.proxy.mcp_server import openapi_to_mcp_generator registered: list = [] @@ -1165,7 +1163,7 @@ class TestRegisterToolsFromOpenAPI: ): import re - from litellm.proxy._experimental.mcp_server import openapi_to_mcp_generator + from litellm.proxy.mcp_server import openapi_to_mcp_generator registered: list = [] @@ -1561,7 +1559,7 @@ class TestBoundedOpenAPISpecLoading: @pytest.mark.asyncio @pytest.mark.parametrize("max_bytes", [12, 13]) async def test_exact_size_and_smaller_specs_load(self, respx_mock, monkeypatch, max_bytes): - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import load_openapi_spec_async + from litellm.proxy.mcp_server.openapi_to_mcp_generator import load_openapi_spec_async monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") route = respx_mock.get("https://93.184.216.34/spec.json").respond(200, content=b'{"paths":{}}') @@ -1572,8 +1570,9 @@ class TestBoundedOpenAPISpecLoading: @pytest.mark.parametrize("headers", [{"content-length": "1000000"}, {"content-encoding": "gzip"}]) async def test_unsafe_response_headers_reject_before_reading(self, respx_mock, monkeypatch, headers): import httpx + from litellm.llms.custom_httpx.http_handler import HTTPResponseLimitError - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( load_openapi_spec_async, ) @@ -1596,8 +1595,9 @@ class TestBoundedOpenAPISpecLoading: @pytest.mark.asyncio async def test_chunked_response_is_bounded_and_closed(self, respx_mock, monkeypatch): import httpx + from litellm.llms.custom_httpx.http_handler import HTTPResponseLimitError - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( load_openapi_spec_async, ) @@ -1624,7 +1624,7 @@ class TestBoundedOpenAPISpecLoading: @pytest.mark.parametrize("target", ["https://93.184.216.35/final.json", "http://127.0.0.1/private.json"]) async def test_bounded_spec_redirects_preserve_ssrf_protection(self, respx_mock, monkeypatch, target): from litellm.litellm_core_utils.url_utils import SSRFError - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import load_openapi_spec_async + from litellm.proxy.mcp_server.openapi_to_mcp_generator import load_openapi_spec_async monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") respx_mock.get("https://93.184.216.34/spec.json").respond(302, headers={"location": target}) @@ -1650,7 +1650,7 @@ def without_mcp(name, *args, **kwargs): raise ModuleNotFoundError('MCP SDK unavailable') return original_import(name, *args, **kwargs) builtins.__import__ = without_mcp -import litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator +import litellm.proxy.mcp_server.openapi_to_mcp_generator """ result = subprocess.run([sys.executable, "-c", script], capture_output=True, text=True) assert result.returncode == 0, result.stderr diff --git a/tests/unit/proxy/_experimental/mcp_server/test_openapi_tool_auth.py b/tests/unit/proxy/mcp_server/test_openapi_tool_auth.py similarity index 91% rename from tests/unit/proxy/_experimental/mcp_server/test_openapi_tool_auth.py rename to tests/unit/proxy/mcp_server/test_openapi_tool_auth.py index ffa25d63391..3ff925c486b 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_openapi_tool_auth.py +++ b/tests/unit/proxy/mcp_server/test_openapi_tool_auth.py @@ -1,4 +1,5 @@ -from litellm.proxy._experimental.mcp_server import operations as mcp_operations +from litellm.proxy.mcp_server import operations as mcp_operations + """ VERIA-7 regression: OpenAPI-backed (local-registry) MCP tools must run through `pre_call_tool_check` before dispatch, the same as managed @@ -25,7 +26,7 @@ async def test_openapi_local_tool_runs_pre_call_tool_check(): """When `execute_mcp_tool` resolves a local-registry (OpenAPI) tool AND a server, the pre-call hook must fire before the local handler runs. Pre-fix this path skipped the hook entirely.""" - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module user = UserAPIKeyAuth( api_key="sk-user", @@ -70,11 +71,11 @@ async def test_openapi_local_tool_runs_pre_call_tool_check(): return_value=fake_tool, ), patch( - "litellm.proxy._experimental.mcp_server.operations._handle_local_mcp_tool", + "litellm.proxy.mcp_server.operations._handle_local_mcp_tool", new=handle_local, ), patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ), ): @@ -112,7 +113,7 @@ async def test_openapi_local_tool_blocked_when_pre_call_check_raises(): tool), the local handler must NOT be invoked.""" from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module user = UserAPIKeyAuth( api_key="sk-user", @@ -159,11 +160,11 @@ async def test_openapi_local_tool_blocked_when_pre_call_check_raises(): return_value=fake_tool, ), patch( - "litellm.proxy._experimental.mcp_server.operations._handle_local_mcp_tool", + "litellm.proxy.mcp_server.operations._handle_local_mcp_tool", new=handle_local, ), patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ), ): @@ -188,7 +189,7 @@ async def test_openapi_local_tool_denied_when_server_not_resolvable(): rather than dispatched without `pre_call_tool_check`.""" from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module user = UserAPIKeyAuth( api_key="sk-user", @@ -224,11 +225,11 @@ async def test_openapi_local_tool_denied_when_server_not_resolvable(): return_value=fake_tool, ), patch( - "litellm.proxy._experimental.mcp_server.operations._handle_local_mcp_tool", + "litellm.proxy.mcp_server.operations._handle_local_mcp_tool", new=handle_local, ), patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ), ): @@ -256,14 +257,14 @@ async def test_openapi_local_tool_injects_resolved_oauth_token(): user's completed OAuth flow stored a token that never reached the upstream API. The resolved credential must land in the `_request_resolved_auth_headers` ContextVar the tool closure reads. Kills the mutant that deletes the resolve_openapi_upstream_auth call in server.py.""" - from litellm.proxy._experimental.mcp_server import server as mcp_module - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server import server as mcp_module + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( request_resolved_auth_headers, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok from litellm.types.mcp import MCPAuth, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -315,11 +316,11 @@ async def test_openapi_local_tool_injects_resolved_oauth_token(): new=AsyncMock(return_value=Ok(StaticHeaderAuth("Bearer stored-user-token"))), ), patch( - "litellm.proxy._experimental.mcp_server.operations._handle_local_mcp_tool", + "litellm.proxy.mcp_server.operations._handle_local_mcp_tool", new=handle_local, ), patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ), ): @@ -350,10 +351,10 @@ def legacy_local_tool(): Yields the server and the list the handler appends to, so a test can tell "refused" from "dispatched" by whether the handler actually ran. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.tool_registry import ( + from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) @@ -412,8 +413,8 @@ async def test_legacy_local_tool_fallback_refuses_unentitled_caller(legacy_local """ from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import server as mcp_module - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server import server as mcp_module + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -461,7 +462,7 @@ async def test_legacy_local_tool_fallback_still_dispatches_entitled_caller( This is the backwards-compatibility half. Refusing this call would trade an authorization hole for an outage on a configuration that worked before. """ - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module server, executed = legacy_local_tool user = _caller_entitled_to([LEGACY_TOOL]) @@ -491,7 +492,7 @@ async def test_legacy_local_tool_fallback_fails_closed_on_empty_prefix( """ from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module _server, executed = legacy_local_tool @@ -520,7 +521,7 @@ async def test_legacy_local_tool_fallback_fails_closed_when_prefix_names_no_serv """ from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module _server, executed = legacy_local_tool other_server = MCPServer( @@ -534,7 +535,7 @@ async def test_legacy_local_tool_fallback_fails_closed_when_prefix_names_no_serv ) with patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ): with pytest.raises(HTTPException) as exc: @@ -558,7 +559,7 @@ async def test_unknown_tool_name_still_reports_not_found(): """ from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module with pytest.raises(HTTPException) as exc: await mcp_operations.execute_mcp_tool( @@ -603,8 +604,8 @@ async def test_per_server_auth_header_reaches_both_openapi_dispatch_arms(dispatc modes the credential has to reach `resolve_openapi_upstream_auth`, whose passthrough arm outranks the ContextVar when it materializes a header. """ - from litellm.proxy._experimental.mcp_server import server as mcp_module - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server import server as mcp_module + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( request_auth_header, ) @@ -640,11 +641,11 @@ async def test_per_server_auth_header_reaches_both_openapi_dispatch_arms(dispatc patch.object(manager, "get_mcp_server_from_tool_name", return_value=server), patch.object(mcp_operations.global_mcp_tool_registry, "get_tool", return_value=fake_tool), patch( - "litellm.proxy._experimental.mcp_server.operations._handle_local_mcp_tool", + "litellm.proxy.mcp_server.operations._handle_local_mcp_tool", new=capture_local, ), patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ), ): @@ -690,8 +691,8 @@ async def test_local_dispatch_reports_the_outcome_instead_of_success(failure: st `call_tool_rest_api` turns an unrecognized exception into HTTP 500 and an upstream 403 or 429 is not a gateway crash. """ - from litellm.proxy._experimental.mcp_server import server as mcp_module - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server import server as mcp_module + from litellm.proxy.mcp_server.exceptions import ( MCPOpenApiUpstreamError, MCPUpstreamAuthError, ) @@ -732,7 +733,7 @@ async def test_local_dispatch_reports_the_outcome_instead_of_success(failure: st new=AsyncMock(return_value=(None, None)), ), patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ), ): @@ -797,9 +798,9 @@ def test_the_openapi_arm_installs_the_guard_when_a_credential_rides_a_custom_slo """Pins the wiring, not just the hook: the arm must actually build a guarded client. Testing the hook alone passes even if this arm never installs it. """ - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( - request_resolved_auth_headers, + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( _upstream_client, + request_resolved_auth_headers, ) token = request_resolved_auth_headers.set({"esb-oauth": "Bearer minted"}) @@ -815,9 +816,9 @@ def test_the_guarded_client_is_reused_rather_than_built_per_call(): sets upstream_token_header would leak an httpx client and its connection pool. Both variants have to come from the shared cache. """ - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( - request_resolved_auth_headers, + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( _upstream_client, + request_resolved_auth_headers, ) token = request_resolved_auth_headers.set({"esb-oauth": "Bearer minted"}) @@ -834,10 +835,10 @@ async def test_the_shared_guard_reads_the_url_from_the_request_context(): """ import httpx - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( _drop_credential_across_origin, - request_resolved_auth_headers, _request_upstream_url, + request_resolved_auth_headers, ) creds = request_resolved_auth_headers.set({"esb-oauth": "Bearer minted"}) @@ -859,9 +860,9 @@ async def test_the_shared_guard_reads_the_url_from_the_request_context(): def test_the_openapi_arm_keeps_the_shared_client_when_no_guard_is_needed(resolved): # Authorization is already stripped across origins by the HTTP client, so taking the guarded # path for it would give up the shared connection pool for nothing. - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( - request_resolved_auth_headers, + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( _upstream_client, + request_resolved_auth_headers, ) token = request_resolved_auth_headers.set(resolved) @@ -880,7 +881,7 @@ async def test_openapi_passthrough_preparation_preserves_credential_precedence( ) -> None: from typing import Final - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager server: Final = MCPServer( server_id="openapi-passthrough", name="openapi-passthrough", transport=MCPTransport.http, diff --git a/tests/unit/proxy/_experimental/mcp_server/test_operations.py b/tests/unit/proxy/mcp_server/test_operations.py similarity index 94% rename from tests/unit/proxy/_experimental/mcp_server/test_operations.py rename to tests/unit/proxy/mcp_server/test_operations.py index 6f7437c90dc..497c4482eba 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_operations.py +++ b/tests/unit/proxy/mcp_server/test_operations.py @@ -11,20 +11,21 @@ from mcp.types import Tool as MCPTool import litellm from litellm.caching.dual_cache import DualCache from litellm.integrations.custom_logger import CustomLogger -from litellm.proxy._experimental.mcp_server import operations -from litellm.proxy._experimental.mcp_server import rest_endpoints -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - HTTPException as MCPServerManagerHTTPException, - ListedToolsCaller, -) -from litellm.proxy._experimental.mcp_server.operations import GatewayOperations, prepare_context -from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry from litellm.proxy._types import UserAPIKeyAuth -from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError +from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache from litellm.proxy.hooks.parallel_request_limiter_v3 import ( PROXY_MaxParallelRequestsHandler_v3, ) +from litellm.proxy.mcp_server import operations, rest_endpoints +from litellm.proxy.mcp_server.mcp_server_manager import ( + HTTPException as MCPServerManagerHTTPException, +) +from litellm.proxy.mcp_server.mcp_server_manager import ( + ListedToolsCaller, +) +from litellm.proxy.mcp_server.operations import GatewayOperations, prepare_context +from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry from litellm.proxy.utils import InternalUsageCache, ProxyLogging, hash_token from litellm.types.mcp import MCPAuth, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -106,11 +107,11 @@ async def test_mapped_caller_bearer_reaches_agent_evaluation( from starlette.requests import Request from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler - from litellm.proxy._experimental.mcp_server import server as gateway - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler - from litellm.proxy._experimental.mcp_server.mcp_context import _mcp_proxy_mode - from litellm.proxy._experimental.mcp_server.tool_search import mcp_proxy_tool_id, with_mcp_proxy_identity from litellm.proxy.guardrails.guardrail_hooks.agent_365.agent_365 import Agent365Guardrail + from litellm.proxy.mcp_server import server as gateway + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.mcp_context import _mcp_proxy_mode + from litellm.proxy.mcp_server.tool_search import mcp_proxy_tool_id, with_mcp_proxy_identity bearer: Final = "signed.caller.assertion" request: Final = Request( @@ -163,7 +164,7 @@ async def test_mapped_caller_bearer_reaches_agent_evaluation( executions: Final[asyncio.Queue[str]] = asyncio.Queue() async def tool() -> str: - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import request_extra_headers + from litellm.proxy.mcp_server.openapi_to_mcp_generator import request_extra_headers assert bearer not in str(request_extra_headers.get()) executions.put_nowait("executed") @@ -313,14 +314,14 @@ async def test_listing_records_only_tools_the_caller_received( @pytest.mark.asyncio async def test_oauth_prefetch_failure_does_not_log_caller_or_exception_text(caplog): - from litellm.proxy._experimental.mcp_server.operations import _prefetch_oauth_creds_for_user + from litellm.proxy.mcp_server.operations import _prefetch_oauth_creds_for_user user_id = "caller\nFORGED-USER-LINE" fetch = AsyncMock(side_effect=RuntimeError("database\nFORGED-ERROR-LINE")) database = object() with ( patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=database), - patch("litellm.proxy._experimental.mcp_server.db.list_user_oauth_credentials", fetch), + patch("litellm.proxy.mcp_server.db.list_user_oauth_credentials", fetch), caplog.at_level("WARNING", logger="LiteLLM"), ): result = await _prefetch_oauth_creds_for_user(UserAPIKeyAuth(user_id=user_id)) @@ -337,7 +338,7 @@ async def test_oauth_prefetch_failure_does_not_log_caller_or_exception_text(capl async def test_dispatch_uses_explicit_context_when_ambient_caller_differs(): from mcp.server.auth.middleware.auth_context import auth_context_var - from litellm.proxy._experimental.mcp_server.server import set_auth_context + from litellm.proxy.mcp_server.server import set_auth_context context = prepare_context( UserAPIKeyAuth(user_id="alpha"), @@ -349,7 +350,7 @@ async def test_dispatch_uses_explicit_context_when_ambient_caller_differs(): handler = AsyncMock(return_value=GetPromptResult(messages=[])) try: set_auth_context(UserAPIKeyAuth(user_id="bravo"), raw_headers={"x-caller": "bravo"}) - with patch("litellm.proxy._experimental.mcp_server.operations.mcp_get_prompt", handler): + with patch("litellm.proxy.mcp_server.operations.mcp_get_prompt", handler): result = await GatewayOperations().execute( GetPromptRequest(params=GetPromptRequestParams(name="alpha-prompt")), context ) @@ -367,8 +368,8 @@ async def test_dispatch_uses_explicit_context_when_ambient_caller_differs(): async def test_legacy_adapter_cleans_context_after_cancelled_operation(): from types import SimpleNamespace - from litellm.proxy._experimental.mcp_server import server - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server import server + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var previous_session = server.active_mcp_session_var.get() previous_request = active_mcp_request_ctx_var.get() @@ -382,7 +383,7 @@ async def test_legacy_adapter_cleans_context_after_cancelled_operation(): raise asyncio.CancelledError with patch( - "litellm.proxy._experimental.mcp_server.server.get_or_extract_auth_context", AsyncMock(return_value=auth) + "litellm.proxy.mcp_server.server.get_or_extract_auth_context", AsyncMock(return_value=auth) ): with pytest.raises(asyncio.CancelledError): await cancelled_operation() @@ -394,8 +395,8 @@ async def test_legacy_adapter_cleans_context_after_cancelled_operation(): async def test_legacy_adapter_cleans_context_when_trace_setup_fails(): from types import SimpleNamespace - from litellm.proxy._experimental.mcp_server import server - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server import server + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var previous_session = server.active_mcp_session_var.get() previous_request = active_mcp_request_ctx_var.get() @@ -416,7 +417,7 @@ async def test_legacy_adapter_cleans_context_when_trace_setup_fails(): async def test_prompt_sampling_receives_explicit_operation_caller_headers_and_ip(): from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server import operations + from litellm.proxy.mcp_server import operations from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -437,8 +438,8 @@ async def test_prompt_sampling_receives_explicit_operation_caller_headers_and_ip sampling = AsyncMock() with ( patch.object(operations, "_get_allowed_mcp_servers", AsyncMock(return_value=[upstream])), - patch("litellm.proxy._experimental.mcp_server.upstream.MCPClient", return_value=client) as factory, - patch("litellm.proxy._experimental.mcp_server.sampling_handler.handle_sampling_create_message", sampling), + patch("litellm.proxy.mcp_server.upstream.MCPClient", return_value=client) as factory, + patch("litellm.proxy.mcp_server.sampling_handler.handle_sampling_create_message", sampling), ): result = await GatewayOperations().execute( GetPromptRequest(params=GetPromptRequestParams(name="explicit_prompt-prompt")), context @@ -519,7 +520,7 @@ async def test_disabled_capability_never_reaches_upstream( from mcp.types import METHOD_NOT_FOUND from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import catalog + from litellm.proxy.mcp_server import catalog monkeypatch.setitem(proxy_server.general_settings, "mcp_disabled_capabilities", [disabled]) request, _client_method, manager_method, upstream_value, result_field = _catalog_case(operation) @@ -567,8 +568,8 @@ async def test_mcp_server_rpm_limits_every_catalog_operation(operation: str) -> from mcp.shared.exceptions import MCPError from mcp.types import INVALID_REQUEST - from litellm.proxy._experimental.mcp_server import catalog - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ServerListOk + from litellm.proxy.mcp_server import catalog + from litellm.proxy.mcp_server.faults.list_outcomes import ServerListOk server: Final = MCPServer( server_id="catalog-rpm", @@ -712,7 +713,7 @@ def _scoped_rig( from mcp.types import CallToolResult, TextContent from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager: Final = MCPServerManager() memory: Final = MCPServer( @@ -787,7 +788,7 @@ async def test_bare_tool_name_without_a_single_server_scope_is_still_unresolved_ @pytest.mark.asyncio async def test_tools_call_pre_call_check_enforces_mcp_server_rpm() -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager server: Final = MCPServer( server_id="catalog-call", @@ -822,7 +823,7 @@ async def test_tools_call_pre_call_check_enforces_mcp_server_rpm() -> None: async def test_tools_call_pre_call_hook_rejection_does_not_enforce_mcp_server_rpm() -> None: from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager server: Final = MCPServer( server_id="catalog-call-pre-hook-rejected", @@ -854,7 +855,7 @@ async def test_tools_call_pre_call_hook_rejection_does_not_enforce_mcp_server_rp @pytest.mark.asyncio async def test_disallowed_tool_does_not_consume_mcp_server_rpm() -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager server: Final = MCPServer( server_id="catalog-call-authorization", @@ -900,7 +901,7 @@ async def test_catalog_helpers_preserve_context_results_and_failure_policy(metho from mcp.server.context import ServerRequestContext from mcp.types import PaginatedRequestParams - from litellm.proxy._experimental.mcp_server import operations, server + from litellm.proxy.mcp_server import operations, server from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -967,7 +968,7 @@ async def test_explicit_proxy_context_rejects_catalog_operations_before_upstream from mcp.shared.exceptions import MCPError from mcp.types import METHOD_NOT_FOUND - from litellm.proxy._experimental.mcp_server import operations + from litellm.proxy.mcp_server import operations operation, _, manager_method, _, _ = _catalog_case(method) upstream = AsyncMock() @@ -985,8 +986,8 @@ async def test_tool_operation_preserves_failure_messages_and_request_trace(failu from mcp.types import CallToolRequest, CallToolRequestParams from litellm.exceptions import BlockedPiiEntityError, GuardrailRaisedException - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.utils import MCPMissingUserEnvVarsError + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.utils import MCPMissingUserEnvVarsError failures = { "missing_env": ( @@ -1029,7 +1030,7 @@ async def test_tool_operation_preserves_failure_messages_and_request_trace(failu ], ) async def test_catalog_operation_preserves_empty_result_for_malformed_upstream_items(method, helper): - from litellm.proxy._experimental.mcp_server import operations + from litellm.proxy.mcp_server import operations operation, _, _, _, collection = _catalog_case(method) with patch.object(operations, helper, AsyncMock(return_value=[{"unexpected": "item"}])): @@ -1042,7 +1043,7 @@ async def test_catalog_operation_preserves_empty_result_for_malformed_upstream_i async def test_tool_listing_returns_empty_result_without_dispatch_for_unavailable_catalog(catalog_unavailable): from mcp.types import ListToolsRequest - from litellm.proxy._experimental.mcp_server import operations + from litellm.proxy.mcp_server import operations allowed = AsyncMock( return_value=[], side_effect=RuntimeError("catalog unavailable") if catalog_unavailable else None @@ -1062,7 +1063,7 @@ async def test_tool_listing_returns_empty_result_without_dispatch_for_unavailabl async def test_explicit_proxy_context_lists_builtin_tools_and_blocks_direct_tool_dispatch(): from mcp.types import CallToolRequest, CallToolRequestParams, ListToolsRequest - from litellm.proxy._experimental.mcp_server import operations + from litellm.proxy.mcp_server import operations context = prepare_context(mcp_proxy_mode=True) allowed = AsyncMock() @@ -1104,7 +1105,7 @@ class TestChallengeMissingTokenExchangeSubject: raw_headers: dict[str, str] | None = None, requested_server: MCPServer | None = None, ) -> None: - from litellm.proxy._experimental.mcp_server.operations import _challenge_missing_token_exchange_subject + from litellm.proxy.mcp_server.operations import _challenge_missing_token_exchange_subject return _challenge_missing_token_exchange_subject( server=server, @@ -1200,7 +1201,7 @@ async def test_execute_mcp_tool_challenges_missing_subject_before_cold_listing() from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import operations + from litellm.proxy.mcp_server import operations server = _server("te-exec", MCPAuth.oauth2_token_exchange) listing = AsyncMock() @@ -1230,9 +1231,9 @@ async def test_local_tool_json_array_is_converted_once_for_the_caller_revision(c text block; converting at the caller's revision keeps the upstream body exactly once.""" from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.tool_outcome import WireCompat, parse_http_body - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.tool_outcome import WireCompat, parse_http_body + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry body = '["a","b"]' tool = MagicMock() @@ -1253,7 +1254,7 @@ async def test_discovery_preserves_caller_scope_and_proxy_restrictions(): context = prepare_context( UserAPIKeyAuth(user_id="scoped"), mcp_servers=["only-this"], mcp_proxy_mode=True, protocol_version="2025-06-18" ) - with patch("litellm.proxy._experimental.mcp_server.operations._execute_handle_list_tools", listed): + with patch("litellm.proxy.mcp_server.operations._execute_handle_list_tools", listed): result = await GatewayOperations().execute(DiscoverRequest(), context) assert result.capabilities.tools is not None assert result.capabilities.resources is None @@ -1267,8 +1268,8 @@ async def test_discovery_preserves_caller_scope_and_proxy_restrictions(): async def test_discovery_outright_tools_failure_still_advertises_other_capabilities() -> None: from mcp.types import DiscoverRequest, ListPromptsResult, ListToolsResult, Prompt - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.catalog import ToolListingFailedOutright + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.catalog import ToolListingFailedOutright tools: Final = AsyncMock(side_effect=ToolListingFailedOutright(code=-32603, message="every server failed")) prompts: Final = AsyncMock(return_value=ListPromptsResult(prompts=[Prompt(name="p")])) @@ -1289,7 +1290,7 @@ async def test_discovery_propagates_non_outright_mcp_errors_from_tools_listing() from mcp import MCPError from mcp.types import INVALID_PARAMS, DiscoverRequest - from litellm.proxy._experimental.mcp_server import operations + from litellm.proxy.mcp_server import operations tools: Final = AsyncMock(side_effect=MCPError(code=INVALID_PARAMS, message="bad cursor")) context: Final = prepare_context( @@ -1304,11 +1305,11 @@ async def test_discovery_propagates_non_outright_mcp_errors_from_tools_listing() @pytest.mark.asyncio async def test_discovery_denial_cannot_advertise_tools(): - from mcp.types import DiscoverRequest from fastapi import HTTPException + from mcp.types import DiscoverRequest denied = AsyncMock(side_effect=HTTPException(status_code=403, detail="Forbidden")) - with patch("litellm.proxy._experimental.mcp_server.operations._execute_handle_list_tools", denied): + with patch("litellm.proxy.mcp_server.operations._execute_handle_list_tools", denied): with pytest.raises(HTTPException) as error: await GatewayOperations().execute(DiscoverRequest(), prepare_context(UserAPIKeyAuth(user_id="denied"))) assert error.value.status_code == 403 @@ -1319,15 +1320,16 @@ async def test_discovery_denial_cannot_advertise_tools(): async def test_discovery_lists_each_capability_with_the_same_caller(available): from mcp.types import ( DiscoverRequest, - ListToolsResult, ListPromptsResult, ListResourcesResult, ListResourceTemplatesResult, + ListToolsResult, Prompt, Resource, ResourceTemplate, ) - from litellm.proxy._experimental.mcp_server import operations + + from litellm.proxy.mcp_server import operations context = prepare_context(UserAPIKeyAuth(user_id="scoped"), mcp_servers=["authorized"]) tools = AsyncMock(return_value=ListToolsResult(tools=[])) @@ -1408,9 +1410,9 @@ async def test_discovery_skips_disabled_capability_listings(disabled: str, monke async def test_discovery_shares_one_server_admission_across_catalog_listings() -> None: from mcp import types - from litellm.proxy._experimental.mcp_server import catalog - from litellm.proxy._experimental.mcp_server.contracts import OperationContext - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ServerListOk + from litellm.proxy.mcp_server import catalog + from litellm.proxy.mcp_server.contracts import OperationContext + from litellm.proxy.mcp_server.faults.list_outcomes import ServerListOk admitted: Final = MCPServer( server_id="discover-admitted", @@ -1506,12 +1508,13 @@ async def test_discovery_shares_one_server_admission_across_catalog_listings() - async def test_discovery_concurrent_listings_drain_on_failure_and_cancellation(outcome): from mcp.types import ( DiscoverRequest, - ListToolsResult, ListPromptsResult, ListResourcesResult, ListResourceTemplatesResult, + ListToolsResult, ) - from litellm.proxy._experimental.mcp_server import operations + + from litellm.proxy.mcp_server import operations ready = [asyncio.Event() for _ in range(4)] closed = [asyncio.Event() for _ in range(4)] @@ -1570,7 +1573,8 @@ async def test_discovery_concurrent_listings_drain_on_failure_and_cancellation(o @pytest.mark.parametrize("log_enabled", [False, True]) async def test_tools_listing_preserves_explicit_spend_log_policy(log_enabled): from mcp.types import PaginatedRequestParams - from litellm.proxy._experimental.mcp_server import operations + + from litellm.proxy.mcp_server import operations listing = AsyncMock(return_value=operations.AggregateToolListing(tools=[], outcomes={})) with patch.object(operations, "_list_mcp_tools", listing): @@ -1614,14 +1618,15 @@ async def test_list_mcp_tools_records_the_catalog_only_when_asked( async def test_discovery_keeps_one_catalog_revision_across_concurrent_listings(monkeypatch): from mcp.types import ( DiscoverRequest, - ListToolsResult, ListPromptsResult, ListResourcesResult, ListResourceTemplatesResult, + ListToolsResult, ) + from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager = MCPServerManager() original = MCPServer(server_id="catalog-server", name="before", transport=MCPTransport.http) @@ -1667,7 +1672,7 @@ async def test_local_handler_freshness_tracks_registered_owner_with_overlapping_ from fastapi import HTTPException from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager monkeypatch.setattr(proxy_server, "prisma_client", None) manager = MCPServerManager() @@ -1710,7 +1715,7 @@ async def test_local_call_cannot_borrow_another_servers_authority( from fastapi import HTTPException from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager: Final = MCPServerManager() allowed: Final = MCPServer(server_id="allowed", name="allowed", transport=MCPTransport.http) @@ -1747,7 +1752,7 @@ async def test_local_call_preserves_matching_and_legacy_handlers( from datetime import datetime from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager: Final = MCPServerManager() server: Final = MCPServer(server_id="allowed", name="allowed", transport=MCPTransport.http) @@ -1777,7 +1782,7 @@ async def test_local_handler_rejects_an_owner_absent_from_the_catalog(monkeypatc from fastapi import HTTPException from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager: Final = MCPServerManager() handler: Final = AsyncMock(return_value="private result") @@ -1854,6 +1859,7 @@ async def test_optional_catalog_preserves_revoked_user_error(monkeypatch, reques from types import SimpleNamespace from mcp import MCPError, types + from litellm.caching.dual_cache import DualCache from litellm.proxy import proxy_server @@ -1943,7 +1949,8 @@ async def test_guardrail_context_never_recovers_a_previous_request_bearer( ) -> None: from mcp.server.auth.middleware.auth_context import auth_context_var from starlette.requests import Request - from litellm.proxy._experimental.mcp_server import server as gateway + + from litellm.proxy.mcp_server import server as gateway request: Final = ( None @@ -1988,12 +1995,19 @@ async def test_guardrail_context_never_recovers_a_previous_request_bearer( @pytest.mark.parametrize("delay", ["target", "probe", "exhausted"]) async def test_discovery_optional_probes_use_remaining_listing_budget(delay, monkeypatch): from types import SimpleNamespace + from mcp.types import ( - DiscoverRequest, ListToolsResult, ListPromptsResult, ListResourcesResult, - ListResourceTemplatesResult, ToolsCapability, Tool, + DiscoverRequest, + ListPromptsResult, + ListResourcesResult, + ListResourceTemplatesResult, + ListToolsResult, + Tool, + ToolsCapability, ) + from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import subscriptions + from litellm.proxy.mcp_server import subscriptions entered = asyncio.Event() cleaned = asyncio.Event() diff --git a/tests/unit/proxy/_experimental/mcp_server/test_per_user_oauth_cache.py b/tests/unit/proxy/mcp_server/test_per_user_oauth_cache.py similarity index 91% rename from tests/unit/proxy/_experimental/mcp_server/test_per_user_oauth_cache.py rename to tests/unit/proxy/mcp_server/test_per_user_oauth_cache.py index efddd1beef3..c0e23319566 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_per_user_oauth_cache.py +++ b/tests/unit/proxy/mcp_server/test_per_user_oauth_cache.py @@ -19,7 +19,7 @@ for _mod in ("orjson",): if _mod not in sys.modules: sys.modules[_mod] = MagicMock() -from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( # noqa: E402 +from litellm.proxy.mcp_server.oauth2_token_cache import ( # noqa: E402 MCPPerUserTokenCache, compute_per_user_token_ttl, mcp_per_user_token_cache, @@ -30,7 +30,7 @@ from litellm.types.mcp_server.mcp_server_manager import MCPServer # noqa: E402 def _import_validate(): """Lazy import to avoid pulling orjson at collection time.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _validate_token_response, ) @@ -263,7 +263,7 @@ class TestMCPPerUserTokenCache: async def test_get_returns_none_on_miss(self, cache, mock_dual_cache): with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.decrypt_value_helper" + "litellm.proxy.mcp_server.oauth2_token_cache.decrypt_value_helper" ) as mock_decrypt, patch("litellm.proxy.proxy_server.user_api_key_cache", mock_dual_cache), ): @@ -278,7 +278,7 @@ class TestMCPPerUserTokenCache: fake_plaintext = "xoxb-slack-token" with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.decrypt_value_helper", + "litellm.proxy.mcp_server.oauth2_token_cache.decrypt_value_helper", return_value=fake_plaintext, ) as mock_decrypt, patch("litellm.proxy.proxy_server.user_api_key_cache", mock_dual_cache), @@ -298,7 +298,7 @@ class TestMCPPerUserTokenCache: fake_encrypted = "encrypted_blob_xyz" with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.encrypt_value_helper", + "litellm.proxy.mcp_server.oauth2_token_cache.encrypt_value_helper", return_value=fake_encrypted, ) as mock_encrypt, patch("litellm.proxy.proxy_server.user_api_key_cache", mock_dual_cache), @@ -315,7 +315,7 @@ class TestMCPPerUserTokenCache: async def test_set_uses_correct_cache_key(self, cache, mock_dual_cache): with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.encrypt_value_helper", + "litellm.proxy.mcp_server.oauth2_token_cache.encrypt_value_helper", return_value="enc", ), patch("litellm.proxy.proxy_server.user_api_key_cache", mock_dual_cache), @@ -339,7 +339,7 @@ class TestMCPPerUserTokenCache: """Cache misses and decrypt errors should both return None without raising.""" with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.decrypt_value_helper", + "litellm.proxy.mcp_server.oauth2_token_cache.decrypt_value_helper", return_value=None, # decrypt returns None on failure ), patch("litellm.proxy.proxy_server.user_api_key_cache", mock_dual_cache), @@ -355,7 +355,7 @@ class TestMCPPerUserTokenCache: mock_dual_cache.async_set_cache.side_effect = RuntimeError("Redis down") with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.encrypt_value_helper", + "litellm.proxy.mcp_server.oauth2_token_cache.encrypt_value_helper", return_value="enc", ), patch("litellm.proxy.proxy_server.user_api_key_cache", mock_dual_cache), @@ -385,7 +385,7 @@ class TestRefreshUserOauthToken: @pytest.mark.asyncio async def test_returns_none_when_no_refresh_token(self, server): - from litellm.proxy._experimental.mcp_server.db import refresh_user_oauth_token + from litellm.proxy.mcp_server.db import refresh_user_oauth_token cred = {"type": "oauth2", "access_token": "OLD"} # no refresh_token result = await refresh_user_oauth_token( @@ -398,7 +398,7 @@ class TestRefreshUserOauthToken: @pytest.mark.asyncio async def test_returns_none_when_no_token_url(self, cred): - from litellm.proxy._experimental.mcp_server.db import refresh_user_oauth_token + from litellm.proxy.mcp_server.db import refresh_user_oauth_token server = _make_server(token_url=None) result = await refresh_user_oauth_token( @@ -411,13 +411,13 @@ class TestRefreshUserOauthToken: @pytest.mark.asyncio async def test_returns_none_on_http_error(self, server, cred): - from litellm.proxy._experimental.mcp_server.db import refresh_user_oauth_token + from litellm.proxy.mcp_server.db import refresh_user_oauth_token mock_client = AsyncMock() mock_client.post.side_effect = Exception("Connection refused") with patch( - "litellm.proxy._experimental.mcp_server.db.get_async_httpx_client", + "litellm.proxy.mcp_server.db.get_async_httpx_client", return_value=mock_client, ): result = await refresh_user_oauth_token( @@ -430,7 +430,7 @@ class TestRefreshUserOauthToken: @pytest.mark.asyncio async def test_stores_and_returns_new_credential(self, server, cred): - from litellm.proxy._experimental.mcp_server.db import refresh_user_oauth_token + from litellm.proxy.mcp_server.db import refresh_user_oauth_token new_token_response = MagicMock() new_token_response.json.return_value = { @@ -453,15 +453,15 @@ class TestRefreshUserOauthToken: with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_async_httpx_client", + "litellm.proxy.mcp_server.db.get_async_httpx_client", return_value=mock_client, ), patch( - "litellm.proxy._experimental.mcp_server.db.store_user_oauth_credential", + "litellm.proxy.mcp_server.db.store_user_oauth_credential", new_callable=AsyncMock, ) as mock_store, patch( - "litellm.proxy._experimental.mcp_server.db.get_user_oauth_credential", + "litellm.proxy.mcp_server.db.get_user_oauth_credential", new_callable=AsyncMock, return_value=stored_cred, ), @@ -486,7 +486,7 @@ class TestRefreshUserOauthToken: @pytest.mark.asyncio async def test_falls_back_to_old_refresh_token_when_not_rotated(self, server, cred): """When provider doesn't return a new refresh_token, keep the old one.""" - from litellm.proxy._experimental.mcp_server.db import refresh_user_oauth_token + from litellm.proxy.mcp_server.db import refresh_user_oauth_token new_token_response = MagicMock() new_token_response.json.return_value = { @@ -501,15 +501,15 @@ class TestRefreshUserOauthToken: with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_async_httpx_client", + "litellm.proxy.mcp_server.db.get_async_httpx_client", return_value=mock_client, ), patch( - "litellm.proxy._experimental.mcp_server.db.store_user_oauth_credential", + "litellm.proxy.mcp_server.db.store_user_oauth_credential", new_callable=AsyncMock, ) as mock_store, patch( - "litellm.proxy._experimental.mcp_server.db.get_user_oauth_credential", + "litellm.proxy.mcp_server.db.get_user_oauth_credential", new_callable=AsyncMock, return_value={"type": "oauth2", "access_token": "NEW_TOKEN"}, ), diff --git a/tests/unit/proxy/_experimental/mcp_server/test_proxy_api_credentials.py b/tests/unit/proxy/mcp_server/test_proxy_api_credentials.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_proxy_api_credentials.py rename to tests/unit/proxy/mcp_server/test_proxy_api_credentials.py index f39aec82c3e..f3d0fed0222 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_proxy_api_credentials.py +++ b/tests/unit/proxy/mcp_server/test_proxy_api_credentials.py @@ -7,20 +7,20 @@ from fastapi import HTTPException from litellm.constants import CLI_JWT_EXPIRATION_HOURS from litellm.models.user import LiteLLM_UserTable -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ConsentTeam, MintedProxyCredential -from litellm.proxy._experimental.mcp_server.proxy_api_credentials import ( - lookup_consent_teams, - lookup_consent_teams_from_database, - mint_proxy_credential, -) from litellm.proxy._types import LitellmUserRoles from litellm.proxy.auth.auth_checks import ExperimentalUIJWTToken from litellm.proxy.auth.route_checks import RouteChecks from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache from litellm.proxy.management_endpoints.ui_sso import CliSsoTeamDetail +from litellm.proxy.mcp_server.gateway_dcr_flow import ConsentTeam, MintedProxyCredential +from litellm.proxy.mcp_server.proxy_api_credentials import ( + lookup_consent_teams, + lookup_consent_teams_from_database, + mint_proxy_credential, +) -_LOAD_USER = "litellm.proxy._experimental.mcp_server.proxy_api_credentials.load_active_user_by_id" -_FETCH_TEAMS = "litellm.proxy._experimental.mcp_server.proxy_api_credentials.fetch_cli_sso_team_details" +_LOAD_USER = "litellm.proxy.mcp_server.proxy_api_credentials.load_active_user_by_id" +_FETCH_TEAMS = "litellm.proxy.mcp_server.proxy_api_credentials.fetch_cli_sso_team_details" _PRISMA = "litellm.proxy.proxy_server.prisma_client" TEAM_DETAILS = ( CliSsoTeamDetail(team_id="team-a", team_alias="Team A", team_models=("gpt-5.4-mini",)), diff --git a/tests/unit/proxy/_experimental/mcp_server/test_rest_endpoints.py b/tests/unit/proxy/mcp_server/test_rest_endpoints.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_rest_endpoints.py rename to tests/unit/proxy/mcp_server/test_rest_endpoints.py index 73e248ff52e..84d32934208 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_rest_endpoints.py +++ b/tests/unit/proxy/mcp_server/test_rest_endpoints.py @@ -6,7 +6,7 @@ from datetime import datetime from typing import Any, Dict, Final, Optional from unittest.mock import AsyncMock, MagicMock -from litellm.proxy._experimental.mcp_server import operations as mcp_operations +from litellm.proxy.mcp_server import operations as mcp_operations if sys.version_info < (3, 11): # BaseExceptionGroup is a builtin only from 3.11 from exceptiongroup import BaseExceptionGroup @@ -18,16 +18,16 @@ from mcp.types import CallToolResult, TextContent, Tool from starlette.requests import Request from litellm.constants import MCP_TOOL_LISTING_TIMEOUT -from litellm.proxy._experimental.mcp_server import rest_endpoints -from litellm.proxy._experimental.mcp_server.auth import ( - user_api_key_auth_mcp as auth_mcp, -) from litellm.proxy._types import ( NewMCPServerRequest, UpdateMCPServerRequest, UserAPIKeyAuth, ) from litellm.proxy.auth.user_api_key_auth import user_api_key_auth +from litellm.proxy.mcp_server import rest_endpoints +from litellm.proxy.mcp_server.auth import ( + user_api_key_auth_mcp as auth_mcp, +) from litellm.types.mcp import MCPAuth, MCPTransport, MCPUpstreamProtocol from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -114,9 +114,9 @@ class TestExecuteWithMcpClient: ) -> None: from starlette.datastructures import Headers - from litellm.experimental_mcp_client.client import MCPClient - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.mcp_client.client import MCPClient from litellm.proxy.management_endpoints import mcp_management_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager saved: Final = MCPServer( server_id="saved-preview-server", @@ -184,8 +184,8 @@ class TestExecuteWithMcpClient: ) -> None: from starlette.datastructures import Headers - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy.management_endpoints import mcp_management_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager saved: Final = MCPServer( server_id="saved-preview-server", @@ -808,10 +808,9 @@ class TestTestConnection: """The edit form resends a saved server without its masked credential; the stored one must be used, as /test/tools/list already does.""" from litellm.proxy._types import LitellmUserRoles - from litellm.types.mcp_server.mcp_server_manager import MCPServer - - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy.management_endpoints import mcp_management_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager + from litellm.types.mcp_server.mcp_server_manager import MCPServer manager = MCPServerManager() monkeypatch.setattr(rest_endpoints, "global_mcp_server_manager", manager) @@ -1209,8 +1208,8 @@ class TestListToolsRestAPI: async def test_single_server_rate_limit_returns_429_without_fetching_tools( self, monkeypatch: pytest.MonkeyPatch ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager server: Final = MCPServer( server_id="rate-limited-server", @@ -1249,8 +1248,8 @@ class TestListToolsRestAPI: async def test_admin_unfiltered_tools_list_does_not_enforce_server_rpm( self, monkeypatch: pytest.MonkeyPatch ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import LitellmUserRoles + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager server: Final = MCPServer( server_id="admin-unfiltered-server", @@ -1404,7 +1403,7 @@ class TestListToolsRestAPI: return admitted_auth monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", fake_reload, ) @@ -1519,7 +1518,7 @@ class TestListToolsRestAPI: return ["toolset-tool-1"] monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", record_reload, ) monkeypatch.setattr( @@ -1573,9 +1572,9 @@ class TestListToolsRestAPI: ) from mcp.types import Tool as MCPTool - import litellm.experimental_mcp_client.client as mcp_client_module - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager - from litellm.proxy._experimental.mcp_server.server import MCPServer + import litellm.mcp_client.client as mcp_client_module + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport monkeypatch.setattr(rest_endpoints, "global_mcp_server_manager", MCPServerManager()) @@ -1766,7 +1765,7 @@ class TestListToolsRestAPI: """A single-server pass-through request whose upstream rejects the token must surface the upstream status (401 or 403) plus its WWW-Authenticate challenge, not collapse into a 200 ``unexpected_error`` body.""" - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) @@ -1835,10 +1834,10 @@ class TestListToolsRestAPI: """A single-server listing whose upstream breaks (5xx, timeout, unreachable) must answer with the truthful gateway status instead of masking the failure as an empty-success {"tools": [], "error": null} body a caller cannot distinguish from a toolless server.""" - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPServerListError, ) - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.mcp_server.faults.list_outcomes import ( ServerListFault, ) @@ -1897,7 +1896,7 @@ class TestListToolsRestAPI: caller can tell "needs upstream auth" apart from "has no tools".""" from pydantic import TypeAdapter - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) @@ -1971,7 +1970,7 @@ class TestListToolsRestAPI: async def test_name_resolution_finds_server_by_uuid(self, monkeypatch): """When server_id is a name string, it should be resolved to its UUID and used for the tools lookup when the UUID is in allowed_server_ids.""" - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport stub_server = MCPServer( @@ -2053,7 +2052,7 @@ class TestListToolsRestAPI: async def test_name_not_in_allowed_returns_access_denied(self, monkeypatch): """When name resolves to a server whose UUID is NOT in allowed_server_ids, the result should be an access_denied error (not a crash or silent pass).""" - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport stub_server = MCPServer( @@ -2109,7 +2108,7 @@ class TestListToolsRestAPI: async def test_mcp_server_name_query_param_resolves_to_server(self, monkeypatch): """mcp_server_name is a name-based alias for server_id: it should resolve to the matching server and scope the response to it.""" - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport stub_server = MCPServer( @@ -2189,8 +2188,8 @@ class TestListToolsRestAPI: assert result["error"] is None async def test_mcp_server_name_filter_uses_real_catalog_with_tool_search(self, monkeypatch): - from litellm.proxy._experimental.mcp_server.server import MCPServer from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport stub_server = MCPServer( @@ -2397,7 +2396,7 @@ class TestListToolsRestAPI: async def test_oauth2_user_token_injected_for_single_server(self, monkeypatch): """For a single-server OAuth2 request, _get_user_oauth_extra_headers is called and the returned headers are forwarded to _get_tools_for_single_server.""" - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport stub_server = MCPServer( @@ -2578,8 +2577,8 @@ class TestCallToolRestAPI: ) async def test_executes_tool_when_allowed(self, monkeypatch, tool_name, native_tool_name): import litellm - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler, MCPServerAccess - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler, MCPServerAccess + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async def fake_contexts(user_api_key_auth): return [user_api_key_auth] @@ -2713,9 +2712,9 @@ class TestCallToolRestAPI: ) -> None: import litellm from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable, LiteLLM_UserTable from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager target_server: Final = MCPServer( server_id="server-b", @@ -3141,7 +3140,7 @@ class TestCallToolRestAPI: MCPUpstreamAuthError) must reach the REST caller as that status with the upstream WWW-Authenticate preserved, so an MCP client can run the upstream OAuth flow, instead of the generic 500 the catch-all would otherwise produce.""" - from litellm.proxy._experimental.mcp_server.exceptions import MCPUpstreamAuthError + from litellm.proxy.mcp_server.exceptions import MCPUpstreamAuthError async def fake_contexts(user_api_key_auth): return [user_api_key_auth] @@ -3473,9 +3472,9 @@ class TestCallToolRestAPI: without the direct branch's relay wrapper, so an MCPUpstreamAuthError from it must be relayed by the endpoint-level handler (a real 401/403 + WWW-Authenticate) rather than falling through the catch-all into a generic 500.""" - import litellm.proxy._experimental.mcp_server.tool_search as tool_search_mod - from litellm.proxy._experimental.mcp_server.exceptions import MCPUpstreamAuthError + import litellm.proxy.mcp_server.tool_search as tool_search_mod from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server.exceptions import MCPUpstreamAuthError challenge = 'Bearer resource_metadata="https://gw.example.com/.well-known/oauth-protected-resource"' @@ -3587,9 +3586,9 @@ async def test_request_selected_tool_specific_guardrail_applies_to_virtual_execu import litellm from litellm.caching.caching import DualCache from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import mcp_server_manager, server, tool_registry from litellm.proxy._types import LiteLLM_ObjectPermissionTable from litellm.proxy.guardrails.guardrail_hooks.custom_code.custom_code_guardrail import CustomCodeGuardrail + from litellm.proxy.mcp_server import mcp_server_manager, server, tool_registry from litellm.proxy.utils import ProxyLogging guardrail: Final = CustomCodeGuardrail( @@ -3672,8 +3671,8 @@ class TestGetToolsForSingleServer: async def test_filters_tools_by_object_permission_mcp_tool_permissions(self, monkeypatch): """Test that tools are filtered by user_api_key_auth.object_permission.mcp_tool_permissions""" - from litellm.proxy._experimental.mcp_server.server import MCPServer from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport mock_tools = [ @@ -3728,7 +3727,7 @@ class TestGetToolsForSingleServer: async def test_no_filtering_when_object_permission_is_none(self, monkeypatch): """Test that all tools are returned when object_permission is None""" - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport mock_tools = [ @@ -3769,8 +3768,8 @@ class TestGetToolsForSingleServer: async def test_no_filtering_when_mcp_tool_permissions_is_none(self, monkeypatch): """Test that all tools are returned when mcp_tool_permissions is None""" - from litellm.proxy._experimental.mcp_server.server import MCPServer from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport mock_tools = [ @@ -3816,8 +3815,8 @@ class TestGetToolsForSingleServer: async def test_no_filtering_when_server_not_in_mcp_tool_permissions(self, monkeypatch): """Test that all tools are returned when server is not in mcp_tool_permissions""" - from litellm.proxy._experimental.mcp_server.server import MCPServer from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport mock_tools = [ @@ -3863,8 +3862,8 @@ class TestGetToolsForSingleServer: async def test_combines_server_allowed_tools_and_object_permission_filters(self, monkeypatch): """Test that both server.allowed_tools and object_permission.mcp_tool_permissions filters are applied""" - from litellm.proxy._experimental.mcp_server.server import MCPServer from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport mock_tools = [ @@ -3920,7 +3919,7 @@ class TestGetToolsForSingleServer: async def test_apply_tool_filters_false_returns_full_catalog(self, monkeypatch): """apply_tool_filters=False returns the raw catalog without the server allowed_tools gate, so the config UI can render disabled tools as off.""" - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport mock_tools = [ @@ -4188,7 +4187,7 @@ class TestPreviewOpenAPITools: } } - from litellm.proxy._experimental.mcp_server import ( + from litellm.proxy.mcp_server import ( openapi_to_mcp_generator, ) @@ -4228,7 +4227,7 @@ class TestPreviewOpenAPITools: suffixes (_2, _3, ...) get assigned to different operations and the dashboard shows names that differ from what's actually registered. """ - from litellm.proxy._experimental.mcp_server import ( + from litellm.proxy.mcp_server import ( openapi_to_mcp_generator, ) @@ -4577,7 +4576,7 @@ class TestToolResponseMcpInfoEnrichment: def test_enriches_mcp_info_with_alias_and_server_id(self): from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport server = MCPServer( @@ -4613,7 +4612,7 @@ class TestToolResponseMcpInfoEnrichment: def test_alias_none_is_explicit_in_mcp_info(self): from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport server = MCPServer( @@ -4678,10 +4677,10 @@ class TestRestListToolsetFiltering: from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport stub_server = MCPServer( @@ -4722,7 +4721,7 @@ class TestRestListToolsetFiltering: patch.object(MCPRequestHandler, "_get_key_object_permission", return_value=key_object_permission), patch.object(MCPRequestHandler, "_get_team_object_permission", AsyncMock(return_value=None)), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -4747,7 +4746,7 @@ class TestV1ResolvedOauth2Gate: @staticmethod def _oauth2_server(*, delegate_auth_to_upstream: bool) -> Any: - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport return MCPServer( @@ -4770,7 +4769,7 @@ class TestV1ResolvedOauth2Gate: async def test_user_oauth_headers_skip_v2_owned_servers( self, delegate_auth_to_upstream, expected_headers, expected_lookups, monkeypatch ): - from litellm.proxy._experimental.mcp_server import db as mcp_db + from litellm.proxy.mcp_server import db as mcp_db server = self._oauth2_server(delegate_auth_to_upstream=delegate_auth_to_upstream) resolve_token = AsyncMock(return_value={"access_token": "stored-token"}) @@ -4932,7 +4931,7 @@ class TestClientAllowlistOnRestRoutes: @pytest.mark.asyncio @pytest.mark.parametrize("revision", ("auto", "2024-11-05", "2025-06-18")) async def test_preview_client_honors_protocol_metadata(revision: MCPUpstreamProtocol) -> None: - from litellm.experimental_mcp_client.client import MCPClient + from litellm.mcp_client.client import MCPClient payload: Final = NewMCPServerRequest( server_name="preview", @@ -4970,9 +4969,9 @@ async def test_saved_preview_protocol_omission_and_explicit_edits( ) -> None: from starlette.datastructures import Headers - from litellm.experimental_mcp_client.client import MCPClient - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.mcp_client.client import MCPClient from litellm.proxy.management_endpoints import mcp_management_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager saved: Final = MCPServer( server_id="saved-preview", @@ -5037,7 +5036,7 @@ async def test_rest_guardrail_bearer_excludes_admission_key( import litellm from litellm.caching.dual_cache import DualCache from litellm.integrations.custom_logger import CustomLogger - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry observed: Final[asyncio.Queue[object]] = asyncio.Queue() diff --git a/tests/unit/proxy/_experimental/mcp_server/test_result_conversion.py b/tests/unit/proxy/mcp_server/test_result_conversion.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_result_conversion.py rename to tests/unit/proxy/mcp_server/test_result_conversion.py index 9926fa131ab..bbc35f11f32 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_result_conversion.py +++ b/tests/unit/proxy/mcp_server/test_result_conversion.py @@ -7,7 +7,7 @@ from mcp_types.methods import serialize_server_result from mcp_types.version import KNOWN_PROTOCOL_VERSIONS, MODERN_PROTOCOL_VERSIONS from pydantic import JsonValue, ValidationError -from litellm.proxy._experimental.mcp_server.result_conversion import ( +from litellm.proxy.mcp_server.result_conversion import ( INPUT_REQUIRED_UNSUPPORTED_MESSAGE, JsonResult, TextResult, @@ -246,7 +246,8 @@ class TestToGatewayTool: @pytest.mark.parametrize("elapsed,expected", [(0, 1000), (0.0001, 999), (0.5, 500), (1, 0), (2, 0), (-1, 1000)]) def test_freshness_aging_preserves_content_and_scope(elapsed: float, expected: int) -> None: from mcp.types import ListPromptsResult, Prompt - from litellm.proxy._experimental.mcp_server.result_conversion import age_freshness + + from litellm.proxy.mcp_server.result_conversion import age_freshness result: Final = ListPromptsResult(prompts=[Prompt(name="kept")], ttl_ms=1000, cache_scope="public") aged: Final = age_freshness(result, elapsed) @@ -263,7 +264,8 @@ def test_aggregate_freshness_never_broadens_sharing( scopes: tuple[Literal["private", "public"], ...], expected: str ) -> None: from mcp.types import CacheableResult - from litellm.proxy._experimental.mcp_server.result_conversion import aggregate_freshness + + from litellm.proxy.mcp_server.result_conversion import aggregate_freshness result: Final = aggregate_freshness(tuple(CacheableResult(ttl_ms=1000, cache_scope=scope) for scope in scopes)) assert result.cache_scope == expected diff --git a/tests/unit/proxy/_experimental/mcp_server/test_semantic_tool_filter.py b/tests/unit/proxy/mcp_server/test_semantic_tool_filter.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_semantic_tool_filter.py rename to tests/unit/proxy/mcp_server/test_semantic_tool_filter.py index f0b4e94f72f..c04323d7f7c 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_semantic_tool_filter.py +++ b/tests/unit/proxy/mcp_server/test_semantic_tool_filter.py @@ -17,7 +17,6 @@ if sys.version_info < (3, 11): # BaseExceptionGroup is a builtin only from 3.11 from mcp.types import Tool as MCPTool - requires_semantic_router = pytest.mark.skipif( sys.version_info >= (3, 14), reason="The semantic-router extra excludes Python 3.14" ) @@ -33,7 +32,7 @@ async def test_semantic_filter_basic_filtering(): When: Query is "send an email" Then: Email tools should rank higher than calendar tools """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) @@ -161,7 +160,7 @@ async def test_semantic_filter_top_k_limiting(): When: top_k=5 Then: Should return at most 5 tools """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) @@ -222,7 +221,7 @@ async def test_semantic_filter_disabled(): """ Test that when filter is disabled, all tools are returned. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) @@ -261,7 +260,7 @@ async def test_semantic_filter_empty_tools(): """ Test that filter handles empty tool list gracefully. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) @@ -289,7 +288,7 @@ async def test_semantic_filter_extract_user_query(): """ Test that user query extraction works correctly from messages. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) @@ -341,10 +340,10 @@ async def test_semantic_filter_hook_triggers_on_completion(): """ Test that the hook triggers for completion requests with tools. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook from litellm.types.utils import Embedding, EmbeddingResponse # Create mock filter @@ -420,10 +419,10 @@ async def test_semantic_filter_hook_skips_no_tools(): """ Test that the hook does NOT trigger when there are no tools. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook # Create mock filter mock_router = Mock() @@ -473,10 +472,10 @@ async def test_semantic_filter_hook_preserves_native_tools(): Then: The native tools must survive unconditionally, and only MCP tools go through the semantic filter. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook from litellm.types.utils import Embedding, EmbeddingResponse mock_router = Mock() @@ -605,10 +604,10 @@ async def test_semantic_filter_hook_all_native_tools(): Then: All tools pass through, and NO spurious semantic filter response headers are emitted (no litellm_semantic_filter_stats in metadata). """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook mock_router = Mock() filter_instance = SemanticMCPToolFilter( @@ -706,10 +705,10 @@ async def test_semantic_filter_hook_responses_api_name_collision(): Then: The native tool must NOT be sent to the semantic filter, even though its name matches an MCP canonical. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook from litellm.types.utils import Embedding, EmbeddingResponse mock_router = Mock() @@ -802,10 +801,10 @@ async def test_semantic_filter_hook_filters_expanded_litellm_proxy_tools(): were filtered out instead of silently forwarding all tools with no stats. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook from litellm.types.utils import Embedding, EmbeddingResponse mock_router = Mock() @@ -924,10 +923,10 @@ async def test_semantic_filter_hook_narrows_mcp_reference_for_chat_completions() reference also removed the marker the MCP gateway matches on, which disabled tool auto-execution for require_approval="never". """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook from litellm.types.utils import Embedding, EmbeddingResponse mock_router = Mock() @@ -1039,10 +1038,10 @@ async def test_semantic_filter_hook_zero_matches_exposes_all_tools_on_both_paths filter_tools to fail closed must fail this test on both paths at once, instead of silently hard-limiting one surface and not the other. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook from litellm.types.utils import Embedding, EmbeddingResponse mock_router = Mock() @@ -1148,10 +1147,10 @@ async def test_semantic_filter_hook_filters_expanded_tools_with_string_input(): expanded-tool filtering must treat it as the user query instead of crashing (which would silently disable MCP expansion). """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook from litellm.types.utils import Embedding, EmbeddingResponse mock_router = Mock() @@ -1218,10 +1217,10 @@ async def test_semantic_filter_hook_expansion_skips_filter_when_disabled(): stats, mirroring the generic path's enabled guard. The MCP gateway then expands the reference itself, so no tool is narrowed away. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook filter_instance = SemanticMCPToolFilter( embedding_model="text-embedding-3-small", @@ -1292,10 +1291,10 @@ async def test_semantic_filter_hook_preserves_tool_order(): Then: The output order must match the original request order, NOT native-first. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook from litellm.types.utils import Embedding, EmbeddingResponse mock_router = Mock() @@ -1402,7 +1401,7 @@ class TestGetToolsByNames: """ def _make_filter(self): - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) @@ -1572,10 +1571,10 @@ async def test_semantic_filter_headers_hook_emits_only_complete_tool_names(): contain complete tool names, in their original order, within the cap. """ from litellm.constants import MAX_MCP_SEMANTIC_FILTER_TOOLS_HEADER_LENGTH - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook filter_instance = SemanticMCPToolFilter( embedding_model="text-embedding-3-small", @@ -1654,7 +1653,7 @@ def _make_context_window_raising_router(state): def _make_context_window_filter(state, top_k: int = 3): - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) @@ -1675,7 +1674,7 @@ async def test_semantic_filter_fails_closed_on_query_time_context_window_error() user query must fail closed with a typed error instead of silently returning all tools (previously reported as N->N "success"). """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticToolFilterContextWindowError, ) @@ -1708,7 +1707,7 @@ async def test_semantic_filter_records_build_time_context_window_error(): the build, which previously left the hook unregistered and filtering silently disabled) and must fail subsequent filtering closed. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticToolFilterContextWindowError, ) @@ -1904,7 +1903,7 @@ def test_is_context_window_error_detection_variants(): generic error must not match. """ import litellm - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( _is_context_window_error, ) @@ -1941,7 +1940,7 @@ def test_is_context_window_error_sees_through_trees_the_chain_walk_missed(): ``__context__`` behind a non-matching ``__cause__``, buried inside an anyio-style ``ExceptionGroup``, and chained deeper than five links.""" import litellm - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( _is_context_window_error, ) @@ -2002,7 +2001,7 @@ def _make_keyword_embedding_router(recorded_inputs): def _make_keyword_filter(recorded_inputs, top_k: int = 3): - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) @@ -2128,7 +2127,7 @@ async def test_request_time_context_window_error_is_request_scoped(): which EVERY user's MCP requests on the worker were blocked with a 400 until restart (index poisoning via a single request). """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticToolFilterContextWindowError, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_server_resolution.py b/tests/unit/proxy/mcp_server/test_server_resolution.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_server_resolution.py rename to tests/unit/proxy/mcp_server/test_server_resolution.py index 4b9214916a8..4a5185a9410 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_server_resolution.py +++ b/tests/unit/proxy/mcp_server/test_server_resolution.py @@ -1,7 +1,6 @@ from __future__ import annotations import asyncio - from collections.abc import Awaitable, Callable, Mapping from dataclasses import dataclass from typing import Final, Literal @@ -10,16 +9,16 @@ from unittest.mock import Mock import pytest from fastapi import HTTPException -from litellm.proxy._experimental.mcp_server.contracts import TargetCatalog -from litellm.proxy._experimental.mcp_server.server_resolution import ( +from litellm.proxy._types import LiteLLM_MCPServerTable, LitellmUserRoles, UserAPIKeyAuth +from litellm.proxy.mcp_server.contracts import TargetCatalog +from litellm.proxy.mcp_server.server_resolution import ( MCPServerTargetCatalog, ResolutionSource, ResolvedMCPServer, authorize_mcp_server, resolve_mcp_server, ) -from litellm.proxy._experimental.mcp_server.ui_session_utils import can_access_mcp_server -from litellm.proxy._types import LiteLLM_MCPServerTable, LitellmUserRoles, UserAPIKeyAuth +from litellm.proxy.mcp_server.ui_session_utils import can_access_mcp_server from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -342,7 +341,7 @@ async def test_authorize_uses_real_access_helper_for_canonical_id( return await can_access_mcp_server(user_api_key_auth, requested_server_id, allowed_servers) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.server_resolution.can_access_mcp_server", + "litellm.proxy.mcp_server.server_resolution.can_access_mcp_server", spy_access, ) if expected_status is None: @@ -559,9 +558,9 @@ async def test_target_catalog_does_not_reuse_admin_authorization_for_another_cal async def test_catalog_without_listing_dependency_fails_explicitly(): from mcp.types import ListToolsRequest - from litellm.proxy._experimental.mcp_server.contracts import OperationContext - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager - from litellm.proxy._experimental.mcp_server.server_resolution import MCPServerTargetCatalog + from litellm.proxy.mcp_server.contracts import OperationContext + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.server_resolution import MCPServerTargetCatalog catalog = MCPServerTargetCatalog(MCPServerManager()) with pytest.raises(RuntimeError, match="listing dependency"): diff --git a/tests/unit/proxy/_experimental/mcp_server/test_short_mcp_tool_prefix.py b/tests/unit/proxy/mcp_server/test_short_mcp_tool_prefix.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_short_mcp_tool_prefix.py rename to tests/unit/proxy/mcp_server/test_short_mcp_tool_prefix.py index 7b6007c405e..89342d5a0f7 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_short_mcp_tool_prefix.py +++ b/tests/unit/proxy/mcp_server/test_short_mcp_tool_prefix.py @@ -13,8 +13,8 @@ from typing import List import pytest from mcp.types import Tool as MCPTool -from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager -from litellm.proxy._experimental.mcp_server.utils import ( +from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager +from litellm.proxy.mcp_server.utils import ( SHORT_MCP_TOOL_PREFIX_LENGTH, add_server_prefix_to_name, compute_short_server_prefix, @@ -359,7 +359,7 @@ class TestShortPrefixCollisionResolution: assert server.short_prefix is None def test_assigns_natural_hash_when_no_collision(self, monkeypatch): - from litellm.proxy._experimental.mcp_server import utils as mcp_utils + from litellm.proxy.mcp_server import utils as mcp_utils monkeypatch.setenv("LITELLM_USE_SHORT_MCP_TOOL_PREFIX", "true") manager = MCPServerManager() @@ -375,14 +375,14 @@ class TestShortPrefixCollisionResolution: # Force every attempt=0 hash to "AAA" and attempt=1 to "AAB". # That way the second server registered must rehash to "AAB". - from litellm.proxy._experimental.mcp_server import utils as mcp_utils + from litellm.proxy.mcp_server import utils as mcp_utils def _fake_hash(server_id: str, attempt: int = 0) -> str: return "AAA" if attempt == 0 else f"AA{chr(ord('A') + attempt)}" monkeypatch.setattr(mcp_utils, "compute_short_server_prefix", _fake_hash) # Also patch the symbol that the manager imported at module load. - from litellm.proxy._experimental.mcp_server import ( + from litellm.proxy.mcp_server import ( mcp_server_manager as mgr_module, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_state_tokens.py b/tests/unit/proxy/mcp_server/test_state_tokens.py similarity index 95% rename from tests/unit/proxy/_experimental/mcp_server/test_state_tokens.py rename to tests/unit/proxy/mcp_server/test_state_tokens.py index b3fc5a89526..fd121e79209 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_state_tokens.py +++ b/tests/unit/proxy/mcp_server/test_state_tokens.py @@ -3,8 +3,8 @@ from typing import Final import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error, Ok -from litellm.proxy._experimental.mcp_server.state_tokens import StateTokenError, open_state, seal_state +from litellm.proxy.mcp_server.outbound_credentials.result import Error, Ok +from litellm.proxy.mcp_server.state_tokens import StateTokenError, open_state, seal_state @pytest.fixture(autouse=True) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_subscriptions.py b/tests/unit/proxy/mcp_server/test_subscriptions.py similarity index 95% rename from tests/unit/proxy/_experimental/mcp_server/test_subscriptions.py rename to tests/unit/proxy/mcp_server/test_subscriptions.py index fadb709e00f..721955a51b8 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_subscriptions.py +++ b/tests/unit/proxy/mcp_server/test_subscriptions.py @@ -12,10 +12,10 @@ from mcp.server.subscriptions import ListenHandler from mcp.shared.subscriptions import PromptsListChanged, ToolsListChanged from mcp.types import ListToolsRequest, ListToolsResult, SubscriptionFilter, SubscriptionsListenRequestParams -from litellm.experimental_mcp_client.client import MCPClient -from litellm.proxy._experimental.mcp_server import subscriptions -from litellm.proxy._experimental.mcp_server.contracts import OperationContext +from litellm.mcp_client.client import MCPClient from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server import subscriptions +from litellm.proxy.mcp_server.contracts import OperationContext from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -181,7 +181,7 @@ async def test_listener_limits_release_capacity_after_cancellation(second_owner: @pytest.mark.asyncio @pytest.mark.parametrize("proxy_mode", [False, True]) async def test_subscription_requires_a_supported_http_gateway_route(proxy_mode: bool) -> None: - from litellm.proxy._experimental.mcp_server import server + from litellm.proxy.mcp_server import server token = server._mcp_proxy_mode.set(proxy_mode) try: @@ -206,7 +206,7 @@ async def test_subscription_requires_a_supported_http_gateway_route(proxy_mode: async def test_subscription_authorization_preserves_original_caller(changed: str | None) -> None: from dataclasses import replace - from litellm.proxy._experimental.mcp_server.server import _owner_fingerprint_for + from litellm.proxy.mcp_server.server import _owner_fingerprint_for initial = OperationContext(_caller=UserAPIKeyAuth(api_key="first", user_id="alice", team_id="team")) current = replace( @@ -341,7 +341,7 @@ async def test_legacy_upstream_without_capabilities_does_not_receive_subscribe() @pytest.mark.parametrize("proxy_mode", [False, True]) def test_legacy_notification_capabilities_require_a_notification_route(proxy_mode: bool) -> None: - from litellm.proxy._experimental.mcp_server import server + from litellm.proxy.mcp_server import server token = server._mcp_proxy_mode.set(proxy_mode) try: @@ -375,7 +375,7 @@ async def test_idle_legacy_listener_detects_closed_upstream_without_restarting_w async def test_proxy_route_rejects_legacy_resource_subscription_before_setup(method: str) -> None: from mcp.types import SubscribeRequestParams, UnsubscribeRequestParams - from litellm.proxy._experimental.mcp_server import server + from litellm.proxy.mcp_server import server params = (SubscribeRequestParams if method == "subscribe_resource" else UnsubscribeRequestParams)(uri="test://value") token = server._mcp_proxy_mode.set(True) @@ -394,7 +394,7 @@ async def test_proxy_route_rejects_legacy_resource_subscription_before_setup(met async def test_only_client_initiated_listeners_consume_server_rate_limit( monkeypatch: pytest.MonkeyPatch, client_requests: tuple[str, ...], tools_list_admitted: bool ) -> None: - from litellm.proxy._experimental.mcp_server import operations + from litellm.proxy.mcp_server import operations allow_one_request(monkeypatch, "alice", "upstream") opened: Final = asyncio.Queue[None]() @@ -447,8 +447,8 @@ async def test_legacy_listener_catalog_refreshes_do_not_consume_server_rate_limi from mcp.types import ListToolsResult, ServerCapabilities, Tool, ToolsCapability from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import catalog, operations - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ServerListOk + from litellm.proxy.mcp_server import catalog, operations + from litellm.proxy.mcp_server.faults.list_outcomes import ServerListOk server: Final = MCPServer(server_id="list-changed", name="list-changed", transport=MCPTransport.http) caller: Final = UserAPIKeyAuth(api_key="list-changed-key", user_id="alice") @@ -502,12 +502,12 @@ async def test_legacy_listener_catalog_refreshes_do_not_consume_server_rate_limi @pytest.mark.asyncio async def test_all_failed_tools_listing_keeps_empty_catalog_digest(monkeypatch: pytest.MonkeyPatch) -> None: - from litellm.proxy._experimental.mcp_server.catalog import ToolListingFailedOutright + from litellm.proxy.mcp_server.catalog import ToolListingFailedOutright listener_context: Final = OperationContext(_caller=UserAPIKeyAuth(user_id="listener")) empty_gateway: Final = _ListingGateway(result=ListToolsResult(tools=[])) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.operations.GatewayOperations", lambda: empty_gateway + "litellm.proxy.mcp_server.operations.GatewayOperations", lambda: empty_gateway ) empty_digest: Final = await subscriptions._listing(ToolsListChanged(), listener_context) @@ -515,7 +515,7 @@ async def test_all_failed_tools_listing_keeps_empty_catalog_digest(monkeypatch: error=ToolListingFailedOutright(code=-32603, message="Every MCP server in scope failed") ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.operations.GatewayOperations", lambda: failed_gateway + "litellm.proxy.mcp_server.operations.GatewayOperations", lambda: failed_gateway ) failed_digest: Final = await subscriptions._listing(ToolsListChanged(), listener_context) @@ -526,7 +526,7 @@ async def test_all_failed_tools_listing_keeps_empty_catalog_digest(monkeypatch: async def test_tools_listing_propagates_other_mcp_errors(monkeypatch: pytest.MonkeyPatch) -> None: failure: Final = MCPError(code=-32602, message="Bad cursor") gateway: Final = _ListingGateway(error=failure) - monkeypatch.setattr("litellm.proxy._experimental.mcp_server.operations.GatewayOperations", lambda: gateway) + monkeypatch.setattr("litellm.proxy.mcp_server.operations.GatewayOperations", lambda: gateway) listener_context: Final = OperationContext(_caller=UserAPIKeyAuth(user_id="listener")) expected_error: Final = pytest.raises(MCPError) diff --git a/tests/unit/proxy/experimental/mcp_server/test_tool_registry.py b/tests/unit/proxy/mcp_server/test_tool_registry.py similarity index 92% rename from tests/unit/proxy/experimental/mcp_server/test_tool_registry.py rename to tests/unit/proxy/mcp_server/test_tool_registry.py index c7df359aae2..d05204b8e64 100644 --- a/tests/unit/proxy/experimental/mcp_server/test_tool_registry.py +++ b/tests/unit/proxy/mcp_server/test_tool_registry.py @@ -2,8 +2,7 @@ import json import pytest - -from litellm.proxy._experimental.mcp_server.tool_registry import MCPToolRegistry +from litellm.proxy.mcp_server.tool_registry import MCPToolRegistry # Test handler function @@ -59,7 +58,7 @@ def test_load_tools_from_config(): "name": "config_tool", "description": "A tool from config", "input_schema": {"type": "object"}, - "handler": "tests.unit.proxy.experimental.mcp_server.test_tool_registry.example_handler", + "handler": "tests.unit.proxy.mcp_server.test_tool_registry.example_handler", } ] diff --git a/tests/unit/proxy/_experimental/mcp_server/test_ui_session_utils.py b/tests/unit/proxy/mcp_server/test_ui_session_utils.py similarity index 91% rename from tests/unit/proxy/_experimental/mcp_server/test_ui_session_utils.py rename to tests/unit/proxy/mcp_server/test_ui_session_utils.py index 293d9443ced..55adbf19ffe 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_ui_session_utils.py +++ b/tests/unit/proxy/mcp_server/test_ui_session_utils.py @@ -6,14 +6,14 @@ import pytest from fastapi import HTTPException from litellm.constants import UI_SESSION_TOKEN_TEAM_ID -from litellm.proxy._experimental.mcp_server.ui_session_utils import ( +from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth +from litellm.proxy.mcp_server.ui_session_utils import ( build_effective_auth_contexts, clone_user_api_key_auth_with_team, granted_toolset_ids, - toolset_grant_contexts, resolve_ui_session_team_ids, + toolset_grant_contexts, ) -from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth def test_clone_user_api_key_auth_with_team_creates_independent_copy(): @@ -68,7 +68,7 @@ async def test_build_effective_auth_contexts_returns_cloned_contexts(monkeypatch mock_resolve = AsyncMock(return_value=["team-one", "team-two"]) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.ui_session_utils.resolve_ui_session_team_ids", + "litellm.proxy.mcp_server.ui_session_utils.resolve_ui_session_team_ids", mock_resolve, ) @@ -87,7 +87,7 @@ async def test_build_effective_auth_contexts_returns_original_when_no_resolution mock_resolve = AsyncMock(return_value=[]) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.ui_session_utils.resolve_ui_session_team_ids", + "litellm.proxy.mcp_server.ui_session_utils.resolve_ui_session_team_ids", mock_resolve, ) @@ -114,7 +114,7 @@ async def test_build_effective_auth_contexts_handles_unpicklable_parent_span( mock_resolve = AsyncMock(return_value=["team-span"]) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.ui_session_utils.resolve_ui_session_team_ids", + "litellm.proxy.mcp_server.ui_session_utils.resolve_ui_session_team_ids", mock_resolve, ) @@ -133,12 +133,12 @@ async def test_build_effective_auth_contexts_appends_admitted_user_context(monke admitted_auth = UserAPIKeyAuth(user_id="user-42") monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.ui_session_utils.resolve_ui_session_team_ids", + "litellm.proxy.mcp_server.ui_session_utils.resolve_ui_session_team_ids", AsyncMock(return_value=["team-one"]), ) reload_mock = AsyncMock(return_value=admitted_auth) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", reload_mock, ) @@ -154,7 +154,7 @@ async def test_build_effective_auth_contexts_never_widens_caller_passed_keys(mon normal_user = UserAPIKeyAuth(team_id="regular-team", user_id="user-1") reload_mock = AsyncMock() monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", reload_mock, ) @@ -169,11 +169,11 @@ async def test_build_effective_auth_contexts_survives_admitted_reload_failure(mo user_auth = UserAPIKeyAuth(team_id=UI_SESSION_TOKEN_TEAM_ID, user_id="user-9") monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.ui_session_utils.resolve_ui_session_team_ids", + "litellm.proxy.mcp_server.ui_session_utils.resolve_ui_session_team_ids", AsyncMock(return_value=["team-a"]), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", AsyncMock(side_effect=HTTPException(status_code=503, detail="db down")), ) @@ -186,13 +186,13 @@ async def test_build_effective_auth_contexts_survives_admitted_reload_failure(mo async def test_acting_user_auth_returns_admitted_subject_for_non_admin_sessions(monkeypatch): """LIT-4861: acting-as-user MCP routes must resolve a non-admin dashboard session as the admitted subject so tool ceilings, reachability, and limits bind exactly as on /mcp.""" - from litellm.proxy._experimental.mcp_server.ui_session_utils import acting_user_auth + from litellm.proxy.mcp_server.ui_session_utils import acting_user_auth user_auth = UserAPIKeyAuth(team_id=UI_SESSION_TOKEN_TEAM_ID, user_id="user-42", user_role="internal_user") admitted_auth = UserAPIKeyAuth(user_id="user-42") reload_mock = AsyncMock(return_value=admitted_auth) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", reload_mock, ) @@ -204,11 +204,11 @@ async def test_acting_user_auth_returns_admitted_subject_for_non_admin_sessions( @pytest.mark.asyncio async def test_acting_user_auth_keeps_admin_sessions_and_passed_keys_unchanged(monkeypatch): - from litellm.proxy._experimental.mcp_server.ui_session_utils import acting_user_auth + from litellm.proxy.mcp_server.ui_session_utils import acting_user_auth reload_mock = AsyncMock() monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", reload_mock, ) @@ -223,11 +223,11 @@ async def test_acting_user_auth_keeps_admin_sessions_and_passed_keys_unchanged(m @pytest.mark.asyncio async def test_acting_user_auth_falls_back_to_session_auth_on_reload_failure(monkeypatch): - from litellm.proxy._experimental.mcp_server.ui_session_utils import acting_user_auth + from litellm.proxy.mcp_server.ui_session_utils import acting_user_auth user_auth = UserAPIKeyAuth(team_id=UI_SESSION_TOKEN_TEAM_ID, user_id="user-9", user_role="internal_user") monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", AsyncMock(side_effect=HTTPException(status_code=503, detail="db down")), ) @@ -239,7 +239,7 @@ async def test_admitted_user_context_carries_the_request_span(monkeypatch): """Swapping the principal must not drop the request: the admitted subject is rebuilt from the user row and carries no span of its own, so every consumer would otherwise lose trace linkage for the resolution and logging it drives.""" - from litellm.proxy._experimental.mcp_server.ui_session_utils import acting_user_auth + from litellm.proxy.mcp_server.ui_session_utils import acting_user_auth class DummySpan: def __init__(self) -> None: @@ -253,7 +253,7 @@ async def test_admitted_user_context_carries_the_request_span(monkeypatch): parent_otel_span=parent_span, ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", AsyncMock(return_value=UserAPIKeyAuth(user_id="user-42")), ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_utils.py b/tests/unit/proxy/mcp_server/test_utils.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_utils.py rename to tests/unit/proxy/mcp_server/test_utils.py index 8d10219796b..00af79cd860 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_utils.py +++ b/tests/unit/proxy/mcp_server/test_utils.py @@ -3,14 +3,14 @@ from unittest.mock import patch import pytest from fastapi import HTTPException -from litellm.proxy._experimental.mcp_server.utils import ( - upstream_credential_headers, +from litellm.proxy._types import NewMCPServerRequest +from litellm.proxy.mcp_server.utils import ( build_synthetic_mcp_request, logging_safe_mcp_headers, + upstream_credential_headers, validate_and_normalize_mcp_server_payload, validate_tool_display_names, ) -from litellm.proxy._types import NewMCPServerRequest from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -26,7 +26,7 @@ def _server_forwarding(*header_names: str) -> MCPServer: def _configured_servers(*servers: MCPServer): return patch.dict( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager.config_mcp_servers", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager.config_mcp_servers", {server.server_id: server for server in servers}, clear=False, ) @@ -273,7 +273,7 @@ class TestBuildSyntheticMcpRequest: @pytest.mark.parametrize("field", ["structuredContent", "structured_content"]) def test_structured_content_redaction_updates_shared_dictionary(field): - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( mcp_tool_result_structured_content, set_mcp_tool_result_structured_content, ) diff --git a/tests/unit/proxy/openai_files_endpoint/test_storage_backend_service.py b/tests/unit/proxy/openai_files_endpoint/test_storage_backend_service.py index 81c5803da33..09104c035c7 100644 --- a/tests/unit/proxy/openai_files_endpoint/test_storage_backend_service.py +++ b/tests/unit/proxy/openai_files_endpoint/test_storage_backend_service.py @@ -1,3 +1,4 @@ +from typing import Final from unittest.mock import MagicMock import pytest @@ -27,10 +28,7 @@ class _RecordingStorageBackend: raise self.delete_error -class _FakeManagedFilesHook(BaseFileEndpoints): - def __init__(self): - self.stored = [] - +class _ManagedFilesEndpoints(BaseFileEndpoints): async def acreate_file( self, create_file_request, llm_router, target_model_names_list, litellm_parent_otel_span, user_api_key_dict ): @@ -48,10 +46,23 @@ class _FakeManagedFilesHook(BaseFileEndpoints): async def afile_content(self, file_id, litellm_parent_otel_span, llm_router, **data): raise NotImplementedError + +class _FakeManagedFilesHook(_ManagedFilesEndpoints): + def __init__(self): + self.stored = [] + async def store_unified_file_id(self, **kwargs): self.stored.append(kwargs) +class _ForwardingManagedFilesHook(_ManagedFilesEndpoints): + def __init__(self, writer: _FakeManagedFilesHook): + self._writer = writer + + def __getattr__(self, name: str) -> object: + return getattr(self._writer, name) + + class _FailingManagedFilesHook(_FakeManagedFilesHook): async def store_unified_file_id(self, **kwargs): raise RuntimeError("db down") @@ -142,6 +153,24 @@ async def test_upload_with_target_model_names_and_hook_stores_unified_id(monkeyp } +@pytest.mark.asyncio +async def test_upload_stores_the_unified_id_through_a_hook_that_forwards_its_writer(monkeypatch): + backend: Final = _RecordingStorageBackend() + monkeypatch.setattr(storage_backend_service, "get_storage_backend", lambda name, prisma_client=None: backend) + writer: Final = _FakeManagedFilesHook() + + file_object: Final = await StorageBackendFileService.upload_file_to_storage_backend( + file_data=_file_data(), + target_storage="azure_storage", + target_model_names=["gpt-x"], + purpose="batch", + proxy_logging_obj=_FakeProxyLogging(hook=_ForwardingManagedFilesHook(writer)), + user_api_key_dict=UserAPIKeyAuth(api_key="sk-test"), + ) + + assert [stored["file_id"] for stored in writer.stored] == [file_object.id] + + @pytest.mark.asyncio async def test_upload_hands_the_prisma_client_to_the_storage_backend_factory(monkeypatch: pytest.MonkeyPatch): backend = _RecordingStorageBackend() diff --git a/tests/unit/proxy/pass_through_endpoints/llm_provider_handlers/test_anthropic_passthrough_logging_handler.py b/tests/unit/proxy/pass_through_endpoints/llm_provider_handlers/test_anthropic_passthrough_logging_handler.py index cc701e1ebd4..e09a179eadf 100644 --- a/tests/unit/proxy/pass_through_endpoints/llm_provider_handlers/test_anthropic_passthrough_logging_handler.py +++ b/tests/unit/proxy/pass_through_endpoints/llm_provider_handlers/test_anthropic_passthrough_logging_handler.py @@ -1,7 +1,7 @@ import asyncio import json from datetime import datetime -from typing import Any, Dict, Final, List +from typing import Final from unittest.mock import AsyncMock, MagicMock, Mock, patch import httpx @@ -11,7 +11,7 @@ from pydantic import ValidationError import litellm from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj -from litellm.llms.anthropic.pass_through.stream_assembly import extract_sse_data +from litellm.llms.anthropic.messages.stream_assembly import extract_sse_data from litellm.proxy.pass_through_endpoints.llm_provider_handlers.anthropic_passthrough_logging_handler import ( AnthropicPassthroughLoggingHandler, ) @@ -145,9 +145,7 @@ class TestAnthropicLoggingHandlerModelFallback: '{"type": "message_stop"}', ] - def _create_mock_logging_obj( - self, model_in_details: str = None - ) -> LiteLLMLoggingObj: + def _create_mock_logging_obj(self, model_in_details: str = None) -> LiteLLMLoggingObj: """Create a mock logging object with optional model in model_call_details""" mock_logging_obj = MagicMock() @@ -166,21 +164,13 @@ class TestAnthropicLoggingHandlerModelFallback: mock_handler = MagicMock() return mock_handler - @patch.object( - AnthropicPassthroughLoggingHandler, "build_complete_streaming_response" - ) - @patch.object( - AnthropicPassthroughLoggingHandler, "_create_anthropic_response_logging_payload" - ) - def test_model_from_request_body_used_when_present( - self, mock_create_payload, mock_build_response - ): + @patch.object(AnthropicPassthroughLoggingHandler, "build_complete_streaming_response") + @patch.object(AnthropicPassthroughLoggingHandler, "_create_anthropic_response_logging_payload") + def test_model_from_request_body_used_when_present(self, mock_create_payload, mock_build_response): """Test that model from request_body is used when present""" # Arrange request_body = {"model": "claude-3-sonnet-20240229"} - logging_obj = self._create_mock_logging_obj( - model_in_details="claude-3-haiku-20240307" - ) + logging_obj = self._create_mock_logging_obj(model_in_details="claude-3-haiku-20240307") passthrough_handler = self._create_mock_passthrough_handler() # Mock successful response building @@ -204,57 +194,37 @@ class TestAnthropicLoggingHandlerModelFallback: # Verify that _build_complete_streaming_response was called with the request_body model mock_build_response.assert_called_once() call_args = mock_build_response.call_args - assert ( - call_args[1]["model"] == "claude-3-sonnet-20240229" - ) # Should use request_body model + assert call_args[1]["model"] == "claude-3-sonnet-20240229" # Should use request_body model def test_model_fallback_logic_isolated(self): """Test just the model fallback logic in isolation""" # Test case 1: Model from request body request_body = {"model": "claude-3-sonnet-20240229"} - logging_obj = self._create_mock_logging_obj( - model_in_details="claude-3-haiku-20240307" - ) + logging_obj = self._create_mock_logging_obj(model_in_details="claude-3-haiku-20240307") # Extract the logic directly from the function model = request_body.get("model", "") - if ( - not model - and hasattr(logging_obj, "model_call_details") - and logging_obj.model_call_details.get("model") - ): + if not model and hasattr(logging_obj, "model_call_details") and logging_obj.model_call_details.get("model"): model = logging_obj.model_call_details.get("model") assert model == "claude-3-sonnet-20240229" # Should use request_body model # Test case 2: Fallback to logging obj request_body = {} - logging_obj = self._create_mock_logging_obj( - model_in_details="claude-3-haiku-20240307" - ) + logging_obj = self._create_mock_logging_obj(model_in_details="claude-3-haiku-20240307") model = request_body.get("model", "") - if ( - not model - and hasattr(logging_obj, "model_call_details") - and logging_obj.model_call_details.get("model") - ): + if not model and hasattr(logging_obj, "model_call_details") and logging_obj.model_call_details.get("model"): model = logging_obj.model_call_details.get("model") assert model == "claude-3-haiku-20240307" # Should use fallback model # Test case 3: Empty string in request body, fallback to logging obj request_body = {"model": ""} - logging_obj = self._create_mock_logging_obj( - model_in_details="claude-3-opus-20240229" - ) + logging_obj = self._create_mock_logging_obj(model_in_details="claude-3-opus-20240229") model = request_body.get("model", "") - if ( - not model - and hasattr(logging_obj, "model_call_details") - and logging_obj.model_call_details.get("model") - ): + if not model and hasattr(logging_obj, "model_call_details") and logging_obj.model_call_details.get("model"): model = logging_obj.model_call_details.get("model") assert model == "claude-3-opus-20240229" # Should use fallback model @@ -264,11 +234,7 @@ class TestAnthropicLoggingHandlerModelFallback: logging_obj = self._create_mock_logging_obj() model = request_body.get("model", "") - if ( - not model - and hasattr(logging_obj, "model_call_details") - and logging_obj.model_call_details.get("model") - ): + if not model and hasattr(logging_obj, "model_call_details") and logging_obj.model_call_details.get("model"): model = logging_obj.model_call_details.get("model") assert model == "" # Should be empty @@ -284,11 +250,7 @@ class TestAnthropicLoggingHandlerModelFallback: # Extract the logic directly from the function model = request_body.get("model", "") - if ( - not model - and hasattr(logging_obj, "model_call_details") - and logging_obj.model_call_details.get("model") - ): + if not model and hasattr(logging_obj, "model_call_details") and logging_obj.model_call_details.get("model"): model = logging_obj.model_call_details.get("model") assert model == "" # Should remain empty since no fallback available @@ -298,11 +260,7 @@ class TestAnthropicLoggingHandlerModelFallback: logging_obj = self._create_mock_logging_obj() # Empty dict model = request_body.get("model", "") - if ( - not model - and hasattr(logging_obj, "model_call_details") - and logging_obj.model_call_details.get("model") - ): + if not model and hasattr(logging_obj, "model_call_details") and logging_obj.model_call_details.get("model"): model = logging_obj.model_call_details.get("model") assert model == "" # Should remain empty @@ -311,9 +269,7 @@ class TestAnthropicLoggingHandlerModelFallback: class TestAzureAnthropicCostCalculation: """Test the custom_llm_provider cost calculation logic for Azure AI Anthropic.""" - def _create_mock_logging_obj( - self, model: str = None, custom_llm_provider: str = None - ) -> LiteLLMLoggingObj: + def _create_mock_logging_obj(self, model: str = None, custom_llm_provider: str = None) -> LiteLLMLoggingObj: """Create a mock logging object with optional model and custom_llm_provider""" mock_logging_obj = MagicMock() mock_model_call_details = {} @@ -326,13 +282,12 @@ class TestAzureAnthropicCostCalculation: return mock_logging_obj @patch("litellm.completion_cost") - def test_cost_calculation_with_azure_ai_custom_llm_provider( - self, mock_completion_cost - ): + def test_cost_calculation_with_azure_ai_custom_llm_provider(self, mock_completion_cost): """Test that custom_llm_provider is passed to completion_cost for Azure AI Anthropic""" - from litellm.types.utils import ModelResponse from datetime import datetime + from litellm.types.utils import ModelResponse + mock_completion_cost.return_value = 0.001 logging_obj = self._create_mock_logging_obj( @@ -365,9 +320,10 @@ class TestAzureAnthropicCostCalculation: @patch("litellm.completion_cost") def test_cost_calculation_without_custom_llm_provider(self, mock_completion_cost): """Test that cost calculation works without custom_llm_provider (standard Anthropic)""" - from litellm.types.utils import ModelResponse from datetime import datetime + from litellm.types.utils import ModelResponse + mock_completion_cost.return_value = 0.001 # No custom_llm_provider in model_call_details @@ -397,13 +353,12 @@ class TestAzureAnthropicCostCalculation: assert call_kwargs["custom_llm_provider"] is None @patch("litellm.completion_cost") - def test_cost_calculation_does_not_duplicate_provider_prefix( - self, mock_completion_cost - ): + def test_cost_calculation_does_not_duplicate_provider_prefix(self, mock_completion_cost): """Test that provider prefix is not duplicated if already present in model name""" - from litellm.types.utils import ModelResponse from datetime import datetime + from litellm.types.utils import ModelResponse + mock_completion_cost.return_value = 0.001 logging_obj = self._create_mock_logging_obj( @@ -436,9 +391,7 @@ class TestAzureAnthropicCostCalculation: assert call_kwargs["custom_llm_provider"] == "azure_ai" @patch("litellm.completion_cost") - def test_cost_calculation_resolves_unknown_model_from_litellm_params( - self, mock_completion_cost - ): + def test_cost_calculation_resolves_unknown_model_from_litellm_params(self, mock_completion_cost): """When the body model is the "unknown" sentinel, the deployment model from litellm_params must be used for costing, not "unknown" (which makes completion_cost raise and the cost silently fall back to $0).""" @@ -451,9 +404,7 @@ class TestAzureAnthropicCostCalculation: logging_obj = self._create_mock_logging_obj(model="unknown") logging_obj.model_call_details["litellm_params"] = { "model": "anthropic/claude-3-5-haiku-20241022", - "metadata": { - "model_group": "passthrough/anthropic/claude-3-5-haiku-20241022" - }, + "metadata": {"model_group": "passthrough/anthropic/claude-3-5-haiku-20241022"}, } logging_obj.litellm_params = logging_obj.model_call_details["litellm_params"] @@ -471,17 +422,12 @@ class TestAzureAnthropicCostCalculation: ) mock_completion_cost.assert_called_once() - assert ( - mock_completion_cost.call_args[1]["model"] - == "anthropic/claude-3-5-haiku-20241022" - ) + assert mock_completion_cost.call_args[1]["model"] == "anthropic/claude-3-5-haiku-20241022" assert kwargs["response_cost"] == 0.001 assert kwargs["model"] == "anthropic/claude-3-5-haiku-20241022" @patch("litellm.completion_cost") - def test_cost_calculation_resolves_unknown_model_from_model_group( - self, mock_completion_cost - ): + def test_cost_calculation_resolves_unknown_model_from_model_group(self, mock_completion_cost): """With only model_group available (no deployment litellm_params.model), the leading passthrough/ prefix must be stripped so the cost map can resolve the model.""" @@ -493,9 +439,7 @@ class TestAzureAnthropicCostCalculation: logging_obj = self._create_mock_logging_obj(model="unknown") logging_obj.model_call_details["litellm_params"] = { - "metadata": { - "model_group": "passthrough/anthropic/claude-3-5-haiku-20241022" - } + "metadata": {"model_group": "passthrough/anthropic/claude-3-5-haiku-20241022"} } logging_obj.litellm_params = logging_obj.model_call_details["litellm_params"] @@ -513,16 +457,11 @@ class TestAzureAnthropicCostCalculation: ) mock_completion_cost.assert_called_once() - assert ( - mock_completion_cost.call_args[1]["model"] - == "anthropic/claude-3-5-haiku-20241022" - ) + assert mock_completion_cost.call_args[1]["model"] == "anthropic/claude-3-5-haiku-20241022" assert kwargs["response_cost"] == 0.002 @patch("litellm.completion_cost") - def test_cost_calculation_skips_unknown_litellm_params_model_for_model_group( - self, mock_completion_cost - ): + def test_cost_calculation_skips_unknown_litellm_params_model_for_model_group(self, mock_completion_cost): """When litellm_params.model is itself the "unknown" sentinel, the deployment-model branch must not short-circuit; resolution falls through to model_group so costing still prices the real model instead of "unknown".""" @@ -535,9 +474,7 @@ class TestAzureAnthropicCostCalculation: logging_obj = self._create_mock_logging_obj(model="unknown") logging_obj.model_call_details["litellm_params"] = { "model": "unknown", - "metadata": { - "model_group": "passthrough/anthropic/claude-3-5-haiku-20241022" - }, + "metadata": {"model_group": "passthrough/anthropic/claude-3-5-haiku-20241022"}, } logging_obj.litellm_params = logging_obj.model_call_details["litellm_params"] @@ -555,17 +492,12 @@ class TestAzureAnthropicCostCalculation: ) mock_completion_cost.assert_called_once() - assert ( - mock_completion_cost.call_args[1]["model"] - == "anthropic/claude-3-5-haiku-20241022" - ) + assert mock_completion_cost.call_args[1]["model"] == "anthropic/claude-3-5-haiku-20241022" assert kwargs["response_cost"] == 0.003 assert kwargs["model"] == "anthropic/claude-3-5-haiku-20241022" @patch("litellm.completion_cost") - def test_streaming_cost_calculation_resolves_model_from_message_start_chunk( - self, mock_completion_cost - ): + def test_streaming_cost_calculation_resolves_model_from_message_start_chunk(self, mock_completion_cost): """On the bare /anthropic passthrough path litellm_params carries no model or model_group and the body model is the "unknown" sentinel; the model must be recovered from the message_start SSE event so completion_cost @@ -628,9 +560,7 @@ class TestAzureAnthropicCostCalculation: ), _sse("message_stop", {"type": "message_stop"}), ] - all_chunks = list( - PassThroughStreamingHandler._convert_raw_bytes_to_str_lines(frames) - ) + all_chunks = list(PassThroughStreamingHandler._convert_raw_bytes_to_str_lines(frames)) logging_obj = RealLoggingObj( model="unknown", @@ -674,9 +604,7 @@ class TestAzureAnthropicCostCalculation: ] assert ( - AnthropicPassthroughLoggingHandler._extract_model_from_anthropic_chunks( - chunks - ) + AnthropicPassthroughLoggingHandler._extract_model_from_anthropic_chunks(chunks) == "claude-3-5-haiku-20241022" ) @@ -692,14 +620,11 @@ class TestAzureAnthropicCostCalculation: ) assert ( - AnthropicPassthroughLoggingHandler._extract_model_from_anthropic_chunks( - [raw_event] - ) + AnthropicPassthroughLoggingHandler._extract_model_from_anthropic_chunks([raw_event]) == "claude-3-5-haiku-20241022" ) - class TestAnthropicBatchPassthroughCostTracking: """Test cases for Anthropic batch passthrough cost tracking functionality""" @@ -799,9 +724,7 @@ class TestAnthropicBatchPassthroughCostTracking: ) mock_batches_config_instance = MagicMock() - mock_batches_config_instance.transform_retrieve_batch_response.return_value = ( - mock_batch_response - ) + mock_batches_config_instance.transform_retrieve_batch_response.return_value = mock_batch_response mock_batches_config.return_value = mock_batches_config_instance # Test the handler @@ -906,9 +829,10 @@ class TestAnthropicBatchPassthroughCostTracking: mock_request_body, ): """Test that model gets 'anthropic/' prefix when not found in router""" + import base64 + from litellm.llms.anthropic.batches.transformation import AnthropicBatchesConfig from litellm.types.utils import LiteLLMBatch - import base64 # Model not in router - returns same model name mock_get_model_id.return_value = "claude-sonnet-4-5-20250929" @@ -929,9 +853,7 @@ class TestAnthropicBatchPassthroughCostTracking: "transform_retrieve_batch_response", return_value=mock_batch_response, ): - with patch.object( - AnthropicPassthroughLoggingHandler, "_store_batch_managed_object" - ): + with patch.object(AnthropicPassthroughLoggingHandler, "_store_batch_managed_object"): result = AnthropicPassthroughLoggingHandler.batch_creation_handler( httpx_response=mock_httpx_response, logging_obj=mock_logging_obj, @@ -946,10 +868,7 @@ class TestAnthropicBatchPassthroughCostTracking: # Verify unified_object_id contains anthropic/ prefix unified_object_id = result["kwargs"]["unified_object_id"] decoded = base64.urlsafe_b64decode(unified_object_id + "==").decode() - assert ( - "anthropic/claude-sonnet-4-5-20250929" in decoded - or "claude-sonnet-4-5-20250929" in decoded - ) + assert "anthropic/claude-sonnet-4-5-20250929" in decoded or "claude-sonnet-4-5-20250929" in decoded @pytest.mark.parametrize( "kwargs,expected_user_id,expected_team_id", @@ -1007,9 +926,7 @@ class TestAnthropicBatchPassthroughCostTracking: mock_managed_files_hook.store_unified_object_id = AsyncMock() with ( patch("litellm.proxy.proxy_server.proxy_logging_obj") as mock_pl, - patch( - "litellm.proxy.pass_through_endpoints.llm_provider_handlers.batch_attribution.verbose_proxy_logger" - ), + patch("litellm.proxy.pass_through_endpoints.llm_provider_handlers.batch_attribution.verbose_proxy_logger"), ): mock_pl.get_proxy_hook.return_value = mock_managed_files_hook AnthropicPassthroughLoggingHandler._store_batch_managed_object( @@ -1060,9 +977,7 @@ class TestAnthropicBatchPassthroughCostTracking: is never tracked. The failure has to reach the log instead of being reported as a success.""" mock_managed_files_hook = MagicMock() - mock_managed_files_hook.store_unified_object_id = AsyncMock( - side_effect=RuntimeError("db down") - ) + mock_managed_files_hook.store_unified_object_id = AsyncMock(side_effect=RuntimeError("db down")) with ( patch("litellm.proxy.proxy_server.proxy_logging_obj") as mock_pl, patch( @@ -1104,9 +1019,7 @@ class TestAnthropicBatchPassthroughCostTracking: this gate an id-scoped route reached the store with a mismatched id, where it could only either claim a row it did not create or fail the model_object_id unique constraint.""" - with patch.object( - AnthropicPassthroughLoggingHandler, "_store_batch_managed_object" - ) as mock_store: + with patch.object(AnthropicPassthroughLoggingHandler, "_store_batch_managed_object") as mock_store: AnthropicPassthroughLoggingHandler.batch_creation_handler( httpx_response=mock_httpx_response, logging_obj=mock_logging_obj, @@ -1120,9 +1033,7 @@ class TestAnthropicBatchPassthroughCostTracking: assert mock_store.call_count == (1 if registers else 0) - def test_batch_creation_handler_failure_status_code( - self, mock_logging_obj, mock_request_body - ): + def test_batch_creation_handler_failure_status_code(self, mock_logging_obj, mock_request_body): """Test batch creation handler with non-200 status code""" mock_response = MagicMock() mock_response.status_code = 400 @@ -1145,9 +1056,7 @@ class TestAnthropicBatchPassthroughCostTracking: assert result["kwargs"]["response_cost"] == 0.0 @patch("litellm.proxy.proxy_server.proxy_logging_obj") - def test_store_batch_managed_object_success( - self, mock_proxy_logging_obj, mock_logging_obj - ): + def test_store_batch_managed_object_success(self, mock_proxy_logging_obj, mock_logging_obj): """Test storing batch managed object""" from litellm.types.utils import LiteLLMBatch @@ -1178,15 +1087,13 @@ class TestAnthropicBatchPassthroughCostTracking: ) # Verify managed files hook was called - mock_proxy_logging_obj.get_proxy_hook.assert_called_once_with( - "managed_files" - ) + mock_proxy_logging_obj.get_proxy_hook.assert_called_once_with("managed_files") class TestBuildCompleteStreamingResponseRobustness: """_build_complete_streaming_response must tolerate non-standard SSE frames.""" - def _build(self, chunks: List[str]): + def _build(self, chunks: list[str]): return AnthropicPassthroughLoggingHandler._build_complete_streaming_response( all_chunks=chunks, litellm_logging_obj=MagicMock(), @@ -1343,11 +1250,7 @@ class TestPureTextFastPathParity: }, ) ) - frames.append( - self._sse( - "content_block_stop", {"type": "content_block_stop", "index": b} - ) - ) + frames.append(self._sse("content_block_stop", {"type": "content_block_stop", "index": b})) frames.append( self._sse( "message_delta", @@ -1405,9 +1308,7 @@ class TestPureTextFastPathParity: # And the full logged payload (sans non-deterministic response id). def _scrub(p): d = dict(p) - r = d.get("complete_streaming_response_in_db") or d.get( - "complete_streaming_response" - ) + r = d.get("complete_streaming_response_in_db") or d.get("complete_streaming_response") return d, getattr(r, "usage", None) assert _scrub(k_fast)[1] == _scrub(k_legacy)[1] @@ -1419,11 +1320,7 @@ class TestPureTextFastPathParity: self._assert_parity(self._text_stream(["Just one piece of text."])) def test_parity_cache_tokens(self): - self._assert_parity( - self._text_stream( - ["a", "b", "c"], input_tokens=20, cache_creation=5, cache_read=7 - ) - ) + self._assert_parity(self._text_stream(["a", "b", "c"], input_tokens=20, cache_creation=5, cache_read=7)) def test_parity_max_tokens_stop(self): self._assert_parity(self._text_stream(["tok"] * 8, stop_reason="max_tokens")) @@ -1484,12 +1381,7 @@ class TestPureTextFastPathParity: self._sse("message_stop", {"type": "message_stop"}), ] all_chunks = self._to_all_chunks(frames) - assert ( - AnthropicPassthroughLoggingHandler._collapse_pure_text_chunks( - list(all_chunks) - ) - is None - ) + assert AnthropicPassthroughLoggingHandler._collapse_pure_text_chunks(list(all_chunks)) is None def test_collapse_returns_none_for_thinking(self): frames = [ @@ -1526,19 +1418,12 @@ class TestPureTextFastPathParity: self._sse("message_stop", {"type": "message_stop"}), ] all_chunks = self._to_all_chunks(frames) - assert ( - AnthropicPassthroughLoggingHandler._collapse_pure_text_chunks( - list(all_chunks) - ) - is None - ) + assert AnthropicPassthroughLoggingHandler._collapse_pure_text_chunks(list(all_chunks)) is None def test_collapse_actually_shrinks_chunk_count(self): frames = self._text_stream(["a"] * 50) all_chunks = list(self._to_all_chunks(frames)) - collapsed = AnthropicPassthroughLoggingHandler._collapse_pure_text_chunks( - all_chunks - ) + collapsed = AnthropicPassthroughLoggingHandler._collapse_pure_text_chunks(all_chunks) assert collapsed is not None # 50 text deltas + 50 event markers + 1 ping collapse to far fewer. assert len(collapsed) < len(all_chunks) / 2 @@ -1604,10 +1489,7 @@ class TestPureTextFastPathParity: self._sse("message_stop", {"type": "message_stop"}), ] all_chunks = list(self._to_all_chunks(frames)) - assert ( - AnthropicPassthroughLoggingHandler._collapse_pure_text_chunks(all_chunks) - is None - ) + assert AnthropicPassthroughLoggingHandler._collapse_pure_text_chunks(all_chunks) is None class TestInterruptedStreamOutputTokenRecovery: @@ -1722,9 +1604,7 @@ class TestInterruptedStreamOutputTokenRecovery: import litellm placeholder = 2 - result = self._run( - self._interrupted_chunks(placeholder_output_tokens=placeholder) - ) + result = self._run(self._interrupted_chunks(placeholder_output_tokens=placeholder)) usage = result["result"].usage expected = litellm.token_counter( @@ -1897,9 +1777,7 @@ class TestStreamFalseDeduplication: "delta": {"type": "text_delta", "text": "Hello"}, }, ), - TestStreamFalseDeduplication._sse( - "content_block_stop", {"type": "content_block_stop", "index": 0} - ), + TestStreamFalseDeduplication._sse("content_block_stop", {"type": "content_block_stop", "index": 0}), TestStreamFalseDeduplication._sse( "message_delta", { @@ -1949,15 +1827,12 @@ class TestStreamFalseDeduplication: # The assembled response must be stored on model_call_details so callbacks # can identify this as a completed streaming call, not an in-progress one. - assert ( - logging_obj.model_call_details.get("complete_streaming_response") - is not None - ), "complete_streaming_response must be set on model_call_details after assembly" + assert logging_obj.model_call_details.get("complete_streaming_response") is not None, ( + "complete_streaming_response must be set on model_call_details after assembly" + ) # The returned result must match what was stored - assert result["result"] is logging_obj.model_call_details.get( - "complete_streaming_response" - ) + assert result["result"] is logging_obj.model_call_details.get("complete_streaming_response") def test_dedup_guard_fires_when_stream_true_on_logging_obj(self): """ @@ -1969,9 +1844,6 @@ class TestStreamFalseDeduplication: This is the _is_assembled_stream_success gate: with stream=False it always returned False and the guard was permanently disabled. """ - from litellm.types.passthrough_endpoints.pass_through_endpoints import ( - EndpointType, - ) from litellm.types.utils import ModelResponse # Simulate what pass_through_endpoints.py now does after stream detection @@ -1986,21 +1858,16 @@ class TestStreamFalseDeduplication: assert logging_obj._is_assembled_stream_success(result=mock_response) is True # First dispatch sets the flag - assert not logging_obj.model_call_details.get( - "has_dispatched_final_stream_success" - ) + assert not logging_obj.model_call_details.get("has_dispatched_final_stream_success") logging_obj.model_call_details["has_dispatched_final_stream_success"] = True # Second dispatch would be blocked — simulate the guard check would_skip = bool( logging_obj._is_assembled_stream_success(result=mock_response) - and logging_obj.model_call_details.get( - "has_dispatched_final_stream_success" - ) + and logging_obj.model_call_details.get("has_dispatched_final_stream_success") ) assert would_skip is True, ( - "Dedup guard must block a second dispatch_success_handlers call for the " - "same assembled streaming response" + "Dedup guard must block a second dispatch_success_handlers call for the same assembled streaming response" ) def test_sse_fallback_path_sets_stream_true_for_dedup(self): @@ -2034,9 +1901,7 @@ class TestStreamFalseDeduplication: would_skip = bool( logging_obj._is_assembled_stream_success(result=mock_response) - and logging_obj.model_call_details.get( - "has_dispatched_final_stream_success" - ) + and logging_obj.model_call_details.get("has_dispatched_final_stream_success") ) assert would_skip is True @@ -2100,9 +1965,9 @@ class TestNonStreamingResponseRedaction: logging_obj=logging_obj, ) - assert ( - "complete_streaming_response" not in logging_obj.model_call_details - ), "non-streaming responses must not populate complete_streaming_response" + assert "complete_streaming_response" not in logging_obj.model_call_details, ( + "non-streaming responses must not populate complete_streaming_response" + ) def test_streaming_sets_complete_streaming_response(self): from litellm.types.utils import ModelResponse @@ -2119,10 +1984,7 @@ class TestNonStreamingResponseRedaction: logging_obj=logging_obj, ) - assert ( - logging_obj.model_call_details.get("complete_streaming_response") - is response - ) + assert logging_obj.model_call_details.get("complete_streaming_response") is response def test_non_streaming_response_is_redacted_when_message_logging_off(self): from litellm.litellm_core_utils.redact_messages import ( @@ -2196,10 +2058,8 @@ class TestAnthropicUsageOnlyFallback: ] def test_build_usage_only_recovers_cache_inclusive_usage(self): - response = ( - AnthropicPassthroughLoggingHandler._build_usage_only_response_from_chunks( - all_chunks=self._CHUNKS, model="claude-3-5-haiku-20241022" - ) + response = AnthropicPassthroughLoggingHandler._build_usage_only_response_from_chunks( + all_chunks=self._CHUNKS, model="claude-3-5-haiku-20241022" ) assert response is not None usage = response.usage @@ -2259,10 +2119,8 @@ class TestAnthropicUsageOnlyFallback: } ), ] - response = ( - AnthropicPassthroughLoggingHandler._build_usage_only_response_from_chunks( - all_chunks=chunks, model="unknown" - ) + response = AnthropicPassthroughLoggingHandler._build_usage_only_response_from_chunks( + all_chunks=chunks, model="unknown" ) assert response is not None assert response.model == "claude-opus-4-6" @@ -2287,9 +2145,7 @@ class TestAnthropicUsageOnlyFallback: ('data: {"a": 1}', {"a": 1}), ], ) - def test_extract_sse_data_handles_malformed_and_sentinel_lines( - self, event_str, expected - ): + def test_extract_sse_data_handles_malformed_and_sentinel_lines(self, event_str, expected): assert extract_sse_data(event_str) == expected def _real_logging_obj(self): @@ -2309,12 +2165,8 @@ class TestAnthropicUsageOnlyFallback: return logging_obj @patch("litellm.completion_cost") - @patch.object( - AnthropicPassthroughLoggingHandler, "build_complete_streaming_response" - ) - def test_handler_falls_back_when_assembly_returns_none( - self, mock_assemble, mock_cost - ): + @patch.object(AnthropicPassthroughLoggingHandler, "build_complete_streaming_response") + def test_handler_falls_back_when_assembly_returns_none(self, mock_assemble, mock_cost): mock_assemble.return_value = None mock_cost.return_value = 0.0021 logging_obj = self._real_logging_obj() @@ -2335,9 +2187,7 @@ class TestAnthropicUsageOnlyFallback: assert result["kwargs"]["response_cost"] == 0.0021 @patch("litellm.completion_cost") - @patch.object( - AnthropicPassthroughLoggingHandler, "build_complete_streaming_response" - ) + @patch.object(AnthropicPassthroughLoggingHandler, "build_complete_streaming_response") def test_handler_falls_back_when_assembly_raises(self, mock_assemble, mock_cost): import litellm @@ -2367,9 +2217,7 @@ class TestAnthropicUsageOnlyFallback: assert result["result"].usage.completion_tokens == 55 assert result["kwargs"]["response_cost"] == 0.0021 - @patch.object( - AnthropicPassthroughLoggingHandler, "build_complete_streaming_response" - ) + @patch.object(AnthropicPassthroughLoggingHandler, "build_complete_streaming_response") def test_handler_returns_none_when_no_usage_recoverable(self, mock_assemble): # assembly fails AND the chunks carry no usage event, so there is nothing # to price; the handler must return None rather than fabricate a response @@ -2391,15 +2239,9 @@ class TestAnthropicUsageOnlyFallback: assert result["result"] is None assert result["kwargs"] == {} - @patch.object( - AnthropicPassthroughLoggingHandler, "build_usage_only_response_from_chunks" - ) - @patch.object( - AnthropicPassthroughLoggingHandler, "build_complete_streaming_response" - ) - def test_handler_does_not_crash_when_usage_only_fallback_raises( - self, mock_assemble, mock_fallback - ): + @patch.object(AnthropicPassthroughLoggingHandler, "build_usage_only_response_from_chunks") + @patch.object(AnthropicPassthroughLoggingHandler, "build_complete_streaming_response") + def test_handler_does_not_crash_when_usage_only_fallback_raises(self, mock_assemble, mock_fallback): # if the usage-only fallback itself raises, it must be treated as None and # drop gracefully, not propagate out and crash the success handler mock_assemble.return_value = None @@ -2427,7 +2269,6 @@ class TestAnthropicResponseCostRecordedOnModelCallDetails: builder must record it there or streaming pass-through logs $0.""" - class TestAnthropicPassthroughFastMode: """Anthropic charges a provider-specific multiplier for ``speed=fast``, applied off ``usage.speed`` and covering every token type, cache included. The response usage @@ -2436,20 +2277,20 @@ class TestAnthropicPassthroughFastMode: MODEL = "claude-opus-4-8" STREAM_CHUNKS = [ - 'event: message_start', + "event: message_start", 'data: {"type": "message_start", "message": {"id": "msg_1", "type": "message", "role": "assistant",' ' "model": "claude-opus-4-8", "content": [], "stop_reason": null,' ' "usage": {"input_tokens": 1000, "cache_read_input_tokens": 200, "output_tokens": 0}}}', - 'event: content_block_start', + "event: content_block_start", 'data: {"type": "content_block_start", "index": 0, "content_block": {"type": "text", "text": ""}}', - 'event: content_block_delta', + "event: content_block_delta", 'data: {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "ok"}}', - 'event: content_block_stop', + "event: content_block_stop", 'data: {"type": "content_block_stop", "index": 0}', - 'event: message_delta', + "event: message_delta", 'data: {"type": "message_delta", "delta": {"stop_reason": "end_turn"},' ' "usage": {"input_tokens": 1000, "cache_read_input_tokens": 200, "output_tokens": 100}}', - 'event: message_stop', + "event: message_stop", 'data: {"type": "message_stop"}', ] @@ -2643,7 +2484,6 @@ class TestRecordPartialUsageForFailure: assert "response_cost" not in logging_obj.model_call_details - @pytest.mark.parametrize( ("all_chunks", "interrupted"), [ @@ -2664,9 +2504,7 @@ def test_stream_was_interrupted_skips_data_lines_that_are_not_json_objects( @pytest.mark.asyncio -async def test_anthropic_passthrough_handler( - mock_httpx_response, mock_response, mock_logging_obj -): +async def test_anthropic_passthrough_handler(mock_httpx_response, mock_response, mock_logging_obj): """ Unit test - Assert that the anthropic passthrough handler calls the litellm logging object's async_success_handler """ @@ -2805,8 +2643,6 @@ def test_create_anthropic_response_logging_payload(mock_logging_obj, metadata_pa def test_handle_logging_anthropic_collected_chunks(all_chunks): from litellm.proxy.pass_through_endpoints.llm_provider_handlers.anthropic_passthrough_logging_handler import ( AnthropicPassthroughLoggingHandler, - PassthroughStandardLoggingPayload, - EndpointType, ) from litellm.types.utils import ModelResponse @@ -3007,3 +2843,164 @@ def test_streamed_messages_end_turn_logs_no_stop_details(mock_logging_obj): assert logged.choices[0].finish_reason == "stop" provider_fields: Final = logged.choices[0].message.provider_specific_fields or {} assert "stop_details" not in provider_fields + + +def _go_sse(event: str, data: dict) -> str: + return f"event: {event}\ndata: {json.dumps(data)}\n\n" + + +_GO_MESSAGE_DELTA_USAGE: Final = { + "input_tokens": 1200, + "output_tokens": 300, + "cost": 0, + "opencode": {"billing_source": "go", "list_cost": 0.00412}, +} + + +def _go_stream_chunks() -> list[str]: + message = { + "id": "msg_go", + "type": "message", + "role": "assistant", + "model": "claude-haiku-5-5", + "content": [], + "stop_reason": None, + "stop_sequence": None, + "usage": {"input_tokens": 1200, "output_tokens": 0}, + } + return [ + _go_sse("message_start", {"type": "message_start", "message": message}), + _go_sse( + "content_block_start", + {"type": "content_block_start", "index": 0, "content_block": {"type": "text", "text": ""}}, + ), + _go_sse( + "content_block_delta", + {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "ok"}}, + ), + _go_sse("content_block_stop", {"type": "content_block_stop", "index": 0}), + _go_sse( + "message_delta", + { + "type": "message_delta", + "delta": {"stop_reason": "end_turn", "stop_sequence": None}, + "usage": _GO_MESSAGE_DELTA_USAGE, + }, + ), + _go_sse("message_stop", {"type": "message_stop"}), + ] + + +def _go_logging_obj() -> LiteLLMLoggingObj: + logging_obj = LiteLLMLoggingObj( + model="opencode_go/claude-haiku-5-5", + messages=[{"role": "user", "content": "hi"}], + stream=True, + call_type="anthropic_messages", + start_time=datetime.now(), + litellm_call_id="go-stream", + function_id="1", + ) + logging_obj.model_call_details["custom_llm_provider"] = "opencode_go" + logging_obj.model_call_details["stream"] = True + logging_obj.model_call_details["litellm_params"] = {} + logging_obj.litellm_params = {} + return logging_obj + + +def test_streamed_messages_bill_the_list_cost_reported_in_the_final_message_delta(): + result = AnthropicPassthroughLoggingHandler._handle_logging_anthropic_collected_chunks( + litellm_logging_obj=_go_logging_obj(), + passthrough_success_handler_obj=MagicMock(), + url_route="/v1/messages", + request_body={"model": "opencode_go/claude-haiku-5-5", "stream": True}, + endpoint_type="messages", + start_time=datetime.now(), + all_chunks=_go_stream_chunks(), + end_time=datetime.now(), + ) + + assert result["kwargs"]["response_cost"] == 0.00412 + assert result["result"]._hidden_params["response_cost"] == 0.00412 + + +def test_streamed_messages_from_other_providers_ignore_a_zero_usage_cost_field(): + logging_obj = _go_logging_obj() + logging_obj.model_call_details["custom_llm_provider"] = "anthropic" + + result = AnthropicPassthroughLoggingHandler._handle_logging_anthropic_collected_chunks( + litellm_logging_obj=logging_obj, + passthrough_success_handler_obj=MagicMock(), + url_route="/v1/messages", + request_body={"model": "claude-haiku-5-5", "stream": True}, + endpoint_type="messages", + start_time=datetime.now(), + all_chunks=_go_stream_chunks(), + end_time=datetime.now(), + ) + + headers = result["result"]._hidden_params.get("additional_headers") or {} + assert "llm_provider-x-litellm-response-cost" not in headers + assert result["kwargs"].get("response_cost") != 0.0 + + +_BEDROCK_TRACE_PRICING: Final = { + "bedrock/guardrails": { + "litellm_provider": "bedrock", + "mode": "guardrail", + "guardrail_cost_per_unit": {"topicPolicyUnits": 0.00015, "contentPolicyUnits": 0.00015}, + } +} +_BEDROCK_INVOKE_TRACE: Final = { + "guardrail": { + "input": {"gid": {"invocationMetrics": {"usage": {"topicPolicyUnits": 1, "contentPolicyUnits": 1}}}}, + "outputs": [{"gid": {"invocationMetrics": {"usage": {"topicPolicyUnits": 2, "contentPolicyUnits": 2}}}}], + } +} + + +def _recorded_guardrail_entries(logging_obj: LiteLLMLoggingObj) -> list: + return logging_obj.model_call_details["litellm_params"]["metadata"]["standard_logging_guardrail_information"] + + +def test_anthropic_passthrough_handler_bills_the_bedrock_guardrail_trace_of_a_messages_response( + monkeypatch, mock_httpx_response, mock_response, mock_logging_obj +) -> None: + monkeypatch.setattr(litellm, "model_cost", _BEDROCK_TRACE_PRICING) + mock_logging_obj.model_call_details["litellm_params"] = {"metadata": {}} + AnthropicPassthroughLoggingHandler.anthropic_passthrough_handler( + httpx_response=mock_httpx_response, + response_body={**mock_response, "amazon-bedrock-trace": _BEDROCK_INVOKE_TRACE}, + logging_obj=mock_logging_obj, + url_route="/v1/messages", + result="success", + start_time=datetime(2025, 1, 1), + end_time=datetime(2025, 1, 1), + cache_hit=False, + ) + (entry,) = _recorded_guardrail_entries(mock_logging_obj) + assert entry["guardrail_provider"] == "bedrock" + assert entry["guardrail_usage"] == {"topicPolicyUnits": 3, "contentPolicyUnits": 3} + assert entry["guardrail_cost"] == pytest.approx(6 * 0.00015) + + +def test_anthropic_passthrough_stream_bills_the_bedrock_guardrail_trace_of_the_message_stop_event( + monkeypatch, mock_logging_obj, all_chunks +) -> None: + monkeypatch.setattr(litellm, "model_cost", _BEDROCK_TRACE_PRICING) + mock_logging_obj.model_call_details["litellm_params"] = {"metadata": {}} + stop_event: Final = json.dumps({"type": "message_stop", "amazon-bedrock-trace": _BEDROCK_INVOKE_TRACE}) + chunks: Final = [*all_chunks, f"event: message_stop\ndata: {stop_event}\n\n"] + AnthropicPassthroughLoggingHandler.handle_logging_anthropic_collected_chunks( + litellm_logging_obj=mock_logging_obj, + passthrough_success_handler_obj=MagicMock(), + url_route="/v1/messages", + request_body={"model": "claude", "messages": []}, + endpoint_type=MagicMock(), + start_time=datetime(2025, 1, 1), + all_chunks=chunks, + end_time=datetime(2025, 1, 1), + ) + (entry,) = _recorded_guardrail_entries(mock_logging_obj) + assert entry["guardrail_usage"] == {"topicPolicyUnits": 3, "contentPolicyUnits": 3} + assert entry["guardrail_cost"] == pytest.approx(6 * 0.00015) diff --git a/tests/unit/proxy/pass_through_endpoints/test_codex_passthrough_endpoints.py b/tests/unit/proxy/pass_through_endpoints/test_codex_passthrough_endpoints.py new file mode 100644 index 00000000000..354c65776dc --- /dev/null +++ b/tests/unit/proxy/pass_through_endpoints/test_codex_passthrough_endpoints.py @@ -0,0 +1,185 @@ +import asyncio +import json +from collections.abc import Iterator +from datetime import datetime +from typing import Final + +import httpx +import pytest +import respx +from fastapi.testclient import TestClient + +import litellm +from litellm.integrations.custom_logger import CustomLogger +from litellm.proxy import proxy_server +from tests._master_key import MASTER_KEY + +_BASE: Final = "https://chatgpt.com/backend-api/codex" +_TOKEN: Final = "test-subscription-token" +_HEADERS: Final = {"authorization": f"Bearer {_TOKEN}", "x-litellm-api-key": MASTER_KEY} + + +@pytest.fixture +def client(monkeypatch: pytest.MonkeyPatch, httpx_transport: None) -> Iterator[TestClient]: + monkeypatch.setattr(proxy_server, "master_key", MASTER_KEY) + yield TestClient(proxy_server.app) + + +def test_native_catalog_preserves_account_and_filters_gateway_credentials( + client: TestClient, respx_mock: respx.MockRouter +) -> None: + catalog: Final = {"models": [{"slug": "subscription-model", "supported_reasoning_levels": ["high"]}]} + upstream: Final = respx_mock.get(f"{_BASE}/models", params={"client_version": "1.0.0"}).respond(json=catalog) + response: Final = client.get( + "/backend-api/codex/models?client_version=1.0.0", + headers={ + **_HEADERS, + "chatgpt-account-id": "account-a", + "cookie": "session=test-cookie", + "x-pass-authorization": "Bearer test-injected-token", + "x-pass-x-litellm-api-key": "test-injected-key", + }, + ) + assert response.status_code == 200 + assert response.json() == catalog + assert upstream.calls.last.request.headers["authorization"] == f"Bearer {_TOKEN}" + assert upstream.calls.last.request.headers["chatgpt-account-id"] == "account-a" + assert "x-litellm-api-key" not in upstream.calls.last.request.headers + assert "cookie" not in upstream.calls.last.request.headers + + +@pytest.mark.parametrize("account", ["account-a", "account-b"]) +def test_native_responses_preserves_body_and_stream( + client: TestClient, respx_mock: respx.MockRouter, account: str +) -> None: + body: Final = { + "model": "subscription-model", + "input": [{"role": "user", "content": "Hello"}], + "reasoning": {"effort": "high"}, + "store": False, + "stream": True, + } + stream: Final = ( + b'event: response.output_text.delta\ndata: {"type":"response.output_text.delta","delta":"Hello"}\n\n' + ) + upstream: Final = respx_mock.post(f"{_BASE}/responses").respond( + content=stream, headers={"content-type": "text/event-stream"} + ) + response: Final = client.post( + "/backend-api/codex/responses", + json=body, + headers={**_HEADERS, "authorization": f"Bearer test-{account}", "chatgpt-account-id": account}, + ) + assert response.status_code == 200 + assert response.content == stream + assert response.headers["content-type"].startswith("text/event-stream") + assert json.loads(upstream.calls.last.request.content) == body + assert upstream.calls.last.request.headers["authorization"] == f"Bearer test-{account}" + assert upstream.calls.last.request.headers["chatgpt-account-id"] == account + + +@pytest.mark.parametrize("gateway_key", [None, "sk-invalid-test-key"]) +def test_gateway_auth_rejects_before_upstream( + client: TestClient, respx_mock: respx.MockRouter, gateway_key: str | None +) -> None: + headers: Final = { + "authorization": f"Bearer {_TOKEN}", + **({"x-litellm-api-key": gateway_key} if gateway_key else {}), + } + response: Final = client.get("/backend-api/codex/models", headers=headers) + assert response.status_code in (400, 401, 403) + assert not respx_mock.calls + + +@pytest.mark.parametrize("authorization", ["", "Basic test", "Bearer ", f"Bearer {MASTER_KEY}"]) +def test_subscription_credential_required(client: TestClient, respx_mock: respx.MockRouter, authorization: str) -> None: + response: Final = client.get("/backend-api/codex/models", headers={**_HEADERS, "authorization": authorization}) + assert response.status_code == 401 + assert not respx_mock.calls + + +@pytest.mark.parametrize("status", [401, 403, 429]) +def test_provider_errors_do_not_fall_back(client: TestClient, respx_mock: respx.MockRouter, status: int) -> None: + upstream: Final = respx_mock.post(f"{_BASE}/responses").respond( + status, json={"error": {"message": "subscription unavailable"}}, headers={"retry-after": "60"} + ) + response: Final = client.post( + "/backend-api/codex/responses", headers=_HEADERS, json={"model": "subscription-model", "stream": True} + ) + assert response.status_code == status + assert upstream.call_count == 1 + + +@pytest.mark.parametrize("method,path", [("POST", "models"), ("GET", "responses"), ("GET", "deviceauth")]) +def test_only_native_inference_routes_are_forwarded( + client: TestClient, respx_mock: respx.MockRouter, method: str, path: str +) -> None: + response: Final = client.request(method, f"/backend-api/codex/{path}", headers=_HEADERS) + assert response.status_code in (405, 422) + assert not respx_mock.calls + + +class UsageRecorder(CustomLogger): + def __init__(self) -> None: + super().__init__() + self.events: Final[asyncio.Queue[dict[str, object]]] = asyncio.Queue() + + async def async_log_success_event( + self, kwargs: dict[str, object], response_obj: object, start_time: datetime, end_time: datetime + ) -> None: + await self.events.put(kwargs) + + +@pytest.mark.asyncio +@pytest.mark.parametrize("stream", [False, True]) +async def test_usage_logged_without_credentials( + monkeypatch: pytest.MonkeyPatch, httpx_transport: None, respx_mock: respx.MockRouter, stream: bool +) -> None: + monkeypatch.setattr(proxy_server, "master_key", MASTER_KEY) + recorder: Final = UsageRecorder() + monkeypatch.setattr(litellm, "_async_success_callback", [recorder]) + litellm.register_model( + { + "chatgpt/subscription-model": { + "litellm_provider": "chatgpt", + "mode": "responses", + "input_cost_per_token": 0.0, + "output_cost_per_token": 0.0, + } + } + ) + result: Final = { + "id": "resp_test", + "object": "response", + "created_at": 1700000000, + "status": "completed", + "model": "subscription-model", + "output": [], + "usage": {"input_tokens": 12, "output_tokens": 3, "total_tokens": 15}, + } + event: Final = {"type": "response.completed", "response": result} + response_body: Final = ( + httpx.Response( + 200, + content=f"event: response.completed\ndata: {json.dumps(event)}\n\n", + headers={"content-type": "text/event-stream"}, + ) + if stream + else httpx.Response(200, json=result) + ) + respx_mock.post(f"{_BASE}/responses").mock(return_value=response_body) + async with httpx.AsyncClient(transport=httpx.ASGITransport(app=proxy_server.app), base_url="http://test") as caller: + response: Final = await caller.post( + "/backend-api/codex/responses", + json={"model": "subscription-model", "stream": stream, "input": "Hello"}, + headers={**_HEADERS, "x-pass-authorization": "Bearer test-hidden-token", "cookie": "test-hidden-cookie"}, + ) + assert response.status_code == 200 + logged: Final = await asyncio.wait_for(recorder.events.get(), timeout=5) + payload: Final = logged["standard_logging_object"] + assert isinstance(payload, dict) + assert payload["prompt_tokens"] == 12 + assert payload["completion_tokens"] == 3 + serialized: Final = json.dumps(logged, default=str) + for secret in (_TOKEN, MASTER_KEY, "test-hidden-token", "test-hidden-cookie"): + assert secret not in serialized diff --git a/tests/unit/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py b/tests/unit/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py index 0186a33dbc4..60043daa402 100644 --- a/tests/unit/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py +++ b/tests/unit/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py @@ -4357,6 +4357,7 @@ class TestVertexRawPredictStreamingClassification: "type": "http", "method": "POST", "path": f"/vertex_ai/{endpoint}", + "path_params": {"endpoint": endpoint}, "headers": [ (b"content-type", b"application/json"), (b"x-litellm-api-key", b"test-key"), diff --git a/tests/unit/proxy/pass_through_endpoints/test_pass_through_endpoints.py b/tests/unit/proxy/pass_through_endpoints/test_pass_through_endpoints.py index db0a74d360a..112e4f6cb6c 100644 --- a/tests/unit/proxy/pass_through_endpoints/test_pass_through_endpoints.py +++ b/tests/unit/proxy/pass_through_endpoints/test_pass_through_endpoints.py @@ -1922,6 +1922,40 @@ async def test_pass_through_request_uses_resolved_timeout(): assert mock_get_client.call_args[1]["params"]["timeout"] == 1500 +@pytest.mark.asyncio +@pytest.mark.parametrize("allow_client_pricing_override", [True, False]) +async def test_pass_through_request_strips_client_guardrail_information(allow_client_pricing_override: bool): + mock_request = MagicMock(spec=Request) + mock_request.method = "POST" + mock_request.headers = Headers({}) + mock_request.query_params = QueryParams({}) + + with patch("litellm.proxy.proxy_server.proxy_logging_obj") as mock_proxy_logging: + mock_proxy_logging.pre_call_hook = AsyncMock(side_effect=RuntimeError("stop before upstream")) + mock_proxy_logging.post_call_failure_hook = AsyncMock() + with pytest.raises(ProxyException): + await pass_through_request( + request=mock_request, + target="http://test.com", + custom_headers={}, + user_api_key_dict=UserAPIKeyAuth( + metadata={"allow_client_pricing_override": allow_client_pricing_override} + ), + custom_body={ + "model": "gpt-4o", + "input_cost_per_token": 0.5, + "metadata": { + "trace_id": "keep-me", + "standard_logging_guardrail_information": [{"guardrail_name": "forged", "guardrail_cost": 5.0}], + }, + }, + ) + + hooked_body: Final = mock_proxy_logging.pre_call_hook.call_args.kwargs["data"] + assert hooked_body["metadata"] == {"trace_id": "keep-me"} + assert ("input_cost_per_token" in hooked_body) is allow_client_pricing_override + + @pytest.mark.asyncio async def test_create_pass_through_route_forwards_timeout(): unique_path = "/test/path/unique/timeout" diff --git a/tests/unit/proxy/pass_through_endpoints/test_streaming_handler_interrupt.py b/tests/unit/proxy/pass_through_endpoints/test_streaming_handler_interrupt.py index 4aa7e9cfbae..ae95c27950c 100644 --- a/tests/unit/proxy/pass_through_endpoints/test_streaming_handler_interrupt.py +++ b/tests/unit/proxy/pass_through_endpoints/test_streaming_handler_interrupt.py @@ -20,7 +20,7 @@ from litellm.proxy.pass_through_endpoints.llm_provider_handlers.tinyfish_passthr from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER -from litellm.llms.anthropic.pass_through.messages.streaming_iterator import aclose_superseded_attempt +from litellm.llms.anthropic.messages.native.streaming_iterator import aclose_superseded_attempt from litellm.proxy.pass_through_endpoints.streaming_handler import ( PassThroughStreamingHandler, ) diff --git a/tests/unit/proxy/proxy_server/test_openapi_customization.py b/tests/unit/proxy/proxy_server/test_openapi_customization.py index 6c588976efc..0eacf333960 100644 --- a/tests/unit/proxy/proxy_server/test_openapi_customization.py +++ b/tests/unit/proxy/proxy_server/test_openapi_customization.py @@ -36,6 +36,7 @@ from litellm.proxy.proxy_server import ( get_openapi_schema, mount_swagger_ui, ) +from tests.unit.litellm_core_utils.attribute_forwarder import AttributeForwarder from .conftest import normalize @@ -209,6 +210,17 @@ def test_inject_websocket_stubs_into_openapi_schema_adds_stub(): } +def test_inject_websocket_stubs_into_openapi_schema_documents_query_params_that_forward_their_fields(): + query_param: Final = AttributeForwarder(SimpleNamespace(name="session_id", required=True)) + route: Final = SimpleNamespace(path="/ws/chat", name="ws_chat", dependant=SimpleNamespace(query_params=[query_param])) + + result: Final = _inject_websocket_stubs_into_openapi_schema({"paths": {}}, [route]) + + assert result["paths"]["/ws/chat"]["get"]["parameters"] == [ + {"name": "session_id", "in": "query", "required": True, "schema": {"type": "string"}} + ] + + def test_inject_websocket_stubs_into_openapi_schema_does_not_overwrite_existing_get(): # Existing GET on the same path must not be replaced by the stub. existing_get = {"summary": "real http get", "operationId": "real_get"} diff --git a/tests/unit/proxy/proxy_server/test_routes_model_info.py b/tests/unit/proxy/proxy_server/test_routes_model_info.py index 2c0e0944edb..9993361d930 100644 --- a/tests/unit/proxy/proxy_server/test_routes_model_info.py +++ b/tests/unit/proxy/proxy_server/test_routes_model_info.py @@ -11,6 +11,7 @@ from __future__ import annotations import asyncio import copy +import json from collections.abc import Callable from contextlib import AbstractContextManager from typing import Final @@ -24,6 +25,7 @@ import litellm from litellm.caching.llm_caching_handler import LLMClientCache from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler from litellm.proxy import proxy_server +from litellm.proxy._types import LiteLLM_ProxyModelTable from litellm.utils import _invalidate_model_cost_lowercase_map from .conftest import normalize # type: ignore[import-not-found] @@ -206,6 +208,80 @@ def test_v2_model_info_invalid_page_returns_422(client, auth_as, empty_router): assert "detail" in response.json() +@pytest.mark.parametrize("encoded", [False, True]) +def test_deleted_model_params_stay_absent_after_reload_and_another_save( + client: TestClient, + auth_as: Callable[[], AbstractContextManager[object]], + monkeypatch: pytest.MonkeyPatch, + mock_prisma: MagicMock, + encoded: bool, +) -> None: + from litellm.proxy.management_endpoints.model_management_endpoints import update_db_model + from litellm.types.proxy.management_endpoints.model_management_endpoints import PatchModelRequest + from litellm.types.router import Deployment, LiteLLM_Params, ModelInfo, updateDeployment, updateLiteLLMParams + + configured: Final = { + "model": "openai/test-model", "api_key": "synthetic-runtime-secret", + "use_litellm_proxy": True, "use_in_pass_through": True, "use_chat_completions_api": False, + "litellm_image_enabled": True, "timeout": 30, "input_cost_per_token": 0.003, + "team_id": "param-only-team", "temperature": 0, "metadata": {}, + } + original: Final = Deployment( + model_name="editor-model", litellm_params=LiteLLM_Params.model_validate(configured), + model_info=ModelInfo(id="editor-model", team_id="owner-team", access_groups=["retained-group"]), + ) + removals: Final = ("litellm_image_enabled", "use_litellm_proxy", "input_cost_per_token", "team_id") + deleted: Final = update_db_model( + db_model=original, + updated_patch=PatchModelRequest( + litellm_params=updateLiteLLMParams(max_retries=0), litellm_params_to_remove=removals, + model_info=ModelInfo(id="editor-model", input_cost_per_token=0.003), + ), + ) + saved_params: Final = json.loads(deleted["litellm_params"]) + saved_info: Final = json.loads(deleted["model_info"]) + assert saved_params == {**{key: value for key, value in configured.items() if key not in removals}, "max_retries": 0} + assert "input_cost_per_token" not in saved_info + assert saved_info["team_id"] == "owner-team" + assert saved_info["access_groups"] == ["retained-group"] + reloaded: Final = Deployment.model_validate( + {"model_name": original.model_name, "litellm_params": saved_params, "model_info": saved_info} + ) + router: Final = litellm.Router(model_list=[{ + "model_name": "editor-model", "litellm_params": saved_params, + "model_info": {"id": "editor-model", "db_model": True}, + }]) + stored_params: Final = {**saved_params, "api_key": "synthetic-stored-secret"} + mock_prisma.db.litellm_proxymodeltable.find_unique.return_value = LiteLLM_ProxyModelTable( + model_id="editor-model", model_name="editor-model", + litellm_params=json.dumps(stored_params) if encoded else stored_params, + model_info={"id": "editor-model"}, + ) + monkeypatch.setattr(proxy_server, "llm_router", router) + monkeypatch.setattr(proxy_server, "prisma_client", mock_prisma) + + with auth_as(): + normal: Final = client.get("/v2/model/info", params={"modelId": "editor-model"}) + editor: Final = client.get("/v2/model/info", params={"modelId": "editor-model", "use_stored_params": "true"}) + + assert normal.status_code == editor.status_code == 200, editor.text + normal_params: Final = normal.json()["data"][0]["litellm_params"] + assert "use_litellm_proxy" in normal_params + assert editor.json()["data"][0]["litellm_params"] == { + key: value for key, value in normal_params.items() if key in saved_params + } + assert editor.json()["data"][0]["litellm_params"]["use_chat_completions_api"] is False + assert "synthetic-runtime-secret" not in editor.text + assert "synthetic-stored-secret" not in editor.text + assert "use_litellm_proxy" in router.model_list[0]["litellm_params"] + + saved_again: Final = update_db_model( + db_model=reloaded, updated_patch=updateDeployment(litellm_params=updateLiteLLMParams(rpm=10, timeout=None)) + ) + persisted: Final = json.loads(saved_again["litellm_params"]) + assert persisted == {**saved_params, "rpm": 10} + + def test_v2_model_info_in_openapi_schema(): """``GET /v2/model/info`` is published in the proxy OpenAPI/Swagger spec.""" from litellm.proxy.proxy_server import get_openapi_schema diff --git a/tests/unit/proxy/public_endpoints/test_public_endpoints.py b/tests/unit/proxy/public_endpoints/test_public_endpoints.py index cc61b6f2fcf..f60c2254b41 100644 --- a/tests/unit/proxy/public_endpoints/test_public_endpoints.py +++ b/tests/unit/proxy/public_endpoints/test_public_endpoints.py @@ -1235,8 +1235,8 @@ def test_public_mcp_hub_derives_publication_metadata_without_mutating_registry( expected_listed: bool, stored_public: bool | None, ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp_server.mcp_server_manager import MCPServer app: Final = FastAPI() @@ -1275,7 +1275,7 @@ def test_public_mcp_hub_derives_publication_metadata_without_mutating_registry( patch("litellm.public_mcp_servers", [server.server_id] if explicit else []), patch("litellm.public_mcp_hub_strict_whitelist", strict), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager, ), ): @@ -1307,7 +1307,7 @@ def test_public_mcp_hub_returns_empty_when_whitelist_unset(): with ( patch("litellm.public_mcp_servers", None), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -1345,7 +1345,7 @@ def test_public_mcp_hub_does_not_expose_upstream_url(): with ( patch("litellm.public_mcp_servers", ["listed"]), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): diff --git a/tests/unit/proxy/response_polling/test_response_polling_handler.py b/tests/unit/proxy/response_polling/test_response_polling_handler.py index 979ab499f3b..63e38ce533a 100644 --- a/tests/unit/proxy/response_polling/test_response_polling_handler.py +++ b/tests/unit/proxy/response_polling/test_response_polling_handler.py @@ -1011,10 +1011,9 @@ class TestPollingConditionChecks: # Create mock router mock_router = Mock() - mock_router.model_name_to_deployment_indices = {"gpt-5": [0]} - mock_router.model_list = [ - {"model_name": "gpt-5", "litellm_params": {"model": "openai/gpt-5"}} - ] + mock_router.deployments_named.side_effect = { + "gpt-5": ({"model_name": "gpt-5", "litellm_params": {"model": "openai/gpt-5"}},) + }.get result = should_use_polling_for_request( background_mode=True, @@ -1033,13 +1032,14 @@ class TestPollingConditionChecks: ) mock_router = Mock() - mock_router.model_name_to_deployment_indices = {"claude-3": [0]} - mock_router.model_list = [ - { - "model_name": "claude-3", - "litellm_params": {"model": "anthropic/claude-3-sonnet"}, - } - ] + mock_router.deployments_named.side_effect = { + "claude-3": ( + { + "model_name": "claude-3", + "litellm_params": {"model": "anthropic/claude-3-sonnet"}, + }, + ) + }.get result = should_use_polling_for_request( background_mode=True, @@ -1183,13 +1183,14 @@ class TestPollingConditionChecks: ) mock_router = Mock() - mock_router.model_name_to_deployment_indices = {"deep-research": [0]} - mock_router.model_list = [ - { - "model_name": "deep-research", - "litellm_params": {"model": "openai/o4-mini-deep-research"}, - } - ] + mock_router.deployments_named.side_effect = { + "deep-research": ( + { + "model_name": "deep-research", + "litellm_params": {"model": "openai/o4-mini-deep-research"}, + }, + ) + }.get # Model alias "deep-research" is in native_background_mode result = should_use_polling_for_request( diff --git a/tests/unit/proxy/spend_tracking/test_input_tokens.py b/tests/unit/proxy/spend_tracking/test_input_tokens.py index 71f4dec2345..c7f13651471 100644 --- a/tests/unit/proxy/spend_tracking/test_input_tokens.py +++ b/tests/unit/proxy/spend_tracking/test_input_tokens.py @@ -30,6 +30,32 @@ async def test_large_input_is_still_counted() -> None: assert isinstance(counts, MappingProxyType) +def test_count_input_tokens_for_model_counts_anthropic_auto_tool_choice() -> None: + model: Final = "claude-sonnet-5-5" + body_without_tool_choice: Final = { + "model": model, + "messages": [{"role": "user", "content": "weather in pune?"}], + "tools": [ + { + "name": "get_weather", + "description": "Get the weather for a location", + "input_schema": { + "type": "object", + "properties": {"location": {"type": "string"}}, + "required": ["location"], + }, + } + ], + } + body_with_tool_choice: Final = body_without_tool_choice | {"tool_choice": {"type": "auto"}} + + expected: Final = count_input_tokens_for_model(request_body=body_without_tool_choice, model=model) + actual: Final = count_input_tokens_for_model(request_body=body_with_tool_choice, model=model) + + assert isinstance(expected, int) + assert actual == expected + + _COMPACTION_ITEM: Final = { "type": "compaction", "id": "cmp_1", diff --git a/tests/unit/proxy/spend_tracking/test_spend_tracking_utils.py b/tests/unit/proxy/spend_tracking/test_spend_tracking_utils.py index 78f5e1ace0c..86d064050eb 100644 --- a/tests/unit/proxy/spend_tracking/test_spend_tracking_utils.py +++ b/tests/unit/proxy/spend_tracking/test_spend_tracking_utils.py @@ -5074,7 +5074,7 @@ async def test_spend_log_request_id_is_the_message_id_a_bridged_streaming_caller adapter mints itself, and it is the only request id that call ever shows the caller, so GET /spend/logs?request_id=msg_... has to land on the row.""" from litellm.litellm_core_utils.litellm_logging import Logging - from litellm.llms.anthropic.pass_through.responses_adapters.streaming_iterator import ( + from litellm.llms.anthropic.messages.responses_adapters.streaming_iterator import ( AnthropicResponsesStreamWrapper, ) from litellm.types.llms.openai import ( diff --git a/tests/unit/proxy/test__types.py b/tests/unit/proxy/test__types.py index 68bfe4b34e5..76ca49362b4 100644 --- a/tests/unit/proxy/test__types.py +++ b/tests/unit/proxy/test__types.py @@ -2,23 +2,35 @@ import json from typing import Final import pytest -from pydantic import ValidationError +from pydantic import BaseModel, ValidationError from litellm.proxy._types import ( ROLES_WITHIN_ORG, + BudgetNewRequest, ChangePasswordRequest, GenerateKeyRequest, + GenerateKeyResponse, KeyRequest, LiteLLM_AuditLogs, + LiteLLM_BudgetTable, + LiteLLM_EndUserTable, LiteLLM_TeamMembership, + LiteLLM_TeamTable, + LiteLLM_UserTable, LitellmUserRoles, + NewCustomerRequest, NewMCPServerRequest, + NewTeamRequest, NewUserRequest, + NewUserResponse, OrganizationMemberUpdateRequest, + RegenerateKeyRequest, ResetSpendRequest, UpdateKeyRequest, UpdateMCPServerRequest, + UpdateTeamRequest, UpdateUserRequest, + UpdateUserRequestNoUserIDorEmail, UserAPIKeyAuth, ) @@ -213,6 +225,75 @@ def test_a_max_budget_that_was_actually_sent_is_kept(sent): assert GenerateKeyRequest(max_budget=sent).max_budget == sent +RATE_LIMIT_REQUESTS: Final = ( + (GenerateKeyRequest, {}), + (RegenerateKeyRequest, {}), + (UpdateKeyRequest, {"key": "sk-test"}), + (NewUserRequest, {}), + (UpdateUserRequestNoUserIDorEmail, {}), + (UpdateUserRequest, {"user_id": "user-test"}), + (NewTeamRequest, {}), + (UpdateTeamRequest, {"team_id": "team-test"}), + (BudgetNewRequest, {}), + (NewCustomerRequest, {"user_id": "customer-test"}), +) + + +@pytest.mark.parametrize(("request_model", "identifiers"), RATE_LIMIT_REQUESTS) +@pytest.mark.parametrize("field", ("rpm_limit", "tpm_limit")) +@pytest.mark.parametrize("value", (-1, -100)) +def test_management_requests_reject_negative_rate_limits( + request_model: type[BaseModel], identifiers: dict[str, str], field: str, value: int +) -> None: + with pytest.raises(ValidationError) as error: + request_model.model_validate({**identifiers, field: value}) + assert error.value.errors()[0]["loc"] == (field,) + + +@pytest.mark.parametrize(("request_model", "identifiers"), RATE_LIMIT_REQUESTS) +@pytest.mark.parametrize("value", (None, 0, 100)) +def test_management_requests_preserve_explicit_rate_limits( + request_model: type[BaseModel], identifiers: dict[str, str], value: int | None +) -> None: + limits: Final = {"rpm_limit": value, "tpm_limit": value} + request: Final = request_model.model_validate({**identifiers, **limits}) + assert request.model_dump(include={"rpm_limit", "tpm_limit"}, exclude_unset=True) == limits + + +@pytest.mark.parametrize(("request_model", "identifiers"), RATE_LIMIT_REQUESTS) +def test_management_requests_leave_omitted_rate_limits_unset( + request_model: type[BaseModel], identifiers: dict[str, str] +) -> None: + request: Final = request_model.model_validate({**identifiers}) + assert request.model_dump(include={"rpm_limit", "tpm_limit"}) == {"rpm_limit": None, "tpm_limit": None} + assert request.model_dump(include={"rpm_limit", "tpm_limit"}, exclude_unset=True) == {} + + +@pytest.mark.parametrize(("response_model", "identifiers"), ( + (GenerateKeyResponse, {"key": "sk-test"}), + (NewUserResponse, {"key": "sk-test"}), + (LiteLLM_TeamTable, {"team_id": "team-test"}), + (LiteLLM_UserTable, {"user_id": "user-test"}), + (LiteLLM_BudgetTable, {"budget_id": "budget-test"}), +)) +def test_existing_negative_rate_limits_remain_readable( + response_model: type[BaseModel], identifiers: dict[str, str] +) -> None: + limits: Final = {"rpm_limit": -1, "tpm_limit": -100} + response: Final = response_model.model_validate({**identifiers, **limits}) + assert response.model_dump(include={"rpm_limit", "tpm_limit"}) == limits + + +def test_existing_customer_negative_rate_limits_remain_readable() -> None: + customer: Final = LiteLLM_EndUserTable.model_validate({ + "user_id": "customer-test", "blocked": False, + "litellm_budget_table": {"rpm_limit": -1, "tpm_limit": -100}, + }) + assert customer.litellm_budget_table is not None + assert customer.litellm_budget_table.rpm_limit == -1 + assert customer.litellm_budget_table.tpm_limit == -100 + + USER_IDENTIFIER_CASES = ( ({"user_id": "user-1"}, True), ({"user_email": "user@example.com"}, True), diff --git a/tests/unit/proxy/test_budget_reservation.py b/tests/unit/proxy/test_budget_reservation.py index 4635e145914..42b41a2e3f2 100644 --- a/tests/unit/proxy/test_budget_reservation.py +++ b/tests/unit/proxy/test_budget_reservation.py @@ -13,10 +13,10 @@ import litellm from litellm.caching.dual_cache import DualCache from litellm.types.caching import RedisPipelineIncrementOperation from litellm.constants import STREAM_SSE_KEEPALIVE_PING_BYTES -from litellm.llms.anthropic.pass_through.messages.agentic_streaming_iterator import ( +from litellm.llms.anthropic.messages.native.agentic_streaming_iterator import ( AgenticAnthropicStreamingIterator, ) -from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( +from litellm.llms.anthropic.messages.native.streaming_iterator import ( AnthropicMessagesStreamingResponse, ) from litellm.proxy._types import ( diff --git a/tests/unit/proxy/test_common_request_processing.py b/tests/unit/proxy/test_common_request_processing.py index 92bf2b45fab..5c99e5a01ea 100644 --- a/tests/unit/proxy/test_common_request_processing.py +++ b/tests/unit/proxy/test_common_request_processing.py @@ -8640,10 +8640,10 @@ class TestStreamingClientDisconnectBilling: through the translate_completion_output_params_streaming result to the inner chat stream's collected chunks or a disconnect bills nothing. """ - from litellm.llms.anthropic.pass_through.adapters.streaming_iterator import ( + from litellm.llms.anthropic.messages.adapters.streaming_iterator import ( AnthropicSSEStream, ) - from litellm.llms.anthropic.pass_through.adapters.transformation import ( + from litellm.llms.anthropic.messages.adapters.transformation import ( AnthropicAdapter, ) from litellm.router import FallbackAwareAnthropicMessagesStream @@ -9180,7 +9180,7 @@ def _apply_stream_usage_tracking( @pytest.mark.asyncio async def test_disconnect_bills_partial_default_route_messages_stream_through_the_responses_adapter(self): - from litellm.llms.anthropic.pass_through.responses_adapters.streaming_iterator import ( + from litellm.llms.anthropic.messages.responses_adapters.streaming_iterator import ( AnthropicResponsesStreamWrapper, ) from litellm.router import FallbackAwareAnthropicMessagesStream @@ -10175,6 +10175,32 @@ class TestInjectCostIntoUsageDict: class TestProcessChunkWithCostInjection: + @pytest.mark.parametrize("model", ["claude-opus-5-5", "vertex_ai/claude-opus-5-5"]) + @pytest.mark.parametrize("search_requests", [None, "null", 0, 1, 2]) + def test_claude_search_stream_cost_matches_complete_usage( + self, monkeypatch: pytest.MonkeyPatch, model: str, search_requests: int | Literal["null"] | None + ) -> None: + monkeypatch.setattr(litellm, "include_cost_in_streaming_usage", True) + usage: Final = litellm.Usage( + prompt_tokens=10760, + completion_tokens=399, + total_tokens=11159, + server_tool_use={"web_search_requests": search_requests} if isinstance(search_requests, int) else None, + ) + wire_usage: Final = usage.model_dump() | ({"server_tool_use": None} if search_requests == "null" else {}) + event: Final = {"object": "chat.completion.chunk", "choices": [], "usage": wire_usage} + chunk: Final = f"data: {json.dumps(event)}\n\n".encode() + + result: Final = ProxyBaseLLMRequestProcessing.process_chunk_with_cost_injection(chunk, model) + + assert isinstance(result, bytes) + payload: Final = json.loads(result.decode().removeprefix("data: ")) + expected_cost: Final = litellm.completion_cost( + model=model, completion_response=litellm.ModelResponse(usage=usage) + ) + assert payload["usage"]["cost"] == pytest.approx(expected_cost) + assert "cost" not in event["usage"] + def test_complete_usage_frame_chunk_is_injected(self, monkeypatch): monkeypatch.setattr(litellm, "include_cost_in_streaming_usage", True) chunk = ( @@ -11897,7 +11923,7 @@ class TestResponseCostFromLoggingObjForBridgedMessages: def test_recomputed_cost_prices_the_reasoning_tokens_of_the_bridged_chat_completion(self): from litellm.types.utils import CompletionTokensDetailsWrapper, ModelResponse, Usage - from litellm.llms.anthropic.pass_through.adapters.transformation import LiteLLMAnthropicMessagesAdapter + from litellm.llms.anthropic.messages.adapters.transformation import LiteLLMAnthropicMessagesAdapter model = "dashscope/qwen-turbo" pricing = litellm.get_model_info(model) @@ -12027,3 +12053,24 @@ class TestResponseCostFromLoggingObjForCacheHits: ) assert cost == "" + + +def test_maybe_get_model_id_reads_the_chat_metadata_the_router_updated_in_place(): + processing_obj: Final = ProxyBaseLLMRequestProcessing(data={"metadata": {"model_info": {"id": "declared-text"}}}) + + assert processing_obj.maybe_get_model_id(None) == "declared-text" + + +def test_maybe_get_model_id_prefers_litellm_metadata_over_caller_metadata_without_a_deployment(): + processing_obj: Final = ProxyBaseLLMRequestProcessing( + data={ + "metadata": {"trace_id": "t-1"}, + "litellm_metadata": {"model_info": {"id": "vision"}}, + } + ) + + assert processing_obj.maybe_get_model_id(None) == "vision" + + +def test_maybe_get_model_id_returns_none_before_the_router_picked_a_deployment(): + assert ProxyBaseLLMRequestProcessing(data={"metadata": {}}).maybe_get_model_id(None) is None diff --git a/tests/unit/proxy/test_dynamic_mcp_route.py b/tests/unit/proxy/test_dynamic_mcp_route.py index 4a8dddb1bf4..dc5c1ba1b79 100644 --- a/tests/unit/proxy/test_dynamic_mcp_route.py +++ b/tests/unit/proxy/test_dynamic_mcp_route.py @@ -18,21 +18,20 @@ from unittest.mock import ANY, AsyncMock, MagicMock, patch import pytest from fastapi import HTTPException - # --------------------------------------------------------------------------- # helpers # --------------------------------------------------------------------------- -_MCP_MANAGER = "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" +_MCP_MANAGER = "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" _HANDLE_HTTP = ( - "litellm.proxy._experimental.mcp_server.server.handle_streamable_http_mcp" + "litellm.proxy.mcp_server.server.handle_streamable_http_mcp" ) _STREAM_ASGI = "litellm.proxy.proxy_server._stream_mcp_asgi_response" _PRISMA = "litellm.proxy.proxy_server.prisma_client" _IS_ACCESS_GROUP = "litellm.proxy.proxy_server._is_mcp_access_group_cached" _USER_API_KEY_CACHE = "litellm.proxy.proxy_server.user_api_key_cache" _GET_ACCESS_GROUP_SERVERS = ( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp." + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp." "MCPRequestHandler.get_mcp_servers_from_access_groups" ) _FORWARD = "litellm.proxy.proxy_server._mcp_forward_as_path" @@ -285,7 +284,7 @@ async def test_dynamic_mcp_route_resolves_toolset(): async def fake_stream(fn, scope, receive): nonlocal captured_toolset_id - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( mcp_active_toolset_id, ) @@ -545,7 +544,7 @@ async def test_toolset_mcp_route_unexpected_exception_returns_500_without_traceb # 7. Aggregate /mcp without a trailing slash (bare mount prefix) # --------------------------------------------------------------------------- -_IS_MCP_AVAILABLE = "litellm.proxy._experimental.mcp_server.utils.is_mcp_available" +_IS_MCP_AVAILABLE = "litellm.proxy.mcp_server.utils.is_mcp_available" def _test_client(): @@ -623,8 +622,8 @@ async def test_dynamic_route_observes_committed_peer_catalog_changes(monkeypatch from litellm.caching.caching import DualCache from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import mcp_server_manager from litellm.proxy._types import LiteLLM_MCPServerTable + from litellm.proxy.mcp_server import mcp_server_manager old_row = LiteLLM_MCPServerTable( server_id="catalog-route", server_name="previous", alias="previous", transport="http", diff --git a/tests/unit/proxy/test_litellm_pre_call_utils.py b/tests/unit/proxy/test_litellm_pre_call_utils.py index 64ff8392c02..a44373b87c8 100644 --- a/tests/unit/proxy/test_litellm_pre_call_utils.py +++ b/tests/unit/proxy/test_litellm_pre_call_utils.py @@ -1,4 +1,5 @@ import asyncio +import base64 import copy import json import os @@ -36,7 +37,6 @@ from litellm.litellm_core_utils.redact_messages import _get_turn_off_message_log from litellm.llms.bedrock.base_aws_llm import BaseAWSLLM from litellm.llms.fireworks_ai.common_utils import get_fireworks_session_id from litellm.proxy._types import AddTeamCallback, ProxyException, TeamCallbackMetadata, UserAPIKeyAuth -from litellm.types.litellm_params import AGENTIC_LOOP_KWARG_NAMES from litellm.proxy.litellm_pre_call_utils import ( KeyAndTeamLoggingSettings, LiteLLMProxyRequestSetup, @@ -58,6 +58,7 @@ from litellm.proxy.litellm_pre_call_utils import ( move_guardrails_to_metadata, ) from litellm.proxy.spend_tracking.spend_tracking_utils import get_logging_payload +from litellm.types.litellm_params import AGENTIC_LOOP_KWARG_NAMES from litellm.types.utils import CredentialItem @@ -926,6 +927,222 @@ async def test_add_litellm_data_to_request_body_snapshot_excludes_proxy_server_r assert snapshot_body["messages"] == [{"role": "user", "content": "hello"}] +FORWARD_PROVIDER_AUTH_HEADERS: Final = { + "forward_llm_provider_auth_headers": True, + "forward_client_headers_to_llm_api": True, +} + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + "sent,request_headers,general_settings,expected", + [ + ({"headers": {"Authorization": "Bearer sk-caller"}}, {}, {}, ("headers",)), + ({"headers": {"X-Trace-Id": "trace-1"}}, {}, {}, ("headers",)), + ({"headers": {}}, {}, {}, ()), + ({"extra_headers": {"API-Key": "caller-azure-key"}}, {}, {}, ("extra_headers",)), + ({"extra_headers": {"OpenAI-Project": "proj_caller"}}, {}, {}, ("extra_headers",)), + ( + {"provider_specific_header": {"custom_llm_provider": "openai", "extra_headers": {"x-api-key": "caller"}}}, + {}, + {}, + ("provider_specific_header",), + ), + ( + { + "provider_specific_header": [ + {"custom_llm_provider": "anthropic", "extra_headers": {"anthropic-beta": "tools"}}, + {"custom_llm_provider": "gemini", "extra_headers": {"X-Goog-Api-Key": "caller"}}, + ] + }, + {}, + {}, + ("provider_specific_header",), + ), + ( + { + "provider_specific_header": { + "custom_llm_provider": "anthropic", + "extra_headers": {"x-caller-trace": "x"}, + } + }, + {}, + {}, + ("provider_specific_header",), + ), + ( + { + "provider_specific_header": { + "custom_llm_provider": "anthropic", + "extra_headers": {"anthropic-version": "2023-06-01", "anthropic-beta": "tools-2024-04-04"}, + } + }, + {}, + {}, + (), + ), + ({"headers": {"Anthropic-Version": "2023-06-01"}}, {}, {}, ()), + ({"organization": "org-caller"}, {}, {}, ("organization",)), + ({"headers": "authorization", "provider_specific_header": "x-api-key"}, {}, {}, ()), + ( + {"api_key": "sk-caller", "headers": {"Ocp-Apim-Subscription-Key": "caller"}}, + {}, + {}, + ("api_key", "headers"), + ), + ({}, {"anthropic-beta": "tools-2024-04-04"}, {}, ()), + ({}, {"anthropic-version": "2023-06-01", "anthropic-beta": "tools-2024-04-04"}, {}, ()), + ({}, {"openai-organization": "org-caller"}, {"forward_openai_org_id": True}, ("organization",)), + ( + {}, + {"x-litellm-api-key": "sk-virtual", "authorization": "Bearer sk-ant-oat01-caller"}, + {}, + ("provider_specific_header",), + ), + ( + {}, + {"authorization": "Bearer sk-virtual", "x-goog-api-key": "AIza-caller"}, + FORWARD_PROVIDER_AUTH_HEADERS, + ("headers",), + ), + ( + {}, + {"authorization": "Bearer sk-virtual", "x-portkey-api-key": "caller-gateway-key"}, + FORWARD_PROVIDER_AUTH_HEADERS, + ("headers",), + ), + ({}, {"authorization": "Bearer sk-virtual"}, FORWARD_PROVIDER_AUTH_HEADERS, ()), + ], + ids=[ + "authorization-in-headers", + "plain-headers", + "empty-headers", + "api-key-in-extra-headers", + "openai-project-in-extra-headers", + "credential-in-provider-specific-header", + "credential-in-one-provider-specific-header-entry", + "plain-provider-specific-header", + "anthropic-version-and-beta-in-provider-specific-header", + "anthropic-version-in-headers", + "organization", + "malformed-header-fields", + "api-key-and-credential-headers", + "proxy-forwarded-anthropic-beta", + "proxy-forwarded-anthropic-sdk-headers", + "proxy-forwarded-openai-organization", + "proxy-forwarded-anthropic-oauth-token", + "proxy-forwarded-provider-auth-header", + "proxy-forwarded-gateway-key", + "proxy-forwarding-nothing", + ], +) +async def test_caller_credential_fields_name_every_field_that_carries_a_caller_header_or_credential( + sent: dict[str, object], + request_headers: dict[str, str], + general_settings: dict[str, object], + expected: tuple[str, ...], +) -> None: + updated: Final = await _request_data_added_by_the_proxy(sent, request_headers, general_settings) + + assert updated["proxy_server_request"]["caller_credential_fields"] == expected + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + "request_headers,expected", + [({}, ()), ({"x-caller-trace": "trace-1"}, ("headers",))], + ids=["user-information-only", "user-information-and-caller-header"], +) +async def test_caller_credential_fields_ignore_the_user_information_the_proxy_adds_to_forwarded_headers( + monkeypatch: pytest.MonkeyPatch, request_headers: dict[str, str], expected: tuple[str, ...] +) -> None: + monkeypatch.setattr(litellm, "add_user_information_to_llm_headers", True) + + updated: Final = await _request_data_added_by_the_proxy({}, request_headers, FORWARD_PROVIDER_AUTH_HEADERS) + + assert updated["headers"]["x-litellm-user_api_key_user_id"] == "test-user" + assert updated["proxy_server_request"]["caller_credential_fields"] == expected + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + "sent,request_headers,general_settings,expected", + [ + ({"headers": {"Anthropic-Version": "2023-06-01"}}, {}, {}, ("headers",)), + ( + { + "provider_specific_header": { + "custom_llm_provider": "anthropic", + "extra_headers": {"anthropic-version": "2023-06-01"}, + } + }, + {}, + {}, + ("provider_specific_header",), + ), + ({"organization": "org-caller"}, {}, {}, ()), + ({"extra_headers": {"API-Key": "caller-azure-key"}}, {}, {}, ()), + ( + {"api_key": "sk-caller", "headers": {"Ocp-Apim-Subscription-Key": "caller"}}, + {}, + {}, + ("api_key", "headers"), + ), + ({}, {"openai-organization": "org-caller"}, {"forward_openai_org_id": True}, ()), + ( + {}, + {"authorization": "Bearer sk-virtual", "x-goog-api-key": "AIza-caller"}, + FORWARD_PROVIDER_AUTH_HEADERS, + (), + ), + ], + ids=[ + "anthropic-version-in-headers", + "anthropic-version-in-provider-specific-header", + "organization", + "api-key-in-extra-headers", + "api-key-and-credential-headers", + "proxy-forwarded-openai-organization", + "proxy-forwarded-provider-auth-header", + ], +) +async def test_credential_fields_name_the_stripped_fields_the_caller_sent( + sent: dict[str, object], + request_headers: dict[str, str], + general_settings: dict[str, object], + expected: tuple[str, ...], +) -> None: + updated: Final = await _request_data_added_by_the_proxy(sent, request_headers, general_settings) + + assert updated["proxy_server_request"]["credential_fields"] == expected + + +async def _request_data_added_by_the_proxy( + sent: dict[str, object], request_headers: dict[str, str], general_settings: dict[str, object] +) -> dict: + from litellm.proxy.litellm_pre_call_utils import add_litellm_data_to_request + + request_mock: Final = MagicMock(spec=Request) + request_mock.url = MagicMock() + request_mock.url.__str__.return_value = "http://localhost/v1/chat/completions" + request_mock.url.path = "/v1/chat/completions" + request_mock.method = "POST" + request_mock.query_params = {} + request_mock.headers = {"content-type": "application/json", **request_headers} + request_mock.client = MagicMock() + request_mock.client.host = "127.0.0.1" + data: Final = {"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "hello"}], **sent} + + return await add_litellm_data_to_request( + data=data, + request=request_mock, + user_api_key_dict=UserAPIKeyAuth(api_key="hashed-key", user_id="test-user"), + proxy_config=MagicMock(), + general_settings=dict(general_settings), + version="test-version", + ) + + def test_initial_snapshot_refresh_clears_a_previous_guardrail_checkpoint() -> None: from litellm.integrations.shadow_eval_logger import GuardrailRequestSnapshot from litellm.litellm_core_utils.litellm_logging import Logging @@ -9208,6 +9425,97 @@ def test_default_team_settings_bool_turn_off_message_logging_redacts(): ) +def _fake_chatgpt_oauth_token(account_id: str) -> str: + header = base64.urlsafe_b64encode(b'{"alg":"RS256"}').rstrip(b"=").decode() + payload = ( + base64.urlsafe_b64encode( + json.dumps({"https://api.openai.com/auth": {"chatgpt_account_id": account_id}, "exp": 4102444800}).encode() + ) + .rstrip(b"=") + .decode() + ) + return f"{header}.{payload}.fake-signature" + + +CHATGPT_OAUTH_TOKEN = f"Bearer {_fake_chatgpt_oauth_token('acct-alice')}" +CHATGPT_ACCOUNT_ID_HEADER_NAME = "ChatGPT-Account-Id" +PLATFORM_API_KEY_BEARER = "Bearer sk-proj-fake-platform-key-0123456789" +CHATGPT_LEAK_TARGET_PROVIDERS = ["openai", "azure", "anthropic", "bedrock", "vertex_ai"] + + +def _codex_client_headers( + authorization_header_name: str = "authorization", account_id: str | None = "acct-alice" +) -> dict: + return { + "content-type": "application/json", + "originator": "codex_cli_rs", + authorization_header_name: CHATGPT_OAUTH_TOKEN, + **({CHATGPT_ACCOUNT_ID_HEADER_NAME: account_id} if account_id is not None else {}), + } + + +def test_clean_headers_keeps_chatgpt_oauth_bearer_when_gateway_key_is_separate(): + result = clean_headers( + headers=Headers({**_codex_client_headers(), "x-litellm-api-key": "sk-proxy-virtual-key"}), + litellm_key_header_name="x-litellm-api-key", + forward_llm_provider_auth_headers=False, + authenticated_with_header="x-litellm-api-key", + ) + + assert result["authorization"] == CHATGPT_OAUTH_TOKEN + assert "x-litellm-api-key" not in result + + +def test_clean_headers_drops_bearer_that_authenticated_to_the_gateway(): + result = clean_headers( + headers=Headers({"authorization": CHATGPT_OAUTH_TOKEN, "content-type": "application/json"}), + litellm_key_header_name=None, + forward_llm_provider_auth_headers=False, + authenticated_with_header="authorization", + ) + + assert _authorization_values(result) == [] + + +@pytest.mark.parametrize("bearer", [PLATFORM_API_KEY_BEARER, "Bearer not.a-jwt", "Bearer a.bm90LWpzb24.c"]) +def test_clean_headers_drops_non_chatgpt_bearers(bearer): + result = clean_headers( + headers=Headers({"authorization": bearer, "x-litellm-api-key": "sk-proxy-virtual-key"}), + litellm_key_header_name="x-litellm-api-key", + forward_llm_provider_auth_headers=False, + authenticated_with_header="x-litellm-api-key", + ) + + assert _authorization_values(result) == [] + + +@pytest.mark.parametrize("authorization_header_name", AUTHORIZATION_HEADER_CASINGS) +def test_chatgpt_oauth_credential_and_account_reach_chatgpt_provider(authorization_header_name): + forwarded = _headers_forwarded_to(_codex_client_headers(authorization_header_name), "chatgpt") + + assert _authorization_values(forwarded) == [CHATGPT_OAUTH_TOKEN] + assert forwarded[CHATGPT_ACCOUNT_ID_HEADER_NAME] == "acct-alice" + + +@pytest.mark.parametrize("custom_llm_provider", CHATGPT_LEAK_TARGET_PROVIDERS) +def test_chatgpt_oauth_credential_is_never_forwarded_to_other_providers(custom_llm_provider): + forwarded = _headers_forwarded_to(_codex_client_headers(), custom_llm_provider) + + assert _authorization_values(forwarded) == [] + assert CHATGPT_OAUTH_TOKEN not in forwarded.values() + assert CHATGPT_ACCOUNT_ID_HEADER_NAME not in forwarded + + +def test_chatgpt_account_header_is_not_forwarded_without_chatgpt_oauth_bearer(): + headers = {**_codex_client_headers(), "authorization": PLATFORM_API_KEY_BEARER} + + assert _headers_forwarded_to(headers, "chatgpt") == {} + + +def test_anthropic_oauth_bearer_does_not_reach_chatgpt_provider(): + assert _authorization_values(_headers_forwarded_to(_client_headers(), "chatgpt")) == [] + + def test_add_user_api_key_auth_to_request_metadata_attributes_a_cli_session_to_its_alias(): data = {"model": "gpt-5.4-nano", "messages": [{"role": "user", "content": "hi"}], "litellm_metadata": {}} session = UserAPIKeyAuth( @@ -9268,7 +9576,7 @@ async def test_mcp_credentials_only_removed_from_logging_copies(path: str, custo with ( patch("litellm.proxy.proxy_server.general_settings", settings), patch.dict( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager.config_mcp_servers", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager.config_mcp_servers", {"header-test": server}, clear=True, ), @@ -10063,8 +10371,8 @@ class TestResolveUserProviderCredentials: _get_hierarchical_router_settings) must be part of discovery.""" from types import SimpleNamespace - from litellm.proxy.litellm_pre_call_utils import _resolve_user_provider_credentials_for_request import litellm.proxy.auth.auth_checks as auth_checks + from litellm.proxy.litellm_pre_call_utils import _resolve_user_provider_credentials_for_request table = self._env(monkeypatch) monkeypatch.setattr( diff --git a/tests/unit/proxy/test_pricing_field_strip.py b/tests/unit/proxy/test_pricing_field_strip.py index 3e9bee9217d..c4a14b39f54 100644 --- a/tests/unit/proxy/test_pricing_field_strip.py +++ b/tests/unit/proxy/test_pricing_field_strip.py @@ -22,6 +22,7 @@ from litellm.proxy.litellm_pre_call_utils import ( _CLIENT_PRICING_METADATA_FIELDS, _strip_client_pricing_overrides, add_litellm_data_to_request, + strip_client_guardrail_information, ) from litellm.types.utils import CustomPricingLiteLLMParams @@ -133,7 +134,7 @@ class TestStripClientPricingOverrides: "standard_logging_guardrail_information": [{"guardrail_cost": 5.0}], }, } - _strip_client_pricing_overrides(data) + strip_client_guardrail_information(data) assert data["metadata"] == {"user_session": "keep-me"} assert data["litellm_metadata"] == {} @@ -164,7 +165,6 @@ class TestStripClientPricingOverrides: def test_metadata_field_set_contains_model_info(self): assert "model_info" in _CLIENT_PRICING_METADATA_FIELDS - assert "standard_logging_guardrail_information" in _CLIENT_PRICING_METADATA_FIELDS def test_strip_emits_debug_log_listing_dropped_fields(self, caplog): # Operators need a paper trail so they can diagnose why a previously @@ -315,6 +315,33 @@ async def test_add_litellm_data_to_request_skips_strip_with_key_opt_in(): assert updated["base_model"] == "gpt-4o-mini" +@pytest.mark.asyncio +@pytest.mark.parametrize("opt_in_field", ["metadata", "team_metadata"]) +async def test_add_litellm_data_to_request_strips_guardrail_information_despite_pricing_opt_in(opt_in_field): + data = { + "model": "gpt-4", + "messages": [{"role": "user", "content": "hi"}], + "input_cost_per_token": 0.0001, + "metadata": { + "user_session": "keep-me", + "standard_logging_guardrail_information": [{"guardrail_name": "forged", "guardrail_cost": 5.0}], + }, + } + + updated = await add_litellm_data_to_request( + data=data, + request=_make_request_mock(), + user_api_key_dict=_user_api_key_auth(**{opt_in_field: {"allow_client_pricing_override": True}}), + proxy_config=MagicMock(), + general_settings={}, + version="test-version", + ) + + assert updated["input_cost_per_token"] == 0.0001 + assert updated["metadata"]["user_session"] == "keep-me" + assert "standard_logging_guardrail_information" not in updated["metadata"] + + @pytest.mark.asyncio async def test_add_litellm_data_to_request_strips_json_string_litellm_metadata(): """``litellm_metadata`` may arrive as a JSON-encoded string (multipart/ diff --git a/tests/unit/proxy/test_proxy_server_endpoints_and_startup.py b/tests/unit/proxy/test_proxy_server_endpoints_and_startup.py index 14196d4a1ac..8c62b225992 100644 --- a/tests/unit/proxy/test_proxy_server_endpoints_and_startup.py +++ b/tests/unit/proxy/test_proxy_server_endpoints_and_startup.py @@ -29,9 +29,9 @@ import litellm import litellm.proxy.proxy_server as proxy_server_module from litellm._internal_context import current_service_target from litellm.caching.caching import RedisCache +from litellm.caching.dual_cache import DualCache from litellm.caching.redis_cluster_cache import RedisClusterCache from litellm.litellm_core_utils.get_model_cost_map import ModelCostMapReloaded -from litellm.caching.dual_cache import DualCache from litellm.proxy._types import ( AwsErrorTypeProxyException, LitellmUserRoles, @@ -9335,8 +9335,8 @@ async def test_increment_spend_counters_reseeds_from_db_on_bad_reserved_counter( from the authoritative DB and adds this request's settled cost, which the async spend flush has not written yet, so budget gating continues.""" from litellm.caching.dual_cache import DualCache - from litellm.proxy.proxy_server import increment_spend_counters from litellm.proxy.db.spend_counter_reseed import SpendCounterReseed + from litellm.proxy.proxy_server import increment_spend_counters counter_cache = DualCache() budget_reservation = { @@ -12350,8 +12350,8 @@ def _config_field_info_client(monkeypatch, user_role): from fastapi.testclient import TestClient import litellm.proxy.proxy_server as ps - from litellm.proxy.config_resolvers import SettingsStore from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.config_resolvers import SettingsStore from litellm.proxy.proxy_server import app db_record = types.SimpleNamespace( @@ -13742,11 +13742,11 @@ def test_startup_is_silent_when_mock_testing_params_disabled(caplog): def _window_spend_enqueue_env(cached_objects: dict): """Point increment_spend_counters at throwaway caches and a real WindowSpendUpdateQueue, and hand back the queue to inspect.""" + import litellm.proxy.proxy_server as ps from litellm.caching.dual_cache import DualCache from litellm.proxy.db.db_transaction_queue.window_spend_update_queue import ( WindowSpendUpdateQueue, ) - import litellm.proxy.proxy_server as ps user_api_key_cache = MagicMock() user_api_key_cache.async_get_cache = AsyncMock(side_effect=lambda key, **_: cached_objects.get(key)) @@ -13825,8 +13825,8 @@ async def test_team_window_spend_row_is_enqueued(): async def test_window_spend_row_is_enqueued_even_when_the_counter_was_reserved(): """A reservation only pre-charged the cache counter with an estimate; the row still owes the actual cost, so the enqueue must not be skipped.""" - from litellm.proxy.proxy_server import increment_spend_counters import litellm.proxy.spend_tracking.budget_reservation as br + from litellm.proxy.proxy_server import increment_spend_counters reset_at = datetime.now(timezone.utc) + timedelta(days=10) key_obj = MagicMock() @@ -15166,7 +15166,7 @@ async def test_update_general_settings_keeps_yaml_openai_websocket_passthrough() def test_settings_store_exposes_dashboard_saved_mcp_client_allowlist_to_the_mcp_gateway() -> None: - from litellm.proxy._experimental.mcp_server.client_allowlist import MCPClientAllowlist, load_mcp_client_allowlist + from litellm.proxy.mcp_server.client_allowlist import MCPClientAllowlist, load_mcp_client_allowlist from litellm.proxy.proxy_server import ProxyConfig settings: Final = ProxyConfig().settings @@ -15207,21 +15207,23 @@ async def test_token_counter_keeps_the_event_loop_free_during_a_huggingface_coun assert_loop_stayed_free(took, lags) -async def test_token_counter_loads_a_custom_tokenizer_off_the_event_loop(monkeypatch): - from litellm.rust_bridge._native import Tokenizer +async def test_token_counter_loads_a_custom_tokenizer_off_the_event_loop(monkeypatch: pytest.MonkeyPatch) -> None: + from queue import SimpleQueue + from threading import Thread, current_thread + + from tokenizers import Tokenizer from litellm import Router - from tests.unit.litellm_core_utils.event_loop_lag import assert_loop_stayed_free, timed_with_loop_lags - claude_tokenizer: Final = litellm.utils.select_tokenizer("claude-fable-5")["tokenizer"] + claude_tokenizer: Final = Tokenizer.from_str(litellm.utils.claude_json_str) + loop_thread: Final = current_thread() + loader_threads: Final[SimpleQueue[Thread]] = SimpleQueue() - class SlowHubTokenizer: - @staticmethod - def from_pretrained(identifier: str, revision: str = "main", token: str | None = None) -> Tokenizer: - time.sleep(0.3) - return claude_tokenizer + def from_pretrained(identifier: str, revision: str = "main", token: str | None = None) -> Tokenizer: + loader_threads.put(current_thread()) + return claude_tokenizer - monkeypatch.setattr("litellm.rust_bridge.tokenizer.from_pretrained", SlowHubTokenizer.from_pretrained) + monkeypatch.setattr("tokenizers.Tokenizer", types.SimpleNamespace(from_pretrained=from_pretrained)) monkeypatch.setattr( "litellm.proxy.proxy_server.llm_router", Router( @@ -15237,21 +15239,21 @@ async def test_token_counter_loads_a_custom_tokenizer_off_the_event_loop(monkeyp ), ) - response, took, lags = await timed_with_loop_lags( - lambda: proxy_server_module.token_counter( + litellm.utils._select_custom_tokenizer_helper.cache_clear() + try: + response: Final = await proxy_server_module.token_counter( TokenCountRequest(model="self-hosted", prompt="count me off the loop") ) - ) - - assert response.tokenizer_type == "huggingface_tokenizer" - assert response.total_tokens > 0 - assert_loop_stayed_free(took, lags) + assert loader_threads.get_nowait() is not loop_thread + assert response.tokenizer_type == "huggingface_tokenizer" + assert response.total_tokens > 0 + finally: + litellm.utils._select_custom_tokenizer_helper.cache_clear() async def test_token_counter_loads_a_custom_tokenizer_once_per_identifier_revision_and_token(monkeypatch): - from litellm.rust_bridge._native import Tokenizer - from litellm import Router + from litellm.rust_bridge._native import Tokenizer from litellm.types.router import DeploymentTypedDict claude_tokenizer: Final[Tokenizer] = litellm.utils.select_tokenizer("claude-fable-5")["tokenizer"] @@ -15304,13 +15306,13 @@ async def test_auth_cache_invalidation_subscriber_evicts_byok_credentials_cached """A peer worker's BYOK revocation broadcast must reach this worker's BYOK credential cache.""" from redis.asyncio import Redis - from litellm.proxy._experimental.mcp_server.byok_credential_cache import ( + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.byok_credential_cache import ( byok_credential_cache, byok_credential_cache_key, cache_byok_credential, get_cached_byok_credential, ) - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache class _QueuePubSub: def __init__(self, messages: list[object]) -> None: @@ -15584,4 +15586,3 @@ async def test_spend_capture_rate_check_job_clears_the_gauge_once_the_setting_is call(api_provider="openai", capture_rate=0.97), call(api_provider="openai", capture_rate=None), ] - diff --git a/tests/unit/proxy/test_proxy_utils_model_creation_and_error_logging.py b/tests/unit/proxy/test_proxy_utils_model_creation_and_error_logging.py index b5940e4c212..bc13595df6c 100644 --- a/tests/unit/proxy/test_proxy_utils_model_creation_and_error_logging.py +++ b/tests/unit/proxy/test_proxy_utils_model_creation_and_error_logging.py @@ -127,51 +127,132 @@ async def test_proxy_only_error_log_marks_no_upstream_llm_call(): @pytest.mark.asyncio -async def test_proxy_only_error_log_keeps_litellm_metadata_in_litellm_params(): - """Responses API requests carry guardrail info under ``litellm_metadata`` - (not ``metadata``). It must land in litellm_params so - ``merge_litellm_metadata`` can surface ``guardrail_information`` in the - spend-log failure row, matching the chat completions path.""" - from litellm.proxy._types import UserAPIKeyAuth +@pytest.mark.parametrize("metadata_field", ["metadata", "litellm_metadata"]) +async def test_proxy_only_error_log_drops_caller_guardrail_information_without_logging_object( + metadata_field: str, + monkeypatch: pytest.MonkeyPatch, +) -> None: + monkeypatch.setattr(litellm, "callbacks", []) + monkeypatch.setattr(litellm, "input_callback", []) + monkeypatch.setattr(litellm, "failure_callback", []) + monkeypatch.setattr(litellm, "_async_failure_callback", []) + guardrail_info: Final = [ + { + "guardrail_name": "caller-guardrail", + "guardrail_status": "guardrail_intervened", + "guardrail_cost": 123.45, + } + ] + request_data: Final[dict[str, object]] = { + "model": "gpt-4o", + "messages": [{"role": "user", "content": "hi"}], + metadata_field: {"tags": ["t"], "standard_logging_guardrail_information": guardrail_info}, + } - proxy_logging_obj = ProxyLogging(user_api_key_cache=DualCache()) - captured = {} - guardrail_info = [{"guardrail_name": "test-guard", "guardrail_status": "blocked"}] + await ProxyLogging(user_api_key_cache=DualCache())._handle_logging_proxy_only_error( + request_data=request_data, + user_api_key_dict=UserAPIKeyAuth(api_key="sk-rejected", team_id="team-a", request_route="/v1/chat/completions"), + route="/v1/chat/completions", + original_exception=HTTPException(status_code=400, detail="blocked"), + ) - def fake_update_environment_variables(self, *args, **kwargs): - captured["litellm_params"] = kwargs.get("litellm_params") - captured["optional_params"] = kwargs.get("optional_params") + details: Final = request_data["litellm_logging_obj"].model_call_details + assert details["standard_logging_object"] is not None + assert details["litellm_params"][metadata_field]["tags"] == ["t"] + assert "standard_logging_guardrail_information" not in details["litellm_params"][metadata_field] + assert "guardrail_cost" not in str(details["standard_logging_object"]) + assert "litellm_metadata" not in details["optional_params"] - from litellm.litellm_core_utils.litellm_logging import Logging - orig_update_env = Logging.update_environment_variables - orig_pre_call = Logging.pre_call - orig_async_failure = Logging.async_failure_handler +@pytest.mark.asyncio +@pytest.mark.parametrize("metadata_field", ["metadata", "litellm_metadata"]) +async def test_proxy_only_error_log_keeps_tags_and_drops_caller_logging_fields( + metadata_field: str, +) -> None: + request_data: Final[dict[str, object]] = { + "model": "gpt-4o", + "messages": [{"role": "user", "content": "hi"}], + metadata_field: { + "langsmith_base_url": "https://caller.invalid", + "langsmith_api_key": "caller-key", + "tags": ["t"], + "user_api_key_team_id": "caller-team", + "user_api_key_hash": "caller-hash", + "user_api_key_auth_metadata": {"caller": "metadata"}, + }, + "langsmith_base_url": "https://caller.invalid", + "standard_callback_dynamic_params": {"gcs_path_service_account": "/caller/sa.json"}, + } - async def _noop_async_failure(self, *args, **kwargs): - return None + await ProxyLogging(user_api_key_cache=DualCache())._handle_logging_proxy_only_error( + request_data=request_data, + user_api_key_dict=UserAPIKeyAuth(api_key="sk-rejected", team_id="team-a", request_route="/v1/chat/completions"), + route="/v1/chat/completions", + original_exception=Exception("bad key"), + ) - Logging.update_environment_variables = fake_update_environment_variables - Logging.pre_call = lambda self, *args, **kwargs: None - Logging.async_failure_handler = _noop_async_failure - try: - await proxy_logging_obj._handle_logging_proxy_only_error( - request_data={ - "model": "gpt-4o", - "input": "blocked prompt", - "litellm_metadata": {"standard_logging_guardrail_information": guardrail_info}, - }, - user_api_key_dict=UserAPIKeyAuth(api_key="sk-9876", request_route="/v1/responses"), - route="/v1/responses", - original_exception=HTTPException(status_code=400, detail="blocked"), - ) - finally: - Logging.update_environment_variables = orig_update_env - Logging.pre_call = orig_pre_call - Logging.async_failure_handler = orig_async_failure + details: Final = request_data["litellm_logging_obj"].model_call_details + assert "caller" not in str(details["standard_callback_dynamic_params"]) + assert "langsmith_base_url" not in details + assert "caller" not in str(details["litellm_params"]) + assert details["litellm_params"][metadata_field]["tags"] == ["t"] + assert details["litellm_params"]["metadata"]["user_api_key_team_id"] == "team-a" + assert details["litellm_params"][metadata_field]["user_api_key_team_id"] == "team-a" - assert captured["litellm_params"]["litellm_metadata"]["standard_logging_guardrail_information"] == guardrail_info - assert "litellm_metadata" not in captured["optional_params"] + +@pytest.mark.asyncio +@pytest.mark.parametrize("metadata_field", ["metadata", "litellm_metadata"]) +async def test_proxy_only_error_log_drops_malformed_metadata_tags(metadata_field: str) -> None: + guardrail_info: Final = [{"guardrail_name": "g", "guardrail_status": "guardrail_intervened"}] + request_data: Final[dict[str, object]] = { + "model": "gpt-4o", + "messages": [{"role": "user", "content": "hi"}], + metadata_field: {"tags": 123, "standard_logging_guardrail_information": guardrail_info}, + } + + await ProxyLogging(user_api_key_cache=DualCache())._handle_logging_proxy_only_error( + request_data=request_data, + user_api_key_dict=UserAPIKeyAuth(api_key="sk-rejected", team_id="team-a", request_route="/v1/chat/completions"), + route="/v1/chat/completions", + original_exception=Exception("bad key"), + ) + + details: Final = request_data["litellm_logging_obj"].model_call_details + assert details["standard_logging_object"] is not None + assert "tags" not in details["litellm_params"][metadata_field] + assert "standard_logging_guardrail_information" not in details["litellm_params"][metadata_field] + + +@pytest.mark.asyncio +@pytest.mark.parametrize("metadata_field", ["metadata", "litellm_metadata"]) +async def test_proxy_only_error_log_builds_payload_when_logging_object_has_malformed_tags( + metadata_field: str, +) -> None: + request_data: Final[dict[str, object]] = { + "model": "gpt-4o", + "messages": [{"role": "user", "content": "hi"}], + "litellm_call_id": "malformed-tags-call", + metadata_field: {"tags": 123}, + } + logging_obj, _ = litellm.utils.function_setup( + original_function="acompletion", + rules_obj=litellm.utils.Rules(), + start_time=real_datetime.datetime.now(), + **request_data, + ) + + await ProxyLogging(user_api_key_cache=DualCache())._handle_logging_proxy_only_error( + request_data={**request_data, "litellm_logging_obj": logging_obj}, + user_api_key_dict=UserAPIKeyAuth(api_key="sk-blocked", team_id="team-a", request_route="/v1/chat/completions"), + route="/v1/chat/completions", + original_exception=HTTPException(status_code=400, detail="Content blocked"), + ) + + standard_logging_object: Final = logging_obj.model_call_details["standard_logging_object"] + assert standard_logging_object is not None + assert standard_logging_object["model"] == request_data["model"] + assert standard_logging_object["metadata"]["user_api_key_team_id"] == "team-a" + assert 123 not in standard_logging_object["request_tags"] @pytest.mark.asyncio diff --git a/tests/unit/proxy/types_utils/test_get_instance_fn_runtime_gate.py b/tests/unit/proxy/types_utils/test_get_instance_fn_runtime_gate.py index 3d76ad54a9c..3b0672b306e 100644 --- a/tests/unit/proxy/types_utils/test_get_instance_fn_runtime_gate.py +++ b/tests/unit/proxy/types_utils/test_get_instance_fn_runtime_gate.py @@ -151,7 +151,7 @@ def test_mcp_tool_registry_threads_config_file_path(): # MCP tool handlers declared in ``config.yaml`` mcp_tools[].handler # may legitimately be ``s3://...``; the YAML-load path must thread # ``config_file_path`` so they resolve. - from litellm.proxy._experimental.mcp_server import tool_registry as tr + from litellm.proxy.mcp_server import tool_registry as tr fake_handler = lambda **kwargs: None # noqa: E731 — registry requires callable with patch.object(tr, "get_instance_fn", return_value=fake_handler) as mock_get: diff --git a/tests/unit/proxy/ui_crud_endpoints/test_proxy_setting_endpoints.py b/tests/unit/proxy/ui_crud_endpoints/test_proxy_setting_endpoints.py index 512f58380ea..4360655c8ca 100644 --- a/tests/unit/proxy/ui_crud_endpoints/test_proxy_setting_endpoints.py +++ b/tests/unit/proxy/ui_crud_endpoints/test_proxy_setting_endpoints.py @@ -1,6 +1,8 @@ import json import os +from collections.abc import Iterator from typing import Final +from unittest.mock import patch import pytest from fastapi.testclient import TestClient @@ -181,6 +183,12 @@ def mock_auth(): app.dependency_overrides.pop(user_api_key_auth, None) +@pytest.fixture(autouse=True) +def isolated_environment() -> Iterator[None]: + with patch.dict(os.environ): + yield + + @pytest.fixture(autouse=True) def fresh_settings_store(monkeypatch: pytest.MonkeyPatch) -> None: from litellm.proxy import proxy_server @@ -1351,35 +1359,45 @@ class TestProxySettingEndpoints: assert values["logo_url"] == "https://cdn.example.com/logo.png" assert values["favicon_url"] == "https://cdn.example.com/favicon.ico" + @pytest.mark.parametrize("env_logo", [ + "https://env.example.com/logo.png", "/mnt/secret/internal/logo.png", + ]) def test_get_ui_theme_settings_stored_value_wins_over_env( - self, mock_auth, monkeypatch - ): + self, monkeypatch: pytest.MonkeyPatch, env_logo: str, + ) -> None: """A stored ui_theme_config field outranks the env var for that field. The env fallback only fills fields the stored config leaves blank, so the UI-driven flow is unchanged while an unstored field still resolves. """ from litellm.proxy.proxy_server import proxy_config + from litellm.proxy.ui_crud_endpoints.proxy_setting_endpoints import UIThemeSettingsResponse - stored_config = { + stored_config: Final[dict[str, object]] = { "litellm_settings": { - "ui_theme_config": {"logo_url": "https://db.example.com/logo.png"} + "ui_theme_config": { + "logo_url": "https://db.example.com/logo.png", + "logo_url_dark": "https://db.example.com/logo-dark.png", + } } } - async def mock_get_config(): + async def mock_get_config() -> dict[str, object]: return stored_config monkeypatch.setattr(proxy_config, "get_config", mock_get_config) - monkeypatch.setenv("UI_LOGO_PATH", "https://env.example.com/logo.png") + monkeypatch.setenv("UI_LOGO_PATH", env_logo) + monkeypatch.setenv("UI_LOGO_PATH_DARK", env_logo) monkeypatch.setenv("LITELLM_FAVICON_URL", "https://env.example.com/favicon.ico") - response = client.get("/get/ui_theme_settings") + response: Final = client.get("/get/ui_theme_settings") assert response.status_code == 200 - values = response.json()["values"] - assert values["logo_url"] == "https://db.example.com/logo.png" - assert values["favicon_url"] == "https://env.example.com/favicon.ico" + result: Final = UIThemeSettingsResponse.model_validate(response.json()) + assert result.values["logo_url"] == "https://db.example.com/logo.png" + assert result.values["logo_url_dark"] == "https://db.example.com/logo-dark.png" + assert result.values["favicon_url"] == "https://env.example.com/favicon.ico" + assert (result.logo_url_via_proxy, result.logo_url_dark_via_proxy) == (False, False) def test_get_ui_theme_settings_reports_unset_when_absent_everywhere( self, mock_proxy_config, monkeypatch @@ -1395,22 +1413,45 @@ class TestProxySettingEndpoints: assert values["logo_url"] is None assert values["favicon_url"] is None - def test_get_ui_theme_settings_does_not_disclose_local_path_env_value( - self, mock_proxy_config, monkeypatch - ): - """This endpoint is public, so an env-configured local filesystem branding - path must never be surfaced to anonymous callers; only public http(s) URLs. - """ - monkeypatch.setenv("UI_LOGO_PATH", "/mnt/secret/internal/logo.png") + @pytest.mark.usefixtures("mock_proxy_config") + @pytest.mark.parametrize("light,public_light,light_via_proxy", [ + (None, None, False), + (" ", None, False), + ("https://cdn.example.com/light.png", "https://cdn.example.com/light.png", False), + ("/mnt/secret/internal/light.png", None, True), + ]) + @pytest.mark.parametrize("dark,public_dark,dark_via_proxy", [ + (None, None, False), + (" ", None, False), + ("https://cdn.example.com/dark.png", "https://cdn.example.com/dark.png", False), + ("/mnt/secret/internal/dark.png", None, True), + ]) + def test_get_ui_theme_settings_separates_private_logo_rendering_from_settings( + self, monkeypatch: pytest.MonkeyPatch, + light: str | None, public_light: str | None, light_via_proxy: bool, + dark: str | None, public_dark: str | None, dark_via_proxy: bool, + ) -> None: + from litellm.proxy.ui_crud_endpoints.proxy_setting_endpoints import UIThemeSettingsResponse + + for key, value in (("UI_LOGO_PATH", light), ("UI_LOGO_PATH_DARK", dark)): + if value is None: + monkeypatch.delenv(key, raising=False) + else: + monkeypatch.setenv(key, value) monkeypatch.setenv("LITELLM_FAVICON_URL", "file:///etc/favicon.ico") - response = client.get("/get/ui_theme_settings") + response: Final = client.get("/get/ui_theme_settings") assert response.status_code == 200 - values = response.json()["values"] - # the local path / file scheme is withheld rather than disclosed - assert values["logo_url"] is None - assert values["favicon_url"] is None + result: Final = UIThemeSettingsResponse.model_validate(response.json()) + assert (result.values["logo_url"], result.values["logo_url_dark"]) == (public_light, public_dark) + assert (result.logo_url_via_proxy, result.logo_url_dark_via_proxy) == (light_via_proxy, dark_via_proxy) + assert result.values["favicon_url"] is None + assert "/mnt/secret/internal/" not in response.text + assert "file:///etc/favicon.ico" not in response.text + for hint in ("logo_url_via_proxy", "logo_url_dark_via_proxy"): + assert hint not in result.values + assert hint not in json.dumps(result.field_schema) def test_get_ui_settings(self, mock_auth, monkeypatch): """Test retrieving UI settings with allowlist sanitization""" @@ -4345,3 +4386,105 @@ class TestMoyaiUrlSetting: await update_ui_settings({"moyai_url": None}, actor) assert persisted["moyai_url"] is None + + +@pytest.mark.parametrize("preset", ["today", "last_7_days", "last_30_days", "month_to_date", "year_to_date"]) +def test_usage_default_range_round_trips_without_overwriting_other_settings( + mock_auth, monkeypatch: pytest.MonkeyPatch, preset: str, +) -> None: + from types import SimpleNamespace + from unittest.mock import AsyncMock, MagicMock + from litellm.proxy import proxy_server + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.auth.user_api_key_auth import user_api_key_auth + from litellm.proxy.config_resolvers import SettingsStore + + prisma: Final = MagicMock() + prisma.db.litellm_uisettings.find_unique = AsyncMock(return_value=SimpleNamespace( + ui_settings={"disable_custom_api_keys": True}, + )) + prisma.db.litellm_uisettings.upsert = AsyncMock() + monkeypatch.setattr(proxy_server, "prisma_client", prisma) + monkeypatch.setattr(proxy_server, "store_model_in_db", True) + monkeypatch.setattr(proxy_server.proxy_config, "settings", SettingsStore("general_settings")) + actor: Final = UserAPIKeyAuth(user_id="test-admin", user_role=LitellmUserRoles.PROXY_ADMIN) + app.dependency_overrides[user_api_key_auth] = lambda: actor + try: + initial: Final = client.get("/get/ui_settings") + assert initial.json()["values"]["usage_default_time_range"] == "last_7_days" + response: Final = client.patch("/update/ui_settings", json={"usage_default_time_range": preset}) + assert response.status_code == 200, response.text + stored: Final = json.loads(prisma.db.litellm_uisettings.upsert.call_args.kwargs["data"]["update"]["ui_settings"]) + assert stored == {"disable_custom_api_keys": True, "usage_default_time_range": preset} + prisma.db.litellm_uisettings.find_unique.return_value = SimpleNamespace(ui_settings=stored) + fetched: Final = client.get("/get/ui_settings") + assert fetched.json()["values"]["usage_default_time_range"] == preset + assert fetched.json()["source"]["usage_default_time_range"] == "db" + finally: + app.dependency_overrides.clear() + + +@pytest.mark.parametrize("submitted", ["invalid", None, 7]) +def test_usage_default_range_rejects_invalid_values_without_writing( + mock_auth, monkeypatch: pytest.MonkeyPatch, submitted: object, +) -> None: + from unittest.mock import AsyncMock, MagicMock + from litellm.proxy import proxy_server + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.auth.user_api_key_auth import user_api_key_auth + + prisma: Final = MagicMock() + prisma.db.litellm_uisettings.upsert = AsyncMock() + monkeypatch.setattr(proxy_server, "prisma_client", prisma) + monkeypatch.setattr(proxy_server, "store_model_in_db", True) + actor: Final = UserAPIKeyAuth(user_id="test-admin", user_role=LitellmUserRoles.PROXY_ADMIN) + app.dependency_overrides[user_api_key_auth] = lambda: actor + try: + response: Final = client.patch("/update/ui_settings", json={"usage_default_time_range": submitted}) + assert response.status_code == 422, response.text + prisma.db.litellm_uisettings.upsert.assert_not_called() + finally: + app.dependency_overrides.clear() + + +@pytest.mark.parametrize("role", [LitellmUserRoles.INTERNAL_USER, LitellmUserRoles.PROXY_ADMIN_VIEW_ONLY]) +def test_usage_default_range_cannot_be_changed_by_non_admins( + mock_auth, monkeypatch: pytest.MonkeyPatch, role: LitellmUserRoles, +) -> None: + from unittest.mock import AsyncMock, MagicMock + from litellm.proxy import proxy_server + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.auth.user_api_key_auth import user_api_key_auth + + prisma: Final = MagicMock() + prisma.db.litellm_uisettings.upsert = AsyncMock() + monkeypatch.setattr(proxy_server, "prisma_client", prisma) + monkeypatch.setattr(proxy_server, "store_model_in_db", True) + actor: Final = UserAPIKeyAuth(user_id="test-user", user_role=role) + app.dependency_overrides[user_api_key_auth] = lambda: actor + try: + response: Final = client.patch("/update/ui_settings", json={"usage_default_time_range": "month_to_date"}) + assert response.status_code == 403, response.text + prisma.db.litellm_uisettings.upsert.assert_not_called() + finally: + app.dependency_overrides.clear() + + +def test_usage_default_range_reports_config_precedence(mock_auth, monkeypatch: pytest.MonkeyPatch) -> None: + from types import SimpleNamespace + from unittest.mock import AsyncMock, MagicMock + from litellm.proxy import proxy_server + from litellm.proxy.config_resolvers import SettingsStore + + prisma: Final = MagicMock() + prisma.db.litellm_uisettings.find_unique = AsyncMock(return_value=SimpleNamespace( + ui_settings={"usage_default_time_range": "today"}, + )) + monkeypatch.setattr(proxy_server, "prisma_client", prisma) + settings: Final = SettingsStore("general_settings") + settings.load_yaml({"usage_default_time_range": "month_to_date"}) + monkeypatch.setattr(proxy_server.proxy_config, "settings", settings) + response: Final = client.get("/get/ui_settings") + assert response.status_code == 200, response.text + assert response.json()["values"]["usage_default_time_range"] == "month_to_date" + assert response.json()["source"]["usage_default_time_range"] == "config" diff --git a/tests/unit/proxy/utils/proxy_logging/test_post_call_failure_hook.py b/tests/unit/proxy/utils/proxy_logging/test_post_call_failure_hook.py index e83efa21dcc..f880d3548f7 100644 --- a/tests/unit/proxy/utils/proxy_logging/test_post_call_failure_hook.py +++ b/tests/unit/proxy/utils/proxy_logging/test_post_call_failure_hook.py @@ -18,7 +18,7 @@ from litellm.constants import PROXY_REJECTED_BEFORE_ROUTING_KEY from litellm.exceptions import GuardrailRaisedException from litellm.integrations.custom_logger import CustomLogger from litellm.proxy._types import ProxyErrorTypes, UserAPIKeyAuth -from litellm.proxy.utils import ProxyLogging +from litellm.proxy.utils import REJECTED_BEFORE_REQUEST_SETUP, REJECTED_BEFORE_REQUEST_SETUP_KEY, ProxyLogging from litellm.types.utils import CachingDetails @@ -194,7 +194,9 @@ async def test_post_call_failure_hook_attributes_single_router_deployment( @pytest.mark.asyncio -async def test_pre_routing_reject_spend_log_keeps_public_model_group(proxy_logging, make_user_api_key_auth, monkeypatch): +async def test_pre_routing_reject_spend_log_keeps_public_model_group( + proxy_logging, make_user_api_key_auth, monkeypatch +): from litellm.proxy import proxy_server from litellm.proxy.spend_tracking.spend_tracking_utils import get_logging_payload @@ -400,6 +402,103 @@ async def test_post_call_failure_hook_flags_pre_routing_reject_despite_caller_mo assert kwargs["litellm_params"]["custom_llm_provider"] == "openai" +@pytest.mark.asyncio +@pytest.mark.parametrize("metadata_field", ["metadata", "litellm_metadata"]) +async def test_pre_routing_reject_logs_the_configured_deployment_over_caller_metadata( + proxy_logging, make_user_api_key_auth, monkeypatch, metadata_field: str +): + from litellm.proxy import proxy_server + from litellm.proxy.spend_tracking.spend_tracking_utils import get_logging_payload + + recorded: list[dict] = [] + + class _RecordingLogger(CustomLogger): + async def async_log_failure_event(self, kwargs, response_obj, start_time, end_time): + recorded.append(kwargs) + + monkeypatch.setattr( + proxy_server, + "llm_router", + litellm.Router( + model_list=[ + { + "model_name": "internal-model", + "litellm_params": {"model": "openai/gpt-4.1", "api_key": "sk-test"}, + } + ] + ), + ) + monkeypatch.setattr(litellm, "callbacks", [_RecordingLogger()]) + proxy_logging.alert_types = [] + request_data: Final[dict[str, object]] = { + "model": "internal-model", + "messages": [{"role": "user", "content": "hi"}], + "litellm_call_id": "caller-routing-metadata", + metadata_field: {"deployment": "openai/caller-chosen", "model_group": "caller-group"}, + } + logging_obj, _ = litellm.utils.function_setup( + original_function="acompletion", rules_obj=litellm.utils.Rules(), start_time=datetime.now(), **request_data + ) + + await proxy_logging.post_call_failure_hook( + request_data={**request_data, "litellm_logging_obj": logging_obj}, + original_exception=HTTPException(status_code=400, detail="Content blocked"), + user_api_key_dict=make_user_api_key_auth(request_route="/chat/completions"), + route="/chat/completions", + ) + + assert len(recorded) == 1 + now: Final = datetime.now() + payload: Final = get_logging_payload( + kwargs={**recorded[0], "completion_start_time": now}, response_obj=None, start_time=now, end_time=now + ) + standard_logging_object: Final = recorded[0]["standard_logging_object"] + assert { + "logged_model": standard_logging_object["model"], + "logged_model_group": standard_logging_object["model_group"], + "spend_model": payload["model"], + "spend_model_group": payload["model_group"], + } == { + "logged_model": "openai/gpt-4.1", + "logged_model_group": "internal-model", + "spend_model": "openai/gpt-4.1", + "spend_model_group": "internal-model", + } + + +@pytest.mark.asyncio +@pytest.mark.parametrize(("error_type", "logged_tags"), [(ProxyErrorTypes.auth_error, []), (None, ["checkout"])]) +async def test_proxy_only_failure_log_keeps_caller_tags_only_after_auth( + proxy_logging, monkeypatch, error_type: ProxyErrorTypes | None, logged_tags: list[str] +): + from litellm.proxy import proxy_server + + recorded: list[dict] = [] + + class _RecordingLogger(CustomLogger): + async def async_log_failure_event(self, kwargs, response_obj, start_time, end_time): + recorded.append(kwargs) + + monkeypatch.setattr(proxy_server, "llm_router", None) + monkeypatch.setattr(litellm, "callbacks", [_RecordingLogger()]) + proxy_logging.alert_types = [] + + await proxy_logging.post_call_failure_hook( + request_data={ + "model": "internal-model", + "messages": [{"role": "user", "content": "hi"}], + "metadata": {"tags": ["checkout"]}, + }, + original_exception=HTTPException(status_code=401, detail="Invalid proxy server token passed"), + user_api_key_dict=UserAPIKeyAuth(request_route="/chat/completions"), + error_type=error_type, + route="/chat/completions", + ) + + assert len(recorded) == 1 + assert recorded[0]["standard_logging_object"]["request_tags"] == logged_tags + + @pytest.mark.asyncio async def test_post_call_failure_hook_attribution_does_not_count_against_the_deployment( proxy_logging, make_user_api_key_auth, monkeypatch @@ -572,9 +671,8 @@ async def test_post_call_failure_hook_omits_provider_when_a_deployment_does_not_ async def test_handle_logging_proxy_only_path_attributes_with_read_only_metadata( proxy_logging, make_user_api_key_auth, monkeypatch ): - """With a logging object already on the request, its metadata is taken as given; - a read-only mapping there must not crash the stamp, and the failure handler - still receives the provider attribution.""" + """With a logging object already on the request, allowlisted metadata is kept, + a read-only mapping must not crash the stamp, and the failure handler receives provider attribution.""" from litellm.proxy import proxy_server monkeypatch.setattr( @@ -593,16 +691,26 @@ async def test_handle_logging_proxy_only_path_attributes_with_read_only_metadata logging_obj = MagicMock() logging_obj.call_type = "acompletion" logging_obj.model_call_details = {} + logging_obj.litellm_params = {"metadata": {"preexisting": "logged"}} logging_obj.async_failure_handler = AsyncMock() + guardrail_info: Final = [ + { + "guardrail_name": "local-block", + "guardrail_status": "guardrail_intervened", + "guardrail_cost": 0.25, + } + ] await proxy_logging._handle_logging_proxy_only_error( request_data={ "litellm_logging_obj": logging_obj, "model": "internal-model", "messages": [{"role": "user", "content": "hi"}], - "metadata": MappingProxyType({"user_api_key_alias": "frozen"}), + "metadata": MappingProxyType( + {"tags": ["checkout"], "standard_logging_guardrail_information": guardrail_info} + ), }, - user_api_key_dict=make_user_api_key_auth(request_route="/chat/completions"), + user_api_key_dict=make_user_api_key_auth(request_route="/chat/completions", key_alias="frozen"), route="/chat/completions", original_exception=HTTPException(status_code=403, detail="blocked"), ) @@ -611,7 +719,11 @@ async def test_handle_logging_proxy_only_path_attributes_with_read_only_metadata update_kwargs = logging_obj.update_environment_variables.call_args.kwargs assert update_kwargs["custom_llm_provider"] == "openai" assert update_kwargs["litellm_params"]["custom_llm_provider"] == "openai" - assert update_kwargs["litellm_params"]["metadata"] == {"user_api_key_alias": "frozen"} + assert { + key: update_kwargs["litellm_params"]["metadata"][key] for key in ("preexisting", "user_api_key_alias") + } == {"preexisting": "logged", "user_api_key_alias": "frozen"} + assert update_kwargs["litellm_params"]["metadata"]["tags"] == ["checkout"] + assert update_kwargs["litellm_params"]["metadata"]["standard_logging_guardrail_information"] == guardrail_info @pytest.mark.asyncio @@ -1001,7 +1113,9 @@ async def test_post_call_failure_hook_guardrail_block_fires_failure_callback( self, kwargs: dict[str, object], response_obj: object, start_time: datetime, end_time: datetime ) -> None: standard_logging_object = kwargs.get("standard_logging_object") - recorded.append(standard_logging_object.get("status") if isinstance(standard_logging_object, dict) else None) + recorded.append( + standard_logging_object.get("status") if isinstance(standard_logging_object, dict) else None + ) monkeypatch.setattr(litellm, "_async_failure_callback", [_StatusRecorder()]) logging_obj = LiteLLMLoggingObj( @@ -1029,3 +1143,52 @@ async def test_post_call_failure_hook_guardrail_block_fires_failure_callback( await asyncio.sleep(0) await asyncio.sleep(0) assert recorded == ["failure"] + + +@pytest.mark.asyncio +async def test_handle_logging_proxy_only_path_flags_requests_that_died_before_request_setup( + proxy_logging, make_user_api_key_auth +): + """A reject before the pipeline set up logging (bad key, bad body) reaches the failure hook with no logging + object. The handler mints a ``litellm_call_id`` so error logs can carry it, and marks the request with a + server-owned sentinel so spend tracking can tell it apart from a guardrail block, which arrives with the + pipeline's logging object. ``request_data`` is the client body, so a client-sent call id or marker value must + not change either outcome.""" + rejected_before_setup: dict[str, object] = { + "model": "m", + "messages": [{"role": "user", "content": "x"}], + "metadata": {}, + "litellm_call_id": "client-supplied", + } + await proxy_logging._handle_logging_proxy_only_error( + request_data=rejected_before_setup, + user_api_key_dict=make_user_api_key_auth(), + route="/chat/completions", + original_exception=HTTPException(status_code=401, detail="bad key"), + ) + + logging_obj = MagicMock() + logging_obj.call_type = "acompletion" + logging_obj.model_call_details = {} + logging_obj.async_failure_handler = AsyncMock() + blocked_by_guardrail: dict[str, object] = { + "litellm_logging_obj": logging_obj, + "litellm_call_id": "call-1", + "model": "m", + "messages": [{"role": "user", "content": "x"}], + "metadata": {}, + REJECTED_BEFORE_REQUEST_SETUP_KEY: True, + } + await proxy_logging._handle_logging_proxy_only_error( + request_data=blocked_by_guardrail, + user_api_key_dict=make_user_api_key_auth(), + route="/chat/completions", + original_exception=HTTPException(status_code=400, detail="blocked"), + ) + + assert ( + rejected_before_setup.get(REJECTED_BEFORE_REQUEST_SETUP_KEY) is REJECTED_BEFORE_REQUEST_SETUP, + rejected_before_setup["litellm_call_id"], + blocked_by_guardrail.get(REJECTED_BEFORE_REQUEST_SETUP_KEY) is REJECTED_BEFORE_REQUEST_SETUP, + blocked_by_guardrail["litellm_call_id"], + ) == (True, "client-supplied", False, "call-1") diff --git a/tests/unit/proxy/utils/proxy_logging/test_streaming_hooks.py b/tests/unit/proxy/utils/proxy_logging/test_streaming_hooks.py index 50f50478ad3..8f8f10565e9 100644 --- a/tests/unit/proxy/utils/proxy_logging/test_streaming_hooks.py +++ b/tests/unit/proxy/utils/proxy_logging/test_streaming_hooks.py @@ -23,7 +23,7 @@ from litellm.exceptions import GuardrailRaisedException from litellm.integrations.custom_guardrail import CustomGuardrail from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj -from litellm.llms.anthropic.pass_through.messages.streaming_iterator import ( +from litellm.llms.anthropic.messages.native.streaming_iterator import ( BaseAnthropicMessagesStreamingIterator, ) from litellm.proxy._types import UserAPIKeyAuth diff --git a/tests/unit/repositories/test_unit_of_work.py b/tests/unit/repositories/test_unit_of_work.py index a08d44b9b4d..082a29b7001 100644 --- a/tests/unit/repositories/test_unit_of_work.py +++ b/tests/unit/repositories/test_unit_of_work.py @@ -6,6 +6,7 @@ import pytest from litellm.repositories.unit_of_work import ( LinkedSpendResetWrites, + SpendResetWrites, budget_cascade_unit_of_work, enduser_spend_reset_unit_of_work, spend_reset_unit_of_work, @@ -39,6 +40,9 @@ class FakeBatch: self.litellm_projecttable = FakeBatchTable("litellm_projecttable", self.calls) self.litellm_endusertable = FakeBatchTable("litellm_endusertable", self.calls) + def execute_raw(self, query: str, *args: object) -> None: + self.calls.append(("execute_raw", {"query": query}, {"args": args})) + async def commit(self) -> None: self.commit_count += 1 @@ -166,7 +170,7 @@ async def test_every_cascade_dependent_writes_to_its_own_table_on_the_one_batch( async with budget_cascade_unit_of_work(_new_batch) as uow: writes = [getattr(uow, field.name) for field in fields(uow)] for write in writes: - if isinstance(write, LinkedSpendResetWrites): + if isinstance(write, SpendResetWrites): write.queue_spend_zero(where={"budget_id": "budget-1"}) else: write.queue_window_advance(budget_id="budget-1", budget_reset_at=reset_at) @@ -192,3 +196,18 @@ async def test_budget_cascade_raising_inside_block_skips_commit(): await _blow_up_mid_transaction() assert batch.commit_count == 0 + + +async def test_membership_total_spend_repair_is_queued_on_the_cascade_batch_ahead_of_the_reset(): + batch = FakeBatch() + + async with budget_cascade_unit_of_work(lambda: batch) as uow: + uow.team_memberships.queue_total_spend_repair(["budget-1", "budget-2"]) + uow.team_memberships.queue_spend_zero(where={"budget_id": "budget-1"}) + assert batch.commit_count == 0 + + assert batch.commit_count == 1 + repair, reset = batch.calls + assert repair[0] == "execute_raw" + assert repair[2] == {"args": (["budget-1", "budget-2"],)} + assert reset == ("litellm_teammembership.update_many", {"budget_id": "budget-1"}, {"spend": 0}) diff --git a/tests/unit/responses/litellm_completion_transformation/test_litellm_completion_responses.py b/tests/unit/responses/litellm_completion_transformation/test_litellm_completion_responses.py index 30e13442c92..63c98b571cb 100644 --- a/tests/unit/responses/litellm_completion_transformation/test_litellm_completion_responses.py +++ b/tests/unit/responses/litellm_completion_transformation/test_litellm_completion_responses.py @@ -14,7 +14,7 @@ from openai.types.responses.response_function_web_search import ( ActionSearchSource, ResponseFunctionWebSearch, ) -from pydantic import TypeAdapter +from pydantic import TypeAdapter, ValidationError import litellm from litellm.constants import CALLER_SESSION_ID_METADATA_KEY @@ -3398,7 +3398,9 @@ class TestUsageTransformation: assert response_usage.input_tokens_details is not None assert response_usage.input_tokens_details.cached_tokens == 5 assert response_usage.input_tokens_details.text_tokens == 8 - assert "cache_write_tokens" not in response_usage.input_tokens_details.model_dump() + assert {"cache_write_tokens", "cache_write_tokens_details"}.isdisjoint( + response_usage.input_tokens_details.model_dump() + ) def test_transform_usage_with_cached_tokens_gemini(self): """Test that cached_tokens from Gemini are properly transformed to input_tokens_details""" @@ -5060,6 +5062,50 @@ class TestHostedWebSearchReplay: assert replayed == search assert input_item == original + def test_replays_search_without_action(self) -> None: + input_item: Final = {"type": "web_search_call", "id": "ws_no_action", "status": "completed"} + + messages: Final = ( + LiteLLMCompletionResponsesConfig._transform_responses_api_input_item_to_chat_completion_message( + input_item=input_item + ) + ) + + assert len(messages) == 1 + assert messages[0]["role"] == "assistant" + content: Final = messages[0].get("content") + assert isinstance(content, str) + assert json.loads(content[content.index("{") :]) == input_item + + @pytest.mark.parametrize( + "fields", + ( + {"status": "completed"}, + {"id": "ws_invalid"}, + {"id": 42, "status": "completed"}, + {"id": "ws_invalid", "status": "invalid"}, + {"id": "ws_invalid", "status": "completed", "action": None}, + {"id": "ws_invalid", "status": "completed", "action": 42}, + {"id": "ws_invalid", "status": "completed", "action": {"type": "invalid"}}, + {"id": "ws_invalid", "status": "completed", "action": {"type": "find_in_page"}}, + ), + ids=( + "missing-id", + "missing-status", + "invalid-id", + "invalid-status", + "null-action", + "invalid-action-type", + "unknown-action", + "incomplete-action", + ), + ) + def test_rejects_search_with_other_invalid_fields(self, fields: Mapping[str, object]) -> None: + with pytest.raises(ValidationError): + LiteLLMCompletionResponsesConfig.transform_responses_api_input_to_messages( + input=[{"type": "web_search_call", **fields}], responses_api_request={} + ) + @pytest.mark.parametrize("order", ((0, 1, 2, 3), (1, 0, 3, 2), (1, 3, 0, 2))) @pytest.mark.parametrize("modify_params", (False, True)) @pytest.mark.parametrize("structured_content", (False, True)) diff --git a/tests/unit/responses/mcp/conftest.py b/tests/unit/responses/mcp/conftest.py index c41ba624ac8..ac661b9a9fb 100644 --- a/tests/unit/responses/mcp/conftest.py +++ b/tests/unit/responses/mcp/conftest.py @@ -5,4 +5,4 @@ import pytest @pytest.fixture(scope="module", autouse=True) def import_mcp_server_before_manager_doubles() -> None: - importlib.import_module("litellm.proxy._experimental.mcp_server.server") + importlib.import_module("litellm.proxy.mcp_server.server") diff --git a/tests/unit/responses/mcp/test_aresponses_api_with_mcp.py b/tests/unit/responses/mcp/test_aresponses_api_with_mcp.py index e88d951ff09..4cbcc6c1519 100644 --- a/tests/unit/responses/mcp/test_aresponses_api_with_mcp.py +++ b/tests/unit/responses/mcp/test_aresponses_api_with_mcp.py @@ -17,7 +17,6 @@ import respx from mcp.types import CallToolResult, ListToolsResult, TextContent from mcp.types import Tool as MCPTool - # Import required modules import litellm from litellm.exceptions import GuardrailRaisedException, MidStreamFallbackError @@ -25,14 +24,15 @@ from litellm.integrations.custom_logger import CustomLogger from litellm.integrations.langfuse.langfuse import langfuse_trace_id, langfuse_trace_metadata from litellm.litellm_core_utils.litellm_logging import Logging from litellm.llms.xai.common_utils import xai_reported_cost_in_usd -from litellm.proxy._experimental.mcp_server import mcp_server_manager -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ServerListOk +from litellm.proxy.mcp_server import mcp_server_manager +from litellm.proxy.mcp_server.faults.list_outcomes import ServerListOk from litellm.proxy.utils import _estimate_dispatched_failure_usage, _failure_fields_to_lift from litellm.responses.mcp.litellm_proxy_mcp_handler import LiteLLM_Proxy_MCP_Handler +from litellm.responses.mcp.mcp_streaming_iterator import MCPEnhancedStreamingIterator from litellm.types.llms.openai import ( + OpenAIMcpServerTool, ResponsesAPIResponse, ResponsesAPIStreamingResponse, - OpenAIMcpServerTool, ToolParam, ) from litellm.types.utils import ModelResponse, StandardLoggingPayload, Usage @@ -1078,10 +1078,11 @@ async def test_aresponses_mcp_call_does_not_forward_admission_authorization( import types from unittest.mock import AsyncMock - from mcp.types import CallToolResult, TextContent, Tool as MCPTool + from mcp.types import CallToolResult, TextContent + from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server import mcp_server_manager from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server import mcp_server_manager from litellm.types.mcp import MCPAuth, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -1184,6 +1185,7 @@ async def test_no_duplicate_mcp_tools_in_streaming_e2e(): sent to the LLM to ensure no duplication occurs. """ from unittest.mock import AsyncMock, patch + from litellm.responses.mcp.litellm_proxy_mcp_handler import ( LiteLLM_Proxy_MCP_Handler, ) @@ -1714,7 +1716,7 @@ async def _auto_execute_through_mcp_server( sys.modules, "litellm.proxy.proxy_server", SimpleNamespace(proxy_logging_obj=None, prisma_client=None) ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", SimpleNamespace( catalog=SimpleNamespace(operation=nullcontext), get_registry=MagicMock(return_value={}), @@ -2041,7 +2043,7 @@ def _serve_the_demo_mcp_listing(monkeypatch: pytest.MonkeyPatch) -> _ListingReco sys.modules, "litellm.proxy.proxy_server", SimpleNamespace(proxy_logging_obj=None, prisma_client=None) ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", SimpleNamespace( catalog=SimpleNamespace(operation=nullcontext), get_registry=MagicMock(return_value={}), @@ -2053,11 +2055,11 @@ def _serve_the_demo_mcp_listing(monkeypatch: pytest.MonkeyPatch) -> _ListingReco ), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", AsyncMock(return_value=[demo_server]), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.catalog.get_filtered_server_tools", + "litellm.proxy.mcp_server.catalog.get_filtered_server_tools", AsyncMock(return_value=(ListToolsResult(tools=[echo_tool]), ServerListOk(tool_count=1))), ) listing_recorder: Final = _ListingRecorder() @@ -2384,8 +2386,11 @@ def _first_index(events: Sequence[object], event_type: str) -> int: async def _scripted_mcp_stream( - model: str, upstream_url: str, rounds: Sequence[bytes] -) -> tuple[tuple[object, ...], respx.Route, AsyncMock, AsyncMock]: + model: str, + upstream_url: str, + rounds: Sequence[bytes], + max_agentic_loops: int | None = None, +) -> tuple[tuple[object, ...], respx.Route, AsyncMock, AsyncMock, MCPEnhancedStreamingIterator]: upstream: Final = respx.post(upstream_url).mock( side_effect=[httpx.Response(200, content=body, headers=SSE_HEADERS) for body in rounds] ) @@ -2402,9 +2407,11 @@ async def _scripted_mcp_stream( tool_choice="required", input=[{"role": "user", "type": "message", "content": "What's the weather in San Francisco?"}], stream=True, + **({"max_agentic_loops": max_agentic_loops} if max_agentic_loops is not None else {}), ) + assert isinstance(response, MCPEnhancedStreamingIterator) events: Final = tuple([event async for event in response]) - return events, upstream, fetch, execute + return events, upstream, fetch, execute, response @pytest.mark.asyncio @@ -2417,7 +2424,7 @@ async def test_streaming_responses_api_with_mcp_tools( model, upstream_url, tool_round, answer_round = SCRIPTED_PROVIDERS[provider] with caplog.at_level(logging.ERROR): - events, upstream, fetch, execute = await _scripted_mcp_stream( + events, upstream, fetch, execute, _ = await _scripted_mcp_stream( model, upstream_url, (tool_round(), answer_round()) ) @@ -2436,6 +2443,22 @@ async def test_streaming_responses_api_with_mcp_tools( assert not [record.getMessage() for record in caplog.records if record.levelno >= logging.ERROR] +@pytest.mark.asyncio +@respx.mock +async def test_streaming_mcp_iterator_uses_max_agentic_loops_from_request(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + model, upstream_url, tool_round, answer_round = SCRIPTED_PROVIDERS["openai"] + + _, _, _, _, iterator = await _scripted_mcp_stream( + model, + upstream_url, + (tool_round(), answer_round()), + max_agentic_loops=7, + ) + + assert iterator.max_tool_call_rounds == 7 + + @pytest.mark.asyncio @respx.mock async def test_streaming_mcp_event_order_and_response_id_consistency( @@ -2445,7 +2468,7 @@ async def test_streaming_mcp_event_order_and_response_id_consistency( model, upstream_url, tool_round, answer_round = SCRIPTED_PROVIDERS["openai"] with caplog.at_level(logging.ERROR): - events, _, _, _ = await _scripted_mcp_stream(model, upstream_url, (tool_round(), answer_round())) + events, _, _, _, _ = await _scripted_mcp_stream(model, upstream_url, (tool_round(), answer_round())) created: Final = _first_index(events, "response.created") in_progress: Final = _first_index(events, "response.in_progress") diff --git a/tests/unit/responses/mcp/test_chat_completions_handler.py b/tests/unit/responses/mcp/test_chat_completions_handler.py index 9064eba161d..ec5968c2a1a 100644 --- a/tests/unit/responses/mcp/test_chat_completions_handler.py +++ b/tests/unit/responses/mcp/test_chat_completions_handler.py @@ -6,19 +6,17 @@ from collections.abc import Mapping, Sequence from datetime import datetime from types import MappingProxyType from typing import Final, cast +from unittest.mock import AsyncMock, patch import pytest import respx from httpx import Response from mcp.types import Tool as MCPTool -from unittest.mock import AsyncMock, patch import litellm from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.litellm_logging import Logging from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER -from litellm.types.utils import ModelResponse, StandardLoggingPayload - from litellm.responses.mcp import chat_completions_handler from litellm.responses.mcp.chat_completions_handler import ( acompletion_with_mcp, @@ -27,6 +25,7 @@ from litellm.responses.mcp.litellm_proxy_mcp_handler import ( LiteLLM_Proxy_MCP_Handler, ) from litellm.responses.utils import ResponsesAPIRequestUtils +from litellm.types.utils import ModelResponse, StandardLoggingPayload @pytest.mark.asyncio @@ -181,15 +180,16 @@ async def test_acompletion_with_mcp_passes_mcp_server_auth_headers_to_process_to @pytest.mark.asyncio async def test_acompletion_with_mcp_auto_exec_performs_follow_up(monkeypatch): - from litellm.utils import CustomStreamWrapper + from unittest.mock import MagicMock + from litellm.types.utils import ( + ChatCompletionDeltaToolCall, + Delta, + Function, ModelResponseStream, StreamingChoices, - Delta, - ChatCompletionDeltaToolCall, - Function, ) - from unittest.mock import MagicMock + from litellm.utils import CustomStreamWrapper tools = [{"type": "function", "function": {"name": "tool"}}] @@ -432,9 +432,9 @@ async def test_acompletion_with_mcp_adds_metadata_to_streaming(monkeypatch): Test that acompletion_with_mcp adds MCP metadata to CustomStreamWrapper and it appears in the final chunk's delta.provider_specific_fields. """ - from litellm.utils import CustomStreamWrapper - from litellm.types.utils import ModelResponseStream, StreamingChoices, Delta from litellm.litellm_core_utils.litellm_logging import Logging + from litellm.types.utils import Delta, ModelResponseStream, StreamingChoices + from litellm.utils import CustomStreamWrapper tools = [{"type": "mcp", "server_url": "litellm_proxy/mcp/local"}] openai_tools = [{"type": "function", "function": {"name": "local_search"}}] @@ -588,8 +588,8 @@ async def test_acompletion_with_mcp_streaming_initial_call_is_streaming(monkeypa Test that acompletion_with_mcp makes the initial LLM call with streaming=True when stream=True is requested, instead of making a non-streaming call first. """ + from litellm.types.utils import Delta, ModelResponseStream, StreamingChoices from litellm.utils import CustomStreamWrapper - from litellm.types.utils import ModelResponseStream, StreamingChoices, Delta tools = [{"type": "mcp", "server_url": "litellm_proxy/mcp/local"}] openai_tools = [{"type": "function", "function": {"name": "local_search"}}] @@ -762,14 +762,14 @@ async def test_acompletion_with_mcp_streaming_metadata_in_correct_chunks(monkeyp - mcp_list_tools should be in the first chunk - mcp_tool_calls and mcp_call_results should be in the final chunk of initial response """ - from litellm.utils import CustomStreamWrapper from litellm.types.utils import ( + ChatCompletionDeltaToolCall, + Delta, + Function, ModelResponseStream, StreamingChoices, - Delta, - ChatCompletionDeltaToolCall, - Function, ) + from litellm.utils import CustomStreamWrapper tools = [{"type": "mcp", "server_url": "litellm_proxy/mcp/local"}] openai_tools = [{"type": "function", "function": {"name": "local_search"}}] @@ -1083,7 +1083,7 @@ async def test_execute_tool_calls_sets_proxy_server_request_arguments(monkeypatc ) monkeypatch.setattr(mcp_handler_module, "function_setup", mock_function_setup) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager.call_tool", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager.call_tool", mock_call_tool, ) @@ -1366,7 +1366,7 @@ async def test_acompletion_with_mcp_streaming_drains_inner_stream_after_exhausti @pytest.mark.asyncio @respx.mock async def test_acompletion_with_mcp_forwards_unserved_external_mcp_tool_to_the_provider(monkeypatch): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager zapier_tool = {"type": "mcp", "server_label": "zapier", "server_url": "https://mcp.zapier.com/api/mcp/mcp"} monkeypatch.setitem(sys.modules, "litellm.proxy.proxy_server", types.SimpleNamespace(prisma_client=None)) @@ -1405,14 +1405,15 @@ async def test_acompletion_with_mcp_forwards_unserved_external_mcp_tool_to_the_p @pytest.mark.parametrize("selection_source", ["metadata", "litellm_metadata", "body"]) @pytest.mark.parametrize("logging_failure", [False, True]) async def test_request_selected_mcp_guardrail_blocks_before_upstream(monkeypatch, selected, stream, selection_source, logging_failure): - from litellm.exceptions import GuardrailRaisedException from mcp.types import Tool + from litellm.caching.caching import DualCache + from litellm.exceptions import GuardrailRaisedException from litellm.integrations.custom_guardrail import CustomGuardrail from litellm.proxy import proxy_server - from litellm.proxy._types import UserAPIKeyAuth, LiteLLM_ObjectPermissionTable - from litellm.proxy._experimental.mcp_server import mcp_server_manager, server, tool_registry - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import AggregateToolListing + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth + from litellm.proxy.mcp_server import mcp_server_manager, server, tool_registry + from litellm.proxy.mcp_server.faults.list_outcomes import AggregateToolListing from litellm.proxy.utils import ProxyLogging from litellm.types.guardrails import GuardrailEventHooks from litellm.types.mcp_server.mcp_server_manager import MCPServer diff --git a/tests/unit/responses/mcp/test_litellm_proxy_mcp_handler.py b/tests/unit/responses/mcp/test_litellm_proxy_mcp_handler.py index 26553558298..4da1bd97c3a 100644 --- a/tests/unit/responses/mcp/test_litellm_proxy_mcp_handler.py +++ b/tests/unit/responses/mcp/test_litellm_proxy_mcp_handler.py @@ -18,10 +18,10 @@ import litellm from litellm.caching.caching import DualCache from litellm.integrations.custom_guardrail import CustomGuardrail from litellm.litellm_core_utils.litellm_logging import Logging -from litellm.proxy._experimental.mcp_server import operations as mcp_operations -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import AggregateToolListing -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ListedToolsCaller, MCPServerManager from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server import operations as mcp_operations +from litellm.proxy.mcp_server.faults.list_outcomes import AggregateToolListing +from litellm.proxy.mcp_server.mcp_server_manager import ListedToolsCaller, MCPServerManager from litellm.proxy.utils import ProxyLogging from litellm.responses import main as responses_main from litellm.responses.mcp import litellm_proxy_mcp_handler as mcp_handler_module @@ -55,7 +55,7 @@ def _setup_mcp_call_environment(monkeypatch: pytest.MonkeyPatch) -> AsyncMock: get_mcp_server_by_name=MagicMock(return_value=None), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) return fake_manager.call_tool @@ -187,11 +187,11 @@ def test_transform_mcp_tools_to_openai_uses_chat_format(monkeypatch): return {"responses": True} monkeypatch.setattr( - "litellm.experimental_mcp_client.tools.transform_mcp_tool_to_openai_tool", + "litellm.mcp_client.tools.transform_mcp_tool_to_openai_tool", fake_transform_chat, ) monkeypatch.setattr( - "litellm.experimental_mcp_client.tools.transform_mcp_tool_to_openai_responses_api_tool", + "litellm.mcp_client.tools.transform_mcp_tool_to_openai_responses_api_tool", fake_transform_responses, ) @@ -313,7 +313,7 @@ async def test_execute_tool_calls_strips_prefix_when_alias_differs_from_server_n mcp_info=None, tool_name_to_display_name=None, ) - from litellm.proxy._experimental.mcp_server import mcp_server_manager as _msm + from litellm.proxy.mcp_server import mcp_server_manager as _msm _msm.global_mcp_server_manager.get_mcp_server_from_tool_name = MagicMock(return_value=fake_server) @@ -355,7 +355,7 @@ async def test_execute_tool_calls_reverse_maps_display_name(monkeypatch): mcp_info=None, tool_name_to_display_name={"read_wiki_structure": "browse_repo_docs"}, ) - from litellm.proxy._experimental.mcp_server import mcp_server_manager as _msm + from litellm.proxy.mcp_server import mcp_server_manager as _msm _msm.global_mcp_server_manager.get_mcp_server_from_tool_name = MagicMock(return_value=colliding_server) _msm.global_mcp_server_manager.get_mcp_server_by_name = MagicMock(return_value=fake_server) @@ -393,7 +393,7 @@ async def test_execute_tool_calls_logs_failure_via_post_call_failure_hook(monkey call_tool=AsyncMock(side_effect=HTTPException(status_code=500, detail="boom")), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) @@ -515,7 +515,7 @@ async def test_execute_tool_calls_applies_post_call_hook_content(monkeypatch): get_mcp_server_by_name=MagicMock(return_value=None), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) @@ -557,7 +557,7 @@ async def test_execute_tool_calls_returns_proxy_result_without_logging(monkeypat get_mcp_server_by_name=MagicMock(return_value=None), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) handler_module = importlib.import_module("litellm.responses.mcp.litellm_proxy_mcp_handler") @@ -591,7 +591,7 @@ async def test_execute_tool_calls_passes_logging_details_to_proxy_hook(monkeypat get_mcp_server_by_name=MagicMock(return_value=None), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) logging_obj = MagicMock() @@ -627,7 +627,7 @@ async def test_execute_tool_calls_continues_when_post_call_logging_fails(monkeyp get_mcp_server_by_name=MagicMock(return_value=None), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) @@ -670,7 +670,7 @@ async def test_get_mcp_tools_from_manager_enables_list_tools_logging(monkeypatch ] mock_get_tools = AsyncMock(return_value=AggregateToolListing(tools=served_tools, outcomes={})) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.server._get_tools_from_mcp_servers", + "litellm.proxy.mcp_server.server._get_tools_from_mcp_servers", mock_get_tools, ) @@ -683,7 +683,7 @@ async def test_get_mcp_tools_from_manager_enables_list_tools_logging(monkeypatch get_mcp_server_by_name=MagicMock(return_value=None), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) @@ -730,7 +730,7 @@ def test_get_parent_request_tags_from_nested_litellm_params(): async def test_get_mcp_tools_from_manager_forwards_request_tags(monkeypatch): mock_get_tools = AsyncMock(return_value=AggregateToolListing(tools=[], outcomes={})) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.server._get_tools_from_mcp_servers", + "litellm.proxy.mcp_server.server._get_tools_from_mcp_servers", mock_get_tools, ) fake_manager = types.SimpleNamespace( @@ -741,7 +741,7 @@ async def test_get_mcp_tools_from_manager_forwards_request_tags(monkeypatch): get_mcp_server_by_name=MagicMock(return_value=None), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) @@ -952,7 +952,7 @@ async def test_gateway_served_names_matches_alias_server_name_name_access_group_ @pytest.mark.asyncio async def test_gateway_served_names_matches_server_id_short_prefix_and_alias_case_like_the_gateway(): - from litellm.proxy._experimental.mcp_server.utils import compute_short_server_prefix + from litellm.proxy.mcp_server.utils import compute_short_server_prefix from litellm.responses.mcp.litellm_proxy_mcp_handler import _gateway_served_names server_id = "0b9ae4ca-1bd2-4faa-b183-7dd812597e3b" @@ -1040,7 +1040,7 @@ def test_should_use_gateway_still_triggers_on_http_mcp_path(): @pytest.mark.asyncio async def test_aresponses_api_with_mcp_forwards_unserved_external_mcp_tool_to_the_provider(monkeypatch): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.responses import main as responses_main from litellm.types.llms.openai import ResponsesAPIResponse @@ -1287,7 +1287,7 @@ async def test_mcp_follow_up_call_is_stateless_when_store_is_false( @pytest.mark.asyncio async def test_responses_discovery_logs_sanitized_caller_headers(monkeypatch: pytest.MonkeyPatch): - from litellm.proxy._experimental.mcp_server import mcp_server_manager, operations + from litellm.proxy.mcp_server import mcp_server_manager, operations headers: Final = { "x-app-id": "app-a", @@ -1365,7 +1365,7 @@ async def test_bridge_listing_leaves_the_callers_catalog_unchanged( get_mcp_server_by_name=MagicMock(return_value=None), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) with ( @@ -1453,7 +1453,7 @@ async def test_concurrent_bridge_calls_use_their_own_served_metadata(monkeypatch monkeypatch.setattr("litellm.proxy.proxy_server.proxy_logging_obj", logger) monkeypatch.setattr(mcp_operations, "global_mcp_server_manager", manager) monkeypatch.setattr(mcp_operations, "_get_allowed_mcp_servers", AsyncMock(return_value=[server])) - monkeypatch.setattr("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", manager) + monkeypatch.setattr("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager) first_listed: Final = asyncio.Event() second_listed: Final = asyncio.Event() @@ -1508,13 +1508,13 @@ def _toolset_gateway_manager(toolset_id: str, server_id: str) -> types.SimpleNam async def _tools_listing_kwargs_for_toolset_url(monkeypatch, team_toolset_id: str) -> dict[str, object]: - from litellm.proxy._experimental.mcp_server.ui_session_utils import granted_toolset_ids from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LitellmUserRoles, UserAPIKeyAuth + from litellm.proxy.mcp_server.ui_session_utils import granted_toolset_ids mock_get_tools = AsyncMock(return_value=AggregateToolListing(tools=[], outcomes={})) - monkeypatch.setattr("litellm.proxy._experimental.mcp_server.server._get_tools_from_mcp_servers", mock_get_tools) + monkeypatch.setattr("litellm.proxy.mcp_server.server._get_tools_from_mcp_servers", mock_get_tools) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", _toolset_gateway_manager("ts-granted", "srv-1"), ) monkeypatch.setattr("litellm.proxy.proxy_server.prisma_client", MagicMock()) @@ -1561,7 +1561,7 @@ async def test_apply_toolset_permissions_pins_the_auth_to_explicit_grants_only(m resolve_toolset_tool_permissions=AsyncMock(return_value={"srv-1": ["add"]}), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) diff --git a/tests/unit/responses/mcp/test_mcp_streaming_iterator.py b/tests/unit/responses/mcp/test_mcp_streaming_iterator.py index 8eb73b7c6e1..78b0e3d4e5b 100644 --- a/tests/unit/responses/mcp/test_mcp_streaming_iterator.py +++ b/tests/unit/responses/mcp/test_mcp_streaming_iterator.py @@ -2,6 +2,7 @@ import sys import types from contextlib import nullcontext from types import SimpleNamespace +from typing import Final from unittest.mock import AsyncMock, MagicMock import pytest @@ -9,7 +10,6 @@ from mcp.types import CallToolResult, TextContent import litellm # noqa: F401 - ensures litellm.responses.main is registered in sys.modules from litellm.responses.mcp.mcp_streaming_iterator import ( - MAX_MCP_TOOL_CALL_ROUNDS, MCPEnhancedStreamingIterator, ) from litellm.types.llms.openai import ( @@ -85,7 +85,7 @@ def _mock_mcp_environment(monkeypatch: pytest.MonkeyPatch) -> AsyncMock: get_mcp_server_by_name=MagicMock(return_value=None), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) monkeypatch.setitem( @@ -96,7 +96,7 @@ def _mock_mcp_environment(monkeypatch: pytest.MonkeyPatch) -> AsyncMock: return call_tool -def _make_iterator(initial_chunks) -> MCPEnhancedStreamingIterator: +def _make_iterator(initial_chunks, max_agentic_loops: int | str | None = None) -> MCPEnhancedStreamingIterator: return MCPEnhancedStreamingIterator( base_iterator=_FakeAsyncStream(initial_chunks), mcp_events=[], @@ -107,6 +107,7 @@ def _make_iterator(initial_chunks) -> MCPEnhancedStreamingIterator: "model": "gpt-4", "input": "what is berriai/litellm?", "tools": [{"type": "mcp"}], + **({"max_agentic_loops": max_agentic_loops} if max_agentic_loops is not None else {}), }, ) @@ -157,35 +158,43 @@ async def test_second_round_tool_call_is_executed_and_reaches_final_text(monkeyp @pytest.mark.asyncio -async def test_tool_call_rounds_are_capped(monkeypatch): +@pytest.mark.parametrize( + ("max_agentic_loops", "expected_cap"), + ( + pytest.param(None, 5, id="unset"), + pytest.param(7, 7, id="integer"), + pytest.param("7", 7, id="integer-string"), + pytest.param(2, 2, id="custom-cap"), + ), +) +async def test_tool_call_rounds_are_capped(monkeypatch, max_agentic_loops, expected_cap): """ A model that keeps calling tools every round must not loop forever — - auto-execution stops at MAX_MCP_TOOL_CALL_ROUNDS, and the follow-up made + auto-execution stops at the configured round cap, and the follow-up made at the cap drops "tools" from the request so the model is forced to answer in text instead of the stream just hanging. """ call_tool = _mock_mcp_environment(monkeypatch) - # Rounds 2..MAX_MCP_TOOL_CALL_ROUNDS keep calling the tool; the call made - # once the cap is hit returns a text-only response. - tool_call_streams = [ - _tool_call_stream(f"call_{i}", "read_wiki_contents") for i in range(2, MAX_MCP_TOOL_CALL_ROUNDS + 1) - ] - aresponses_mock = AsyncMock(side_effect=[*tool_call_streams, _text_only_stream("giving up on tools")]) + tool_call_streams: Final = tuple( + _tool_call_stream(f"call_{i}", "read_wiki_contents") for i in range(2, expected_cap + 1) + ) + aresponses_mock: Final = AsyncMock(side_effect=(*tool_call_streams, _text_only_stream("giving up on tools"))) monkeypatch.setattr(responses_main_module, "aresponses", aresponses_mock) iterator = _make_iterator( [ _output_item_added_chunk(), _completed_chunk([_function_call("call_1", "read_wiki_contents")]), - ] + ], + max_agentic_loops=max_agentic_loops, ) _ = [chunk async for chunk in iterator] - assert iterator.tool_call_round == MAX_MCP_TOOL_CALL_ROUNDS - assert call_tool.call_count == MAX_MCP_TOOL_CALL_ROUNDS - assert aresponses_mock.call_count == MAX_MCP_TOOL_CALL_ROUNDS + assert iterator.tool_call_round == expected_cap + assert call_tool.call_count == expected_cap + assert aresponses_mock.call_count == expected_cap # Every follow-up before the cap still offered tools; only the capped one drops them. for call in aresponses_mock.call_args_list[:-1]: @@ -193,6 +202,12 @@ async def test_tool_call_rounds_are_capped(monkeypatch): assert "tools" not in aresponses_mock.call_args_list[-1].kwargs +@pytest.mark.parametrize(("max_agentic_loops", "expected_error"), ((0, ValueError), ("three", TypeError))) +def test_invalid_max_agentic_loops_raises_when_creating_iterator(max_agentic_loops, expected_error): + with pytest.raises(expected_error, match=r"litellm_params\.max_agentic_loops"): + _make_iterator([], max_agentic_loops=max_agentic_loops) + + @pytest.mark.asyncio async def test_continuation_id_is_final_round_not_interim_tool_call(monkeypatch): """ diff --git a/tests/unit/responses/mcp/test_tool_precheck.py b/tests/unit/responses/mcp/test_tool_precheck.py index 832151ce2a6..bd37114ccea 100644 --- a/tests/unit/responses/mcp/test_tool_precheck.py +++ b/tests/unit/responses/mcp/test_tool_precheck.py @@ -14,11 +14,11 @@ import respx import litellm from litellm.responses.mcp.tool_precheck import may_name_litellm_mcp_gateway -GATEWAY_REGISTRY_MODULE: Final = "litellm.proxy._experimental.mcp_server.mcp_server_manager" +GATEWAY_REGISTRY_MODULE: Final = "litellm.proxy.mcp_server.mcp_server_manager" GATEWAY_HANDLER_MODULES: Final = ( "litellm.responses.mcp.litellm_proxy_mcp_handler", "litellm.responses.mcp.chat_completions_handler", - "litellm.llms.anthropic.pass_through.messages.mcp_handler", + "litellm.llms.anthropic.messages.native.mcp_handler", ) FUNCTION_TOOL: Final = { diff --git a/tests/unit/responses/test_responses_api_bridge_flag.py b/tests/unit/responses/test_responses_api_bridge_flag.py index 63204114501..278bd4c1e52 100644 --- a/tests/unit/responses/test_responses_api_bridge_flag.py +++ b/tests/unit/responses/test_responses_api_bridge_flag.py @@ -10,6 +10,7 @@ import copy import json from collections.abc import Mapping from importlib import import_module +from pathlib import Path from typing import Final, cast from unittest.mock import MagicMock, patch @@ -852,3 +853,92 @@ def test_bridge_reasoning_effort_reads_only_a_string_or_mapping_effort_nested_in extra_body: JsonValue, expected: JsonValue ) -> None: assert bridge_reasoning_effort(None, extra_body) == expected + + +@pytest.mark.parametrize("asynchronous", [False, True]) +@pytest.mark.parametrize("stream", [False, True]) +@pytest.mark.parametrize("prefix", ["", "responses/"]) +@pytest.mark.parametrize("catalog_mode", [None, "chat", "responses"]) +@pytest.mark.asyncio +async def test_chatgpt_completion_routes_to_responses_without_a_provider_catalog_entry( + monkeypatch: pytest.MonkeyPatch, + tmp_path: Path, + respx_mock: respx.MockRouter, + asynchronous: bool, + stream: bool, + prefix: str, + catalog_mode: str | None, +) -> None: + model: Final = "test-chatgpt-routing" + monkeypatch.setenv("CHATGPT_TOKEN_DIR", str(tmp_path)) + monkeypatch.setenv("CHATGPT_API_BASE", "https://chatgpt.example") + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + (tmp_path / "auth.json").write_text( + json.dumps({"access_token": "fake-access-token", "expires_at": 253402300799, "account_id": "fake-account"}) + ) + monkeypatch.delitem(litellm.model_cost, f"chatgpt/{model}", raising=False) + monkeypatch.delitem(litellm.model_cost, model, raising=False) + if catalog_mode is not None: + monkeypatch.setitem(litellm.model_cost, model, {"mode": catalog_mode, "litellm_provider": "openai"}) + litellm.get_model_info.cache_clear() + payload: Final = { + "id": "resp_test", + "object": "response", + "created_at": 1, + "status": "completed", + "model": model, + "output": [ + { + "type": "message", + "id": "msg_test", + "status": "completed", + "role": "assistant", + "content": [{"type": "output_text", "text": "hello", "annotations": []}], + } + ], + "usage": {"input_tokens": 1, "output_tokens": 1, "total_tokens": 2}, + } + events: Final = ( + {"type": "response.created", "response": {**payload, "status": "in_progress", "output": []}}, + { + "type": "response.output_text.delta", + "delta": "hello", + "item_id": "msg_test", + "output_index": 0, + "content_index": 0, + }, + {"type": "response.completed", "response": payload}, + ) + upstream: Final = respx_mock.post("https://chatgpt.example/responses").respond( + 200, + headers={"content-type": "text/event-stream"}, + text="".join(f"event: {event['type']}\ndata: {json.dumps(event)}\n\n" for event in events), + ) + kwargs: Final = { + "model": f"chatgpt/{prefix}{model}", + "messages": [{"role": "user", "content": "Say hello"}], + "api_base": "https://chatgpt.example", + "stream": stream, + "num_retries": 0, + } + response: Final = await litellm.acompletion(**kwargs) if asynchronous else litellm.completion(**kwargs) + result: Final = ( + litellm.stream_chunk_builder([chunk async for chunk in response] if asynchronous else list(response)) + if stream + else response + ) + assert result is not None + assert result.choices[0].message.content == "hello" + assert upstream.call_count == 1 + sent: Final = json.loads(upstream.calls[0].request.content) + assert sent["model"] == model + assert sent["store"] is False + assert sent["input"] == [ + {"type": "message", "role": "user", "content": [{"type": "input_text", "text": "Say hello"}]} + ] + + +@pytest.mark.parametrize("provider", ["openai", "azure", "xai", "github_copilot"]) +def test_missing_catalog_entry_does_not_force_other_providers_to_responses(provider: str) -> None: + info, model = responses_api_bridge_check(model="test-chatgpt-routing-control", custom_llm_provider=provider) + assert (info.get("mode"), model) == (None, "test-chatgpt-routing-control") diff --git a/tests/unit/responses/test_responses_api_request_body.py b/tests/unit/responses/test_responses_api_request_body.py index 36b5d8f135b..bf571c74e22 100644 --- a/tests/unit/responses/test_responses_api_request_body.py +++ b/tests/unit/responses/test_responses_api_request_body.py @@ -8,7 +8,8 @@ import asyncio import copy import json import logging -from collections.abc import Awaitable, Callable +import math +from collections.abc import Awaitable, Callable, Mapping from pathlib import Path from importlib import import_module from typing import Final @@ -17,10 +18,12 @@ from unittest.mock import AsyncMock, patch import httpx import pytest import respx +from pydantic import TypeAdapter import litellm from litellm._logging import verbose_logger from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler +from litellm.types.llms.openai import ResponsesAPIResponse from tests.unit.llms.bedrock.slow_upstream import ( STREAM_TIMEOUT_SECONDS, UPSTREAM_FIRST_BYTE_SECONDS, @@ -333,7 +336,9 @@ async def test_aresponses_sends_the_declared_reasoning_effort_level_rounded_up( def _effort_levels_disabled_by(entry: dict) -> tuple[str, ...]: - return tuple(level for level in ("none", "minimal", "low") if entry.get(f"supports_{level}_reasoning_effort") is False) + return tuple( + level for level in ("none", "minimal", "low") if entry.get(f"supports_{level}_reasoning_effort") is False + ) def _gpt_5_row_disabling_a_level(provider: str) -> tuple[str, str]: @@ -623,7 +628,8 @@ async def test_aresponses_websocket_strips_responses_routing_prefix_from_openai_ from litellm.responses.main import _aresponses_websocket with patch.object( - import_module("litellm.responses.main").base_llm_http_handler, "async_responses_websocket", + import_module("litellm.responses.main").base_llm_http_handler, + "async_responses_websocket", new_callable=AsyncMock, ) as mock_ws: await _aresponses_websocket( @@ -645,7 +651,8 @@ async def test_aresponses_websocket_keeps_routing_hints_out_of_the_relay_kwargs( from litellm.responses.main import _aresponses_websocket with patch.object( - import_module("litellm.responses.main").base_llm_http_handler, "async_responses_websocket", + import_module("litellm.responses.main").base_llm_http_handler, + "async_responses_websocket", new_callable=AsyncMock, ) as mock_ws: await _aresponses_websocket( @@ -671,7 +678,9 @@ _ORIGINAL_WS_INPUT = [ @pytest.mark.asyncio @pytest.mark.parametrize("nested", [False, True]) -async def test_aresponses_websocket_forwards_the_routed_input_in_the_first_frame(nested: bool): # test-quality-ok: the first frame handed to the relay is the only place the routed input is observable before the provider socket +async def test_aresponses_websocket_forwards_the_routed_input_in_the_first_frame( + nested: bool, +): # test-quality-ok: the first frame handed to the relay is the only place the routed input is observable before the provider socket from unittest.mock import MagicMock from litellm.responses.main import _aresponses_websocket @@ -682,7 +691,8 @@ async def test_aresponses_websocket_forwards_the_routed_input_in_the_first_frame ) with patch.object( - import_module("litellm.responses.main").base_llm_http_handler, "async_responses_websocket", + import_module("litellm.responses.main").base_llm_http_handler, + "async_responses_websocket", new_callable=AsyncMock, ) as mock_ws: await _aresponses_websocket( @@ -711,7 +721,8 @@ async def test_aresponses_websocket_forwards_the_first_frame_verbatim_when_routi first_message = '{"type": "response.create", "model": "gpt-5.6", "input": [{"role": "user", "content": "hi"}]}' with patch.object( - import_module("litellm.responses.main").base_llm_http_handler, "async_responses_websocket", + import_module("litellm.responses.main").base_llm_http_handler, + "async_responses_websocket", new_callable=AsyncMock, ) as mock_ws: await _aresponses_websocket( @@ -968,9 +979,7 @@ async def test_injection_points_reach_a_foundry_deployment_of_an_openai_model(mo Azure OpenAI one the Foundry deployment got Anthropic marks the Responses transform then stripped.""" monkeypatch.setenv("AZURE_AI_API_BASE", "https://other-deployment.openai.azure.com") injected_client = AsyncHTTPHandler() - mock_post = AsyncMock( - return_value=MockResponse(_minimal_responses_api_payload("resp_foundry", "gpt-6-astra"), 200) - ) + mock_post = AsyncMock(return_value=MockResponse(_minimal_responses_api_payload("resp_foundry", "gpt-6-astra"), 200)) injected_client.post = mock_post await litellm.aresponses( @@ -1234,6 +1243,77 @@ def test_faked_stream_accepts_a_text_timeout(monkeypatch: pytest.MonkeyPatch) -> ] +async def _invoke_responses(sync_mode: bool, model: str, pricing: Mapping[str, float]) -> ResponsesAPIResponse: + response: Final = ( + litellm.responses(model=model, input="hi", **pricing) + if sync_mode + else await litellm.aresponses(model=model, input="hi", **pricing) + ) + assert isinstance(response, ResponsesAPIResponse) + return response + + +def _response_cost(response: ResponsesAPIResponse) -> float: + hidden_params: Final[dict[str, float]] = getattr(response, "_hidden_params") + return hidden_params["response_cost"] + + +@pytest.mark.asyncio +@pytest.mark.parametrize("sync_mode", (True, False)) +@pytest.mark.parametrize("model", ("openai/gpt-5.4-nano", "openai/custom-priced-model-not-in-cost-map")) +async def test_responses_bills_per_call_custom_pricing_from_usage( + monkeypatch: pytest.MonkeyPatch, respx_mock: respx.MockRouter, sync_mode: bool, model: str +): + monkeypatch.setenv("OPENAI_API_KEY", "fake-api-key") + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + model_cost: Final[dict[str, object]] = getattr(litellm, "model_cost") + monkeypatch.setattr(litellm, "model_cost", dict(model_cost)) + litellm.in_memory_llm_clients_cache.flush_cache() + respx_mock.post("https://api.openai.com/v1/responses").mock( + return_value=httpx.Response(200, json=_minimal_responses_api_payload("resp_custom_price", model.split("/")[1])) + ) + pricing: Final = {"input_cost_per_token": 1e-5, "output_cost_per_token": 2e-5} + + response: Final = await _invoke_responses(sync_mode, model, pricing) + + assert response.usage is not None + expected: Final = ( + response.usage.input_tokens * pricing["input_cost_per_token"] + + response.usage.output_tokens * pricing["output_cost_per_token"] + ) + assert math.isclose(_response_cost(response), expected) + + +@pytest.mark.asyncio +async def test_concurrent_responses_calls_keep_their_own_per_call_prices( + monkeypatch: pytest.MonkeyPatch, respx_mock: respx.MockRouter +): + monkeypatch.setenv("OPENAI_API_KEY", "fake-api-key") + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + litellm.in_memory_llm_clients_cache.flush_cache() + model: Final = "openai/gpt-5.4-nano" + model_cost: Final[dict[str, object]] = getattr(litellm, "model_cost") + cost_map_row_before: Final = copy.deepcopy(model_cost.get(model)) + respx_mock.post("https://api.openai.com/v1/responses").mock( + return_value=httpx.Response(200, json=_minimal_responses_api_payload("resp_concurrent", "gpt-5.4-nano")) + ) + rates: Final = ((1e-5, 2e-5), (3e-5, 4e-5)) + + responses: Final = await asyncio.gather( + *( + _invoke_responses(False, model, {"input_cost_per_token": in_rate, "output_cost_per_token": out_rate}) + for in_rate, out_rate in rates + ) + ) + + for response, (in_rate, out_rate) in zip(responses, rates, strict=True): + assert response.usage is not None + assert math.isclose( + _response_cost(response), response.usage.input_tokens * in_rate + response.usage.output_tokens * out_rate + ) + assert model_cost.get(model) == cost_map_row_before + + @pytest.mark.parametrize("asynchronous", [False, True]) @pytest.mark.parametrize("stream", [False, True]) @pytest.mark.parametrize( @@ -1339,3 +1419,49 @@ async def test_responses_opencode_session_uses_effective_destination( assert sent.headers.get("x-opencode-session") == (None if explicit_base else "conversation-123") assert sent.headers["authorization"] == "Bearer test-key" assert json.loads(sent.content) == {"model": "gpt-6-luna", "input": "hello"} + + +_JSON_OBJECT: Final = TypeAdapter(dict[str, object]) + + +@pytest.mark.asyncio +async def test_router_responses_deployment_pricing_keeps_inherited_cache_rates( + monkeypatch: pytest.MonkeyPatch, respx_mock: respx.MockRouter +): + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + model_cost: Final[dict[str, object]] = getattr(litellm, "model_cost") + monkeypatch.setattr(litellm, "model_cost", dict(model_cost)) + litellm.in_memory_llm_clients_cache.flush_cache() + rates: Final = {"input_cost_per_token": 1e-5, "output_cost_per_token": 2e-5} + router: Final = litellm.Router( + model_list=[ + { + "model_name": "nano", + "litellm_params": {"model": "openai/gpt-5.4-nano", "api_key": "fake-api-key", **rates}, + "model_info": {"id": "nano-deployment"}, + } + ] + ) + payload: Final[dict[str, object]] = _minimal_responses_api_payload("resp_router_cache", "gpt-5.4-nano") + usage: Final = _JSON_OBJECT.validate_python(payload["usage"]) + cached_tokens: Final = 8 + respx_mock.post("https://api.openai.com/v1/responses").mock( + return_value=httpx.Response( + 200, + json={**payload, "usage": {**usage, "input_tokens_details": {"cached_tokens": cached_tokens}}}, + ) + ) + + response: Final = await router.aresponses(model="nano", input="hi") + + assert isinstance(response, ResponsesAPIResponse) + assert response.usage is not None + uncached_input: Final = response.usage.input_tokens - cached_tokens + full_price: Final = ( + response.usage.input_tokens * rates["input_cost_per_token"] + + response.usage.output_tokens * rates["output_cost_per_token"] + ) + floor: Final = ( + uncached_input * rates["input_cost_per_token"] + response.usage.output_tokens * rates["output_cost_per_token"] + ) + assert floor < _response_cost(response) < full_price diff --git a/tests/unit/responses/test_responses_utils.py b/tests/unit/responses/test_responses_utils.py index 6ee2c495705..0863abd1f1e 100644 --- a/tests/unit/responses/test_responses_utils.py +++ b/tests/unit/responses/test_responses_utils.py @@ -1,5 +1,6 @@ from importlib import import_module import base64 +from typing import Final from unittest.mock import MagicMock, patch import pytest @@ -7,10 +8,11 @@ import pytest import litellm from litellm.llms.openai.responses.transformation import OpenAIResponsesAPIConfig +from litellm.litellm_core_utils.llm_cost_calc.utils import generic_cost_per_token from litellm.responses.litellm_completion_transformation.transformation import LiteLLMCompletionResponsesConfig from litellm.responses.utils import ResponseAPILoggingUtils, ResponsesAPIRequestUtils from litellm.types.llms.openai import ResponseAPIUsage, ResponsesAPIOptionalRequestParams, ResponsesAPIResponse -from litellm.types.utils import Usage +from litellm.types.utils import ModelInfo, Usage from litellm.utils import _invalidate_model_cost_lowercase_map @@ -413,6 +415,43 @@ class TestResponseAPILoggingUtils: assert result.prompt_tokens_details.cache_creation_tokens == 10059 assert result.prompt_tokens_details.cached_tokens == 0 + @pytest.mark.parametrize("as_model", [False, True]) + def test_transform_response_api_usage_prices_12h_cache_writes(self, as_model: bool) -> None: + usage_data: Final = { + "input_tokens": 5_000, + "output_tokens": 0, + "total_tokens": 5_000, + "input_tokens_details": { + "cache_write_tokens": 5_000, + "cache_write_tokens_details": {"ttl_30m_tokens": 3_000, "ttl_12h_tokens": 2_000}, + }, + } + usage_input: Final = ResponseAPIUsage(**usage_data) if as_model else usage_data + usage: Final = ResponseAPILoggingUtils.transform_response_api_usage_to_chat_usage(usage_input) + model_info: Final[ModelInfo] = { + "input_cost_per_token": 1e-6, + "output_cost_per_token": 2e-6, + "cache_creation_input_token_cost": 3e-6, + "cache_creation_input_token_cost_above_12hr": 5e-6, + } + + assert usage.prompt_tokens_details is not None + assert usage.prompt_tokens_details.cache_write_tokens == 5_000 + assert usage.prompt_tokens_details.cache_creation_token_details is not None + assert usage.prompt_tokens_details.cache_creation_token_details.ephemeral_12h_input_tokens == 2_000 + assert usage.prompt_tokens_details.cache_creation_token_details.ephemeral_30m_input_tokens == 3_000 + cost: Final = generic_cost_per_token( + model="test-12h-cache-write", + usage=usage, + custom_llm_provider="openai", + model_info=model_info, + )[0] + + assert cost == pytest.approx( + 3_000 * model_info["cache_creation_input_token_cost"] + + 2_000 * model_info["cache_creation_input_token_cost_above_12hr"] + ) + def test_transform_response_api_usage_mixed_details(self): """Test transformation handles mixed token details (cached + image + audio).""" # Setup - hypothetical usage with mixed token types @@ -894,6 +933,42 @@ class TestResponsesInputToChatMessages: ) == [user_message] +class TestMergeProviderSpecificHeaders: + def test_scoped_headers_merge_only_for_matching_provider(self): + scoped = {"custom_llm_provider": "chatgpt", "extra_headers": {"Authorization": "Bearer client-token"}} + + merged = ResponsesAPIRequestUtils.merge_provider_specific_headers( + extra_headers={"originator": "codex_cli_rs"}, + provider_specific_header=scoped, + custom_llm_provider="chatgpt", + ) + untouched = ResponsesAPIRequestUtils.merge_provider_specific_headers( + extra_headers={"originator": "codex_cli_rs"}, + provider_specific_header=scoped, + custom_llm_provider="openai", + ) + + assert merged == {"originator": "codex_cli_rs", "Authorization": "Bearer client-token"} + assert untouched == {"originator": "codex_cli_rs"} + + def test_sequence_of_scoped_entries_each_keep_their_own_scope(self): + entries = [ + {"custom_llm_provider": "anthropic", "extra_headers": {"Authorization": "Bearer anthropic-token"}}, + {"custom_llm_provider": "chatgpt", "extra_headers": {"Authorization": "Bearer chatgpt-token"}}, + ] + + merged = ResponsesAPIRequestUtils.merge_provider_specific_headers( + extra_headers=None, provider_specific_header=entries, custom_llm_provider="chatgpt" + ) + + assert merged == {"Authorization": "Bearer chatgpt-token"} + + def test_no_scoped_headers_returns_extra_headers_unchanged(self): + assert ResponsesAPIRequestUtils.merge_provider_specific_headers( + extra_headers=None, provider_specific_header=None, custom_llm_provider="chatgpt" + ) is None + + def test_responses_object_bills_an_explicit_cache_hit_at_the_explicit_rate(): model = "dashscope/qwen-responses-explicit-cache-test" previous_row = litellm.model_cost.get(model) diff --git a/tests/unit/router_strategy/test_complexity_router.py b/tests/unit/router_strategy/test_complexity_router.py index f956bb66e6c..2d27a025ffa 100644 --- a/tests/unit/router_strategy/test_complexity_router.py +++ b/tests/unit/router_strategy/test_complexity_router.py @@ -112,6 +112,13 @@ def _heuristic_v2_artifact() -> TrainedTierArtifact: ) +def _answer_deployments_named(router: MagicMock) -> None: + """Make a mock router answer `deployments_named` from its own `model_list`, the way Router answers from its index.""" + router.deployments_named.side_effect = lambda name: ( + tuple(deployment for deployment in router.model_list if deployment["model_name"] == name) or None + ) + + @pytest.fixture def mock_router_instance(): """Create a mock LiteLLM Router instance.""" @@ -1065,6 +1072,11 @@ class TestCustomDimensions: "create table widgets (id integer); ALTER TABLE widgets ADD label text;", id="regex", ), + pytest.param( + {"patterns": [r"\b(?Pcreate|alter)\s{1,4}?table\b"]}, + "CREATE TABLE widgets (id integer)", + id="named-group-alternation-lazy-repeat", + ), ], ) def test_custom_dimension_changes_only_matching_requests( @@ -3176,7 +3188,7 @@ class TestCapabilityClassifier: {"model_name": "efficient-model", "litellm_params": {"input_cost_per_token": 0.000001}}, {"model_name": "capable-model", "litellm_params": {"input_cost_per_token": 0.00001}}, ] - mock_router_instance.model_name_to_deployment_indices = {"efficient-model": [0], "capable-model": [1]} + _answer_deployments_named(mock_router_instance) router: Final = self._router( mock_router_instance, adaptive=True, @@ -5665,7 +5677,7 @@ class TestAdaptiveSoftFloors: "model_info": {"adaptive_router_preferences": {"quality_tier": 3, "strengths": []}}, }, ] - router.model_name_to_deployment_indices = {"cheap": [0], "premium": [1]} + _answer_deployments_named(router) return router @pytest.fixture @@ -6824,7 +6836,7 @@ class TestTierModelAffinity: ) -> ComplexityRouter: mock_router_instance.cache = DualCache() mock_router_instance.model_list = [] - mock_router_instance.model_name_to_deployment_indices = {} + _answer_deployments_named(mock_router_instance) return ComplexityRouter( model_name="affinity-router", litellm_router_instance=mock_router_instance, @@ -7542,7 +7554,7 @@ class TestSessionAffinity: "model_info": {}, }, ] - mock_router_instance.model_name_to_deployment_indices = {"cheap": [0]} + _answer_deployments_named(mock_router_instance) router = ComplexityRouter( model_name="hybrid", litellm_router_instance=mock_router_instance, @@ -7808,6 +7820,102 @@ class TestClassificationMode: assert pure.routing_decision["cause"] == "user_turn_continuation" assert hybrid.model == "gpt-4o-mini" + CODEX_USER_AGENT = "codex-tui/0.164.0 (Ubuntu 22.4.0; x86_64) screen (codex-tui; 0.164.0)" + COMPACTION_PROMPT = {"role": "user", "content": "Hello! Summarize the conversation so far."} + COMPACTION_SUMMARY = { + "role": "user", + "content": "Another language model started to solve this problem and produced a summary of its thinking " + "process. You also have access to the state of the tools that were used by that language model.\nHi.", + } + + def _codex_kwargs( + self, session_id: str, request_kind: str, transport: str = "client_metadata" + ) -> dict[str, object]: + turn_metadata: Final = json.dumps({"session_id": session_id, "request_kind": request_kind}) + carrier: Final = ( + {"client_metadata": {"x-codex-turn-metadata": turn_metadata}} + if transport == "client_metadata" + else {"proxy_server_request": {"headers": {"x-codex-turn-metadata": turn_metadata}}} + ) + return {"metadata": {"session_id": session_id, "user_agent": self.CODEX_USER_AGENT}, **carrier} + + @pytest.mark.asyncio + @pytest.mark.parametrize("transport", ["client_metadata", "header"]) + async def test_codex_compaction_request_replays_held_decision( + self, mock_router_instance, user_turn_config, transport + ): + """Codex's compaction call carries a synthetic user prompt; it must hold the session's + decision instead of classifying the prompt as a new human ask.""" + router = self._router(mock_router_instance, user_turn_config) + session = f"codex-compact-{transport}" + await router.async_pre_routing_hook( + model="test-model", request_kwargs=self._codex_kwargs(session, "turn"), messages=[self.REASONING_ASK] + ) + compaction = await router.async_pre_routing_hook( + model="test-model", + request_kwargs=self._codex_kwargs(session, "compaction", transport), + messages=[self.REASONING_ASK, self.ASSISTANT_ANSWER, self.COMPACTION_PROMPT], + ) + assert compaction.model == "o1-preview" + assert compaction.routing_decision["cause"] == "user_turn_continuation" + + @pytest.mark.asyncio + async def test_codex_post_compaction_summary_is_a_continuation(self, mock_router_instance, user_turn_config): + """The first request after a mid-turn compaction ends on Codex's summary fragment, which + is not a human ask, so the held decision carries on.""" + router = self._router(mock_router_instance, user_turn_config) + await router.async_pre_routing_hook( + model="test-model", + request_kwargs=self._codex_kwargs("codex-summary", "turn"), + messages=[self.REASONING_ASK], + ) + resumed = await router.async_pre_routing_hook( + model="test-model", + request_kwargs=self._codex_kwargs("codex-summary", "turn"), + messages=[self.REASONING_ASK, self.COMPACTION_SUMMARY], + ) + assert resumed.model == "o1-preview" + assert resumed.routing_decision["cause"] == "user_turn_continuation" + + @pytest.mark.asyncio + async def test_codex_summary_quoting_escalation_keyword_keeps_held_tier( + self, mock_router_instance, user_turn_config + ): + router = self._router(mock_router_instance, user_turn_config) + await router.async_pre_routing_hook( + model="test-model", request_kwargs=self._codex_kwargs("codex-quote", "turn"), messages=[self.SIMPLE_ASK] + ) + quoted_summary: Final = { + "role": "user", + "content": f"{self.COMPACTION_SUMMARY['content']} The user said LITELLM ESCALATE", + } + resumed = await router.async_pre_routing_hook( + model="test-model", + request_kwargs=self._codex_kwargs("codex-quote", "turn"), + messages=[self.SIMPLE_ASK, quoted_summary], + ) + assert resumed.model == "gpt-4o-mini" + assert resumed.routing_decision["cause"] == "user_turn_continuation" + + @pytest.mark.asyncio + async def test_codex_human_ask_after_compaction_reclassifies(self, mock_router_instance, user_turn_config): + router = self._router(mock_router_instance, user_turn_config) + await router.async_pre_routing_hook( + model="test-model", request_kwargs=self._codex_kwargs("codex-next", "turn"), messages=[self.REASONING_ASK] + ) + await router.async_pre_routing_hook( + model="test-model", + request_kwargs=self._codex_kwargs("codex-next", "compaction"), + messages=[self.REASONING_ASK, self.ASSISTANT_ANSWER, self.COMPACTION_PROMPT], + ) + next_ask = await router.async_pre_routing_hook( + model="test-model", + request_kwargs=self._codex_kwargs("codex-next", "turn"), + messages=[self.REASONING_ASK, self.COMPACTION_SUMMARY, self.SIMPLE_ASK], + ) + assert next_ask.model == "gpt-4o-mini" + assert next_ask.routing_decision["cause"] != "user_turn_continuation" + @pytest.mark.asyncio async def test_session_affinity_wins_when_both_knobs_are_on(self, mock_router_instance, user_turn_config): """With session_affinity also on, the pin short-circuits new asks too and keeps its own @@ -11346,7 +11454,7 @@ class TestClientHousekeepingCalls: "model_info": {"adaptive_router_preferences": {"quality_tier": 3, "strengths": []}}, }, ] - adaptive_instance.model_name_to_deployment_indices = {"cheap": [0], "premium": [1]} + _answer_deployments_named(adaptive_instance) router = ComplexityRouter( model_name="hybrid", litellm_router_instance=adaptive_instance, @@ -13437,7 +13545,7 @@ class TestPlanModeTierFloor: "model_info": {"adaptive_router_preferences": {"quality_tier": 3, "strengths": []}}, }, ] - adaptive_instance.model_name_to_deployment_indices = {"cheap": [0], "premium": [1]} + _answer_deployments_named(adaptive_instance) router = ComplexityRouter( model_name="hybrid", litellm_router_instance=adaptive_instance, @@ -14936,7 +15044,7 @@ class TestModalityRouting: elif path == "adaptive_pick_rewritten": config["adaptive"] = True mock_router_instance.model_list = [] - mock_router_instance.model_name_to_deployment_indices = {} + _answer_deployments_named(mock_router_instance) router = self._router(mock_router_instance, config, vision) result = await router.async_pre_routing_hook(model="m", request_kwargs=request_kwargs, messages=messages) assert result.model == expected_model diff --git a/tests/unit/router_strategy/test_lowest_latency.py b/tests/unit/router_strategy/test_lowest_latency.py index 9af5def0d56..706ec567710 100644 --- a/tests/unit/router_strategy/test_lowest_latency.py +++ b/tests/unit/router_strategy/test_lowest_latency.py @@ -176,6 +176,8 @@ def test_sync_chat_zero_completion_tokens_falls_back_to_seconds(): MODEL_GROUP = "gpt-4o-mini" FAST_TTFT_ID = "fast-ttft-short-output" SLOW_TTFT_ID = "slow-ttft-long-output" +FAST_API_BASE = "https://fast.example.test/v1" +SLOW_API_BASE = "https://slow.example.test/v1" STREAMING_DEPLOYMENTS = [ {"model_info": {"id": FAST_TTFT_ID}, "litellm_params": {}}, {"model_info": {"id": SLOW_TTFT_ID}, "litellm_params": {}}, @@ -407,6 +409,69 @@ async def test_async_get_available_deployments_treats_missing_samples_as_zero_la assert picked["model_info"]["id"] == DEPLOYMENT_ID +@pytest.mark.asyncio +@pytest.mark.parametrize( + ("ttft_samples", "expected_latency"), + [([-602.0], 0.0), ([10.0, 10.0, -40.0], 10.0), ([float("nan"), 2.0], 2.0)], + ids=["negative", "negative_average", "nan"], +) +async def test_unusable_ttft_samples_do_not_leave_the_buffer_window_empty( + ttft_samples: list[float], expected_latency: float +): + """``completion_start_time - start_time`` can be negative or NaN. With a non-zero + ``lowest_latency_buffer`` a negative average pushes ``lowest_latency + buffer`` + below every candidate, so the group must still route instead of raising + IndexError from ``random.choice``, and the bad samples must not reach the ranking.""" + cache: Final = DualCache() + handler: Final = LowestLatencyLoggingHandler(router_cache=cache, routing_args={"lowest_latency_buffer": 5}) + cache.set_cache( + key=f"{MODEL_GROUP}_map", + value={FAST_TTFT_ID: {"time_to_first_token_seconds": ttft_samples}}, + ) + metadata: Final[dict[str, object]] = {} + request_kwargs: Final[dict[str, object]] = {"stream": True, "metadata": metadata} + + picked = await handler.async_get_available_deployments( + model_group=MODEL_GROUP, + healthy_deployments=[{"model_info": {"id": FAST_TTFT_ID}, "litellm_params": {"api_base": FAST_API_BASE}}], + request_kwargs=request_kwargs, + ) + + assert picked is not None + assert picked["model_info"]["id"] == FAST_TTFT_ID + assert metadata["_latency_per_deployment"] == {FAST_API_BASE: expected_latency} + + +@pytest.mark.asyncio +async def test_unusable_ttft_samples_fall_back_to_recorded_latency(): + """A deployment whose TTFT samples are all unusable is ranked by its recorded + latency, so dirty samples cannot make it look like the fastest deployment.""" + cache: Final = DualCache() + handler: Final = LowestLatencyLoggingHandler(router_cache=cache, routing_args={"lowest_latency_buffer": 5}) + cache.set_cache( + key=f"{MODEL_GROUP}_map", + value={ + FAST_TTFT_ID: {"latency_normalized": [0.1], "time_to_first_token_seconds": [-600.0]}, + SLOW_TTFT_ID: {"latency_normalized": [5.0], "time_to_first_token_seconds": [-300.0]}, + }, + ) + metadata: Final[dict[str, object]] = {} + request_kwargs: Final[dict[str, object]] = {"stream": True, "metadata": metadata} + + picked = await handler.async_get_available_deployments( + model_group=MODEL_GROUP, + healthy_deployments=[ + {"model_info": {"id": FAST_TTFT_ID}, "litellm_params": {"api_base": FAST_API_BASE}}, + {"model_info": {"id": SLOW_TTFT_ID}, "litellm_params": {"api_base": SLOW_API_BASE}}, + ], + request_kwargs=request_kwargs, + ) + + assert picked is not None + assert picked["model_info"]["id"] == FAST_TTFT_ID + assert metadata["_latency_per_deployment"] == {FAST_API_BASE: 0.1, SLOW_API_BASE: 5.0} + + def _latency_router(routing_strategy_args: dict) -> Router: return Router( model_list=[ diff --git a/tests/unit/router_strategy/test_router_tag_regex_routing.py b/tests/unit/router_strategy/test_router_tag_regex_routing.py index 212c2627d88..46e79a1b8c8 100644 --- a/tests/unit/router_strategy/test_router_tag_regex_routing.py +++ b/tests/unit/router_strategy/test_router_tag_regex_routing.py @@ -121,6 +121,7 @@ async def test_claude_code_ua_routes_to_cc_deployment(): llm_router_instance=router, model="claude-sonnet", healthy_deployments=ALL_DEPLOYMENTS, + request_deployments=ALL_DEPLOYMENTS, request_kwargs={"metadata": {"user_agent": "claude-code/1.2.3"}}, ) assert len(result) == 1 @@ -135,6 +136,7 @@ async def test_regular_ua_routes_to_default_deployment(): llm_router_instance=router, model="claude-sonnet", healthy_deployments=ALL_DEPLOYMENTS, + request_deployments=ALL_DEPLOYMENTS, request_kwargs={"metadata": {"user_agent": "Mozilla/5.0 (browser)"}}, ) assert len(result) == 1 @@ -149,6 +151,7 @@ async def test_no_ua_routes_to_default_deployment(): llm_router_instance=router, model="claude-sonnet", healthy_deployments=ALL_DEPLOYMENTS, + request_deployments=ALL_DEPLOYMENTS, request_kwargs={"metadata": {}}, ) assert len(result) == 1 @@ -164,6 +167,7 @@ async def test_tag_routing_metadata_written_for_regex_match(): llm_router_instance=router, model="claude-sonnet", healthy_deployments=ALL_DEPLOYMENTS, + request_deployments=ALL_DEPLOYMENTS, request_kwargs={"metadata": metadata}, ) assert "tag_routing" in metadata @@ -181,6 +185,7 @@ async def test_tag_filtering_disabled_returns_all_deployments(): llm_router_instance=router, model="claude-sonnet", healthy_deployments=ALL_DEPLOYMENTS, + request_deployments=ALL_DEPLOYMENTS, request_kwargs={"metadata": {"user_agent": "claude-code/1.0"}}, ) assert result == ALL_DEPLOYMENTS @@ -199,6 +204,7 @@ async def test_empty_healthy_deployments_with_request_tags_returns_empty_list(): llm_router_instance=router, model="gpt-5.2", healthy_deployments=[], + request_deployments=[], request_kwargs={ "metadata": {"tags": ["client_id:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"]} }, @@ -228,6 +234,7 @@ async def test_explicit_tag_match_takes_precedence_over_regex(): llm_router_instance=router, model="claude-sonnet", healthy_deployments=[deployment_with_both], + request_deployments=[deployment_with_both], request_kwargs={"metadata": metadata}, ) assert len(result) == 1 @@ -269,6 +276,7 @@ async def test_user_agent_present_no_tag_regex_deployments_does_not_raise(): llm_router_instance=router, model="gpt-4", healthy_deployments=plain_tag_only_deployments, + request_deployments=plain_tag_only_deployments, request_kwargs={"metadata": {"user_agent": "Mozilla/5.0 (any-client)"}}, ) # Falls through to "return healthy_deployments" path unchanged @@ -305,6 +313,7 @@ async def test_tag_routing_metadata_not_overwritten_for_multiple_matches(): llm_router_instance=router, model="claude-sonnet", healthy_deployments=[deployment_a, deployment_b], + request_deployments=[deployment_a, deployment_b], request_kwargs={"metadata": metadata}, ) assert len(result) == 2 @@ -357,6 +366,7 @@ async def test_match_any_false_strict_tag_check_blocks_regex_fallback(): llm_router_instance=router, model="claude-sonnet", healthy_deployments=[deployment_strict, default_deployment], + request_deployments=[deployment_strict, default_deployment], request_kwargs={"metadata": metadata}, ) ids = [d["model_info"]["id"] for d in result] @@ -387,6 +397,7 @@ async def test_match_any_false_regex_only_deployment_still_matches(): llm_router_instance=router, model="claude-sonnet", healthy_deployments=[regex_only_deployment], + request_deployments=[regex_only_deployment], request_kwargs={"metadata": {"user_agent": "claude-code/1.0"}}, ) assert len(result) == 1 diff --git a/tests/unit/router_strategy/test_router_tag_routing.py b/tests/unit/router_strategy/test_router_tag_routing.py index 097a34cf2e6..26d04be7e25 100644 --- a/tests/unit/router_strategy/test_router_tag_routing.py +++ b/tests/unit/router_strategy/test_router_tag_routing.py @@ -3,12 +3,14 @@ import logging -from typing import Final +from typing import Final, Literal +from unittest.mock import patch import pytest import litellm from litellm._logging import verbose_logger +from litellm.responses.utils import ResponsesAPIRequestUtils from litellm.router_strategy.tag_based_routing import get_deployments_for_tag from litellm.types.router import RouterErrors @@ -1367,14 +1369,17 @@ def test_chain_allows_fail_open_true_when_any_member_sets_flag(): {"model_info": {}, "litellm_params": {"tags": ["provider:anthropic"]}}, {"model_info": {"allow_fail_open": True}, "litellm_params": {"tags": ["provider:openai"]}}, ] - assert _chain_allows_fail_open(deployments, frozenset(), frozenset({"provider:anthropic"}), frozenset()) is True + assert ( + _chain_allows_fail_open(deployments, deployments, frozenset(), frozenset({"provider:anthropic"}), frozenset()) + is True + ) def test_chain_allows_fail_open_false_by_default(): from litellm.router_strategy.tag_based_routing import _chain_allows_fail_open deployments = [{"model_info": {}}, {}] - assert _chain_allows_fail_open(deployments, frozenset(), frozenset(), frozenset()) is False + assert _chain_allows_fail_open(deployments, deployments, frozenset(), frozenset(), frozenset()) is False def test_chain_allows_fail_open_true_when_no_required_tag_is_known_at_all(): @@ -1386,7 +1391,10 @@ def test_chain_allows_fail_open_true_when_no_required_tag_is_known_at_all(): deployments = [ {"model_info": {"allow_fail_open": True}, "litellm_params": {"tags": ["default", "reasoning_type:low"]}}, ] - assert _chain_allows_fail_open(deployments, frozenset(), frozenset({"reasoning_type:high"}), frozenset()) is True + assert ( + _chain_allows_fail_open(deployments, deployments, frozenset(), frozenset({"reasoning_type:high"}), frozenset()) + is True + ) def test_unknown_required_tag_hides_an_answer_denies_fail_open(): @@ -1407,7 +1415,11 @@ def test_unknown_required_tag_hides_an_answer_denies_fail_open(): # fail-open must be denied even though the flag is set on the group. assert ( _chain_allows_fail_open( - deployments, frozenset(), frozenset({"region:us-east", "totally-invented-tag-nobody-has"}), frozenset() + deployments, + deployments, + frozenset(), + frozenset({"region:us-east", "totally-invented-tag-nobody-has"}), + frozenset(), ) is False ) @@ -1434,7 +1446,9 @@ def test_unknown_required_tag_allows_fail_open_when_no_answer_is_hidden(): # carries both, so this is a genuinely unsatisfiable combination, not an invented # tag masking a narrower answer. Fail-open must proceed normally. assert ( - _chain_allows_fail_open(deployments, frozenset(), frozenset({"region:us-east", "region:eu"}), frozenset()) + _chain_allows_fail_open( + deployments, deployments, frozenset(), frozenset({"region:us-east", "region:eu"}), frozenset() + ) is True ) @@ -1496,8 +1510,8 @@ def test_chain_allows_fail_open_true_when_prefixed_unknown_required_tag_is_confi }, ] required_set = frozenset({"provider:anthropic", "typo-tag"}) - assert _chain_allows_fail_open(deployments, frozenset(), required_set, frozenset()) is False - assert _chain_allows_fail_open(deployments, frozenset(), required_set, required_set) is True + assert _chain_allows_fail_open(deployments, deployments, frozenset(), required_set, frozenset()) is False + assert _chain_allows_fail_open(deployments, deployments, frozenset(), required_set, required_set) is True # --- get_deployments_for_tag required-AND ("&") integration tests --- @@ -1765,6 +1779,141 @@ async def test_required_and_combined_with_positive_unmatched_raises_by_default() # --- get_deployments_for_tag allow_fail_open integration tests --- +def _fail_open_router(opted_in_group: str | None = "chat", route: str = "model") -> litellm.Router: + model_name: Final = "chat-*" if route == "wildcard" else "chat" + team_info: Final = {"team_id": "team-a", "team_public_model_name": "public-chat"} if route == "team" else {} + return litellm.Router( + model_list=[ + { + "model_name": model_name if opted_in_group in (None, "chat") else opted_in_group, + "litellm_params": {"model": "openai/gpt-6.1-sol", "api_key": "unused", "tags": ["vision"]}, + "model_info": {"id": "opted-in", "allow_fail_open": opted_in_group is not None, **team_info}, + }, + { + "model_name": model_name, + "litellm_params": {"model": "openai/gpt-6.1-sol", "api_key": "unused", "tags": ["region:eu"]}, + "model_info": {"id": "remaining", **team_info}, + }, + ], + routing_groups=( + [{"group_name": "public-chat", "models": ["chat"], "routing_strategy": "simple-shuffle"}] + if route == "routing_group" + else None + ), + model_group_alias={"public-chat": "chat"} if route == "alias" else {}, + enable_tag_filtering=True, + optional_pre_call_checks=["responses_api_deployment_check"], + ) + + +def _response_id_for_remaining_deployment() -> str: + return ResponsesAPIRequestUtils._build_responses_api_response_id( + custom_llm_provider="openai", model_id="remaining", response_id="resp_previous" + ) + + +@pytest.mark.asyncio() +@pytest.mark.parametrize("narrowing", ("affinity", "cooldown")) +@pytest.mark.parametrize("tags", (("component:chat-search",), ("&vision",), ("!region:eu",))) +@pytest.mark.parametrize("route", ("model", "routing_group", "wildcard", "team", "alias")) +async def test_tag_fail_open_survives_deployment_narrowing( + narrowing: Literal["affinity", "cooldown"], tags: tuple[str, ...], route: str +) -> None: + router: Final = _fail_open_router(route=route) + requested_model: Final = "chat" if route == "model" else "chat-test" if route == "wildcard" else "public-chat" + with patch("time.time", return_value=1_700_000_000.0): + if narrowing == "cooldown": + router.cooldown_cache.add_deployment_to_cooldown( + model_id="opted-in", + original_exception=RuntimeError("unavailable"), + exception_status=500, + cooldown_time=60, + ) + candidates: Final = await router.async_get_healthy_deployments( + model=requested_model, + request_kwargs={ + "litellm_metadata": {"tags": list(tags), "inherited_tags": [], "user_api_key_team_id": "team-a"}, + **( + {"previous_response_id": _response_id_for_remaining_deployment()} if narrowing == "affinity" else {} + ), + }, + ) + assert isinstance(candidates, (list, tuple)) + assert tuple(deployment["model_info"]["id"] for deployment in candidates) == ("remaining",) + + +@pytest.mark.asyncio() +@pytest.mark.parametrize("route", ("routing_group", "wildcard", "team", "alias")) +async def test_tag_fail_open_resolves_public_model_names(route: str) -> None: + router: Final = _fail_open_router(route=route) + candidates: Final = await router.async_get_healthy_deployments( + model="chat-test" if route == "wildcard" else "public-chat", + request_kwargs={ + "litellm_metadata": {"tags": ["component:chat-search"], "user_api_key_team_id": "team-a"}, + }, + ) + assert isinstance(candidates, (list, tuple)) + assert {deployment["model_info"]["id"] for deployment in candidates} == {"opted-in", "remaining"} + + +@pytest.mark.asyncio() +@pytest.mark.parametrize("opted_in_group", (None, "other-group")) +async def test_tag_fail_open_requires_opt_in_in_the_requested_group(opted_in_group: str | None) -> None: + router: Final = _fail_open_router(opted_in_group) + with pytest.raises(ValueError, match=RouterErrors.no_deployments_with_tag_routing.value): + await router.async_get_healthy_deployments( + model="chat", + request_kwargs={ + "previous_response_id": _response_id_for_remaining_deployment(), + "litellm_metadata": {"tags": ["component:chat-search"], "inherited_tags": []}, + }, + ) + + +@pytest.mark.asyncio() +async def test_tag_fail_open_does_not_use_another_teams_opt_in() -> None: + router: Final = litellm.Router( + model_list=[ + { + "model_name": "chat", + "litellm_params": {"model": "openai/gpt-6.1-sol", "api_key": "unused"}, + "model_info": { + "id": team_id, + "team_id": team_id, + "team_public_model_name": "public-chat", + "allow_fail_open": team_id == "team-a", + }, + } + for team_id in ("team-a", "team-b") + ], + enable_tag_filtering=True, + ) + with pytest.raises(ValueError, match=RouterErrors.no_deployments_with_tag_routing.value): + await router.async_get_healthy_deployments( + model="public-chat", + request_kwargs={ + "litellm_metadata": {"tags": ["component:chat-search"], "user_api_key_team_id": "team-b"}, + }, + ) + + +@pytest.mark.asyncio() +@pytest.mark.parametrize("inherited_tag", ("&vision", "!region:eu")) +async def test_tag_fail_open_preserves_inherited_policy_after_affinity(inherited_tag: str) -> None: + router: Final = _fail_open_router() + with pytest.raises(ValueError, match=RouterErrors.no_deployments_with_tag_routing.value): + await router.async_get_healthy_deployments( + model="chat", + request_kwargs={ + "previous_response_id": _response_id_for_remaining_deployment(), + "litellm_metadata": { + "tags": [inherited_tag, "component:chat-search"], + "inherited_tags": [inherited_tag], + }, + }, + ) + + @pytest.mark.asyncio() async def test_allow_fail_open_required_and_unmatched_falls_back_to_default_pool(): router = litellm.Router( @@ -3305,10 +3454,12 @@ async def _routed_to(router: litellm.Router, metadata: dict[str, object]) -> str async def _pool(router: litellm.Router, metadata: dict[str, object]) -> frozenset[str]: + request_deployments: Final = router.get_model_list(model_name="chat") deployments: Final = await get_deployments_for_tag( llm_router_instance=router, model="chat", - healthy_deployments=router.get_model_list(model_name="chat"), + healthy_deployments=request_deployments, + request_deployments=request_deployments, request_kwargs={"metadata": metadata}, ) return frozenset(deployment["model_info"]["id"] for deployment in deployments) diff --git a/tests/unit/router_strategy/test_savings_baseline.py b/tests/unit/router_strategy/test_savings_baseline.py index 5efc73d2dcb..4241a541202 100644 --- a/tests/unit/router_strategy/test_savings_baseline.py +++ b/tests/unit/router_strategy/test_savings_baseline.py @@ -107,8 +107,7 @@ class TestResolveBaseline: served; a dashboard counterfactual must not be able to take routing down.""" class Exploding: - @property - def model_name_to_deployment_indices(self): + def deployments_named(self, model_name): raise RuntimeError("router is mid-reload") assert resolve_baseline(Exploding(), ["anything"]) is None diff --git a/tests/unit/router_utils/pre_call_checks/test_session_id_affinity.py b/tests/unit/router_utils/pre_call_checks/test_session_id_affinity.py index 9bbaed0ae1b..6b4ea74894a 100644 --- a/tests/unit/router_utils/pre_call_checks/test_session_id_affinity.py +++ b/tests/unit/router_utils/pre_call_checks/test_session_id_affinity.py @@ -1,20 +1,368 @@ import asyncio import json from typing import Final +from collections.abc import AsyncIterator, Mapping +from datetime import datetime, timezone from unittest.mock import AsyncMock, MagicMock, patch import pytest +from fakeredis import FakeRedis, FakeServer +from fakeredis.aioredis import FakeConnection +from redis.asyncio import BlockingConnectionPool, Redis import litellm from litellm.caching.affinity_cache import claim_affinity_pin from litellm.caching.dual_cache import DualCache from litellm.caching.in_memory_cache import InMemoryCache +from litellm.caching.redis_cache import RedisCache from litellm.constants import SESSION_DEPLOYMENT_AFFINITY_TTL_METADATA_KEY, SESSION_ID_GENERATED_METADATA_KEY from litellm.router_utils.pre_call_checks.deployment_affinity_check import ( DeploymentAffinityCheck, ) +def _repinning_router(enabled: bool | None = True) -> litellm.Router: + return litellm.Router( + model_list=[ + { + "model_name": "repin-group", + "litellm_params": {"model": "openai/test-model", "api_key": "fake-api-key"}, + "model_info": {"id": deployment_id}, + } + for deployment_id in ("original", "replacement", "other") + ] + + [ + { + "model_name": "unrelated-group", + "litellm_params": {"model": "openai/test-model", "api_key": "fake-api-key"}, + "model_info": {"id": "unrelated"}, + } + ], + optional_pre_call_checks=["session_affinity", "deployment_affinity"], + **({"session_affinity_repin_on_failover": enabled} if enabled is not None else {}), + ) + + +def _repin_params(deployment_id: str, caller: str = "caller-1") -> dict[str, object]: + return { + "model_info": {"id": deployment_id}, + "metadata": { + "model_group": "repin-group", + "deployment_model_name": "repin-group", + "session_id": "repin-session", + "user_api_key_hash": caller, + }, + } + + +def _repin_key(caller: str = "caller-1") -> str: + return DeploymentAffinityCheck.get_session_affinity_cache_key("repin-group", "repin-session", caller) + + +def _cool_down_original(router: litellm.Router) -> None: + router.cooldown_cache.add_deployment_to_cooldown( + model_id="original", original_exception=RuntimeError("test outage"), exception_status=503, cooldown_time=3600 + ) + + +async def _record_replacement_success( + router: litellm.Router, deployment_id: str = "replacement", response: object = None +) -> None: + timestamp: Final = datetime(2026, 1, 1, tzinfo=timezone.utc) + await router.deployment_callback_on_success( + {"litellm_params": _repin_params(deployment_id), "standard_logging_object": {"total_tokens": 0}}, + {"choices": [{"message": {"content": "ok"}}]} if response is None else response, + timestamp, + timestamp, + ) + + +@pytest.mark.parametrize("enabled", [None, False, True], ids=["default", "disabled", "enabled"]) +@pytest.mark.parametrize("unavailable", ["cooldown", "removed", "temporary-filter"]) +async def test_session_repin_requires_opt_in_unavailable_original_and_success( + enabled: bool | None, unavailable: str +) -> None: + router: Final = _repinning_router(enabled) + try: + await router.cache.async_set_cache(_repin_key(), {"model_id": "original"}) + await router.cache.async_set_cache(_repin_key("caller-2"), {"model_id": "original"}) + user_key: Final = DeploymentAffinityCheck.get_affinity_cache_key("repin-group", "caller-1") + await router.cache.async_set_cache(user_key, {"model_id": "original"}) + if unavailable == "cooldown": + _cool_down_original(router) + elif unavailable == "removed": + router.delete_deployment("original") + callback: Final = next(cb for cb in router.optional_callbacks or () if isinstance(cb, DeploymentAffinityCheck)) + await callback.async_pre_call_deployment_hook(_repin_params("replacement"), None) + assert await router.cache.async_get_cache(_repin_key()) == {"model_id": "original"} + await _record_replacement_success(router) + expected: Final = "replacement" if enabled and unavailable != "temporary-filter" else "original" + assert await router.cache.async_get_cache(_repin_key()) == {"model_id": expected} + assert await router.cache.async_get_cache(_repin_key("caller-2")) == {"model_id": "original"} + assert await router.cache.async_get_cache(user_key) == {"model_id": "original"} + router.cooldown_cache.cooldown_store.flush_cache() + await _record_replacement_success(router, "other") + assert await router.cache.async_get_cache(_repin_key()) == {"model_id": expected} + finally: + router.discard() + + +@pytest.mark.parametrize("status", ["failed", "incomplete", "in_progress", "cancelled"]) +@pytest.mark.parametrize("wrapped", [False, True]) +async def test_unsuccessful_responses_do_not_repin(status: str, wrapped: bool) -> None: + router: Final = _repinning_router() + try: + await router.cache.async_set_cache(_repin_key(), {"model_id": "original"}) + _cool_down_original(router) + response: Final[Mapping[str, object]] = {"status": status} + await _record_replacement_success(router, response={"response": response} if wrapped else response) + assert await router.cache.async_get_cache(_repin_key()) == {"model_id": "original"} + finally: + router.discard() + + +async def test_concurrent_successful_replacements_keep_first_winner() -> None: + router: Final = _repinning_router() + try: + await router.cache.async_set_cache(_repin_key(), {"model_id": "original"}) + _cool_down_original(router) + await asyncio.gather(_record_replacement_success(router), _record_replacement_success(router, "other")) + winner: Final = await router.cache.async_get_cache(_repin_key()) + assert winner in ({"model_id": "replacement"}, {"model_id": "other"}) + router.cooldown_cache.cooldown_store.flush_cache() + await _record_replacement_success(router, "original") + assert await router.cache.async_get_cache(_repin_key()) == winner + finally: + router.discard() + + +async def test_healthy_legacy_string_pin_is_preserved_with_repinning_enabled() -> None: + router: Final = _repinning_router() + try: + await router.cache.async_set_cache(_repin_key(), "original") + await _record_replacement_success(router) + assert await router.cache.async_get_cache(_repin_key()) == "original" + finally: + router.discard() + + +@pytest.mark.parametrize("route_bucket", ["metadata", "litellm_metadata"]) +async def test_repin_session_after_success_reads_split_metadata(route_bucket: str) -> None: + router: Final = _repinning_router() + try: + await router.cache.async_set_cache(_repin_key(), {"model_id": "original"}) + _cool_down_original(router) + session_bucket: Final = "litellm_metadata" if route_bucket == "metadata" else "metadata" + await router._repin_session_after_success( + { + "model_info": {"id": "replacement"}, + route_bucket: {"deployment_model_name": "repin-group"}, + session_bucket: {"session_id": "repin-session", "user_api_key_hash": "caller-1"}, + }, + {"status": "completed"}, + ) + assert await router.cache.async_get_cache(_repin_key()) == {"model_id": "replacement"} + finally: + router.discard() + + +@pytest.mark.parametrize("enabled", [False, True]) +async def test_session_selection_observes_another_workers_repin_only_when_enabled(enabled: bool) -> None: + server: Final = FakeServer() + sync_client: Final = FakeRedis(server=server) + pool: Final = BlockingConnectionPool(connection_class=FakeConnection, server=server) + router: Final = _repinning_router(enabled) + try: + with ( + patch("redis.Redis.from_url", return_value=sync_client), + patch("redis.asyncio.BlockingConnectionPool.from_url", return_value=pool), + ): + redis: Final = RedisCache(url=f"redis://repin-cache.example:6379/{int(enabled)}") + router.cache.attach_redis_cache(redis) + other_worker: Final = DualCache(redis_cache=redis) + router.cache.in_memory_cache.set_cache(_repin_key(), {"model_id": "original"}, ttl=3600) + await other_worker.async_set_cache(_repin_key(), {"model_id": "replacement"}, ttl=3600) + callback: Final = next( + cb for cb in router.optional_callbacks or () if isinstance(cb, DeploymentAffinityCheck) + ) + selected: Final = await callback.async_filter_deployments( + model="repin-group", + healthy_deployments=router.get_model_list(model_name="repin-group") or [], + messages=None, + request_kwargs=_repin_params("replacement"), + ) + assert [deployment["model_info"]["id"] for deployment in selected] == [ + "replacement" if enabled else "original" + ] + finally: + router.discard() + await pool.aclose() + sync_client.close() + + +@pytest.fixture +async def shared_session_router() -> AsyncIterator[tuple[litellm.Router, FakeServer, RedisCache]]: + server: Final = FakeServer() + sync_client: Final = FakeRedis(server=server) + pool: Final = BlockingConnectionPool(connection_class=FakeConnection, server=server) + router: Final = _repinning_router() + try: + with ( + patch("redis.Redis.from_url", return_value=sync_client), + patch("redis.asyncio.BlockingConnectionPool.from_url", return_value=pool), + ): + redis: Final = RedisCache(url="redis://session-outage.example:6379/0") + router.cache.attach_redis_cache(redis) + yield router, server, redis + finally: + router.discard() + await pool.aclose() + sync_client.close() + + +async def _selected_session_ids(router: litellm.Router) -> tuple[str, ...]: + callback: Final = next(cb for cb in router.optional_callbacks or () if isinstance(cb, DeploymentAffinityCheck)) + selected: Final = await callback.async_filter_deployments( + model="repin-group", + healthy_deployments=router.get_model_list(model_name="repin-group") or [], + messages=None, + request_kwargs=_repin_params("replacement"), + ) + return tuple(deployment["model_info"]["id"] for deployment in selected) + + +@pytest.mark.parametrize("has_pin", [False, True]) +async def test_redis_read_failures_and_open_breaker_preserve_session_routing( + shared_session_router: tuple[litellm.Router, FakeServer, RedisCache], has_pin: bool +) -> None: + router, server, redis = shared_session_router + if has_pin: + await redis.async_set_cache(_repin_key(), {"model_id": "replacement"}, ttl=3600) + router.cache.in_memory_cache.set_cache(_repin_key(), {"model_id": "original"}, ttl=3600) + assert await _selected_session_ids(router) == ("replacement",) + server.connected = False + with patch("time.time", return_value=1790000000.0): + for _ in range(redis._circuit_breaker.failure_threshold + 1): + assert set(await _selected_session_ids(router)) == ( + {"replacement"} if has_pin else {"original", "replacement", "other"} + ) + assert redis._circuit_breaker.is_open() + + +async def test_confirmed_redis_miss_does_not_revive_a_local_pin_during_outage( + shared_session_router: tuple[litellm.Router, FakeServer, RedisCache], +) -> None: + router, server, _ = shared_session_router + router.cache.in_memory_cache.set_cache(_repin_key(), {"model_id": "original"}, ttl=3600) + assert set(await _selected_session_ids(router)) == {"original", "replacement", "other"} + server.connected = False + assert set(await _selected_session_ids(router)) == {"original", "replacement", "other"} + + +async def test_shared_session_pin_resumes_after_a_transient_redis_failure( + shared_session_router: tuple[litellm.Router, FakeServer, RedisCache], +) -> None: + router, server, redis = shared_session_router + await redis.async_set_cache(_repin_key(), {"model_id": "replacement"}, ttl=3600) + router.cache.in_memory_cache.set_cache(_repin_key(), {"model_id": "original"}, ttl=3600) + server.connected = False + assert await _selected_session_ids(router) == ("original",) + server.connected = True + assert await _selected_session_ids(router) == ("replacement",) + + +@pytest.mark.parametrize("shared_value", [None, {"model_id": "original"}]) +async def test_delayed_shared_pin_read_preserves_a_newer_local_write( + shared_session_router: tuple[litellm.Router, FakeServer, RedisCache], shared_value: Mapping[str, str] | None +) -> None: + router, server, redis = shared_session_router + if shared_value is not None: + await redis.async_set_cache(_repin_key(), shared_value, ttl=3600) + observed: Final = asyncio.Event() + resume: Final = asyncio.Event() + + class DelayedReader(Redis): + async def get(self, name: str) -> object: + value: Final = await super().get(name) + observed.set() + await resume.wait() + return value + + reader: Final = DelayedReader(connection_pool=redis.init_async_client().connection_pool) + litellm.in_memory_llm_clients_cache.set_cache(key=redis._get_async_client_cache_key(), value=reader) + pending: Final = asyncio.create_task(_selected_session_ids(router)) + try: + await observed.wait() + router.cache.in_memory_cache.set_cache(_repin_key(), {"model_id": "replacement"}, ttl=3600) + finally: + resume.set() + await pending + server.connected = False + assert await _selected_session_ids(router) == ("replacement",) + + +@pytest.mark.parametrize( + "response", + [ + {"status": "failed", "response": {"status": "completed"}}, + {"error": {"message": "test failure"}, "response": {"status": "completed"}}, + {"response": {"response": {"status": "completed"}}}, + ], +) +async def test_unsuccessful_or_nested_response_envelopes_never_repin(response: Mapping[str, object]) -> None: + router: Final = _repinning_router() + try: + await router.cache.async_set_cache(_repin_key(), {"model_id": "original"}) + _cool_down_original(router) + await _record_replacement_success(router, response=response) + assert await router.cache.async_get_cache(_repin_key()) == {"model_id": "original"} + finally: + router.discard() + + +class _ReadCountingCache(InMemoryCache): + def __init__(self) -> None: + super().__init__() + self.read_keys: tuple[str, ...] = () + + def get_cache(self, key: str, **kwargs: object) -> object: + self.read_keys += (key,) + return super().get_cache(key, **kwargs) + + +@pytest.mark.parametrize("case", ["disabled", "no-session", "generated-session", "group-disabled", "active"]) +async def test_repin_cooldown_reads_are_limited_to_active_session_route(case: str) -> None: + router: Final = _repinning_router(case != "disabled") + reads: Final = _ReadCountingCache() + try: + router.cooldown_cache.cooldown_store.in_memory_cache = reads + callback: Final = next(cb for cb in router.optional_callbacks or () if isinstance(cb, DeploymentAffinityCheck)) + if case == "group-disabled": + callback.model_group_affinity_config = {"repin-group": []} + await router._repin_session_after_success( + { + "model_info": {"id": "replacement"}, + "metadata": { + "deployment_model_name": "repin-group", + **({"session_id": "repin-session"} if case != "no-session" else {}), + SESSION_ID_GENERATED_METADATA_KEY: case == "generated-session", + }, + }, + {"status": "completed"}, + ) + expected: Final = ( + { + router.cooldown_cache.get_cooldown_cache_key(model_id) + for model_id in ("original", "replacement", "other") + } + if case == "active" + else set() + ) + assert set(reads.read_keys) == expected + finally: + router.discard() + + class MockResponse: def __init__(self, json_data, status_code): self._json_data = json_data diff --git a/tests/unit/router_utils/test_fallback_event_handlers.py b/tests/unit/router_utils/test_fallback_event_handlers.py index 75b6ab04446..53375ee0ab4 100644 --- a/tests/unit/router_utils/test_fallback_event_handlers.py +++ b/tests/unit/router_utils/test_fallback_event_handlers.py @@ -16,7 +16,7 @@ from pydantic import TypeAdapter import litellm from litellm import Router from litellm.integrations.custom_logger import CustomLogger -from litellm.llms.anthropic.pass_through.messages.fake_stream_iterator import FakeAnthropicMessagesStreamIterator +from litellm.llms.anthropic.messages.native.fake_stream_iterator import FakeAnthropicMessagesStreamIterator from litellm.litellm_core_utils import get_llm_provider_logic from litellm.litellm_core_utils.litellm_logging import Logging from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapper diff --git a/tests/unit/router_utils/test_reasoning_effort_capability.py b/tests/unit/router_utils/test_reasoning_effort_capability.py index d634e239ea9..d0564812c48 100644 --- a/tests/unit/router_utils/test_reasoning_effort_capability.py +++ b/tests/unit/router_utils/test_reasoning_effort_capability.py @@ -203,7 +203,7 @@ class TestNoneLevelPolarity: def test_azure_advertisement_matches_the_azure_request_gate(self, model_key): """AzureOpenAIGPT5Config raises UnsupportedParamsError on reasoning_effort='none' for models it does not flag, so advertising the level there would offer routing a 400.""" - from litellm.llms.azure.chat.gpt_5_transformation import AzureOpenAIGPT5Config + from litellm.llms.azure.chat.gpt_reasoning_transformation import AzureOpenAIGPT5Config from litellm.utils import get_model_info_helper model_info = dict(get_model_info_helper(model=model_key.split("/", 1)[1], custom_llm_provider="azure")) diff --git a/tests/unit/rust_bridge/messages/test_secrets.py b/tests/unit/rust_bridge/messages/test_secrets.py index 64208182025..f6439753809 100644 --- a/tests/unit/rust_bridge/messages/test_secrets.py +++ b/tests/unit/rust_bridge/messages/test_secrets.py @@ -9,7 +9,7 @@ import pytest import litellm from litellm.integrations.custom_secret_manager import CustomSecretManager -from litellm.llms.anthropic.pass_through.messages.handler import anthropic_messages +from litellm.llms.anthropic.messages.native.handler import anthropic_messages from litellm.rust_bridge.host import settings from litellm.rust_bridge.messages.entrypoints import NATIVE_AMESSAGES, NATIVE_MESSAGES from litellm.rust_bridge.public_call import NativeCall diff --git a/tests/unit/secret_managers/test_google_secret_manager.py b/tests/unit/secret_managers/test_google_secret_manager.py index 2051be08f7c..7effde4fb30 100644 --- a/tests/unit/secret_managers/test_google_secret_manager.py +++ b/tests/unit/secret_managers/test_google_secret_manager.py @@ -1,6 +1,7 @@ import base64 import binascii import json +from collections import OrderedDict from dataclasses import dataclass from typing import Final @@ -120,7 +121,7 @@ def manager(monkeypatch: pytest.MonkeyPatch) -> GoogleSecretManager: monkeypatch.setattr(litellm, "secret_manager_client", None) monkeypatch.setattr(litellm, "_key_management_system", None) monkeypatch.setattr(litellm, "_key_management_settings", KeyManagementSettings()) - monkeypatch.setattr(litellm.vertex_chat_completion, "_credentials_project_mapping", {}) + monkeypatch.setattr(litellm.vertex_chat_completion, "_credentials_project_mapping", OrderedDict()) monkeypatch.setattr(google.auth, "default", _default_credentials) monkeypatch.setenv("GOOGLE_SECRET_MANAGER_PROJECT_ID", PROJECT_ID) monkeypatch.delenv("GOOGLE_SECRET_MANAGER_ALWAYS_READ_SECRET_MANAGER", raising=False) diff --git a/tests/unit/systemone/test_main.py b/tests/unit/systemone/test_main.py index 05a9850a221..80713c1ea2b 100644 --- a/tests/unit/systemone/test_main.py +++ b/tests/unit/systemone/test_main.py @@ -5,8 +5,10 @@ import json from collections.abc import Mapping from types import MappingProxyType from typing import Final +from uuid import uuid4 import pytest +import responses import respx from respx.models import Call @@ -34,6 +36,48 @@ _CLOUDFLARE_CLEF_URL: Final = f"{_CLOUDFLARE_API_BASE}/@cf/cloudflare/clef" _PNG_DATA_URL: Final = "data:image/png;base64,AA==" +@responses.activate +@pytest.mark.parametrize("use_async", (True, False), ids=("asystemone", "systemone")) +@pytest.mark.parametrize("model", ("ai_decide", "serving-decider")) +@pytest.mark.parametrize("base_from_env", (True, False)) +async def test_should_authenticate_databricks_systemone_with_oauth_m2m( + monkeypatch: pytest.MonkeyPatch, + respx_mock: respx.MockRouter, + use_async: bool, + model: str, + base_from_env: bool, +) -> None: + monkeypatch.setenv("DATABRICKS_CLIENT_ID", "synthetic-client") + monkeypatch.setenv("DATABRICKS_CLIENT_SECRET", f"synthetic-{uuid4().hex}") + monkeypatch.setenv("DATABRICKS_API_BASE", "https://workspace.example/serving-endpoints") + token: Final = responses.post( + "https://workspace.example/oidc/v1/token", json={"access_token": "oauth-token", "expires_in": 3600} + ) + url: Final = ( + "https://workspace.example/api/2.0/ai-functions/ai-decide" + if model == "ai_decide" + else f"https://workspace.example/serving-endpoints/{model}/invocations" + ) + upstream_response: Final = {"answers": {"is_refund": {"type": "noul", "noul": 0.93}}} + route: Final = respx_mock.post(url).respond( + json={"response": upstream_response} if model == "ai_decide" else upstream_response + ) + kwargs: Final[Mapping[str, object]] = { + "model": f"databricks/{model}", + "state": _STATE, + "questions": _SYSTEMONE_QUESTIONS, + **({} if base_from_env else {"api_base": "https://workspace.example/serving-endpoints"}), + } + + for _ in range(2): + result: Final = await litellm.asystemone(**kwargs) if use_async else litellm.systemone(**kwargs) + assert isinstance(result, DecisionsResponse) + assert result.answers["is_refund"].model_dump(mode="json") == {"type": "noul", "noul": 0.93} + assert route.calls.last.request.headers["Authorization"] == "Bearer oauth-token" + assert route.call_count == 2 + assert token.call_count == 1 + + @pytest.fixture(autouse=True) def _httpx_transport(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) diff --git a/tests/unit/test_auto_update_price_and_context_window_file.py b/tests/unit/test_auto_update_price_and_context_window_file.py deleted file mode 100644 index 435747e9a09..00000000000 --- a/tests/unit/test_auto_update_price_and_context_window_file.py +++ /dev/null @@ -1,222 +0,0 @@ -"""Unit tests for the Friendli transform in -`.github/scripts/auto_update_price_and_context_window_file.py`.""" - -from __future__ import annotations - -import importlib.util -import sys -from pathlib import Path - -import pytest - -SCRIPT_PATH = ( - Path(__file__).resolve().parents[2] - / ".github" - / "scripts" - / "auto_update_price_and_context_window_file.py" -) - - -@pytest.fixture(scope="module") -def sync_module(): - spec = importlib.util.spec_from_file_location( - "auto_update_price_and_context_window_file", SCRIPT_PATH - ) - assert spec and spec.loader, f"Could not load spec for {SCRIPT_PATH}" - module = importlib.util.module_from_spec(spec) - sys.modules["auto_update_price_and_context_window_file"] = module - spec.loader.exec_module(module) - return module - - -def _reasoning_model(**overrides: object) -> dict: - model = { - "id": "zai-org/GLM-Test", - "base_model": "zhipuai/glm-test", - "context_length": 1048576, - "max_completion_tokens": 131072, - "pricing": {"input": "0.00000015", "output": "0.0000005", "input_cache_read": "0.00000003"}, - "reasoning": True, - "reasoning_options": [{"type": "effort", "values": ["max", "high", "low"]}], - "functionality": { - "tool_call": True, - "parallel_tool_call": True, - "structured_output": True, - "system_messages": True, - "tool_choice": True, - }, - "input_modalities": ["text", "image", "video"], - "mode": "chat", - } - model.update(overrides) - return model - - -def test_transform_emits_declared_effort_levels_in_canonical_order(sync_module): - entry = sync_module.transform_friendli_data([_reasoning_model()], {})[ - "friendliai/zai-org/GLM-Test" - ] - assert entry["supports_reasoning"] is True - assert entry["reasoning_effort_levels"] == ["low", "high", "max"] - assert not any(k.endswith("_reasoning_effort") for k in entry) - - -def test_transform_reasoning_model_without_effort_options_declares_empty_levels(sync_module): - model = _reasoning_model(reasoning_options=[{"type": "budget_tokens", "values": []}]) - entry = sync_module.transform_friendli_data([model], {})["friendliai/zai-org/GLM-Test"] - assert entry["reasoning_effort_levels"] == [] - - -def test_transform_non_reasoning_model_declares_no_levels(sync_module): - model = _reasoning_model(reasoning=False, reasoning_options=[]) - entry = sync_module.transform_friendli_data([model], {})["friendliai/zai-org/GLM-Test"] - assert entry["supports_reasoning"] is False - assert "reasoning_effort_levels" not in entry - - -def test_transform_max_tokens_mirrors_output_cap_not_context(sync_module): - entry = sync_module.transform_friendli_data([_reasoning_model()], {})[ - "friendliai/zai-org/GLM-Test" - ] - assert entry["max_input_tokens"] == 1048576 - assert entry["max_output_tokens"] == 131072 - assert entry["max_tokens"] == entry["max_output_tokens"] - - -def test_transform_prompt_caching_follows_cache_pricing(sync_module): - cached = sync_module.transform_friendli_data([_reasoning_model()], {})[ - "friendliai/zai-org/GLM-Test" - ] - assert cached["supports_prompt_caching"] is True - assert cached["cache_read_input_token_cost"] == 3e-08 - - uncached_model = _reasoning_model(pricing={"input": "0.00000014", "output": "0.0000004"}) - uncached = sync_module.transform_friendli_data([uncached_model], {})[ - "friendliai/zai-org/GLM-Test" - ] - assert uncached["supports_prompt_caching"] is False - assert "cache_read_input_token_cost" not in uncached - - -def test_transform_modalities_set_vision_image_and_video_flags(sync_module): - entry = sync_module.transform_friendli_data([_reasoning_model()], {})[ - "friendliai/zai-org/GLM-Test" - ] - assert entry["supports_vision"] is True - assert entry["supports_image_input"] is True - assert entry["supports_video_input"] is True - - text_only = _reasoning_model(input_modalities=["text"]) - entry_text = sync_module.transform_friendli_data([text_only], {})[ - "friendliai/zai-org/GLM-Test" - ] - assert entry_text["supports_vision"] is False - assert entry_text["supports_image_input"] is False - assert entry_text["supports_video_input"] is False - - -def test_transform_skips_rows_without_valid_token_prices_so_priced_local_entries_survive(sync_module): - local = { - "friendliai/zai-org/GLM-Test": { - "litellm_provider": "friendliai", - "input_cost_per_token": 1.5e-07, - "output_cost_per_token": 5e-07, - } - } - unpriced_rows = [ - _reasoning_model(pricing={}), - _reasoning_model(pricing=None), - _reasoning_model(pricing={"input": "0.00000015"}), - _reasoning_model(pricing={"output": "0.0000005"}), - _reasoning_model(pricing={"input": "not-a-number", "output": "0.0000005"}), - _reasoning_model(pricing={"input": "-0.00000015", "output": "0.0000005"}), - _reasoning_model(pricing={"input": "inf", "output": "0.0000005"}), - _reasoning_model(pricing={"input": "nan", "output": "0.0000005"}), - ] - remote = sync_module.transform_friendli_data(unpriced_rows, local) - assert remote == {} - sync_module.sync_local_data_with_remote(local, remote, replace_keys=frozenset(remote)) - assert local["friendliai/zai-org/GLM-Test"]["input_cost_per_token"] == 1.5e-07 - assert local["friendliai/zai-org/GLM-Test"]["output_cost_per_token"] == 5e-07 - - -def test_transform_keeps_zero_priced_rows(sync_module): - free_model = _reasoning_model(pricing={"input": "0", "output": "0"}) - entry = sync_module.transform_friendli_data([free_model], {})["friendliai/zai-org/GLM-Test"] - assert entry["input_cost_per_token"] == 0.0 - assert entry["output_cost_per_token"] == 0.0 - - -def test_transforms_survive_failed_fetch(sync_module): - assert sync_module.transform_friendli_data(None, {}) == {} - assert sync_module.transform_friendli_data([], {}) == {} - assert sync_module.transform_openrouter_data(None) == {} - assert sync_module.transform_vercel_ai_gateway_data(None) == {} - - -def test_vercel_transform_skips_rows_without_token_pricing_or_limits(sync_module): - rows = [ - { - "id": "wan-video", - "pricing": {"video_duration_pricing": [{"resolution": "720p", "cost_per_second": "0.1"}]}, - }, - { - "id": "qwen3-embedding", - "context_window": 32768, - "max_tokens": 32768, - "pricing": {"input": "0.00000001"}, - }, - { - "id": "no-limits-chat", - "pricing": {"input": "0.000001", "output": "0.000002"}, - }, - { - "id": "good-chat", - "context_window": 128000, - "max_tokens": 8192, - "pricing": {"input": "0.000001", "output": "0.000002"}, - }, - ] - transformed = sync_module.transform_vercel_ai_gateway_data(rows) - assert list(transformed) == ["vercel_ai_gateway/good-chat"] - assert transformed["vercel_ai_gateway/good-chat"]["input_cost_per_token"] == 1e-06 - assert transformed["vercel_ai_gateway/good-chat"]["output_cost_per_token"] == 2e-06 - - -def test_sync_replaces_friendli_entries_so_dropped_cache_pricing_does_not_survive(sync_module): - local = { - "friendliai/zai-org/GLM-Test": { - "litellm_provider": "friendliai", - "cache_read_input_token_cost": 3e-08, - "supports_prompt_caching": True, - } - } - uncached_model = _reasoning_model(pricing={"input": "0.00000014", "output": "0.0000004"}) - remote = sync_module.transform_friendli_data([uncached_model], local) - sync_module.sync_local_data_with_remote(local, remote, replace_keys=frozenset(remote)) - synced = local["friendliai/zai-org/GLM-Test"] - assert "cache_read_input_token_cost" not in synced - assert synced["supports_prompt_caching"] is False - - -def test_sync_still_merges_entries_outside_replace_keys(sync_module): - local = {"openrouter/some-model": {"input_cost_per_token": 1e-06, "supports_vision": True}} - remote = {"openrouter/some-model": {"input_cost_per_token": 2e-06}} - sync_module.sync_local_data_with_remote(local, remote) - assert local["openrouter/some-model"] == {"input_cost_per_token": 2e-06, "supports_vision": True} - - -def test_transform_inherits_allowlisted_keys_from_base_model_entry(sync_module): - local = { - "zhipuai/glm-test": { - "supports_pdf_input": True, - "supports_assistant_prefill": True, - "input_cost_per_token": 9e-06, - } - } - entry = sync_module.transform_friendli_data([_reasoning_model()], local)[ - "friendliai/zai-org/GLM-Test" - ] - assert entry["supports_pdf_input"] is True - assert entry["supports_assistant_prefill"] is True - assert entry["input_cost_per_token"] == 1.5e-07 diff --git a/tests/unit/test_cerebras_llama_model_metadata.py b/tests/unit/test_cerebras_llama_model_metadata.py new file mode 100644 index 00000000000..c5ec096e553 --- /dev/null +++ b/tests/unit/test_cerebras_llama_model_metadata.py @@ -0,0 +1,115 @@ +# What does this test? +""" +Verifies that Cerebras Llama 3.1 models (standard hyphenated aliases): +- cerebras/llama-3.1-8b +- cerebras/llama-3.1-70b + +have correct rate card metadata, context window limits, and cost calculation parity +with the un-hyphenated variants in model_prices_and_context_window.json. +Fixes: https://github.com/BerriAI/litellm/issues/48157 +""" + +import json +from pathlib import Path + +import pytest + +import litellm + + +@pytest.fixture(scope="module") +def model_cost_maps(): + root = Path(__file__).resolve().parents[2] + main_path = root / "model_prices_and_context_window.json" + backup_path = root / "litellm" / "model_prices_and_context_window_backup.json" + + with open(main_path, "r", encoding="utf-8") as f: + main_map = json.load(f) + with open(backup_path, "r", encoding="utf-8") as f: + backup_map = json.load(f) + + return main_map, backup_map + + +CEREBRAS_MODELS_EXPECTED = { + "cerebras/llama-3.1-8b": { + "input_cost_per_token": 1e-07, + "output_cost_per_token": 1e-07, + "max_input_tokens": 128000, + "max_output_tokens": 128000, + "mode": "chat", + "litellm_provider": "cerebras", + }, + "cerebras/llama-3.1-70b": { + "input_cost_per_token": 6e-07, + "output_cost_per_token": 6e-07, + "max_input_tokens": 128000, + "max_output_tokens": 128000, + "mode": "chat", + "litellm_provider": "cerebras", + }, +} + +PAIR_PARITY = [ + ("cerebras/llama-3.1-8b", "cerebras/llama3.1-8b"), + ("cerebras/llama-3.1-70b", "cerebras/llama3.1-70b"), +] + + +@pytest.mark.parametrize("model_id,expected_data", CEREBRAS_MODELS_EXPECTED.items()) +def test_cerebras_llama_model_metadata(model_cost_maps, model_id, expected_data): + """Test that hyphenated Cerebras Llama 3.1 models exist and have expected metadata in both catalogs.""" + main_map, backup_map = model_cost_maps + + assert model_id in main_map, f"Missing {model_id} in main catalog" + assert model_id in backup_map, f"Missing {model_id} in backup catalog" + + main_entry = main_map[model_id] + backup_entry = backup_map[model_id] + assert main_entry == backup_entry, f"Parity mismatch between main and backup for {model_id}" + + for key, expected_val in expected_data.items(): + assert main_entry.get(key) == expected_val, ( + f"{model_id}[{key}] got {main_entry.get(key)}, expected {expected_val}" + ) + + +@pytest.mark.parametrize("hyphenated,unhyphenated", PAIR_PARITY) +def test_cerebras_llama_parity_with_unhyphenated(model_cost_maps, hyphenated, unhyphenated): + """Test that hyphenated and un-hyphenated variants have identical pricing and context limits.""" + main_map, _ = model_cost_maps + + assert hyphenated in main_map + assert unhyphenated in main_map + + entry_hyphen = main_map[hyphenated] + entry_unhyphen = main_map[unhyphenated] + + assert entry_hyphen["input_cost_per_token"] == entry_unhyphen["input_cost_per_token"] + assert entry_hyphen["output_cost_per_token"] == entry_unhyphen["output_cost_per_token"] + assert entry_hyphen["max_input_tokens"] == entry_unhyphen["max_input_tokens"] + assert entry_hyphen["max_output_tokens"] == entry_unhyphen["max_output_tokens"] + + +def test_cerebras_llama_cost_per_token(): + """Test that litellm.cost_per_token accurately computes costs for hyphenated Cerebras models.""" + prompt_tokens = 1_000_000 + completion_tokens = 1_000_000 + + # llama-3.1-8b: $0.10 input + $0.10 output per 1M tokens + cost_prompt, cost_comp = litellm.cost_per_token( + model="cerebras/llama-3.1-8b", + prompt_tokens=prompt_tokens, + completion_tokens=completion_tokens, + ) + assert pytest.approx(cost_prompt, rel=1e-5) == 0.10 + assert pytest.approx(cost_comp, rel=1e-5) == 0.10 + + # llama-3.1-70b: $0.60 input + $0.60 output per 1M tokens + cost_prompt_70b, cost_comp_70b = litellm.cost_per_token( + model="cerebras/llama-3.1-70b", + prompt_tokens=prompt_tokens, + completion_tokens=completion_tokens, + ) + assert pytest.approx(cost_prompt_70b, rel=1e-5) == 0.60 + assert pytest.approx(cost_comp_70b, rel=1e-5) == 0.60 diff --git a/tests/unit/test_check_mcp_operation_boundary.py b/tests/unit/test_check_mcp_operation_boundary.py index d7ac72de9f0..0969c461ad2 100644 --- a/tests/unit/test_check_mcp_operation_boundary.py +++ b/tests/unit/test_check_mcp_operation_boundary.py @@ -9,11 +9,11 @@ from scripts.check_mcp_operation_boundary import main, violations "source", ( "from mcp.server.auth.middleware.auth_context import auth_context_var as hidden", - "from litellm.proxy._experimental.mcp_server.mcp_context import _mcp_proxy_mode as mode", + "from litellm.proxy.mcp_server.mcp_context import _mcp_proxy_mode as mode", "caller = legacy.get_active_auth_context()", "owners = transport._stateful_session_owners", "from weakref import WeakKeyDictionary", - "from litellm.proxy._experimental.mcp_server.server import get_auth_context", + "from litellm.proxy.mcp_server.server import get_auth_context", ), ) def test_shared_operation_boundary_rejects_ambient_state(source): @@ -21,7 +21,7 @@ def test_shared_operation_boundary_rejects_ambient_state(source): def test_legacy_adapter_may_resolve_context_but_policy_must_receive_it(): - source = "from litellm.proxy._experimental.mcp_server.mcp_context import _mcp_proxy_mode" + source = "from litellm.proxy.mcp_server.mcp_context import _mcp_proxy_mode" assert violations(Path("server.py"), source) == () assert violations(Path("legacy_callbacks.py"), source) == () assert violations(Path("operations.py"), "def execute(context):\n return context.client_ip") == () @@ -32,7 +32,7 @@ def test_boundary_command_rejects_shared_state_and_accepts_explicit_context(tmp_ import subprocess import sys - package = tmp_path / "litellm/proxy/_experimental/mcp_server" + package = tmp_path / "litellm/proxy/mcp_server" package.mkdir(parents=True) module = package / "operations.py" module.write_text("from mcp.server.auth.middleware.auth_context import auth_context_var as hidden\n") diff --git a/tests/unit/test_circleci_path_filter.py b/tests/unit/test_circleci_path_filter.py index c44560b96f1..9f695960517 100644 --- a/tests/unit/test_circleci_path_filter.py +++ b/tests/unit/test_circleci_path_filter.py @@ -51,7 +51,7 @@ CI = [".github/workflows/test-unit.yml"] [ ("mcp-dependencies", ["pyproject.toml"], "run"), ("mcp-dependencies", ["uv.lock"], "run"), - ("mcp-dependencies", ["litellm/experimental_mcp_client/client.py"], "run"), + ("mcp-dependencies", ["litellm/mcp_client/client.py"], "run"), ("mcp-dependencies", ["tests/e2e/mcp/datadog_mcp.py"], "run"), ("mcp-dependencies", ["litellm-proxy-extras/pyproject.toml"], "run"), ("mcp-dependencies", ["scripts/check_mcp_sdk_install.py"], "run"), diff --git a/tests/unit/test_cost_calculator.py b/tests/unit/test_cost_calculator.py index 5d4eb5fae12..27b25c1f98e 100644 --- a/tests/unit/test_cost_calculator.py +++ b/tests/unit/test_cost_calculator.py @@ -16,6 +16,7 @@ import litellm from litellm import TranscriptionResponse, model_cost from litellm.constants import REALTIME_METERED_USAGE_KEY from litellm.cost_calculator import BaseTokenUsageProcessor, RealtimeAPITokenUsageProcessor, ResponsesWebSocketTokenUsageProcessor, batch_cost_calculator, completion_cost, cost_per_token, handle_realtime_stream_cost_calculation, response_cost_calculator +from litellm.litellm_core_utils.llm_cost_calc.utils import parse_prompt_tokens_details from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.fallback_generalizations import ( get_fallback_generalization_rules, @@ -34,7 +35,7 @@ from litellm.types.llms.base import CachedTokensDetails from litellm.types.llms.openai import HttpxBinaryResponseContent, OpenAIRealtimeStreamList, ResponseAPIUsage, ResponsesAPIResponse from litellm.types.llms.xai import RealtimeMeteredUsage from litellm.types.rerank import RerankResponse -from litellm.types.utils import CallTypes, Choices, CompletionTokensDetailsWrapper, EmbeddingResponse, ImageObject, ImageResponse, ImageUsage, ImageUsageInputTokensDetails, LiteLLMRealtimeStreamLoggingObject, Message, ModelInfo, ModelResponse, PromptTokensDetails, PromptTokensDetailsWrapper, Usage +from litellm.types.utils import CacheCreationTokenDetails, CallTypes, Choices, CompletionTokensDetailsWrapper, EmbeddingResponse, ImageObject, ImageResponse, ImageUsage, ImageUsageInputTokensDetails, LiteLLMRealtimeStreamLoggingObject, Message, ModelInfo, ModelResponse, PromptTokensDetails, PromptTokensDetailsWrapper, Usage from litellm.types.videos.main import VideoObject from litellm.utils import supports_prompt_caching import os @@ -3337,14 +3338,7 @@ def test_anthropic_us_data_residency_uplift_on_claude_4_6_and_later_models(_loca def test_gemini_cache_tokens_details_no_negative_values(): - """ - Test for Issue #18750: Negative text_tokens with Gemini caching - - When using Gemini with explicit caching, the response includes cacheTokensDetails - which breaks down cached tokens by modality. This test ensures that: - 1. text_tokens is never negative - 2. We correctly subtract cached tokens per modality (not total) - """ + """Ensure issue #18750 cache details remain non-negative after cost parsing.""" from litellm.llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini import ( VertexGeminiConfig, ) @@ -3372,27 +3366,17 @@ def test_gemini_cache_tokens_details_no_negative_values(): usage = VertexGeminiConfig.calculate_usage(completion_response) - # Text tokens should be non-cached text only: 9402 - 9393 = 9 - assert usage.prompt_tokens_details.text_tokens == 9, ( - f"Expected text_tokens=9, got {usage.prompt_tokens_details.text_tokens}" - ) + prompt_details: Final = parse_prompt_tokens_details(usage) - # Image tokens should be non-cached image only: 258 - 258 = 0 - assert usage.prompt_tokens_details.image_tokens == 0, ( - f"Expected image_tokens=0, got {usage.prompt_tokens_details.image_tokens}" + assert usage.prompt_tokens_details.text_tokens == 9402 + assert usage.prompt_tokens_details.image_tokens == 258 + assert usage.prompt_tokens_details.cached_tokens == 9651 + assert usage.prompt_tokens_details.cached_tokens_details == CachedTokensDetails( + text_tokens=9393, image_tokens=258 ) - - # Total cached should match - assert usage.prompt_tokens_details.cached_tokens == 9651, ( - f"Expected cached_tokens=9651, got {usage.prompt_tokens_details.cached_tokens}" - ) - - # MOST IMPORTANT: text_tokens should NEVER be negative - assert usage.prompt_tokens_details.text_tokens >= 0, ( - f"BUG: text_tokens is negative ({usage.prompt_tokens_details.text_tokens})! This was the issue in #18750" - ) - - print("✅ Issue #18750 fix verified: text_tokens is correctly calculated and non-negative") + assert prompt_details["text_tokens"] == 9 + assert prompt_details["image_tokens"] == 0 + assert prompt_details["text_tokens"] >= 0 def test_gemini_without_cache_tokens_details(): @@ -5963,6 +5947,110 @@ def test_batch_cost_calculator_bills_cache_write_tokens_at_the_batch_input_rate_ assert prompt_cost == pytest.approx(300_048 * 3e-6) +_TWELVE_HOUR_BATCH_MODEL_INFO: Final = cast( + ModelInfo, + { + "input_cost_per_token_batches": 1e-6, + "input_cost_per_token_above_272k_tokens_batches": 3e-6, + "cache_creation_input_token_cost_batches": 1.25e-6, + "cache_creation_input_token_cost_above_272k_tokens_batches": 3.75e-6, + "cache_creation_input_token_cost_above_12hr_batches": 2.5e-6, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches": 7.5e-6, + "output_cost_per_token_batches": 4e-6, + }, +) + + +def _twelve_hour_cache_write_usage(prompt_tokens: int) -> Usage: + return Usage( + prompt_tokens=prompt_tokens, + completion_tokens=4, + total_tokens=prompt_tokens + 4, + prompt_tokens_details=PromptTokensDetailsWrapper( + cached_tokens=0, + cache_creation_tokens=500, + cache_creation_token_details=CacheCreationTokenDetails( + ephemeral_30m_input_tokens=300, ephemeral_12h_input_tokens=200 + ), + ), + ) + + +@pytest.mark.parametrize( + ("prompt_tokens", "input_rate", "write_rate", "twelve_hour_rate"), + [(1_000, 1e-6, 1.25e-6, 2.5e-6), (272_000, 1e-6, 1.25e-6, 2.5e-6), (300_000, 3e-6, 3.75e-6, 7.5e-6)], +) +def test_batch_cost_calculator_bills_12h_cache_writes_at_the_12h_batch_rate_for_the_crossed_tier( + prompt_tokens: int, input_rate: float, write_rate: float, twelve_hour_rate: float +) -> None: + from litellm.cost_calculator import batch_cost_calculator + + prompt_cost, completion_cost_value = batch_cost_calculator( + usage=_twelve_hour_cache_write_usage(prompt_tokens), + model="lit-12h-batch-model", + custom_llm_provider="openai", + model_info=_TWELVE_HOUR_BATCH_MODEL_INFO, + ) + + assert prompt_cost == pytest.approx((prompt_tokens - 500) * input_rate + 300 * write_rate + 200 * twelve_hour_rate) + assert completion_cost_value == pytest.approx(4 * 4e-6) + + +@pytest.mark.parametrize( + ("prompt_tokens", "input_rate", "twelve_hour_write_rate"), [(1_000, 1e-6, 2.5e-6), (300_000, 3e-6, 7.5e-6)] +) +def test_batch_cost_calculator_bills_12h_cache_writes_once_when_only_the_12h_batch_key_exists( + prompt_tokens: int, input_rate: float, twelve_hour_write_rate: float +) -> None: + from litellm.cost_calculator import batch_cost_calculator + + model_info: Final = cast( + ModelInfo, + { + key: rate + for key, rate in _TWELVE_HOUR_BATCH_MODEL_INFO.items() + if not key.startswith("cache_creation_input_token_cost_") + or key.startswith("cache_creation_input_token_cost_above_12hr") + }, + ) + + prompt_cost, _ = batch_cost_calculator( + usage=_twelve_hour_cache_write_usage(prompt_tokens), + model="lit-12h-batch-model", + custom_llm_provider="openai", + model_info=model_info, + ) + + assert prompt_cost == pytest.approx((prompt_tokens - 200) * input_rate + 200 * twelve_hour_write_rate) + + +@pytest.mark.parametrize(("prompt_tokens", "write_rate"), [(1_000, 1.25e-6), (300_000, 3.75e-6)]) +def test_batch_cost_calculator_bills_12h_cache_writes_at_the_batch_cache_write_rate_without_a_12h_batch_key( + prompt_tokens: int, write_rate: float +) -> None: + from litellm.cost_calculator import batch_cost_calculator + + model_info: Final = cast( + ModelInfo, + { + key: rate + for key, rate in _TWELVE_HOUR_BATCH_MODEL_INFO.items() + if not key.startswith("cache_creation_input_token_cost_above_12hr") + }, + ) + + prompt_cost, _ = batch_cost_calculator( + usage=_twelve_hour_cache_write_usage(prompt_tokens), + model="lit-12h-batch-model", + custom_llm_provider="openai", + model_info=model_info, + ) + + assert prompt_cost == pytest.approx( + (prompt_tokens - 500) * (1e-6 if prompt_tokens <= 272_000 else 3e-6) + 500 * write_rate + ) + + def test_batch_cost_calculator_prices_modalities_and_cached_tokens_together_in_the_crossed_tier() -> None: from litellm.cost_calculator import batch_cost_calculator @@ -5990,6 +6078,45 @@ def test_batch_cost_calculator_prices_modalities_and_cached_tokens_together_in_t assert prompt_cost == pytest.approx(298_926 * 3e-6 + 64 * 5e-6 + 10 * 3e-6 + 1_000 * 3e-7) +def test_batch_cost_calculator_prices_cached_audio_at_its_batch_rate() -> None: + model_info: Final[ModelInfo] = { + "input_cost_per_token": 2e-6, + "input_cost_per_token_batches": 1e-6, + "input_cost_per_audio_token": 6e-6, + "input_cost_per_audio_token_batches": 3e-6, + "cache_read_input_token_cost": 8e-7, + "cache_read_input_token_cost_batches": 4e-7, + "cache_read_input_audio_token_cost": 5e-7, + "cache_read_input_audio_token_cost_batches": 2e-7, + } + usage: Final = Usage( + prompt_tokens=40, + completion_tokens=0, + total_tokens=40, + prompt_tokens_details=PromptTokensDetailsWrapper( + text_tokens=20, + audio_tokens=20, + cached_tokens=10, + cached_tokens_details=CachedTokensDetails(text_tokens=5, audio_tokens=5), + ), + ) + + prompt_cost, _ = batch_cost_calculator( + usage=usage, + model="gemini-audio-batch-test-model", + custom_llm_provider="gemini", + model_info=model_info, + ) + + expected: Final = ( + 15 * model_info["input_cost_per_token_batches"] + + 15 * model_info["input_cost_per_audio_token_batches"] + + 5 * model_info["cache_read_input_token_cost_batches"] + + 5 * model_info["cache_read_input_audio_token_cost_batches"] + ) + assert prompt_cost == pytest.approx(expected) + + QWEN3_NEXT_REGIONS: Final = ("ap-northeast-1", "ap-south-1", "ap-southeast-2", "eu-west-1", "eu-west-2", "sa-east-1") diff --git a/tests/unit/test_internal_context.py b/tests/unit/test_internal_context.py index 60a75c688c4..f78c6064f76 100644 --- a/tests/unit/test_internal_context.py +++ b/tests/unit/test_internal_context.py @@ -54,7 +54,7 @@ _IN_MEMORY_ONLY_CALLERS: Final = frozenset( "litellm/llms/azure/common_utils.py", "litellm/llms/bedrock/base_aws_llm.py", "litellm/llms/custom_httpx/http_handler.py", - "litellm/llms/databricks/agent/transformation.py", + "litellm/llms/databricks/common_utils.py", "litellm/llms/gigachat/authenticator.py", "litellm/llms/github_copilot/per_user_auth.py", "litellm/llms/litellm_proxy/skills/handler.py", @@ -62,13 +62,13 @@ _IN_MEMORY_ONLY_CALLERS: Final = frozenset( "litellm/llms/openai_like/model_info.py", "litellm/llms/vertex_ai/vertex_ai_non_gemini.py", "litellm/llms/watsonx/common_utils.py", - "litellm/proxy/_experimental/mcp_server/byok_credential_cache.py", - "litellm/proxy/_experimental/mcp_server/catalog.py", - "litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py", - "litellm/proxy/_experimental/mcp_server/oauth_identity_binding.py", - "litellm/proxy/_experimental/mcp_server/operations.py", - "litellm/proxy/_experimental/mcp_server/outbound_credentials/sso_assertion_store.py", - "litellm/proxy/_experimental/mcp_server/outbound_credentials/token_endpoint.py", + "litellm/proxy/mcp_server/byok_credential_cache.py", + "litellm/proxy/mcp_server/catalog.py", + "litellm/proxy/mcp_server/discoverable_endpoints.py", + "litellm/proxy/mcp_server/oauth_identity_binding.py", + "litellm/proxy/mcp_server/operations.py", + "litellm/proxy/mcp_server/outbound_credentials/sso_assertion_store.py", + "litellm/proxy/mcp_server/outbound_credentials/token_endpoint.py", "litellm/proxy/agent_endpoints/databricks_oauth.py", "litellm/proxy/common_utils/registry_read_through.py", "litellm/proxy/container_endpoints/ownership.py", diff --git a/tests/unit/test_model_prices_and_context_window.py b/tests/unit/test_model_prices_and_context_window.py index 701b79d0ba9..1f84be7710f 100644 --- a/tests/unit/test_model_prices_and_context_window.py +++ b/tests/unit/test_model_prices_and_context_window.py @@ -12,7 +12,7 @@ from pydantic import BaseModel, ConfigDict, JsonValue, TypeAdapter import litellm from litellm.litellm_core_utils.fallback_generalizations import match_capability_generalizations -from litellm.llms.openai.chat.gpt_5_transformation import is_gpt_reasoning_series_name +from litellm.llms.openai.chat.gpt_reasoning_transformation import is_gpt_reasoning_series_name from litellm.llms.openai_like.json_loader import JSONProviderRegistry from litellm.router_utils.reasoning_effort_capability import resolve_supported_reasoning_efforts from litellm.types.utils import SearchFreeRequests @@ -27,13 +27,29 @@ def prices() -> dict: return json.loads(PRICES_PATH.read_text()) +@pytest.mark.parametrize("model", ("azure/gpt-audio-1.5-2026-02-23", "azure/gpt-audio-mini-2025-10-06")) +def test_azure_audio_snapshot_capabilities_match_declared_modalities(model: str, local_model_cost_map: None) -> None: + catalog: Final = TypeAdapter(dict[str, JsonValue]).validate_json(PRICES_PATH.read_bytes()) + backup: Final = TypeAdapter(dict[str, JsonValue]).validate_json(BACKUP_PRICES_PATH.read_bytes()) + entry: Final = catalog[model] + assert isinstance(entry, dict) + assert entry == backup[model] + input_modalities: Final = entry["supported_modalities"] + output_modalities: Final = entry["supported_output_modalities"] + assert isinstance(input_modalities, list) + assert isinstance(output_modalities, list) + expected: Final = ("audio" in input_modalities, "audio" in output_modalities) + info: Final = litellm.get_model_info(model) + assert (info["supports_audio_input"], info["supports_audio_output"]) == expected + assert (litellm.supports_audio_input(model), litellm.supports_audio_output(model)) == expected + + class _CopilotEndpointRow(BaseModel): model_config = ConfigDict(frozen=True, extra="ignore") mode: str max_input_tokens: int max_output_tokens: int - max_tokens: int supported_endpoints: tuple[str, ...] @@ -79,18 +95,22 @@ def _anthropic_counterpart(key: str) -> str: @pytest.mark.parametrize(("path",), [(PRICES_PATH,), (BACKUP_PRICES_PATH,)], ids=("main", "backup")) -def test_github_copilot_rows_derive_mode_and_max_tokens_from_their_endpoints(path: Path) -> None: +def test_github_copilot_rows_derive_mode_from_their_endpoints(path: Path) -> None: rows: Final[Mapping[str, _CopilotEndpointRow]] = _copilot_endpoint_rows(path) assert rows, f"No GitHub Copilot endpoint rows found in {path}" - assert {key: (row.mode, row.max_tokens) for key, row in rows.items()} == { - key: ( - "chat" if "/v1/chat/completions" in row.supported_endpoints else "responses", - row.max_output_tokens, - ) - for key, row in rows.items() + assert {key: row.mode for key, row in rows.items()} == { + key: "chat" if "/v1/chat/completions" in row.supported_endpoints else "responses" for key, row in rows.items() } +def _rows_carrying_legacy_max_tokens(prices: Mapping[str, Mapping[str, object]]) -> tuple[str, ...]: + return tuple(key for key, row in prices.items() if "max_tokens" in row) + + +def test_no_row_carries_the_retired_max_tokens_field(prices: dict) -> None: + assert _rows_carrying_legacy_max_tokens(prices) == () + + def test_github_copilot_backup_rows_match_the_main_catalog() -> None: assert _github_copilot_catalog_rows(PRICES_PATH) == _github_copilot_catalog_rows(BACKUP_PRICES_PATH) @@ -455,30 +475,23 @@ def is_active_priced_mistral_chat_row(name: str, entry: Mapping[str, object]) -> ) -def cache_read_is_tenth_of_input(entry: Mapping[str, object]) -> bool: +def cache_read_is_below_input(entry: Mapping[str, object]) -> bool: cache_read: Final = entry.get("cache_read_input_token_cost") input_cost: Final = entry.get("input_cost_per_token") - return ( - isinstance(cache_read, float) - and isinstance(input_cost, (int, float)) - and 0 < cache_read < input_cost - and cache_read == pytest.approx(input_cost / 10) - ) + return isinstance(cache_read, float) and isinstance(input_cost, (int, float)) and 0 < cache_read < input_cost @pytest.mark.parametrize("path", (PRICES_PATH, BACKUP_PRICES_PATH), ids=("main", "backup")) def test_active_mistral_chat_rows_price_cache_reads_below_input(path: Path): """A Mistral chat row without a cache-read rate bills cached prompt tokens at zero, so every - active priced row must carry one, and it must be cheaper than a fresh input token. Mistral - bills cached tokens at 10% of the input price for every model (docs.mistral.ai/studio/ - conversations/advanced/prompt-caching, read 2026-09-18), so the ratio is checked as well.""" + active priced row must carry one, and it must be cheaper than a fresh input token.""" rows: Mapping[str, object] = json.loads(path.read_text()) drifted: Final = [ f"{name}: cache_read={entry.get('cache_read_input_token_cost')} input={entry.get('input_cost_per_token')}" for name, entry in rows.items() if isinstance(entry, dict) and is_active_priced_mistral_chat_row(name, entry) - and not cache_read_is_tenth_of_input(entry) + and not cache_read_is_below_input(entry) ] assert drifted == [] @@ -591,7 +604,6 @@ def test_tencent_tokenhub_glm_rows_match_published_metadata(path: Path): or entry.get("litellm_provider") != "tencent" or entry.get("max_input_tokens") != 1000000 or entry.get("max_output_tokens") != 128000 - or entry.get("max_tokens") != 128000 or entry.get("input_cost_per_token_cache_hit") != entry.get("cache_read_input_token_cost") ) assert actual == TENCENT_TOKENHUB_GLM_ROWS @@ -609,7 +621,7 @@ def test_tencent_tokenhub_kimi_rows_match_published_metadata(path: Path): entry.get("input_cost_per_token"), entry.get("output_cost_per_token"), entry.get("cache_read_input_token_cost"), - entry.get("max_tokens"), + entry.get("max_output_tokens"), entry.get("supports_vision", False), entry.get("supports_video_input", False), ) @@ -783,7 +795,6 @@ def test_volcengine_doubao_seed_2_1_pro_260915_row_matches_published_metadata(pa assert entry["mode"] == "chat" assert entry["max_input_tokens"] == 1024000 assert entry["max_output_tokens"] == 256000 - assert entry["max_tokens"] == 256000 # Volcengine Ark pricing https://www.volcengine.com/docs/82379/1544106 checked 2026-10-20 assert entry["input_cost_per_token"] == pytest.approx(6.0 / 6.9565 / 1_000_000, rel=1e-4) assert entry["output_cost_per_token"] == pytest.approx(30.0 / 6.9565 / 1_000_000, rel=1e-4) @@ -791,3 +802,26 @@ def test_volcengine_doubao_seed_2_1_pro_260915_row_matches_published_metadata(pa sibling = rows["volcengine/doubao-seed-2-1-pro-260628"] assert isinstance(sibling, dict) assert all(entry[key] == sibling[key] for key in ("input_cost_per_token", "output_cost_per_token", "cache_read_input_token_cost")) + + +def _bedrock_gpt_oss_rows(prices: Mapping[str, JsonValue]) -> tuple[str, ...]: + return tuple( + key + for key, row in prices.items() + if "gpt-oss" in key and isinstance(row, dict) and str(row.get("litellm_provider", "")).startswith("bedrock") + ) + + +@pytest.mark.parametrize("path", [PRICES_PATH, BACKUP_PRICES_PATH], ids=["main", "backup"]) +def test_bedrock_gpt_oss_rows_declare_vision_support_like_their_safeguard_siblings(path: Path) -> None: + prices: Final = json.loads(path.read_text()) + rows: Final = _bedrock_gpt_oss_rows(prices) + assert rows, "no Bedrock gpt-oss rows found" + reference: Final = prices["openai.gpt-oss-safeguard-120b"]["supports_vision"] + undeclared: Final = tuple(key for key in rows if prices[key].get("supports_vision") is not reference) + assert undeclared == (), f"modality routing only skips rows that declare supports_vision: {undeclared}" + + +def test_bedrock_gpt_oss_vision_is_explicitly_disabled_for_the_router_gate() -> None: + assert litellm.utils.is_vision_explicitly_disabled("bedrock/openai.gpt-oss-120b-1:0") is True + assert litellm.utils.is_vision_explicitly_disabled("bedrock_mantle/openai.gpt-oss-20b") is True diff --git a/tests/unit/test_private_usage_aliases.py b/tests/unit/test_private_usage_aliases.py index e73b9950594..1d9c2e87100 100644 --- a/tests/unit/test_private_usage_aliases.py +++ b/tests/unit/test_private_usage_aliases.py @@ -177,157 +177,157 @@ MODULE_IMPORT_ALIAS_CASES: Final = ( "PROXY_DynamicRateLimitHandlerV3", ), ( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp", "_read_request_body", "read_request_body", ), ( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp", "_run_centralized_common_checks", "run_centralized_common_checks", ), ( - "litellm.proxy._experimental.mcp_server.bridge_token_flow", + "litellm.proxy.mcp_server.bridge_token_flow", "_V2_GCM_PREFIX", "V2_GCM_PREFIX", ), ( - "litellm.proxy._experimental.mcp_server.db", + "litellm.proxy.mcp_server.db", "_get_salt_key", "get_salt_key", ), ( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints", + "litellm.proxy.mcp_server.discoverable_endpoints", "_bridge_mint_error_response", "bridge_mint_error_response", ), ( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints", + "litellm.proxy.mcp_server.discoverable_endpoints", "_extract_user_id_from_request", "extract_user_id_from_request", ), ( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints", + "litellm.proxy.mcp_server.discoverable_endpoints", "_finish_bridge_mint", "finish_bridge_mint", ), ( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints", + "litellm.proxy.mcp_server.discoverable_endpoints", "_prepare_bridge_mint", "prepare_bridge_mint", ), ( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints", + "litellm.proxy.mcp_server.discoverable_endpoints", "_prepare_bridge_refresh", "prepare_bridge_refresh", ), ( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints", + "litellm.proxy.mcp_server.discoverable_endpoints", "_read_request_body", "read_request_body", ), ( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints", + "litellm.proxy.mcp_server.discoverable_endpoints", "_reload_active_user_by_id", "reload_active_user_by_id", ), ( - "litellm.proxy._experimental.mcp_server.mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager", "_is_mcp_admitted_user_subject", "is_mcp_admitted_user_subject", ), ( - "litellm.proxy._experimental.mcp_server.mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager", "_redact_mcp_resource_url", "redact_mcp_resource_url", ), ( - "litellm.proxy._experimental.mcp_server.oauth2_flow_backfill", + "litellm.proxy.mcp_server.oauth2_flow_backfill", "_decode_oauth_payload", "decode_oauth_payload", ), ( - "litellm.proxy._experimental.mcp_server.operations", + "litellm.proxy.mcp_server.operations", "_caller_authorization_fans_out", "caller_authorization_fans_out", ), ( - "litellm.proxy._experimental.mcp_server.operations", + "litellm.proxy.mcp_server.operations", "_client_forwarded_authorization_headers", "client_forwarded_authorization_headers", ), ( - "litellm.proxy._experimental.mcp_server.operations", + "litellm.proxy.mcp_server.operations", "_redact_mcp_resource_url", "redact_mcp_resource_url", ), ( - "litellm.proxy._experimental.mcp_server.operations", + "litellm.proxy.mcp_server.operations", "_request_auth_header", "request_auth_header", ), ( - "litellm.proxy._experimental.mcp_server.operations", + "litellm.proxy.mcp_server.operations", "_request_extra_headers", "request_extra_headers", ), ( - "litellm.proxy._experimental.mcp_server.operations", + "litellm.proxy.mcp_server.operations", "_request_resolved_auth_headers", "request_resolved_auth_headers", ), ( - "litellm.proxy._experimental.mcp_server.operations", + "litellm.proxy.mcp_server.operations", "_resolve_openapi_tool_auth", "resolve_openapi_tool_auth", ), ( - "litellm.proxy._experimental.mcp_server.operations", + "litellm.proxy.mcp_server.operations", "_should_strip_caller_authorization", "should_strip_caller_authorization", ), ( - "litellm.proxy._experimental.mcp_server.rest_endpoints", + "litellm.proxy.mcp_server.rest_endpoints", "_UPSTREAM_OAUTH_DISCOVERY_AUTH_TYPES", "UPSTREAM_OAUTH_DISCOVERY_AUTH_TYPES", ), ( - "litellm.proxy._experimental.mcp_server.rest_endpoints", + "litellm.proxy.mcp_server.rest_endpoints", "_apply_toolset_scope", "apply_toolset_scope", ), ( - "litellm.proxy._experimental.mcp_server.rest_endpoints", + "litellm.proxy.mcp_server.rest_endpoints", "_inherit_credentials_from_existing_server", "inherit_credentials_from_existing_server", ), ( - "litellm.proxy._experimental.mcp_server.rest_endpoints", + "litellm.proxy.mcp_server.rest_endpoints", "_redact_mcp_resource_url", "redact_mcp_resource_url", ), ( - "litellm.proxy._experimental.mcp_server.rest_endpoints", + "litellm.proxy.mcp_server.rest_endpoints", "_safe_get_request_headers", "safe_get_request_headers", ), ( - "litellm.proxy._experimental.mcp_server.server", + "litellm.proxy.mcp_server.server", "_is_mcp_admitted_user_subject", "is_mcp_admitted_user_subject", ), ( - "litellm.proxy._experimental.mcp_server.server", + "litellm.proxy.mcp_server.server", "_mcp_active_toolset_id", "mcp_active_toolset_id", ), ( - "litellm.proxy._experimental.mcp_server.server", + "litellm.proxy.mcp_server.server", "_mcp_gateway_initialize_instructions", "mcp_gateway_initialize_instructions", ), ( - "litellm.proxy._experimental.mcp_server.server", + "litellm.proxy.mcp_server.server", "_mcp_gateway_server_name", "mcp_gateway_server_name", ), @@ -2108,49 +2108,49 @@ PROPERTY_CASES: Final = ( CLASS_PROPERTY_CASES: Final = () LLMS_ALIAS_CASES: Final = ( ( - "litellm.llms.anthropic.pass_through.adapters.transformation", + "litellm.llms.anthropic.messages.adapters.transformation", "LiteLLMAnthropicMessagesAdapter", "_translate_openai_usage_to_anthropic_usage", "translate_openai_usage_to_anthropic_usage", False, ), ( - "litellm.llms.anthropic.pass_through.adapters.transformation", + "litellm.llms.anthropic.messages.adapters.transformation", "LiteLLMAnthropicMessagesAdapter", "_translate_openai_usage_to_anthropic_usage_delta", "translate_openai_usage_to_anthropic_usage_delta", False, ), ( - "litellm.llms.anthropic.pass_through.adapters.transformation", + "litellm.llms.anthropic.messages.adapters.transformation", "LiteLLMAnthropicMessagesAdapter", "_translate_streaming_openai_chunk_to_anthropic_content_block", "translate_streaming_openai_chunk_to_anthropic_content_block", False, ), ( - "litellm.llms.anthropic.pass_through.context_management.dispatcher", + "litellm.llms.anthropic.messages.context_management.dispatcher", "", "_normalize_spec", "normalize_spec", False, ), ( - "litellm.llms.anthropic.pass_through.messages.streaming_iterator", + "litellm.llms.anthropic.messages.native.streaming_iterator", "", "_is_message_stop_chunk", "is_message_stop_chunk", False, ), ( - "litellm.llms.anthropic.pass_through.messages.streaming_iterator", + "litellm.llms.anthropic.messages.native.streaming_iterator", "", "_is_provider_error_chunk", "is_provider_error_chunk", False, ), ( - "litellm.llms.anthropic.pass_through.messages.transformation", + "litellm.llms.anthropic.messages.native.transformation", "", "_messages_carry_output_config", "messages_carry_output_config", @@ -2233,7 +2233,7 @@ LLMS_ALIAS_CASES: Final = ( ("litellm.llms.oci.chat.generic", "", "_normalize_oci_finish_reason", "normalize_oci_finish_reason", False), ("litellm.llms.oci.chat.generic", "", "_synthesize_oci_tool_call_id", "synthesize_oci_tool_call_id", False), ("litellm.llms.ollama.common_utils", "", "_convert_image", "convert_image", False), - ("litellm.llms.openai.chat.gpt_5_transformation", "", "_get_effort_level", "get_effort_level", False), + ("litellm.llms.openai.chat.gpt_reasoning_transformation", "", "_get_effort_level", "get_effort_level", False), ("litellm.llms.openai.completion.utils", "", "_transform_prompt", "transform_prompt", False), ( "litellm.llms.openai.cost_calculation", @@ -2310,294 +2310,294 @@ LLMS_ALIAS_CASES: Final = ( ) PROXY_ALIAS_CASES: Final = ( ( - 'litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp', + 'litellm.proxy.mcp_server.auth.user_api_key_auth_mcp', '', '_is_mcp_admitted_user_subject', 'is_mcp_admitted_user_subject', False, ), ( - 'litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp', + 'litellm.proxy.mcp_server.auth.user_api_key_auth_mcp', 'MCPRequestHandler', '_get_mcp_auth_header_from_headers', 'get_mcp_auth_header_from_headers', False, ), ( - 'litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp', + 'litellm.proxy.mcp_server.auth.user_api_key_auth_mcp', 'MCPRequestHandler', '_get_mcp_server_auth_headers_from_headers', 'get_mcp_server_auth_headers_from_headers', False, ), ( - 'litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp', + 'litellm.proxy.mcp_server.auth.user_api_key_auth_mcp', 'MCPRequestHandler', '_get_mcp_servers_from_access_groups', 'get_mcp_servers_from_access_groups', False, ), ( - 'litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp', + 'litellm.proxy.mcp_server.auth.user_api_key_auth_mcp', 'MCPRequestHandler', '_get_oauth2_headers_from_headers', 'get_oauth2_headers_from_headers', False, ), ( - 'litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp', + 'litellm.proxy.mcp_server.auth.user_api_key_auth_mcp', 'MCPRequestHandler', '_safe_get_headers_from_scope', 'safe_get_headers_from_scope', False, ), ( - 'litellm.proxy._experimental.mcp_server.bridge_token_flow', + 'litellm.proxy.mcp_server.bridge_token_flow', '', '_bridge_mint_error_response', 'bridge_mint_error_response', False, ), ( - 'litellm.proxy._experimental.mcp_server.bridge_token_flow', + 'litellm.proxy.mcp_server.bridge_token_flow', '', '_extract_user_id_from_request', 'extract_user_id_from_request', False, ), ( - 'litellm.proxy._experimental.mcp_server.bridge_token_flow', + 'litellm.proxy.mcp_server.bridge_token_flow', '', '_finish_bridge_mint', 'finish_bridge_mint', False, ), ( - 'litellm.proxy._experimental.mcp_server.bridge_token_flow', + 'litellm.proxy.mcp_server.bridge_token_flow', '', '_prepare_bridge_mint', 'prepare_bridge_mint', False, ), ( - 'litellm.proxy._experimental.mcp_server.bridge_token_flow', + 'litellm.proxy.mcp_server.bridge_token_flow', '', '_prepare_bridge_refresh', 'prepare_bridge_refresh', False, ), ( - 'litellm.proxy._experimental.mcp_server.bridge_token_flow', + 'litellm.proxy.mcp_server.bridge_token_flow', '', '_reload_active_user_by_id', 'reload_active_user_by_id', False, ), ( - 'litellm.proxy._experimental.mcp_server.byok_oauth_endpoints', + 'litellm.proxy.mcp_server.byok_oauth_endpoints', '', '_user_id_from_session_cookie', 'user_id_from_session_cookie', False, ), ( - 'litellm.proxy._experimental.mcp_server.db', + 'litellm.proxy.mcp_server.db', '', '_decode_oauth_payload', 'decode_oauth_payload', False, ), ( - 'litellm.proxy._experimental.mcp_server.discoverable_endpoints', + 'litellm.proxy.mcp_server.discoverable_endpoints', '', '_raise_if_not_oauth2', 'raise_if_not_oauth2', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_context', + 'litellm.proxy.mcp_server.mcp_context', '', '_mcp_active_toolset_id', 'mcp_active_toolset_id', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_context', + 'litellm.proxy.mcp_server.mcp_context', '', '_mcp_gateway_initialize_instructions', 'mcp_gateway_initialize_instructions', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_context', + 'litellm.proxy.mcp_server.mcp_context', '', '_mcp_gateway_server_name', 'mcp_gateway_server_name', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', '', '_UPSTREAM_OAUTH_DISCOVERY_AUTH_TYPES', 'UPSTREAM_OAUTH_DISCOVERY_AUTH_TYPES', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', '', '_caller_authorization_fans_out', 'caller_authorization_fans_out', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', '', '_client_forwarded_authorization_headers', 'client_forwarded_authorization_headers', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', '', '_resolve_openapi_tool_auth', 'resolve_openapi_tool_auth', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', '', '_should_strip_caller_authorization', 'should_strip_caller_authorization', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', 'MCPServerManager', '_build_mcp_server_table', 'build_mcp_server_table', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', 'MCPServerManager', '_build_stdio_env', 'build_stdio_env', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', 'MCPServerManager', '_create_mcp_client', 'create_mcp_client', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', 'MCPServerManager', '_ensure_upstream_initialize_instructions_cached', 'ensure_upstream_initialize_instructions_cached', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', 'MCPServerManager', '_extract_subject_token', 'extract_subject_token', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', 'MCPServerManager', '_get_mcp_server_from_tool_name', 'get_mcp_server_from_tool_name', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', 'MCPServerManager', '_get_tools_from_server', 'get_tools_from_server', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', 'MCPServerManager', '_is_server_accessible_from_ip', 'is_server_accessible_from_ip', False, ), ( - 'litellm.proxy._experimental.mcp_server.oauth2_token_cache', + 'litellm.proxy.mcp_server.oauth2_token_cache', '', '_compute_per_user_token_ttl', 'compute_per_user_token_ttl', False, ), ( - 'litellm.proxy._experimental.mcp_server.oauth_utils', + 'litellm.proxy.mcp_server.oauth_utils', '', '_redact_mcp_resource_url', 'redact_mcp_resource_url', False, ), ( - 'litellm.proxy._experimental.mcp_server.server', + 'litellm.proxy.mcp_server.server', '', '_redact_mcp_resource_url', 'redact_mcp_resource_url', False, ), ( - 'litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator', + 'litellm.proxy.mcp_server.openapi_to_mcp_generator', '', '_OPENAPI_TOOL_NAME_MAX_LEN', 'OPENAPI_TOOL_NAME_MAX_LEN', False, ), ( - 'litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator', + 'litellm.proxy.mcp_server.openapi_to_mcp_generator', '', '_request_auth_header', 'request_auth_header', False, ), ( - 'litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator', + 'litellm.proxy.mcp_server.openapi_to_mcp_generator', '', '_request_extra_headers', 'request_extra_headers', False, ), ( - 'litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator', + 'litellm.proxy.mcp_server.openapi_to_mcp_generator', '', '_request_resolved_auth_headers', 'request_resolved_auth_headers', False, ), ( - 'litellm.proxy._experimental.mcp_server.semantic_tool_filter', + 'litellm.proxy.mcp_server.semantic_tool_filter', 'SemanticMCPToolFilter', '_extract_tool_info', 'extract_tool_info', False, ), ( - 'litellm.proxy._experimental.mcp_server.server', + 'litellm.proxy.mcp_server.server', '', '_apply_toolset_scope', 'apply_toolset_scope', False, ), ( - 'litellm.proxy._experimental.mcp_server.server_resolution', + 'litellm.proxy.mcp_server.server_resolution', 'MCPServerRegistry', '_build_mcp_server_table', 'build_mcp_server_table', False, ), ( - 'litellm.proxy._experimental.mcp_server.server_resolution', + 'litellm.proxy.mcp_server.server_resolution', 'MCPServerRegistry', '_is_server_accessible_from_ip', 'is_server_accessible_from_ip', @@ -4867,7 +4867,7 @@ LLMS_FORWARDER_CASES: Final = ( False, ), ( - "litellm.llms.openai.chat.gpt_5_transformation", + "litellm.llms.openai.chat.gpt_reasoning_transformation", "OpenAIGPT5Config", "_supports_reasoning_effort_level", "supports_reasoning_effort_level", diff --git a/tests/unit/test_router/test_router.py b/tests/unit/test_router/test_router.py index 9cc1bf6ce79..e2ee80b7874 100644 --- a/tests/unit/test_router/test_router.py +++ b/tests/unit/test_router/test_router.py @@ -5,16 +5,17 @@ import functools import gc import itertools import json +import linecache import logging import os import sys import threading import warnings -from collections.abc import AsyncIterable, AsyncIterator, Awaitable, Callable, Mapping +from collections.abc import AsyncIterable, AsyncIterator, Awaitable, Callable, Iterator, Mapping from datetime import datetime, timedelta, timezone from pathlib import Path -from types import MappingProxyType, SimpleNamespace -from typing import TYPE_CHECKING, Final, Literal, cast +from types import CodeType, FrameType, MappingProxyType, SimpleNamespace +from typing import TYPE_CHECKING, Final, Literal, TypeVar, cast from unittest.mock import AsyncMock, MagicMock, Mock, patch import httpx @@ -38,8 +39,8 @@ from litellm.integrations.custom_guardrail import CustomGuardrail from litellm.integrations.custom_logger import CustomLogger from litellm.integrations.otel.plumbing.context import set_request_root_span from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLogging -from litellm.llms.anthropic.pass_through.messages.streaming_iterator import closing_superseded_attempt -from litellm.llms.anthropic.pass_through.messages.agentic_streaming_iterator import ( +from litellm.llms.anthropic.messages.native.streaming_iterator import closing_superseded_attempt +from litellm.llms.anthropic.messages.native.agentic_streaming_iterator import ( SERVER_FULFILLED_TOOL_LEAK_ERROR_SSE_BYTES, ) from litellm.llms.bedrock.common_utils import BedrockError @@ -60,7 +61,10 @@ from litellm.router import ( _without_line_breaks, Span, ) +from litellm.proxy.response_polling.polling_handler import should_use_polling_for_request from litellm.router_strategy import simple_shuffle +from litellm.router_strategy.complexity_router.complexity_router import ComplexityRouter +from litellm.router_strategy.savings_baseline import Baseline, _models_in from litellm.router_utils.client_initalization_utils import MaxParallelRequestsLimit from litellm.router_utils.cooldown_handlers import ( _async_get_cooldown_deployments, @@ -108,6 +112,137 @@ if TYPE_CHECKING: from litellm.integrations.otel.logger import OpenTelemetryV2 +_ROUTER_DECISIONS_RESPONSE: Final[Mapping[str, object]] = { + "model": "gpt-6-luna", + "answers": [{"type": "predicate", "name": "damaged", "probability": 0.9}], + "usage": { + "input_tokens": 1, + "input_tokens_details": {"cached_tokens": 0, "cache_write_tokens": 0}, + "output_tokens": 1, + "output_tokens_details": {"reasoning_tokens": 0}, + "total_tokens": 2, + }, +} + + +_OPENAI_DECISIONS_PARAMS: Final[Mapping[str, object]] = { + "model": "openai/gpt-6-luna", + "api_base": "https://api.openai.com/v1", + "api_key": "k", +} +_BEDROCK_DECISIONS_PARAMS: Final[Mapping[str, object]] = { + "model": "bedrock/us.openai.gpt-5.6-terra", + "aws_access_key_id": "fake", + "aws_secret_access_key": "fake", + "aws_region_name": "us-east-1", +} + + +def _decisions_leg(leg_id: str, params: Mapping[str, object], weight: int | None = None) -> dict[str, object]: + return { + "model_name": "decision-group", + "litellm_params": params if weight is None else {**params, "weight": weight}, + "model_info": {"id": leg_id}, + } + + +_OPENAI_DECISIONS_LEG: Final = _decisions_leg("openai-leg", _OPENAI_DECISIONS_PARAMS) +_BEDROCK_DECISIONS_LEG: Final = _decisions_leg("bedrock-leg", _BEDROCK_DECISIONS_PARAMS) + + +def _mixed_decisions_group_router(*legs: dict[str, object]) -> Router: + return Router(model_list=list(legs), routing_strategy="simple-shuffle") + + +@pytest.fixture +def _router_httpx_transport(monkeypatch: pytest.MonkeyPatch) -> Iterator[None]: + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + litellm.in_memory_llm_clients_cache.flush_cache() + yield + litellm.in_memory_llm_clients_cache.flush_cache() + + +@pytest.mark.asyncio +async def test_decisions_on_a_mixed_group_never_routes_to_a_leg_without_decisions_support( + respx_mock: respx.MockRouter, + _router_httpx_transport: None, +) -> None: + router: Final = _mixed_decisions_group_router(_OPENAI_DECISIONS_LEG, _BEDROCK_DECISIONS_LEG) + route: Final = respx_mock.post("https://api.openai.com/v1/decisions").respond(json=_ROUTER_DECISIONS_RESPONSE) + + for _ in range(20): + await router.adecisions( + model="decision-group", + input=[{"role": "user", "content": "The package arrived with a broken screen."}], + questions=[ + {"type": "predicate", "name": "damaged", "instructions": "Does the customer report a damaged item?"} + ], + ) + + assert route.call_count == 20 + + +def test_decisions_on_a_mixed_group_never_routes_to_a_leg_without_decisions_support_sync( + respx_mock: respx.MockRouter, +) -> None: + router: Final = _mixed_decisions_group_router(_OPENAI_DECISIONS_LEG, _BEDROCK_DECISIONS_LEG) + route: Final = respx_mock.post("https://api.openai.com/v1/decisions").respond(json=_ROUTER_DECISIONS_RESPONSE) + + for _ in range(20): + router.decisions( + model="decision-group", + input=[{"role": "user", "content": "The package arrived with a broken screen."}], + questions=[ + {"type": "predicate", "name": "damaged", "instructions": "Does the customer report a damaged item?"} + ], + ) + + assert route.call_count == 20 + + +@pytest.mark.asyncio +async def test_decisions_on_a_group_with_no_capable_leg_still_returns_the_provider_error() -> None: + router: Final = Router( + model_list=[ + { + "model_name": "bedrock-only", + "litellm_params": { + "model": "bedrock/us.openai.gpt-5.6-terra", + "aws_access_key_id": "fake", + "aws_secret_access_key": "fake", + "aws_region_name": "us-east-1", + }, + "model_info": {"id": "bedrock-leg"}, + } + ] + ) + + with pytest.raises(litellm.BadRequestError, match="Unknown Decisions provider 'bedrock'"): + await router.adecisions( + model="bedrock-only", + input=[{"role": "user", "content": "The package arrived with a broken screen."}], + questions=[ + {"type": "predicate", "name": "damaged", "instructions": "Does the customer report a damaged item?"} + ], + ) + + +@pytest.mark.asyncio +async def test_chat_on_a_mixed_group_still_reaches_the_leg_without_decisions_support() -> None: + router: Final = _mixed_decisions_group_router( + _decisions_leg("openai-leg", _OPENAI_DECISIONS_PARAMS, weight=0), + _decisions_leg("bedrock-leg", _BEDROCK_DECISIONS_PARAMS, weight=1), + ) + + response: Final = await router.acompletion( + model="decision-group", + messages=[{"role": "user", "content": "Say hi"}], + mock_response="hi", + ) + + assert response._hidden_params["model_id"] == "bedrock-leg" + + def test_update_kwargs_does_not_mutate_defaults_and_merges_metadata(): # initialize a real Router (env‑vars can be empty) router = litellm.Router( @@ -148,6 +283,15 @@ def test_update_kwargs_does_not_mutate_defaults_and_merges_metadata(): assert kwargs["litellm_metadata"] == {"baz": 123} +def test_router_model_group_llm_provider_resolves_chatgpt_without_login(tmp_path, monkeypatch: pytest.MonkeyPatch): + monkeypatch.setenv("CHATGPT_TOKEN_DIR", str(tmp_path)) + params: Final = LiteLLM_Params(model="chatgpt/gpt-5.4") + + assert Router._model_group_llm_provider(params) == ("gpt-5.4", "chatgpt") + assert Router._model_group_llm_provider(LiteLLM_Params(model="no-such-provider-model-xyz")) == ("", "") + assert not any(tmp_path.iterdir()) + + def test_router_with_model_info_and_model_group(): """ Test edge case where user specifies model_group in model_info @@ -8741,7 +8885,8 @@ def test_get_wildcard_deployment_usable_by_team_prefers_the_team_pattern(): pytest.param(False, "rwild-chat", "team-r", ("team-r-wildcard",), id="team-pattern-when-no-proxy-wide-match"), pytest.param(False, "rwild-chat", "team-b", (), id="another-teams-pattern-never-serves"), pytest.param(False, "rwild-chat", None, (), id="no-team-no-team-pattern"), - pytest.param(True, "rwild-chat", "team-r", ("catch-all",), id="proxy-wide-pattern-beats-the-team-pattern"), + pytest.param(True, "rwild-chat", "team-r", ("team-r-wildcard",), id="team-pattern-beats-the-proxy-wide-pattern"), + pytest.param(True, "rwild-chat", "team-b", ("catch-all",), id="another-team-falls-through-to-proxy-wide"), pytest.param(True, "ptu-chat", "team-r", ("ptu-wildcard",), id="only-the-most-specific-proxy-wide-pattern"), ], ) @@ -8780,6 +8925,39 @@ def test_wildcard_route_deployments_is_the_one_pattern_routing_serves_from( ) +@pytest.mark.parametrize( + ("team_id", "expected_id"), + [ + pytest.param("team-a", "team-a-byok", id="team-key-uses-its-own-byok-wildcard"), + pytest.param("team-b", "shared-openrouter", id="team-without-byok-uses-the-shared-wildcard"), + pytest.param(None, "shared-openrouter", id="key-without-team-uses-the-shared-wildcard"), + ], +) +def test_team_byok_wildcard_is_served_before_a_proxy_wide_wildcard_of_the_same_name( + team_id: str | None, expected_id: str +): + """Regression: a proxy-wide openrouter/* shadowed a team's own openrouter/* BYOK deployment for that team's keys.""" + router: Final = litellm.Router( + model_list=[ + { + "model_name": "model_name_team-a_internal", + "litellm_params": {"model": "openrouter/*", "api_key": "sk-team-a"}, + "model_info": {"id": "team-a-byok", "team_id": "team-a", "team_public_model_name": "openrouter/*"}, + }, + { + "model_name": "openrouter/*", + "litellm_params": {"model": "openrouter/*", "api_key": "sk-shared"}, + "model_info": {"id": "shared-openrouter"}, + }, + ] + ) + requested: Final = "openrouter/openai/gpt-5-nano" + + served: Final = router.wildcard_route_deployments(requested, team_id) + + assert tuple(Deployment.model_validate(d).model_info.id for d in served) == (expected_id,) + + def test_get_deployment_credentials_with_provider_aws_bedrock_runtime_endpoint(): """ Test that get_deployment_credentials_with_provider correctly copies @@ -29871,3 +30049,544 @@ async def test_responses_fallback_wrapper_disconnect_billing_keeps_the_primary_s wrapped.adopt_fallback_headers(fallback) assert wrapped.partial_response_on_disconnect().response.usage.output_tokens == primary_tokens + fallback_tokens + + +_SYNC_SECONDS: Final = 10 +_ROUTER_FILE: Final = Router.__init__.__code__.co_filename +_INDEX_LOCK_LINES: Final = frozenset( + number + for number, line in enumerate(linecache.getlines(_ROUTER_FILE), start=1) + if "with self._deployment_index_lock" in line +) + +_Read = TypeVar("_Read") + + +def _concurrent_delete_deployment(index: int) -> dict[str, object]: + return { + "model_name": f"model-{index}", + "litellm_params": {"model": f"openai/gpt-{index}", "api_key": "k"}, + "model_info": { + "id": f"deployment-{index}", + "team_id": "team-1", + "team_public_model_name": "public-shared" if index >= 2 else f"public-{index}", + }, + } + + +def _concurrent_delete_router() -> Router: + return Router(model_list=[_concurrent_delete_deployment(index) for index in range(4)]) + + +def _read_during_held_write( + read: Callable[[], _Read], + write: Callable[[], object], + event: Literal["call", "c_call"] = "call", + write_after: CodeType | None = None, +) -> _Read: + """Run `read` on its own thread while `write` waits at its first `event` in the re-index, after the list shrank and + before the maps caught up. With `write_after`, the write starts when `read` returns from that function. The write + resumes once `read` returns or reaches the router's index lock, so a read that skips the lock meets the half-updated + list and a read that takes the lock waits for the write""" + reindex: Final = Router._update_deployment_indices_after_removal.__code__ + held: Final = threading.Event() + release: Final = threading.Event() + settled: Final = threading.Event() + released_in_time: Final[list[bool]] = [] + outcome: Final[list[_Read]] = [] + failure: Final[list[BaseException]] = [] + + def hold_in_reindex(frame: FrameType, observed: str, _arg: object) -> None: + if observed == event and frame.f_code is reindex and not held.is_set(): + held.set() + released_in_time.append(release.wait(timeout=_SYNC_SECONDS)) + + def run_write() -> None: + previous: Final = sys.getprofile() + sys.setprofile(hold_in_reindex) + try: + write() + finally: + sys.setprofile(previous) + + writer: Final = threading.Thread(target=run_write) + + def start_write() -> None: + writer.start() + assert held.wait(timeout=_SYNC_SECONDS), "the write never reached re-indexing" + + def watch_read(frame: FrameType, observed: str, _arg: object) -> Callable[..., object] | None: + if frame.f_code.co_filename != _ROUTER_FILE: + return None + if observed == "return" and frame.f_code is write_after and writer.ident is None: + start_write() + elif observed == "line" and held.is_set() and frame.f_lineno in _INDEX_LOCK_LINES: + settled.set() + return watch_read + + def run_read() -> None: + previous: Final = sys.gettrace() + sys.settrace(watch_read) + try: + outcome.append(read()) + except BaseException as error: + failure.append(error) + finally: + sys.settrace(previous) + settled.set() + + reader: Final = threading.Thread(target=run_read) + try: + if write_after is None: + start_write() + reader.start() + assert settled.wait(timeout=_SYNC_SECONDS), "the read neither returned nor reached the index lock" + finally: + release.set() + if reader.ident is not None: + reader.join() + if writer.ident is not None: + writer.join() + assert released_in_time == [True], "the write was not held for the whole read" + if failure: + raise failure[0] + return outcome[0] + + +def _deployment_ids(deployments: list[DeploymentTypedDict]) -> tuple[str, ...]: + return tuple(deployment["model_info"]["id"] for deployment in deployments) + + +@pytest.mark.parametrize( + ("read", "expected"), + [ + pytest.param( + lambda router: router.get_deployment("deployment-3").model_info.id, "deployment-3", id="get_deployment" + ), + pytest.param( + lambda router: router.get_model_info("deployment-3")["model_info"]["id"], + "deployment-3", + id="get_model_info", + ), + pytest.param( + lambda router: _deployment_ids(router.get_all_deployments("model-3")), + ("deployment-3",), + id="get_all_deployments", + ), + pytest.param( + lambda router: _deployment_ids(router.get_all_deployments("public-shared", team_id="team-1")), + ("deployment-2", "deployment-3"), + id="get_all_deployments-team", + ), + pytest.param( + lambda router: router.map_team_model("public-shared", "team-1"), "public-shared", id="map_team_model" + ), + pytest.param(lambda router: router.get_model_ids("model-3"), ["deployment-3"], id="get_model_ids-by-name"), + pytest.param( + lambda router: router.get_model_ids(), ["deployment-1", "deployment-2", "deployment-3"], id="get_model_ids" + ), + pytest.param( + lambda router: router.get_deployment_by_model_group_name("model-3").model_info.id, + "deployment-3", + id="get_deployment_by_model_group_name", + ), + pytest.param( + lambda router: router.get_model_listing_info("model-3").cost_map_keys, + ("openai/gpt-3",), + id="get_model_listing_info", + ), + pytest.param( + lambda router: router.team_model_has_alternatives("deployment-3"), True, id="team_model_has_alternatives" + ), + pytest.param( + lambda router: ( + router._get_model_group_deployment_usable_by_team( + model_group_name="model-3", team_id="team-1" + ).model_info.id + ), + "deployment-3", + id="model_group_deployment_usable_by_team", + ), + pytest.param( + lambda router: ( + router._get_team_public_name_deployment(model_id="public-shared", team_id="team-1").model_info.id + ), + "deployment-2", + id="team_public_name_deployment", + ), + pytest.param( + lambda router: _deployment_ids(router._team_deployments_across_teams("public-shared")), + ("deployment-2", "deployment-3"), + id="team_deployments_across_teams", + ), + pytest.param( + lambda router: _deployment_ids(list(router.deployments_named("model-3") or ())), + ("deployment-3",), + id="deployments_named", + ), + pytest.param( + lambda router: should_use_polling_for_request( + background_mode=True, + polling_via_cache_enabled=["openai"], + redis_cache=MagicMock(), + model="model-3", + llm_router=router, + ), + True, + id="response_polling_provider_lookup", + ), + pytest.param( + lambda router: _models_in(router, "model-3"), + (Baseline("openai/gpt-3", "deployment-3"),), + id="savings_baseline_candidates", + ), + ], +) +def test_lookup_during_a_concurrent_delete_returns_the_requested_deployment( + read: Callable[[Router], object], expected: object +) -> None: + router: Final = _concurrent_delete_router() + + observed: Final = _read_during_held_write(lambda: read(router), lambda: router.delete_deployment("deployment-0")) + + assert observed == expected + + +def test_lookup_during_an_upsert_returns_the_requested_deployment() -> None: + router: Final = _concurrent_delete_router() + rotated: Final = Deployment( + **{**_concurrent_delete_deployment(0), "litellm_params": {"model": "openai/gpt-0", "api_key": "rotated"}} + ) + + observed: Final = _read_during_held_write( + lambda: router.get_deployment("deployment-3").model_info.id, lambda: router.upsert_deployment(rotated) + ) + + assert observed == "deployment-3" + + +def test_add_during_a_concurrent_delete_indexes_the_added_deployment() -> None: + router: Final = _concurrent_delete_router() + + _read_during_held_write( + lambda: router.add_deployment(Deployment(**_concurrent_delete_deployment(4))), + lambda: router.delete_deployment("deployment-0"), + ) + + assert [router.get_deployment(f"deployment-{index}").model_info.id for index in range(1, 5)] == [ + f"deployment-{index}" for index in range(1, 5) + ] + + +def test_set_model_list_during_a_concurrent_delete_indexes_the_new_list() -> None: + router: Final = _concurrent_delete_router() + + _read_during_held_write( + lambda: router.set_model_list([_concurrent_delete_deployment(index) for index in range(10, 14)]), + lambda: router.delete_deployment("deployment-0"), + event="c_call", + ) + + assert router.get_model_ids() == [f"deployment-{index}" for index in range(10, 14)] + + +def test_team_model_has_alternatives_when_a_delete_starts_after_its_deployment_lookup() -> None: + router: Final = _concurrent_delete_router() + + has_alternatives: Final = _read_during_held_write( + lambda: router.team_model_has_alternatives("deployment-3"), + lambda: router.delete_deployment("deployment-0"), + write_after=Router.get_deployment.__code__, + ) + + assert has_alternatives is True + + +def test_init_adaptive_router_deployment_during_a_concurrent_delete_prices_the_listed_model() -> None: + priced: Final = { + **_concurrent_delete_deployment(3), + "litellm_params": {"model": "openai/gpt-3", "api_key": "k", "input_cost_per_token": 3e-06}, + } + router: Final = Router(model_list=[*(_concurrent_delete_deployment(index) for index in range(3)), priced]) + adaptive: Final = Deployment( + model_name="adaptive", + litellm_params=LiteLLM_Params( + model="auto_router/adaptive_router", adaptive_router_config={"available_models": ["model-3"]} + ), + model_info=ModelInfo(id="adaptive"), + ) + + _read_during_held_write( + lambda: router.init_adaptive_router_deployment(deployment=adaptive), + lambda: router.delete_deployment("deployment-0"), + ) + + assert router.adaptive_routers["adaptive"][0].strategy.model_to_cost == {"model-3": 3e-06} + + +def test_complexity_router_adaptive_pool_during_a_concurrent_delete_prices_the_listed_model() -> None: + priced: Final = { + **_concurrent_delete_deployment(3), + "litellm_params": {"model": "openai/gpt-3", "api_key": "k", "input_cost_per_token": 3e-06}, + } + router: Final = Router(model_list=[*(_concurrent_delete_deployment(index) for index in range(3)), priced]) + complexity: Final = ComplexityRouter( + model_name="hybrid", + litellm_router_instance=router, + complexity_router_config={"adaptive": True, "tiers": {"SIMPLE": ["model-3"]}}, + ) + + adaptive: Final = _read_during_held_write( + complexity._ensure_adaptive_router, lambda: router.delete_deployment("deployment-0") + ) + + assert adaptive is not None + assert adaptive.model_to_cost == {"model-3": 3e-06} + + +def test_delete_of_an_unknown_deployment_returns_none_and_keeps_the_list() -> None: + router: Final = _concurrent_delete_router() + + assert router.delete_deployment("deployment-9") is None + assert router.get_model_ids() == [f"deployment-{index}" for index in range(4)] + + +def test_get_model_ids_by_name_skips_team_deployments_only_when_asked() -> None: + shared: Final = {"model_name": "shared", "litellm_params": {"model": "openai/gpt-shared", "api_key": "k"}} + router: Final = Router( + model_list=[ + {**shared, "model_info": {"id": "global"}}, + {**shared, "model_info": {"id": "team", "team_id": "team-1", "team_public_model_name": "public"}}, + ] + ) + + assert router.get_model_ids("shared", exclude_team_models=True) == ["global"] + assert router.get_model_ids("shared") == ["global", "team"] + + +_IMAGE_PART = {"type": "image_url", "image_url": {"url": "data:image/png;base64,iVBORw0KGgo="}} +_IMAGE_CHAT = [{"role": "user", "content": [{"type": "text", "text": "What is in this image?"}, _IMAGE_PART]}] +_IMAGE_RESPONSES_INPUT = [ + { + "role": "user", + "content": [ + {"type": "input_text", "text": "What is in this image?"}, + {"type": "input_image", "image_url": "data:image/png;base64,iVBORw0KGgo="}, + ], + } +] +_VISION_LEG: Final[dict[str, object]] = {"litellm_params": {"model": "openai/gpt-5.6-terra"}, "model_info": {"id": "vision"}} +_DECLARED_TEXT_LEG: Final[dict[str, object]] = { + "litellm_params": {"model": "bedrock/openai.gpt-oss-120b-1:0"}, + "model_info": {"id": "declared-text", "supports_vision": False}, +} + + +def _mixed_router(*deployments: dict[str, object], routing_strategy: str = "latency-based-routing") -> litellm.Router: + return litellm.Router( + model_list=[{"model_name": "mixed", **deployment} for deployment in deployments], + routing_strategy=routing_strategy, + ) + + +def _candidate_ids( + router: litellm.Router, + messages: list[dict[str, object]] | None = None, + request_kwargs: dict[str, object] | None = None, +) -> list[str]: + candidates: Final = router._without_declared_text_only_deployments( + router.get_model_list(model_name="mixed"), "mixed", messages, request_kwargs + ) + return [d["model_info"]["id"] for d in candidates] + + +def test_router_picks_the_vision_leg_for_image_requests_without_enable_pre_call_checks(): + router: Final = _mixed_router(_VISION_LEG, _DECLARED_TEXT_LEG) + assert router.enable_pre_call_checks is False + for _ in range(5): + assert router.get_available_deployment(model="mixed", messages=_IMAGE_CHAT)["model_info"]["id"] == "vision" + + +@pytest.mark.asyncio +async def test_async_router_picks_the_vision_leg_for_responses_images_without_enable_pre_call_checks(): + router: Final = _mixed_router(_VISION_LEG, _DECLARED_TEXT_LEG) + for _ in range(5): + deployment: Final = await router.async_get_available_deployment( + model="mixed", request_kwargs={"input": _IMAGE_RESPONSES_INPUT} + ) + assert deployment["model_info"]["id"] == "vision" + + +def test_router_sends_an_image_to_the_text_only_leg_when_pre_call_checks_drop_the_vision_leg(): + router: Final = litellm.Router( + model_list=[ + {"model_name": "mixed", **_VISION_LEG, "model_info": {"id": "vision", "max_input_tokens": 1}}, + {"model_name": "mixed", **_DECLARED_TEXT_LEG}, + ], + routing_strategy="latency-based-routing", + enable_pre_call_checks=True, + ) + assert router.get_available_deployment(model="mixed", messages=_IMAGE_CHAT)["model_info"]["id"] == "declared-text" + + +def test_router_sends_an_image_to_the_text_only_leg_when_the_vision_leg_is_cooling_down(): + router: Final = _mixed_router(_VISION_LEG, _DECLARED_TEXT_LEG) + router.cooldown_cache.add_deployment_to_cooldown( + model_id="vision", original_exception=Exception("bad key"), exception_status=401, cooldown_time=60 + ) + assert router.get_available_deployment(model="mixed", messages=_IMAGE_CHAT)["model_info"]["id"] == "declared-text" + + +def test_without_declared_text_only_deployments_passes_a_chosen_deployment_through(): + assert litellm.Router._without_declared_text_only_deployments(_DECLARED_TEXT_LEG, "mixed", _IMAGE_CHAT, None) is _DECLARED_TEXT_LEG + + +def test_image_routing_drop_declared_text_only_legs_for_image_requests(): + router: Final = _mixed_router(_VISION_LEG, _DECLARED_TEXT_LEG) + assert _candidate_ids(router, messages=_IMAGE_CHAT) == ["vision"] + + +def test_image_routing_keep_declared_text_only_legs_for_text_requests(): + router: Final = _mixed_router(_VISION_LEG, _DECLARED_TEXT_LEG) + assert _candidate_ids(router, messages=[{"role": "user", "content": "Say hi"}]) == [ + "vision", + "declared-text", + ] + + +def test_image_routing_drop_declared_text_only_legs_for_responses_input_image(): + router: Final = _mixed_router(_VISION_LEG, _DECLARED_TEXT_LEG) + assert _candidate_ids(router, request_kwargs={"input": _IMAGE_RESPONSES_INPUT}) == ["vision"] + + +def test_image_routing_send_image_to_the_group_when_every_leg_is_declared_text_only(): + other_text_leg = {**_DECLARED_TEXT_LEG, "model_info": {"id": "declared-text-2", "supports_vision": False}} + router: Final = _mixed_router(_DECLARED_TEXT_LEG, other_text_leg) + assert _candidate_ids(router, messages=_IMAGE_CHAT) == [ + "declared-text", + "declared-text-2", + ] + + +def test_image_routing_keep_undeclared_custom_legs_for_image_requests(): + custom_leg = { + "litellm_params": {"model": "hosted_vllm/Qwen2.5-VL-7B-Instruct", "api_base": "http://localhost:8000"}, + "model_info": {"id": "custom"}, + } + router: Final = _mixed_router(_VISION_LEG, custom_leg) + assert _candidate_ids(router, messages=_IMAGE_CHAT) == ["vision", "custom"] + + +def test_image_routing_resolve_vision_through_the_cost_map_and_base_model(): + catalog_text_leg = {"litellm_params": {"model": "bedrock/deepseek.v3.2"}, "model_info": {"id": "catalog-text"}} + azure_text_leg = { + "litellm_params": {"model": "azure/my-audio-deployment", "api_base": "https://x.openai.azure.com"}, + "model_info": {"id": "azure-text", "base_model": "azure/gpt-audio"}, + } + router: Final = _mixed_router(_VISION_LEG, catalog_text_leg, azure_text_leg) + assert _candidate_ids(router, messages=_IMAGE_CHAT) == ["vision"] + + +@pytest.mark.parametrize( + ("deployment", "expected"), + [ + (_DECLARED_TEXT_LEG, True), + ({"litellm_params": {"model": "bedrock/openai.gpt-oss-120b-1:0"}, "model_info": {"supports_vision": True}}, False), + ({"litellm_params": {"model": "bedrock/deepseek.v3.2"}, "model_info": {}}, True), + ({"litellm_params": {"model": "azure/my-deploy"}, "model_info": {"base_model": "azure/gpt-audio"}}, True), + ({"litellm_params": {"model": "hosted_vllm/Qwen2.5-VL-7B-Instruct"}, "model_info": {}}, False), + ({"litellm_params": {"model": "no-such-model-anywhere"}, "model_info": {}}, False), + ({"litellm_params": {}, "model_info": {}}, False), + ], + ids=["override-false", "override-true", "cost-map-false", "base-model-false", "undeclared", "unresolvable", "no-params"], +) +def test_deployment_declares_no_vision_reads_the_override_then_the_cost_map(deployment: dict[str, object], expected: bool): + assert litellm.Router._deployment_declares_no_vision(deployment, "mixed") is expected + + +def test_request_carries_image_sees_chat_parts_and_responses_input_items(): + assert litellm.Router._request_carries_image(_IMAGE_CHAT, {}) is True + assert litellm.Router._request_carries_image(None, {"input": _IMAGE_RESPONSES_INPUT}) is True + assert litellm.Router._request_carries_image([{"role": "user", "content": "Say hi"}], {}) is False + assert litellm.Router._request_carries_image(None, {"input": "Say hi"}) is False + + +@pytest.mark.asyncio +@pytest.mark.usefixtures("isolate_litellm_state") +@pytest.mark.parametrize("surface", ["chat", "messages"]) +@pytest.mark.parametrize("credential_kind", ["oauth", "api_key"]) +async def test_anthropic_caller_rate_limit_does_not_block_other_credentials( + respx_mock: respx.MockRouter, monkeypatch: pytest.MonkeyPatch, surface: str, credential_kind: str +) -> None: + from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler + from litellm.types.router import AllowedFailsPolicy + + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + monkeypatch.setattr("time.time", lambda: 1767225600.0) + + def upstream(request: httpx.Request) -> httpx.Response: + credential: Final = request.headers.get("authorization", request.headers.get("x-api-key", "")) + if credential.endswith("limited") and route.call_count < 2: + return httpx.Response( + 429, + headers={"retry-after": "168307"}, + json={"type": "error", "error": {"type": "rate_limit_error", "message": "usage limit"}}, + ) + return httpx.Response(200, json={ + "id": "msg-healthy", "type": "message", "role": "assistant", "model": "claude-sonnet-5-5", + "content": [{"type": "text", "text": "healthy account"}], "stop_reason": "end_turn", + "usage": {"input_tokens": 2, "output_tokens": 2}, + }) + + route: Final = respx_mock.post("https://api.anthropic.com/v1/messages").mock(side_effect=upstream) + router: Final = Router( + model_list=[{ + "model_name": "claude", "litellm_params": { + "model": "anthropic/claude-sonnet-5-5", "api_key": "fake-gateway-key", + }, "model_info": {"id": "shared-anthropic"}, + }], + num_retries=0, + allowed_fails_policy=AllowedFailsPolicy(RateLimitErrorAllowedFails=1), + ) + client: Final = AsyncHTTPHandler(transport=httpx.AsyncHTTPTransport()) + + async def call(account: str | None) -> object: + credentials: Final = ( + {"provider_specific_header": { + "custom_llm_provider": "anthropic", "extra_headers": { + "Authorization": f"Bearer sk-ant-oat-fake-{account}", + }, + }} if credential_kind == "oauth" else {"api_key": f"fake-{account}"} + ) if account is not None else {} + if surface == "messages": + max_tokens: Final = litellm.get_max_tokens("anthropic/claude-sonnet-5-5") + assert max_tokens is not None + return await router.aanthropic_messages( + model="claude", messages=[{"role": "user", "content": "hello"}], + client=client, max_tokens=max_tokens, **credentials, + ) + return await router.acompletion( + model="claude", messages=[{"role": "user", "content": "hello"}], + client=client, **credentials, + ) + + try: + for _ in range(2): + with pytest.raises(litellm.RateLimitError): + await call("limited") + await GLOBAL_LOGGING_WORKER.flush() + limited_calls: Final = len(route.calls) + assert limited_calls == 2 + await call("healthy") + assert len(route.calls) == limited_calls + 1 + assert route.calls[-1].request.headers.get( + "authorization", route.calls[-1].request.headers.get("x-api-key", "") + ) == ("Bearer sk-ant-oat-fake-healthy" if credential_kind == "oauth" else "fake-healthy") + await call(None) + assert len(route.calls) == limited_calls + 2 + assert route.calls[-1].request.headers["x-api-key"] == "fake-gateway-key" + await call("limited") + assert len(route.calls) == limited_calls + 3 + finally: + await GLOBAL_LOGGING_WORKER.flush() + await client.close() diff --git a/tests/unit/test_router_model_cost_isolation.py b/tests/unit/test_router_model_cost_isolation.py index f001008ee2c..20b0055f729 100644 --- a/tests/unit/test_router_model_cost_isolation.py +++ b/tests/unit/test_router_model_cost_isolation.py @@ -3081,6 +3081,36 @@ def test_reload_keeps_custom_pricing_configured_on_litellm_params_for_a_db_model _invalidate_model_cost_lowercase_map() +def test_reload_keeps_custom_pricing_of_a_db_model_on_a_router_built_without_a_model_list( + monkeypatch: pytest.MonkeyPatch, +) -> None: + """ + A proxy whose config.yaml has no model_list builds its router without one and + takes every deployment from the DB afterwards. A price data reload must restore + that deployment's custom pricing exactly as it does for a config router. + """ + fetched_catalog: Final = copy.deepcopy(litellm.model_cost) + router: Final = Router() + router.add_deployment( + deployment=Deployment( + model_name="db-only-priced", + litellm_params=LiteLLM_Params( + model="openai/gpt-4o", + api_key="sk-fake", + input_cost_per_token=0.000123, + output_cost_per_token=0.000456, + ), + model_info=ModelInfo(id="db-only-priced-id"), + ) + ) + assert litellm.model_cost["db-only-priced-id"]["input_cost_per_token"] == 0.000123 + + _simulate_price_data_reload_with_provider_sets(monkeypatch, fetched_catalog) + + assert litellm.model_cost["db-only-priced-id"]["input_cost_per_token"] == 0.000123 + assert litellm.model_cost["db-only-priced-id"]["output_cost_per_token"] == 0.000456 + + def test_replay_live_router_model_cost_rebuilds_every_live_router(): """ A process can hold more than one Router, so the rebuild has to fan out across diff --git a/tests/unit/test_spend_logs_guard.py b/tests/unit/test_spend_logs_guard.py new file mode 100644 index 00000000000..9a033045dd0 --- /dev/null +++ b/tests/unit/test_spend_logs_guard.py @@ -0,0 +1,79 @@ +import importlib.util +import sys +from pathlib import Path +from typing import Final + +_SCRIPT: Final = Path(__file__).resolve().parents[2] / "ci_cd" / "spend_logs_guard.py" +_SPEC: Final = importlib.util.spec_from_file_location("spend_logs_guard", _SCRIPT) +assert _SPEC is not None and _SPEC.loader is not None +guard: Final = importlib.util.module_from_spec(_SPEC) +sys.modules["spend_logs_guard"] = guard +_SPEC.loader.exec_module(guard) + + +def _diff(path: str, added: str, start: int = 10) -> str: + return f"diff --git a/{path} b/{path}\n--- a/{path}\n+++ b/{path}\n@@ -{start},0 +{start},1 @@\n+{added}\n" + + +class TestSpendLogHits: + def test_an_added_schema_line_naming_the_table_is_a_hit(self): + diff: Final = _diff( + "schema.prisma", ' @@index([api_key, startTime], map: "LiteLLM_SpendLogs_api_key_startTime_idx")', 740 + ) + assert guard.spend_log_hits(diff) == ( + 'schema.prisma: @@index([api_key, startTime], map: "LiteLLM_SpendLogs_api_key_startTime_idx")', + ) + + def test_an_added_migration_line_is_a_hit_in_any_case(self): + path: Final = "litellm-proxy-extras/litellm_proxy_extras/migrations/20260101000000_x/migration.sql" + hits: Final = guard.spend_log_hits(_diff(path, 'CREATE INDEX "i" ON "litellm_spendlogs"("api_key");', 3)) + assert hits == (f'{path}: CREATE INDEX "i" ON "litellm_spendlogs"("api_key");',) + + def test_a_removed_line_or_another_table_or_an_unwatched_file_is_not_a_hit(self): + removed: Final = "--- a/schema.prisma\n+++ b/schema.prisma\n@@ -1,1 +1,0 @@\n-model LiteLLM_SpendLogs {\n" + other: Final = _diff("schema.prisma", " team_id String // LiteLLM_TeamTable, not MyLiteLLM_SpendLogs", 5) + elsewhere: Final = _diff("litellm/proxy/utils.py", 'table = "LiteLLM_SpendLogs"', 5) + assert guard.spend_log_hits(removed + other + elsewhere) == () + + def test_two_files_in_one_diff_are_attributed_to_their_own_path(self): + diff: Final = _diff("litellm/proxy/schema.prisma", " a LiteLLM_SpendLogs", 1) + _diff( + "schema.prisma", " b String", 1 + ) + assert guard.spend_log_hits(diff) == ("litellm/proxy/schema.prisma: a LiteLLM_SpendLogs",) + + +class TestApprovedBy: + def test_the_latest_review_of_the_approver_decides(self): + reviews: Final = tuple( + guard.Review(state=state, user=guard.Reviewer(login=login)) + for login, state in ( + ("kerry-berri", "CHANGES_REQUESTED"), + ("someone-else", "APPROVED"), + ("kerry-berri", "APPROVED"), + ) + ) + assert guard.approved_by(reviews, "kerry-berri") is True + assert guard.approved_by(reviews[::-1], "kerry-berri") is False + + def test_no_review_from_the_approver_is_not_an_approval(self): + other: Final = guard.Review(state="APPROVED", user=guard.Reviewer(login="someone-else")) + assert guard.approved_by((other,), "kerry-berri") is False + assert guard.approved_by((), "kerry-berri") is False + + +class TestExitCode: + def test_a_pull_request_without_spend_log_lines_passes_without_reviews(self, tmp_path, monkeypatch, capsys): + monkeypatch.setattr(guard, "added_diff", lambda base, head: _diff("schema.prisma", " foo String", 1)) + reviews: Final = tmp_path / "r.json" + reviews.write_text("[]") + assert guard.main(["--base", "a", "--head", "b", "--approver", "kerry-berri", "--reviews", str(reviews)]) == 0 + assert "nothing to review" in capsys.readouterr().out + + def test_a_spend_log_change_fails_until_the_approver_approves(self, tmp_path, monkeypatch, capsys): + monkeypatch.setattr(guard, "added_diff", lambda base, head: _diff("schema.prisma", " x LiteLLM_SpendLogs", 7)) + reviews: Final = tmp_path / "r.json" + reviews.write_text('[{"user": {"login": "someone-else"}, "state": "APPROVED"}]') + assert guard.main(["--base", "a", "--head", "b", "--approver", "kerry-berri", "--reviews", str(reviews)]) == 1 + assert "schema.prisma: x LiteLLM_SpendLogs" in capsys.readouterr().out + reviews.write_text('[{"user": {"login": "kerry-berri"}, "state": "APPROVED"}]') + assert guard.main(["--base", "a", "--head", "b", "--approver", "kerry-berri", "--reviews", str(reviews)]) == 0 diff --git a/tests/unit/test_sync_together_ai_models.py b/tests/unit/test_sync_together_ai_models.py deleted file mode 100644 index b8a85bcfbdc..00000000000 --- a/tests/unit/test_sync_together_ai_models.py +++ /dev/null @@ -1,378 +0,0 @@ -import importlib.util -import json -from pathlib import Path -from types import MappingProxyType - -import pytest - -ROOT = Path(__file__).resolve().parents[2] -SCRIPT = ROOT / "scripts" / "sync_together_ai_models.py" -FIXTURES = Path(__file__).resolve().parent / "fixtures" / "together_ai_sync" - -_spec = importlib.util.spec_from_file_location("sync_together_ai_models", SCRIPT) -assert _spec is not None and _spec.loader is not None -sync = importlib.util.module_from_spec(_spec) -_spec.loader.exec_module(sync) - -RECORDED_CATALOG = sync.load_catalog(FIXTURES.joinpath("models_serverless.json").read_bytes()) -RECORDED_DOC = sync.parse_deprecations(FIXTURES.joinpath("deprecations.md").read_text()) - - -def _doc(removal_dates: dict[str, str], redirects: dict[str, str] | None = None) -> object: - return sync.DeprecationDoc( - removal_dates=MappingProxyType(removal_dates), - redirects=MappingProxyType(redirects or {}), - ) - - -def _chat_model(model_id: str, ctx: int = 4096, price: float = 1.0, cached: float | None = None) -> object: - return sync.CatalogModel( - id=model_id, - type="chat", - context_length=ctx, - pricing=sync.CatalogPricing(input=price, output=price, cached_input=cached), - ) - - -@pytest.mark.parametrize( - ("per_million", "expected"), - [ - (3, 3e-06), - (15, 1.5e-05), - (1.4, 1.4e-06), - (0.25999999999999995, 2.6e-07), - (0.060000000000000005, 6e-08), - (1.0399999999999998, 1.04e-06), - (0, 0.0), - ], -) -def test_per_token_normalizes_float_artifacts(per_million: float, expected: float) -> None: - assert sync.per_token(per_million) == expected - - -def test_parse_deprecations_recorded_fixture() -> None: - assert dict(RECORDED_DOC.redirects) == { - "mistralai/Mistral-7B-Instruct-v0.3": "mistralai/Ministral-3-14B-Instruct-2512", - "Kimi-K2": "Kimi-K2-0905", - "DeepSeek-V3": "DeepSeek-V3.1", - "DeepSeek-V3-0324": "DeepSeek-V3.1", - "DeepSeek-R1": "DeepSeek-R1-0528", - } - assert len(RECORDED_DOC.removal_dates) == 208 - assert RECORDED_DOC.removal_dates["google/gemma-3n-E4B-it"] == "2026-08-04" - - -def test_parse_deprecations_duplicate_rows_keep_most_recent_date() -> None: - assert RECORDED_DOC.removal_dates["Qwen/Qwen3-235B-A22B-Thinking-2507"] == "2026-04-16" - - -@pytest.mark.parametrize( - "markdown", - [ - "# Deprecations\n\nNothing here anymore.\n", - "\n## Active model redirects\n\n| A | B |\n| --- | --- |\n| `x` | `y` |\n\n## Something else\n", - "\n## Deprecation history\n\n### Inference\n\n| Date | Model | R |\n| --- | --- | --- |\n| 2026-01-01 | `m` | No |\n", - ], -) -def test_parse_deprecations_raises_when_a_table_parses_empty(markdown: str) -> None: - with pytest.raises(sync.SyncError): - sync.parse_deprecations(markdown) - - -def test_load_catalog_raises_on_shape_change() -> None: - with pytest.raises(sync.SyncError): - sync.load_catalog(b'[{"id": "x", "type": "chat"}]') - - -def test_load_catalog_raises_when_no_token_models_remain() -> None: - only_video = json.dumps([{"id": "v", "type": "video", "pricing": {"input": 0, "output": 0}}]).encode() - with pytest.raises(sync.SyncError): - sync.load_catalog(only_video) - - -def test_recorded_catalog_counts() -> None: - assert len(RECORDED_CATALOG) == 102 - assert sum(1 for model in RECORDED_CATALOG if model.type in sync.TYPE_TO_MODE) == 26 - assert sum(1 for model in RECORDED_CATALOG if model.pricing.cached_input) == 13 - - -def test_added_chat_model_matches_reviewed_registry_shape() -> None: - outcome = sync.compute_sync({}, RECORDED_CATALOG, RECORDED_DOC) - assert len(outcome.added) == 26 - assert not outcome.deprecated - assert outcome.cost_map["together_ai/moonshotai/Kimi-K3"] == { - "cache_read_input_token_cost": 3e-07, - "input_cost_per_token": 3e-06, - "litellm_provider": "together_ai", - "max_input_tokens": 1048576, - "max_tokens": 1048576, - "mode": "chat", - "output_cost_per_token": 1.5e-05, - "source": "https://docs.together.ai/docs/serverless-models", - "supports_function_calling": True, - "supports_parallel_function_calling": True, - "supports_prompt_caching": True, - "supports_reasoning": True, - "supports_response_schema": True, - "supports_tool_choice": True, - "supports_vision": True, - } - - -def test_added_embedding_model_has_no_output_token_cap() -> None: - outcome = sync.compute_sync({}, RECORDED_CATALOG, RECORDED_DOC) - assert outcome.cost_map["together_ai/intfloat/multilingual-e5-large-instruct"] == { - "input_cost_per_token": 2e-08, - "litellm_provider": "together_ai", - "max_input_tokens": 514, - "max_tokens": 514, - "mode": "embedding", - "output_cost_per_token": 2e-08, - "output_vector_size": 1024, - "source": "https://docs.together.ai/docs/serverless-models", - } - - -def test_moderation_type_maps_to_chat_mode() -> None: - outcome = sync.compute_sync({}, RECORDED_CATALOG, RECORDED_DOC) - guard = outcome.cost_map["together_ai/meta-llama/Llama-Guard-4-12B"] - assert guard["mode"] == "chat" - assert "max_output_tokens" not in guard - - -def test_output_ceiling_comes_from_the_rule_never_from_context_length() -> None: - glm = next(model for model in RECORDED_CATALOG if model.id == "zai-org/GLM-5.2") - fresh = sync.compute_sync({}, [_chat_model("acme/unreviewed", ctx=1048576), glm], _doc({"x": "2026-01-01"})) - unreviewed = fresh.cost_map["together_ai/acme/unreviewed"] - assert "max_output_tokens" not in unreviewed - assert (unreviewed["max_input_tokens"], unreviewed["max_tokens"]) == (1048576, 1048576) - reviewed = fresh.cost_map["together_ai/zai-org/GLM-5.2"] - assert (reviewed["max_input_tokens"], reviewed["max_output_tokens"], reviewed["max_tokens"]) == ( - 1048575, - 128000, - 128000, - ) - inflated = { - "together_ai/zai-org/GLM-5.2": { - "input_cost_per_token": 1.4e-06, - "litellm_provider": "together_ai", - "max_input_tokens": 1048575, - "max_output_tokens": 1048575, - "max_tokens": 1048575, - "mode": "chat", - "output_cost_per_token": 4.4e-06, - } - } - corrected = sync.compute_sync(inflated, [glm], _doc({"x": "2026-01-01"})) - assert corrected.cost_map["together_ai/zai-org/GLM-5.2"]["max_output_tokens"] == 128000 - assert any("max_output_tokens: 1048575 -> 128000" in line for line in corrected.updated) - - -def test_docs_removed_but_live_model_stays_live_with_warning() -> None: - outcome = sync.compute_sync({}, RECORDED_CATALOG, RECORDED_DOC) - gemma = outcome.cost_map["together_ai/google/gemma-3n-E4B-it"] - assert "deprecation_date" not in gemma - assert any("gemma-3n-E4B-it" in warning and "2026-08-04" in warning for warning in outcome.warnings) - - -def test_price_change_updates_api_fields_and_keeps_curated_ones() -> None: - registry = { - "together_ai/acme/chat-1": { - "input_cost_per_token": 9e-07, - "litellm_provider": "together_ai", - "max_input_tokens": 4096, - "max_output_tokens": 2048, - "max_tokens": 2048, - "mode": "chat", - "output_cost_per_token": 9e-07, - "supports_audio_input": True, - } - } - outcome = sync.compute_sync(registry, [_chat_model("acme/chat-1", ctx=8192, price=2.0)], _doc({"x": "2026-01-01"})) - entry = outcome.cost_map["together_ai/acme/chat-1"] - assert entry["input_cost_per_token"] == 2e-06 - assert entry["max_input_tokens"] == 8192 - assert entry["max_output_tokens"] == 2048 - assert entry["supports_audio_input"] is True - assert len(outcome.updated) == 1 - assert "input_cost_per_token" in outcome.updated[0] - - -def test_cached_input_appearing_and_disappearing() -> None: - registry = { - "together_ai/acme/chat-1": { - "cache_read_input_token_cost": 1e-07, - "input_cost_per_token": 1e-06, - "litellm_provider": "together_ai", - "max_input_tokens": 4096, - "mode": "chat", - "output_cost_per_token": 1e-06, - "supports_prompt_caching": True, - }, - "together_ai/acme/chat-2": { - "input_cost_per_token": 1e-06, - "litellm_provider": "together_ai", - "max_input_tokens": 4096, - "mode": "chat", - "output_cost_per_token": 1e-06, - }, - } - catalog = [_chat_model("acme/chat-1"), _chat_model("acme/chat-2", cached=0.25999999999999995)] - outcome = sync.compute_sync(registry, catalog, _doc({"x": "2026-01-01"})) - assert "cache_read_input_token_cost" not in outcome.cost_map["together_ai/acme/chat-1"] - assert "supports_prompt_caching" not in outcome.cost_map["together_ai/acme/chat-1"] - assert outcome.cost_map["together_ai/acme/chat-2"]["cache_read_input_token_cost"] == 2.6e-07 - assert outcome.cost_map["together_ai/acme/chat-2"]["supports_prompt_caching"] is True - - -def test_capability_rule_backfills_existing_entry() -> None: - registry = { - "together_ai/moonshotai/Kimi-K3": { - "input_cost_per_token": 3e-06, - "litellm_provider": "together_ai", - "max_input_tokens": 1048576, - "mode": "chat", - "output_cost_per_token": 1.5e-05, - } - } - kimi = next(model for model in RECORDED_CATALOG if model.id == "moonshotai/Kimi-K3") - outcome = sync.compute_sync(registry, [kimi], _doc({"x": "2026-01-01"})) - assert outcome.cost_map["together_ai/moonshotai/Kimi-K3"]["supports_reasoning"] is True - assert any("supports_reasoning" in line for line in outcome.updated) - - -def test_disappeared_model_gets_docs_date_and_is_never_deleted() -> None: - registry = { - "together_ai/acme/gone": { - "input_cost_per_token": 1e-06, - "litellm_provider": "together_ai", - "mode": "chat", - "output_cost_per_token": 1e-06, - } - } - outcome = sync.compute_sync(registry, [_chat_model("acme/alive")], _doc({"acme/gone": "2026-07-01"})) - assert outcome.cost_map["together_ai/acme/gone"]["deprecation_date"] == "2026-07-01" - assert outcome.deprecated == ("together_ai/acme/gone: deprecation_date",) - - -def test_disappeared_model_without_docs_date_warns_instead() -> None: - registry = { - "together_ai/acme/gone": { - "input_cost_per_token": 1e-06, - "litellm_provider": "together_ai", - "mode": "chat", - "output_cost_per_token": 1e-06, - } - } - outcome = sync.compute_sync(registry, [_chat_model("acme/alive")], _doc({"other": "2026-07-01"})) - assert "deprecation_date" not in outcome.cost_map["together_ai/acme/gone"] - assert not outcome.deprecated - assert any("acme/gone" in warning and "human" in warning for warning in outcome.warnings) - - -def test_curated_deprecation_date_is_never_overwritten() -> None: - registry = { - "together_ai/acme/gone": { - "deprecation_date": "2026-06-15", - "input_cost_per_token": 1e-06, - "litellm_provider": "together_ai", - "mode": "chat", - "output_cost_per_token": 1e-06, - } - } - outcome = sync.compute_sync(registry, [_chat_model("acme/alive")], _doc({"acme/gone": "2026-07-01"})) - assert outcome.cost_map["together_ai/acme/gone"]["deprecation_date"] == "2026-06-15" - assert any("2026-06-15" in warning and "2026-07-01" in warning for warning in outcome.warnings) - - -def test_redirect_chain_resolves_to_final_live_model() -> None: - doc = _doc({"acme/a": "2026-01-01"}, redirects={"acme/a": "acme/b", "acme/b": "acme/c"}) - live = frozenset({"acme/c"}) - assert sync.resolve_successor("acme/a", doc, live) == "acme/c" - - -def test_redirect_dead_end_yields_no_successor() -> None: - doc = _doc({"acme/a": "2026-01-01"}, redirects={"acme/a": "acme/b"}) - assert sync.resolve_successor("acme/a", doc, frozenset({"acme/other"})) is None - - -def test_redirect_short_names_resolve_by_unique_suffix() -> None: - doc = _doc({"moonshotai/Kimi-K2": "2026-01-01"}, redirects={"Kimi-K2": "Kimi-K2-0905"}) - live = frozenset({"moonshotai/Kimi-K2-0905"}) - assert sync.resolve_successor("moonshotai/Kimi-K2", doc, live) == "moonshotai/Kimi-K2-0905" - - -def test_successor_written_only_when_not_curated() -> None: - registry = { - "together_ai/acme/a": { - "input_cost_per_token": 1e-06, - "litellm_provider": "together_ai", - "mode": "chat", - "output_cost_per_token": 1e-06, - }, - "together_ai/acme/b": { - "input_cost_per_token": 1e-06, - "litellm_provider": "together_ai", - "metadata": {"successor": "together_ai/acme/curated"}, - "mode": "chat", - "output_cost_per_token": 1e-06, - }, - } - doc = _doc({"acme/a": "2026-01-01", "acme/b": "2026-01-01"}, redirects={"acme/a": "acme/c", "acme/b": "acme/c"}) - outcome = sync.compute_sync(registry, [_chat_model("acme/c")], doc) - assert outcome.cost_map["together_ai/acme/a"]["metadata"] == {"successor": "together_ai/acme/c"} - assert outcome.cost_map["together_ai/acme/b"]["metadata"] == {"successor": "together_ai/acme/curated"} - assert any("acme/curated" in warning for warning in outcome.warnings) - - -def test_reappearance_clears_deprecation_date() -> None: - registry = { - "together_ai/acme/back": { - "deprecation_date": "2026-05-01", - "input_cost_per_token": 1e-06, - "litellm_provider": "together_ai", - "max_input_tokens": 4096, - "mode": "chat", - "output_cost_per_token": 1e-06, - } - } - outcome = sync.compute_sync(registry, [_chat_model("acme/back")], _doc({"x": "2026-01-01"})) - assert "deprecation_date" not in outcome.cost_map["together_ai/acme/back"] - assert outcome.reappeared == ("together_ai/acme/back",) - - -def test_new_chat_model_without_rule_is_flagged() -> None: - outcome = sync.compute_sync({}, [_chat_model("acme/unreviewed")], _doc({"x": "2026-01-01"})) - assert any("acme/unreviewed" in warning and "capability rule" in warning for warning in outcome.warnings) - - -def test_new_keys_land_at_the_end_of_the_provider_block() -> None: - registry = { - "aaa": {"mode": "chat"}, - "together_ai/acme/old": { - "input_cost_per_token": 1e-06, - "litellm_provider": "together_ai", - "mode": "chat", - "output_cost_per_token": 1e-06, - }, - "zzz": {"mode": "chat"}, - } - outcome = sync.compute_sync(registry, [_chat_model("acme/old"), _chat_model("acme/new")], _doc({"x": "2026-01-01"})) - assert list(outcome.cost_map) == ["aaa", "together_ai/acme/old", "together_ai/acme/new", "zzz"] - - -def test_sync_is_idempotent_over_the_repo_cost_map() -> None: - cost_map = json.loads((ROOT / "model_prices_and_context_window.json").read_text()) - first = sync.compute_sync(cost_map, RECORDED_CATALOG, RECORDED_DOC) - second = sync.compute_sync(first.cost_map, RECORDED_CATALOG, RECORDED_DOC) - assert not second.has_changes - assert second.cost_map == first.cost_map - - -def test_pr_body_lists_every_section_and_the_skipped_types() -> None: - outcome = sync.compute_sync({}, RECORDED_CATALOG, RECORDED_DOC) - body = sync.render_pr_body(outcome) - assert "### Added (26)" in body - assert "### Warnings needing a human call" in body - assert "image (29)" in body - assert "video (38)" in body diff --git a/tests/unit/test_together_ai_model_metadata.py b/tests/unit/test_together_ai_model_metadata.py index dccba3d66f9..3616c6216ca 100644 --- a/tests/unit/test_together_ai_model_metadata.py +++ b/tests/unit/test_together_ai_model_metadata.py @@ -75,18 +75,6 @@ def cost_map() -> CostMap: return COST_MAP_ADAPTER.validate_python(json.load(f)) -def test_together_chat_entries_never_carry_context_length_as_output_ceiling(cost_map: CostMap): - inflated = sorted( - model - for model, info in cost_map.items() - if info.get("litellm_provider") == "together_ai" - and info.get("mode") == "chat" - and "max_output_tokens" in info - and info["max_output_tokens"] == info.get("max_input_tokens") - ) - assert inflated == [] - - def _successor(info: dict[str, object]) -> str | None: metadata = info.get("metadata") if not isinstance(metadata, dict): @@ -95,8 +83,6 @@ def _successor(info: dict[str, object]) -> str | None: return successor if isinstance(successor, str) else None - - def test_together_backup_cost_map_in_sync(cost_map: CostMap): with open(REPO_ROOT / "litellm" / "model_prices_and_context_window_backup.json") as f: backup = COST_MAP_ADAPTER.validate_python(json.load(f)) diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index ad069aa987b..38287b25169 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -21,7 +21,7 @@ from unittest.mock import AsyncMock, MagicMock, Mock, patch import httpx import pytest import respx -from jsonschema import validate +from jsonschema import Draft7Validator, validate import litellm from litellm.exceptions import MidStreamFallbackError @@ -576,7 +576,7 @@ def test_all_model_configs(): from litellm.llms.vertex_ai.vertex_ai_partner_models.ai21.transformation import ( VertexAIAi21Config, ) - from litellm.llms.vertex_ai.vertex_ai_partner_models.llama3.transformation import ( + from litellm.llms.vertex_ai.vertex_ai_partner_models.llama.transformation import ( VertexAILlama3Config, ) @@ -923,6 +923,457 @@ def validate_model_cost_values(model_data, exceptions=None): return len(violations) == 0, violations +_COST_MAP_ROW_SCHEMA: Final = { + "type": "object", + "additionalProperties": { + "type": "object", + "properties": { + "supports_computer_use": {"type": "boolean"}, + "cache_creation_input_audio_token_cost": {"type": "number"}, + "cache_creation_input_token_cost": {"type": "number"}, + "cache_creation_input_token_cost_above_1hr": {"type": "number"}, + "cache_creation_input_token_cost_above_12hr": {"type": "number"}, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens": { + "type": "number" + }, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_flex": { + "type": "number" + }, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_priority": { + "type": "number" + }, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches": { + "type": "number" + }, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_ultrafast": { + "type": "number" + }, + "cache_creation_input_token_cost_above_12hr_flex": {"type": "number"}, + "cache_creation_input_token_cost_above_12hr_priority": {"type": "number"}, + "cache_creation_input_token_cost_above_12hr_batches": {"type": "number"}, + "cache_creation_input_token_cost_above_12hr_ultrafast": {"type": "number"}, + "cache_creation_input_token_cost_above_32k_tokens": {"type": "number"}, + "cache_creation_input_token_cost_above_100k_tokens": {"type": "number"}, + "cache_creation_input_token_cost_above_100k_tokens_batches": {"type": "number"}, + "cache_creation_input_token_cost_above_128k_tokens": {"type": "number"}, + "cache_creation_input_token_cost_above_200k_tokens": {"type": "number"}, + "cache_creation_input_token_cost_above_256k_tokens": {"type": "number"}, + "cache_creation_input_token_cost_above_272k_tokens": {"type": "number"}, + "cache_creation_input_token_cost_above_272k_tokens_flex": {"type": "number"}, + "cache_creation_input_token_cost_above_272k_tokens_ultrafast": {"type": "number"}, + "cache_creation_input_token_cost_above_272k_tokens_priority": {"type": "number"}, + "cache_creation_input_token_cost_above_200k_tokens_batches": {"type": "number"}, + "cache_creation_input_token_cost_above_272k_tokens_batches": {"type": "number"}, + "cache_creation_input_token_cost_batches": {"type": "number"}, + "cache_creation_input_token_cost_decisions": {"type": "number"}, + "cache_creation_input_token_cost_above_272k_tokens_decisions": {"type": "number"}, + "cache_read_input_token_cost_decisions": {"type": "number"}, + "cache_read_input_token_cost_above_272k_tokens_decisions": {"type": "number"}, + "input_cost_per_token_decisions": {"type": "number"}, + "input_cost_per_token_above_272k_tokens_decisions": {"type": "number"}, + "output_cost_per_token_decisions": {"type": "number"}, + "output_cost_per_token_above_272k_tokens_decisions": {"type": "number"}, + "cache_creation_input_token_cost_flex": {"type": "number"}, + "cache_creation_input_token_cost_priority": {"type": "number"}, + "cache_creation_input_token_cost_ultrafast": {"type": "number"}, + "cache_read_input_token_cost": {"type": "number"}, + "explicit_cache_read_input_token_cost": {"type": "number"}, + "cache_read_input_token_cost_above_32k_tokens": {"type": "number"}, + "cache_read_input_token_cost_above_100k_tokens": {"type": "number"}, + "cache_read_input_token_cost_above_100k_tokens_batches": {"type": "number"}, + "cache_read_input_token_cost_above_128k_tokens": {"type": "number"}, + "cache_read_input_token_cost_above_200k_tokens": {"type": "number"}, + "cache_read_input_token_cost_above_200k_tokens_batches": {"type": "number"}, + "cache_read_input_token_cost_above_256k_tokens": {"type": "number"}, + "cache_read_input_token_cost_above_272k_tokens": {"type": "number"}, + "cache_read_input_token_cost_above_272k_tokens_flex": {"type": "number"}, + "cache_read_input_token_cost_above_272k_tokens_ultrafast": {"type": "number"}, + "cache_read_input_token_cost_above_512k_tokens": {"type": "number"}, + "input_cost_per_token_above_272k_tokens_ultrafast": {"type": "number"}, + "cache_read_input_token_cost_batches": {"type": "number"}, + "cache_read_input_token_cost_above_272k_tokens_batches": {"type": "number"}, + "cache_creation_input_token_cost_above_1hr_above_100k_tokens": {"type": "number"}, + "cache_creation_input_token_cost_above_1hr_above_200k_tokens": {"type": "number"}, + "cache_read_input_audio_token_cost": {"type": "number"}, + "cache_read_input_audio_token_cost_batches": {"type": "number"}, + "cache_read_input_audio_token_cost_flex": {"type": "number"}, + "cache_read_input_audio_token_cost_priority": {"type": "number"}, + "cache_read_input_image_token_cost": {"type": "number"}, + "audio_transcription_config": {"type": "string"}, + "deprecation_date": {"type": "string"}, + "input_cost_per_audio_per_second": {"type": "number"}, + "input_cost_per_audio_per_second_above_128k_tokens": {"type": "number"}, + "google_maps_grounding_cost_per_query": {"type": "number"}, + "input_cost_per_audio_token": {"type": "number"}, + "input_cost_per_audio_token_flex": {"type": "number"}, + "input_cost_per_image_token": {"type": "number"}, + "input_cost_per_character": {"type": "number"}, + "input_cost_per_character_above_128k_tokens": {"type": "number"}, + "input_cost_per_image": {"type": "number"}, + "input_cost_per_image_above_128k_tokens": {"type": "number"}, + "input_cost_per_video_token": {"type": "number"}, + "input_cost_per_token_above_32k_tokens": {"type": "number"}, + "input_cost_per_token_above_100k_tokens": {"type": "number"}, + "input_cost_per_token_above_100k_tokens_batches": {"type": "number"}, + "input_cost_per_token_above_200k_tokens": {"type": "number"}, + "input_cost_per_token_above_200k_tokens_batches": {"type": "number"}, + "input_cost_per_token_above_256k_tokens": {"type": "number"}, + "input_cost_per_token_above_272k_tokens": {"type": "number"}, + "input_cost_per_token_above_512k_tokens": {"type": "number"}, + "cache_read_input_token_cost_flex": {"type": "number"}, + "cache_read_input_token_cost_priority": {"type": "number"}, + "cache_read_input_token_cost_balanced": {"type": "number"}, + "cache_read_input_token_cost_ultrafast": {"type": "number"}, + "cache_read_input_token_cost_above_200k_tokens_priority": {"type": "number"}, + "cache_read_input_token_cost_above_272k_tokens_priority": {"type": "number"}, + "input_cost_per_token_flex": {"type": "number"}, + "input_cost_per_token_priority": {"type": "number"}, + "input_cost_per_token_balanced": {"type": "number"}, + "input_cost_per_token_ultrafast": {"type": "number"}, + "input_cost_per_token_above_200k_tokens_priority": {"type": "number"}, + "input_cost_per_token_above_272k_tokens_priority": {"type": "number"}, + "input_cost_per_token_above_272k_tokens_batches": {"type": "number"}, + "input_cost_per_token_above_272k_tokens_flex": {"type": "number"}, + "input_cost_per_audio_token_priority": {"type": "number"}, + "output_cost_per_token_flex": {"type": "number"}, + "output_cost_per_token_priority": {"type": "number"}, + "output_cost_per_token_balanced": {"type": "number"}, + "output_cost_per_token_ultrafast": {"type": "number"}, + "output_cost_per_token_above_200k_tokens_priority": {"type": "number"}, + "output_cost_per_token_above_272k_tokens_priority": {"type": "number"}, + "output_cost_per_token_above_272k_tokens_ultrafast": {"type": "number"}, + "output_cost_per_token_above_272k_tokens_batches": {"type": "number"}, + "output_cost_per_token_above_272k_tokens_flex": {"type": "number"}, + "regional_endpoint_uplift_multiplier": {"type": "number"}, + "regional_processing_uplift_multiplier_eu": {"type": "number"}, + "regional_processing_uplift_multiplier_us": {"type": "number"}, + "input_cost_per_pixel": {"type": "number"}, + "input_cost_per_query": {"type": "number"}, + "input_cost_per_request": {"type": "number"}, + "cost_per_second": {"type": "number"}, + "input_cost_per_second": {"type": "number"}, + "input_cost_per_text_message": {"type": "number"}, + "input_cost_per_token": {"type": "number"}, + "input_cost_per_token_above_128k_tokens": {"type": "number"}, + "input_cost_per_audio_token_batches": {"type": "number"}, + "input_cost_per_image_token_batches": {"type": "number"}, + "input_cost_per_token_batches": {"type": "number"}, + "input_cost_per_video_token_batches": {"type": "number"}, + "input_cost_per_token_cache_hit": {"type": "number"}, + "input_cost_per_video_per_second": {"type": "number"}, + "input_cost_per_video_per_second_above_8s_interval": {"type": "number"}, + "input_cost_per_video_per_second_above_15s_interval": {"type": "number"}, + "input_cost_per_video_per_second_above_128k_tokens": {"type": "number"}, + "input_dbu_cost_per_token": {"type": "number"}, + "annotation_cost_per_page": {"type": "number"}, + "annotation_cost_per_page_batches": {"type": "number"}, + "ocr_cost_per_page": {"type": "number"}, + "ocr_cost_per_page_batches": {"type": "number"}, + "ocr_cost_per_credit": {"type": "number"}, + "code_interpreter_cost_per_session": {"type": "number"}, + "inference_geo": {"type": "string"}, + "litellm_provider": {"type": "string"}, + "max_input_tokens": {"type": "number"}, + "max_output_tokens": {"type": "number"}, + "max_tokens": {"type": "number"}, + "metadata": {"type": "object"}, + "provider_specific_entry": {"type": "object"}, + "mode": { + "type": "string", + "enum": [ + "audio_speech", + "audio_transcription", + "chat", + "completion", + "container", + "decisions", + "image_edit", + "embedding", + "evaluation", + "extraction", + "guardrail", + "image_generation", + "video_generation", + "moderation", + "rerank", + "realtime", + "responses", + "ocr", + "search", + "vector_store", + ], + }, + "output_cost_per_audio_token": {"type": "number"}, + "output_cost_per_character": {"type": "number"}, + "output_cost_per_character_above_128k_tokens": {"type": "number"}, + "output_cost_per_image": {"type": "number"}, + "output_cost_per_image_512": {"type": "number"}, + "output_cost_per_image_1024": {"type": "number"}, + "output_cost_per_image_1536": {"type": "number"}, + "output_cost_per_image_0.5K": {"type": "number"}, + "output_cost_per_image_1K": {"type": "number"}, + "output_cost_per_image_2K": {"type": "number"}, + "output_cost_per_image_4K": {"type": "number"}, + "output_cost_per_image_token": {"type": "number"}, + "output_cost_per_image_token_batches": {"type": "number"}, + "output_cost_per_video_token": {"type": "number"}, + "output_cost_per_pixel": {"type": "number"}, + "output_cost_per_second": {"type": "number"}, + "output_cost_per_second_480p": {"type": "number"}, + "output_cost_per_second_720p": {"type": "number"}, + "output_cost_per_second_768p": {"type": "number"}, + "output_cost_per_second_2k": {"type": "number"}, + "output_cost_per_second_1080p": {"type": "number"}, + "output_cost_per_second_4k": {"type": "number"}, + "output_cost_per_token": {"type": "number"}, + "output_cost_per_token_above_32k_tokens": {"type": "number"}, + "output_cost_per_token_above_100k_tokens": {"type": "number"}, + "output_cost_per_token_above_100k_tokens_batches": {"type": "number"}, + "output_cost_per_token_above_128k_tokens": {"type": "number"}, + "output_cost_per_token_above_200k_tokens": {"type": "number"}, + "output_cost_per_token_above_200k_tokens_batches": {"type": "number"}, + "output_cost_per_token_above_256k_tokens": {"type": "number"}, + "output_cost_per_token_above_272k_tokens": {"type": "number"}, + "output_cost_per_token_above_512k_tokens": {"type": "number"}, + "output_cost_per_token_batches": {"type": "number"}, + "output_cost_per_reasoning_token": {"type": "number"}, + "output_cost_per_video_per_second": {"type": "number"}, + "output_db_cost_per_token": {"type": "number"}, + "output_dbu_cost_per_token": {"type": "number"}, + "output_vector_size": {"type": "number"}, + "rpd": {"type": "number"}, + "rpm": {"type": "number"}, + "source": {"type": "string"}, + "comment": {"type": "string"}, + "supports_assistant_prefill": {"type": "boolean"}, + "supports_anthropic_compaction": {"type": "boolean"}, + "supports_audio_input": {"type": "boolean"}, + "supports_audio_output": {"type": "boolean"}, + "gemini_native_audio": {"type": "boolean"}, + "gemini_audio_only_live": {"type": "boolean"}, + "supports_embedding_image_input": {"type": "boolean"}, + "supports_forced_tool_use": {"type": "boolean"}, + "supports_function_calling": {"type": "boolean"}, + "supports_image_input": {"type": "boolean"}, + "supports_nova_canvas_image_edit": {"type": "boolean"}, + "supports_parallel_function_calling": {"type": "boolean"}, + "supports_parallel_tool_use_config": {"type": "boolean"}, + "supports_pdf_input": {"type": "boolean"}, + "prompt_cache_min_tokens": {"type": "number"}, + "supports_prompt_cache_breakpoint": {"type": "boolean"}, + "supports_thinking_cache_preservation": {"type": "boolean"}, + "supports_prompt_caching": {"type": "boolean"}, + "supports_response_schema": {"type": "boolean"}, + "supports_system_messages": {"type": "boolean"}, + "supports_tool_choice": {"type": "boolean"}, + "supports_tool_search": {"type": "boolean"}, + "supports_video_input": {"type": "boolean"}, + "supports_box_questions": {"type": "boolean"}, + "supports_vision": {"type": "boolean"}, + "supports_web_search": {"type": "boolean"}, + "token_count_framing": {"type": "integer"}, + "token_count_model": { + "type": "object", + "properties": {"model": {"type": "string"}, "region": {"type": "string"}}, + "required": ["model"], + }, + "token_count_tokenizer": {"type": "string", "enum": ["kimi_k3"]}, + "supports_bedrock_runtime_chat_completions_tools_with_reasoning": {"type": "boolean"}, + "supports_bedrock_runtime_chat_completions_response_format": {"type": "boolean"}, + "supports_bedrock_runtime_chat_completions_inline_reasoning": {"type": "boolean"}, + "supports_bedrock_converse_tool_result_images": {"type": "boolean"}, + "supports_url_context": {"type": "boolean"}, + "supports_multimodal": {"type": "boolean"}, + "uses_embed_content": {"type": "boolean"}, + "supports_reasoning": {"type": "boolean"}, + "supports_minimal_reasoning_effort": {"type": "boolean"}, + "supports_low_reasoning_effort": {"type": "boolean"}, + "supports_none_reasoning_effort": {"type": "boolean"}, + "supports_xhigh_reasoning_effort": {"type": "boolean"}, + "supports_max_reasoning_effort": {"type": "boolean"}, + "reasoning_effort_levels": { + "type": "array", + "items": {"type": "string", "enum": ["none", "minimal", "low", "medium", "high", "xhigh", "max"]}, + }, + "default_reasoning_effort": { + "type": "string", + "enum": ["none", "minimal", "low", "medium", "high", "xhigh"], + }, + "supports_adaptive_thinking": {"type": "boolean"}, + "supports_anthropic_thinking_payload": {"type": "boolean"}, + "supports_legacy_thinking": {"type": "boolean"}, + "thinking_always_on": {"type": "boolean"}, + "supports_mid_conversation_system": {"type": "boolean"}, + "supports_sampling_params": {"type": "boolean"}, + "supports_output_config": {"type": "boolean"}, + "supports_speed": {"type": "boolean"}, + "supports_fast_mode": {"type": "boolean"}, + "supported_audio_formats": { + "type": "array", + "items": { + "type": "string", + "enum": ["mp3", "wav"], + }, + }, + "vertex_ai_audio_api": { + "type": "string", + "enum": ["lyria_predict", "lyria_interactions"], + }, + "bedrock_output_config_effort_ceiling": { + "type": "string", + "enum": ["low", "medium", "high", "max", "xhigh"], + }, + "bedrock_converse_supports_strict_tools": {"type": "boolean"}, + "supports_regex_lookaround": {"type": "boolean"}, + "tpm": {"type": "number"}, + "supported_endpoints": { + "type": "array", + "items": { + "type": "string", + "enum": [ + "/v1/responses", + "/v1/embeddings", + "/v1/chat/completions", + "/v1/completions", + "/v1/messages", + "/v1/images/generations", + "/v1/realtime", + "/v1/realtime/transcription_sessions", + "/v1/images/variations", + "/v1/images/edits", + "/v1/batch", + "/v1beta/interactions", + "/v1beta/models", + "/v1/audio/transcriptions", + "/v1/audio/speech", + "/v1/ocr", + "/v1/videos", + "/vertex_ai/live", + "/v1/listen", + "/v1/systemone", + "/v1/decisions", + "/v1beta/interactions", + ], + }, + }, + "supported_regions": { + "type": "array", + "items": { + "type": "string", + }, + }, + "guardrail_cost_per_unit": { + "type": "object", + "additionalProperties": {"type": "number"}, + }, + "search_context_cost_per_query": { + "type": "object", + "properties": { + "search_context_size_low": {"type": "number"}, + "search_context_size_medium": {"type": "number"}, + "search_context_size_high": {"type": "number"}, + }, + "additionalProperties": False, + }, + "web_search_billing_unit": { + "type": "string", + "enum": ["per_prompt", "per_query"], + }, + "search_free_requests": { + "type": "object", + "properties": { + "count": {"type": "integer", "minimum": 1}, + "period": {"type": "string", "enum": ["day", "month"]}, + "shared_group": {"type": "string"}, + }, + "required": ["count", "period", "shared_group"], + "additionalProperties": False, + }, + "citation_cost_per_token": {"type": "number"}, + "supported_modalities": { + "type": "array", + "items": { + "type": "string", + "enum": ["text", "audio", "image", "video"], + }, + }, + "supported_output_modalities": { + "type": "array", + "items": { + "type": "string", + "enum": ["text", "image", "audio", "code", "video"], + }, + }, + "supports_native_streaming": {"type": "boolean"}, + "supports_image_size": {"type": "boolean"}, + "supports_native_structured_output": {"type": "boolean"}, + "supports_bedrock_native_structured_output": {"type": "boolean"}, + "use_openai_responses_path": {"type": "boolean"}, + "off_peak_pricing": { + "type": "object", + "properties": { + "hours_utc": { + "oneOf": [{"type": "string"}, {"type": "array", "items": {"type": "string"}}], + }, + "windows": { + "type": "array", + "items": { + "type": "object", + "properties": { + "hours_utc": { + "oneOf": [{"type": "string"}, {"type": "array", "items": {"type": "string"}}], + }, + "weekdays": { + "type": "array", + "items": {"oneOf": [{"type": "integer"}, {"type": "string"}]}, + }, + }, + "required": ["hours_utc"], + "additionalProperties": False, + }, + }, + "weekday_timezone": {"type": "string"}, + "input_cost_per_token": {"type": "number"}, + "output_cost_per_token": {"type": "number"}, + "output_cost_per_reasoning_token": {"type": "number"}, + "cache_read_input_token_cost": {"type": "number"}, + "cache_creation_input_token_cost": {"type": "number"}, + }, + "additionalProperties": False, + }, + "tiered_pricing": { + "type": "array", + "items": { + "type": "object", + "properties": { + "range": { + "type": "array", + "items": {"type": "number"}, + "minItems": 2, + "maxItems": 2, + }, + "input_cost_per_token": {"type": "number"}, + "output_cost_per_token": {"type": "number"}, + "cache_read_input_token_cost": {"type": "number"}, + "cache_creation_input_token_cost": {"type": "number"}, + "output_cost_per_reasoning_token": {"type": "number"}, + "max_results_range": { + "type": "array", + "items": {"type": "number"}, + "minItems": 2, + "maxItems": 2, + }, + "input_cost_per_query": {"type": "number"}, + }, + "additionalProperties": False, + }, + }, + }, + "additionalProperties": False, + }, +} + + def test_aaamodel_prices_and_context_window_json_is_valid(): """ Validates the `model_prices_and_context_window.json` file. @@ -930,430 +1381,6 @@ def test_aaamodel_prices_and_context_window_json_is_valid(): If this test fails after you update the json, you need to update the schema or correct the change you made. """ - INTENDED_SCHEMA = { - "type": "object", - "additionalProperties": { - "type": "object", - "properties": { - "supports_computer_use": {"type": "boolean"}, - "cache_creation_input_audio_token_cost": {"type": "number"}, - "cache_creation_input_token_cost": {"type": "number"}, - "cache_creation_input_token_cost_above_1hr": {"type": "number"}, - "cache_creation_input_token_cost_above_32k_tokens": {"type": "number"}, - "cache_creation_input_token_cost_above_100k_tokens": {"type": "number"}, - "cache_creation_input_token_cost_above_100k_tokens_batches": {"type": "number"}, - "cache_creation_input_token_cost_above_128k_tokens": {"type": "number"}, - "cache_creation_input_token_cost_above_200k_tokens": {"type": "number"}, - "cache_creation_input_token_cost_above_256k_tokens": {"type": "number"}, - "cache_creation_input_token_cost_above_272k_tokens": {"type": "number"}, - "cache_creation_input_token_cost_above_272k_tokens_flex": {"type": "number"}, - "cache_creation_input_token_cost_above_272k_tokens_ultrafast": {"type": "number"}, - "cache_creation_input_token_cost_above_272k_tokens_priority": {"type": "number"}, - "cache_creation_input_token_cost_above_200k_tokens_batches": {"type": "number"}, - "cache_creation_input_token_cost_above_272k_tokens_batches": {"type": "number"}, - "cache_creation_input_token_cost_batches": {"type": "number"}, - "cache_creation_input_token_cost_decisions": {"type": "number"}, - "cache_creation_input_token_cost_above_272k_tokens_decisions": {"type": "number"}, - "cache_read_input_token_cost_decisions": {"type": "number"}, - "cache_read_input_token_cost_above_272k_tokens_decisions": {"type": "number"}, - "input_cost_per_token_decisions": {"type": "number"}, - "input_cost_per_token_above_272k_tokens_decisions": {"type": "number"}, - "output_cost_per_token_decisions": {"type": "number"}, - "output_cost_per_token_above_272k_tokens_decisions": {"type": "number"}, - "cache_creation_input_token_cost_flex": {"type": "number"}, - "cache_creation_input_token_cost_priority": {"type": "number"}, - "cache_creation_input_token_cost_ultrafast": {"type": "number"}, - "cache_read_input_token_cost": {"type": "number"}, - "explicit_cache_read_input_token_cost": {"type": "number"}, - "cache_read_input_token_cost_above_32k_tokens": {"type": "number"}, - "cache_read_input_token_cost_above_100k_tokens": {"type": "number"}, - "cache_read_input_token_cost_above_100k_tokens_batches": {"type": "number"}, - "cache_read_input_token_cost_above_128k_tokens": {"type": "number"}, - "cache_read_input_token_cost_above_200k_tokens": {"type": "number"}, - "cache_read_input_token_cost_above_200k_tokens_batches": {"type": "number"}, - "cache_read_input_token_cost_above_256k_tokens": {"type": "number"}, - "cache_read_input_token_cost_above_272k_tokens": {"type": "number"}, - "cache_read_input_token_cost_above_272k_tokens_flex": {"type": "number"}, - "cache_read_input_token_cost_above_272k_tokens_ultrafast": {"type": "number"}, - "cache_read_input_token_cost_above_512k_tokens": {"type": "number"}, - "input_cost_per_token_above_272k_tokens_ultrafast": {"type": "number"}, - "cache_read_input_token_cost_batches": {"type": "number"}, - "cache_read_input_token_cost_above_272k_tokens_batches": {"type": "number"}, - "cache_creation_input_token_cost_above_1hr_above_100k_tokens": {"type": "number"}, - "cache_creation_input_token_cost_above_1hr_above_200k_tokens": {"type": "number"}, - "cache_read_input_audio_token_cost": {"type": "number"}, - "cache_read_input_image_token_cost": {"type": "number"}, - "audio_transcription_config": {"type": "string"}, - "deprecation_date": {"type": "string"}, - "input_cost_per_audio_per_second": {"type": "number"}, - "input_cost_per_audio_per_second_above_128k_tokens": {"type": "number"}, - "google_maps_grounding_cost_per_query": {"type": "number"}, - "input_cost_per_audio_token": {"type": "number"}, - "input_cost_per_image_token": {"type": "number"}, - "input_cost_per_character": {"type": "number"}, - "input_cost_per_character_above_128k_tokens": {"type": "number"}, - "input_cost_per_image": {"type": "number"}, - "input_cost_per_image_above_128k_tokens": {"type": "number"}, - "input_cost_per_video_token": {"type": "number"}, - "input_cost_per_token_above_32k_tokens": {"type": "number"}, - "input_cost_per_token_above_100k_tokens": {"type": "number"}, - "input_cost_per_token_above_100k_tokens_batches": {"type": "number"}, - "input_cost_per_token_above_200k_tokens": {"type": "number"}, - "input_cost_per_token_above_200k_tokens_batches": {"type": "number"}, - "input_cost_per_token_above_256k_tokens": {"type": "number"}, - "input_cost_per_token_above_272k_tokens": {"type": "number"}, - "input_cost_per_token_above_512k_tokens": {"type": "number"}, - "cache_read_input_token_cost_flex": {"type": "number"}, - "cache_read_input_token_cost_priority": {"type": "number"}, - "cache_read_input_token_cost_balanced": {"type": "number"}, - "cache_read_input_token_cost_ultrafast": {"type": "number"}, - "cache_read_input_token_cost_above_200k_tokens_priority": {"type": "number"}, - "cache_read_input_token_cost_above_272k_tokens_priority": {"type": "number"}, - "input_cost_per_token_flex": {"type": "number"}, - "input_cost_per_token_priority": {"type": "number"}, - "input_cost_per_token_balanced": {"type": "number"}, - "input_cost_per_token_ultrafast": {"type": "number"}, - "input_cost_per_token_above_200k_tokens_priority": {"type": "number"}, - "input_cost_per_token_above_272k_tokens_priority": {"type": "number"}, - "input_cost_per_token_above_272k_tokens_batches": {"type": "number"}, - "input_cost_per_token_above_272k_tokens_flex": {"type": "number"}, - "input_cost_per_audio_token_priority": {"type": "number"}, - "output_cost_per_token_flex": {"type": "number"}, - "output_cost_per_token_priority": {"type": "number"}, - "output_cost_per_token_balanced": {"type": "number"}, - "output_cost_per_token_ultrafast": {"type": "number"}, - "output_cost_per_token_above_200k_tokens_priority": {"type": "number"}, - "output_cost_per_token_above_272k_tokens_priority": {"type": "number"}, - "output_cost_per_token_above_272k_tokens_ultrafast": {"type": "number"}, - "output_cost_per_token_above_272k_tokens_batches": {"type": "number"}, - "output_cost_per_token_above_272k_tokens_flex": {"type": "number"}, - "regional_endpoint_uplift_multiplier": {"type": "number"}, - "regional_processing_uplift_multiplier_eu": {"type": "number"}, - "regional_processing_uplift_multiplier_us": {"type": "number"}, - "input_cost_per_pixel": {"type": "number"}, - "input_cost_per_query": {"type": "number"}, - "input_cost_per_request": {"type": "number"}, - "cost_per_second": {"type": "number"}, - "input_cost_per_second": {"type": "number"}, - "input_cost_per_text_message": {"type": "number"}, - "input_cost_per_token": {"type": "number"}, - "input_cost_per_token_above_128k_tokens": {"type": "number"}, - "input_cost_per_audio_token_batches": {"type": "number"}, - "input_cost_per_image_token_batches": {"type": "number"}, - "input_cost_per_token_batches": {"type": "number"}, - "input_cost_per_video_token_batches": {"type": "number"}, - "input_cost_per_token_cache_hit": {"type": "number"}, - "input_cost_per_video_per_second": {"type": "number"}, - "input_cost_per_video_per_second_above_8s_interval": {"type": "number"}, - "input_cost_per_video_per_second_above_15s_interval": {"type": "number"}, - "input_cost_per_video_per_second_above_128k_tokens": {"type": "number"}, - "input_dbu_cost_per_token": {"type": "number"}, - "annotation_cost_per_page": {"type": "number"}, - "annotation_cost_per_page_batches": {"type": "number"}, - "ocr_cost_per_page": {"type": "number"}, - "ocr_cost_per_page_batches": {"type": "number"}, - "ocr_cost_per_credit": {"type": "number"}, - "code_interpreter_cost_per_session": {"type": "number"}, - "inference_geo": {"type": "string"}, - "litellm_provider": {"type": "string"}, - "max_input_tokens": {"type": "number"}, - "max_output_tokens": {"type": "number"}, - "max_tokens": {"type": "number"}, - "metadata": {"type": "object"}, - "provider_specific_entry": {"type": "object"}, - "mode": { - "type": "string", - "enum": [ - "audio_speech", - "audio_transcription", - "chat", - "completion", - "container", - "image_edit", - "embedding", - "evaluation", - "extraction", - "guardrail", - "image_generation", - "video_generation", - "moderation", - "rerank", - "realtime", - "responses", - "ocr", - "search", - "vector_store", - ], - }, - "output_cost_per_audio_token": {"type": "number"}, - "output_cost_per_character": {"type": "number"}, - "output_cost_per_character_above_128k_tokens": {"type": "number"}, - "output_cost_per_image": {"type": "number"}, - "output_cost_per_image_512": {"type": "number"}, - "output_cost_per_image_1024": {"type": "number"}, - "output_cost_per_image_1536": {"type": "number"}, - "output_cost_per_image_0.5K": {"type": "number"}, - "output_cost_per_image_1K": {"type": "number"}, - "output_cost_per_image_2K": {"type": "number"}, - "output_cost_per_image_4K": {"type": "number"}, - "output_cost_per_image_token": {"type": "number"}, - "output_cost_per_image_token_batches": {"type": "number"}, - "output_cost_per_video_token": {"type": "number"}, - "output_cost_per_pixel": {"type": "number"}, - "output_cost_per_second": {"type": "number"}, - "output_cost_per_second_480p": {"type": "number"}, - "output_cost_per_second_720p": {"type": "number"}, - "output_cost_per_second_768p": {"type": "number"}, - "output_cost_per_second_2k": {"type": "number"}, - "output_cost_per_second_1080p": {"type": "number"}, - "output_cost_per_second_4k": {"type": "number"}, - "output_cost_per_token": {"type": "number"}, - "output_cost_per_token_above_32k_tokens": {"type": "number"}, - "output_cost_per_token_above_100k_tokens": {"type": "number"}, - "output_cost_per_token_above_100k_tokens_batches": {"type": "number"}, - "output_cost_per_token_above_128k_tokens": {"type": "number"}, - "output_cost_per_token_above_200k_tokens": {"type": "number"}, - "output_cost_per_token_above_200k_tokens_batches": {"type": "number"}, - "output_cost_per_token_above_256k_tokens": {"type": "number"}, - "output_cost_per_token_above_272k_tokens": {"type": "number"}, - "output_cost_per_token_above_512k_tokens": {"type": "number"}, - "output_cost_per_token_batches": {"type": "number"}, - "output_cost_per_reasoning_token": {"type": "number"}, - "output_cost_per_video_per_second": {"type": "number"}, - "output_db_cost_per_token": {"type": "number"}, - "output_dbu_cost_per_token": {"type": "number"}, - "output_vector_size": {"type": "number"}, - "rpd": {"type": "number"}, - "rpm": {"type": "number"}, - "source": {"type": "string"}, - "comment": {"type": "string"}, - "supports_assistant_prefill": {"type": "boolean"}, - "supports_anthropic_compaction": {"type": "boolean"}, - "supports_audio_input": {"type": "boolean"}, - "supports_audio_output": {"type": "boolean"}, - "gemini_native_audio": {"type": "boolean"}, - "gemini_audio_only_live": {"type": "boolean"}, - "supports_embedding_image_input": {"type": "boolean"}, - "supports_forced_tool_use": {"type": "boolean"}, - "supports_function_calling": {"type": "boolean"}, - "supports_image_input": {"type": "boolean"}, - "supports_nova_canvas_image_edit": {"type": "boolean"}, - "supports_parallel_function_calling": {"type": "boolean"}, - "supports_parallel_tool_use_config": {"type": "boolean"}, - "supports_pdf_input": {"type": "boolean"}, - "prompt_cache_min_tokens": {"type": "number"}, - "supports_prompt_cache_breakpoint": {"type": "boolean"}, - "supports_thinking_cache_preservation": {"type": "boolean"}, - "supports_prompt_caching": {"type": "boolean"}, - "supports_response_schema": {"type": "boolean"}, - "supports_system_messages": {"type": "boolean"}, - "supports_tool_choice": {"type": "boolean"}, - "supports_tool_search": {"type": "boolean"}, - "supports_video_input": {"type": "boolean"}, - "supports_box_questions": {"type": "boolean"}, - "supports_vision": {"type": "boolean"}, - "supports_web_search": {"type": "boolean"}, - "token_count_framing": {"type": "integer"}, - "token_count_model": { - "type": "object", - "properties": {"model": {"type": "string"}, "region": {"type": "string"}}, - "required": ["model"], - }, - "token_count_tokenizer": {"type": "string", "enum": ["kimi_k3"]}, - "supports_bedrock_runtime_chat_completions_tools_with_reasoning": {"type": "boolean"}, - "supports_bedrock_runtime_chat_completions_response_format": {"type": "boolean"}, - "supports_bedrock_runtime_chat_completions_inline_reasoning": {"type": "boolean"}, - "supports_bedrock_converse_tool_result_images": {"type": "boolean"}, - "supports_url_context": {"type": "boolean"}, - "supports_multimodal": {"type": "boolean"}, - "uses_embed_content": {"type": "boolean"}, - "supports_reasoning": {"type": "boolean"}, - "supports_minimal_reasoning_effort": {"type": "boolean"}, - "supports_low_reasoning_effort": {"type": "boolean"}, - "supports_none_reasoning_effort": {"type": "boolean"}, - "supports_xhigh_reasoning_effort": {"type": "boolean"}, - "supports_max_reasoning_effort": {"type": "boolean"}, - "reasoning_effort_levels": { - "type": "array", - "items": {"type": "string", "enum": ["none", "minimal", "low", "medium", "high", "xhigh", "max"]}, - }, - "default_reasoning_effort": { - "type": "string", - "enum": ["none", "minimal", "low", "medium", "high", "xhigh"], - }, - "supports_adaptive_thinking": {"type": "boolean"}, - "supports_anthropic_thinking_payload": {"type": "boolean"}, - "supports_legacy_thinking": {"type": "boolean"}, - "thinking_always_on": {"type": "boolean"}, - "supports_mid_conversation_system": {"type": "boolean"}, - "supports_sampling_params": {"type": "boolean"}, - "supports_output_config": {"type": "boolean"}, - "supports_speed": {"type": "boolean"}, - "supports_fast_mode": {"type": "boolean"}, - "supported_audio_formats": { - "type": "array", - "items": { - "type": "string", - "enum": ["mp3", "wav"], - }, - }, - "vertex_ai_audio_api": { - "type": "string", - "enum": ["lyria_predict", "lyria_interactions"], - }, - "bedrock_output_config_effort_ceiling": { - "type": "string", - "enum": ["low", "medium", "high", "max", "xhigh"], - }, - "bedrock_converse_supports_strict_tools": {"type": "boolean"}, - "supports_regex_lookaround": {"type": "boolean"}, - "tpm": {"type": "number"}, - "supported_endpoints": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "/v1/responses", - "/v1/embeddings", - "/v1/chat/completions", - "/v1/completions", - "/v1/messages", - "/v1/images/generations", - "/v1/realtime", - "/v1/realtime/transcription_sessions", - "/v1/images/variations", - "/v1/images/edits", - "/v1/batch", - "/v1beta/interactions", - "/v1/audio/transcriptions", - "/v1/audio/speech", - "/v1/ocr", - "/v1/videos", - "/vertex_ai/live", - "/v1/listen", - "/v1/systemone", - "/v1/decisions", - "/v1beta/interactions", - ], - }, - }, - "supported_regions": { - "type": "array", - "items": { - "type": "string", - }, - }, - "guardrail_cost_per_unit": { - "type": "object", - "additionalProperties": {"type": "number"}, - }, - "search_context_cost_per_query": { - "type": "object", - "properties": { - "search_context_size_low": {"type": "number"}, - "search_context_size_medium": {"type": "number"}, - "search_context_size_high": {"type": "number"}, - }, - "additionalProperties": False, - }, - "web_search_billing_unit": { - "type": "string", - "enum": ["per_prompt", "per_query"], - }, - "search_free_requests": { - "type": "object", - "properties": { - "count": {"type": "integer", "minimum": 1}, - "period": {"type": "string", "enum": ["day", "month"]}, - "shared_group": {"type": "string"}, - }, - "required": ["count", "period", "shared_group"], - "additionalProperties": False, - }, - "citation_cost_per_token": {"type": "number"}, - "supported_modalities": { - "type": "array", - "items": { - "type": "string", - "enum": ["text", "audio", "image", "video"], - }, - }, - "supported_output_modalities": { - "type": "array", - "items": { - "type": "string", - "enum": ["text", "image", "audio", "code", "video"], - }, - }, - "supports_native_streaming": {"type": "boolean"}, - "supports_image_size": {"type": "boolean"}, - "supports_native_structured_output": {"type": "boolean"}, - "supports_bedrock_native_structured_output": {"type": "boolean"}, - "use_openai_responses_path": {"type": "boolean"}, - "off_peak_pricing": { - "type": "object", - "properties": { - "hours_utc": { - "oneOf": [{"type": "string"}, {"type": "array", "items": {"type": "string"}}], - }, - "windows": { - "type": "array", - "items": { - "type": "object", - "properties": { - "hours_utc": { - "oneOf": [{"type": "string"}, {"type": "array", "items": {"type": "string"}}], - }, - "weekdays": { - "type": "array", - "items": {"oneOf": [{"type": "integer"}, {"type": "string"}]}, - }, - }, - "required": ["hours_utc"], - "additionalProperties": False, - }, - }, - "weekday_timezone": {"type": "string"}, - "input_cost_per_token": {"type": "number"}, - "output_cost_per_token": {"type": "number"}, - "output_cost_per_reasoning_token": {"type": "number"}, - "cache_read_input_token_cost": {"type": "number"}, - "cache_creation_input_token_cost": {"type": "number"}, - }, - "additionalProperties": False, - }, - "tiered_pricing": { - "type": "array", - "items": { - "type": "object", - "properties": { - "range": { - "type": "array", - "items": {"type": "number"}, - "minItems": 2, - "maxItems": 2, - }, - "input_cost_per_token": {"type": "number"}, - "output_cost_per_token": {"type": "number"}, - "cache_read_input_token_cost": {"type": "number"}, - "cache_creation_input_token_cost": {"type": "number"}, - "output_cost_per_reasoning_token": {"type": "number"}, - "max_results_range": { - "type": "array", - "items": {"type": "number"}, - "minItems": 2, - "maxItems": 2, - }, - "input_cost_per_query": {"type": "number"}, - }, - "additionalProperties": False, - }, - }, - }, - "additionalProperties": False, - }, - } - prod_json = os.path.join(os.path.dirname(__file__), "..", "..", "model_prices_and_context_window.json") with open(prod_json, "r") as model_prices_file: actual_json = json.load(model_prices_file) @@ -1362,7 +1389,7 @@ def test_aaamodel_prices_and_context_window_json_is_valid(): actual_json.pop("fallback_generalizations", None) # reserved meta key, not a model entry # Validate schema - validate(actual_json, INTENDED_SCHEMA) + validate(actual_json, _COST_MAP_ROW_SCHEMA) # Validate cost values # Define exceptions for models that are allowed to have costs > 1 @@ -1384,6 +1411,21 @@ def test_aaamodel_prices_and_context_window_json_is_valid(): raise AssertionError(error_message) +def test_cost_map_schema_accepts_12hr_cache_write_rates_for_batch_and_ultrafast_tiers() -> None: + row: Final = { + "litellm_provider": "openai", + "mode": "chat", + "input_cost_per_token": 1e-6, + "output_cost_per_token": 2e-6, + "cache_creation_input_token_cost_above_12hr_batches": 3e-6, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_batches": 4e-6, + "cache_creation_input_token_cost_above_12hr_ultrafast": 5e-6, + "cache_creation_input_token_cost_above_12hr_above_272k_tokens_ultrafast": 6e-6, + } + + assert Draft7Validator(_COST_MAP_ROW_SCHEMA).is_valid({"synthetic-12hr-cache-write-model": row}) + + def test_max_tokens_consistency(): """ Test that max_tokens == max_output_tokens for all models. @@ -2218,6 +2260,45 @@ class TestProxyFunctionCalling: @pytest.mark.usefixtures("isolated_openai_model_sets", "local_model_cost_map") +def test_get_model_info_derives_max_tokens_from_the_output_limit() -> None: + model: Final = "derived-max-tokens-chat-model" + litellm.register_model( + { + model: { + "litellm_provider": "openai", + "mode": "chat", + "max_input_tokens": 400000, + "max_output_tokens": 128000, + "input_cost_per_token": 0.0, + "output_cost_per_token": 0.0, + } + }, + persist_across_reloads=False, + ) + info: Final = litellm.get_model_info(model, custom_llm_provider="openai") + assert info["max_tokens"] == 128000 + assert litellm.get_max_tokens(model) == 128000 + + +def test_get_model_info_derives_max_tokens_from_the_input_limit_when_the_row_has_no_output_limit() -> None: + model: Final = "derived-max-tokens-embedding-model" + litellm.register_model( + { + model: { + "litellm_provider": "openai", + "mode": "embedding", + "max_input_tokens": 8191, + "input_cost_per_token": 0.0, + "output_cost_per_token": 0.0, + } + }, + persist_across_reloads=False, + ) + info: Final = litellm.get_model_info(model, custom_llm_provider="openai") + assert info["max_tokens"] == 8191 + assert info["max_output_tokens"] is None + + def test_register_model_price_is_used_for_completion_cost() -> None: model: Final = "migration-custom-pricing-model" price: Final = { @@ -2529,7 +2610,7 @@ def test_priced_router_deployment_id_stays_out_of_wildcard_model_listing(): def test_anthropic_claude_4_invoke_chat_provider_config(): """Test that the Anthropic Claude 4 Invoke chat provider config is correct.""" - from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformation import ( + from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude_transformation import ( AmazonAnthropicClaudeConfig, ) @@ -5075,7 +5156,7 @@ def test_request_path_cost_map_walks_survive_a_registration_mid_walk( from litellm.llms.fal_ai.cost_calculator import _keyed_rows from litellm.llms.fireworks_ai.chat.transformation import FireworksAIConfig from litellm.llms.ollama.common_utils import OllamaModelInfo - from litellm.llms.openai.chat.gpt_5_transformation import _catalogue_declares_default_effort + from litellm.llms.openai.chat.gpt_reasoning_transformation import _catalogue_declares_default_effort from litellm.utils import _handle_new_key_with_scan, _invalidate_model_cost_lowercase_map walks: Final[Mapping[str, Callable[[], object]]] = { @@ -8587,7 +8668,7 @@ def test_basic_trimming_no_max_tokens_specified(): trimmed_messages = trim_messages(messages, model="gpt-4") print("trimmed messages for gpt-4") print(trimmed_messages) - assert (get_token_count(messages=trimmed_messages, model="gpt-4")) <= litellm.model_cost["gpt-4"]["max_tokens"] + assert (get_token_count(messages=trimmed_messages, model="gpt-4")) <= litellm.model_cost["gpt-4"]["max_input_tokens"] def test_multiple_messages_trimming(): diff --git a/tests/unit/test_utils_get_model_info.py b/tests/unit/test_utils_get_model_info.py index bfaac44a483..302a7d60cdd 100644 --- a/tests/unit/test_utils_get_model_info.py +++ b/tests/unit/test_utils_get_model_info.py @@ -61,6 +61,30 @@ def test_get_model_info_custom_llm_with_same_name_vllm(monkeypatch): assert model_info["input_cost_per_token"] == 0.0 +def test_get_model_info_passes_through_gemini_tiered_audio_rates() -> None: + model: Final = "gemini-tiered-audio-rates-test" + prices: Final = { + "input_cost_per_audio_token_flex": 1e-6, + "input_cost_per_audio_token_priority": 2e-6, + "cache_read_input_audio_token_cost_flex": 3e-7, + "cache_read_input_audio_token_cost_priority": 4e-7, + "cache_read_input_audio_token_cost_batches": 5e-7, + } + litellm.register_model( + { + model: { + "litellm_provider": "gemini", + "mode": "chat", + **prices, + } + } + ) + + model_info: Final = litellm.get_model_info(model=model, custom_llm_provider="gemini") + + assert {key: model_info[key] for key in prices} == prices + + def test_get_model_info_ollama_chat(): from litellm.llms.ollama.completion.transformation import OllamaConfig @@ -136,6 +160,7 @@ def _enforce_bedrock_converse_models( info.get("litellm_provider") == "bedrock" and info.get("mode") == "chat" and model not in whitelist_models + and BedrockModelInfo.get_bedrock_route(model) != "claude_platform" and not ( (base_model := BedrockModelInfo.get_base_model(model)) != model and model_cost.get(base_model, {}).get("litellm_provider") == "bedrock_converse" diff --git a/tests/unit/test_uuid_helper.py b/tests/unit/test_uuid_helper.py index 589d3f96a17..f636942ba88 100644 --- a/tests/unit/test_uuid_helper.py +++ b/tests/unit/test_uuid_helper.py @@ -1,14 +1,20 @@ -import importlib +from typing import Final +from uuid import NAMESPACE_DNS, UUID, uuid5 as stdlib_uuid5 + +from litellm._uuid import uuid, uuid4 -def test_uses_fastuuid_and_uuid4_works(): - mod = importlib.import_module("litellm._uuid") - fastuuid_mod = importlib.import_module("fastuuid") - assert hasattr(mod, "uuid4") - assert hasattr(mod, "uuid") - assert mod.uuid is fastuuid_mod +def test_uuid4_returns_canonical_random_uuid() -> None: + for value in (uuid4(), uuid.uuid4()): + encoded: Final = str(value) + parsed: Final = UUID(encoded) + assert parsed.version == 4 + assert encoded == str(parsed) + assert value.bytes == parsed.bytes - # Ensure uuid4 returns something that looks like a UUID string - val = str(mod.uuid4()) - assert isinstance(val, str) - assert len(val) >= 8 + +def test_uuid5_accepts_byte_names_for_stable_ids() -> None: + namespace: Final = uuid.UUID(str(NAMESPACE_DNS)) + name: Final = "guardrail-\u00e9" + generated: Final = uuid.uuid5(namespace, name.encode("utf-8")) + assert str(generated) == str(stdlib_uuid5(NAMESPACE_DNS, name)) diff --git a/tests/unit/types/test_litellm_params.py b/tests/unit/types/test_litellm_params.py index b0086662f1c..740342f54d9 100644 --- a/tests/unit/types/test_litellm_params.py +++ b/tests/unit/types/test_litellm_params.py @@ -94,6 +94,7 @@ CONNECTION_NAMES: Final = ( "github_copilot_host", "configurable_clientside_auth_params", "use_xai_oauth", + "chatgpt_auth_file", "fireworks_forward_user_id", "aws_batch_role_arn", "aws_bedrock_control_plane_endpoint", diff --git a/tests/unit/types/test_router.py b/tests/unit/types/test_router.py index 2892a829eab..7855eba0042 100644 --- a/tests/unit/types/test_router.py +++ b/tests/unit/types/test_router.py @@ -16,8 +16,8 @@ from litellm.types.router import ( holds_secret_pointer, reject_server_owned_wif_params, server_owned_wif_fields_named, - server_owned_wif_fields_written, server_owned_wif_fields_present, + server_owned_wif_fields_written, ) from litellm.types.utils import ( CustomPricingLiteLLMParams, @@ -367,6 +367,7 @@ def test_server_owned_registry_includes_anthropic_openai_and_oauth_token_exchang + openai_wif_litellm_params + oauth_token_exchange_litellm_params + github_copilot_oauth_litellm_params + + ("chatgpt_auth_file",) ) assert set(openai_wif_litellm_params) == { "openai_identity_provider_id", diff --git a/ui/Dockerfile b/ui/Dockerfile index 4b6b0c1581a..d78a155b874 100644 --- a/ui/Dockerfile +++ b/ui/Dockerfile @@ -3,7 +3,7 @@ # UI container — Next.js static export served by nginx. ARG UI_BUILD_IMAGE=node:24.19-alpine3.24@sha256:d32cdf619f63fe0471182d08996dd516c6275bb5fd31ae06e55a570bd9e1ad43 -ARG NGINX_VERSION=1.31.5-alpine3.24@sha256:34f40471dea485273c5e2a04dd5e97a682332ceb4a9adecd67de450dcb2fb390 +ARG NGINX_VERSION=1.31.8-alpine3.24@sha256:1ef7ca94d7879df82421428ce13bd1eaa412404953859cf7a5b6512c25e67a60 # ---------- builder ---------- FROM ${UI_BUILD_IMAGE} AS builder @@ -27,6 +27,8 @@ RUN npm run build # ---------- runtime ---------- FROM nginx:${NGINX_VERSION} AS runtime +RUN apk upgrade --no-cache brotli-libs + # Drop the upstream default :80 server; we own the config. RUN rm -f /etc/nginx/conf.d/default.conf diff --git a/ui/litellm-dashboard/eslint-suppressions.json b/ui/litellm-dashboard/eslint-suppressions.json index 38d4c435e9a..c8231b90bfd 100644 --- a/ui/litellm-dashboard/eslint-suppressions.json +++ b/ui/litellm-dashboard/eslint-suppressions.json @@ -1730,9 +1730,6 @@ "src/components/model_group_alias_settings.tsx": { "local/filename-pascal-case": { "count": 1 - }, - "react-hooks/set-state-in-effect": { - "count": 1 } }, "src/components/model_info_view.tsx": { @@ -1740,7 +1737,7 @@ "count": 1 }, "prefer-const": { - "count": 5 + "count": 3 }, "react-hooks/set-state-in-effect": { "count": 1 @@ -2175,11 +2172,6 @@ "count": 1 } }, - "src/utils/dataUtils.test.ts": { - "max-nested-callbacks": { - "count": 1 - } - }, "tests/CreateKeyPage.expiredToken.test.tsx": { "@typescript-eslint/no-require-imports": { "count": 3 diff --git a/ui/litellm-dashboard/src/app/(dashboard)/hooks/models/useModels.test.ts b/ui/litellm-dashboard/src/app/(dashboard)/hooks/models/useModels.test.ts index e9df939f220..76db710f5ba 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/hooks/models/useModels.test.ts +++ b/ui/litellm-dashboard/src/app/(dashboard)/hooks/models/useModels.test.ts @@ -125,10 +125,42 @@ describe("useModelsInfo", () => { undefined, false, undefined, + {}, ); expect(modelInfoCall).toHaveBeenCalledTimes(1); }); + it("keeps saved model parameters separate from hydrated parameters in the query cache", async () => { + vi.mocked(modelInfoCall).mockImplementation(async (...args) => ({ + ...mockPaginatedModelInfoResponse, + data: [{ litellm_params: args[15]?.useStoredParams ? {} : { litellm_image_enabled: false } }], + })); + const { result } = renderHook( + () => ({ + hydrated: useModelsInfo(1, 50, undefined, "model-1"), + stored: useModelsInfo( + 1, + 50, + undefined, + "model-1", + undefined, + undefined, + undefined, + false, + undefined, + undefined, + false, + undefined, + { useStoredParams: true }, + ), + }), + { wrapper }, + ); + await waitFor(() => expect(result.current.stored.isSuccess && result.current.hydrated.isSuccess).toBe(true)); + expect(result.current.stored.data?.data[0].litellm_params).toEqual({}); + expect(result.current.hydrated.data?.data[0].litellm_params).toEqual({ litellm_image_enabled: false }); + }); + it("should use custom page and size parameters", async () => { (modelInfoCall as any).mockResolvedValue(mockPaginatedModelInfoResponse); @@ -156,6 +188,7 @@ describe("useModelsInfo", () => { undefined, false, undefined, + {}, ); }); diff --git a/ui/litellm-dashboard/src/app/(dashboard)/hooks/models/useModels.ts b/ui/litellm-dashboard/src/app/(dashboard)/hooks/models/useModels.ts index 24f76065f34..f9304bab0d2 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/hooks/models/useModels.ts +++ b/ui/litellm-dashboard/src/app/(dashboard)/hooks/models/useModels.ts @@ -45,6 +45,7 @@ export const useModelsInfo = ( accessGroup?: string, wildcardOnly: boolean = false, blocked?: boolean, + options: { useStoredParams?: boolean } = {}, ) => { const { accessToken, userId, userRole } = useAuthorized(); return useQuery({ @@ -57,6 +58,7 @@ export const useModelsInfo = ( ...(search && { search }), ...(modelName && { modelName }), ...(modelId && { modelId }), + useStoredParams: Boolean(options.useStoredParams), ...(teamId && { teamId }), ...(sortBy && { sortBy }), ...(sortOrder && { sortOrder }), @@ -86,6 +88,7 @@ export const useModelsInfo = ( accessGroup, wildcardOnly, blocked, + options, ), enabled: Boolean(accessToken && userId && userRole), }); @@ -121,6 +124,7 @@ export interface AutoRouterDeployment extends AutoRouterCandidateDeployment { /** False for config.yaml-defined deployments, which the update and delete routes refuse. */ db_model?: boolean | null; base_model?: string | null; + blocked?: boolean | null; mode?: string | null; created_at?: string | null; updated_at?: string | null; diff --git a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/CreateMCPServer.integration.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/CreateMCPServer.integration.test.tsx index 65656a053ce..3b3269b87cc 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/CreateMCPServer.integration.test.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/CreateMCPServer.integration.test.tsx @@ -396,6 +396,46 @@ describe("CreateMCPServer", () => { expect(payload.credentials).toEqual({ auth_value: "my-secret-key" }); }); + it("creates an Authorization (raw header) server with the header value sent verbatim", async () => { + await selectHttpTransport(); + + fireEvent.change(getServerNameInput(), { target: { value: "Raw_Auth_Server" } }); + fireEvent.change(screen.getByPlaceholderText("https://your-mcp-server.com"), { + target: { value: "https://example.com/mcp" }, + }); + + await selectOption("Authentication", "Authorization (raw header)"); + + fireEvent.change(await screen.findByPlaceholderText("Enter token or secret"), { + target: { value: "ApiKey raw-key-123" }, + }); + + vi.mocked(networking.createMCPServer).mockResolvedValue({ + server_id: "new-server-2", + server_name: "Raw_Auth_Server", + alias: "Raw_Auth_Server", + url: "https://example.com/mcp", + transport: "http", + auth_type: "authorization", + created_at: "2024-01-01T00:00:00Z", + created_by: "user-1", + updated_at: "2024-01-01T00:00:00Z", + updated_by: "user-1", + }); + + await act(async () => { + fireEvent.click(screen.getByRole("button", { name: "Add MCP Server" })); + }); + + await waitFor(() => { + expect(networking.createMCPServer).toHaveBeenCalledTimes(1); + }); + + const [, payload] = vi.mocked(networking.createMCPServer).mock.calls[0]; + expect(payload.auth_type).toBe("authorization"); + expect(payload.credentials).toEqual({ auth_value: "ApiKey raw-key-123" }); + }); + it("does not write the browser-authorized token into form.credentials for true_passthrough", async () => { await selectHttpTransport(); diff --git a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/createServerPayload.ts b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/createServerPayload.ts index 30c4c502c42..5536b4b1bc4 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/createServerPayload.ts +++ b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/createServerPayload.ts @@ -15,6 +15,7 @@ export const AUTH_TYPES_REQUIRING_AUTH_VALUE = [ AUTH_TYPE.BEARER_TOKEN, AUTH_TYPE.TOKEN, AUTH_TYPE.BASIC, + AUTH_TYPE.AUTHORIZATION, ]; export const AUTH_TYPES_REQUIRING_CREDENTIALS = [ diff --git a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/editServerPayload.differential.cases.ts b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/editServerPayload.differential.cases.ts index 4219113918b..e9f32b5c4db 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/editServerPayload.differential.cases.ts +++ b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/editServerPayload.differential.cases.ts @@ -82,6 +82,7 @@ const AUTH_TYPES = [ "bearer_token", "token", "basic", + "authorization", "oauth2", "oauth2_token_exchange", "oauth2_id_jag", diff --git a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/mcp_server_edit.integration.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/mcp_server_edit.integration.test.tsx index 9f91c06e9e5..15b09961a84 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/mcp_server_edit.integration.test.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/mcp_server_edit.integration.test.tsx @@ -135,6 +135,11 @@ const CASES: readonly Case[] = [ server: { ...BASE, auth_type: "basic", credentials: CREDS }, expected: { ...EXPECTED_BASE, auth_type: "basic", credentials: { auth_value: "secret-value" } }, }, + { + label: "authorization sends only auth_value under credentials", + server: { ...BASE, auth_type: "authorization", credentials: CREDS }, + expected: { ...EXPECTED_BASE, auth_type: "authorization", credentials: { auth_value: "secret-value" } }, + }, { label: "oauth2 m2m mounts token_url and omits the interactive endpoints entirely", server: { diff --git a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/mcp_server_edit.tsx b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/mcp_server_edit.tsx index f35e3ab3d3a..57985fd8cbb 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/mcp_server_edit.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/mcp_server_edit.tsx @@ -51,6 +51,7 @@ import OAuthFormFields from "./OAuthFormFields"; import MCPLogoSelector from "./MCPLogoSelector"; import EnvVarsSection from "./EnvVarsSection"; import { validateMCPServerUrl, validateMCPServerName, normalizeToolOverrideMap } from "./utils"; +import { AUTH_TYPES_REQUIRING_AUTH_VALUE } from "./createServerPayload"; import { EditServerFormValues, buildEditServerPayload, editPayloadErrorMessage } from "./editServerPayload"; import { DUPLICATE_IDENTIFIER_MESSAGE, findDuplicateMcpServer, mcpSubmitErrorReason } from "./duplicateServerCheck"; import { toast } from "@/lib/toast"; @@ -94,7 +95,6 @@ interface MCPServerEditProps { stdioEnabled?: boolean; } -const AUTH_TYPES_REQUIRING_AUTH_VALUE = [AUTH_TYPE.API_KEY, AUTH_TYPE.BEARER_TOKEN, AUTH_TYPE.TOKEN, AUTH_TYPE.BASIC]; export const EDIT_OAUTH_UI_STATE_KEY = "litellm-mcp-oauth-edit-state"; const MCPServerEdit: React.FC = ({ diff --git a/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/components/AccessGroupBudgetModal.tsx b/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/components/AccessGroupBudgetModal.tsx index a66f31a0dc0..54decbfff3d 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/components/AccessGroupBudgetModal.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/components/AccessGroupBudgetModal.tsx @@ -102,6 +102,7 @@ const AccessGroupBudgetModal: React.FC = ({ id={id} value={value || null} onChange={(next) => onChange(next ?? undefined)} + placeholder="Keep current" /> )} diff --git a/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/components/AutoRouters/AutoRoutersPanel.tsx b/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/components/AutoRouters/AutoRoutersPanel.tsx index 6f7e04f92c6..2d1c24685f0 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/components/AutoRouters/AutoRoutersPanel.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/components/AutoRouters/AutoRoutersPanel.tsx @@ -106,10 +106,7 @@ export function AutoRoutersPanel({ > Add Auto Router - - Choose a classifier to route each request to a model. Called like any other model, so clients keep using a - single model name. - + Choose models for your auto router. { expect(await screen.findByLabelText(/Max Budget/)).toHaveValue(2.5); }); + it("keeps the stored reset period when Keep current is selected", async () => { + GET.mockResolvedValue({ + data: { + access_groups: [ + { + ...BUDGETED_GROUP, + budget: { ...BUDGETED_GROUP.budget, budget_duration: "24h" }, + }, + ], + }, + }); + renderPanel(); + await openActions("premium"); + await userEvent.click(await screen.findByText("Edit budget")); + + await userEvent.click(await screen.findByRole("combobox", { name: "Reset Budget" })); + const keepCurrentOption = await screen.findByRole("option", { name: "Keep current" }); + expect(keepCurrentOption).toBeInTheDocument(); + await userEvent.click(keepCurrentOption); + await userEvent.click(screen.getByRole("button", { name: "Save Budget" })); + + await waitFor(() => + expect(PUT).toHaveBeenCalledWith("/access_group/{access_group}/budget", { + params: { path: { access_group: "premium" } }, + body: { max_budget: 2.5 }, + }), + ); + expect(PUT.mock.calls[0][1].body).not.toHaveProperty("budget_duration"); + }); + it("refuses to save a budget with every field blank", async () => { renderPanel(); await openActions("shared"); diff --git a/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/panels/ModelGroupAliasPanel.integration.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/panels/ModelGroupAliasPanel.integration.test.tsx index 227a34335a3..36a9f92dfd4 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/panels/ModelGroupAliasPanel.integration.test.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/panels/ModelGroupAliasPanel.integration.test.tsx @@ -10,6 +10,7 @@ vi.mock("@/app/(dashboard)/hooks/useAuthorized", () => ({ vi.mock("@/components/networking", () => ({ getCallbacksCall: vi.fn(), + getProxyBaseUrl: () => "https://proxy.test", getRouterSettingsCall: vi.fn(), setCallbacksCall: vi.fn(), })); diff --git a/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/panels/ModelGroupAliasPanel.tsx b/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/panels/ModelGroupAliasPanel.tsx index 025923e08e9..e6c720f38cf 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/panels/ModelGroupAliasPanel.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/panels/ModelGroupAliasPanel.tsx @@ -2,7 +2,7 @@ import { useEffect, useState } from "react"; import ModelGroupAliasSettings from "@/components/model_group_alias_settings"; -import { getCallbacksCall, getRouterSettingsCall } from "@/components/networking"; +import { getCallbacksCall, getProxyBaseUrl, getRouterSettingsCall } from "@/components/networking"; import useAuthorized from "@/app/(dashboard)/hooks/useAuthorized"; export default function ModelGroupAliasPanel() { @@ -22,6 +22,7 @@ export default function ModelGroupAliasPanel() { : null; const managedByConfig = currentAliasOwnership?.managedByConfig ?? false; const ownershipLoading = Boolean(accessToken && !currentAliasOwnership); + const preferenceScope = userID ? JSON.stringify([getProxyBaseUrl(), userID]) : null; useEffect(() => { if (!accessToken) { @@ -62,6 +63,8 @@ export default function ModelGroupAliasPanel() { return ( { vi.unstubAllGlobals(); }); - it("lists the key's decision models from the proxy that answers the request, sorted by name", async () => { + it("lists the key's models with decision modes or endpoints from the request proxy, sorted by name", async () => { mockFetch.mockResolvedValueOnce( modelGroupInfo([ { model_group: "pplx-decider", mode: "evaluation" }, { model_group: "gpt-5.5", mode: "chat" }, { model_group: "jev-latest", mode: "evaluation" }, { model_group: "unknown-mode", mode: null }, + { model_group: "native-decision", mode: "decisions" }, + { + model_group: "chat-decisions", + mode: "chat", + supported_endpoints: ["/v1/chat/completions", "/v1/decisions"], + }, + { model_group: "chat-systemone", mode: "chat", supported_endpoints: ["/v1/systemone"] }, + { model_group: "custom-decision", mode: "custom", supported_endpoints: ["/v1/decisions"] }, + { model_group: "endpoint-only", supported_endpoints: ["/v1/decisions"] }, + { model_group: "chat-only", mode: "chat", supported_endpoints: ["/v1/chat/completions"] }, + { model_group: "no-endpoints", mode: "chat", supported_endpoints: [] }, + { model_group: "null-endpoints", mode: "chat", supported_endpoints: null }, + { model_group: "missing-mode" }, + { model_group: "custom-mode", mode: "custom" }, ]), ); await expect(fetchDecisionModels("virtual-key", "https://custom.example.com/")).resolves.toEqual([ + "chat-decisions", + "chat-systemone", + "custom-decision", + "endpoint-only", "jev-latest", + "native-decision", "pplx-decider", ]); expect(mockFetch).toHaveBeenCalledWith( diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/llm_calls/system_one.ts b/ui/litellm-dashboard/src/app/(dashboard)/playground/llm_calls/system_one.ts index a4030029903..035a05729ba 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/playground/llm_calls/system_one.ts +++ b/ui/litellm-dashboard/src/app/(dashboard)/playground/llm_calls/system_one.ts @@ -2,7 +2,7 @@ import { z } from "zod"; import { getGatewayBaseUrl, getGlobalLitellmHeaderName, getProxyBaseUrl } from "@/components/networking"; import { withRequiredHeaders } from "@/components/llm_calls/request_headers"; import { createApiClient } from "@/lib/http/client"; -import { isDecisionMode } from "@/lib/decisionModels"; +import { isDecisionEntry } from "@/lib/decisionModels"; import { systemOneResponseSchema, type PlaygroundRequest, @@ -26,7 +26,13 @@ export type PlaygroundDecisionRequest = | { endpoint: "/v1/decisions"; payload: OpenAIDecisionsRequest }; const modelGroupInfoSchema = z.object({ - data: z.array(z.object({ model_group: z.string(), mode: z.string().nullish() })), + data: z.array( + z.object({ + model_group: z.string(), + mode: z.string().nullish(), + supported_endpoints: z.array(z.string()).nullish(), + }), + ), }); function proxyClient(customBaseUrl?: string, getDefaultBaseUrl: () => string = getProxyBaseUrl) { @@ -56,7 +62,7 @@ export async function fetchDecisionModels( }); return modelGroupInfoSchema .parse(body) - .data.filter((group) => isDecisionMode(group.mode)) + .data.filter(isDecisionEntry) .map((group) => group.model_group) .sort((a, b) => a.localeCompare(b)); } diff --git a/ui/litellm-dashboard/src/app/(dashboard)/router-settings/_components/general_settings.integration.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/router-settings/_components/general_settings.integration.test.tsx index 35434830d98..d7dfb8151fc 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/router-settings/_components/general_settings.integration.test.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/router-settings/_components/general_settings.integration.test.tsx @@ -80,6 +80,42 @@ describe("GeneralSettings General tab", () => { vi.mocked(deleteConfigFieldSetting).mockClear(); }); + it.each([ + ["maximum_spend_logs_retention_period", null, "7d"], + ["maximum_health_check_retention_period", "30d", "14d"], + ["maximum_daily_tag_spend_retention_period", undefined, "90d"], + ["maximum_spend_logs_cleanup_run_budget", "5m", "10m"], + ["maximum_spend_logs_cleanup_batch_timeout", "", "45s"], + ["mcp_client_id_header", "x-client-id", "X-MCP-Client.ID"], + ])("displays, updates and resets the String setting %s", async (fieldName, initialValue, updatedValue) => { + vi.mocked(getGeneralSettingsCall).mockResolvedValue([ + ...SETTINGS_FIXTURE, + { + field_name: fieldName, + field_type: "String", + field_value: initialValue, + field_description: "string setting", + stored_in_db: initialValue != null, + field_default_value: null, + }, + ]); + const user = userEvent.setup(); + renderWithProviders(); + await user.click(screen.getByRole("tab", { name: "General" })); + const input = await screen.findByRole("textbox", { name: fieldName }); + expect(input).toHaveValue(initialValue ?? ""); + fireEvent.change(input, { target: { value: updatedValue } }); + const row = screen.getByRole("row", { name: new RegExp(fieldName) }); + await user.click(within(row).getByRole("button", { name: "Update" })); + expect(vi.mocked(updateConfigFieldSetting).mock.calls).toEqual([["token", fieldName, updatedValue]]); + expect(within(row).getByText("In DB")).toBeInTheDocument(); + const resetIcon = row.querySelectorAll("td")[3].querySelector("svg"); + expect(resetIcon).not.toBeNull(); + await user.click(resetIcon as unknown as Element); + expect(vi.mocked(deleteConfigFieldSetting).mock.calls).toEqual([["token", fieldName]]); + expect(input).toHaveValue(""); + }); + it("updates max_ui_session_budget with its own value, not the value at its filtered index", async () => { const user = userEvent.setup(); renderWithProviders(); diff --git a/ui/litellm-dashboard/src/app/(dashboard)/router-settings/_components/general_settings.tsx b/ui/litellm-dashboard/src/app/(dashboard)/router-settings/_components/general_settings.tsx index 5d28adb7ef3..67712d78a13 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/router-settings/_components/general_settings.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/router-settings/_components/general_settings.tsx @@ -68,6 +68,15 @@ const SettingValueEditor: React.FC<{ /> ); } + if (setting.field_type === "String") { + return ( + onChange(setting.field_name, event.target.value)} + /> + ); + } if (setting.field_type === "Integer") { return ( { }); it("should handle search errors and show notification", async () => { - const error = new Error("Search failed"); + const error = new Error( + JSON.stringify({ + error: { + message: "User not allowed to access search tool: exa-search-2", + type: "user_search_tool_access_denied", + code: "403", + }, + }), + ); vi.mocked(networking.searchToolQueryCall).mockRejectedValue(error); const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {}); const user = userEvent.setup(); @@ -281,11 +289,29 @@ describe("SearchToolTester", () => { const searchButton = screen.getByRole("button", { name: /search/i }); await user.click(searchButton); await waitFor(() => { - expect(toast.fromError).toHaveBeenCalledWith("Failed to query search tool"); + expect(toast.fromError).toHaveBeenCalledWith(error); }); consoleSpy.mockRestore(); }); + it("should not show empty results or add history when search fails", async () => { + vi.mocked(networking.searchToolQueryCall).mockRejectedValue(new Error("Search failed")); + const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {}); + const user = userEvent.setup(); + render(); + const input = screen.getByPlaceholderText("Enter your search query..."); + fireEvent.change(input, { target: { value: "test query" } }); + await user.click(screen.getByRole("button", { name: /search/i })); + + await waitFor(() => { + expect(toast.fromError).toHaveBeenCalled(); + }); + expect(screen.queryByText("No results found")).not.toBeInTheDocument(); + expect(screen.queryByText("test query")).not.toBeInTheDocument(); + expect(screen.getByText("Test your search tool")).toBeInTheDocument(); + consoleSpy.mockRestore(); + }); + it("should maintain search history", async () => { const user = userEvent.setup(); render(); diff --git a/ui/litellm-dashboard/src/app/(dashboard)/search-tools/_components/SearchToolTester.tsx b/ui/litellm-dashboard/src/app/(dashboard)/search-tools/_components/SearchToolTester.tsx index 7dcef3fc6ba..646120443c7 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/search-tools/_components/SearchToolTester.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/search-tools/_components/SearchToolTester.tsx @@ -60,7 +60,7 @@ export const SearchToolTester: React.FC = ({ searchToolNa setSearchHistory((prev) => [historyEntry, ...prev]); } catch (error) { console.error("Error querying search tool:", error); - toast.fromError("Failed to query search tool"); + toast.fromError(error); } finally { setIsLoading(false); } diff --git a/ui/litellm-dashboard/src/app/(dashboard)/ui-theme/UIThemeSettings.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/ui-theme/UIThemeSettings.test.tsx index 4b58590ffd1..86ef33c0d8b 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/ui-theme/UIThemeSettings.test.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/ui-theme/UIThemeSettings.test.tsx @@ -10,7 +10,8 @@ const setLogoUrl = vi.fn(); const setLogoUrlDark = vi.fn(); const setFaviconUrl = vi.fn(); -vi.mock("@/contexts/ThemeContext", () => ({ +vi.mock("@/contexts/ThemeContext", async (importOriginal) => ({ + ...(await importOriginal()), useTheme: () => ({ logoUrl: null, setLogoUrl, @@ -22,7 +23,7 @@ vi.mock("@/contexts/ThemeContext", () => ({ })); vi.mock("@/components/networking", () => ({ - getProxyBaseUrl: () => "", + getProxyBaseUrl: () => "/gateway", getGlobalLitellmHeaderName: () => "Authorization", })); @@ -111,6 +112,34 @@ describe("UIThemeSettings", () => { expect(bodyOf(patchCalls()[0]).logo_url_dark).toBe("https://a.test/logo-dark.png"); }); + it.each(["Save Changes", "Reset to Default"])( + "should keep local logo routes out of settings and clear preview overrides with %s", + async (action) => { + const user = userEvent.setup(); + fetchMock.mockImplementation(async () => + Response.json({ + values: { logo_url: null, logo_url_dark: null }, + logo_url_via_proxy: true, + logo_url_dark_via_proxy: true, + }), + ); + + render(); + + await waitFor(() => expect(setLogoUrlDark).toHaveBeenCalledWith("/gateway/get_image?theme=dark")); + expect(setLogoUrl).toHaveBeenCalledWith("/gateway/get_image"); + expect(screen.getByPlaceholderText(LOGO_PLACEHOLDER)).toHaveValue(""); + expect(screen.getByPlaceholderText(LOGO_DARK_PLACEHOLDER)).toHaveValue(""); + + await user.click(screen.getByRole("button", { name: action })); + await waitFor(() => expect(patchCalls()).toHaveLength(1)); + expect(bodyOf(patchCalls()[0])).toEqual({ logo_url: null, logo_url_dark: null, favicon_url: null }); + + expect(setLogoUrl).toHaveBeenLastCalledWith(null); + expect(setLogoUrlDark).toHaveBeenLastCalledWith(null); + }, + ); + it("should surface a backend failure when saving fails", async () => { const user = userEvent.setup(); render(); diff --git a/ui/litellm-dashboard/src/app/(dashboard)/ui-theme/UIThemeSettings.tsx b/ui/litellm-dashboard/src/app/(dashboard)/ui-theme/UIThemeSettings.tsx index b6bc0f28dd5..c0b3bd26001 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/ui-theme/UIThemeSettings.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/ui-theme/UIThemeSettings.tsx @@ -4,7 +4,7 @@ import { Card, CardContent } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { UiLoadingSpinner } from "@/components/ui/ui-loading-spinner"; -import { useTheme } from "@/contexts/ThemeContext"; +import { resolveThemeImages, useTheme } from "@/contexts/ThemeContext"; import { getProxyBaseUrl, getGlobalLitellmHeaderName } from "@/components/networking"; import { toast } from "@/lib/toast"; @@ -40,12 +40,13 @@ const UIThemeSettings: React.FC = ({ userID, userRole, acc }); if (response.ok) { const data = await response.json(); + const images = resolveThemeImages(data, proxyBaseUrl); setLogoUrlInput(data.values?.logo_url || ""); setLogoUrlDarkInput(data.values?.logo_url_dark || ""); setFaviconUrlInput(data.values?.favicon_url || ""); - setLogoUrl(data.values?.logo_url || null); - setLogoUrlDark(data.values?.logo_url_dark || null); - setFaviconUrl(data.values?.favicon_url || null); + setLogoUrl(images.logoUrl); + setLogoUrlDark(images.logoUrlDark); + setFaviconUrl(images.faviconUrl); } } catch (error) { console.error("Error fetching theme settings:", error); diff --git a/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.test.tsx index 24e9936a1d0..adb6d8791a7 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.test.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.test.tsx @@ -1914,6 +1914,61 @@ describe("UsagePage", () => { ); }); + it("queries the configured month and preserves later manual selections", async () => { + const now = new Date(2026, 9, 24, 12); + vi.useFakeTimers({ toFake: ["Date"] }); + vi.setSystemTime(now); + try { + renderWithProviders(); + await waitFor(() => + expect(mockUserDailyActivityAggregatedCall).toHaveBeenCalledWith( + expect.objectContaining({ + startTime: new Date(2026, 9, 1), + endTime: new Date(2026, 9, 24, 23, 59, 59, 999), + }), + ), + ); + expect(mockUserDailyActivityAggregatedCall).toHaveBeenCalledTimes(1); + fireEvent.click(screen.getByTestId("pick-a-different-range")); + await waitFor(() => + expect(mockUserDailyActivityAggregatedCall).toHaveBeenLastCalledWith( + expect.objectContaining({ + startTime: new Date(2024, 0, 1), + endTime: new Date(2024, 0, 8, 23, 59, 59, 999), + }), + ), + ); + } finally { + vi.useRealTimers(); + } + }); + + it.each(["?range=today", "?from=2025-03-01&to=2025-03-05"])( + "preserves explicit dates over configured defaults for %s", + async (searchParams) => { + vi.useFakeTimers({ toFake: ["Date"] }); + vi.setSystemTime(new Date(2026, 9, 24, 12)); + try { + const view = renderWithProviders(, { + searchParams, + }); + const startTime = searchParams.includes("range=today") ? new Date(2026, 9, 24) : new Date(2025, 2, 1); + const endTime = searchParams.includes("range=today") + ? new Date(2026, 9, 24, 23, 59, 59, 999) + : new Date(2025, 2, 5, 23, 59, 59, 999); + await waitFor(() => + expect(mockUserDailyActivityAggregatedCall).toHaveBeenCalledWith( + expect.objectContaining({ startTime, endTime }), + ), + ); + view.rerender(); + expect(mockUserDailyActivityAggregatedCall).toHaveBeenCalledTimes(1); + } finally { + vi.useRealTimers(); + } + }, + ); + it("fetches the custom range in the URL and writes a newly picked one", async () => { const { lastQuery } = renderAt("?from=2025-03-01&to=2025-03-05"); diff --git a/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.tsx b/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.tsx index 3ff758a3c18..d7d3b502b6f 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.tsx @@ -82,6 +82,7 @@ import { clientDateRangePatch, clientPanelPatch, dateRangeFromParams, + defaultUsageDateRange, dateRangePatch, entitySelectionPatch, selectedEntitiesFromParams, @@ -108,23 +109,24 @@ interface UsagePageProps { teams: Team[]; organizations: Organization[]; teamsLoading?: boolean; + defaultTimeRange?: string; } -const UsagePage: React.FC = ({ teams, organizations, teamsLoading = false }) => { +const UsagePage: React.FC = ({ teams, organizations, teamsLoading = false, defaultTimeRange }) => { const { accessToken, userRole, userId: userID, premiumUser, isLoading: authorizationLoading } = useAuthorized(); const [gatewayActivityData, setGatewayActivityData] = useState(null); - // Create initial dates outside of state to prevent recreation - const initialFromDate = useMemo(() => new Date(Date.now() - 7 * 24 * 60 * 60 * 1000), []); - const initialToDate = useMemo(() => new Date(), []); + const defaultRange = useMemo(() => defaultUsageDateRange(defaultTimeRange), [defaultTimeRange]); const [urlParams, setUrlParams] = useQueryStates(usageUrlParsers); const { range, from, to } = urlParams; const dateValue = useMemo( - () => dateRangeFromParams({ range, from, to }) ?? { from: initialFromDate, to: initialToDate }, - [range, from, to, initialFromDate, initialToDate], + () => dateRangeFromParams({ range, from, to }) ?? defaultRange.value, + [range, from, to, defaultRange], ); + const presetShortLabel = range ?? (from === null && to === null ? defaultRange.preset : null); + const { client_range, client_from, client_to } = urlParams; const clientDateValue = useMemo( () => clientDateRangeFromParams({ client_range, client_from, client_to }) ?? dateValue, @@ -481,7 +483,11 @@ const UsagePage: React.FC = ({ teams, organizations, teamsLoadin )}
- + +
), @@ -204,6 +205,18 @@ describe("BulkEditUserModal", () => { }); }); + it("omits an unset reset period from the bulk update payload", async () => { + const user = userEvent.setup(); + renderWithProviders(); + + await user.click(screen.getByRole("button", { name: "Submit with unset duration" })); + + await waitFor(() => { + expect(mockUserBulkUpdateUserCall).toHaveBeenCalledWith("test-token", { max_budget: 100 }, ["user1", "user2"]); + }); + expect(mockUserBulkUpdateUserCall.mock.calls[0][1]).not.toHaveProperty("budget_duration"); + }); + it("should call userBulkUpdateUserCall with allUsers flag when update all users is enabled", async () => { const user = userEvent.setup(); renderWithProviders(); diff --git a/ui/litellm-dashboard/src/app/(dashboard)/users/_components/user_edit_view.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/users/_components/user_edit_view.test.tsx index 156b27672d5..f71384d80d7 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/users/_components/user_edit_view.test.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/users/_components/user_edit_view.test.tsx @@ -322,6 +322,35 @@ describe("UserEditView", () => { expect(callArgs.metadata).toEqual(MOCK_USER_DATA.user_info.metadata); }); + it("uses No change for an unset reset period in bulk edit", async () => { + const onSubmit = vi.fn(); + const userDataWithUnsetResetPeriod = { + ...MOCK_USER_DATA, + user_info: { + ...MOCK_USER_DATA.user_info, + max_budget: null, + budget_duration: null, + }, + }; + renderWithProviders( + , + ); + + const resetPeriod = await screen.findByRole("combobox", { name: "Reset Budget" }); + expect(resetPeriod).toHaveTextContent("No change"); + await userEvent.click(resetPeriod); + await userEvent.click(await screen.findByRole("option", { name: "No change" })); + + const unlimitedBudget = await screen.findByRole("checkbox", { name: "Unlimited Budget" }); + await waitFor(() => expect(unlimitedBudget).toBeChecked()); + await userEvent.click(unlimitedBudget); + fireEvent.change(screen.getByRole("spinbutton", { name: /max budget/i }), { target: { value: "12.5" } }); + await userEvent.click(screen.getByRole("button", { name: /save changes/i })); + + await waitFor(() => expect(onSubmit).toHaveBeenCalled()); + expect(onSubmit.mock.calls[0][0]).toMatchObject({ max_budget: "12.5", budget_duration: null }); + }); + it("should set max_budget to null when unlimited budget is checked on submit", async () => { const onSubmitMock = vi.fn(); const userDataWithNullBudget = { diff --git a/ui/litellm-dashboard/src/app/(dashboard)/users/_components/user_edit_view.tsx b/ui/litellm-dashboard/src/app/(dashboard)/users/_components/user_edit_view.tsx index 647761bb44b..d4317d477f8 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/users/_components/user_edit_view.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/users/_components/user_edit_view.tsx @@ -315,7 +315,14 @@ export function UserEditView({ - {({ id, value, onChange }) => } + {({ id, value, onChange }) => ( + + )} {!isBulkEdit && ( diff --git a/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/user_info_view.integration.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/user_info_view.integration.test.tsx index 948607bff37..d434987b873 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/user_info_view.integration.test.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/user_info_view.integration.test.tsx @@ -201,13 +201,13 @@ describe("UserInfoView add-to-team form", () => { await openEditor(user); await user.click(screen.getByRole("combobox", { name: "Reset Budget" })); - await user.click(await screen.findByRole("option", { name: "n/a" })); + await user.click(await screen.findByRole("option", { name: "Never resets" })); await user.click(screen.getByRole("button", { name: /save changes/i })); await waitFor(() => expect(mockUserUpdateUserCall).toHaveBeenCalled()); expect(mockUserUpdateUserCall.mock.calls[0][1]).toMatchObject({ budget_duration: null }); await openEditor(user); - expect(screen.getByRole("combobox", { name: "Reset Budget" })).toHaveTextContent("n/a"); + expect(screen.getByRole("combobox", { name: "Reset Budget" })).toHaveTextContent("Never resets"); }); }); diff --git a/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/user_info_view.tsx b/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/user_info_view.tsx index 2056142b50a..476c043a258 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/user_info_view.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/user_info_view.tsx @@ -47,6 +47,7 @@ import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/u import ScopedSavingsTab from "@/components/shared/ScopedSavingsTab"; import { AutoRouterUsageView } from "@/app/(dashboard)/cost-optimization/_components/AutoRouterBenchmarksTab"; import { useActivityDateRange } from "@/app/(dashboard)/cost-optimization/_components/useDailyActivityRange"; +import { BudgetPeriodTooltip } from "@/components/shared/BudgetPeriodTooltip"; interface UserInfoViewProps { userId: string; @@ -507,7 +508,15 @@ export default function UserInfoView({
-

Spend

+

+ Spend + +

${formatNumberWithCommas(userData.spend || 0, 2)}

diff --git a/ui/litellm-dashboard/src/app/chat/layout.integration.test.tsx b/ui/litellm-dashboard/src/app/chat/layout.integration.test.tsx index 12acf9192aa..2efe698ec69 100644 --- a/ui/litellm-dashboard/src/app/chat/layout.integration.test.tsx +++ b/ui/litellm-dashboard/src/app/chat/layout.integration.test.tsx @@ -1,12 +1,10 @@ import userEvent from "@testing-library/user-event"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; -import { renderWithProviders, screen, testQueryClient } from "@/../tests/test-utils"; +import { renderWithProviders, screen, testQueryClient, within } from "@/../tests/test-utils"; import { setServerRootPath } from "@/lib/serverRootPath"; -import { recordChatQuery } from "@/lib/telemetry/chat"; +import { getProxyBaseUrl } from "@/components/networking"; import ChatLayout from "./layout"; -vi.mock("@/lib/telemetry/chat", () => ({ recordChatQuery: vi.fn(async () => {}) })); - const { router, route } = vi.hoisted(() => ({ router: { push: vi.fn(), replace: vi.fn() }, route: { pathname: "/ui/chat" }, @@ -36,9 +34,13 @@ vi.mock("@/app/(dashboard)/hooks/uiSettings/useUISettings", () => ({ const plugin = { name: "observability", display_name: "Observability", url: "https://plugin.example.com" }; const originalLocation = Object.getOwnPropertyDescriptor(window, "location")!; const assign = vi.fn(); +const LIGHT_LOGO = "https://cdn.test/light.svg"; +const DARK_LOGO = "https://cdn.test/dark.svg"; +let themeResponse: unknown = { values: {} }; describe("Chat layout product navigation", () => { beforeEach(() => { + themeResponse = { values: {} }; route.pathname = "/ui/chat"; localStorage.clear(); localStorage.setItem("litellm_plugin_mode", plugin.name); @@ -58,7 +60,7 @@ describe("Chat layout product navigation", () => { expect(new Headers(init?.headers).get("Authorization")).toBe("Bearer chat-layout-test-token"); return Response.json([plugin]); case "/get/ui_theme_settings": - return Response.json({ values: {} }); + return Response.json(themeResponse); case "/sso/get/ui_settings": return Response.json({}); default: @@ -78,6 +80,55 @@ describe("Chat layout product navigation", () => { vi.clearAllMocks(); }); + it.each([ + ["public", [LIGHT_LOGO, DARK_LOGO], [false, false], [LIGHT_LOGO, DARK_LOGO]], + ["local", [null, null], [true, true], ["/get_image", "/get_image?theme=dark"]], + ["public light and local dark", [LIGHT_LOGO, null], [false, true], [LIGHT_LOGO, "/get_image?theme=dark"]], + ["local light and public dark", [null, DARK_LOGO], [true, false], ["/get_image", DARK_LOGO]], + ["public light only", [LIGHT_LOGO, null], [false, false], [LIGHT_LOGO, LIGHT_LOGO]], + ["public dark only", [null, DARK_LOGO], [false, false], [DARK_LOGO, DARK_LOGO]], + ["local light only", [null, null], [true, false], ["/get_image", "/get_image"]], + ["local dark only", [null, null], [false, true], ["/get_image?theme=dark", "/get_image?theme=dark"]], + ] as const)( + "should render %s organization logos from the theme response", + async ( + _label, + [logo_url, logo_url_dark], + [logo_url_via_proxy, logo_url_dark_via_proxy], + [lightSource, darkSource], + ) => { + themeResponse = { values: { logo_url, logo_url_dark }, logo_url_via_proxy, logo_url_dark_via_proxy }; + const user = userEvent.setup(); + renderWithProviders( + +

Chat content

+ , + ); + + await user.click(screen.getByRole("button", { name: "Open chat navigation" })); + const logo = await screen.findByRole("img", { name: "Organization logo" }); + const [light, dark] = within(logo).getAllByAltText(""); + const source = (path: string) => (path.startsWith("/") ? `${getProxyBaseUrl()}${path}` : path); + expect(light).toHaveAttribute("src", source(lightSource)); + expect(dark).toHaveAttribute("src", source(darkSource)); + expect(light).toHaveClass("dark:hidden"); + expect(dark).toHaveClass("hidden", "dark:block"); + }, + ); + + it("should omit organization branding when no logo is configured", async () => { + const user = userEvent.setup(); + renderWithProviders( + +

Chat content

+
, + ); + + await user.click(screen.getByRole("button", { name: "Open chat navigation" })); + expect(await screen.findByRole("dialog", { name: "LiteLLM Chat" })).toBeInTheDocument(); + expect(screen.queryByRole("img", { name: "Organization logo" })).not.toBeInTheDocument(); + }); + it.each([ { pathname: "/ui/chat", root: "/", gateway: "/ui/" }, { pathname: "/gateway/ui/chat/models/", root: "/gateway", gateway: "/gateway/ui/" }, @@ -94,7 +145,6 @@ describe("Chat layout product navigation", () => { ); expect(screen.getByRole("heading", { name: "Chat content" })).toBeVisible(); - expect(recordChatQuery).not.toHaveBeenCalled(); await user.click(screen.getByRole("button", { name: "Switch workspace, current: Chat" })); expect(await screen.findByRole("menuitem", { name: "Observability" })).toBeInTheDocument(); expect(localStorage.getItem("litellm_plugin_mode")).toBe(plugin.name); @@ -103,7 +153,6 @@ describe("Chat layout product navigation", () => { expect(localStorage.getItem("litellm_plugin_mode")).toBe("ai-gateway"); expect(assign).toHaveBeenCalledWith(gateway); - expect(recordChatQuery).not.toHaveBeenCalled(); }, ); diff --git a/ui/litellm-dashboard/src/app/chat/layout.test.tsx b/ui/litellm-dashboard/src/app/chat/layout.test.tsx index 0b0cb96ddc9..a741a7725dd 100644 --- a/ui/litellm-dashboard/src/app/chat/layout.test.tsx +++ b/ui/litellm-dashboard/src/app/chat/layout.test.tsx @@ -3,7 +3,7 @@ import { act, fireEvent, screen } from "@testing-library/react"; import { renderWithProviders as render } from "@/../tests/test-utils"; import ChatLayout from "./layout"; -const { mockUseAuthorized, mockUseUISettings, mockReplace, mockUiHref, recordChatQuery, state } = vi.hoisted(() => { +const { mockUseAuthorized, mockUseUISettings, mockReplace, mockUiHref, state } = vi.hoisted(() => { const state = { enableChatUI: false, isUISettingsLoading: false, @@ -14,7 +14,6 @@ const { mockUseAuthorized, mockUseUISettings, mockReplace, mockUiHref, recordCha return { state, mockReplace: vi.fn(), - recordChatQuery: vi.fn(async () => {}), mockUiHref: vi.fn((segment: string) => `/mocked-ui/${segment}`), mockUseAuthorized: vi.fn(() => ({ accessToken: "token-123", @@ -38,7 +37,6 @@ vi.mock("next/navigation", () => ({ vi.mock("@/app/(dashboard)/hooks/useAuthorized", () => ({ default: mockUseAuthorized })); vi.mock("@/app/(dashboard)/hooks/uiSettings/useUISettings", () => ({ useUISettings: mockUseUISettings })); vi.mock("@/utils/uiHref", () => ({ uiHref: mockUiHref })); -vi.mock("@/lib/telemetry/chat", () => ({ recordChatQuery })); vi.mock("@/components/navbar", () => ({ default: () =>
})); vi.mock("@/contexts/ThemeContext", () => ({ ThemeProvider: ({ children }: { children: React.ReactNode }) => <>{children}, @@ -66,7 +64,6 @@ describe("ChatLayout", () => { state.userId = "user-1"; mockReplace.mockClear(); mockUiHref.mockClear(); - recordChatQuery.mockClear(); vi.restoreAllMocks(); vi.unstubAllGlobals(); }); @@ -81,7 +78,6 @@ describe("ChatLayout", () => { expect(screen.getByTestId("chat-shell")).toBeInTheDocument(); expect(screen.getByTestId("page-content")).toBeInTheDocument(); expect(mockReplace).not.toHaveBeenCalled(); - expect(recordChatQuery).not.toHaveBeenCalled(); }); it("should redirect without recording a query when enable_chat_ui is off", () => { @@ -93,7 +89,6 @@ describe("ChatLayout", () => { ); expect(screen.queryByTestId("chat-shell")).not.toBeInTheDocument(); expect(mockReplace).toHaveBeenCalledWith("/mocked-ui/"); - expect(recordChatQuery).not.toHaveBeenCalled(); }); it("should wait for UI settings without recording a query", () => { @@ -105,7 +100,6 @@ describe("ChatLayout", () => { ); expect(screen.queryByTestId("chat-shell")).not.toBeInTheDocument(); expect(mockReplace).not.toHaveBeenCalled(); - expect(recordChatQuery).not.toHaveBeenCalled(); }); it("should wait for the signed-in user's identity without recording a query", () => { @@ -118,7 +112,6 @@ describe("ChatLayout", () => { ); expect(screen.queryByTestId("chat-shell")).not.toBeInTheDocument(); expect(screen.queryByTestId("page-content")).not.toBeInTheDocument(); - expect(recordChatQuery).not.toHaveBeenCalled(); }); it("should hide Chat without recording a query when the signed-in user's identity cannot be confirmed", () => { @@ -131,7 +124,6 @@ describe("ChatLayout", () => { ); expect(screen.queryByTestId("chat-shell")).not.toBeInTheDocument(); expect(screen.queryByTestId("page-content")).not.toBeInTheDocument(); - expect(recordChatQuery).not.toHaveBeenCalled(); }); it("should not record a query or fetch telemetry when opening, focusing, or revisiting Chat", () => { @@ -140,11 +132,9 @@ describe("ChatLayout", () => { const view = render(Chat content); act(() => fireEvent.focus(window)); - expect(recordChatQuery).not.toHaveBeenCalled(); visibility.mockReturnValue("visible"); act(() => fireEvent(document, new Event("visibilitychange"))); - expect(recordChatQuery).not.toHaveBeenCalled(); view.rerender(Another Chat page); act(() => fireEvent.focus(window)); @@ -155,14 +145,12 @@ describe("ChatLayout", () => { fireEvent.focus(window); fireEvent(document, new Event("visibilitychange")); }); - expect(recordChatQuery).not.toHaveBeenCalled(); expect(fetch).not.toHaveBeenCalled(); }); it("should not record a query or fetch telemetry when the signed-in account changes", () => { state.enableChatUI = true; const view = render(Chat content); - expect(recordChatQuery).not.toHaveBeenCalled(); state.userId = "user-2"; view.rerender(Chat content); @@ -172,7 +160,6 @@ describe("ChatLayout", () => { state.isAuthorized = false; view.rerender(Chat content); act(() => fireEvent.focus(window)); - expect(recordChatQuery).not.toHaveBeenCalled(); expect(fetch).not.toHaveBeenCalled(); }); }); diff --git a/ui/litellm-dashboard/src/app/chat/page.images.integration.test.tsx b/ui/litellm-dashboard/src/app/chat/page.images.integration.test.tsx index f7bbf59c0cb..7e4401fc3ab 100644 --- a/ui/litellm-dashboard/src/app/chat/page.images.integration.test.tsx +++ b/ui/litellm-dashboard/src/app/chat/page.images.integration.test.tsx @@ -3,11 +3,8 @@ import userEvent from "@testing-library/user-event"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { renderWithProviders, testQueryClient } from "@/../tests/test-utils"; import { ChatShellProvider } from "@/contexts/ChatShellContext"; -import { recordChatQuery } from "@/lib/telemetry/chat"; import ChatConversationPage from "./page"; -vi.mock("@/lib/telemetry/chat", () => ({ recordChatQuery: vi.fn(async () => {}) })); - vi.mock("next/navigation", () => ({ useRouter: () => ({ push: vi.fn(), replace: vi.fn() }), })); @@ -67,10 +64,10 @@ async function chooseModel(user: ReturnType, current: st } beforeEach(() => { + vi.stubEnv("NODE_ENV", "production"); localStorage.clear(); testQueryClient.clear(); requests.length = 0; - vi.mocked(recordChatQuery).mockClear(); models = [ { model_group: "research-chat", mode: "chat", providers: ["openai"] }, { model_group: "studio-image", mode: "image_generation", providers: ["openai"] }, @@ -109,6 +106,11 @@ beforeEach(() => { }); afterEach(() => { + for (const [input] of vi.mocked(fetch).mock.calls) { + const url = input instanceof Request ? input.url : String(input); + expect(new URL(url, window.location.origin).origin).toBe(window.location.origin); + } + vi.unstubAllEnvs(); vi.unstubAllGlobals(); localStorage.clear(); }); @@ -121,10 +123,9 @@ describe("chat image workflows", () => { await userEvent.setup().click(screen.getByRole("button", { name: "research-chat", exact: true })); expect(await screen.findByRole("button", { name: /^studio-image/ })).toBeInTheDocument(); expect(screen.getByRole("button", { name: "Send" })).toBeDisabled(); - expect(recordChatQuery).not.toHaveBeenCalled(); }); - it("should upload a document as a file part, preserve it on edit, and keep contents out of metrics", async () => { + it("should upload a document as a file part, preserve it on edit", async () => { const user = userEvent.setup(); renderChat(); await screen.findByRole("button", { name: "research-chat" }); @@ -145,7 +146,6 @@ describe("chat image workflows", () => { "data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,cHJpdmF0ZSBmaXh0dXJl", }; expect(requests[0].body).toMatchObject({ input: [{ role: "user", content: [filePart] }] }); - expect(recordChatQuery).toHaveBeenCalledExactlyOnceWith("media-test-user"); await user.click(screen.getByRole("button", { name: "Edit message" })); act(() => fireEvent.change(screen.getByRole("textbox", { name: "Edit message" }), { @@ -175,7 +175,6 @@ describe("chat image workflows", () => { await user.click(await screen.findByRole("button", { name: "Remove note-0.txt" })); expect(screen.queryByText("note-0.txt")).not.toBeInTheDocument(); expect(screen.getByRole("button", { name: "Send" })).toBeDisabled(); - expect(recordChatQuery).not.toHaveBeenCalled(); }); it("should restore the selected chat model after switching modes and reopening the page", async () => { @@ -201,7 +200,6 @@ describe("chat image workflows", () => { expect(screen.queryByRole("img", { name: "diagram.png" })).not.toBeInTheDocument(); expect(screen.getByRole("button", { name: "Send" })).toBeDisabled(); expect(requests).toHaveLength(0); - expect(recordChatQuery).not.toHaveBeenCalled(); }); it("should send the image and preserve it when editing and resending the message", async () => { @@ -212,7 +210,6 @@ describe("chat image workflows", () => { await user.type(screen.getByRole("textbox", { name: "Message", exact: true }), "Explain this diagram"); await user.click(screen.getByRole("button", { name: "Send" })); await screen.findByText("I can see the uploaded image."); - expect(recordChatQuery).toHaveBeenCalledExactlyOnceWith("media-test-user"); expect(requests[0].body).toMatchObject({ model: "research-chat", input: [ @@ -246,7 +243,6 @@ describe("chat image workflows", () => { }); expect(requests[1].body).not.toHaveProperty("previous_response_id"); expect(screen.queryByText("Explain this diagram", { selector: "p" })).not.toBeInTheDocument(); - expect(recordChatQuery).toHaveBeenCalledTimes(2); }); it("should preserve a chat turn when editing it while an image model is selected", async () => { @@ -267,7 +263,6 @@ describe("chat image workflows", () => { expect(screen.getByRole("heading", { name: "Explain the experiment" })).toBeInTheDocument(); expect(screen.getByText("I can see the uploaded image.")).toBeInTheDocument(); expect(requests).toHaveLength(1); - expect(recordChatQuery).toHaveBeenCalledExactlyOnceWith("media-test-user"); }); it("should continue an image conversation using the completed response context", async () => { @@ -288,7 +283,6 @@ describe("chat image workflows", () => { }); it("should generate and render an image through the selected Model Hub model", async () => { - vi.mocked(recordChatQuery).mockReturnValueOnce(new Promise(() => {})); const user = userEvent.setup(); renderChat(); await screen.findByRole("button", { name: "research-chat" }); @@ -301,7 +295,6 @@ describe("chat image workflows", () => { expect(requests).toEqual([ { pathname: "/images/generations", body: { model: "studio-image", prompt: "A blue research lab" } }, ]); - expect(recordChatQuery).toHaveBeenCalledExactlyOnceWith("media-test-user"); }); it("should list no image models when the account has none permitted", async () => { @@ -327,7 +320,6 @@ describe("chat image workflows", () => { await user.click(screen.getByRole("button", { name: "Generate image" })); expect(await screen.findByText(/Image access is disabled for this key/)).toBeInTheDocument(); expect(screen.queryByRole("img", { name: "Generated image 1" })).not.toBeInTheDocument(); - expect(recordChatQuery).toHaveBeenCalledExactlyOnceWith("media-test-user"); }); it("should abort image generation when the user stops the request", async () => { @@ -346,12 +338,10 @@ describe("chat image workflows", () => { fireEvent.keyDown(screen.getByRole("textbox", { name: "Message", exact: true }), { key: "Enter" }); }); expect(requests).toHaveLength(1); - expect(recordChatQuery).toHaveBeenCalledExactlyOnceWith("media-test-user"); await user.click(screen.getByRole("button", { name: "Stop request" })); expect(generationSignal?.aborted).toBe(true); expect(await screen.findByText("[stopped]")).toBeInTheDocument(); expect(screen.queryByRole("img", { name: "Generated image 1" })).not.toBeInTheDocument(); - expect(recordChatQuery).toHaveBeenCalledTimes(1); }); it("should reject unsupported pasted files without issuing a request", async () => { @@ -364,7 +354,6 @@ describe("chat image workflows", () => { }); expect(await screen.findByRole("alert")).toHaveTextContent("Choose a PNG, JPEG, WebP, or GIF image."); expect(requests).toHaveLength(0); - expect(recordChatQuery).not.toHaveBeenCalled(); }); it("should not count a blank submission as a query", async () => { @@ -377,7 +366,6 @@ describe("chat image workflows", () => { fireEvent.keyDown(screen.getByRole("textbox", { name: "Message", exact: true }), { key: "Enter" }); }); expect(requests).toHaveLength(0); - expect(recordChatQuery).not.toHaveBeenCalled(); }); it("should count one query for a message that streams text and executes multiple MCP tools", async () => { @@ -390,7 +378,6 @@ describe("chat image workflows", () => { await user.click(serverSwitch); await waitFor(() => expect(screen.getByRole("switch")).toBeChecked()); await user.click(screen.getByRole("button", { name: "Connect tools" })); - expect(recordChatQuery).not.toHaveBeenCalled(); act(() => { fireEvent.change(screen.getByRole("textbox", { name: "Message", exact: true }), { @@ -404,6 +391,5 @@ describe("chat image workflows", () => { expect(requests[0].body).toMatchObject({ tools: [{ type: "mcp", server_label: "research-tools", require_approval: "never" }], }); - expect(recordChatQuery).toHaveBeenCalledExactlyOnceWith("media-test-user"); }); }); diff --git a/ui/litellm-dashboard/src/app/chat/page.mcp.integration.test.tsx b/ui/litellm-dashboard/src/app/chat/page.mcp.integration.test.tsx index 4c4612f1ba8..367935a42a2 100644 --- a/ui/litellm-dashboard/src/app/chat/page.mcp.integration.test.tsx +++ b/ui/litellm-dashboard/src/app/chat/page.mcp.integration.test.tsx @@ -7,7 +7,6 @@ import type { Conversation, MCPEvent } from "@/components/chat/types"; import ChatConversationPage from "./page"; vi.mock("next/navigation", () => ({ useRouter: () => ({ push: vi.fn(), replace: vi.fn() }) })); -vi.mock("@/lib/telemetry/chat", () => ({ recordChatQuery: vi.fn(async () => {}) })); const userId = "mcp-replay-user"; const storageKey = `litellm_chat_history_v1:${userId}`; diff --git a/ui/litellm-dashboard/src/app/chat/page.tsx b/ui/litellm-dashboard/src/app/chat/page.tsx index 0af45cbbcf3..1e8f29642be 100644 --- a/ui/litellm-dashboard/src/app/chat/page.tsx +++ b/ui/litellm-dashboard/src/app/chat/page.tsx @@ -25,7 +25,6 @@ import { runChatRequest } from "@/components/chat/runChatRequest"; import { readChatAttachment, MAX_CHAT_ATTACHMENTS, CHAT_ATTACHMENT_ACCEPT } from "@/components/chat/attachmentHelpers"; import ChatFileChip from "@/components/chat/ChatFileChip"; import { useQueryState } from "nuqs"; -import { recordChatQuery } from "@/lib/telemetry/chat"; const LOCALSTORAGE_MODEL_KEY = "litellm_chat_selected_model"; @@ -81,7 +80,6 @@ export default function ChatConversationPage() { const router = useRouter(); const { accessToken, - userId, conversations, selectedMCPServers, setSelectedMCPServers, @@ -323,7 +321,6 @@ export default function ChatConversationPage() { onUpdate: (updates: AssistantMessageUpdate) => updateLastAssistantMessage(convId, updates), }; try { - void recordChatQuery(userId); await runChatRequest(request); } finally { if (abortControllerRef.current === requestController) { @@ -343,7 +340,6 @@ export default function ChatConversationPage() { mode, attachments, accessToken, - userId, createConversation, appendMessage, updateLastAssistantMessage, diff --git a/ui/litellm-dashboard/src/components/DashboardHeader.test.tsx b/ui/litellm-dashboard/src/components/DashboardHeader.test.tsx index 770315af49f..202a111ea97 100644 --- a/ui/litellm-dashboard/src/components/DashboardHeader.test.tsx +++ b/ui/litellm-dashboard/src/components/DashboardHeader.test.tsx @@ -124,7 +124,8 @@ describe("DashboardHeader breadcrumb", () => { const tools = await screen.findByRole("dialog", { name: "Gateway tools" }); expect(within(tools).getByRole("button", { name: "Switch workspace, current: AI Gateway" })).toBeInTheDocument(); expect(within(tools).getByRole("link", { name: "Docs" })).toBeInTheDocument(); - expect(within(tools).getByRole("button", { name: "Aria Agent" })).toBeInTheDocument(); + expect(within(screen.getByRole("banner")).getByRole("button", { name: "Aria Agent" })).toBeInTheDocument(); + expect(screen.getAllByRole("button", { name: "Aria Agent" })).toHaveLength(1); }); it("closes mobile tools when switching to desktop and keeps them closed when returning", async () => { diff --git a/ui/litellm-dashboard/src/components/DashboardHeader.tsx b/ui/litellm-dashboard/src/components/DashboardHeader.tsx index b31fc794f79..55f163c2495 100644 --- a/ui/litellm-dashboard/src/components/DashboardHeader.tsx +++ b/ui/litellm-dashboard/src/components/DashboardHeader.tsx @@ -73,43 +73,46 @@ export function DashboardHeader({ -
- {showWorkerSwitch && ( - <> - - - - )} +
- - - {!hideCommunityLinks && } - - - {deploymentHealth} - -
-
- - {deploymentHealth} - - - }> - - - - Gateway tools - - {showWorkerSwitch && } -
- - - - - {!hideCommunityLinks && } -
-
-
+
+ {showWorkerSwitch && ( + <> + + + + )} + + + {!hideCommunityLinks && } + + + {deploymentHealth} + +
+
+ + {deploymentHealth} + + + } + > + + + + Gateway tools + + {showWorkerSwitch && } +
+ + + + {!hideCommunityLinks && } +
+
+
+
); diff --git a/ui/litellm-dashboard/src/components/ModelInfoEditForm.tsx b/ui/litellm-dashboard/src/components/ModelInfoEditForm.tsx index 70fe23202bf..085334567ed 100644 --- a/ui/litellm-dashboard/src/components/ModelInfoEditForm.tsx +++ b/ui/litellm-dashboard/src/components/ModelInfoEditForm.tsx @@ -34,7 +34,7 @@ import type { Tag } from "./tag_management/types"; import { ModelTeamSelect } from "./view_model/ModelTeamSelect"; import VectorStoreSelector from "./vector_store_management/VectorStoreSelector"; import { formatPtuUtcDisplay, utcIsoToPickerValue } from "../utils/ptuDatetime"; -import { isMaskedSecret } from "../utils/maskedSecretUtils"; +import { editableModelExtraParams, parseModelExtraParams } from "../utils/modelEditParams"; import { MAX_COST_PER_PTU_PER_HOUR, MAX_PTU_COUNT, @@ -127,22 +127,13 @@ const modelEditShape = { type ModelEditFieldName = keyof typeof modelEditShape; -const isJson = (value: string): boolean => { - try { - JSON.parse(value); - return true; - } catch { - return false; - } -}; - const buildSchema = (ptuEnabled: boolean, isFieldTouched: (field: TouchedPricingField) => boolean) => z.object(modelEditShape).superRefine((values, ctx) => { const reject = (path: ModelEditFieldName, message: string) => ctx.addIssue({ code: "custom", path: [path], message }); - if (values.litellm_extra_params && !isJson(values.litellm_extra_params)) { - reject("litellm_extra_params", "Please enter valid JSON"); + if (parseModelExtraParams(values.litellm_extra_params) === null) { + reject("litellm_extra_params", "Please enter a valid JSON object"); } // antd validates only mounted fields, and the PTU block does not render when the flag is off. @@ -245,15 +236,7 @@ export const toModelEditFormValues = (localModelData: any, isWildcardModel: bool // antd never mounted this field for a non-wildcard model, so the key must be absent, not null. ...(isWildcardModel ? { health_check_model: localModelData.model_info?.health_check_model } : {}), litellm_credential_name: localModelData.litellm_params?.litellm_credential_name ?? null, - litellm_extra_params: JSON.stringify( - Object.fromEntries( - Object.entries(localModelData.litellm_params || {}).filter( - ([key, value]) => key !== "litellm_credential_name" && !isMaskedSecret(value), - ), - ), - null, - 2, - ), + litellm_extra_params: JSON.stringify(editableModelExtraParams(localModelData.litellm_params ?? {}), null, 2), team_id: localModelData.model_info?.team_id ?? undefined, }); @@ -775,7 +758,7 @@ const ModelInfoEditForm: React.FC = ({ LiteLLM Params @@ -784,9 +767,10 @@ const ModelInfoEditForm: React.FC = ({ {({ value, ...control }) => (