OpenAI Python SDK with Meridian
Drop-in replacement — change base_url and your existing OpenAI Python code routes through Meridian with zero friction.
Install
pip install openaiQuick start
from openai import OpenAI
client = OpenAI(
api_key="nim_live_***",
base_url="https://meridian.getnimbus.net/api/v1"
)
resp = client.chat.completions.create(
model="azure-swc/gpt-4.1",
messages=[{"role": "user", "content": "hello"}]
)
print(resp.choices[0].message.content)Streaming
Set stream=True and iterate chunks — identical to native OpenAI behavior.
for chunk in client.chat.completions.create(
model="azure-swc/gpt-4.1",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True
):
print(chunk.choices[0].delta.content or "", end="", flush=True)Tool calls
Function calling works out of the box. Define tools, inspect tool_calls on the response, execute, and return results in a follow-up message.
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current temperature for a city",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string"}
},
"required": ["city"]
}
}
}]
resp = client.chat.completions.create(
model="azure-swc/gpt-4.1",
messages=[{"role": "user", "content": "What's the weather in London?"}],
tools=tools
)
tool_call = resp.choices[0].message.tool_calls[0]
print(tool_call.function.name, tool_call.function.arguments)Vision
Pass image URLs or base64-encoded images in the content array — same multimodal format.
resp = client.chat.completions.create(
model="azure-swc/gpt-4.1",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "Describe this image"},
{
"type": "image_url",
"image_url": {"url": "https://example.com/photo.jpg"}
}
]
}]
)
print(resp.choices[0].message.content)JSON mode
Guarantee structured output with response_format={"type": "json_object"}.
resp = client.chat.completions.create(
model="azure-swc/gpt-4.1",
messages=[{"role": "user", "content": "List three colors as JSON"}],
response_format={"type": "json_object"}
)
import json
data = json.loads(resp.choices[0].message.content)
print(data)