Heroku AI SDK Provider - v0.4.3
    Preparing search index...

    Class HerokuChatLanguageModel

    Heroku chat language model implementation compatible with AI SDK v5.

    This class provides chat completion capabilities using Heroku's AI infrastructure, specifically designed to work seamlessly with the Vercel AI SDK's chat functions. Supports both streaming and non-streaming responses, tool calling, and all standard AI SDK features.

    HerokuChatLanguageModel Implements the LanguageModelV2 interface from @ai-sdk/provider.

    Basic usage with AI SDK:

    import { generateText, streamText } from "ai";
    import { heroku } from "heroku-ai-provider";

    const model = heroku.chat("claude-4-sonnet");


    // Generate text
    const { text } = await generateText({
    model,
    prompt: "Explain quantum computing"
    });

    // Stream text
    const { textStream } = await streamText({
    model,
    prompt: "Write a story about AI"
    });

    for await (const delta of textStream) {
    process.stdout.write(delta);
    }

    Advanced usage with tools:

    import { generateText, tool } from "ai";
    import { z } from "zod";

    const { text } = await generateText({
    model,
    prompt: "What's the weather like in New York?",
    tools: {
    getWeather: tool({
    description: "Get current weather for a location",
    parameters: z.object({
    location: z.string().describe("The city name")
    }),
    execute: async ({ location }) => {
    return { temperature: 72, condition: "sunny" };
    }
    })
    },
    stopWhen: stepCountIs(5)
    });

    Direct model usage:

    import { HerokuChatLanguageModel } from "heroku-ai-provider";

    const model = new HerokuChatLanguageModel(
    "claude-4-sonnet",
    process.env.INFERENCE_KEY!,
    "https://us.inference.heroku.com/v1/chat/completions"
    );

    const result = await model.doGenerate({
    inputFormat: "prompt",
    mode: { type: "regular" },
    prompt: "Hello, world!"
    });

    console.log(result.text);

    Implements

    • LanguageModelV2
    Index

    Constructors

    • Constructor for the Heroku Chat Language Model.

      Parameters

      • model: string

        The Heroku chat model identifier (e.g., "claude-4-sonnet")

      • apiKey: string

        Your Heroku AI API key for chat completions

      • baseUrl: string

        The base URL for the Heroku chat completions API

      Returns HerokuChatLanguageModel

      When parameters are invalid or missing

      const model = new HerokuChatLanguageModel(
      "claude-4-sonnet",
      process.env.INFERENCE_KEY!,
      "https://us.inference.heroku.com/v1/chat/completions"
      );

    Properties

    specificationVersion: "v2" = ...

    The language model must specify which language model interface version it implements.

    provider: "heroku" = ...

    Name of the provider for logging purposes.

    modelId: string

    Provider-specific model ID for logging purposes.

    supportedUrls: Record<string, RegExp[]> = {}

    Supported URL patterns by media type for the provider.

    The keys are media type patterns or full media types (e.g. */* for everything, audio/*, video/*, or application/pdf). and the values are arrays of regular expressions that match the URL paths.

    The matching should be against lower-case URLs.

    Matched URLs are supported natively by the model and are not downloaded.

    A map of supported URL patterns by media type (as a promise or a plain object).

    Methods

    • Generate a chat completion using the Heroku AI API.

      This method implements the AI SDK v5 LanguageModelV2 interface for non-streaming chat completions, including tool calling and conversation history.

      Parameters

      • options: LanguageModelV2CallOptions

        Configuration options for the chat completion

      Returns Promise<
          {
              content: LanguageModelV2Content[];
              finishReason: LanguageModelV2FinishReason;
              usage: LanguageModelV2Usage;
              providerMetadata: undefined;
              request: { body: Record<string, unknown> };
              response: {
                  id?: string;
                  timestamp?: Date;
                  modelId?: string;
                  body: Record<string, unknown>;
              };
              warnings: LanguageModelV2CallWarning[];
          },
      >

      Completion content, usage metadata, and any provider warnings

      When the API request fails or input validation fails

      const result = await model.doGenerate({
      prompt: [
      { role: "user", content: [{ type: "text", text: "Tell me a joke" }] },
      ],
      });
      console.log(result.content[0]);
    • Generate a streaming chat completion using the Heroku AI API.

      This method implements the AI SDK v5 LanguageModelV2 interface for streaming chat completions and returns a readable stream of structured parts.

      Parameters

      • options: LanguageModelV2CallOptions

      Returns Promise<
          {
              stream: ReadableStream<LanguageModelV2StreamPart>;
              request: { body: Record<string, unknown> };
              response: { headers: { [k: string]: string } | undefined };
          },
      >