Models → Pricing → Docs → Blog → Changelog → Contact → Status →
Get started freeLog in

Gemini API format

Send requests in Google's Gemini format. They are translated and run through the same gateway as every other request.

⏱ 4 min read

Endpoints

MethodPathPurpose
POST/v1beta/models/{model}:generateContentOne answer as JSON
POST/v1beta/models/{model}:streamGenerateContentStreamed answer
POST/v1beta/models/{model}:countTokensEstimate input tokens
GET/v1beta/modelsModel list (same list as /v1/models)

The host is https://freemodel.in. The same POST paths also work under /v1/models/…. Any other method after the colon returns 404 NOT_FOUND.

{model} is any listed model id, not only Gemini models. Authentication, plan rules, multipliers, rate limits and billing are the same as for chat completions. gemini-3.1-pro needs a paid plan; free accounts can use the free models such as gpt-6-luna.

Authentication

Send your key as x-goog-api-key: fm_…, Authorization: Bearer fm_…, or the ?key= query parameter. A header is safer than the query string. The key needs the inference scope.

Example

curl "https://freemodel.in/v1beta/models/gpt-6-luna:generateContent" \
  -H "x-goog-api-key: fm_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "systemInstruction": {"parts": [{"text": "Answer briefly."}]},
    "contents": [{"role": "user", "parts": [{"text": "Name three prime numbers."}]}],
    "generationConfig": {"temperature": 0.3, "maxOutputTokens": 512}
  }'
{
  "candidates": [{
    "content": {"role": "model", "parts": [{"text": "2, 3 and 5."}]},
    "finishReason": "STOP",
    "index": 0
  }],
  "usageMetadata": {"promptTokenCount": 24, "candidatesTokenCount": 7, "totalTokenCount": 31},
  "modelVersion": "gpt-6-luna"
}
import requests

r = requests.post(
    "https://freemodel.in/v1beta/models/gpt-6-luna:generateContent",
    headers={"x-goog-api-key": "fm_your_key_here"},
    json={"contents": [{"role": "user", "parts": [{"text": "Name three prime numbers."}]}]},
    timeout=120,
)
r.raise_for_status()
print(r.json()["candidates"][0]["content"]["parts"][0]["text"])

Request fields

FieldHandling
contents[]Roles user and model. Parts: text, inlineData (images are passed as images; text/* data is decoded to text; other types become a short placeholder), fileData (passed only as a reference to the file URI), functionCall, functionResponse. Parts marked thought are skipped.
systemInstructionText parts become the system prompt.
tools[].functionDeclarationsFunction tools. parameters or parametersJsonSchema; Gemini's upper-case types and nullable are converted to JSON Schema.
tools[].googleSearchPassed on as a web search tool (see the web_search capability on Models).
toolConfig.functionCallingConfigmode AUTO, ANY or NONE; allowedFunctionNames with one name forces that function.
generationConfigtemperature, topP, maxOutputTokens, stopSequences, and responseMimeType: "application/json" with optional responseSchema / responseJsonSchema (see Structured output).

Response fields

  • candidates[0].content.parts — text parts, reasoning as parts with "thought": true, and functionCall parts (id, name, args).
  • finishReason — STOP, MAX_TOKENS or SAFETY.
  • usageMetadata — promptTokenCount, candidatesTokenCount, totalTokenCount, and thoughtsTokenCount when the model reasoned.
  • modelVersion — the model id you asked for.

Streaming

:streamGenerateContent returns chunks in the same shape as above. Add ?alt=sse to get server-sent events (data: {…} lines); without it the stream is one JSON array of chunks. The last chunk has finishReason and usageMetadata.

curl -N "https://freemodel.in/v1beta/models/gpt-6-luna:streamGenerateContent?alt=sse" \
  -H "x-goog-api-key: fm_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{"contents": [{"role": "user", "parts": [{"text": "Count to five."}]}]}'

countTokens

Returns {"totalTokens": N}, an estimate from the length of contents, systemInstruction and tools (also read from a wrapping generateContentRequest). It is not charged.

Using a Gemini client

This surface is meant for tools that let you change the Gemini base URL, such as Gemini CLI or the Google GenAI SDK with GOOGLE_GEMINI_BASE_URL. Set the base URL to https://freemodel.in and use your fm_ key as the API key. Check your tool's own docs for the exact setting name.

Errors

Errors from the model call use Google's shape:

{"error": {"code": 429, "message": "…", "status": "RESOURCE_EXHAUSTED"}}

Status names: INVALID_ARGUMENT (400, 422), UNAUTHENTICATED (401), PERMISSION_DENIED (403), NOT_FOUND (404), RESOURCE_EXHAUSTED (429), UNAVAILABLE (5xx). A body that is not JSON gets 400 INVALID_ARGUMENT.

Checks that run before the model is called — key, plan tokens, free-plan rules, unknown model, rate limits — answer in the OpenAI error shape with a code such as invalid_api_key, tokens_exhausted or model_not_found. Handle both shapes. All codes are on Errors and status codes.

Was this page helpful?
Still stuck?
Open a support ticket from your dashboard or message our support bot on Telegram.
Telegram supportGet help