From adc4c01aa91ef71ccf088bc49996d99368cb8ecf Mon Sep 17 00:00:00 2001 From: Yassin Kortam Date: Wed, 11 Nov 2026 20:19:57 -0800 Subject: [PATCH] chore: move scripts and runtime sources under litellm (#51006) Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .agents/skills/database-access/SKILL.md | 73 ------- .../references/python-fastapi.md | 101 --------- .../references/python-repository.md | 119 ---------- .../database-access/references/rust-axum.md | 4 - .agents/skills/litellm-setup/SKILL.md | 205 ------------------ .github/CODEOWNERS | 2 +- .github/CONTRIBUTING.md | 2 +- .../actions/setup-uv-with-retries/action.yml | 5 + .gitguardian.yaml => .github/gitguardian.yaml | 0 .github/scripts/ci/classify_changes.sh | 4 +- .github/scripts/setup_rust_environment.sh | 13 ++ .github/scripts/verify_linux_native_wheel.py | 3 + .github/workflows/auto-close-duplicates.yml | 8 +- .github/workflows/check-schema-sync.yml | 20 +- .github/workflows/conventional-commits.yml | 4 +- .github/workflows/cost-map-guard.yml | 5 +- .github/workflows/cost-map-pins-recheck.yml | 6 +- .github/workflows/duplicate_issue_check.yml | 12 +- .github/workflows/image-scan.yml | 13 +- .github/workflows/issue_classifier.yml | 22 +- .github/workflows/issue_fixed_comment.yml | 12 +- .github/workflows/issue_label_sync.yml | 14 +- .github/workflows/mutation-test.yml | 2 +- .../workflows/publish-lint-base-counts.yml | 14 +- .github/workflows/spend-logs-guard.yml | 5 +- .github/workflows/sync-schema.yml | 12 +- .github/workflows/test-linting.yml | 20 +- .../test-mcp-dependency-resolution.yml | 19 +- .github/workflows/test-merge-smoke.yml | 2 +- .github/workflows/test-rust-db.yml | 8 +- .github/workflows/test-rust.yml | 26 ++- .github/workflows/test-unit.yml | 4 +- .gitignore | 2 +- AGENTS.md | 8 +- Makefile | 36 +-- README.md | 2 +- litellm/deploy/docker/Dockerfile | 16 +- litellm/deploy/docker/README.md | 8 +- litellm/deploy/docker/docker-entrypoint.sh | 8 +- .../helm/litellm/templates/_helpers.tpl | 4 +- .../helm/litellm/templates/ingress.yaml | 2 +- litellm/deploy/terraform/litellm/README.md | 2 +- .../deploy/terraform/litellm/aws/locals.tf | 2 +- .../deploy/terraform/litellm/gcp/locals.tf | 2 +- litellm/packaging/litellm-core/pyproject.toml | 9 +- .../packaging/litellm-proxy/pyproject.toml | 4 +- .../request_log_indexes.py | 2 +- .../litellm_proxy_extras/utils.py | 8 +- litellm/proxy-extras/migration_runbook.md | 24 +- litellm/proxy/_types.py | 2 +- litellm/proxy/client/cli/README.md | 8 +- .../client/cli/commands/autoroute/commands.py | 2 +- litellm/proxy/db/create_views.py | 2 +- .../spend_logs_partition_manager.py | 2 +- {backend => litellm/runtime/backend}/main.py | 8 +- .../runtime/backend}/routes/__init__.py | 0 .../runtime/backend}/routes/allowlist.py | 0 .../runtime/gateway}/AGENTS.md | 0 .../runtime/gateway}/launch.py | 2 +- {gateway => litellm/runtime/gateway}/main.py | 0 .../runtime/gateway}/routes/__init__.py | 0 .../runtime/gateway}/routes/allowlist.py | 0 .../runtime/migrations}/run.py | 0 {.cargo => litellm/rust/.cargo}/config.toml | 0 .../rust/rust-toolchain.toml | 0 schema.prisma => litellm/schema.prisma | 0 .../scripts}/adaptive_router_demo/README.md | 4 +- .../scripts}/adaptive_router_demo/chat.html | 0 .../adaptive_router_demo/dashboard.html | 0 .../scripts}/adaptive_router_demo/eval.py | 2 +- .../scripts}/adaptive_router_demo/traffic.py | 2 +- .../scripts}/auto-close-duplicates.test.ts | 0 .../scripts}/auto-close-duplicates.ts | 0 .../benchmark_anthropic_messages_perf.py | 4 +- .../benchmark_chat_completions_perf.py | 4 +- .../scripts}/benchmark_mock.py | 0 .../benchmark_model_response_creator.py | 4 +- .../scripts}/benchmark_ocr_callbacks.py | 4 +- .../scripts}/benchmark_proxy_vs_provider.py | 16 +- .../benchmark_streaming_chunk_overhead.py | 2 +- .../scripts}/build_core_distribution.py | 9 +- .../scripts}/check_mcp_operation_boundary.py | 0 .../scripts}/check_mcp_sdk_install.py | 0 .../scripts}/check_openapi_docs.py | 2 +- .../scripts}/check_schema_compatibility.py | 15 +- .../scripts}/check_test_quality.py | 4 +- .../scripts}/check_type_discipline.py | 4 + .../scripts}/ci_cd/TEST_KEY_PATTERNS.md | 2 +- .../scripts}/ci_cd/check_file_length.py | 0 .../scripts}/ci_cd/check_files_match.py | 0 .../scripts}/ci_cd/cost_map_guard.py | 10 +- .../scripts/ci_cd}/cost_map_pins.json | 0 .../scripts}/ci_cd/run_migration.py | 4 +- .../scripts}/ci_cd/security_scans_readme.md | 0 .../scripts}/ci_cd/spend_logs_guard.py | 1 + .../scripts}/classify-issue.test.ts | 4 +- .../scripts}/classify-issue.ts | 4 +- .../scripts}/comment-fixed-issue.test.ts | 0 .../scripts}/comment-fixed-issue.ts | 0 .../scripts}/create_litellm_branch.ps1 | 0 .../scripts}/create_litellm_branch.sh | 0 .../create_team_key_and_submit_guardrail.sh | 0 .../scripts}/db/backfill_daily_tool_spend.sql | 2 +- .../scripts}/db/backfill_key_total_spend.sql | 4 +- ...ckfill_key_total_spend_from_spend_logs.sql | 4 +- .../scripts}/db/create_views.py | 0 .../scripts}/db/migrate_keys.py | 0 .../scripts}/db/partition_spend_logs.sql | 2 +- .../strip_vector_store_internal_metadata.py | 0 .../scripts}/db/unpartition_spend_logs.sql | 2 +- .../scripts}/db/update_unassigned_teams.py | 0 .../scripts}/default_branch.py | 0 .../scripts}/eval_compression.py | 6 +- .../scripts}/flag-duplicate-issue.test.ts | 0 .../scripts}/flag-duplicate-issue.ts | 0 .../scripts}/gate_slot_lock.py | 6 +- .../generate_provider_endpoints_support.py | 4 +- .../scripts}/generate_trace_types.py | 6 +- .../scripts}/githooks/commit-msg | 0 .../benchmark_get_all_latest_health_checks.py | 0 .../health_check/health_check_client.py | 0 .../health_check_client_README.md | 24 +- .../health_check_requirements.txt | 0 .../run_parallel_health_checks.ps1 | 0 .../run_parallel_health_checks.sh | 0 {scripts => litellm/scripts}/install-cli.sh | 6 +- {scripts => litellm/scripts}/install.sh | 4 +- .../scripts}/install_git_hooks.sh | 8 +- {scripts => litellm/scripts}/issue-labels.ts | 2 +- .../scripts}/label-issue.test.ts | 0 {scripts => litellm/scripts}/label-issue.ts | 0 ...missing_request_id_simple_spend_logs.jsonl | 0 ..._missing_request_id_swarm_spend_logs.jsonl | 0 .../claude_agent_sdk_simple_spend_logs.jsonl | 0 .../claude_agent_sdk_swarm_spend_logs.jsonl | 0 .../spend/crewai_simple_spend_logs.jsonl | 0 .../spend/crewai_swarm_spend_logs.jsonl | 0 .../spend/deepagents_simple_spend_logs.jsonl | 0 .../spend/deepagents_swarm_spend_logs.jsonl | 0 ...google_adk_billed_failure_spend_logs.jsonl | 0 .../spend/google_adk_retry_spend_logs.jsonl | 0 .../spend/google_adk_simple_spend_logs.jsonl | 0 .../spend/google_adk_stream_spend_logs.jsonl | 0 .../spend/google_adk_swarm_spend_logs.jsonl | 0 .../spend/langchain_simple_spend_logs.jsonl | 0 .../spend/langchain_swarm_spend_logs.jsonl | 0 .../spend/langgraph_simple_spend_logs.jsonl | 0 .../spend/langgraph_swarm_spend_logs.jsonl | 0 .../spend/llamaindex_simple_spend_logs.jsonl | 0 .../spend/llamaindex_swarm_spend_logs.jsonl | 0 .../spend/mastra_simple_spend_logs.jsonl | 0 .../spend/mastra_swarm_spend_logs.jsonl | 0 .../openai_agents_simple_spend_logs.jsonl | 0 .../openai_agents_swarm_spend_logs.jsonl | 0 .../opentelemetry_simple_spend_logs.jsonl | 0 .../opentelemetry_swarm_spend_logs.jsonl | 0 ...ydantic_ai_billed_failure_spend_logs.jsonl | 0 .../spend/pydantic_ai_retry_spend_logs.jsonl | 0 .../spend/pydantic_ai_simple_spend_logs.jsonl | 0 .../spend/pydantic_ai_stream_spend_logs.jsonl | 0 .../spend/pydantic_ai_swarm_spend_logs.jsonl | 0 .../pydantic_ai_swarm_stream_spend_logs.jsonl | 0 ...ntic_ai_token_limit_swarm_spend_logs.jsonl | 0 .../fixtures/spend/spend_logs.jsonl | 0 .../strands_billed_failure_spend_logs.jsonl | 0 .../spend/strands_retry_spend_logs.jsonl | 0 .../spend/strands_simple_spend_logs.jsonl | 0 .../spend/strands_swarm_spend_logs.jsonl | 0 ...cel_ai_sdk_billed_failure_spend_logs.jsonl | 0 .../vercel_ai_sdk_py_simple_spend_logs.jsonl | 0 .../vercel_ai_sdk_py_swarm_spend_logs.jsonl | 0 .../vercel_ai_sdk_retry_spend_logs.jsonl | 0 .../vercel_ai_sdk_simple_spend_logs.jsonl | 0 .../vercel_ai_sdk_stream_spend_logs.jsonl | 0 .../vercel_ai_sdk_swarm_spend_logs.jsonl | 0 .../claude_agent_sdk_detailed_export.json | 0 .../traces/claude_agent_sdk_export.json | 0 ...e_agent_sdk_missing_request_id_simple.json | 0 ...de_agent_sdk_missing_request_id_swarm.json | 0 .../traces/claude_agent_sdk_simple.json | 0 .../traces/claude_agent_sdk_swarm.json | 0 .../traces/claude_code_native_logs.json | 0 .../claude_code_native_tool_result.json | 0 .../traces/claude_code_native_traces.json | 0 .../fixtures/traces/crewai_simple.json | 0 .../fixtures/traces/crewai_swarm.json | 0 .../fixtures/traces/deepagents_simple.json | 0 .../fixtures/traces/deepagents_swarm.json | 0 .../traces/google_adk_billed_failure.json | 0 .../fixtures/traces/google_adk_retry.json | 0 .../fixtures/traces/google_adk_simple.json | 0 .../fixtures/traces/google_adk_stream.json | 0 .../fixtures/traces/google_adk_swarm.json | 0 .../fixtures/traces/langchain_simple.json | 0 .../fixtures/traces/langchain_swarm.json | 0 .../fixtures/traces/langgraph_simple.json | 0 .../fixtures/traces/langgraph_swarm.json | 0 .../traces/langsmith_deep_agent_export.json | 0 .../fixtures/traces/llamaindex_simple.json | 0 .../fixtures/traces/llamaindex_swarm.json | 0 .../fixtures/traces/mastra_simple.json | 0 .../fixtures/traces/mastra_swarm.json | 0 .../fixtures/traces/openai_agents_simple.json | 0 .../fixtures/traces/openai_agents_swarm.json | 0 .../fixtures/traces/opentelemetry_simple.json | 0 .../fixtures/traces/opentelemetry_swarm.json | 0 .../traces/pydantic_ai_billed_failure.json | 0 .../fixtures/traces/pydantic_ai_retry.json | 0 .../fixtures/traces/pydantic_ai_simple.json | 0 .../fixtures/traces/pydantic_ai_stream.json | 0 .../fixtures/traces/pydantic_ai_swarm.json | 0 .../traces/pydantic_ai_swarm_stream.json | 0 .../traces/pydantic_ai_token_limit_swarm.json | 0 .../fixtures/traces/query_alternate.json | 0 .../fixtures/traces/query_children.json | 0 .../fixtures/traces/query_other_team.json | 0 .../fixtures/traces/query_root.json | 0 .../traces/strands_billed_failure.json | 0 .../fixtures/traces/strands_retry.json | 0 .../fixtures/traces/strands_simple.json | 0 .../fixtures/traces/strands_swarm.json | 0 .../traces/vercel_ai_sdk_billed_failure.json | 0 .../traces/vercel_ai_sdk_py_simple.json | 0 .../traces/vercel_ai_sdk_py_swarm.json | 0 .../fixtures/traces/vercel_ai_sdk_retry.json | 0 .../fixtures/traces/vercel_ai_sdk_simple.json | 0 .../fixtures/traces/vercel_ai_sdk_stream.json | 0 .../fixtures/traces/vercel_ai_sdk_swarm.json | 0 .../schemas/models/ReadQueryName.json | 0 .../schemas/models/TraceAgentRow.json | 0 .../schemas/models/TraceAgentsParams.json | 0 .../schemas/models/TraceQueryHelp.json | 0 .../schemas/requests/TraceDetailRequest.json | 0 .../requests/TraceErrorPageRequest.json | 0 .../schemas/requests/TraceListRequest.json | 0 .../schemas/requests/TraceQueryRequest.json | 0 .../schemas/requests/TraceSpanRequest.json | 0 .../schemas/responses/TraceSQLResponse.json | 0 .../lens_assets/schemas/types/QueryScope.json | 0 .../lens_assets/schemas/types/SpanDetail.json | 0 .../schemas/types/SpanErrorPage.json | 0 .../lens_assets/schemas/types/Tenant.json | 0 .../lens_assets/schemas/types/Trace.json | 0 .../lens_assets/schemas/types/TracePage.json | 0 .../lens_assets/schemas/types/TraceScope.json | 0 .../scripts}/lens_assets/source.json | 0 .../scripts}/lint_base_counts.py | 6 +- .../mock_bedrock_passthrough_target.py | 4 +- .../scripts}/mock_grayswan_timeout_server.py | 2 +- .../scripts}/mutation_report.py | 2 +- .../scripts}/openapi_docs_gate.py | 16 +- .../scripts}/pre_commit_lint.sh | 22 +- .../scripts}/prisma_generate_if_needed.py | 2 +- {scripts => litellm/scripts}/quickstart.ps1 | 10 +- {scripts => litellm/scripts}/quickstart.sh | 12 +- .../scripts}/ruff_strict_gate.py | 4 +- .../scripts}/seed_request_logs.py | 2 +- .../scripts}/seed_tracing_fixtures.py | 6 +- .../scripts}/sync-issue-labels.test.ts | 0 .../scripts}/sync-issue-labels.ts | 0 .../scripts}/test_agent_mcp_endpoints.sh | 0 .../test_guardrails_register_endpoints.sh | 0 .../scripts}/test_quality_gate.py | 16 +- .../scripts}/test_tool_allowlist_script.py | 4 +- .../scripts}/tpm_headline_test.sh | 2 +- .../scripts}/trace_codegen/README.md | 6 +- .../scripts}/trace_codegen/config.json | 2 +- .../templates/ScalarTypeAliasType.jinja2 | 0 .../templates/TypeAliasType.jinja2 | 0 .../templates/TypedDictClass.jinja2 | 0 .../templates/pydantic_v2/BaseModel.jinja2 | 0 .../templates/pydantic_v2/types.jinja2 | 0 .../trace_codegen/templates/types.jinja2 | 0 .../scripts}/type_check_gate.py | 8 +- .../scripts}/type_discipline_gate.py | 14 +- .../scripts}/verify_adaptive_router.py | 2 +- .../scripts}/with_dashboard_node.sh | 2 +- litellm/tracing/AGENTS.md | 2 +- litellm/tracing/generated/models.py | 2 +- litellm/tracing/generated/requests.py | 2 +- litellm/tracing/generated/responses.py | 2 +- litellm/tracing/generated/types.py | 2 +- litellm/types/interactions/README.md | 2 +- .../src/lib/http/schema.d.ts | 2 +- pyproject.toml | 25 ++- scripts/ci_cd/baseline_db.py | 60 ----- .../base_sdk_tests/test_core_distribution.py | 40 ++-- .../check_migrations_no_data_rewrites.py | 2 +- .../ensure_async_clients_test.py | 10 +- ...est_generate_provider_endpoints_support.py | 4 +- tests/integration/README.md | 4 +- tests/integration/_support/process.py | 11 +- .../database/image/test_image_admin_mcp.py | 2 +- .../migrations/test_db_schema_migration.py | 6 +- .../migrations/test_request_log_indexes.py | 2 +- .../test_request_log_indexes_at_boot.py | 4 +- .../database/test_spend_lock_order.py | 2 +- .../database/test_spendlogs_ledger_parity.py | 2 +- ...st_strip_vector_store_internal_metadata.py | 2 +- tests/unit/gateway/test_launch.py | 4 +- .../unit/integration_support/test_process.py | 28 +++ .../test_litellm_proxy_extras_utils.py | 2 +- tests/unit/proxy/db/test_prisma_query_span.py | 2 +- .../proxy/test_claude_code_marketplace.py | 2 +- tests/unit/proxy/test_component_allowlists.py | 15 +- tests/unit/proxy/test_db_schema_changes.py | 2 +- .../test_verify_linux_native_wheel.py | 4 + .../unit/test_check_mcp_operation_boundary.py | 4 +- tests/unit/test_check_openapi_docs.py | 2 +- tests/unit/test_check_test_quality.py | 4 +- tests/unit/test_check_type_discipline.py | 4 +- tests/unit/test_ci_path_filter.py | 4 +- tests/unit/test_cost_map_guard.py | 23 +- tests/unit/test_default_branch.py | 14 +- tests/unit/test_docker_entrypoint.py | 12 +- tests/unit/test_gate_slot_lock.py | 2 +- tests/unit/test_git_hooks.py | 4 +- tests/unit/test_lint_base_counts.py | 2 +- tests/unit/test_lint_workflow_diff_gates.py | 2 +- tests/unit/test_mutation_report.py | 4 +- tests/unit/test_openapi_docs_gate.py | 4 +- tests/unit/test_pre_commit_lint.py | 14 +- tests/unit/test_prisma_generate_if_needed.py | 2 +- tests/unit/test_repo_agent_skills.py | 68 ------ tests/unit/test_seed_tracing_fixtures.py | 4 +- tests/unit/test_spend_logs_guard.py | 16 +- tests/unit/test_test_quality_gate.py | 6 +- tests/unit/test_type_discipline_gate.py | 2 +- tests/unit/test_with_dashboard_node.py | 2 +- 329 files changed, 610 insertions(+), 1087 deletions(-) delete mode 100644 .agents/skills/database-access/SKILL.md delete mode 100644 .agents/skills/database-access/references/python-fastapi.md delete mode 100644 .agents/skills/database-access/references/python-repository.md delete mode 100644 .agents/skills/database-access/references/rust-axum.md delete mode 100644 .agents/skills/litellm-setup/SKILL.md rename .gitguardian.yaml => .github/gitguardian.yaml (100%) create mode 100644 .github/scripts/setup_rust_environment.sh rename {backend => litellm/runtime/backend}/main.py (85%) rename {backend => litellm/runtime/backend}/routes/__init__.py (100%) rename {backend => litellm/runtime/backend}/routes/allowlist.py (100%) rename {gateway => litellm/runtime/gateway}/AGENTS.md (100%) rename {gateway => litellm/runtime/gateway}/launch.py (98%) rename {gateway => litellm/runtime/gateway}/main.py (100%) rename {gateway => litellm/runtime/gateway}/routes/__init__.py (100%) rename {gateway => litellm/runtime/gateway}/routes/allowlist.py (100%) rename {migrations => litellm/runtime/migrations}/run.py (100%) rename {.cargo => litellm/rust/.cargo}/config.toml (100%) rename rust-toolchain.toml => litellm/rust/rust-toolchain.toml (100%) rename schema.prisma => litellm/schema.prisma (100%) rename {scripts => litellm/scripts}/adaptive_router_demo/README.md (98%) rename {scripts => litellm/scripts}/adaptive_router_demo/chat.html (100%) rename {scripts => litellm/scripts}/adaptive_router_demo/dashboard.html (100%) rename {scripts => litellm/scripts}/adaptive_router_demo/eval.py (99%) rename {scripts => litellm/scripts}/adaptive_router_demo/traffic.py (99%) rename {scripts => litellm/scripts}/auto-close-duplicates.test.ts (100%) rename {scripts => litellm/scripts}/auto-close-duplicates.ts (100%) rename {scripts => litellm/scripts}/benchmark_anthropic_messages_perf.py (99%) rename {scripts => litellm/scripts}/benchmark_chat_completions_perf.py (99%) rename {scripts => litellm/scripts}/benchmark_mock.py (100%) rename {scripts => litellm/scripts}/benchmark_model_response_creator.py (96%) rename {scripts => litellm/scripts}/benchmark_ocr_callbacks.py (98%) rename {scripts => litellm/scripts}/benchmark_proxy_vs_provider.py (98%) rename {scripts => litellm/scripts}/benchmark_streaming_chunk_overhead.py (99%) rename {scripts => litellm/scripts}/build_core_distribution.py (93%) rename {scripts => litellm/scripts}/check_mcp_operation_boundary.py (100%) rename {scripts => litellm/scripts}/check_mcp_sdk_install.py (100%) rename {scripts => litellm/scripts}/check_openapi_docs.py (96%) rename {scripts => litellm/scripts}/check_schema_compatibility.py (86%) rename {scripts => litellm/scripts}/check_test_quality.py (99%) rename {scripts => litellm/scripts}/check_type_discipline.py (99%) rename {scripts => litellm/scripts}/ci_cd/TEST_KEY_PATTERNS.md (94%) rename {scripts => litellm/scripts}/ci_cd/check_file_length.py (100%) rename {scripts => litellm/scripts}/ci_cd/check_files_match.py (100%) rename {scripts => litellm/scripts}/ci_cd/cost_map_guard.py (96%) rename {ci_cd => litellm/scripts/ci_cd}/cost_map_pins.json (100%) rename {scripts => litellm/scripts}/ci_cd/run_migration.py (99%) rename {scripts => litellm/scripts}/ci_cd/security_scans_readme.md (100%) rename {scripts => litellm/scripts}/ci_cd/spend_logs_guard.py (99%) rename {scripts => litellm/scripts}/classify-issue.test.ts (99%) rename {scripts => litellm/scripts}/classify-issue.ts (98%) rename {scripts => litellm/scripts}/comment-fixed-issue.test.ts (100%) rename {scripts => litellm/scripts}/comment-fixed-issue.ts (100%) rename {scripts => litellm/scripts}/create_litellm_branch.ps1 (100%) rename {scripts => litellm/scripts}/create_litellm_branch.sh (100%) rename {scripts => litellm/scripts}/create_team_key_and_submit_guardrail.sh (100%) rename {scripts => litellm/scripts}/db/backfill_daily_tool_spend.sql (97%) rename {scripts => litellm/scripts}/db/backfill_key_total_spend.sql (92%) rename {scripts => litellm/scripts}/db/backfill_key_total_spend_from_spend_logs.sql (95%) rename {scripts => litellm/scripts}/db/create_views.py (100%) rename {scripts => litellm/scripts}/db/migrate_keys.py (100%) rename {scripts => litellm/scripts}/db/partition_spend_logs.sql (99%) rename {scripts => litellm/scripts}/db/strip_vector_store_internal_metadata.py (100%) rename {scripts => litellm/scripts}/db/unpartition_spend_logs.sql (97%) rename {scripts => litellm/scripts}/db/update_unassigned_teams.py (100%) rename {scripts => litellm/scripts}/default_branch.py (100%) rename {scripts => litellm/scripts}/eval_compression.py (99%) rename {scripts => litellm/scripts}/flag-duplicate-issue.test.ts (100%) rename {scripts => litellm/scripts}/flag-duplicate-issue.ts (100%) rename {scripts => litellm/scripts}/gate_slot_lock.py (96%) rename {scripts => litellm/scripts}/generate_provider_endpoints_support.py (98%) rename {scripts => litellm/scripts}/generate_trace_types.py (97%) rename {scripts => litellm/scripts}/githooks/commit-msg (100%) rename {scripts => litellm/scripts}/health_check/benchmark_get_all_latest_health_checks.py (100%) rename {scripts => litellm/scripts}/health_check/health_check_client.py (100%) rename {scripts => litellm/scripts}/health_check/health_check_client_README.md (90%) rename {scripts => litellm/scripts}/health_check/health_check_requirements.txt (100%) rename {scripts => litellm/scripts}/health_check/run_parallel_health_checks.ps1 (100%) rename {scripts => litellm/scripts}/health_check/run_parallel_health_checks.sh (100%) rename {scripts => litellm/scripts}/install-cli.sh (97%) rename {scripts => litellm/scripts}/install.sh (98%) rename {scripts => litellm/scripts}/install_git_hooks.sh (81%) rename {scripts => litellm/scripts}/issue-labels.ts (94%) rename {scripts => litellm/scripts}/label-issue.test.ts (100%) rename {scripts => litellm/scripts}/label-issue.ts (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/claude_agent_sdk_missing_request_id_simple_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/claude_agent_sdk_missing_request_id_swarm_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/claude_agent_sdk_simple_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/claude_agent_sdk_swarm_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/crewai_simple_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/crewai_swarm_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/deepagents_simple_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/deepagents_swarm_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/google_adk_billed_failure_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/google_adk_retry_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/google_adk_simple_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/google_adk_stream_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/google_adk_swarm_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/langchain_simple_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/langchain_swarm_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/langgraph_simple_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/langgraph_swarm_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/llamaindex_simple_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/llamaindex_swarm_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/mastra_simple_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/mastra_swarm_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/openai_agents_simple_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/openai_agents_swarm_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/opentelemetry_simple_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/opentelemetry_swarm_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/pydantic_ai_billed_failure_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/pydantic_ai_retry_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/pydantic_ai_simple_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/pydantic_ai_stream_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/pydantic_ai_swarm_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/pydantic_ai_swarm_stream_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/pydantic_ai_token_limit_swarm_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/strands_billed_failure_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/strands_retry_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/strands_simple_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/strands_swarm_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/vercel_ai_sdk_billed_failure_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/vercel_ai_sdk_py_simple_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/vercel_ai_sdk_py_swarm_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/vercel_ai_sdk_retry_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/vercel_ai_sdk_simple_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/vercel_ai_sdk_stream_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/spend/vercel_ai_sdk_swarm_spend_logs.jsonl (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/claude_agent_sdk_detailed_export.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/claude_agent_sdk_export.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/claude_agent_sdk_missing_request_id_simple.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/claude_agent_sdk_missing_request_id_swarm.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/claude_agent_sdk_simple.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/claude_agent_sdk_swarm.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/claude_code_native_logs.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/claude_code_native_tool_result.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/claude_code_native_traces.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/crewai_simple.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/crewai_swarm.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/deepagents_simple.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/deepagents_swarm.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/google_adk_billed_failure.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/google_adk_retry.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/google_adk_simple.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/google_adk_stream.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/google_adk_swarm.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/langchain_simple.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/langchain_swarm.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/langgraph_simple.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/langgraph_swarm.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/langsmith_deep_agent_export.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/llamaindex_simple.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/llamaindex_swarm.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/mastra_simple.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/mastra_swarm.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/openai_agents_simple.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/openai_agents_swarm.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/opentelemetry_simple.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/opentelemetry_swarm.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/pydantic_ai_billed_failure.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/pydantic_ai_retry.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/pydantic_ai_simple.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/pydantic_ai_stream.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/pydantic_ai_swarm.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/pydantic_ai_swarm_stream.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/pydantic_ai_token_limit_swarm.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/query_alternate.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/query_children.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/query_other_team.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/query_root.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/strands_billed_failure.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/strands_retry.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/strands_simple.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/strands_swarm.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/vercel_ai_sdk_billed_failure.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/vercel_ai_sdk_py_simple.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/vercel_ai_sdk_py_swarm.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/vercel_ai_sdk_retry.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/vercel_ai_sdk_simple.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/vercel_ai_sdk_stream.json (100%) rename {scripts => litellm/scripts}/lens_assets/fixtures/traces/vercel_ai_sdk_swarm.json (100%) rename {scripts => litellm/scripts}/lens_assets/schemas/models/ReadQueryName.json (100%) rename {scripts => litellm/scripts}/lens_assets/schemas/models/TraceAgentRow.json (100%) rename {scripts => litellm/scripts}/lens_assets/schemas/models/TraceAgentsParams.json (100%) rename {scripts => litellm/scripts}/lens_assets/schemas/models/TraceQueryHelp.json (100%) rename {scripts => litellm/scripts}/lens_assets/schemas/requests/TraceDetailRequest.json (100%) rename {scripts => litellm/scripts}/lens_assets/schemas/requests/TraceErrorPageRequest.json (100%) rename {scripts => litellm/scripts}/lens_assets/schemas/requests/TraceListRequest.json (100%) rename {scripts => litellm/scripts}/lens_assets/schemas/requests/TraceQueryRequest.json (100%) rename {scripts => litellm/scripts}/lens_assets/schemas/requests/TraceSpanRequest.json (100%) rename {scripts => litellm/scripts}/lens_assets/schemas/responses/TraceSQLResponse.json (100%) rename {scripts => litellm/scripts}/lens_assets/schemas/types/QueryScope.json (100%) rename {scripts => litellm/scripts}/lens_assets/schemas/types/SpanDetail.json (100%) rename {scripts => litellm/scripts}/lens_assets/schemas/types/SpanErrorPage.json (100%) rename {scripts => litellm/scripts}/lens_assets/schemas/types/Tenant.json (100%) rename {scripts => litellm/scripts}/lens_assets/schemas/types/Trace.json (100%) rename {scripts => litellm/scripts}/lens_assets/schemas/types/TracePage.json (100%) rename {scripts => litellm/scripts}/lens_assets/schemas/types/TraceScope.json (100%) rename {scripts => litellm/scripts}/lens_assets/source.json (100%) rename {scripts => litellm/scripts}/lint_base_counts.py (98%) rename {scripts => litellm/scripts}/mock_bedrock_passthrough_target.py (98%) rename {scripts => litellm/scripts}/mock_grayswan_timeout_server.py (96%) rename {scripts => litellm/scripts}/mutation_report.py (99%) rename {scripts => litellm/scripts}/openapi_docs_gate.py (91%) rename {scripts => litellm/scripts}/pre_commit_lint.sh (94%) rename {scripts => litellm/scripts}/prisma_generate_if_needed.py (98%) rename {scripts => litellm/scripts}/quickstart.ps1 (99%) rename {scripts => litellm/scripts}/quickstart.sh (99%) rename {scripts => litellm/scripts}/ruff_strict_gate.py (97%) rename {scripts => litellm/scripts}/seed_request_logs.py (99%) rename {scripts => litellm/scripts}/seed_tracing_fixtures.py (99%) rename {scripts => litellm/scripts}/sync-issue-labels.test.ts (100%) rename {scripts => litellm/scripts}/sync-issue-labels.ts (100%) rename {scripts => litellm/scripts}/test_agent_mcp_endpoints.sh (100%) rename {scripts => litellm/scripts}/test_guardrails_register_endpoints.sh (100%) rename {scripts => litellm/scripts}/test_quality_gate.py (91%) rename {scripts => litellm/scripts}/test_tool_allowlist_script.py (97%) rename {scripts => litellm/scripts}/tpm_headline_test.sh (98%) rename {scripts => litellm/scripts}/trace_codegen/README.md (55%) rename {scripts => litellm/scripts}/trace_codegen/config.json (89%) rename {scripts => litellm/scripts}/trace_codegen/templates/ScalarTypeAliasType.jinja2 (100%) rename {scripts => litellm/scripts}/trace_codegen/templates/TypeAliasType.jinja2 (100%) rename {scripts => litellm/scripts}/trace_codegen/templates/TypedDictClass.jinja2 (100%) rename {scripts => litellm/scripts}/trace_codegen/templates/pydantic_v2/BaseModel.jinja2 (100%) rename {scripts => litellm/scripts}/trace_codegen/templates/pydantic_v2/types.jinja2 (100%) rename {scripts => litellm/scripts}/trace_codegen/templates/types.jinja2 (100%) rename {scripts => litellm/scripts}/type_check_gate.py (97%) rename {scripts => litellm/scripts}/type_discipline_gate.py (93%) rename {scripts => litellm/scripts}/verify_adaptive_router.py (99%) rename {scripts => litellm/scripts}/with_dashboard_node.sh (97%) delete mode 100644 scripts/ci_cd/baseline_db.py delete mode 100644 tests/unit/test_repo_agent_skills.py diff --git a/.agents/skills/database-access/SKILL.md b/.agents/skills/database-access/SKILL.md deleted file mode 100644 index d25636b4ab5..00000000000 --- a/.agents/skills/database-access/SKILL.md +++ /dev/null @@ -1,73 +0,0 @@ ---- -name: database-access -description: Organize database repositories and proxy dependency wiring, manage connection ownership, or port Prisma operations to Rust and SQLx without expanding migration scope -metadata: - internal: true ---- - -# Database access - -## Situations - -- Adding a query or an operation to a repository, read [adding a query](references/python-repository.md#adding-a-query) -- Moving existing Prisma calls behind a repository, read [moving existing access](references/python-repository.md#moving-existing-access-into-a-repository) -- Porting a repository from Prisma to Rust and SQLx, read [porting to SQLx](references/python-repository.md#porting-a-repository-to-sqlx) -- Injecting a repository into a route, read [Python and FastAPI](references/python-fastapi.md) or [Rust and Axum](references/rust-axum.md) - -## Adding new database access - -- Put Python database access behind an operation in `litellm/repositories` -- Give each repository its own FastAPI provider, so a route builds only the repositories it uses -- A provider borrows existing handles and performs no database I/O during construction -- Define the operations a route calls as a Protocol in `litellm/models/.py`, next to its domain types - - The Protocol takes and returns domain types, never Prisma models, raw rows or serialized payloads - - Parsing and serialization of stored values live in the repository - - Add a Protocol when a repository gets a provider, not up front for every repository -- Keep query execution inside the repository, with one implementation per repository and no backend switch or fallback -- A repository is either all Prisma or all native, never a mix of both -- Prisma is fine for the implementation, adding a query does not require a Rust port -- Native Rust callers use `litellm/rust/crates/db` directly - -## Framework wiring - -- Python routes receive a per-repository dependency such as `UserBannerRepositoryDep` and call its operations, such as `banners.get_banner()` -- `DatabaseDep` lives in `litellm/proxy/deps/database.py`, repository providers in `litellm/proxy/deps/repositories.py` - - A provider returns the feature's Protocol, so routes never see which backend implements it - - Dependencies used by one feature only, like the banner audit binding, stay next to that feature's routes -- Repositories never import FastAPI, so jobs and helpers can use them without a request -- Use named FastAPI providers with `Annotated[..., Depends(...)]`, ordinary helpers and jobs receive explicit arguments -- Preserve each route's no-database behavior, authorization precedence and background-task scheduling -- Read [Python and FastAPI](references/python-fastapi.md) for provider examples, lifespan state and route verification -- Read [Rust and Axum](references/rust-axum.md) when adding database access to Rust handlers - -## Connection ownership - -- Keep connection setup and shutdown separate from repositories, which own no pools -- Reuse existing handles, never connect per request or disconnect from a repository operation -- Give each pool one owner for setup and shutdown, borrowed handles never close it -- Finish requests, jobs and queued database work before closing connections -- Clean up resources opened before a startup failure, without a second disconnect fallback -- Add a backend to the existing lifecycle owner and pass its handle only to repositories that need it -- Preserve cancellation, timeout, error and transaction semantics across the native bridge - -## Changing ownership or reloading resources - -- Inventory initialization, reload, tests, background jobs and shutdown together -- Move every writer when changing authoritative storage, copying a replaceable global into state is insufficient -- A frozen repository does not make its clients immutable -- Decide whether each request captures one resource generation or reads it again during processing -- Build and validate replacements before publishing them, preserving the old generation on failure -- Serialize reloads and coordinate publication with shutdown -- Drain streams and background users before retiring old resources, retaining every generation grows resource use -- Define multi-worker coordination separately from an in-process swap -- Choose mechanisms such as `ArcSwap` only after defining publication, capture and retirement - -## Migration context and boundaries - -- Long-term direction is to centralize Python database access in repositories, then replace their Prisma implementations with Rust APIs one repository at a time -- Prisma and native repositories coexist during the transition, unrelated existing calls can stay as they are -- Prisma and SQLx keep separate client pools to PgBouncer, which pools connections to PostgreSQL - - Size both layers together and preserve reader/writer routing and 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/.agents/skills/database-access/references/python-fastapi.md b/.agents/skills/database-access/references/python-fastapi.md deleted file mode 100644 index 2f6d1b001fc..00000000000 --- a/.agents/skills/database-access/references/python-fastapi.md +++ /dev/null @@ -1,101 +0,0 @@ -# Python and FastAPI - -## Existing pattern - -- `UserBannerStore` in `litellm/models/user_banner.py` is the Protocol the banner routes call -- `get_database` in `litellm/proxy/deps/database.py` reads the lifespan-owned handle from request state -- `get_user_banner_repository` in `litellm/proxy/deps/repositories.py` builds the banner repository from that handle -- Choose each repository's replica routing once in its provider, never at call sites -- A handler receives `UserBannerStore | None`, never a Prisma client or a concrete repository -- `UserBannerRepository` implements `UserBannerStore` structurally, keeping the existing Prisma table, serialization and configuration-sync behavior -- The banner audit provider binds the legacy audit callable at request time, without performing audit I/O -- A native repository can later implement the same Protocol without changing handler signatures, see [porting a repository to SQLx](python-repository.md#porting-a-repository-to-sqlx) - -## Dependency injection - -- Add one provider and one `Annotated` alias per repository in `litellm/proxy/deps/repositories.py` -- Annotate the provider and alias with the feature's Protocol, not the concrete repository -- A route depends only on the repositories it calls, so a request never builds repositories it does not use -- Do not build repositories once at lifespan, a reconnect can replace the Prisma client they wrap - -```python -class UserBannerStore(Protocol): - async def get_banner(self) -> UserBanner: ... - - async def save_banner(self, banner: UserBanner) -> None: ... -``` - -```python -async def get_user_banner_repository(database: DatabaseDep) -> UserBannerStore | None: - return None if database is None else UserBannerRepository(database.prisma) - - -UserBannerRepositoryDep: TypeAlias = Annotated[UserBannerStore | None, Depends(get_user_banner_repository)] -``` - -- FastAPI caches each provider within a request, so routes and sub-dependencies share one instance -- Ordinary helpers and jobs receive explicit arguments, never unresolved `Depends` defaults -- A route still reading the `prisma_client` global or building a repository inline switches to the repository's `...RepositoryDep`, keeping its no-database behavior and error precedence - -```python -async def get_user_banner(banners: UserBannerRepositoryDep) -> UserBanner: - if banners is None: - return UserBanner() - return await banners.get_banner() -``` - -## Lifespan state - -- Prisma startup owns connection setup, authentication refresh, health checks and migrations -- `Database` holds the initialized Prisma client and the `NativeDatabase` handle, without holding fields per feature - - The native handle opens no pool yet, its `connect` and `close` are noops -- The proxy lifespan builds the handle with `Database.open`, registers `Database.aclose` on its exit stack and publishes it in request state - - Callers only open and close `Database`, which closes Prisma and the native handle together, and `open` closes Prisma itself when the native connect fails -- Starlette shallow-copies lifespan state into request state, which is distinct from `app.state` -- The database module never imports a repository, legacy globals borrow its handle without owning shutdown -- Drain requests, jobs, logging, spend and audit work before database teardown -- The exit stack closes the handle on exit, including startup failures after the client is created -- When adding native resources, initialize them in the serving process, respecting runtime fork restrictions -- Await native shutdown instead of depending on Python garbage collection -- Apply the [connection ownership rules](../SKILL.md#connection-ownership) when changing the owner - -## Timing and errors - -- FastAPI resolves dependencies before entering the handler -- Handler exception handling cannot catch failures raised during dependency resolution -- A universal required-database dependency can override authorization and validation behavior -- Banner GET without a database returns the default disabled banner -- Banner PATCH checks the admin role before returning the existing missing-database error -- Invalid stored banner data falls back to the default, but storage failures still propagate -- Banner writes finish before the success audit is queued as a FastAPI background task -- Queue post-response work with `BackgroundTasks`, not bare `asyncio.create_task`, so the in-flight drain waits for it before the database closes -- Do not move background work into an awaited provider merely to remove an import - -## Verification - -- Exercise real FastAPI handlers using `dependency_overrides` for external boundaries -- Keep production parsing and persistence code real -- Restore overrides after each test -- Verify complete response bodies, status codes and OpenAPI against the base -- Include combined failure conditions to pin error precedence -- Check saved values, fresh revisions, audit contents and failed-write behavior -- Check lifespan state with a running lifespan, not only a TestClient that skips startup -- Verify providers do not connect, query, disconnect or audit eagerly -- Use real PostgreSQL and live proxy requests when changing persistence behavior - -## Scope - -- Preserve direct Python call sites or migrate them explicitly -- Inventory imports, state writers, side effects and error ordering before migrating a feature -- Preserve configuration sync and serialization, and state which legacy reads remain -- Do not migrate every route in a large module just to establish the pattern -- Do not invent providers for resources without consumers - -## Framework references - -- [Lifespan events](https://fastapi.tiangolo.com/advanced/events/) and [Starlette lifespan state](https://starlette.dev/lifespan/) -- [`SessionDep`-style `Annotated` aliases](https://fastapi.tiangolo.com/tutorial/sql-databases/#create-a-session-dependency), which `DatabaseDep` and `UserBannerRepositoryDep` follow -- [Dependency composition and caching](https://fastapi.tiangolo.com/tutorial/dependencies/sub-dependencies/) -- [Background tasks and dependencies with `yield`](https://fastapi.tiangolo.com/advanced/advanced-dependencies/#background-tasks-and-dependencies-with-yield-technical-details) -- [Dependency overrides](https://fastapi.tiangolo.com/advanced/testing-dependencies/) -- [Testing lifespan](https://fastapi.tiangolo.com/advanced/testing-events/) diff --git a/.agents/skills/database-access/references/python-repository.md b/.agents/skills/database-access/references/python-repository.md deleted file mode 100644 index dbf7a098e97..00000000000 --- a/.agents/skills/database-access/references/python-repository.md +++ /dev/null @@ -1,119 +0,0 @@ -# Python repositories - -## Adding a query - -Use this when a feature needs a read or write that no repository offers yet, including one more operation on an existing repository - -### Before starting - -- Search `litellm/repositories` for a repository that already owns the table, and extend it instead of adding a second one -- Check `litellm/models/.py` for an existing Protocol and domain types -- Decide the route's behavior when no database is configured, and where that check sits relative to authorization and validation - -### Steps - -1. Domain types and Protocol in `litellm/models/.py` - - The Protocol takes and returns domain types, never Prisma models, raw rows or serialized payloads - - Add the Protocol together with the provider, not for repositories nothing injects -2. Repository in `litellm/repositories/_repository.py` - - Implement the operation with Prisma, a Rust port is not required - - Compose the Prisma client and type the tables it touches with `TableActions` from `prisma_protocols.py`, never inherit `PrismaTableRepository` - - Parse and serialize stored values here, so callers only see domain types - - Never import FastAPI, connect, disconnect or choose replicas per call -3. Provider and `Annotated` alias in `litellm/proxy/deps/repositories.py`, see [dependency injection](python-fastapi.md#dependency-injection) -4. The route takes `RepositoryDep`, handles `None` with the behavior decided above, and calls the operation -5. Jobs and helpers that need the operation receive the repository as an explicit argument, built by their caller from the handle it already holds - -### Done when - -- Handler tests drive the real route with `dependency_overrides` and the real repository code, see [verification](python-fastapi.md#verification) -- Tests cover the no-database path, error precedence, and what was actually stored -- Persistence changes are checked against real PostgreSQL through a live proxy - -### Out of scope - -- Porting the query to Rust, see [porting a repository to SQLx](#porting-a-repository-to-sqlx) -- Moving unrelated direct Prisma calls in the same module - -## Moving existing access into a repository - -Use this when code calls Prisma directly, through `prisma_client.db.` or a helper, and the calls should live behind a repository. The backend stays Prisma - -### Before starting - -- List every call being moved, its callers, and the transaction or batch it runs in -- List the module's imports, global state writers, side effects such as audit and config sync, and error ordering -- Record current return values, raised errors and response bodies, these are what the change must preserve - -### Steps - -1. Move the existing Prisma code into the relevant repository in `litellm/repositories` without rewriting the queries -2. Add domain types and a Protocol in `litellm/models/.py` when a route will inject the repository -3. Replace each direct call with the repository operation, through a provider for routes and explicit arguments for jobs and helpers, see [Python and FastAPI](python-fastapi.md) -4. Calls sharing a transaction move into the same repository or unit of work in one change -5. State which legacy reads remain and why, when the change does not move all of them - -### Done when - -- Focused regression tests pin the preserved return values, errors and transaction behavior -- Response bodies, status codes and OpenAPI match the base -- Configuration sync and serialization behave the same, including invalid stored data - -### Out of scope - -- Switching the backend, even when an equivalent Rust query exists -- Converting other routes in the module just to establish the pattern -- Cleanups unrelated to the moved calls - -## Porting a repository to SQLx - -Status: TBD. No repository has been ported yet. `database.native` is a `NativeDatabase` from `crates/python-bridge/src/db.rs` whose `connect` and `close` are noops that open no pool, and the PyO3 repository surface does not exist. A real pool takes typed writer/reader settings and a token provider, never the Prisma `DATABASE_URL`, which carries Prisma-only params and rotating IAM tokens. The constraints below are settled, the steps are a sketch to revise after the first port lands - -Use this only when a port is explicitly requested. Repository extraction does not require one - -### When not to port - -- An equivalent Rust or SQLx query existing is not a reason to switch a Prisma caller -- Leave existing backend selection unchanged unless integration is explicitly requested -- Never port part of a repository, it is either all Prisma or all native - -### Before starting - -- Identify the repository's inputs, outputs, errors and transaction boundary -- List repositories that share a transaction with it, they move together -- Check `litellm/rust/crates/db` for an equivalent query and reuse it when its behavior matches - -### Steps - -1. Rust queries, following `litellm/rust/crates/db/AGENTS.md` - - Static SQL in `queries/`, compile-checked with SQLx, typed inputs and row projections in `src/` - - Dynamic filters and sort keys become closed Rust enums that select static SQL, every value is bound - - Refresh SQLx query metadata after SQL changes -2. PyO3 surface exposing typed operations, never SQL text, table names or column names from Python. TBD: where it lives and how the handle reaches it -3. Native repository implementing the same Protocol in `litellm/repositories` - - Converts typed PyO3 results to domain types, preserving defaults, invalid-data handling and storage errors - - Python conversion stays in the bridge, not in `crates/db` -4. Switch the provider in `litellm/proxy/deps/repositories.py`, the Protocol and routes stay unchanged - -```diff - async def get_user_banner_repository(database: DatabaseDep) -> UserBannerStore | None: -- return None if database is None else UserBannerRepository(database.prisma) -+ return None if database is None else NativeUserBannerRepository(database.native) -``` - -5. Delete the Prisma repository in the same change and switch every caller, including jobs and helpers - -### Done when - -- Behavior is verified against real PostgreSQL, covering null handling, conflicts, ordering, errors and transaction semantics -- `DATABASE_URL=... cargo test -p litellm-db --locked -- --include-ignored` passes against a Prisma-migrated database -- Live proxy requests show unchanged responses. TBD: a Python-side real-PostgreSQL test harness - -### Rollback - -- Roll back the release, never retry an uncertain native write through Prisma - -### Out of scope - -- SQLx owning schema migrations, and removing Prisma -- Converting unrelated routes to dependency injection diff --git a/.agents/skills/database-access/references/rust-axum.md b/.agents/skills/database-access/references/rust-axum.md deleted file mode 100644 index 83368d27233..00000000000 --- a/.agents/skills/database-access/references/rust-axum.md +++ /dev/null @@ -1,4 +0,0 @@ -# Rust and Axum - -- This should use same `crates/db` what is exposed to Python world. -- Details are TBD. diff --git a/.agents/skills/litellm-setup/SKILL.md b/.agents/skills/litellm-setup/SKILL.md deleted file mode 100644 index 7c824751d6f..00000000000 --- a/.agents/skills/litellm-setup/SKILL.md +++ /dev/null @@ -1,205 +0,0 @@ ---- -name: litellm-setup -description: Set up a self-hosted LiteLLM proxy, the OpenAI-compatible LLM gateway, on this machine, from install through provider keys, config.yaml, a master key, optional Postgres and Admin UI, and a verified chat completion. Use when the user asks to set up LiteLLM, install the LiteLLM proxy, self-host an LLM gateway, or put one endpoint in front of OpenAI, Anthropic, Gemini, Azure, Bedrock, Ollama, or other providers. Not for using the LiteLLM Python SDK inside an app ---- - -# Set up a LiteLLM proxy - -Take the user from nothing to a running LiteLLM proxy that has answered one chat completion. Run every command yourself unless a step says the user does it - -Never print a secret. Provider keys, the master key, the salt key, the database URL, and virtual keys live only in `.env`, and `config.yaml` reads them through `os.environ/NAME`. Check that a value is there with `grep -c '^NAME=.' .env`, never with `cat .env` or `echo "$NAME"`. Load `.env` into a shell with this line, which exports each line as it is, so a `&` or `$` in a value stays literal, and first drops any database settings the shell already had and sets `LITELLM_MODE=PRODUCTION`, which stops `litellm` from also loading a `.env` it finds above its install folder, such as `~/.env`, so only this `.env` picks the database. The steps that need it start with it: - -```bash -unset DATABASE_URL DIRECT_URL DATABASE_HOST; export LITELLM_MODE=PRODUCTION; while IFS= read -r line || [ -n "$line" ]; do case "$line" in [A-Za-z_]*=*) export "$line" ;; esac; done < .env -``` - -## 1. Ask once - -Ask everything in one message, with defaults the user can accept by saying "go": - -- Providers and models. Default is OpenAI with its newest flagship model, using the `OPENAI_API_KEY` in your environment when `[ -n "$OPENAI_API_KEY" ] && echo set` says it is there. Run that check before asking, and say in the question that the default uses that variable, naming it but never its value, since a key in your environment can belong to another account -- Whether they want virtual keys, teams, spend tracking, or the Admin UI. Those need Postgres, plain routing does not. Default is no -- uv (default) or Docker. With Postgres, Docker runs the repo's quickstart, which brings its own database, and uv needs a Postgres server they already have, with a new, empty database for LiteLLM, so someone with their own Postgres server picks uv -- Folder and port. Defaults are `./litellm-proxy` (`./litellm-gateway` for the quickstart) and 4000 - -Then follow the steps for their answers. Plain routing skips steps 3 and 6. The quickstart is steps 2, 3, 8, and 9. uv with their own Postgres skips step 3 - -In the same message, say that someone who picks uv and would rather answer prompts can run `litellm --setup` in a separate terminal window once LiteLLM is installed, not through Claude Code. Never run it yourself, since it needs a real terminal and without one prints "Setup cancelled." and writes nothing. Give them the command as `LITELLM_MODE=PRODUCTION /litellm --setup`, with `` replaced by the folder `uv tool dir --bin` prints, to run from the folder they want the config in. It writes `litellm_config.yaml` there with the provider keys and master key in plain text and offers to start the proxy, which then listens on every network interface and stops with Ctrl+C in that window. When the user is done, run this in that folder. It makes the file readable only by them, keeps it out of git (the wizard does neither), and prints only the model names. Never print that file or run `grep`, `sed`, or `cat` on it: - -```bash -chmod 600 litellm_config.yaml; grep -qx 'litellm_config.yaml' .gitignore 2>/dev/null || echo 'litellm_config.yaml' >> .gitignore -"$(uv tool dir)/litellm/bin/python" -I -c 'import yaml; print(*(m["model_name"] for m in yaml.safe_load(open("litellm_config.yaml"))["model_list"]), sep="\n")' -``` - -Then skip to step 8 and run it against their proxy, starting that shell command with this line instead of the loader line, which reads the master key without printing it: - -```bash -export LITELLM_MASTER_KEY="$("$(uv tool dir)/litellm/bin/python" -I -c 'import yaml; print(yaml.safe_load(open("litellm_config.yaml"))["general_settings"]["master_key"])')" -``` - -## 2. Check prerequisites - -```bash -uv --version; docker info --format '{{.ServerVersion}}'; docker compose version; curl --version | head -1; openssl version; command -v python3 -``` - -On native Windows, ask the user to run Claude Code inside WSL, since every command here is POSIX shell. Every path needs curl, openssl, and python3, so ask the user to install any that is missing. The uv path needs uv, which downloads a supported Python (LiteLLM supports 3.10 to 3.14) when the `--python` range in step 4 rules out the one on the machine. If uv is missing, offer to install it, and only after the user says yes run `curl -LsSf https://astral.sh/uv/install.sh | env UV_NO_MODIFY_PATH=1 sh`, which leaves their shell profile alone (https://docs.astral.sh/uv/getting-started/installation/). It puts uv in `~/.local/bin`, so start every later command that runs `uv` or `litellm` with `export PATH="$HOME/.local/bin:$PATH";`. The Docker path needs a running Docker daemon, and the quickstart also needs Docker Compose v2. If `docker info` says `permission denied`, the user's account cannot use Docker without sudo. Offer the uv path, or ask them to add themselves to the `docker` group the way https://docs.docker.com/engine/install/linux-postinstall/ shows and start a new login session before you check again - -Check the port is free with `curl -s -o /dev/null --max-time 2 http://127.0.0.1:4000; echo $?`, which prints `7` (could not connect) only when nothing listens there. Don't use `lsof` for this, since it misses ports that root or Docker hold. If it is taken, pick another port and use it everywhere below, because a proxy asked for a busy 4000 silently moves to a random port - -## 3. Postgres with Docker: run the quickstart - -The repo's quickstart starts the gateway, Postgres, and the Admin UI in Docker, listening on this machine only, and puts a `litellm-gateway` command in that folder that stops, starts, updates, or removes them. It asks nothing when it has no terminal. It writes the master key, salt key, and database password to its own `.env` and never prints them. Download it, then run it with the folder and port from step 1. It returns once the gateway is ready: - -```bash -curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm/main/scripts/quickstart.sh -o quickstart.sh -LITELLM_DIR="$PWD/litellm-gateway" LITELLM_PORT=4000 sh quickstart.sh --yes -cd litellm-gateway -``` - -Models live in the database here, so add each one through the API instead of a `config.yaml`, naming it the way step 5 says. Pipe the request body in, so the provider key never shows up in output or on a command line. Unless the user agreed to the key in your environment, as step 5 says, ask them to add the line `OPENAI_API_KEY=` to this `.env` themselves. Run the loader line first: - -```bash -python3 -c 'import json, os, sys; json.dump({"model_name": "gpt-6.1-sol", "litellm_params": {"model": "openai/gpt-6.1-sol", "api_key": os.environ["OPENAI_API_KEY"]}}, sys.stdout)' \ - | curl -sS -o /dev/null -w '%{http_code}\n' http://127.0.0.1:4000/model/new \ - -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @- -``` - -Run that in one shell command that starts with the loader line, since the master key is in `.env`. `200` means the model was added. Then go to step 8 - -## 4. Install - -uv: - -```bash -uv tool install --python '>=3.10,<3.15' 'litellm[proxy]' -export PATH="$(uv tool dir --bin):$PATH"; litellm --version -``` - -With their own Postgres, install `'litellm[proxy,extra_proxy]'` instead, with the same `--python` range, which adds the Prisma client the proxy uses for the database. Running `uv tool install` again with the new extras replaces the old install. Start every later command that runs `litellm` with `export PATH="$(uv tool dir --bin):$PATH";`, so this install runs even when the shell has no `litellm` or an older one from a venv or `pip install litellm`. `uv tool update-shell` puts it on the PATH of new shells by editing the user's shell profile, so run it only after the user says yes - -Docker: - -```bash -docker pull docker.litellm.ai/berriai/litellm:main-stable -``` - -## 5. Write `.env` and `config.yaml` - -Run every command from here on in the folder from step 1. Create `.env` readable only by the user, keep it out of git, and add a master key unless it already has one. The proxy refuses to start without one, and `sk-` is the format of every key it issues: - -```bash -mkdir -p litellm-proxy && cd litellm-proxy -touch .env && chmod 600 .env; grep -qx '.env' .gitignore 2>/dev/null || echo '.env' >> .gitignore -grep -q '^LITELLM_MASTER_KEY=.' .env || printf 'LITELLM_MASTER_KEY=sk-%s\n' "$(openssl rand -hex 32)" >> .env -``` - -Copy a provider key that is already in your environment only after the user agreed to that variable, in their step 1 answer or when you ask now, and copy it without printing it, as in `printf 'OPENAI_API_KEY=%s\n' "$OPENAI_API_KEY" >> .env`. Otherwise ask the user to add the line `OPENAI_API_KEY=` to `.env` themselves and tell you when it is there. If they paste a key into the chat anyway, write it to `.env` and never repeat it. Keep one `NAME=value` per line with no quotes, so `docker --env-file` and the loader line read the same value - -Confirm each model's current LiteLLM name in the cost map instead of trusting memory, since model names go stale fast. This prints the chat models of the provider named last (`openai`, `anthropic`, `gemini`, `azure`, `bedrock`, `vertex_ai`, and so on) the way `config.yaml` takes them, with the provider in front. It matches by prefix, so `bedrock` also lists the newer Bedrock models and `vertex_ai` lists every Vertex family. For Ollama, use a model from `ollama list` instead: - -```bash -curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json | python3 -c ' -import json, sys -for name, row in json.load(sys.stdin).items(): - provider = str(row.get("litellm_provider", "")) if isinstance(row, dict) else "" - if provider.startswith(sys.argv[1]) and row.get("mode") == "chat": - prefix = "bedrock" if provider == "bedrock_converse" else "vertex_ai" if provider.startswith("vertex_ai") else provider - print(name if name.startswith(prefix + "/") else prefix + "/" + name) -' openai -``` - -In `config.yaml`, `model` is a name from that list, as in `openai/gpt-6.1-sol` or `bedrock/us.anthropic.`, and `model_name` is what clients will send. If the folder already has a `config.yaml`, show the user its `model_name` lines and ask before replacing it. This example uses the newest GPT model in the cost map when this skill was written, so replace it with what the user picked: - -```yaml -model_list: - - model_name: gpt-6.1-sol - litellm_params: - model: openai/gpt-6.1-sol - api_key: os.environ/OPENAI_API_KEY - -general_settings: - master_key: os.environ/LITELLM_MASTER_KEY -``` - -Add one entry per model. On Azure, ask the user for each deployment's name and the model it runs. Use `azure/` as `model`, since Azure routes by deployment and a name from the lookup works only when the deployment has that same name, and add `model_info:` with `base_model: azure/` to the entry, since LiteLLM prices each call by that name. Providers that need more than a key, like Azure or Bedrock, list their `litellm_params` on their page under https://docs.litellm.ai/docs/providers. Point every secret at `.env` through `os.environ/NAME` the same way - -## 6. Their own Postgres, on the uv path - -Ask the user to create a new, empty database for LiteLLM on their server (`CREATE DATABASE litellm;`) and add `DATABASE_URL=postgresql://...` for it to `.env` themselves. The proxy creates its tables there on first start and stops on a database that already holds other tables. If that URL goes through a transaction pooler such as PgBouncer, they also add `DIRECT_URL` for the same database without the pooler, which the migrations use. Then add a salt key. It encrypts the provider credentials the proxy stores in the database and falls back to the master key when unset, so set it once and never change it: - -```bash -grep -q '^LITELLM_SALT_KEY=.' .env || printf 'LITELLM_SALT_KEY=sk-%s\n' "$(openssl rand -hex 32)" >> .env -``` - -Generate the Prisma client once inside the tool's environment. A pip or uv install doesn't ship it generated (Docker images do): - -```bash -tool="$(uv tool dir)/litellm" -schema=$("$tool/bin/python" -I -c 'import importlib.util, os; print(os.path.join(importlib.util.find_spec("litellm").submodule_search_locations[0], "proxy", "schema.prisma"))') -PATH="$tool/bin:$PATH" prisma generate --schema "$schema" -``` - -## 7. Start the proxy - -Bind to `127.0.0.1` unless the user wants other machines to reach it - -uv, in one shell command that starts with the loader line, since the installed `litellm` does not read `.env` by itself: - -```bash -export PATH="$HOME/.local/bin:$PATH"; export PATH="$(uv tool dir --bin):$PATH" -nohup litellm --config config.yaml --host 127.0.0.1 --port 4000 > litellm.log 2>&1 & -echo $! > litellm.pid -``` - -Docker: - -```bash -docker run -d --name litellm --env-file .env -v "$PWD/config.yaml:/app/config.yaml:ro" -p 127.0.0.1:4000:4000 \ - docker.litellm.ai/berriai/litellm:main-stable --config /app/config.yaml --port 4000 -``` - -Wait on the health route, stopping early if the proxy exits. The first start with Postgres applies the database migrations and takes longer. Define `alive` for the path you took, `alive() { kill -0 "$(cat litellm.pid)" 2>/dev/null; }` for uv or `alive() { [ "$(docker inspect -f '{{.State.Running}}' litellm 2>/dev/null)" = true ]; }` for Docker, in the same shell command as the loop: - -```bash -for i in $(seq 1 180); do curl -fsS http://127.0.0.1:4000/health/liveliness >/dev/null 2>&1 && break; alive || break; sleep 1; done -curl -sS http://127.0.0.1:4000/health/readiness -``` - -Readiness reports `"db":"connected"` with Postgres and `"db":"Not connected"` without it. If the proxy never comes up, read the end of `litellm.log` (or `docker logs litellm`) and check the troubleshooting list - -## 8. Verify with a chat completion - -Use a `model_name` from `config.yaml` (or step 3), in one shell command that starts with the loader line: - -```bash -curl -sS http://127.0.0.1:4000/v1/chat/completions \ - -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" \ - -d '{"model": "gpt-6.1-sol", "messages": [{"role": "user", "content": "Say hello in five words."}]}' -``` - -Show the user the reply in `choices[0].message.content`. An error here means the setup is not done, so fix it before handing off - -## 9. Hand off - -Tell the user, without printing any secret: - -- The base URL is `http://127.0.0.1:4000`. Any OpenAI-compatible client works with it as the base URL and the master key or a virtual key as the API key -- The master key is `LITELLM_MASTER_KEY` in the folder's `.env`, or `general_settings.master_key` in `litellm_config.yaml` when they used `litellm --setup` -- To stop it, `kill "$(cat litellm.pid)"` (uv), `docker stop litellm` (Docker), `/litellm-gateway stop` (quickstart), or Ctrl+C in its window (`litellm --setup`). To start it again, `docker start litellm`, `/litellm-gateway start`, on uv the whole step 7 command as you ran it, loader line and PATH export included, wrapped in `( ... )` so their shell keeps its own settings, shown as a code block and never paraphrased, since a new shell has neither, or for `litellm --setup` `LITELLM_MODE=PRODUCTION /litellm --config litellm_config.yaml --host 127.0.0.1 --port ` in a terminal window in that folder, with `` and `` filled in, since running the wizard again writes a new config with a new master key. `update` and `uninstall` update or remove a quickstart install. Give the quickstart commands with the folder's full path, since a bare `litellm-gateway` is on PATH only when `~/.local/bin` is, and can belong to an earlier install -- With Postgres, the Admin UI is at `http://127.0.0.1:4000/ui` (user `admin`, password the master key), and `POST /key/generate` with the master key creates virtual keys with their own budgets and model lists. Without Postgres, both need step 3 or 6 first -- The Admin UI warns that the master-key login is a shared secret, which is fine while only this machine reaches the proxy. Before anyone else can reach it, invite an admin with their own password on the Internal Users page, then set `general_settings.disable_env_credential_login: true` in the proxy config -- To manage the running proxy from a coding agent (keys, teams, users, models, MCP servers), install `npx skills add BerriAI/litellm-skills -g` - -## Troubleshooting - -- `refused to start: no master key is set` means the loader line did not run in the shell command that started `litellm`, or `--env-file .env` is missing from `docker run` -- `a database URL is set but the prisma CLI is neither on PATH nor importable` means the install lacks `extra_proxy`, so rerun step 4 with it, or, on plain routing, that the command that started `litellm` did not start with the loader line -- `The Client hasn't been generated yet` or `Unable to find Prisma binaries` means the Prisma generate command in step 6 has not run -- `Incorrect API key provided` or another provider `AuthenticationError` means a provider key is wrong. Fix it in `.env` and restart, since the proxy reads the environment only at startup. On uv, stop it and rerun step 7. On Docker, `docker rm -f litellm` and rerun step 7, since `docker restart` keeps the environment the container was created with. On the quickstart the key is saved with the model, so delete the model and add it again: `GET /model/info` lists each model's `model_info.id`, and `POST /model/delete` with `{"id": ""}` deletes it -- `Cannot automatically baseline this database` means `DATABASE_URL` points at a database that already holds tables LiteLLM did not create. Point it at a new, empty database -- `LLM Provider NOT provided` means a `model` in `config.yaml` (or step 3) lacks its provider in front. Use the name as the step 5 lookup prints it -- `Invalid model name passed in model=...` means the request's `model` is not a `model_name` in `config.yaml` or step 3. `GET /v1/models` lists the ones the key can use -- `No connected db.` on a proxy without Postgres means the bearer token is not the master key -- `Conflict. The container name "/litellm" is already in use` means an earlier run left a container. `docker start litellm` reuses it, or with the user's OK `docker rm -f litellm` and rerun step 7 -- Inside Docker, `localhost` in `config.yaml` (an Ollama `api_base`, say) is the container itself. Use `host.docker.internal`, and on Linux also pass `--add-host=host.docker.internal:host-gateway` diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index c32e08d2eac..3631faaece8 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,6 +1,6 @@ /model_prices_and_context_window.json @mateo-berri @ryan-crabbe-berri @kerry-berri @joshua-berri /litellm/model_prices_and_context_window_backup.json @mateo-berri @ryan-crabbe-berri @kerry-berri @joshua-berri -/ci_cd/cost_map_pins.json @mateo-berri @ryan-crabbe-berri @kerry-berri @joshua-berri +/litellm/scripts/ci_cd/cost_map_pins.json @mateo-berri @ryan-crabbe-berri @kerry-berri @joshua-berri /litellm/deploy/helm/ @yassin-berriai /litellm/deploy/terraform/ @yassin-berriai /.github/workflows/zizmor.yml @yuneng-berri diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 5880cf7d8c2..02beeb9fac1 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -360,7 +360,7 @@ Local lint and budget checks follow origin's current default branch. They refres ## Submitting Your PR 1. **Push your branch**: `git push origin your-feature-branch` -2. **Create a PR**: Go to GitHub and open a pull request against the repository's current default branch. Run `python3 scripts/default_branch.py --branch` to check its name +2. **Create a PR**: Go to GitHub and open a pull request against the repository's current default branch. Run `python3 litellm/scripts/default_branch.py --branch` to check its name 3. **Fill out the PR template**: Provide clear description of changes 4. **Wait for review**: Maintainers will review and provide feedback 5. **Address feedback**: Make requested changes and push updates diff --git a/.github/actions/setup-uv-with-retries/action.yml b/.github/actions/setup-uv-with-retries/action.yml index a99716f5eac..15efaf63c54 100644 --- a/.github/actions/setup-uv-with-retries/action.yml +++ b/.github/actions/setup-uv-with-retries/action.yml @@ -11,6 +11,11 @@ inputs: runs: using: composite steps: + - name: Configure the Rust build environment + shell: bash + working-directory: ${{ github.workspace }} + run: bash .github/scripts/setup_rust_environment.sh + - name: Set up uv (attempt 1) id: attempt-1 continue-on-error: true diff --git a/.gitguardian.yaml b/.github/gitguardian.yaml similarity index 100% rename from .gitguardian.yaml rename to .github/gitguardian.yaml diff --git a/.github/scripts/ci/classify_changes.sh b/.github/scripts/ci/classify_changes.sh index 30d76f3d085..f78c76bda77 100755 --- a/.github/scripts/ci/classify_changes.sh +++ b/.github/scripts/ci/classify_changes.sh @@ -19,11 +19,11 @@ while IFS= read -r file || [ -n "$file" ]; do esac case "$file" in *.md | *.mdx) : ;; - pyproject.toml | */pyproject.toml | uv.lock | uv.toml | .python-version | rust-toolchain.toml | litellm/rust/* | litellm/__init__.py | litellm/proxy/proxy_server.py | litellm/*mcp* | tests/*mcp* | litellm/integrations/arize/* | tests/base_sdk_tests/* | scripts/check_mcp_sdk_install.py | .github/workflows/test-mcp-dependency-resolution.yml | .github/actions/detect-changes/* | .github/actions/setup-uv-with-retries/* | .github/actions/cache-cargo-build/* | .github/scripts/detect_changes.sh | .github/scripts/uv_sync_with_retries.sh | .github/scripts/ci/classify_changes.sh | tests/unit/test_ci_path_filter.py | tests/unit/test_detect_changes.py) + pyproject.toml | */pyproject.toml | uv.lock | uv.toml | .python-version | litellm/rust/* | litellm/__init__.py | litellm/proxy/proxy_server.py | litellm/*mcp* | tests/*mcp* | litellm/integrations/arize/* | tests/base_sdk_tests/* | litellm/scripts/check_mcp_sdk_install.py | .github/workflows/test-mcp-dependency-resolution.yml | .github/actions/detect-changes/* | .github/actions/setup-uv-with-retries/* | .github/actions/cache-cargo-build/* | .github/scripts/detect_changes.sh | .github/scripts/uv_sync_with_retries.sh | .github/scripts/ci/classify_changes.sh | tests/unit/test_ci_path_filter.py | tests/unit/test_detect_changes.py) has_mcp_dependencies=true ;; esac case "$file" in - litellm/rust/* | litellm/rust_bridge/* | rust-toolchain.toml | pyproject.toml | uv.lock | tests/windows_tests/* | .github/scripts/ci/* | .github/actions/*) + litellm/rust/* | litellm/rust_bridge/* | pyproject.toml | uv.lock | tests/windows_tests/* | .github/scripts/ci/* | .github/actions/*) has_windows_release=true ;; esac case "$file" in diff --git a/.github/scripts/setup_rust_environment.sh b/.github/scripts/setup_rust_environment.sh new file mode 100644 index 00000000000..ec9228bc1d2 --- /dev/null +++ b/.github/scripts/setup_rust_environment.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -euo pipefail + +root=$(git rev-parse --show-toplevel) +toolchain=$(sed -n 's/^[[:space:]]*channel[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/p' "$root/litellm/rust/rust-toolchain.toml") +test -n "$toolchain" +rustup toolchain install "$toolchain" --profile minimal --component rustfmt --component clippy --no-self-update +{ + echo "RUSTUP_TOOLCHAIN=$toolchain" + echo "CARGO_NET_RETRY=5" + echo "CARGO_HTTP_MULTIPLEXING=false" + echo "SQLX_OFFLINE=${SQLX_OFFLINE:-true}" +} >> "${GITHUB_ENV:?GITHUB_ENV is required}" diff --git a/.github/scripts/verify_linux_native_wheel.py b/.github/scripts/verify_linux_native_wheel.py index 04276c23f1c..ce5375c3494 100644 --- a/.github/scripts/verify_linux_native_wheel.py +++ b/.github/scripts/verify_linux_native_wheel.py @@ -137,6 +137,9 @@ def main( "litellm/proxy-extras/", "litellm/rust/", "litellm/packaging/", + "litellm/scripts/", + "litellm/runtime/", + "litellm/schema.prisma", ) ) or any(part.endswith(".dSYM") for part in PurePosixPath(member.filename).parts) diff --git a/.github/workflows/auto-close-duplicates.yml b/.github/workflows/auto-close-duplicates.yml index 9a362b4c85c..a6366ab5269 100644 --- a/.github/workflows/auto-close-duplicates.yml +++ b/.github/workflows/auto-close-duplicates.yml @@ -16,8 +16,8 @@ on: pull_request: paths: - .github/workflows/auto-close-duplicates.yml - - scripts/auto-close-duplicates.ts - - scripts/auto-close-duplicates.test.ts + - litellm/scripts/auto-close-duplicates.ts + - litellm/scripts/auto-close-duplicates.test.ts permissions: {} @@ -40,7 +40,7 @@ jobs: bun-version: "1.4.0" - name: Test the sweep - run: bun test scripts/auto-close-duplicates.test.ts + run: bun test litellm/scripts/auto-close-duplicates.test.ts sweep: if: github.event_name != 'pull_request' && github.repository == 'BerriAI/litellm' @@ -62,7 +62,7 @@ jobs: bun-version: "1.4.0" - name: Close unanswered duplicates, reopen ones the reporter answered - run: bun run scripts/auto-close-duplicates.ts + run: bun run litellm/scripts/auto-close-duplicates.ts env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} DRY_RUN: ${{ inputs.dry_run == true }} diff --git a/.github/workflows/check-schema-sync.yml b/.github/workflows/check-schema-sync.yml index 17c69033c25..8b2bd707719 100644 --- a/.github/workflows/check-schema-sync.yml +++ b/.github/workflows/check-schema-sync.yml @@ -3,7 +3,7 @@ name: Check Schema Sync on: pull_request: paths: - - 'schema.prisma' + - 'litellm/schema.prisma' - 'litellm/proxy/schema.prisma' - 'litellm/proxy-extras/litellm_proxy_extras/schema.prisma' @@ -16,7 +16,7 @@ concurrency: jobs: check-sync: - name: Verify schema.prisma copies match root + name: Verify litellm/schema.prisma copies match the canonical schema runs-on: ubuntu-latest timeout-minutes: 5 steps: @@ -27,7 +27,7 @@ jobs: - name: Reject symlinked schema files run: | - for f in schema.prisma litellm/proxy/schema.prisma litellm/proxy-extras/litellm_proxy_extras/schema.prisma; do + for f in litellm/schema.prisma litellm/proxy/schema.prisma litellm/proxy-extras/litellm_proxy_extras/schema.prisma; do if [ -L "$f" ]; then echo "::error file=$f::$f is a symlink, which is not allowed" exit 1 @@ -38,24 +38,24 @@ jobs: run: | EXIT=0 - diff schema.prisma litellm/proxy/schema.prisma || { - echo "::error file=litellm/proxy/schema.prisma::litellm/proxy/schema.prisma differs from root schema.prisma" + diff litellm/schema.prisma litellm/proxy/schema.prisma || { + echo "::error file=litellm/proxy/schema.prisma::litellm/proxy/schema.prisma differs from root litellm/schema.prisma" EXIT=1 } - diff schema.prisma litellm/proxy-extras/litellm_proxy_extras/schema.prisma || { - echo "::error file=litellm/proxy-extras/litellm_proxy_extras/schema.prisma::litellm/proxy-extras/litellm_proxy_extras/schema.prisma differs from root schema.prisma" + diff litellm/schema.prisma litellm/proxy-extras/litellm_proxy_extras/schema.prisma || { + echo "::error file=litellm/proxy-extras/litellm_proxy_extras/schema.prisma::litellm/proxy-extras/litellm_proxy_extras/schema.prisma differs from root litellm/schema.prisma" EXIT=1 } if [ "$EXIT" -ne 0 ]; then echo "" echo "Schema files are out of sync." - echo "The root schema.prisma is the source of truth." + echo "The root litellm/schema.prisma is the source of truth." echo "" echo "To fix, run from the repo root:" - echo " cp schema.prisma litellm/proxy/schema.prisma" - echo " cp schema.prisma litellm/proxy-extras/litellm_proxy_extras/schema.prisma" + echo " cp litellm/schema.prisma litellm/proxy/schema.prisma" + echo " cp litellm/schema.prisma litellm/proxy-extras/litellm_proxy_extras/schema.prisma" exit 1 fi diff --git a/.github/workflows/conventional-commits.yml b/.github/workflows/conventional-commits.yml index f8d416ca487..bd44c3e3c17 100644 --- a/.github/workflows/conventional-commits.yml +++ b/.github/workflows/conventional-commits.yml @@ -3,7 +3,7 @@ name: Conventional PR Title # Squash-merge replaces the merge commit subject with the PR title, so # enforcing Conventional Commits at the PR-title level is what actually gates # the commits that land on the default branch. The local commit-msg hook -# (scripts/githooks/commit-msg) is a best-effort assist; this workflow is the gate. +# (litellm/scripts/githooks/commit-msg) is a best-effort assist; this workflow is the gate. # # See https://www.conventionalcommits.org/en/v1.0.0/ @@ -28,7 +28,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - # Must mirror the type list in scripts/githooks/commit-msg. + # Must mirror the type list in litellm/scripts/githooks/commit-msg. types: | feat fix diff --git a/.github/workflows/cost-map-guard.yml b/.github/workflows/cost-map-guard.yml index 672e91accec..90c8d5a3f9e 100644 --- a/.github/workflows/cost-map-guard.yml +++ b/.github/workflows/cost-map-guard.yml @@ -49,8 +49,11 @@ jobs: HEAD_SHA: ${{ github.event.pull_request.head.sha }} HEAD_REF: ${{ github.event.pull_request.head.ref }} run: | - guard=scripts/ci_cd/cost_map_guard.py + guard=litellm/scripts/ci_cd/cost_map_guard.py # TODO: Drop the legacy path after this lands on main. + if [ ! -f "$guard" ]; then + guard=scripts/ci_cd/cost_map_guard.py + fi if [ ! -f "$guard" ]; then guard=ci_cd/cost_map_guard.py fi diff --git a/.github/workflows/cost-map-pins-recheck.yml b/.github/workflows/cost-map-pins-recheck.yml index f2572efbb31..34482a842ee 100644 --- a/.github/workflows/cost-map-pins-recheck.yml +++ b/.github/workflows/cost-map-pins-recheck.yml @@ -8,7 +8,7 @@ on: paths: - model_prices_and_context_window.json - litellm/model_prices_and_context_window_backup.json - - ci_cd/cost_map_pins.json + - litellm/scripts/ci_cd/cost_map_pins.json permissions: {} @@ -28,8 +28,8 @@ jobs: BEFORE_SHA: ${{ github.event.before }} AFTER_SHA: ${{ github.event.after }} FORCED: ${{ github.event.forced }} - COST_MAP_PATHS: '["model_prices_and_context_window.json", "litellm/model_prices_and_context_window_backup.json", "ci_cd/cost_map_pins.json"]' - PINS_PATHS: '["ci_cd/cost_map_pins.json"]' + COST_MAP_PATHS: '["model_prices_and_context_window.json", "litellm/model_prices_and_context_window_backup.json", "litellm/scripts/ci_cd/cost_map_pins.json"]' + PINS_PATHS: '["litellm/scripts/ci_cd/cost_map_pins.json"]' run: | if [[ "$BEFORE_SHA" =~ ^0+$ || "$FORCED" == true ]] \ || ! gh api "repos/${GITHUB_REPOSITORY}/compare/${BEFORE_SHA}...${AFTER_SHA}?per_page=1" \ diff --git a/.github/workflows/duplicate_issue_check.yml b/.github/workflows/duplicate_issue_check.yml index 91eee3ca383..325f62a7e2d 100644 --- a/.github/workflows/duplicate_issue_check.yml +++ b/.github/workflows/duplicate_issue_check.yml @@ -13,9 +13,9 @@ on: - .github/workflows/duplicate_issue_check.yml - .github/prompts/duplicate-issue-check.md - .github/prompts/duplicate-issue-check.schema.json - - scripts/flag-duplicate-issue.ts - - scripts/flag-duplicate-issue.test.ts - - scripts/auto-close-duplicates.ts + - litellm/scripts/flag-duplicate-issue.ts + - litellm/scripts/flag-duplicate-issue.test.ts + - litellm/scripts/auto-close-duplicates.ts permissions: {} @@ -38,7 +38,7 @@ jobs: bun-version: "1.4.0" - name: Test the flag step - run: bun test scripts/flag-duplicate-issue.test.ts + run: bun test litellm/scripts/flag-duplicate-issue.test.ts classify: if: github.event_name != 'pull_request' && github.repository == 'BerriAI/litellm' @@ -125,7 +125,7 @@ jobs: - name: Checkout scripts uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 with: - sparse-checkout: scripts + sparse-checkout: litellm/scripts persist-credentials: false - name: Setup Bun @@ -134,7 +134,7 @@ jobs: bun-version: "1.4.0" - name: Comment and label - run: bun run scripts/flag-duplicate-issue.ts + run: bun run litellm/scripts/flag-duplicate-issue.ts env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} VERDICT: ${{ needs.classify.outputs.verdict }} diff --git a/.github/workflows/image-scan.yml b/.github/workflows/image-scan.yml index af4e995e6b2..dde06c9ba52 100644 --- a/.github/workflows/image-scan.yml +++ b/.github/workflows/image-scan.yml @@ -10,13 +10,14 @@ on: - litellm/deploy/docker/Dockerfile - litellm/deploy/docker/Dockerfile.dockerignore - litellm/deploy/docker/docker-entrypoint.sh - - migrations/run.py - - gateway/main.py - - gateway/launch.py - - gateway/routes/allowlist.py + - litellm/runtime/migrations/run.py + - litellm/runtime/gateway/main.py + - litellm/runtime/gateway/launch.py + - litellm/runtime/gateway/routes/allowlist.py - litellm/cli/** - - backend/main.py - - backend/routes/allowlist.py + - .github/packaging/** + - litellm/runtime/backend/main.py + - litellm/runtime/backend/routes/allowlist.py - litellm/rust/** - litellm/proxy/lens/** - litellm/proxy/prisma_migration.py diff --git a/.github/workflows/issue_classifier.yml b/.github/workflows/issue_classifier.yml index 842e4c40b5e..57ab65bad13 100644 --- a/.github/workflows/issue_classifier.yml +++ b/.github/workflows/issue_classifier.yml @@ -16,12 +16,12 @@ on: - .github/issue-labels.json - .github/ISSUE_TEMPLATE/bug_report.yml - .github/ISSUE_TEMPLATE/feature_request.yml - - scripts/classify-issue.ts - - scripts/classify-issue.test.ts - - scripts/label-issue.ts - - scripts/label-issue.test.ts - - scripts/issue-labels.ts - - scripts/auto-close-duplicates.ts + - litellm/scripts/classify-issue.ts + - litellm/scripts/classify-issue.test.ts + - litellm/scripts/label-issue.ts + - litellm/scripts/label-issue.test.ts + - litellm/scripts/issue-labels.ts + - litellm/scripts/auto-close-duplicates.ts permissions: {} @@ -49,7 +49,7 @@ jobs: bun-version: "1.4.0" - name: Test the gate, the validation and the label step - run: bun test scripts/classify-issue.test.ts scripts/label-issue.test.ts + run: bun test litellm/scripts/classify-issue.test.ts litellm/scripts/label-issue.test.ts classify-issue: # An edit to a labelled issue is dropped here; the script decides the rest against the live labels @@ -73,7 +73,7 @@ jobs: with: sparse-checkout: | .github - scripts + litellm/scripts persist-credentials: false - name: Setup Bun @@ -108,7 +108,7 @@ jobs: ISSUE_CLASSIFIER_MODEL: ${{ vars.ISSUE_CLASSIFIER_MODEL }} run: | set -euo pipefail - bun run scripts/classify-issue.ts > classification.json + bun run litellm/scripts/classify-issue.ts > classification.json { echo 'verdict< /dev/null 2>&1 uv run --no-sync --with mutmut==3.5.0 mutmut results > mutmut-results.txt 2>&1 - uv run --no-sync python scripts/mutation_report.py + uv run --no-sync python litellm/scripts/mutation_report.py # The full report can be very long for big test files; the run-page # summary cuts off at 1 MB. Append the head of the report (summary # + survivor list) and link out to the artifact for the full body. diff --git a/.github/workflows/publish-lint-base-counts.yml b/.github/workflows/publish-lint-base-counts.yml index bbe9cadc893..b0a297932f7 100644 --- a/.github/workflows/publish-lint-base-counts.yml +++ b/.github/workflows/publish-lint-base-counts.yml @@ -3,7 +3,7 @@ name: Publish lint base counts # Every commit on main can become a future merge-base. # Publishing its per-rule counts for each lint gate (strict ruff, type discipline, # test quality, basedpyright) as an artifact lets the gates download them through -# scripts/lint_base_counts.py in seconds instead of scanning the merge-base tree in +# litellm/scripts/lint_base_counts.py in seconds instead of scanning the merge-base tree in # a throwaway worktree on every fresh checkout or moved merge-base. # No concurrency group on purpose: runs must never cancel each other, because # every sha's artifact matters (any of them can become a merge-base). @@ -30,15 +30,15 @@ jobs: matrix: include: - checker: ruff-strict - script: scripts/ruff_strict_gate.py + script: litellm/scripts/ruff_strict_gate.py - checker: type-discipline - script: scripts/type_discipline_gate.py + script: litellm/scripts/type_discipline_gate.py - checker: test-quality - script: scripts/test_quality_gate.py + script: litellm/scripts/test_quality_gate.py - checker: openapi-docs - script: scripts/openapi_docs_gate.py + script: litellm/scripts/openapi_docs_gate.py - checker: basedpyright - script: scripts/type_check_gate.py + script: litellm/scripts/type_check_gate.py steps: - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 @@ -91,7 +91,7 @@ jobs: - name: Emit basedpyright counts for HEAD if: matrix.checker == 'basedpyright' run: | - python scripts/type_check_gate.py --emit-counts-dir "$RUNNER_TEMP/lint-counts" + python litellm/scripts/type_check_gate.py --emit-counts-dir "$RUNNER_TEMP/lint-counts" - name: Name the counts artifact run: | diff --git a/.github/workflows/spend-logs-guard.yml b/.github/workflows/spend-logs-guard.yml index 26523450013..9405c37b9c4 100644 --- a/.github/workflows/spend-logs-guard.yml +++ b/.github/workflows/spend-logs-guard.yml @@ -42,8 +42,11 @@ jobs: MERGE_BASE: ${{ steps.revisions.outputs.merge_base }} HEAD_SHA: ${{ github.event.pull_request.head.sha }} run: | - guard=scripts/ci_cd/spend_logs_guard.py + guard=litellm/scripts/ci_cd/spend_logs_guard.py # TODO: Drop the legacy path after this lands on main. + if [ ! -f "$guard" ]; then + guard=scripts/ci_cd/spend_logs_guard.py + fi if [ ! -f "$guard" ]; then guard=ci_cd/spend_logs_guard.py fi diff --git a/.github/workflows/sync-schema.yml b/.github/workflows/sync-schema.yml index 597ff592ee6..3a83444cb97 100644 --- a/.github/workflows/sync-schema.yml +++ b/.github/workflows/sync-schema.yml @@ -1,9 +1,9 @@ -name: Sync schema.prisma copies +name: Sync litellm/schema.prisma copies on: pull_request: paths: - - 'schema.prisma' + - 'litellm/schema.prisma' # Scoped to ONLY the permissions needed: # - contents:write to push the sync commit to the PR branch @@ -37,7 +37,7 @@ jobs: - name: Reject symlinked schema files run: | - for f in schema.prisma litellm/proxy/schema.prisma litellm/proxy-extras/litellm_proxy_extras/schema.prisma; do + for f in litellm/schema.prisma litellm/proxy/schema.prisma litellm/proxy-extras/litellm_proxy_extras/schema.prisma; do if [ -L "$f" ]; then echo "::error file=$f::$f is a symlink, which is not allowed" exit 1 @@ -46,8 +46,8 @@ jobs: - name: Copy root schema to other locations run: | - cp schema.prisma litellm/proxy/schema.prisma - cp schema.prisma litellm/proxy-extras/litellm_proxy_extras/schema.prisma + cp litellm/schema.prisma litellm/proxy/schema.prisma + cp litellm/schema.prisma litellm/proxy-extras/litellm_proxy_extras/schema.prisma - name: Check for changes id: diff @@ -69,5 +69,5 @@ jobs: git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git checkout -B "$GITHUB_HEAD_REF" git add -- litellm/proxy/schema.prisma litellm/proxy-extras/litellm_proxy_extras/schema.prisma - git commit -m "chore: sync schema.prisma copies from root" + git commit -m "chore: sync litellm/schema.prisma copies from the canonical schema" git push origin "HEAD:$GITHUB_HEAD_REF" diff --git a/.github/workflows/test-linting.yml b/.github/workflows/test-linting.yml index 80502cc4c5f..f401d022858 100644 --- a/.github/workflows/test-linting.yml +++ b/.github/workflows/test-linting.yml @@ -114,7 +114,7 @@ jobs: - name: Check ruff format if: steps.changes.outputs.decision != 'skip' run: | - git diff --name-only --diff-filter=ACMR "$GATE_BASE_SHA" HEAD -- ':(glob)litellm/**/*.py' | grep -Ev '^litellm/(enterprise|ui|vscode-extension|rust|proxy-extras|packaging|cli)/' > "$RUNNER_TEMP/ruff_format_files.txt" || true + git diff --name-only --diff-filter=ACMR "$GATE_BASE_SHA" HEAD -- ':(glob)litellm/**/*.py' | grep -Ev '^litellm/(enterprise|ui|vscode-extension|rust|proxy-extras|packaging|cli|scripts|runtime)/' > "$RUNNER_TEMP/ruff_format_files.txt" || true if [ ! -s "$RUNNER_TEMP/ruff_format_files.txt" ]; then echo "No changed litellm Python files to check with ruff format." exit 0 @@ -133,7 +133,7 @@ jobs: - name: Check MCP operation boundary if: steps.changes.outputs.decision != 'skip' - run: uv run --no-sync python scripts/check_mcp_operation_boundary.py + run: uv run --no-sync python litellm/scripts/check_mcp_operation_boundary.py - name: Run Ruff linting if: steps.changes.outputs.decision != 'skip' @@ -152,21 +152,21 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | - uv run --no-sync python scripts/ruff_strict_gate.py --base "$GATE_BASE_SHA" + uv run --no-sync python litellm/scripts/ruff_strict_gate.py --base "$GATE_BASE_SHA" - name: Check type discipline (mutable collections / casts / type guards / kwargs / unexplained suppressions, delta vs merge-base counts) if: steps.changes.outputs.decision != 'skip' env: GH_TOKEN: ${{ github.token }} run: | - uv run --no-sync python scripts/type_discipline_gate.py --base "$GATE_BASE_SHA" + uv run --no-sync python litellm/scripts/type_discipline_gate.py --base "$GATE_BASE_SHA" - name: Check test quality (zero-assert / mock-echo tests, sys.path.insert, raw env writes, litellm global mutation, credential-gated skips, conftest snapshot inventory, delta vs merge-base counts) if: steps.changes.outputs.decision != 'skip' env: GH_TOKEN: ${{ github.token }} run: | - uv run --no-sync python scripts/test_quality_gate.py --base "$GATE_BASE_SHA" + uv run --no-sync python litellm/scripts/test_quality_gate.py --base "$GATE_BASE_SHA" - name: Check OpenAPI docs (POST routes without a request schema, description or 200 schema, delta vs merge-base counts) if: steps.changes.outputs.decision != 'skip' @@ -174,7 +174,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | uv sync --frozen --group proxy-dev --group e2e-dev --extra proxy - uv run --no-sync python scripts/openapi_docs_gate.py --base "$GATE_BASE_SHA" + uv run --no-sync python litellm/scripts/openapi_docs_gate.py --base "$GATE_BASE_SHA" - name: Print OpenAI version if: steps.changes.outputs.decision != 'skip' @@ -186,7 +186,7 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | - uv run --no-sync python scripts/type_check_gate.py --base "$GATE_BASE_SHA" + uv run --no-sync python litellm/scripts/type_check_gate.py --base "$GATE_BASE_SHA" - name: Check tests/e2e basedpyright (zero errors) if: steps.changes.outputs.decision != 'skip' @@ -258,7 +258,7 @@ jobs: if [ -n "$GITGUARDIAN_API_KEY" ]; then retry() { "$@" || { sleep 15; "$@"; } || { sleep 30; "$@"; }; } retry git fetch --no-tags --unshallow origin - uv tool run --from 'ggshield==1.48.0' ggshield secret scan repo . + uv tool run --from 'ggshield==1.48.0' ggshield --config-path .github/gitguardian.yaml secret scan repo . else echo "GITGUARDIAN_API_KEY not set, skipping ggshield scan" fi @@ -375,7 +375,7 @@ jobs: exit 0 fi files="$(git diff --name-only "$base" HEAD)" - if grep -Ev '^litellm/(ui|vscode-extension|rust|proxy-extras|packaging|cli)/' <<< "$files" | grep -E '^(litellm/|enterprise/|(pyproject\.toml|uv\.lock)$|\.github/workflows/test-linting\.yml$)' >/dev/null || grep -Eq '^litellm/ui/litellm-dashboard/(src/lib/http/schema\.d\.ts|scripts/gen-api-types\.mjs|package(-lock)?\.json)$' <<< "$files"; then + if grep -Ev '^litellm/(ui|vscode-extension|rust|proxy-extras|packaging|cli|scripts|runtime)/' <<< "$files" | grep -E '^(litellm/|enterprise/|(pyproject\.toml|uv\.lock)$|\.github/workflows/test-linting\.yml$)' >/dev/null || grep -Eq '^litellm/ui/litellm-dashboard/(src/lib/http/schema\.d\.ts|scripts/gen-api-types\.mjs|package(-lock)?\.json)$' <<< "$files"; then echo "relevant=true" >> "$GITHUB_OUTPUT" else echo "No litellm, enterprise, dependency or generator changes in this pull request, nothing to verify." @@ -524,7 +524,7 @@ jobs: 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 + run: uv run --no-sync python litellm/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 diff --git a/.github/workflows/test-mcp-dependency-resolution.yml b/.github/workflows/test-mcp-dependency-resolution.yml index 0305ed7939e..6d6b2307700 100644 --- a/.github/workflows/test-mcp-dependency-resolution.yml +++ b/.github/workflows/test-mcp-dependency-resolution.yml @@ -10,17 +10,17 @@ on: - "uv.lock" - "uv.toml" - ".python-version" - - "rust-toolchain.toml" + - "litellm/rust/rust-toolchain.toml" - "litellm/rust/**" - "litellm/__init__.py" - "litellm/_version.py" - "litellm/_lazy_imports_registry.py" - - "scripts/build_core_distribution.py" + - "litellm/scripts/build_core_distribution.py" - "litellm/proxy/proxy_server.py" - "litellm/**/*mcp*" - "litellm/**/*mcp*/**" - "litellm/integrations/arize/**" - - "scripts/check_mcp_sdk_install.py" + - "litellm/scripts/check_mcp_sdk_install.py" - "tests/base_sdk_tests/**" - ".github/workflows/test-mcp-dependency-resolution.yml" - ".github/actions/detect-changes/**" @@ -91,7 +91,7 @@ jobs: checker=("$GITHUB_WORKSPACE/tests/base_sdk_tests/check_base_sdk_install.py") (cd "$RUNNER_TEMP" && "$GITHUB_WORKSPACE/.venv-$extra/bin/python" -I "$GITHUB_WORKSPACE/tests/base_sdk_tests/check_sdk_http.py") else - checker=("$GITHUB_WORKSPACE/scripts/check_mcp_sdk_install.py" --extra "$extra") + checker=("$GITHUB_WORKSPACE/litellm/scripts/check_mcp_sdk_install.py" --extra "$extra") fi (cd "$RUNNER_TEMP" && "$GITHUB_WORKSPACE/.venv-$extra/bin/python" "${checker[@]}") done @@ -115,7 +115,7 @@ jobs: if [ "$extra" = core ]; then checker=("$GITHUB_WORKSPACE/tests/base_sdk_tests/check_base_sdk_install.py") else - checker=("$GITHUB_WORKSPACE/scripts/check_mcp_sdk_install.py" --extra "$extra") + checker=("$GITHUB_WORKSPACE/litellm/scripts/check_mcp_sdk_install.py" --extra "$extra") fi (cd "$RUNNER_TEMP" && "$GITHUB_WORKSPACE/.venv-lowest-$extra/bin/python" "${checker[@]}") done @@ -147,15 +147,16 @@ jobs: - name: Build the core wheel and source distribution run: >- uv run --no-project --with coverage==7.14.0 python -m coverage run --rcfile=/dev/null - --branch --include="*/scripts/build_core_distribution.py" - scripts/build_core_distribution.py --out-dir dist/core + --branch --include="*/litellm/scripts/build_core_distribution.py" + litellm/scripts/build_core_distribution.py --out-dir dist/core - name: Verify metadata, resources, and independent source rebuild env: CORE_DISTRIBUTION_DIR: ${{ github.workspace }}/dist/core run: >- uv run --no-project --with pytest==9.0.3 --with pytest-cov==5.0.0 --with coverage==7.14.0 --with 'tomli==2.4.1; python_version < "3.11"' - python -m pytest tests/base_sdk_tests/test_core_distribution.py -v - --cov-config=/dev/null --cov=scripts.build_core_distribution --cov-branch --cov-append --cov-report= + python -m coverage run --rcfile=/dev/null --append --branch + --include="*/litellm/scripts/build_core_distribution.py" + -m pytest tests/base_sdk_tests/test_core_distribution.py -v - name: Verify isolated core installations run: | wheel=$(realpath dist/core/litellm_core-*.whl) diff --git a/.github/workflows/test-merge-smoke.yml b/.github/workflows/test-merge-smoke.yml index cf5c16f679d..362d56c314e 100644 --- a/.github/workflows/test-merge-smoke.yml +++ b/.github/workflows/test-merge-smoke.yml @@ -229,7 +229,7 @@ jobs: "prisma==0.11.0" \ "openai==2.24.0" export PATH="/tmp/litellm-pip/bin:$PATH" - /tmp/litellm-pip/bin/prisma generate --schema=schema.prisma + /tmp/litellm-pip/bin/prisma generate --schema=litellm/schema.prisma - name: Start the fake OpenAI endpoint run: | diff --git a/.github/workflows/test-rust-db.yml b/.github/workflows/test-rust-db.yml index 309843a11d5..6d4eba7b25e 100644 --- a/.github/workflows/test-rust-db.yml +++ b/.github/workflows/test-rust-db.yml @@ -9,8 +9,8 @@ on: - "litellm/rust/clippy.toml" - "litellm/proxy-extras/litellm_proxy_extras/migrations/**" - "**/schema.prisma" - - ".cargo/**" - - "rust-toolchain.toml" + - "litellm/rust/.cargo/**" + - "litellm/rust/rust-toolchain.toml" - "pyproject.toml" - "uv.lock" - ".github/actions/setup-uv-with-retries/**" @@ -26,8 +26,8 @@ on: - "litellm/rust/clippy.toml" - "litellm/proxy-extras/litellm_proxy_extras/migrations/**" - "**/schema.prisma" - - ".cargo/**" - - "rust-toolchain.toml" + - "litellm/rust/.cargo/**" + - "litellm/rust/rust-toolchain.toml" - "pyproject.toml" - "uv.lock" - ".github/actions/setup-uv-with-retries/**" diff --git a/.github/workflows/test-rust.yml b/.github/workflows/test-rust.yml index 1e60b301ad1..74a6957aba4 100644 --- a/.github/workflows/test-rust.yml +++ b/.github/workflows/test-rust.yml @@ -6,9 +6,9 @@ on: - "litellm/rust/**" - "model_prices_and_context_window.json" - "litellm/rust_bridge/**" - - "scripts/generate_trace_types.py" - - "scripts/trace_codegen/**" - - "scripts/lens_assets/**" + - "litellm/scripts/generate_trace_types.py" + - "litellm/scripts/trace_codegen/**" + - "litellm/scripts/lens_assets/**" - "litellm/tracing/**" - "tests/test_litellm_rust/**" - "litellm/integrations/custom_logger.py" @@ -24,10 +24,10 @@ on: - "litellm/llms/base_llm/ocr/**" - "litellm/llms/custom_httpx/llm_http_handler.py" - "Makefile" - - ".cargo/**" + - "litellm/rust/.cargo/**" - "pyproject.toml" - "uv.lock" - - "rust-toolchain.toml" + - "litellm/rust/rust-toolchain.toml" - ".github/actions/setup-uv-with-retries/**" - ".github/scripts/smoke_test_native_wheel.py" - ".github/scripts/verify_linux_native_wheel.py" @@ -41,9 +41,9 @@ on: - "litellm/rust/**" - "model_prices_and_context_window.json" - "litellm/rust_bridge/**" - - "scripts/generate_trace_types.py" - - "scripts/trace_codegen/**" - - "scripts/lens_assets/**" + - "litellm/scripts/generate_trace_types.py" + - "litellm/scripts/trace_codegen/**" + - "litellm/scripts/lens_assets/**" - "litellm/tracing/**" - "tests/test_litellm_rust/**" - "litellm/integrations/custom_logger.py" @@ -59,10 +59,10 @@ on: - "litellm/llms/base_llm/ocr/**" - "litellm/llms/custom_httpx/llm_http_handler.py" - "Makefile" - - ".cargo/**" + - "litellm/rust/.cargo/**" - "pyproject.toml" - "uv.lock" - - "rust-toolchain.toml" + - "litellm/rust/rust-toolchain.toml" - ".github/actions/setup-uv-with-retries/**" - ".github/scripts/smoke_test_native_wheel.py" - ".github/scripts/verify_linux_native_wheel.py" @@ -96,7 +96,9 @@ jobs: with: persist-credentials: false - - run: rustup toolchain install --no-self-update + - name: Configure the Rust build environment + working-directory: . + run: bash .github/scripts/setup_rust_environment.sh - run: cargo fmt --all --check @@ -160,7 +162,7 @@ jobs: - name: Check generated trace contracts working-directory: . - run: uv run scripts/generate_trace_types.py --check + run: uv run litellm/scripts/generate_trace_types.py --check - run: cargo nextest run --workspace --locked diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml index b4ef0f3bc1c..4c048ace26a 100644 --- a/.github/workflows/test-unit.yml +++ b/.github/workflows/test-unit.yml @@ -1080,7 +1080,7 @@ jobs: fi uv run --no-sync python -c 'import os, sys; print(sys.version); assert f"{sys.version_info.major}.{sys.version_info.minor}" == os.environ["UV_PYTHON"]' - - name: Check schema.prisma against the merge base + - name: Check litellm/schema.prisma against the merge base if: steps.changes.outputs.decision != 'skip' && matrix.shard == 'db-and-spend' && github.event_name == 'pull_request' timeout-minutes: 3 env: @@ -1093,7 +1093,7 @@ jobs: merge_base=$(gh api "repos/${GITHUB_REPOSITORY}/compare/${base_ref}...${HEAD_SHA}?per_page=1" --jq '.merge_base_commit.sha') test -n "$merge_base" git fetch --no-tags --depth=1 origin "$merge_base" - uv run --no-sync python scripts/check_schema_compatibility.py --base-commit "$merge_base" + uv run --no-sync python litellm/scripts/check_schema_compatibility.py --base-commit "$merge_base" - name: Cache Prisma binaries if: steps.changes.outputs.decision != 'skip' diff --git a/.gitignore b/.gitignore index e7785febd94..0e20c40bc7f 100644 --- a/.gitignore +++ b/.gitignore @@ -106,7 +106,7 @@ litellm_config.yaml litellm/proxy/to_delete_loadtest_work/* update_model_cost_map.py tests/unit/proxy/mcp_server/test_mcp_server_manager.py -scripts/test_vertex_ai_search.py +litellm/scripts/test_vertex_ai_search.py LAZY_LOADING_IMPROVEMENTS.md STABILIZATION_TODO.md **/test-results diff --git a/AGENTS.md b/AGENTS.md index 77a3c065c42..6a04ad56071 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -30,7 +30,7 @@ A test must only fail when litellm code changes. Never pin facts we don't own (a End-to-end tests belong in `tests/e2e/`. A rule about one directory's files, like its harness or which CI runs it, goes in that directory's `AGENTS.md`, never only in a README or here. Read a directory's `AGENTS.md` before editing files in it -When creating PRs, target the repository's current default branch for both internal and external / OSS contributions. Check it with `python3 scripts/default_branch.py --branch` instead of assuming a branch name or relying on cached `origin/HEAD` +When creating PRs, target the repository's current default branch for both internal and external / OSS contributions. Check it with `python3 litellm/scripts/default_branch.py --branch` instead of assuming a branch name or relying on cached `origin/HEAD` When writing a PR body, treat the comments and imperative instructions inside .github/PULL_REQUEST_TEMPLATE/general.md as rules to follow, not just layout. Agent harnesses may strip HTML comments from copies of that file injected into context, so read .github/PULL_REQUEST_TEMPLATE/general.md from disk before writing a PR body to make sure you see every comment rule. A section you have nothing to put in (Relevant issues, Affected release, Linear ticket, Caveats, QA runbook, and so on) is removed entirely, heading included, never left as an empty title @@ -56,11 +56,11 @@ Don't hesitate to use values in .env to get needed API keys and other secrets, a Python max line length is 120, not 88 -The five lint gates (`scripts/ruff_strict_gate.py`, `scripts/type_discipline_gate.py`, `scripts/test_quality_gate.py`, `scripts/openapi_docs_gate.py`, `scripts/type_check_gate.py`) compare each rule's codebase count on your branch against the count at its merge-base with the default branch, and a rule may not grow. There are no budget files to edit or ratchet: when a gate fails, fix the violations the branch introduced or remove at least as many of that rule elsewhere in the tree. The one exception is `reportAny` / `reportExplicitAny`, which share a fixed codebase-wide cap in `ANY_CAPS` in `scripts/type_check_gate.py` because Any spreads past the lines you touch. A branch may add Anys while the total stays under that cap. Only lower `ANY_CAPS`, and only in its own PR to the default branch, never raise it on a feature branch +The five lint gates (`litellm/scripts/ruff_strict_gate.py`, `litellm/scripts/type_discipline_gate.py`, `litellm/scripts/test_quality_gate.py`, `litellm/scripts/openapi_docs_gate.py`, `litellm/scripts/type_check_gate.py`) compare each rule's codebase count on your branch against the count at its merge-base with the default branch, and a rule may not grow. There are no budget files to edit or ratchet: when a gate fails, fix the violations the branch introduced or remove at least as many of that rule elsewhere in the tree. The one exception is `reportAny` / `reportExplicitAny`, which share a fixed codebase-wide cap in `ANY_CAPS` in `litellm/scripts/type_check_gate.py` because Any spreads past the lines you touch. A branch may add Anys while the total stays under that cap. Only lower `ANY_CAPS`, and only in its own PR to the default branch, never raise it on a feature branch `make check` (f.k.a. `make pre-commit`, which still works identically as an alias) saves its complete output to a log file in .git (overwriting previous logs) and prints that path as its first and last output lines. To inspect a run, read or grep that log instead of re-running the multi-minute checks just to see a different slice -`make check`, `make lint`, `scripts/pre_commit_lint.sh`, and the standalone lint gates (`scripts/ruff_strict_gate.py`, `scripts/type_discipline_gate.py`, `scripts/type_check_gate.py`) each hold one of 2 machine-wide slots, so when other sessions or worktrees on the same box are already running heavy work, yours prints "all N machine-wide slots are busy" followed by "queueing" and then stays quiet until a slot frees. Give the command a long timeout and let it wait rather than killing it, retrying it, or assuming it hung. Don't change the # of machine-wide slots or make it unlimited by setting `LITELLM_GATE_SLOTS=0` +`make check`, `make lint`, `litellm/scripts/pre_commit_lint.sh`, and the standalone lint gates (`litellm/scripts/ruff_strict_gate.py`, `litellm/scripts/type_discipline_gate.py`, `litellm/scripts/type_check_gate.py`) each hold one of 2 machine-wide slots, so when other sessions or worktrees on the same box are already running heavy work, yours prints "all N machine-wide slots are busy" followed by "queueing" and then stays quiet until a slot frees. Give the command a long timeout and let it wait rather than killing it, retrying it, or assuming it hung. Don't change the # of machine-wide slots or make it unlimited by setting `LITELLM_GATE_SLOTS=0` If you're trying to create a new function that relies on untyped stuff, instead of adding more Any's and pushing `reportAny` / `reportExplicitAny` closer to their cap in `ANY_CAPS`, just validate it in the caller with Pydantic (a model or `TypeAdapter` that returns the typed thing or raises will do) and then pass the now typed variable in @@ -88,8 +88,6 @@ Do not put names of customers or customer company names in code, PR descriptions CI supply-chain safety: Never pipe a remote script into a shell (`curl ... | bash`, `wget ... | sh`). Download the artifact to a file, verify its SHA-256 checksum, then install. Pin every external tool to a specific version with a full URL (not `latest` or `stable`). Verify checksums for all downloaded binaries, using the provider's official `.sha256` / `.sha256sum` sidecar when available. These rules apply to every download in CI -For database operations, connection ownership and proxy dependency wiring, follow [database-access](.agents/skills/database-access/SKILL.md) - Prisma migrations apply synchronously at proxy boot, before it serves traffic, so a migration must only change schema, never rewrite rows. No `UPDATE`, `DELETE` or `MERGE`, and no `INSERT ... SELECT`: on a spend-log-sized table any of those is minutes of downtime plus a doubled heap that plain autovacuum won't give back. `tests/code_coverage_tests/check_migrations_no_data_rewrites.py` enforces this. When a rewrite is genuinely bounded and has to ship inside the migration, mark the statement `-- data-migration-ok: ` Follow these coding conventions for new/updated code (a three-line fix in a legacy file shouldn't trigger huge drive-by refactors): diff --git a/Makefile b/Makefile index d30a9ab8293..63fab29d9b5 100644 --- a/Makefile +++ b/Makefile @@ -60,14 +60,18 @@ help: @echo "slots (default 2; 0 disables) so parallel sessions don't thrash one machine." UV := uv +export RUSTUP_TOOLCHAIN ?= $(shell sed -n 's/^[[:space:]]*channel[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/p' litellm/rust/rust-toolchain.toml) +export CARGO_NET_RETRY ?= 5 +export CARGO_HTTP_MULTIPLEXING ?= false +export SQLX_OFFLINE ?= true UV_RUN := $(UV) run --no-sync BASE_REF ?= export BASE_REF -RESOLVE_BASE = python3 scripts/default_branch.py --base "$(BASE_REF)" +RESOLVE_BASE = python3 litellm/scripts/default_branch.py --base "$(BASE_REF)" # Machine-wide slot queue for the heavy targets below; python3 + stdlib only, so -# it runs before any venv exists. See scripts/gate_slot_lock.py. -GATE_SLOT_LOCK := python3 scripts/gate_slot_lock.py +# it runs before any venv exists. See litellm/scripts/gate_slot_lock.py. +GATE_SLOT_LOCK := python3 litellm/scripts/gate_slot_lock.py LINT_DEP_INSTALL ?= install-dev LINT_E2E_DEP_INSTALL ?= lint-install @@ -90,8 +94,8 @@ install-dev: # machine-wide slots the CPU-bound gates below share. bootstrap: $(UV) sync --inexact --frozen --extra proxy --group proxy-dev --group e2e-dev - $(UV_RUN) python scripts/prisma_generate_if_needed.py - cd litellm/ui/litellm-dashboard && ../../../scripts/with_dashboard_node.sh npm install --no-audit --no-fund + $(UV_RUN) python litellm/scripts/prisma_generate_if_needed.py + cd litellm/ui/litellm-dashboard && ../../scripts/with_dashboard_node.sh npm install --no-audit --no-fund @main_root=$$(git worktree list --porcelain | head -1 | sed 's/^worktree //'); \ if [ "$$main_root" != "$$(git rev-parse --show-toplevel)" ] && [ -f "$$main_root/.env" ] && [ ! -f .env ]; then \ cp "$$main_root/.env" .env && echo "bootstrap: copied .env from $$main_root"; \ @@ -123,7 +127,7 @@ install-helm-unittest: # Install git hooks that enforce Conventional Commits. # Opt-in: not chained into install-dev. install-hooks: - ./scripts/install_git_hooks.sh + ./litellm/scripts/install_git_hooks.sh # Formatting # Wrap width is pyproject.toml's single source of truth (line-length = 120), shared by the @@ -139,12 +143,12 @@ lint-fetch-base: # Mirror test-linting.yml's python job environment: the proxy-dev group plus a generated # Prisma client, so `basedpyright tests/e2e` resolves the same modules CI does. The -# basedpyright gate itself no longer measures here (scripts/type_check_gate.py provisions its +# basedpyright gate itself no longer measures here (litellm/scripts/type_check_gate.py provisions its # own .venv-typecheck). --inexact tops up the venv instead of pruning the proxy extras # gen:api and the running proxy need. lint-install: $(UV) sync --inexact --frozen --group proxy-dev --group e2e-dev - $(UV_RUN) python scripts/prisma_generate_if_needed.py + $(UV_RUN) python litellm/scripts/prisma_generate_if_needed.py # Diff-scoped format check, mirroring test-linting.yml's "Check ruff format" step: # only the litellm Python files changed vs the base are checked, so a pre-existing @@ -163,7 +167,7 @@ lint-format-check-changed: $(LINT_DEP_INSTALL) $(LINT_DEP_BASE) # Linting targets lint-ruff: $(LINT_DEP_INSTALL) - $(UV_RUN) python scripts/check_mcp_operation_boundary.py + $(UV_RUN) python litellm/scripts/check_mcp_operation_boundary.py cd litellm && $(UV_RUN) ruff check . && cd .. $(UV_RUN) ruff check --config .github/linters/ruff-tests.toml tests @@ -204,7 +208,7 @@ lint-ruff-FULL-dev: install-dev else echo "No changed .py files to check."; fi lint-basedpyright: $(LINT_DEP_INSTALL) $(LINT_DEP_BASE) - $(UV_RUN) python scripts/type_check_gate.py --base "$(BASE_REF)" + $(UV_RUN) python litellm/scripts/type_check_gate.py --base "$(BASE_REF)" lint-e2e-basedpyright: $(LINT_E2E_DEP_INSTALL) $(UV_RUN) basedpyright tests/e2e tests/e2e_harness @@ -212,29 +216,29 @@ lint-e2e-basedpyright: $(LINT_E2E_DEP_INSTALL) # Type-discipline gate (mutable collections / casts / type guards / kwargs / # unexplained suppressions), the test-linting.yml step `make lint` used to omit. lint-type-discipline: $(LINT_DEP_INSTALL) $(LINT_DEP_BASE) - $(UV_RUN) python scripts/type_discipline_gate.py --base "$(BASE_REF)" + $(UV_RUN) python litellm/scripts/type_discipline_gate.py --base "$(BASE_REF)" # Test-quality gate (zero-assert / mock-echo tests, sys.path.insert, raw env writes, # litellm module-global mutation, credential-gated skips, conftest snapshot # inventory), counted across tests/ the same delta-vs-base way. lint-test-quality: $(LINT_DEP_INSTALL) $(LINT_DEP_BASE) - $(UV_RUN) python scripts/test_quality_gate.py --base "$(BASE_REF)" + $(UV_RUN) python litellm/scripts/test_quality_gate.py --base "$(BASE_REF)" # OpenAPI docs gate (POST routes without a request body schema, a description or a # 200 schema in app.openapi()), counted the same delta-vs-base way so a new endpoint # has to show up documented in Swagger UI. lint-openapi-docs: $(LINT_DEP_INSTALL) $(LINT_DEP_BASE) - $(UV_RUN) python scripts/openapi_docs_gate.py --base "$(BASE_REF)" + $(UV_RUN) python litellm/scripts/openapi_docs_gate.py --base "$(BASE_REF)" lint-format: format-check lint-ruff-strict: install-dev - $(UV_RUN) python scripts/ruff_strict_gate.py --base "$(BASE_REF)" + $(UV_RUN) python litellm/scripts/ruff_strict_gate.py --base "$(BASE_REF)" # Strict gate, invoked the same way CI does in test-linting.yml so a local pass # means the CI check will pass too. lint-gate: $(LINT_DEP_INSTALL) $(LINT_DEP_BASE) - $(UV_RUN) python scripts/ruff_strict_gate.py --base "$(BASE_REF)" + $(UV_RUN) python litellm/scripts/ruff_strict_gate.py --base "$(BASE_REF)" check-circular-imports: $(LINT_DEP_INSTALL) cd litellm && $(UV_RUN) python ../tests/documentation_tests/test_circular_imports.py && cd .. @@ -272,7 +276,7 @@ check: @$(GATE_SLOT_LOCK) $(MAKE) check-inner check-inner: bootstrap - ./scripts/pre_commit_lint.sh + ./litellm/scripts/pre_commit_lint.sh pre-commit: @echo "make pre-commit is a legacy alias; use make check" >&2 diff --git a/README.md b/README.md index 1c6769b1224..c07905759de 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ proxy, CLI, and optional extras Build and install core from this checkout while its release integration is pending: ```shell -python scripts/build_core_distribution.py --out-dir dist/core +python litellm/scripts/build_core_distribution.py --out-dir dist/core python -m pip install dist/core/litellm_core-*.whl ``` diff --git a/litellm/deploy/docker/Dockerfile b/litellm/deploy/docker/Dockerfile index a713983063c..28161792dea 100644 --- a/litellm/deploy/docker/Dockerfile +++ b/litellm/deploy/docker/Dockerfile @@ -68,6 +68,9 @@ RUN apk add --no-cache \ libsndfile ENV UV_PROJECT_ENVIRONMENT=/app/.venv \ + CARGO_NET_RETRY=5 \ + CARGO_HTTP_MULTIPLEXING=false \ + SQLX_OFFLINE=true \ UV_LINK_MODE=copy \ UV_PYTHON_DOWNLOADS=0 \ PATH="/app/.venv/bin:${PATH}" @@ -116,11 +119,11 @@ RUN uv sync --frozen --no-install-package litellm-proxy --no-default-groups --no RUN uv pip install --python /app/.venv/bin/python --no-deps /wheels/litellm_proxy-*.whl -RUN cp -r litellm/enterprise "$(.venv/bin/python -c 'import sysconfig; print(sysconfig.get_path("purelib"))')/litellm/enterprise" +RUN cp -r litellm/enterprise litellm/runtime "$(.venv/bin/python -c 'import sysconfig; print(sysconfig.get_path("purelib"))')/litellm/" RUN HOME=/opt/prisma XDG_CACHE_HOME=/opt/prisma/.cache PRISMA_BINARY_CACHE_DIR=/opt/prisma/binaries \ npm_config_cache=/root/.npm \ - prisma generate --schema=./schema.prisma + prisma generate --schema=litellm/schema.prisma RUN sed -i 's/\r$//' litellm/deploy/docker/docker-entrypoint.sh && chmod +x litellm/deploy/docker/docker-entrypoint.sh @@ -181,14 +184,13 @@ ENV PATH="/app/.venv/bin:${PATH}" \ COPY --from=builder /app/.venv /app/.venv COPY --from=liteadmin-builder /opt/liteadmin /opt/liteadmin COPY --from=builder /app/litellm/deploy/docker/docker-entrypoint.sh /app/docker-entrypoint.sh -COPY --from=builder /app/schema.prisma /app/schema.prisma +COPY --from=builder /app/litellm/schema.prisma /app/litellm/schema.prisma +COPY --from=builder /app/litellm/schema.prisma /app/schema.prisma +COPY --from=builder /app/litellm/runtime/gateway /app/gateway COPY --from=builder /app/litellm/proxy/prisma_migration.py /app/litellm/proxy/prisma_migration.py # enterprise/ is imported by source path at runtime (proxy_cli puts the # working directory on sys.path; litellm/proxy/hooks resolves # litellm.enterprise.enterprise_hooks from it) -COPY --from=builder /app/gateway /app/gateway -COPY --from=builder /app/backend /app/backend -COPY --from=builder /app/migrations /app/migrations COPY --from=builder /opt/prisma /opt/prisma COPY --from=builder /var/lib/litellm /var/lib/litellm COPY litellm/ui/nginx.conf /etc/nginx/nginx.conf @@ -207,7 +209,7 @@ RUN find /app/.venv -depth -type d -path "*/tornado/test" -exec rm -rf {} + && \ ls /opt/prisma/binaries/node_modules/@prisma/engines/query-engine-* >/dev/null && \ python -c "from prisma.client import BINARY_PATHS; paths = list(BINARY_PATHS.query_engine.values()); assert paths and all(p.startswith('/opt/prisma/') for p in paths), paths" && \ python -c "from litellm.rust_bridge import _native" && \ - python -c "import gateway.launch, backend.main" + python -c "import gateway.launch, litellm.runtime.backend.main" USER 65532:65532 diff --git a/litellm/deploy/docker/README.md b/litellm/deploy/docker/README.md index 8dc7dacc34b..d1e6e9dc142 100644 --- a/litellm/deploy/docker/README.md +++ b/litellm/deploy/docker/README.md @@ -19,11 +19,11 @@ Saved quickstart scripts need a one-time URL override after the source layout mi ```bash LITELLM_COMPOSE_URL=https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/deploy/docker/docker-compose.quickstart.yml \ -LITELLM_SCRIPT_URL=https://raw.githubusercontent.com/BerriAI/litellm/main/scripts/quickstart.sh \ +LITELLM_SCRIPT_URL=https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/scripts/quickstart.sh \ litellm-gateway update ``` -In PowerShell, set the same environment variables, with `LITELLM_SCRIPT_URL` ending in `scripts/quickstart.ps1`, before running `litellm-gateway update`. Remove the overrides after the saved script refreshes. +In PowerShell, set the same environment variables, with `LITELLM_SCRIPT_URL` ending in `litellm/scripts/quickstart.ps1`, before running `litellm-gateway update`. Remove the overrides after the saved script refreshes. ## Prerequisites @@ -42,9 +42,9 @@ Every LiteLLM container runs the same image. The first word of the container com |--------------|-----------------------------------------------------|------| | `proxy` | `litellm ...` (everything in one process, default) | 4000 | | `gateway` | `python -m gateway.launch ...` (inference routes) | 4000 | -| `backend` | `uvicorn backend.main:app ...` (management routes) | 4001 | +| `backend` | `uvicorn litellm.runtime.backend.main:app ...` (management routes) | 4001 | | `ui` | nginx serving the static admin UI | 3000 | -| `migrations` | `python migrations/run.py`, `prisma migrate deploy` then exit | | +| `migrations` | `python -m litellm.runtime.migrations.run`, `prisma migrate deploy` then exit | | | `metrics` | `python -m litellm.proxy.prometheus_metrics_server ...` | `--port` | | `collector` | `python -m litellm.proxy.collector ...` | | diff --git a/litellm/deploy/docker/docker-entrypoint.sh b/litellm/deploy/docker/docker-entrypoint.sh index 621236491a9..ff8fb8b5d5b 100755 --- a/litellm/deploy/docker/docker-entrypoint.sh +++ b/litellm/deploy/docker/docker-entrypoint.sh @@ -8,9 +8,9 @@ # # proxy litellm ARGS everything in one process (default) # gateway python -m gateway.launch ARGS inference routes, 0.0.0.0:4000 -# backend uvicorn backend.main:app ARGS management routes, 0.0.0.0:4001 +# backend uvicorn litellm.runtime.backend.main:app ARGS management routes, 0.0.0.0:4001 # ui nginx serving the admin UI port 3000 -# migrations python migrations/run.py prisma migrate deploy, then exit +# migrations python litellm/runtime/migrations/run.py prisma migrate deploy, then exit # metrics python -m litellm.proxy.prometheus_metrics_server ARGS # collector python -m litellm.proxy.collector ARGS # --admin-agent the bundled LiteAdmin Slack agent (litellm-admin-agent --web ARGS) @@ -97,7 +97,7 @@ os.execvp("litellm", ["litellm", *sys.argv[1:]])' "$@" set -- python -m gateway.launch --workers "${NUM_WORKERS:-1}" --host 0.0.0.0 --port 4000 "$@" ;; backend) - set -- uvicorn backend.main:app --host 0.0.0.0 --port 4001 "$@" + set -- uvicorn litellm.runtime.backend.main:app --host 0.0.0.0 --port 4001 "$@" ;; ui) ui_hook="$(dirname "$0")/ui/docker-entrypoint.d/40-litellm-runtime-config.sh" @@ -108,7 +108,7 @@ os.execvp("litellm", ["litellm", *sys.argv[1:]])' "$@" exec nginx -g 'daemon off;' "$@" ;; migrations) - set -- python /app/migrations/run.py "$@" + set -- python -m litellm.runtime.migrations.run "$@" ;; metrics) set -- python -m litellm.proxy.prometheus_metrics_server "$@" diff --git a/litellm/deploy/helm/litellm/templates/_helpers.tpl b/litellm/deploy/helm/litellm/templates/_helpers.tpl index 13222d8284e..827c55d2aef 100644 --- a/litellm/deploy/helm/litellm/templates/_helpers.tpl +++ b/litellm/deploy/helm/litellm/templates/_helpers.tpl @@ -296,7 +296,7 @@ by the controller rather than declared, so nothing there can collide. LITELLM_MASTER_KEY, and PROXY_MASTER_KEY for configs copied from litellm-helm, for the app containers only. The migrations Job runs as a pre-install hook, before the chart's generated master key Secret exists, and -migrations/run.py never reads the key, so the Job must not reference it. +litellm/runtime/migrations/run.py never reads the key, so the Job must not reference it. */}} {{- define "litellm.masterKeyEnv" -}} {{- range list "LITELLM_MASTER_KEY" "PROXY_MASTER_KEY" }} @@ -507,7 +507,7 @@ The migrations Job (helm.sh/hook: pre-upgrade) is the single owner of Prisma schema-update on startup and contends with the Job — and with each other — for Prisma's Postgres advisory lock on the writer, which makes the Job's `migrate deploy` intermittently block until its per-attempt timeout -and retry-exhaust. The Job's entrypoint (migrations/run.py) does not import +and retry-exhaust. The Job's entrypoint (litellm/runtime/migrations/run.py) does not import proxy_server and never reads DISABLE_SCHEMA_UPDATE, so emitting it here is a harmless no-op for the Job and authoritative for the app pods. */}} diff --git a/litellm/deploy/helm/litellm/templates/ingress.yaml b/litellm/deploy/helm/litellm/templates/ingress.yaml index 6bc5e8f1acb..6c3670152ca 100644 --- a/litellm/deploy/helm/litellm/templates/ingress.yaml +++ b/litellm/deploy/helm/litellm/templates/ingress.yaml @@ -90,7 +90,7 @@ {{- $uiPaths = append $uiPaths (dict "path" "/*.txt" "pathType" "ImplementationSpecific") }} {{- end }} {{/* - Gateway data-plane prefixes — must mirror gateway/routes/allowlist.py. + Gateway data-plane prefixes — must mirror litellm/runtime/gateway/routes/allowlist.py. Versioned paths are listed explicitly to avoid routing management routes (e.g. /v1/access_group, /v2/key/info, /v1/tool/*, /v1/agents, /v1/workflows, /v2/user/info, /v2/team/list, /v2/model/info, /v2/login, /v2/guardrails/*, diff --git a/litellm/deploy/terraform/litellm/README.md b/litellm/deploy/terraform/litellm/README.md index 70011dbb393..22f768e3718 100644 --- a/litellm/deploy/terraform/litellm/README.md +++ b/litellm/deploy/terraform/litellm/README.md @@ -46,7 +46,7 @@ starts the process named by its first argument, so each workload only differs in the argument the module passes The load balancer routes gateway path prefixes (mirrored verbatim from -`gateway/routes/allowlist.py`) to the gateway, UI asset paths (`/`, +`litellm/runtime/gateway/routes/allowlist.py`) to the gateway, UI asset paths (`/`, `/litellm-asset-prefix/*`, `/_next/*`, `/favicon.ico`) to the UI, and everything else to the backend. diff --git a/litellm/deploy/terraform/litellm/aws/locals.tf b/litellm/deploy/terraform/litellm/aws/locals.tf index e15310ead3e..9a772ed7a81 100644 --- a/litellm/deploy/terraform/litellm/aws/locals.tf +++ b/litellm/deploy/terraform/litellm/aws/locals.tf @@ -1,4 +1,4 @@ -# Gateway path prefixes — mirrored verbatim from gateway/routes/allowlist.py +# Gateway path prefixes — mirrored verbatim from litellm/runtime/gateway/routes/allowlist.py # and the helm ingress in litellm/deploy/helm/litellm/templates/ingress.yaml. Anything not in # this list and not a UI asset path falls through to the backend (management # API) catch-all rule on the ALB. diff --git a/litellm/deploy/terraform/litellm/gcp/locals.tf b/litellm/deploy/terraform/litellm/gcp/locals.tf index ad3a0d385d9..9bbe8bfd879 100644 --- a/litellm/deploy/terraform/litellm/gcp/locals.tf +++ b/litellm/deploy/terraform/litellm/gcp/locals.tf @@ -1,4 +1,4 @@ -# Gateway path prefixes — mirrored verbatim from gateway/routes/allowlist.py +# Gateway path prefixes — mirrored verbatim from litellm/runtime/gateway/routes/allowlist.py # and litellm/deploy/helm/litellm/templates/ingress.yaml. URL maps use the "path matcher" # rule with `paths` lists; up to 10 path globs per rule, up to 50 rules # per matcher. Easily fits the gateway list in one rule per chunk-of-10. diff --git a/litellm/packaging/litellm-core/pyproject.toml b/litellm/packaging/litellm-core/pyproject.toml index 9dd91f82cce..f002db805c1 100644 --- a/litellm/packaging/litellm-core/pyproject.toml +++ b/litellm/packaging/litellm-core/pyproject.toml @@ -54,8 +54,8 @@ features = ["extension-module"] profile = "release" editable-profile = "dev" include = [ - { path = "rust-toolchain.toml", format = "sdist" }, - { path = ".cargo/config.toml", format = "sdist" }, + { path = "litellm/rust/rust-toolchain.toml", format = "sdist" }, + { path = "litellm/rust/.cargo/config.toml", format = "sdist" }, { path = "model_prices_and_context_window.json", format = "sdist" }, "litellm/router_strategy/complexity_router/artifacts/*.json", "litellm/router_strategy/complexity_router/fuse_presets.json", @@ -66,6 +66,11 @@ include = [ "litellm/proxy/common_utils/codex_bedrock_runtime_models_0.166.0.json", ] exclude = [ + "litellm/scripts", + "litellm/scripts/**", + "litellm/runtime", + "litellm/runtime/**", + "litellm/schema.prisma", "litellm/enterprise", "litellm/enterprise/**", "litellm/proxy-extras", diff --git a/litellm/packaging/litellm-proxy/pyproject.toml b/litellm/packaging/litellm-proxy/pyproject.toml index c0dff90461b..8efdca8db74 100644 --- a/litellm/packaging/litellm-proxy/pyproject.toml +++ b/litellm/packaging/litellm-proxy/pyproject.toml @@ -16,8 +16,8 @@ targets = [{ name = "litellm-gateway", kind = "bin" }] profile = "release" editable-profile = "dev" include = [ - { path = "rust-toolchain.toml", format = "sdist" }, - { path = ".cargo/config.toml", format = "sdist" }, + { path = "litellm/rust/rust-toolchain.toml", format = "sdist" }, + { path = "litellm/rust/.cargo/config.toml", format = "sdist" }, { path = "model_prices_and_context_window.json", format = "sdist" }, ] 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 ad74d67a2ff..d68b8c77c0d 100644 --- a/litellm/proxy-extras/litellm_proxy_extras/request_log_indexes.py +++ b/litellm/proxy-extras/litellm_proxy_extras/request_log_indexes.py @@ -4,7 +4,7 @@ background, once it serves). A migration cannot build them: a plain `CREATE INDEX` blocks spend-log inserts for the whole build, and `CREATE INDEX CONCURRENTLY` is refused on a partitioned parent -(scripts/db/partition_spend_logs.sql). `REQUEST_LOG_INDEXES` is the one list to extend; +(litellm/scripts/db/partition_spend_logs.sql). `REQUEST_LOG_INDEXES` is the one list to extend; names match what Prisma derives from the `@@index` declarations in schema.prisma, so an index a database already has is recognized and never rebuilt. """ diff --git a/litellm/proxy-extras/litellm_proxy_extras/utils.py b/litellm/proxy-extras/litellm_proxy_extras/utils.py index 8d316e42ca5..f8625088d8e 100644 --- a/litellm/proxy-extras/litellm_proxy_extras/utils.py +++ b/litellm/proxy-extras/litellm_proxy_extras/utils.py @@ -147,7 +147,7 @@ _SPEND_LOGS_PK_CLAUSE_RE = re.compile( ) PARTITIONED_SPEND_LOGS_PUSH_ERROR = ( - "LiteLLM_SpendLogs is a partitioned table (see scripts/db/partition_spend_logs.sql), " + "LiteLLM_SpendLogs is a partitioned table (see litellm/scripts/db/partition_spend_logs.sql), " '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 ' @@ -179,7 +179,7 @@ def _without_spend_logs_pk_clauses(statement: str) -> str | None: def filter_partitioned_spend_logs_diff(diff_sql: str) -> str: """Drop statements from a `prisma migrate diff` script that fight the - SpendLogs partitioning runbook (scripts/db/partition_spend_logs.sql): the + SpendLogs partitioning runbook (litellm/scripts/db/partition_spend_logs.sql): the primary-key rewrite on "LiteLLM_SpendLogs", which Postgres rejects on a partitioned table, and drops of runbook artifacts such as "LiteLLM_SpendLogs_legacy".""" @@ -679,7 +679,7 @@ class ProxyExtrasDBManager: """True when the connected database's LiteLLM_SpendLogs is a partitioned table in Prisma's target schema (the `schema` URL param, falling back to Prisma's default target, public), i.e. the operator - ran scripts/db/partition_spend_logs.sql. Returns False when psycopg is + ran litellm/scripts/db/partition_spend_logs.sql. Returns False when psycopg is unavailable or the database cannot be reached, preserving the pre-existing behavior in those cases.""" database_url = os.getenv("DATABASE_URL") @@ -692,7 +692,7 @@ class ProxyExtrasDBManager: logger.warning( "psycopg is not installed; skipping the LiteLLM_SpendLogs " "partition check. If this table is partitioned (see " - "scripts/db/partition_spend_logs.sql), schema reconciliation " + "litellm/scripts/db/partition_spend_logs.sql), schema reconciliation " "will try to rewrite its primary key and fail. Install the " "litellm[extra_proxy] extra, which now includes psycopg." ) diff --git a/litellm/proxy-extras/migration_runbook.md b/litellm/proxy-extras/migration_runbook.md index e49416ddb73..08c944a988d 100644 --- a/litellm/proxy-extras/migration_runbook.md +++ b/litellm/proxy-extras/migration_runbook.md @@ -10,7 +10,7 @@ Before doing anything else, make sure all `schema.prisma` files in the repo are | File | Purpose | |------|---------| -| `schema.prisma` (repo root) | Source of truth | +| `litellm/schema.prisma` (canonical) | Source of truth | | `litellm/proxy/schema.prisma` | Used by the proxy server | | `litellm/proxy-extras/litellm_proxy_extras/schema.prisma` | Used for migration generation | @@ -18,16 +18,16 @@ Before doing anything else, make sure all `schema.prisma` files in the repo are ```bash # 1. Diff all schema files against the root source of truth -diff schema.prisma litellm/proxy/schema.prisma -diff schema.prisma litellm/proxy-extras/litellm_proxy_extras/schema.prisma +diff litellm/schema.prisma litellm/proxy/schema.prisma +diff litellm/schema.prisma litellm/proxy-extras/litellm_proxy_extras/schema.prisma # 2. If there are differences, copy the root schema to all locations -cp schema.prisma litellm/proxy/schema.prisma -cp schema.prisma litellm/proxy-extras/litellm_proxy_extras/schema.prisma +cp litellm/schema.prisma litellm/proxy/schema.prisma +cp litellm/schema.prisma litellm/proxy-extras/litellm_proxy_extras/schema.prisma # 3. Verify all files are now identical -diff schema.prisma litellm/proxy/schema.prisma && echo "proxy schema in sync" || echo "MISMATCH" -diff schema.prisma litellm/proxy-extras/litellm_proxy_extras/schema.prisma && echo "extras schema in sync" || echo "MISMATCH" +diff litellm/schema.prisma litellm/proxy/schema.prisma && echo "proxy schema in sync" || echo "MISMATCH" +diff litellm/schema.prisma litellm/proxy-extras/litellm_proxy_extras/schema.prisma && echo "extras schema in sync" || echo "MISMATCH" ``` > **Do NOT proceed to migration generation until all schema files are identical.** @@ -43,7 +43,7 @@ brew install postgresql@14 # macOS export PATH="/opt/homebrew/opt/postgresql@14/bin:$PATH" # Run migration -uv run --with testing.postgresql python scripts/ci_cd/run_migration.py "your_migration_name" +uv run --with testing.postgresql python litellm/scripts/ci_cd/run_migration.py "your_migration_name" ``` ## What It Does @@ -69,7 +69,7 @@ When the guard fires: 1. Update your branch: ```bash - base_branch=$(python3 scripts/default_branch.py --branch) && + base_branch=$(python3 litellm/scripts/default_branch.py --branch) && git fetch origin "+refs/heads/$base_branch:refs/remotes/origin/$base_branch" && git rebase "origin/$base_branch" ``` @@ -89,7 +89,7 @@ When the guard fires: 4. Only if the drops are genuinely intentional, re-run with the flag: ```bash - uv run --with testing.postgresql python scripts/ci_cd/run_migration.py "your_migration_name" --allow-destructive + uv run --with testing.postgresql python litellm/scripts/ci_cd/run_migration.py "your_migration_name" --allow-destructive ``` > **AI AGENTS / ASSISTANTS:** Do **not** automatically re-run the command with `--allow-destructive`. If the guard fires while you are driving the runbook for a human, stop, show them the error, and wait for their explicit confirmation before passing the flag. Auto-passing `--allow-destructive` is the exact failure mode this guard exists to prevent. @@ -98,7 +98,7 @@ When the guard fires: **Missing testing module:** ```bash -uv run --with testing.postgresql python scripts/ci_cd/run_migration.py "your_migration_name" +uv run --with testing.postgresql python litellm/scripts/ci_cd/run_migration.py "your_migration_name" ``` **initdb not found:** @@ -115,7 +115,7 @@ rm -rf litellm/proxy-extras/litellm_proxy_extras/migrations/[empty_dir] ## Rules - Sync all `schema.prisma` files first (Step 0) -- Update `schema.prisma` at the repo root first, then sync copies +- Update `litellm/schema.prisma` first, then sync copies - Review generated SQL before committing - Use descriptive migration names - Never edit existing migration files diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index b7f4d7a70b9..1eab9d80484 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -3034,7 +3034,7 @@ class ConfigGeneralSettings(LiteLLMPydanticObjectBase): ) use_spend_logs_partitioning: bool | None = Field( None, - description="If True and LiteLLM_SpendLogs has been converted to a range-partitioned table (scripts/db/partition_spend_logs.sql), retention cleanup drops expired partitions instead of deleting rows, and pre-creates upcoming partitions. Default is False.", + description="If True and LiteLLM_SpendLogs has been converted to a range-partitioned table (litellm/scripts/db/partition_spend_logs.sql), retention cleanup drops expired partitions instead of deleting rows, and pre-creates upcoming partitions. Default is False.", ) maximum_spend_logs_cleanup_batch_size: int | None = Field( None, diff --git a/litellm/proxy/client/cli/README.md b/litellm/proxy/client/cli/README.md index 52d367d7333..02bbeb75158 100644 --- a/litellm/proxy/client/cli/README.md +++ b/litellm/proxy/client/cli/README.md @@ -589,7 +589,7 @@ The Codex undo receipt is kept in a private `.litellm` directory beside the reso `lite configure claude` wires Claude Code up persistently with a long-lived virtual key, a pinned model and an undo, and `lite unconfigure claude` puts things back: ```bash -curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm/main/scripts/install.sh | sh +curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/scripts/install.sh | sh lite --base-url https://your-proxy.example.com configure claude --api-key sk-... --model claude-auto claude ``` @@ -625,17 +625,17 @@ After upgrading the CLI, run `lite configure claude` to refresh `~/.litellm/stat `lite autoroute start` builds and runs a throwaway litellm proxy locally, so unlike the rest of this CLI it needs the proxy server runtime, not just the thin `litellm[cli]` client. Install `litellm[proxy]` (which ships the `lite` command too) with a single curl command -- no existing Python tooling required, `uv` is bootstrapped automatically if missing: ```bash -curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm/main/scripts/install.sh | sh +curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/scripts/install.sh | sh ``` To QA an unreleased branch or commit instead of the latest PyPI release, set `LITELLM_CLI_REF`: ```bash -curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm//scripts/install.sh | \ +curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm//litellm/scripts/install.sh | \ LITELLM_CLI_REF= sh ``` -The thin `scripts/install-cli.sh` installs only `litellm[cli]`, which is enough for `lite login`, `lite claude`, and `lite up`, but not for `lite autoroute start`; running it against a `litellm[cli]` install fails fast with a message telling you to install the proxy runtime. +The thin `litellm/scripts/install-cli.sh` installs only `litellm[cli]`, which is enough for `lite login`, `lite claude`, and `lite up`, but not for `lite autoroute start`; running it against a `litellm[cli]` install fails fast with a message telling you to install the proxy runtime. Point the CLI at your real proxy and key before running any `lite model-groups` or `lite autoroute` command -- like every other command in this CLI, they read `LITELLM_PROXY_URL`/`LITELLM_PROXY_API_KEY` (or `--base-url`/`--api-key`), no `lite login` required: diff --git a/litellm/proxy/client/cli/commands/autoroute/commands.py b/litellm/proxy/client/cli/commands/autoroute/commands.py index d9fc3ae9f77..6975a4c8e69 100644 --- a/litellm/proxy/client/cli/commands/autoroute/commands.py +++ b/litellm/proxy/client/cli/commands/autoroute/commands.py @@ -111,7 +111,7 @@ def start(port: int) -> None: "lite autoroute start launches a local litellm proxy, which needs the proxy runtime that the " f"thin `litellm[cli]` install does not include (missing: {', '.join(missing)}). Install the " "proxy runtime with `uv tool install --force 'litellm[proxy]'`, or to QA a branch, " - "`curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm//scripts/install.sh | " + "`curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm//litellm/scripts/install.sh | " "LITELLM_CLI_REF= sh`." ) diff --git a/litellm/proxy/db/create_views.py b/litellm/proxy/db/create_views.py index fd5c2356373..0b7fad88230 100644 --- a/litellm/proxy/db/create_views.py +++ b/litellm/proxy/db/create_views.py @@ -51,7 +51,7 @@ async def create_view_tolerating_race(db: SupportsExecuteRaw, view_name: str, dd async def create_missing_views(db: SupportsRawQueries) -> None: """ -------------------------------------------------- - NOTE: Copy of `scripts/db/create_views.py`. + NOTE: Copy of `litellm/scripts/db/create_views.py`. -------------------------------------------------- Checks if the LiteLLM_VerificationTokenView and MonthlyGlobalSpend exists in the user's db. diff --git a/litellm/proxy/db/db_transaction_queue/spend_logs_partition_manager.py b/litellm/proxy/db/db_transaction_queue/spend_logs_partition_manager.py index f916d53a63a..f9b0f8cf9d9 100644 --- a/litellm/proxy/db/db_transaction_queue/spend_logs_partition_manager.py +++ b/litellm/proxy/db/db_transaction_queue/spend_logs_partition_manager.py @@ -9,7 +9,7 @@ to the OS immediately, with no tombstones and no vacuum. This manager only acts when use_spend_logs_partitioning is enabled in general_settings AND the table is already partitioned (set up via the -scripts/db/partition_spend_logs.sql runbook). Without both, the cleanup job +litellm/scripts/db/partition_spend_logs.sql runbook). Without both, the cleanup job keeps the batched-DELETE path, so existing deployments are untouched. """ diff --git a/backend/main.py b/litellm/runtime/backend/main.py similarity index 85% rename from backend/main.py rename to litellm/runtime/backend/main.py index e0cef90c979..435fc61e3ef 100644 --- a/backend/main.py +++ b/litellm/runtime/backend/main.py @@ -5,7 +5,7 @@ route table to just the management/admin surface used by the dashboard. Purely additive — no existing module is modified. Run with: - uvicorn backend.main:app --host 0.0.0.0 --port 4001 + uvicorn litellm.runtime.backend.main:app --host 0.0.0.0 --port 4001 """ from collections.abc import AsyncGenerator, Mapping @@ -16,7 +16,7 @@ from starlette.applications import Starlette from starlette.routing import Mount from starlette.types import Lifespan -# See gateway/main.py for why we assemble DATABASE_URL(s) here before +# See litellm/runtime/gateway/main.py for why we assemble DATABASE_URL(s) here before # importing proxy_server. from litellm.proxy.db.db_url_settings import DatabaseURLSettings @@ -24,7 +24,7 @@ DatabaseURLSettings.from_env().apply_to_env() from litellm.proxy.proxy_server import app -from backend.routes.allowlist import ( +from litellm.runtime.backend.routes.allowlist import ( BACKEND_EXACT_PATHS, BACKEND_MOUNT_PATHS, BACKEND_PATH_PREFIXES, @@ -45,7 +45,7 @@ def _is_backend_route(route) -> bool: return any(path.startswith(prefix) for prefix in BACKEND_PATH_PREFIXES) -# See gateway/main.py for why the trim runs inside the lifespan instead of at +# See litellm/runtime/gateway/main.py for why the trim runs inside the lifespan instead of at # module scope. _proxy_lifespan: Final = app.router.lifespan_context diff --git a/backend/routes/__init__.py b/litellm/runtime/backend/routes/__init__.py similarity index 100% rename from backend/routes/__init__.py rename to litellm/runtime/backend/routes/__init__.py diff --git a/backend/routes/allowlist.py b/litellm/runtime/backend/routes/allowlist.py similarity index 100% rename from backend/routes/allowlist.py rename to litellm/runtime/backend/routes/allowlist.py diff --git a/gateway/AGENTS.md b/litellm/runtime/gateway/AGENTS.md similarity index 100% rename from gateway/AGENTS.md rename to litellm/runtime/gateway/AGENTS.md diff --git a/gateway/launch.py b/litellm/runtime/gateway/launch.py similarity index 98% rename from gateway/launch.py rename to litellm/runtime/gateway/launch.py index a1d6bccc404..666c51350fa 100644 --- a/gateway/launch.py +++ b/litellm/runtime/gateway/launch.py @@ -1,6 +1,6 @@ """Gateway supervisor: assemble DATABASE_URL, start the in-container PgBouncer, then run uvicorn. -``gateway/main.py`` assembles ``DATABASE_URL`` inside every uvicorn worker, which +``litellm/runtime/gateway/main.py`` assembles ``DATABASE_URL`` inside every uvicorn worker, which is fine for a plain Postgres URL but not for the pooler: PgBouncer must be started exactly once per pod, before the workers fork, and the workers must be handed the loopback URL it listens on. A pre-existing ``DATABASE_URL`` wins in diff --git a/gateway/main.py b/litellm/runtime/gateway/main.py similarity index 100% rename from gateway/main.py rename to litellm/runtime/gateway/main.py diff --git a/gateway/routes/__init__.py b/litellm/runtime/gateway/routes/__init__.py similarity index 100% rename from gateway/routes/__init__.py rename to litellm/runtime/gateway/routes/__init__.py diff --git a/gateway/routes/allowlist.py b/litellm/runtime/gateway/routes/allowlist.py similarity index 100% rename from gateway/routes/allowlist.py rename to litellm/runtime/gateway/routes/allowlist.py diff --git a/migrations/run.py b/litellm/runtime/migrations/run.py similarity index 100% rename from migrations/run.py rename to litellm/runtime/migrations/run.py diff --git a/.cargo/config.toml b/litellm/rust/.cargo/config.toml similarity index 100% rename from .cargo/config.toml rename to litellm/rust/.cargo/config.toml diff --git a/rust-toolchain.toml b/litellm/rust/rust-toolchain.toml similarity index 100% rename from rust-toolchain.toml rename to litellm/rust/rust-toolchain.toml diff --git a/schema.prisma b/litellm/schema.prisma similarity index 100% rename from schema.prisma rename to litellm/schema.prisma diff --git a/scripts/adaptive_router_demo/README.md b/litellm/scripts/adaptive_router_demo/README.md similarity index 98% rename from scripts/adaptive_router_demo/README.md rename to litellm/scripts/adaptive_router_demo/README.md index fc855fc24fe..a7a517cad97 100644 --- a/scripts/adaptive_router_demo/README.md +++ b/litellm/scripts/adaptive_router_demo/README.md @@ -76,7 +76,7 @@ The dashboard is a single static HTML file. Either: - **If your browser blocks `file://` fetches:** ```bash - cd scripts/adaptive_router_demo + cd litellm/scripts/adaptive_router_demo python3 -m http.server 8080 ``` @@ -95,7 +95,7 @@ Click **Connect**. The dashboard polls `GET /adaptive_router/state` every In a second terminal, replacing `` with the key printed in step 1: ```bash -uv run python scripts/adaptive_router_demo/traffic.py \ +uv run python litellm/scripts/adaptive_router_demo/traffic.py \ --proxy-url http://localhost:4000 \ --api-key \ --router smart-cheap-router \ diff --git a/scripts/adaptive_router_demo/chat.html b/litellm/scripts/adaptive_router_demo/chat.html similarity index 100% rename from scripts/adaptive_router_demo/chat.html rename to litellm/scripts/adaptive_router_demo/chat.html diff --git a/scripts/adaptive_router_demo/dashboard.html b/litellm/scripts/adaptive_router_demo/dashboard.html similarity index 100% rename from scripts/adaptive_router_demo/dashboard.html rename to litellm/scripts/adaptive_router_demo/dashboard.html diff --git a/scripts/adaptive_router_demo/eval.py b/litellm/scripts/adaptive_router_demo/eval.py similarity index 99% rename from scripts/adaptive_router_demo/eval.py rename to litellm/scripts/adaptive_router_demo/eval.py index a9a8a7bc71c..06f30efd905 100644 --- a/scripts/adaptive_router_demo/eval.py +++ b/litellm/scripts/adaptive_router_demo/eval.py @@ -9,7 +9,7 @@ For each test case: 4. Prints PASS or FAIL with one line of reasoning. Run: - uv run python scripts/adaptive_router_demo/eval.py \ + uv run python litellm/scripts/adaptive_router_demo/eval.py \ --proxy-url http://localhost:4000 \ --api-key "$LITELLM_MASTER_KEY" \ --router smart-cheap-router \ diff --git a/scripts/adaptive_router_demo/traffic.py b/litellm/scripts/adaptive_router_demo/traffic.py similarity index 99% rename from scripts/adaptive_router_demo/traffic.py rename to litellm/scripts/adaptive_router_demo/traffic.py index 5ff806ef5a6..b4f79a0267d 100644 --- a/scripts/adaptive_router_demo/traffic.py +++ b/litellm/scripts/adaptive_router_demo/traffic.py @@ -21,7 +21,7 @@ Why this shape: flow through routing + post-call hooks, so no API keys / no spend. Run: - uv run python scripts/adaptive_router_demo/traffic.py \\ + uv run python litellm/scripts/adaptive_router_demo/traffic.py \\ --proxy-url http://localhost:4000 \\ --api-key "$LITELLM_MASTER_KEY" \\ --router smart-cheap-router \\ diff --git a/scripts/auto-close-duplicates.test.ts b/litellm/scripts/auto-close-duplicates.test.ts similarity index 100% rename from scripts/auto-close-duplicates.test.ts rename to litellm/scripts/auto-close-duplicates.test.ts diff --git a/scripts/auto-close-duplicates.ts b/litellm/scripts/auto-close-duplicates.ts similarity index 100% rename from scripts/auto-close-duplicates.ts rename to litellm/scripts/auto-close-duplicates.ts diff --git a/scripts/benchmark_anthropic_messages_perf.py b/litellm/scripts/benchmark_anthropic_messages_perf.py similarity index 99% rename from scripts/benchmark_anthropic_messages_perf.py rename to litellm/scripts/benchmark_anthropic_messages_perf.py index 3639e5ef326..e1d8a7ed8ad 100644 --- a/scripts/benchmark_anthropic_messages_perf.py +++ b/litellm/scripts/benchmark_anthropic_messages_perf.py @@ -13,11 +13,11 @@ streaming SSE wire format (``message_start`` -> ``content_block_delta`` -> can be compared without depending on real provider latency. Example: - uv run python scripts/benchmark_anthropic_messages_perf.py \ + uv run python litellm/scripts/benchmark_anthropic_messages_perf.py \ --label baseline --proxy-command ".venv/bin/litellm" Compare an already-running proxy: - uv run python scripts/benchmark_anthropic_messages_perf.py \ + uv run python litellm/scripts/benchmark_anthropic_messages_perf.py \ --no-start-proxy --label current """ diff --git a/scripts/benchmark_chat_completions_perf.py b/litellm/scripts/benchmark_chat_completions_perf.py similarity index 99% rename from scripts/benchmark_chat_completions_perf.py rename to litellm/scripts/benchmark_chat_completions_perf.py index 61f04836cac..805d8fd486b 100644 --- a/scripts/benchmark_chat_completions_perf.py +++ b/litellm/scripts/benchmark_chat_completions_perf.py @@ -6,11 +6,11 @@ from any checkout. That makes it useful for comparing tags/commits without depending on real provider latency. Example: - uv run python scripts/benchmark_chat_completions_perf.py \ + uv run python litellm/scripts/benchmark_chat_completions_perf.py \ --label current --requests 500 --concurrency 100 Compare another checkout: - uv run python scripts/benchmark_chat_completions_perf.py \ + uv run python litellm/scripts/benchmark_chat_completions_perf.py \ --label v1.83.14-stable --litellm-dir /tmp/litellm-v1.83.14-stable """ diff --git a/scripts/benchmark_mock.py b/litellm/scripts/benchmark_mock.py similarity index 100% rename from scripts/benchmark_mock.py rename to litellm/scripts/benchmark_mock.py diff --git a/scripts/benchmark_model_response_creator.py b/litellm/scripts/benchmark_model_response_creator.py similarity index 96% rename from scripts/benchmark_model_response_creator.py rename to litellm/scripts/benchmark_model_response_creator.py index 881870d3854..d7e0199e6fc 100644 --- a/scripts/benchmark_model_response_creator.py +++ b/litellm/scripts/benchmark_model_response_creator.py @@ -6,8 +6,8 @@ isolate per-call cost. Driving the full wrapper adds threadpool logging, gc, and other noise that swamps microsecond-scale changes here. Example: - uv run python scripts/benchmark_model_response_creator.py --label baseline - uv run python scripts/benchmark_model_response_creator.py --label optimized + uv run python litellm/scripts/benchmark_model_response_creator.py --label baseline + uv run python litellm/scripts/benchmark_model_response_creator.py --label optimized """ from __future__ import annotations diff --git a/scripts/benchmark_ocr_callbacks.py b/litellm/scripts/benchmark_ocr_callbacks.py similarity index 98% rename from scripts/benchmark_ocr_callbacks.py rename to litellm/scripts/benchmark_ocr_callbacks.py index e2282356356..ad7d1e8024d 100644 --- a/scripts/benchmark_ocr_callbacks.py +++ b/litellm/scripts/benchmark_ocr_callbacks.py @@ -2,7 +2,7 @@ """Measure serial sync/async OCR latency through a loopback HTTP provider Run each callback mode in a fresh process against an installed release wheel: -python -I scripts/benchmark_ocr_callbacks.py --callbacks none --label before \ +python -I litellm/scripts/benchmark_ocr_callbacks.py --callbacks none --label before \ --expected-transport rust --iterations 200 --warmup 20 --output before-none.json Repeat with --callbacks noop and with the candidate wheel in a separate venv """ @@ -199,7 +199,7 @@ async def main() -> int: raise RuntimeError("benchmark requires initially empty callback registrations") callback: Final = NoopCallback() if args.callbacks == "noop": - litellm.callbacks.append(callback) + litellm.logging_callback_manager.add_litellm_callback(callback) rust_toggle: Final = getattr(litellm, "rust", None) if callable(rust_toggle): diff --git a/scripts/benchmark_proxy_vs_provider.py b/litellm/scripts/benchmark_proxy_vs_provider.py similarity index 98% rename from scripts/benchmark_proxy_vs_provider.py rename to litellm/scripts/benchmark_proxy_vs_provider.py index 28d9d0c9cc7..0d289ee1ae0 100755 --- a/scripts/benchmark_proxy_vs_provider.py +++ b/litellm/scripts/benchmark_proxy_vs_provider.py @@ -539,28 +539,28 @@ Examples: export PROVIDER_URL='https://api.openai.com/v1/chat/completions' export LITELLM_PROXY_API_KEY="$LITELLM_MASTER_KEY" export PROVIDER_API_KEY='sk-openai-key' - python scripts/benchmark_proxy_vs_provider.py + python litellm/scripts/benchmark_proxy_vs_provider.py # 2. Multiple runs for statistical accuracy (recommended) - python scripts/benchmark_proxy_vs_provider.py --runs 5 + python litellm/scripts/benchmark_proxy_vs_provider.py --runs 5 # 3. Realistic load testing with concurrency limit - python scripts/benchmark_proxy_vs_provider.py --max-concurrent 100 --requests 2000 + python litellm/scripts/benchmark_proxy_vs_provider.py --max-concurrent 100 --requests 2000 # 4. Quick test with fewer requests - python scripts/benchmark_proxy_vs_provider.py --requests 100 + python litellm/scripts/benchmark_proxy_vs_provider.py --requests 100 # 5. Parallel execution (not recommended - may affect accuracy) - python scripts/benchmark_proxy_vs_provider.py --parallel + python litellm/scripts/benchmark_proxy_vs_provider.py --parallel # 6. Custom timeout for slower endpoints - python scripts/benchmark_proxy_vs_provider.py --timeout 120 + python litellm/scripts/benchmark_proxy_vs_provider.py --timeout 120 # 7. Combined options for comprehensive testing - python scripts/benchmark_proxy_vs_provider.py --runs 3 --requests 500 --max-concurrent 50 + python litellm/scripts/benchmark_proxy_vs_provider.py --runs 3 --requests 500 --max-concurrent 50 # 8. Skip warmup (not recommended - may affect first request accuracy) - python scripts/benchmark_proxy_vs_provider.py --no-warmup + python litellm/scripts/benchmark_proxy_vs_provider.py --no-warmup """, ) parser.add_argument( diff --git a/scripts/benchmark_streaming_chunk_overhead.py b/litellm/scripts/benchmark_streaming_chunk_overhead.py similarity index 99% rename from scripts/benchmark_streaming_chunk_overhead.py rename to litellm/scripts/benchmark_streaming_chunk_overhead.py index 11fbea6a6a3..9a5fe751a23 100644 --- a/scripts/benchmark_streaming_chunk_overhead.py +++ b/litellm/scripts/benchmark_streaming_chunk_overhead.py @@ -7,7 +7,7 @@ and Bedrock Converse (ModelResponseStream). A full proxy benchmark adds FastAPI, HTTP, and TCP latency, which dilutes the per-chunk CPU signal. Example: - uv run python scripts/benchmark_streaming_chunk_overhead.py \\ + uv run python litellm/scripts/benchmark_streaming_chunk_overhead.py \\ --streams 500 --chunks 200 --warmup 50 --repeats 5 """ diff --git a/scripts/build_core_distribution.py b/litellm/scripts/build_core_distribution.py similarity index 93% rename from scripts/build_core_distribution.py rename to litellm/scripts/build_core_distribution.py index 62a4a3b37a1..3f72c771ac8 100644 --- a/scripts/build_core_distribution.py +++ b/litellm/scripts/build_core_distribution.py @@ -8,12 +8,10 @@ import tempfile from pathlib import Path from typing import Final -ROOT: Final = Path(__file__).resolve().parents[1] +ROOT: Final = Path(__file__).resolve().parents[2] SOURCES: Final = ( "litellm", "litellm/rust", - ".cargo", - "rust-toolchain.toml", "model_prices_and_context_window.json", "README.md", "LICENSE", @@ -57,7 +55,10 @@ def stage_core_distribution(source: Path, destination: Path, *, package: str = " def ignored_sources(directory: str, names: list[str]) -> set[str]: workspace_sources: Final = ( - {"enterprise", "proxy-extras", "packaging", "rust", "cli", "ui", "vscode-extension", "deploy"} + { + "enterprise", "proxy-extras", "packaging", "rust", "cli", "scripts", "runtime", + "schema.prisma", "ui", "vscode-extension", "deploy", + } if Path(directory) == source / "litellm" else set() ) diff --git a/scripts/check_mcp_operation_boundary.py b/litellm/scripts/check_mcp_operation_boundary.py similarity index 100% rename from scripts/check_mcp_operation_boundary.py rename to litellm/scripts/check_mcp_operation_boundary.py diff --git a/scripts/check_mcp_sdk_install.py b/litellm/scripts/check_mcp_sdk_install.py similarity index 100% rename from scripts/check_mcp_sdk_install.py rename to litellm/scripts/check_mcp_sdk_install.py diff --git a/scripts/check_openapi_docs.py b/litellm/scripts/check_openapi_docs.py similarity index 96% rename from scripts/check_openapi_docs.py rename to litellm/scripts/check_openapi_docs.py index 219ef912952..e88594f5a51 100755 --- a/scripts/check_openapi_docs.py +++ b/litellm/scripts/check_openapi_docs.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """List the POST operations in the proxy's OpenAPI document that Swagger UI cannot explain. -Every finding is one line, `` ``, so scripts/openapi_docs_gate.py can +Every finding is one line, `` ``, so litellm/scripts/openapi_docs_gate.py can count them per rule the same delta-vs-base way as the other lint gates. The rules: OA001 no request body schema (the handler reads ``request.body()`` and never told FastAPI diff --git a/scripts/check_schema_compatibility.py b/litellm/scripts/check_schema_compatibility.py similarity index 86% rename from scripts/check_schema_compatibility.py rename to litellm/scripts/check_schema_compatibility.py index c56986a38c8..5d7ee790cb2 100644 --- a/scripts/check_schema_compatibility.py +++ b/litellm/scripts/check_schema_compatibility.py @@ -67,11 +67,18 @@ def main() -> int: options: Final = TypeAdapter(dict[str, str | None]).validate_python(vars(parser.parse_args())) base_commit: Final = options["base_commit"] base: Final = base_commit if base_commit else _merge_base(options["base_ref"] or "") - previous: Final = subprocess.run( - ("git", "show", f"{base}:schema.prisma"), capture_output=True, text=True, check=True - ).stdout + canonical: Final = subprocess.run( + ("git", "show", f"{base}:litellm/schema.prisma"), capture_output=True, text=True, check=False + ) + previous: Final = ( + canonical.stdout + if canonical.returncode == 0 + else subprocess.run( + ("git", "show", f"{base}:schema.prisma"), capture_output=True, text=True, check=True + ).stdout + ) changes: Final = check_breaking_changes( - parse_model_fields(previous), parse_model_fields(Path("schema.prisma").read_text()) + parse_model_fields(previous), parse_model_fields(Path("litellm/schema.prisma").read_text()) ) if changes: sys.stderr.write("\n".join(changes) + "\n") diff --git a/scripts/check_test_quality.py b/litellm/scripts/check_test_quality.py similarity index 99% rename from scripts/check_test_quality.py rename to litellm/scripts/check_test_quality.py index 6e82fe8c229..79a2ff57eeb 100644 --- a/scripts/check_test_quality.py +++ b/litellm/scripts/check_test_quality.py @@ -1,10 +1,10 @@ #!/usr/bin/env python3 """Test-quality checker: the test-suite smells no linter enforces. -Sibling of scripts/check_type_discipline.py, same output contract +Sibling of litellm/scripts/check_type_discipline.py, same output contract (``path:line: CODE message``) and same stdlib-only constraint, aimed at the test tree instead of the package. Each rule is a shape the testing-strategy audit -measured and named; scripts/test_quality_gate.py fails any change that grows the +measured and named; litellm/scripts/test_quality_gate.py fails any change that grows the codebase total of one past its merge-base count. Rules diff --git a/scripts/check_type_discipline.py b/litellm/scripts/check_type_discipline.py similarity index 99% rename from scripts/check_type_discipline.py rename to litellm/scripts/check_type_discipline.py index b16ba9feac6..574ba8cf3da 100644 --- a/scripts/check_type_discipline.py +++ b/litellm/scripts/check_type_discipline.py @@ -1171,6 +1171,8 @@ def collect_paths(raw: Iterable[str]) -> Iterator[Path]: "litellm/proxy-extras/", "litellm/packaging/", "litellm/rust/", + "litellm/scripts/", + "litellm/runtime/", ) ) ) @@ -1184,6 +1186,8 @@ def collect_paths(raw: Iterable[str]) -> Iterator[Path]: "litellm/proxy-extras/", "litellm/packaging/", "litellm/rust/", + "litellm/scripts/", + "litellm/runtime/", ) ): yield p diff --git a/scripts/ci_cd/TEST_KEY_PATTERNS.md b/litellm/scripts/ci_cd/TEST_KEY_PATTERNS.md similarity index 94% rename from scripts/ci_cd/TEST_KEY_PATTERNS.md rename to litellm/scripts/ci_cd/TEST_KEY_PATTERNS.md index aada8608397..bc9f6403654 100644 --- a/scripts/ci_cd/TEST_KEY_PATTERNS.md +++ b/litellm/scripts/ci_cd/TEST_KEY_PATTERNS.md @@ -33,7 +33,7 @@ token = "test-api-key-with-high-entropy" ## Configured Ignore Patterns -These patterns are in `.gitguardian.yaml` for high-entropy test keys: +These patterns are in `.github/gitguardian.yaml` for high-entropy test keys: - `sk-test-*` - OpenAI-style test keys - `sk-mock-*` - Mock API keys - `sk-fake-*` - Fake API keys diff --git a/scripts/ci_cd/check_file_length.py b/litellm/scripts/ci_cd/check_file_length.py similarity index 100% rename from scripts/ci_cd/check_file_length.py rename to litellm/scripts/ci_cd/check_file_length.py diff --git a/scripts/ci_cd/check_files_match.py b/litellm/scripts/ci_cd/check_files_match.py similarity index 100% rename from scripts/ci_cd/check_files_match.py rename to litellm/scripts/ci_cd/check_files_match.py diff --git a/scripts/ci_cd/cost_map_guard.py b/litellm/scripts/ci_cd/cost_map_guard.py similarity index 96% rename from scripts/ci_cd/cost_map_guard.py rename to litellm/scripts/ci_cd/cost_map_guard.py index 09138bd6c14..28ca4e462b5 100644 --- a/scripts/ci_cd/cost_map_guard.py +++ b/litellm/scripts/ci_cd/cost_map_guard.py @@ -2,7 +2,7 @@ Every pull request whose diff against its merge base touches one of the two cost map files or the pins file gets the file checks: the files parse, the backup copy matches the root file, and every capability pinned in -ci_cd/cost_map_pins.json (a value verified against a live provider call where the provider's model listing says +litellm/scripts/ci_cd/cost_map_pins.json (a value verified against a live provider call where the provider's model listing says otherwise) still holds in the tree that merging the pull request into its base branch produces, so a branch cut before a pin was added cannot lower it, and a pull request that deletes the pins file fails too. A pull request that leaves all three untouched skips them, since merging it keeps the base branch's copies and its head tree only carries @@ -26,14 +26,15 @@ from types import MappingProxyType from typing import Final COST_MAP_PATH: Final = "model_prices_and_context_window.json" +COST_MAP_PATHS: Final = ("litellm/data/model_prices_and_context_window.json", COST_MAP_PATH) BACKUP_PATH: Final = "litellm/model_prices_and_context_window_backup.json" -PINS_PATH: Final = "ci_cd/cost_map_pins.json" +PINS_PATH: Final = "litellm/scripts/ci_cd/cost_map_pins.json" PINS_PATHS: Final = ( "litellm/scripts/ci_cd/cost_map_pins.json", "scripts/ci_cd/cost_map_pins.json", "ci_cd/cost_map_pins.json", ) -GUARDED_PATHS: Final = (COST_MAP_PATH, BACKUP_PATH) +GUARDED_PATHS: Final = (*COST_MAP_PATHS, BACKUP_PATH) CHECKED_PATHS: Final = (*GUARDED_PATHS, *PINS_PATHS) BOT_BRANCH_PREFIX: Final = "litellm_cost_map_sync_" PRICE_SYNC_BRANCH_PREFIX: Final = "litellm-providers/price-sync" @@ -258,7 +259,8 @@ def _git(*args: str) -> str | None: def snapshot(revision: str, *, read_git: Callable[[str, str], str | None] = _git) -> Snapshot: return Snapshot( - *(read_git("show", f"{revision}:{path}") or "" for path in GUARDED_PATHS), + next((text for path in COST_MAP_PATHS if (text := read_git("show", f"{revision}:{path}")) is not None), ""), + read_git("show", f"{revision}:{BACKUP_PATH}") or "", next((text for path in PINS_PATHS if (text := read_git("show", f"{revision}:{path}")) is not None), ""), ) diff --git a/ci_cd/cost_map_pins.json b/litellm/scripts/ci_cd/cost_map_pins.json similarity index 100% rename from ci_cd/cost_map_pins.json rename to litellm/scripts/ci_cd/cost_map_pins.json diff --git a/scripts/ci_cd/run_migration.py b/litellm/scripts/ci_cd/run_migration.py similarity index 99% rename from scripts/ci_cd/run_migration.py rename to litellm/scripts/ci_cd/run_migration.py index 17614663a78..92afecdf3e9 100644 --- a/scripts/ci_cd/run_migration.py +++ b/litellm/scripts/ci_cd/run_migration.py @@ -238,7 +238,7 @@ def create_migration( skip_freshness_check (bool): Skip the "branch is up to date" check. Only for intentional migrations against an older base. """ - root_dir = Path(__file__).resolve().parents[2] + root_dir = Path(__file__).resolve().parents[3] if skip_freshness_check: print( @@ -254,7 +254,7 @@ def create_migration( migrations_dir = ( root_dir / "litellm" / "proxy-extras" / "litellm_proxy_extras" / "migrations" ) - schema_path = root_dir / "schema.prisma" + schema_path = root_dir / "litellm/schema.prisma" # Create temporary PostgreSQL database with testing.postgresql.Postgresql() as postgresql: diff --git a/scripts/ci_cd/security_scans_readme.md b/litellm/scripts/ci_cd/security_scans_readme.md similarity index 100% rename from scripts/ci_cd/security_scans_readme.md rename to litellm/scripts/ci_cd/security_scans_readme.md diff --git a/scripts/ci_cd/spend_logs_guard.py b/litellm/scripts/ci_cd/spend_logs_guard.py similarity index 99% rename from scripts/ci_cd/spend_logs_guard.py rename to litellm/scripts/ci_cd/spend_logs_guard.py index 99f8c8cffec..9741667bf64 100644 --- a/scripts/ci_cd/spend_logs_guard.py +++ b/litellm/scripts/ci_cd/spend_logs_guard.py @@ -26,6 +26,7 @@ from pydantic import BaseModel, ConfigDict, TypeAdapter WATCHED: Final = ( "schema.prisma", + "litellm/schema.prisma", "litellm/proxy/schema.prisma", "litellm/proxy-extras/litellm_proxy_extras/schema.prisma", ) diff --git a/scripts/classify-issue.test.ts b/litellm/scripts/classify-issue.test.ts similarity index 99% rename from scripts/classify-issue.test.ts rename to litellm/scripts/classify-issue.test.ts index 96236dde4da..5d3113f4f17 100644 --- a/scripts/classify-issue.test.ts +++ b/litellm/scripts/classify-issue.test.ts @@ -24,7 +24,7 @@ import { type Schema, } from "./classify-issue"; import { MANIFEST, NAMESPACES } from "./issue-labels"; -import schemaJson from "../.github/prompts/issue-classifier.schema.json"; +import schemaJson from "../../.github/prompts/issue-classifier.schema.json"; const schema = schemaJson as Schema; const routes = routesOf(schema); @@ -133,7 +133,7 @@ describe("sections", () => { test("the known headings are exactly the field labels of the two issue forms", async () => { const labels = await Promise.all( ["bug_report.yml", "feature_request.yml"].map(async (file) => { - const form = Bun.YAML.parse(await Bun.file(`${import.meta.dir}/../.github/ISSUE_TEMPLATE/${file}`).text()) as { + const form = Bun.YAML.parse(await Bun.file(`${import.meta.dir}/../../.github/ISSUE_TEMPLATE/${file}`).text()) as { readonly body: readonly { readonly attributes?: { readonly label?: string } }[]; }; return form.body.flatMap((field) => (field.attributes?.label === undefined ? [] : [field.attributes.label.trim()])); diff --git a/scripts/classify-issue.ts b/litellm/scripts/classify-issue.ts similarity index 98% rename from scripts/classify-issue.ts rename to litellm/scripts/classify-issue.ts index 7b72b29e711..3dd3e20cec7 100644 --- a/scripts/classify-issue.ts +++ b/litellm/scripts/classify-issue.ts @@ -376,8 +376,8 @@ export function readConfig( if (import.meta.main) { const { token, apiBase, apiKey, ...config } = readConfig(process.env, new Date()); - const prompt = await Bun.file(`${import.meta.dir}/../.github/prompts/issue-classifier.md`).text(); - const schema = (await Bun.file(`${import.meta.dir}/../.github/prompts/issue-classifier.schema.json`).json()) as Schema; + const prompt = await Bun.file(`${import.meta.dir}/../../.github/prompts/issue-classifier.md`).text(); + const schema = (await Bun.file(`${import.meta.dir}/../../.github/prompts/issue-classifier.schema.json`).json()) as Schema; const verdict = await classifyIssue(githubApi(token), litellmClient(apiBase, apiKey), config, prompt, schema); if (verdict === null) { console.error(`#${config.issueNumber}: edit ignored, the issue is already classified or older than the edit window`); diff --git a/scripts/comment-fixed-issue.test.ts b/litellm/scripts/comment-fixed-issue.test.ts similarity index 100% rename from scripts/comment-fixed-issue.test.ts rename to litellm/scripts/comment-fixed-issue.test.ts diff --git a/scripts/comment-fixed-issue.ts b/litellm/scripts/comment-fixed-issue.ts similarity index 100% rename from scripts/comment-fixed-issue.ts rename to litellm/scripts/comment-fixed-issue.ts diff --git a/scripts/create_litellm_branch.ps1 b/litellm/scripts/create_litellm_branch.ps1 similarity index 100% rename from scripts/create_litellm_branch.ps1 rename to litellm/scripts/create_litellm_branch.ps1 diff --git a/scripts/create_litellm_branch.sh b/litellm/scripts/create_litellm_branch.sh similarity index 100% rename from scripts/create_litellm_branch.sh rename to litellm/scripts/create_litellm_branch.sh diff --git a/scripts/create_team_key_and_submit_guardrail.sh b/litellm/scripts/create_team_key_and_submit_guardrail.sh similarity index 100% rename from scripts/create_team_key_and_submit_guardrail.sh rename to litellm/scripts/create_team_key_and_submit_guardrail.sh diff --git a/scripts/db/backfill_daily_tool_spend.sql b/litellm/scripts/db/backfill_daily_tool_spend.sql similarity index 97% rename from scripts/db/backfill_daily_tool_spend.sql rename to litellm/scripts/db/backfill_daily_tool_spend.sql index 9c65be20ada..472fe696d55 100644 --- a/scripts/db/backfill_daily_tool_spend.sql +++ b/litellm/scripts/db/backfill_daily_tool_spend.sql @@ -26,7 +26,7 @@ -- such buckets keep the writer's numbers and skip the backfill's. -- -- Usage: --- psql "$DATABASE_URL" -v cutover="'2026-07-25T00:00:00Z'" -f scripts/db/backfill_daily_tool_spend.sql +-- psql "$DATABASE_URL" -v cutover="'2026-07-25T00:00:00Z'" -f litellm/scripts/db/backfill_daily_tool_spend.sql SET TIME ZONE 'UTC'; diff --git a/scripts/db/backfill_key_total_spend.sql b/litellm/scripts/db/backfill_key_total_spend.sql similarity index 92% rename from scripts/db/backfill_key_total_spend.sql rename to litellm/scripts/db/backfill_key_total_spend.sql index 8c3d75ef5e2..81123b4ace8 100644 --- a/scripts/db/backfill_key_total_spend.sql +++ b/litellm/scripts/db/backfill_key_total_spend.sql @@ -22,14 +22,14 @@ -- budget_id links to a LiteLLM_BudgetTable row whose budget_duration IS -- NOT NULL (a linked budget resets the key's spend each period too). For -- those keys this script only recovers the current period; --- scripts/db/backfill_key_total_spend_from_spend_logs.sql is an optional +-- litellm/scripts/db/backfill_key_total_spend_from_spend_logs.sql is an optional -- follow-up that rebuilds the earlier periods from LiteLLM_SpendLogs. -- -- 3. No proxy restart is needed. The proxy picks up the corrected values on -- its next read of each key. -- -- Usage: --- psql "$DATABASE_URL" -f scripts/db/backfill_key_total_spend.sql +-- psql "$DATABASE_URL" -f litellm/scripts/db/backfill_key_total_spend.sql UPDATE "LiteLLM_VerificationToken" SET total_spend = spend diff --git a/scripts/db/backfill_key_total_spend_from_spend_logs.sql b/litellm/scripts/db/backfill_key_total_spend_from_spend_logs.sql similarity index 95% rename from scripts/db/backfill_key_total_spend_from_spend_logs.sql rename to litellm/scripts/db/backfill_key_total_spend_from_spend_logs.sql index b76a5d1fb6d..5a26ca042b8 100644 --- a/scripts/db/backfill_key_total_spend_from_spend_logs.sql +++ b/litellm/scripts/db/backfill_key_total_spend_from_spend_logs.sql @@ -1,4 +1,4 @@ --- Optional follow-up to scripts/db/backfill_key_total_spend.sql. Run that +-- Optional follow-up to litellm/scripts/db/backfill_key_total_spend.sql. Run that -- script first; this one rebuilds earlier budget periods for the keys it -- can only partially fix: keys whose spend resets each period, because their own -- budget_duration IS NOT NULL or because their budget_id links to a @@ -38,7 +38,7 @@ -- its next read of each key. -- -- Usage: --- psql "$DATABASE_URL" -f scripts/db/backfill_key_total_spend_from_spend_logs.sql +-- psql "$DATABASE_URL" -f litellm/scripts/db/backfill_key_total_spend_from_spend_logs.sql -- Active keys whose spend resets (own budget_duration, or a linked -- LiteLLM_BudgetTable row with one). Rebuild from LiteLLM_SpendLogs, diff --git a/scripts/db/create_views.py b/litellm/scripts/db/create_views.py similarity index 100% rename from scripts/db/create_views.py rename to litellm/scripts/db/create_views.py diff --git a/scripts/db/migrate_keys.py b/litellm/scripts/db/migrate_keys.py similarity index 100% rename from scripts/db/migrate_keys.py rename to litellm/scripts/db/migrate_keys.py diff --git a/scripts/db/partition_spend_logs.sql b/litellm/scripts/db/partition_spend_logs.sql similarity index 99% rename from scripts/db/partition_spend_logs.sql rename to litellm/scripts/db/partition_spend_logs.sql index 217a7463b54..9c09b3626af 100644 --- a/scripts/db/partition_spend_logs.sql +++ b/litellm/scripts/db/partition_spend_logs.sql @@ -32,7 +32,7 @@ -- The spend-log cleanup job then verifies the table is partitioned and reclaims -- disk by dropping expired partitions instead of deleting rows. It also -- pre-creates upcoming partitions on each run. To roll back, see --- scripts/db/unpartition_spend_logs.sql. +-- litellm/scripts/db/unpartition_spend_logs.sql. BEGIN; diff --git a/scripts/db/strip_vector_store_internal_metadata.py b/litellm/scripts/db/strip_vector_store_internal_metadata.py similarity index 100% rename from scripts/db/strip_vector_store_internal_metadata.py rename to litellm/scripts/db/strip_vector_store_internal_metadata.py diff --git a/scripts/db/unpartition_spend_logs.sql b/litellm/scripts/db/unpartition_spend_logs.sql similarity index 97% rename from scripts/db/unpartition_spend_logs.sql rename to litellm/scripts/db/unpartition_spend_logs.sql index 3f2b9c768b0..9c0e8fb1905 100644 --- a/scripts/db/unpartition_spend_logs.sql +++ b/litellm/scripts/db/unpartition_spend_logs.sql @@ -1,4 +1,4 @@ --- Rolls back scripts/db/partition_spend_logs.sql: converts the native +-- Rolls back litellm/scripts/db/partition_spend_logs.sql: converts the native -- range-partitioned "LiteLLM_SpendLogs" table back into a plain, -- non-partitioned table matching the default LiteLLM schema. -- diff --git a/scripts/db/update_unassigned_teams.py b/litellm/scripts/db/update_unassigned_teams.py similarity index 100% rename from scripts/db/update_unassigned_teams.py rename to litellm/scripts/db/update_unassigned_teams.py diff --git a/scripts/default_branch.py b/litellm/scripts/default_branch.py similarity index 100% rename from scripts/default_branch.py rename to litellm/scripts/default_branch.py diff --git a/scripts/eval_compression.py b/litellm/scripts/eval_compression.py similarity index 99% rename from scripts/eval_compression.py rename to litellm/scripts/eval_compression.py index a169cc02d74..2365fea76b0 100644 --- a/scripts/eval_compression.py +++ b/litellm/scripts/eval_compression.py @@ -4,9 +4,9 @@ Prompt Compression Evaluation Harness Compare model performance on coding tasks with and without prompt compression. Usage: - python scripts/eval_compression.py --model gpt-4o --problems 5 - python scripts/eval_compression.py --model claude-sonnet-4-20250514 --problems 12 --runs 3 - python scripts/eval_compression.py --model gpt-4o-mini --padding-factor 50 + python litellm/scripts/eval_compression.py --model gpt-4o --problems 5 + python litellm/scripts/eval_compression.py --model claude-sonnet-4-20250514 --problems 12 --runs 3 + python litellm/scripts/eval_compression.py --model gpt-4o-mini --padding-factor 50 The harness runs each problem in two modes: 1. **baseline** — raw prompt sent directly to the model. diff --git a/scripts/flag-duplicate-issue.test.ts b/litellm/scripts/flag-duplicate-issue.test.ts similarity index 100% rename from scripts/flag-duplicate-issue.test.ts rename to litellm/scripts/flag-duplicate-issue.test.ts diff --git a/scripts/flag-duplicate-issue.ts b/litellm/scripts/flag-duplicate-issue.ts similarity index 100% rename from scripts/flag-duplicate-issue.ts rename to litellm/scripts/flag-duplicate-issue.ts diff --git a/scripts/gate_slot_lock.py b/litellm/scripts/gate_slot_lock.py similarity index 96% rename from scripts/gate_slot_lock.py rename to litellm/scripts/gate_slot_lock.py index c1ab00461e0..053fb6087e1 100644 --- a/scripts/gate_slot_lock.py +++ b/litellm/scripts/gate_slot_lock.py @@ -2,8 +2,8 @@ """Machine-wide slot lock for this repo's heavy entrypoints. `make check`, `make lint`, and the standalone lint gates -(scripts/ruff_strict_gate.py, scripts/type_discipline_gate.py, -scripts/type_check_gate.py) each hold one of N machine-wide slots while they +(litellm/scripts/ruff_strict_gate.py, litellm/scripts/type_discipline_gate.py, +litellm/scripts/type_check_gate.py) each hold one of N machine-wide slots while they run, so however many sessions and worktrees share one machine, at most N of them execute a basedpyright/pytest/prettier storm at a time instead of all thrashing it at once. Slots are fcntl.flock files (macOS ships no flock(1) @@ -22,7 +22,7 @@ itself. Any filesystem error fails open and the command runs unlocked: the lock is a courtesy to the machine, never a gate that may break a build (CI runs one job per machine, so there it only ever takes the instant path). -CLI: python3 scripts/gate_slot_lock.py [args...] +CLI: python3 litellm/scripts/gate_slot_lock.py [args...] """ from __future__ import annotations diff --git a/scripts/generate_provider_endpoints_support.py b/litellm/scripts/generate_provider_endpoints_support.py similarity index 98% rename from scripts/generate_provider_endpoints_support.py rename to litellm/scripts/generate_provider_endpoints_support.py index a2329ccded3..d9b3706bcd3 100644 --- a/scripts/generate_provider_endpoints_support.py +++ b/litellm/scripts/generate_provider_endpoints_support.py @@ -11,7 +11,7 @@ from typing import Final from pydantic import JsonValue, TypeAdapter -ROOT: Final = Path(__file__).resolve().parents[1] +ROOT: Final = Path(__file__).resolve().parents[2] COST_MAP_PATH: Final = ROOT / "model_prices_and_context_window.json" SOURCE_PATH: Final = ROOT / "provider_endpoints_support.json" OUTPUT_PATHS: Final = ( @@ -218,7 +218,7 @@ def generate_files( 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" + + "\nRun `uv run --no-sync python litellm/scripts/generate_provider_endpoints_support.py` to regenerate it\n" ) return 1 for path in output_paths: diff --git a/scripts/generate_trace_types.py b/litellm/scripts/generate_trace_types.py similarity index 97% rename from scripts/generate_trace_types.py rename to litellm/scripts/generate_trace_types.py index d1ab6e6bc3c..d3e6d8dd640 100644 --- a/scripts/generate_trace_types.py +++ b/litellm/scripts/generate_trace_types.py @@ -18,10 +18,10 @@ from typing import Final from pydantic import BaseModel, ConfigDict, JsonValue, TypeAdapter -ROOT: Final = Path(__file__).resolve().parents[1] -TOOLING: Final = ROOT / "scripts/trace_codegen" +ROOT: Final = Path(__file__).resolve().parents[2] +TOOLING: Final = ROOT / "litellm/scripts/trace_codegen" GENERATED: Final = ROOT / "litellm/tracing/generated" -ASSETS: Final = ROOT / "scripts/lens_assets" +ASSETS: Final = ROOT / "litellm/scripts/lens_assets" SCHEMAS: Final = TypeAdapter(dict[str, dict[str, JsonValue]]) diff --git a/scripts/githooks/commit-msg b/litellm/scripts/githooks/commit-msg similarity index 100% rename from scripts/githooks/commit-msg rename to litellm/scripts/githooks/commit-msg diff --git a/scripts/health_check/benchmark_get_all_latest_health_checks.py b/litellm/scripts/health_check/benchmark_get_all_latest_health_checks.py similarity index 100% rename from scripts/health_check/benchmark_get_all_latest_health_checks.py rename to litellm/scripts/health_check/benchmark_get_all_latest_health_checks.py diff --git a/scripts/health_check/health_check_client.py b/litellm/scripts/health_check/health_check_client.py similarity index 100% rename from scripts/health_check/health_check_client.py rename to litellm/scripts/health_check/health_check_client.py diff --git a/scripts/health_check/health_check_client_README.md b/litellm/scripts/health_check/health_check_client_README.md similarity index 90% rename from scripts/health_check/health_check_client_README.md rename to litellm/scripts/health_check/health_check_client_README.md index 41c7ab7c35d..60be5700f3a 100644 --- a/scripts/health_check/health_check_client_README.md +++ b/litellm/scripts/health_check/health_check_client_README.md @@ -19,7 +19,7 @@ A health check tool for testing all configured models on a LiteLLM proxy. Tests ```bash export LITELLM_BASE_URL="https://litellm.example.com" export LITELLM_API_KEY="your-api-key" -python scripts/health_check/health_check_client.py +python litellm/scripts/health_check/health_check_client.py ``` **Option 2: Use YAML config file** @@ -27,7 +27,7 @@ python scripts/health_check/health_check_client.py export LITELLM_BASE_URL="https://litellm.example.com" export LITELLM_API_KEY="your-api-key" export LITELLM_MODELS_YAML="/path/to/config.yaml" -python scripts/health_check/health_check_client.py +python litellm/scripts/health_check/health_check_client.py ``` **Option 3: Use custom authentication header** @@ -35,7 +35,7 @@ python scripts/health_check/health_check_client.py export LITELLM_BASE_URL="https://litellm.example.com" export LITELLM_API_KEY="your-api-key" export LITELLM_CUSTOM_AUTH_HEADER="x-custom-auth-header" -python scripts/health_check/health_check_client.py +python litellm/scripts/health_check/health_check_client.py ``` ### As a Docker Container @@ -73,14 +73,14 @@ Run multiple health check containers in parallel: ```powershell $env:LITELLM_BASE_URL="https://litellm.example.com" $env:LITELLM_API_KEY="your-api-key" -.\scripts\health_check\run_parallel_health_checks.ps1 16 +.\litellm\scripts\health_check\run_parallel_health_checks.ps1 16 ``` **Bash/Shell:** ```bash export LITELLM_BASE_URL="https://litellm.example.com" export LITELLM_API_KEY="your-api-key" -./scripts/health_check/run_parallel_health_checks.sh 16 +./litellm/scripts/health_check/run_parallel_health_checks.sh 16 ``` **With Custom Auth Header:** @@ -88,7 +88,7 @@ export LITELLM_API_KEY="your-api-key" $env:LITELLM_BASE_URL="https://litellm.example.com" $env:LITELLM_API_KEY="your-api-key" $env:LITELLM_CUSTOM_AUTH_HEADER="x-custom-auth-header" -.\scripts\health_check\run_parallel_health_checks.ps1 16 +.\litellm\scripts\health_check\run_parallel_health_checks.ps1 16 ``` **With Custom Docker Image:** @@ -96,7 +96,7 @@ $env:LITELLM_CUSTOM_AUTH_HEADER="x-custom-auth-header" $env:LITELLM_BASE_URL="https://litellm.example.com" $env:LITELLM_API_KEY="your-api-key" $env:LITELLM_CUSTOM_AUTH_HEADER="x-custom-auth-header" -.\scripts\health_check\run_parallel_health_checks.ps1 -NumParallelJobs 16 -ImageName "your-registry/your-image:tag" +.\litellm\scripts\health_check\run_parallel_health_checks.ps1 -NumParallelJobs 16 -ImageName "your-registry/your-image:tag" ``` **Bash with Custom Image:** @@ -104,7 +104,7 @@ $env:LITELLM_CUSTOM_AUTH_HEADER="x-custom-auth-header" export LITELLM_BASE_URL="https://litellm.example.com" export LITELLM_API_KEY="your-api-key" export LITELLM_CUSTOM_AUTH_HEADER="x-custom-auth-header" -./scripts/health_check/run_parallel_health_checks.sh 16 "your-registry/your-image:tag" +./litellm/scripts/health_check/run_parallel_health_checks.sh 16 "your-registry/your-image:tag" ``` @@ -224,19 +224,19 @@ Run multiple health checks in parallel: **PowerShell:** ```powershell # Using default image -.\scripts\health_check\run_parallel_health_checks.ps1 16 +.\litellm\scripts\health_check\run_parallel_health_checks.ps1 16 # Using custom image -.\scripts\health_check\run_parallel_health_checks.ps1 -NumParallelJobs 16 -ImageName "your-registry/your-image:tag" +.\litellm\scripts\health_check\run_parallel_health_checks.ps1 -NumParallelJobs 16 -ImageName "your-registry/your-image:tag" ``` **Bash:** ```bash # Using default image -./scripts/health_check/run_parallel_health_checks.sh 16 +./litellm/scripts/health_check/run_parallel_health_checks.sh 16 # Using custom image -./scripts/health_check/run_parallel_health_checks.sh 16 "your-registry/your-image:tag" +./litellm/scripts/health_check/run_parallel_health_checks.sh 16 "your-registry/your-image:tag" ``` ### 3. CI/CD Integration diff --git a/scripts/health_check/health_check_requirements.txt b/litellm/scripts/health_check/health_check_requirements.txt similarity index 100% rename from scripts/health_check/health_check_requirements.txt rename to litellm/scripts/health_check/health_check_requirements.txt diff --git a/scripts/health_check/run_parallel_health_checks.ps1 b/litellm/scripts/health_check/run_parallel_health_checks.ps1 similarity index 100% rename from scripts/health_check/run_parallel_health_checks.ps1 rename to litellm/scripts/health_check/run_parallel_health_checks.ps1 diff --git a/scripts/health_check/run_parallel_health_checks.sh b/litellm/scripts/health_check/run_parallel_health_checks.sh similarity index 100% rename from scripts/health_check/run_parallel_health_checks.sh rename to litellm/scripts/health_check/run_parallel_health_checks.sh diff --git a/scripts/install-cli.sh b/litellm/scripts/install-cli.sh similarity index 97% rename from scripts/install-cli.sh rename to litellm/scripts/install-cli.sh index 332bd559672..d3f36cc29d9 100755 --- a/scripts/install-cli.sh +++ b/litellm/scripts/install-cli.sh @@ -1,11 +1,11 @@ #!/usr/bin/env bash # LiteLLM CLI Installer (the thin `lite` client) -# Usage: curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm/main/scripts/install-cli.sh | sh +# Usage: curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/scripts/install-cli.sh | sh # # Installs only litellm[cli]: the `lite` command for authenticating to a LiteLLM # proxy and running coding agents (lite claude / codex / opencode) through it. # None of the proxy server runtime is pulled in. To run a proxy server instead, -# use scripts/install.sh, which installs litellm[proxy]. +# use litellm/scripts/install.sh, which installs litellm[proxy]. # # Needs only curl: uv is bootstrapped if missing, and uv provisions a compatible # Python itself (honouring litellm's requires-python), downloading a managed one @@ -13,7 +13,7 @@ # # To try an unreleased branch instead of the latest PyPI release (for example, to # QA a CLI feature before it ships), set LITELLM_CLI_REF to a branch, tag, or commit: -# curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm//scripts/install-cli.sh | \ +# curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm//litellm/scripts/install-cli.sh | \ # LITELLM_CLI_REF= sh # # NOTE: set -e without pipefail for POSIX sh compatibility (dash on Ubuntu/Debian diff --git a/scripts/install.sh b/litellm/scripts/install.sh similarity index 98% rename from scripts/install.sh rename to litellm/scripts/install.sh index 275916d8a37..e6f70c609ad 100755 --- a/scripts/install.sh +++ b/litellm/scripts/install.sh @@ -1,13 +1,13 @@ #!/usr/bin/env bash # LiteLLM Installer -# Usage: curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm/main/scripts/install.sh | sh +# Usage: curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/scripts/install.sh | sh # # Needs only curl: uv is bootstrapped if missing, and uv provisions a compatible # Python itself (reusing a suitable system one, else downloading a managed build). # # To install from an unreleased branch, tag, or commit instead of the latest PyPI # release, set LITELLM_CLI_REF: -# curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm//scripts/install.sh | \ +# curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm//litellm/scripts/install.sh | \ # LITELLM_CLI_REF= sh # # NOTE: set -e without pipefail for POSIX sh compatibility (dash on Ubuntu/Debian diff --git a/scripts/install_git_hooks.sh b/litellm/scripts/install_git_hooks.sh similarity index 81% rename from scripts/install_git_hooks.sh rename to litellm/scripts/install_git_hooks.sh index 35d5ce4c968..f8e53bc584b 100755 --- a/scripts/install_git_hooks.sh +++ b/litellm/scripts/install_git_hooks.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# Install the repo's git hooks by pointing core.hooksPath at scripts/githooks. +# Install the repo's git hooks by pointing core.hooksPath at litellm/scripts/githooks. # # Idempotent: re-running just reaffirms the config and refreshes chmod bits. # Run from anywhere inside the repo. @@ -13,7 +13,7 @@ if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then fi repo_root=$(git rev-parse --show-toplevel) -hooks_dir="$repo_root/scripts/githooks" +hooks_dir="$repo_root/litellm/scripts/githooks" if [ ! -d "$hooks_dir" ]; then echo "install_git_hooks: $hooks_dir does not exist" >&2 @@ -24,11 +24,11 @@ fi # filesystems sometimes lose the exec bit; this normalizes it. chmod +x "$hooks_dir"/* 2>/dev/null || true -git config core.hooksPath scripts/githooks +git config core.hooksPath litellm/scripts/githooks cat < Iterator[bytes]: text = ( - "mock streaming: ok from scripts/mock_bedrock_passthrough_target.py " + "mock streaming: ok from litellm/scripts/mock_bedrock_passthrough_target.py " "(invoke-with-response-stream)." ) headers = { diff --git a/scripts/mock_grayswan_timeout_server.py b/litellm/scripts/mock_grayswan_timeout_server.py similarity index 96% rename from scripts/mock_grayswan_timeout_server.py rename to litellm/scripts/mock_grayswan_timeout_server.py index bc40e13dfa5..8fc20cff7dc 100644 --- a/scripts/mock_grayswan_timeout_server.py +++ b/litellm/scripts/mock_grayswan_timeout_server.py @@ -2,7 +2,7 @@ Minimal mock GraySwan monitor server that intentionally responds slowly. Usage: - python scripts/mock_grayswan_timeout_server.py --port 8787 --delay 35 + python litellm/scripts/mock_grayswan_timeout_server.py --port 8787 --delay 35 Point GRAYSWAN_API_BASE at http://127.0.0.1:8787 so the guardrail hits this endpoint and times out (the guardrail client has a 30s timeout). diff --git a/scripts/mutation_report.py b/litellm/scripts/mutation_report.py similarity index 99% rename from scripts/mutation_report.py rename to litellm/scripts/mutation_report.py index d0f9ddf0491..001318ccf9b 100644 --- a/scripts/mutation_report.py +++ b/litellm/scripts/mutation_report.py @@ -29,7 +29,7 @@ if sys.version_info >= (3, 11): else: import tomli as tomllib -ROOT = Path(__file__).resolve().parent.parent +ROOT = Path(__file__).resolve().parents[2] MUTMUT_INVOCATION = ["uv", "run", "--no-sync", "--with", "mutmut==3.5.0", "mutmut"] diff --git a/scripts/openapi_docs_gate.py b/litellm/scripts/openapi_docs_gate.py similarity index 91% rename from scripts/openapi_docs_gate.py rename to litellm/scripts/openapi_docs_gate.py index c53b96ae5d7..fb88f0ab361 100755 --- a/scripts/openapi_docs_gate.py +++ b/litellm/scripts/openapi_docs_gate.py @@ -1,14 +1,14 @@ #!/usr/bin/env python3 -"""Delta-vs-base gate for the OA* rules in scripts/check_openapi_docs.py. +"""Delta-vs-base gate for the OA* rules in litellm/scripts/check_openapi_docs.py. -Sibling of scripts/test_quality_gate.py, pointed at the proxy's OpenAPI document +Sibling of litellm/scripts/test_quality_gate.py, pointed at the proxy's OpenAPI document instead of a source tree. Each rule is counted over every POST operation the proxy serves at HEAD and at the merge-base with the branch this change merges into, and the gate fails only when a rule grew past the merge-base count, so a new endpoint has to ship with a request schema, a description and a 200 schema while the undocumented routes that already exist are only ever allowed to shrink. -The merge-base counts come from scripts/lint_base_counts.py: the disk cache, then the +The merge-base counts come from litellm/scripts/lint_base_counts.py: the disk cache, then the CI artifact published for that commit, then a pass of the current checker over a detached worktree at the merge-base with that tree first on PYTHONPATH. """ @@ -39,8 +39,8 @@ from lint_base_counts import ( sha256_of, ) -REPO_ROOT: Final = Path(__file__).resolve().parent.parent -CHECKER: Final = REPO_ROOT / "scripts" / "check_openapi_docs.py" +REPO_ROOT: Final = Path(__file__).resolve().parents[2] +CHECKER: Final = REPO_ROOT / "litellm/scripts" / "check_openapi_docs.py" TARGET: Final = "litellm" TERMINATION_SIGNALS: Final = (signal.SIGTERM, signal.SIGHUP) @@ -127,8 +127,8 @@ def base_counts(ref: str, repo_root: Path = REPO_ROOT, checker: Path = CHECKER) worktree: Final = parent / "wt" try: _run(["git", "worktree", "add", "--detach", str(worktree), ref], cwd=repo_root) - (worktree / "scripts").mkdir(parents=True, exist_ok=True) - base_checker: Final = worktree / "scripts" / "check_openapi_docs.py" + (worktree / "litellm/scripts").mkdir(parents=True, exist_ok=True) + base_checker: Final = worktree / "litellm/scripts" / "check_openapi_docs.py" shutil.copy(checker, base_checker) _install_base_native(worktree, repo_root) return count_by_rule(_check(worktree, base_checker)) @@ -171,7 +171,7 @@ def cmd_check(base: str) -> None: "`openapi_extra={'requestBody': inline_request_body(Model, example)}` when the handler reads " "`request.body()`), a docstring, and a 200 schema (`response_model=` or `responses={200: {'model': ...}}`), " "or document an equal number of existing routes; the ceiling is the merge-base count. Run " - "`python scripts/check_openapi_docs.py` to see every finding." + "`python litellm/scripts/check_openapi_docs.py` to see every finding." ) raise SystemExit(1) diff --git a/scripts/pre_commit_lint.sh b/litellm/scripts/pre_commit_lint.sh similarity index 94% rename from scripts/pre_commit_lint.sh rename to litellm/scripts/pre_commit_lint.sh index def604c88cb..e8fe0beb4d1 100755 --- a/scripts/pre_commit_lint.sh +++ b/litellm/scripts/pre_commit_lint.sh @@ -13,8 +13,8 @@ # - tests/e2e and tests/e2e_harness Python # -> `make lint-e2e-basedpyright` (test-linting.yml's e2e type-check step) # + raw HTTP client ban (test-linting.yml's check_e2e_no_raw_requests) -# - tests/ Python, .github/linters/ruff-tests.toml, scripts/check_test_quality.py, -# scripts/test_quality_gate.py +# - tests/ Python, .github/linters/ruff-tests.toml, litellm/scripts/check_test_quality.py, +# litellm/scripts/test_quality_gate.py # -> ruff over .github/linters/ruff-tests.toml + `make lint-test-quality` (test-linting.yml's # test-tree ruff and test-quality gate steps) # - dashboard -> prettier + eslint + lint budgets (test-linting.yml's ui job) @@ -23,14 +23,14 @@ # # Each block is skipped when no matching files are in scope, so unrelated commits # stay fast. This is intentionally not auto-installed as a git hook (see -# scripts/install_git_hooks.sh): the dashboard and basedpyright passes can take +# litellm/scripts/install_git_hooks.sh): the dashboard and basedpyright passes can take # minutes, so it's run on demand rather than firing on every human commit. It is # hook-compatible if you want that anyway: -# `ln -s ../../scripts/pre_commit_lint.sh .git/hooks/pre-commit`. +# `ln -s ../../litellm/scripts/pre_commit_lint.sh .git/hooks/pre-commit`. set -eu -# Queue for one of the machine-wide heavy-work slots (see scripts/gate_slot_lock.py) +# Queue for one of the machine-wide heavy-work slots (see litellm/scripts/gate_slot_lock.py) # before anything else, so N parallel `make check` runs across worktrees execute two # at a time instead of thrashing the machine. The wrapper exports # LITELLM_GATE_SLOT_HELD, so this re-exec happens exactly once and everything this @@ -98,21 +98,21 @@ existing_files() { litellm_py_pattern='^litellm/.*\.py$' e2e_py_pattern='^tests/e2e(_harness)?/.*\.py$' -test_tree_pattern='^(tests/.*\.py|\.github/linters/ruff-tests\.toml|pyproject\.toml|scripts/(check_test_quality|test_quality_gate)\.py)$' +test_tree_pattern='^(tests/.*\.py|\.github/linters/ruff-tests\.toml|pyproject\.toml|litellm/scripts/(check_test_quality|test_quality_gate)\.py)$' spec_pattern='^(litellm/.*|enterprise/.*|pyproject\.toml|uv\.lock|litellm/ui/litellm-dashboard/(scripts/gen-api-types\.mjs|package\.json|package-lock\.json|src/lib/http/schema\.d\.ts))$' ui_prettier_pattern='^litellm/ui/litellm-dashboard/.*\.(js|jsx|ts|tsx|mjs|cjs|json|css|scss|md|mdx|yml|yaml|html)$' ui_eslint_pattern='^litellm/ui/litellm-dashboard/.*\.(js|jsx|ts|tsx|mjs|cjs)$' -litellm_py_files=$(scope_match "$litellm_py_pattern" | grep -Ev '^litellm/(enterprise|ui|vscode-extension|rust|proxy-extras|packaging|cli)/' || true) -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 +litellm_py_files=$(scope_match "$litellm_py_pattern" | grep -Ev '^litellm/(enterprise|ui|vscode-extension|rust|proxy-extras|packaging|cli|scripts|runtime)/' || true) +if [ -n "$(scope_match '^(litellm/proxy/mcp_server/|litellm/scripts/check_mcp_operation_boundary\.py)')" ]; then + uv run --no-sync python litellm/scripts/check_mcp_operation_boundary.py || exit 1 fi e2e_py_files=$(scope_match "$e2e_py_pattern") test_tree_files=$(scope_match "$test_tree_pattern") # ruff format (and CI's format step) skip enterprise; the rest of make lint covers it. fmt_files=$(printf '%s\n' "$litellm_py_files" | grep -v '^litellm/enterprise/' | existing_files) spec_files=$({ - scope_match "$spec_pattern" | grep -Ev '^litellm/(ui|vscode-extension|rust|proxy-extras|packaging|cli)/' || true + scope_match "$spec_pattern" | grep -Ev '^litellm/(ui|vscode-extension|rust|proxy-extras|packaging|cli|scripts|runtime)/' || true scope_match '^litellm/ui/litellm-dashboard/(scripts/gen-api-types\.mjs|package\.json|package-lock\.json|src/lib/http/schema\.d\.ts)$' }) # CI's ui job runs prettier over a wider extension set than eslint; keep that @@ -271,7 +271,7 @@ genapi_checks() { echo "✗ The Python env lacks the proxy deps (orjson/prisma) that gen:api needs." >&2 bootstrap_hint status=1 - elif ! uv run --no-sync python scripts/prisma_generate_if_needed.py; then + elif ! uv run --no-sync python litellm/scripts/prisma_generate_if_needed.py; then echo "✗ Could not regenerate Prisma client (prisma generate failed)." >&2 status=1 elif ! uv run --no-sync python -m litellm.proxy._lazy_openapi_snapshot; then diff --git a/scripts/prisma_generate_if_needed.py b/litellm/scripts/prisma_generate_if_needed.py similarity index 98% rename from scripts/prisma_generate_if_needed.py rename to litellm/scripts/prisma_generate_if_needed.py index f2d2232b23f..fad9ad5d61d 100644 --- a/scripts/prisma_generate_if_needed.py +++ b/litellm/scripts/prisma_generate_if_needed.py @@ -26,7 +26,7 @@ import sys from collections.abc import Callable, Mapping from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent +REPO_ROOT = Path(__file__).resolve().parents[2] SCHEMA = REPO_ROOT / "litellm" / "proxy" / "schema.prisma" STAMP = Path(sys.prefix) / "litellm-prisma-schema.stamp" diff --git a/scripts/quickstart.ps1 b/litellm/scripts/quickstart.ps1 similarity index 99% rename from scripts/quickstart.ps1 rename to litellm/scripts/quickstart.ps1 index 9d1d65f959e..b8b46cde58d 100644 --- a/scripts/quickstart.ps1 +++ b/litellm/scripts/quickstart.ps1 @@ -1,9 +1,9 @@ # LiteLLM Gateway quickstart for Windows: the gateway, Postgres, and the admin UI in one command. -# powershell -c "irm https://raw.githubusercontent.com/BerriAI/litellm/main/scripts/quickstart.ps1 | iex" +# powershell -c "irm https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/scripts/quickstart.ps1 | iex" # On macOS and Linux, scripts/quickstart.sh does the same. # # To read it before running it: -# irm https://raw.githubusercontent.com/BerriAI/litellm/main/scripts/quickstart.ps1 -OutFile quickstart.ps1 +# irm https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/scripts/quickstart.ps1 -OutFile quickstart.ps1 # notepad quickstart.ps1 # powershell -ExecutionPolicy Bypass -File quickstart.ps1 # @@ -14,7 +14,7 @@ # with -Yes. # # It also takes an action, which the litellm-gateway command it installs takes too: -# & ([scriptblock]::Create((irm https://raw.githubusercontent.com/BerriAI/litellm/main/scripts/quickstart.ps1))) stop +# & ([scriptblock]::Create((irm https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/scripts/quickstart.ps1))) stop # status, start (up), stop (down), restart, logs, open, update, uninstall # # -Yes, or LITELLM_YES=1 no questions: install to ~\litellm-gateway, don't open a browser, @@ -43,7 +43,7 @@ function Invoke-LiteLLMQuickstart { $composeUrl = 'https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/deploy/docker/docker-compose.quickstart.yml' if ($env:LITELLM_COMPOSE_URL) { $composeUrl = $env:LITELLM_COMPOSE_URL } - $scriptUrl = 'https://raw.githubusercontent.com/BerriAI/litellm/main/scripts/quickstart.ps1' + $scriptUrl = 'https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/scripts/quickstart.ps1' if ($env:LITELLM_SCRIPT_URL) { $scriptUrl = $env:LITELLM_SCRIPT_URL } $onWindows = ($PSVersionTable.PSEdition -eq 'Desktop') -or ((Test-Path variable:IsWindows) -and $IsWindows) @@ -70,7 +70,7 @@ function Invoke-LiteLLMQuickstart { ' -Yes, -y ask nothing; without a console, uninstall needs it' '' 'From the install command:' - ' & ([scriptblock]::Create((irm https://raw.githubusercontent.com/BerriAI/litellm/main/scripts/quickstart.ps1))) status' + ' & ([scriptblock]::Create((irm https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/scripts/quickstart.ps1))) status' ) | ForEach-Object { $To.WriteLine($_) } } diff --git a/scripts/quickstart.sh b/litellm/scripts/quickstart.sh similarity index 99% rename from scripts/quickstart.sh rename to litellm/scripts/quickstart.sh index 53a6f39c74a..b956fc2d69f 100755 --- a/scripts/quickstart.sh +++ b/litellm/scripts/quickstart.sh @@ -1,10 +1,10 @@ #!/bin/sh # LiteLLM Gateway quickstart: the gateway, Postgres, and the admin UI in one command. -# curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm/main/scripts/quickstart.sh | sh -# On Windows, scripts/quickstart.ps1 does the same in PowerShell. +# curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/scripts/quickstart.sh | sh +# On Windows, litellm/scripts/quickstart.ps1 does the same in PowerShell. # # To read it before running it: -# curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm/main/scripts/quickstart.sh -o quickstart.sh +# curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/scripts/quickstart.sh -o quickstart.sh # less quickstart.sh # sh quickstart.sh # @@ -15,7 +15,7 @@ # run with --yes. # # It also takes an action, which the litellm-gateway command it installs takes too: -# curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm/main/scripts/quickstart.sh | sh -s -- stop +# curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/scripts/quickstart.sh | sh -s -- stop # status, start (up), stop (down), restart, logs, open, update, uninstall # # --yes, -y no questions: install to ~/litellm-gateway, don't open a browser, @@ -35,7 +35,7 @@ set -eu COMPOSE_URL="${LITELLM_COMPOSE_URL:-https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/deploy/docker/docker-compose.quickstart.yml}" -SCRIPT_URL="${LITELLM_SCRIPT_URL:-https://raw.githubusercontent.com/BerriAI/litellm/main/scripts/quickstart.sh}" +SCRIPT_URL="${LITELLM_SCRIPT_URL:-https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/scripts/quickstart.sh}" # A port set by the caller is never moved; later steps export LITELLM_PORT too. PORT_PINNED="${LITELLM_PORT:+1}" @@ -324,7 +324,7 @@ install it finds. Actions: --yes, -y ask nothing; without a terminal, uninstall needs it From the install command: - curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm/main/scripts/quickstart.sh | sh -s -- status + curl -fsSL https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/scripts/quickstart.sh | sh -s -- status USAGE } diff --git a/scripts/ruff_strict_gate.py b/litellm/scripts/ruff_strict_gate.py similarity index 97% rename from scripts/ruff_strict_gate.py rename to litellm/scripts/ruff_strict_gate.py index 248a76cea1d..3b73decce60 100644 --- a/scripts/ruff_strict_gate.py +++ b/litellm/scripts/ruff_strict_gate.py @@ -7,7 +7,7 @@ past the merge-base count, so a change is blamed for the violations it adds, never for drift that already sits in the base. There is no committed budget: the merge-base count is the ceiling, so it moves only when the base branch does. -The merge-base counts come from scripts/lint_base_counts.py: the disk cache, +The merge-base counts come from litellm/scripts/lint_base_counts.py: the disk cache, then the CI artifact published for that commit, then a ruff pass over a detached worktree at the merge-base under the current ruff configs. ``--emit-counts-dir`` writes HEAD's counts as the file that artifact is built @@ -36,7 +36,7 @@ from lint_base_counts import ( sha256_of, ) -REPO_ROOT: Final = Path(__file__).resolve().parent.parent +REPO_ROOT: Final = Path(__file__).resolve().parents[2] STRICT_CONFIG: Final = REPO_ROOT / ".github/linters/ruff-strict.toml" BASE_CONFIG: Final = REPO_ROOT / "pyproject.toml" TARGET: Final = "litellm" diff --git a/scripts/seed_request_logs.py b/litellm/scripts/seed_request_logs.py similarity index 99% rename from scripts/seed_request_logs.py rename to litellm/scripts/seed_request_logs.py index 1217a9fb7e4..d28aed18e10 100644 --- a/scripts/seed_request_logs.py +++ b/litellm/scripts/seed_request_logs.py @@ -15,7 +15,7 @@ from typing import TYPE_CHECKING, Final, Literal import httpx from pydantic import BaseModel, ConfigDict, JsonValue, TypeAdapter -from scripts.seed_tracing_fixtures import JSON_OBJECT, spend_fixtures +from litellm.scripts.seed_tracing_fixtures import JSON_OBJECT, spend_fixtures if TYPE_CHECKING: from prisma.types import LiteLLM_SpendLogsCreateWithoutRelationsInput diff --git a/scripts/seed_tracing_fixtures.py b/litellm/scripts/seed_tracing_fixtures.py similarity index 99% rename from scripts/seed_tracing_fixtures.py rename to litellm/scripts/seed_tracing_fixtures.py index c6f0570c17c..db64f7ff29c 100644 --- a/scripts/seed_tracing_fixtures.py +++ b/litellm/scripts/seed_tracing_fixtures.py @@ -35,9 +35,9 @@ if TYPE_CHECKING: from prisma import Prisma from prisma.types import LiteLLM_SpendLogsCreateWithoutRelationsInput -REPO_ROOT: Final = Path(__file__).resolve().parents[1] -TRACE_FIXTURES: Final = REPO_ROOT / "scripts/lens_assets/fixtures/traces" -SPEND_FIXTURES: Final = REPO_ROOT / "scripts/lens_assets/fixtures/spend" +REPO_ROOT: Final = Path(__file__).resolve().parents[2] +TRACE_FIXTURES: Final = REPO_ROOT / "litellm/scripts/lens_assets/fixtures/traces" +SPEND_FIXTURES: Final = REPO_ROOT / "litellm/scripts/lens_assets/fixtures/spend" JSON: Final[TypeAdapter[JsonValue]] = TypeAdapter(JsonValue) JSON_OBJECT: Final = TypeAdapter(dict[str, JsonValue]) SPEND_ROWS: Final = TypeAdapter(tuple[SpendLogRecord, ...]) diff --git a/scripts/sync-issue-labels.test.ts b/litellm/scripts/sync-issue-labels.test.ts similarity index 100% rename from scripts/sync-issue-labels.test.ts rename to litellm/scripts/sync-issue-labels.test.ts diff --git a/scripts/sync-issue-labels.ts b/litellm/scripts/sync-issue-labels.ts similarity index 100% rename from scripts/sync-issue-labels.ts rename to litellm/scripts/sync-issue-labels.ts diff --git a/scripts/test_agent_mcp_endpoints.sh b/litellm/scripts/test_agent_mcp_endpoints.sh similarity index 100% rename from scripts/test_agent_mcp_endpoints.sh rename to litellm/scripts/test_agent_mcp_endpoints.sh diff --git a/scripts/test_guardrails_register_endpoints.sh b/litellm/scripts/test_guardrails_register_endpoints.sh similarity index 100% rename from scripts/test_guardrails_register_endpoints.sh rename to litellm/scripts/test_guardrails_register_endpoints.sh diff --git a/scripts/test_quality_gate.py b/litellm/scripts/test_quality_gate.py similarity index 91% rename from scripts/test_quality_gate.py rename to litellm/scripts/test_quality_gate.py index a9ad60f088c..ea0785ba836 100644 --- a/scripts/test_quality_gate.py +++ b/litellm/scripts/test_quality_gate.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 -"""Delta-vs-base gate for the TQ* rules in scripts/check_test_quality.py. +"""Delta-vs-base gate for the TQ* rules in litellm/scripts/check_test_quality.py. -Sibling of scripts/type_discipline_gate.py, pointed at the test tree instead of +Sibling of litellm/scripts/type_discipline_gate.py, pointed at the test tree instead of the package. Each rule is counted across the whole `tests` tree at HEAD and at the merge-base with the branch this change merges into, and the gate fails only when a rule grew past the merge-base count, so a change is blamed for the @@ -9,7 +9,7 @@ violations it adds, never for drift that already exists in the base. There is no committed budget: the merge-base count is the ceiling, so it moves only when the base branch does. -The merge-base counts come from scripts/lint_base_counts.py: the disk cache, +The merge-base counts come from litellm/scripts/lint_base_counts.py: the disk cache, then the CI artifact published for that commit, then a pass of the current checker over a detached worktree at the merge-base, so a rule introduced on this branch is counted at the base too. ``--emit-counts-dir`` writes HEAD's @@ -41,8 +41,8 @@ from lint_base_counts import ( sha256_of, ) -REPO_ROOT: Final = Path(__file__).resolve().parent.parent -CHECKER: Final = REPO_ROOT / "scripts" / "check_test_quality.py" +REPO_ROOT: Final = Path(__file__).resolve().parents[2] +CHECKER: Final = REPO_ROOT / "litellm/scripts" / "check_test_quality.py" TARGET: Final = "tests" TERMINATION_SIGNALS: Final = (signal.SIGTERM, signal.SIGHUP) @@ -110,8 +110,8 @@ def base_counts(ref: str, repo_root: Path = REPO_ROOT, checker: Path = CHECKER) worktree: Final = parent / "wt" try: _run(["git", "worktree", "add", "--detach", str(worktree), ref], cwd=repo_root) - (worktree / "scripts").mkdir(parents=True, exist_ok=True) - base_checker: Final = worktree / "scripts" / "check_test_quality.py" + (worktree / "litellm/scripts").mkdir(parents=True, exist_ok=True) + base_checker: Final = worktree / "litellm/scripts" / "check_test_quality.py" shutil.copy(checker, base_checker) return count_by_rule(_check(worktree, base_checker)) finally: @@ -167,7 +167,7 @@ def cmd_check(base: str) -> None: print( "Fix the new violations, or give each one a reason (`# test-quality-ok: `), or remove an " "equal number elsewhere; the ceiling is the merge-base count. Run " - "`python scripts/check_test_quality.py tests/` to see every finding." + "`python litellm/scripts/check_test_quality.py tests/` to see every finding." ) raise SystemExit(1) diff --git a/scripts/test_tool_allowlist_script.py b/litellm/scripts/test_tool_allowlist_script.py similarity index 97% rename from scripts/test_tool_allowlist_script.py rename to litellm/scripts/test_tool_allowlist_script.py index 607a8c39473..13311c951ad 100644 --- a/scripts/test_tool_allowlist_script.py +++ b/litellm/scripts/test_tool_allowlist_script.py @@ -3,7 +3,7 @@ Standalone script to test tool allowlist enforcement and tool name extraction. Run from repo root: - uv run python scripts/test_tool_allowlist_script.py + uv run python litellm/scripts/test_tool_allowlist_script.py Or run the unit tests: uv run pytest tests/unit/proxy/test_tools_allowlist_enforcement.py -v @@ -14,7 +14,7 @@ import sys from pathlib import Path # Ensure repo root is on path -repo_root = Path(__file__).resolve().parent.parent +repo_root = Path(__file__).resolve().parents[2] if str(repo_root) not in sys.path: sys.path.insert(0, str(repo_root)) diff --git a/scripts/tpm_headline_test.sh b/litellm/scripts/tpm_headline_test.sh similarity index 98% rename from scripts/tpm_headline_test.sh rename to litellm/scripts/tpm_headline_test.sh index ef6750e2433..0ce8293bd15 100755 --- a/scripts/tpm_headline_test.sh +++ b/litellm/scripts/tpm_headline_test.sh @@ -15,7 +15,7 @@ # kubectl port-forward -n litellm svc/litellm-gateway 4000:4000 # # Run: -# bash scripts/tpm_headline_test.sh +# bash litellm/scripts/tpm_headline_test.sh set -u PROXY="${PROXY:-http://localhost:4000}" MASTER_KEY="${MASTER_KEY:-sk-perf-test-fixed-do-not-rotate}" diff --git a/scripts/trace_codegen/README.md b/litellm/scripts/trace_codegen/README.md similarity index 55% rename from scripts/trace_codegen/README.md rename to litellm/scripts/trace_codegen/README.md index 00ff931e4ce..f903491150e 100644 --- a/scripts/trace_codegen/README.md +++ b/litellm/scripts/trace_codegen/README.md @@ -1,8 +1,8 @@ -Run `uv run scripts/generate_trace_types.py` from the repository root to regenerate Python HTTP contracts. Run it with `--check` to verify the frozen Lens schemas and compare generated Python with committed files +Run `uv run litellm/scripts/generate_trace_types.py` from the repository root to regenerate Python HTTP contracts. Run it with `--check` to verify the frozen Lens schemas and compare generated Python with committed files -Lens owns the Rust contracts. `scripts/lens_assets/source.json` pins the Lens repository revision and SHA-256 of each schema and development fixture. The gateway consumes these data files offline; it does not compile or maintain a second Rust tracing implementation +Lens owns the Rust contracts. `litellm/scripts/lens_assets/source.json` pins the Lens repository revision and SHA-256 of each schema and development fixture. The gateway consumes these data files offline; it does not compile or maintain a second Rust tracing implementation -To update the pin, check out the intended Lens commit and run its `export-traces-schema` binary for the default, `--requests` and `--responses` modes, plus `export-traces-clickhouse-schema`, with the `schema` feature and locked dependencies. Import the consumed roots into the corresponding `scripts/lens_assets/schemas` group and copy fixtures from that same commit. Update the source revision and hashes together, then regenerate and run the gateway trace contract tests +To update the pin, check out the intended Lens commit and run its `export-traces-schema` binary for the default, `--requests` and `--responses` modes, plus `export-traces-clickhouse-schema`, with the `schema` feature and locked dependencies. Import the consumed roots into the corresponding `litellm/scripts/lens_assets/schemas` group and copy fixtures from that same commit. Update the source revision and hashes together, then regenerate and run the gateway trace contract tests The generator pins datamodel-code-generator through its inline dependency metadata. Neither it nor the schema exporter is a runtime dependency. The templates preserve frozen models, tuple conversion and bounded scalars. Request models retain each canonical schema's extra-field policy, including ignored unknown GET parameters and forbidden extra SQL body fields diff --git a/scripts/trace_codegen/config.json b/litellm/scripts/trace_codegen/config.json similarity index 89% rename from scripts/trace_codegen/config.json rename to litellm/scripts/trace_codegen/config.json index 03c0574eaef..7a1d10d624e 100644 --- a/scripts/trace_codegen/config.json +++ b/litellm/scripts/trace_codegen/config.json @@ -7,7 +7,7 @@ "3.10", "--disable-timestamp", "--custom-file-header", - "# @generated by scripts/generate_trace_types.py, do not edit", + "# @generated by litellm/scripts/generate_trace_types.py, do not edit", "--use-standard-collections", "--use-union-operator", "--enum-field-as-literal", diff --git a/scripts/trace_codegen/templates/ScalarTypeAliasType.jinja2 b/litellm/scripts/trace_codegen/templates/ScalarTypeAliasType.jinja2 similarity index 100% rename from scripts/trace_codegen/templates/ScalarTypeAliasType.jinja2 rename to litellm/scripts/trace_codegen/templates/ScalarTypeAliasType.jinja2 diff --git a/scripts/trace_codegen/templates/TypeAliasType.jinja2 b/litellm/scripts/trace_codegen/templates/TypeAliasType.jinja2 similarity index 100% rename from scripts/trace_codegen/templates/TypeAliasType.jinja2 rename to litellm/scripts/trace_codegen/templates/TypeAliasType.jinja2 diff --git a/scripts/trace_codegen/templates/TypedDictClass.jinja2 b/litellm/scripts/trace_codegen/templates/TypedDictClass.jinja2 similarity index 100% rename from scripts/trace_codegen/templates/TypedDictClass.jinja2 rename to litellm/scripts/trace_codegen/templates/TypedDictClass.jinja2 diff --git a/scripts/trace_codegen/templates/pydantic_v2/BaseModel.jinja2 b/litellm/scripts/trace_codegen/templates/pydantic_v2/BaseModel.jinja2 similarity index 100% rename from scripts/trace_codegen/templates/pydantic_v2/BaseModel.jinja2 rename to litellm/scripts/trace_codegen/templates/pydantic_v2/BaseModel.jinja2 diff --git a/scripts/trace_codegen/templates/pydantic_v2/types.jinja2 b/litellm/scripts/trace_codegen/templates/pydantic_v2/types.jinja2 similarity index 100% rename from scripts/trace_codegen/templates/pydantic_v2/types.jinja2 rename to litellm/scripts/trace_codegen/templates/pydantic_v2/types.jinja2 diff --git a/scripts/trace_codegen/templates/types.jinja2 b/litellm/scripts/trace_codegen/templates/types.jinja2 similarity index 100% rename from scripts/trace_codegen/templates/types.jinja2 rename to litellm/scripts/trace_codegen/templates/types.jinja2 diff --git a/scripts/type_check_gate.py b/litellm/scripts/type_check_gate.py similarity index 97% rename from scripts/type_check_gate.py rename to litellm/scripts/type_check_gate.py index 874fda013be..ef5736a0709 100644 --- a/scripts/type_check_gate.py +++ b/litellm/scripts/type_check_gate.py @@ -32,7 +32,7 @@ process OOMs at the ~4 GB default, and when callers had to remember the flag, every hand-copied pipeline (Makefile, CI, a dev running the recipe by hand) was one forgotten env line away from an 80-second crash. The base pass is a second basedpyright run over a detached worktree at the merge-base, under the -same environment so import resolution matches, and scripts/lint_base_counts.py +same environment so import resolution matches, and litellm/scripts/lint_base_counts.py spares it whenever it can: the per-rule counts are cached under the repo's git common dir keyed by merge-base commit, ``pyproject.toml``, ``uv.lock``, the Prisma schema, and the dependency-group set, and on a disk-cache miss the @@ -76,7 +76,7 @@ from lint_base_counts import ( resolve_base_point, ) -REPO_ROOT = Path(__file__).resolve().parent.parent +REPO_ROOT = Path(__file__).resolve().parents[2] PYRIGHT_CONFIG = REPO_ROOT / "pyproject.toml" UV_LOCK = REPO_ROOT / "uv.lock" @@ -87,7 +87,7 @@ UV_LOCK = REPO_ROOT / "uv.lock" # matched. TYPECHECK_ENV_DIR = REPO_ROOT / ".venv-typecheck" TYPECHECK_DEP_GROUPS = ("proxy-dev", "e2e-dev") -PRISMA_GENERATE_SCRIPT = REPO_ROOT / "scripts" / "prisma_generate_if_needed.py" +PRISMA_GENERATE_SCRIPT = REPO_ROOT / "litellm/scripts" / "prisma_generate_if_needed.py" PRISMA_SCHEMA = REPO_ROOT / "litellm" / "proxy" / "schema.prisma" # basedpyright's node process needs more than the ~4 GB default heap on this @@ -310,7 +310,7 @@ def judge(head: Mapping[str, int], base: Mapping[str, int], base_point: str) -> print(f" {breach.rule}: total {breach.total} over ceiling {breach.ceiling} (this change added {breach.added})") print( "Reduce the new errors or remove an equal number elsewhere; the ceiling is the merge-base " - "count, or the cap in ANY_CAPS (scripts/type_check_gate.py) when that is higher." + "count, or the cap in ANY_CAPS (litellm/scripts/type_check_gate.py) when that is higher." ) summary: Final = "; ".join(f"{b.rule} {b.total}/{b.ceiling} (+{b.added})" for b in breaches) print(f"BREACHED RULES: {summary}") diff --git a/scripts/type_discipline_gate.py b/litellm/scripts/type_discipline_gate.py similarity index 93% rename from scripts/type_discipline_gate.py rename to litellm/scripts/type_discipline_gate.py index 5e6745c041d..f60b7602811 100644 --- a/scripts/type_discipline_gate.py +++ b/litellm/scripts/type_discipline_gate.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 -"""Delta-vs-base gate for the LIT* rules in scripts/check_type_discipline.py. +"""Delta-vs-base gate for the LIT* rules in litellm/scripts/check_type_discipline.py. -Sibling of scripts/ruff_strict_gate.py. Each rule is counted across the whole +Sibling of litellm/scripts/ruff_strict_gate.py. Each rule is counted across the whole `litellm` tree at HEAD and at the merge-base with the branch this change merges into, and the gate fails only when a rule grew past the merge-base count, so a change is blamed for the violations it adds, never for drift that already exists @@ -23,7 +23,7 @@ violating comprehension spanning it and to any single-line violating comprehension on that line), and LIT015 (pydantic model not frozen; suppress with `# frozen-ok: `). -The merge-base counts come from scripts/lint_base_counts.py: the disk cache, +The merge-base counts come from litellm/scripts/lint_base_counts.py: the disk cache, then the CI artifact published for that commit, then a pass of the current checker over a detached worktree at the merge-base, so a rule change on this branch is measured on both sides. ``--emit-counts-dir`` writes HEAD's counts @@ -51,8 +51,8 @@ from lint_base_counts import ( sha256_of, ) -REPO_ROOT: Final = Path(__file__).resolve().parent.parent -CHECKER: Final = REPO_ROOT / "scripts" / "check_type_discipline.py" +REPO_ROOT: Final = Path(__file__).resolve().parents[2] +CHECKER: Final = REPO_ROOT / "litellm/scripts" / "check_type_discipline.py" TARGET: Final = "litellm" _HUNK: Final = re.compile(r"^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@") @@ -108,8 +108,8 @@ def base_counts(ref: str) -> dict[str, int]: try: _run(["git", "worktree", "add", "--detach", str(worktree), ref]) # Measure the base with the *current* rule logic, not whatever shipped at base. - (worktree / "scripts").mkdir(parents=True, exist_ok=True) - checker: Final = worktree / "scripts" / "check_type_discipline.py" + (worktree / "litellm/scripts").mkdir(parents=True, exist_ok=True) + checker: Final = worktree / "litellm/scripts" / "check_type_discipline.py" shutil.copy(CHECKER, checker) return count_by_rule(_check(worktree, checker)) finally: diff --git a/scripts/verify_adaptive_router.py b/litellm/scripts/verify_adaptive_router.py similarity index 99% rename from scripts/verify_adaptive_router.py rename to litellm/scripts/verify_adaptive_router.py index fde9dc51a15..aa2522b87d4 100644 --- a/scripts/verify_adaptive_router.py +++ b/litellm/scripts/verify_adaptive_router.py @@ -11,7 +11,7 @@ Requires: * "smart" (expensive, higher quality) Run: - uv run python scripts/verify_adaptive_router.py + uv run python litellm/scripts/verify_adaptive_router.py Optional env: LITELLM_PROXY_URL (default: http://localhost:4000) diff --git a/scripts/with_dashboard_node.sh b/litellm/scripts/with_dashboard_node.sh similarity index 97% rename from scripts/with_dashboard_node.sh rename to litellm/scripts/with_dashboard_node.sh index 106c3243ce7..934ce5e78a1 100755 --- a/scripts/with_dashboard_node.sh +++ b/litellm/scripts/with_dashboard_node.sh @@ -3,7 +3,7 @@ set -eu [ $# -gt 0 ] || { echo "usage: $0 [args...]" >&2; exit 2; } -repo_root=$(cd "$(dirname "$0")/.." && pwd) +repo_root=$(cd "$(dirname "$0")/../.." && pwd) dashboard="$repo_root/litellm/ui/litellm-dashboard" floor=$(sed -n 's/.*"node": *">=\([0-9][0-9.]*\)".*/\1/p' "$dashboard/package.json") pinned=$(tr -d '[:space:]' < "$dashboard/.nvmrc") diff --git a/litellm/tracing/AGENTS.md b/litellm/tracing/AGENTS.md index 397252be7df..7a23b694b06 100644 --- a/litellm/tracing/AGENTS.md +++ b/litellm/tracing/AGENTS.md @@ -3,7 +3,7 @@ - Lens owns trace normalization, schemas, storage, graph assembly and querying in `BerriAI/lens` - This package owns the HTTP client, gateway response validation and asynchronous gateway spend export. Keep the trace reader remote-only - Gateway endpoints preserve authenticated user/team scope, trace references, pagination and public error categories -- `generated/` comes from `scripts/generate_trace_types.py` using the Lens schemas pinned in `scripts/lens_assets/source.json`. Update the canonical Lens Rust contracts and import their schema outputs before regenerating. Never edit generated Python +- `generated/` comes from `litellm/scripts/generate_trace_types.py` using the Lens schemas pinned in `litellm/scripts/lens_assets/source.json`. Update the canonical Lens Rust contracts and import their schema outputs before regenerating. Never edit generated Python - Keep the pinned schema and fixture checksums current. CI verifies assets and regenerated Python without a Rust trace implementation in this repository - Independent gateway ClickHouse spend logging lives in `litellm/integrations/clickhouse`, using `litellm/rust_bridge/clickhouse.py` and the native spend writer - OTLP upload routes only return setup guidance. Keep their JSON/protobuf error encoding without restoring ingestion or a native trace fallback diff --git a/litellm/tracing/generated/models.py b/litellm/tracing/generated/models.py index af2fb3e2211..0273ca6dc67 100644 --- a/litellm/tracing/generated/models.py +++ b/litellm/tracing/generated/models.py @@ -1,4 +1,4 @@ -# @generated by scripts/generate_trace_types.py, do not edit +# @generated by litellm/scripts/generate_trace_types.py, do not edit from __future__ import annotations diff --git a/litellm/tracing/generated/requests.py b/litellm/tracing/generated/requests.py index f0c9cbc2d4e..331572b85c9 100644 --- a/litellm/tracing/generated/requests.py +++ b/litellm/tracing/generated/requests.py @@ -1,4 +1,4 @@ -# @generated by scripts/generate_trace_types.py, do not edit +# @generated by litellm/scripts/generate_trace_types.py, do not edit from __future__ import annotations diff --git a/litellm/tracing/generated/responses.py b/litellm/tracing/generated/responses.py index 38dee46b305..0b2527b477f 100644 --- a/litellm/tracing/generated/responses.py +++ b/litellm/tracing/generated/responses.py @@ -1,4 +1,4 @@ -# @generated by scripts/generate_trace_types.py, do not edit +# @generated by litellm/scripts/generate_trace_types.py, do not edit from __future__ import annotations diff --git a/litellm/tracing/generated/types.py b/litellm/tracing/generated/types.py index ed2f90391be..ca139e1dcf6 100644 --- a/litellm/tracing/generated/types.py +++ b/litellm/tracing/generated/types.py @@ -1,4 +1,4 @@ -# @generated by scripts/generate_trace_types.py, do not edit +# @generated by litellm/scripts/generate_trace_types.py, do not edit from __future__ import annotations diff --git a/litellm/types/interactions/README.md b/litellm/types/interactions/README.md index 45783d604db..e2b4369654b 100644 --- a/litellm/types/interactions/README.md +++ b/litellm/types/interactions/README.md @@ -31,7 +31,7 @@ uv tool run --from datamodel-code-generator==0.66.0 datamodel-codegen \ --base-class litellm.types.llms.base.LiteLLMBaseModel ``` -The pin is the same `datamodel-code-generator` version `scripts/generate_trace_types.py` uses. The generator names +The pin is the same `datamodel-code-generator` version `litellm/scripts/generate_trace_types.py` uses. The generator names inline enums by order of appearance (`Status`, `Status1`, `Status2`, ...), so a regeneration can rename them. The compliance tests resolve each status enum through its model's `status` field, but `tests/unit/interactions/test_background_cost_polling.py` and diff --git a/litellm/ui/litellm-dashboard/src/lib/http/schema.d.ts b/litellm/ui/litellm-dashboard/src/lib/http/schema.d.ts index 8f01b3a7379..226493e2bb0 100644 --- a/litellm/ui/litellm-dashboard/src/lib/http/schema.d.ts +++ b/litellm/ui/litellm-dashboard/src/lib/http/schema.d.ts @@ -31785,7 +31785,7 @@ export interface components { use_spend_logs_ledger: boolean; /** * Use Spend Logs Partitioning - * @description If True and LiteLLM_SpendLogs has been converted to a range-partitioned table (scripts/db/partition_spend_logs.sql), retention cleanup drops expired partitions instead of deleting rows, and pre-creates upcoming partitions. Default is False. + * @description If True and LiteLLM_SpendLogs has been converted to a range-partitioned table (litellm/scripts/db/partition_spend_logs.sql), retention cleanup drops expired partitions instead of deleting rows, and pre-creates upcoming partitions. Default is False. */ use_spend_logs_partitioning?: boolean | null; /** diff --git a/pyproject.toml b/pyproject.toml index 121ae1a6939..39c760ef943 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -343,8 +343,8 @@ profile = "release" editable-profile = "dev" include = [ { path = ".github/packaging/*.py", format = "sdist" }, - { path = "rust-toolchain.toml", format = "sdist" }, - { path = ".cargo/config.toml", format = "sdist" }, + { path = "litellm/rust/rust-toolchain.toml", format = "sdist" }, + { path = "litellm/rust/.cargo/config.toml", format = "sdist" }, "litellm/integrations/prometheus_helpers/grafana_dashboards/**", "litellm/proxy/_experimental/out/**", "litellm/router_strategy/complexity_router/artifacts/*.json", @@ -358,6 +358,11 @@ include = [ { path = "model_prices_and_context_window.json", format = "sdist" }, ] exclude = [ + "litellm/scripts", + "litellm/scripts/**", + "litellm/runtime", + "litellm/runtime/**", + "litellm/schema.prisma", "litellm/enterprise", "litellm/enterprise/**", "litellm/proxy-extras", @@ -392,8 +397,8 @@ concurrent-builds = 1 cache-keys = [ { file = "pyproject.toml" }, { env = "MATURIN_PEP517_ARGS" }, - { file = "rust-toolchain.toml" }, - { file = ".cargo/config.toml" }, + { file = "litellm/rust/rust-toolchain.toml" }, + { file = "litellm/rust/.cargo/config.toml" }, { file = "litellm/rust/Cargo.lock" }, { file = "litellm/rust/Cargo.toml" }, { file = "litellm/rust/crates/**/*" }, @@ -442,8 +447,8 @@ version_files = [ ] [tool.pytest.ini_options] -norecursedirs = ["*.egg", ".*", "_darcs", "build", "CVS", "dist", "node_modules", "venv", "{arch}", "**/litellm/ui", "**/litellm/vscode-extension", "**/litellm/enterprise", "**/litellm/proxy-extras", "**/litellm/packaging", "**/litellm/rust"] -pythonpath = ["scripts"] +norecursedirs = ["*.egg", ".*", "_darcs", "build", "CVS", "dist", "node_modules", "venv", "{arch}", "**/litellm/ui", "**/litellm/vscode-extension", "**/litellm/enterprise", "**/litellm/proxy-extras", "**/litellm/packaging", "**/litellm/rust", "**/litellm/scripts", "**/litellm/runtime"] +pythonpath = ["litellm/scripts", "litellm/runtime"] asyncio_mode = "auto" asyncio_default_fixture_loop_scope = "session" markers = [ @@ -510,6 +515,7 @@ source = ["litellm"] relative_files = true [tool.ruff] +src = [".", "litellm/runtime"] lint.ignore = ["F405", "E402", "F403"] # The second group is the strict gate's graduates: rules the codebase already has zero # violations of, so they hard-fail here instead of being counted by the strict gate. @@ -528,7 +534,7 @@ lint.extend-select = [ # so RUF100 leaves their directives alone: the strict gate (.github/linters/ruff-strict.toml) and upstream # litellm's own ruff config both rely on suppressions this config can't see. lint.external = [ - # Enforced by the strict-rule gate (scripts/ruff_strict_gate.py + .github/linters/ruff-strict.toml). + # Enforced by the strict-rule gate (litellm/scripts/ruff_strict_gate.py + .github/linters/ruff-strict.toml). # 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. @@ -540,7 +546,7 @@ lint.external = [ ] line-length = 120 -extend-exclude = ["litellm/deploy", "litellm/ui", "litellm/vscode-extension", "litellm/enterprise", "litellm/proxy-extras", "litellm/packaging", "litellm/rust", "litellm/proxy/discovery_endpoints/skill_scanner_adapter"] +extend-exclude = ["litellm/scripts", "litellm/runtime", "litellm/deploy", "litellm/ui", "litellm/vscode-extension", "litellm/enterprise", "litellm/proxy-extras", "litellm/packaging", "litellm/rust", "litellm/proxy/discovery_endpoints/skill_scanner_adapter"] format.exclude = ["**/enterprise/**"] @@ -570,9 +576,10 @@ banned-module-level-imports = ["prisma"] "litellm/proxy/utils.py" = ["F401"] [tool.pyright] +extraPaths = ["litellm/runtime"] include = ["litellm"] ignore = [] -exclude = ["**/node_modules", "**/__pycache__", "tests/e2e/claude_code", "tests/e2e_harness/claude_code", "tests/e2e/ui", "litellm/types/utils.py", "litellm/proxy/_types.py", "litellm/deploy", "litellm/ui", "litellm/vscode-extension", "litellm/enterprise", "litellm/proxy-extras", "litellm/packaging", "litellm/rust", "litellm/proxy/discovery_endpoints/skill_scanner_adapter"] +exclude = ["**/node_modules", "**/__pycache__", "tests/e2e/claude_code", "tests/e2e_harness/claude_code", "tests/e2e/ui", "litellm/types/utils.py", "litellm/proxy/_types.py", "litellm/scripts", "litellm/runtime", "litellm/deploy", "litellm/ui", "litellm/vscode-extension", "litellm/enterprise", "litellm/proxy-extras", "litellm/packaging", "litellm/rust", "litellm/proxy/discovery_endpoints/skill_scanner_adapter"] pythonVersion = "3.12" typeCheckingMode = "strict" enableTypeIgnoreComments = false diff --git a/scripts/ci_cd/baseline_db.py b/scripts/ci_cd/baseline_db.py deleted file mode 100644 index 3fb9203b6a7..00000000000 --- a/scripts/ci_cd/baseline_db.py +++ /dev/null @@ -1,60 +0,0 @@ -import subprocess -from pathlib import Path -from datetime import datetime - - -def create_baseline(): - """Create baseline migration in deploy/migrations""" - try: - # Get paths - root_dir = Path(__file__).resolve().parents[2] - deploy_dir = root_dir / "deploy" - migrations_dir = deploy_dir / "migrations" - schema_path = root_dir / "schema.prisma" - - # Create migrations directory - migrations_dir.mkdir(parents=True, exist_ok=True) - - # Create migration_lock.toml if it doesn't exist - lock_file = migrations_dir / "migration_lock.toml" - if not lock_file.exists(): - lock_file.write_text('provider = "postgresql"\n') - - # Create timestamp-based migration directory - timestamp = datetime.now().strftime("%Y%m%d%H%M%S") - migration_dir = migrations_dir / f"{timestamp}_baseline" - migration_dir.mkdir(parents=True, exist_ok=True) - - # Generate migration SQL - result = subprocess.run( - [ - "prisma", - "migrate", - "diff", - "--from-empty", - "--to-schema-datamodel", - str(schema_path), - "--script", - ], - capture_output=True, - text=True, - check=True, - ) - - # Write the SQL to migration.sql - migration_file = migration_dir / "migration.sql" - migration_file.write_text(result.stdout) - - print(f"Created baseline migration in {migration_dir}") - return True - - except subprocess.CalledProcessError as e: - print(f"Error running prisma command: {e.stderr}") - return False - except Exception as e: - print(f"Error creating baseline migration: {str(e)}") - return False - - -if __name__ == "__main__": - create_baseline() diff --git a/tests/base_sdk_tests/test_core_distribution.py b/tests/base_sdk_tests/test_core_distribution.py index adb60cbb478..08196b9aee6 100644 --- a/tests/base_sdk_tests/test_core_distribution.py +++ b/tests/base_sdk_tests/test_core_distribution.py @@ -1,4 +1,5 @@ import email +import importlib.util import os import subprocess import sys @@ -18,6 +19,15 @@ else: ROOT: Final = Path(__file__).resolve().parents[2] +BUILD_SPEC: Final = importlib.util.spec_from_file_location( + "build_core_distribution", ROOT / "litellm/scripts/build_core_distribution.py" +) +assert BUILD_SPEC is not None and BUILD_SPEC.loader is not None +BUILD: Final = importlib.util.module_from_spec(BUILD_SPEC) +BUILD_SPEC.loader.exec_module(BUILD) +SOURCES: Final = BUILD.SOURCES +stage_core_distribution: Final = BUILD.stage_core_distribution +main: Final = BUILD.main @pytest.mark.parametrize( @@ -31,16 +41,14 @@ ROOT: Final = Path(__file__).resolve().parents[2] def test_build_command_selects_requested_distributions( tmp_path: Path, sdist_only: bool, package_cli_args: tuple[str, ...], package: str ) -> None: - from scripts.build_core_distribution import main - output: Final = tmp_path / "dist" arguments: Final = ["build_core_distribution.py", *package_cli_args, "--out-dir", str(output)] + ( ["--sdist-only"] if sdist_only else [] ) with ( patch.object(sys, "argv", arguments), - patch("scripts.build_core_distribution.stage_core_distribution") as stage, - patch("scripts.build_core_distribution.subprocess.run") as run, + patch.object(BUILD, "stage_core_distribution") as stage, + patch.object(BUILD.subprocess, "run") as run, ): main() run.assert_called_once() @@ -67,8 +75,6 @@ def source_repository(tmp_path: Path) -> Path: def test_staging_stamps_release_version_without_modifying_sources( tmp_path: Path, source_repository: Path, package: str ) -> None: - from scripts.build_core_distribution import SOURCES, stage_core_distribution - source: Final = source_repository for name in SOURCES: path: Final = source / name @@ -78,6 +84,10 @@ def test_staging_stamps_release_version_without_modifying_sources( elif name == "litellm/rust": path.mkdir() (path / "Cargo.toml").write_text("shared rust") + for configuration in ("rust-toolchain.toml", ".cargo/config.toml"): + target: Final = path / configuration + target.parent.mkdir(parents=True, exist_ok=True) + target.write_bytes((ROOT / "litellm" / "rust" / configuration).read_bytes()) else: path.parent.mkdir(parents=True, exist_ok=True) path.write_text(f"shared {name}") @@ -96,7 +106,10 @@ def test_staging_stamps_release_version_without_modifying_sources( assert not (stage / "litellm" / "__init__.py").exists() assert all( (stage / name).exists() - for name in ("litellm/rust", ".cargo", "rust-toolchain.toml", "model_prices_and_context_window.json") + for name in ( + "litellm/rust", "litellm/rust/.cargo/config.toml", "litellm/rust/rust-toolchain.toml", + "model_prices_and_context_window.json", + ) ) assert manifest.read_bytes() == original assert (source / "pyproject.toml").read_text() == '[project]\nname = "litellm"\nversion = "9.8.7rc1"\n' @@ -112,8 +125,6 @@ def test_staging_stamps_release_version_without_modifying_sources( def test_gateway_staging_refuses_manifest_without_in_tree_rust_path(tmp_path: Path, source_repository: Path) -> None: - from scripts.build_core_distribution import SOURCES, stage_core_distribution - source: Final = source_repository for name in SOURCES: path: Final = source / name @@ -198,7 +209,8 @@ def test_core_artifacts_exclude_local_configuration(distributions: tuple[Path, P @pytest.mark.parametrize( - "relative_path", ["rust-toolchain.toml", ".cargo/config.toml", "model_prices_and_context_window.json"] + "relative_path", + ["litellm/rust/rust-toolchain.toml", "litellm/rust/.cargo/config.toml", "model_prices_and_context_window.json"], ) def test_core_sdist_preserves_native_build_configuration(distribution_directory: Path, relative_path: str) -> None: sdists: Final = tuple(distribution_directory.glob("litellm_core-*.tar.gz")) @@ -215,7 +227,7 @@ def test_core_sdist_rebuilds_without_repository(distributions: tuple[Path, Path] with tarfile.open(distributions[1]) as archive: archive.extractall(tmp_path, filter="data") source: Final = next(tmp_path.glob("litellm_core-*")) - assert not (source / "scripts/build_core_distribution.py").exists() + assert not (source / "litellm/scripts/build_core_distribution.py").exists() assert tomllib.loads((source / "pyproject.toml").read_text())["project"]["name"] == "litellm-core" result: Final = subprocess.run( ["uv", "build", "--python", sys.executable, "--wheel", "--out-dir", str(tmp_path / "rebuilt")], @@ -233,8 +245,6 @@ def test_core_sdist_rebuilds_without_repository(distributions: tuple[Path, Path] def test_staging_copies_sources_without_build_artifacts(tmp_path: Path, source_repository: Path) -> None: - from scripts.build_core_distribution import SOURCES, stage_core_distribution - source: Final = source_repository for name in SOURCES: (source / name).mkdir() @@ -255,8 +265,6 @@ def test_staging_copies_sources_without_build_artifacts(tmp_path: Path, source_r def test_staging_preserves_gitignore_rules(tmp_path: Path, source_repository: Path) -> None: - from scripts.build_core_distribution import SOURCES, stage_core_distribution - source: Final = source_repository for name in SOURCES: (source / name).mkdir() @@ -287,8 +295,6 @@ def test_staging_preserves_gitignore_rules(tmp_path: Path, source_repository: Pa def test_staging_rejects_missing_release_version(tmp_path: Path) -> None: - from scripts.build_core_distribution import stage_core_distribution - manifest: Final = tmp_path / "litellm/packaging/litellm-core/pyproject.toml" manifest.parent.mkdir(parents=True) manifest.write_bytes((ROOT / "litellm/packaging/litellm-core/pyproject.toml").read_bytes()) diff --git a/tests/code_coverage_tests/check_migrations_no_data_rewrites.py b/tests/code_coverage_tests/check_migrations_no_data_rewrites.py index 882c71abd87..014ec840a3d 100644 --- a/tests/code_coverage_tests/check_migrations_no_data_rewrites.py +++ b/tests/code_coverage_tests/check_migrations_no_data_rewrites.py @@ -27,7 +27,7 @@ table without a default is still free on every version. An index on a request-log table cannot ship as a migration at all. A plain `CREATE INDEX` blocks writes to the table until the build finishes, and `CREATE INDEX CONCURRENTLY` is refused by Postgres on a partitioned parent, which LiteLLM_SpendLogs -is wherever the operator ran scripts/db/partition_spend_logs.sql. The migration job builds +is wherever the operator ran litellm/scripts/db/partition_spend_logs.sql. The migration job builds those indexes after `migrate deploy`, concurrently and per partition, from the list in litellm_proxy_extras/request_log_indexes.py, so that list is where a new one goes. diff --git a/tests/code_coverage_tests/ensure_async_clients_test.py b/tests/code_coverage_tests/ensure_async_clients_test.py index f4922a11806..461207ad545 100644 --- a/tests/code_coverage_tests/ensure_async_clients_test.py +++ b/tests/code_coverage_tests/ensure_async_clients_test.py @@ -1,5 +1,11 @@ import ast import os +from itertools import filterfalse +from typing import Final + +NON_SDK_SOURCE_DIRS: Final = frozenset( + {"cli", "deploy", "enterprise", "packaging", "proxy-extras", "runtime", "rust", "scripts", "ui", "vscode-extension"} +) ALLOWED_FILES = [ # Lens data traffic owns one pool per app lifespan, isolated from model traffic and closed on shutdown. @@ -86,7 +92,9 @@ def scan_directory_for_async_handler(base_dir): """ violations = {} - for root, _, files in os.walk(base_dir): + for root, dirs, files in os.walk(base_dir): + if os.path.normpath(root) == os.path.normpath(base_dir): + dirs[:] = filterfalse(NON_SDK_SOURCE_DIRS.__contains__, dirs) for file in files: if file.endswith(".py"): file_path = os.path.join(root, file) diff --git a/tests/code_coverage_tests/test_generate_provider_endpoints_support.py b/tests/code_coverage_tests/test_generate_provider_endpoints_support.py index c2ec6f56c3a..62782edb7f4 100644 --- a/tests/code_coverage_tests/test_generate_provider_endpoints_support.py +++ b/tests/code_coverage_tests/test_generate_provider_endpoints_support.py @@ -6,7 +6,7 @@ from typing import Final import pytest from pydantic import JsonValue -from scripts.generate_provider_endpoints_support import ( +from litellm.scripts.generate_provider_endpoints_support import ( generate_provider_endpoints_support, main, ) @@ -155,7 +155,7 @@ def test_check_reports_stale_output_without_writing(tmp_path: Path, capsys: pyte 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 + assert "litellm/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: diff --git a/tests/integration/README.md b/tests/integration/README.md index 1f9399c8b22..6c96091e77a 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -26,9 +26,9 @@ Reuse the existing canned provider handlers through `_support/upstream.py`. It r Owned proxies disable `.env` loading by default. A contract testing dotenv behavior can explicitly set `PYTHON_DOTENV_DISABLED=0` in its owned environment. The runner drops inherited `*_API_KEY` variables, so a contract that needs one sets a synthetic value in its owned environment. An explicit scratch writer database drops an inherited reader with a different database name; pass both database URLs when the contract needs a paired reader. Database relays close listeners, active connections and their event loops on teardown. Upstream startup failures reap the child process before returning the failure. Custom subprocesses, direct SQL and background tasks still need an explicit owner in the test -Owned proxy workers configure a 32-thread executor before application startup, preserving additional worker startup hooks. Held synchronous provider calls must not consume a CPU-dependent executor limit before the rest of a fault burst can start. The proxy entrypoint imports LiteLLM inside `main`, so spawned workers begin supervision before importing the application. Worker healthchecks have a five-second deadline by default, so uvicorn kills a worker that stays paused longer than that. Tests never signal proxy processes themselves. `OwnedProxy.kill_worker` SIGKILLs a worker and returns once its replacement answers readiness with its own pid, `replacing_worker` does the same for a kill that has to land mid-burst, and `suspended` pauses a worker or the supervisor, which only works on a proxy launched with `healthcheck=WorkerHealthcheck.LENIENT`. The `kill()` that `replacing_worker` yields returns as soon as the worker is dead, so a test can release requests it holds on the surviving worker right away. Uvicorn may take a full worker healthcheck to notice the death, so the block waits for the supervisor to reap the worker and for the replacement only when it exits. Helper processes that are not the proxy stop through `stop_child`, `stop_processes` and `stop_process_group` and pause through `paused`. `scripts/check_test_quality.py` rule TQ010 rejects a raw `os.kill`, SIGKILL / SIGSTOP / SIGCONT, `.kill()`, `.terminate()`, `.suspend()` or `.send_signal()` anywhere under `tests/integration` outside `_support`, and TQ011 rejects an assertion that caps an elapsed time with a fixed number. Bound timings with `_support/timing.py` instead, relative to a measured control or to the injected delay. `run.py` measures how long this box takes to import the proxy application before it starts pytest, records it in `boot-calibration.json` beside the results and exports it as `INTEGRATION_IMPORT_SECONDS`. Readiness deadlines, graceful stops and the default per-test timeout are multiples of that measurement (`_support/budget.py`), so a slower box gets longer budgets and a two-worker proxy gets twice the readiness deadline of a one-worker one. Readiness requires responsive worker identities that are still alive and a positively identified owned listener. Unreadable socket records cannot establish ownership. Crash tests own their client tasks with `TaskGroup`, release held peers in `finally` and verify that the intended worker dies. A test requiring traffic on both workers prepares that traffic explicitly instead of assuming OS load balancing, for example by sending each half while the other worker is suspended +Owned proxy workers configure a 32-thread executor before application startup, preserving additional worker startup hooks. Held synchronous provider calls must not consume a CPU-dependent executor limit before the rest of a fault burst can start. The proxy entrypoint imports LiteLLM inside `main`, so spawned workers begin supervision before importing the application. Worker healthchecks have a five-second deadline by default, so uvicorn kills a worker that stays paused longer than that. Tests never signal proxy processes themselves. `OwnedProxy.kill_worker` SIGKILLs a worker and returns once its replacement answers readiness with its own pid, `replacing_worker` does the same for a kill that has to land mid-burst, and `suspended` pauses a worker or the supervisor, which only works on a proxy launched with `healthcheck=WorkerHealthcheck.LENIENT`. The `kill()` that `replacing_worker` yields returns as soon as the worker is dead, so a test can release requests it holds on the surviving worker right away. Uvicorn may take a full worker healthcheck to notice the death, so the block waits for the supervisor to reap the worker and for the replacement only when it exits. Helper processes that are not the proxy stop through `stop_child`, `stop_processes` and `stop_process_group` and pause through `paused`. `litellm/scripts/check_test_quality.py` rule TQ010 rejects a raw `os.kill`, SIGKILL / SIGSTOP / SIGCONT, `.kill()`, `.terminate()`, `.suspend()` or `.send_signal()` anywhere under `tests/integration` outside `_support`, and TQ011 rejects an assertion that caps an elapsed time with a fixed number. Bound timings with `_support/timing.py` instead, relative to a measured control or to the injected delay. `run.py` measures how long this box takes to import the proxy application before it starts pytest, records it in `boot-calibration.json` beside the results and exports it as `INTEGRATION_IMPORT_SECONDS`. Readiness deadlines, graceful stops and the default per-test timeout are multiples of that measurement (`_support/budget.py`), so a slower box gets longer budgets and a two-worker proxy gets twice the readiness deadline of a one-worker one. Readiness requires responsive worker identities that are still alive and a positively identified owned listener. Unreadable socket records cannot establish ownership. Crash tests own their client tasks with `TaskGroup`, release held peers in `finally` and verify that the intended worker dies. A test requiring traffic on both workers prepares that traffic explicitly instead of assuming OS load balancing, for example by sending each half while the other worker is suspended -Every owned listener's default port comes from `allocate_port()` in `_support/ports.py`. That covers owned proxies, scripted upstreams, fake providers, OTLP sinks, database relays and Redis, including peers such as `wire_server` that bind and keep their own sockets. Keeping those listeners out of the ephemeral range prevents them from taking a port Prisma selected with a bind-and-close probe before its query engine starts. Each pytest process claims a block of 200 ports between 10000 and 32767 by holding an exclusive lock file per block in the system temp directory, so two runs on one machine, such as parallel worktrees, never share a block, and the OS drops the lock when the process exits. The range sits above the fixed service ports and below the Linux and macOS ephemeral ranges, so a port-0 bind or an outbound connection never lands in a block. Ports inside a block go out in order and are never handed out twice in a run, a port that something outside the harness already holds is skipped, and a process that uses up its block claims the next free one. A test that restarts a server on the same port allocates that port up front instead of reading it back from the first server. TQ012 in `scripts/check_test_quality.py` rejects reading a port back from a port-0 bind anywhere under `tests/integration` +Every owned listener's default port comes from `allocate_port()` in `_support/ports.py`. That covers owned proxies, scripted upstreams, fake providers, OTLP sinks, database relays and Redis, including peers such as `wire_server` that bind and keep their own sockets. Keeping those listeners out of the ephemeral range prevents them from taking a port Prisma selected with a bind-and-close probe before its query engine starts. Each pytest process claims a block of 200 ports between 10000 and 32767 by holding an exclusive lock file per block in the system temp directory, so two runs on one machine, such as parallel worktrees, never share a block, and the OS drops the lock when the process exits. The range sits above the fixed service ports and below the Linux and macOS ephemeral ranges, so a port-0 bind or an outbound connection never lands in a block. Ports inside a block go out in order and are never handed out twice in a run, a port that something outside the harness already holds is skipped, and a process that uses up its block claims the next free one. A test that restarts a server on the same port allocates that port up front instead of reading it back from the first server. TQ012 in `litellm/scripts/check_test_quality.py` rejects reading a port back from a port-0 bind anywhere under `tests/integration` The GitHub Actions workflow starts its own database and Redis, restricts test-phase egress to its owned services and writes JUnit plus an executed-node manifest. Missing setup, failed cleanup or a selected test with neither a passed call nor a skip fail qualification. Skipped nodes are listed under `skipped` in `execution.json`, so the skip reasons double as the open bug list. `GITHUB_FILES` in `run.py` lists the files excluded from the `run_integration.sh` selection diff --git a/tests/integration/_support/process.py b/tests/integration/_support/process.py index 6a81d5745b7..09f562586be 100644 --- a/tests/integration/_support/process.py +++ b/tests/integration/_support/process.py @@ -946,6 +946,15 @@ def configless_proxy_process( _stop_launch(launch) +def _gateway_environment( + gateway: Gateway, overrides: Mapping[str, str], source: Mapping[str, str] = os.environ +) -> Mapping[str, str]: + root: Final = _proxy_root() + environment: Final = _proxy_environment(gateway, overrides, (), source) + paths: Final = (str(root / "litellm/runtime"), str(root / "tests"), str(root), environment.get("PYTHONPATH", "")) + return MappingProxyType({**environment, "PYTHONPATH": os.pathsep.join(path for path in paths if path)}) + + @contextmanager def owned_gateway_image( gateway: Gateway, directory: Path, overrides: Mapping[str, str], *, config: Path, workers: int @@ -954,7 +963,7 @@ def owned_gateway_image( `python -m gateway.launch`, with the config handed over as `CONFIG_FILE_PATH`. It serves the data plane only, so keys come from a proxy that shares its database.""" root: Final = _proxy_root() - environment: Final = _proxy_environment(gateway, {**overrides, "CONFIG_FILE_PATH": str(config)}, ()) + environment: Final = _gateway_environment(gateway, {**overrides, "CONFIG_FILE_PATH": str(config)}) output: Final = Path(os.environ.get("INTEGRATION_RESULTS_DIR", str(directory))) output.mkdir(parents=True, exist_ok=True) command: Final = ( diff --git a/tests/integration/database/image/test_image_admin_mcp.py b/tests/integration/database/image/test_image_admin_mcp.py index 1a8b3f3008c..aab22f354e4 100644 --- a/tests/integration/database/image/test_image_admin_mcp.py +++ b/tests/integration/database/image/test_image_admin_mcp.py @@ -28,7 +28,7 @@ from litellm.proxy import proxy_server module_name: Final = { "unified": "litellm.proxy.proxy_server", - "backend": "backend.main", + "backend": "litellm.runtime.backend.main", "gateway": "gateway.main", }[sys.argv[2]] app: Final = importlib.import_module(module_name).app diff --git a/tests/integration/database/migrations/test_db_schema_migration.py b/tests/integration/database/migrations/test_db_schema_migration.py index fa1231e882d..0102678daa5 100644 --- a/tests/integration/database/migrations/test_db_schema_migration.py +++ b/tests/integration/database/migrations/test_db_schema_migration.py @@ -25,7 +25,7 @@ def test_schema_migration_in_sync(): source_migrations_dir = Path( "./litellm/proxy-extras/litellm_proxy_extras/migrations" ) - source_schema_path = Path("./schema.prisma") + source_schema_path = Path("./litellm/schema.prisma") temp_base = Path(tempfile.mkdtemp(prefix="litellm_schema_migration_")) schema_path = temp_base / "schema.prisma" @@ -37,7 +37,7 @@ def test_schema_migration_in_sync(): if not any(migrations_dir.iterdir()): pytest.fail( - "No existing migrations found. Run `python scripts/ci_cd/baseline_db.py`." + "No existing migrations found. Restore the committed SQL migration history before retrying." ) subprocess.run( @@ -67,7 +67,7 @@ def test_schema_migration_in_sync(): if drift.strip(): pytest.fail( "Schema changes detected that no migration captures. Run " - "`python scripts/ci_cd/run_migration.py `.\n\n" + "`python litellm/scripts/ci_cd/run_migration.py `.\n\n" + drift ) else: diff --git a/tests/integration/database/migrations/test_request_log_indexes.py b/tests/integration/database/migrations/test_request_log_indexes.py index fc28f8fd2f3..bb85eeb6605 100644 --- a/tests/integration/database/migrations/test_request_log_indexes.py +++ b/tests/integration/database/migrations/test_request_log_indexes.py @@ -40,7 +40,7 @@ requires_db: Final = pytest.mark.skipif( REPO: Final = Path(__file__).resolve().parents[4] PACKAGE: Final = REPO / "litellm-proxy-extras" / "litellm_proxy_extras" -PARTITION_SCRIPT: Final = REPO / "scripts" / "db" / "partition_spend_logs.sql" +PARTITION_SCRIPT: Final = REPO / "litellm/scripts" / "db" / "partition_spend_logs.sql" API_KEY_INDEX_MIGRATION: Final = "20260823000000_add_spend_logs_api_key_starttime_index" CALL_ID_INDEX_MIGRATION: Final = "20260831120001_spend_logs_litellm_call_id_index" API_KEY_INDEX: Final = "LiteLLM_SpendLogs_api_key_startTime_idx" diff --git a/tests/integration/database/test_request_log_indexes_at_boot.py b/tests/integration/database/test_request_log_indexes_at_boot.py index 86323c49d47..3337393a52a 100644 --- a/tests/integration/database/test_request_log_indexes_at_boot.py +++ b/tests/integration/database/test_request_log_indexes_at_boot.py @@ -21,7 +21,7 @@ pytestmark: Final = pytest.mark.timeout(240) REPO_ROOT: Final = Path(__file__).resolve().parents[3] PRISMA_DIR: Final = REPO_ROOT / "litellm-proxy-extras" / "litellm_proxy_extras" -PARTITION_SCRIPT: Final = REPO_ROOT / "scripts" / "db" / "partition_spend_logs.sql" +PARTITION_SCRIPT: Final = REPO_ROOT / "litellm/scripts" / "db" / "partition_spend_logs.sql" SHIPPED_MIGRATIONS: Final = tuple(sorted(path.name for path in (PRISMA_DIR / "migrations").iterdir() if path.is_dir())) API_KEY_INDEX_MIGRATION: Final = "20260823000000_add_spend_logs_api_key_starttime_index" CALL_ID_INDEX_MIGRATION: Final = "20260831120001_spend_logs_litellm_call_id_index" @@ -96,7 +96,7 @@ def migrate_deploy(database_url: str, schema: Path) -> subprocess.CompletedProce def migration_job(database_url: str, resolver: Resolver) -> subprocess.CompletedProcess[str]: """The migrations image entrypoint, as the helm migration Job runs it.""" return subprocess.run( - [sys.executable, "-I", str(REPO_ROOT / "migrations" / "run.py")], + [sys.executable, "-I", str(REPO_ROOT / "litellm/runtime/migrations" / "run.py")], capture_output=True, text=True, timeout=MIGRATION_JOB_SECONDS, diff --git a/tests/integration/database/test_spend_lock_order.py b/tests/integration/database/test_spend_lock_order.py index a7e00b7fa87..26e7473133e 100644 --- a/tests/integration/database/test_spend_lock_order.py +++ b/tests/integration/database/test_spend_lock_order.py @@ -54,7 +54,7 @@ _SEED: Final = ( def schema_sql() -> str: return subprocess.run( [sys.executable, "-I", "-m", "prisma", "migrate", "diff", "--from-empty", "--to-schema-datamodel", - str(_ROOT / "schema.prisma"), "--script"], + str(_ROOT / "litellm/schema.prisma"), "--script"], check=True, capture_output=True, text=True, diff --git a/tests/integration/database/test_spendlogs_ledger_parity.py b/tests/integration/database/test_spendlogs_ledger_parity.py index 3019d75a2a7..1a3fb41ba9c 100644 --- a/tests/integration/database/test_spendlogs_ledger_parity.py +++ b/tests/integration/database/test_spendlogs_ledger_parity.py @@ -257,7 +257,7 @@ def ledger_schema() -> str: "diff", "--from-empty", "--to-schema-datamodel", - str(_ROOT / "schema.prisma"), + str(_ROOT / "litellm/schema.prisma"), "--script", ], check=True, diff --git a/tests/unit/db_scripts/test_strip_vector_store_internal_metadata.py b/tests/unit/db_scripts/test_strip_vector_store_internal_metadata.py index 1adca1ffbeb..c653b5eb736 100644 --- a/tests/unit/db_scripts/test_strip_vector_store_internal_metadata.py +++ b/tests/unit/db_scripts/test_strip_vector_store_internal_metadata.py @@ -8,7 +8,7 @@ from typing import Final import httpx import pytest -_SCRIPT: Final = Path(__file__).resolve().parents[3] / "scripts" / "db" / "strip_vector_store_internal_metadata.py" +_SCRIPT: Final = Path(__file__).resolve().parents[3] / "litellm/scripts" / "db" / "strip_vector_store_internal_metadata.py" _spec: Final = importlib.util.spec_from_file_location("strip_vector_store_internal_metadata", _SCRIPT) strip_script: Final = importlib.util.module_from_spec(_spec) sys.modules[_spec.name] = strip_script diff --git a/tests/unit/gateway/test_launch.py b/tests/unit/gateway/test_launch.py index 95b3a94c3bc..eba1ad685c2 100644 --- a/tests/unit/gateway/test_launch.py +++ b/tests/unit/gateway/test_launch.py @@ -44,8 +44,10 @@ def test_a_uvicorn_worker_reimports_the_launcher_without_loading_litellm(): sys.executable, "-I", "-c", - 'import runpy, sys; runpy.run_module("gateway.launch", run_name="__mp_main__", alter_sys=True); ' + 'import runpy, sys; sys.path.insert(0, sys.argv[1]); ' + 'runpy.run_module("gateway.launch", run_name="__mp_main__", alter_sys=True); ' 'print("litellm" in sys.modules)', + str(Path(__file__).resolve().parents[3] / "litellm" / "runtime"), ], capture_output=True, text=True, diff --git a/tests/unit/integration_support/test_process.py b/tests/unit/integration_support/test_process.py index ea9c9fcc854..e5e9cd7f889 100644 --- a/tests/unit/integration_support/test_process.py +++ b/tests/unit/integration_support/test_process.py @@ -11,6 +11,7 @@ import time from collections.abc import Iterator, Mapping from contextlib import contextmanager from functools import reduce +from importlib.machinery import PathFinder from pathlib import Path from types import MappingProxyType, ModuleType from typing import Final @@ -47,6 +48,33 @@ from tests.integration._support.process import ( TESTS_DIR: Final = Path(__file__).resolve().parents[2] +@pytest.mark.parametrize( + ("inherited", "explicit", "remaining"), + ( + (None, None, ()), + ("inherited", None, ("inherited",)), + ("inherited", "explicit", ("explicit",)), + ("inherited", "", ()), + ), +) +def test_gateway_children_find_moved_launcher_and_keep_the_effective_pythonpath( + process_module: ModuleType, inherited: str | None, explicit: str | None, remaining: tuple[str, ...] +) -> None: + with httpx.Client(base_url="http://127.0.0.1:1", trust_env=False) as client: + environment: Final = process_module._gateway_environment( + Gateway(client, "owned-test-key", "http://127.0.0.1:1"), + {} if explicit is None else {"PYTHONPATH": explicit}, + {} if inherited is None else {"PYTHONPATH": inherited}, + ) + root: Final = TESTS_DIR.parent + paths: Final = tuple(environment["PYTHONPATH"].split(os.pathsep)) + assert paths == (str(root / "litellm/runtime"), str(TESTS_DIR), str(root), *remaining) + package: Final = PathFinder.find_spec("gateway", paths) + assert package is not None + launcher: Final = PathFinder.find_spec("gateway.launch", package.submodule_search_locations) + assert launcher is not None and launcher.origin == str(root / "litellm/runtime/gateway/launch.py") + + @pytest.mark.parametrize("config_contents", ("[]\n", "general_settings: []\n", "general_settings: {}\n")) def test_worker_configuration_preserves_sibling_auth_modules( monkeypatch: pytest.MonkeyPatch, diff --git a/tests/unit/litellm_proxy_extras/test_litellm_proxy_extras_utils.py b/tests/unit/litellm_proxy_extras/test_litellm_proxy_extras_utils.py index e224692b327..186a38c4327 100644 --- a/tests/unit/litellm_proxy_extras/test_litellm_proxy_extras_utils.py +++ b/tests/unit/litellm_proxy_extras/test_litellm_proxy_extras_utils.py @@ -621,7 +621,7 @@ DROP TABLE "LiteLLM_SpendLogs_legacy"; class TestPartitionedSpendLogsDriftFilter: - """A doc-partitioned LiteLLM_SpendLogs (scripts/db/partition_spend_logs.sql) has a + """A doc-partitioned LiteLLM_SpendLogs (litellm/scripts/db/partition_spend_logs.sql) has a composite primary key that schema.prisma cannot express, so `prisma migrate diff` emits a primary-key rewrite that Postgres rejects, aborting the whole drift script before its legitimate statements run.""" diff --git a/tests/unit/proxy/db/test_prisma_query_span.py b/tests/unit/proxy/db/test_prisma_query_span.py index 55ba03d9f2c..8039c40bd80 100644 --- a/tests/unit/proxy/db/test_prisma_query_span.py +++ b/tests/unit/proxy/db/test_prisma_query_span.py @@ -468,7 +468,7 @@ def test_every_prisma_call_site_in_the_proxy_renders_a_bounded_postgres_span_nam def test_every_model_in_the_prisma_schema_is_a_renderable_span_table() -> None: - schema: Final = (_REPO / "schema.prisma").read_text() + schema: Final = (_REPO / "litellm/schema.prisma").read_text() declared: Final = frozenset(re.findall(r"^model (\w+) \{", schema, re.MULTILINE)) assert declared == spans_mod._PRISMA_MODELS diff --git a/tests/unit/proxy/test_claude_code_marketplace.py b/tests/unit/proxy/test_claude_code_marketplace.py index 7e8417fa3cc..43c0fd110fe 100644 --- a/tests/unit/proxy/test_claude_code_marketplace.py +++ b/tests/unit/proxy/test_claude_code_marketplace.py @@ -4,7 +4,7 @@ import pytest @pytest.mark.asyncio async def test_claude_code_plugin_table_schema_exists(): - with open("schema.prisma", "r") as f: + with open("litellm/schema.prisma", "r") as f: schema = f.read() assert "LiteLLM_ClaudeCodePluginTable" in schema, ( "LiteLLM_ClaudeCodePluginTable model missing from schema.prisma - " diff --git a/tests/unit/proxy/test_component_allowlists.py b/tests/unit/proxy/test_component_allowlists.py index 738fe9d53df..8bd8cc8d772 100644 --- a/tests/unit/proxy/test_component_allowlists.py +++ b/tests/unit/proxy/test_component_allowlists.py @@ -4,7 +4,7 @@ The componentization scaffold splits the proxy FastAPI app into two runtime components by trimming the route table inside a wrapped lifespan context: gateway.main -> only paths matched by gateway/routes/allowlist.py - backend.main -> only paths matched by backend/routes/allowlist.py + litellm.runtime.backend.main -> only paths matched by litellm/runtime/backend/routes/allowlist.py If either allowlist drops a path that was reachable on the monolithic app, clients hitting that path on the corresponding pod get a 404. This test @@ -12,7 +12,7 @@ guarantees that the union of the two trimmed route sets equals the full set of routes on the proxy app — i.e. no endpoint is dropped on the floor. The union-coverage test reproduces the same predicate that ``gateway/main.py`` -and ``backend/main.py`` use, without importing them. The component modules wrap +and ``litellm/runtime/backend/main.py`` use, without importing them. The component modules wrap the shared ``app.router.lifespan_context``; importing them in the test process would chain wrappers and corrupt the snapshot. The gateway Mount tests below import the real ``gateway.main._is_gateway_route`` instead, undoing both of the @@ -64,7 +64,7 @@ _REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", if _REPO_ROOT not in sys.path: sys.path.insert(0, _REPO_ROOT) -from backend.routes.allowlist import BACKEND_MOUNT_PATHS +from litellm.runtime.backend.routes.allowlist import BACKEND_MOUNT_PATHS from gateway.routes.allowlist import GATEWAY_MOUNT_PATHS from litellm.proxy import tracing_endpoints from litellm.proxy._lazy_features import LazyFeature, attach_lazy_features @@ -95,7 +95,7 @@ _PRE_COMPONENT_LIFESPAN = app.router.lifespan_context from gateway.main import _gateway_lifespan, _is_gateway_route app.router.lifespan_context = _PRE_COMPONENT_LIFESPAN -from backend.main import _backend_lifespan +from litellm.runtime.backend.main import _backend_lifespan app.router.lifespan_context = _PRE_COMPONENT_LIFESPAN for _key, _previous in _PRE_DB_ENV.items(): @@ -106,8 +106,9 @@ for _key, _previous in _PRE_DB_ENV.items(): _COVERAGE_PROBE: Final = """ import json, os, sys sys.path.insert(0, os.environ["LITELLM_COMPONENT_ALLOWLIST_REPO_ROOT"]) +sys.path.insert(0, os.path.join(os.environ["LITELLM_COMPONENT_ALLOWLIST_REPO_ROOT"], "litellm", "runtime")) from starlette.routing import Mount -from backend.routes.allowlist import BACKEND_EXACT_PATHS, BACKEND_PATH_PREFIXES +from litellm.runtime.backend.routes.allowlist import BACKEND_EXACT_PATHS, BACKEND_PATH_PREFIXES from gateway.routes.allowlist import GATEWAY_EXACT_PATHS, GATEWAY_PATH_PREFIXES from litellm.proxy._lazy_features import loaded_lazy_modules from litellm.proxy.proxy_server import app @@ -258,7 +259,7 @@ def test_retired_otlp_routes_reject_uploads_without_dependencies_on_each_compone def test_gateway_plus_backend_covers_full_app(): """Every route on the proxy app must be served by gateway or backend. - ``gateway.main`` and ``backend.main`` trim the route table once, inside the + ``gateway.main`` and ``litellm.runtime.backend.main`` trim the route table once, inside the lifespan, so the set this has to cover is the one registered at startup. A lazy feature appends its router on demand, after that trim, and whether a sibling test in the same xdist worker has triggered one is not something @@ -286,7 +287,7 @@ def test_gateway_plus_backend_covers_full_app(): uncovered: Final = report["uncovered"] assert not uncovered, ( f"{len(uncovered)} route(s) are not exposed on either component. " - f"Update gateway/routes/allowlist.py or backend/routes/allowlist.py to cover:\n " + f"Update litellm/runtime/gateway/routes/allowlist.py or litellm/runtime/backend/routes/allowlist.py to cover:\n " + "\n ".join(uncovered) ) diff --git a/tests/unit/proxy/test_db_schema_changes.py b/tests/unit/proxy/test_db_schema_changes.py index f43e2d2a8ce..c2e72c86329 100644 --- a/tests/unit/proxy/test_db_schema_changes.py +++ b/tests/unit/proxy/test_db_schema_changes.py @@ -2,7 +2,7 @@ from typing import Final import pytest -from scripts.check_schema_compatibility import check_breaking_changes, parse_model_fields +from litellm.scripts.check_schema_compatibility import check_breaking_changes, parse_model_fields ORIGINAL: Final = "model Item {\n id String @id\n label String?\n}\n" diff --git a/tests/unit/rust_bridge/test_verify_linux_native_wheel.py b/tests/unit/rust_bridge/test_verify_linux_native_wheel.py index a609549cf25..232cb0a069d 100644 --- a/tests/unit/rust_bridge/test_verify_linux_native_wheel.py +++ b/tests/unit/rust_bridge/test_verify_linux_native_wheel.py @@ -144,6 +144,10 @@ def test_accepts_expected_release_wheel_tags(tmp_path: Path) -> None: "litellm/proxy-extras/litellm_proxy_extras/__init__.py", "litellm/rust/crates/config/src/lib.rs", "litellm/packaging/litellm-core/pyproject.toml", + "litellm/scripts/default_branch.py", + "litellm/runtime/backend/main.py", + "litellm/runtime/gateway/launch.py", + "litellm/schema.prisma", ), ) def test_rejects_repository_sources_in_the_wheel( diff --git a/tests/unit/test_check_mcp_operation_boundary.py b/tests/unit/test_check_mcp_operation_boundary.py index 0969c461ad2..4c5b56e0cc7 100644 --- a/tests/unit/test_check_mcp_operation_boundary.py +++ b/tests/unit/test_check_mcp_operation_boundary.py @@ -2,7 +2,7 @@ from pathlib import Path import pytest -from scripts.check_mcp_operation_boundary import main, violations +from litellm.scripts.check_mcp_operation_boundary import main, violations @pytest.mark.parametrize( @@ -36,7 +36,7 @@ def test_boundary_command_rejects_shared_state_and_accepts_explicit_context(tmp_ 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") - command = [sys.executable, str(Path(__file__).resolve().parents[2] / "scripts/check_mcp_operation_boundary.py")] + command = [sys.executable, str(Path(__file__).resolve().parents[2] / "litellm/scripts/check_mcp_operation_boundary.py")] monkeypatch.chdir(tmp_path) assert main() == 1 assert "operations.py:1:" in capsys.readouterr().err diff --git a/tests/unit/test_check_openapi_docs.py b/tests/unit/test_check_openapi_docs.py index c6ea0cd936e..a277eeb6932 100644 --- a/tests/unit/test_check_openapi_docs.py +++ b/tests/unit/test_check_openapi_docs.py @@ -1,4 +1,4 @@ -"""Tests for scripts/check_openapi_docs.py, the scan behind scripts/openapi_docs_gate.py.""" +"""Tests for litellm/scripts/check_openapi_docs.py, the scan behind litellm/scripts/openapi_docs_gate.py.""" from collections.abc import Mapping from typing import Final diff --git a/tests/unit/test_check_test_quality.py b/tests/unit/test_check_test_quality.py index 9d6b5cb4d88..2a6faca0b3f 100644 --- a/tests/unit/test_check_test_quality.py +++ b/tests/unit/test_check_test_quality.py @@ -1,4 +1,4 @@ -"""Tests for scripts/check_test_quality.py. +"""Tests for litellm/scripts/check_test_quality.py. Every rule is exercised on a snippet that violates it and on one that does not, so dropping a rule, widening it, or inverting the suppression check makes a test fail. @@ -18,7 +18,7 @@ from typing import Final import pytest _REPO_ROOT = Path(__file__).resolve().parents[2] -_MODULE_PATH = _REPO_ROOT / "scripts" / "check_test_quality.py" +_MODULE_PATH = _REPO_ROOT / "litellm/scripts" / "check_test_quality.py" _spec = importlib.util.spec_from_file_location("check_test_quality", _MODULE_PATH) checker = importlib.util.module_from_spec(_spec) # @dataclass(slots=True) rebuilds its class through sys.modules[__module__], so the diff --git a/tests/unit/test_check_type_discipline.py b/tests/unit/test_check_type_discipline.py index f5b5b723d05..f67a51d476c 100644 --- a/tests/unit/test_check_type_discipline.py +++ b/tests/unit/test_check_type_discipline.py @@ -1,4 +1,4 @@ -"""Tests for scripts/check_type_discipline.py. +"""Tests for litellm/scripts/check_type_discipline.py. Each rule is exercised on a snippet that violates it and on one that does not, so a mutation that drops a rule, inverts a suppression, or breaks the comment scanner makes @@ -16,7 +16,7 @@ from typing import Final import pytest _REPO_ROOT = Path(__file__).resolve().parents[2] -_MODULE_PATH = _REPO_ROOT / "scripts" / "check_type_discipline.py" +_MODULE_PATH = _REPO_ROOT / "litellm/scripts" / "check_type_discipline.py" _spec = importlib.util.spec_from_file_location("check_type_discipline", _MODULE_PATH) checker = importlib.util.module_from_spec(_spec) sys.modules[_spec.name] = checker # let the frozen dataclass resolve its own module diff --git a/tests/unit/test_ci_path_filter.py b/tests/unit/test_ci_path_filter.py index 442357617d7..bd90c40524d 100644 --- a/tests/unit/test_ci_path_filter.py +++ b/tests/unit/test_ci_path_filter.py @@ -54,14 +54,14 @@ CI = [".github/workflows/test-unit.yml"] ("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"), + ("mcp-dependencies", ["litellm/scripts/check_mcp_sdk_install.py"], "run"), ("mcp-dependencies", [".github/workflows/test-mcp-dependency-resolution.yml"], "run"), ("mcp-dependencies", [".github/scripts/ci/classify_changes.sh"], "run"), ("mcp-dependencies", ["litellm/llms/openai/chat/gpt_transformation.py"], "skip"), ("mcp-dependencies", DOCS + CLIENT, "skip"), ("windows-release", ["litellm/rust/crates/inference/src/lib.rs"], "run"), ("windows-release", ["litellm/rust_bridge/dispatch.py"], "run"), - ("windows-release", ["rust-toolchain.toml"], "run"), + ("windows-release", ["litellm/rust/rust-toolchain.toml"], "run"), ("windows-release", ["pyproject.toml"], "run"), ("windows-release", ["uv.lock"], "run"), ("windows-release", ["tests/windows_tests/check_windows_wheel_install.py"], "run"), diff --git a/tests/unit/test_cost_map_guard.py b/tests/unit/test_cost_map_guard.py index 0dff94a75d6..c971baab9c9 100644 --- a/tests/unit/test_cost_map_guard.py +++ b/tests/unit/test_cost_map_guard.py @@ -11,7 +11,7 @@ from typing import Final import pytest ROOT: Final = Path(__file__).resolve().parents[2] -CI_CD: Final = ROOT / "scripts" / "ci_cd" +CI_CD: Final = ROOT / "litellm/scripts" / "ci_cd" def _load(name: str) -> ModuleType: @@ -384,12 +384,31 @@ def test_relocated_pins_cannot_be_changed_by_bots(pins_path: str) -> None: assert guard.pin_author_failures("litellm_fix_pricing", "Bot", (pins_path,)) == (BOT_AUTHOR_PIN_FAILURE,) +@pytest.mark.parametrize("cost_map_path", guard.COST_MAP_PATHS) +@pytest.mark.parametrize("content", (_serialize(BASE_MAP) + "\n", "", "not json")) +def test_main_reads_cost_maps_in_both_repository_layouts( + tmp_path: Path, cost_map_path: str, content: str +) -> None: + subprocess.run(("git", "init", "-q", str(tmp_path)), check=True) + base: Final = _commit(tmp_path, BASE_MAP, "base") + destination: Final = tmp_path / cost_map_path + destination.parent.mkdir(parents=True, exist_ok=True) + if destination != tmp_path / guard.COST_MAP_PATH: + (tmp_path / guard.COST_MAP_PATH).rename(destination) + destination.write_text(content) + (tmp_path / guard.BACKUP_PATH).write_text(content) + head: Final = _git_commit(tmp_path, "update cost map layout") + result: Final = _run_guard(tmp_path, base, head, "litellm_fix_pricing") + assert result.returncode == (0 if content.strip().startswith("{") else 1), result.stdout + result.stderr + + def _commit(repo: Path, cost_map: dict[str, object], message: str, pins: str | None = None) -> str: text = _serialize(cost_map) pins_file = repo / guard.PINS_PATH if pins is not None or not pins_file.exists(): - pins_file.parent.mkdir(exist_ok=True) + pins_file.parent.mkdir(parents=True, exist_ok=True) pins_file.write_text(NO_PINS if pins is None else pins) + (repo / guard.COST_MAP_PATH).parent.mkdir(parents=True, exist_ok=True) (repo / guard.COST_MAP_PATH).write_text(text) (repo / guard.BACKUP_PATH).parent.mkdir(exist_ok=True) (repo / guard.BACKUP_PATH).write_text(text) diff --git a/tests/unit/test_default_branch.py b/tests/unit/test_default_branch.py index 3ed842b3b8e..2f6b8353157 100644 --- a/tests/unit/test_default_branch.py +++ b/tests/unit/test_default_branch.py @@ -25,7 +25,7 @@ def remote_and_clone(tmp_path: Path) -> tuple[Path, Path]: seed: Final = tmp_path / "seed" seed.mkdir() _git(seed, "init", "-q", "-b", "release_branch") - (seed / "scripts").mkdir() + (seed / "litellm/scripts").mkdir(parents=True) for name in ( "default_branch.py", "lint_base_counts.py", @@ -35,9 +35,9 @@ def remote_and_clone(tmp_path: Path) -> tuple[Path, Path]: "type_check_gate.py", "gate_slot_lock.py", ): - shutil.copyfile(ROOT / "scripts" / name, seed / "scripts" / name) + shutil.copyfile(ROOT / "litellm/scripts" / name, seed / "litellm/scripts" / name) shutil.copyfile(ROOT / "Makefile", seed / "Makefile") - (seed / "litellm").mkdir() + (seed / "litellm").mkdir(exist_ok=True) (seed / "litellm" / "example.py").write_text("value = 0\n") _commit(seed, "staging base") _git(seed, "checkout", "-qb", "main") @@ -53,7 +53,7 @@ def remote_and_clone(tmp_path: Path) -> tuple[Path, Path]: def _resolve(repo: Path, *args: str) -> subprocess.CompletedProcess[str]: return subprocess.run( - [sys.executable, str(ROOT / "scripts" / "default_branch.py"), *args], + [sys.executable, str(ROOT / "litellm/scripts" / "default_branch.py"), *args], cwd=repo, capture_output=True, text=True, @@ -136,7 +136,7 @@ def _freshness(repo: Path, *args: str) -> subprocess.CompletedProcess[str]: sys.executable, "-c", "import sys; from pathlib import Path; " - "from scripts.ci_cd.run_migration import _check_branch_freshness; " + "from litellm.scripts.ci_cd.run_migration import _check_branch_freshness; " "_check_branch_freshness(Path(sys.argv[1]), sys.argv[2] if len(sys.argv) > 2 else None)", str(repo), *args, @@ -189,7 +189,7 @@ def test_each_gate_refuses_an_unverifiable_default(remote_and_clone: tuple[Path, remote, repo = remote_and_clone _git(repo, "remote", "set-url", "origin", str(remote / "missing")) result: Final = subprocess.run( - [sys.executable, f"scripts/{gate}.py"], + [sys.executable, f"litellm/scripts/{gate}.py"], cwd=repo, capture_output=True, text=True, @@ -203,7 +203,7 @@ def test_each_gate_refuses_an_unverifiable_default(remote_and_clone: tuple[Path, def test_direct_make_target_fetches_default_once(remote_and_clone: tuple[Path, Path], target: str) -> None: _, repo = remote_and_clone trace: Final = repo.parent / "git-trace.jsonl" - shutil.copyfile(ROOT / "scripts" / "check_test_quality.py", repo / "scripts" / "check_test_quality.py") + shutil.copyfile(ROOT / "litellm/scripts" / "check_test_quality.py", repo / "litellm/scripts" / "check_test_quality.py") (repo / "tests").mkdir() result: Final = subprocess.run( ["make", "-o", "install-dev", target, "LINT_DEP_INSTALL=", "UV_RUN=env"], diff --git a/tests/unit/test_docker_entrypoint.py b/tests/unit/test_docker_entrypoint.py index e9e4e492bfe..fa3568d926e 100644 --- a/tests/unit/test_docker_entrypoint.py +++ b/tests/unit/test_docker_entrypoint.py @@ -168,10 +168,10 @@ def _entrypoint_argv(dockerfile: Path) -> tuple[str, ...]: "exec=python", "args=-m gateway.launch --workers 1 --host 0.0.0.0 --port 4000 --port 8080", ), - (("backend",), "exec=uvicorn", "args=backend.main:app --host 0.0.0.0 --port 4001"), - (("backend", "--port", "9001"), "exec=uvicorn", "args=backend.main:app --host 0.0.0.0 --port 4001 --port 9001"), + (("backend",), "exec=uvicorn", "args=litellm.runtime.backend.main:app --host 0.0.0.0 --port 4001"), + (("backend", "--port", "9001"), "exec=uvicorn", "args=litellm.runtime.backend.main:app --host 0.0.0.0 --port 4001 --port 9001"), (("ui",), "exec=nginx", "args=-g daemon off;"), - (("migrations",), "exec=python", "args=/app/migrations/run.py"), + (("migrations",), "exec=python", "args=-m litellm.runtime.migrations.run"), (("metrics", "--port", "9090"), "exec=python", "args=-m litellm.proxy.prometheus_metrics_server --port 9090"), (("collector",), "exec=python", "args=-m litellm.proxy.collector"), ], @@ -212,7 +212,7 @@ def test_the_dockerfile_leaves_the_command_empty_so_the_env_var_can_pick_the_com @pytest.mark.parametrize( "component, argv, expected_exec, expected_args", [ - ("backend", (), "exec=uvicorn", "args=backend.main:app --host 0.0.0.0 --port 4001"), + ("backend", (), "exec=uvicorn", "args=litellm.runtime.backend.main:app --host 0.0.0.0 --port 4001"), ( "gateway", ("--port", "4100"), @@ -324,7 +324,7 @@ def test_ddtrace_disabled_execs_the_command_directly(tmp_path: Path) -> None: assert recorded == ( "exec=uvicorn", - "args=backend.main:app --host 0.0.0.0 --port 4001 --workers 2", + "args=litellm.runtime.backend.main:app --host 0.0.0.0 --port 4001 --workers 2", "DD_TRACE_OPENAI_ENABLED=", f"PYTHONPATH={PYTHONPATH_SENTINEL}", ) @@ -402,7 +402,7 @@ def test_a_raw_metrics_reader_keeps_the_workers_samples(argv: tuple[str, ...], t [ ("python", "-m", "gateway.launch"), ("litellm", "--config", "/app/config.yaml"), - ("uvicorn", "backend.main:app"), + ("uvicorn", "litellm.runtime.backend.main:app"), ], ) def test_a_raw_writer_starts_with_an_empty_prometheus_multiproc_dir(argv: tuple[str, ...], tmp_path: Path) -> None: diff --git a/tests/unit/test_gate_slot_lock.py b/tests/unit/test_gate_slot_lock.py index c80e876700b..8a7252ce2f9 100644 --- a/tests/unit/test_gate_slot_lock.py +++ b/tests/unit/test_gate_slot_lock.py @@ -14,7 +14,7 @@ from pathlib import Path import pytest ROOT = Path(__file__).resolve().parents[2] -HELPER = ROOT / "scripts" / "gate_slot_lock.py" +HELPER = ROOT / "litellm/scripts" / "gate_slot_lock.py" _spec = importlib.util.spec_from_file_location("gate_slot_lock", HELPER) assert _spec is not None and _spec.loader is not None diff --git a/tests/unit/test_git_hooks.py b/tests/unit/test_git_hooks.py index c143f7f353e..bfc2856e029 100644 --- a/tests/unit/test_git_hooks.py +++ b/tests/unit/test_git_hooks.py @@ -1,4 +1,4 @@ -"""Tests for the repo's git hook scripts in ``scripts/githooks/``. +"""Tests for the repo's git hook scripts in ``litellm/scripts/githooks/``. The commit-msg hook enforces Conventional Commits. It is exercised as a subprocess against representative valid / invalid inputs so that any future @@ -16,7 +16,7 @@ from pathlib import Path import pytest _REPO_ROOT = Path(__file__).resolve().parents[2] -_HOOKS_DIR = _REPO_ROOT / "scripts/githooks" +_HOOKS_DIR = _REPO_ROOT / "litellm/scripts/githooks" _COMMIT_MSG_HOOK = _HOOKS_DIR / "commit-msg" pytestmark = pytest.mark.skipif( diff --git a/tests/unit/test_lint_base_counts.py b/tests/unit/test_lint_base_counts.py index 84f8a0936c0..8312159b6f3 100644 --- a/tests/unit/test_lint_base_counts.py +++ b/tests/unit/test_lint_base_counts.py @@ -1,4 +1,4 @@ -"""Tests for scripts/lint_base_counts.py, the merge-base counting shared by the +"""Tests for litellm/scripts/lint_base_counts.py, the merge-base counting shared by the four lint gates: the ceiling rule with its optional per-rule caps, the on-disk cache and its eviction, the CI artifact fetch, the artifact emit, and the merge-base resolution.""" diff --git a/tests/unit/test_lint_workflow_diff_gates.py b/tests/unit/test_lint_workflow_diff_gates.py index 40aa4afbfa0..058800244e6 100644 --- a/tests/unit/test_lint_workflow_diff_gates.py +++ b/tests/unit/test_lint_workflow_diff_gates.py @@ -517,7 +517,7 @@ UI_API_TYPES_DETECT: Final[str] = next( for step in yaml.safe_load(WORKFLOW.read_text())["jobs"]["ui-api-types"]["steps"] if step.get("id") == "changes" ) -PRE_COMMIT_LINT: Final = WORKFLOW.parents[2] / "scripts" / "pre_commit_lint.sh" +PRE_COMMIT_LINT: Final = WORKFLOW.parents[2] / "litellm/scripts" / "pre_commit_lint.sh" TERRAFORM_PROVIDER_WORKFLOW: Final = WORKFLOW.with_name("test-terraform-provider.yml") diff --git a/tests/unit/test_mutation_report.py b/tests/unit/test_mutation_report.py index 60b29ef2628..c4bb88cf91f 100644 --- a/tests/unit/test_mutation_report.py +++ b/tests/unit/test_mutation_report.py @@ -1,4 +1,4 @@ -"""Tests for scripts/mutation_report.py. +"""Tests for litellm/scripts/mutation_report.py. The report is the only thing anyone reads after a mutation run, so the one thing it must never do is describe a run that produced nothing as a run that killed everything. @@ -11,7 +11,7 @@ import sys from pathlib import Path _REPO_ROOT = Path(__file__).resolve().parents[2] -_MODULE_PATH = _REPO_ROOT / "scripts" / "mutation_report.py" +_MODULE_PATH = _REPO_ROOT / "litellm/scripts" / "mutation_report.py" _spec = importlib.util.spec_from_file_location("mutation_report", _MODULE_PATH) report = importlib.util.module_from_spec(_spec) sys.modules[_spec.name] = report diff --git a/tests/unit/test_openapi_docs_gate.py b/tests/unit/test_openapi_docs_gate.py index b376178c8a9..2e48cf0970f 100644 --- a/tests/unit/test_openapi_docs_gate.py +++ b/tests/unit/test_openapi_docs_gate.py @@ -1,6 +1,6 @@ -"""Tests for scripts/openapi_docs_gate.py. +"""Tests for litellm/scripts/openapi_docs_gate.py. -The blame rule lives in scripts/lint_base_counts.py and is tested there; what is tested +The blame rule lives in litellm/scripts/lint_base_counts.py and is tested there; what is tested here is the checker output parse and `introduced`, the diff scan that names the new endpoint behind a breach. """ diff --git a/tests/unit/test_pre_commit_lint.py b/tests/unit/test_pre_commit_lint.py index bb83f6adade..a9b9020a6dc 100644 --- a/tests/unit/test_pre_commit_lint.py +++ b/tests/unit/test_pre_commit_lint.py @@ -12,7 +12,7 @@ import pytest from tests._process_helpers import process_is_gone ROOT = Path(__file__).resolve().parents[2] -SCRIPT = ROOT / "scripts" / "pre_commit_lint.sh" +SCRIPT = ROOT / "litellm/scripts" / "pre_commit_lint.sh" WHOLE_TREE_RUFF = "run --no-sync ruff check --config .github/linters/ruff-tests.toml tests" TEST_TREE_RAN = "ran: test-tree lint (.github/linters/ruff-tests.toml + test-quality gate)" TEST_TREE_SKIPPED = ( @@ -468,11 +468,11 @@ def test_frontend_python_helpers_do_not_trigger_sdk_checks(tmp_path: Path) -> No def test_staged_files_matching_no_check_print_an_explicit_noop_note_and_nonempty_log(tmp_path: Path) -> None: repo, bin_dir = _sandbox(tmp_path) _commit_all(repo, "base") - _stage_file(repo, "scripts/tool.py", "def main() -> None: ...\n") + _stage_file(repo, "litellm/scripts/tool.py", "def main() -> None: ...\n") proc = _run(repo, bin_dir, {}) assert proc.returncode == 0, proc.stdout + proc.stderr assert "no gating lint check matches the files in scope, so nothing ran" in proc.stdout - assert "scripts/tool.py" in proc.stdout + assert "litellm/scripts/tool.py" in proc.stdout assert "a no-op, not a lint verdict" in proc.stdout assert "check: PASS" in proc.stdout assert "linting Python" not in proc.stdout @@ -508,8 +508,8 @@ def test_tests_only_change_runs_the_whole_test_tree_ruff_and_the_quality_gate(tm "changed", [ ".github/linters/ruff-tests.toml", - "scripts/check_test_quality.py", - "scripts/test_quality_gate.py", + "litellm/scripts/check_test_quality.py", + "litellm/scripts/test_quality_gate.py", "tests/e2e/test_x.py", ], ) @@ -631,11 +631,11 @@ def test_run_under_a_held_slot_skips_reacquiring_the_gate_lock(tmp_path: Path) - def test_hook_symlink_install_still_resolves_the_slot_lock_helper(tmp_path: Path) -> None: repo, bin_dir = _sandbox(tmp_path) - scripts_dir = repo / "scripts" + scripts_dir = repo / "litellm/scripts" scripts_dir.mkdir() shutil.copy(SCRIPT, scripts_dir / "pre_commit_lint.sh") shutil.copy(SCRIPT.parent / "gate_slot_lock.py", scripts_dir / "gate_slot_lock.py") - (repo / ".git" / "hooks" / "pre-commit").symlink_to(Path("../../scripts/pre_commit_lint.sh")) + (repo / ".git" / "hooks" / "pre-commit").symlink_to(Path("../../litellm/scripts/pre_commit_lint.sh")) lock_dir = tmp_path / "gate-locks" proc = subprocess.run( ["git", "-c", "user.email=t@t", "-c", "user.name=t", "commit", "-qm", "hooked"], diff --git a/tests/unit/test_prisma_generate_if_needed.py b/tests/unit/test_prisma_generate_if_needed.py index c36f580e24f..7d451afa26d 100644 --- a/tests/unit/test_prisma_generate_if_needed.py +++ b/tests/unit/test_prisma_generate_if_needed.py @@ -4,7 +4,7 @@ import sys from pathlib import Path _MODULE_PATH = ( - Path(__file__).resolve().parents[2] / "scripts" / "prisma_generate_if_needed.py" + Path(__file__).resolve().parents[2] / "litellm/scripts" / "prisma_generate_if_needed.py" ) _spec = importlib.util.spec_from_file_location("prisma_generate_if_needed", _MODULE_PATH) mod = importlib.util.module_from_spec(_spec) diff --git a/tests/unit/test_repo_agent_skills.py b/tests/unit/test_repo_agent_skills.py deleted file mode 100644 index d3321cd76b9..00000000000 --- a/tests/unit/test_repo_agent_skills.py +++ /dev/null @@ -1,68 +0,0 @@ -from collections.abc import Iterator -from fnmatch import fnmatch -from pathlib import Path -from typing import Final - -import pytest -import yaml - -_REPO_ROOT: Final = Path(__file__).resolve().parents[2] -_SKILLS_DIR: Final = _REPO_ROOT / ".agents" / "skills" -_SKILL_DIRECTORIES: Final = tuple(sorted(skill_file.parent for skill_file in _SKILLS_DIR.glob("*/SKILL.md"))) -_FULL_DEPTH_MAX_DEPTH: Final = 5 -_FULL_DEPTH_SKIPPED_NAMES: Final = frozenset(("node_modules", ".git", "dist", "build", "__pycache__")) -_GITIGNORED_NAME_PATTERNS: Final = tuple( - line.strip().rstrip("/") - for line in (_REPO_ROOT / ".gitignore").read_text(encoding="utf-8").splitlines() - if line.strip() and not line.startswith(("#", "!")) and "/" not in line.strip().rstrip("/") -) - - -def _absent_from_a_clone_or_skipped_by_the_cli(name: str) -> bool: - return name in _FULL_DEPTH_SKIPPED_NAMES or any(fnmatch(name, pattern) for pattern in _GITIGNORED_NAME_PATTERNS) - - -def _full_depth_skill_directories(directory: Path, depth: int) -> Iterator[Path]: - if (directory / "SKILL.md").is_file(): - yield directory - if depth == _FULL_DEPTH_MAX_DEPTH: - return - for child in sorted(directory.iterdir()): - if child.is_dir() and not _absent_from_a_clone_or_skipped_by_the_cli(child.name): - yield from _full_depth_skill_directories(child, depth + 1) - - -_NON_END_USER_SKILL_DIRECTORIES: Final = tuple( - directory for directory in _full_depth_skill_directories(_REPO_ROOT, 0) if directory.parent != _SKILLS_DIR -) - - -def _frontmatter(skill_directory: Path) -> object: - opening, frontmatter, _body = (skill_directory / "SKILL.md").read_text(encoding="utf-8").split("---\n", 2) - assert opening == "", f"{skill_directory.name}/SKILL.md must open with a --- frontmatter block" - return yaml.safe_load(frontmatter) - - -@pytest.mark.parametrize("skill_directory", _SKILL_DIRECTORIES, ids=lambda path: path.name) -def test_skill_frontmatter_has_string_name_matching_its_directory_and_a_description(skill_directory: Path) -> None: - frontmatter: Final = _frontmatter(skill_directory) - assert isinstance(frontmatter, dict), frontmatter - assert frontmatter.get("name") == skill_directory.name, frontmatter - description: Final = frontmatter.get("description") - assert isinstance(description, str) and description.strip(), frontmatter - - -@pytest.mark.parametrize( - "skill_directory", - _NON_END_USER_SKILL_DIRECTORIES, - ids=lambda path: str(path.relative_to(_REPO_ROOT)), -) -def test_skill_outside_skills_folder_is_hidden_from_end_user_skill_installs(skill_directory: Path) -> None: - frontmatter: Final = _frontmatter(skill_directory) - assert isinstance(frontmatter, dict), frontmatter - metadata: Final = frontmatter.get("metadata") - assert isinstance(metadata, dict) and metadata.get("internal") is True, ( - f"{skill_directory} needs `metadata: {{internal: true}}`, or `npx skills add BerriAI/litellm` installs it " - "for end users, from a root dot-folder always and from anywhere with --full-depth (skills CLI 1.7.4, " - "checked 2026-10-28)" - ) diff --git a/tests/unit/test_seed_tracing_fixtures.py b/tests/unit/test_seed_tracing_fixtures.py index cee056257dd..9d13ee1bba6 100644 --- a/tests/unit/test_seed_tracing_fixtures.py +++ b/tests/unit/test_seed_tracing_fixtures.py @@ -15,7 +15,7 @@ from pydantic import InstanceOf, TypeAdapter from litellm.tracing.generated.responses import TraceSQLResponse from litellm.tracing.types import SpendLogRecord -from scripts.seed_tracing_fixtures import ( +from litellm.scripts.seed_tracing_fixtures import ( JSON, TRACE_FIXTURES, fixture_capture, @@ -218,7 +218,7 @@ async def test_seed_copy_uses_lens_authenticated_tenant_for_both_spend_stores(mo async def test_seed_copy_ids_come_from_lens_normalization(monkeypatch: pytest.MonkeyPatch) -> None: from litellm.tracing.remote import RemoteTraceStore - from scripts.seed_tracing_fixtures import seeded_trace_ids + from litellm.scripts.seed_tracing_fixtures import seeded_trace_ids monkeypatch.setenv("LITELLM_MASTER_KEY", "fixture-admin") diff --git a/tests/unit/test_spend_logs_guard.py b/tests/unit/test_spend_logs_guard.py index 2545bf82117..5edfe2eeab9 100644 --- a/tests/unit/test_spend_logs_guard.py +++ b/tests/unit/test_spend_logs_guard.py @@ -7,7 +7,7 @@ from typing import Final import pytest -_SCRIPT: Final = Path(__file__).resolve().parents[2] / "scripts" / "ci_cd" / "spend_logs_guard.py" +_SCRIPT: Final = Path(__file__).resolve().parents[2] / "litellm/scripts" / "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) @@ -58,6 +58,20 @@ def _with_line(schema: str, after: int, line: str) -> str: return "".join(lines[:after]) + f"{line}\n" + "".join(lines[after:]) +@pytest.mark.parametrize( + "path", + ( + "schema.prisma", + "litellm/schema.prisma", + "litellm/proxy/schema.prisma", + "litellm/proxy-extras/litellm_proxy_extras/schema.prisma", + ), +) +def test_spend_log_changes_in_every_schema_copy_require_review(path: str) -> None: + assert guard.watched(path) + assert guard.spend_log_hits(_added(path, " tokens Int", start=11), _blocks(path)) == (f"{path}: +tokens Int",) + + class TestModelBlock: def test_the_block_runs_from_the_model_line_through_its_closing_brace(self): assert guard.model_block(SCHEMA) == range(9, 14) diff --git a/tests/unit/test_test_quality_gate.py b/tests/unit/test_test_quality_gate.py index b98e539d4b0..6246e85536a 100644 --- a/tests/unit/test_test_quality_gate.py +++ b/tests/unit/test_test_quality_gate.py @@ -1,6 +1,6 @@ -"""Tests for scripts/test_quality_gate.py. +"""Tests for litellm/scripts/test_quality_gate.py. -The blame rule itself lives in scripts/lint_base_counts.py and is tested there; +The blame rule itself lives in litellm/scripts/lint_base_counts.py and is tested there; what is tested here is `parse_changed_lines`, the diff scan that turns a breach into file:line. The base scan spawns a worktree and a checker subprocess, so its cleanup on termination is driven end to end. @@ -19,7 +19,7 @@ from typing import Final, NamedTuple import test_quality_gate as gate _REPO_ROOT = Path(__file__).resolve().parents[2] -_MODULE_PATH = _REPO_ROOT / "scripts" / "test_quality_gate.py" +_MODULE_PATH = _REPO_ROOT / "litellm/scripts" / "test_quality_gate.py" _SCAN_BASE = ( "import pathlib, sys\n" diff --git a/tests/unit/test_type_discipline_gate.py b/tests/unit/test_type_discipline_gate.py index e99a7be4359..292207fc625 100644 --- a/tests/unit/test_type_discipline_gate.py +++ b/tests/unit/test_type_discipline_gate.py @@ -1,4 +1,4 @@ -"""Tests for scripts/type_discipline_gate.py. +"""Tests for litellm/scripts/type_discipline_gate.py. The gate compares each LIT rule's codebase count against the merge-base count, so what is pinned here is the identity that keys those base counts and the diff scan diff --git a/tests/unit/test_with_dashboard_node.py b/tests/unit/test_with_dashboard_node.py index 0f4b836007b..345896c278f 100644 --- a/tests/unit/test_with_dashboard_node.py +++ b/tests/unit/test_with_dashboard_node.py @@ -4,7 +4,7 @@ import subprocess from pathlib import Path ROOT = Path(__file__).resolve().parents[2] -SCRIPT = ROOT / "scripts" / "with_dashboard_node.sh" +SCRIPT = ROOT / "litellm/scripts" / "with_dashboard_node.sh" def _floor() -> str: