Using a model
Give the generator a provider, and a model designs the block. @rudra-js/anthropic connects Claude. Any other model works through an adapter you write.
Connecting Claude
Install the adapter next to core:
npm install @rudra-js/anthropic@latest @rudra-js/core@latest @rudra-js/attested@latestIf your app has @rudra-js/react, add it to the line with @latest too. The quick start says why every name needs it.
import { createAnthropicProvider } from '@rudra-js/anthropic';
import { createComponentGenerator } from '@rudra-js/core';
const provider = createAnthropicProvider({ apiKey: process.env.ANTHROPIC_API_KEY! });
export const generator = createComponentGenerator({ provider });apiKeyis the only option you have to pass.createAnthropicProviderlists the rest.- Create the generator once, at the top of a module, so every request shares its cache.
- Before you call it done, check that the model answered.
What the model changes
The model writes the layout, the headings and the copy. In the default mode, core still picks the products for each shopper. What the model decides has the full split.
Core checks every block the model writes before it reaches the page. When the model fails or runs out of time, the shopper gets the block core builds without a model.
Letting the model pick the products
Pass generation: 'per-shopper', and the model writes a block for each shopper.
import { createAnthropicProvider } from '@rudra-js/anthropic';
import { createComponentGenerator } from '@rudra-js/core';
export const generator = createComponentGenerator({
provider: createAnthropicProvider({ apiKey: process.env.ANTHROPIC_API_KEY! }),
generation: 'per-shopper',
});- The model picks which of your candidates to show, and in what order.
- It writes the line and the badge under each product. Core checks both before they reach the page.
- The model is sent the shopper's own signals, such as what they liked and searched for. What the model sees lists them.
- Every shopper gets a model call of their own, so you pay for more calls.
Read Running it in a regulated shop before you turn this on for real shoppers.
Picking another Claude model
Pass model to the adapter, and raise the generator's modelTimeoutMs to fit it. Picking another Claude model shows both, and names the models that also need thinking: null.
Using a model other than Claude
Core takes any object with a name, a model and a generate method. It can call a hosted API, a model you run yourself, or one deployed in your own cloud account. In tests, it can answer with a reply you recorded. Core depends on no model vendor's SDK.
ComponentProvider has the full shape and an adapter you can start from.
Where the calls go
Each model call is one POST to /v1/messages on api.anthropic.com. What the model sees lists what it holds. It can be personal data, even though it never names the shopper.
If your shop is in the EU or the UK, or sells to shoppers there, you're the one sending personal data out. You need a data processing agreement with whoever receives it. If they are outside the EU and the UK, you also need a transfer mechanism. This holds even when your shop itself is outside both.
With a key from your own Anthropic account, the receiver is Anthropic. Anthropic's data processing addendum is part of its Commercial Terms. It makes Anthropic your processor and includes the transfer clauses. A proxy you run yourself doesn't change that.
If you point baseUrl at a gateway or platform someone else runs, its operator receives the calls too. With a key from your own Anthropic account, Anthropic is still your processor, and the operator is a second one. You need a data processing agreement with the operator as well. When the platform issued the key, Anthropic says the platform's terms govern that use. Then the platform's agreement is the one that covers you.
@rudra-js/anthropic is code that runs in your app. It isn't a party to any of these agreements. For the rest of what a privacy review asks, see Running it in a regulated shop.