> For the list of every page, fetch /llms.txt. The API contract is the OpenAPI file linked from the API reference.

# Generate content (Gemini generateContent format)

POST https%3A%2F%2Fapi.usemeadow.ai/v1beta/models/{model}:generateContent
Content-Type: application/json

Use this when your client speaks Google's Gemini API: gemini-cli, or a Google
GenAI SDK with a custom base URL. Set the base URL to `MEADOW_BASE_URL` and the
API key to a Meadow key. Send the key in `x-goog-api-key`, where the Gemini
clients send it, or in `Authorization: Bearer`. Meadow also reads the `key` query
parameter, but avoid it: query strings end up in proxy, browser and server logs.
Meadow drops the key before it logs, records or calls the vendor, and no answer
repeats the request URL.

The same two methods are served under `/v1`, the default API version of the
Google GenAI SDKs: `POST /v1/models/{model}:generateContent` and
`POST /v1/models/{model}:streamGenerateContent`. Meadow calls Google AI Studio
with the version you used. It calls Vertex on `v1`.

`{model}` is a Meadow model id. A catalog id such as `gemini-3.8-flash` routes to
`google`, then `vertex`. `google/<id>` pins Google AI Studio and `vertex/<id>`
pins Vertex. Claude, GPT and Grok models are not served in this format.

The body is Google's `GenerateContentRequest` and goes to the vendor unchanged.
The response is Google's `GenerateContentResponse`, unchanged. Meadow converts
nothing between this format and the other three. It reads `usageMetadata` to
record tokens and cost, and `generationConfig.maxOutputTokens` and
`candidateCount` to estimate a call. A key with a token limit or a dollar limit
needs `generationConfig.maxOutputTokens`. Meadow's own `models` and `provider`
fields are not read on this route: project routing applies.

Meadow's own errors on this route use Google's envelope,
`{"error": {"code", "message", "status", "details"}}`, with Meadow's error code
as the `reason` of an `ErrorInfo` detail. A vendor error is passed through as
the vendor sent it.

`countTokens`, `embedContent`, `batchEmbedContents` and `batchGenerateContent`
answer 501 in Google's envelope. File upload, files, cached contents, batches and
the Live API WebSocket paths answer 404 in Google's envelope. None reaches a
vendor. Google's model list is not served.

Scope: `models`.

```bash
curl -sS "$MEADOW_BASE_URL/v1beta/models/gemini-3.8-flash:generateContent" \
  -H "x-goog-api-key: $MEADOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"contents":[{"role":"user","parts":[{"text":"Reply with the single word: meadow"}]}],
       "generationConfig":{"maxOutputTokens":16}}'
```

Reference: https://docs.usemeadow.ai/api-endpoints/models/generate-content

## Authentication

- `Authorization` header (bearer token, required) — A Meadow API key, sent as `Authorization: Bearer mdw_...`. The header `x-api-key: mdw_...` is accepted in its place.

## Request

### Path parameters

- `model` (string, required) — A Meadow model id, for example `gemini-3.8-flash`, `google/gemini-3.8-flash` or `vertex/gemini-3.8-flash`.

### Body (application/json)

This endpoint expects a map from string to any.

- `map from string to any`

## Response

### 200

The vendor's `GenerateContentResponse`, unchanged. Usage is in `usageMetadata`.

- `map from string to any`

## Errors

### 400 Bad Request Error

Either Meadow refused the request, or the vendor did. A Meadow 400 is in Google's envelope. A vendor 400 has the vendor's own body and carries `x-meadow-provider`.

- `error` (GoogleErrorError, required)

## Types

### GoogleErrorError

- `code` (integer, required) — The HTTP status.
- `message` (string, required) — A sentence for people. It can change
- `status` (string, required) — The `google.rpc.Code` name, for example `INVALID_ARGUMENT`.
- `details` (list of map from string to any, optional)

## Examples

### Served by Google AI Studio (written by hand, not captured live)

**Response**

```json
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "meadow"
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP"
    }
  ],
  "modelVersion": "gemini-3.8-flash",
  "responseId": "rsp-0000000001",
  "usageMetadata": {
    "candidatesTokenCount": 2,
    "promptTokenCount": 9,
    "totalTokenCount": 11
  }
}
```

**SDK Code**

```python Served by Google AI Studio (written by hand, not captured live)
import requests

url = "https://api.example.com/v1beta/models/model:generateContent"

headers = {"Authorization": "Bearer <token>"}

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

print(response.json())
```

```javascript Served by Google AI Studio (written by hand, not captured live)
const url = 'https://api.example.com/v1beta/models/model:generateContent';
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};

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

```go Served by Google AI Studio (written by hand, not captured live)
package main

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

func main() {

	url := "https://api.example.com/v1beta/models/model:generateContent"

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

	req.Header.Add("Authorization", "Bearer <token>")

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

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

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

}
```

```ruby Served by Google AI Studio (written by hand, not captured live)
require 'uri'
require 'net/http'

url = URI("https://api.example.com/v1beta/models/model:generateContent")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'

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

```java Served by Google AI Studio (written by hand, not captured live)
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.example.com/v1beta/models/model:generateContent")
  .header("Authorization", "Bearer <token>")
  .asString();
```

```php Served by Google AI Studio (written by hand, not captured live)
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.example.com/v1beta/models/model:generateContent', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

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

```csharp Served by Google AI Studio (written by hand, not captured live)
using RestSharp;

var client = new RestClient("https://api.example.com/v1beta/models/model:generateContent");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift Served by Google AI Studio (written by hand, not captured live)
import Foundation

let headers = ["Authorization": "Bearer <token>"]

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

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()
```

### Let Meadow pick the vendor

**Request**

```json
{
  "contents": [
    {
      "parts": [
        {
          "text": "Reply with the single word: meadow"
        }
      ],
      "role": "user"
    }
  ],
  "generationConfig": {
    "maxOutputTokens": 16
  }
}
```

**Response**

```json
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "meadow"
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP"
    }
  ],
  "modelVersion": "gemini-3.8-flash",
  "responseId": "rsp-0000000001",
  "usageMetadata": {
    "candidatesTokenCount": 2,
    "promptTokenCount": 9,
    "totalTokenCount": 11
  }
}
```

**SDK Code**

```python Let Meadow pick the vendor
import requests

url = "https://api.example.com/v1beta/models/model:generateContent"

payload = {
    "contents": [
        {
            "parts": [{ "text": "Reply with the single word: meadow" }],
            "role": "user"
        }
    ],
    "generationConfig": { "maxOutputTokens": 16 }
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Let Meadow pick the vendor
const url = 'https://api.example.com/v1beta/models/model:generateContent';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"contents":[{"parts":[{"text":"Reply with the single word: meadow"}],"role":"user"}],"generationConfig":{"maxOutputTokens":16}}'
};

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

```go Let Meadow pick the vendor
package main

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

func main() {

	url := "https://api.example.com/v1beta/models/model:generateContent"

	payload := strings.NewReader("{\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"text\": \"Reply with the single word: meadow\"\n        }\n      ],\n      \"role\": \"user\"\n    }\n  ],\n  \"generationConfig\": {\n    \"maxOutputTokens\": 16\n  }\n}")

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

	req.Header.Add("Authorization", "Bearer <token>")
	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 Let Meadow pick the vendor
require 'uri'
require 'net/http'

url = URI("https://api.example.com/v1beta/models/model:generateContent")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"text\": \"Reply with the single word: meadow\"\n        }\n      ],\n      \"role\": \"user\"\n    }\n  ],\n  \"generationConfig\": {\n    \"maxOutputTokens\": 16\n  }\n}"

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

```java Let Meadow pick the vendor
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.example.com/v1beta/models/model:generateContent")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"text\": \"Reply with the single word: meadow\"\n        }\n      ],\n      \"role\": \"user\"\n    }\n  ],\n  \"generationConfig\": {\n    \"maxOutputTokens\": 16\n  }\n}")
  .asString();
```

```php Let Meadow pick the vendor
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.example.com/v1beta/models/model:generateContent', [
  'body' => '{
  "contents": [
    {
      "parts": [
        {
          "text": "Reply with the single word: meadow"
        }
      ],
      "role": "user"
    }
  ],
  "generationConfig": {
    "maxOutputTokens": 16
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Let Meadow pick the vendor
using RestSharp;

var client = new RestClient("https://api.example.com/v1beta/models/model:generateContent");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"text\": \"Reply with the single word: meadow\"\n        }\n      ],\n      \"role\": \"user\"\n    }\n  ],\n  \"generationConfig\": {\n    \"maxOutputTokens\": 16\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Let Meadow pick the vendor
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "contents": [
    [
      "parts": [["text": "Reply with the single word: meadow"]],
      "role": "user"
    ]
  ],
  "generationConfig": ["maxOutputTokens": 16]
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/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()
```