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

# Model Discovery (AI SDK)

> How to fetch live model IDs for use with the AI SDK provider.

The Vercel AI SDK provider does not expose a built-in `listModels()` helper.
Use one of these patterns to keep model IDs current.

## Option 1: Fetch from the Gateway API

```ts theme={null}
const response = await fetch("https://api.phaseo.app/v1/gateway/models", {
  method: "GET",
  headers: {
    Authorization: `Bearer ${process.env.AI_STATS_API_KEY}`,
  },
});

const filteredResponse = await fetch(
  "https://api.phaseo.app/v1/gateway/models?provider=anthropic&status=active,deprecated&availability=all",
  {
    headers: {
      Authorization: `Bearer ${process.env.AI_STATS_API_KEY}`,
    },
  },
);

if (!response.ok || !filteredResponse.ok) {
  throw new Error("Failed to load models");
}

const models = await response.json();
const filteredModels = await filteredResponse.json();
console.log(models, filteredModels);
```

## Option 2: Use the official TypeScript SDK

```ts theme={null}
import AIStats from "@ai-stats/sdk";

const client = new AIStats({ apiKey: process.env.AI_STATS_API_KEY! });
const models = await client.getModels({
  provider: ["anthropic"],
  status: ["active", "deprecated"],
  availability: "all",
});

console.log(models);
```

## Using discovered IDs with AI SDK

```ts theme={null}
import { aiStats } from "@ai-stats/ai-sdk-provider";
import { generateText } from "ai";

const result = await generateText({
  model: aiStats("openai/gpt-5-nano"),
  prompt: "Hello from a discovered model ID.",
});

console.log(result.text);
```

## Notes

* Model IDs use `provider/model` format.
* `/v1/gateway/models` supports filters such as `provider`, `status`, `organisation`, `endpoints`, and `availability`.
* Re-check model availability periodically for routing and deprecations.
* Prefer selecting IDs from `/v1/gateway/models` over hard-coding long-term.
