vertex-proxy 0.2.0__tar.gz → 0.4.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 (28) hide show
  1. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/CHANGELOG.md +21 -0
  2. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/PKG-INFO +49 -5
  3. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/README.md +48 -4
  4. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/docker-compose.yaml +5 -1
  5. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/tests/test_config.py +44 -3
  6. vertex_proxy-0.4.0/tests/test_ollama.py +56 -0
  7. vertex_proxy-0.4.0/tests/test_openai_anthropic_bridge.py +364 -0
  8. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/tests/test_routing.py +90 -1
  9. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/vertex_proxy/__init__.py +1 -1
  10. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/vertex_proxy/config.py +22 -7
  11. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/vertex_proxy/main.py +295 -16
  12. vertex_proxy-0.4.0/vertex_proxy/openai_anthropic_bridge.py +276 -0
  13. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/.env.example +0 -0
  14. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/.github/workflows/ci.yml +0 -0
  15. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/.github/workflows/release.yml +0 -0
  16. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/.gitignore +0 -0
  17. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/CONTRIBUTING.md +0 -0
  18. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/Dockerfile +0 -0
  19. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/LICENSE +0 -0
  20. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/examples/claude-code-env.sh +0 -0
  21. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/examples/hermes-config-snippet.yaml +0 -0
  22. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/examples/systemd.service +0 -0
  23. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/launchd/ai.hermes.vertex-proxy.plist.template +0 -0
  24. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/launchd/install.sh +0 -0
  25. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/pyproject.toml +0 -0
  26. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/tests/__init__.py +0 -0
  27. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/vertex_proxy/__main__.py +0 -0
  28. {vertex_proxy-0.2.0 → vertex_proxy-0.4.0}/vertex_proxy/auth.py +0 -0
@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.4.0] - 2026-06-25
11
+
12
+ ### Added
13
+ - Ollama backend support: route OpenAI-compatible requests to local Ollama servers via `VERTEX_PROXY_OLLAMA_BACKENDS` config. Supports wildcard (`"*"`) for auto-discovery of all models from an Ollama server's `/api/tags` endpoint. Ollama is matched after the Vertex routes so a discovered local model cannot shadow a managed model.
14
+ - Ollama models appear in `/v1/models` with `owned_by=ollama` and `provider=ollama`.
15
+ - docker-compose updated with Ollama env config and `host.docker.internal` networking.
16
+
17
+ ### Fixed
18
+ - Strip `context_management` field from Anthropic requests before forwarding to Vertex AI. Claude Code v2.1+ sends this field, and Vertex rejects it with 400 "Extra inputs are not permitted".
19
+
20
+ ## [0.3.0] - 2026-06-06
21
+
22
+ ### Added
23
+ - OpenAI -> Anthropic bridge: Claude models are reachable through the OpenAI Chat Completions route (`/v1/chat/completions`); system/tool/assistant messages, max_tokens/temperature/stop, streaming, and tool calls are translated, and response-side Claude `tool_use` is mapped back to OpenAI `tool_calls`.
24
+ - Recent Anthropic models on Vertex: Opus 4.8/4.7/4.6 and Sonnet 4.6 (dateless 4.6-generation IDs).
25
+ - Per-provider model-listing endpoints: `/anthropic/v1/models`, `/gemini/v1/models`, `/gemini/v1beta/models`; plus OpenAI-compatible `created`/`owned_by` fields on `/v1/models`.
26
+
27
+ ### Fixed
28
+ - Corrected the Vertex IDs for the pre-4.6 Claude family: Opus 4.5 -> `@20251101` and Haiku 4.5 -> `@20251001` (both previously 404'd at the Vertex call).
29
+ - The OpenAI-route Anthropic model validation now accepts the dateless 4.6-generation IDs (the old guard required an `@` and rejected `claude-opus-4-8` etc.).
30
+
10
31
  ## [0.2.0] - 2026-06-02
11
32
 
12
33
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vertex-proxy
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Summary: Anthropic + Gemini + OpenAI API-compatible proxy for Google Cloud Vertex AI. Bridges static-URL API consumers to Vertex AI's service-account auth.
5
5
  Project-URL: Homepage, https://github.com/prasadus92/vertex-proxy
6
6
  Project-URL: Author, https://prasad.tech
@@ -116,8 +116,9 @@ curl -X POST http://127.0.0.1:8787/gemini/v1beta/models/gemini-2.5-flash:generat
116
116
  |---|---|---|
117
117
  | `POST /anthropic/v1/messages` | Anthropic Messages API | `publishers/anthropic/models/{model}:rawPredict` |
118
118
  | `POST /gemini/v1beta/models/{m}:{action}` | Gemini generateContent API | `publishers/google/models/{m}:{action}` |
119
- | `POST /openai/v1/chat/completions` | OpenAI Chat Completions | Gemini (via Vertex OpenAI-compat) + MaaS partner models (Kimi, GLM, MiniMax, Qwen, Grok) |
120
- | `GET /v1/models` | - | Lists routable models |
119
+ | `POST /openai/v1/chat/completions` | OpenAI Chat Completions | Anthropic Claude (via OpenAI->Anthropic translation) + Gemini (via Vertex OpenAI-compat) + MaaS partner models (Kimi, GLM, MiniMax, Qwen, Grok) |
120
+ | `GET /v1/models` | - | Lists all routable models (OpenAI-compatible fields: id, object, created, owned_by) |
121
+ | `GET /anthropic/v1/models`, `/gemini/v1/models`, `/gemini/v1beta/models` | - | Per-provider model listings (for clients scoped to a single provider base_url) |
121
122
  | `GET /health` | - | Liveness + auth check |
122
123
 
123
124
  The OpenAI Chat Completions shape is also accepted under the `/gemini` prefix and the bare root, so clients that build their URL from a `base_url` of `.../openai`, `.../gemini`, or the server root all reach the same handler. Model-discovery probes (`/v1/models`, `/models`) are mirrored under those prefixes too.
@@ -125,14 +126,25 @@ The OpenAI Chat Completions shape is also accepted under the `/gemini` prefix an
125
126
  Streaming is supported on all routes (Anthropic, Gemini, and the OpenAI-compat route).
126
127
  Streaming requests use a no-read-timeout upstream client so long Vertex generations do not get cut off during idle periods.
127
128
 
129
+ Anthropic Claude is now reachable through the OpenAI Chat Completions route too: the proxy translates OpenAI <-> Anthropic Messages, so OpenAI-SDK clients can use Claude on Vertex without the Anthropic API. Tool calls are translated on the non-streaming path; streamed `tool_use` is text-only for now.
130
+
128
131
  ## Pre-configured models
129
132
 
130
133
  All aliases live in [`vertex_proxy/config.py`](vertex_proxy/config.py); extend as needed.
131
134
 
132
135
  **Anthropic** (on Vertex, `us-east5` by default)
136
+
137
+ 4.6-generation IDs are dateless: the bare id IS the pinned snapshot, so the
138
+ proxy passes it through unchanged. Do not append `@<date>` (it 404s).
139
+ - `claude-opus-4-8` → `claude-opus-4-8`
140
+ - `claude-opus-4-7` → `claude-opus-4-7`
141
+ - `claude-opus-4-6` → `claude-opus-4-6`
142
+ - `claude-sonnet-4-6` → `claude-sonnet-4-6`
143
+
144
+ Pre-4.6 IDs carry a snapshot date that Vertex separates with `@`:
133
145
  - `claude-sonnet-4-5-20250929` → `claude-sonnet-4-5@20250929`
134
- - `claude-opus-4-5-20250929` → `claude-opus-4-5@20250929`
135
- - `claude-haiku-4-5-20250929` → `claude-haiku-4-5@20250929`
146
+ - `claude-opus-4-5` → `claude-opus-4-5@20251101`
147
+ - `claude-haiku-4-5` → `claude-haiku-4-5@20251001`
136
148
 
137
149
  **Gemini** (on Vertex, `us-central1` by default)
138
150
  - `gemini-2.5-pro`, `gemini-2.5-flash`, `gemini-2.0-flash`
@@ -144,6 +156,20 @@ All aliases live in [`vertex_proxy/config.py`](vertex_proxy/config.py); extend a
144
156
  - `qwen3.5`, `qwen-3` (Alibaba)
145
157
  - `grok-4.20`, `grok-4.1-fast` (xAI)
146
158
 
159
+ **Ollama** (local models, auto-discovered)
160
+
161
+ Set `VERTEX_PROXY_OLLAMA_BACKENDS` to a JSON object mapping model names to Ollama base URLs. Use `"*"` as a wildcard key to auto-discover all models from a server:
162
+
163
+ ```bash
164
+ # Auto-discover all models from a local Ollama instance
165
+ export VERTEX_PROXY_OLLAMA_BACKENDS='{"*": "http://localhost:11434"}'
166
+
167
+ # Or map specific models to specific servers
168
+ export VERTEX_PROXY_OLLAMA_BACKENDS='{"qwen3:30b-a3b": "http://localhost:11434", "llama3.3:70b": "http://gpu-server:11434"}'
169
+ ```
170
+
171
+ Discovered models appear in `/v1/models` with `owned_by=ollama` and are routed through Ollama's OpenAI-compatible endpoint (`/v1/chat/completions`).
172
+
147
173
  ## Recipes
148
174
 
149
175
  ### Claude Code CLI
@@ -190,6 +216,23 @@ Set the base URL environment variable the client supports (usually one of `ANTHR
190
216
  export ANTHROPIC_BASE_URL=http://127.0.0.1:8787/anthropic
191
217
  ```
192
218
 
219
+ ### OpenAI-SDK client -> Claude
220
+
221
+ Point any OpenAI-SDK client at the proxy's `/v1` base and request a Claude model by name. The proxy translates the OpenAI Chat Completions request into an Anthropic Messages call to Vertex and translates the response back:
222
+
223
+ ```python
224
+ from openai import OpenAI
225
+
226
+ client = OpenAI(base_url="http://127.0.0.1:8787/v1", api_key="bypass")
227
+ resp = client.chat.completions.create(
228
+ model="claude-opus-4-8",
229
+ messages=[{"role": "user", "content": "hello"}],
230
+ )
231
+ print(resp.choices[0].message.content)
232
+ ```
233
+
234
+ System messages, `max_tokens`/`temperature`/`stop`, streaming, and tool calls are translated (streamed `tool_use` is not yet).
235
+
193
236
  ## Run as a service (macOS launchd)
194
237
 
195
238
  ```bash
@@ -219,6 +262,7 @@ All settings accept `VERTEX_PROXY_` env var prefix or CLI flags.
219
262
  | `VERTEX_PROXY_MAAS_REGION` | `us-central1` | Region for Kimi / GLM / MiniMax / Qwen / Grok |
220
263
  | `VERTEX_PROXY_HOST` | `127.0.0.1` | Bind host |
221
264
  | `VERTEX_PROXY_PORT` | `8787` | Bind port |
265
+ | `VERTEX_PROXY_OLLAMA_BACKENDS` | `{}` | JSON map of model names to Ollama base URLs; `"*"` auto-discovers |
222
266
  | `VERTEX_PROXY_TOKEN_REFRESH_SECONDS` | `3000` | Token refresh interval (50 min) |
223
267
  | `VERTEX_PROXY_LOG_LEVEL` | `info` | uvicorn log level |
224
268
 
@@ -84,8 +84,9 @@ curl -X POST http://127.0.0.1:8787/gemini/v1beta/models/gemini-2.5-flash:generat
84
84
  |---|---|---|
85
85
  | `POST /anthropic/v1/messages` | Anthropic Messages API | `publishers/anthropic/models/{model}:rawPredict` |
86
86
  | `POST /gemini/v1beta/models/{m}:{action}` | Gemini generateContent API | `publishers/google/models/{m}:{action}` |
87
- | `POST /openai/v1/chat/completions` | OpenAI Chat Completions | Gemini (via Vertex OpenAI-compat) + MaaS partner models (Kimi, GLM, MiniMax, Qwen, Grok) |
88
- | `GET /v1/models` | - | Lists routable models |
87
+ | `POST /openai/v1/chat/completions` | OpenAI Chat Completions | Anthropic Claude (via OpenAI->Anthropic translation) + Gemini (via Vertex OpenAI-compat) + MaaS partner models (Kimi, GLM, MiniMax, Qwen, Grok) |
88
+ | `GET /v1/models` | - | Lists all routable models (OpenAI-compatible fields: id, object, created, owned_by) |
89
+ | `GET /anthropic/v1/models`, `/gemini/v1/models`, `/gemini/v1beta/models` | - | Per-provider model listings (for clients scoped to a single provider base_url) |
89
90
  | `GET /health` | - | Liveness + auth check |
90
91
 
91
92
  The OpenAI Chat Completions shape is also accepted under the `/gemini` prefix and the bare root, so clients that build their URL from a `base_url` of `.../openai`, `.../gemini`, or the server root all reach the same handler. Model-discovery probes (`/v1/models`, `/models`) are mirrored under those prefixes too.
@@ -93,14 +94,25 @@ The OpenAI Chat Completions shape is also accepted under the `/gemini` prefix an
93
94
  Streaming is supported on all routes (Anthropic, Gemini, and the OpenAI-compat route).
94
95
  Streaming requests use a no-read-timeout upstream client so long Vertex generations do not get cut off during idle periods.
95
96
 
97
+ Anthropic Claude is now reachable through the OpenAI Chat Completions route too: the proxy translates OpenAI <-> Anthropic Messages, so OpenAI-SDK clients can use Claude on Vertex without the Anthropic API. Tool calls are translated on the non-streaming path; streamed `tool_use` is text-only for now.
98
+
96
99
  ## Pre-configured models
97
100
 
98
101
  All aliases live in [`vertex_proxy/config.py`](vertex_proxy/config.py); extend as needed.
99
102
 
100
103
  **Anthropic** (on Vertex, `us-east5` by default)
104
+
105
+ 4.6-generation IDs are dateless: the bare id IS the pinned snapshot, so the
106
+ proxy passes it through unchanged. Do not append `@<date>` (it 404s).
107
+ - `claude-opus-4-8` → `claude-opus-4-8`
108
+ - `claude-opus-4-7` → `claude-opus-4-7`
109
+ - `claude-opus-4-6` → `claude-opus-4-6`
110
+ - `claude-sonnet-4-6` → `claude-sonnet-4-6`
111
+
112
+ Pre-4.6 IDs carry a snapshot date that Vertex separates with `@`:
101
113
  - `claude-sonnet-4-5-20250929` → `claude-sonnet-4-5@20250929`
102
- - `claude-opus-4-5-20250929` → `claude-opus-4-5@20250929`
103
- - `claude-haiku-4-5-20250929` → `claude-haiku-4-5@20250929`
114
+ - `claude-opus-4-5` → `claude-opus-4-5@20251101`
115
+ - `claude-haiku-4-5` → `claude-haiku-4-5@20251001`
104
116
 
105
117
  **Gemini** (on Vertex, `us-central1` by default)
106
118
  - `gemini-2.5-pro`, `gemini-2.5-flash`, `gemini-2.0-flash`
@@ -112,6 +124,20 @@ All aliases live in [`vertex_proxy/config.py`](vertex_proxy/config.py); extend a
112
124
  - `qwen3.5`, `qwen-3` (Alibaba)
113
125
  - `grok-4.20`, `grok-4.1-fast` (xAI)
114
126
 
127
+ **Ollama** (local models, auto-discovered)
128
+
129
+ Set `VERTEX_PROXY_OLLAMA_BACKENDS` to a JSON object mapping model names to Ollama base URLs. Use `"*"` as a wildcard key to auto-discover all models from a server:
130
+
131
+ ```bash
132
+ # Auto-discover all models from a local Ollama instance
133
+ export VERTEX_PROXY_OLLAMA_BACKENDS='{"*": "http://localhost:11434"}'
134
+
135
+ # Or map specific models to specific servers
136
+ export VERTEX_PROXY_OLLAMA_BACKENDS='{"qwen3:30b-a3b": "http://localhost:11434", "llama3.3:70b": "http://gpu-server:11434"}'
137
+ ```
138
+
139
+ Discovered models appear in `/v1/models` with `owned_by=ollama` and are routed through Ollama's OpenAI-compatible endpoint (`/v1/chat/completions`).
140
+
115
141
  ## Recipes
116
142
 
117
143
  ### Claude Code CLI
@@ -158,6 +184,23 @@ Set the base URL environment variable the client supports (usually one of `ANTHR
158
184
  export ANTHROPIC_BASE_URL=http://127.0.0.1:8787/anthropic
159
185
  ```
160
186
 
187
+ ### OpenAI-SDK client -> Claude
188
+
189
+ Point any OpenAI-SDK client at the proxy's `/v1` base and request a Claude model by name. The proxy translates the OpenAI Chat Completions request into an Anthropic Messages call to Vertex and translates the response back:
190
+
191
+ ```python
192
+ from openai import OpenAI
193
+
194
+ client = OpenAI(base_url="http://127.0.0.1:8787/v1", api_key="bypass")
195
+ resp = client.chat.completions.create(
196
+ model="claude-opus-4-8",
197
+ messages=[{"role": "user", "content": "hello"}],
198
+ )
199
+ print(resp.choices[0].message.content)
200
+ ```
201
+
202
+ System messages, `max_tokens`/`temperature`/`stop`, streaming, and tool calls are translated (streamed `tool_use` is not yet).
203
+
161
204
  ## Run as a service (macOS launchd)
162
205
 
163
206
  ```bash
@@ -187,6 +230,7 @@ All settings accept `VERTEX_PROXY_` env var prefix or CLI flags.
187
230
  | `VERTEX_PROXY_MAAS_REGION` | `us-central1` | Region for Kimi / GLM / MiniMax / Qwen / Grok |
188
231
  | `VERTEX_PROXY_HOST` | `127.0.0.1` | Bind host |
189
232
  | `VERTEX_PROXY_PORT` | `8787` | Bind port |
233
+ | `VERTEX_PROXY_OLLAMA_BACKENDS` | `{}` | JSON map of model names to Ollama base URLs; `"*"` auto-discovers |
190
234
  | `VERTEX_PROXY_TOKEN_REFRESH_SECONDS` | `3000` | Token refresh interval (50 min) |
191
235
  | `VERTEX_PROXY_LOG_LEVEL` | `info` | uvicorn log level |
192
236
 
@@ -1,4 +1,4 @@
1
- # Example docker-compose setup for vertex-proxy.
1
+ # vertex-proxy docker-compose setup.
2
2
  # Usage:
3
3
  # 1. Copy .env.example to .env and fill in your values
4
4
  # 2. Place your GCP service-account JSON at ./credentials/gcp-key.json
@@ -22,8 +22,12 @@ services:
22
22
  VERTEX_PROXY_ANTHROPIC_REGION: ${VERTEX_PROXY_ANTHROPIC_REGION:-us-east5}
23
23
  VERTEX_PROXY_GEMINI_REGION: ${VERTEX_PROXY_GEMINI_REGION:-us-central1}
24
24
  VERTEX_PROXY_LOG_LEVEL: ${VERTEX_PROXY_LOG_LEVEL:-info}
25
+ # Ollama backend: auto-discover all models from the host's Ollama
26
+ VERTEX_PROXY_OLLAMA_BACKENDS: '{"*": "http://host.docker.internal:11434"}'
25
27
  # Uncomment to require a bearer token on all routes:
26
28
  # VERTEX_PROXY_API_KEY: ${VERTEX_PROXY_API_KEY}
29
+ extra_hosts:
30
+ - "host.docker.internal:host-gateway"
27
31
  healthcheck:
28
32
  test: ["CMD", "python", "-c", "import urllib.request,sys;sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8787/health',timeout=3).status==200 else 1)"]
29
33
  interval: 30s
@@ -2,6 +2,8 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import re
6
+
5
7
  from vertex_proxy.config import Settings
6
8
 
7
9
 
@@ -20,11 +22,50 @@ def test_anthropic_aliases_include_sonnet() -> None:
20
22
  assert s.anthropic_model_aliases["claude-sonnet-4-5-20250929"] == "claude-sonnet-4-5@20250929"
21
23
 
22
24
 
23
- def test_anthropic_aliases_have_at_sign_format() -> None:
24
- """Vertex expects the '@' format for all model IDs."""
25
+ # Vertex uses two ID conventions, split at the Claude 4.6 generation:
26
+ # * 4.6-gen and later (Opus 4.6/4.7/4.8, Sonnet 4.6) use a DATELESS bare ID;
27
+ # appending '@<date>' makes the Vertex call 404.
28
+ # * pre-4.6 (Sonnet 4.5/4, Opus 4.5, Haiku 4.5) carry a snapshot date that
29
+ # Vertex separates with '@', e.g. claude-haiku-4-5@20251001.
30
+ _DATELESS_46_GEN = {
31
+ "claude-opus-4-8",
32
+ "claude-opus-4-7",
33
+ "claude-opus-4-6",
34
+ "claude-sonnet-4-6",
35
+ }
36
+
37
+
38
+ def test_anthropic_46_gen_aliases_are_dateless() -> None:
39
+ """4.6-generation Vertex IDs are bare (no '@', no date); a suffix 404s."""
40
+ s = Settings()
41
+ for model in _DATELESS_46_GEN:
42
+ vertex_id = s.anthropic_model_aliases[model]
43
+ assert vertex_id == model, f"4.6-gen alias {model!r} must map to bare id, got {vertex_id!r}"
44
+ assert "@" not in vertex_id, (
45
+ f"4.6-gen alias {model!r} must NOT carry '@', got {vertex_id!r}"
46
+ )
47
+
48
+
49
+ def test_anthropic_pre_46_aliases_use_at_sign_date() -> None:
50
+ """Pre-4.6 Vertex IDs separate the snapshot date with '@', never '-'."""
25
51
  s = Settings()
26
52
  for alias, vertex_id in s.anthropic_model_aliases.items():
27
- assert "@" in vertex_id, f"anthropic alias {alias!r} → {vertex_id!r} missing '@'"
53
+ if vertex_id in _DATELESS_46_GEN:
54
+ continue
55
+ assert "@" in vertex_id, f"pre-4.6 alias {alias!r} → {vertex_id!r} missing '@' date sep"
56
+ # The eight digits after '@' must be the snapshot date.
57
+ head, _, date = vertex_id.partition("@")
58
+ assert date.isdigit() and len(date) == 8, f"{alias!r} → {vertex_id!r} bad date segment"
59
+ # The head (model name) must NOT carry a '-YYYYMMDD' dash-date; on Vertex
60
+ # the date is always '@'-separated, never '-' (that is the Claude-API form).
61
+ assert not re.search(r"-\d{8}$", head), f"{alias!r} has a '-' date in {vertex_id!r}"
62
+
63
+
64
+ def test_opus_45_and_haiku_45_use_correct_snapshot_dates() -> None:
65
+ """Opus 4.5 = @20251101 and Haiku 4.5 = @20251001 on Vertex (not @20250929)."""
66
+ s = Settings()
67
+ assert s.anthropic_model_aliases["claude-opus-4-5"] == "claude-opus-4-5@20251101"
68
+ assert s.anthropic_model_aliases["claude-haiku-4-5"] == "claude-haiku-4-5@20251001"
28
69
 
29
70
 
30
71
  def test_gemini_aliases_include_pro_and_flash() -> None:
@@ -0,0 +1,56 @@
1
+ """Unit tests for Ollama backend integration."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import pytest
6
+ from httpx import ASGITransport, AsyncClient
7
+
8
+ from vertex_proxy.config import Settings
9
+ from vertex_proxy.main import build_app
10
+
11
+
12
+ def test_ollama_backends_default_empty() -> None:
13
+ """Ollama backends default to an empty dict."""
14
+ s = Settings()
15
+ assert s.ollama_backends == {}
16
+
17
+
18
+ def test_ollama_backends_explicit_model() -> None:
19
+ """Explicit model-to-URL mapping is parsed correctly."""
20
+ s = Settings(ollama_backends={"qwen3:30b": "http://localhost:11434"})
21
+ assert s.ollama_backends["qwen3:30b"] == "http://localhost:11434"
22
+
23
+
24
+ def test_ollama_backends_wildcard() -> None:
25
+ """Wildcard key '*' is accepted in config."""
26
+ s = Settings(ollama_backends={"*": "http://gpu:11434"})
27
+ assert s.ollama_backends["*"] == "http://gpu:11434"
28
+
29
+
30
+ @pytest.mark.anyio
31
+ async def test_ollama_models_in_v1_models() -> None:
32
+ """Ollama models registered via explicit config appear in /v1/models."""
33
+ settings = Settings(
34
+ ollama_backends={"test-model:7b": "http://fake:11434"},
35
+ )
36
+ app = build_app(settings)
37
+
38
+ # Manually populate the Ollama registry (skip async discovery)
39
+ from vertex_proxy import main as main_mod
40
+
41
+ main_mod._OLLAMA_MODELS["test-model:7b"] = "http://fake:11434"
42
+
43
+ try:
44
+ transport = ASGITransport(app=app)
45
+ async with AsyncClient(transport=transport, base_url="http://test") as client:
46
+ resp = await client.get("/v1/models")
47
+ assert resp.status_code == 200
48
+ data = resp.json()
49
+ model_ids = [m["id"] for m in data["data"]]
50
+ assert "test-model:7b" in model_ids
51
+ # Check owned_by and provider
52
+ ollama_model = [m for m in data["data"] if m["id"] == "test-model:7b"][0]
53
+ assert ollama_model["owned_by"] == "ollama"
54
+ assert ollama_model["provider"] == "ollama"
55
+ finally:
56
+ main_mod._OLLAMA_MODELS.clear()