OpenAI compatible API
GenAI4Science portal has built-in compatibility with the OpenAI Chat Completions API, making it possible to use more tooling.
API url
The OpenAI API url is:
Authentication
To ensure secure access to the API, authentication is required. You can authenticate your API requests using the Bearer Token mechanism. Obtain your API key from Settings > Account in the Portal.
Usage
To invoke OpenAI compatible API endpoint, use the same OpenAI format
cURL
Set your API key in the header parameter "Authorization" after "Bearer"
curl https://genai.science-cloud.hu/ollama/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-9a..." \
-d '{
"model": "llama3.1:8b",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
]
}'
Python
Set your API key
from openai import OpenAI
client = OpenAI(base_url="https://genai.science-cloud.hu/ollama/v1/", api_key="sk-9a...")
print(client.models.list())
response = client.chat.completions.create(
model="llama3.1:8b",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is a LLM?"}
]
)
print(response)
More details: https://ollama.com/blog/openai-compatibility