Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/anthropic-client-injection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@tanstack/ai-anthropic': minor
---

Add `createAnthropicChatWithClient` and `anthropicVertexText` (from
`@tanstack/ai-anthropic/vertex`) so Claude can run on Vertex AI and other
Anthropic-compatible transports.
7 changes: 7 additions & 0 deletions .changeset/vertex-gemini.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@tanstack/ai-gemini': minor
'@tanstack/ai-vertex': minor
---

Add `@tanstack/ai-vertex` for Gemini on Vertex AI, and allow the Gemini
client to start without an API key when Vertex or Enterprise mode is on.
11 changes: 11 additions & 0 deletions .changeset/vertex-grok-mistral.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@tanstack/ai-grok': minor
'@tanstack/ai-mistral': minor
'@tanstack/ai-anthropic': minor
---

Add Vertex AI factories for Grok (`grokVertexText`, `grokVertexSummarize`)
and Mistral (`mistralVertexText`) on `@tanstack/ai-grok/vertex` and
`@tanstack/ai-mistral/vertex`. Vertex factories accept only the chat
models in the Google partner catalog. `anthropicVertexText` now uses
the same Vertex Claude catalog.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ Official adapters include:
| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ |
| [`@tanstack/ai-openrouter`](https://tanstack.com/ai/latest/docs/adapters/openrouter) | 300+ models through one OpenRouter API, with per-request cost tracking |
| [`@tanstack/ai-openai`](https://tanstack.com/ai/latest/docs/adapters/openai) | OpenAI chat, image, video, speech, transcription, realtime, and provider tools |
| [`@tanstack/ai-anthropic`](https://tanstack.com/ai/latest/docs/adapters/anthropic) | Anthropic Claude chat, thinking, tools, and structured outputs |
| [`@tanstack/ai-anthropic`](https://tanstack.com/ai/latest/docs/adapters/anthropic) | Anthropic Claude chat, thinking, tools, structured outputs, and Vertex Claude |
| [`@tanstack/ai-gemini`](https://tanstack.com/ai/latest/docs/adapters/gemini) | Google Gemini chat, image, speech, and audio generation |
| [`@tanstack/ai-vertex`](https://tanstack.com/ai/latest/docs/adapters/vertex) | Gemini on Vertex AI with regional endpoints and Google Cloud credentials |
| [`@tanstack/ai-ollama`](https://tanstack.com/ai/latest/docs/adapters/ollama) | Local Ollama models |
| [`@tanstack/ai-grok`](https://tanstack.com/ai/latest/docs/adapters/grok) | xAI Grok chat, images, and realtime |
| [`@tanstack/ai-groq`](https://tanstack.com/ai/latest/docs/adapters/groq) | Groq low-latency inference |
Expand Down
85 changes: 83 additions & 2 deletions docs/adapters/anthropic.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,68 @@ const config: Omit<AnthropicTextConfig, "apiKey"> = {

const adapter = createAnthropicChat("claude-sonnet-4-6", process.env.ANTHROPIC_API_KEY!, config);
```


## Claude on Vertex

Use `@tanstack/ai-anthropic/vertex` when Claude must run on Vertex AI. That
is the path for regional endpoints and Google Cloud credentials.

Install the Vertex SDK next to the Anthropic adapter:

```bash
npm install @tanstack/ai-anthropic @anthropic-ai/vertex-sdk
```

```typescript
import { chat } from "@tanstack/ai";
import { anthropicVertexText } from "@tanstack/ai-anthropic/vertex";

const stream = chat({
adapter: anthropicVertexText("claude-sonnet-5", {
project: "my-project",
location: "europe-west1",
}),
messages: [{ role: "user", content: "Hello!" }],
});
```

`anthropicVertexText` accepts only the Claude models in the Vertex catalog.
It does not accept Anthropic-only ids such as `claude-opus-5-fast`.

`project` and `location` use the same names as `@tanstack/ai-vertex`, so one
auth object works for Gemini and Claude.

If you omit `project`, Application Default Credentials can still fill it.
`location` is required. You can pass it on the factory or set
`GOOGLE_CLOUD_LOCATION`, `GOOGLE_VERTEX_LOCATION`, or `CLOUD_ML_REGION`.

Gemini on Vertex lives in [`@tanstack/ai-vertex`](./vertex).

## Custom Anthropic client

Use `createAnthropicChatWithClient` when you already have an
Anthropic-compatible client. The adapter only needs `beta.messages.create`.
Message mapping, streaming, tools, media, usage, and structured output stay
on the same TanStack path.

```bash
npm install @tanstack/ai-anthropic @anthropic-ai/vertex-sdk
```

```typescript
import { AnthropicVertex } from "@anthropic-ai/vertex-sdk";
import { createAnthropicChatWithClient } from "@tanstack/ai-anthropic";

const client = new AnthropicVertex({
projectId: "my-project",
region: "europe-west1",
});

const adapter = createAnthropicChatWithClient("claude-sonnet-5", client);
```

The injected client must implement the Anthropic Beta Messages protocol.
Endpoint-specific model and feature support stays the caller's job.

## Example: Chat Completion

Expand Down Expand Up @@ -257,7 +318,7 @@ ANTHROPIC_API_KEY=sk-ant-...

## API Reference

Every factory pair follows the same shape: the short factory (`anthropicText`, `anthropicSummarize`) reads `ANTHROPIC_API_KEY` from the environment, while `createAnthropicChat` / `createAnthropicSummarize` take an explicit API key. Both take `model` as the first argument.
Every factory pair follows the same shape: the short factory (`anthropicText`, `anthropicSummarize`) reads `ANTHROPIC_API_KEY` from the environment, while `createAnthropicChat` / `createAnthropicSummarize` take an explicit API key. Both take `model` as the first argument. For Claude on Vertex, use `anthropicVertexText` from `@tanstack/ai-anthropic/vertex`. For any other custom transport, `createAnthropicChatWithClient` accepts an Anthropic-compatible Messages client.

### `anthropicText(model, config?)` / `createAnthropicChat(model, apiKey, config?)`

Expand All @@ -268,6 +329,26 @@ Creates an Anthropic chat adapter.
- `model` - Claude model id (e.g. `"claude-sonnet-5"`, `"claude-fable-5"`, `"claude-opus-4-8"`)
- `config?.baseURL` - Custom base URL (optional)

### `anthropicVertexText(model, config?)`

Creates an Anthropic chat adapter on Vertex. Import it from
`@tanstack/ai-anthropic/vertex`.

**Parameters:**

- `model` - Claude model id
- `config.project` - GCP project id (optional if ADC can resolve it)
- `config.location` - Vertex region (or set `GOOGLE_CLOUD_LOCATION`)

### `createAnthropicChatWithClient(model, client)`

Creates an Anthropic chat adapter using an injected client.

**Parameters:**

- `model` - Claude model id
- `client` - Client exposing `beta.messages.create`

### `anthropicSummarize(model, config?)` / `createAnthropicSummarize(model, apiKey, config?)`

Creates an Anthropic summarization adapter.
Expand Down
2 changes: 2 additions & 0 deletions docs/adapters/gemini.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ For a full working example with image generation, see the [media generation exam
npm install @tanstack/ai-gemini
```

Need Gemini on Vertex AI (regional endpoints and Google Cloud credentials)? Use the [Vertex adapter](./vertex).

## Basic Usage

```typescript
Expand Down
44 changes: 44 additions & 0 deletions docs/adapters/grok.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,50 @@ const config: Omit<GrokTextConfig, "apiKey"> = {
const adapter = createGrokText("grok-build-0.1", process.env.XAI_API_KEY!, config);
```

## Grok on Vertex

Use `@tanstack/ai-grok/vertex` when Grok must run on Vertex AI. That path
uses Google Cloud credentials and Vertex regional or global endpoints.

```bash
npm install @tanstack/ai-grok google-auth-library
```

```typescript
import { chat } from "@tanstack/ai";
import { grokVertexText } from "@tanstack/ai-grok/vertex";

const stream = chat({
adapter: grokVertexText("grok-4.3", {
project: "my-project",
location: "global",
}),
messages: [{ role: "user", content: "Hello!" }],
});
```

`project` and `location` use the same names as `@tanstack/ai-vertex`. If you
omit `location`, the factory uses `global`.

`grokVertexText` accepts only the Grok chat models that Vertex lists:

- `grok-4.3`
- `grok-4.20-reasoning`
- `grok-4.20-non-reasoning`
- `grok-4.1-fast-reasoning`
- `grok-4.1-fast-non-reasoning`

xAI API models such as `grok-4.6` and `grok-build-0.1` are not on Vertex.

The adapter sends the Vertex model id `xai/grok-4.3`. Install
`google-auth-library` for Application Default Credentials, or pass
`authClient` or `getAccessToken`.

Use `grokVertexSummarize` from the same entry when you need summarize on
Vertex.

Gemini on Vertex lives in [`@tanstack/ai-vertex`](./vertex).

## Example: Chat Completion

```typescript
Expand Down
42 changes: 42 additions & 0 deletions docs/adapters/mistral.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,48 @@ const adapter = createMistralText(
);
```

## Mistral on Vertex

Use `@tanstack/ai-mistral/vertex` when Mistral must run on Vertex AI. That
path uses Google Cloud credentials and the publisher `rawPredict` endpoint.

Mistral on Vertex is regional only. Use `us-central1` or `europe-west4`.

```bash
npm install @tanstack/ai-mistral google-auth-library
```

```typescript
import { chat } from "@tanstack/ai";
import { mistralVertexText } from "@tanstack/ai-mistral/vertex";

const stream = chat({
adapter: mistralVertexText("mistral-medium-3", {
project: "my-project",
location: "europe-west4",
}),
messages: [{ role: "user", content: "Hello!" }],
});
```

`project` and `location` use the same names as `@tanstack/ai-vertex`.
`location` is required.

`mistralVertexText` accepts only the Mistral chat models that Vertex lists:

- `mistral-medium-3`
- `mistral-small-2503`
- `codestral-2`

Mistral API aliases such as `mistral-large-latest` and `mistral-medium-latest`
are not Vertex model ids. Vertex also lists `mistral-ocr-2505`, but that
model is OCR, not chat.

Install `google-auth-library` for Application Default Credentials, or pass
`authClient` or `getAccessToken`.

Gemini on Vertex lives in [`@tanstack/ai-vertex`](./vertex).

## Example: Chat Completion

```typescript
Expand Down
Loading
Loading