Skip to content

MARSOHS-2740: use DigitalOcean Inference for --model on claude-code and codex - #2118

Merged
SSharma-10 merged 4 commits into
digitalocean:mainfrom
nveerdixit:marsohs-2740-model-uses-do-inference
Nov 25, 2026
Merged

SSharma-10 merged 4 commits into
digitalocean:mainfrom
nveerdixit:marsohs-2740-model-uses-do-inference

Conversation

@nveerdixit

@nveerdixit nveerdixit commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

doctl harness-runtime create --harness claude-code --model kimi-k3 failed before creating anything:

Error: Missing environment value
manifest references environment variable(s) not set locally: ANTHROPIC_API_KEY

--harness codex --model kimi-k3 failed the same way on OPENAI_API_KEY. Creating the same harness and model in the console works, using a DigitalOcean Inference key and no vendor key.

The cause was ordering. --harness claude-code / codex always wrote a ${ANTHROPIC_API_KEY} / ${OPENAI_API_KEY} placeholder into the manifest, and doctl resolves placeholders locally before any API call. So the managed-key request added in #2114 was never reached.

Behaviour change: billing (needs owner approval)

For --harness claude-code and --harness codex, a user who has ANTHROPIC_API_KEY or OPENAI_API_KEY exported and passes --model used to run on their own vendor key, billed by the vendor. After this change that session runs on DigitalOcean Inference, billed to the user's DigitalOcean team. Only an explicit --secret ANTHROPIC_API_KEY=… / --secret OPENAI_API_KEY=… keeps them on their own vendor account. Like #2111 and #2112, this needs the owner's sign-off before merge.

How users learn about it:

  • stderr on create/launch, whenever the exported key is ignored: Using DigitalOcean Inference for kimi-k3; model usage is billed to your DigitalOcean team. ANTHROPIC_API_KEY in your environment is not used; to use and be billed on your own Anthropic account, pass --secret ANTHROPIC_API_KEY=... (or =@file).
  • --dry-run stderr: A DigitalOcean Inference key will be requested for this session when it is created; model usage is billed to your DigitalOcean team.
  • --model flag help and the create/launch help both say the session is billed to the team, and that an exported key no longer counts.

What changes

For --harness claude-code and --harness codex, a non-empty --model now means DigitalOcean Inference:

You pass Result
--model kimi-k3 No vendor key slot. doctl asks the platform to issue a DigitalOcean Inference key for the session.
--model kimi-k3 with ANTHROPIC_API_KEY exported in the shell Same as above. The exported key is ignored. One stderr line says usage is billed to the DigitalOcean team and how to use your own key.
--model X --secret ANTHROPIC_API_KEY=… (or OPENAI_API_KEY for codex) Your own key, exactly as before. No key is issued.
--model X --secret HARNESS_INFERENCE_API_KEY=… Your own DigitalOcean key. No vendor slot, nothing issued.
--model X with the other vendor's key in --secret Unchanged. The harness's own key is still required, and doctl fails loudly if it is missing.
no --model Unchanged.

Why an exported key does not count: inside the session a vendor key takes precedence over the DigitalOcean key. If doctl forwarded it, kimi-k3 would be sent to the vendor and fail at the first prompt instead of at create. An explicit --secret is a clear request; an exported variable usually belongs to another tool.

Also:

  • The claude-code validation warning "HARNESS_INFERENCE_MODEL is only used with HARNESS_INFERENCE_API_KEY…" no longer fires when a DigitalOcean key will be used. It still fires when a native Anthropic key, or only an OpenAI key, is present, because the model would then be ignored.
  • --dry-run says on stderr when a DigitalOcean Inference key will be requested and that it bills the team. It stays quiet when an inference or vendor key's env/secrets slot holds an unresolved ${VAR}, because create would ask for that key instead. A ${VAR} elsewhere (for example in a prompt) does not count.
  • The help text for --model and the create/launch help explain the choice.
  • The help paragraph about the issued key now says "the platform" instead of naming an internal service.

Unchanged: codex-agentapi (OpenAI runs that agent loop, so it needs an OpenAI key), opencode, openhands, hermes, --spec manifests and --from-config.

Testing

Live, against the API, on 2026-11-11 (each session and its Agent Config was removed afterwards):

Command Result
create --harness codex --model kimi-k3, no vendor key The agent's answer on stdout matched a random token exactly
create --harness claude-code --model kimi-k3, no vendor key The reply came back
Same, with a fake ANTHROPIC_API_KEY exported Exact token back. The note was printed, and the session held only the DigitalOcean key, not the fake one
--harness claude-code --model kimi-k3 --secret OPENAI_API_KEY=… Fails locally on the missing ANTHROPIC_API_KEY, and no session is created

Unit tests in commands/agents_model_inference_test.go cover every row of the table above, the validation warning both ways, --dry-run, -o json stdout staying clean, and the shared create/launch path. I also confirmed that each of these tests fails when its rule is broken: counting only one vendor's key, dropping the OpenAI-only warning, and restoring the old warning condition.

go test ./commands/ ./do/ passes except TestRegistryLogout, which also fails on unmodified main in my environment (it needs the OS keychain).

Notes for review

  • This touches the managed-key logic from harness-runtime: opt into manage_model_access_key across the config/session create commands #2114. needsManagedModelAccessKey is unchanged; this change only stops writing the vendor slot that kept it from running.
  • It relies on the platform giving the session its inference endpoint, as it already does for opencode and openhands. Sessions are routed by the model id, so an account without access to a model gets the same tier error at the first prompt as it would in the console.

Refs: MARSOHS-2740

🤖 Generated with Claude Code

@gitguardian

gitguardian Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

…nd codex

For --harness claude-code and --harness codex, a non-empty --model now means DigitalOcean Inference when no Anthropic or OpenAI key is passed with --secret. The generated manifest then leaves out the vendor key slot, so the existing key-issuing request supplies the key instead of failing on a missing local ANTHROPIC_API_KEY or OPENAI_API_KEY. Passing either vendor key with --secret keeps the harness's own slot as before, and a key exported in the shell is ignored with one stderr note. The claude-code validation warning about HARNESS_INFERENCE_MODEL no longer fires when a DigitalOcean key will be used, and still fires when a native key, or only an OpenAI key, is present. Help text and --dry-run explain how the key is chosen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nveerdixit
nveerdixit force-pushed the marsohs-2740-model-uses-do-inference branch from 03199b1 to db75457 Compare November 11, 2026 08:59
@nveerdixit

Copy link
Copy Markdown
Contributor Author

Live check against the API. claude-code with --model kimi-k3 and a (fake) ANTHROPIC_API_KEY exported: doctl says the exported key is not used, the session is created without a vendor key, and the prompt is answered on DigitalOcean Inference. codex with --model kimi-k3 and no key also returned the expected answer.

claude-code kimi-k3

@sanpj2292

Copy link
Copy Markdown
Contributor

Review notes.

  1. Billing behaviour change, not flagged as one. A user with ANTHROPIC_API_KEY or OPENAI_API_KEY exported who passes --model used to run on their own vendor key. They now run on DigitalOcean Inference, billed to the team, and the only notice is one stderr line from noteIgnoredVendorKey (commands/agents.go:1212). Please call this out as a behaviour change needing the owner's approval, as MARSOHS-2586: balance fails clearly when the balance cannot be read #2111 and MARSOHS-2589: default --permission to ask and print the applied policy #2112 do.
  2. Nit: hasKeyPlaceholder (commands/agents.go:1238-1240) uses strings.Contains on the whole manifest, so ${OPENAI_API_KEY} appearing inside a prompt also counts as a placeholder and suppresses the dry-run note. Checking the secrets and env values instead would be exact.
  3. Nit: the new commands/agents_model_inference_test.go could live in agents_run_test.go next to the existing buildHarnessManifest tests.
  4. Interaction with MARSOHS-2589: default --permission to ask and print the applied policy #2112: its ValidatePolicy pre-check doesn't send manage_model_access_key, so for --model sessions the policy line it prints may not match create.

@sdharavath sdharavath left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

…ey placeholders by slot (MARSOHS-2740)

With --harness claude-code or codex, --model now runs on DigitalOcean
Inference even when ANTHROPIC_API_KEY or OPENAI_API_KEY is exported.
The stderr note, the --dry-run note, the --model flag help and the
create help now say that model usage is billed to the DigitalOcean team
and how to stay on your own vendor account.

hasKeyPlaceholder now reads the env and secret slots of the inference
and vendor keys instead of searching the whole manifest, so a ${VAR}
inside a prompt no longer suppresses the --dry-run note.

Co-authored-by: Cursor <cursoragent@cursor.com>
@nveerdixit

Copy link
Copy Markdown
Contributor Author

Thanks @sanpj2292. Addressed in cec5953.

  1. Billing behaviour change. Agreed, and now called out at the top of the PR description as a behaviour change that needs the owner's approval, like MARSOHS-2586: balance fails clearly when the balance cannot be read #2111 and MARSOHS-2589: default --permission to ask and print the applied policy #2112. The disclosure is also stronger in the CLI itself:
    • create/launch stderr, when an exported ANTHROPIC_API_KEY/OPENAI_API_KEY is ignored: Using DigitalOcean Inference for kimi-k3; model usage is billed to your DigitalOcean team. ANTHROPIC_API_KEY in your environment is not used; to use and be billed on your own Anthropic account, pass --secret ANTHROPIC_API_KEY=... (or =@file).
    • --dry-run stderr now ends with ; model usage is billed to your DigitalOcean team.
    • the --model flag help and the create/launch help say the session is billed to the team, and that a key exported in the shell no longer keeps a --model session on the vendor.
  2. hasKeyPlaceholder. Fixed. It now parses the manifest and checks only the env and secrets slots of HARNESS_INFERENCE_API_KEY, OPENAI_API_KEY and ANTHROPIC_API_KEY. New test TestPrintResolvedManifest_KeyNoteIgnoresPlaceholderOutsideKeySlots puts ${OPENAI_API_KEY} in a prompt and expects the note. It fails against the old strings.Contains version.
  3. Test file location. Leaving it as is. The file groups the tests for this one rule (manifest, create, launch, dry-run, validation), and most of them drive RunAgentsCreate and printResolvedManifest rather than buildHarnessManifest, so moving them into agents_run_test.go would split the suite without making either file easier to read. Happy to move it if you feel strongly.
  4. MARSOHS-2589: default --permission to ask and print the applied policy #2112 ValidatePolicy. Agreed, that is a real gap. ValidatePolicy is not on main or this branch yet, so there is nothing to change here. Whichever of the two lands second should pass manage_model_access_key to the pre-check whenever needsManagedModelAccessKey(manifest) is true, so the printed policy matches create. I'll carry that over to whichever PR merges second.

go test ./commands/ ./do/ passes except TestRegistryLogout, which also fails on unmodified main here (it needs the OS keychain).

@sanpj2292 sanpj2292 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The billing change is now flagged in the description and in the CLI ("billed to your DigitalOcean team" in the stderr note, --dry-run output and help), and hasKeyPlaceholder now checks only the key slots in env and secrets.

This approval covers the code. The behaviour change (an exported vendor key no longer keeps a --model session on the vendor's billing) still needs the owner's approval, as the description says.

Merge note: this PR conflicts with #2093 in commands/agents.go.

@SSharma-10
SSharma-10 merged commit 1825a8d into digitalocean:main Nov 25, 2026
6 checks passed
nveerdixit added a commit to nveerdixit/doctl that referenced this pull request Nov 26, 2026
Conflict in commands/agents_test.go: both sides appended tests at the
end of the file (this branch's JSON permission-line test, main's `logs`
tests). Kept both.

digitalocean#2118's --model create tests had no ValidatePolicy stub. Every --harness
create now runs the policy check alongside create, so the unexpected
call failed inside that goroutine and create waited on it forever (the
package timed out). They now allow the check without asserting its line,
since create is made to fail and the check may be cancelled.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

4 participants