darnit

Your API integrations, invisibly mended.

Your dependencies didn't change. The API did. Your code keeps calling it the old way. darnit finds the exact lines, rewrites them, runs your tests, and opens the pull request.

npm install -g darnit

Or skip the install: npx darnit check. Needs Node 22.12 or newer.

RevDescriptionStatus
Amax_tokens on OpenAI chat completionsSuperseded
Bmax_completion_tokens
rewritten by darnit
Tests passed

Three outcomes, verbatim.

Every line below is darnit's own output. Pick one.

  1. darnit check

    Lists every affected call site, with the vendor's own notice.

  2. darnit fix

    Rewrites them with rules proven in CI.

  3. <your tests>

    Your build and tests decide. If either breaks, the files go back.

$ darnit check
openai 2024-09-12: Rename max_tokens to max_completion_tokens on chat completions
chat.ts:11:5 max_tokens: 256
1 call site in 1 file
https://developers.openai.com/api/docs/api-reference/chat/createthe vendor's own notice
Scanned 1 JavaScript, TypeScript or Python file against 33 change records.
Not checked: request options built elsewhere and passed in as a variable.
$ darnit fix
- max_tokens: 256,
+ max_completion_tokens: 256,revised
✓ Rename max_tokens to max_completion_tokens on chat completions: 1 file
tests: npm test passedyour tests, not ours

No change: the same file also calls anthropic.messages.create({ max_tokens: 1024 }). darnit leaves it alone. That one is correct.

$ darnit check
openai 2024-09-12: Rename max_tokens to max_completion_tokens on chat completions
src/summarize.js:5:5 max_tokens: 256
1 call site in 1 file
$ darnit fix
✗ Rename max_tokens to max_completion_tokens on chat completions: rewritten, then put back
tests: npm test failed; files put back. The change broke your tests.put back
AssertionError [ERR_ASSERTION]: undefined == 256the test that caught it
$ darnit check
openai 2023-11-06: Move chat completion functions to tools
weather.js:9:5 functions: [{ name: "get_weather", parameters: { type: "obj…
weather.js:10:5 function_call: "auto"
2 call sites in 1 file
https://developers.openai.com/api/docs/changelog
https://developers.openai.com/api/docs/api-reference/chat/create
$ darnit fix
- Move chat completion functions to tools: found in 1 file, not rewritten: migration not yet automated; see the record notesreported, not half-fixed

This change also alters how replies are read, so a safe rewrite needs a person. darnit tells you where, and changes nothing.

Why you can trust the pull request

  • Every rewrite is a rule proven in CI before it ships. Same rule, same result, in every repo.
  • Checks your SDK version before touching anything. Too old: it stops and names the upgrade.
  • Runs your build and tests, and puts the files back if either breaks.
  • Lists what it couldn't fix as needs a human: file:line instead of pretending.
  • One pull request per change. Never force-pushes, never pushes to your default branch.
A pull request darnit opened on darnit-sh/darnit-example, a small example repository. Every word below is darnit's.

Rename max_tokens to max_completion_tokens on chat completions #3

darnit wants to merge darnit/openai-max-tokens-to-max-completion-tokens into main

Renames max_tokens to max_completion_tokens. OpenAI deprecated max_tokens on chat completions, and it doesn't work with o-series models. On reasoning models the new limit also counts reasoning tokens, so the same number can give a shorter visible answer.

Why

OpenAI announced this change on 2024-09-12: https://developers.openai.com/api/docs/api-reference/chat/create

chat/create max_tokens: 'This value is now deprecated in favor of max_completion_tokens, and is not compatible with o-series models' (verified 2026-08-03)

What changed

  • app/summarize.py

Verified

  • python3 -m pytest -q passed
test output
.                                                                        [100%]
1 passed in 0.00s

Not verified

  • This change needs openai >= 1.45.0 (PyPI); darnit could not find the version this repository uses.
  • No generated regression tests yet; the checks above are the repository's own.
  • Request options built elsewhere and passed in as a variable are not followed.
  • Repos passing max_tokens through a shared config/options object need the rename at the config source, not the call site

darnit 0.1.0, change record openai:2024-09-12:max-tokens-to-max-completion-tokens

What it covers today

Fixes 1 OpenAI change, reports more, watches weekly. Small on purpose: a change gets a rewrite only when the rewrite is proven.

VendorStatusWhat that means
OpenAISupportedChange records and rewrites
Anthropic, Stripe, TwilioRecognizeddarnit init finds them; no change records yet

Reads JavaScript, TypeScript and Python. Runs on macOS and Linux. Want one covered? Open an issue.

Try it on your repo.

npx darnit check

Read-only. It lists what it finds and changes nothing. Install for good with npm install -g darnit.