API
To use the API, you wil first need to find your API key, accessible from the UI. Click on your user avatar and navigate to Settings, and then the Account page in settings. Here you will be able to see the API Keys. Expand this section and copy either the JWT token or create an API key.
Use the following endpoint to connect to the API.
For an OpenAI API-compatible response, use https://genai.rcac.purdue.edu/api/chat/completions
For a streaming response, this will return results formated like:
data: {"id": "llama3.1:latest-dd3f8a12-a36f-4fcc-9537-02a9e7c1d9c8", "created": 1749755137, "model": "llama3.1:latest", "choices": [{"index": 0, "logprobs": null, "finish_reason": null, "delta": {"content": "I"}}], "object": "chat.completion.chunk"}
For a non-streaming response, this will return results formated like:
{"id":"llama3.1:latest-703c01b4-c58d-4f78-b7e3-f0df34a91ede","created":1749755251,"model":"llama3.1:latest","choices":[{"index":0,"logprobs":null,"finish_reason":"stop","message":{"content":"I don't have a personal name. I'm an AI designed to assist and communicate with users, so I'm often referred to as a \"chatbot\" or simply \"Assistant.\" If you'd like, I can generate a unique identifier for our conversation, but it won't be a traditional name. How can I help you today?","role":"assistant"}}],"object":"chat.completion","usage":{"response_token/s":180.38,"prompt_token/s":13403.27,"total_duration":397326193,"load_duration":13348992,"prompt_eval_count":15,"prompt_tokens":15,"prompt_eval_duration":1119130,"eval_count":69,"completion_tokens":69,"eval_duration":382515521,"approximate_total":"0h0m0s","total_tokens":84,"completion_tokens_details":{"reasoning_tokens":0,"accepted_prediction_tokens":0,"rejected_prediction_tokens":0}}}
To use the endpoint, insert your API key in the example Python code below:
import requests
url = "https://genai.rcac.purdue.edu/api/chat/completions"
headers = {
"Authorization": f"Bearer {jwt_token_or_api_key}",
"Content-Type": "application/json"
}
body = {
"model": "llama3.1:latest",
"messages": [
{
"role": "user",
"content": "What is your name?"
}
],
"stream": True
}
response = requests.post(url, headers=headers, json=body)
if response.status_code == 200:
print(response.text)
else:
raise Exception(f"Error: {response.status_code}, {response.text}")
This will return output in a JSON format along with metadata.