Gemini generateContent
The native Gemini API supports JSON and SSE responses. Put the model ID in the request path and the input text in contents[].parts[].
Before you start
Follow the quickstart to get an API key and select an endpoint that accepts direct HTTP calls. Send ICODEEASY_API_KEY in x-goog-api-key and replace YOUR_MODEL_ID with a Gemini model ID supported by the endpoint.
Request example
generateContent returns a complete JSON response.
curl -sS https://api.icodeeasy.cc/v1beta/models/YOUR_MODEL_ID:generateContent \
-H "x-goog-api-key: $ICODEEASY_API_KEY" \
-H 'Content-Type: application/json' \
--data '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Say hello."
}
]
}
]
}'
Read the response
Read text parts from candidates[].content.parts[]. When present, usageMetadata carries promptTokenCount, candidatesTokenCount, and cachedContentTokenCount.
{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"text": "Hello!"
}
]
},
"finishReason": "STOP"
}
]
}
Streaming request example
curl -NsS 'https://api.icodeeasy.cc/v1beta/models/YOUR_MODEL_ID:streamGenerateContent?alt=sse' \
-H "x-goog-api-key: $ICODEEASY_API_KEY" \
-H 'Content-Type: application/json' \
--data '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Say hello."
}
]
}
]
}'
Streaming response example
Each Gemini SSE data: payload is a JSON response fragment. Assemble text from candidates[].content.parts[] per candidate and check its finishReason. Preserve any received output as incomplete if the response reports an error or the connection closes before completion.
data: {"candidates":[{"index":0,"content":{"role":"model","parts":[{"text":"Hello!"}]}}]}
data: {"candidates":[{"index":0,"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":10,"candidatesTokenCount":4,"totalTokenCount":14}}
Read usage from a frame that includes usageMetadata. It uses the same fields as the JSON response.
Related guides
Getting Started
Create an account, obtain an API key, choose an endpoint, and send a first request to confirm that I Code Easy is working.
Gemini CLI Setup
Install Gemini CLI, configure authentication and the custom service domain, then use strict non-streaming JSON, SSE responses, and the video analysis demo correctly.
Model Capability Catalog
Compare public text, image, and video models by normalized request ID, compatible protocols, supported clients, tool use, media capabilities, limits, and review date.