Skip to content

Getting started

Choose an API · Pricing · Check your balance

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 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.

POSThttps://gptunnel.ru/v1/chat/completions

Request headers

ParameterTypeRequired?Description
AuthorizationstringRequiredYour API key.

Request body

ParameterTypeRequired?Description
modelstringRequiredModel ID from GET /v1/models, such as gpt-6-luna.
messagesarrayRequiredMessages that provide the conversation context.
max_completion_tokensnumberOptionalMaximum number of response tokens. The example uses 128.
useWalletBalancebooleanOptionalSet to true to use your personal balance with a business key.

See Check your balance for more on choosing a balance.

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 json
import os
from 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'])

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"
}
]
}