Last verified: July 20, 2026
An existing OpenAI Python application can test Gemini through LumeAPI by changing three client settings: the API key, the base URL, and the model ID. Keep the Chat Completions message and response shape for common text requests, then run regression tests for streaming, tools, structured data, errors, latency, and cost before moving production traffic.
This is a migration guide, not a promise that Gemini and OpenAI models behave identically. The goal is a reversible model change behind one LumeAPI integration, key, wallet, and request-log workflow.
The three-setting migration
A simplified OpenAI client may start like this:
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
response = client.chat.completions.create(
model=os.environ['OPENAI_MODEL'],
messages=[{'role': 'user', 'content': 'Summarize this incident report.'}],
)
print(response.choices[0].message.content)The LumeAPI Gemini version changes configuration, not the application's basic messages and response access:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ['LUMEAPI_KEY'],
base_url='https://api.lumeapi.site/v1',
)
response = client.chat.completions.create(
model='gemini-3.5-flash',
messages=[{'role': 'user', 'content': 'Summarize this incident report.'}],
)
print(response.choices[0].message.content)The effective diff is:
-client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
+client = OpenAI(
+ api_key=os.environ['LUMEAPI_KEY'],
+ base_url='https://api.lumeapi.site/v1',
+)
response = client.chat.completions.create(
- model=os.environ['OPENAI_MODEL'],
+ model='gemini-3.5-flash',
messages=messages,
)Do not replace environment variables globally until this exact client path passes tests. Large applications may create separate clients in web processes, workers, scheduled jobs, and evaluation tools.
Why use LumeAPI instead of another separate integration?
The product advantage is consolidation. One LumeAPI key and compatible endpoint can access available Gemini, GPT, and Claude text models. The same USD wallet funds those models, and per-call logs let an operator query model, tokens, cost, and latency. The same account also covers listed image and video models, with their documented modality-specific parameters and asynchronous job flows.
This does not remove model differences. It reduces integration and billing duplication while leaving model choice, testing, and rollback under application control.
Map the Gemini model explicitly
Use a stable internal alias rather than scattering provider model names through business code:
import os
from openai import OpenAI
MODEL_ALIASES = {
'current': 'gpt-5.4-mini',
'gemini-fast': 'gemini-3.5-flash',
'gemini-economy': 'gemini-3-flash',
'gemini-pro': 'gemini-3.1-pro-preview',
}
client = OpenAI(
api_key=os.environ['LUMEAPI_KEY'],
base_url='https://api.lumeapi.site/v1',
timeout=30.0,
max_retries=2,
)
def selected_model() -> str:
alias = os.getenv('AI_MODEL_ALIAS', 'current')
try:
return MODEL_ALIASES[alias]
except KeyError as exc:
raise RuntimeError(f'Unknown AI_MODEL_ALIAS: {alias}') from excRollback becomes an alias change rather than a code rewrite. Keep the alias configuration versioned and auditable.
Compatibility test matrix
A 200 response proves only that one request was accepted. Use a test matrix that represents the application.
| Area | What can often stay the same | What must be retested |
|---|---|---|
| Basic chat | messages, model, common choices response | Prompt quality, refusals, output length |
| System instruction | Common system-message shape | Instruction priority and behavior |
| Streaming | stream=True and chunk iteration | Empty events, disconnects, usage, proxy buffering |
| Tools | OpenAI-shaped tool definitions when documented | Tool selection, argument schema, parallel calls, loops |
| Structured data | Application schema and validator | Supported parameters and schema adherence |
| Context | Application history manager | Actual model limits, truncation, long-input quality |
| Errors | HTTP status handling | Error body, request ID, retryability, upstream capacity |
| Usage and cost | Token accounting workflow | Field presence, billed rate, retries, cache behavior |
| Provider-native features | None assumed | Use only when LumeAPI explicitly documents support |
Google's own Gemini documentation currently describes an OpenAI-library compatibility path, but LumeAPI uses its own base URL, key, catalog, billing, and supported feature surface. Test the route actually used in production.
Build a small migration harness
Use the same prompts against the current and candidate model IDs:
import os
import time
from openai import OpenAI
client = OpenAI(
api_key=os.environ['LUMEAPI_KEY'],
base_url='https://api.lumeapi.site/v1',
timeout=45.0,
max_retries=1,
)
MODELS = ['gpt-5.4-mini', 'gemini-3.5-flash']
PROMPTS = [
'Classify this ticket as billing, technical, or account: login fails after reset.',
'Summarize this note in one sentence: deployment passed but cache refresh lagged.',
]
for model in MODELS:
for prompt in PROMPTS:
started = time.perf_counter()
response = client.chat.completions.create(
model=model,
messages=[{'role': 'user', 'content': prompt}],
)
elapsed_ms = round((time.perf_counter() - started) * 1000)
print({
'model': model,
'latency_ms': elapsed_ms,
'input_tokens': response.usage.prompt_tokens if response.usage else None,
'output_tokens': response.usage.completion_tokens if response.usage else None,
'text': response.choices[0].message.content,
})This harness is a starting point, not a benchmark. Add real, anonymized cases and score task success with a deterministic check or a documented human rubric. Query LumeAPI logs after the run to reconcile model, tokens, cost, and gateway latency.
Compare cost with the same workload
On July 20, 2026, LumeAPI listed Gemini 3.5 Flash at $0.90 input and $5.40 output per million tokens, about 40% below the $1.50 / $9.00 reference displayed on the page. Supported GPT models on the platform showed discounts as high as 70% against their page references.
Do not choose Gemini solely because of the percentage. Calculate cost per successful task, including output length, retries, validation failures, and any fallback. The Gemini Python guide contains a worked Flash cost example.
Stage the rollout
A safe sequence is:
- Run an offline test set through the current model and Gemini.
- Compare task success, format validity, latency, error rate, tokens, and cost.
- Route internal or test-account traffic to
gemini-3.5-flash. - Start a small production cohort behind
AI_MODEL_ALIAS. - Review LumeAPI call logs and application business metrics.
- Increase traffic only while guardrails remain acceptable.
- Roll back by changing the alias if quality, errors, latency, or cost regress.
Do not silently mix results from several models without logging the selected model. Support teams need to know which model produced a problematic response.
Streaming migration test
stream = client.chat.completions.create(
model='gemini-3.5-flash',
messages=[{'role': 'user', 'content': 'Write a short release note.'}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end='', flush=True)Verify first-token behavior, empty events, final output, proxy buffering, client cancellation, and what happens when the connection breaks. Do not assume a stream can resume from the last token unless the application implements a safe restart strategy.
Common migration failures
The request still reaches the old endpoint
Trace the hostname used by the real client instance. Do not log the full authorization header. Centralize client creation so workers and background jobs cannot retain a default endpoint.
A Gemini model ID returns 404
Copy the ID from the live Gemini catalog and confirm that the base URL includes /v1. Preview names can change.
Output parsing breaks
A new model may follow formatting instructions differently. Validate output against a schema and define a safe fallback; do not parse arbitrary prose with a fragile regular expression.
Tool retries repeat an action
Protect external writes with idempotency keys or durable state. A retry must not send a duplicate email, create a second order, or repeat a payment.
Cost looks lower but task success falls
Token price is only one component. Include retries, longer output, validation failure, human escalation, and fallback in cost per completed task.
Migration checklist
- Replace the key in a protected environment.
- Set
https://api.lumeapi.site/v1on every active client. - Copy a current Gemini model ID from LumeAPI docs.
- Keep model choice behind an alias.
- Test normal, long, streaming, tool, structured, failure, and timeout cases.
- Compare task success, latency, errors, token usage, and billed cost.
- Inspect the model and request data in LumeAPI logs.
- Roll out gradually and keep a one-step rollback.
- Review the Gemini API hub, OpenAI-compatible API, and multi-model API.
Sources and verification
- LumeAPI Gemini API, Gemini 3.5 Flash docs, and OpenAI-compatible API for current gateway configuration, model IDs, prices, and product boundaries.
- Google's official OpenAI compatibility guide for the OpenAI-library migration pattern.
- Official OpenAI Python library for client configuration, streaming, timeouts, retries, usage, and errors.
The code was syntax-checked on July 20, 2026. No customer inference key was used, so the article does not claim observed model quality, latency, or complete provider-native parity.