Gemini native API

The Google Gemini native endpoint for apps built on the Google SDKs.

The endpoint compatible with the native Google Gemini API format. Apps already built on the official Google SDKs (google-genai, @google/genai) only need a new address and key. If you just need chat, you can also call Gemini models through Chat Completions.

POST https://tokenfunc.com/v1beta/models/{model}:generateContent

cURL

curl "https://tokenfunc.com/v1beta/models/gemini-2.5-pro:generateContent" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: sk-xxxxxxxxxxxxxxxx" \
  -d '{
    "contents": [{"role": "user", "parts": [{"text": "Hello!"}]}]
  }'

Python

# pip install google-genai
from google import genai
from google.genai import types

# base_url is just this site's address; the SDK appends /v1beta/models/...
client = genai.Client(
    api_key="sk-xxxxxxxxxxxxxxxx",
    http_options=types.HttpOptions(base_url="https://tokenfunc.com"),
)

resp = client.models.generate_content(model="gemini-2.5-pro", contents="Hello!")
print(resp.text)

Node.js

// npm install @google/genai
import { GoogleGenAI } from '@google/genai'

// baseUrl is just this site's address; the SDK appends /v1beta/models/...
const ai = new GoogleGenAI({
  apiKey: 'sk-xxxxxxxxxxxxxxxx',
  httpOptions: { baseUrl: 'https://tokenfunc.com' },
})

const resp = await ai.models.generateContent({
  model: 'gemini-2.5-pro',
  contents: 'Hello!',
})
console.log(resp.text)

Authentication

Any of these works; the first is recommended:

FormExample
x-goog-api-key header (Google SDK default)x-goog-api-key: sk-xxxxxxxxxxxxxxxx
key URL parameter...:generateContent?key=sk-xxxxxxxxxxxxxxxx; logs can capture it, not recommended
Authorization headerAuthorization: Bearer sk-xxxxxxxxxxxxxxxx

Request parameters

Besides text, parts can hold images: {"inline_data": {"mime_type": "image/jpeg", "data": "<Base64>"}}.

200

{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [{ "text": "Hello! How can I help you today?" }]
      },
      "finishReason": "STOP",
      "index": 0
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 3,
    "candidatesTokenCount": 9,
    "thoughtsTokenCount": 0,
    "totalTokenCount": 12
  },
  "modelVersion": "gemini-2.5-pro",
  "responseId": "abc123"
}

Response fields

Streaming

Change the action to streamGenerateContent and add ?alt=sse to receive an SSE event stream. This site always answers with SSE, even without ?alt=sse (Google returns a JSON array in that case). In the SDKs, use generate_content_stream (Python) or generateContentStream (Node.js).

cURL

curl -N "https://tokenfunc.com/v1beta/models/gemini-2.5-pro:streamGenerateContent?alt=sse" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: sk-xxxxxxxxxxxxxxxx" \
  -d '{"contents": [{"role": "user", "parts": [{"text": "Write a four-line poem about autumn"}]}]}'

Python

for chunk in client.models.generate_content_stream(model="gemini-2.5-pro", contents="Write a four-line poem about autumn"):
    print(chunk.text, end="", flush=True)

Node.js

const stream = await ai.models.generateContentStream({
  model: 'gemini-2.5-pro',
  contents: 'Write a four-line poem about autumn',
})
for await (const chunk of stream) process.stdout.write(chunk.text ?? '')

List models

GET https://tokenfunc.com/v1beta/models returns the models your key can use, in Gemini format:

curl "https://tokenfunc.com/v1beta/models" -H "x-goog-api-key: sk-xxxxxxxxxxxxxxxx"

Good to know