AI SDK model-ID autocomplete is not a runtime allowlist

If your application must restrict which models a caller can select, do not use the AI SDK’s model-ID autocomplete list as the enforcement boundary. In the documented @ai-sdk/openai-compatible example, accepting IDs outside that list is intentional.

This matters when a model ID comes from configuration, a request field, or a user-selectable setting rather than a literal you type in the editor.

What the autocomplete example actually promises

The AI SDK’s “Including model ids for auto-completion” section defines four types:

Type Where the documentation uses that family of ID
ExampleChatModelIds chatModel(id)
ExampleCompletionModelIds completionModel(id)
ExampleEmbeddingModelIds embeddingModel(id)
ExampleImageModelIds imageModel(id)

Each union combines named string literals with (string & {}). The four types are then supplied to createOpenAICompatible in chat, completion, embedding, image order. The language-model section also documents provider(id) and languageModel(id) as chat-model constructors.

The example’s comment makes the intended tradeoff explicit: model.chatModel offers autocomplete from ExampleChatModelIds “while still allowing free-form strings as well.” The named entries are suggestions, not an exhaustive permitted set. Treat those IDs as documentation examples, not as a current catalog for your endpoint.

Separate three different questions

A review of model selection should distinguish:

  1. Does the editor suggest this ID, or does the type accept it? The documented example deliberately accepts free-form strings.
  2. Does this application permit the selection? That is an application-policy decision, not established by the autocomplete example.
  3. Can this endpoint successfully serve the requested operation with this account? Neither a suggested ID nor constructing a model object proves that.

The engineering consequence is straightforward: a caller-supplied string can fit the documented type without belonging to your intended application allowlist. Even replacing the permissive union with a narrower TypeScript type does not, by itself, add a runtime membership check to external input.

That is a boundary argument, not a claim that the SDK or a provider has no other controls.

Put the restriction before model construction

For an application that requires restricted selection, I would use this flow:

  • Select a trusted provider configuration and the intended model family first. Keep policy specific to that combination rather than maintaining one undifferentiated list of IDs.
  • Treat an externally supplied model ID as unvalidated input. Check that it is a string and an exact member of the application’s approved set.
  • Reject an unapproved value before passing it to chatModel, completionModel, embeddingModel, or imageModel. Do not silently forward it just because the SDK type accepts it.
  • Pass only the validated value into the appropriate factory. Keep remote request handling separate: locally allowed does not mean remotely available or authorized.

These are proposed application controls, not a built-in AI SDK allowlist feature documented on this page.

A useful test plan would include an approved ID, an unlisted but plausible ID, a non-string input, and an ID approved for a different provider or model family. For rejected inputs, check both the application error and the absence of an outgoing model request. Separately test the approved path against the intended endpoint; that answers a different question from whether local policy rejected bad input.

No compiler check or endpoint request was run for this article. The source is the AI SDK OpenAI Compatible Providers documentation, captured September 13, 2026, with no supplied publication date; this is not a claim of a newly released feature.

Keep autocomplete for developer convenience. Use an explicit runtime check when “these are the suggested IDs” needs to become “these are the only selections this application permits.”

The operational failure mode here is treating “the SDK accepted the string” as a successful routing decision. I would make the boundary observable and fail closed:

  1. Record the requested model ID, provider/model-family policy key, and validation result (but avoid logging prompts or credentials).
  2. Reject a non-string or non-member before constructing the SDK model object. Emit a metric such as model_selection_rejected_total tagged only with a safe policy reason, and stop—do not retry a policy rejection.
  3. For an approved ID, construct the model and call the endpoint. Track request outcome separately (model_request_success_total, rate limits, timeouts, and other provider errors). A successful local check is not evidence that the remote model is available.
  4. Escalate when an approved ID repeatedly produces availability or authorization errors; the response should be a policy/configuration review, not an automatic expansion of the allowlist. If the provider changes its catalog, pause that route until the approved set is reviewed.

A useful runbook test has two independent assertions: an unlisted-but-plausible ID produces no outgoing request, while an approved ID reaches the endpoint and reports its remote result separately. This distinction remains important even if the autocomplete union is narrowed: types can improve editor guidance, but the runtime gate still owns external input.