Skip to main content
The Atlaso SDK includes an adapter for the AI SDK (the ai package). It gives you a model for one user, and puts the call’s receipt on the result as providerMetadata.atlaso.
ai 6 and 7 both work. ai 7 itself needs Node 22 or newer. For Responses models, also install @ai-sdk/openai.

A model per request

Call createAtlaso() once, at module scope: it holds your key and no user. Inside each request, after your sign-in check, call forUser(userId).chat(model).
With streamText, the receipt is on each step’s finish-step part. The streaming route example sends it to useChat.
  • forUser(id).responses(model) gives a Responses model (needs @ai-sdk/openai). If your bundler cannot load that package on demand, pass its createOpenAI to createAtlaso({ createOpenAI }).
  • forUser(id, { memory: "off", tags: { feature: "chat" } }) sets the same per-call options as the core SDK.
  • forUser(id).memory is the memory API for that user.
  • Stream cost: createAtlaso({ includeUsage: true }) asks the stream for usage, so the receipt has its cost. Left unset, nothing is added to your request and a stream receipt says usage_not_requested.

Memory tools for agents

forUser(id).tools.aiSdk() gives remember, list_memories, and the read-only search_memories tool bound to that user. Search takes a query and an optional limit of 1 to 20. There is no user argument for the model to fill in. forget is added only with { allowForget: true }, and it can delete only facts returned by list_memories or named in a receipt you pass with { receipt }.
Every step of the run, model calls and tool calls alike, carries the same user.

Your own provider, per-call headers

If you keep your own @ai-sdk/openai-compatible provider, build it once without a user and pass the user’s headers on each call. You get no receipt this way; use forUser(id).chat() for receipts.
The dangerous pattern: a user in the provider settings. A provider built at module scope with an x-atlaso-user header sends every request, for every user, as that user. Whoever signs in next gets the first user’s facts.

Choose providers

routing() from atlaso/ai-sdk sets which providers may answer, in what order, and whether a backup may answer. Pass it as providerOptions on a chat() model. It takes the same options and runs the same checks as the core routing(), and sends nothing when no option is set. Responses models (responses()) do not carry it: the adapter throws routing_not_supported instead of dropping it.
To add other options for this provider in the same call, spread the inner object: providerOptions: { atlaso: { ...routing(options).atlaso, reasoningEffort: "low" } }.

Limits

  • There is no receipt before the first token arrives, and none for a stream you abort: the AI SDK sends no finish part then.
  • providerMetadata.atlaso replaces any metadata under the same key from the provider package.
  • If you pass your own core client with createAtlaso({ atlaso }), also pass the same fetch there if you gave it a custom one.