Skip to main content
Version: 3.6.0

Quickstart: your first Model Gateway call

This quickstart is for developers. In about 10 minutes you create an API key and call a model through the Model Gateway, the platform's OpenAI-compatible API.

You need:

  • an account in a tenant, with access to at least one chat model
  • curl, or Python with the openai package

1. Create an API key​

  1. Open API Keys in the portal and select Create key.
  2. Under Key type, choose Personal (selected resources), and enter a Display name.
  3. Under Grants, set Resource type to Model (or Model Alias, if your tenant has one for the model), choose the model under Resource, and keep the action Invoke.
  4. Select Create, then copy the key now. It is shown only once and can't be retrieved later.

Each model or RAG page in the CM portal has a Create API key link that opens this form with that model or RAG endpoint already granted.

2. Copy the API URL​

The API URL is at the bottom of the portal sidebar, with a button that copies it. Set it and your key as environment variables:

export API_BASE_URL="https://api.<your-domain>"
export API_KEY="cm_api_…"

3. Find your model ID​

List the models your key can use:

curl -sS "${API_BASE_URL}/v1/models" \
-H "Authorization: Bearer ${API_KEY}"

Copy the id of the model you want. Send it exactly as it appears in the list:

export MODEL_ID="YOUR_MODEL_ID"

4. Call the model​

With curl:

curl -sS "${API_BASE_URL}/v1/chat/completions" \
-H "Authorization: Bearer ${API_KEY}" \
-H "Content-Type: application/json" \
-d "{\"model\": \"${MODEL_ID}\", \"messages\": [{\"role\": \"user\", \"content\": \"Hello\"}]}"

Or with the OpenAI Python client:

import os

from openai import OpenAI

client = OpenAI(base_url=f"{os.environ['API_BASE_URL']}/v1", api_key=os.environ["API_KEY"])

resp = client.chat.completions.create(
model=os.environ["MODEL_ID"],
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)

The gateway checks that your key may invoke the model, forwards your message, and returns an OpenAI-style chat completion. The model's reply is in choices[0].message.content, which is what the Python example prints.

A 404 means the model ID doesn't match a ready model: check it against the list from step 3. A 403 means the key has no Invoke grant on that model.

Keep the key secret. Don't put it in client-side code or commit it to version control.

More resources​