Vercel AI SDK (Anthropic provider)
@ai-sdk/anthropic with the ai package, on plugboard's Messages API.
Connect
The provider's base URL ends in /v1; it appends /messages:
ts
const baseURL = process.env.PLUGBOARD_BASE_URL! // ends in /v1
const apiKey = process.env.PLUGBOARD_KEY!
export const anthropic = createAnthropic({ baseURL, apiKey })Chat
ts
const { text, finishReason, usage } = await generateText({ model: make(model), prompt: "Reply with exactly: pong", maxOutputTokens: 1024 })Tool calls
The SDK runs execute and sends the follow-up request. Plugboard only returns the call.
ts
const get_weather = tool({
description: "Current weather for a city",
inputSchema: z.object({ city: z.string().describe("City name") }),
execute: async ({ city }) => {
cities.push(city)
return weatherResult
},
})
const result = await generateText({ model: make(model), tools: { get_weather }, stopWhen: isStepCount(4), prompt: PROMPT, maxOutputTokens: 1024 })Structured output
Output.object works with the default structuredOutputMode (which sends output_config.format for Claude models) and with "jsonTool" (a forced tool named json). The example uses "jsonTool":
ts
const { output } = await generateText({
model: make(model),
output: Output.object({ schema: Meal }),
prompt: PROMPT,
maxOutputTokens: 1024,
providerOptions: { anthropic: { structuredOutputMode: "jsonTool" } },
})Limits
- The SDK has no model-list call.
GET /v1/modelsaccepts the same key asx-api-keyorAuthorization: Bearer. - Errors carry
error.typeand noerror.code. - The schema in structured output is not enforced by the provider. Validate the answer.