How to use chat.ai.e-infra.cz via API
Generating an API token
- Log in to https://chat.ai.e-infra.cz/ via browser using your Metacentrum credentials. If you don't have one, here is how to get access.
- On the top right, click on the profile icon and open Settings.
- Navigate to the Account and click on API keys (display).
- Ignore JWT token and select API key and either generate new or display existing.
- Copy the generated API key and store it securely.
- Use this key in API requests to authenticate and access Open-WebUI services.
Endpoint API is: https://chat.ai.e-infra.cz/api/.
Listing available models
As the models are named differently in the web UI, it is necessary to list the ones that are available via the API. This can be done using the following command:
curl -H "Authorization: Bearer TOKEN" https://chat.ai.e-infra.cz/api/models | jq .data[].id
Where TOKEN
refers to the e-infra token acquired in previous steps. It is also a good way of checking whether the token is valid. The output should be similar to this:
"llama3.3:latest" "llama3.3:70b-instruct-fp16" "deepseek-r1:32b-qwen-distill-fp16" "qwen2.5-coder:32b-instruct-q8_0" "aya-expanse:latest"
Inference
As the E-Infra uses OpenAI-compatible server, you can use any Python framework that is capable of HTTP requests. Several options for inspiration are:
- openai-python: the official implementation for OpenAI API.
- PydanticAI: an extensive toolkit that supports advanced applications.
- requests: low-level approach, recommended when you want custom behavior.
Example using openai-python
import os import openai client = openai.OpenAI( # using environment variables are one of the safer ways to pass your API keys api_key=os.environ["EINFRA_AI_TOKEN"], #openai uses chatgpt url as default - we need to override it here base_url="https://chat.ai.e-infra.cz/api/", ) response = client.chat.completions.create( #here you paste the selected model model="deepseek-r1", messages=[ {"role": "system", "content": "Talk like a pirate."}, { "role": "user", "content": "How do I check if a Python object is an instance of a class?", }, ], ) print(response.choices[0].message.content)
References
Official documentation: https://docs.cerit.io/en/docs/web-apps/chat-ai