This guide provides step-by-step instructions for deploying the Grok X User Search val to Val Town.
-
Val Town CLI: Install the Val Town CLI
npm install -g @val-town/cli -
API Key: Get your xAI API key from x.ai
- Sign up for xAI account
- Navigate to API section
- Generate your API key
cd /home/didierlacroix1/containers/val-town/individual_vals/grok_user_search
vt create grokUserSearch
Note: This will prompt asking if you want to use existing files. Type y to continue.
vt push
Go to your Val Town dashboard β Settings β Environment Variables and add:
- Key:
XAI_API_KEY - Value: Your xAI API key
cd /home/didierlacroix1/containers/val-town/individual_vals mkdir grok_search_empty cd grok_search_empty vt create grokUserSearch
cp ../grok_user_search/* .
vt push
- Create New Val in Val Town web interface
- Upload Files manually:
main.tsgrok_client.tstypes.tsdeno.jsonindex.html(Web UI)
In Val Town dashboard, set:
XAI_API_KEY=your_xai_api_key_here
Web Interface (Recommended): Visit your val's URL in a web browser:
https://your-username-grokUserSearch.web.val.run
API Test:
curl -X POST https://your-username-grokUserSearch.web.val.run \ -H "Content-Type: application/json" \ -d '{ "query": "find all the latest prompts mentioned", "targetUser": "dl4senses" }'
- Check val runs without errors
- Test with different queries
- Verify API responses include citations
cd /home/didierlacroix1/containers/val-town/individual_vals/grok_user_search vt watch
This will automatically sync changes to Val Town.
- Edit files locally
vt pushto upload changes- Test the updated val
vt pull
Solution: This is expected - type y when prompted to continue with existing files.
Solution: Ensure XAI_API_KEY is set in Val Town dashboard β Settings β Environment Variables.
Solution: Check that all TypeScript imports are correct and files exist in the val.
Solution: The code includes CORS headers, but verify your browser isn't blocking requests.
curl -X POST https://your-val-url.web.val.run \ -H "Content-Type: application/json" \ -d '{ "query": "latest AI developments", "maxResults": 10 }'
curl -X POST https://your-val-url.web.val.run \ -H "Content-Type: application/json" \ -d '{ "query": "find all the latest prompts mentioned by @dl4senses", "targetUser": "dl4senses", "includeMedia": true }'
curl -X POST https://your-val-url.web.val.run \ -H "Content-Type: application/json" \ -d '{ "query": "AI breakthroughs", "dateRange": { "from": "2025-01-01", "to": "2025-01-15" } }'
In Val Town dashboard:
- Go to your val
- Click "Logs" tab
- View request logs and error messages
Check xAI dashboard for:
- API request counts
- Token usage
- Rate limiting
- API Key Security: Never commit API keys to code
- Input Validation: Code includes input sanitization
- Rate Limiting: Monitor and respect xAI rate limits
- Error Handling: Errors don't expose sensitive information
- The val runs serverless on Val Town
- xAI handles the heavy processing
- Consider response times for complex queries
- Monitor token usage for cost management
For issues:
- Val Town Issues: Check Val Town documentation
- xAI API Issues: Check x.ai documentation
- Code Issues: Review implementation and test locally
After successful deployment:
- Test with various queries
- Monitor API usage and costs
- Consider adding caching for repeated queries
- Implement rate limiting if needed
- Add analytics for query patterns