Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(types): filter null fields from reasoning output items (#22370)

Shivaang5f28422f4990
diff --git a/litellm/types/llms/openai.py b/litellm/types/llms/openai.py
index c0aae9bc2de..f82f6a02f22 100644
--- a/litellm/types/llms/openai.py
+++ b/litellm/types/llms/openai.py
@@ -71,7 +71,7 @@ from openai.types.responses.response_create_params import (
ToolParam,
)
from openai.types.responses.response_function_tool_call import ResponseFunctionToolCall
-from pydantic import BaseModel, ConfigDict, Discriminator, PrivateAttr, field_validator
+from pydantic import BaseModel, ConfigDict, Discriminator, PrivateAttr, field_serializer, field_validator
from typing_extensions import Annotated, Dict, Required, TypedDict, override
from litellm.types.llms.base import BaseLiteLLMOpenAIResponseObject
@@ -1260,6 +1260,36 @@ class ResponsesAPIResponse(BaseLiteLLMOpenAIResponseObject):
return ResponseAPIUsage(**value)
return value
+ @field_serializer("output", mode="wrap")
+ @classmethod
+ def _serialize_output_filter_reasoning_nulls(cls, value, handler, _info):
+ """
+ Filter null status/content/encrypted_content from reasoning output items.
+
+ Mirrors the request-side filtering in
+ OpenAIResponsesAPIConfig._handle_reasoning_item() which filters these
+ same fields before sending requests to providers.
+
+ Without this, reasoning items include null fields that cause SDK errors
+ (e.g., the OpenAI C# SDK crashes on status=null).
+
+ Issue: https://github.com/BerriAI/litellm/issues/16824
+ """
+ serialized = handler(value)
+ if not isinstance(serialized, list):
+ return serialized
+ return [
+ {
+ k: v
+ for k, v in item.items()
+ if v is not None
+ or k not in ("status", "content", "encrypted_content")
+ }
+ if isinstance(item, dict) and item.get("type") == "reasoning"
+ else item
+ for item in serialized
+ ]
+
@property
def output_text(self) -> str:
"""
diff --git a/tests/test_litellm/proxy/auth/test_handle_jwt.py b/tests/test_litellm/proxy/auth/test_handle_jwt.py
index 3c190974277..8418dde5e9c 100644
--- a/tests/test_litellm/proxy/auth/test_handle_jwt.py
+++ b/tests/test_litellm/proxy/auth/test_handle_jwt.py
@@ -1559,7 +1559,6 @@ async def test_resolve_jwks_url_caches_resolved_jwks_uri():
jwks_url = "https://login.microsoftonline.com/tenant/discovery/keys"
mock_response = MagicMock()
- mock_response.status_code = 200
mock_response.json.return_value = {"jwks_uri": jwks_url}
with patch.object(handler.http_handler, "get", new_callable=AsyncMock, return_value=mock_response) as mock_get:
@@ -1588,7 +1587,6 @@ async def test_resolve_jwks_url_raises_if_no_jwks_uri_in_discovery_doc():
discovery_url = "https://example.com/.well-known/openid-configuration"
mock_response = MagicMock()
- mock_response.status_code = 200
mock_response.json.return_value = {"issuer": "https://example.com"} # no jwks_uri
with patch.object(handler.http_handler, "get", new_callable=AsyncMock, return_value=mock_response):
diff --git a/tests/test_litellm/types/llms/test_types_llms_openai.py b/tests/test_litellm/types/llms/test_types_llms_openai.py
index 054fe505764..94221bd0efc 100644
--- a/tests/test_litellm/types/llms/test_types_llms_openai.py
+++ b/tests/test_litellm/types/llms/test_types_llms_openai.py
@@ -263,3 +263,150 @@ class TestAssistantMessageImageUrlContent:
assert "image_url" in types, (
f"image_url block was silently dropped during AllMessageValues serialisation; blocks: {content}"
)
+
+
+class TestResponsesAPIReasoningNullFields:
+ """
+ Tests for issue #16824: reasoning output items should not include null
+ status/content/encrypted_content fields.
+
+ When a provider returns reasoning items without these fields, LiteLLM's
+ Pydantic parsing adds them as Optional defaults (None). Serializing them
+ as null breaks downstream SDKs (e.g., the OpenAI C# SDK crashes on
+ status=null).
+
+ The fix uses a field_serializer on ResponsesAPIResponse.output that
+ mirrors the request-side filtering in
+ OpenAIResponsesAPIConfig._handle_reasoning_item().
+ """
+
+ def _make_response(self, output):
+ from litellm.types.llms.openai import ResponsesAPIResponse
+
+ return ResponsesAPIResponse(
+ id="resp_test",
+ created_at=1741476542,
+ model="gpt-5-mini",
+ object="response",
+ status="completed",
+ output=output,
+ )
+
+ def test_reasoning_item_null_fields_removed_model_dump(self):
+ """Null status/content/encrypted_content should be absent from model_dump."""
+ response = self._make_response(
+ output=[{"id": "rs_abc", "type": "reasoning", "summary": []}]
+ )
+ dumped = response.model_dump()
+ reasoning = dumped["output"][0]
+ assert "status" not in reasoning
+ assert "content" not in reasoning
+ assert "encrypted_content" not in reasoning
+
+ def test_reasoning_item_null_fields_removed_model_dump_json(self):
+ """Null fields should also be absent from model_dump_json."""
+ response = self._make_response(
+ output=[{"id": "rs_abc", "type": "reasoning", "summary": []}]
+ )
+ parsed = json.loads(response.model_dump_json())
+ reasoning = parsed["output"][0]
+ assert "status" not in reasoning
+ assert "content" not in reasoning
+ assert "encrypted_content" not in reasoning
+
+ def test_reasoning_item_non_null_values_preserved(self):
+ """Non-null values on reasoning items should be kept."""
+ response = self._make_response(
+ output=[
+ {
+ "id": "rs_abc",
+ "type": "reasoning",
+ "summary": [],
+ "status": "completed",
+ "encrypted_content": "gAAAA...",
+ }
+ ]
+ )
+ dumped = response.model_dump()
+ reasoning = dumped["output"][0]
+ assert reasoning["status"] == "completed"
+ assert reasoning["encrypted_content"] == "gAAAA..."
+
+ def test_message_item_not_affected(self):
+ """Non-reasoning output items should keep all their fields."""
+ response = self._make_response(
+ output=[
+ {
+ "id": "msg_abc",
+ "type": "message",
+ "role": "assistant",
+ "status": "completed",
+ "content": [
+ {
+ "type": "output_text",
+ "text": "Hello!",
+ "annotations": [],
+ }
+ ],
+ }
+ ]
+ )
+ dumped = response.model_dump()
+ message = dumped["output"][0]
+ assert message["status"] == "completed"
+ assert message["type"] == "message"
+ assert len(message["content"]) == 1
+
+ def test_mixed_output_reasoning_and_message(self):
+ """Reasoning items cleaned, message items untouched in same response."""
+ response = self._make_response(
+ output=[
+ {"id": "rs_abc", "type": "reasoning", "summary": []},
+ {
+ "id": "msg_abc",
+ "type": "message",
+ "role": "assistant",
+ "status": "completed",
+ "content": [
+ {
+ "type": "output_text",
+ "text": "Answer",
+ "annotations": [],
+ }
+ ],
+ },
+ ]
+ )
+ dumped = response.model_dump()
+ reasoning = [
+ o for o in dumped["output"] if isinstance(o, dict) and o.get("type") == "reasoning"
+ ][0]
+ message = [
+ o for o in dumped["output"] if isinstance(o, dict) and o.get("type") == "message"
+ ][0]
+ assert "status" not in reasoning
+ assert "content" not in reasoning
+ assert message["status"] == "completed"
+ assert len(message["content"]) == 1
+
+ def test_reasoning_core_fields_preserved(self):
+ """id, type, summary should always be present on reasoning items."""
+ response = self._make_response(
+ output=[{"id": "rs_abc", "type": "reasoning", "summary": ["thinking..."]}]
+ )
+ dumped = response.model_dump()
+ reasoning = dumped["output"][0]
+ assert reasoning["id"] == "rs_abc"
+ assert reasoning["type"] == "reasoning"
+ assert reasoning["summary"] == ["thinking..."]
+
+ def test_top_level_null_fields_unaffected(self):
+ """Top-level response fields with None should not be affected."""
+ response = self._make_response(
+ output=[{"id": "rs_abc", "type": "reasoning", "summary": []}]
+ )
+ dumped = response.model_dump()
+ assert "error" in dumped
+ assert dumped["error"] is None
+ assert "instructions" in dumped
+ assert dumped["instructions"] is None
diff --git a/ui/litellm-dashboard/src/components/Projects/ProjectDetailsPage.tsx b/ui/litellm-dashboard/src/components/Projects/ProjectDetailsPage.tsx
index 77beac65ad7..637771e2299 100644
--- a/ui/litellm-dashboard/src/components/Projects/ProjectDetailsPage.tsx
+++ b/ui/litellm-dashboard/src/components/Projects/ProjectDetailsPage.tsx
@@ -17,11 +17,10 @@ import {
} from "antd";
import { LoadingOutlined } from "@ant-design/icons";
import { BarChart } from "@tremor/react";
-import { ArrowLeftIcon, DollarSignIcon, EditIcon, UsersIcon } from "lucide-react";
+import { ArrowLeftIcon, DollarSignIcon, EditIcon, KeyIcon, UsersIcon } from "lucide-react";
import { useMemo, useState } from "react";
import DefaultProxyAdminTag from "../common_components/DefaultProxyAdminTag";
import { EditProjectModal } from "./ProjectModals/EditProjectModal";
-import { ProjectKeysSection } from "./ProjectKeysSection";
const { Title, Text } = Typography;
const { Content } = Layout;
@@ -204,7 +203,17 @@ export function ProjectDetail({ projectId, onBack }: ProjectDetailProps) {
{/* Keys & Team */}
<Row gutter={[16, 16]} style={{ marginBottom: 24 }}>
<Col xs={24} lg={12}>
- <ProjectKeysSection projectId={project.project_id} />
+ <Card
+ title={
+ <Flex align="center" gap={8}>
+ <KeyIcon size={16} />
+ Keys
+ </Flex>
+ }
+ style={{ height: "100%" }}
+ >
+ <Empty description="No keys to display" image={Empty.PRESENTED_IMAGE_SIMPLE} />
+ </Card>
</Col>
<Col xs={24} lg={12}>
<Card
diff --git a/ui/litellm-dashboard/src/components/Projects/ProjectsPage.tsx b/ui/litellm-dashboard/src/components/Projects/ProjectsPage.tsx
index 3762ddbb376..f0b593c2e49 100644
--- a/ui/litellm-dashboard/src/components/Projects/ProjectsPage.tsx
+++ b/ui/litellm-dashboard/src/components/Projects/ProjectsPage.tsx
@@ -1,15 +1,12 @@
-import { useDeleteProject } from "@/app/(dashboard)/hooks/projects/useDeleteProject";
import { useProjects, ProjectResponse } from "@/app/(dashboard)/hooks/projects/useProjects";
import { useTeams } from "@/app/(dashboard)/hooks/teams/useTeams";
import { LoadingOutlined, PlusOutlined } from "@ant-design/icons";
import {
- Alert,
Button,
Card,
Flex,
Input,
Layout,
- message,
Pagination,
Space,
Spin,
@@ -22,8 +19,6 @@ import {
import type { ColumnsType } from "antd/es/table";
import { LayersIcon, SearchIcon } from "lucide-react";
import { useEffect, useMemo, useState } from "react";
-import DeleteResourceModal from "../common_components/DeleteResourceModal";
-import TableIconActionButton from "../common_components/IconActionButton/TableIconActionButtons/TableIconActionButton";
import { CreateProjectModal } from "./ProjectModals/CreateProjectModal";
import { ProjectDetail } from "./ProjectDetailsPage";
@@ -35,11 +30,8 @@ export function ProjectsPage() {
const { data: projects, isLoading } = useProjects();
const { data: teams, isLoading: isTeamsLoading } = useTeams();
- const deleteMutation = useDeleteProject();
-
const [selectedProjectId, setSelectedProjectId] = useState<string | null>(null);
const [isCreateModalVisible, setIsCreateModalVisible] = useState(false);
- const [projectToDelete, setProjectToDelete] = useState<ProjectResponse | null>(null);
const [searchText, setSearchText] = useState("");
const [currentPage, setCurrentPage] = useState(1);
const pageSize = 10;
@@ -158,18 +150,6 @@ export function ProjectsPage() {
responsive: ["xl"],
render: (date: string) => new Date(date).toLocaleDateString(),
},
- {
- title: "Actions",
- key: "actions",
- width: 80,
- render: (_: unknown, record: ProjectResponse) => (
- <TableIconActionButton
- variant="Delete"
- tooltipText="Delete project"
- onClick={() => setProjectToDelete(record)}
- />
- ),
- },
];
if (selectedProjectId) {
@@ -185,12 +165,6 @@ export function ProjectsPage() {
<Content
style={{ padding: token.paddingLG, paddingInline: token.paddingLG * 2 }}
>
- <Alert
- message="Projects is currently in beta. Features and behavior may change without notice."
- type="warning"
- showIcon
- style={{ marginBottom: 16 }}
- />
<Flex
justify="space-between"
align="center"
@@ -198,7 +172,7 @@ export function ProjectsPage() {
>
<Space direction="vertical" size={0}>
<Title level={2} style={{ margin: 0 }}>
- [BETA] Projects
+ Projects
</Title>
<Text type="secondary">
Manage projects within your teams
@@ -250,34 +224,6 @@ export function ProjectsPage() {
isOpen={isCreateModalVisible}
onClose={() => setIsCreateModalVisible(false)}
/>
-
- <DeleteResourceModal
- isOpen={projectToDelete !== null}
- title="Delete Project"
- alertMessage="This action is irreversible. All keys must be unlinked from this project before it can be deleted."
- message="Are you sure you want to delete this project?"
- resourceInformationTitle="Project Information"
- resourceInformation={[
- { label: "Name", value: projectToDelete?.project_alias || "—" },
- { label: "Project ID", value: projectToDelete?.project_id, code: true },
- { label: "Team", value: teamAliasMap.get(projectToDelete?.team_id ?? "") || projectToDelete?.team_id || "—" },
- ]}
- onCancel={() => setProjectToDelete(null)}
- onOk={() => {
- if (!projectToDelete) return;
- deleteMutation.mutate([projectToDelete.project_id], {
- onSuccess: () => {
- message.success("Project deleted successfully");
- setProjectToDelete(null);
- },
- onError: (error) => {
- message.error(error.message || "Failed to delete project");
- },
- });
- }}
- confirmLoading={deleteMutation.isPending}
- requiredConfirmation={projectToDelete?.project_alias ?? undefined}
- />
</Content>
);
}