API Documentation
The Partida API allows you to programmatically generate, refine, publish, and playtest browser-based games.
Authentication
The Partida API supports two authentication methods:
- Session Cookies - Automatically used when making requests from the web app
- API Keys - For programmatic access from external applications
To use API key authentication, include the key in the Authorization header:
Authorization: Bearer og_your_api_key_hereYou can generate an API key from the Settings page.
Endpoints
/api/generate
Generate a new game from a text prompt.
Request Body
{
"prompt": "string", // Required: Game description
"visualStyle": "string", // Optional: Visual style
"environment": "string" // Optional: Game environment
}Visual Style Options
"2d-pixel", "2d-vector", "3d", "isometric", "hand-drawn", "neon-glow"
Response
{
"title": "string",
"description": "string",
"inputs": ["string"],
"code": "string",
"score": number,
"grade": "string",
"breakdown": { ... },
"suggestions": ["string"]
}Examples
curl -X POST https://partida.ai/api/generate \
-H "Authorization: Bearer og_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A space shooter with asteroids",
"visualStyle": "2d-pixel"
}'/api/games
Publish a game to the Partida platform.
Request Body
{
"title": "string",
"description": "string",
"prompt": "string",
"code": "string",
"inputs": ["string"]
}Response
{
"id": "string",
"title": "string",
"description": "string",
"code": "string",
"inputs": ["string"],
"playUrl": "string",
...
}Examples
curl -X POST https://partida.ai/api/games \
-H "Authorization: Bearer og_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"title": "Space Shooter",
"description": "Dodge asteroids in space",
"prompt": "A space shooter game",
"code": "<!DOCTYPE html>...",
"inputs": ["keyboard", "mouse"]
}'/api/games
Retrieve a list of all published games.
Response
[
{
"id": "string",
"title": "string",
"description": "string",
"inputs": ["string"],
...
}
]Examples
curl https://partida.ai/api/games \ -H "Authorization: Bearer og_your_api_key_here"
/api/games/:id
Retrieve details for a specific game.
Response
{
"id": "string",
"title": "string",
"description": "string",
"code": "string",
"inputs": ["string"],
...
}Examples
curl https://partida.ai/api/games/abc123 \ -H "Authorization: Bearer og_your_api_key_here"
/api/playground/chat
Refine and iterate on a game using conversational chat.
Request Body
{
"code": "string",
"title": "string",
"description": "string",
"inputs": ["string"],
"message": "string",
"chatHistory": [
{ "role": "user" | "assistant", "content": "string" }
]
}Response
{
"code": "string",
"label": "string",
"score": number,
"grade": "string",
"breakdown": { ... },
"suggestions": ["string"],
"codeValidation": { ... }
}Examples
curl -X POST https://partida.ai/api/playground/chat \
-H "Authorization: Bearer og_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"code": "<!DOCTYPE html>...",
"title": "Space Shooter",
"message": "Make the asteroids move faster",
"chatHistory": []
}'/api/playtest
Run automated visual playtest on a game with screenshots.
Request Body
{
"code": "string", // Option 1: Provide code directly
"title": "string",
"inputs": ["string"]
}
// OR
{
"id": "string" // Option 2: Reference existing game
}Response
{
"screenshots": ["string"],
"analysis": { ... },
"issues": ["string"],
...
}Examples
curl -X POST https://partida.ai/api/playtest \
-H "Authorization: Bearer og_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"id": "abc123"
}'/api/drafts
Create a draft for testing before publishing.
Request Body
{
"title": "string",
"description": "string",
"code": "string",
"inputs": ["string"]
}Response
{
"id": "string",
"title": "string",
"testUrl": "string",
...
}Examples
curl -X POST https://partida.ai/api/drafts \
-H "Authorization: Bearer og_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"title": "Test Game",
"description": "Testing new features",
"code": "<!DOCTYPE html>...",
"inputs": ["keyboard"]
}'/api/auth/api-key
Generate a new API key for authentication.
Response
{
"apiKey": "og_xxxxxxxxxxxxxxxx"
}Warning: The API key is only shown once. Save it securely.
Examples
curl -X POST https://partida.ai/api/auth/api-key \ -H "Cookie: session=your_session_cookie"
Game File Format
Games on Partida are self-contained HTML documents that run entirely in the browser.
Allowed CDN Libraries
- Three.js - For 3D graphics and rendering
- TensorFlow.js - For pose detection and machine learning
Available Input Types
keyboard, mouse, trackpad, camera, microphone, arrows, internet, poseGames must be self-contained and not require external resources beyond the allowed CDN libraries.
Best Practices
Follow these guidelines to ensure your games work well within the Partida platform.
Pause / Resume
Games should listen for og-pause and og-resume postMessage events from the parent frame. This allows the playground to pause your game when the user switches tabs, opens settings, or interacts with other UI elements.
window.addEventListener('message', (event) => {
if (event.data === 'og-pause') {
// Pause game loop, mute audio, etc.
gamePaused = true;
}
if (event.data === 'og-resume') {
// Resume game loop, unmute audio, etc.
gamePaused = false;
}
});Scoring
To submit scores to the leaderboard, use postMessage to send the score to the parent frame. The score must be a numeric value.
// Submit a score to the leaderboard
window.parent.postMessage({
type: 'og-score',
score: numericValue
}, '*');Save / Load
Use the built-in window.og API for game state persistence. Saves are stored server-side per user, so progress follows players across devices. Falls back to localStorage for anonymous users.
// Save game state (fires instantly)
window.og.save({ level: 5, score: 1200, inventory: ['sword'] });
// Load saved game state (async — use await!)
const savedData = await window.og.load();
if (savedData) {
restoreGame(savedData);
}
// Clear saved data
window.og.clearSave();Console Bridge
Console errors from your game are automatically captured and surfaced to the playground. This means any console.error() calls or uncaught exceptions will appear in the playground's error panel, making it easy to debug issues without opening browser dev tools.
Self-Contained HTML
All games must be self-contained HTML documents. This means all CSS, JavaScript, and assets must be inlined within a single HTML file. External resources are not allowed beyond the approved CDN libraries (Three.js, TensorFlow.js). Do not reference external stylesheets, scripts, images, or fonts.
In-Game AI
Research PreviewGames can call an LLM at runtime for NPC dialogue, dynamic content, hints, or story generation. The API key never enters the game — requests are proxied through the server via postMessage. The logged-in user's session is used for authentication. Each call costs 0.05 credits.
// Send a prompt to the LLM from your game
window.og.chat("Describe a mysterious cave entrance")
.then(response => {
showDialogue(response);
});
// With options
window.og.chat("Give me a riddle", { maxTokens: 100 });Use for: NPC dialogue, dynamic descriptions, hints, story generation. Avoid: game loop logic, physics calculations, per-frame calls.
Testing
Partida provides several ways to test your games, from visual playtesting to automated scoring and unit tests.
/api/playtest
The playtest endpoint launches your game in a headless browser, takes screenshots at intervals, and uses AI vision to analyze whether the game renders correctly, responds to input, and looks polished. You can provide either raw HTML code or reference an existing game by ID.
curl -X POST https://partida.ai/api/playtest \
-H "Authorization: Bearer og_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{ "id": "abc123" }'/api/test-games
The automated scoring endpoint runs a batch of games through the testing pipeline and returns quality scores and detailed breakdowns. Use this to validate games before publishing or to benchmark game quality across iterations.
curl -X POST https://partida.ai/api/test-games \
-H "Authorization: Bearer og_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{ "gameIds": ["abc123", "def456"] }'Vitest Suite
The project includes a Vitest test suite for running unit and integration tests locally. Use this to validate API routes, utility functions, and game logic before deploying.
# Run the full test suite npm test # Run tests in watch mode npm test -- --watch # Run a specific test file npm test -- path/to/test.test.ts
Automated Scoring Breakdown
Every game is scored by a static analysis pass that scans the HTML source for key patterns. Each category is scored 0-100, then weighted to produce a final composite score. Below is exactly what the test checks for in each category.
| Category | Weight | What It Checks |
|---|---|---|
| Instructions | 12% | Start screen or start prompt (e.g. "click to start", "press space to start"), explicit control descriptions (e.g. "arrow keys", "WASD", "use mouse"), objective text (e.g. "collect", "survive", "avoid") |
| Objective | 15% | Score/points tracking with visible display (fillText/innerHTML), high score or localStorage persistence, timer or countdown, level/wave/stage system, collectibles (coins, gems, stars, powerups) |
| Fail State | 18% | Game over screen or death/lose state, lives/health/HP/hearts system, time-up condition (countdown reaching zero), collision or damage detection (enemies, spikes, hazards) |
| Restart | 10% | Restart/play-again/try-again mechanism, dedicated reset function (initGame, resetGame, startGame), state variable resets (score = 0, lives = 3, level = 1) |
| Difficulty | 12% | Difficulty scaling keywords (harder, speed up, faster), level/wave system with multiple references, dynamic spawn rate or enemy speed changes, combo/multiplier/streak/bonus system |
| Environment | 13% | Entity variety (enemies, obstacles, collectibles, projectiles, particles, terrain), collision detection logic, visual effects (particles, shake, flash, glow, gradient), audio (AudioContext, sound playback), parallax/depth/background layers |
| Technical | 12% | DOCTYPE declaration, canvas or div rendering target, script tag present, game loop (requestAnimationFrame or setInterval), resize handling, canvas getContext call, input validation (declared inputs match actual listeners), CDN validation (only allowed libraries), minimum code length |
| Anti-Exploit | 8% | Resource limits (ink, ammo, fuel, energy, mana), sandbox detection (builder/creator without fail state penalized), trivial win prevention (no enemies and no time pressure penalized), time pressure and progressive challenge rewarded |
| Mobile | 10% | Touch event listeners (touchstart, touchmove, touchend), on-screen control elements, tap-based instructions (e.g. "tap to start"), preventDefault on touch events to block scroll, viewport meta tag, mobile/touch device detection |
Grading Scale
The weighted composite score maps to a letter grade:
A game must score at least 40 with no critical technical errors to pass. Games that fail are not eligible for publishing.
Upload
You can upload your own hand-crafted HTML game directly to Partida without using the AI generation pipeline. This is useful if you already have a game built and want to publish it to the platform.
- Prepare your game as a single, self-contained HTML file
- Make sure it follows the Game File Format requirements
- Implement pause/resume and scoring if applicable
- Visit the upload page and submit your file
Rate Limits
Partida uses a credit-based system to manage API usage:
New accounts start with 3 credits. Additional credits can be purchased from your account settings.
AI Providers
Partida supports multiple AI providers for game generation and refinement.
Claude (Anthropic)
Fully SupportedClaude is the primary AI provider for Partida. It powers game generation, chat refinement, in-game AI, and automated playtesting.
OpenAI
Coming SoonSupport for OpenAI models (GPT-4o, o1, etc.) is planned.
xAI (Grok)
Coming SoonSupport for xAI's Grok models is planned.
Google Gemini
Coming SoonSupport for Google's Gemini models is planned.
Coming Soon
We are actively working on new features to expand the Partida platform. Here is what is on the roadmap:
Multiplayer Gameplay
Real-time multiplayer support so players can compete or cooperate in the same game session.
AI Input Improvements
Better pose detection, face tracking, and camera-based input for more immersive gameplay experiences.
OpenAI, xAI, Gemini API Support
Choose from multiple AI providers for game generation, including GPT-4o, Grok, and Gemini models.
Credit System for Creators
Creators earn credits from gameplay on their published games, rewarding popular and high-quality content.