mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
[Fix] - Responses API - add /openai routes for responses API. (Azure OpenAI SDK Compatibility) (#15988)
* add /openai routes for responses API * TestResponsesAPIEndpoints
This commit is contained in:
parent
43af45ab88
commit
4cef208c5f
3 changed files with 78 additions and 0 deletions
|
|
@ -17,6 +17,11 @@ router = APIRouter()
|
|||
dependencies=[Depends(user_api_key_auth)],
|
||||
tags=["responses"],
|
||||
)
|
||||
@router.post(
|
||||
"/openai/v1/responses",
|
||||
dependencies=[Depends(user_api_key_auth)],
|
||||
tags=["responses"],
|
||||
)
|
||||
async def responses_api(
|
||||
request: Request,
|
||||
fastapi_response: Response,
|
||||
|
|
@ -90,6 +95,11 @@ async def responses_api(
|
|||
dependencies=[Depends(user_api_key_auth)],
|
||||
tags=["responses"],
|
||||
)
|
||||
@router.get(
|
||||
"/openai/v1/responses/{response_id}",
|
||||
dependencies=[Depends(user_api_key_auth)],
|
||||
tags=["responses"],
|
||||
)
|
||||
async def get_response(
|
||||
response_id: str,
|
||||
request: Request,
|
||||
|
|
@ -162,6 +172,11 @@ async def get_response(
|
|||
dependencies=[Depends(user_api_key_auth)],
|
||||
tags=["responses"],
|
||||
)
|
||||
@router.delete(
|
||||
"/openai/v1/responses/{response_id}",
|
||||
dependencies=[Depends(user_api_key_auth)],
|
||||
tags=["responses"],
|
||||
)
|
||||
async def delete_response(
|
||||
response_id: str,
|
||||
request: Request,
|
||||
|
|
@ -234,6 +249,11 @@ async def delete_response(
|
|||
dependencies=[Depends(user_api_key_auth)],
|
||||
tags=["responses"],
|
||||
)
|
||||
@router.get(
|
||||
"/openai/v1/responses/{response_id}/input_items",
|
||||
dependencies=[Depends(user_api_key_auth)],
|
||||
tags=["responses"],
|
||||
)
|
||||
async def get_response_input_items(
|
||||
response_id: str,
|
||||
request: Request,
|
||||
|
|
@ -297,6 +317,11 @@ async def get_response_input_items(
|
|||
dependencies=[Depends(user_api_key_auth)],
|
||||
tags=["responses"],
|
||||
)
|
||||
@router.post(
|
||||
"/openai/v1/responses/{response_id}/cancel",
|
||||
dependencies=[Depends(user_api_key_auth)],
|
||||
tags=["responses"],
|
||||
)
|
||||
async def cancel_response(
|
||||
response_id: str,
|
||||
request: Request,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
"""
|
||||
Test for response_api_endpoints/endpoints.py
|
||||
"""
|
||||
import unittest
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from litellm.proxy.proxy_server import app
|
||||
|
||||
|
||||
class TestResponsesAPIEndpoints(unittest.TestCase):
|
||||
@pytest.mark.asyncio
|
||||
@patch("litellm.proxy.proxy_server.llm_router")
|
||||
@patch("litellm.proxy.proxy_server.user_api_key_auth")
|
||||
async def test_openai_v1_responses_route(self, mock_auth, mock_router):
|
||||
"""
|
||||
Test that /openai/v1/responses endpoint is correctly registered and accessible.
|
||||
"""
|
||||
mock_auth.return_value = MagicMock(
|
||||
token="test_token",
|
||||
user_id="test_user",
|
||||
team_id=None,
|
||||
)
|
||||
|
||||
mock_router.aresponses = AsyncMock(
|
||||
return_value={
|
||||
"id": "resp_abc123",
|
||||
"object": "realtime.response",
|
||||
"status": "completed",
|
||||
"output": [
|
||||
{
|
||||
"type": "message",
|
||||
"role": "assistant",
|
||||
"content": [{"type": "text", "text": "Test response"}],
|
||||
}
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
test_data = {"model": "gpt-4o", "input": "Tell me about AI"}
|
||||
|
||||
response = client.post(
|
||||
"/openai/v1/responses",
|
||||
json=test_data,
|
||||
headers={"Authorization": "Bearer sk-1234"},
|
||||
)
|
||||
|
||||
assert response.status_code in [200, 401, 500]
|
||||
|
||||
Loading…
Add table
Reference in a new issue