Skip to content

AI SDK model integration

The /adapters/ai-sdk subpath translates AI SDK 7 capabilities into neutral llm-core ports. The version covered by the conformance suite is available as AI_SDK_SUPPORTED_VERSION.

Language model

createAiSdk7Model accepts an AI SDK LanguageModel and a registered ModelProfile. The returned value implements the neutral model contract.

The adapter translates:

  • neutral model requests and tool declarations into AI SDK calls;
  • generated content, usage, warnings, and tool calls back into neutral results;
  • live abort signals through an optional trusted resolver;
  • provider approval requests into a classification hook that can deny or request approval, but cannot authorize execution.

AI SDK tool definitions created by this adapter have no executor. Meaningful effects still pass through llm-core controlled tool execution.

Provider metadata

The composition root must supply nativeContract with two executable boundaries:

  • redact receives a validated JSON snapshot of each native fact and returns the safe projection that may cross the application boundary;
  • observe receives the redacted fact under the dev.ai-sdk namespace.

Completion content, warning detail, approval records, generated files, sources, response metadata, provider metadata, step results, final-step state and structured output cross this boundary before a completion can succeed. Every AI SDK stream part crosses the same boundary before its neutral projection is emitted. The safe redaction result, rather than the original provider value, is the only source for portable warnings, response identifiers and structured output.

Snapshots reject proxies before reflection and reject accessors, non-enumerable data, symbols, sparse arrays, array extras, cycles and non-portable prototypes without invoking hidden code. Redactor inputs, observer events and returned projections are detached and deeply frozen. A missing or rejected projection, an observer failure or invalid native value fails the affected model operation rather than silently dropping the fact.

Redacted top-level provider metadata is also recorded in the response's dev.ai-sdk extension with the exact [email protected] and @ai-sdk/[email protected] authority. Portable warnings retain the supported AI SDK warning type and detail.

AI_SDK7_OPERATION_DISPOSITIONS is the closed operation matrix for this adapter authority. generateText, streamText, provider metadata, warnings, approvals, generated files, sources and the closed API-call, abort and generic-error families are supported. Step snapshots preserve call identity, ordering, content, finish reasons, usage, performance, warnings, request, response and provider metadata. The executable model handle and execution-only runtime and tools contexts are explicitly unsupported. Raw stream parts and provider-executed tool facts are rejected before observation or portable projection. Diagnostic stacks and unregistered AI SDK error families are also unsupported. The matrix contains no not-applicable claims.

Media

The same subpath exports:

FactoryNeutral port
fromAiSdkImageModelImageGenerationPort
fromAiSdkSpeechModelSpeechGenerationPort
fromAiSdkTranscriptionModelTranscriptionPort

Media input may contain live bytes or an integrity-bound resource reference. Referenced media requires an authorized resolver. Generated bytes cross a MediaOutputProjector before they become portable content.

The adapter validates exact output counts, media types, resource length and digest, and closed result shapes. A native failure becomes a stable boundary error rather than leaking a provider payload.

Retrieval helpers

createAiSdkEmbedder implements Embedder for one or many non-blank text values. createAiSdkReranker maps the native ranking back to the supplied portable documents and their relevance scores.

These are capability adapters, not an orchestration layer. Retrieval, reranking, model calls, and effects remain separately composed by the application.