TokenCode is compatible with the Google Gemini API protocol. You can use the Google AI SDK or any Gemini-compatible client to connect directly.
https://tokencode.dev
The Gemini protocol uses URL query parameters for authentication:
Header authentication is also supported:
Gemini-compatible content generation endpoint.
curl "https://tokencode.dev/v1beta/models/gemini-2.5-pro:generateContent?key=sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"parts": [
{"text": "Explain quantum computing"}
]
}
],
"generationConfig": {
"temperature": 0.7,
"maxOutputTokens": 1024
}
}'
Request parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| contents | array | Yes | Content array containing conversation history |
| generationConfig | object | No | Generation configuration |
| generationConfig.temperature | number | No | Sampling temperature (0-2) |
| generationConfig.maxOutputTokens | integer | No | Maximum output tokens |
| generationConfig.topP | number | No | Nucleus sampling probability |
| generationConfig.topK | integer | No | Top-K sampling |
| generationConfig.stopSequences | array | No | Stop sequences |
| systemInstruction | object | No | System instruction |
| tools | array | No | Function Calling tool definitions |
Response example:
{
"candidates": [
{
"content": {
"parts": [
{"text": "Quantum computing is a type of computing that leverages quantum mechanics..."}
],
"role": "model"
},
"finishReason": "STOP",
"index": 0
}
],
"usageMetadata": {
"promptTokenCount": 25,
"candidatesTokenCount": 128,
"totalTokenCount": 153
},
"modelVersion": "gemini-2.5-pro"
}
Streaming content generation endpoint.
curl "https://tokencode.dev/v1beta/models/gemini-2.5-pro:streamGenerateContent?key=sk-your-api-key&alt=sse" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"parts": [
{"text": "Explain quantum computing"}
]
}
]
}'
Streaming responses use SSE format, with each event containing partial generated content.
Returns the list of available Gemini models.
curl "https://tokencode.dev/v1beta/models?key=sk-your-api-key"
When calling non-Google models through the Gemini protocol endpoint, TokenCode automatically performs protocol conversion:
import google.generativeai as genai
genai.configure(
api_key="sk-your-api-key",
client_options={"api_endpoint": "https://tokencode.dev"}
)
model = genai.GenerativeModel("gemini-2.5-pro")
response = model.generate_content("Hello!")
print(response.text)
const { GoogleGenerativeAI } = require("@google/generative-ai");
const genAI = new GoogleGenerativeAI("sk-your-api-key");
// Set custom base URL
const model = genAI.getGenerativeModel({ model: "gemini-2.5-pro" });
Gemini natively supports multimodal input:
model = genai.GenerativeModel("gemini-2.5-pro")
response = model.generate_content([
"Describe this image",
{"inline_data": {"mime_type": "image/png", "data": "<base64-encoded-image>"}}
])
Error responses follow the Gemini error format:
{
"error": {
"code": 400,
"message": "API key not valid",
"status": "INVALID_ARGUMENT"
}
}
| HTTP Status Code | Meaning |
|---|---|
| 400 | Invalid request parameters |
| 401 | Authentication failed |
| 403 | Insufficient permissions |
| 404 | Model not found |
| 429 | Rate limit or insufficient balance |
| 500 | Internal server error |