Generate Content
/v1beta/models/{model}:generateContentGenerates content using Google Gemini API format
On this page
AnyPath supports the native Google Gemini API format for Gemini models.
Path Parameters
Parameter model
Model name (e.g., gemini-2.5-pro, gemini-2.5-flash).
Query Parameters
Parameter key
API key (alternative to header authentication).
Authentication
Gemini endpoints support multiple authentication methods:
?key=YOUR_API_KEYquery parameterx-goog-api-key: YOUR_API_KEYheaderAuthorization: Bearer YOUR_API_KEYheader
Request Body
Parameter contents
Conversation contents.
Each content object contains:
role(string):userormodelparts(array): Content parts. AnyPath supports:- text parts:
{ "text": "..." } - inline media parts:
inlineData/inline_data - URL-based file parts:
fileData/file_data
- text parts:
For media parts, AnyPath currently accepts image MIME types. For production traffic, prefer URL-based fileData / file_data media parts with a public https URL.
Parameter systemInstruction
System instruction for the model.
Parameter generationConfig
Generation configuration:
temperature(number): Sampling temperaturetopP(number): Nucleus sampling probabilitytopK(integer): Top-K samplingmaxOutputTokens(integer): Maximum output tokensstopSequences(array): Stop sequences
Parameter safetySettings
Safety filter settings.
Response
Response Field candidates
Generated content candidates.
Response Field usageMetadata
Token usage information.
Request Example
curl -X POST "https://api.anypath.dev/v1beta/models/gemini-2.5-pro:generateContent?key=sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"parts": [{"text": "Hello, Gemini!"}]
}
],
"generationConfig": {
"temperature": 0.7,
"maxOutputTokens": 1024
}
}'
import google.generativeai as genai
genai.configure(
api_key="sk-your-api-key",
transport="rest",
client_options={"api_endpoint": "api.anypath.dev"}
)
model = genai.GenerativeModel("gemini-2.5-pro")
response = model.generate_content("Hello, Gemini!")
print(response.text)
import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI("sk-your-api-key", {
baseUrl: "https://api.anypath.dev"
});
const model = genAI.getGenerativeModel({ model: "gemini-2.5-pro" });
const result = await model.generateContent("Hello, Gemini!");
console.log(result.response.text());
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
payload := map[string]interface{}{
"contents": []map[string]interface{}{
{
"parts": []map[string]string{
{"text": "Hello, Gemini!"},
},
},
},
"generationConfig": map[string]interface{}{
"temperature": 0.7,
"maxOutputTokens": 1024,
},
}
jsonData, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST",
"https://api.anypath.dev/v1beta/models/gemini-2.5-pro:generateContent?key=sk-your-api-key",
bytes.NewBuffer(jsonData))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
<?php
$payload = [
'contents' => [
[
'parts' => [
['text' => 'Hello, Gemini!']
]
]
],
'generationConfig' => [
'temperature' => 0.7,
'maxOutputTokens' => 1024
]
];
$ch = curl_init('https://api.anypath.dev/v1beta/models/gemini-2.5-pro:generateContent?key=sk-your-api-key');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json'
],
CURLOPT_POSTFIELDS => json_encode($payload)
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
echo $data['candidates'][0]['content']['parts'][0]['text'];
Vision Input Example
For Gemini multimodal requests, place media inside contents[].parts[] using either inline bytes or URL-based file references.
Supported media categories:
- image
For inline media, use either inlineData or inline_data and pass Base64-encoded file bytes.
For URL-based media, use either fileData or file_data and pass a public https URL.
Image Input Example
Use inline image bytes:
{
"contents": [
{
"role": "user",
"parts": [
{ "text": "Please describe this image." },
{
"inlineData": {
"mimeType": "image/jpeg",
"data": "/9j/4AAQSkZJRgABAQ..."
}
}
]
}
]
}
Use an image URL:
{
"contents": [
{
"role": "user",
"parts": [
{ "text": "Please describe this image." },
{
"fileData": {
"mimeType": "image/jpeg",
"fileUri": "https://example.com/demo.jpg"
}
}
]
}
]
}
Response Example
{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{"text": "Hello! How can I assist you today?"}
]
},
"finishReason": "STOP",
"safetyRatings": [
{"category": "HARM_CATEGORY_HARASSMENT", "probability": "NEGLIGIBLE"}
]
}
],
"usageMetadata": {
"promptTokenCount": 5,
"candidatesTokenCount": 10,
"totalTokenCount": 15
}
}
Error Response Example
{
"error": {
"message": "API key spending limit exceeded.",
"type": "spending_limit_exceeded",
"code": "spending_limit_exceeded"
}
}
{
"error": {
"message": "The requested model does not exist or is not available.",
"type": "model_not_found",
"code": "model_not_found"
}
}