AI Docs
API
Class References
Function References
- text
- textOptions
- combineStrategies
- convertMessagesToModelMessages
- convertZodToJsonSchema
- createReplayStream
- embedding
- generateMessageId
- maxIterations
- messages
- modelMessageToUIMessage
- modelMessagesToUIMessages
- normalizeToUIMessage
- parsePartialJSON
- summarize
- toServerSentEventsStream
- toServerSentEventsResponse
- toolDefinition
- uiMessageToModelMessages
- realtimeToken
- untilFinishReason
Interface References
- AIAdapter
- AIAdapterConfig
- AgentLoopState
- AudioPart
- AudioVisualization
- BaseStreamChunk
- TextCompletionChunk
- TextOptions
- ChunkRecording
- ChunkStrategy
- ClientTool
- ContentPartSource
- ContentStreamChunk
- DefaultMessageMetadataByModality
- DocumentPart
- DoneStreamChunk
- EmbeddingOptions
- EmbeddingResult
- ErrorStreamChunk
- ImagePart
- InternalToolCallState
- JSONParser
- ModelMessage
- ProcessorResult
- ProcessorState
- RealtimeAdapter
- RealtimeClientOptions
- RealtimeConnection
- RealtimeMessage
- RealtimeSessionConfig
- RealtimeToken
- RealtimeTokenAdapter
- RealtimeTokenOptions
- ResponseFormat
- ServerTool
- StreamProcessorEvents
- StreamProcessorHandlers
- StreamProcessorOptions
- SummarizationOptions
- SummarizationResult
- TextPart
- ThinkingPart
- ThinkingStreamChunk
- Tool
- ToolCall
- ToolCallPart
- ToolCallStreamChunk
- ToolConfig
- ToolDefinition
- ToolDefinitionConfig
- ToolDefinitionInstance
- ToolInputAvailableStreamChunk
- ToolResultPart
- ToolResultStreamChunk
- UIMessage
- VideoPart
Type Alias References
- AgentLoopStrategy
- AnyClientTool
- TextStreamOptionsForModel
- TextStreamOptionsUnion
- ConstrainedContent
- ConstrainedModelMessage
- ContentPart
- ContentPartForModalities
- ExtractModalitiesForModel
- ExtractModelsFromAdapter
- InferToolInput
- InferToolName
- InferToolOutput
- MessagePart
- RealtimeEvent
- RealtimeMessagePart
- RealtimeMode
- RealtimeStatus
- ModalitiesArrayToUnion
- Modality
- StreamChunk
- ToolCallState
- ToolResultState
Variable References
AI/LLM: This documentation page is available in plain markdown format at/ai/latest/docs/reference/functions/keyedAdapter.md
keyedAdapter
ts
function keyedAdapter<TAdapter>(provider, create): KeyedAdapter<TAdapter>;Defined in: packages/ai/src/byok/keyed.ts:63
Wrap an adapter factory that needs a provider key. The host finds the key and calls create just before each call, so the key is not in your code or in a .env file. Works for every adapter kind: text, image, speech, audio, video, and the rest.
Type Parameters#
TAdapter#
TAdapter
Parameters#
provider#
string | ByokProvider<string>
The provider whose key create needs: a BYOK descriptor such as openaiByok (its env names are the fallback), or a provider id.
create#
(key) => TAdapter
Builds the adapter from the key.
Returns#
KeyedAdapter<TAdapter>
Throws#
Error when the provider id is not a valid BYOK slug.
Example#
ts
import { createOpenaiChat } from '@tanstack/ai-openai'
import { openaiByok } from '@tanstack/ai-openai/byok'
const adapter = keyedAdapter(openaiByok, (key) =>
createOpenaiChat('gpt-5.5', key),
)
// In a server route, with `getByokKey` from `@tanstack/ai/byok/server`:
const key = getByokKey(request, adapter.provider)
if (key) chat({ adapter: adapter.create(key), messages })