Skip to content

AI Content Generation

This page provides a thorough overview of AI-powered content generation in OpenReport, including setup, configuration, examples and details on required and optional properties.

Back to homepage


Overview

OpenReport allows to dynamically generate text and heading content using AI providers. Instead of specifying the "body" property manually or using "source", user can provide an "ai_prompt" property. OpenReport sends the prompt to the configured AI provider and uses the generated text as the component's body content.

This feature supports three AI providers:

  • OpenAI (e.g., GPT-4o, GPT-4o-mini)
  • Anthropic (e.g., Claude Sonnet, Claude Haiku)
  • Google Gemini (e.g., Gemini 2.0 Flash)

Setup

API Key

Before using AI content generation, set the API key for your chosen provider as an environment variable.

OpenAI:

export OPENAI_API_KEY="sk-..."

Anthropic:

export ANTHROPIC_API_KEY="sk-ant-..."

Google Gemini:

export GOOGLE_API_KEY="AI..."

On Windows, use set instead of export:

set OPENAI_API_KEY=sk-...

The API key must be set before running OpenReport. If the key is missing, OpenReport will raise an error with a clear message indicating which environment variable is expected.

Back to top


Configuration

ai_config

The "ai_config" instance is specified at the document level and configures the AI provider for all "ai_prompt" instances within that document.

document:
  name: report.docx
  ai_config:
    provider: openai
    model: gpt-4o-mini
  structure:
    # ...

Required properties

Property Type Description
provider string The AI provider to use. Available options: openai, anthropic, google.
model string The model identifier to use (e.g., gpt-4o-mini, claude-sonnet-4-5-20250929, gemini-2.0-flash).

ai_prompt

The "ai_prompt" property is specified on "text" or "heading" components. It replaces the "body" property: instead of specifying the text manually, the user provides a prompt that is sent to the AI provider.

- text:
    ai_prompt: "Write a professional paragraph about renewable energy trends."
  • Type: string

  • Description: A prompt to send to the AI provider configured in "ai_config". The generated text will be used as the component's body content.

Back to top


Examples

Basic text generation

The simplest use case: generate a single paragraph using AI.

document:
  name: ai_report.docx
  ai_config:
    provider: openai
    model: gpt-4o-mini
  structure:
    - text:
        ai_prompt: "Write a professional introductory paragraph about climate change."
        font: Calibri
        size: 11
        alignment: justify

This specification creates a document with one text paragraph. The paragraph content is generated by OpenAI's GPT-4o-mini model based on the provided prompt. The generated text is formatted with Calibri font, size 11 and justified alignment.

Back to top

Heading generation

AI-generated content can also be used for headings.

document:
  name: ai_report.docx
  ai_config:
    provider: anthropic
    model: claude-sonnet-4-5-20250929
  structure:
    - heading:
        ai_prompt: "Generate a concise title for a section about market analysis methodology"
        level: 1
    - text:
        ai_prompt: "Write a detailed paragraph about market analysis methodology, covering both qualitative and quantitative approaches."
        font: Calibri
        size: 11

This specification creates a document with a heading and a text paragraph, both generated by Anthropic's Claude Sonnet model. The heading is styled as level 1.

Back to top

Combining AI and manual content

AI-generated content can be freely mixed with manually specified content within the same document.

document:
  name: mixed_report.docx
  ai_config:
    provider: openai
    model: gpt-4o-mini
  structure:
    - heading:
        body: Introduction
        level: 1
    - text:
        ai_prompt: "Write a professional introductory paragraph for an annual financial report."
        font: Calibri
        size: 11
    - heading:
        body: Revenue Overview
        level: 2
    - text:
        body: >-
          The table below presents the revenue data for the fiscal year.
        font: Calibri
        size: 11
    - table:
        source:
          output: table
          source_type: local
          location: 'input/table/revenue.xlsx'
    - heading:
        body: Conclusion
        level: 1
    - text:
        ai_prompt: "Write a brief professional conclusion for an annual financial report, emphasizing positive growth outlook."
        font: Calibri
        size: 11

This specification demonstrates that "ai_prompt", "body" and "source" can all be used across different components within the same document. Only one of these three should be specified per component.

Back to top

Using Google Gemini

The same functionality is available with Google's Gemini models.

document:
  name: gemini_report.docx
  ai_config:
    provider: google
    model: gemini-2.0-flash
  structure:
    - heading:
        body: Project Summary
        level: 1
    - text:
        ai_prompt: "Write a concise project summary paragraph for a software development project that delivered a new customer portal."
        font: Calibri
        size: 11
        alignment: justify

Back to top

Full formatting with AI content

All standard text and heading formatting properties are fully compatible with AI-generated content. The formatting is applied to the generated text in the same way as it would be applied to manually specified text.

document:
  name: formatted_ai_report.docx
  ai_config:
    provider: anthropic
    model: claude-sonnet-4-5-20250929
  structure:
    - heading:
        body: Executive Summary
        level: 1
        colour: dark blue
        font: Georgia
    - text:
        ai_prompt: "Write an executive summary paragraph for a quarterly business review highlighting strong Q3 performance."
        font: Georgia
        size: 12
        alignment: justify
        colour: black
        first_line_indent: 1.27
        space_after: 2
        line_spacing_rule: one_point_five

All optional text properties ("bold", "italic", "underline", "colour", "font", "size", "alignment", etc.) work with "ai_prompt" exactly as they work with "body".

Back to top


Supported providers

Provider provider value API key environment variable Example models
OpenAI openai OPENAI_API_KEY gpt-4o, gpt-4o-mini
Anthropic anthropic ANTHROPIC_API_KEY claude-sonnet-4-5-20250929, claude-haiku-4-5-20251001
Google google GOOGLE_API_KEY gemini-2.0-flash, gemini-2.5-pro-preview-05-06

Back to top


Error handling

OpenReport provides clear error messages for common issues:

Scenario Error message
"ai_prompt" used without "ai_config" 'ai_prompt' found but no 'ai_config' defined at document level.
Missing API key environment variable OPENAI_API_KEY environment variable is not set. (or ANTHROPIC_API_KEY, GOOGLE_API_KEY)
Invalid provider name Unknown AI provider 'xxx'. Supported providers: openai, anthropic, google.
Missing "model" in "ai_config" 'model' is required in ai_config.
API request failure API request failed with status {code}. with the response details.

Back to top


Important notes

  • Only one content source should be specified per component: "body", "source" or "ai_prompt". If "ai_prompt" is present, it takes priority and overwrites any "body" value.
  • The "ai_config" is specified once at the document level and applies to all "ai_prompt" instances within that document.
  • AI content generation requires an active internet connection to communicate with the AI provider's API.
  • API usage costs are determined by the chosen provider and model. Please refer to the respective provider's pricing page.
  • The generated content is not cached. Each document generation run sends new requests to the AI provider.

Continue to Components generation

Back to top

Back to homepage