Skip to content

Python

Chat Completions

import requests
response = requests.post(
"https://ghostmind.optdmsa.com/v1/chat/completions",
headers={
"Authorization": "Bearer sk-gm-...",
"Content-Type": "application/json",
},
json={
"model": "auto",
"messages": [{"role": "user", "content": "Hello!"}],
},
)
print(response.json())

Streaming

import requests
response = requests.post(
"https://ghostmind.optdmsa.com/v1/chat/completions",
headers={
"Authorization": "Bearer sk-gm-...",
"Content-Type": "application/json",
},
json={
"model": "auto",
"stream": True,
"messages": [{"role": "user", "content": "Hello!"}],
},
stream=True,
)
for line in response.iter_lines():
if line:
print(line.decode())

Next Steps