Python SDK
Python SDK
The Global API is fully OpenAI-compatible, so use the official OpenAI Python SDK.
Installation
pip install openai
Full Example
from openai import OpenAI
client = OpenAI(
api_key="ga_xxxxxxxxxxxx",
base_url="https://global-apis.com/v1"
)
Chat
chat = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain REST APIs in simple terms."}
],
temperature=0.7,
max_tokens=500
)
print(chat.choices[0].message.content)
Streaming
stream = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "Count to 5"}],
stream=True
)
for chunk in stream:
print(chunk.choices[0].delta.content, end="")