Docs
CodeRabbit
Cloudflare
AG Grid
SerpAPI
Netlify
OpenRouter
Neon
WorkOS
Clerk
Electric
PowerSync
Sentry
Railway
Prisma
Strapi
Unkey
CodeRabbit
Cloudflare
AG Grid
SerpAPI
Netlify
OpenRouter
Neon
WorkOS
Clerk
Electric
PowerSync
Sentry
Railway
Prisma
Strapi
Unkey
Class References
Function References
Interface References
Type Alias References
Variable References

createModel

Function: createModel()

ts
function createModel<TName, TInput>(name, input): ExtendedModelDef<TName, TInput>;
function createModel<TName, TInput>(name, input): ExtendedModelDef<TName, TInput>;

Defined in: packages/typescript/ai/src/extend-adapter.ts:61

Creates a custom model definition for use with extendAdapter.

This is a helper function that provides proper type inference without requiring manual as const casts on individual properties.

Type Parameters

TName

TName extends string

The model name (inferred from argument)

TInput

TInput extends readonly Modality[]

The input modalities array (inferred from argument)

Parameters

name

TName

The model name identifier (literal string)

input

TInput

Array of supported input modalities

Returns

ExtendedModelDef<TName, TInput>

A properly typed model definition for use with extendAdapter

Example

typescript
import { extendAdapter, createModel } from '@tanstack/ai'
import { openaiText } from '@tanstack/ai-openai'

// Define custom models with full type inference
const customModels = [
  createModel('my-fine-tuned-gpt4', ['text', 'image']),
  createModel('local-llama', ['text']),
] as const

const myOpenai = extendAdapter(openaiText, customModels)
import { extendAdapter, createModel } from '@tanstack/ai'
import { openaiText } from '@tanstack/ai-openai'

// Define custom models with full type inference
const customModels = [
  createModel('my-fine-tuned-gpt4', ['text', 'image']),
  createModel('local-llama', ['text']),
] as const

const myOpenai = extendAdapter(openaiText, customModels)