Complexity: 🟢 Beginner
This example demonstrates how to configure a NeMo Agent toolkit FastAPI frontend to accept requests in the OpenAI Responses API format.
The OpenAI Responses API uses a different request format than the Chat Completions API:
| Feature | Chat Completions API | Responses API |
|---|---|---|
| Input field | messages (array) |
input (string or array) |
| System prompt | In messages array | instructions field |
| Response object | chat.completion |
response |
| Streaming events | chat.completion.chunk |
response.created, response.output_text.delta, etc. |
This example configures the /v1/responses endpoint to accept the Responses API format while the standard /generate and /chat endpoints continue using Chat Completions format.
⚠️ Important: The Responses API format is provided for pass-through compatibility with managed services that support stateful backends (such as OpenAI and Azure OpenAI). NeMo Agent toolkit workflows do not inherently support stateful backends. Features likeprevious_response_idwill be accepted but ignored.
- Install LangChain integration (required for
tool_calling_agentworkflow):
uv pip install -e '.[langchain]'- Set up the NVIDIA API key:
export NVIDIA_API_KEY=<YOUR_API_KEY>nat serve --config_file examples/front_ends/responses_api_endpoint/configs/config.ymlThe server will start on port 8088 with the following endpoints:
| Endpoint | Format | Description |
|---|---|---|
/generate |
NAT default | Standard workflow endpoint |
/chat |
Chat Completions | OpenAI Chat Completions format |
/chat/stream |
Chat Completions | Streaming Chat Completions |
/v1/responses |
Responses API | OpenAI Responses API format |
curl -X POST http://localhost:8088/v1/responses \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-4o-mini",
"input": "What time is it?"
}'Expected Response:
{
"id": "resp_abc123...",
"object": "response",
"status": "completed",
"model": "gpt-4o-mini",
"output": [
{
"type": "message",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "The current time is..."
}
]
}
]
}curl -X POST http://localhost:8088/v1/responses \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-4o-mini",
"input": "What time is it?",
"stream": true
}'Expected SSE Events:
event: response.created
data: {"type": "response.created", "response": {"id": "resp_...", "status": "in_progress"}}
event: response.output_item.added
data: {"type": "response.output_item.added", ...}
event: response.output_text.delta
data: {"type": "response.output_text.delta", "delta": "The current"}
event: response.output_text.delta
data: {"type": "response.output_text.delta", "delta": " time is..."}
event: response.done
data: {"type": "response.done", "response": {"status": "completed", ...}}
curl -X POST http://localhost:8088/v1/responses \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-4o-mini",
"input": "What time is it?",
"instructions": "You are a helpful assistant. Always be concise."
}'curl -X POST http://localhost:8088/v1/responses \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-4o-mini",
"input": "What time is it?",
"tools": [
{
"type": "function",
"name": "current_datetime",
"description": "Get the current date and time"
}
]
}'The /chat endpoint continues to use the Chat Completions format:
curl -X POST http://localhost:8088/chat \
-H 'Content-Type: application/json' \
-d '{
"messages": [{"role": "user", "content": "What time is it?"}]
}'If you want to use the Responses API format on a custom path (not containing "responses"), use the explicit openai_api_v1_format setting:
general:
front_end:
_type: fastapi
workflow:
openai_api_v1_path: /v1/custom/endpoint
openai_api_v1_format: responses # Force Responses API formatAvailable format options:
auto(default): Detects based on path patternchat_completions: Force Chat Completions API formatresponses: Force Responses API format
- No Stateful Backend:
previous_response_idis accepted but ignored - No Built-in Tools: OpenAI built-in tools like
code_interpreterare not executed by NAT; use theresponses_api_agentworkflow type for that functionality - Tool Format Conversion: Responses API tool definitions are converted to Chat Completions format internally
- Tool Calling Agent with Responses API - For using OpenAI's Responses API directly with built-in tools
- Simple Auth - Authentication example
- Custom Routes - Custom endpoint routes