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

# Gemini Text generation

## Request

<CodeGroup>
  ```shellscript cURL theme={null}
  curl --location 'https://api.znapai.com/gemini/v1beta/models/gemini-3.1-flash-lite-preview:generateContent' \
  --header 'x-goog-api-key: $ZnapAI_API_KEY' \
  --header 'Content-Type: application/json' \
  --header 'spend-logs-metadata: {"user_id": "user-123", "project_id": "proj_abc", "env": "production"}' \
  --data '{
      "contents": [{
        "parts": [{"text": "Say hello"}]
      }]
    }'
  ```
</CodeGroup>

## Response

```json theme={null}
{
    "candidates": [
        {
            "content": {
                "parts": [
                    {
                        "text": "Hello! How can I help you today?",
                        "thoughtSignature": "EjQKMgG+Pvb77bf2HCbvhPqtGFBZnNbcz3s5bMch0bEGM796BQfxY+30wIBcyFIObyExxedG"
                    }
                ],
                "role": "model"
            },
            "finishReason": "STOP",
            "index": 0
        }
    ],
    "usageMetadata": {
        "promptTokenCount": 2,
        "candidatesTokenCount": 9,
        "totalTokenCount": 11,
        "promptTokensDetails": [
            {
                "modality": "TEXT",
                "tokenCount": 2
            }
        ]
    },
    "modelVersion": "gemini-3.1-flash-lite-preview",
    "responseId": "73HeadnqD7_Zg8UP5tae2Q0"
}
```

***

## Parameters

<ParamField path="spend-logs-metadata" type="header" required={false}>
  An optional header used for spend logging metadata, containing JSON properties like `user_id`, `project_id`, and `env`.
</ParamField>

<ParamField path="contents" type="array" required>
  The conversation history or input prompts as an array of content objects.

  <Expandable title="contents[]" defaultOpen="True">
    <ResponseField name="role" type="string">
      The role of the creator of the content (e.g. `"user"` or `"model"`).
    </ResponseField>

    <ResponseField name="parts" type="array" required>
      An ordered list of parts that constitute a single message turn.

      <Expandable title="parts[]" defaultOpen="True">
        <ResponseField name="text" type="string">
          The text prompt or response content.
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ParamField>

<ParamField path="systemInstruction" type="object">
  System instructions that provide context, rules, or guidelines to the model.

  <Expandable title="systemInstruction" defaultOpen="False">
    <ResponseField name="parts" type="array" required>
      An ordered list of parts that constitute the system instruction.

      <Expandable title="parts[]">
        <ResponseField name="text" type="string">
          The text content of the system instruction.
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ParamField>

<ParamField path="generationConfig" type="object">
  Configuration options for model generation and outputs.

  <Expandable title="generationConfig" defaultOpen="False">
    <ResponseField name="temperature" type="number">
      Controls the randomness of the output.
    </ResponseField>

    <ResponseField name="topP" type="number">
      The maximum cumulative probability of tokens to consider when sampling.
    </ResponseField>

    <ResponseField name="topK" type="integer">
      The maximum number of tokens to consider when sampling.
    </ResponseField>

    <ResponseField name="candidateCount" type="integer">
      Number of generated responses to return.
    </ResponseField>

    <ResponseField name="maxOutputTokens" type="integer">
      The maximum number of tokens to include in a candidate.
    </ResponseField>

    <ResponseField name="stopSequences" type="array">
      A list of strings that tell the model to stop generating text.
    </ResponseField>
  </Expandable>
</ParamField>

<ParamField path="tools" type="array">
  A list of `Tools` the model may use to generate the next response. Supported tools are function declarations and code execution.

  <Expandable title="tools[]" defaultOpen="False">
    <ResponseField name="function_declarations" type="array">
      A list of function declarations the model can call.

      <Expandable title="function_declarations[]">
        <ResponseField name="name" type="string" required>
          The name of the function to call.
        </ResponseField>

        <ResponseField name="description" type="string">
          A description of what the function does.
        </ResponseField>

        <ResponseField name="parameters" type="object">
          Describes the parameters for the function in JSON Schema format.

          <Expandable title="parameters">
            <ResponseField name="type" type="string">
              The type of the parameters object. Usually `"object"`.
            </ResponseField>

            <ResponseField name="properties" type="object">
              A map of parameter names to their schema definitions.
            </ResponseField>

            <ResponseField name="required" type="array">
              List of required parameter names.
            </ResponseField>
          </Expandable>
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="code_execution" type="object">
      Enables the model to execute code as part of generation. Pass an empty object `{}` to enable.
    </ResponseField>
  </Expandable>
</ParamField>

<ParamField path="toolConfig" type="object">
  Tool configuration for any `Tool` specified in the request.

  <Expandable title="toolConfig" defaultOpen="False">
    <ResponseField name="function_calling_config" type="object">
      Configuration for function calling behavior.

      <Expandable title="function_calling_config">
        <ResponseField name="mode" type="string">
          Controls how the model uses the provided functions. One of:

          * `"AUTO"` — model decides whether to call a function or respond in text
          * `"ANY"` — model must call one of the provided functions
          * `"NONE"` — model must not call any functions
        </ResponseField>

        <ResponseField name="allowed_function_names" type="array">
          Optional. When `mode` is `"ANY"`, limits the model to only call functions from this list.
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ParamField>

<ParamField path="safetySettings" type="array">
  A list of unique safety settings for blocking unsafe content.

  <Expandable title="safetySettings[]" defaultOpen="False">
    <ResponseField name="category" type="string">
      The category for this setting (e.g. `HARM_CATEGORY_HATE_SPEECH`).
    </ResponseField>

    <ResponseField name="threshold" type="string">
      Block threshold for this category (e.g. `BLOCK_MEDIUM_AND_ABOVE`).
    </ResponseField>
  </Expandable>
</ParamField>

***

## Params to Avoid

| Param                 | Reason                                                                       |
| --------------------- | ---------------------------------------------------------------------------- |
| `model`               | Model is specified in the URL path, not in the request body                  |
| `messages`            | Native Gemini API uses `contents`, not `messages`                            |
| `max_tokens`          | Use `generationConfig.maxOutputTokens` instead                               |
| `temperature`         | Use `generationConfig.temperature` instead                                   |
| `top_p`               | Use `generationConfig.topP` instead                                          |
| `top_k`               | Use `generationConfig.topK` instead                                          |
| `stop`                | Use `generationConfig.stopSequences` instead                                 |
| `presence_penalty`    | Not natively supported by Gemini                                             |
| `frequency_penalty`   | Not natively supported by Gemini                                             |
| `spend-logs-metadata` | This metadata must be passed as an HTTP header, not in the JSON request body |
