Skip to main content

LiteLLM SDK

The LiteLLM SDK calls MAG as an OpenAI-compatible endpoint. Use the prefix openai/ before the model name.

Install the SDK:

python -m pip install litellm

Make sure the environment variable AMSC_TOKEN contains your PAT. Then run this Python code:

import os

import litellm

response = litellm.completion(
model="openai/claude-sonnet",
api_base="https://mag.genesis.americansciencecloud.org/v1",
api_key=os.environ["AMSC_TOKEN"],
messages=[{"role": "user", "content": "In one sentence, explain what an AI model is."}],
)
print(response.choices[0].message.content)

The prefix openai/ tells LiteLLM to use the OpenAI-compatible protocol. MAG receives the model name after the prefix. To use a different model, change the text after openai/.