API referenceAdvanced usersUpdated
POST/v1beta/models/{model}:generateContent

API console

POST/v1beta/models/gemini-3.8-flash:generateContent
View keys

Requests use the API key you enter and follow standard API billing.

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.

bash
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.

json
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "text": "Hello!"
          }
        ]
      },
      "finishReason": "STOP"
    }
  ]
}

Streaming request example

bash
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.

text
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.