
This Gemini 4 Neon API guide takes you from an API key to a working request in cURL, the Python OpenAI SDK, and Google's native generateContent format, all with the model ID gemini-4-neon. Every request body follows PoYo's published schema as of November 23, 2026. You can test prompts on the Gemini 4 Neon model page first.
New to the model? The Gemini 4 Neon API overview covers limits, prices, and positioning.
Before you start
Create a key in the PoYo dashboard and keep it on your server:
export POYO_API_KEY="your-poyo-key"
| Format | Endpoint | Use it when |
|---|---|---|
| Chat Completions | POST https://api.poyo.ai/v1/chat/completions | You already use the OpenAI SDK, text messages |
| Gemini Native | POST https://api.poyo.ai/v1beta/models/gemini-4-neon:generateContent | You need image, audio, video or PDF parts (inlineData) |
| Gemini Native streaming | POST https://api.poyo.ai/v1beta/models/gemini-4-neon:streamGenerateContent | Native format with server-sent events |
Every request sends Authorization: Bearer $POYO_API_KEY. gemini-4-neon does not support /v1/responses or /v1/messages on PoYo.
First Gemini 4 Neon API request with cURL
curl https://api.poyo.ai/v1/chat/completions \
-H "Authorization: Bearer $POYO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-4-neon",
"messages": [
{"role": "system", "content": "You are a security reviewer. Cite line numbers."},
{"role": "user", "content": "Review this Flask handler for injection risks: ..."}
],
"max_tokens": 8192,
"temperature": 1
}'
model and messages are required. Optional fields in PoYo's schema: temperature (0–2), top_p (0–1, use it or temperature, not both), max_tokens, stream, stop (up to 4 sequences), frequency_penalty and presence_penalty (−2 to 2), and n. Message content is a string.
The response is a standard chat.completion object: text in choices[0].message.content, the stop cause in choices[0].finish_reason, and counts in usage.prompt_tokens, usage.completion_tokens, and usage.total_tokens.
Python with the OpenAI SDK
Point the SDK at PoYo and change nothing else:
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.poyo.ai/v1", api_key=os.environ["POYO_API_KEY"])
resp = client.chat.completions.create(
model="gemini-4-neon",
messages=[
{"role": "system", "content": "You are a senior backend engineer."},
{"role": "user", "content": "Plan a zero-downtime migration from Postgres 14 to 17."},
],
max_tokens=8192,
)
print(resp.choices[0].message.content)
print(resp.choices[0].finish_reason, resp.usage.prompt_tokens, resp.usage.completion_tokens)
Coming from gemini-4-carbon, gemini-4-argon, or another model that supports Chat Completions on PoYo, the switch is a one-line change to model.
Streaming with the OpenAI SDK
With stream=True, PoYo sends chat.completion.chunk events and ends with data: [DONE]. Text arrives in choices[0].delta.content, and the last chunk carries finish_reason and usage:
stream = client.chat.completions.create(
model="gemini-4-neon",
messages=[{"role": "user", "content": "Explain idempotency keys with one payment example."}],
max_tokens=4096,
stream=True,
)
usage = None
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
if getattr(chunk, "usage", None):
usage = chunk.usage
print("\n", usage)
The Gemini-native generateContent format
The native endpoint takes the model in the URL path. The body uses contents (each with role user or model and a parts array), plus optional generationConfig (temperature, topP, topK, maxOutputTokens, stopSequences) and safetySettings:
import os, requests
URL = "https://api.poyo.ai/v1beta/models/gemini-4-neon:generateContent"
HEADERS = {"Authorization": f"Bearer {os.environ['POYO_API_KEY']}"}
body = {
"contents": [{"role": "user", "parts": [{"text": "Compare CRDTs and operational transforms."}]}],
"generationConfig": {"maxOutputTokens": 2048},
}
r = requests.post(URL, headers=HEADERS, json=body, timeout=600)
r.raise_for_status()
data = r.json()
text = "".join(
p["text"]
for c in data.get("candidates", [])
for p in c.get("content", {}).get("parts", [])
if "text" in p and not p.get("thought")
)
print(text)
print(data["usageMetadata"])
The response is Google's GenerateContentResponse, returned directly with no code / data wrapper. Thinking models can add parts with thought: true or a thoughtSignature, so skip parts without text, as above.
Native streaming
Swap the method for :streamGenerateContent. Each data: line is a partial GenerateContentResponse, the last event carries finishReason, and the stream ends with data: [DONE]. The alt=sse query parameter is accepted but not required.
import json
STREAM_URL = "https://api.poyo.ai/v1beta/models/gemini-4-neon:streamGenerateContent"
usage = {}
with requests.post(STREAM_URL, headers=HEADERS, json=body, stream=True, timeout=600) as r:
r.raise_for_status()
for line in r.iter_lines(decode_unicode=True):
if not line or not line.startswith("data: "):
continue
payload = line[len("data: "):]
if payload == "[DONE]":
break
event = json.loads(payload)
for cand in event.get("candidates", []):
for part in cand.get("content", {}).get("parts", []):
if "text" in part and not part.get("thought"):
print(part["text"], end="", flush=True)
usage = event.get("usageMetadata", usage)
print("\n", usage)
Image and file input through the Gemini 4 Neon API
PoYo's docs list text, image, audio, video, and PDF input for gemini-4-neon. File input goes through the native format as an inlineData part with a mimeType and base64 data. Put the text instruction before media parts:
{
"contents": [
{
"role": "user",
"parts": [
{"text": "Read this architecture diagram and list every service that writes to the database."},
{"inlineData": {"mimeType": "image/png", "data": "BASE64_IMAGE_DATA"}}
]
}
],
"generationConfig": {"maxOutputTokens": 4096}
}
PoYo's Chat Completions schema documents content as a string, so don't send OpenAI-style image arrays to /v1/chat/completions. PoYo's docs show an image example only; for PDF, audio, and video, send one small file first and check the response before building a pipeline. Media counts toward prompt tokens.
Thinking level and max output
Google gives Gemini 4 Neon four thinking levels: low, medium, high (default), and xhigh. PoYo's model page says thinking-level control goes through the native endpoint, but the published generationConfig schema does not list a thinking field yet. This guide sends none, so requests run at high. Check the Gemini Native docs before adding one.
| Format | Max output field | Signal that output was cut off |
|---|---|---|
| Chat Completions | max_tokens | finish_reason: "length" |
| Gemini Native | generationConfig.maxOutputTokens | finishReason other than STOP |
The default synchronous output cap is 64K tokens inside a 1,048,576-token shared context. Thinking tokens count as output, so the output count in usage can be larger than the visible answer.
How your first Gemini 4 Neon API bill is calculated
PoYo prices gemini-4-neon at $2.40 per 1M input tokens, $12.00 per 1M output tokens, and $0.12 per 1M cache-read tokens (1 credit = $0.005).
| Format | Input tokens | Output tokens (incl. thinking) |
|---|---|---|
| Chat Completions | usage.prompt_tokens | usage.total_tokens − usage.prompt_tokens |
| Gemini Native | usageMetadata.promptTokenCount | totalTokenCount − promptTokenCount |
INPUT_USD, OUTPUT_USD = 2.40, 12.00 # PoYo, per 1M tokens
def neon_cost_usd(input_tokens: int, output_tokens: int) -> float:
return (input_tokens * INPUT_USD + output_tokens * OUTPUT_USD) / 1_000_000
def neon_cost_credits(input_tokens: int, output_tokens: int) -> float:
return neon_cost_usd(input_tokens, output_tokens) / 0.005
Example: 1,500 input tokens and 3,000 output tokens (answer plus thinking):
input: 1,500 × $2.40 / 1,000,000 = $0.00360 (0.72 credits)
output: 3,000 × $12.00 / 1,000,000 = $0.03600 (7.20 credits)
total: $0.03960 (7.92 credits)
This prices every prompt token at the full input rate. Google says caching is implicit for Neon, so cached reads at $0.12 per 1M can only lower the bill. Scenarios at scale are in Gemini 4 Neon API pricing.
Errors worth handling
| HTTP | Cause | What to do |
|---|---|---|
| 400 | Missing or invalid field | Fix the request body |
| 400 | Wrong format for this model; message lists supported URIs | Use Chat Completions or Gemini Native |
| 400 | Gemini Native error, shape {"error": {"code": 400, "message": "...", "status": "INVALID_ARGUMENT"}} | Fix contents / generationConfig |
| 401 | Missing or invalid API key | Check the Authorization header |
| 402 | Insufficient credits | Top up before retrying |
| 404 | Unknown model ID | Check the spelling: gemini-4-neon |
| 500 / 502 / 503 | Server or upstream error | Retry with exponential backoff |
PoYo's docs say LLM endpoints are currently not rate limited, but treat a 429 like a 5xx: wait and retry. With the OpenAI SDK, catch openai.APIStatusError and branch on status_code. Full bodies are in PoYo error codes.
Checklist before you ship
- Keep
POYO_API_KEYserver-side. - Always set
max_tokensormaxOutputTokens, and logfinish_reason/finishReason. - Store each response's usage block next to your own request ID.
- Put long, stable context first and the changing question last, which gives implicit caching a chance.
- Retry only 5xx and
429; a 400 fails again until the body changes.
Next: Gemini 4 Neon API for coding agents.
Frequently asked questions
How do I call the Gemini 4 Neon API in Python?
Use the OpenAI SDK with base_url="https://api.poyo.ai/v1", your PoYo key, and model="gemini-4-neon". For native requests, POST to /v1beta/models/gemini-4-neon:generateContent with requests.
Does the Gemini 4 Neon API support streaming?
Yes. Set "stream": true on Chat Completions, or call :streamGenerateContent. Both return server-sent events that end with data: [DONE].
How do I send an image to the Gemini 4 Neon API?
Use the native endpoint with an inlineData part (mimeType plus base64 data) after your text part. Chat Completions on PoYo takes string content.
How do I set the Gemini 4 Neon API thinking level?
Google's levels are low, medium, high (default) and xhigh. PoYo routes thinking control through the native format; check the Gemini Native docs for the current field. Without it, requests run at high.
Why does the Gemini 4 Neon API return 400 on /v1/responses?
gemini-4-neon supports only Chat Completions and Gemini Native on PoYo. Other formats return 400 with the supported URIs.