Skip to main content

Example

import { Metorial } from 'metorial';
import { metorialAiSdk } from '@metorial/ai-sdk';
import { anthropic } from '@ai-sdk/anthropic';
import { streamText } from 'ai';

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

await metorial.withProviderSession(
    metorialAiSdk,
    {
        serverDeployments: [{ serverDeploymentId: 'your-deployment-id' }],
        streaming: true
    },
    async ({ tools, closeSession }) => {
        let result = streamText({
            model: anthropic('claude-sonnet-4-5'),
            prompt: 'Help me',
            tools: tools,
            onFinish: async () => await closeSession()
        });

        for await (let text of result.textStream) {
            process.stdout.write(text);
        }
    }
);