veryfront/provider

Import

TypeScript
import {  clearModelProviders,  ensureModelReady,  getRegisteredModelProviders,  hasModelProvider,  registerModelProvider,  resolveModel,} from "veryfront/provider";

Examples

Resolve a model

TypeScript
import { resolveModel } from "veryfront/provider"; const model = resolveModel("veryfront-cloud/openai/gpt-5-nano");

API

registerModelProvider(name, factory)

Register a custom model provider factory for the active project scope or application bootstrap.

Returns: ModelProviderRegistrationDisposer

resolveModel(modelString)

Resolve a "provider/model" string to a framework-compatible model runtime.

Returns: ModelRuntime

hasModelProvider(name)

Check whether a model provider is available in the current scope.

Returns: boolean

getRegisteredModelProviders()

Get provider names available in the current scope.

Returns: string[]

clearModelProviders()

Clear all registered model providers and reset lazy built-ins (for testing).

Returns: void

Exports

Components

NameDescriptionSource
DEFAULT_VERYFRONT_CLOUD_MODEL_IDShort ID of the built-in default model. resolveVeryfrontCloudModelId() resolves a short ID only through a loaded served catalog. Where no catalog may have loaded, use resolveVeryfrontCloudDefaultModelId(), which returns the provider-qualified default either way.source
VERYFRONT_CLOUD_MODEL_PREFIXShared Veryfront Cloud model prefix value.source

Functions

NameDescriptionSource
clearModelProvidersClear all registered model providers and reset lazy built-ins (for testing).source
ensureModelReadyEagerly verify that the resolved model's runtime is available.source
getRegisteredModelProvidersGet provider names available in the current scope.source
getVeryfrontCloudProviderFromModelIdReturn the Veryfront Cloud provider named by a model ID, including a provider this package does not list.source
hasModelProviderCheck whether a model provider is available in the current scope.source
loadVeryfrontCloudModelCatalogLoad the model catalog Veryfront Cloud serves, with the Veryfront Cloud credentials and project in effect, so model facts read synchronously afterward (thinking defaults, short aliases such as opus, the default model) come from it. Resolves to whether a catalog is available. Never throws. When a refresh fails, the last catalog loaded for these credentials stays in use. While none has loaded (no credentials, or no load has succeeded yet), reads use protocol defaults only: resolveVeryfrontCloudModelId() resolves no short alias and no model has a thinking default.source
normalizeVeryfrontCloudModelIdNormalizes Veryfront Cloud model ID.source
registerModelProviderRegister a custom model provider factory for the active project scope or application bootstrap.source
resolveHostedVeryfrontCloudModelIdPrefix a model ID for a hosted run. Alias of resolveVeryfrontCloudGatewayModelId, with the same contract: call it only once Veryfront Cloud is the chosen backend, because it prefixes ANY well-formed provider segment, including providers this package does not list. Read that function's documentation before calling this one.source
resolveModelResolve a "provider/model" string to a framework-compatible model runtime.source
resolveVeryfrontCloudDefaultModelIdProvider-qualified ID of the default model: the one the served catalog names once it is loaded, otherwise the built-in default.source
resolveVeryfrontCloudGatewayModelIdPrefix a model ID so it resolves through the Veryfront Cloud gateway, including a provider this package does not list.source
resolveVeryfrontCloudModelIdResolve a model ID or short alias to a provider-qualified model ID.source
resolveVeryfrontCloudModelThinkingResolves Veryfront Cloud model thinking.source
resolveVeryfrontCloudReasoningOptionResolves provider-neutral runtime reasoning for a Veryfront Cloud model.source
resolveVeryfrontCloudThinkingProviderOptionsOptions accepted by resolve Veryfront Cloud thinking provider.source
tryGetVeryfrontCloudProviderFromModelIdReturn the Veryfront Cloud provider named by a model ID, including one this package does not list, or undefined when the ID names none.source

Types

NameDescriptionSource
ModelProviderFactoryPublic API contract for model provider factory.source
ModelProviderRegistrationDisposersource
ModelRuntimePublic API contract for model runtime.source
VeryfrontCloudModelIdA provider-qualified Veryfront Cloud model ID, for example anthropic/claude-sonnet-4-6. Any provider and model the platform serves fits, so a new model needs no release of this package.source
VeryfrontCloudModelThinkingConfigConfiguration used by Veryfront Cloud model thinking.source
VeryfrontCloudProviderIdA Veryfront Cloud provider ID: a listed provider, or any other well-formed provider string.source
VeryfrontCloudRuntimeModelIdA model ID routed through Veryfront Cloud: veryfront-cloud/<provider>/<model>.source

Deep imports

These import paths group focused functionality under this module. Each is a separate barrel; import only what you need.

veryfront/provider/openai-reasoning

TypeScript
import {  getDefaultOpenAIReasoningEffort,  isOpenAIReasoningModel,  rejectsOpenAISamplingParams,} from "veryfront/provider/openai-reasoning";

Functions

NameDescriptionSource
getDefaultOpenAIReasoningEffortsource
isOpenAIReasoningModelsource
rejectsOpenAISamplingParamssource
resolveOpenAIReasoningConfigsource
shouldRequestOpenAIReasoningSummarysource
supportsDefaultReasoningParamssource

Types

NameDescriptionSource
OpenAIProviderReasoningEffortsource
OpenAIProviderReasoningOptionsource
OpenAIReasoningEffortsource
ResolvedOpenAIReasoningsource

veryfront/provider/shared

Shared plumbing consumed by the @veryfront/ext-* provider extensions. This barrel is the stable extension-facing surface. Implementations remain internal to runtime-loader.ts and runtime-loader/; their physical location may change without changing extension imports.

TypeScript
import {  buildProviderError,  closeSchemaForOutputConfig,  createAnthropicRequestInit,} from "veryfront/provider/shared";

Components

NameDescriptionSource
DEFAULT_PROVIDER_STREAM_HEADERS_TIMEOUT_MSDefault deadline for one stream attempt to return response headers.source
DEFAULT_PROVIDER_STREAM_IDLE_TIMEOUT_MSDefault deadline for the next chunk of a stream response body.source
DEFAULT_PROVIDER_STREAM_TOTAL_HEADERS_BUDGET_MSCeiling on the wall time replays may spend waiting for stream response headers.source
MAX_PROVIDER_SSE_BUFFER_CODE_UNITSMaximum decoded provider SSE data retained or parsed in one pass.source
STREAM_FRAGMENT_COMPACTION_SIZEFragments joined into one string at a time, bounding array growth.source
TOOL_INPUT_PENDING_THRESHOLD_MSShared tool input pending threshold ms value.source
VERYFRONT_PROVIDER_STREAM_IDLE_TIMEOUT_ENVEnvironment key overriding the stream body idle deadline, in milliseconds.source

Functions

NameDescriptionSource
buildProviderErrorInspect a non-2xx response and build the most specific ProviderError subclass we can. Reads the response body as text (it's already dead on the wire by this point). Body classification handles the cases where HTTP status alone is ambiguous - notably OpenAI insufficient_quota vs rate_limit_exceeded both arriving as 429.source
closeSchemaForOutputConfigClose every object in a schema bound for output_config.source
createAnthropicRequestInitCreate Anthropic request init.source
createClassifiedProviderStreamProtocolErrorCreate a ProviderStreamProtocolError with a trusted WeakMap classification.source
createClassifiedStreamRangeErrorCreate a native RangeError with a trusted WeakMap classification.source
createGoogleRequestInitCreate Google request init.source
createOpenAIRequestInitCreate request init options for OpenAI-compatible providers.source
createStreamRetentionBudgetCreate an empty retention budget.source
createWarningCollectorCreate warning collector.source
fileInputBaseNameThe base name of a file part's filename, or undefined when none is usable. Requests and errors leave the machine, so a local path must not.source
getAnthropicMessagesUrlReturn Anthropic messages URL.source
getGoogleEmbeddingUrlReturn Google embedding URL.source
getGoogleGenerateContentUrlReturn Google generate content URL.source
getGoogleStreamGenerateContentUrlReturn Google stream generate content URL.source
getOpenAIChatCompletionsUrlReturn OpenAI chat completions URL.source
getOpenAIEmbeddingUrlReturn OpenAI embedding URL.source
getOpenAIResponsesUrlReturn OpenAI responses URL.source
isImageFileInputWhether a prompt part is an image. MIME types compare case-insensitively.source
isNumberArrayCheck whether a value is an array of numbers.source
isProxyWithoutHooksIdentify a Proxy without evaluating any trap on the proxied value.source
jsonValuesEqualCompare JSON-compatible values independently of object key order.source
mergeUsageMerge provider usage counters.source
notifyProviderRequestRetryReport a provider request retry to the debug log and to the active observer. An observer that throws, or whose promise rejects, never affects the request.source
parseFinalSseChunkParse the final unterminated SSE block without making the synthetic frame delimiter count against the caller-visible retention boundary.source
parseRetryAfterMsParses retry after ms.source
parseSseChunkParse a bounded provider SSE buffer.source
promptHasDocumentInputWhether a prompt carries a non-image file in a user message.source
readGatewayBillingModeRead a trusted gateway billing mode from provider metadata.source
readGatewayUsageCostsRead the credit amount of a gateway veryfront usage envelope.source
readInlineFileDataRead the base64 payload of an inline data: file part. Returns undefined for remote URLs. MIME types compare case-insensitively.source
readProviderOptionsOptions accepted by read provider.source
readRecordRecord shape for read.source
readRemoteFileUrlReturn a remote file URL, or throw before inference. A local path or other non-HTTP scheme must not reach the provider request.source
readTextPartsRead text content parts from provider messages.source
requestJsonRequest and parse a bounded JSON response.source
requestStreamRequest a streaming response. When the request body is replayable, typed retryable failures are retried up to two times before provider output is exposed. Each attempt gets a fresh stream header deadline, and replays are capped so the whole header wait stays inside one shared budget. ReadableStream request bodies are not retried because fetch can consume them on the first attempt.source
reserveStreamRetentionReserve room for one streamed fragment. Returns the exceeded limit without changing the budget, or undefined once the fragment is accounted for.source
routesOpenAIDocumentInputToResponsesWhether an OpenAI-wire provider serves document input on Responses, so the auto transport may move a request with a document there. Mistral and generic compatible servers do not, and keep the local Chat Completions error. An openai provider on a custom base URL is a compatible server too.source
snapshotJsonValueCreate a bounded, deeply owned, accessor-free snapshot of a JSON value.source
snapshotProviderJsonValueCreate the provider-boundary snapshot used by request builders.source
stringifyJsonValueSerialize a JSON-compatible value.source
stringifyToolArgumentsPreserve provider-native argument text while serializing structured tool inputs.source
stringifyToolResultValuePreserve text tool results while serializing structured tool results.source
toOpenAICompatibleMessagesConvert runtime prompt messages into OpenAI-compatible chat messages. Adjacent non-empty system layers become one ordered instruction so strict Chat Completions providers receive a compatible message sequence. A verified transport capability can preserve the original system message boundaries.source
toOpenAICompatibleToolsConvert runtime tool definitions into OpenAI-compatible function tools.source
unsupportedFileInputErrorError for a file part that a provider transport cannot send.source
unwrapToolInputSchemaZod schema for unwrap tool input.source
waitForProviderStreamRetryWait out a retry delay, rejecting the moment the caller cancels. Shared with providers that must replay a request the SSE body failed, so every retry path honors cancellation the same way.source
withToolInputStatusTransitionsApplies tool input status transitions.source

Classes

NameDescriptionSource
ProviderErrorBase class for typed provider errors. The retryable flag is the primary signal for callers (or a retry wrapper) to decide whether to re-issue the request. retryAfterMs is set when the provider gave an explicit delay hint (Retry-After header, Retry-Info trailer).source
ProviderOutputTruncatedErrorProvider stopped generating at the output token limit, leaving the response incomplete (for example a tool_use block whose input JSON never closed).source
ProviderOverloadedErrorProvider reports it is overloaded (Anthropic 529, OpenAI/Google 503).source
ProviderQuotaErrorProvider account quota is exhausted - non-retryable.source
ProviderRateLimitErrorProvider is rate limiting this API key (OpenAI/Google 429 with Retry-After).source
ProviderRequestErrorNon-retryable 4xx/5xx that doesn't fit another bucket.source
ProviderStreamProtocolErrorProvider answered with a successful status, but its response stream broke the provider's own event protocol, so the runtime could not read it.source
StreamFragmentBufferAccumulates streamed string fragments with storage proportional to their content rather than to how many fragments the provider sent. Every STREAM_FRAGMENT_COMPACTION_SIZE fragments are joined into one string, so millions of one-byte deltas do not become millions of array entries.source

Types

NameDescriptionSource
JsonSnapshotOptionsResource limits applied while taking a provider-boundary JSON snapshot.source
JsonSnapshotValueA deeply owned JSON value returned by snapshotJsonValue.source
ModelRuntimeCallOptionsCanonical request contract passed to ModelRuntime generation hooks.source
ModelRuntimePromptMessageImmutable prompt view accepted by model-runtime calls.source
ModelRuntimeToolDefinitionCanonical tool definition sent to a model runtime.source
OpenAICompatibleChatMessageMessage shape for OpenAI-compatible chat requests.source
OpenAICompatibleChatRequestRequest payload for OpenAI-compatible chat completion providers.source
ProviderWarningStructured warning emitted when a provider runtime drops or rewrites a caller-provided option. Mirrors the AI ecosystem convention (Vercel AI SDK, LangChain) of returning unsupported-setting warnings on the runtime result so callers can discover silently-dropped fields without having to read the source.source
RuntimeAssistantContentPartCanonical assistant content accepted when invoking a model runtime.source
RuntimePromptMessageHistorical mutable provider-facing prompt contract retained for source compatibility.source
RuntimeReasoningOptionProvider-neutral reasoning controls accepted by model runtimes.source
RuntimeResponseFormatProvider-neutral structured-output request.source
RuntimeUsageCanonical provider-neutral usage reported by text-generation runtimes.source
StreamRetentionBudgetRunning totals for one retention budget. Create with createStreamRetentionBudget.source
StreamRetentionLimitsRetention bounds for content a provider stream adapter keeps while it assembles a response: tool-call arguments, and raw text or reasoning kept for replay.source
StreamRetentionOverflowWhich limit a fragment would exceed.source

Constants

NameDescriptionSource
canIdentifyProxyWithoutHooksWhether this runtime can distinguish Proxy values without evaluating a trap. Callers that need a fail-closed guarantee must not treat a false result from isProxyWithoutHooks as proof when this capability is absent.source

veryfront/provider/types

TypeScript
import type {  EmbeddingRuntime,  ModelRuntime,  ModelRuntimeCallOptions,} from "veryfront/provider/types";

Types

NameDescriptionSource
EmbeddingRuntimesource
ModelRuntimePublic API contract for model runtime.source
ModelRuntimeCallOptionsCanonical request contract passed to ModelRuntime generation hooks.source
ModelRuntimeCapabilitiesExplicit behavioral support advertised by a model runtime.source
ModelRuntimeGenerateResultsource
ModelRuntimePromptMessageImmutable prompt view accepted by model-runtime calls.source
ModelRuntimeStreamResultsource
ModelRuntimeToolDefinitionCanonical tool definition sent to a model runtime.source
RuntimeAssistantContentPartCanonical assistant content accepted when invoking a model runtime.source
RuntimeMetadatasource
RuntimePromptMessageHistorical mutable provider-facing prompt contract retained for source compatibility.source
RuntimeReasoningOptionProvider-neutral reasoning controls accepted by model runtimes.source
RuntimeResponseFormatProvider-neutral structured-output request.source
RuntimeStructuredOutputVariantsource

veryfront/provider/veryfront-cloud/cli-context

Narrow public boundary for first-party CLI operations that need to execute provider work inside a Veryfront Cloud request context.

TypeScript
import { runWithVeryfrontCloudContextAsync } from "veryfront/provider/veryfront-cloud/cli-context";

Functions

NameDescriptionSource
runWithVeryfrontCloudContextAsyncRun with Veryfront Cloud context async.source

Types

NameDescriptionSource
VeryfrontCloudContextContext for Veryfront Cloud.source