Skip to main content
Anthropic Claude models are available through Vertex AI using the :rawPredict endpoint with the Anthropic Messages API format.

Provider constant

Use the Vertex::Anthropic constant to access Claude models:
use Prism\Vertex\Enums\Vertex;

Vertex::Anthropic  // 'vertex-anthropic'

Configuration

Claude models use the shared vertex configuration block:
'vertex' => [
    'project_id'  => env('VERTEX_PROJECT_ID'),
    'location'    => env('VERTEX_LOCATION', 'us-central1'),
    'credentials' => env('VERTEX_CREDENTIALS'), // path to service-account.json
],
Express mode is not supported for Claude models. You must provide a project ID and location.

Per-provider configuration

You can override the shared configuration for Claude models only:
'vertex' => [
    'project_id'  => env('VERTEX_PROJECT_ID'),
    'location'    => env('VERTEX_LOCATION', 'us-central1'),
    'credentials' => env('VERTEX_CREDENTIALS'),
],

// Override for Anthropic only (e.g. different region)
'vertex-anthropic' => [
    'location' => 'europe-west1',
],

API schema

Claude models use the Anthropic schema, which provides:
  • :rawPredict endpoint with Anthropic Messages API format
  • API version: vertex-2023-10-16
  • Publisher: anthropic
  • Supports text generation and structured output
  • No native embeddings support

Example models

  • claude-3-5-sonnet@20241022
  • claude-3-5-haiku@20241022
  • claude-3-opus@20240229
  • claude-3-sonnet@20240229
  • claude-3-haiku@20240307
Claude model names use versioned identifiers with @ symbols (e.g., @20241022). This ensures you’re using a specific model version.

Usage examples

Text generation

use Prism\Prism\Prism;
use Prism\Vertex\Enums\Vertex;

$response = Prism::text()
    ->using(Vertex::Anthropic, 'claude-3-5-sonnet@20241022')
    ->withPrompt('Explain quantum computing in simple terms')
    ->asText();

echo $response->text;

Structured output

Claude models don’t have native JSON mode, so Prism Vertex appends a schema instruction to your prompt:
use Prism\Prism\Prism;
use Prism\Vertex\Enums\Vertex;
use Prism\Prism\Schema\ObjectSchema;
use Prism\Prism\Schema\StringSchema;
use Prism\Prism\Schema\ArraySchema;

$schema = new ObjectSchema(
    name: 'languages',
    description: 'Top programming languages',
    properties: [
        new ArraySchema(
            'languages',
            'List of programming languages',
            items: new ObjectSchema(
                name: 'language',
                description: 'Programming language details',
                properties: [
                    new StringSchema('name', 'The language name'),
                    new StringSchema('popularity', 'Popularity description'),
                ]
            )
        )
    ]
);

$response = Prism::structured()
    ->using(Vertex::Anthropic, 'claude-3-5-sonnet@20241022')
    ->withSchema($schema)
    ->withPrompt('List the top 3 programming languages')
    ->asStructured();

$data = $response->structured;

Custom JSON instruction

You can customize the JSON schema instruction prompt:
$response = Prism::structured()
    ->using(Vertex::Anthropic, 'claude-3-5-sonnet@20241022')
    ->withSchema($schema)
    ->withProviderOptions([
        'jsonModeMessage' => 'Respond with valid JSON conforming to this schema: {schema}',
    ])
    ->withPrompt('List the top 3 programming languages')
    ->asStructured();
The {schema} placeholder will be replaced with your JSON schema.

Multi-turn conversation

use Prism\Prism\Prism;
use Prism\Vertex\Enums\Vertex;
use Prism\Prism\ValueObjects\Messages\UserMessage;
use Prism\Prism\ValueObjects\Messages\AssistantMessage;

$response = Prism::text()
    ->using(Vertex::Anthropic, 'claude-3-5-haiku@20241022')
    ->withMessages([
        new UserMessage('What is the capital of France?'),
        new AssistantMessage('The capital of France is Paris.'),
        new UserMessage('What is its population?'),
    ])
    ->asText();

echo $response->text;

Capabilities

Text generation

Full support for text generation with multi-turn conversations

Structured output

Structured output via prompt-based JSON instruction

Limitations

  • No native embeddings support
  • Requires Standard mode (project ID + location)
  • Structured output relies on prompt instruction, not native constraints

API version

The Anthropic schema uses API version vertex-2023-10-16 by default. This is the Anthropic Messages API format adapted for Vertex AI.

Next steps

Structured output

Learn more about structured output

Configuration

See all configuration options

Build docs developers (and LLMs) love