Tool Calling
Basic tool calls
import os
from openai import OpenAI
client = OpenAI(
api_key='<API_KEY>',
base_url='https://llm.onerouter.pro/v1'
)
tools = [
{
'type': 'function',
'function': {
'name': 'get_weather',
'description': 'Get the current weather in a given location',
'parameters': {
'type': 'object',
'properties': {
'location': {
'type': 'string',
'description': 'The city and state, e.g. San Francisco, CA'
},
'unit': {
'type': 'string',
'enum': ['celsius', 'fahrenheit'],
'description': 'The unit for temperature'
}
},
'required': ['location']
}
}
}
]
completion = client.chat.completions.create(
model='claude-sonnet-4-5@20250929',
messages=[
{
'role': 'user',
'content': 'What is the weather like in San Francisco?'
}
],
tools=tools,
tool_choice='auto',
stream=False,
)
print('Assistant:', completion.choices[0].message.content)
print('Tool calls:', completion.choices[0].message.tool_calls)Next steps
Tool CallingLast updated