Content

Why AI Coding Agents Keep Using Deprecated APIs and Outdated Code (and How to Fix It)

Why ChatGPT, Claude, Cursor, Copilot, and other AI coding agents keep writing deprecated API calls and outdated code, how to spot it, a worked example with Stripe's legacy Charges API, and the fixes that keep agents on current APIs.

AI AgentOct 7, 2026

Key takeaways

  • -AI coding agents use deprecated APIs because old patterns outnumber new ones in training data, and the model has no live view of the library version you have installed.
  • -Pasting docs helps but is not a guarantee: a 2026 study found models often fail to fully suppress outdated knowledge, though structured API documentation was the largest single improvement it measured.
  • -Deprecated code usually still runs, so builds and tests pass and the problem shows up later.
  • -Stripe's API reference now marks creating a charge as deprecated and due for removal, yet years of examples keep that pattern in AI output. Stripe's own llms.txt tells models never to recommend the Charges API.
  • -The fixes that work: give the agent your installed versions and version-matched docs, name the replacements in a rules file, make deprecation warnings fail lint, remove stale examples, and verify API calls before they run.
  • -For API calls, Swytchcode has agents read the real operation schema before each call and only runs operations you have enabled, so invented or removed operations fail before a request is sent.

AI coding agents use deprecated APIs because the model learned from years of public code, and old patterns outnumber new ones. A method that was standard for five years has five years of tutorials, forum answers, and open-source examples behind it. Its replacement may have months. The model has no live view of the library you have installed, so unless something in its context says otherwise, it writes the version it saw most often. The fix is to put the current API in front of the agent before it writes code, name the old calls it must avoid, and check the result against the real API before it runs.

This applies to ChatGPT, Claude, Cursor, GitHub Copilot, Codex, and other assistants alike. This article explains the causes, shows how to spot outdated code, walks through Stripe's legacy Charges API as an example, and lists the fixes that work. Checked against Stripe's documentation, Stack Overflow's published research, and recent academic studies in October 2026.

Why does AI write deprecated code?

  • Training data is frozen. Every model has a knowledge cutoff. A deprecation announced after that date does not exist for the model, and deprecations inside your own company never appear in any training set.
  • Old code outnumbers new code. Even when the model has seen the replacement, the older pattern usually appears far more often in what it learned from.
  • The model does not know your version. Without package.json or a lockfile in context, it guesses which version you use. A study of more than 4,000 developer conversations with ChatGPT (the DevGPT dataset, MSR 2024) found library version constraints in only 9% of code-related conversations, and most of those were added by the developer.
  • Memory can override the docs you paste. A 2026 study of code generation under API changes ("When LLMs Lag Behind", arXiv 2604.09515) found that models often fail to fully suppress outdated knowledge even when given updated information. Structured API documentation was still the largest single improvement it measured, raising the executable rate by 57% compared with a short description of the change.
  • Your own codebase teaches the old pattern. Agents search the repository and imitate what they find. If old call sites remain, the agent copies them into new code.
  • Deprecated code usually still runs. Deprecation is a warning until the API is removed. The build passes, the tests pass, and the problem shows up later.

Stack Overflow's 2026 analysis of the developer AI trust gap lists references to methods that were deprecated years ago among the problems developers report, alongside references to APIs that do not exist at all.

Signs your AI assistant is writing outdated code

  • Deprecation warnings. Console warnings at runtime, or methods shown with a strikethrough in your editor.
  • Code that matches old tutorials. The generated code looks like a blog post from several years ago, and the current docs show a different approach.
  • Archived or replaced packages. The agent installs a package that is deprecated on npm or PyPI, or imports a module your version no longer ships.
  • Parameters missing from the docs. Fields the agent passes do not appear in the current API reference, or the API returns errors about unknown parameters.
  • Type errors after an upgrade. In typed projects, removed or renamed methods fail to compile. Deprecated methods that still exist often compile without complaint.

Example: AI writing Stripe's legacy Charges API

Stripe payments show the problem clearly because the old and new APIs look very different. For years, the standard Stripe integration created a charge from a card token in a single server call. Stripe replaced it with Payment Intents, which supports Strong Customer Authentication (SCA) and 3D Secure.

  • Deprecated in the API reference. Stripe's API reference marks the create and capture charge methods as deprecated, says they will be removed soon, and tells integrations to move to a different payment flow such as Payment Intents.
  • Legacy in the guides. Stripe's Charges API page labels it legacy and lists features it does not support, including businesses in India, bank requests for card authentication, and SCA.
  • Older pages differ. Some older Stripe pages still describe Charges as available. The API reference is the place to check current status.
// Outdated: Charges API with a card token
const charge = await stripe.charges.create({
  amount: 1099,
  currency: "usd",
  source: "tok_visa",
});

// Current: create a PaymentIntent on the server,
// then confirm it on the client with Stripe.js and the Payment Element
const paymentIntent = await stripe.paymentIntents.create({
  amount: 1099,
  currency: "usd",
  automatic_payment_methods: { enabled: true },
});
// Send paymentIntent.client_secret to the client

Stripe addresses AI tools directly. The llms.txt file on docs.stripe.com instructs language model agents never to recommend the Charges API, and Stripe's best-practices skill for agents says the same while listing the Sources API as deprecated and the Tokens API as outdated. That a vendor writes instructions aimed at models shows how persistent the old pattern is.

Newer models are improving. A small 2026 pilot published by Synscribe found current frontier models chose Payment Intents unprompted, so widely discussed deprecations are increasingly absorbed. The risk remains with older and smaller models, agents working in a codebase that already uses Charges, and changes too recent for training data. The same pilot found agents producing obsolete configuration for Tailwind CSS v4 until a short directive was added to their context.

How to stop AI from using deprecated APIs

  1. Give it your versions first. Have the agent read package.json, the lockfile, or installed types before writing code, and state which version it is targeting.
  2. Give it version-matched docs. Point it at the docs for the version you run. Many vendors publish llms.txt files or Markdown versions of their docs, and documentation MCP servers can fetch pages on demand. The newest docs can describe features your installed version lacks, so match the version.
  3. Name the replacements. List each deprecated call and its replacement in AGENTS.md, CLAUDE.md, or a Cursor rule. Explicit mappings work better than "use the latest version".
  4. Make deprecation fail lint. Turn on @typescript-eslint/no-deprecated for TypeScript, or Pyright's reportDeprecated and Ruff's banned-api rules for Python, and treat them as errors so the agent sees and fixes them.
  5. Remove stale examples. Search the repository for old call sites and outdated example files. Migrate or delete them so the agent has nothing old to copy.
  6. Feed errors back. Give the agent typecheck failures, lint output, and deprecation warnings, and ask it to fix them before you review.
  7. Verify API calls before they run. For third-party APIs, check each call against the provider's current schema before a request is sent.
FixWhat it helps withLimit
Read package.json and lockfile firstMatches code to the versions you actually runOnly works if the agent is required to do it
Version-matched docs, llms.txt, or a docs MCP serverReplaces memory with current referenceModels can still fall back on what they learned
Rules file with replacementsStops known deprecated calls in new codeGuides the model without enforcing anything
Deprecation lint as errorsCatches deprecated symbols the type checker knows aboutMisses APIs called over HTTP or without type information
Remove stale examplesGives the agent nothing old to copyManual, and needs repeating
Verify API calls against the live schemaBlocks removed operations and unknown fields before the requestCovers API calls, not library code
## Dependencies

- Read package.json and the lockfile before writing code. State the version you are targeting.
- Use the documentation for the installed version.

## Deprecated APIs

- Stripe: never use stripe.charges.create, the Sources API, or the Tokens API. Use Checkout Sessions or Payment Intents.
- Node.js: never use url.parse(). Use new URL().
- Python: never use datetime.utcnow(). Use datetime.now(datetime.UTC).

Put a block like this in your agent's rules file and add a line each time you catch a new outdated pattern.

Where Swytchcode fits

Swytchcode is an execution layer between agents and the APIs they call. When an agent calls an API through Swytchcode, it does not write the request from memory. It discovers the operation that matches the job, reads that operation's real schema with swy info, and runs it with swy exec. Every call goes through one pipeline: resolve the tool, validate inputs, evaluate policies, resolve credentials, execute, and normalize the response. Credentials never pass through the model's context.

The project's tooling.json works as an allowlist. Only operations you add with swy add can run, so you decide which operations are available to the agent at all.

npm install -g swytchcode
swy init --editor=cursor --mode=sandbox
swy doctor

# Find the operation by intent, then enable only what you need
swy discover "accept a one-time card payment" --json
swy get <project>
swy add <canonical_id>
swy info <canonical_id>
swy exec <canonical_id>

In sandbox mode, calls go to the provider's test environment. What happens when the agent reaches for an outdated operation or field:

  • Unknown or not-enabled operations are rejected. An invented canonical ID, or a real one that has not been added to the project, exits with code 2 and no request is sent.
  • Invalid inputs fail before the request. A missing required field, a wrong type, or a field the operation does not define exits with code 1 before the provider sees the request.
  • Provider errors come back structured. Each error includes the status code, an error category, and whether it is retryable. A 200 response with an error in the body counts as a failure.
  • Changed operations are flagged. swy sync warns when an installed operation's method has changed upstream.
  • Writes can be held. dry_run=true previews the request without sending it. For production, allow and deny rules are available from the Pro plan, and approval rules that route a payment or other write to Slack or Telegram are available on Business and Enterprise.

Where this does not help

Swytchcode governs the API calls an agent executes. It does not check library code such as React components or Node.js built-ins, and it does not rewrite deprecated calls already in your application. For those, use the version, docs, rules, and lint steps above.

Frequently asked questions

Why does ChatGPT give outdated code?
ChatGPT learned from a fixed snapshot of public code in which older patterns appear far more often than newer ones, and it does not know which library version you use unless you tell it. Give it your version and the current docs for that version.

How do I make Cursor or Claude use the latest documentation?
Add the docs to the agent's context: index them in Cursor, point Claude at a vendor's llms.txt or Markdown docs, or connect a documentation MCP server. Then add a rule that the agent must read package.json first and use docs for the installed version.

Does a newer model stop deprecated code?
It helps with deprecations that happened before its training cutoff. It cannot know about changes after that date or about deprecations inside your own codebase, so the fixes above still apply.

Is Stripe's Charges API deprecated?
Stripe's API reference marks creating and capturing charges as deprecated and says the methods will be removed soon. Stripe recommends Payment Intents or Checkout Sessions for new integrations.

How do I stop my AI agent from using deprecated APIs?
Give it your installed versions and matching docs, list deprecated calls and their replacements in a rules file, make deprecation warnings fail lint, remove stale examples from the repository, and verify API calls against the current schema before they run.

Swytchcode resources

More content