Setup ​
Install the Anthropic adapter next to the core runtime:
pnpm add @anvia/core @anvia/anthropicConfigure the direct API ​
Set the API key in the server environment:
ANTHROPIC_API_KEY="your-api-key"Create the client in a server-only module:
import { AnthropicClient } from '@anvia/anthropic'
export const anthropic = new AnthropicClient({
apiKey: process.env.ANTHROPIC_API_KEY,
})
export const completionModel = anthropic.completionModel(
'claude-sonnet-4-20250514',
)The constructor fails when neither apiKey nor an existing Anthropic SDK client is supplied. Fail during application startup instead of waiting for the first user request.
Use it with an agent ​
import { AgentBuilder } from '@anvia/core'
import { completionModel } from './anthropic'
export const supportAgent = new AgentBuilder(
'support',
completionModel,
)
.instructions(
'Answer support questions clearly. Use tools for account data.',
)
.defaultMaxTurns(4)
.build()The agent is provider-neutral. Provider selection stays in the model module, which makes testing and later model changes easier.
Use an Anthropic-compatible endpoint ​
Pass a custom baseUrl when a gateway exposes an Anthropic-compatible Messages API:
const client = new AnthropicClient({
apiKey: process.env.PROVIDER_API_KEY,
baseUrl: process.env.PROVIDER_BASE_URL,
})
const model = client.completionModel('provider/model-name')Compatibility labels do not guarantee identical behavior. Smoke test streaming, required tool calls, media blocks, usage reporting, and error responses against the exact endpoint.
Keep credentials out of the browser ​
Browser code should call an application route that owns the agent or completion request. Never expose an Anthropic key through client-side environment variables, serialized props, or a public configuration endpoint.