LLM API Security: Lock Down AI Endpoints in 2026

LLM API Security: Lock Down AI Endpoints in 2026

What happens when the API key that powers your customer-facing chatbot ends up in a public GitHub repository at 2 a.m.? Nothing good, and usually nothing fast. The key keeps working, the bills keep climbing, and nobody notices until the invoice arrives or a researcher emails your support inbox. That scenario captures why LLM API security has become its own discipline rather than a footnote in application security. An LLM endpoint is still an API, with keys, quotas, and object-level access rules, but it also accepts free-form natural language and often acts on the world through tools. That combination breaks several assumptions that ordinary API hardening depends on. (Application programming interface (Wikipedia))

This article walks through the threat model, the controls that actually hold up in production, and the mistakes teams make again and again when they ship their first LLM-backed feature.

Why an LLM endpoint cannot be treated as a standard REST API

Most API security advice assumes inputs are structured. You validate a JSON schema, reject unexpected fields, and move on. An LLM endpoint accepts unstructured text, and its output is unstructured too. That means classical input validation gets you partway and then stops. A prompt that passes every schema check can still instruct the model to ignore its system message, leak its instructions, or call a tool it should not touch.

There is also a cost dimension that traditional APIs rarely have. Every token costs money, and a single abusive caller can generate enormous inference bills in minutes. Rate limiting here is an availability control and a financial control.

And then there is the agency problem. The moment you give a model access to a database query tool, an email sender, or a payment API, the model’s mistakes become your system’s actions. Security work shifts from “can this caller read this record” to “can this generated sentence trigger this function.”

The threat model, named plainly

The threat model, named plainly

Two public taxonomies do most of the heavy lifting for teams building an LLM security program. The first is the OWASP Top 10 for LLM Applications, which ranks prompt injection and its direct and indirect variants as the leading LLM-specific risk. Direct injection arrives through user input. Indirect injection arrives through data the model reads: a retrieved document, a web page, an email body, a tool response. The second is the OWASP API Security Top 10, whose 2023 edition puts broken object level authorization and broken authentication at the top of the list. LLM endpoints inherit both lists. They do not replace each other.

In practice, the risks that bite teams cluster into five groups:

Risk What it looks like in production First control to reach for
Indirect prompt injection A retrieved PDF contains instructions the model obeys Treat retrieved content as untrusted, separate privileges
Key exposure A live key ships in browser JavaScript or a public repo Server-side proxying, short-lived credentials
Cost abuse One caller loops the endpoint and burns the budget Per-key quotas, token caps, anomaly alerts
Excessive agency The model can delete records because the tool allows it Least-privilege tools, human approval for writes
Sensitive data leakage The model repeats another tenant’s data from context Tenant isolation, output filtering, no secrets in prompts

Notice that only one of those five is really about the model’s intelligence. The rest are ordinary security engineering problems wearing a new hat.

Keys, quotas, and the boring controls that matter most

Start with the least glamorous work, because it prevents the most incidents.

Never let a provider key reach the client. Browser-side JavaScript is readable by anyone with developer tools. Mobile binaries get decompiled. The only safe pattern is a server-side proxy that holds the credential and authenticates the actual user before forwarding the request. This is not a novel insight, but key leakage in public repositories and client bundles remains a recurring finding in secret-scanning research, which is exactly why it keeps appearing in incident write-ups.

Scope keys to a single purpose. One key per environment, per service, and ideally per feature. If a key leaks, you revoke one thing instead of everything. Rotate on a schedule and after any staff departure.

Set hard token ceilings. A maximum output length per request, a maximum context size, and a per-key daily spend cap. Without a ceiling, a runaway loop is an unbounded bill.

Rate limit by identity, not by IP alone. IP-based limits fail behind shared corporate networks and are trivially bypassed. Authenticated user ID plus API key is the relevant basis.

Log requests and responses with care. You need audit trails. You also need to avoid storing personal data and secrets in logs that half the engineering organization can read. Redact before you persist.

For teams building out the broader program around these controls, the enterprise AI and cloud security material is a reasonable reference point for how the pieces fit together.

Prompt injection: the problem nobody has fully solved

It is worth being blunt here. As of the current state of the field, there is no complete, agreed technical fix for prompt injection. Defenses reduce risk. None of them eliminate it. Anyone claiming otherwise is selling something.

The reason is structural. An LLM cannot reliably distinguish between instructions from its operator and instructions embedded in data it was asked to process. Both arrive as tokens in the same context window. When a model summarizes a web page, the page’s text carries the same weight as the system prompt unless the architecture enforces a boundary the model itself cannot cross.

What actually helps, in rough order of effectiveness:

  • Privilege separation. The model never holds credentials. It requests actions through a broker that checks authorization independently of anything the model says.

  • Human approval for consequential actions. Sending money, deleting data, and emailing external parties should require a confirmation step.

  • Least-privilege tools. A tool that can only read three columns is safer than a tool that runs arbitrary SQL.

  • Input and output filtering. Useful for catching known patterns, useless against novel phrasing. Treat it as one layer, not the layer.

  • Content provenance. Mark retrieved content as untrusted in the prompt structure, and keep the instruction channel separate from the data channel where the API allows it.

The honest framing for leadership: indirect injection is a design constraint, not a bug you close with a sprint.

Authorization is where most real breaches will happen

Prompt injection gets the headlines. Broken authorization gets the breaches. If your LLM feature retrieves documents, the retrieval layer must enforce the same access rules as the rest of your application. A vector search that returns chunks from every tenant because the index was built without tenant filters is a data breach with extra steps, and the model will happily summarize the leak.

Three practical rules:

  • Filter before retrieval, not after generation. Do not rely on the model to withhold what it was given.

  • Check object-level permissions on every tool call. The model does not know who the user is. Your broker does.

  • Test with two accounts. The simplest authorization test in the world: log in as user A, ask the assistant about user B’s data, confirm it fails. Run it every release.

If your organization is drafting role definitions for the people who own this work, the guide to what to look for in an AI security role description covers the skills mix that actually maps to these tasks.

Governance and regulation: what changes the calculus

Security work on LLM APIs increasingly sits inside a governance frame. The NIST AI Risk Management Framework organizes AI risk work into four functions (Govern, Map, Measure, Manage) and gives security teams a vocabulary that executives already recognize. The NIST Generative AI Profile extends it with risks specific to generative systems, including confabulation, data privacy, and information security. Neither document is LLM-API-specific, and neither is mandatory in the United States, but both are widely used as the reference structure for AI security programs. (What an enterprise security advisory should tell you) (OWASP Top 10 Web Application Security Risks)

In the European Union, the AI Act introduces a risk-tiered regulatory regime with staged application dates. Teams deploying LLM features for EU users should confirm which tier their system falls into and which obligations apply on which date, because the timeline has been the subject of ongoing guidance and debate.

The practical takeaway for engineers: governance frameworks mostly ask you to document what you already should be doing. Inventories of models and endpoints. Risk assessments. Monitoring. Incident response that covers AI-specific failure modes. If you build those artifacts as you go, compliance becomes a byproduct rather than a project.

A workable checklist for shipping

Before a first LLM feature goes live, these items should be true. They are not exhaustive, but skipping any of them is how the incidents in the table above happen.

  • Provider credentials live only on the server, scoped per service, and rotate on a schedule.

  • Every request is authenticated and authorized as a specific user, with object-level checks in the retrieval and tool layers.

  • Per-key and per-user quotas exist, with hard token ceilings and spend alerts.

  • Tools are least-privilege, and write actions require human confirmation.

  • Retrieved content is treated as untrusted input, and the prompt structure separates instructions from data.

  • Logs redact personal data and secrets, and are retained per policy.

  • An abuse playbook exists: who revokes keys, who contacts customers, who talks to regulators.

Teams often find that items one through three take a week and items four through six take a quarter. That ratio is normal. The architectural decisions are cheap early and expensive late.

Conclusion

LLM API security is mostly API security with two new wrinkles: inputs that cannot be validated by schema, and outputs that can take action. The controls that hold up are unglamorous. Server-side key handling. Real authorization. Quotas and ceilings. Least-privilege tools with human approval on the dangerous ones. Prompt injection remains an open problem, and the teams that handle it best are the ones that design around it rather than pretending a filter solved it. Start with the boring controls, assume the model will eventually be fooled, and make sure that when it is, the blast radius is small.

Frequently asked questions

What is LLM API security?

It is the practice of protecting the endpoints that serve large language model features, covering credential management, authentication and authorization, rate limiting and cost controls, prompt injection defenses, tool permissions, and logging. It combines classical API security with risks specific to models that accept natural language and act through tools.

Is prompt injection a solved problem?

No. There is no complete, agreed technical fix as of the current state of the field. Input filtering, output filtering, privilege separation, and human approval all reduce risk, but none eliminates it. Any vendor or article claiming prompt injection is fully solved should be treated with skepticism and asked for evidence.

What is the difference between direct and indirect prompt injection?

Direct injection comes from the user’s own input, such as someone typing instructions to override the system prompt. Indirect injection arrives through content the model reads, such as a retrieved document, a web page, or a tool response. Indirect injection is harder to defend against because filtering the user’s prompt does nothing to stop it.

Why is putting an API key in front-end code dangerous?

Anyone can read browser-side JavaScript or decompile a mobile app, so a key shipped to the client is effectively public. It can be extracted and used to run up costs, access data, or abuse the endpoint. The standard fix is a server-side proxy that holds the credential and authenticates the real user before forwarding requests.

How do I stop one user from running up my inference bill?

Combine several controls: a maximum output token count per request, a maximum context size, per-user and per-key rate limits, daily spend caps, and alerts on unusual usage patterns. Rate limiting by authenticated identity rather than IP address is essential, since IP-based limits are easily bypassed and fail behind shared networks.

Does the EU AI Act apply to my LLM feature?

It depends on your role and the risk tier of the system, and the obligations apply on a staged timeline. Teams serving EU users should determine whether they are a provider or deployer, identify the applicable tier, and confirm current application dates against official guidance, since the timeline has been subject to ongoing clarification.

Where should a security team start?

With credentials and authorization. Move keys server-side, scope and rotate them, enforce per-user authentication, and verify that retrieval and tool layers check object-level permissions. Those steps prevent the most common and most damaging incidents, and they are cheaper to implement before launch than after an incident review.

Latest articles

Scroll to Top