Blocking unapproved OpenAI models at runtime when developers change the model parameter in code
To block unapproved OpenAI models, enforce an approved-model list at request time in the execution path, and treat the model parameter as untrusted input. Code review, documentation and key-level controls act before or around the request, so a changed model string can still reach the API. An in-path check that compares the requested model to the allowlist, returns an explicit allow or block outcome and records each decision closes that gap.
Why review and key controls leave a gap
The model name in an LLM request is a string. It can sit in application code, an SDK call, an environment variable or a configuration file, and any developer who can change one of those can change the model. A newer, costlier or unvetted model then reaches production through an ordinary pull request or a configuration edit.
Code review depends on a reviewer noticing the change, and it cannot see values that are resolved at runtime. Internal documentation tells developers what is approved but enforces nothing. API key scoping limits who can call the service, but a key is not a per-request statement of which model is acceptable for which application.
NIST draft guidance on AI data center security (SP 800-239, initial public draft) treats every request as a potential threat and warns that unapproved models reaching production can have serious consequences. Applied to LLM calls, that means the model parameter should be validated on each request rather than trusted because it came from your own codebase. Treat these NIST documents as draft guidance, not binding requirements.
Enforcement points, ordered by strength
The ordering below is editorial judgment based on where each control sits relative to the request. The stronger the position in the execution path, the less it depends on developer behavior.
- Code-level checks: A shared helper validates the model before calling the API. Easy to adopt, but it relies on every team using the helper and can be bypassed by calling the SDK directly.
- CI checks: Pipelines scan for model names and fail the build on unapproved values. Catches static literals before merge. Cannot see values resolved at runtime and does not apply when code is deployed outside the pipeline.
- Network or egress proxy: Outbound traffic to the provider is forced through a proxy that can inspect requests. Applies regardless of the code, provided traffic cannot route around it. Policy depth depends on how well the proxy understands each API surface.
- Provider-side project restrictions: Restrictions configured in the provider account are a useful backstop where available. Confirm they can express your approved list per team and application, and that decision evidence is held in systems you control.
- In-path runtime policy: A policy layer in the execution path evaluates each request against the approved list and returns an outcome before the call proceeds. It covers code, configuration and SDK overrides, and produces the evidence record.
Designing the per-request check
Start by placing the check where every model call must pass, then decide what it evaluates and what it returns. These layers complement each other. CI checks and provider-side restrictions can reduce noise and add depth, while the in-path check is the control that holds when the others miss.
Define the approved list as data, not code, so that it has an owner, a version and a change history. Scope entries by team or application where needs differ, since one global list is rarely right for a regulated enterprise.
Decide the block behavior in advance. A hard block with a clear error is the simplest and most predictable. Rewriting a request to a different model changes what the caller receives and should be an explicit policy choice, not a default.
- Force all provider traffic through the enforcement point and deny direct egress.
- Read the requested model from every API surface the organization uses, not only chat-style calls.
- Normalize the identifier, then match it against a versioned allowlist.
- Treat anything that does not match as blocked, including unknown names.
- Return a defined error to the caller and raise an alert on repeated blocks.
- Write the decision to durable storage with the policy version.
Handling aliases, pinned names and custom models
Model identifiers can take more than one form. A name may refer to a general family, a version-pinned release, or a customer-specific model such as a fine-tuned one. An allowlist that matches loosely, for example by prefix, can approve models nobody reviewed. An allowlist that matches only one string can break when a team legitimately uses a pinned equivalent.
A safer approach is to list approved identifiers explicitly and decide, for each, whether the pinned and unpinned forms are both permitted. Approve custom or fine-tuned identifiers individually, since each reflects separate training and review. Default to deny for any value that is not listed, so a new name is blocked until someone approves it.
Also check how the model value can be supplied. SDK-level overrides, configuration files and per-request arguments can all set it, and different API endpoints may carry it in different places. The enforcement point should read the value from the request as sent, not from what the application claims it intended.
Evidence each decision should produce
NIST draft guidance names logging API calls and their responses as a key initial step for detecting suspicious activity, and it supports retaining records of internal protections. For model enforcement, the record that answers an auditor's question is the decision itself.
Each record should capture the requested model, the policy version applied, the outcome (allowed or blocked), the requester identity and a timestamp. Requester identity matters because traceable credentials and scoped access let you attribute a request to a team, service or person. Retain blocked requests as well as allowed ones, because they show the control operating.
Set retention and export rules before rollout. Decide how long records are kept, where they are stored and how they reach the systems auditors already use. A record that cannot be produced when asked has little value.
Runtime enforcement with Trussed
Trussed enforces policy in the execution path across models, agents, tools, MCP servers, AI sites and coding assistants. Policy outcomes include allow, redact, block, rate limit and escalate for human approval, applied to individual interactions and tool calls. For this use case, a request naming a model outside the approved list is enforced at runtime, not reviewed after the fact, whatever the application code or configuration specifies.
Enforcement generates audit-ready evidence continuously, mapped to frameworks including HIPAA, NAIC, NYDFS, the EU AI Act and NIST. Trussed can be self-managed in the customer cloud, with configurable retention and data residency. It has run in continuous production in a regulated enterprise for more than 18 months and brings 100+ models under one policy plane.
Whichever approach you choose, test it with the cases above: a changed model string, a pinned name, a custom model identifier and a direct SDK override. The control is working when each is allowed or blocked as policy says and each leaves a record.
Per-request model check
Request
Application or SDK call carries a model value.
Evaluate
Requested model is normalized and compared with the approved list.
Decide
Allow, or block with a defined response to the caller.
Record
Decision, policy version and requester are retained as evidence.
See per-request model enforcement in practice
Review how an approved-model policy is enforced in the execution path and how each decision becomes audit-ready evidence.
Talk to an ExpertHow does your AI governance program compare?
See where your program has gaps in less than 2 minutes.