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

# Use Modellix LLM with the Vercel AI SDK

> Point the Vercel AI SDK at Modellix with createOpenAICompatible, baseURL, and provider/name model IDs.

Use the [Vercel AI SDK](https://ai-sdk.dev/docs/foundations/providers-and-models) against the Modellix LLM gateway. Create an [OpenAI Compatible](https://ai-sdk.dev/providers/openai-compatible-providers) provider with `baseURL` set to `https://llm.modellix.ai/v1`, then call `generateText` / `streamText` with Modellix `provider/name` model IDs.

<Note>
  This page covers **LLM text** only (`https://llm.modellix.ai`).

  Modellix model IDs are `provider/name` (for example `openai/gpt-5.5`). Pass that full string to the provider model factory. See [Models & Pricing](/llm/overview#models-and-pricing).
</Note>

## Set Up the AI SDK

<Steps>
  <Step title="Install Packages">
    ```bash theme={null}
    npm install ai @ai-sdk/openai-compatible
    ```

    For the alternate `@ai-sdk/openai` path below, also install `@ai-sdk/openai`. For Anthropic Messages, install `@ai-sdk/anthropic`.
  </Step>

  <Step title="Set Credentials">
    Create a Modellix API key in the [console](https://modellix.ai/console/api-key):

    ```bash theme={null}
    export MODELLIX_API_KEY="mdlx-xxxxxxxx"
    ```

    | Setting   | Value                                                                        |
    | --------- | ---------------------------------------------------------------------------- |
    | API key   | Modellix API Key (`MODELLIX_API_KEY`)                                        |
    | `baseURL` | `https://llm.modellix.ai/v1` (include `/v1` for OpenAI-compatible providers) |
    | Model     | Exact Modellix Model ID (`provider/name`)                                    |

    <Warning>
      Use a Modellix key, not an OpenAI platform key. Do not point the AI SDK at the media host (`https://api.modellix.ai`).
    </Warning>
  </Step>

  <Step title="Create an OpenAI Compatible Provider (Recommended)">
    Prefer `@ai-sdk/openai-compatible` for third-party gateways:

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

    const modellix = createOpenAICompatible({
      name: "modellix",
      apiKey: process.env.MODELLIX_API_KEY,
      baseURL: "https://llm.modellix.ai/v1",
    });

    const { text } = await generateText({
      model: modellix("openai/gpt-5.5"),
      prompt: "Introduce yourself in one sentence",
    });

    console.log(text);
    ```

    Swap the model string for any catalog ID (`anthropic/claude-sonnet-5`, `google/gemini-3.6-flash`, and so on). Traffic still uses Chat Completions on `https://llm.modellix.ai/v1`.
  </Step>

  <Step title="Optional: Streaming">
    ```typescript theme={null}
    import { streamText } from "ai";

    const result = streamText({
      model: modellix("openai/gpt-5.5"),
      prompt: "Write a one-line haiku about APIs",
    });

    for await (const textPart of result.textStream) {
      process.stdout.write(textPart);
    }
    ```
  </Step>

  <Step title="Optional: createOpenAI + Chat Completions">
    You can also customize `@ai-sdk/openai`. The default `modellix("...")` factory targets the **Responses** API. Modellix supports Responses, but for Chat Completions–only client code paths use `.chat()`:

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

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

    const modellix = createOpenAI({
      apiKey: process.env.MODELLIX_API_KEY,
      baseURL: "https://llm.modellix.ai/v1",
      name: "modellix",
    });

    // Chat Completions
    const chat = await generateText({
      model: modellix.chat("openai/gpt-5.5"),
      prompt: "ping",
    });

    // Responses (same host + /v1)
    const responses = await generateText({
      model: modellix("openai/gpt-5.5"),
      prompt: "ping",
    });

    console.log(chat.text, responses.text);
    ```

    See [AI SDK OpenAI provider](https://ai-sdk.dev/providers/ai-sdk-providers/openai) for `baseURL` and `.chat()` details.
  </Step>

  <Step title="Optional: Anthropic Provider (Messages)">
    For native Anthropic Messages instead of OpenAI-compatible Chat Completions:

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

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

    const modellix = createAnthropic({
      apiKey: process.env.MODELLIX_API_KEY,
      baseURL: "https://llm.modellix.ai", // no /v1
    });

    const { text } = await generateText({
      model: modellix("anthropic/claude-sonnet-5"),
      prompt: "Introduce yourself in one sentence",
    });
    ```

    Same host shape as the [Anthropic SDK](/llm/sdk/anthropic-sdk): **no** `/v1` on `baseURL`. Most AI SDK apps should stay on `createOpenAICompatible` + `/v1` unless you specifically need Messages.
  </Step>
</Steps>

## Troubleshooting

| Symptom                  | Check                                                                              |
| ------------------------ | ---------------------------------------------------------------------------------- |
| 401 Unauthorized         | `MODELLIX_API_KEY` / `apiKey` is a valid Modellix key                              |
| 404 / wrong path         | OpenAI-compatible `baseURL` includes `/v1`; Anthropic `baseURL` does **not**       |
| Model not found          | Model is a full ID like `openai/gpt-5.5`, not bare `gpt-5.5`                       |
| Responses vs Chat errors | Use `createOpenAICompatible` or `createOpenAI(...).chat(...)` for Chat Completions |
| Still hitting OpenAI     | Custom provider `baseURL` is Modellix, not the default OpenAI host                 |

## Related

* [AI SDK — Providers and models](https://ai-sdk.dev/docs/foundations/providers-and-models) — provider architecture
* [OpenAI Compatible providers](https://ai-sdk.dev/providers/openai-compatible-providers) — `createOpenAICompatible`
* [OpenAI provider](https://ai-sdk.dev/providers/ai-sdk-providers/openai) — `createOpenAI`, `.chat()`, Responses
* [OpenAI SDK](/llm/sdk/openai-sdk) — same `/v1` gateway without the AI SDK
* [LangChain](/llm/framework/langchain) — another Chat Completions client path
* [Models & Pricing](/llm/overview#models-and-pricing) — Model IDs and rates
* [LLM API guide](/llm/api/api) — protocols and curl examples
