TypeScript API: Models
Providers and models: OpenAI, Anthropic, Gemini, Azure, Bedrock, Vertex AI, local servers and more. Generated from the declarations and doc comments of criogenai 0.1.7. See also: TypeScript API overview, the same module in Python.
import {
openai,
anthropic,
gemini,
FakeModel,
openaiCompatible,
ModelOptions,
ProviderModel,
openrouter,
ollama,
lmstudio,
deepseek,
mistral,
xai,
groq,
cerebras,
together,
fireworks,
qwen,
moonshot,
zai,
anthropicCompatible,
FakeReply,
KaggleOptions,
KaggleModel,
kaggle,
AzureOptions,
AzureModel,
azure,
BedrockOptions,
BedrockModel,
bedrock,
VertexOptions,
VertexModel,
vertex,
ModelCall,
ModelAnswer,
FunctionModel,
Model,
Embedder,
} from "criogenai";Contents#
| Name | Kind | Summary |
|---|---|---|
openai | function | A model on OpenAI's API (OPENAI_API_KEY), e.g. openai("gpt-5-mini"). |
anthropic | function | A Claude model on Anthropic's Messages API (ANTHROPIC_API_KEY), e.g. anthropic("claude-sonnet-5-5"). |
gemini | function | A Google Gemini model through Gemini's OpenAI-compatible API (GEMINI_API_KEY), e.g. gemini("gemini-2.5-flash"). |
FakeModel | class | A simulated model for tests: answers with the scripted replies in order (a string is a text reply), then echoes. |
openaiCompatible | function | Any OpenAI-compatible server. |
ModelOptions | interface | Options of the provider functions (openai, anthropic, gemini, ...). |
ProviderModel | class | A model on a provider's API. |
openrouter | function | A model on OpenRouter (OPENROUTER_API_KEY), named as OpenRouter names it, e.g. openrouter("meta-llama/llama-3.3-70b-instruct"). |
ollama | function | A model on Ollama on this machine, no key, e.g. ollama("llama3.2"): nothing leaves your network. |
lmstudio | function | LM Studio on this machine (or baseUrl), no key. |
deepseek | function | DeepSeek (DEEPSEEK_API_KEY), e.g. deepseek("deepseek-chat"). |
mistral | function | Mistral AI (MISTRAL_API_KEY), e.g. mistral("mistral-large-latest"). |
xai | function | xAI's Grok models (XAI_API_KEY). |
groq | function | Groq's fast inference for open models (GROQ_API_KEY). |
cerebras | function | Cerebras's fast inference for open models (CEREBRAS_API_KEY). |
together | function | Together AI's open models (TOGETHER_API_KEY). |
fireworks | function | Fireworks AI's open models (FIREWORKS_API_KEY). |
qwen | function | Qwen on Alibaba Cloud Model Studio, international endpoint (DASHSCOPE_API_KEY). |
moonshot | function | Moonshot AI's Kimi models (MOONSHOT_API_KEY). |
zai | function | Z.ai's GLM models (ZAI_API_KEY). |
anthropicCompatible | function | Any server that speaks Anthropic's Messages API: a self-hosted gateway, or a provider's Anthropic-style endpoint (DeepSeek, Z.ai, Qwen and Moonshot offer one). |
FakeReply | type | One scripted answer of a FakeModel. |
KaggleOptions | interface | Options of kaggle(...) and KaggleModel. |
KaggleModel | class | A model on Kaggle's Model Proxy. |
kaggle | function | A model on Kaggle's Model Proxy, e.g. kaggle("google/gemini-3.6-flash"). |
AzureOptions | interface | Options of azure(...) and AzureModel: the endpoint and credentials. |
AzureModel | class | A deployment on Azure OpenAI or Microsoft Foundry. |
azure | function | A deployment on Azure OpenAI or Foundry, e.g. azure("gpt-5-mini", { endpoint: "my-resource" }). |
BedrockOptions | interface | Options of bedrock(...) and BedrockModel: region, key and API. |
BedrockModel | class | A model on Amazon Bedrock. |
bedrock | function | A model on Amazon Bedrock, e.g. bedrock("us.anthropic.claude-sonnet-5", { region: "us-east-1" }). |
VertexOptions | interface | Options of vertex(...) and VertexModel: project, location and credentials. |
VertexModel | class | A model on Google Vertex AI. |
vertex | function | A model on Google Vertex AI, e.g. vertex("google/gemini-3.6-flash", { project: "p", location: "global" }). |
ModelCall | interface | What a model function receives: the request the engine would send to a provider. |
ModelAnswer | type | A model function's answer. |
FunctionModel | class | A model written in JavaScript: for each model call the engine calls respond with the request, and the agent loop (tools, approvals, retries, limits) goes on with its answer. |
Model | type | Anything an agent or a gateway accepts as a model: a "provider:model" string or a model object. |
Embedder | class | Turns text into vectors, for long-term memory searched by meaning (memory.semantic(embedder)). |
openai#
function openai(model: string, options?: ModelOptions): ProviderModelA model on OpenAI's API (OPENAI_API_KEY), e.g. openai("gpt-5-mini"). The same as the string "openai:gpt-5-mini".
Parameters
model(string): The model name, e.g. "gpt-5-mini".options(ModelOptions, optional):apiKey(else OPENAI_API_KEY) andbaseUrl.
Raises
Error: No key given and OPENAI_API_KEY is not set.
Example
import { Agent, openai } from "criogenai";
const agent = new Agent({ model: openai("gpt-5-mini"), instructions: "Answer in one sentence." });anthropic#
function anthropic(model: string, options?: ModelOptions): ProviderModelA Claude model on Anthropic's Messages API (ANTHROPIC_API_KEY), e.g. anthropic("claude-sonnet-5-5").
Parameters
model(string): The model name.options(ModelOptions, optional):apiKey(else ANTHROPIC_API_KEY) andbaseUrl.
Raises
Error: No key given and ANTHROPIC_API_KEY is not set.
Example
import { Agent, anthropic, openai } from "criogenai";
// Claude first; OpenAI when Claude fails with a transient error after its retries.
const agent = new Agent({ model: anthropic("claude-sonnet-5-5"), fallbacks: [openai("gpt-5-mini")] });gemini#
function gemini(model: string, options?: ModelOptions): ProviderModelA Google Gemini model through Gemini's OpenAI-compatible API (GEMINI_API_KEY), e.g. gemini("gemini-2.5-flash").
Parameters
model(string): The model name.options(ModelOptions, optional):apiKey(else GEMINI_API_KEY) andbaseUrl.
Raises
Error: No key given and GEMINI_API_KEY is not set.
FakeModel#
class FakeModel {
constructor(replies?: (string | FakeReply)[], options?: { delayMs?: number; failFirst?: number; byTurn?: boolean; name?: string; });
}A simulated model for tests: answers with the scripted replies in order (a string is a text reply), then echoes. Never a network call.
Use it in tests and examples: script text answers and tool calls
(FakeReply.toolCall), and the agent loop runs for real around them.
Usage is counted, and replies name the model "fake".
Parameters
replies((string | FakeReply)[], default[]): The answers, in order: a string is a text reply;FakeReply.toolCall(...)andFakeReply.toolCalls(...)ask for tools.options({ delayMs?: number; failFirst?: number; byTurn?: boolean; name?: string; }, default{}):delayMs(default 0),failFirst(default 0),byTurn(default false) andname, as described on the properties.
Example
import { Agent, FakeModel, FakeReply } from "criogenai";
const model = new FakeModel([FakeReply.toolCall("lookup", { orderId: "A-1" }), "Order A-1 shipped."]);
// A model that fails twice with rate_limited, then answers: tests retries.
const flaky = new FakeModel(["Done."], { failFirst: 2 });
console.log((await new Agent({ model: flaky }).run("Go")).text); // "Done."FakeModel.replies#
readonly replies: FakeReply[]The scripted replies, in order.
FakeModel.delayMs#
readonly delayMs: numberHow long each reply takes, in milliseconds.
FakeModel.failFirst#
readonly failFirst: numberThe first n calls fail with rate_limited (transient), to test retries.
FakeModel.byTurn#
readonly byTurn: booleanChoose each reply by the conversation's turn (the first reply for a run's first model call, the second for its second, then the last repeats) instead of using replies up: one model serves many runs, also at once.
FakeModel.name#
readonly name: string | undefinedThe model name in replies ("fake:<name>"), to tell two fake models apart.
FakeModel.spec#
spec(): Record<string, unknown>The JSON spec the engine builds the model from.
openaiCompatible#
function openaiCompatible(model: string, options: ModelOptions & { baseUrl: string; name?: string; allowInsecureHttp?: boolean; }): ProviderModelAny OpenAI-compatible server. allowInsecureHttp: send the key over plain
http:// to another machine (a vLLM server on your LAN); refused by
default, because a key sent over http is readable by anyone on the path.
Parameters
model(string): The model name the server expects.options(ModelOptions & { baseUrl: string; name?: string; allowInsecureHttp?: boolean; }):baseUrl(required: the API root, usually ending in /v1),apiKeyif the server wants one,name(shown as the provider; default "custom") andallowInsecureHttp.
Example
import { Agent, openaiCompatible } from "criogenai";
const agent = new Agent({
model: openaiCompatible("meta-llama/Llama-3.3-70B-Instruct", { baseUrl: "http://localhost:8000/v1", name: "vllm" }),
});ModelOptions#
interface ModelOptions {
apiKey?: string;
baseUrl?: string;
}Options of the provider functions (openai, anthropic, gemini, ...).
Fields
apiKey(string, optional): The API key. Without it, the key comes from the provider's environment variable (e.g. OPENAI_API_KEY).baseUrl(string, optional): Another address for the provider's API (a proxy, a regional endpoint). Without it, the provider's own.
ProviderModel#
class ProviderModel {
constructor(kind: string, model: string, options?: ModelOptions & { name?: string; allowInsecureHttp?: boolean; });
}A model on a provider's API. The provider functions (openai("..."),
anthropic("..."), ...) make these; construct one directly only for a
provider name held in a variable.
The API key is kept private: it is not a property, and toJSON() (so
JSON.stringify) leaves it out.
Parameters
kind(string): The provider name (as in "provider:model" strings), "openai_compatible" or "anthropic_compatible".model(string): The model name, as the provider knows it.options(ModelOptions & { name?: string; allowInsecureHttp?: boolean; }, default{}):apiKeyandbaseUrl; for the compatible kinds alsoname(shown as the provider) andallowInsecureHttp.
Raises
ValidationError: The provider needs a key, none was given or found in its environment variable, and there is nobaseUrl(invalid_value).
ProviderModel.kind#
readonly kind: stringThe provider: "openai", "anthropic", "gemini", ..., "openai_compatible" or "anthropic_compatible".
ProviderModel.model#
readonly model: stringThe model name, as the provider knows it (e.g. "gpt-5-mini").
ProviderModel.baseUrl#
readonly baseUrl?: stringThe API address, when not the provider's default.
ProviderModel.spec#
spec(): Record<string, unknown>The JSON spec (with the key; never logged).
ProviderModel.toJSON#
toJSON(): Record<string, unknown>{ kind, model }, without the key: what JSON.stringify and logs show.
openrouter#
function openrouter(model: string, options?: ModelOptions): ProviderModelA model on OpenRouter (OPENROUTER_API_KEY), named as OpenRouter names it, e.g. openrouter("meta-llama/llama-3.3-70b-instruct").
Parameters
model(string): The model name, with its maker's prefix.options(ModelOptions, optional):apiKey(else OPENROUTER_API_KEY) andbaseUrl.
Raises
Error: No key given and OPENROUTER_API_KEY is not set.
ollama#
function ollama(model: string, options?: { baseUrl?: string; }): ProviderModelA model on Ollama on this machine, no key, e.g. ollama("llama3.2"): nothing leaves your network.
Parameters
model(string): The model name, asollama listshows it.options({ baseUrl?: string; }, optional):baseUrl: another Ollama server.
Example
import { Agent, ollama } from "criogenai";
const agent = new Agent({ model: ollama("llama3.2") }); // `ollama pull llama3.2` firstlmstudio#
function lmstudio(model: string, options?: { baseUrl?: string; }): ProviderModelLM Studio on this machine (or baseUrl), no key.
Parameters
model(string): The model name, as LM Studio shows it.options({ baseUrl?: string; }, optional):baseUrl: another LM Studio server.
deepseek#
function deepseek(model: string, options?: ModelOptions): ProviderModelDeepSeek (DEEPSEEK_API_KEY), e.g. deepseek("deepseek-chat").
Parameters
model(string): The model name.options(ModelOptions, optional):apiKey(else DEEPSEEK_API_KEY) andbaseUrl.
mistral#
function mistral(model: string, options?: ModelOptions): ProviderModelMistral AI (MISTRAL_API_KEY), e.g. mistral("mistral-large-latest").
Parameters
model(string): The model name.options(ModelOptions, optional):apiKey(else MISTRAL_API_KEY) andbaseUrl.
xai#
function xai(model: string, options?: ModelOptions): ProviderModelxAI's Grok models (XAI_API_KEY).
Parameters
model(string): The model name.options(ModelOptions, optional):apiKey(else XAI_API_KEY) andbaseUrl.
groq#
function groq(model: string, options?: ModelOptions): ProviderModelGroq's fast inference for open models (GROQ_API_KEY).
Parameters
model(string): The model name, e.g. "llama-3.3-70b-versatile".options(ModelOptions, optional):apiKey(else GROQ_API_KEY) andbaseUrl.
cerebras#
function cerebras(model: string, options?: ModelOptions): ProviderModelCerebras's fast inference for open models (CEREBRAS_API_KEY).
Parameters
model(string): The model name.options(ModelOptions, optional):apiKey(else CEREBRAS_API_KEY) andbaseUrl.
together#
function together(model: string, options?: ModelOptions): ProviderModelTogether AI's open models (TOGETHER_API_KEY).
Parameters
model(string): The model name.options(ModelOptions, optional):apiKey(else TOGETHER_API_KEY) andbaseUrl.
fireworks#
function fireworks(model: string, options?: ModelOptions): ProviderModelFireworks AI's open models (FIREWORKS_API_KEY).
Parameters
model(string): The model name.options(ModelOptions, optional):apiKey(else FIREWORKS_API_KEY) andbaseUrl.
qwen#
function qwen(model: string, options?: ModelOptions): ProviderModelQwen on Alibaba Cloud Model Studio, international endpoint (DASHSCOPE_API_KEY).
China: baseUrl: "https://dashscope.aliyuncs.com/compatible-mode/v1".
Parameters
model(string): The model name.options(ModelOptions, optional):apiKey(else DASHSCOPE_API_KEY) andbaseUrl.
moonshot#
function moonshot(model: string, options?: ModelOptions): ProviderModelMoonshot AI's Kimi models (MOONSHOT_API_KEY). China keys: baseUrl: "https://api.moonshot.cn/v1".
Parameters
model(string): The model name.options(ModelOptions, optional):apiKey(else MOONSHOT_API_KEY) andbaseUrl.
zai#
function zai(model: string, options?: ModelOptions): ProviderModelZ.ai's GLM models (ZAI_API_KEY). China keys: baseUrl: "https://open.bigmodel.cn/api/paas/v4".
Parameters
model(string): The model name.options(ModelOptions, optional):apiKey(else ZAI_API_KEY) andbaseUrl.
anthropicCompatible#
function anthropicCompatible(model: string, options: ModelOptions & { baseUrl: string; name?: string; allowInsecureHttp?: boolean; }): ProviderModelAny server that speaks Anthropic's Messages API: a self-hosted gateway, or a provider's Anthropic-style endpoint (DeepSeek, Z.ai, Qwen and Moonshot offer one).
Parameters
model(string): The model name the server expects.options(ModelOptions & { baseUrl: string; name?: string; allowInsecureHttp?: boolean; }):baseUrl(required),apiKey,name(shown as the provider; default "custom") andallowInsecureHttp(as foropenaiCompatible).
FakeReply#
type FakeReply = { text: string } | { toolCalls: { name: string; args: Record<string, unknown> }[] };One scripted answer of a FakeModel.
KaggleOptions#
interface KaggleOptions {
apiToken?: string;
proxyUrl?: string;
proxyToken?: string;
apiBase?: string;
}Options of kaggle(...) and KaggleModel.
Kaggle's Model Proxy serves the hosted models your Kaggle account's
AI-model allowance pays for. Credentials, in order: apiToken; proxyUrl
and proxyToken; else MODEL_PROXY_URL and MODEL_PROXY_API_KEY,
KAGGLE_API_TOKEN, or the access_token file in KAGGLE_CONFIG_DIR or
~/.kaggle. The engine mints the short-lived proxy token and renews it.
For prototypes and tests, not production traffic.
Fields
apiToken(string, optional): A Kaggle API token; the engine mints the proxy token from it. Else the environment (see above).proxyUrl(string, optional): The proxy's address, withproxyToken(a proxy token you already have).proxyToken(string, optional): A proxy token minted elsewhere, withproxyUrl. It is not renewed.apiBase(string, optional): Where proxy tokens are minted (tests).
KaggleModel#
class KaggleModel {
constructor(model: string, options?: KaggleOptions);
}A model on Kaggle's Model Proxy. kaggle(model, options) and the string
"kaggle:<model>" make the same thing; see KaggleOptions for credentials.
The token is not a property, and toJSON() leaves it out.
Parameters
model(string): The model name on the proxy.options(KaggleOptions, default{}): Credentials; without them, the environment.
Example
import { Agent, kaggle } from "criogenai";
// KAGGLE_API_TOKEN set, or ~/.kaggle/access_token present
const agent = new Agent({ model: kaggle("google/gemini-3.6-flash") });KaggleModel.kind#
readonly kind: "kaggle"Always "kaggle".
KaggleModel.model#
readonly model: stringThe model name on the proxy, e.g. "google/gemini-3.6-flash".
KaggleModel.spec#
spec(): Record<string, unknown>The JSON spec (with any token; never logged).
KaggleModel.toJSON#
toJSON(): Record<string, unknown>{ kind, model }, without any token: what JSON.stringify and logs show.
kaggle#
function kaggle(model: string, options?: KaggleOptions): KaggleModelA model on Kaggle's Model Proxy, e.g. kaggle("google/gemini-3.6-flash").
Parameters
model(string): The model name on the proxy.options(KaggleOptions, optional): Credentials (seeKaggleOptions); without them, the environment.
AzureOptions#
interface AzureOptions {
endpoint?: string;
apiKey?: string;
token?: string;
tenantId?: string;
clientId?: string;
clientSecret?: string;
managedIdentity?: boolean;
api?: "responses" | "chat";
scope?: string;
authority?: string;
identityEndpoint?: string;
}Options of azure(...) and AzureModel: the endpoint and credentials.
For Azure OpenAI or Microsoft Foundry. endpoint is the
resource name or URL (else AZURE_OPENAI_ENDPOINT). Credentials, in order:
apiKey; token (a bearer token from elsewhere); clientSecret with
tenantId and clientId (a service principal); managedIdentity (with
clientId for a user-assigned identity); else AZURE_OPENAI_API_KEY, or
AZURE_TENANT_ID + AZURE_CLIENT_ID + AZURE_CLIENT_SECRET, or
AZURE_USE_MANAGED_IDENTITY=1. The engine obtains and renews Entra ID
tokens. api: "chat" for Foundry's models from other makers.
Fields
endpoint(string, optional): The resource name ("my-resource") or its URL. Else AZURE_OPENAI_ENDPOINT.apiKey(string, optional): An Azure OpenAI API key. Else AZURE_OPENAI_API_KEY, unless another credential is given.token(string, optional): A bearer token you obtained yourself (it is not renewed).tenantId(string, optional): The Entra ID tenant, withclientIdandclientSecret. Else AZURE_TENANT_ID.clientId(string, optional): The service principal's application id; withmanagedIdentity, a user-assigned identity. Else AZURE_CLIENT_ID (for a client secret).clientSecret(string, optional): A service principal's secret, withtenantIdandclientId.managedIdentity(boolean, optional):true: use the managed identity of the Azure host the code runs on.api("responses" | "chat", optional): "responses" (OpenAI's models, the default) or "chat" (Chat Completions, for Foundry's models from other makers).scope(string, default"https://cognitiveservices.azure.com/.default"): The scope Entra ID tokens are requested for. Foundry also accepts "https://ai.azure.com/.default".authority(string, optional): Where Entra ID tokens are issued (sovereign clouds; tests).identityEndpoint(string, optional): Another managed-identity endpoint (tests).
AzureModel#
class AzureModel {
constructor(model: string, options?: AzureOptions);
}A deployment on Azure OpenAI or Microsoft Foundry. azure(model, options)
and the string "azure:<deployment>" make the same thing; see AzureOptions
for the endpoint and credentials. Secrets are not properties, and
toJSON() leaves them out.
Needs the 0.1.6 engine for your platform; with an older one, using the
model (building an agent with it, a gateway call) throws an error with
code unsupported.
Parameters
model(string): The deployment name.options(AzureOptions, default{}): The endpoint, credentials and API (seeAzureOptions); without them, the environment.
Raises
TypeError:apiis not "responses" or "chat".
Example
import { Agent, AzureModel } from "criogenai";
// A service principal; the engine fetches and renews Entra ID tokens.
const model = new AzureModel("gpt-5-mini", {
endpoint: "my-resource",
tenantId: process.env.AZURE_TENANT_ID,
clientId: process.env.AZURE_CLIENT_ID,
clientSecret: process.env.AZURE_CLIENT_SECRET,
});
const agent = new Agent({ model });AzureModel.kind#
readonly kind: "azure"Always "azure".
AzureModel.model#
readonly model: stringThe deployment name.
AzureModel.spec#
spec(): Record<string, unknown>The JSON spec (with any secret; never logged).
AzureModel.toJSON#
toJSON(): Record<string, unknown>{ kind, model }, without any secret: what JSON.stringify and logs show.
azure#
function azure(model: string, options?: AzureOptions): AzureModelA deployment on Azure OpenAI or Foundry, e.g. azure("gpt-5-mini", { endpoint: "my-resource" }).
Parameters
model(string): The deployment name.options(AzureOptions, optional): The endpoint, credentials and API (seeAzureOptions); without them, the environment.
Example
import { Agent, azure } from "criogenai";
// AZURE_OPENAI_API_KEY set; a Foundry model from another maker goes over Chat Completions.
const agent = new Agent({ model: azure("my-llama-deployment", { endpoint: "my-resource", api: "chat" }) });BedrockOptions#
interface BedrockOptions {
region?: string;
apiKey?: string;
api?: "auto" | "messages" | "chat" | "responses";
baseUrl?: string;
}Options of bedrock(...) and BedrockModel: region, key and API.
Amazon Bedrock with an API key. region (else AWS_REGION
or AWS_DEFAULT_REGION; there is no default, so data never goes to a region
you did not choose); apiKey (else AWS_BEARER_TOKEN_BEDROCK). Claude is
called over the Anthropic Messages API and other makers' models over Chat
Completions; api forces one. baseUrl reaches bedrock-mantle or a VPC
endpoint. IAM roles (SigV4) are not supported yet.
Fields
region(string, optional): The AWS region, e.g. "us-east-1". Else AWS_REGION or AWS_DEFAULT_REGION; there is no default.apiKey(string, optional): A Bedrock API key. Else AWS_BEARER_TOKEN_BEDROCK.api("responses" | "chat" | "auto" | "messages", default"auto"): Which API to call: "auto" (Anthropic's models over the Messages API, the rest over Chat Completions), "messages", "chat" or "responses" (for models whose model card lists the Responses API).baseUrl(string, optional): Another endpoint: bedrock-mantle or a VPC endpoint.
BedrockModel#
class BedrockModel {
constructor(model: string, options?: BedrockOptions);
}A model on Amazon Bedrock. bedrock(model, options) and the string
"bedrock:<model id>" make the same thing; see BedrockOptions. The key
is not a property, and toJSON() leaves it out.
Needs the 0.1.6 engine for your platform; with an older one, using the
model throws an error with code unsupported.
Parameters
model(string): The Bedrock model id or inference profile, e.g. "us.anthropic.claude-sonnet-5".options(BedrockOptions, default{}): Region, key, API and endpoint; without them, the environment.
Raises
TypeError:apiis not "auto", "messages", "chat" or "responses".
BedrockModel.kind#
readonly kind: "bedrock"Always "bedrock".
BedrockModel.model#
readonly model: stringThe Bedrock model id or inference profile.
BedrockModel.spec#
spec(): Record<string, unknown>The JSON spec (with any key; never logged).
BedrockModel.toJSON#
toJSON(): Record<string, unknown>{ kind, model }, without the key: what JSON.stringify and logs show.
bedrock#
function bedrock(model: string, options?: BedrockOptions): BedrockModelA model on Amazon Bedrock, e.g. bedrock("us.anthropic.claude-sonnet-5", { region: "us-east-1" }).
Parameters
model(string): The Bedrock model id or inference profile.options(BedrockOptions, optional): Region, key, API and endpoint (seeBedrockOptions); without them, the environment.
Example
import { Agent, bedrock } from "criogenai";
// AWS_BEARER_TOKEN_BEDROCK set; the region is always chosen explicitly.
const agent = new Agent({ model: bedrock("us.anthropic.claude-sonnet-5", { region: "us-east-1" }) });VertexOptions#
interface VertexOptions {
project?: string;
location?: string;
token?: string;
credentialsFile?: string;
api?: "auto" | "chat" | "claude";
host?: string;
tokenUrl?: string;
metadataUrl?: string;
}Options of vertex(...) and VertexModel: project, location and credentials.
Google Vertex AI. project (else GOOGLE_CLOUD_PROJECT) and
location (else GOOGLE_CLOUD_LOCATION; no default, it decides where data is
processed). Credentials: token, credentialsFile, else
GOOGLE_APPLICATION_CREDENTIALS, gcloud's application-default file, or the
metadata server on Google Cloud. Service-account key files are not supported
yet. claude-… models go to Claude's endpoint, the rest to the
OpenAI-compatible one; api forces one.
Fields
project(string, optional): The Google Cloud project id. Else GOOGLE_CLOUD_PROJECT.location(string, optional): The region, e.g. "us-central1" or "global"; it decides where data is processed. Else GOOGLE_CLOUD_LOCATION; there is no default.token(string, optional): An OAuth access token you obtained yourself.credentialsFile(string, optional): A credentials file of typeauthorized_user(asgcloud auth application-default loginwrites); service-account key files are refused. Else GOOGLE_APPLICATION_CREDENTIALS, gcloud's file, or the metadata server.api("chat" | "auto" | "claude", default"auto"): Which endpoint to call: "auto" (claude-…models to Claude's endpoint, the rest to the OpenAI-compatible one), "chat" (OpenAI-compatible Chat Completions) or "claude" (Anthropic Messages).host(string, optional): Another API host (a private endpoint; tests).tokenUrl(string, optional): Token endpoints elsewhere (tests).metadataUrl(string, optional): Another metadata server address (tests).
VertexModel#
class VertexModel {
constructor(model: string, options?: VertexOptions);
}A model on Google Vertex AI. vertex(model, options) and the string
"vertex:<model>" make the same thing; see VertexOptions. Tokens are not
properties, and toJSON() leaves them out.
Needs the 0.1.6 engine for your platform; with an older one, using the
model throws an error with code unsupported.
Parameters
model(string): The model name.options(VertexOptions, default{}): Project, location, credentials and API; without them, the environment.
Raises
TypeError:apiis not "auto", "chat" or "claude".
VertexModel.kind#
readonly kind: "vertex"Always "vertex".
VertexModel.model#
readonly model: stringThe model name, e.g. "google/gemini-3.6-flash" or a claude-… model.
VertexModel.spec#
spec(): Record<string, unknown>The JSON spec (with any token; never logged).
VertexModel.toJSON#
toJSON(): Record<string, unknown>{ kind, model }, without any token: what JSON.stringify and logs show.
vertex#
function vertex(model: string, options?: VertexOptions): VertexModelA model on Google Vertex AI, e.g. vertex("google/gemini-3.6-flash", { project: "p", location: "global" }).
Parameters
model(string): The model name.options(VertexOptions, optional): Project, location, credentials and API (seeVertexOptions); without them, the environment.
Example
import { Agent, vertex } from "criogenai";
// Credentials from GOOGLE_APPLICATION_CREDENTIALS, gcloud, or the metadata server.
const agent = new Agent({ model: vertex("google/gemini-3.6-flash", { project: "my-project", location: "global" }) });ModelCall#
interface ModelCall {
messages: Record<string, unknown>[];
tools?: Record<string, unknown>[];
settings?: Record<string, unknown>;
output?: Record<string, unknown> | null;
[key: string]: unknown;
}What a model function receives: the request the engine would send to a provider.
It has the messages so far, the tools the model may call, the settings
and any output schema (ModelRequest in schemas/criogenai.schema.json).
Fields
messages(Record<string, unknown>[]): The conversation so far, system message first, in the transcript format ofresult.messages.tools(Record<string, unknown>[], optional): The tools the model may call, each withname,descriptionandinput_schema.settings(Record<string, unknown>, optional): Generation settings, such as temperature and the token limit, when set.output(Record<string, unknown> | null, optional): A structured-output request ({ schema, strategy? }: the JSON Schema the answer must match), when there is one. An agent'soutputschema reaches a function model as afinal_outputtool intoolsinstead.
ModelAnswer#
type ModelAnswer = string | FakeReply | { message: Record<string, unknown> } | { error: { kind: string; message: string } };A model function's answer.
Text, tool calls (FakeReply.toolCall), an exact assistant message, or a
classified error ({ error: { kind: "rate_limited", message } } is
retried as a provider's would be).
FunctionModel#
class FunctionModel {
constructor(respond: (call: ModelCall) => ModelAnswer | Promise<ModelAnswer>, options?: { name?: string; });
}A model written in JavaScript: for each model call the
engine calls respond with the request, and the agent loop (tools,
approvals, retries, limits) goes on with its answer. For a model that runs
in the page (WebGPU, a browser's built-in model), your own client, or
scripted replies chosen by what the request says (tests and demos, where
several agents share one model). If respond throws, the call fails with
model_failed.
Needs the 0.1.4 engine or newer for your platform; with an older one,
using the model throws an error with code unsupported.
Parameters
respond((call: ModelCall) => ModelAnswer | Promise<ModelAnswer>): Called for every model call with the request; returns (or resolves to) the answer: text,FakeReply.toolCall(...),{ message }or{ error: { kind, message } }.options({ name?: string; }, default{}):name: the model name in replies and traces (default "function").
Raises
TypeError:respondis not a function.
Example
import { Agent, FakeReply, FunctionModel } from "criogenai";
// Ask for the weather tool once, then answer with what it returned.
const model = new FunctionModel((call) => {
const last = call.messages[call.messages.length - 1];
if (last.role === "user") return FakeReply.toolCall("get_weather", { city: "Paris" });
return `The tool said: ${JSON.stringify(last.content)}`;
});
const agent = new Agent({ model });FunctionModel.kind#
readonly kind: "function"Always "function".
FunctionModel.name#
readonly name: stringThe model name in replies and traces.
FunctionModel.spec#
spec(): Record<string, unknown>The JSON spec: the function is registered with the engine on first use.
FunctionModel.toJSON#
toJSON(): Record<string, unknown>{ kind: "function", name }: what JSON.stringify and logs show.
Model#
type Model =string | ProviderModel | KaggleModel | AzureModel | BedrockModel | VertexModel | FakeModel | FunctionModel;Anything an agent or a gateway accepts as a model: a "provider:model" string or a model object.
The string's provider is one of openai, gemini, anthropic, openrouter,
deepseek, mistral, xai, groq, cerebras, together, fireworks, qwen,
moonshot, zai (keys from their environment variables), ollama, lmstudio
(no key), kaggle, azure, bedrock or vertex (credentials from the
environment). Use the functions (openai(...), azure(...), ...) to pass
keys or options in code.
Embedder#
class Embedder {
constructor(spec: Record<string, unknown>);
}Turns text into vectors, for long-term memory searched by meaning
(memory.semantic(embedder)). Built from the same
providers as models; keys come from the same environment variables.
Parameters
spec(Record<string, unknown>): The engine spec.
Embedder.openai#
static openai(model?: string, options?: { apiKey?: string; dimensions?: number; }): EmbedderOpenAI's /embeddings (key from OPENAI_API_KEY).
Parameters
model(string, default"text-embedding-3-small"): The embedding model.options({ apiKey?: string; dimensions?: number; }, default{}):apiKey(else OPENAI_API_KEY) anddimensions(shorter vectors, for models that support it).
Raises
ValidationError: No key was given or found in OPENAI_API_KEY (invalid_value).
Example
import { Embedder, Gateway } from "criogenai";
const vectors = await new Gateway().embed(Embedder.openai(), ["refund policy", "shipping times"]);Embedder.gemini#
static gemini(model?: string, options?: { apiKey?: string; }): EmbedderGemini's OpenAI-compatible /embeddings (GEMINI_API_KEY).
Parameters
model(string, default"gemini-embedding-001"): The embedding model.options({ apiKey?: string; }, default{}):apiKey(else GEMINI_API_KEY).
Embedder.ollama#
static ollama(model?: string, options?: { baseUrl?: string; }): EmbedderOllama on this machine (or baseUrl): nothing leaves your network.
Parameters
model(string, default"nomic-embed-text"): The embedding model (ollama pullit first).options({ baseUrl?: string; }, default{}):baseUrl: another Ollama server.
Embedder.openaiCompatible#
static openaiCompatible(model: string, options: { baseUrl: string; apiKey?: string; dimensions?: number; }): EmbedderAny OpenAI-compatible /embeddings (vLLM, a gateway).
Parameters
model(string): The embedding model the server expects.options({ baseUrl: string; apiKey?: string; dimensions?: number; }):baseUrl(required),apiKeyanddimensions.
Embedder.fake#
static fake(options?: { synonyms?: Record<string, string>; failing?: boolean; }): EmbedderFor tests, never a network call: texts sharing words are close;
synonyms makes different words count as the same ({ car: "automobile" });
failing makes every call fail (search then falls back to keywords).
Parameters
options({ synonyms?: Record<string, string>; failing?: boolean; }, default{}):synonyms(word to the word it counts as) andfailing(default false).
Embedder.toJSON#
toJSON(): Record<string, unknown>{ kind, model }, without the key: what JSON.stringify and logs show.