Skip to content

feat(codemode): make model configurable instead of hardcoded gpt-4.1#849

Merged
threepointone merged 3 commits into
mainfrom
feat/codemode-configurable-model
Feb 6, 2026
Merged

feat(codemode): make model configurable instead of hardcoded gpt-4.1#849
threepointone merged 3 commits into
mainfrom
feat/codemode-configurable-model

Conversation

@Muhammad-Bin-Ali

Copy link
Copy Markdown
Contributor

Resolves #794

feat(codemode): make model configurable instead of hardcoded gpt-4.1

Problem

experimental_codemode hardcodes openai("gpt-4.1") in the generateObject call (packages/codemode/src/ai.ts:70), preventing users from choosing their own model.

Solution

Add a required model: LanguageModel parameter to experimental_codemode, allowing callers to pass any AI SDK-compatible model.

Changes

  • packages/codemode/src/ai.ts
    • Added model: LanguageModel to the options type
    • Replaced openai("gpt-4.1") with options.model in the generateObject call
    • Removed unused @ai-sdk/openai import
  • examples/codemode/src/server.ts
    • Passes the existing model variable to the codemode() call

Usage

import { experimental_codemode } from "@cloudflare/codemode/ai";
import { openai } from "@ai-sdk/openai";
const { prompt, tools } = await experimental_codemode({
  model: openai("gpt-5"), // <-- now configurable
  prompt: "You are a helpful assistant",
  tools: {
    /* ... */
  }
  // ...other config
});

Notes

  • This is a breaking change since model is required. Callers must now explicitly provide a model. Chosen to make it a breaking change so users are explicitly aware of the model they're using.
  • The dist/ artifacts (ai.d.ts, ai.js) need to be regenerated via npm run build in packages/codemode/.

This PR description was generated by OpenCode

@Muhammad-Bin-Ali
Muhammad-Bin-Ali requested a review from a team February 5, 2026 19:38
@changeset-bot

changeset-bot Bot commented Feb 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5d7314c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@cloudflare/codemode Patch
agents Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@claude

claude Bot commented Feb 5, 2026

Copy link
Copy Markdown

Claude Code Review

Issues:

  1. Breaking change incorrectly marked as patch (packages/codemode/src/ai.ts:44)

    • The changeset marks this as a patch, but the PR description acknowledges it's a breaking change
    • Making model required breaks existing code that calls experimental_codemode without it
    • Should be major if truly required, or make it optional with a default to keep it as patch
  2. Documentation contradicts implementation (docs/codemode.md:112, packages/codemode/README.md:90,160)

    • Docs say model is "optional, defaults to openai('gpt-4.1')"
    • Type signature shows model?: LanguageModel (optional with ?)
    • Implementation correctly has model?: LanguageModel in the type, which is good
  3. Redundant ternary (packages/codemode/src/ai.ts:71)

    • options.model ? options.model : openai("gpt-4.1") should use nullish coalescing: options.model ?? openai("gpt-4.1")

Recommendation:
Change changeset from patch to minor since the parameter is optional (not breaking), but this is a new feature addition.

agents-git-bot Bot pushed a commit to cloudflare/cloudflare-docs that referenced this pull request Feb 5, 2026
Synced from cloudflare/agents#849

- Add required `model` parameter to `experimental_codemode` API
- Update usage example to show model configuration
- Add API reference section with complete parameter documentation
- Add migration guide for breaking change from v0.0.6
- Users can now use any AI SDK-compatible model instead of hardcoded gpt-4.1

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@pkg-pr-new

pkg-pr-new Bot commented Feb 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/agents@849

commit: 5d7314c

@Muhammad-Bin-Ali
Muhammad-Bin-Ali force-pushed the feat/codemode-configurable-model branch from d6dd59b to 6cc93f9 Compare February 5, 2026 19:46
@threepointone

Copy link
Copy Markdown
Contributor

This should be a patch changeset

Comment thread packages/codemode/src/ai.ts Outdated
Comment thread packages/codemode/src/ai.ts Outdated
@threepointone
threepointone merged commit 21a7977 into main Feb 6, 2026
6 checks passed
@threepointone
threepointone deleted the feat/codemode-configurable-model branch February 6, 2026 08:45
@github-actions github-actions Bot mentioned this pull request Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CodeMode LLM pinned to gpt-4.1

2 participants