Basic Setup Guide
Goal: Set up a complete development environment for building AI-powered Svelte applications with all necessary tools and configurations
Reusable Guide: This setup guide is referenced across all Svelte AI Elements tutorials. Complete these steps once, and you're ready for any advanced guide!
Step 1: Installing Svelte
Create a new SvelteKit project with TypeScript and Tailwind CSS support. We'll use the sv CLI for quick setup:
When prompted, select the following options:
- Which template? → SvelteKit minimal
- Add type checking? → Yes, using TypeScript
- Add additional options? → Add Tailwind CSS
Navigate to your project directory:
Success! You now have a modern SvelteKit project with TypeScript and Tailwind CSS ready to go.
Step 2: Installing shadcn-svelte
shadcn-svelte provides beautiful, accessible UI components that integrate seamlessly with Tailwind CSS. Install and configure it:
Configure components.json with the following settings:
This creates a lib/components/ui directory structure with pre-configured components that work perfectly with Svelte AI Elements.
Step 3: Configuring OpenRouter & AI Models
OpenRouter provides free access to multiple AI models through a single API. Let's set it up:
1. Get Your API Key
Visit https://openrouter.ai/keys and sign up for a free account. Generate your API key.
2. Create Environment File
Create a .env.local file in your project root:
3. Free AI Models Available
You can use these free models for testing and development:
x-ai/grok-4-fast:free
deepseek/deepseek-chat-v3.1:free
z-ai/glm-4.5-air:free
qwen/qwen3-coder:free
moonshotai/kimi-k2:freeImportant: Never commit your .env.local file to version control. Add it to .gitignore.
Step 4: AI SDK Integration
Install the Vercel AI SDK and OpenRouter provider to enable streaming AI responses:
Create an AI configuration file to manage your AI settings:
This configuration file allows you to easily switch between different AI models and manage your API credentials in one place.
Step 5: Adding Svelte AI Elements Components
Svelte AI Elements provides pre-built components for common AI patterns. Add components as needed using the CLI:
Example: Adding Components
Install specific components for your project:
For chat interfaces:
For prompt inputs:
For loading states:
Note: Each guide will specify which components to install using the [COMPONENT] placeholder. Install only the components you need for that specific tutorial.
Verifying Your Setup
Let's verify everything is working correctly. Start the development server:
Your development server should start at http://localhost:5173. Check for:
- No TypeScript errors in terminal
- Tailwind CSS styles loading correctly
- No console errors in browser DevTools
- Environment variables loaded (check your backend routes)
Your development environment is ready. You can now proceed with any Svelte AI Elements tutorial or guide.
Ready to Build Something Amazing?
You've completed the basic setup! This foundation will be referenced in all other guides. Bookmark this page for quick reference.