mlpal-gateway 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. mlpal_gateway-0.2.0/.env.oss.example +10 -0
  2. mlpal_gateway-0.2.0/.github/ISSUE_TEMPLATE/bug_report.md +19 -0
  3. mlpal_gateway-0.2.0/.github/ISSUE_TEMPLATE/feature_request.md +14 -0
  4. mlpal_gateway-0.2.0/.github/PULL_REQUEST_TEMPLATE.md +12 -0
  5. mlpal_gateway-0.2.0/.github/workflows/ci.yml +36 -0
  6. mlpal_gateway-0.2.0/.github/workflows/publish-public-pypi.yml +61 -0
  7. mlpal_gateway-0.2.0/.gitignore +25 -0
  8. mlpal_gateway-0.2.0/CODE_OF_CONDUCT.md +36 -0
  9. mlpal_gateway-0.2.0/CONTRIBUTING.md +41 -0
  10. mlpal_gateway-0.2.0/Dockerfile +62 -0
  11. mlpal_gateway-0.2.0/LICENSE +201 -0
  12. mlpal_gateway-0.2.0/NOTICE +10 -0
  13. mlpal_gateway-0.2.0/PKG-INFO +216 -0
  14. mlpal_gateway-0.2.0/PUBLISH_CHECKLIST.md +51 -0
  15. mlpal_gateway-0.2.0/README.md +145 -0
  16. mlpal_gateway-0.2.0/SECURITY.md +23 -0
  17. mlpal_gateway-0.2.0/alembic/env.py +99 -0
  18. mlpal_gateway-0.2.0/alembic/script.py.mako +26 -0
  19. mlpal_gateway-0.2.0/alembic/versions/20260125_1751_41438244c0af_initial_schema.py +153 -0
  20. mlpal_gateway-0.2.0/alembic/versions/20260126_0300_add_user_credits.py +87 -0
  21. mlpal_gateway-0.2.0/alembic/versions/20260126_0400_add_user_billing_status.py +79 -0
  22. mlpal_gateway-0.2.0/alembic/versions/20260127_1200_add_meta_model_routing.py +167 -0
  23. mlpal_gateway-0.2.0/alembic/versions/20260206_1000_add_claude_opus_46.py +96 -0
  24. mlpal_gateway-0.2.0/alembic/versions/20260207_1100_add_cu_rate_columns.py +60 -0
  25. mlpal_gateway-0.2.0/alembic/versions/20260406_0105_wallet_debit_state.py +67 -0
  26. mlpal_gateway-0.2.0/alembic/versions/20260527_2300_cc_metadata.py +58 -0
  27. mlpal_gateway-0.2.0/alembic/versions/20260604_1200_api_keys_tags.py +52 -0
  28. mlpal_gateway-0.2.0/alembic/versions/20260621_1200_model_pause.py +41 -0
  29. mlpal_gateway-0.2.0/alembic/versions/20260724_1200_model_feedback.py +48 -0
  30. mlpal_gateway-0.2.0/alembic/versions/20260802_1200_api_key_policy.py +38 -0
  31. mlpal_gateway-0.2.0/alembic/versions/20260805_1200_model_source.py +39 -0
  32. mlpal_gateway-0.2.0/alembic/versions/20260807_1200_request_payloads.py +46 -0
  33. mlpal_gateway-0.2.0/alembic/versions/20260811_1200_routing_candidates.py +41 -0
  34. mlpal_gateway-0.2.0/alembic/versions/20260811_2000_cu_precision.py +35 -0
  35. mlpal_gateway-0.2.0/alembic/versions/20260811_2200_platform_fee_idx.py +32 -0
  36. mlpal_gateway-0.2.0/alembic.ini +71 -0
  37. mlpal_gateway-0.2.0/config/gateway.yaml +17 -0
  38. mlpal_gateway-0.2.0/console/.gitignore +4 -0
  39. mlpal_gateway-0.2.0/console/Dockerfile +14 -0
  40. mlpal_gateway-0.2.0/console/README.md +50 -0
  41. mlpal_gateway-0.2.0/console/index.html +21 -0
  42. mlpal_gateway-0.2.0/console/nginx.conf +19 -0
  43. mlpal_gateway-0.2.0/console/package-lock.json +5141 -0
  44. mlpal_gateway-0.2.0/console/package.json +42 -0
  45. mlpal_gateway-0.2.0/console/postcss.config.js +5 -0
  46. mlpal_gateway-0.2.0/console/public/favicon.ico +1 -0
  47. mlpal_gateway-0.2.0/console/public/favicon.png +0 -0
  48. mlpal_gateway-0.2.0/console/public/logo.png +0 -0
  49. mlpal_gateway-0.2.0/console/src/App.tsx +45 -0
  50. mlpal_gateway-0.2.0/console/src/components/Brand.tsx +26 -0
  51. mlpal_gateway-0.2.0/console/src/components/CodeSnippet.tsx +53 -0
  52. mlpal_gateway-0.2.0/console/src/components/KeyDetail.tsx +293 -0
  53. mlpal_gateway-0.2.0/console/src/components/Layout.tsx +193 -0
  54. mlpal_gateway-0.2.0/console/src/components/RouterTags.tsx +88 -0
  55. mlpal_gateway-0.2.0/console/src/components/ui/badge.tsx +32 -0
  56. mlpal_gateway-0.2.0/console/src/components/ui/button.tsx +38 -0
  57. mlpal_gateway-0.2.0/console/src/components/ui/card.tsx +28 -0
  58. mlpal_gateway-0.2.0/console/src/components/ui/input.tsx +17 -0
  59. mlpal_gateway-0.2.0/console/src/components/ui/label.tsx +14 -0
  60. mlpal_gateway-0.2.0/console/src/index.css +165 -0
  61. mlpal_gateway-0.2.0/console/src/lib/api.test.ts +126 -0
  62. mlpal_gateway-0.2.0/console/src/lib/api.ts +485 -0
  63. mlpal_gateway-0.2.0/console/src/lib/cn.ts +7 -0
  64. mlpal_gateway-0.2.0/console/src/lib/connection.test.tsx +44 -0
  65. mlpal_gateway-0.2.0/console/src/lib/connection.tsx +80 -0
  66. mlpal_gateway-0.2.0/console/src/lib/snippets.ts +52 -0
  67. mlpal_gateway-0.2.0/console/src/lib/theme.ts +36 -0
  68. mlpal_gateway-0.2.0/console/src/main.tsx +22 -0
  69. mlpal_gateway-0.2.0/console/src/pages/Catalog.tsx +130 -0
  70. mlpal_gateway-0.2.0/console/src/pages/Keys.tsx +462 -0
  71. mlpal_gateway-0.2.0/console/src/pages/Models.tsx +361 -0
  72. mlpal_gateway-0.2.0/console/src/pages/Overview.tsx +392 -0
  73. mlpal_gateway-0.2.0/console/src/pages/Playground.tsx +210 -0
  74. mlpal_gateway-0.2.0/console/src/pages/Providers.tsx +178 -0
  75. mlpal_gateway-0.2.0/console/src/pages/Settings.tsx +170 -0
  76. mlpal_gateway-0.2.0/console/src/pages/Setup.tsx +139 -0
  77. mlpal_gateway-0.2.0/console/src/pages/Traces.tsx +571 -0
  78. mlpal_gateway-0.2.0/console/src/pages/Usage.tsx +206 -0
  79. mlpal_gateway-0.2.0/console/src/test/setup.ts +1 -0
  80. mlpal_gateway-0.2.0/console/tsconfig.json +24 -0
  81. mlpal_gateway-0.2.0/console/vite.config.ts +19 -0
  82. mlpal_gateway-0.2.0/docker-compose.yaml +119 -0
  83. mlpal_gateway-0.2.0/docs/API_SURFACE.md +80 -0
  84. mlpal_gateway-0.2.0/docs/FEATURES.md +90 -0
  85. mlpal_gateway-0.2.0/docs/POSITIONING.md +125 -0
  86. mlpal_gateway-0.2.0/enterprise/.gitkeep +0 -0
  87. mlpal_gateway-0.2.0/enterprise/LICENSE +16 -0
  88. mlpal_gateway-0.2.0/enterprise/README.md +20 -0
  89. mlpal_gateway-0.2.0/paper/bench/cache_exp.py +89 -0
  90. mlpal_gateway-0.2.0/paper/bench/figures.py +145 -0
  91. mlpal_gateway-0.2.0/paper/bench/harness.py +142 -0
  92. mlpal_gateway-0.2.0/paper/bench/litellm-config.yaml +8 -0
  93. mlpal_gateway-0.2.0/paper/bench/results-cache.json +80 -0
  94. mlpal_gateway-0.2.0/paper/bench/results-main.json +323 -0
  95. mlpal_gateway-0.2.0/paper/bench/results-prod.json +109 -0
  96. mlpal_gateway-0.2.0/paper/bench/stats.py +34 -0
  97. mlpal_gateway-0.2.0/paper/fig-architecture.svg +77 -0
  98. mlpal_gateway-0.2.0/paper/fig-cache.svg +590 -0
  99. mlpal_gateway-0.2.0/paper/fig-lifetimes.svg +465 -0
  100. mlpal_gateway-0.2.0/paper/fig-overhead.svg +590 -0
  101. mlpal_gateway-0.2.0/paper/fig-routing.svg +68 -0
  102. mlpal_gateway-0.2.0/paper/index.html +468 -0
  103. mlpal_gateway-0.2.0/paper/mlpal-gateway-technical-report.pdf +0 -0
  104. mlpal_gateway-0.2.0/pyproject.toml +162 -0
  105. mlpal_gateway-0.2.0/scripts/bootstrap_admin_key.py +303 -0
  106. mlpal_gateway-0.2.0/scripts/init-db-oss.sql +24 -0
  107. mlpal_gateway-0.2.0/scripts/reconcile_catalog.py +59 -0
  108. mlpal_gateway-0.2.0/src/mlpal_assistants_service/__init__.py +3 -0
  109. mlpal_gateway-0.2.0/src/mlpal_assistants_service/adapters/__init__.py +40 -0
  110. mlpal_gateway-0.2.0/src/mlpal_assistants_service/adapters/anthropic.py +1226 -0
  111. mlpal_gateway-0.2.0/src/mlpal_assistants_service/adapters/base.py +1306 -0
  112. mlpal_gateway-0.2.0/src/mlpal_assistants_service/adapters/bedrock.py +1452 -0
  113. mlpal_gateway-0.2.0/src/mlpal_assistants_service/adapters/circuit_breaker.py +330 -0
  114. mlpal_gateway-0.2.0/src/mlpal_assistants_service/adapters/factory.py +235 -0
  115. mlpal_gateway-0.2.0/src/mlpal_assistants_service/adapters/google.py +1675 -0
  116. mlpal_gateway-0.2.0/src/mlpal_assistants_service/adapters/openai.py +1768 -0
  117. mlpal_gateway-0.2.0/src/mlpal_assistants_service/api/__init__.py +1 -0
  118. mlpal_gateway-0.2.0/src/mlpal_assistants_service/api/admin_v1/__init__.py +23 -0
  119. mlpal_gateway-0.2.0/src/mlpal_assistants_service/api/deps.py +519 -0
  120. mlpal_gateway-0.2.0/src/mlpal_assistants_service/api/mounting.py +84 -0
  121. mlpal_gateway-0.2.0/src/mlpal_assistants_service/api/v1/__init__.py +27 -0
  122. mlpal_gateway-0.2.0/src/mlpal_assistants_service/api/v1/admin.py +713 -0
  123. mlpal_gateway-0.2.0/src/mlpal_assistants_service/api/v1/audio.py +137 -0
  124. mlpal_gateway-0.2.0/src/mlpal_assistants_service/api/v1/chat.py +231 -0
  125. mlpal_gateway-0.2.0/src/mlpal_assistants_service/api/v1/embeddings.py +49 -0
  126. mlpal_gateway-0.2.0/src/mlpal_assistants_service/api/v1/images.py +49 -0
  127. mlpal_gateway-0.2.0/src/mlpal_assistants_service/api/v1/keys.py +397 -0
  128. mlpal_gateway-0.2.0/src/mlpal_assistants_service/api/v1/models.py +199 -0
  129. mlpal_gateway-0.2.0/src/mlpal_assistants_service/api/v1/usage.py +156 -0
  130. mlpal_gateway-0.2.0/src/mlpal_assistants_service/api/v2/__init__.py +12 -0
  131. mlpal_gateway-0.2.0/src/mlpal_assistants_service/api/v2/catalog.py +130 -0
  132. mlpal_gateway-0.2.0/src/mlpal_assistants_service/api/v2/feedback.py +78 -0
  133. mlpal_gateway-0.2.0/src/mlpal_assistants_service/api/v2/messages.py +138 -0
  134. mlpal_gateway-0.2.0/src/mlpal_assistants_service/catalog/curated.json +138 -0
  135. mlpal_gateway-0.2.0/src/mlpal_assistants_service/catalog/pricing.json +1003 -0
  136. mlpal_gateway-0.2.0/src/mlpal_assistants_service/catalog/registry.json +1855 -0
  137. mlpal_gateway-0.2.0/src/mlpal_assistants_service/catalog/routing.json +162 -0
  138. mlpal_gateway-0.2.0/src/mlpal_assistants_service/core/__init__.py +1 -0
  139. mlpal_gateway-0.2.0/src/mlpal_assistants_service/core/auth.py +129 -0
  140. mlpal_gateway-0.2.0/src/mlpal_assistants_service/core/cache.py +274 -0
  141. mlpal_gateway-0.2.0/src/mlpal_assistants_service/core/config.py +404 -0
  142. mlpal_gateway-0.2.0/src/mlpal_assistants_service/core/exceptions.py +229 -0
  143. mlpal_gateway-0.2.0/src/mlpal_assistants_service/core/file_config.py +43 -0
  144. mlpal_gateway-0.2.0/src/mlpal_assistants_service/core/metrics.py +280 -0
  145. mlpal_gateway-0.2.0/src/mlpal_assistants_service/core/security.py +94 -0
  146. mlpal_gateway-0.2.0/src/mlpal_assistants_service/core/storage.py +352 -0
  147. mlpal_gateway-0.2.0/src/mlpal_assistants_service/core/telemetry.py +202 -0
  148. mlpal_gateway-0.2.0/src/mlpal_assistants_service/db/__init__.py +9 -0
  149. mlpal_gateway-0.2.0/src/mlpal_assistants_service/db/models/__init__.py +44 -0
  150. mlpal_gateway-0.2.0/src/mlpal_assistants_service/db/models/api_key.py +164 -0
  151. mlpal_gateway-0.2.0/src/mlpal_assistants_service/db/models/base.py +45 -0
  152. mlpal_gateway-0.2.0/src/mlpal_assistants_service/db/models/meta_routing.py +96 -0
  153. mlpal_gateway-0.2.0/src/mlpal_assistants_service/db/models/model_feedback.py +58 -0
  154. mlpal_gateway-0.2.0/src/mlpal_assistants_service/db/models/model_pricing.py +177 -0
  155. mlpal_gateway-0.2.0/src/mlpal_assistants_service/db/models/model_registry.py +146 -0
  156. mlpal_gateway-0.2.0/src/mlpal_assistants_service/db/models/request_payload.py +37 -0
  157. mlpal_gateway-0.2.0/src/mlpal_assistants_service/db/models/usage_log.py +174 -0
  158. mlpal_gateway-0.2.0/src/mlpal_assistants_service/db/models/user_billing_status.py +101 -0
  159. mlpal_gateway-0.2.0/src/mlpal_assistants_service/db/models/user_credits.py +208 -0
  160. mlpal_gateway-0.2.0/src/mlpal_assistants_service/db/session.py +95 -0
  161. mlpal_gateway-0.2.0/src/mlpal_assistants_service/main.py +798 -0
  162. mlpal_gateway-0.2.0/src/mlpal_assistants_service/observability/__init__.py +8 -0
  163. mlpal_gateway-0.2.0/src/mlpal_assistants_service/observability/context.py +86 -0
  164. mlpal_gateway-0.2.0/src/mlpal_assistants_service/observability/middleware.py +133 -0
  165. mlpal_gateway-0.2.0/src/mlpal_assistants_service/repositories/__init__.py +37 -0
  166. mlpal_gateway-0.2.0/src/mlpal_assistants_service/repositories/api_key_repository.py +147 -0
  167. mlpal_gateway-0.2.0/src/mlpal_assistants_service/repositories/base.py +114 -0
  168. mlpal_gateway-0.2.0/src/mlpal_assistants_service/repositories/billing_repository.py +463 -0
  169. mlpal_gateway-0.2.0/src/mlpal_assistants_service/repositories/credit_repository.py +313 -0
  170. mlpal_gateway-0.2.0/src/mlpal_assistants_service/repositories/feedback_repository.py +83 -0
  171. mlpal_gateway-0.2.0/src/mlpal_assistants_service/repositories/meta_routing_repository.py +110 -0
  172. mlpal_gateway-0.2.0/src/mlpal_assistants_service/repositories/model_repository.py +97 -0
  173. mlpal_gateway-0.2.0/src/mlpal_assistants_service/repositories/pricing_repository.py +128 -0
  174. mlpal_gateway-0.2.0/src/mlpal_assistants_service/repositories/usage_repository.py +255 -0
  175. mlpal_gateway-0.2.0/src/mlpal_assistants_service/schemas/__init__.py +42 -0
  176. mlpal_gateway-0.2.0/src/mlpal_assistants_service/schemas/api_key.py +185 -0
  177. mlpal_gateway-0.2.0/src/mlpal_assistants_service/schemas/assets.py +58 -0
  178. mlpal_gateway-0.2.0/src/mlpal_assistants_service/schemas/audio.py +157 -0
  179. mlpal_gateway-0.2.0/src/mlpal_assistants_service/schemas/chat.py +289 -0
  180. mlpal_gateway-0.2.0/src/mlpal_assistants_service/schemas/common.py +68 -0
  181. mlpal_gateway-0.2.0/src/mlpal_assistants_service/schemas/embeddings.py +61 -0
  182. mlpal_gateway-0.2.0/src/mlpal_assistants_service/schemas/images.py +230 -0
  183. mlpal_gateway-0.2.0/src/mlpal_assistants_service/schemas/model.py +77 -0
  184. mlpal_gateway-0.2.0/src/mlpal_assistants_service/schemas/routing.py +66 -0
  185. mlpal_gateway-0.2.0/src/mlpal_assistants_service/schemas/usage.py +89 -0
  186. mlpal_gateway-0.2.0/src/mlpal_assistants_service/seams/__init__.py +12 -0
  187. mlpal_gateway-0.2.0/src/mlpal_assistants_service/seams/billing.py +101 -0
  188. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/__init__.py +27 -0
  189. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/api_key.py +418 -0
  190. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/audio.py +575 -0
  191. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/bedrock_mantle.py +274 -0
  192. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/capture.py +196 -0
  193. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/catalog.py +414 -0
  194. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/catalog_sync.py +317 -0
  195. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/chat.py +888 -0
  196. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/credit.py +292 -0
  197. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/debit_retry_worker.py +74 -0
  198. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/embedding.py +367 -0
  199. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/gemini_cache.py +130 -0
  200. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/image.py +482 -0
  201. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/messages_v2/__init__.py +0 -0
  202. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/messages_v2/anthropic_backend.py +52 -0
  203. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/messages_v2/anthropic_edge.py +97 -0
  204. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/messages_v2/core.py +472 -0
  205. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/messages_v2/edges.py +84 -0
  206. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/messages_v2/emit.py +230 -0
  207. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/messages_v2/errors.py +35 -0
  208. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/messages_v2/reasoning.py +41 -0
  209. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/messages_v2/schemas.py +51 -0
  210. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/messages_v2/translate_in.py +309 -0
  211. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/messages_v2/translating_edge.py +142 -0
  212. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/messages_v2/usage.py +96 -0
  213. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/platform_fee.py +178 -0
  214. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/policy.py +257 -0
  215. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/pricing.py +394 -0
  216. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/rate_limiter.py +318 -0
  217. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/router.py +683 -0
  218. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/traces.py +113 -0
  219. mlpal_gateway-0.2.0/src/mlpal_assistants_service/services/usage.py +500 -0
  220. mlpal_gateway-0.2.0/tests/conftest.py +170 -0
  221. mlpal_gateway-0.2.0/tests/unit/__init__.py +1 -0
  222. mlpal_gateway-0.2.0/tests/unit/test_api_key_schema.py +33 -0
  223. mlpal_gateway-0.2.0/tests/unit/test_api_key_service.py +134 -0
  224. mlpal_gateway-0.2.0/tests/unit/test_api_surface.py +109 -0
  225. mlpal_gateway-0.2.0/tests/unit/test_auth_seam.py +82 -0
  226. mlpal_gateway-0.2.0/tests/unit/test_billing_gate.py +96 -0
  227. mlpal_gateway-0.2.0/tests/unit/test_billing_repository.py +340 -0
  228. mlpal_gateway-0.2.0/tests/unit/test_cache_invalidator.py +82 -0
  229. mlpal_gateway-0.2.0/tests/unit/test_capture.py +79 -0
  230. mlpal_gateway-0.2.0/tests/unit/test_catalog.py +353 -0
  231. mlpal_gateway-0.2.0/tests/unit/test_catalog_sync.py +122 -0
  232. mlpal_gateway-0.2.0/tests/unit/test_chat_stream_tool_calls.py +125 -0
  233. mlpal_gateway-0.2.0/tests/unit/test_chat_wallet_gating.py +181 -0
  234. mlpal_gateway-0.2.0/tests/unit/test_circuit_breaker.py +82 -0
  235. mlpal_gateway-0.2.0/tests/unit/test_cors_preflight.py +47 -0
  236. mlpal_gateway-0.2.0/tests/unit/test_debit_retry_worker.py +66 -0
  237. mlpal_gateway-0.2.0/tests/unit/test_error_observability.py +102 -0
  238. mlpal_gateway-0.2.0/tests/unit/test_feedback.py +74 -0
  239. mlpal_gateway-0.2.0/tests/unit/test_gemini_cache.py +233 -0
  240. mlpal_gateway-0.2.0/tests/unit/test_google_thinking_reserve.py +100 -0
  241. mlpal_gateway-0.2.0/tests/unit/test_image_size_resolver.py +65 -0
  242. mlpal_gateway-0.2.0/tests/unit/test_messages_v2.py +421 -0
  243. mlpal_gateway-0.2.0/tests/unit/test_messages_v2_translate.py +621 -0
  244. mlpal_gateway-0.2.0/tests/unit/test_meta_routing.py +158 -0
  245. mlpal_gateway-0.2.0/tests/unit/test_modality_wallet_gating.py +217 -0
  246. mlpal_gateway-0.2.0/tests/unit/test_model_pause.py +98 -0
  247. mlpal_gateway-0.2.0/tests/unit/test_openai_stream_tool_calls.py +67 -0
  248. mlpal_gateway-0.2.0/tests/unit/test_platform_fee.py +168 -0
  249. mlpal_gateway-0.2.0/tests/unit/test_policy.py +328 -0
  250. mlpal_gateway-0.2.0/tests/unit/test_pricing_service.py +115 -0
  251. mlpal_gateway-0.2.0/tests/unit/test_provider_activation.py +73 -0
  252. mlpal_gateway-0.2.0/tests/unit/test_provider_error_mapping.py +67 -0
  253. mlpal_gateway-0.2.0/tests/unit/test_rate_limiter.py +178 -0
  254. mlpal_gateway-0.2.0/tests/unit/test_router_cache.py +69 -0
  255. mlpal_gateway-0.2.0/tests/unit/test_security.py +146 -0
  256. mlpal_gateway-0.2.0/tests/unit/test_stream_heartbeat.py +155 -0
  257. mlpal_gateway-0.2.0/tests/unit/test_traces_selfscope.py +133 -0
  258. mlpal_gateway-0.2.0/tests/unit/test_ttl_cache.py +200 -0
  259. mlpal_gateway-0.2.0/tests/unit/test_usage_service.py +32 -0
  260. mlpal_gateway-0.2.0/tests/unit/test_wallet_gating_disabled.py +137 -0
  261. mlpal_gateway-0.2.0/uv.lock +4024 -0
@@ -0,0 +1,10 @@
1
+ # MLPal Assistants Gateway — self-hosted (OSS). Copy to `.env`, set >=1 key.
2
+ # The docker-compose stack sets DB/Redis + local-mode flags for you; you only
3
+ # need to provide the provider keys you have. Adapters light up per key present.
4
+
5
+ OPENAI_API_KEY=
6
+ ANTHROPIC_API_KEY=
7
+ GOOGLE_API_KEY=
8
+
9
+ # Optional: enable Bedrock (needs AWS creds in the environment).
10
+ # MLPAL_ENABLE_BEDROCK=true
@@ -0,0 +1,19 @@
1
+ ---
2
+ name: Bug report
3
+ about: Something isn't working
4
+ labels: bug
5
+ ---
6
+
7
+ **What happened**
8
+ A clear description of the bug.
9
+
10
+ **To reproduce**
11
+ Steps / a minimal request. Do NOT paste real API keys or secrets.
12
+
13
+ **Expected**
14
+ What you expected to happen.
15
+
16
+ **Environment**
17
+ - Deploy: docker-compose / other
18
+ - Gateway version / commit:
19
+ - Providers configured (which keys present):
@@ -0,0 +1,14 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea
4
+ labels: enhancement
5
+ ---
6
+
7
+ **Problem**
8
+ What are you trying to do that's hard today?
9
+
10
+ **Proposal**
11
+ What would you like to see?
12
+
13
+ **Alternatives / prior art**
14
+ Anything else considered (e.g. how OpenRouter/LiteLLM/Portkey handle it).
@@ -0,0 +1,12 @@
1
+ ## What & why
2
+
3
+ <!-- What does this change and why? Link any issue. -->
4
+
5
+ ## Checklist
6
+
7
+ - [ ] Tests added/updated (unit for logic, and any regression for a bug fixed)
8
+ - [ ] `uv run ruff check .` passes
9
+ - [ ] `uv run python -m pytest tests/unit/ -q` passes
10
+ - [ ] No secrets / `.env` / real provider keys committed
11
+ - [ ] `core` does not import from `enterprise/`
12
+ - [ ] Signed off (`git commit -s`)
@@ -0,0 +1,36 @@
1
+ name: ci
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ gateway:
10
+ name: gateway (lint + unit tests)
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - name: Install uv
15
+ uses: astral-sh/setup-uv@v5
16
+ - name: Sync deps
17
+ run: uv sync --all-extras
18
+ - name: Lint
19
+ run: uv run ruff check .
20
+ - name: Unit tests
21
+ run: uv run python -m pytest tests/unit/ -q
22
+
23
+ console:
24
+ name: console (build + test)
25
+ runs-on: ubuntu-latest
26
+ defaults:
27
+ run:
28
+ working-directory: console
29
+ steps:
30
+ - uses: actions/checkout@v4
31
+ - uses: actions/setup-node@v4
32
+ with:
33
+ node-version: "22"
34
+ - run: npm ci
35
+ - run: npm test
36
+ - run: npm run build
@@ -0,0 +1,61 @@
1
+ # Publish to PUBLIC PyPI via Trusted Publishing (OIDC — no API token stored).
2
+ #
3
+ # Trigger: pushing a version tag (v0.2.0, v1.0.0, …). The tag must match the
4
+ # version in pyproject.toml — the workflow fails closed if they disagree.
5
+ #
6
+ # One-time PyPI setup (account → Publishing → "Add a new pending publisher"):
7
+ # PyPI project name: mlpal-gateway
8
+ # Owner: mlpalOld
9
+ # Repository: mlpal-gateway
10
+ # Workflow: publish-public-pypi.yml
11
+ # Environment: pypi
12
+ name: Publish to Public PyPI
13
+
14
+ on:
15
+ push:
16
+ tags: ["v*"]
17
+
18
+ jobs:
19
+ build:
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+
24
+ - name: Verify tag matches pyproject version
25
+ run: |
26
+ PKG_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
27
+ TAG_VERSION="${GITHUB_REF_NAME#v}"
28
+ if [ "$PKG_VERSION" != "$TAG_VERSION" ]; then
29
+ echo "Tag $GITHUB_REF_NAME != pyproject version $PKG_VERSION" >&2
30
+ exit 1
31
+ fi
32
+
33
+ - uses: astral-sh/setup-uv@v3
34
+
35
+ - name: Run tests
36
+ run: |
37
+ uv sync --all-extras
38
+ uv run python -m pytest tests/ -q
39
+
40
+ - name: Build sdist + wheel
41
+ run: uv build
42
+
43
+ - uses: actions/upload-artifact@v4
44
+ with:
45
+ name: dist
46
+ path: dist/
47
+
48
+ publish:
49
+ needs: build
50
+ runs-on: ubuntu-latest
51
+ environment: pypi
52
+ permissions:
53
+ id-token: write # OIDC for Trusted Publishing
54
+ steps:
55
+ - uses: actions/download-artifact@v4
56
+ with:
57
+ name: dist
58
+ path: dist/
59
+
60
+ - name: Publish to PyPI
61
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,25 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .venv/
6
+ venv/
7
+ .pytest_cache/
8
+ .ruff_cache/
9
+ .mypy_cache/
10
+ dist/
11
+ build/
12
+
13
+ # Node (console)
14
+ node_modules/
15
+ console/dist/
16
+
17
+ # Env / secrets — NEVER commit real keys
18
+ .env
19
+ .env.local
20
+ *.local
21
+
22
+ # OS / editor
23
+ .DS_Store
24
+ .idea/
25
+ .vscode/
@@ -0,0 +1,36 @@
1
+ # Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to a positive environment:
15
+
16
+ - Demonstrating empathy and kindness toward other people
17
+ - Being respectful of differing opinions, viewpoints, and experiences
18
+ - Giving and gracefully accepting constructive feedback
19
+ - Focusing on what is best for the overall community
20
+
21
+ Examples of unacceptable behavior:
22
+
23
+ - Trolling, insulting or derogatory comments, and personal or political attacks
24
+ - Public or private harassment
25
+ - Publishing others' private information without explicit permission
26
+
27
+ ## Enforcement
28
+
29
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
30
+ reported to the maintainers at conduct@mlpal.ai. All complaints will be reviewed
31
+ and investigated promptly and fairly.
32
+
33
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
34
+ version 2.1.
35
+
36
+ [homepage]: https://www.contributor-covenant.org
@@ -0,0 +1,41 @@
1
+ # Contributing to MLPal Gateway
2
+
3
+ Thanks for your interest! MLPal Gateway is early-stage and we welcome issues,
4
+ discussion, and PRs.
5
+
6
+ ## Open-core boundary
7
+
8
+ - Everything **outside** `enterprise/` is Apache-2.0 and open to contributions.
9
+ - The **`enterprise/`** directory is commercial (see `enterprise/LICENSE`). PRs
10
+ that add features there won't be accepted from outside contributors; propose
11
+ them as an issue instead.
12
+
13
+ ## Development
14
+
15
+ ```bash
16
+ uv sync --all-extras
17
+ uv run python -m pytest tests/unit/ -v # unit tests
18
+ uv run ruff check . # lint
19
+ docker compose up # full local box (gateway + console)
20
+ ```
21
+
22
+ Console (admin UI):
23
+
24
+ ```bash
25
+ cd console && npm install && npm test && npm run build
26
+ ```
27
+
28
+ ## Guidelines
29
+
30
+ - Keep the correct path the easy path; prefer clarity over cleverness.
31
+ - Add tests for new behavior and for any bug you fix — code isn't done without them.
32
+ - Never commit secrets. Never add a real provider key or `.env`.
33
+ - Keep `core` free of imports from `enterprise/` — the open-source build must
34
+ stand alone.
35
+ - Conventional-ish commit messages are appreciated (`feat:`, `fix:`, `docs:`…).
36
+
37
+ ## DCO
38
+
39
+ By contributing, you certify that you wrote the code or have the right to submit
40
+ it under the Apache-2.0 license (Developer Certificate of Origin). Sign off your
41
+ commits with `git commit -s`.
@@ -0,0 +1,62 @@
1
+ # syntax=docker/dockerfile:1
2
+
3
+ # Build stage
4
+ FROM python:3.11-slim as builder
5
+
6
+ WORKDIR /app
7
+
8
+ # Install uv
9
+ COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
10
+
11
+ # Copy project files (include the lockfile for reproducible installs)
12
+ COPY pyproject.toml uv.lock README.md ./
13
+
14
+ # Install the EXACT locked dependency versions instead of resolving fresh from
15
+ # pyproject constraints. Fresh resolution silently drifted prod to newer SDKs on
16
+ # every rebuild (e.g. google-genai 1.x→2.x changed Gemini tool/thinking behavior).
17
+ # The project code itself is provided via PYTHONPATH in the runtime stage.
18
+ RUN uv export --frozen --no-dev --no-emit-project -o /tmp/requirements.txt && \
19
+ uv pip install --system --no-cache -r /tmp/requirements.txt
20
+
21
+ # Runtime stage
22
+ FROM python:3.11-slim as runtime
23
+
24
+ WORKDIR /app
25
+
26
+ # Create non-root user
27
+ RUN groupadd --gid 1000 appgroup && \
28
+ useradd --uid 1000 --gid appgroup --shell /bin/bash appuser
29
+
30
+ # Copy installed packages from builder
31
+ COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
32
+ COPY --from=builder /usr/local/bin /usr/local/bin
33
+
34
+ # Copy application code
35
+ COPY src/ ./src/
36
+ COPY alembic/ ./alembic/
37
+ COPY alembic.ini .
38
+ # Seed + bootstrap scripts (used by the docker-compose migrate/seed init
39
+ # containers for self-hosted setup). Harmless in the managed image.
40
+ COPY scripts/ ./scripts/
41
+ COPY config/ ./config/
42
+
43
+ # Set ownership
44
+ RUN chown -R appuser:appgroup /app
45
+
46
+ # Switch to non-root user
47
+ USER appuser
48
+
49
+ # Environment variables
50
+ ENV PYTHONUNBUFFERED=1 \
51
+ PYTHONDONTWRITEBYTECODE=1 \
52
+ PYTHONPATH=/app/src
53
+
54
+ # Expose port
55
+ EXPOSE 8000
56
+
57
+ # Health check
58
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
59
+ CMD python -c "import httpx; httpx.get('http://localhost:8000/health/live')" || exit 1
60
+
61
+ # Run the application
62
+ CMD ["uvicorn", "mlpal_assistants_service.main:app", "--host", "0.0.0.0", "--port", "8000"]
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work, excluding
103
+ those notices that do not pertain to any part of the Derivative
104
+ Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and do
117
+ not modify the License. You may add Your own attribution notices
118
+ within Derivative Works that You distribute, alongside or as an
119
+ addendum to the NOTICE text from the Work, provided that such
120
+ additional attribution notices cannot be construed as modifying
121
+ the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 MLPal, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,10 @@
1
+ MLPal Gateway
2
+ Copyright 2026 MLPal, Inc.
3
+
4
+ This product includes software developed at MLPal, Inc.
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License"); the core of this
7
+ repository is open source. See LICENSE.
8
+
9
+ The `enterprise/` directory is NOT covered by the Apache License and is provided
10
+ under a separate commercial license. See enterprise/LICENSE.