# AI

AI-powered features including text editing, call coaching, needs analysis, form filling, pipeline generation, image generation, reference-guided image editing, text-to-speech generation, and AI tool generators (form, document, whiteboard, website page) that create fully-structured workspace assets from a plain-language prompt.

**Base URL:** `https://api.trustpager.com/functions/v1/api/v1`

## Endpoints

### POST /ai/edit-text

Rewrite, improve, translate, summarize, or edit text using AI. Costs 1 credit. Accepts both "text"/"instruction" or "originalText"/"editInstructions" field names.

**Scopes:** `ai:use` — [full detail](./ai/post-ai-edit-text.md)

### POST /ai/call-coaching

Analyze a call, meeting, or SMS transcript for coaching insights. Returns performance scores, strengths, improvements, and coaching summary. Costs 3 credits. Provide transcript_id (preferred, auto-resolves text and metadata) or transcript_text (raw text).

**Scopes:** `ai:use` — [full detail](./ai/post-ai-call-coaching.md)

### POST /ai/generate-pipeline

Auto-generate a pipeline structure with stages from a text description. Costs 3 credits.

**Scopes:** `ai:use` — [full detail](./ai/post-ai-generate-pipeline.md)

### POST /ai/needs-analysis

Run AI needs analysis on a deal -- extracts client requirements and recommendations from all linked transcripts and activities. Provide deal_id; the system fetches all related data automatically.

**Scopes:** `ai:use` — [full detail](./ai/post-ai-needs-analysis.md)

### POST /ai/fill-form

Use AI to pre-fill form fields based on a prompt. template_id and prompt are required. The system fetches form fields automatically.

**Scopes:** `ai:use` — [full detail](./ai/post-ai-fill-form.md)

### POST /ai/generate-image

Generate an AI image from a text prompt using the NanoBanana model (google:4@1). Returns a CDN image URL, seed, and dimensions. Costs credits. The image is automatically saved to company files. IMPORTANT: Only 11 specific dimension pairs are accepted -- invalid dimensions return a VALIDATION_ERROR with the full list. Default: 1024x1024. Default output format is lossless PNG; pass output_format to override.

**Scopes:** `ai:use` — [full detail](./ai/post-ai-generate-image.md)

### POST /ai/edit-image

Edit an existing image using AI reference guidance. Provide 1-3 reference image URLs (the subject to preserve) and a text prompt describing the new surroundings, style, or lighting. Uses the NanoBanana model (google:4@1, identity-preserving). Returns a CDN image URL, seed, and dimensions. Costs credits. The result is automatically saved to company files. IMPORTANT: Only 11 specific dimension pairs are accepted -- same constraints as generate-image. Reference URLs must be public http(s) URLs.

**Scopes:** `ai:use` — [full detail](./ai/post-ai-edit-image.md)

### POST /ai/upscale-image

Upscale an image using AI (Runware imageUpscale). Multiplies the source image dimensions by the given factor (2x, 3x, or 4x). Accepts any public http(s) image URL -- including URLs returned by generate-image or edit-image. The upscaled result is automatically saved to R2 and company files. Costs the same credits as generate-image (ai_image feature cost). Requires scope: ai:use.

**Scopes:** `ai:use` — [full detail](./ai/post-ai-upscale-image.md)

### POST /ai/generate-speech

Convert text to speech audio using ElevenLabs. Uploads the audio to R2 and saves to company files. Returns an audio URL, duration, file size, and credits charged. Costs 50 credits per 100 characters (minimum 50 credits). Voice resolution order: workspace voices by name -> workspace default -> platform voices -> presets (jessica/rachel/adam/sam) -> raw ElevenLabs voice ID. Optionally returns timed transcript segments (sentences, phrases, or words) for animation timing (e.g. Remotion video sync).

**Scopes:** `ai:use` — [full detail](./ai/post-ai-generate-speech.md)

### POST /ai/generate-form

Generate a complete form template with AI, auto-wired to CRM variables. The generator maps fields whose labels unambiguously match a writable CRM variable (e.g. Email -> contact.email, ABN -> account.tax_number). Workspace custom fields are included in the wiring vocabulary. By default (persist=true), creates the form_templates row and all form_template_fields rows and returns the new template_id. Costs credits (ai_tool_generate).

**Scopes:** `ai:use` — [full detail](./ai/post-ai-generate-form.md)

### POST /ai/generate-document

Generate a document template with AI -- proposals, contracts, reports, invoices, letters. Produces structured sections (cover page, text blocks, tables, signature blocks) with {{variable}} tokens for auto-filling. By default (persist=true), creates the document_templates row and all document_template_sections rows and returns the new template_id. Costs credits (ai_tool_generate).

**Scopes:** `ai:use` — [full detail](./ai/post-ai-generate-document.md)

### POST /ai/generate-whiteboard

Generate a whiteboard/diagram template with AI -- process flows, org charts, decision trees, customer journeys, system architectures. Produces Excalidraw-compatible shapes with coordinated colour themes. By default (persist=true), creates whiteboard_templates + whiteboard_snapshots rows. Costs credits (ai_tool_generate).

**Scopes:** `ai:use` — [full detail](./ai/post-ai-generate-whiteboard.md)

### POST /ai/generate-website-page

Generate a complete website landing page with AI -- picks industry-appropriate sections (hero, social proof, features, pricing, FAQ, CTA, etc.) from the business description. Creates website + homepage + all page sections in one call. By default (persist=true), inserts rows into websites, website_pages, and website_page_sections. Costs credits (ai_tool_generate).

**Scopes:** `ai:use` — [full detail](./ai/post-ai-generate-website-page.md)

### POST /ai/transcript-summary

Server-side AI intelligence extraction from a transcript. Runs Claude on the full transcript text server-side (no transport size limits) and returns a compact structured summary. Ideal for large transcripts that exceed MCP context limits, or when you need intelligence rather than raw text. Costs 1 credit.

**Scopes:** `ai:use` — [full detail](./ai/post-ai-transcript-summary.md)
