Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
6a574ec
feat(js/plugins/anthropic): add community plugin as starter
cabljac Oct 27, 2025
3cf225f
refactor(js/plugins/anthropic): make compatible with monorepo
cabljac Oct 27, 2025
e83d82b
feat(js/plugins/anthropic): convert tests and add test setup
cabljac Oct 27, 2025
f66c101
chore(js/plugins/anthropic): remove retired claude-3-sonnet
HassanBahati Oct 28, 2025
48bc949
chore(js/plugins/anthropic): remove retired claude-35-sonnet
HassanBahati Oct 28, 2025
9403e05
chore(js/plugins/anthropic): format
HassanBahati Oct 28, 2025
81edfdc
chore(js/plugins/anthropic): add supported anthropic models
HassanBahati Oct 29, 2025
1a6ec39
refactor: code improvements
CorieW Nov 3, 2025
1e4246f
fix(anthropic): remove todo comment as unnecessary and replace deprec…
CorieW Nov 3, 2025
885d52e
refactor: allow hidden test client injection
cabljac Nov 4, 2025
381c745
feat: add pdf support and complete some test todos
cabljac Nov 4, 2025
fbb2256
refactor: some small code improvements
cabljac Nov 4, 2025
b87e6b7
feat(js/plugins/anthropic): add .model() shim for convenient model re…
cabljac Oct 27, 2025
ff40bb8
refactor(anthropic): a lot of refactoring and add beta api
CorieW Nov 7, 2025
0ecd9c8
refactor(anthropic): pass in message generics, keep two runners separate
cabljac Nov 10, 2025
85e79c1
refactor(anthropic): clean up classes and types a bit
cabljac Nov 10, 2025
dd9c8b8
refactor(anthropic): tighten up API and tests
cabljac Nov 10, 2025
759fcdf
refactor(anthropic): get tool types from genkit messages instead
cabljac Nov 10, 2025
031dc25
refactor(anthropic): provide beta flag in options and at request conf…
cabljac Nov 10, 2025
e4e4860
refactor(anthropic): extract out types.ts for runner
cabljac Nov 10, 2025
723783c
refactor(anthropic): hoist runners
cabljac Nov 11, 2025
2fd1878
refactor(anthropic): rename classes and add more tests
cabljac Nov 11, 2025
5135664
docs: refresh anthropic plugin branding and attribution
cabljac Nov 11, 2025
7812c8a
refactor(anthropic): add basic testapp and remove nested ternary
cabljac Nov 11, 2025
7e8aaf6
refactor(anthropic): remove redundant factory layer
cabljac Nov 11, 2025
04a3c9e
refactor(anthropic): clean up ABC pattern and generic name
cabljac Nov 11, 2025
d6ed66b
refactor(anthropic): collect up runner param types
cabljac Nov 11, 2025
94771a5
docs(anthropic): document shared helper
cabljac Nov 11, 2025
5f0d0c2
refactor(anthropic): handle stable server tool responses
cabljac Nov 11, 2025
e2840a5
refactor(anthropic): add some code comments and extract web search ma…
cabljac Nov 11, 2025
4086727
feat(anthropic): handle remote image URLs
cabljac Nov 11, 2025
e7d3731
fix(anthropic): some system prompt and image handling issues
cabljac Nov 11, 2025
aaf9314
docs(anthropic): have runner interfaces extend the base interface
cabljac Nov 11, 2025
c3a4658
refactor(anthropic): extract out list function
cabljac Nov 11, 2025
88089d9
refactor(anthropic): clean up list code
cabljac Nov 11, 2025
aadc150
docs(anthropic): update README
cabljac Nov 11, 2025
455899e
fix(anthropic): correct model ids/refs/names
cabljac Nov 11, 2025
a57c03a
chore(anthropic): remove old link in README
cabljac Nov 11, 2025
dfae670
refactor(anthropic): extract magic string
cabljac Nov 11, 2025
509128c
fix(js/plugins/anthropic): pnpm install no frozen lockfile
cabljac Nov 11, 2025
2325311
feat(js/plugins/anthropic): handle extended thinking requests in configs
cabljac Nov 17, 2025
2990cdd
chore(js/plugins/anthropic): update license headers
cabljac Nov 17, 2025
4158750
fix(js/plugins/anthropic): handle webp and text/plain
cabljac Nov 17, 2025
edd7134
test(js/testapps/anthropic): add extra flows for manual tests
cabljac Nov 17, 2025
df96b08
docs(js/plugins/anthropic): update code comments and test app
cabljac Nov 17, 2025
66771ff
fix(js/plugins/anthropic): use genkit logger and update docs
cabljac Nov 17, 2025
74f8539
refactor(js/plugins/anthropic): refactor model references approach to…
cabljac Nov 25, 2025
00cd665
refactor(js/testapps/anthropic): fix commonRef and listActions
cabljac Nov 26, 2025
4c86cda
Update js/plugins/anthropic/package.json
cabljac Nov 26, 2025
0d3f695
refactor(js/plugins/anthropic): remove dedicated workflow
cabljac Nov 26, 2025
8b90519
Merge remote-tracking branch 'upstream/main' into anthropic-plugin
cabljac Nov 26, 2025
00182da
chore(js): regen lockfile to fix builds
cabljac Nov 26, 2025
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
3 changes: 3 additions & 0 deletions js/plugins/anthropic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lib/
node_modules/
coverage/
17 changes: 17 additions & 0 deletions js/plugins/anthropic/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# typescript source files
src/
tests/
tsconfig.json
tsup.common.ts
tsup.config.ts

# GitHub files
.github/
.gitignore
.npmignore
CODE_OF_CONDUCT.md
CONTRIBUTING.md

# Developer related files
.devcontainer/
.vscode/
8 changes: 8 additions & 0 deletions js/plugins/anthropic/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This project includes code derived from the Firebase Genkit Anthropic community plugin
(https://github.com/BloomLabsInc/genkit-plugins/tree/main/plugins/anthropic).

Copyright 2024 Bloom Labs Inc.
Copyright 2025 Google LLC.

Licensed under the Apache License, Version 2.0.
See the LICENSE file distributed with this project for the full license text.
195 changes: 195 additions & 0 deletions js/plugins/anthropic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# Firebase Genkit + Anthropic AI

<h1 align="center">Firebase Genkit <> Anthropic AI Plugin</h1>

<h4 align="center">Anthropic AI plugin for Google Firebase Genkit</h4>

`@genkit-ai/anthropic` is the official Anthropic plugin for [Firebase Genkit](https://github.com/firebase/genkit). It supersedes the earlier community package `genkitx-anthropic` and is now maintained by Google.

## Supported models

The plugin supports the most recent Anthropic models: **Claude Sonnet 4.5**, **Claude Opus 4.1**, **Claude Haiku 4.5**, **Claude Sonnet 4**, **Claude Opus 4**, **Claude 3.5 Haiku**, and **Claude 3 Haiku**.

## Installation

Install the plugin in your project with your favorite package manager:

- `npm install @genkit-ai/anthropic`
- `yarn add @genkit-ai/anthropic`
- `pnpm add @genkit-ai/anthropic`

## Usage

### Initialize

```typescript
import { genkit } from 'genkit';
import { anthropic } from '@genkit-ai/anthropic';

const ai = genkit({
plugins: [anthropic({ apiKey: process.env.ANTHROPIC_API_KEY })],
// specify a default model for generate here if you wish:
model: anthropic.model('claude-sonnet-4-5'),
});
```

### Basic examples

The simplest way to generate text is by using the `generate` method:

```typescript
const response = await ai.generate({
model: anthropic.model('claude-3-haiku'),
prompt: 'Tell me a joke.',
});

console.log(response.text);
```

### Multi-modal prompt

```typescript
// ...initialize Genkit instance (as shown above)...

const response = await ai.generate({
prompt: [
{ text: 'What animal is in the photo?' },
{ media: { url: imageUrl } },
],
config: {
// control of the level of visual detail when processing image embeddings
// Low detail level also decreases the token usage
visualDetailLevel: 'low',
},
});
console.log(response.text);
```

### Extended thinking

Claude 4 models can expose their internal reasoning. Enable it per-request with the Anthropic thinking config and read the reasoning from the response:

```typescript
const response = await ai.generate({
prompt: 'Walk me through your reasoning for Fermat’s little theorem.',
config: {
thinking: {
enabled: true,
budgetTokens: 4096, // Must be >= 1024 and less than max_tokens
},
},
});

console.log(response.text); // Final assistant answer
console.log(response.reasoning); // Summarized thinking steps
```

When thinking is enabled, request bodies sent through the plugin include the `thinking` payload (`{ type: 'enabled', budget_tokens: … }`) that Anthropic's API expects, and streamed responses deliver `reasoning` parts as they arrive so you can render the chain-of-thought incrementally.

### Beta API Limitations

The beta API surface provides access to experimental features, but some server-managed tool blocks are not yet supported by this plugin. The following beta API features will cause an error if encountered:

- `web_fetch_tool_result`
- `code_execution_tool_result`
- `bash_code_execution_tool_result`
- `text_editor_code_execution_tool_result`
- `mcp_tool_result`
- `mcp_tool_use`
- `container_upload`

Note that `server_tool_use` and `web_search_tool_result` ARE supported and work with both stable and beta APIs.

### Within a flow

```typescript
import { z } from 'genkit';

// ...initialize Genkit instance (as shown above)...

export const jokeFlow = ai.defineFlow(
{
name: 'jokeFlow',
inputSchema: z.string(),
outputSchema: z.string(),
},
async (subject) => {
const llmResponse = await ai.generate({
prompt: `tell me a joke about ${subject}`,
});
return llmResponse.text;
}
);
```

### Direct model usage (without Genkit instance)

The plugin supports Genkit Plugin API v2, which allows you to use models directly without initializing the full Genkit framework:

```typescript
import { anthropic } from '@genkit-ai/anthropic';

// Create a model reference directly
const claude = anthropic.model('claude-sonnet-4-5');

// Use the model directly
const response = await claude({
messages: [
{
role: 'user',
content: [{ text: 'Tell me a joke.' }],
},
],
});

console.log(response);
```

You can also create model references using the plugin's `model()` method:

```typescript
import { anthropic } from '@genkit-ai/anthropic';

// Create model references
const claudeSonnet45 = anthropic.model('claude-sonnet-4-5');
const claudeOpus41 = anthropic.model('claude-opus-4-1');
const claude35Haiku = anthropic.model('claude-3-5-haiku');

// Use the model reference directly
const response = await claudeSonnet45({
messages: [
{
role: 'user',
content: [{ text: 'Hello!' }],
},
],
});
```

This approach is useful for:

- Framework developers who need raw model access
- Testing models in isolation
- Using Genkit models in non-Genkit applications

## Acknowledgements

This plugin builds on the community work published as [`genkitx-anthropic`](https://github.com/BloomLabsInc/genkit-plugins/blob/main/plugins/anthropic/README.md) by Bloom Labs Inc. Their Apache 2.0–licensed implementation provided the foundation for this maintained package.

## Contributing

Want to contribute to the project? That's awesome! Head over to our [Contribution Guidelines](CONTRIBUTING.md).

## Need support?

> [!NOTE]
> This repository depends on Google's Firebase Genkit. For issues and questions related to Genkit, please refer to instructions available in [Genkit's repository](https://github.com/firebase/genkit).


## Credits

This plugin is maintained by Google with acknowledgement to the community contributions from [Bloom Labs Inc](https://github.com/BloomLabsInc).

## License

This project is licensed under the [Apache 2.0 License](https://github.com/BloomLabsInc/genkit-plugins/blob/main/LICENSE).
70 changes: 70 additions & 0 deletions js/plugins/anthropic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"name": "@genkit-ai/anthropic",
"description": "Genkit AI framework plugin for Anthropic APIs.",
"keywords": [
"genkit",
"genkit-plugin",
"genkit-model",
"anthropic",
"anthropic-ai",
"claude-4",
"haiku-4",
"opus",
"haiku",
"sonnet",
"ai",
"genai",
"generative-ai"
],
"version": "1.23.0",
"type": "commonjs",
"repository": {
"type": "git",
"url": "https://github.com/firebase/genkit.git",
"directory": "js/plugins/anthropic"
},
"author": "genkit",
"license": "Apache-2.0",
"peerDependencies": {
"genkit": "workspace:^"
},
"dependencies": {
"@anthropic-ai/sdk": "^0.68.0"
},
"devDependencies": {
"@types/node": "^20.11.16",
"check-node-version": "^4.2.1",
"genkit": "workspace:*",
"npm-run-all": "^4.1.5",
"rimraf": "^6.0.1",
"tsup": "^8.3.5",
"tsx": "^4.19.2",
"typescript": "^4.9.0"
},
"types": "./lib/index.d.ts",
"exports": {
".": {
"types": "./lib/index.d.ts",
"require": "./lib/index.js",
"import": "./lib/index.mjs",
"default": "./lib/index.js"
}
},
"files": [
"lib"
],
"publishConfig": {
"provenance": true,
"access": "public"
},
"scripts": {
"check": "tsc",
"compile": "tsup-node",
"build:clean": "rimraf ./lib",
"build": "npm-run-all build:clean check compile",
"build:watch": "tsup-node --watch",
"test": "tsx --test tests/*_test.ts",
"test:file": "tsx --test",
"test:coverage": "check-node-version --node '>=22' && tsx --test --experimental-test-coverage --test-coverage-include='src/**/*.ts' ./tests/**/*_test.ts"
}
}
Loading