Last verified: July 20, 2026
You can call a current GPT model from Python through LumeAPI with the official OpenAI client. Set base_url to https://api.lumeapi.site/v1, load a LumeAPI key, and use an exact GPT model ID from the live catalog. The same client can later call Claude or Gemini by changing only the model ID, while the account, key, wallet, and request logs remain in one place.
This guide starts with a minimal GPT request, then adds streaming, bounded error handling, and a reproducible cost calculation. It is intentionally GPT-specific; for a provider-neutral setup, use the OpenAI-compatible Python guide.
Choose a GPT model before writing code
LumeAPI listed these GPT text models on July 20, 2026. Prices are USD per 1 million input/output tokens. Confirm the live GPT API page before deployment because availability and rates can change.
| Model ID | LumeAPI input / output | Page reference input / output | Difference shown on page | Practical starting point |
|---|---|---|---|---|
gpt-5.4-mini | $0.225 / $1.35 | $0.75 / $4.50 | 70% lower | High-volume chat, classification, short generation |
gpt-5.4 | $0.75 / $4.50 | $2.50 / $15.00 | 70% lower | General production work |
gpt-5.6-terra | $0.75 / $4.50 | $2.50 / $15.00 | 70% lower | Cost/performance GPT-5.6 workloads |
gpt-5.6-sol | $1.50 / $9.00 | $5.00 / $30.00 | 70% lower | Demanding coding, reasoning, and agent tasks |
Start with gpt-5.4-mini when request cost matters and move to a larger model only when your own evaluation shows that it improves completed-task quality. A model with a higher token price can still be economical if it needs fewer retries, but that must be measured on your workload.
Install the Python client
Use Python 3.9 or newer and install the current OpenAI package:
python -m pip install --upgrade openaiKeep the key outside source code. On macOS or Linux:
export LUMEAPI_KEY='your-lumeapi-key'In PowerShell:
$env:LUMEAPI_KEY = 'your-lumeapi-key'Use a secret manager in production. Never ship the key in browser JavaScript, a mobile bundle, a public repository, or a screenshot.
Send a minimal GPT request
Create gpt_example.py:
import os
from openai import OpenAI
api_key = os.getenv('LUMEAPI_KEY')
if not api_key:
raise RuntimeError('Set LUMEAPI_KEY before running this script.')
client = OpenAI(
api_key=api_key,
base_url='https://api.lumeapi.site/v1',
)
response = client.chat.completions.create(
model='gpt-5.4-mini',
messages=[
{
'role': 'system',
'content': 'Answer clearly and use no more than three sentences.',
},
{
'role': 'user',
'content': 'What should an API health check verify?',
},
],
)
print(response.choices[0].message.content)
print({
'model': response.model,
'input_tokens': response.usage.prompt_tokens if response.usage else None,
'output_tokens': response.usage.completion_tokens if response.usage else None,
})Run it:
python gpt_example.pyThe client sends the request to https://api.lumeapi.site/v1/chat/completions. The generated text is in response.choices[0].message.content. Usage fields may be used for application-side cost estimates when the response contains them. LumeAPI also provides per-call logs where model, tokens, cost, and latency can be reviewed after a request.
Calculate the request cost
For a text model billed separately for input and output, use:
cost = input_tokens / 1,000,000 × input_rate
+ output_tokens / 1,000,000 × output_rateSuppose a gpt-5.4-mini call uses 1,500 input tokens and 500 output tokens. At the LumeAPI rates verified above:
1,500 / 1,000,000 × $0.225 = $0.0003375
500 / 1,000,000 × $1.35 = $0.0006750
total $0.0010125Using the reference rates displayed on the same page, the calculation is $0.003375. The difference is 70% for this model and rate pair. This example does not mean every model on the platform has a 70% discount; use the current model page for the exact comparison and date.
A small helper keeps the arithmetic explicit:
def estimate_cost(
input_tokens: int,
output_tokens: int,
input_rate: float = 0.225,
output_rate: float = 1.35,
) -> float:
return (
input_tokens / 1_000_000 * input_rate
+ output_tokens / 1_000_000 * output_rate
)
print(f'${estimate_cost(1500, 500):.7f}')Treat local estimates as forecasts. Use the wallet and request logs as the billing record.
Stream GPT output
Streaming improves perceived response time in a chat or coding interface:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ['LUMEAPI_KEY'],
base_url='https://api.lumeapi.site/v1',
)
stream = client.chat.completions.create(
model=os.getenv('LUMEAPI_MODEL', 'gpt-5.4-mini'),
messages=[
{'role': 'user', 'content': 'Give me five API monitoring checks.'}
],
stream=True,
)
for chunk in stream:
if not chunk.choices:
continue
text = chunk.choices[0].delta.content
if text:
print(text, end='', flush=True)
print()A stream event may not contain text, so check both choices and delta.content. In a web application, also stop or cancel upstream work when the client disconnects; otherwise an abandoned request can continue consuming budget.
Add production error handling
Configure a finite timeout and keep retries bounded:
import os
import openai
from openai import OpenAI
client = OpenAI(
api_key=os.environ['LUMEAPI_KEY'],
base_url='https://api.lumeapi.site/v1',
timeout=30.0,
max_retries=2,
)
def ask_gpt(question: str) -> str:
try:
response = client.chat.completions.create(
model=os.getenv('LUMEAPI_MODEL', 'gpt-5.4-mini'),
messages=[{'role': 'user', 'content': question}],
)
return response.choices[0].message.content or ''
except openai.AuthenticationError as exc:
raise RuntimeError('Check the LumeAPI key and base URL.') from exc
except openai.RateLimitError as exc:
raise RuntimeError('Rate limited; retry later with bounded backoff.') from exc
except openai.APITimeoutError as exc:
raise RuntimeError('The GPT request exceeded the timeout.') from exc
except openai.APIStatusError as exc:
raise RuntimeError(
f'API returned HTTP {exc.status_code}; request_id={exc.request_id}'
) from excDo not retry 401 authentication failures or an invalid model name unchanged. For 429 and selected 5xx failures, use exponential backoff with jitter and cap the total time spent retrying. If the request can trigger an external side effect, add idempotency at the application layer before retrying.
Common GPT Python problems
The request goes to api.openai.com
Confirm that the exact client instance sending the request has base_url='https://api.lumeapi.site/v1'. Large applications often construct more than one SDK client.
The API returns model not found
Copy the model ID from the live catalog or GPT-5.4 mini documentation. A display name is not always an API ID.
The API returns 401
Check that the running Python process received LUMEAPI_KEY; a variable in your terminal may not exist in an IDE, container, worker, or deployment environment. Follow the LLM API 401 checklist without printing the key.
Cost is higher than expected
Inspect both input and output tokens, repeated context, retries, and model selection. Output tokens may cost more than input tokens. Query the LumeAPI call log for the model, tokens, cost, and latency of the exact request instead of estimating from message length.
Why use LumeAPI for this GPT workflow?
This integration keeps the familiar OpenAI-shaped Chat Completions request while exposing current GPT model IDs through one LumeAPI key and USD wallet. The same client can call available Claude and Gemini text models later by changing the model ID. The same account also covers listed image and video models, although those modalities can use different parameters or asynchronous job flows.
The product advantage should be verified in the workflow: copy model IDs from the catalog, compare dated prices, and inspect request logs. OpenAI compatibility does not imply that every provider-native endpoint or beta feature is identical. Test the exact streaming, tools, structured output, and error behavior your application needs.
Production checklist
- Keep the API key server-side.
- Use the exact current model ID.
- Store the base URL and model in centralized configuration.
- Set timeouts and bounded retries.
- Log the selected model, status, request ID, latency, and usage without exposing prompts or secrets.
- Compare cost per completed task, not only cost per token.
- Test a larger GPT model only when your evaluation shows a benefit.
- Review the GPT API hub, AI API pricing, and OpenAI-compatible API before production rollout.
Sources and verification
- LumeAPI GPT API and GPT-5.4 mini docs for the current model IDs, endpoint, and rates used on July 20, 2026.
- Official OpenAI Python library for client initialization, Chat Completions, streaming, timeouts, retries, usage, and API error classes.
The code blocks were parsed with Python on July 20, 2026. A customer inference key was not used for a billable end-to-end request, so this article does not claim observed output quality or latency.