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

# POST /api/generate — Generate JSON-LD from a Schema Type

> Generate valid JSON-LD by providing a Schema.org type name and field values. Supports guest and authenticated requests with different rate limit tiers.

The generate endpoint builds a valid JSON-LD object from a Schema.org type name and a set of field values you provide. You can call it without authentication as a guest, or as an authenticated user to apply generation against your account's usage quota and benefit from higher rate limits.

This endpoint is useful when you want to programmatically generate structured data — for example, as part of a content publishing pipeline or a custom schema tooling workflow.

## Endpoint

```
POST https://schemagen.io/api/generate
```

## Request body

<ParamField body="type" type="string" required>
  The Schema.org type name to generate (e.g., `Article`, `Product`, `LocalBusiness`, `FAQPage`). The value must match a type supported by SchemaGen. If the type is unrecognized, the API returns `400` with a list of supported types.
</ParamField>

<ParamField body="data" type="object" required>
  An object containing the field values for the schema. The accepted fields depend on the `type` you specify. Required fields for the given type must be present or the API returns a validation error.
</ParamField>

## Response

<ResponseField name="jsonLd" type="object">
  The generated JSON-LD object, ready to embed in a `<script type="application/ld+json">` tag. Includes `@context` set to `https://schema.org` and `@type` matching the requested type.
</ResponseField>

## Code examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://schemagen.io/api/generate" \
    -H "Content-Type: application/json" \
    -d '{
      "type": "Article",
      "data": {
        "headline": "How structured data improves SEO",
        "author": "Jane Smith",
        "datePublished": "2026-05-08",
        "url": "https://example.com/blog/structured-data-seo"
      }
    }'
  ```

  ```javascript JavaScript (fetch) theme={null}
  const response = await fetch('https://schemagen.io/api/generate', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      type: 'Article',
      data: {
        headline: 'How structured data improves SEO',
        author: 'Jane Smith',
        datePublished: '2026-05-08',
        url: 'https://example.com/blog/structured-data-seo',
      },
    }),
  });

  const { jsonLd } = await response.json();
  console.log(jsonLd);
  ```
</CodeGroup>

## Example response

```json theme={null}
{
  "jsonLd": {
    "@context": "https://schema.org",
    "@type": "Article",
    "headline": "How structured data improves SEO",
    "author": {
      "@type": "Person",
      "name": "Jane Smith"
    },
    "datePublished": "2026-05-08",
    "url": "https://example.com/blog/structured-data-seo"
  }
}
```

## Error responses

### 400 — invalid type

If you pass an unsupported `type`, the API returns `400` with a message listing valid types:

```json theme={null}
{
  "error": "Invalid or missing schema type. Supported types: Article, Product, LocalBusiness, ..."
}
```

### 400 — validation failed

If your `data` object is missing required fields or contains invalid values for the given type, the API returns `400` with a structured breakdown:

```json theme={null}
{
  "error": "Validation failed",
  "details": {
    "headline": {
      "_errors": ["Required"]
    }
  }
}
```

### 429 — rate limit exceeded

```json theme={null}
{
  "error": "Too many requests. Please wait a moment."
}
```

### 403 — usage limit reached

Authenticated users whose plan quota is exhausted receive a `403` with error code `limit_reached`:

```json theme={null}
{
  "error": "limit_reached"
}
```

<Info>
  Guest (unauthenticated) callers are not subject to usage quotas — only IP-based rate limits. If you need to call this endpoint at high volume from a server, authenticate your requests to get a per-user rate limit and quota tracking against your plan.
</Info>

<Warning>
  Usage is incremented only after a successful generation. Failed requests (400, 429, 403) do not count against your plan quota.
</Warning>
