Google Vertex

Google Vertex API Keys

To use Google Vertex AI with OneRouter, you’ll need to provide your Google Cloud service account key in JSON format.

The service account key should include all standard Google Cloud service account fields, with an optional region field for specifying the deployment region.

{
  "type": "service_account",
  "project_id": "your-project-id",
  "private_key_id": "your-private-key-id",
  "private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
  "client_email": "[email protected]",
  "client_id": "your-client-id",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/[email protected]",
  "universe_domain": "googleapis.com",
  "region": "global"
}

You can find these values in your Google Cloud Console:

  1. Service Account Key: Navigate to the Google Cloud Console, go to “IAM & Admin” > “Service Accounts”, click the "+Create service" account button to create a new service account, when complete the process, you will get a JSON key.

  2. region (optional): Specify the region for your Vertex AI deployment.

    1. Use "global" to allow requests to run in any available region

    2. Or specify a specific region like "us-central1" or "europe-west1".

Make sure your service account has the necessary permissions to access Vertex AI services:

  • aiplatform.endpoints.predict

  • aiplatform.endpoints.streamingPredict (for streaming responses)

Example IAM policy:

{
  "bindings": [
    {
      "role": "roles/aiplatform.user",
      "members": [
        "serviceAccount:[email protected]"
      ]
    }
  ]
}

Learn more in the Google Cloud Vertex AI documentation and Service Account setup guide.

Using the OpenAI SDK

from openai import OpenAI

client = OpenAI(
  base_url="https://llm.onerouter.pro/v1",
  api_key="<API_KEY>",
)

completion = client.chat.completions.create(
  byok_conf={
    "provider": "google-vertex",
    "fallback": True,
    "credentials": {
      "type": "service_account",
      "project_id": "your-project-id",
      "private_key_id": "your-private-key-id",
      "private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
      "client_email": "[email protected]",
      "client_id": "your-client-id",
      "auth_uri": "https://accounts.google.com/o/oauth2/auth",
      "token_uri": "https://oauth2.googleapis.com/token",
      "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
      "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/[email protected]",
      "universe_domain": "googleapis.com",
      "region": "global"
    } 
  },
  model="gemini-2.5-pro",
  messages=[
    {
      "role": "user",
      "content": "What is the meaning of life?"
    }
  ]
)

print(completion.choices[0].message.content)
  • byok_conf: When this parameter is included in the input, OneRouter will route requests according to the BYOK configuration information specified. When this parameter is null or not provided, OneRouter defaults to routing to the shared provider pool.

  • provider: Specifies the name of the provider where the request should be routed.

  • fallback: OneRouter always prioritizes using your provider keys when available. By default, if your key encounters a rate limit or failure, OneRouter will fall back to using shared OneRouter credits.

    • The default value for fallback is True.

    • If fallback is specified as False, OneRouter will only use your key for requests to that provider.

  • credentials: The keys and credentials used for authentication with the specified provider.

Using the OneRouter API directly

import requests
import json

response = requests.post(
  url="https://llm.onerouter.pro/v1/chat/completions",
  headers={
    "Authorization": "Bearer <API_KEY>",
    "Content-Type": "application/json"
  },
  data=json.dumps({
    "byok_conf": {
      "provider": "google-vertex",
      "fallback": True,
      "credentials": {
        "type": "service_account",
        "project_id": "your-project-id",
        "private_key_id": "your-private-key-id",
        "private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
        "client_email": "[email protected]",
        "client_id": "your-client-id",
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "token_uri": "https://oauth2.googleapis.com/token",
        "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
        "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/[email protected]",
        "universe_domain": "googleapis.com",
        "region": "global"
        } 
    },
    "model": "gemini-2.5-pro", 
    "messages": [
      {
        "role": "user",
        "content": "What is the meaning of life?"
      }
    ]
  })
)
print(response.json()["choices"][0]["message"]["content"])

Last updated