[Feature]: support guided decoding parameters in the /chat/completions endpoint of trtllm-serve
Open
@laikhtewari is already working on this.
Since Dec 4, 2025.
feature request
OpenAI API
- Dominant language
- Python
- Stars
- 14.7k
- Forks
- 2.8k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 489
Description
🚀 The feature, motivation and pitch
openai.OpenAI.chat.completions.create doesn't have guided decoding fields in the method signature. Guided decoding fields like guided_json must be passed in extra_body.
If I make a request with extra_body, it fails with
openai.BadRequestError: Error code: 400 - {'object': 'error', 'message': "[{'type': 'extra_forbidden', 'loc': ('body', 'guided_json'), 'msg': 'Extra inputs are not permitted', 'input': {'type': 'object', 'properties': {'title': {'type': 'string'}, 'rating': {'type': 'number'}}, 'required': ['title', 'rating']}}]", 'type': 'BadRequestError', 'param': None, 'code': 400}
vllm serve and python -m sglang.launch_server APIs support extra_body and guided decoding parameters.
Steps to reproduce
- Start container
set -u
export CONTAINER_NAME=extra-body-test
export IMG_NAME=nvcr.io/nvidia/tensorrt-llm/release:1.2.0rc4
docker run -it --rm --name=$CONTAINER_NAME \
--gpus '"device=4"' \
--shm-size=16GB \
-e HF_TOKEN=$HF_TOKEN \
-v "$HOME/trtllm-perf-isolation:/perf" \
-u root \
$IMG_NAME \
/bin/bash
- Deploy the model
trtllm-serve serve Qwen/Qwen3-0.6B --reasoning_parser deepseek-r1
- Create a new shell, exec into the container and run the following script:
from openai import OpenAI
import sys
if len(sys.argv) > 1:
model_name = sys.argv[1]
else:
model_name = "gpt-oss-120b"
client = OpenAI(base_url="http://localhost:8000/v1", api_key="not-used")
json_schema = {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"rating": {
"type": "number"
}
},
"required": [
"title",
"rating"
]
}
confusing_json_schema = {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"score": {
"type": "number"
}
},
"required": [
"name",
"score"
]
}
prompt = (f"Return the title and the rating based on the following movie review according to this JSON schema: {str(confusing_json_schema)}.\n"
f"Review: Inception is a really well made film. I rate it four stars out of five.")
messages = [
{"role": "user", "content": prompt},
]
response = client.chat.completions.create(
model=model_name,
messages=messages,
extra_body={"guided_json": json_schema},
stream=False
)
assistant_message = response.choices[0].message.content
print("message:")
print(assistant_message)
print("reasoning_content:")
print(getattr(response.choices[0].message, "reasoning_content", None))
Alternatives
No response
Additional context
No response
Before submitting a new issue...
- Make sure you already searched for relevant issues, and checked the documentation and examples for answers to frequently asked questions.
Contributor 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.
Assessment
This issue has not been assessed yet.