Skip to main content

Example

import { Metorial } from 'metorial';
import { metorialOpenAI } from '@metorial/openai';
import OpenAI from 'openai';

let metorial = new Metorial({ apiKey: process.env.METORIAL_API_KEY });
let openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

await metorial.withProviderSession(
    metorialOpenAI.chatCompletions,
    { serverDeployments: [{ serverDeploymentId: 'your-deployment-id' }] },
    async ({ tools, callTools, closeSession }) => {
        let response = await openai.chat.completions.create({
            model: 'gpt-4o',
            messages: [{ role: 'user', content: 'Help me' }],
            tools: tools
        });

        // Handle tool calls
        await closeSession();
    }
);