ajyadav013/claude-kit/anthropic-vertex-integration
Claude Code and agent skill by ajyadav013/claude-kit
Trust tier 3
- community
Source check pending
Checking that the SKILL.md file is still in the repository.
Claude on Vertex AI via the AnthropicVertex SDK — lazy ADC client init, env-based project/region resolution, async helpers, backoff retry. Use when calling Claude via GCP Vertex AI (not direct Anthropic API).
Install
npx vskill@latest install ajyadav013/claude-kit/anthropic-vertex-integrationSKILL.md
The same SKILL.md was published earlier as ajyadav013/claude-kit/anthropic-vertex-integration.
Integrate Claude on Vertex AI using the AnthropicVertex SDK with lazy authentication, resilient helpers, and optional tracing.
When to use
- Calling Claude via Google Cloud Vertex AI (not the direct Anthropic API with API keys)
- Building async helpers for one-shot completions, JSON extraction, or tool-use calls
- Implementing exponential-backoff retry for transient Vertex AI errors
- Composing system prompts from personas or task instructions
- Adding Langfuse observability to Claude completions (latency, input/output, errors)
- Migrating from direct Anthropic SDK (API-key auth) to Vertex AI (ADC auth)
- Setting up lazy client initialization with env-var-based project/region resolution
- Creating a reusable LazyClient pattern for SDK singletons with test reset hooks
Core conventions
- AnthropicVertex SDK installation: install with
pip install 'anthropic[vertex]'(the[vertex]extra is required). The SDK uses Google Cloud Application Default Credentials (ADC) — rungcloud auth application-default loginlocally or rely on service-account credentials in production (GOOGLE_APPLICATION_CREDENTIALS env var).
- Project-ID resolution fallback chain:
_resolve_project_id(project_id)checksproject_idparameter →VERTEX_PROJECT_ID→BQ_PROJECT_ID→GOOGLE_CLOUD_PROJECT→GCLOUD_PROJECTenv vars in order, raisingValueErrorif all are empty. This lets BigQuery-focused services reuseBQ_PROJECT_IDfor Vertex calls without duplicating config.
- Region/location resolution:
_resolve_location(location)checkslocationparameter →VERTEX_LOCATIONorGOOGLE_CLOUD_LOCATIONenv vars → a default (e.g.,us-central1,us-east5). Claude on Vertex AI is available in specific regions; check Vertex AI docs for current list.
- Lazy client factory:
get_vertex_client(project_id, location) -> (client, resolved_project, resolved_location)importsAnthropicVertexlazily (raisingImportErrorwith install hint if missing), resolves project/location, and returns(AnthropicVertex(project_id=..., region=...), project, location). Construct on each call for simplicity, or wrap in aLazyClient[AnthropicVertex]singleton (see references) for caching and test-reset support.
- Async messages.create wrapper:
async def generate_text(user_prompt, *, system=None, model="claude-sonnet-4-6", max_tokens=4096, max_retries=5)callsclient.messages.create(model=model, max_tokens=max_tokens, system=system, messages=[{"role": "user", "content": user_prompt}]), concatenatesresponse.contenttext blocks, and returnsstr. Wrap the call in a retry loop with exponential backoff (see #6).
- Exponential-backoff retry: wrap
client.messages.create()in afor attempt in range(max_retries)loop. On exception, sleepdelayseconds (starting at 1), doubledelay, and retry. On the last attempt, re-raise the error. Log each retry attempt with attempt number and delay.
- JSON extraction helper:
async def generate_json_text(...)appends\n\nIMPORTANT: You MUST respond with valid JSON only. Do not include any text outside the JSON structure.to the system prompt and passesresponse_mime_type="application/json"as metadata (not a native Anthropic param; used for tracing only). Returns raw text; caller parses JSON. Optionally defineextract_json(text)to strip\\\jsonfences via regex andjson.loads(), falling back to the first{...}` match if the full string fails.
- System-prompt composition: define
build_system_prompt(personas: Iterable[str], task_instruction: str) -> strto load persona templates from apersonas/directory and concatenate them with the task instruction. This separates role definition from task-specific context. Personas are reusable across tasks.
- LazyClient pattern for caching: define a generic
LazyClient[T]that takes aCallable[[], T]factory, buildsTon first.get(), caches it, and exposes.reset()for tests. Use as_client = LazyClient(_build_client); client() -> AnthropicVertex: return _client.get(). This defers GCP credential checks until first use and lets tests reset the client after env-var changes.
- Langfuse tracing wrapper: define
trace_completion(name, model, provider="anthropic-vertex", metadata=None)as a context manager that yields a_CompletionTracerwithset_input(prompt),set_output(text),set_error(exc)methods. On context exit, flush to Langfuse if enabled (lazy singletonget_langfuse()). Degrades to no-op ifLANGFUSE_ENABLED=falseor keys are missing. Env vars:LANGFUSE_PUBLIC_KEY,LANGFUSE_SECRET_KEY,LANGFUSE_HOST. Install withpip install langfuse.
- Model selection via env vars: define a settings singleton with
CLAUDE_SONNET_MODEL(defaultclaude-sonnet-4-6),CLAUDE_OPUS_MODEL, etc. Usemodel = model or settings.sonnet_modelin helpers. Current Vertex AI Claude models:claude-sonnet-4-6,claude-sonnet-4@20250514,claude-3-5-sonnet-v2@20241022,claude-3-5-haiku@20241022.
- Vision (image input) support:
complete_with_vision(prompt, images, ...)builds acontentlist with image blocks (either{"type": "image", "source": {"type": "url", "url": ...}}or{"type": "image", "source": {"type": "base64", "media_type": "image/jpeg", "data": ...}}) followed by a text block. Supported MIME types:image/jpeg,image/png,image/gif,image/webp. Pass tomessages=[{"role": "user", "content": content}].
- Tool-use (function calling) support:
complete_with_tools(messages, tools, ...)passes a multi-turn conversation history (messages: list[dict]) andtools: list[dict](Anthropic tool-definition format) toclient.messages.create(). Returns the fullMessageresponse object so caller can inspectresponse.stop_reasonand iterateresponse.contentfortool_useblocks, execute tools, and appendtool_resultmessages for the next turn.
- Sync vs async SDK: the
anthropicSDK is sync-only (as of 2025-06). If your app is async, wrapclient.messages.create()inasyncio.get_event_loop().run_in_executor(None, call_create)to avoid blocking the event loop. The examples above useasync defwith nativeawait client.messages.create()—this assumes a hypothetical async SDK; adjust to executor pattern if using the current sync SDK.
- Streaming responses:
client.messages.stream()returns a context manager yielding text chunks. Wrap in executor and yield chunks via an async generator. Not shown in examples; see Anthropic SDK docs for stream API.
Skeleton / example
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/anthropic-vertex-integration/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ajyadav013/claude-kit/anthropic-vertex-integration)