Every agent needs one inference path. Choose it independently from where the app is developed or deployed.
An agent's model is a "provider/model" string. Omit it to use the default
mistral/mistral-small-2503 through Veryfront Cloud. Without Cloud context,
the default remains openai/gpt-5-nano with your direct provider key.
Prerequisites
- At least one agent defined under
agents/(see Agents). - One configured inference path from the table above.
Veryfront Cloud AI Gateway
The AI Gateway provides managed model access without a model-vendor API key.
Run veryfront login, then Push the project once to create its local project
link. veryfront dev and veryfront eval load the stored login and linked
project automatically.
To authenticate without an interactive browser (CI, a container, a remote
shell), set VERYFRONT_API_TOKEN instead. The environment variable takes
precedence over a stored login, so it also works as a temporary override on a
machine that is already signed in. veryfront whoami reports which credential
is active. This is a separate credential from a model provider key: it selects
the AI Gateway, it does not authenticate you to a vendor.
Model selection follows these rules:
Use an explicit gateway model when the route must never switch to a direct provider:
import { agent } from "veryfront/agent"; export default agent({ model: "veryfront-cloud/openai/gpt-5.5", system: "You are a helpful assistant.",});VERYFRONT_DEFAULT_MODEL can select another gateway default for omitted
models and model: "auto". It is optional.
Call the AI Gateway from other clients
Code outside Veryfront can use the AI Gateway through the official OpenAI and Anthropic clients. Create a project API key with the Write permission in Studio under Settings > API Keys. Inference requests are writes, so a Read-only key is refused.
The key starts with vf_ and is bound to its project.
The examples read it from VERYFRONT_API_KEY, a name for your own code only.
The Veryfront CLI and SDK read VERYFRONT_API_TOKEN, described above.
For a one-snippet setup per tool, including Claude Code, Codex, and the Vercel AI SDK, see the AI Gateway quickstart.
Set the project API key in your shell before running the examples:
export VERYFRONT_API_KEY="<your-project-api-key>"Name the model as <provider>/<model>. List the models your key can use:
curl https://api.veryfront.com/ai/models \ -H "Authorization: Bearer $VERYFRONT_API_KEY"The response lists deployments, one for each place a model runs. Each
deployment separates three things:
model: what the model is.model.idis the name to send, andmodel.aliasesare other names that select the same model.model_provider: who made the model, for example Anthropic or Mistral.inference_provider: who runs it, for example Google.regionsays where.
A model can run with more than one inference provider. Its deployments are
listed in routing order, and the gateway uses the first one with
enabled: true. A deployment that a policy in force refuses is listed with
enabled: false, and disabled_by names that policy: account, project
or api_key. The deployment with is_default: true is the default model.
Install the clients for the examples you want to run:
npm install openai @anthropic-ai/sdkUse a model that supports Chat Completions with the OpenAI client at
https://api.veryfront.com/ai/v1. Models supporting other operations use their
corresponding endpoints. Model identifiers can include vendors this SDK has no
built-in entry for:
import OpenAI from "openai"; const projectApiKey = process.env.VERYFRONT_API_KEY;if (!projectApiKey) { throw new Error("Set VERYFRONT_API_KEY before running this example.");} const client = new OpenAI({ baseURL: "https://api.veryfront.com/ai/v1", apiKey: projectApiKey,}); const completion = await client.chat.completions.create({ model: "mistral/mistral-small-2503", messages: [{ role: "user", content: "Say hello." }],});curl https://api.veryfront.com/ai/v1/chat/completions \ -H "Authorization: Bearer $VERYFRONT_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model":"mistral/mistral-small-2503","messages":[{"role":"user","content":"Say hello."}]}'Anthropic models also speak the Anthropic Messages protocol. The Anthropic
client adds /v1/messages to its base URL:
import Anthropic from "@anthropic-ai/sdk"; const client = new Anthropic({ baseURL: "https://api.veryfront.com/ai", apiKey: null, authToken: process.env.VERYFRONT_API_KEY,}); const message = await client.messages.create({ model: "anthropic/claude-sonnet-4-6", max_tokens: 1024, messages: [{ role: "user", content: "Say hello." }],});curl https://api.veryfront.com/ai/v1/messages \ -H "Authorization: Bearer $VERYFRONT_API_KEY" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{"model":"anthropic/claude-sonnet-4-6","max_tokens":1024,"messages":[{"role":"user","content":"Say hello."}]}'Inside a Veryfront agent, use a veryfront-cloud/<provider>/<model> string
instead. The SDK routes through Veryfront's project runtime gateway for the
selected provider and model.
Runtime conventions (recommended)
For most projects, omit model to use the default for your inference path. Set
model: "auto" only when you want runtime conventions to choose the backend:
import { agent } from "veryfront/agent"; export default agent({ system: "You are a helpful assistant.",});Verify provider resolution through any AG-UI route that uses this agent:
curl -N http://localhost:3000/api/ag-ui \ -H "Content-Type: application/json" \ -H "Cookie: __Host-vf_csrf=local-check" \ -H "x-csrf-token: local-check" \ -d '{"messages":[{"id":"1","role":"user","parts":[{"type":"text","text":"Reply with the active inference mode if available."}]}]}'In a client UI, useChat() also exposes inferenceMode so you can confirm
whether the response used cloud or server-local inference.
The runtime resolves model: "auto" from Cloud context or direct provider
credentials. VERYFRONT_DEFAULT_MODEL, VERYFRONT_DEFAULT_EMBEDDING_MODEL, and
VERYFRONT_RAG_BACKEND are optional overrides.
Direct providers
Set only the variables for the provider you use:
OPENAI_API_KEYfor OpenAI.ANTHROPIC_API_KEYfor Anthropic.GOOGLE_API_KEYfor Google.MISTRAL_API_KEYfor direct Mistral requests. Without this key, hosted Mistral models route through Veryfront Cloud when cloud bootstrap is available.OPENAI_BASE_URLfor OpenAI-compatible services.
Keeping keys out of the project
Provider credentials are read from the environment. To avoid a plaintext key in the project, keep the reference in an ignored env file and resolve it with your secret manager when you run a command:
ANTHROPIC_API_KEY="op://Private/Anthropic API/credential"op run --env-file=.env.local -- veryfront devVeryfront never overwrites a variable that is already set, so the resolved value wins over the op:// reference sitting in the file.
Wrap once rather than per command:
{ "scripts": { "dev": "op run --env-file=.env.local -- veryfront dev", "eval": "op run --env-file=.env.local -- veryfront eval" }}A .envrc with direnv covers every command in the directory, including ones started by an editor. The same pattern works with other managers:
doppler run -- veryfront devinfisical run -- veryfront devenvconsul -secret secret/veryfront -- veryfront dev # HashiCorp VaultVeryfront does not resolve op:// or similar references itself. An unresolved reference is treated as a literal value and reaches the provider as an invalid key, so run the wrapper rather than the bare command.
The same applies to VERYFRONT_API_TOKEN if you keep the platform credential in a manager too.
If you would rather not manage a provider key at all, use the Veryfront Cloud AI Gateway instead.
Explicit provider env vars still work when you want to pin a provider directly:
import { agent } from "veryfront/agent"; export default agent({ model: "openai/gpt-5.5", // OpenAI // model: "anthropic/claude-sonnet-4-6", // Anthropic // model: "google/gemini-3.5-flash", // Google // model: "veryfront-cloud/mistral/mistral-small-2503", // Mistral through AI Gateway system: "You are a helpful assistant.",});Enable OpenAI-hosted web search
Declare web_search in the agent's provider tools. Veryfront routes the call
through OpenAI's Responses API, including for models that otherwise use Chat
Completions:
import { agent } from "veryfront/agent"; export default agent({ model: "openai/gpt-4.1", providerTools: ["web_search"],});This tool requires an OpenAI endpoint that implements the Responses and hosted
web-search contracts. See the
ext-llm-openai reference
for supported identifiers, arguments, and replay limits.
Embedded ONNX inference
Embedded inference is explicit. Use a local/* model when you want the app
server process to run a curated ONNX model through @huggingface/transformers.
For local chat development, use Ollama or LM Studio unless you specifically
need the model to run inside the app process.
For Node.js or Bun, install the optional runtime alongside Veryfront. Deno resolves the runtime on first use.
npm install @huggingface/transformersThe Transformers and ONNX packages add approximately 500 MB before model weights.
Embedded ONNX inference is not available from compiled standalone binaries. Use a package-manager installation of Veryfront for this inference path.
Select a supported model:
import { agent } from "veryfront/agent"; export default agent({ model: "local/qwen3.5-0.8b", system: "You are a helpful assistant.",});The selected model is downloaded and cached on first use. If the runtime cannot
load ONNX, the chat handler returns a 503 setup error. Veryfront never starts
an embedded model automatically.
Embedded ONNX inference uses CPU by default. To request WebGPU, use:
export VERYFRONT_LOCAL_AI_DEVICE=webgpuIf WebGPU is requested but unavailable, Veryfront returns a setup error instead of retrying on CPU.
To enable Gemma4 thinking in the local prompt template, use:
export VERYFRONT_LOCAL_AI_THINKING=1Thinking is disabled by default.
To disable embedded ONNX inference, use:
export VERYFRONT_DISABLE_LOCAL_AI=1Model strings
Agents reference models as "provider/model". The framework splits on the first /, so nested model IDs work:
// Veryfront Cloud explicit overrideagent({ model: "veryfront-cloud/openai/gpt-5.5" });agent({ model: "veryfront-cloud/mistral/mistral-small-2503" }); // Direct provider overrideagent({ model: "openai/gpt-5.5" }); // Nested model ID (e.g. OpenRouter)agent({ model: "openai/meta-llama/llama-3.1-405b" });OpenAI-compatible services
Override the base URL to route through an OpenAI-compatible API. Public HTTPS services such as OpenRouter work without changing the host network policy:
OPENAI_API_KEY=<API_KEY>OPENAI_BASE_URL=https://openrouter.ai/api/v1Both apiKey and baseURL are resolved per-request, so each project in a multi-tenant setup can have its own configuration.
Anthropic and Mistral take the same treatment, for a self-hosted deployment or a gateway in front of the vendor:
Include the API version segment in the value, matching the defaults above.
For local chat development, use Ollama or LM Studio. Both keep model loading and hardware management outside the Veryfront app process.
Local OpenAI-compatible servers need an explicit host-network opt-in. Veryfront
blocks loopback and private destinations by default to prevent server-side
request forgery. Set VERYFRONT_HOST_ALLOWED_INTERNAL_PROVIDER_ORIGINS to the
exact provider origins that Veryfront can reach. Include the scheme, host, and
port, but do not include /v1 or another path. Other internal destinations
remain blocked. Only the runtime operator can set this policy. A project
environment cannot grant itself access.
Ollama
Start Ollama and download a model. This example uses a model with tool-use support:
ollama pull qwen3:1.7bSet the OpenAI-compatible endpoint in the terminal that starts Veryfront:
export OPENAI_API_KEY="<TOKEN>"export OPENAI_BASE_URL="http://localhost:11434/v1"export VERYFRONT_HOST_ALLOWED_INTERNAL_PROVIDER_ORIGINS="http://localhost:11434"Use the Ollama model ID under the openai provider:
agent({ model: "openai/qwen3:1.7b" });Ollama ignores the token by default, but Veryfront requires a non-empty value
for OPENAI_API_KEY. See
Ollama OpenAI compatibility.
LM Studio
Load a model in LM Studio, start its local server on port 1234, then list the model IDs it exposes:
lms server start --port 1234curl http://localhost:1234/v1/modelsSet the endpoint in the terminal that starts Veryfront:
export OPENAI_API_KEY="<TOKEN>"export OPENAI_BASE_URL="http://localhost:1234/v1"export VERYFRONT_HOST_ALLOWED_INTERNAL_PROVIDER_ORIGINS="http://localhost:1234"Use an ID returned by /v1/models. For example:
agent({ model: "openai/qwen2.5-7b-instruct", system: "You are a helpful local assistant.",});LM Studio does not require a token unless you enable authentication, but
Veryfront still requires a non-empty OPENAI_API_KEY. See
LM Studio OpenAI compatibility.
Model behavior varies in both runtimes. Select a model with native tool-use support when the agent uses tools.
Custom provider registration
For providers not covered by env vars, use registerModelProvider():
import { registerModelProvider } from "veryfront/provider"; const unregisterOllama = registerModelProvider("ollama", (id) => { // Return a framework-compatible model runtime for this model ID. // Prefer built-in providers when possible; custom registration is an // advanced interop surface for non-standard backends. The runtime must // implement the framework's generation hooks, including doGenerate() // and doStream(). return createOllamaRuntime(id);}); // Then use itagent({ model: "ollama/llama3.2" });The factory receives the model ID and must return a framework-compatible model
runtime with the generation surface the framework expects, including
doGenerate() and doStream().
Registration inside a project source context is isolated to that project.
Registration during application bootstrap, outside a project context, becomes
the default for every project unless a project registers an override. The
returned disposer removes only the registration created by that call.
Call unregisterOllama() during application teardown when the registration is
no longer needed.
Direct model resolution
For cases outside the agent system:
import { resolveModel } from "veryfront/provider"; const model = resolveModel("openai/gpt-5.5");const cloudModel = resolveModel("veryfront-cloud/openai/gpt-5.5");Provider authentication errors
Native provider HTTP 401 and 403 refusals produce agent-provider-auth-error
with the message "Agent provider authentication failed". Check your provider
credential and its permissions before running the agent again. Provider response
text and credentials stay private. Gateway inference policy refusals retain their
specific policy error; rate limits and service failures retain their existing
classification.
Verify it worked
Call your agent's AG-UI route once provider env vars are set:
curl -N http://localhost:3000/api/ag-ui \ -H "Content-Type: application/json" \ -H "Cookie: __Host-vf_csrf=local-check" \ -H "x-csrf-token: local-check" \ -d '{"messages":[{"id":"1","role":"user","parts":[{"type":"text","text":"Reply with the active inference mode if available."}]}]}'A token stream that ends without an authentication error means the provider
resolved. In a chat UI, the inferenceMode field on useChat reports
whether the call used cloud, server-local, or browser inference.
Local file input
Use fileFromBytes from veryfront/llm to send a local PDF without an upload link.
The helper accepts Uint8Array bytes, including Node.js Buffer values, and
returns a file part for generate or agent messages.
import { readFile } from "node:fs/promises";import { fileFromBytes, generate } from "veryfront/llm"; const file = fileFromBytes({ bytes: await readFile("report.pdf"), filename: "report.pdf", mediaType: "application/pdf", maxBytes: 4 * 1024 * 1024,}); const result = await generate({ model: "openai/gpt-5.5", input: [{ id: "report-request", role: "user", parts: [{ type: "text", text: "Summarize this report." }, file], }],});console.log(result.text);Configure your direct provider key as described above. No Veryfront Cloud token
or file-upload service is required. Deno applications can use Deno.readFile,
and browser applications can use new Uint8Array(await file.arrayBuffer()) to
obtain bytes before passing them to trusted server code.
The framework encodes bytes internally. OpenAI Responses receives file_data,
Anthropic receives a base64 document source for PDFs, and Google receives
inlineData. OpenAI Responses and Anthropic also accept PDF URLs. Google
accepts URLs for images and Gemini Files API URIs only, so send other files to
Google as inline data. Inline files on OpenAI Responses must be a PDF, text,
code, JSON, XML, or office document. Inline files on Google must be an image,
audio, video, PDF, text, code, JSON, or XML file.
A file part that a transport cannot send fails before inference with an error
that names the file and MIME type. Chat Completions transports reject all
non-image files, and Anthropic rejects files other than images and PDFs. OpenAI
and Veryfront Cloud OpenAI models on the default auto transport send requests
with non-image files through Responses. Mistral and custom OpenAI-compatible
base URLs do not move a request to Responses for a file, so Chat Completions
rejects it. This includes an OpenAI model created with a baseURL that is not
on api.openai.com. Reasoning models and hosted tools still use Responses there.
Set openAITransport: "responses" when a model is pinned to Chat Completions or
its compatible server implements Responses. Select a model that supports the file type. The helper does
not add model capabilities. The check covers stored chat history too, so a
conversation with a document attachment needs a document-capable model on every
later turn.
maxBytes limits one file before encoding. Hosted durable runs record each
model call, and a record over 10 MiB refuses the call, so keep inline files well
below that after base64 encoding. Use planFileParts
below for aggregate attachment budgets. Base64 adds about one third to request size;
provider request and model limits still apply. The helper does not validate file
contents or extract text. Filenames and MIME types must describe the actual file.
The filename must be a base name such as report.pdf, not a path, a drive prefix such as C:, or ./..,
without leading or trailing spaces, because providers receive it.
Attachment budgets
Use planFileParts to apply per-file, total, and count budgets to several files
without throwing. The result lists the parts to send and every omitted file with
a reason. complete is true only when every file is sent.
import { planFileParts } from "veryfront/llm"; const attachments = [ { bytes: await Deno.readFile("./invoice.pdf"), filename: "invoice.pdf", mediaType: "application/pdf", }, { bytes: await Deno.readFile("./notes.txt"), filename: "notes.txt", mediaType: "text/plain", },]; const plan = planFileParts({ files: attachments, // 6 MiB raw is about 8 MiB in base64, under the 10 MiB durable-run record limit. maxFileBytes: 4 * 1024 * 1024, maxTotalBytes: 6 * 1024 * 1024, maxFiles: 10,}); if (!plan.complete) { // Filenames can contain customer data, so log only index, bytes, and reason. console.warn( "Files not sent", plan.omitted.map(({ index, bytes, reason }) => ({ index, bytes, reason })), );}The helper checks files in input order. Omitted files do not use the budget, so a later smaller file can still be sent. An unset budget does not limit. Reasons are:
A file is a PDF when its MIME type is application/pdf or its filename ends in
.pdf. The filename must be a base name, as for fileFromBytes. Omitted
entries report only the base name of a filename and the lowercased MIME type,
or "" when either is invalid, so logging them does not leak local paths. Only
a non-array files value or an invalid budget throws INVALID_ARGUMENT.
Budgets count raw bytes only. The helper does not infer page counts or model context limits from file size, so a file within budget can still exceed a provider page or context limit. Treat an incomplete plan as incomplete input, for example by sending the result to review instead of automating on it.