> ## Documentation Index
> Fetch the complete documentation index at: https://docs.auriko.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Vercel AI SDK

> Use the Vercel AI SDK with Auriko's routing and cost optimization

Use Auriko as your LLM provider in the Vercel AI SDK with a first-party provider package.

This integration is for TypeScript and JavaScript. For Python, use the [LangChain](/frameworks/langchain) or [LlamaIndex](/frameworks/llamaindex) integration.

<Note>
  `@auriko/ai-sdk-provider` is at 0.2.0. Expect API changes before 1.0.
</Note>

## Prerequisites

* An [Auriko API key](https://auriko.ai/signup?redirectTo=%2Fdashboard%3Ftab%3Dapi-keys)
* Node.js 18+

## Install

```bash theme={null}
npm install @auriko/ai-sdk-provider ai
```

## Use the provider

Create a provider instance and pass it to any AI SDK function:

```typescript theme={null}
import { createAuriko } from "@auriko/ai-sdk-provider";
import { generateText } from "ai";

const auriko = createAuriko();

const { text } = await generateText({
  model: auriko("gpt-4o"),
  prompt: "What is the capital of France?",
});

console.log(text);
```

`createAuriko()` reads your `AURIKO_API_KEY` environment variable by default.

## Stream responses

Use `streamText` for streaming:

```typescript theme={null}
import { createAuriko } from "@auriko/ai-sdk-provider";
import { streamText } from "ai";

const auriko = createAuriko();

const result = streamText({
  model: auriko("gpt-4o"),
  prompt: "Count to 10",
});

for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}
```

## Configure options

`createAuriko()` accepts these parameters:

| Parameter  | Type                     | Default                      | Description                                              |
| ---------- | ------------------------ | ---------------------------- | -------------------------------------------------------- |
| `apiKey`   | `string`                 | `AURIKO_API_KEY` env         | API key                                                  |
| `baseURL`  | `string`                 | `"https://api.auriko.ai/v1"` | API base URL                                             |
| `headers`  | `Record<string, string>` | `undefined`                  | Custom headers                                           |
| `fetch`    | `typeof fetch`           | `globalThis.fetch`           | Custom fetch implementation                              |
| `routing`  | `RoutingOptions`         | `undefined`                  | Default [routing configuration](/guides/routing-options) |
| `metadata` | `AurikoMetadataParam`    | `undefined`                  | Request metadata (tags, user ID, trace ID)               |

## Configure routing

Set routing defaults when you create the provider:

```typescript theme={null}
import { createAuriko, Optimize } from "@auriko/ai-sdk-provider";
import type { AurikoResponseMetadata } from "@auriko/ai-sdk-provider";
import { generateText } from "ai";

const auriko = createAuriko({
  routing: { optimize: Optimize.COST, max_ttft_ms: 1000 },
});

const result = await generateText({
  model: auriko("gpt-4o"),
  prompt: "Hello!",
});

const meta = result.providerMetadata?.auriko as AurikoResponseMetadata | undefined;
if (meta) {
  console.log(`Provider: ${meta.provider}`);
  console.log(`Cost: $${meta.cost?.usd}`);
}
```

For routing parameters, see the [routing options guide](/guides/routing-options) and [advanced routing guide](/guides/advanced-routing).

## Access routing metadata

For non-streaming calls, read `result.providerMetadata?.auriko`:

```typescript theme={null}
const meta = result.providerMetadata?.auriko as AurikoResponseMetadata | undefined;
console.log(meta?.provider);
```

For streaming calls, `await` the metadata:

```typescript theme={null}
const result = streamText({ model: auriko("gpt-4o"), prompt: "Hello!" });
const metadata = await result.providerMetadata;
const meta = metadata?.auriko as AurikoResponseMetadata | undefined;
console.log(meta?.provider);
```

Import `AurikoResponseMetadata` from `@auriko/ai-sdk-provider` for type-safe access.

## Configure manually

<Accordion title="Alternative: use @ai-sdk/openai directly">
  You can point the OpenAI-compatible provider at Auriko's API:

  ```bash theme={null}
  npm install @ai-sdk/openai ai
  ```

  ```typescript theme={null}
  import { createOpenAI } from "@ai-sdk/openai";
  import { generateText } from "ai";

  const openai = createOpenAI({
    baseURL: "https://api.auriko.ai/v1",
    apiKey: process.env.AURIKO_API_KEY,
  });

  const { text } = await generateText({
    model: openai.chat("gpt-4o"), // .chat() recommended: routing metadata available via Chat Completions
    prompt: "Hello!",
  });
  ```

  This approach doesn't include built-in routing or response metadata. You can set a routing strategy with a [suffix shortcut](/guides/advanced-routing#use-suffix-shortcuts) (e.g., `openai.chat("gpt-4o:cost-focus")`). For routing configuration and typed metadata, use `@auriko/ai-sdk-provider`.
</Accordion>
