
Product
Introducing Socket Scanning for OpenVSX Extensions
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.
@composio/anthropic
Advanced tools
Non-Agentic Provider for Anthropic in Composio SDK.
npm install @composio/anthropic
# or
yarn add @composio/anthropic
# or
pnpm add @composio/anthropic
Required environment variables:
COMPOSIO_API_KEY: Your Composio API keyANTHROPIC_API_KEY: Your Anthropic API keyOptional environment variables:
ANTHROPIC_API_URL: Custom API base URL (defaults to Anthropic's API)import { Composio } from '@composio/core';
import { AnthropicProvider } from '@composio/anthropic';
// Initialize Composio with Anthropic provider
const composio = new Composio({
apiKey: 'your-composio-api-key',
// Initialize with optional caching
provider: new AnthropicProvider({ cacheTools: true }),
});
// Get available tools
const tools = await composio.tools.get('user123', {
toolkits: ['gmail', 'googlecalendar'],
limit: 10,
});
Check out our complete example implementations:
import { Composio } from '@composio/core';
import { AnthropicProvider } from '@composio/anthropic';
import Anthropic from '@anthropic-ai/sdk';
// Initialize Anthropic
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
});
// Initialize Composio
const composio = new Composio({
apiKey: process.env.COMPOSIO_API_KEY,
provider: new AnthropicProvider(),
});
// Get tools
const tools = await composio.tools.get('user123', {
toolkits: ['gmail'],
});
// Create a message with tools
const message = await anthropic.messages.create({
model: 'claude-3-sonnet-20240229',
max_tokens: 1024,
tools: tools,
messages: [
{
role: 'user',
content: 'Send an email to support@example.com',
},
],
});
// Handle tool calls
if (message.content[0].type === 'tool_calls') {
const toolCall = message.content[0];
const result = await composio.provider.executeToolCall('user123', toolCall, {
connectedAccountId: 'account123',
});
console.log('Tool execution result:', result);
}
import { Composio } from '@composio/core';
import { AnthropicProvider } from '@composio/anthropic';
import Anthropic from '@anthropic-ai/sdk';
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
});
const composio = new Composio({
apiKey: process.env.COMPOSIO_API_KEY,
provider: new AnthropicProvider(),
});
const tools = await composio.tools.get('user123', {
toolkits: ['gmail'],
});
const stream = await anthropic.messages.stream({
model: 'claude-3-sonnet-20240229',
max_tokens: 1024,
tools: tools,
messages: [
{
role: 'user',
content: 'Send an email to support@example.com',
},
],
});
for await (const messageChunk of stream) {
if (messageChunk.type === 'content_block_delta' && messageChunk.delta.type === 'tool_calls') {
const result = await composio.provider.executeToolCall('user123', messageChunk.delta, {
connectedAccountId: 'account123',
});
console.log('Tool execution result:', result);
} else {
console.log('Message chunk:', messageChunk);
}
}
The Anthropic provider can be configured with various options:
const provider = new AnthropicProvider({
// Enable tool caching
cacheTools: true,
// Custom execution modifiers
modifiers: {
beforeExecute: params => {
// Transform parameters before execution
return params;
},
afterExecute: response => {
// Transform response after execution
return response;
},
},
});
The AnthropicProvider class extends BaseNonAgenticProvider and provides Anthropic-specific functionality.
new AnthropicProvider(options?: { cacheTools?: boolean })
options.cacheTools: Optional boolean to enable tool caching (default: false)wrapTool(tool: Tool): AnthropicToolWraps a Composio tool in the Anthropic format.
const tool = provider.wrapTool(composioTool);
wrapTools(tools: Tool[]): AnthropicToolCollectionWraps multiple Composio tools in the Anthropic format.
const tools = provider.wrapTools(composioTools);
executeToolCall(userId: string, toolUse: AnthropicToolUseBlock, options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise<string>Executes a tool call from Anthropic and returns the result as a string.
const result = await composio.provider.executeToolCall(
'user123',
{
type: 'tool_use',
id: 'tu_123',
name: 'tool-name',
input: { param: 'value' },
},
{
connectedAccountId: 'account123',
customAuthParams: {
/* ... */
},
},
{
beforeExecute: params => params,
afterExecute: response => response,
}
);
handleToolCalls(userId: string, message: Message, options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise<Anthropic.Messages.MessageParam[]>Processes and executes all tool calls found in an Anthropic message response. This method automatically extracts tool calls from the message content, executes them, and returns their results.
Parameters:
userId (string): The ID of the user making the tool callsmessage (Message): The Anthropic message response containing tool callsoptions (optional): Additional options for tool execution
connectedAccountId: ID of the connected accountcustomAuthParams: Custom authentication parametersmodifiers (optional): Functions to modify tool execution
beforeExecute: Transform parameters before executionafterExecute: Transform response after executionReturns: Promise<Anthropic.Messages.MessageParam[]>: Tool execution results for the assistant message
Example:
const message = {
id: 'msg_123',
content: [
{ type: 'text', text: 'Hello' },
{
type: 'tool_use',
id: 'tu_123',
name: 'test-tool',
input: { param: 'value' },
},
{
type: 'tool_use',
id: 'tu_456',
name: 'another-tool',
input: { param: 'value2' },
},
],
};
const results = await provider.handleToolCalls(
'user123',
message,
{
connectedAccountId: 'account123',
customAuthParams: {
parameters: [{ name: 'token', value: 'abc123', in: 'header' }],
},
},
{
beforeExecute: params => params,
afterExecute: response => response,
}
);
// results will be an array of tool execution responses
// from each tool execution in the order they appeared
// this can be passed directly to LLM
We welcome contributions! Please see our Contributing Guide for more details.
ISC License
For support, please visit our Documentation or join our Discord Community.
FAQs
Non-Agentic Provider for Anthropic in Composio SDK
We found that @composio/anthropic demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.

Product
Bringing supply chain security to the next generation of JavaScript package managers

Product
A safer, faster way to eliminate vulnerabilities without updating dependencies