# Generate Content

Generate content using the Google Gemini-compatible request format.

- Source: https://www.unifyllm.com/docs/api-reference/generate-content/
- Language: en

## Endpoint

```http
POST https://api.unifyllm.top/v1beta/models/{model}:{GenerateContentType}
```

Use the authentication and headers shown in the request examples. Content-Type: application/json

[Integration guide](https://www.unifyllm.com/docs/gemini-image/)

## Parameters

| Field | Location | Type | Required | Description | Allowed values | Example |
| --- | --- | --- | --- | --- | --- | --- |
| model | path | string | yes | Model identifier used for this request. |  | gemini-3.5-flash |
| GenerateContentType | path | string | yes | Gemini-compatible generation action. | generateContent, streamGenerateContent | generateContent |
| key | query | string | no | Optional request parameter. |  | {{key}} |
| contents | body | array | yes | Gemini-compatible content payload. |  |  |

## Text

```json
{
  "contents": [
    {
      "parts": [
        {
          "text": "Write a story about a magic backpack."
        }
      ]
    }
  ]
}
```

### cURL

```bash
curl --request POST \
  --url 'https://api.unifyllm.top/v1beta/models/gemini-3.5-flash:generateContent' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "contents": [
    {
      "parts": [
        {
          "text": "Write a story about a magic backpack."
        }
      ]
    }
  ]
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1beta/models/gemini-3.5-flash:generateContent", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <YOUR_API_KEY>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "contents": [
      {
        "parts": [
          {
            "text": "Write a story about a magic backpack."
          }
        ]
      }
    ]
  }),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import json
import requests

response = requests.post(
    "https://api.unifyllm.top/v1beta/models/gemini-3.5-flash:generateContent",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=json.loads("{\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"text\": \"Write a story about a magic backpack.\"\n        }\n      ]\n    }\n  ]\n}")
)
response.raise_for_status()
print(response.json())
```

## Image Input

```json
{
  "contents": [
    {
      "parts": [
        {
          "inline_data": {
            "mime_type": "image/jpeg",
            "data": "<BASE64_DATA>"
          }
        },
        {
          "text": "Caption this image."
        }
      ]
    }
  ]
}
```

### cURL

```bash
curl --request POST \
  --url 'https://api.unifyllm.top/v1beta/models/gemini-3.5-flash:generateContent' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "contents": [
    {
      "parts": [
        {
          "inline_data": {
            "mime_type": "image/jpeg",
            "data": "<BASE64_DATA>"
          }
        },
        {
          "text": "Caption this image."
        }
      ]
    }
  ]
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1beta/models/gemini-3.5-flash:generateContent", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <YOUR_API_KEY>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "contents": [
      {
        "parts": [
          {
            "inline_data": {
              "mime_type": "image/jpeg",
              "data": "<BASE64_DATA>"
            }
          },
          {
            "text": "Caption this image."
          }
        ]
      }
    ]
  }),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import json
import requests

response = requests.post(
    "https://api.unifyllm.top/v1beta/models/gemini-3.5-flash:generateContent",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=json.loads("{\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"inline_data\": {\n            \"mime_type\": \"image/jpeg\",\n            \"data\": \"<BASE64_DATA>\"\n          }\n        },\n        {\n          \"text\": \"Caption this image.\"\n        }\n      ]\n    }\n  ]\n}")
)
response.raise_for_status()
print(response.json())
```

## Response examples

### Example 1 — HTTP 200

```json
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "xxx",
            "thoughtSignature": "xxx"
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP"
    }
  ],
  "modelVersion": "gemini-3.5-flash",
  "responseId": "Qf9VavfVA9DVz7IP-NjW6AY",
  "usageMetadata": {
    "candidatesTokenCount": 1978,
    "promptTokenCount": 9,
    "thoughtsTokenCount": 1339,
    "totalTokenCount": 3326
  }
}
```
