Documentation
AI

AI Chat and Generation

Add your API Key and use the included pages for your first chat, image, and credit charge

The project includes AI chat, image generation, and video generation pages. Start with a reply from the default model, then enable image generation. Configure only the providers you want to use.

Complete login and admin setup first. API requests use provider quota, so prepare a working Key and balance for testing.

1. Prepare the model catalog

Run the local setup command from your project directory:

pnpm db:seed:local

Open Admin → AI Prices (/admin/ai-prices). You should see example prices for GPT-4o Mini chat, Flux images, and Kling video.

For a deployed website, run pnpm db:seed:remote instead and check that website's admin area. Local and deployed environments need their own setup.

2. Get your first reply

  1. Create a Key in OpenAI API Keys and add it to local .dev.vars:

    OPENAI_API_KEY=your-api-key
  2. Restart pnpm dev, sign in, and open /chat/.

  3. Keep the default GPT-4o Mini selected and send “Write a welcome message for a new user.”

  4. A streaming reply confirms chat is connected.

If credits are enabled, grant your test account a balance first. Credits are off by default, so you can try chat before setting them up. The provider still charges for actual requests.

Admin → AI Config (/admin/ai-config) shows whether a Key is configured. Secrets are read-only there: change .dev.vars and restart locally, or update the matching Worker secret online.

3. Set how many credits users spend

Enable credits in Settings, then edit existing rows in AI Prices.

What to priceWhat to find in the catalog
GPT-4o Mini chatBoth openai/gpt-4o-mini@in and openai/gpt-4o-mini@out
Standard image generationfal/flux-dev@1024x1024
Reference-image generationfal/flux-dev-image-to-image
Video generationfal/kling-v1-standard@720p

Start with Credits / unit and Min credits. The two chat rows set credits per thousand input and output tokens. Images use a per-image price; the example video uses a per-second price. Keep the existing models, units, and input limits for your first test.

These are example prices. Adjust them for your product before launch. After a reply finishes, open Usage from the avatar menu and check the charge. Chat can work without a price, but missing prices are not charged.

4. Generate your first image

Use a deployed test website for the complete flow. Follow deployment to prepare Cloudflare resources and file storage to save and view generated results.

  1. Create a Key in fal.ai Dashboard and upload it as a Worker secret. For local use, add it to .dev.vars:

    FAL_KEY=your-fal-key
    OPENAI_API_KEY=your-openai-key
  2. Open Admin → Settings → Content Moderation. Prompt checks use openai/gpt-4o-mini by default, so you need a working OpenAI Key even when fal.ai generates the image. If you choose another prompt-checking model, configure that model's provider Key.

  3. Confirm this website has an active Flux price in AI Prices and give your test account enough credits.

  4. Open /ai-image-generator/, select the standard Flux image model, enter a description, check the estimated credits, and submit.

  5. Wait for completion. Check that the asset library previews the image, its link opens, and Usage shows the credits spent.

For reference images, complete upload setup, select a reference-image model, and upload a JPEG, PNG, or WebP image. Wait for the image check before submitting. Reference checks use OpenAI omni-moderation-latest by default and also need OPENAI_API_KEY.

Once images work, open /ai-video-generator/. Use the mode dropdown beside the model picker to choose text-to-video, image-to-video, first and last frame, or reference media. Upload one opening image, both frames, or reference media as required. Models with audio generation expose an audio switch. Video results include playback and a link to the original file.

Add image and video models

The model and generation mode use compact dropdown controls. Changing the mode filters compatible models and reveals the required image inputs. Images support text generation and reference-based editing; videos support text, one image, first and last frame, and reference media.

The catalog includes 8 fal image and 9 fal video endpoint presets, plus four modes each for Replicate Seedance 2 and Seedance 2 Fast: FLUX.1 Dev (text and reference image), Schnell, FLUX1.1 Pro / Ultra, FLUX.1 Kontext Pro, GPT Image 1 (text and multi-image editing), Kling 1 / 2.1, and the four Veo 3.1 modes. Frame pairs map to first_frame_url and last_frame_url; multiple images map to image_urls. Veo reference video accepts up to 3 images and uses 8 seconds at 16:9. Its 1080p output uses 8 seconds.

These are capability presets, not a live inventory of each platform. Seedance uses Pixmelody's Replicate versions and parameter contract for bytedance/seedance-2.0 and bytedance/seedance-2.0-fast. Veo remains on fal and accepts image references only.

Choose Admin → AI Prices → Add → Load model parameters, then set a unique pricing key, credits per unit, and minimum credits before activating the price. Other fal models can be added using their endpoint, display name, and supported parameter constraints. All active fal image and video models appear automatically in the matching workspace. Generation requires an active price and the matching provider secret (FAL_KEY for fal, REPLICATE_API_TOKEN for Seedance); unconfigured presets remain available to browse.

For different quality or resolution prices, add multiple rows for the same model. Set Variant to the matching value (for example, low or high) and restrict the allowed qualities or resolutions for that price. Video models must declare the discrete durations their endpoint accepts. The server validates controls before holding credits and uses the same defaults as the form. To price audio separately, create distinct variants with audio generation fixed on or off.

Custom fal models can declare image, video and audio reference fields, counts and combined duration limits. Clients send referenceAssetIds, referenceVideoAssetIds and referenceAudioAssetIds; the server verifies ownership, kind and duration before resolving URLs. Legacy referenceAssetId requests remain compatible. Audio generation uses a boolean generate_audio. Settings use the existing ai_price.constraints column and media duration uses media_asset.duration_ms; no SQL migration is required.

Seedance video and audio references

  1. Set REPLICATE_API_TOKEN in .dev.vars and restart locally, or set the matching Worker secret for deployment. AI Config displays its status; secrets are read-only there.
  2. In AI Prices → Add → Load model parameters, select Seedance 2 or Seedance 2 Fast and a mode. Set a pricing key and credit prices, then activate the row. Presets use per-second billing; you choose the rates. Selecting the automatic generation mode allows one price to cover all supported modes, or create separate rows restricted to individual modes.
  3. Choose Reference to video and Seedance. Add up to 9 images, 3 videos and 3 audio files. Video and audio references may total at most 15 seconds. Audio needs an image or video alongside it.
  4. Upload MP4 video (up to 50 MB), MP3/WAV/M4A audio (up to 10 MB), or JPEG/PNG/WebP images (up to 10 MB). Preview or remove references before submitting. Submission waits for all uploads and validates their limits.

Seedance 2 supports 480p, 720p, 1080p and 4k; Fast supports 480p and 720p. Both offer 4–15 second output and audio generation control. The mode picker filters compatible model names. Changing the model or mode clears reference inputs.

The server checks video/audio containers, completeness and duration. Images retain the existing image moderation flow. There is no independent video/audio content moderation service yet; generation remains subject to the provider's checks. Replicate jobs complete through the existing reconciliation polling, so keep AI queues and Cron configured. The pinned API versions come from Pixmelody code and have not been tested with a live paid generation.

Use another chat provider

Create a Key in the provider's console, add it to .dev.vars, restart, and select its model in chat. Use the same variable name as a Worker secret online.

ProviderVariable
AnthropicANTHROPIC_API_KEY
GoogleGOOGLE_GENERATIVE_AI_API_KEY
xAIXAI_API_KEY
GroqGROQ_API_KEY
MistralMISTRAL_API_KEY
CohereCOHERE_API_KEY
DeepSeekDEEPSEEK_API_KEY, plus DEEPSEEK_BASE_URL if needed
Hugging FaceHF_TOKEN
NovitaNOVITA_API_KEY
SiliconFlowSILICONFLOW_API_KEY
BasetenBASETEN_API_KEY
VolcengineVOLCENGINE_API_KEY

The chat selector does not hide providers without keys. Check credentials, quota, and model access before selecting a model. To charge credits for it, also configure its input and output prices.

If something does not work

SymptomFirst check
Chat model is unavailableThe provider's Key, quota, and model access
Model is marked unavailableFAL_KEY is configured in this environment and the model has an active price
Insufficient creditsTest account balance and the selected model's estimated cost
An ordinary prompt cannot generateThe model in Settings → Content Moderation has a working Key; then check moderation records
Finished image does not openSTORAGE_PUBLIC_URL belongs to the R2 bucket storing the result
Reference upload failsUpload settings, allowed website origins, and the OpenAI moderation Key

Moderation records are at /admin/moderation. Local storage is separate from online R2. Complete asset access, upload, and payment checks on a deployed test website.

On this page