OpenAI Provider
Updated 19 days ago • May 3, 2026
@kortyx/openai is the OpenAI provider package for Kortyx.
It gives you two entry points:
openai: a batteries-included default provider selectorcreateOpenAI(...): an explicit factory for custom setup
1. Install the package
2. What the package exports
What each export is for:
openai: default provider selector for the fastest startcreateOpenAI(...): custom provider instance with explicit settingsMODELS: built-in OpenAI model ids exposed by the packagePROVIDER_ID: the provider id string, currently"openai"
3. Basic usage in the same file
openai is a provider selector, which means:
- it is callable:
openai("gpt-4.1-mini") - it also exposes provider metadata:
openai.id,openai.models
Good to know: The built-in model list gives autocomplete, but arbitrary OpenAI model ids are accepted as strings.
4. Shared app bootstrap usage
If you want one shared import path across your app, re-export openai from a bootstrap file such as src/lib/providers.ts.
Then import it from that file where you actually use it:
5. Advanced usage with explicit settings
Use createOpenAI(...) when you want app-owned configuration instead of the default environment-based setup.
Use the factory when you need to:
- pass
apiKeyexplicitly - use a custom
baseUrl - provide a custom
fetch
6. Credentials and first-use behavior
The default openai export resolves credentials on first use, not at import time.
Supported environment variables:
OPENAI_API_KEYKORTYX_OPENAI_API_KEY
If neither variable is set and you did not pass apiKey to createOpenAI(...), the provider throws a configuration error the first time an OpenAI model is actually used.
7. Create model refs for workflow and node params
You can also attach default model options to the ref itself:
Those become default options for later useReason(...) calls unless you override them at call time.
8. Use the model with useReason(...)
Good to know: Provider setup is not done on
createAgent(...). Model selection happens where you calluseReason(...)by passing a model ref.
9. Supported normalized call options
OpenAI currently maps these generic Kortyx options:
temperaturestreamingmaxOutputTokensstopSequencesabortSignalreasoning.effortreasoning.maxTokensresponseFormat.typeresponseFormat.schema
Current OpenAI provider options:
providerOptions.openai.reasoningEffortproviderOptions.openai.maxCompletionTokensproviderOptions.openai.serviceTierproviderOptions.openai.storeproviderOptions.openai.metadataproviderOptions.openai.systemMessageModeproviderOptions.openai.structuredOutputsproviderOptions.openai.strictJsonSchema
Current mapping details:
responseFormat.type: "json"maps to OpenAI JSON moderesponseFormat.schemamaps to OpenAI structured outputs unlessstructuredOutputsisfalse- reasoning models use
max_completion_tokens; non-reasoning models usemax_tokens - reasoning model system messages default to OpenAI developer messages
Current warning-backed gaps:
temperatureis omitted for OpenAI reasoning models unlessreasoning.effortis"none"on supported newer modelsreasoning.maxTokensis not a separate OpenAI reasoning budget; Kortyx maps output token limits to the provider field- unknown
providerOptionskeys are ignored and reported inresult.warnings
10. Normalized metadata you get back
OpenAI returns the normalized Kortyx result fields when the API provides them:
usagefinishReasonproviderMetadatawarningsraw
OpenAI-specific metadata currently includes fields such as:
providerIdmodelIdresponseIdresponseModelcreatedusagecachedTokensreasoningTokensacceptedPredictionTokensrejectedPredictionTokens
Use providerMetadata when you need debugging or observability details without coupling your app code to the raw provider payload shape.
Supported scope
@kortyx/openai currently supports text generation through OpenAI chat completions via useReason(...), including streaming and non-streaming invocation.
It does not currently expose the OpenAI Responses API, embeddings, image generation, audio, transcription, file APIs, or OpenAI-hosted tools. Check result.warnings when you rely on advanced generic options and want to verify how OpenAI handled them.
Available built-in OpenAI model ids
gpt-5.4gpt-5.4-minigpt-5.4-nanogpt-5.4-progpt-4.1gpt-4.1-minigpt-4ogpt-4o-minio4-mini
Next steps
- See Hooks for
useReason(...)behavior and structured output - See Provider API for the shared normalized provider contract