SDK 示例
SDK Overview
Usage examples for various language SDKs
Supported Languages
smai.ai is compatible with the OpenAI API, and you can use any SDK that supports OpenAI.
Python
Use the OpenAI Python SDK
JavaScript
Use the OpenAI Node.js SDK
cURL
Directly call the HTTP API
Streaming Response
Implement streaming output
Quick Start
Python
from openai import OpenAI
client = OpenAI(
api_key="sk-your-api-key",
base_url="https://api.smai.ai/v1"
)
response = client.chat.completions.create(
model="gpt-4.1",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)JavaScript
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'sk-your-api-key',
baseURL: 'https://api.smai.ai/v1',
});
const response = await client.chat.completions.create({
model: 'gpt-4.1',
messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(response.choices[0].message.content);cURL
curl https://api.smai.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-api-key" \
-d '{"model": "gpt-4.1", "messages": [{"role": "user", "content": "Hello!"}]}'Configuration Highlights
All SDK configurations require just two parameters:
| Parameter | Value |
|---|---|
| API Key | sk-your-api-key |
| Base URL | https://api.smai.ai/v1 |
