LINKORA
OverviewQuickstart

Vercel AI SDK

Using Linkora with Vercel AI SDK

Vercel AI SDK

You can use the Vercel AI SDK to integrate Linkora with your Next.js app. To get started, install @linkora/ai-sdk-provider:

npm install @linkora/ai-sdk-provider

And then you can use streamText() API to stream text from Linkora.

import { createLinkora } from '@linkora/ai-sdk-provider';
import { streamText } from 'ai';
import { z } from 'zod';

export const getLasagnaRecipe = async (modelName: string) => {
  const linkora = createLinkora({
    apiKey: '<LINKORA_API_KEY>',
  });

  const response = streamText({
    model: linkora(modelName),
    prompt: 'Write a vegetarian lasagna recipe for 4 people.',
  });

  await response.consumeStream();
  return response.text;
};

export const getWeather = async (modelName: string) => {
  const linkora = createLinkora({
    apiKey: '<LINKORA_API_KEY>',
  });

  const response = streamText({
    model: linkora(modelName),
    prompt: 'What is the weather in San Francisco, CA in Fahrenheit?',
    tools: {
      getCurrentWeather: {
        description: 'Get the current weather in a given location',
        parameters: z.object({
          location: z
            .string()
            .describe('The city and state, e.g. San Francisco, CA'),
          unit: z.enum(['celsius', 'fahrenheit']).optional(),
        }),
        execute: async ({ location, unit = 'celsius' }) => {
          // Mock response for the weather
          const weatherData = {
            'Boston, MA': {
              celsius: '15°C',
              fahrenheit: '59°F',
            },
            'San Francisco, CA': {
              celsius: '18°C',
              fahrenheit: '64°F',
            },
          };

          const weather = weatherData[location];
          if (!weather) {
            return `Weather data for ${location} is not available.`;
          }

          return `The current weather in ${location} is ${weather[unit]}.`;
        },
      },
    },
  });

  await response.consumeStream();
  return response.text;
};

Video Generation

Linkora supports video generation through the AI SDK's experimental_generateVideo API. The provider handles the asynchronous submit-poll-download workflow automatically.

import { createLinkora } from '@linkora/ai-sdk-provider';
import { experimental_generateVideo as generateVideo } from 'ai';

const linkora = createLinkora({
  apiKey: '<LINKORA_API_KEY>',
});

const { video } = await generateVideo({
  model: linkora.videoModel('google/veo-3.1'),
  prompt: 'A golden retriever playing fetch on a sunny beach with waves crashing in the background',
  aspectRatio: '16:9',
  duration: 4,
});

console.log(video.mediaType); // 'video/mp4'
console.log(video.uint8Array.byteLength); // video size in bytes

Passthrough Options

Each video model supports model-specific parameters that can be passed through via provider.options in extraBody, keyed by provider slug. See the video generation docs for the full list of allowed_passthrough_parameters per model.

import { createLinkora } from '@linkora/ai-sdk-provider';
import { experimental_generateVideo as generateVideo } from 'ai';

const linkora = createLinkora({
  apiKey: '<LINKORA_API_KEY>',
});

const { video } = await generateVideo({
  model: linkora.videoModel('google/veo-3.1', {
    generateAudio: true,
    extraBody: {
      provider: {
        options: {
          'google-vertex': {
            parameters: {
              personGeneration: 'allow_all',
              enhancePrompt: true,
            },
          },
        },
      },
    },
  }),
  prompt: 'A timelapse of a flower blooming in a sunlit garden',
  aspectRatio: '16:9',
});

Video Model Settings

SettingTypeDefaultDescription
`generateAudio`boolean`false`Whether to generate audio alongside the video
`pollIntervalMs`number`2000`Polling interval in milliseconds when waiting for generation
`maxPollTimeMs`number`600000`Maximum time in milliseconds to wait before timing out
`extraBody`objectNoneDefault body parameters merged into every request for this model

Image-to-Video

You can pass a reference image to guide the video generation:

import { createLinkora } from '@linkora/ai-sdk-provider';
import { experimental_generateVideo as generateVideo } from 'ai';

const linkora = createLinkora({
  apiKey: '<LINKORA_API_KEY>',
});

const { video } = await generateVideo({
  model: linkora.videoModel('alibaba/wan-2.7'),
  prompt: 'A character walking through a forest',
  image: new URL('https://example.com/first-frame.png'),
  resolution: '1920x1080',
});

Provider Metadata

The response includes Linkora-specific metadata accessible via providerMetadata:

import { createLinkora } from '@linkora/ai-sdk-provider';
import { experimental_generateVideo as generateVideo } from 'ai';

const linkora = createLinkora({
  apiKey: '<LINKORA_API_KEY>',
});

const result = await generateVideo({
  model: linkora.videoModel('google/veo-3.1'),
  prompt: 'A slow pan across a calm mountain lake at sunrise',
  aspectRatio: '16:9',
});

console.log(result.providerMetadata?.linkora);
// { generationId: 'gen-...', cost: 0.25 }

For the full list of supported models, resolutions, aspect ratios, and provider-specific options, see the Video Generation documentation.