Large Language Models Python API
June 26, 2026 · View on GitHub
Unified python API for multiple LLM providers including alibaba, baidu, deepseek, google, tencent, xunfei, zhipu, and openrouter.
Install
pip install chatchat
Quick Start
Terminal Chat
$ chatchat run baidu ernie-lite-8k
user> Hello
assistant> Hello! How can I help you today?
user> /exit
$ chatchat run google gemini-2.5-flash --proxy YOUR_PROXY
user> Introduce yourself briefly.
assistant> Hello! I am a large language model...
user> /exit
Python Client
from chatchat.client import Client
llm = Client('tencent', model='hunyuan-lite')
# chat
response = llm.chat([{'role': 'user', 'content': 'Hello'}])
# stream
for chunk in llm.chat([{'role': 'user', 'content': 'Hello'}], stream=True):
print(chunk, end='')
Tool Calling & Agent
from chatchat.tool import tool
from chatchat.agent import Agent
@tool(
name='get_weather', description='get weather for a city',
parameters={
'type': 'object',
'properties': {
'city': {
'type': 'string',
'description': 'the city name, e.g., Shanghai',
}
},
'required': ['city'],
}
)
def get_weather(city):
return f'{city} is Sunny.'
agent = Agent(provider='zhipu', model='glm-4.7-flash', tools=[get_weather])
response = agent('How is the weather in Shanghai?')
Agent to Agent
from chatchat.agent import Agent
from chatchat.tool import tool
@tool(
name='query_ticket', description='query train tickets',
parameters={
'type': 'object',
'properties': {
'from_city': {
'type': 'string',
'description': 'the city name, e.g., Shanghai',
},
'to_city': {
'type': 'string',
'description': 'the city name, e.g., Beijing',
}
},
'required': ['from_city', 'to_city'],
}
)
def query_ticket(from_city, to_city):
...
travel_agent = Agent(
name='travel_agent',
description='query tickets between cities',
provider='zhipu', model='glm-4.7-flash',
tools=[query_ticket],
)
agent = Agent(provider='zhipu', model='glm-4.7-flash', tools=[travel_agent])
Configuration
# set API key
chatchat config <provider>.api_key=YOUR_API_KEY
# list supported providers
chatchat config --list
Refer to examples for more usage.
Sponsor
| 公众号 | |
|---|---|
![]() |
|
| AliPay | WeChatPay |
![]() |
![]() |


