> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anyone.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Gemini generateContent and streaming via Anyone

> Generate content using Google Gemini-compatible endpoints. Pass your Anyone API key as x-goog-api-key or as a query parameter named key.

Anyone exposes Google Gemini-compatible endpoints at the `/v1beta/models/{model}` path, matching the format used by the Google AI SDKs and the Gemini REST API. You authenticate with your Anyone API key using the `x-goog-api-key` header or a `key` query parameter — no Google credentials needed. Anyone routes the request to whichever upstream channel is configured for the model you specify in the URL path.

## Endpoints

| Method | Path                                           | Description                         |
| ------ | ---------------------------------------------- | ----------------------------------- |
| `POST` | `/v1beta/models/{model}:generateContent`       | Generate a response (non-streaming) |
| `POST` | `/v1beta/models/{model}:streamGenerateContent` | Generate a response as a stream     |

The model name is part of the URL path, not the request body. For example, to use `gemini-3.1-pro-preview`, send a `POST` to `/v1beta/models/gemini-3.1-pro-preview:generateContent`.

## Authentication

Pass your Anyone API key using either method:

**Header (recommended):**

```
x-goog-api-key: YOUR_TOKEN
```

**Query parameter:**

```
POST /v1beta/models/gemini-3.1-pro-preview:generateContent?key=YOUR_TOKEN
```

## Request parameters

<ParamField body="contents" type="object[]" required>
  The conversation history as an array of content objects. Each object has a `role` and a `parts` array.

  <Expandable title="content properties">
    <ParamField body="contents[].role" type="string">
      The role of the content author. Use `"user"` for user turns and `"model"` for model turns. Omit for single-turn requests.
    </ParamField>

    <ParamField body="contents[].parts" type="object[]" required>
      An array of content parts that make up this turn.

      <Expandable title="part properties">
        <ParamField body="contents[].parts[].text" type="string">
          A text part. Pass this for plain text input or to provide text alongside other modalities.
        </ParamField>

        <ParamField body="contents[].parts[].inlineData" type="object">
          Inline binary data (e.g. an image or audio clip encoded in base64).

          <Expandable title="inlineData properties">
            <ParamField body="contents[].parts[].inlineData.mimeType" type="string" required>
              The MIME type of the data, for example `"image/jpeg"`, `"audio/mp3"`, or `"video/mp4"`.
            </ParamField>

            <ParamField body="contents[].parts[].inlineData.data" type="string" required>
              Base64-encoded bytes.
            </ParamField>
          </Expandable>
        </ParamField>

        <ParamField body="contents[].parts[].fileData" type="object">
          Reference to a file by URI, for example a Google Cloud Storage URI or a Files API URI.

          <Expandable title="fileData properties">
            <ParamField body="contents[].parts[].fileData.mimeType" type="string">
              The MIME type of the file.
            </ParamField>

            <ParamField body="contents[].parts[].fileData.fileUri" type="string" required>
              The URI of the file.
            </ParamField>
          </Expandable>
        </ParamField>

        <ParamField body="contents[].parts[].functionCall" type="object">
          A function call the model wants to make. Contains `name` and `args`.
        </ParamField>

        <ParamField body="contents[].parts[].functionResponse" type="object">
          The result of a function call. Contains `name` and `response`.
        </ParamField>
      </Expandable>
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="systemInstruction" type="object">
  A system prompt. Structure is the same as a `contents` item: an object with a `parts` array. Only `text` parts are supported for system instructions.

  ```json theme={null}
  {
    "systemInstruction": {
      "parts": [{"text": "You are a helpful assistant."}]
    }
  }
  ```

  Also accepted as `system_instruction` (snake\_case).
</ParamField>

<ParamField body="generationConfig" type="object">
  Parameters that control how the model generates output. Also accepted as `generation_config`.

  <Expandable title="generationConfig properties">
    <ParamField body="generationConfig.temperature" type="number">
      Sampling temperature. Higher values are more creative; lower values are more deterministic.
    </ParamField>

    <ParamField body="generationConfig.topP" type="number">
      Nucleus sampling probability mass. Also accepted as `top_p`.
    </ParamField>

    <ParamField body="generationConfig.topK" type="number">
      Top-k sampling. Also accepted as `top_k`.
    </ParamField>

    <ParamField body="generationConfig.maxOutputTokens" type="integer">
      The maximum number of tokens to generate. Also accepted as `max_output_tokens`.
    </ParamField>

    <ParamField body="generationConfig.candidateCount" type="integer">
      Number of candidate responses to generate. Defaults to `1`.
    </ParamField>

    <ParamField body="generationConfig.stopSequences" type="string[]">
      Sequences at which the model stops generating. Also accepted as `stop_sequences`.
    </ParamField>

    <ParamField body="generationConfig.responseMimeType" type="string">
      The MIME type for the response. Use `"application/json"` to request JSON output. Also accepted as `response_mime_type`.
    </ParamField>

    <ParamField body="generationConfig.responseSchema" type="object">
      A JSON Schema that the response must conform to. Requires `responseMimeType` to be `"application/json"`. Also accepted as `response_schema`.
    </ParamField>

    <ParamField body="generationConfig.responseModalities" type="string[]">
      Output modalities to request, for example `["TEXT"]` or `["TEXT", "IMAGE"]`. Also accepted as `response_modalities`.
    </ParamField>

    <ParamField body="generationConfig.thinkingConfig" type="object">
      Configuration for extended thinking. Also accepted as `thinking_config`.

      <Expandable title="thinkingConfig properties">
        <ParamField body="generationConfig.thinkingConfig.includeThoughts" type="boolean">
          Whether to include the model's thoughts in the response. Also accepted as `include_thoughts`.
        </ParamField>

        <ParamField body="generationConfig.thinkingConfig.thinkingBudget" type="integer">
          Maximum number of tokens to use for thinking. Also accepted as `thinking_budget`.
        </ParamField>

        <ParamField body="generationConfig.thinkingConfig.thinkingLevel" type="string">
          Reasoning effort level: `"low"`, `"medium"`, or `"high"`. Also accepted as `thinking_level`.
        </ParamField>
      </Expandable>
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="tools" type="object[]">
  Tools the model may use. Supports `functionDeclarations`, `googleSearch`, `googleSearchRetrieval`, `codeExecution`, and `urlContext`.
</ParamField>

<ParamField body="toolConfig" type="object">
  Controls how the model selects tools.

  <Expandable title="toolConfig properties">
    <ParamField body="toolConfig.functionCallingConfig" type="object">
      Function calling configuration.

      <Expandable title="functionCallingConfig properties">
        <ParamField body="toolConfig.functionCallingConfig.mode" type="string">
          Function calling mode: `"AUTO"`, `"ANY"`, or `"NONE"`.
        </ParamField>

        <ParamField body="toolConfig.functionCallingConfig.allowedFunctionNames" type="string[]">
          When `mode` is `"ANY"`, restricts tool calls to this list of function names.
        </ParamField>
      </Expandable>
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="safetySettings" type="object[]">
  Override the default safety filters. Each entry specifies a `category` and `threshold`.
</ParamField>

## Response fields

<ResponseField name="candidates" type="object[]">
  An array of generated response candidates.

  <Expandable title="candidate properties">
    <ResponseField name="candidates[].content" type="object">
      The generated content.

      <Expandable title="content properties">
        <ResponseField name="candidates[].content.role" type="string">
          Always `"model"` for generated content.
        </ResponseField>

        <ResponseField name="candidates[].content.parts" type="object[]">
          An array of content parts. Each part has a `text` field for text output, or `functionCall` for tool invocations. Parts with `thought: true` contain the model's internal reasoning when thinking is enabled.
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="candidates[].finishReason" type="string">
      Why the model stopped. Common values: `"STOP"` (natural end), `"MAX_TOKENS"` (token limit), `"SAFETY"` (safety filter), `"RECITATION"`.
    </ResponseField>

    <ResponseField name="candidates[].index" type="integer">
      The index of this candidate.
    </ResponseField>

    <ResponseField name="candidates[].safetyRatings" type="object[]">
      Safety ratings for each harm category.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="usageMetadata" type="object">
  Token usage for the request.

  <Expandable title="usageMetadata properties">
    <ResponseField name="usageMetadata.promptTokenCount" type="integer">
      Tokens in the input `contents`.
    </ResponseField>

    <ResponseField name="usageMetadata.candidatesTokenCount" type="integer">
      Tokens in the generated candidates.
    </ResponseField>

    <ResponseField name="usageMetadata.totalTokenCount" type="integer">
      Total tokens used.
    </ResponseField>

    <ResponseField name="usageMetadata.thoughtsTokenCount" type="integer">
      Tokens used for thinking, when extended thinking is enabled.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="promptFeedback" type="object">
  Feedback about the prompt, including safety ratings and any block reason if the prompt was blocked.
</ResponseField>

## Examples

<Tabs>
  <Tab title="Non-streaming">
    <CodeGroup>
      ```bash cURL theme={null}
      curl "https://api.anyone.ai/v1beta/models/gemini-3.1-pro-preview:generateContent" \
        -H "x-goog-api-key: YOUR_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{
          "contents": [
            {
              "role": "user",
              "parts": [{"text": "Explain the difference between RAM and ROM."}]
            }
          ],
          "generationConfig": {
            "temperature": 0.7,
            "maxOutputTokens": 512
          }
        }'
      ```

      ```python Python (google-genai SDK) theme={null}
      import google.generativeai as genai

      genai.configure(
          api_key="YOUR_TOKEN",
          client_options={"api_endpoint": "https://api.anyone.ai"},
      )

      model = genai.GenerativeModel("gemini-3.1-pro-preview")
      response = model.generate_content("Explain the difference between RAM and ROM.")

      print(response.text)
      ```
    </CodeGroup>

    **Example response:**

    ```json theme={null}
    {
      "candidates": [
        {
          "content": {
            "role": "model",
            "parts": [
              {
                "text": "RAM (Random Access Memory) is volatile memory used for temporary storage while your computer is running..."
              }
            ]
          },
          "finishReason": "STOP",
          "index": 0,
          "safetyRatings": []
        }
      ],
      "usageMetadata": {
        "promptTokenCount": 11,
        "candidatesTokenCount": 142,
        "totalTokenCount": 153
      }
    }
    ```
  </Tab>

  <Tab title="Streaming">
    ```bash cURL theme={null}
    curl "https://api.anyone.ai/v1beta/models/gemini-3.1-pro-preview:streamGenerateContent" \
      -H "x-goog-api-key: YOUR_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{
        "contents": [
          {"role": "user", "parts": [{"text": "Count from 1 to 5."}]}
        ]
      }'
    ```

    The server returns a newline-delimited stream of JSON objects, each representing a partial response chunk. Each chunk has the same structure as a non-streaming response, with partial `candidates[].content.parts[].text`.
  </Tab>

  <Tab title="Multi-turn">
    ```bash cURL theme={null}
    curl "https://api.anyone.ai/v1beta/models/gemini-3.1-pro-preview:generateContent" \
      -H "x-goog-api-key: YOUR_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{
        "systemInstruction": {
          "parts": [{"text": "You are a geography expert."}]
        },
        "contents": [
          {"role": "user", "parts": [{"text": "What is the longest river in Africa?"}]},
          {"role": "model", "parts": [{"text": "The Nile is the longest river in Africa."}]},
          {"role": "user", "parts": [{"text": "How long is it in kilometers?"}]}
        ]
      }'
    ```
  </Tab>
</Tabs>

## Thinking models

Anyone supports Gemini thinking models, which perform additional reasoning before generating a response. You have three ways to enable thinking:

**1. Thinking model suffix** — append `-thinking` to any supported model name:

```bash theme={null}
POST /v1beta/models/gemini-3.1-pro-preview-thinking:generateContent
POST /v1beta/models/gemini-3.1-pro-preview-thinking:generateContent
```

**2. Effort suffix** — append `-low`, `-medium`, or `-high` for fine-grained control:

```bash theme={null}
POST /v1beta/models/gemini-3.1-pro-preview-high:generateContent
```

**3. `thinkingConfig` in `generationConfig`** — pass the configuration explicitly:

```json theme={null}
{
  "contents": [...],
  "generationConfig": {
    "thinkingConfig": {
      "includeThoughts": true,
      "thinkingBudget": 8192
    }
  }
}
```

When thinking is active, parts with `"thought": true` in the response contain the model's reasoning. These parts are not shown to end users by default — your application decides whether to display them.

<Tip>
  If you only need text output and do not want to process thinking parts, set `includeThoughts: false` and let the model reason internally without including those tokens in the response body.
</Tip>
