Provider deployment ID: Deploy a provider (e.g., Exa for search) from the dashboard
AI provider API key: OpenAI, Anthropic, Google, etc.
Installation
The Metorial SDK consists of two parts: the core SDK (which handles sessions and tool management) and a provider package (which integrates with your chosen AI model). Install both to get started.
$
# Install the core SDK
npm install metorial
# Install a provider package (choose one or more)
npm install @metorial/ai-sdk # Vercel AI SDK (recommended)
npm install @metorial/anthropic # Anthropic Claude
npm install @metorial/openai # OpenAI
npm install @metorial/google # Google Gemini
npm install @metorial/mistral # Mistral
npm install @metorial/deepseek # DeepSeek
$
# Install the SDK
pip install metorial
# Install your AI provider
pip install anthropic # For Claude
pip install openai # For OpenAI/DeepSeek
We support OpenAI, Anthropic, Google, Mistral, DeepSeek, and any OpenAI-compatible API. See the TypeScript SDK and Python SDK repos for all available providers.
Your first AI agent
This example shows how to create an AI agent that can use tools from your deployed providers. The agent will have access to any tools provided by your provider deployment (like search, file operations, or API calls).
What this code does:
Initializes the Metorial SDK with your API key
Creates a session connected to your provider deployment
Passes the available tools to your AI model
Handles tool calls in an agentic loop
import { Metorial } from 'metorial';import { metorialAiSdk } from '@metorial/ai-sdk';import { anthropic } from '@ai-sdk/anthropic';import { stepCountIs, streamText } from 'ai';let metorial = new Metorial({ apiKey: process.env.METORIAL_API_KEY});let session = await metorial.connect({ adapter: metorialAiSdk(), providers: [ { providerDeploymentId: 'your-provider-deployment-id' } ]});let result = streamText({ model: anthropic('claude-sonnet-4-20250514'), prompt: 'Search for the latest AI research', stopWhen: stepCountIs(10), tools: session.tools()});for await (let textPart of result.textStream) { process.stdout.write(textPart);}
from metorial import Metorial, metorial_anthropicfrom anthropic import AsyncAnthropicimport asyncioimport osmetorial = Metorial(api_key=os.getenv("METORIAL_API_KEY"))anthropic = AsyncAnthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))async def main(): session = await metorial.connect( adapter=metorial_anthropic(), providers=[{"provider_deployment_id": "your-provider-deployment-id"}], ) response = await anthropic.messages.create( model="claude-sonnet-4-20250514", max_tokens=1024, tools=session.tools(), messages=[{"role": "user", "content": "What's trending on Hacker News?"}], ) if response.stop_reason == "tool_use": tool_calls = [b for b in response.content if b.type == "tool_use"] results = await session.call_tools(tool_calls) # Add results to messages and continue conversation...asyncio.run(main())
OAuth flow
For services requiring user authentication (like Slack, GitHub, or Google Calendar), use a Provider Setup Session to authorize your users. The resulting Provider Auth Config stores their credentials for reuse.
The flow:
Create a Provider Setup Session for each service that needs authentication
Redirect your user to the session URL to complete OAuth
Wait for the setup session to complete — you get back an auth config
Pass the auth config ID when creating sessions for that user
import { Metorial } from 'metorial';import { metorialAnthropic } from '@metorial/anthropic';let metorial = new Metorial({ apiKey: process.env.METORIAL_API_KEY});// 1. Create a setup session for the providerlet setupSession = await metorial.providerDeployments.setupSessions.create({ providerId: 'your-slack-provider-id', providerAuthMethodId: 'oauth' // redirectUrl: 'https://yourapp.com/oauth/callback'});// 2. Send the URL to your userconsole.log('Authorize Slack:', setupSession.url);// 3. Wait for completion — returns the completed setup sessionlet completed = await metorial.providerDeployments.setupSessions.waitForCompletion([setupSession]);// Store completed[0].authConfig.id for this user in your database// 4. Use the auth config in a sessionlet session = await metorial.connect({ adapter: metorialAnthropic(), providers: [ { providerDeploymentId: 'your-provider-deployment-id', providerAuthConfigId: completed[0]!.authConfig!.id } ]});let tools = session.tools();
import asynciofrom metorial import Metorial, metorial_anthropicasync def main(): metorial = Metorial(api_key="your-metorial-api-key") # 1. Create a setup session for the provider setup_session = metorial.provider_deployments.setup_sessions.create( provider_id="your-slack-provider-id", provider_auth_method_id="oauth" # redirect_url="https://yourapp.com/oauth/callback" ) # 2. Send the URL to your user print(f"Authorize Slack: {setup_session.url}") # 3. Wait for completion — returns the completed setup session completed = await metorial.wait_for_setup_session([setup_session]) # Store completed.auth_config.id for this user in your database # 4. Use the auth config in a session session = await metorial.connect( adapter=metorial_anthropic(), providers=[ { "provider_deployment_id": "your-slack-provider-deployment-id", "provider_auth_config_id": completed[0].auth_config.id }, { "provider_deployment_id": "your-exa-deployment-id" # No OAuth needed } ], ) tools = session.tools() # Use tools...asyncio.run(main())
Error handling
Both SDKs raise an error for API failures such as a wrong API key, a rate limit, or an unknown deployment ID. In Python, catch MetorialAPIError or a subclass. In TypeScript, check the error with isMetorialSDKError from @metorial/util-endpoint (npm install @metorial/util-endpoint). Error handling lists the fields and classes.