Skip to content

[Feature] Vertex Express API calls #1441

@stefan-jiroveanu

Description

@stefan-jiroveanu

What Would You Like to See with the Gateway?

Vertex AI API keys only work with Express Mode endpoints, which I think are incompatible with Portkey's current implementation, but I am not really sure.

Context for your Request

Google Cloud Vertex AI supports two authentication methods:

  1. OAuth 2.0 Tokens

    • Works with all Vertex AI endpoints
    • Works with Portkey gateway
    • Requires service account JSON file
  2. API Keys

    • Only works with Express Mode endpoints
    • Blocked on Standard Vertex AI endpoints

What I've tried:

Approach 1: Pass API key directly to Portkey using Authorization header

curl -X POST "http://localhost:8787/v1/chat/completions" \
  -H "x-portkey-provider: vertex-ai" \
  -H "Authorization: Bearer myApiKey" \
  -H "x-portkey-vertex-project-id: myProjectId" \
  -H "x-portkey-vertex-region: myRegion" \
  -d '{
    "model": "gemini-2.5-flash",
    "messages": [{"role": "user", "content": "Say hello"}]
  }'

Result: Failed

{
  "error": {
    "reason": "API_KEY_SERVICE_BLOCKED",
    "message": "Request had invalid authentication credentials. Expected OAuth 2 access token"
  }
}

It looks Portkey routes to Standard Vertex AI endpoints which currently don't support API Key auth.

Approach 2: Use Portkey's custom-host parameter to route to Vertex AI's OpenAI-compatible endpoint

curl -X POST "http://localhost:8787/v1/chat/completions" \
  -H "x-portkey-provider: openai" \
  -H "x-portkey-custom-host: https://aiplatform.googleapis.com/v1/projects/{myProjectId}/locations/{myRegion}/endpoints/openapi" \
  -H "Authorization: Bearer myApiKey" \
  -d '{
    "model": "google/gemini-2.5-flash",
    "messages": [{"role": "user", "content": "Say hello"}]
  }'

Result: Failed

{
  "error": {
    "reason": "API_KEY_SERVICE_BLOCKED",
    "message": "Request had invalid authentication credentials"
  }
}

Tried this due to: https://docs.cloud.google.com/vertex-ai/generative-ai/docs/start/openai

Approach 3: Try to route Portkey to Express Mode using custom-host

curl -X POST "http://localhost:8787/v1/chat/completions" \
  -H "x-portkey-provider: openai" \
  -H "x-portkey-custom-host: https://aiplatform.googleapis.com/v1/publishers/google/models" \
  -H "Authorization: Bearer myApiKey" \
  -d '{
    "model": "gemini-2.5-flash",
    "messages": [{"role": "user", "content": "Say hello"}]
  }'

Result: Failed - 404 Not Found

Why: Portkey appends /v1/chat/completions to the custom host, creating:

https://aiplatform.googleapis.com/v1/publishers/google/models/v1/chat/completions

This endpoint doesn't exist. Express Mode expects:

https://aiplatform.googleapis.com/v1/publishers/google/models/{model}:generateContent

NOTE: Also UI for portkey gateway broke on this specific request, because the response was

{ html: "" }

Not a breaking issue, might worth knowing.

Approach 4: Bypass Portkey and call Express Mode directly with API key

curl -X POST "https://aiplatform.googleapis.com/v1/publishers/google/models/gemini-2.5-flash:generateContent?key=myApiKey" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": {
      "role": "user",
      "parts": {"text": "Say hello"}
    }
  }'

Result: SUCCESS!

{
  "candidates": [{
    "content": {
      "role": "model",
      "parts": [{"text": "Hello there!"}]
    }
  }],
  "usageMetadata": {
    "promptTokenCount": 2,
    "candidatesTokenCount": 3
  }
}

This is an example to showcase that my current setup is working without Portkey, so not an API Key issue.

Your Twitter/LinkedIn

https://www.linkedin.com/in/stefanjiroveanu/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions