Неден бастау керек?
API таңдау · Бағалар · Балансты тексеру
API кілтін алыңыз
«API кілтін алыңыз» бөліміЖеке кабинеттегі API қойындысын ашып, кілт жасаңыз. Кілтті жеке профильде де, бизнес-профильде де жасауға болады.
Кілтті жасағанда немесе өңдегенде, оған рұқсат етілген модельдерді таңдауға болады. Сонда каталогта сол кілтпен пайдалануға болатын модельдер ғана көрінеді. Басқа модельге сұрау жіберсеңіз, API HTTP 403 мәртебесін және model_not_allowed кодын қайтарады (Creative Lab API үшін code: 29, транскрипция үшін code: 19). Бұл шектеу бүкіл ашық API-ге, соның ішінде мәтінді дыбыстауға (tts2), бет ауыстыруға (faceswap) және транскрипцияға (whisper) қолданылады. Бұл модельдерді де сол тізімнен таңдауға болады. Тізімді бос қалдырсаңыз, кілтке барлық модель қолжетімді болады.
Алғашқы сұрауды жіберіңіз
«Алғашқы сұрауды жіберіңіз» бөліміТіл моделінен жауап алу үшін chat/completions әдісіне API кілтімен сұрау жіберіңіз. Кілтіңізге қолжетімді модельдердің идентификаторларын модельдер каталогынан қараңыз.
https://gptunnel.ru/v1/chat/completionsСұрау тақырыптары
| Параметр | Түрі | Беру міндетті ме? | Сипаттама |
|---|---|---|---|
Authorization | string | Міндетті | API кілті. |
Сұрау денесі
| Параметр | Түрі | Беру міндетті ме? | Сипаттама |
|---|---|---|---|
model | string | Міндетті | GET /v1/models қайтаратын модель идентификаторы. Мысалы, gpt-6-luna. |
messages | array | Міндетті | Әңгіме контексін құрайтын хабарламалар. |
max_completion_tokens | number | Міндетті емес | Жауаптағы токендердің ең көп саны. Мысалда 128 деп көрсетілген. |
useWalletBalance | boolean | Міндетті емес | Бизнес-кілтпен жіберілген сұрауды жеке шоттан төлеу үшін true мәнін беріңіз. |
Шотты таңдау туралы толығырақ балансты тексеру нұсқаулығында жазылған.
Сұрау мысалы
«Сұрау мысалы» бөліміAPI кілтін GPTUNNEL_API_KEY орта айнымалысына жазып, төлем жасалатын шотты таңдаңыз. Модельге сұрау жіберу ақылы. Төлем сомасын жауаптың usage.total_cost өрісінен қараңыз.
import jsonimport osfrom urllib.request import Request, urlopen
body = { 'model': "gpt-6-luna", 'messages': [{"role":"user","content":"2 + 2 қанша болады? Жауабын цифрмен жаз."}], 'max_completion_tokens': 128,}request = Request( 'https://gptunnel.ru/v1/chat/completions', method='POST', headers={ 'Authorization': os.environ['GPTUNNEL_API_KEY'], 'Content-Type': 'application/json', }, data=json.dumps(body).encode('utf-8'),)with urlopen(request, timeout=30) as response: print(json.load(response)['choices'][0]['message']['content'])curl --fail-with-body --silent --show-error \ --url 'https://gptunnel.ru/v1/chat/completions' \ --header "Authorization: ${GPTUNNEL_API_KEY:?GPTUNNEL_API_KEY мәнін орнатыңыз}" \ --json '{ "model": "gpt-6-luna", "messages": [ { "role": "user", "content": "2 + 2 қанша болады? Жауабын цифрмен жаз." } ], "max_completion_tokens": 128}'const apiKey = process.env.GPTUNNEL_API_KEYif (!apiKey) throw new Error("GPTUNNEL_API_KEY мәнін орнатыңыз")
const response = await fetch('https://gptunnel.ru/v1/chat/completions', { method: 'POST', headers: { Authorization: apiKey, 'Content-Type': 'application/json', }, body: JSON.stringify({ "model": "gpt-6-luna", "messages": [ { "role": "user", "content": "2 + 2 қанша болады? Жауабын цифрмен жаз." } ], "max_completion_tokens": 128}),})
if (!response.ok) throw new Error(await response.text())console.log((await response.json()).choices[0].message.content)import jsonimport osfrom urllib.request import Request, urlopen
body = { 'model': "gpt-6-luna", 'messages': [{"role":"user","content":"2 + 2 қанша болады? Жауабын цифрмен жаз."}], 'max_completion_tokens': 128, 'useWalletBalance': True,}request = Request( 'https://gptunnel.ru/v1/chat/completions', method='POST', headers={ 'Authorization': os.environ['GPTUNNEL_API_KEY'], 'Content-Type': 'application/json', }, data=json.dumps(body).encode('utf-8'),)with urlopen(request, timeout=30) as response: print(json.load(response)['choices'][0]['message']['content'])curl --fail-with-body --silent --show-error \ --url 'https://gptunnel.ru/v1/chat/completions' \ --header "Authorization: ${GPTUNNEL_API_KEY:?GPTUNNEL_API_KEY мәнін орнатыңыз}" \ --json '{ "model": "gpt-6-luna", "messages": [ { "role": "user", "content": "2 + 2 қанша болады? Жауабын цифрмен жаз." } ], "max_completion_tokens": 128, "useWalletBalance": true}'const apiKey = process.env.GPTUNNEL_API_KEYif (!apiKey) throw new Error("GPTUNNEL_API_KEY мәнін орнатыңыз")
const response = await fetch('https://gptunnel.ru/v1/chat/completions', { method: 'POST', headers: { Authorization: apiKey, 'Content-Type': 'application/json', }, body: JSON.stringify({ "model": "gpt-6-luna", "messages": [ { "role": "user", "content": "2 + 2 қанша болады? Жауабын цифрмен жаз." } ], "max_completion_tokens": 128, "useWalletBalance": true}),})
if (!response.ok) throw new Error(await response.text())console.log((await response.json()).choices[0].message.content)Жауап үзіндісі
«Жауап үзіндісі» бөліміАлғашқы жауаптың мәтіні choices[0].message.content өрісінде келеді. Сұрау қабылданбаса, API қателерін анықтау нұсқаулығын қараңыз.
{ "model": "gpt-6-luna", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "4" }, "finish_reason": "stop" } ]}