Skip to main content

Overview

Add your Invent AI assistant to any Astro site. Perfect for content-focused websites with islands architecture and multi-framework support.

Installation

1

Create Assistant Component

Astro supports multiple frameworks. Choose your preferred approach:

Pure Astro Component

React Component (with React integration)

2

Add to Layout

3

Configure Environment

Add to .env:

User Authentication

Security Requirement: When using any user-* attributes (user-id, user-name, user-avatar), you must also provide user-hash. Both user-id and user-hash must be provided together, or neither should be provided. The user-hash must be generated on your backend using HMAC-SHA256 with your assistant’s secret key. Never expose the secret key to the client.

Server-Side Hash Generation

Use Astro API endpoints:

Using in Layout with Server-Side Data

Content Collections Integration

Pass content data for better context:

TypeScript Support

Add type declarations:

Using with React/Vue/Svelte Islands

Astro’s island architecture allows mixing frameworks:

Tips for Astro

Islands Architecture

Perfect for partial hydration

Multi-Framework

Use React, Vue, Svelte, or pure Astro

Content Collections

Integrate with content data

SSG & SSR

Works with static and server modes

Troubleshooting

Solutions:
  • Ensure script tag is in component, not layout head
  • Check client directives if using framework components
  • Verify URL is correct
  • Check browser console for errors
Solutions:
  • Use appropriate client directive (client:load, client:visible)
  • Ensure script loads after component hydrates
  • Check for SSR/client mismatches
Solutions:
  • Restart dev server after adding env variables
  • Use PUBLIC_ prefix for client-accessible variables
  • Keep secret key without prefix (server-only)
  • Use import.meta.env not process.env

Best Practices

  • Use API routes or server-side code for hash generation
  • Keep secret key in .env (never commit)
  • Use PUBLIC_ prefix only for non-sensitive variables
  • Choose appropriate client directives for islands
  • Leverage Astro’s content collections for context