A complete guide to bridging Google Cloud Platform (GCP) Vertex AI with OpenCode using vertexproxy.rs — a lightweight, high-performance Rust proxy that translates OpenAI Chat Completion requests into Vertex AI calls.
OpenCode relies on standard OpenAI-compatible providers for custom endpoints. However, GCP Vertex AI uses:
- Google Cloud IAM & OAuth2 authentication (instead of static API keys).
- The proprietary Vertex AI
generateContent/streamGenerateContentREST API. - Proprietary thinking signatures across tool-calling loops in newer Gemini models.
vertexproxy.rs bridges this gap transparently:
- Zero auth friction: Reads
gcloudApplication Default Credentials (ADC) and handles automatic OAuth2 token refreshes in the background. - Thinking state preservation: Encodes Gemini thought signatures into OpenAI tool-call IDs (
<id>__<function>__thought__<sig>) so multi-turn agentic tool calling in OpenCode retains full reasoning context. - Blazingly fast & resource light: Written in Rust (Axum/Tokio), runs as a background daemon using under 15MB of RAM.
- Streaming & Function Calling: Full SSE streaming (
stream: true) and tool declaration/execution compatibility.
┌──────────────┐ OpenAI HTTP / SSE ┌──────────────────┐ Vertex REST API ┌─────────────────────────┐
│ OpenCode │ ──────────────────────> │ vertex-proxy │ ────────────────────> │ GCP Vertex AI │
│ Agent │ <────────────────────── │ (localhost:8000) │ <──────────────────── │ (aiplatform.googleapis)│
└──────────────┘ └────────┬─────────┘ └─────────────────────────┘
│
Refreshes OAuth token
▼
~/.config/gcloud/
application_default_credentials.json
vertex-proxy uses User Account Application Default Credentials (ADC) with the OAuth refresh-token flow.
- Install Google Cloud SDK (
gcloud) if you haven't already. - Authenticate user ADC with Cloud Platform scopes:
gcloud auth application-default login \ --scopes=https://www.googleapis.com/auth/cloud-platform
- Set your active quota / default project:
(Ensure the Vertex AI API (
gcloud config set project YOUR_GCP_PROJECT_IDaiplatform.googleapis.com) is enabled in your GCP project).
Clone and build the binary using Cargo:
# Clone the repository
git clone https://github.com/morawskidotmy/vertexproxy.rs.git
cd vertexproxy.rs
# Build the optimized release binary
cargo build --release
# Copy to your local user bin path
mkdir -p ~/.local/bin
cp target/release/vertex-proxy ~/.local/bin/Verify it runs:
~/.local/bin/vertex-proxy --helpTo keep vertex-proxy running automatically in the background without manual terminal sessions, manage it via a systemd user service.
- Create the unit file at
~/.config/systemd/user/vertex-proxy.service:
[Unit]
Description=Vertex AI OpenAI-Compatible Proxy (Rust)
After=network.target
[Service]
Type=simple
ExecStart=%h/.local/bin/vertex-proxy
Restart=always
RestartSec=3
Environment=PORT=8000
Environment=VERTEX_PROXY_HOST=127.0.0.1
Environment=VERTEX_LOCATION=global
Environment=RUST_LOG=info
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=default.targetConfiguration Options:
PORT/VERTEX_PROXY_PORT: Default8000.VERTEX_PROXY_HOST: Bind address (default127.0.0.1).VERTEX_LOCATION: Vertex AI region (e.g.,global,us-central1,europe-west1). Default isglobal.VERTEX_PROJECT_ID: (Optional) Explicit GCP project ID override if not specified in your ADC file.
- Reload systemd, enable, and start the service:
systemctl --user daemon-reload
systemctl --user enable --now vertex-proxy- Check service status:
systemctl --user status vertex-proxyEdit your OpenCode configuration file (typically ~/.config/opencode/opencode.jsonc or ~/.config/opencode/opencode.json).
Register vertex-proxy as an OpenAI-compatible provider using @ai-sdk/openai-compatible:
curl http://127.0.0.1:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3.8-flash",
"messages": [
{"role": "user", "content": "Respond with 'Vertex Proxy is live!'."}
]
}'Start OpenCode and switch to any of the configured Vertex models:
opencode --model vertex-proxy/gemini-3.8-flashOr switch to it directly inside the OpenCode TUI / Web model picker (/model).
- View Live Logs: Monitor incoming tool calls, prompt tokens, and Vertex responses:
journalctl --user -u vertex-proxy -f
- Token Refresh: User ADC credentials expire periodically.
vertex-proxyrefreshes tokens automatically using the refresh token inside~/.config/gcloud/application_default_credentials.json. If your credentials ever get revoked, simply re-run:gcloud auth application-default login --scopes=https://www.googleapis.com/auth/cloud-platform
- Service Accounts vs User ADC: Use
gcloud auth application-default loginrather than a static service account key JSON file, as the proxy relies on the OAuth refresh-token exchange flow.
{ "$schema": "https://opencode.ai/config.json", "providers": { "vertex-proxy": { "package": "aisdk:@ai-sdk/openai-compatible", "settings": { "baseURL": "http://127.0.0.1:8000/v1" }, "models": { "gemini-3.8-flash": {}, "gemini-3.7-flash": {}, "gemini-3.6-flash": {}, "gemini-3.5-flash": {}, "gemini-3.5-flash-lite": {}, "gemini-3.1-flash-lite": {}, "gemini-3.1-pro-preview": {}, "gemini-3-flash-preview": {}, "gemini-2.5-pro": {}, "gemini-2.5-flash": {}, "gemini-2.5-flash-lite": {} } } } }