Generate content

Endpoint
POST/v1beta/models/{model}:generateContent

Gemini native protocol endpoint; requests and responses match the Google API. The base URL has no /v1: the full address is https://api.moyiapi.com/v1beta/models/{model}:generateContent.

Request

Header Value Notes
x-goog-api-key sk-moyiapi-xxxxxx Authentication (the Google GenAI SDK uses this by default). Authorization: Bearer or x-api-key also work
content-type application/json

Minimal request body:

json
{
  "contents": [
    {"role": "user", "parts": [{"text": "Introduce yourself in one sentence"}]}
  ]
}

Parameters

Field Type Required Notes
{model} path Yes A Gemini model ID such as gemini-3.5-flash
contents array Yes Conversation contents; role is user or model, parts hold text (text) or inline data (inlineData)
generationConfig object No Generation settings: temperature, topP, topK, maxOutputTokens, seed; image models also take responseModalities and imageConfig

Other fields pass through in the Gemini API format.

Response

json
{
  "candidates": [
    {
      "content": {"role": "model", "parts": [{"text": "I am Gemini..."}]},
      "finishReason": "STOP"
    }
  ],
  "usageMetadata": {"promptTokenCount": 12, "candidatesTokenCount": 22, "totalTokenCount": 34},
  "modelVersion": "gemini-3.5-flash",
  "responseId": "…"
}
Field Notes
candidates[].content.parts[] The reply; text is in text, image models return inlineData
candidates[].finishReason Why generation stopped, such as STOP
usageMetadata Token usage
modelVersion The model that produced the response
responseId Response ID

Examples

bash
curl https://api.moyiapi.com/v1beta/models/gemini-3.5-flash:generateContent \
  -H "Authorization: Bearer sk-moyiapi-xxxxxx" \
  -H "content-type: application/json" \
  -d '{
    "contents": [
      {"role": "user", "parts": [{"text": "Introduce yourself in one sentence"}]}
    ]
  }'

With the Google SDK, point the base URL at https://api.moyiapi.com and use your Moyi API key; common environment variables:

bash
export GOOGLE_GEMINI_BASE_URL="https://api.moyiapi.com"
export GEMINI_API_KEY="sk-moyiapi-xxxxxx"
export GEMINI_API_KEY_AUTH_MECHANISM="bearer"

Errors

HTTP status error.type When it happens
401 missing_auth_credential / invalid_api_key / invalid_bearer_token Authentication failed; see Authentication
400 model_not_supported The model cannot be called at the moment; use another model from GET /v1/models
Ready? Three steps to startLog in to the console · top up · create an API key
DiscordGet community help instantly
Generate content · Docs