> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.beatapi.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.beatapi.io/_mcp/server.

# Generate text content with a Gemini-compatible request

POST https://api.beatapi.io/v1beta/models/{model}:{action}
Content-Type: application/json

Gemini-compatible endpoint for generateContent and streamGenerateContent. The BeatAPI key is removed before forwarding.

Reference: https://docs.beatapi.io/api-reference/gpt-5-6/text/generate-gemini-compatible-content

## Authentication

- `x-goog-api-key` header (required) — Gemini-compatible API key header. Use a BeatAPI API key.
- `Authorization` header (bearer token, required) — Send your API key as `Authorization: Bearer <BEATAPI_API_KEY>`.

## Request

### Path parameters

- `model` (string, required) — Public text model id exposed by BeatAPI. Call GET /v1/models to discover the models enabled for your environment.
- `action` (enum, required)
  - Allowed values: `generateContent`, `streamGenerateContent`

### Body (application/json)

This endpoint expects a map from string to any.

- `map from string to any`

## Response

### 200

Gemini-compatible JSON response or server-sent event stream

- `map from string to any`

## Errors

### 400 Bad Request Error

Malformed JSON or an unsupported field (`bad_request`), or input refused by moderation (`content_policy_violation`). Not retryable unchanged.

- `TextError`

### 401 Unauthorized Error

No API key (`missing_api_key`), or a key that is wrong, expired, disabled or exhausted (`invalid_api_key`).

- `TextError`

### 402 Payment Required Error

Insufficient balance (`insufficient_credits`). The account balance is zero or below the price of this request.

- `TextError`

### 403 Forbidden Error

The key or account is not permitted to use this model (`forbidden`), for example a model that is not available on free credit.

- `TextError`

### 404 Not Found Error

Unknown model (`not_found`). List the enabled models with `GET /v1/models`.

- `TextError`

### 429 Too Many Requests Error

Too many requests (`rate_limit_exceeded`, including the free-model limits). Retry after `Retry-After` seconds.

- `TextError`

### 500 Internal Server Error

Unexpected internal error (`internal_error`). Retryable.

- `TextError`

### 503 Service Unavailable Error

The request could not be completed (`processing_unavailable`, `processing_timeout` or `processing_failed`). Nothing was charged. Retry with backoff.

- `TextError`

## Types

### OpenAITextError

- `error` (OpenAiTextErrorError, required)

### AnthropicTextError

- `type` ("error", required)
- `error` (AnthropicTextErrorError, required)

### OpenAiTextErrorError

- `message` (string, required) — English sentence that states the cause.
- `type` (string, optional)
- `code` (string, optional) — BeatAPI error code, for example `insufficient_credits` or `rate_limit_exceeded`.

### AnthropicTextErrorError

- `type` (string, required)
- `message` (string, required) — English sentence that states the cause.

## Examples

**Request**

```json
{
  "contents": [
    {
      "parts": [
        {
          "text": "Explain this architecture decision in three concise bullets."
        }
      ],
      "role": "user"
    }
  ]
}
```

**Response**

```json
{}
```

**SDK Code**

```python Text_generateGeminiCompatibleContent_example
import requests

url = "https://api.beatapi.io/v1beta/models/model:generateContent"

payload = { "contents": [
        {
            "parts": [{ "text": "Explain this architecture decision in three concise bullets." }],
            "role": "user"
        }
    ] }
headers = {
    "x-goog-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Text_generateGeminiCompatibleContent_example
const url = 'https://api.beatapi.io/v1beta/models/model:generateContent';
const options = {
  method: 'POST',
  headers: {'x-goog-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"contents":[{"parts":[{"text":"Explain this architecture decision in three concise bullets."}],"role":"user"}]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Text_generateGeminiCompatibleContent_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.beatapi.io/v1beta/models/model:generateContent"

	payload := strings.NewReader("{\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"text\": \"Explain this architecture decision in three concise bullets.\"\n        }\n      ],\n      \"role\": \"user\"\n    }\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-goog-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Text_generateGeminiCompatibleContent_example
require 'uri'
require 'net/http'

url = URI("https://api.beatapi.io/v1beta/models/model:generateContent")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-goog-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"text\": \"Explain this architecture decision in three concise bullets.\"\n        }\n      ],\n      \"role\": \"user\"\n    }\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java Text_generateGeminiCompatibleContent_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.beatapi.io/v1beta/models/model:generateContent")
  .header("x-goog-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"text\": \"Explain this architecture decision in three concise bullets.\"\n        }\n      ],\n      \"role\": \"user\"\n    }\n  ]\n}")
  .asString();
```

```php Text_generateGeminiCompatibleContent_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.beatapi.io/v1beta/models/model:generateContent', [
  'body' => '{
  "contents": [
    {
      "parts": [
        {
          "text": "Explain this architecture decision in three concise bullets."
        }
      ],
      "role": "user"
    }
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-goog-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Text_generateGeminiCompatibleContent_example
using RestSharp;

var client = new RestClient("https://api.beatapi.io/v1beta/models/model:generateContent");
var request = new RestRequest(Method.POST);
request.AddHeader("x-goog-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"text\": \"Explain this architecture decision in three concise bullets.\"\n        }\n      ],\n      \"role\": \"user\"\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Text_generateGeminiCompatibleContent_example
import Foundation

let headers = [
  "x-goog-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["contents": [
    [
      "parts": [["text": "Explain this architecture decision in three concise bullets."]],
      "role": "user"
    ]
  ]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.beatapi.io/v1beta/models/model:generateContent")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```