A simple Python client example for interacting with the Chutes AI API.
This project demonstrates how to make API requests to the Chutes AI service to generate text completions using large language models (LLMs) like DeepSeek V3. Use this as a starting point for integrating Chutes AI capabilities into your Python applications.
- Python 3.6+
requestslibrary- A Chutes AI API token
-
Clone this repository:
git clone https://github.com/yourusername/Chutes-API.git cd Chutes-API -
Install the required dependencies:
pip install requests
-
Set up your API token as an environment variable:
export CHUTES_API_TOKEN=cpk_...
The example script rest.py demonstrates how to make a basic API request:
import requests
import os
API_TOKEN = os.getenv("CHUTES_API_TOKEN")
API_URL = "https://llm.chutes.ai/v1/chat/completions"
# Make sure your API token is set
if not API_TOKEN:
print("Error: CHUTES_API_TOKEN environment variable not set.")
else:
# Sample request payload
payload = {
"model": "deepseek-ai/DeepSeek-V3-Base",
"messages": [{"role": "user", "content": "What is the capital of France?"}],
"max_tokens": 32
}
headers = {"Authorization": f"Bearer {API_TOKEN}"}
try:
response = requests.post(API_URL, headers=headers, json=payload, timeout=15)
response.raise_for_status()
print(response.json()["choices"][0]["message"]["content"])
except Exception as e:
print(f"An error occurred: {e}")python rest.pyYou can customize your API requests by modifying the payload:
- Change the
modelto use different AI models available through Chutes AI - Update the
messagesarray with different prompts - Adjust parameters like
max_tokens,temperature, etc.
- Chutes AI Dashboard
- API Documentation (if available)
This project is licensed under the terms included in the LICENSE file.
For issues with the API itself, contact Chutes AI support. For issues with this example code, please open an issue in the repository.