[Feature] Return actual prompt token IDs in opt-in Anthropic non-stream responses
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 1/100
Research direction
Implementation PR #5232 is linked and already provides the requested behavior. Review that PR and the named regression tests, test_messages_non_stream_with_output_ids_and_routed_experts and test_messages_non_stream_does_not_add_prompt_ids_without_opt_in, to see how the response includes prompt IDs only when requested. Done means the PR is merged or its changes are otherwise present.
Written by the indexing model from the issue text.
Description
Motivation
Please expose the actual inference prompt token IDs in Anthropic non-streaming /v1/messages responses when the existing LMDeploy extension return_token_ids=true is requested.
The endpoint currently exposes output_ids under this flag, but does not include prompt_token_ids. For agentic RL trajectory recording, we need both the actual prompt IDs and generated IDs to align the recorded actions with the backend sequence. Re-tokenizing rendered messages is not a reliable substitute, especially with tool messages, chat templates, and image expansion.
This is a request for an opt-in LMDeploy extension, not a requirement of the standard Anthropic API.
Reproduction and expected behavior
Against an LMDeploy server with a supported model loaded:
curl http://localhost:23333/v1/messages \
-H 'Content-Type: application/json' \
-H 'anthropic-version: 2023-06-01' \
-d '{
"model": "<served-model-name>",
"max_tokens": 16,
"stream": false,
"messages": [{"role": "user", "content": "Hi"}],
"return_token_ids": true
}'
Actual: the response includes output_ids, but omits prompt_token_ids.
Expected: also include prompt_token_ids from chat_runner.prompt_token_ids, preserving the backend's actual prompt sequence. When the flag is omitted or false, keep the current response shape and omit this extra field.
Related resources
Implementation PR: #5232, head b828647add4711a703b2d1a9a9c96dce79e140a3.
The PR reuses IDs already available on the chat runner; it adds a response field and conditional serialization rather than introducing another tokenizer path. Endpoint regression tests cover opt-in prompt IDs and default omission:
test_messages_non_stream_with_output_ids_and_routed_expertstest_messages_non_stream_does_not_add_prompt_ids_without_opt_in
Scope is non-streaming responses. Our current OpenAI-compatible rollout path is unaffected; this request is for the Anthropic trajectory-recording path.
- Dominant language
- Python
- Stars
- 8.2k
- Forks
- 797
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 52
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from InternLM/lmdeploy
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 2 days
-
[Bug] apply_rotary_pos_emb: leaves output tails unwritten with partial rotationPossibly taken @shotsan claimed this 15 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 2 days
-
[Bug] PyTorch engine ignores use_rslora, so rsLoRA adapters run sqrt(r) times too weakPossibly taken @Andreas-Hum claimed this 26 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 2 days
-
[Feature] Expose `max_model_len` (session_len) in `/v1/models` model cardPossibly taken @FOWEPJF255 claimed this 37 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 2 days
All issues in InternLM/lmdeploy
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Techiebutler/freeframe#687 ·
Maintainers usually reply within 1 day
-
bug verbose GC
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
IBM/javacore-analyser#677 ·
Maintainers usually reply within 1 day
-
area/config comp/plugins P1 platform/qqbot tool/file type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
NousResearch/hermes-agent#163932 · 1 comment ·
Maintainers usually reply within 1 day
-
plugins/dsh: todayStr() computes UTC but is documented as local — journal entries written 00:00–08:00 local land in the previous day's filePossibly taken @Beehtrix claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
zilliztech/memsearch#907 · 1 comment ·
Maintainers usually reply within 1 day
-
external
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
langchain-ai/docs#8386 ·
Maintainers usually reply within 1 day