Skip to content

Commit 6dd09e2

Browse files
feat(api): Add responses.input_tokens.count
1 parent caabd7c commit 6dd09e2

File tree

10 files changed

+716
-4
lines changed

10 files changed

+716
-4
lines changed

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 135
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-b062c33330de7e3bbf992fd4f0799afd868c30a66c39418dd2c62f4add3b45b6.yml
3-
openapi_spec_hash: fe067f5b1c0e93799b5ea7fde3c4b1b3
4-
config_hash: 4b6f471b24d659514b86b736c90a0c0a
1+
configured_endpoints: 136
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-812a10f8fb54c584efc914422b574cb3f43dc238b5733b13f6a0b2308b7d9910.yml
3+
openapi_spec_hash: 0222041ba12a5ff6b94924a834fa91a2
4+
config_hash: 50ee3382a63c021a9f821a935950e926

api.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,18 @@ Methods:
865865

866866
- <code title="get /responses/{response_id}/input_items">client.responses.input_items.<a href="./src/openai/resources/responses/input_items.py">list</a>(response_id, \*\*<a href="src/openai/types/responses/input_item_list_params.py">params</a>) -> <a href="./src/openai/types/responses/response_item.py">SyncCursorPage[ResponseItem]</a></code>
867867

868+
## InputTokens
869+
870+
Types:
871+
872+
```python
873+
from openai.types.responses import InputTokenCountResponse
874+
```
875+
876+
Methods:
877+
878+
- <code title="post /responses/input_tokens">client.responses.input_tokens.<a href="./src/openai/resources/responses/input_tokens.py">count</a>(\*\*<a href="src/openai/types/responses/input_token_count_params.py">params</a>) -> <a href="./src/openai/types/responses/input_token_count_response.py">InputTokenCountResponse</a></code>
879+
868880
# Realtime
869881

870882
Types:

examples/responses_input_tokens.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from typing import List
2+
3+
from openai import OpenAI
4+
from openai.types.responses.tool_param import ToolParam
5+
from openai.types.responses.response_input_item_param import ResponseInputItemParam
6+
7+
8+
def main() -> None:
9+
client = OpenAI()
10+
tools: List[ToolParam] = [
11+
{
12+
"type": "function",
13+
"name": "get_current_weather",
14+
"description": "Get current weather in a given location",
15+
"parameters": {
16+
"type": "object",
17+
"properties": {
18+
"location": {
19+
"type": "string",
20+
"description": "City and state, e.g. San Francisco, CA",
21+
},
22+
"unit": {
23+
"type": "string",
24+
"enum": ["c", "f"],
25+
"description": "Temperature unit to use",
26+
},
27+
},
28+
"required": ["location", "unit"],
29+
"additionalProperties": False,
30+
},
31+
"strict": True,
32+
}
33+
]
34+
35+
input_items: List[ResponseInputItemParam] = [
36+
{
37+
"type": "message",
38+
"role": "user",
39+
"content": [{"type": "input_text", "text": "What's the weather in San Francisco today?"}],
40+
}
41+
]
42+
43+
response = client.responses.input_tokens.count(
44+
model="gpt-5",
45+
instructions="You are a concise assistant.",
46+
input=input_items,
47+
tools=tools,
48+
tool_choice={"type": "function", "name": "get_current_weather"},
49+
)
50+
print(f"input tokens: {response.input_tokens}")
51+
52+
53+
if __name__ == "__main__":
54+
main()

src/openai/resources/responses/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
InputItemsWithStreamingResponse,
1717
AsyncInputItemsWithStreamingResponse,
1818
)
19+
from .input_tokens import (
20+
InputTokens,
21+
AsyncInputTokens,
22+
InputTokensWithRawResponse,
23+
AsyncInputTokensWithRawResponse,
24+
InputTokensWithStreamingResponse,
25+
AsyncInputTokensWithStreamingResponse,
26+
)
1927

2028
__all__ = [
2129
"InputItems",
@@ -24,6 +32,12 @@
2432
"AsyncInputItemsWithRawResponse",
2533
"InputItemsWithStreamingResponse",
2634
"AsyncInputItemsWithStreamingResponse",
35+
"InputTokens",
36+
"AsyncInputTokens",
37+
"InputTokensWithRawResponse",
38+
"AsyncInputTokensWithRawResponse",
39+
"InputTokensWithStreamingResponse",
40+
"AsyncInputTokensWithStreamingResponse",
2741
"Responses",
2842
"AsyncResponses",
2943
"ResponsesWithRawResponse",

0 commit comments

Comments
 (0)