from openai import OpenAI
import os
import sys
_USE_COLOR = sys.stdout.isatty() and os.getenv("NO_COLOR") is None
_REASONING_COLOR = "\033[90m" if _USE_COLOR else ""
_RESET_COLOR = "\033[0m" if _USE_COLOR else ""
client = OpenAI(
base_url = "https://integrate.api.nvidia.com/v1",
api_key = "$NVIDIA_API_KEY"
)
completion = client.chat.completions.create(
model="z-ai/glm-5.1",
messages=[{"role":"user","content":""}],
temperature=1,
top_p=1,
max_tokens=16384,
stream=True
)
for chunk in completion:
if not getattr(chunk, "choices", None):
continue
if len(chunk.choices) == 0 or getattr(chunk.choices[0], "delta", None) is None:
continue
delta = chunk.choices[0].delta
if getattr(delta, "content", None) is not None:
print(delta.content, end="")Follow the steps below to download and run the NVIDIA NIM inference microservice for this model on your infrastructure of choice.
$ docker login nvcr.io
Username: $oauthtoken
Password: <PASTE_API_KEY_HERE>
Pull and run the NVIDIA NIM with the command below. This will download the optimized model for your infrastructure.
export NGC_API_KEY=<PASTE_API_KEY_HERE>
export LOCAL_NIM_CACHE=~/.cache/nim
mkdir -p "$LOCAL_NIM_CACHE"
chmod -R a+w "$LOCAL_NIM_CACHE"
docker run -it --rm \
--gpus all \
--shm-size=16GB \
-e NGC_API_KEY \
-v "$LOCAL_NIM_CACHE:/opt/nim/.cache" \
-p 8000:8000 \
nvcr.io/nim/zai-org/glm-51:latest
You can now make a local API call using this curl command:
curl -X 'POST' \
'http://0.0.0.0:8000/v1/chat/completions' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"model": "z-ai/glm-5.1",
"messages": [{"role":"user", "content":"Which number is larger, 9.11 or 9.8?"}],
"max_tokens": 64
}'
For more details on getting started with this NIM, visit the NVIDIA NIM Docs.