Use case
Customer support
A support assistant has to feel instant, stay on topic and know when to hand over to a person. Streaming handles the first; your prompt and help content handle the rest.
The problem
Customers abandon a chat that sits silent for several seconds, so waiting for a complete answer before showing anything feels broken. Answers also have to come from your policies, not the model's general knowledge, and traffic is spiky: a launch or an outage can multiply volume in an hour.
How it works with NeuronGate
01
Customer message
From your chat widget
02
Your backend
Adds instructions and matching help articles
03
Streaming request
stream: true to /v1/chat/completions
04
Tokens to the widget
Forwarded as they arrive
05
Hand-off check
Escalate to a person when needed
With stream: true the response arrives as server-sent events in the OpenAI chunk format, so the first words appear while the rest is still being generated. Keep the API key on your server: the widget talks to your backend, and your backend talks to NeuronGate.
Choosing models
Support favours fast, inexpensive models with good instruction-following. Compare latency and price in the model catalog, then test on a sample of real tickets.
| Role | Good fit | Why | Trade-off |
|---|---|---|---|
| First-line replies | ~google/gemini-flash-latest | Fast first token and low price for high volume | Can be terse on nuanced policy questions |
| Complex or upset customers | ~anthropic/claude-sonnet-latest | Careful tone and better judgement on edge cases | Several times the price per reply |
| Fallback | deepseek/deepseek-v4-flash | Different provider, so an outage on one rarely hits both | Check its answers against your tone guide |
| Ticket summaries | deepseek/deepseek-v4-flash | Cheap for summarising the conversation for the human agent | Not customer-facing, so tone matters less |
Example: streaming with a fallback model
Stream the reply and, if the first model fails before any text arrives, try a second one. Once tokens have reached the customer, don't switch models mid-answer.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://neurongate.net/v1",
api_key=os.environ["NEURONGATE_API_KEY"],
)
import openai
MODELS = ["~google/gemini-flash-latest", "deepseek/deepseek-v4-flash"]
RETRYABLE = (openai.APIConnectionError, openai.InternalServerError, openai.RateLimitError)
def stream_reply(messages):
"""Yield text chunks, trying the next model only if nothing was sent yet."""
for model in MODELS:
sent_any = False
try:
stream = client.chat.completions.create(
model=model, messages=messages, stream=True, max_tokens=600,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
sent_any = True
yield chunk.choices[0].delta.content
return
except RETRYABLE:
if sent_any:
raise # don't restart an answer the customer is reading
raise RuntimeError("All models failed; hand the chat to a person")Give the model a way out
Cap the reply length
max_tokens. Support answers rarely need more than a few hundred tokens, and the cap bounds the cost of a model that rambles.Cost control
- 1
Give the workload its own key
Create a key just for the support assistant under API keys. Its usage then shows up separately in the logs, and revoking it touches nothing else. - 2
Set a monthly spend cap
Once the key has spent its cap for the month, its requests are refused until the next month or until you raise the cap. Size it from a week of real traffic, not a guess. - 3
Allowlist the models it may call
Restrict the key to the models this workload actually uses, for example~google/gemini-flash-latestanddeepseek/deepseek-v4-flash. A typo or a prompt-injected model switch then fails instead of quietly running on a pricier model. - 4
Watch the logs
Filter the request log by this key to see tokens, cost and latency per call. Export CSV for a monthly cost-per-workload report.
FAQ
Are customer conversations stored by NeuronGate?
No. NeuronGate logs metadata for each request (model, tokens, cost, latency, status) but not the prompt or completion text. Keep transcripts in your own system if you need them.
Can I call NeuronGate directly from the browser?
Don't. Anyone who opens the page could copy the key. Call NeuronGate from your backend and stream the text on to the widget.
What happens when traffic spikes?
Requests keep flowing as long as the key is under its cap and your balance covers them. Size the monthly cap with headroom for launches, and keep the fallback model in your code for provider-side problems.