1212from openai .types .completion_usage import CompletionUsage
1313from openai .types .create_embedding_response import CreateEmbeddingResponse , Usage
1414from openai .types .embedding import Embedding
15- from openai .types .responses import Response , ResponseOutputItem , ResponseOutputMessage , ResponseUsage
15+ from openai .types .responses import Response , ResponseUsage , ResponseOutputMessage , ResponseOutputText
1616
1717from posthog .ai .openai import OpenAI
1818
@@ -36,10 +36,7 @@ def mock_openai_response():
3636 finish_reason = "stop" ,
3737 index = 0 ,
3838 message = ChatCompletionMessage (
39- content = {
40- "type" : "text" ,
41- "text" : "Test response" ,
42- },
39+ content = "Test response" ,
4340 role = "assistant" ,
4441 ),
4542 )
@@ -58,23 +55,39 @@ def mock_openai_response_with_responses_api():
5855 id = "test" ,
5956 model = "gpt-4o-mini" ,
6057 object = "response" ,
58+ created_at = 1741476542 ,
59+ status = "completed" ,
60+ error = None ,
61+ incomplete_details = None ,
62+ instructions = None ,
63+ max_output_tokens = None ,
64+ tools = [],
65+ tool_choice = "auto" ,
6166 output = [
62- ResponseOutputItem (
67+ ResponseOutputMessage (
68+ id = "msg_123" ,
6369 type = "message" ,
6470 role = "assistant" ,
71+ status = "completed" ,
6572 content = [
66- ResponseOutputMessage (
67- type = "input_text " ,
73+ ResponseOutputText (
74+ type = "output_text " ,
6875 text = "Test response" ,
76+ annotations = [],
6977 )
7078 ],
7179 )
7280 ],
81+ parallel_tool_calls = True ,
82+ previous_response_id = None ,
7383 usage = ResponseUsage (
7484 input_tokens = 10 ,
7585 output_tokens = 10 ,
86+ output_tokens_details = {"reasoning_tokens" : 15 },
7687 total_tokens = 20 ,
7788 ),
89+ user = None ,
90+ metadata = {},
7891 )
7992
8093
@@ -537,7 +550,7 @@ def test_responses_api(mock_client, mock_openai_response_with_responses_api):
537550 client = OpenAI (api_key = "test-key" , posthog_client = mock_client )
538551 response = client .responses .create (
539552 model = "gpt-4o-mini" ,
540- input = [{ "role" : "user" , "content" : " Hello"}] ,
553+ input = " Hello" ,
541554 posthog_distinct_id = "test-id" ,
542555 posthog_properties = {"foo" : "bar" },
543556 )
@@ -555,6 +568,7 @@ def test_responses_api(mock_client, mock_openai_response_with_responses_api):
555568 assert props ["$ai_output_choices" ] == [{"role" : "assistant" , "content" : "Test response" }]
556569 assert props ["$ai_input_tokens" ] == 10
557570 assert props ["$ai_output_tokens" ] == 10
571+ assert props ["$ai_reasoning_tokens" ] == 15
558572 assert props ["$ai_http_status" ] == 200
559573 assert props ["foo" ] == "bar"
560574 assert isinstance (props ["$ai_latency" ], float )
0 commit comments