Docs

Generate Content

POST/v1beta/models/{model}:generateContent

Generates content using Google Gemini API format

On this page
  1. Path Parameters
  2. Query Parameters
  3. Authentication
  4. Request Body
  5. Response
  6. Request Example
  7. Vision Input Example
  8. Image Input Example
  9. Response Example
  10. Error Response Example

AnyPath supports the native Google Gemini API format for Gemini models.

Path Parameters

Parameter model

Type: string

Location: path

Required: yes

Model name (e.g., gemini-2.5-pro, gemini-2.5-flash).

Query Parameters

Parameter key

Type: string

Location: query

API key (alternative to header authentication).

Authentication

Gemini endpoints support multiple authentication methods:

  • ?key=YOUR_API_KEY query parameter
  • x-goog-api-key: YOUR_API_KEY header
  • Authorization: Bearer YOUR_API_KEY header

Request Body

Parameter contents

Type: array

Location: body

Required: yes

Conversation contents.

Each content object contains:

  • role (string): user or model
  • parts (array): Content parts. AnyPath supports:
    • text parts: { "text": "..." }
    • inline media parts: inlineData / inline_data
    • URL-based file parts: fileData / file_data

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

Type: object

Location: body

System instruction for the model.

Parameter generationConfig

Type: object

Location: body

Generation configuration:

  • temperature (number): Sampling temperature
  • topP (number): Nucleus sampling probability
  • topK (integer): Top-K sampling
  • maxOutputTokens (integer): Maximum output tokens
  • stopSequences (array): Stop sequences

Parameter safetySettings

Type: array

Location: body

Safety filter settings.

Response

Response Field candidates

Type: array

Generated content candidates.

Response Field usageMetadata

Type: object

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"
  }
}