API Reference

GenerateText Method

The GenerateText method allows you to create human-like text using advanced AI models. Perfect for content generation, translations, and creative writing.

Input Parameters

ParameterTypeDescription
modelAIModelSpecify which Lumia AI model to use for generation
promptstringYour input text that guides the AI's response
systemstring (optional)Define the AI's behavior and context for better results

Response Object

The method returns a Promise with the following properties:

  • text: Generated content from the AI model
  • finishReason: Why the generation process ended
  • usage: Detailed token consumption metrics

Code Example

import { generateText } from 'ai';
import { Lumia } from '@ai-sdk/Lumia';

async function createBlogPost() {
  const { text } = await generateText({
    model: Lumia('Lumia-V2-Pro'),
    prompt: 'Write a blog post about AI in healthcare',
    system: 'You are an expert in healthcare technology'
  });
  
  console.log(text);
}

createBlogPost();

StreamText Method

The StreamText method enables real-time text generation with instant feedback. Ideal for chat interfaces, live content creation, and interactive applications.

Input Parameters

ParameterTypeDescription
modelAIModelChoose your preferred Lumia AI model
promptstringThe input prompt for streaming generation
systemstring (optional)Set the AI's role and behavior context
onChunkfunctionHandle each piece of generated text in real-time
onFinishfunctionExecute code when the stream completes

Response Object

Returns a StreamResult object containing:

  • text: Promise resolving to the complete generated content
  • finishReason: Promise with the completion status
  • usage: Promise containing detailed token metrics

Code Example

import { streamText } from 'ai';
import { Lumia } from '@ai-sdk/Lumia';

function createStory() {
  const result = streamText({
    model: Lumia('Lumia-V2-Pro'),
    prompt: 'Write a story about a digital artist',
    system: 'You are a creative storyteller',
    onChunk: ({ chunk }) => {
      if (chunk.type === 'text-delta') {
        // Show text as it's generated
        updateUI(chunk.text);
      }
    },
    onFinish: (result) => {
      console.log('Story completed!');
    }
  });

  // Get the complete story when done
  result.text.then(story => {
    saveToDatabase(story);
  });
}

createStory();