Getting started
Choose an API · Pricing · Check your balance
Get an API key
Section titled “Get an API key”Open the API tab in your GPTunneL account and create a key. Both personal and business profiles support API keys.
When you create or edit a key, you can select the models it may use. Model catalogs then show only the selected models. A request to any other model returns HTTP 403 with model_not_allowed (Creative Lab returns code: 29, transcription returns code: 19). The restriction applies across the public API, including text to speech (tts2), face swapping (faceswap) and transcription (whisper). You can select these models in the same list. Leave the list empty to allow all models.
Send your first request
Section titled “Send your first request”Send an authenticated request to chat/completions to get a response from a language model. Find the model IDs available to your key in the model catalog.
https://gptunnel.ru/v1/chat/completionsRequest headers
| Parameter | Type | Required? | Description |
|---|---|---|---|
Authorization | string | Required | Your API key. |
Request body
| Parameter | Type | Required? | Description |
|---|---|---|---|
model | string | Required | Model ID from GET /v1/models, such as gpt-6-luna. |
messages | array | Required | Messages that provide the conversation context. |
max_completion_tokens | number | Optional | Maximum number of response tokens. The example uses 128. |
useWalletBalance | boolean | Optional | Set to true to use your personal balance with a business key. |
See Check your balance for more on choosing a balance.
Example request
Section titled “Example request”Set the GPTUNNEL_API_KEY environment variable and choose which balance to use. The model request incurs a charge. Check usage.total_cost in your response for the amount.
import jsonimport osfrom urllib.request import Request, urlopen
body = { 'model': "gpt-6-luna", 'messages': [{"role":"user","content":"What's 2 + 2? Answer with a digit."}], '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:?Set GPTUNNEL_API_KEY}" \ --json '{ "model": "gpt-6-luna", "messages": [ { "role": "user", "content": "What'\''s 2 + 2? Answer with a digit." } ], "max_completion_tokens": 128}'const apiKey = process.env.GPTUNNEL_API_KEYif (!apiKey) throw new Error("Set 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": "What's 2 + 2? Answer with a digit." } ], "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":"What's 2 + 2? Answer with a digit."}], '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:?Set GPTUNNEL_API_KEY}" \ --json '{ "model": "gpt-6-luna", "messages": [ { "role": "user", "content": "What'\''s 2 + 2? Answer with a digit." } ], "max_completion_tokens": 128, "useWalletBalance": true}'const apiKey = process.env.GPTUNNEL_API_KEYif (!apiKey) throw new Error("Set 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": "What's 2 + 2? Answer with a digit." } ], "max_completion_tokens": 128, "useWalletBalance": true}),})
if (!response.ok) throw new Error(await response.text())console.log((await response.json()).choices[0].message.content)Response excerpt
Section titled “Response excerpt”Read choices[0].message.content for the text of the first reply. If your request is rejected, see Troubleshoot API errors.
{ "model": "gpt-6-luna", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "4" }, "finish_reason": "stop" } ]}