လျင်မြန်စွာ စတင်ရန်
ပထမဆုံး request ကို ပြုလုပ်ပါ- သင့် key ကိုရယူ၊ message တစ်ခုပို့ပြီး ပြန်ကြားချက်ကို ဖတ်ပါ။ API သည် OpenAI နှင့် Anthropic format များကို ပြောဆိုသဖြင့် သင်သုံးနေပြီးသား SDK ၏ base URL နှင့် key ကို ပြောင်းပြီးနောက် အလုပ်လုပ်သည်။
1. သင့် key ကို ရယူပါ
account တိုင်းတွင် API key တစ်ခုရှိသည်။ Sign in ဝင်ပြီး Keys & usage ကိုဖွင့်ကာ ကူးယူပါ။ key သည် endpoint တိုင်းနှင့် model တိုင်းတွင် အလုပ်လုပ်သည်။ Keys & usage
2. သင့် client ကို API သို့ ညွှန်ပါ
Endpoint အားလုံးသည် base URL တစ်ခုအောက်တွင် ရှိသည်။ OpenAI SDK က အဆုံးတွင် /v1 ပါသည့်ပုံစံကို လက်ခံပြီး Anthropic SDK က /v1/messages ကို ကိုယ်တိုင်ထည့်သဖြင့် ၎င်းမပါသည့်ပုံစံကို လက်ခံသည်။
| Client | Base URL |
|---|---|
| OpenAI SDK များနှင့် OpenAI နှင့် ကိုက်ညီသော client များ | https://api.shannon-ai.com/v1 |
| Anthropic SDK များ | https://api.shannon-ai.com |
စာသားထုတ်လုပ်သော endpoint သုံးခုရှိသည်။ ၎င်းတို့သည် တူညီသော model များသို့ ရောက်သည်၊ သင့် code သုံးနေပြီးသား format ပါသည့်တစ်ခုကို ရွေးပါ။
| Endpoint | Format |
|---|---|
POST /v1/chat/completions | OpenAI Chat Completions |
POST /v1/messages | Anthropic Messages |
POST /v1/responses | OpenAI Responses |
3. ပထမဆုံး request ကို ပို့ပါ
Chat Completions endpoint ရှိ shannon-3 သို့ user message တစ်ခု ပို့ပါ။ YOUR_API_KEY ကို သင့် key ဖြင့် အစားထိုးပါ။
POST https://api.shannon-ai.com/v1/chat/completions
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.shannon-ai.com/v1"
)
response = client.chat.completions.create(
model="shannon-3",
messages=[
{"role": "user", "content": "Hello, Shannon!"}
],
max_tokens=1024
)
print(response.choices[0].message.content) import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'YOUR_API_KEY',
baseURL: 'https://api.shannon-ai.com/v1'
});
const response = await client.chat.completions.create({
model: 'shannon-3',
messages: [
{ role: 'user', content: 'Hello, Shannon!' }
],
max_tokens: 1024
});
console.log(response.choices[0].message.content); package main
import (
"context"
"fmt"
openai "github.com/sashabaranov/go-openai"
)
func main() {
config := openai.DefaultConfig("YOUR_API_KEY")
config.BaseURL = "https://api.shannon-ai.com/v1"
client := openai.NewClientWithConfig(config)
resp, err := client.CreateChatCompletion(
context.Background(),
openai.ChatCompletionRequest{
Model: "shannon-3",
Messages: []openai.ChatCompletionMessage{
{Role: "user", Content: "Hello, Shannon!"},
},
MaxTokens: 1024,
},
)
if err != nil {
panic(err)
}
fmt.Println(resp.Choices[0].Message.Content)
} curl -X POST "https://api.shannon-ai.com/v1/chat/completions" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "shannon-3",
"messages": [
{"role": "user", "content": "Hello, Shannon!"}
],
"max_tokens": 1024
}' | Field | Type | Default | ဖော်ပြချက် |
|---|---|---|---|
model | string | ဖြေကြားမည့် model ၏ id။ id များကို Models & pricing တွင် စာရင်းပြထားသည်။ | |
messages | array | ယခုအထိ စကားပြောဆိုမှု- role နှင့် content ပါသော object များ။ နောက်ဆုံး user message သည် prompt ဖြစ်သည်။ လိုအပ်သည်။ | |
max_tokens | integer | 4096 | request ၏ output budget၊ 1 မှ 65,536 အထိ။ request သည် ဤပမာဏကို သင့်လက်ကျန်ငွေမှ ဖယ်ထားပြီး အမှန်တကယ်သုံးခဲ့သည့်အတွက် ကျသင့်ငွေတောင်းသည်။ |
stream | boolean | false | true သည် အဖြေကို ရေးနေစဉ် အပိုင်းလိုက် ပို့စေသည်။ |
request body သည် JSON ဖြစ်ပြီး header Content-Type: application/json လိုအပ်သည်။ field အပြည့်အစုံစာရင်းကို endpoint စာမျက်နှာတွင် ဖော်ပြထားသည်။ Chat Completions
ပြန်ကြားချက်
stream မပါသော call သည် အဖြေပြီးမြောက်သောအခါ JSON object တစ်ခု ပြန်ပေးသည်။ အောက်ပါစာသားများနှင့် နံပါတ်များသည် ဥပမာများ ဖြစ်သည်။
{
"id": "chatcmpl-9b2f6c1e4a7d4f0f8a3c5d2e1b6a7c90",
"object": "chat.completion",
"created": 1791590400,
"model": "shannon-3",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! What would you like to work on?",
"reasoning_content": "A greeting. A short, friendly reply fits."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 1386,
"completion_tokens": 74,
"total_tokens": 1460
}
} | Field | Type | ဖော်ပြချက် |
|---|---|---|
id | string | chatcmpl- နောက်တွင် hexadecimal စာလုံး 32 လုံး။ |
object | string | အမြဲတမ်း chat.completion။ |
created | integer | ပြန်ကြားချိန်၊ Unix စက္ကန့်ဖြင့်။ |
model | string | ဖြေကြားခဲ့သော model ၏ ထုတ်ပြန်ထားသော id၊ သင် alias သို့မဟုတ် အခြားစာလုံးပေါင်း ပို့ခဲ့သည့်အခါတွင်ပင်။ |
choices | array | entry တစ်ခုတည်း အမြဲရှိပြီး index 0 ဖြစ်သည်။ |
choices[0].message.role | string | အမြဲတမ်း assistant။ |
choices[0].message.content | string | null | အဖြေ။ ပြန်ကြားချက်တွင် tool_calls ပါလျှင် ၎င်းသည် null ဖြစ်နိုင်သည်။ |
choices[0].message.reasoning_content | string | null | model ၏ အဖြေမတိုင်မီ reasoning၊ မရှိလျှင် null။ |
choices[0].message.tool_calls | array | model က သင်ကြေညာထားသော tools တစ်ခုခုကို ခေါ်မှသာ ပါသည်။ |
choices[0].finish_reason | string | အဖြေတစ်ခုအတွက် stop၊ model က tool တစ်ခုခေါ်လျှင် tool_calls။ |
usage.prompt_tokens | integer | ဤအဖြေအတွက် model ဖတ်ခဲ့သော tokens။ shannon-2-* နှင့် Shannon 3 မိသားစုတွင် ၎င်းသည် သင်ပို့ခဲ့သော စာသားထက် ပိုများနိုင်သည်။ |
usage.completion_tokens | integer | model က ရေးသားခဲ့သော token အရေအတွက်။ |
usage.total_tokens | integer | စုစုပေါင်း။ Shannon model ၏ ကျသင့်ငွေကို ဤနံပါတ်မှ တွက်ချက်သည်။ |
-
usageတွင် token ရေတွက်မှုများ ပါပြီး ငွေပမာဏ မပါပါ။ call က သင့်လက်ကျန်ငွေမှ နုတ်ယူသည့်ပမာဏကို Keys & usage တွင် request တစ်ခုချင်းစီအလိုက် ပြသည်၊ တွက်ချက်ပုံကို ကန့်သတ်ချက်များနှင့် လက်ကျန်ငွေ စာမျက်နှာတွင် ဖော်ပြထားသည်။ ကန့်သတ်ချက်များနှင့် လက်ကျန်ငွေ - ပြန်ကြားချက်တိုင်း၊ အမှားနှင့် stream အပါအဝင်၊ တွင် header
x-request-idပါသည်။ သင့် request တွင်x-request-idheader ပါလျှင် ၎င်း၏ တန်ဖိုး ပြန်လာသည်၊ မပါလျှင် တန်ဖိုးသည် hexadecimal စာလုံး 12 လုံးဖြစ်သည်။ ၎င်းကို သင့် log များတွင် သိမ်းထားပါ- ၎င်းသည် ဤ request တစ်ခုတည်းကို အမည်ပေးသည်။
တူညီသော call ကို stream အဖြစ်
အဖြေကို ရေးနေစဉ် ဖတ်ရန် stream ကို true ဟု သတ်မှတ်ပါ။ request ၏ အခြားအရာအားလုံး တူညီစွာ ကျန်ရှိသည်။
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.shannon-ai.com/v1"
)
stream = client.chat.completions.create(
model="shannon-3",
messages=[
{"role": "user", "content": "Hello, Shannon!"}
],
max_tokens=1024,
stream=True
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True) import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'YOUR_API_KEY',
baseURL: 'https://api.shannon-ai.com/v1'
});
const stream = await client.chat.completions.create({
model: 'shannon-3',
messages: [
{ role: 'user', content: 'Hello, Shannon!' }
],
max_tokens: 1024,
stream: true
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
} curl -N -X POST "https://api.shannon-ai.com/v1/chat/completions" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "shannon-3",
"messages": [
{"role": "user", "content": "Hello, Shannon!"}
],
"max_tokens": 1024,
"stream": true
}' stream ၏ frame တစ်ခုစီသည် data: ဖြင့်စပြီး JSON object တစ်ခု ပါသော စာကြောင်းတစ်ကြောင်း ဖြစ်သည်။ စာကြောင်းများစွာဖြင့် ပုံနှိပ်ထားသော frame တစ်ခု-
{
"id": "chatcmpl-9b2f6c1e4a7d4f0f8a3c5d2e1b6a7c90",
"object": "chat.completion.chunk",
"created": 1791590400,
"model": "shannon-3",
"choices": [
{
"index": 0,
"delta": {
"content": "Hello! "
},
"finish_reason": null
}
]
} | Frames, အစီအစဉ်အတိုင်း | delta | finish_reason |
|---|---|---|
| model သည် reasoning လုပ်နေစဉ်။ frame သုညခု သို့မဟုတ် ပိုများသည်။ | {"reasoning_content": "…"} | null |
| အဖြေကို အပိုင်းလိုက်။ frame သုညခု သို့မဟုတ် ပိုများသည်။ | {"content": "…"} | null |
နောက်ဆုံး JSON frame။ ၎င်းတွင် usage လည်း ပါသည်၊ တောင်းဆိုရန် မလိုပါ။ | {} | "stop" |
stream ၏ အဆုံး- data: [DONE] စာကြောင်း။ |
- ပြန်ကြားချက်တွင် status
200နှင့်content-type: text/event-streamပါသည်။ frame တိုင်းသည်data: <json>စာကြောင်းဖြစ်ပြီး ၎င်းနောက်တွင် စာကြောင်းလွတ်တစ်ကြောင်း လိုက်သည်။ : pingစာကြောင်းသည် 15 စက္ကန့်တိုင်း ရောက်လာသည်။ ၎င်းသည် ချိတ်ဆက်မှုကို ဖွင့်ထားစေသော comment ဖြစ်ပြီး SSE client များက ကျော်သွားသည်။- stream ပွင့်ပြီးနောက် ဖြစ်ပေါ်သော ကျရှုံးမှုသည်
data: {"error": {…}}frame အဖြစ် ရောက်လာသည်။ status သည်200အတိုင်း ရှိနေသဖြင့် frame များကို စစ်ဆေးပါ။
call မအောင်မြင်လျှင်
အမှားသည် type နှင့် message ပါသော error ပါဝင်သည့် JSON object ဖြစ်သည်။ ဤအရာများသည် ပထမဆုံး call က အများဆုံးကြုံရသော ပြန်ကြားချက်များ ဖြစ်သည်။
| Status | Type | မက်ဆေ့ချ် | အဓိပ္ပာယ် |
|---|---|---|---|
401 | authentication_error | Missing authentication | API သို့ key မရောက်ခဲ့ပါ။ Authorization: Bearer နောက်တွင် သင့် key ကို ထည့်ပို့ပါ။ |
401 | authentication_error | Invalid API key | key သည် account တစ်ခု၏ လက်ရှိ key မဟုတ်ပါ။ Keys & usage မှ ထပ်မံကူးယူပါ။ |
400 | invalid_request_error | unknown model: <id> | model သည် ထုတ်ပြန်ထားသော id မဟုတ်ပါ။ Models & pricing ရှိ id တစ်ခုကို သုံးပါ။ |
422 | invalid_request_error | Failed to deserialize the JSON body into the target type… | field တစ်ခု၏ JSON type မှားနေသည်၊ သို့မဟုတ် messages မပါပါ။ |
429 | rate_limit_error | Quota exceeded. Upgrade your plan at shannon-ai.com/plan | request ၏ output budget သည် သင့်လက်ကျန်ငွေထဲ မဆန့်ပါ။ |
နောက်ထပ် ဘယ်ကိုသွားမလဲ
- Model များနှင့် ဈေးနှုန်း — Model တစ်ခုကို ရွေးပါ- id များ၊ context window များနှင့် ဈေးနှုန်းများ။
- Chat Completions — သင်ခေါ်ခဲ့သော endpoint ၏ request field များ၊ ပြန်ကြားချက် field များနှင့် stream event များ အားလုံး။
- စตรีမင်း — stream ၏ frame များ၊ keep-alive စာကြောင်းများနှင့် stream အတွင်းရှိ အမှားများ။
- လုပ်ဆောင်ချက် ခေါ်ဆိုမှု — model ကို သင့် function များ ခေါ်စေပါ။
- ကန့်သတ်ချက်များနှင့် လက်ကျန်ငွေ — request တစ်ခုက ဖယ်ထားသည့်အရာနှင့် ကုန်ကျစရိတ်၊ request မည်မျှ ပို့နိုင်သည်ကို ဖော်ပြသည်။
- API Playground — သင့် key ဖြင့် browser တွင် request များကို စမ်းသပ်ပါ။