Skip to content

Instantly share code, notes, and snippets.

@heiko-braun
Last active August 5, 2025 05:56
Show Gist options
  • Select an option

  • Save heiko-braun/8481eaae4d6a07499b7801baf942bcc6 to your computer and use it in GitHub Desktop.

Select an option

Save heiko-braun/8481eaae4d6a07499b7801baf942bcc6 to your computer and use it in GitHub Desktop.
from locust import HttpUser, task, between
from dotenv import load_dotenv
import os
import urllib3
import uuid
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
load_dotenv()
class MyUser(HttpUser):
wait_time = between(1, 5) # Random wait time between requests
@task
def litellm_completion(self):
payload = {
"model": "fake-openai-endpoint",
"messages": [
{"role": "system", "content": "You are a chat bot."},
{"role": "user", "content": "Hello, how are you?"},
]
}
response = self.client.post(
"v1/chat/completions",
json=payload,
verify=False
)
if response.status_code != 200:
# log the errors in error.txt
with open("error.txt", "a") as error_log:
error_log.write(response.text + "\n")
def on_start(self):
self.api_key = os.getenv('API_KEY', os.getenv("USER_KEY"))
self.client.headers.update({'Authorization': f'Bearer {self.api_key}'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment