OpenRouterTeam / ai-sdk-provider

The OpenRouter provider for the Vercel AI SDK contains support for hundreds of AI models through the OpenRouter chat and completion APIs.
https://www.npmjs.com/package/@openrouter/ai-sdk-provider
19 stars 5 forks source link

Add functionality to send extra body arguments within streamText API #2

Closed RostyslavManko closed 1 month ago

RostyslavManko commented 1 month ago

The Vanilla Vercel AI SDK doesn't support sending extra body arguments like provider, route, and others, which OpenRouter provides. These arguments are essential for fully using the OpenRouter. Please add support for these arguments to the streamText function.

daun-io commented 1 month ago

Hi @RostyslavManko,

Thanks for the request. We've created an extraBody argument.

You can use it like this:

import { createOpenRouter } from "@ai-sdk/openrouter";

const provider = createOpenRouter({
  apiKey: "your-api-key",
  // Extra body to pass to OpenRouter
  extraBody: {
    custom_field: "custom_value",
    providers: {
      anthropic: {
        custom_field: "custom_value",
      },
    },
  },
});
const model = provider.chat("anthropic/claude-3.5-sonnet");
const response = await model.doStream({
  inputFormat: "prompt",
  mode: { type: "regular" },
  prompt: [{ role: "user", content: "Hello" }],
});
RostyslavManko commented 1 month ago

Could you please update @openrouter/ai-sdk-provider's package so we can start using it? The last update was a month ago. Screenshot from 2024-08-20 21-17-08