Last verified: July 23, 2026
Short path: Start with the GPT API guide, compare the OpenAI-compatible gateway option, and check current AI API pricing before changing models.
Your GPT API is slow because “the model” is only one part of the request path. DNS, connection setup, queueing, prompt size, output length, tool loops, retries, and your own proxy can all inflate p95. The fastest fix is usually not a rewrite: measure each phase, stop accidental retries and oversized prompts, then test a smaller catalog model such as gpt-5.4-mini against your production-shaped workload.
Quick Answer
| Question | Direct answer |
|---|---|
| Why is my GPT API slow? | First separate connection time, time to first byte, token generation, and application processing; a high p95 often comes from queueing, long prompts, retries, or agent hops rather than one slow model call. |
| What is the fastest GPT API slow fix? | Reuse HTTP connections, set an explicit timeout, cap output tokens, log request attempts, and remove duplicate retries before changing application architecture. |
| How do I reduce OpenAI API latency in production? | Measure a baseline, shrink the request, test gpt-5.4-mini, and compare the same request through your current provider and an OpenAI-compatible gateway. |
| Should I switch providers immediately? | No. Prove where the time is spent first; a gateway can reduce cost or give you another route, but it cannot repair a prompt that sends 100,000 tokens on every agent hop. |
| What is the main catch? | Lower latency can mean lower quality, shorter answers, or different behavior. Keep an evaluation set and a rollback path. |
In short
The practical answer to “why is the gpt api slow?” is to treat latency as a measured request pipeline, not a model-vibes problem. Most teams should fix connection reuse, prompt growth, output limits, and retry multiplication before rewriting their app. Once those are under control, route only the requests that pass your quality test to a faster or cheaper model; do not make every call a premium reasoning request.
What most guides get wrong
The common myth is: “If GPT latency is bad, the provider is having a bad day.”
That explanation is attractive because it lets you skip instrumentation. It also misses the most expensive failure mode: a request that is already slow gets retried two or three times, while each retry carries the same large conversation and tool output. Your dashboard shows a slow provider. The underlying problem is a client that turns one slow request into four.
A second misleading shortcut is comparing average latency. Interactive systems are damaged by the tail. A 700 ms average can still produce a frustrating 8-second p95 if a small number of requests contain huge contexts or wait behind a retry queue. Record p50, p95, and p99, but also record input tokens, output tokens, attempt number, model id, timeout reason, and whether tools were involved.
Fix the multiplication first. Then decide whether the model or route needs to change.
A realistic production scenario
This is a composite incident based on a common production pattern, not a claim about a named customer.
A five-person support-automation team runs a Python API behind a Kubernetes ingress. Their service calls a GPT-4-class model for ticket classification, then asks the model to draft a response when confidence is low. The p95 for the whole endpoint reaches 11 seconds even though the first model call usually returns in about 2 seconds.
The turning point is a request trace. The service creates a new HTTP client for every call, sends the entire ticket history plus previous tool results, and uses a blanket retry wrapper around the whole operation. A transient 429 causes the classification call and the drafting call to repeat. One ticket produces three model attempts and 28,000 input tokens.
The team does not rewrite the workflow. They reuse the client, trim old tool transcripts, cap the draft length, and retry only an individual idempotent request. They then test gpt-5.4-mini for classification while keeping the existing model for difficult drafts. The important change is not a magic endpoint. It is making the latency budget visible.
Expert take
An LLM request has at least four latency components:
- Client and network setup: DNS lookup, TCP/TLS connection setup, proxy traversal, and connection-pool misses.
- Provider-side waiting: admission, queueing, and the time before response bytes begin.
- Generation: time to produce the requested output. More output generally gives the model more work to do, and a long requested completion gives the tail more room to expand.
- Your application: JSON parsing, tool execution, database calls, moderation or policy checks, and any second or third model hop.
You cannot choose the right fix until you know which component dominates. A time-to-first-byte problem points you toward network path, queueing, or provider behavior. A fast first byte followed by a long completion points toward output size or streaming consumption. A long endpoint duration with normal model timings points toward your tools or orchestration.
There is also a difference between single-call latency and workflow latency. An agent that makes four sequential calls with a 1.5-second p95 for each does not have a 1.5-second user experience. Its critical path is roughly the sum of those waits, plus tool time. Parallelize independent lookups where correctness permits; do not parallelize calls merely to hide an unbounded retry policy.
When should you not follow the advice in this runbook? Do not switch a production model solely because a small synthetic test is faster. If the model handles structured output, tool selection, or domain terminology materially better, the extra latency may be cheaper than retries, human review, or incorrect actions. Likewise, provider-native features such as specialized batch processing or prompt caching may be a better fit for offline workloads than a gateway route. Verify those features in the provider’s current documentation rather than assuming an OpenAI-compatible endpoint exposes them.
LumeAPI is an independent third-party gateway, not OpenAI, Anthropic, or Google. It exposes the catalog’s OpenAI-compatible Chat Completions endpoint, but gateway compatibility does not mean identical support for every provider-native API feature. Benchmark your exact request shape and confirm the features your application depends on.
Runbook: diagnose the slow path without rewriting the app
1. Define the latency budget
Write down the user-facing target before changing code. For example:
- 300 ms for your application before the model call
- 2 seconds for the first model response bytes
- 4 seconds for the complete answer
- 1 second for tool execution
- one bounded retry, only where safe
This is not a promise that the provider will meet the budget. It is a way to identify which component has consumed it.
Use one correlation ID from the incoming HTTP request through every model attempt. At minimum, log:
request_id
model
attempt
started_at
time_to_first_byte_ms
total_duration_ms
input_tokens
output_tokens
status_code
timeout_type
tool_countNever log API keys or full user prompts by default. Prompt excerpts can contain credentials, personal data, or proprietary text.
2. Split first-byte and full-response timing
Many clients report only total duration. That makes two very different failures look identical:
- The server takes a long time to begin responding.
- The server starts quickly but generates a long answer.
If your application uses streaming, measure the timestamp of the first received chunk and the timestamp of the final chunk. If it does not stream, you can still compare connection setup and total request time, but you will not know the provider’s first-byte behavior from the client alone.
A useful diagnostic matrix looks like this:
| Observation | Likely investigation |
|---|---|
| High time before first byte, small prompts | Network path, connection reuse, provider queueing, route comparison |
| First byte is acceptable, final byte is slow | Output length, generation target, streaming consumer, post-processing |
| Only retries are slow | Retry backoff, 429/5xx handling, duplicate work, pool saturation |
| Latency rises with input size | Prompt history, retrieved chunks, tool transcript, serialization |
| Model call is normal but endpoint is slow | Tools, database calls, synchronous orchestration, downstream services |
| p50 is fine and p95 is poor | Tail requests, large-context outliers, cold connections, contention |
Do not conclude that a gateway is faster or slower from one request. Use identical prompts, the same region and client path where possible, and a production-shaped distribution of short and long requests.
3. Check connection reuse before touching prompts
Creating a new HTTP client for each request can repeatedly pay connection setup costs. It also makes connection pools, DNS behavior, and socket exhaustion harder to reason about.
The lowest-risk change is to create one long-lived client per application process and reuse it. The exact implementation depends on your language and HTTP library. If you use an SDK, confirm its current connection and timeout behavior in the official documentation. The OpenAI API documentation is the right place to verify current API shapes and provider-specific options.
For a migration test, a direct HTTP call makes the route explicit:
import os
import time
import requests
BASE_URL = "https://api.lumeapi.site/v1"
MODEL = "gpt-5.4-mini"
session = requests.Session()
session.headers.update({
"Authorization": f"Bearer {os.environ['LUMEAPI_KEY']}",
"Content-Type": "application/json",
})
payload = {
"model": MODEL,
"messages": [
{"role": "user", "content": "Classify this support ticket: login fails after password reset."}
],
"max_tokens": 120,
"temperature": 0,
}
started = time.perf_counter()
try:
response = session.post(
f"{BASE_URL}/chat/completions",
json=payload,
timeout=(3.0, 20.0), # connect timeout, read timeout
)
elapsed_ms = (time.perf_counter() - started) * 1000
response.raise_for_status()
body = response.json()
print({
"model": MODEL,
"status": response.status_code,
"duration_ms": round(elapsed_ms),
"usage": body.get("usage"),
})
except requests.Timeout:
print("model request timed out")
except requests.HTTPError as exc:
print("model request failed:", exc)This example is intentionally small. In production, use your service’s structured logger, redact response content, and make the timeout fit the endpoint’s user-facing budget. A read timeout that is longer than the load balancer timeout simply moves the failure to a less useful layer.
4. Find accidental prompt growth
Log token counts, not just character counts. A prompt can grow because:
- the full conversation is resent on every turn;
- failed tool calls remain in the next request;
- retrieval returns duplicate or low-value chunks;
- a summarizer appends summaries without removing source messages;
- an agent includes hidden scratch data in every hop;
- a retry rebuilds the prompt incorrectly and duplicates messages.
For each request, compare:
input_tokens_this_attempt
input_tokens_first_attempt
number_of_messages
tool_result_bytes
retrieved_chunk_countSet a hard policy for history. Keep the system instruction, the current task, and the minimum evidence needed to answer. Summarize old turns once, then replace them; do not append a new summary on every request.
Do not blindly truncate from the front. The oldest message may contain important constraints, while the newest tool result may be redundant. A safer approach is to classify context by value: required instructions, current user request, authoritative records, recent state, and disposable history.
5. Put output limits on the expensive path
Output tokens are easy to overlook because the input prompt is visible in logs and the generated response feels like the product. A draft, explanation, or tool argument can become much longer than the user needs.
Use a task-specific output ceiling:
- classification: short structured result;
- extraction: bounded JSON fields;
- UI summary: a few paragraphs;
- code generation: a larger ceiling with a separate timeout;
- tool arguments: strict schema and size validation.
A limit is not a quality strategy by itself. Test whether the answer is being cut off, and return a controlled fallback when it is. But leaving every request open-ended is a latency strategy too: an accidental essay becomes a tail outlier.
6. Audit retries, backoff, and idempotency
Retries are useful for transient failures and dangerous when they wrap a multi-step workflow.
A safe pattern is:
- Give each model attempt its own attempt number.
- Retry only status classes and exceptions you have decided are transient.
- Bound the number of attempts and total retry time.
- Do not repeat a completed tool side effect just because the client did not receive the final response.
- Add jitter to backoff if many workers retry together.
- Preserve the original request ID so you can see multiplication in traces.
Here is a basic request-level pattern. It does not decide which statuses are transient for your provider; that policy must match the provider documentation and your operation’s idempotency.
import random
import time
import requests
RETRYABLE_STATUS = {429, 500, 502, 503, 504}
def post_chat(session, base_url, payload, max_attempts=2):
last_error = None
for attempt in range(1, max_attempts + 1):
try:
response = session.post(
f"{base_url}/chat/completions",
json=payload,
timeout=(3.0, 20.0),
)
if response.status_code not in RETRYABLE_STATUS:
response.raise_for_status()
return response.json(), attempt
last_error = RuntimeError(
f"retryable model status {response.status_code}"
)
except (requests.Timeout, requests.ConnectionError) as exc:
last_error = exc
if attempt < max_attempts:
delay = min(2.0, 0.25 * (2 ** (attempt - 1)))
time.sleep(delay + random.uniform(0, 0.1))
raise RuntimeError("model request failed after bounded retries") from last_errorThis code retries the HTTP request, not an entire agent workflow. If the request includes a tool that changes a database, sends an email, or charges a card, separate model planning from side effects and use an idempotency design in your application. A retry loop cannot infer whether a side effect happened after a dropped connection.
7. Test a smaller model on the right slice
Do not migrate the whole application to a smaller model because a ping endpoint is fast. Make a small routing experiment:
- retain the current model for high-risk or ambiguous requests;
- send classification, extraction, and short transformations to
gpt-5.4-mini; - compare correctness, schema validity, tool selection, and complete latency;
- promote only if it passes your acceptance threshold.
The catalog lists gpt-5.4-mini at $0.225 per 1 million input tokens and $1.35 per 1 million output tokens through LumeAPI. That is a cost difference, not a guaranteed latency claim. The only reliable answer for your workload comes from measurement.
If you need a different capability or behavior, test the exact catalog model ID rather than using a family nickname. For example, the available IDs include gpt-5.4, gpt-5.6-terra, and gpt-5.6-sol; do not substitute an undocumented alias into your production route.
Cost and latency: do not confuse the two
A cheaper route may improve your budget while leaving p95 unchanged. Conversely, a faster model may cost more per token but reduce infrastructure time, user abandonment, or sequential agent hops.
For a simple monthly comparison, assume 1 million input tokens and 100,000 output tokens. The calculation is:
monthly cost = input millions × input rate
+ output millions × output rate| Catalog model | Official input / output per 1M | LumeAPI input / output per 1M | Example monthly total* |
|---|---|---|---|
gpt-5.4-mini | $0.75 / $4.50 | $0.225 / $1.35 | $0.36 |
gpt-5.4 | $2.50 / $15.00 | $0.75 / $4.50 | $1.20 |
gpt-5.6-terra | $2.50 / $15.00 | $0.75 / $4.50 | $1.20 |
gpt-5.6-sol | $5.00 / $30.00 | $1.50 / $9.00 | $2.40 |
\*Assumes 1M input tokens plus 0.1M output tokens in one month. Rates are from the LumeAPI catalog updated July 22, 2026. “Official” is a reference-rate column supplied in the brief; verify current provider pricing before committing to a budget.
This table does not prove that LumeAPI has lower p95. It tells you what a controlled route test could save if token usage stays constant. LumeAPI uses a USD wallet and transparent per-token catalog rates, but it remains an independent third-party gateway. Check your application’s required features, observability, regional requirements, and failure behavior before moving all traffic.
A useful production metric is cost per successful task, not cost per request. If a cheaper model fails validation and triggers two extra attempts, its apparent token discount may disappear.
Decision matrix: choose the smallest change that addresses the cause
| Symptom | First action | Model change? | Route change? |
|---|---|---|---|
| New client per request | Reuse a session or SDK client | No | No |
| Large input token outliers | Trim, summarize, deduplicate context | Maybe | No |
| Long generated answers | Set task-specific output limits | Maybe | No |
| Sequential agent hops | Parallelize independent work or remove a hop | Maybe | No |
| 429s create long tails | Bound retries and inspect concurrency | No | Maybe |
| Network path dominates | Compare regions, pools, and routes | No | Yes, after measurement |
| Classification is slow and simple | Evaluate gpt-5.4-mini | Yes | Optional |
| Native provider feature is required | Use the provider’s documented path | No | Possibly not a gateway |
The winner depends on the failure mode. For prompt inflation, the winner is prompt surgery. For simple classification, gpt-5.4-mini is the first catalog candidate to evaluate. For a network-specific problem, a route comparison is justified. There is no reason to pay migration cost for a problem caused by a seventh retry.
A 30-minute investigation checklist
Run this checklist against a sample of slow requests:
- [ ] Confirm whether the reported p95 is model-call latency or full endpoint latency.
- [ ] Add a request ID and attempt number to every model call.
- [ ] Record first-byte and final-byte timing where streaming is used.
- [ ] Record input and output token counts for slow requests.
- [ ] Compare first attempt duration with retry attempt duration.
- [ ] Check whether a new HTTP connection is created per request.
- [ ] Check connection-pool limits and worker concurrency.
- [ ] Identify tool calls and database work on the critical path.
- [ ] Find prompts that resend old tool results or duplicate retrieved chunks.
- [ ] Set an explicit connection timeout and read timeout.
- [ ] Bound retries by both count and total elapsed time.
- [ ] Verify that retried operations cannot duplicate side effects.
- [ ] Test a reduced prompt without changing the model.
- [ ] Test
gpt-5.4-minion a labeled quality set. - [ ] Compare direct OpenAI traffic with the same request through the gateway.
- [ ] Keep a rollback switch for model and route selection.
The most important checkbox is the one teams skip: compare the complete workflow, not a single HTTP call. A 1-second model request repeated four times is a 4-second user experience before your database and rendering costs.
What to monitor after the fix
Create separate dashboards for:
- request p50, p95, and p99;
- model time to first byte;
- model total duration;
- application time outside the model;
- input and output tokens;
- timeout rate;
- 429 and 5xx rate;
- retry attempts per original request;
- completion truncation rate;
- validation or tool-call failure rate;
- cost per successful task.
Break down the tail by model ID, endpoint, tenant, request size, and route. An aggregate p95 can hide the fact that only one tenant sends enormous histories or that only one worker pool has exhausted its connections.
Alert on retry amplification as well as error rate. A service with zero visible errors can still be unhealthy if every successful request needs two attempts and consumes three times the expected tokens.
When a gateway helps—and when it does not
An OpenAI-compatible gateway can make a route comparison less invasive because the application’s request shape can remain close to Chat Completions and the base URL can change. LumeAPI’s catalog provides the endpoint https://api.lumeapi.site/v1, bearer-token authentication, and the model IDs listed in the catalog.
That is useful for controlled experiments, cost reduction, and model selection. It is not a promise of lower latency. The gateway adds another network and operational dependency, and compatibility does not guarantee parity with every native provider feature. Measure from the same deployment environment, compare error handling, and confirm that streaming, tool calls, structured outputs, and any provider-specific options your app needs actually work for your chosen route.
A gateway is also not a substitute for queue control. If your own worker pool allows 500 concurrent requests against a service designed for 50, moving the base URL may merely move the queue.
FAQ
Why is the GPT API slow only at p95?
High p95 usually means a subset of requests has a distinct cost, such as a huge prompt, long output, cold connection, tool delay, or retry chain. Segment slow requests by token count, attempt number, model, and tool usage instead of looking only at the aggregate average.
What is the fastest gpt api slow fix without changing models?
Reuse the HTTP client, set explicit timeouts, cap output length, and stop retrying the entire workflow. These changes preserve model behavior and often remove avoidable tail latency before a model migration is needed.
How can I reduce OpenAI API latency in production?
Measure first-byte and total timing, reduce repeated context, remove unnecessary sequential hops, bound retries, and evaluate a smaller model on low-risk tasks. A provider or gateway switch should come after you identify whether the network, prompt, generation, or application is the bottleneck.
Should I use streaming to fix a slow GPT API?
Streaming can improve perceived responsiveness by showing early output, but it does not necessarily reduce the time required to generate the complete answer. Measure time to first byte and time to final byte separately, and ensure your client and proxy do not buffer the stream.
Is LumeAPI guaranteed to be faster than the direct OpenAI API?
No. LumeAPI is an independent third-party gateway, so you must benchmark the same request shape and deployment path against your current provider. It may offer different catalog pricing and a convenient compatible route, but it does not guarantee lower p95 or identical support for native features.
When should I switch from gpt-5.4 to gpt-5.4-mini?
Switch when gpt-5.4-mini passes your task-specific quality, schema, and tool-use evaluations and its latency improvement matters to the product. Keep the larger model for requests where a wrong answer costs more than the additional delay.
Next steps
- Instrument one endpoint today with request IDs, attempt counts, first-byte timing, total duration, token counts, and tool timing.
- Fix the no-rewrite causes first: connection reuse, prompt duplication, unbounded output, and workflow-level retries.
- Run a controlled evaluation of
gpt-5.4-miniand a second route using the lower-cost OpenAI-compatible option, with rollback enabled.
The core lesson is simple: a slow GPT API is often an observability and multiplication problem before it is a model problem. Measure the critical path, remove repeated work, and change the model or route only where the evidence says it will help.