SDK 示例
cURL Example
Using cURL to call the API
Basic Request
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!"}
]
}'With System Prompt
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": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is artificial intelligence?"}
]
}'With Parameters
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": "Write a poem"}
],
"temperature": 0.8,
"max_tokens": 500
}'Streaming Output
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": "Tell a story"}
],
"stream": true
}'Streaming response format:
data: {"id":"chatcmpl-xxx","choices":[{"delta":{"content":"From"}}]}
data: {"id":"chatcmpl-xxx","choices":[{"delta":{"content":"the"}}]}
data: [DONE]Get Model List
curl https://api.smai.ai/v1/models \
-H "Authorization: Bearer sk-your-api-key"Responses API (Inference Model)
curl https://api.smai.ai/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-api-key" \
-d '{
"model": "o3-pro",
"input": "Prove the Pythagorean theorem",
"reasoning": {
"effort": "high"
}
}'Using Environment Variables
For security, it is recommended to store the API Key in environment variables:
# Set environment variable
export SMAI_API_KEY="sk-your-api-key"
# Use environment variable
curl https://api.smai.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $SMAI_API_KEY" \
-d '{
"model": "gpt-4.1",
"messages": [{"role": "user", "content": "Hello!"}]
}'Save Response to File
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!"}]
}' \
-o response.jsonFormat Output
Use jq to format JSON output:
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!"}]
}' | jq '.choices[0].message.content'