Python API Access
KeyMaker is OpenAI-compatible, so you can call campusGenAI’s models from Python with the official openai SDK — just point it at the KeyMaker base URL and authenticate with your API key. This is the foundation for research pipelines, batch processing, and custom applications.
Prerequisites
Section titled “Prerequisites”- Python 3.8 or newer (
python --version) - A valid KeyMaker API key from your sponsor — see Getting Started
Install the SDK
Section titled “Install the SDK”pip install openaiKeyMaker is compatible with the OpenAI SDK because the underlying proxy (LiteLLM) speaks the OpenAI API format. No campusGenAI-specific package is required.
Save your API key
Section titled “Save your API key”Store your KeyMaker key as an environment variable rather than hardcoding it into your scripts or notebooks — that keeps it out of files you might share or commit.
macOS / Linux:
echo 'export KEYMAKER_API_KEY="YOUR_KEY_HERE"' >> ~/.zshrc && source ~/.zshrcWindows (PowerShell):
[Environment]::SetEnvironmentVariable("KEYMAKER_API_KEY", "YOUR_KEY_HERE", "User")Restart your terminal afterward so the variable is available to Python.
Create the client
Section titled “Create the client”Point the OpenAI client at the KeyMaker base URL and read your key from the environment:
import osimport openai
client = openai.OpenAI( api_key=os.environ["KEYMAKER_API_KEY"], base_url="https://thekeymaker.umass.edu/v1",)See available models
Section titled “See available models”List the models your KeyMaker account can use:
models = client.models.list()print("Available models:")for model in models.data: print(f"- {model.id}")Make note of the model name you want to use (for example, claude-opus-4-8). See the Model Comparison page for what each model is best at.
Send your first request
Section titled “Send your first request”response = client.chat.completions.create( model="claude-opus-4-8", messages=[ {"role": "user", "content": "This is a test request, write a short poem."}, ], max_tokens=50,)
print(response.choices[0].message.content)If you see the model’s reply printed, your setup is working — all requests now route through KeyMaker, using the models, permissions, and usage controls of the KeyMaker platform.
Inspect token usage
Section titled “Inspect token usage”Every response carries a usage object showing how many tokens the request consumed — useful for tracking cost against your funding source:
print(response.usage)# CompletionUsage(completion_tokens=50, prompt_tokens=17, total_tokens=67, ...)Integrate into your application
Section titled “Integrate into your application”For real use, create the client once and wrap requests in a function you can call throughout your code. Reading the key from the environment means the same function works in a script, a notebook, or a deployed service without changes.
import osimport openai
client = openai.OpenAI( api_key=os.environ["KEYMAKER_API_KEY"], base_url="https://thekeymaker.umass.edu/v1",)
def ask(prompt, model="claude-opus-4-8"): response = client.chat.completions.create( model=model, messages=[{"role": "user", "content": prompt}], ) return response.choices[0].message.content
# Reuse it across your applicationfor topic in ["photosynthesis", "tariffs", "tectonic plates"]: print(ask(f"Explain {topic} in one sentence."))This is the same call you made above, factored so the client is configured in one place and reused — the pattern behind batch processing and research pipelines.
Troubleshooting
Section titled “Troubleshooting”Authentication errors Confirm your key is available to Python:
import osprint(os.environ.get("KEYMAKER_API_KEY"))If it prints None, the variable isn’t set in this environment — re-run the Save your API key step and restart your terminal (or your notebook kernel). If the key is present but still rejected, verify it’s correct, hasn’t expired or been revoked, and re-copy it from the KeyMaker portal if needed.
Model not found
List the models available to your account (the snippet above) and update the model value to match exactly.
Connection or base-URL errors
Confirm base_url is exactly https://thekeymaker.umass.edu/v1, including the /v1 suffix.
Next steps
Section titled “Next steps”- Usage and Best Practices — monitoring usage, cost awareness, and security
Need help?
Section titled “Need help?”- Get help: Contact us
- About campusGenAI: Main site
Your interface may look slightly different depending on your institution’s deployment.