Get up to speed with our API in one minute.
Welcome to the Inference Endpoints of the Swiss AI Platform! This guide will walk you through the basics of accessing and using our API to run inference with the new Apertus 70B model
1. Obtain your personal API Key
To get started, you'll need to have an API key. You can find your personal key in your hacker profile.
With your API key, you can authenticate your requests to our API. There is a rate limit of 5 requests per second.
2. Set up your API Key (recommended)
Configure your API key as an environment variable. This approach streamlines your API usage by eliminating the need to include the key in every request. Moreover, it enhances security by reducing the risk of accidental exposing your API key in your codebase.
For Linux or macOS, you can set the environment variable in your terminal session like this:
export SWISS_AI_PLATFORM_API_KEY=<your-api-key>
3. Requesting your first answer from Apertus 70B
Our API's are OpenAI API compatible, so you can query our models as you are used to with the OpenAI SDK.
Here's how to call a chat model using curl
:
curl -X POST https://api.swisscom.com/layer/swiss-ai-weeks/apertus-70b/v1/chat/completions \\
-H "Authorization: Bearer $SWISS_AI_PLATFORM_API_KEY" \\
-H "Content-Type: application/json" \\
-d '{
"model": "swiss-ai/Apertus-70B",
"messages": [
{"role": "user", "content": "Hello, how are you?"}
]
}'
Or, if you prefer Python, you can use the OpenAI Python SDK. First, install the SDK if you haven't already:
pip install openai
Then, you can use the following Python code to make a request:
import os
import openai
client = openai.OpenAI(
api_key=os.getenv("SWISS_AI_PLATFORM_API_KEY"),
base_url="https://api.swisscom.com/layer/swiss-ai-weeks/apertus-70b/v1"
)
stream = client.chat.completions.create(
model="swiss-ai/Apertus-70B",
messages=[
{"role": "system", "content": "You are a travel agent. Be descriptive and helpful"},
{"role": "user", "content": "What are the best places to visit in Switzerland?"}
],
stream=True
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="", flush=True)
🎉 Congratulations! You have successfully made your first request to the Swiss AI Platform's Inference Endpoints!