Build advanced AI agents with OpenAI. Connect 600+ integrations, automate workflows, and deploy with ease using Metorial.
When integrating OpenAI with Metorial, proper error handling ensures your application remains robust and provides good user experiences.
try {
await metorial.withProviderSession(
metorialOpenAI.chatCompletions,
{ serverDeployments: ['your-deployment'] },
async session => {
// Your code here
}
);
} catch (error) {
if (error.message.includes('authentication') || error.message.includes('api key')) {
console.error('Invalid API key. Please check your credentials.');
}
}
The Metorial SDK handles tool call errors gracefully by returning error messages instead of throwing:
let toolResponses = await session.callTools(toolCalls);
// Tool errors are included in the response, not thrown
// OpenAI will see the error message and can respond appropriately
try {
const response = await openai.chat.completions.create({
model: 'gpt-4o',
messages,
tools: session.tools
});
} catch (error) {
if (error.status === 429) {
console.error('Rate limit exceeded. Please wait before retrying.');
// Implement exponential backoff here
}
}
import { Metorial } from 'metorial';
import { metorialOpenAI } from '@metorial/openai';
import OpenAI from 'openai';
async function chatWithTools(userMessage: string) {
const metorial = new Metorial({
apiKey: process.env.METORIAL_API_KEY
});
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY
});
try {
await metorial.withProviderSession(
metorialOpenAI.chatCompletions,
{ serverDeployments: ['your-deployment'] },
async session => {
try {
const messages = [{ role: 'user', content: userMessage }];
const response = await openai.chat.completions.create({
model: 'gpt-4o',
messages,
tools: session.tools
});
const toolCalls = response.choices[0]?.message.tool_calls;
if (toolCalls) {
const toolResponses = await session.callTools(toolCalls);
// Errors from tools are handled internally
messages.push(
{ role: 'assistant', tool_calls: toolCalls },
...toolResponses
);
const finalResponse = await openai.chat.completions.create({
model: 'gpt-4o',
messages,
tools: session.tools
});
return finalResponse.choices[0]?.message.content;
}
return response.choices[0]?.message.content;
} catch (openaiError) {
console.error('OpenAI API error:', openaiError);
throw new Error('Failed to get response from OpenAI');
}
}
);
} catch (metorialError) {
console.error('Metorial error:', metorialError);
throw new Error('Failed to connect to Metorial');
}
}
Supercharge your OpenAI GPT applications with Metorial's extensive integration library featuring over 600 tools and services. Our MCP-powered platform makes it simple to connect GPT-4, GPT-4o, and other OpenAI models to the APIs your applications need. With Metorial's Python and TypeScript SDKs, adding integrations to your OpenAI-based agents and applications takes just a couple of lines of code—no more spending weeks building custom connectors. Whether you're creating chatbots, assistants, automation workflows, or AI-powered features with OpenAI's industry-leading language models, Metorial handles all the integration complexity. Connect to productivity tools like Google Workspace and Microsoft 365, CRMs like Salesforce and HubSpot, development tools like GitHub and Jira, and hundreds of other popular services instantly. Our open-source approach gives you full transparency and control while eliminating the burden of maintaining integration code, handling authentication, and managing API changes. Focus your team on building unique AI experiences and delivering value to users—let Metorial manage the integration infrastructure that powers your OpenAI applications.
Let's take your AI-powered applications to the next level, together.
Metorial provides developers with instant access to 600+ MCP servers for building AI agents that can interact with real-world tools and services. Built on MCP, Metorial simplifies agent tool integration by offering pre-configured connections to popular platforms like Google Drive, Slack, GitHub, Notion, and hundreds of other APIs. Our platform supports all major AI agent frameworks—including LangChain, AutoGen, CrewAI, and LangGraph—enabling developers to add tool calling capabilities to their agents in just a few lines of code. By eliminating the need for custom integration code, Metorial helps AI developers move from prototype to production faster while maintaining security and reliability. Whether you're building autonomous research agents, customer service bots, or workflow automation tools, Metorial's MCP server library provides the integrations you need to connect your agents to the real world.