main
 1from typing import List
 2
 3from openai import OpenAI
 4from openai.types.responses.tool_param import ToolParam
 5from openai.types.responses.response_input_item_param import ResponseInputItemParam
 6
 7
 8def 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
53if __name__ == "__main__":
54    main()