Prism Vertex allows you to use multiple providers simultaneously, each with its own configuration. This enables you to use different authentication methods, regions, or models for different parts of your application.
Shared configuration
All providers share a single vertex configuration block by default:
return [
'providers' => [
'vertex' => [
'project_id' => env ( 'VERTEX_PROJECT_ID' ),
'location' => env ( 'VERTEX_LOCATION' , 'us-central1' ),
'credentials' => env ( 'VERTEX_CREDENTIALS' ),
],
],
];
With this configuration, all provider constants use the same settings:
use Prism\Prism\ Prism ;
use Prism\Vertex\Enums\ Vertex ;
// All use the same project_id, location, and credentials
$gemini = Prism :: text ()
-> using ( Vertex :: Gemini , 'gemini-2.5-flash' )
-> withPrompt ( 'Hello' )
-> asText ();
$claude = Prism :: text ()
-> using ( Vertex :: Anthropic , 'claude-3-5-sonnet@20241022' )
-> withPrompt ( 'Hello' )
-> asText ();
$mistral = Prism :: text ()
-> using ( Vertex :: Mistral , 'mistral-small-2503' )
-> withPrompt ( 'Hello' )
-> asText ();
Per-provider configuration
You can override the shared configuration for specific providers by adding per-provider config blocks:
return [
'providers' => [
// Shared configuration
'vertex' => [
'project_id' => env ( 'VERTEX_PROJECT_ID' ),
'location' => env ( 'VERTEX_LOCATION' , 'us-central1' ),
'credentials' => env ( 'VERTEX_CREDENTIALS' ),
],
// Override for Anthropic (different region)
'vertex-anthropic' => [
'location' => 'europe-west1' ,
],
// Override for Gemini (API key instead of credentials)
'vertex-gemini' => [
'api_key' => env ( 'VERTEX_GEMINI_API_KEY' ),
],
],
];
Now each provider uses its own configuration:
Uses europe-west1 region: $response = Prism :: text ()
-> using ( Vertex :: Anthropic , 'claude-3-5-sonnet@20241022' )
-> withPrompt ( 'Hello' )
-> asText ();
Configuration:
project_id: from shared config
location: europe-west1 (overridden)
credentials: from shared config
Uses API key authentication: $response = Prism :: text ()
-> using ( Vertex :: Gemini , 'gemini-2.5-flash' )
-> withPrompt ( 'Hello' )
-> asText ();
Configuration:
project_id: from shared config
location: from shared config
api_key: from vertex-gemini config (overridden)
Uses shared configuration: $response = Prism :: text ()
-> using ( Vertex :: Mistral , 'mistral-small-2503' )
-> withPrompt ( 'Hello' )
-> asText ();
Configuration:
project_id: from shared config
location: from shared config
credentials: from shared config
Provider configuration keys
Each provider constant maps to a configuration key:
Provider Constant Config Key Vertex::Geminivertex-geminiVertex::Anthropicvertex-anthropicVertex::Mistralvertex-mistralVertex::Metavertex-metaVertex::DeepSeekvertex-deepseekVertex::AI21vertex-ai21Vertex::Kimivertex-kimiVertex::MiniMaxvertex-minimaxVertex::OpenAIvertex-openaiVertex::Qwenvertex-qwenVertex::ZAIvertex-zai
Common use cases
Here are common scenarios where per-provider configuration is useful:
Different regions for different providers
Use different regions for latency optimization:
return [
'providers' => [
'vertex' => [
'project_id' => env ( 'VERTEX_PROJECT_ID' ),
'location' => 'us-central1' , // Default for most providers
'credentials' => env ( 'VERTEX_CREDENTIALS' ),
],
// Use Europe region for Anthropic
'vertex-anthropic' => [
'location' => 'europe-west1' ,
],
// Use Asia region for Gemini
'vertex-gemini' => [
'location' => 'asia-northeast1' ,
],
],
];
Different authentication methods
Use API key for Gemini (Express mode) and service account for others:
return [
'providers' => [
'vertex' => [
'project_id' => env ( 'VERTEX_PROJECT_ID' ),
'location' => env ( 'VERTEX_LOCATION' ),
'credentials' => env ( 'VERTEX_CREDENTIALS' ),
],
// Use API key for Gemini (Express mode)
'vertex-gemini' => [
'api_key' => env ( 'VERTEX_GEMINI_API_KEY' ),
// Omit project_id and location for Express mode
],
],
];
Express mode only supports Google Gemini models. Partner models require Standard mode with project_id and location.
Different projects for billing separation
Use different GCP projects for cost tracking:
return [
'providers' => [
'vertex' => [
'project_id' => env ( 'VERTEX_PROJECT_ID' ),
'location' => env ( 'VERTEX_LOCATION' ),
'credentials' => env ( 'VERTEX_CREDENTIALS' ),
],
// Use separate project for production Gemini workloads
'vertex-gemini' => [
'project_id' => env ( 'VERTEX_GEMINI_PROJECT_ID' ),
'credentials' => env ( 'VERTEX_GEMINI_CREDENTIALS' ),
],
// Use separate project for experimental Claude workloads
'vertex-anthropic' => [
'project_id' => env ( 'VERTEX_ANTHROPIC_PROJECT_ID' ),
'credentials' => env ( 'VERTEX_ANTHROPIC_CREDENTIALS' ),
],
],
];
Configuration merging
Per-provider configurations are merged with the shared configuration:
The shared vertex configuration provides defaults:
'vertex' => [
'project_id' => 'my-project' ,
'location' => 'us-central1' ,
'credentials' => '/path/to/service-account.json' ,
]
Per-provider config overrides only the specified values:
'vertex-anthropic' => [
'location' => 'europe-west1' ,
]
The final configuration for Vertex::Anthropic is:
[
'project_id' => 'my-project' , // from shared
'location' => 'europe-west1' , // overridden
'credentials' => '/path/to/service-account.json' , // from shared
]
Complete example
Here’s a complete example using multiple providers with different configurations:
return [
'providers' => [
// Shared configuration for most providers
'vertex' => [
'project_id' => env ( 'VERTEX_PROJECT_ID' ),
'location' => 'us-central1' ,
'credentials' => env ( 'VERTEX_CREDENTIALS' ),
],
// Gemini uses Express mode with API key
'vertex-gemini' => [
'api_key' => env ( 'VERTEX_GEMINI_API_KEY' ),
],
// Anthropic uses Europe region
'vertex-anthropic' => [
'location' => 'europe-west1' ,
],
// Meta uses separate project
'vertex-meta' => [
'project_id' => env ( 'VERTEX_META_PROJECT_ID' ),
'credentials' => env ( 'VERTEX_META_CREDENTIALS' ),
],
],
];
Usage:
use Prism\Prism\ Prism ;
use Prism\Vertex\Enums\ Vertex ;
// Uses Express mode (API key only)
$gemini = Prism :: text ()
-> using ( Vertex :: Gemini , 'gemini-2.5-flash' )
-> withPrompt ( 'Hello' )
-> asText ();
// Uses europe-west1 region
$claude = Prism :: text ()
-> using ( Vertex :: Anthropic , 'claude-3-5-sonnet@20241022' )
-> withPrompt ( 'Hello' )
-> asText ();
// Uses separate GCP project
$llama = Prism :: text ()
-> using ( Vertex :: Meta , 'llama-4-scout-17b-16e-instruct-maas' )
-> withPrompt ( 'Hello' )
-> asText ();
// Uses shared config (us-central1, main project)
$mistral = Prism :: text ()
-> using ( Vertex :: Mistral , 'mistral-small-2503' )
-> withPrompt ( 'Hello' )
-> asText ();
Runtime provider options
You can also override configuration at runtime using withProviderOptions():
use Prism\Vertex\Enums\ VertexSchema ;
$response = Prism :: text ()
-> using ( Vertex :: Gemini , 'gemini-2.5-flash' )
-> withProviderOptions ([
'apiSchema' => VertexSchema :: Anthropic , // Override API schema
'jsonModeMessage' => 'Custom JSON instruction' , // Custom JSON message
])
-> withPrompt ( 'Hello' )
-> asText ();
Runtime options override both shared and per-provider configuration. Use with caution.
Available configuration options
All configuration options that can be set:
Option Type Description project_idstring GCP project ID locationstring GCP region (e.g., us-central1) credentialsstring Path to service account JSON file api_keystring API key for authentication apiSchemaVertexSchemaForce specific API schema (Gemini, Anthropic, or OpenAI)
Best practices
Start with shared configuration
Define common settings in the shared vertex config:
'vertex' => [
'project_id' => env ( 'VERTEX_PROJECT_ID' ),
'location' => env ( 'VERTEX_LOCATION' , 'us-central1' ),
'credentials' => env ( 'VERTEX_CREDENTIALS' ),
],
Override only what’s different
Only specify values that differ from the shared config:
// Good: Override only location
'vertex-anthropic' => [
'location' => 'europe-west1' ,
],
// Bad: Repeat all values
'vertex-anthropic' => [
'project_id' => env ( 'VERTEX_PROJECT_ID' ),
'location' => 'europe-west1' ,
'credentials' => env ( 'VERTEX_CREDENTIALS' ),
],
Use environment variables
Store sensitive values in environment variables:
VERTEX_PROJECT_ID = my-project
VERTEX_LOCATION = us-central1
VERTEX_CREDENTIALS = /path/to/service-account.json
VERTEX_GEMINI_API_KEY = your-api-key
VERTEX_ANTHROPIC_PROJECT_ID = anthropic-project
Document your configuration
Add comments explaining why you’re using different settings:
'vertex' => [
'project_id' => env ( 'VERTEX_PROJECT_ID' ),
'location' => 'us-central1' , // Main US region for lowest latency
'credentials' => env ( 'VERTEX_CREDENTIALS' ),
],
// Use Europe region for GDPR compliance
'vertex-anthropic' => [
'location' => 'europe-west1' ,
],
// Use Express mode for development
'vertex-gemini' => [
'api_key' => env ( 'VERTEX_GEMINI_API_KEY' ),
],
Next steps
Text generation Generate text responses using Vertex AI
Structured output Generate JSON responses with schema validation
Embeddings Create text embeddings for semantic search
Configuration View complete configuration reference