
This commit introduces a new language model provider, `anthropic_vertex_ai`, that integrates Anthropic's models via the Google Cloud Vertex AI platform. The implementation uses Google Cloud's Application Default Credentials (ADC) for authentication and fetches `project_id` and `location_id` from the user's settings.
6.5 KiB
Task ID: TA001 - Integrate Anthropic Models via Google Vertex AI**
Objective:
To develop a new language model provider, anthropic_vertex_ai
, that seamlessly integrates Anthropic's models (e.g., Claude) into the Zed editor via the Google Cloud Vertex AI platform.
Background:
While Zed has a direct integration with Anthropic's API, many users operate within the Google Cloud ecosystem. Vertex AI provides access to third-party models like Anthropic's through its own endpoint. This task involves creating a new provider that bridges the existing anthropic
API logic with the authentication and endpoint requirements of Google Cloud.
This integration will not use explicit API keys. Instead, it will leverage Google's Application Default Credentials (ADC), a standard mechanism for authenticating GCP services, ensuring a secure and streamlined user experience. Configuration will be provided through settings.json
to specify the required project_id
and location
for the Vertex AI endpoint.
Key Requirements:
- Authentication: Must use Google Cloud's Application Default Credentials (ADC) for all API requests. The implementation should not handle manual tokens.
- Configuration: The provider must be configurable via
settings.json
, allowing the user to specify their Google Cloudproject_id
andlocation
. - Endpoint Construction: Must dynamically construct the correct Vertex AI endpoint URL for each request, in the format:
https://$LOCATION-aiplatform.googleapis.com/v1/projects/$PROJECT_ID/locations/$LOCATION/publishers/anthropic/models/$MODEL:streamRawPredict
. - Payload Adaptation: The JSON payload sent to the endpoint must be modified to:
- Include the mandatory field:
"anthropic_version": "vertex-2023-10-16"
. - Exclude the
model
field, as it is specified in the URL.
- Include the mandatory field:
- Integration: The new provider must be a first-class citizen within Zed, appearing in the model selection list and functioning identically to other integrated providers.
Implementation Plan:
Step 1: Foundational Analysis & Crate Setup
- Action 1.1: Analyze
google_vertex
Crate: Thoroughly examinecrates/google_vertex/src/google_vertex.rs
to understand its implementation of ADC-based authentication and how it reads settings likeproject_id
andlocation
. This will serve as the template for our authentication logic. - Action 1.2: Define Configuration Struct: In a new file,
crates/anthropic_vertex_ai/src/lib.rs
, define theAnthropicVertexAISettings
struct. This struct will deserialize theproject_id
andlocation
from the user'ssettings.json
. - Action 1.3: Update
Cargo.toml
: Create/update theCargo.toml
file for theanthropic_vertex_ai
crate. It should include dependencies from bothanthropic
(for serde structs) andgoogle_vertex
(for GCP-related dependencies likegcp_auth
). - Action 1.4: Create
lib.rs
: Ensurecrates/anthropic_vertex_ai/src/lib.rs
exists to house theLanguageModelProvider
implementation and serve as the crate's entry point.
Step 2: Adapt Core Anthropic Logic
- Action 2.1: Modify
Request
Struct: Incrates/anthropic_vertex_ai/src/anthropic_vertex_ai.rs
, modify the mainRequest
struct:- Add a new field:
pub anthropic_version: &'static str
. - Remove the existing
pub model: String
field.
- Add a new field:
- Action 2.2: Refactor Completion Functions: Refactor the
stream_completion_with_rate_limit_info
function to be more generic.- It will now accept the fully-constructed Vertex AI endpoint URL as a parameter.
- It will accept an ADC-aware
HttpClient
instance instead of a simple API key. - The logic for setting the
Authorization
header will be updated to use aBearer
token provided by theHttpClient
.
Step 3: Implement the LanguageModelProvider
- Action 3.1: Define Provider Struct: In
crates/anthropic_vertex_ai/src/lib.rs
, define the mainAnthropicVertexAIProvider
struct. It will store the settings defined in Action 1.2. - Action 3.2: Implement
LanguageModelProvider
Trait: Implement thelanguage_model::LanguageModelProvider
trait forAnthropicVertexAIProvider
. - Action 3.3: Implement Core Logic: The trait methods will contain the central logic:
- On initialization, the provider will create an
HttpClient
configured to use Google's ADC, following the pattern in thegoogle_vertex
crate. - For each completion request, it will dynamically construct the full, model-specific Vertex AI URL using the configured
project_id
,location
, and the requested model name. - It will create an instance of the modified
Request
struct fromanthropic_vertex_ai.rs
, setting theanthropic_version
field correctly. - Finally, it will call the refactored
stream_completion_with_rate_limit_info
function, passing the authenticated client and the constructed request.
- On initialization, the provider will create an
Step 4: Final Integration
- Action 4.1: Workspace Integration: Add
anthropic_vertex_ai
to the main workspaceCargo.toml
to link the new crate. - Action 4.2: Module Declaration: Add
pub mod anthropic_vertex_ai;
tocrates/language_models/src/provider.rs
to make the module visible. - Action 4.3: Provider Registration: In
crates/language_models/src/lib.rs
, update the central list of language model providers to include an instance ofAnthropicVertexAIProvider
.
Verification Plan:
- Compile-Time Verification: At each major step, ask the human to review the code for compilation errors and adherence to project standards.
- Configuration Verification: The implementation will be tested against a
settings.json
file configured as follows:"language_servers": { "anthropic-vertex": { "enabled": true, "project_id": "your-gcp-project-id", "location": "europe-west1" } }, "assistant": { "default_model": { "provider": "anthropic-vertex", "name": "claude-sonnet-4@20250514" } }
- Runtime Verification:
- Launch Zed with the above configuration.
- Ensure the local environment is authenticated with GCP (e.g., via
gcloud auth application-default login
). - Open the assistant panel and confirm that
"anthropic-vertex/claude-sonnet-4@20250514"
is the selected model. - Send a test prompt to the assistant.
- Success Condition: A valid, streamed response is received from the assistant, confirming that the entire chain—from configuration and authentication to request execution and response parsing—is working correctly.