Gemini text API
Use Gemini request and response formats for text generation and SSE.
Gemini text API
Generate text
curl "https://api.apimodel.store/v1beta/models/gemini-3.5-flash:generateContent" \
-H "x-goog-api-key: $MODELPORT_API_KEY" \
-H "Idempotency-Key: YOUR_UNIQUE_REQUEST_KEY" \
-H "Content-Type: application/json" \
--data '{"contents":[{"role":"user","parts":[{"text":"Describe a coastal city in one sentence."}]}],"generationConfig":{"maxOutputTokens":128}}'Stream text
curl -N "https://api.apimodel.store/v1beta/models/gemini-3.5-flash:streamGenerateContent?alt=sse" \
-H "x-goog-api-key: $MODELPORT_API_KEY" \
-H "Idempotency-Key: YOUR_UNIQUE_REQUEST_KEY" \
-H "Content-Type: application/json" \
--data '{"contents":[{"role":"user","parts":[{"text":"Describe a coastal city in one sentence."}]}],"generationConfig":{"maxOutputTokens":128}}'Use an available Gemini text model from GET /v1/models. Authenticate with a ModelPort key in x-goog-api-key or the Bearer header.
Send text parts in user or model turns and put system text in systemInstruction. Supported generationConfig fields include maxOutputTokens, temperature, topP, stopSequences, presencePenalty, and frequencyPenalty. The endpoint returns one candidate and currently accepts text only.
Read text from candidates[0].content.parts. The final SSE event carries the finish reason and usageMetadata. Set a cap with max_price_usd. Reuse the idempotency key on a retry and look up the final charge with X-ModelPort-Request-Id.