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

# Models

> TypeScript API reference for Netra models. Fetch model details and pricing information for AI models tracked by your project.

The Netra SDK exposes a `models` client that lets you:

* **Fetch model pricing** - Retrieve pricing details for all AI models in your project
* **Filter by model name** - Look up pricing for a specific model by name

This page shows how to use `Netra.models` to query model pricing information programmatically.

## Getting Started

The `models` client is available on the main `Netra` entry point after initialization.

```typescript theme={null}
import { Netra } from "netra-sdk";

await Netra.init({
  appName: "sample-app",
});

// Access the models client
await Netra.models.getModelPricing();
```

***

## getModelPricing

Fetch model details and pricing for all models associated with your project, or filter by a specific model name.

```typescript Usage theme={null}
import { Netra } from "netra-sdk";

await Netra.init({
  appName: "sample-app",
});

// Fetch pricing for all models in the project
const allModels = await Netra.models.getModelPricing();
console.log(allModels);

// Fetch pricing for a specific model
const model = await Netra.models.getModelPricing({ name: "gpt-4o-mini" });
console.log(model);
```

```typescript Signature theme={null}
getModelPricing(params?: GetModelPricingParams): Promise<ModelPricing[] | null>
```

### Parameters

| Parameter | Type | Description |
| - | - | - |
| `name` | `string?` | Optional model name to filter results. When omitted, returns all models for the project. |
| `useCache` | `boolean?` | When `true`, read and write the in-memory cache. Defaults to `false`. |
| `cacheTtl` | `number?` | Per-call cache TTL in seconds. When omitted with `useCache: true`, defaults to `300`. |

### Response

Returns an array of `ModelPricing` objects from the API. Returns `null` if the request fails or the client is not initialized. Returns an empty array if the project has no matching models.

> [accordion] ModelPricing
>
> ```typescript theme={null}
> interface ModelPricing {
>   name: string;
>   projectId: string | null;
>   matchPattern: string;
>   prices: ModelPrice[];
> }
>
> interface ModelPrice {
>   usageType: string;
>   minUnits: number;
>   maxUnits: number;
>   price: number;
>   unitValue: number;
> }
> ```

> [!TIP]
>
> The `name` parameter performs a filter on the server side. Use it to avoid fetching the full model catalog when you only need pricing for a specific model.

> [!NOTE]
>
> `getModelPricing` is async. Always `await` the call. Errors are logged and `null` is returned so your application keeps running.

***

## Caching

By default, every `getModelPricing` call hits the backend. Pass `useCache: true` to serve repeated lookups from an in-memory TTL cache.

```typescript theme={null}
const pricing = await Netra.models.getModelPricing({
  name: "gpt-4o-mini",
  useCache: true,
});
```

Cache keys include the model name (or `"all"` when `name` is omitted), so filtered and unfiltered results are stored separately. Failed lookups (`null`) are not cached.

### clearCache

Clear all cached model pricing entries. The SDK also clears this cache when you call `Netra.shutdown()`.

```typescript theme={null}
Netra.models.clearCache();
```

**Returns:** `void`

***

## Configuration

### Environment Variables

The models client respects the following environment variables:

| Variable | Default | Description |
| - | - | - |
| `NETRA_OTLP_ENDPOINT` | — | **Required.** The OTLP endpoint used to derive the models API base URL. |
| `NETRA_API_KEY` | — | API key for authenticating requests. |

***

## Complete Example

```typescript theme={null}
import { Netra } from "netra-sdk";

// Initialize the SDK
await Netra.init({
  appName: "pricing-demo",
  headers: `x-api-key=${process.env.NETRA_API_KEY}`,
});

// 1. Fetch all model pricing
const allModels = await Netra.models.getModelPricing();
console.log(`Total models available: ${allModels?.length ?? 0}\n`);
console.log(allModels);

// 2. Look up pricing for a specific model
const targetModel = "gpt-4o-mini";
const results = await Netra.models.getModelPricing({ name: targetModel });

if (results && results.length > 0) {
  console.log(results);
} else {
  console.log(`\nNo pricing found for ${targetModel}`);
}

await Netra.shutdown();
```

## Next Steps

* [TypeScript SDK Overview](https://docs.getnetra.ai/sdk-reference/sdk/typescript.md) - Full TypeScript API reference
* [Prompts](https://docs.getnetra.ai/sdk-reference/prompts/typescript.md) - Fetch managed prompt templates
* [Dashboard Query](https://docs.getnetra.ai/sdk-reference/dashboard-query/typescript.md) - Query dashboard metrics
* [Usage & Traces](https://docs.getnetra.ai/sdk-reference/usage/typescript.md) - Query traces and spans


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.