| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Stable Diffusion REST API Documentation</title>
- <style>
- * {
- margin: 0;
- padding: 0;
- box-sizing: border-box;
- }
- body {
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
- line-height: 1.6;
- color: #e9ecef;
- background-color: #1a1a1a;
- }
- .container {
- max-width: 1200px;
- margin: 0 auto;
- padding: 20px;
- display: flex;
- gap: 2rem;
- }
- .sidebar {
- width: 280px;
- flex-shrink: 0;
- position: sticky;
- top: 20px;
- height: fit-content;
- max-height: calc(100vh - 40px);
- overflow-y: auto;
- }
- .main-content {
- flex: 1;
- min-width: 0;
- }
- header {
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
- color: white;
- padding: 2rem;
- margin-bottom: 2rem;
- border-radius: 8px;
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
- }
- .header-content {
- text-align: center;
- }
- h1 {
- font-size: 2.5rem;
- margin-bottom: 0.5rem;
- font-weight: 700;
- color: #000000;
- }
- .subtitle {
- font-size: 1.2rem;
- opacity: 0.9;
- }
- .toc {
- background: #2d3748;
- padding: 1.5rem;
- border-radius: 8px;
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
- margin-bottom: 2rem;
- border: 1px solid #4a5568;
- }
- .toc h2 {
- color: #667eea;
- margin-bottom: 1rem;
- font-size: 1.5rem;
- }
- .toc ul {
- list-style: none;
- }
- .toc-level-1 {
- margin-bottom: 1rem;
- }
- .toc-level-1 > li {
- margin-bottom: 0.5rem;
- font-weight: 600;
- }
- .toc-level-2 {
- margin-left: 1rem;
- margin-top: 0.5rem;
- }
- .toc-level-2 li {
- margin-bottom: 0.25rem;
- font-weight: 400;
- }
- .toc a {
- color: #a0aec0;
- text-decoration: none;
- transition: color 0.3s ease;
- display: block;
- padding: 0.25rem 0;
- border-radius: 4px;
- }
- .toc a:hover {
- color: #667eea;
- background: #4a5568;
- text-decoration: none;
- }
- .toc a.active {
- color: #667eea;
- background: #4a5568;
- }
- .section {
- background: #2d3748;
- margin-bottom: 2rem;
- border-radius: 8px;
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
- overflow: hidden;
- border: 1px solid #4a5568;
- }
- .section-header {
- background: #667eea;
- color: white;
- padding: 1.5rem;
- border-left: 4px solid #764ba2;
- }
- .section-content {
- padding: 1.5rem;
- }
- h2 {
- color: #000000;
- margin-bottom: 1rem;
- font-size: 1.8rem;
- font-weight: 600;
- }
- h3 {
- color: #000000;
- margin: 1.5rem 0 1rem 0;
- font-size: 1.4rem;
- font-weight: 600;
- border-bottom: 2px solid #4a5568;
- padding-bottom: 0.5rem;
- }
- h4 {
- color: #000000;
- margin: 1rem 0 0.5rem 0;
- font-size: 1.2rem;
- font-weight: 600;
- }
- .endpoint {
- background: #1a202c;
- border: 1px solid #4a5568;
- border-radius: 6px;
- padding: 1rem;
- margin: 1rem 0;
- font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
- }
- .method {
- display: inline-block;
- padding: 0.25rem 0.5rem;
- border-radius: 4px;
- font-weight: bold;
- font-size: 0.9rem;
- margin-right: 0.5rem;
- }
- .get { background: #28a745; color: white; }
- .post { background: #007bff; color: white; }
- .put { background: #ffc107; color: #212529; }
- .delete { background: #dc3545; color: white; }
- .code-block {
- background: #1a202c;
- border: 1px solid #4a5568;
- border-radius: 6px;
- padding: 1rem;
- margin: 1rem 0;
- overflow-x: auto;
- font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
- font-size: 0.9rem;
- color: #e2e8f0;
- }
- .json {
- background: #1a202c;
- color: #68d391;
- border-radius: 6px;
- padding: 1rem;
- margin: 1rem 0;
- overflow-x: auto;
- font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
- font-size: 0.9rem;
- border: 1px solid #4a5568;
- }
- .parameter-table {
- width: 100%;
- border-collapse: collapse;
- margin: 1rem 0;
- background: #2d3748;
- border-radius: 6px;
- overflow: hidden;
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
- border: 1px solid #4a5568;
- }
- .parameter-table th {
- background: #667eea;
- color: white;
- padding: 0.75rem;
- text-align: left;
- font-weight: 600;
- }
- .parameter-table td {
- padding: 0.75rem;
- border-bottom: 1px solid #4a5568;
- color: #e2e8f0;
- }
- .parameter-table tr:nth-child(even) {
- background: #1a202c;
- }
- .required {
- color: #fc8181;
- font-weight: bold;
- }
- .optional {
- color: #68d391;
- font-weight: bold;
- }
- .note {
- background: #2d3748;
- border: 1px solid #f6e05e;
- border-radius: 6px;
- padding: 1rem;
- margin: 1rem 0;
- border-left: 4px solid #f6e05e;
- color: #e2e8f0;
- }
- .warning {
- background: #2d3748;
- border: 1px solid #fc8181;
- border-radius: 6px;
- padding: 1rem;
- margin: 1rem 0;
- border-left: 4px solid #fc8181;
- color: #e2e8f0;
- }
- .info {
- background: #2d3748;
- border: 1px solid #63b3ed;
- border-radius: 6px;
- padding: 1rem;
- margin: 1rem 0;
- border-left: 4px solid #63b3ed;
- color: #e2e8f0;
- }
- .response-example {
- background: #2d3748;
- border: 1px solid #68d391;
- border-radius: 6px;
- padding: 1rem;
- margin: 1rem 0;
- color: #e2e8f0;
- }
- .error-example {
- background: #2d3748;
- border: 1px solid #fc8181;
- border-radius: 6px;
- padding: 1rem;
- margin: 1rem 0;
- color: #e2e8f0;
- }
- .back-to-top {
- position: fixed;
- bottom: 20px;
- right: 20px;
- background: #667eea;
- color: white;
- padding: 0.5rem 1rem;
- border-radius: 6px;
- text-decoration: none;
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
- transition: all 0.3s ease;
- border: 1px solid #764ba2;
- }
- .back-to-top:hover {
- background: #764ba2;
- transform: translateY(-2px);
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
- }
- @media (max-width: 1024px) {
- .container {
- flex-direction: column;
- }
- .sidebar {
- width: 100%;
- position: static;
- height: auto;
- max-height: none;
- margin-bottom: 2rem;
- }
- .main-content {
- width: 100%;
- }
- }
- @media (max-width: 768px) {
- .container {
- padding: 10px;
- }
- h1 {
- font-size: 2rem;
- }
- .toc-level-2 {
- margin-left: 0.5rem;
- }
- .parameter-table {
- font-size: 0.8rem;
- }
- .json {
- font-size: 0.8rem;
- }
- .section-content {
- padding: 1rem;
- }
- .toc {
- padding: 1rem;
- }
- }
- </style>
- </head>
- <body>
- <div class="container">
- <aside class="sidebar">
- <nav class="toc">
- <h2>Table of Contents</h2>
- <ul class="toc-level-1">
- <li><a href="#authentication">Authentication</a>
- <ul class="toc-level-2">
- <li><a href="#authentication-methods">Authentication Methods</a></li>
- <li><a href="#authentication-endpoints">Authentication Endpoints</a></li>
- </ul>
- </li>
- <li><a href="#system-information">System Information</a></li>
- <li><a href="#model-management">Model Management</a></li>
- <li><a href="#image-generation">Image Generation</a></li>
- <li><a href="#queue-management">Queue Management</a></li>
- <li><a href="#file-management">File Management</a></li>
- <li><a href="#utilities">Utilities</a></li>
- <li><a href="#error-responses">Error Responses</a></li>
- <li><a href="#authentication-and-authorization">Authentication and Authorization</a></li>
- <li><a href="#rate-limiting-and-usage">Rate Limiting and Usage</a></li>
- <li><a href="#websocket-support">WebSocket Support</a></li>
- <li><a href="#examples">Examples</a></li>
- <li><a href="#configuration">Configuration</a></li>
- <li><a href="#troubleshooting">Troubleshooting</a></li>
- </ul>
- </nav>
- </aside>
- <main class="main-content">
- <header>
- <div class="header-content">
- <h1>Stable Diffusion REST API Documentation</h1>
- <p class="subtitle">Comprehensive API reference for stable-diffusion.cpp-rest server</p>
- </div>
- </header>
- <section id="authentication" class="section">
- <div class="section-header">
- <h2>Authentication</h2>
- </div>
- <div class="section-content">
- <h3 id="authentication-methods">Authentication Methods</h3>
- <p>The API supports multiple authentication methods:</p>
- <ul>
- <li><strong>None</strong>: No authentication required</li>
- <li><strong>JWT</strong>: JSON Web Token authentication</li>
- <li><strong>API Key</strong>: API key authentication</li>
- <li><strong>Unix</strong>: Unix user authentication</li>
- <li><strong>PAM</strong>: Pluggable Authentication Modules</li>
- </ul>
- <h3 id="authentication-endpoints">Authentication Endpoints</h3>
-
- <h4>POST /api/auth/login</h4>
- <p>Authenticate with the server and receive an access token.</p>
-
- <div class="endpoint">
- <span class="method post">POST</span> /api/auth/login
- </div>
- <h5>Request Body:</h5>
- <div class="json">
- {
- "username": "string",
- "password": "string" // Optional for Unix auth without PAM
- }
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "token": "string",
- "user": {
- "id": "string",
- "username": "string",
- "role": "string",
- "permissions": ["string"]
- },
- "message": "string"
- }
- </div>
- <h4>POST /api/auth/logout</h4>
- <p>Log out and invalidate the current session.</p>
-
- <div class="endpoint">
- <span class="method post">POST</span> /api/auth/logout
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "message": "Logout successful"
- }
- </div>
- <h4>GET /api/auth/validate</h4>
- <p>Validate the current authentication token.</p>
-
- <div class="endpoint">
- <span class="method get">GET</span> /api/auth/validate
- </div>
- <h5>Headers:</h5>
- <div class="code-block">
- Authorization: Bearer <token>
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "user": {
- "id": "string",
- "username": "string",
- "role": "string",
- "permissions": ["string"]
- },
- "valid": true
- }
- </div>
- <h4>POST /api/auth/refresh</h4>
- <p>Refresh the current authentication token.</p>
-
- <div class="endpoint">
- <span class="method post">POST</span> /api/auth/refresh
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "token": "string",
- "message": "Token refreshed successfully"
- }
- </div>
- <h4>GET /api/auth/me</h4>
- <p>Get information about the currently authenticated user.</p>
-
- <div class="endpoint">
- <span class="method get">GET</span> /api/auth/me
- </div>
- <h5>Headers:</h5>
- <div class="code-block">
- Authorization: Bearer <token>
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "user": {
- "id": "string",
- "username": "string",
- "role": "string",
- "permissions": ["string"]
- }
- }
- </div>
- </div>
- </section>
- <section id="system-information" class="section">
- <div class="section-header">
- <h2>System Information</h2>
- </div>
- <div class="section-content">
- <h4>GET /api/health</h4>
- <p>Check if the server is running and healthy.</p>
-
- <div class="endpoint">
- <span class="method get">GET</span> /api/health
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "status": "healthy",
- "timestamp": 1234567890,
- "version": "1.0.0"
- }
- </div>
- <h4>GET /api/status</h4>
- <p>Get detailed server and system status.</p>
-
- <div class="endpoint">
- <span class="method get">GET</span> /api/status
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "server": {
- "running": true,
- "host": "localhost",
- "port": 8080
- },
- "generation_queue": {
- "running": true,
- "queue_size": 5,
- "active_generations": 1
- },
- "models": {
- "loaded_count": 2,
- "available_count": 10
- }
- }
- </div>
- <h4>GET /api/version</h4>
- <p>Get version information about the server.</p>
-
- <div class="endpoint">
- <span class="method get">GET</span> /api/version
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "version": "1.0.0",
- "type": "release",
- "commit": {
- "short": "abc1234",
- "full": "abc1234567890abcdef"
- },
- "branch": "main",
- "clean": true,
- "build_time": "2024-01-01T12:00:00Z"
- }
- </div>
- <h4>GET /api/config</h4>
- <p>Get server configuration (requires authentication).</p>
-
- <div class="endpoint">
- <span class="method get">GET</span> /api/config
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "config": {
- // Server configuration details
- }
- }
- </div>
- <h4>GET /api/system</h4>
- <p>Get system information (requires authentication).</p>
-
- <div class="endpoint">
- <span class="method get">GET</span> /api/system
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "system": {
- // System information details
- }
- }
- </div>
- <h4>POST /api/system/restart</h4>
- <p>Restart the server (requires admin authentication).</p>
-
- <div class="endpoint">
- <span class="method post">POST</span> /api/system/restart
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "message": "Server restart initiated"
- }
- </div>
- </div>
- </section>
- <section id="model-management" class="section">
- <div class="section-header">
- <h2>Model Management</h2>
- </div>
- <div class="section-content">
- <h4>GET /api/models</h4>
- <p>List all available models with filtering and pagination support.</p>
-
- <div class="endpoint">
- <span class="method get">GET</span> /api/models
- </div>
- <h5>Query Parameters:</h5>
- <table class="parameter-table">
- <thead>
- <tr>
- <th>Parameter</th>
- <th>Type</th>
- <th>Required</th>
- <th>Description</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>type</td>
- <td>string</td>
- <td class="optional">No</td>
- <td>Filter by model type (checkpoint, vae, lora, etc.)</td>
- </tr>
- <tr>
- <td>search</td>
- <td>string</td>
- <td class="optional">No</td>
- <td>Search in model names and descriptions</td>
- </tr>
- <tr>
- <td>sort_by</td>
- <td>string</td>
- <td class="optional">No</td>
- <td>Sort field (name, size, date, type, loaded)</td>
- </tr>
- <tr>
- <td>sort_order</td>
- <td>string</td>
- <td class="optional">No</td>
- <td>Sort order (asc, desc)</td>
- </tr>
- <tr>
- <td>limit</td>
- <td>integer</td>
- <td class="optional">No</td>
- <td>Pagination limit (default: 50, 0 = no limit)</td>
- </tr>
- <tr>
- <td>page</td>
- <td>integer</td>
- <td class="optional">No</td>
- <td>Page number (default: 1)</td>
- </tr>
- </tbody>
- </table>
- <div class="note">
- <strong>Note:</strong> This endpoint supports advanced filtering by model type, date ranges, size categories, and loaded status.
- </div>
- <h4>POST /api/models/{modelId}/load</h4>
- <p>Load a specific model into memory.</p>
-
- <div class="endpoint">
- <span class="method post">POST</span> /api/models/{modelId}/load
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "message": "Model loaded successfully",
- "model": "string"
- }
- </div>
- <h4>POST /api/models/{modelId}/unload</h4>
- <p>Unload a specific model from memory.</p>
-
- <div class="endpoint">
- <span class="method post">POST</span> /api/models/{modelId}/unload
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "message": "Model unloaded successfully",
- "model": "string"
- }
- </div>
- <h4>GET /api/models/types</h4>
- <p>Get available model types.</p>
-
- <div class="endpoint">
- <span class="method get">GET</span> /api/models/types
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "types": [
- "checkpoint",
- "vae",
- "lora",
- "controlnet",
- "embedding",
- "esrgan",
- "taesd"
- ]
- }
- </div>
- <h4>POST /api/models/refresh</h4>
- <p>Rescan model directories for new models.</p>
-
- <div class="endpoint">
- <span class="method post">POST</span> /api/models/refresh
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "message": "Model refresh completed",
- "models_found": 5,
- "models_updated": 2
- }
- </div>
- </div>
- </section>
- <section id="image-generation" class="section">
- <div class="section-header">
- <h2>Image Generation</h2>
- </div>
- <div class="section-content">
- <h4>POST /api/generate/text2img</h4>
- <p>Generate images from text prompts.</p>
-
- <div class="endpoint">
- <span class="method post">POST</span> /api/generate/text2img
- </div>
- <div class="info">
- <strong>Authentication Required:</strong> Yes
- </div>
- <h5>Request Body:</h5>
- <div class="json">
- {
- "model_name": "string",
- "prompt": "string",
- "negative_prompt": "string",
- "width": 1024,
- "height": 1024,
- "steps": 20,
- "cfg_scale": 7.0,
- "sampling_method": "euler",
- "scheduler": "karras",
- "seed": "random",
- "batch_count": 1,
- "clip_skip": 1,
- "n_threads": 4,
- "offload_params_to_cpu": false,
- "clip_on_cpu": false,
- "vae_on_cpu": false,
- "diffusion_flash_attn": false,
- "diffusion_conv_direct": false,
- "vae_conv_direct": false,
- "vae_path": "string",
- "clip_l_path": "string",
- "clip_g_path": "string",
- "taesd_path": "string",
- "embedding_dir": "string",
- "lora_model_dir": "string"
- }
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "request_id": "string",
- "status": "queued",
- "message": "Generation request queued successfully"
- }
- </div>
- <h4>POST /api/generate/img2img</h4>
- <p>Generate images from text prompts and input images.</p>
-
- <div class="endpoint">
- <span class="method post">POST</span> /api/generate/img2img
- </div>
- <div class="info">
- <strong>Authentication Required:</strong> Yes
- </div>
- <h4>POST /api/generate/controlnet</h4>
- <p>Generate images using ControlNet.</p>
-
- <div class="endpoint">
- <span class="method post">POST</span> /api/generate/controlnet
- </div>
- <div class="info">
- <strong>Authentication Required:</strong> Yes
- </div>
- <h4>POST /api/generate/upscale</h4>
- <p>Upscale images using ESRGAN models.</p>
-
- <div class="endpoint">
- <span class="method post">POST</span> /api/generate/upscale
- </div>
- <div class="info">
- <strong>Authentication Required:</strong> Yes
- </div>
- <h4>POST /api/generate/inpainting</h4>
- <p>Generate images with inpainting.</p>
-
- <div class="endpoint">
- <span class="method post">POST</span> /api/generate/inpainting
- </div>
- <div class="info">
- <strong>Authentication Required:</strong> Yes
- </div>
- </div>
- </section>
- <section id="queue-management" class="section">
- <div class="section-header">
- <h2>Queue Management</h2>
- </div>
- <div class="section-content">
- <h4>GET /api/queue/status</h4>
- <p>Get current queue status and all jobs.</p>
-
- <div class="endpoint">
- <span class="method get">GET</span> /api/queue/status
- </div>
- <div class="info">
- <strong>Authentication Required:</strong> Yes
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "queue": {
- "size": 5,
- "active_generations": 1,
- "running": true,
- "jobs": [
- {
- "id": "string",
- "status": "queued|processing|completed|failed",
- "prompt": "string",
- "queued_time": 1234567890,
- "start_time": 1234567890,
- "end_time": 1234567890,
- "position": 1,
- "progress": 0.5,
- "current_step": 10,
- "total_steps": 20,
- "time_elapsed": 5000,
- "time_remaining": 5000,
- "speed": 2.0
- }
- ]
- }
- }
- </div>
- <h4>GET /api/queue/job/{jobId}</h4>
- <p>Get detailed information about a specific job.</p>
-
- <div class="endpoint">
- <span class="method get">GET</span> /api/queue/job/{jobId}
- </div>
- <div class="info">
- <strong>Authentication Required:</strong> Yes
- </div>
- <h4>POST /api/queue/cancel</h4>
- <p>Cancel a specific job.</p>
-
- <div class="endpoint">
- <span class="method post">POST</span> /api/queue/cancel
- </div>
- <div class="info">
- <strong>Authentication Required:</strong> Yes
- </div>
- <h5>Request Body:</h5>
- <div class="json">
- {
- "job_id": "string"
- }
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "status": "success",
- "message": "Job cancelled successfully",
- "job_id": "string"
- }
- </div>
- <h4>POST /api/queue/clear</h4>
- <p>Clear all queued jobs.</p>
-
- <div class="endpoint">
- <span class="method post">POST</span> /api/queue/clear
- </div>
- <div class="info">
- <strong>Authentication Required:</strong> Yes
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "status": "success",
- "message": "Queue cleared successfully"
- }
- </div>
- </div>
- </section>
- <section id="file-management" class="section">
- <div class="section-header">
- <h2>File Management</h2>
- </div>
- <div class="section-content">
- <h4>GET /api/queue/job/{jobId}/output/{filename}</h4>
- <p>Download a specific output file from a completed job.</p>
-
- <div class="endpoint">
- <span class="method get">GET</span> /api/queue/job/{jobId}/output/{filename}
- </div>
- <div class="info">
- <strong>Authentication Required:</strong> No (public for frontend access)
- </div>
- <p><strong>Response:</strong> Binary file data with appropriate Content-Type header</p>
- <h4>GET /api/v1/jobs/{jobId}/output/{filename}</h4>
- <p>Alternative endpoint for downloading job output files.</p>
-
- <div class="endpoint">
- <span class="method get">GET</span> /api/v1/jobs/{jobId}/output/{filename}
- </div>
- <div class="info">
- <strong>Authentication Required:</strong> No
- </div>
- <h5>Query Parameters:</h5>
- <table class="parameter-table">
- <thead>
- <tr>
- <th>Parameter</th>
- <th>Type</th>
- <th>Required</th>
- <th>Description</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>thumb</td>
- <td>boolean</td>
- <td class="optional">No</td>
- <td>Generate thumbnail</td>
- </tr>
- <tr>
- <td>size</td>
- <td>integer</td>
- <td class="optional">No</td>
- <td>Thumbnail size (50-500px)</td>
- </tr>
- </tbody>
- </table>
- <p><strong>Response:</strong> Image file or thumbnail</p>
- <h4>GET /api/image/download</h4>
- <p>Download an image from a URL (CORS-free handling).</p>
-
- <div class="endpoint">
- <span class="method get">GET</span> /api/image/download
- </div>
- <div class="info">
- <strong>Authentication Required:</strong> No
- </div>
- <p><strong>Response:</strong> Binary image data</p>
- </div>
- </section>
- <section id="utilities" class="section">
- <div class="section-header">
- <h2>Utilities</h2>
- </div>
- <div class="section-content">
- <h4>GET /api/samplers</h4>
- <p>Get available sampling methods.</p>
-
- <div class="endpoint">
- <span class="method get">GET</span> /api/samplers
- </div>
- <div class="info">
- <strong>Authentication Required:</strong> Yes
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "samplers": [
- "euler",
- "euler_a",
- "heun",
- "dpm2",
- "dpmpp2s_a",
- "dpmpp2m",
- "dpmpp2mv2",
- "ipndm",
- "ipndm_v",
- "lcm",
- "ddim_trailing",
- "tcd"
- ]
- }
- </div>
- <h4>GET /api/schedulers</h4>
- <p>Get available schedulers.</p>
-
- <div class="endpoint">
- <span class="method get">GET</span> /api/schedulers
- </div>
- <div class="info">
- <strong>Authentication Required:</strong> Yes
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "schedulers": [
- "discrete",
- "karras",
- "exponential",
- "ays",
- "gits",
- "smoothstep",
- "sgm_uniform",
- "simple"
- ]
- }
- </div>
- <h4>GET /api/parameters</h4>
- <p>Get available generation parameters and their defaults.</p>
-
- <div class="endpoint">
- <span class="method get">GET</span> /api/parameters
- </div>
- <div class="info">
- <strong>Authentication Required:</strong> Yes
- </div>
- <h5>Response:</h5>
- <div class="json response-example">
- {
- "parameters": {
- "width": {
- "min": 64,
- "max": 4096,
- "default": 1024,
- "step": 8
- },
- "height": {
- "min": 64,
- "max": 4096,
- "default": 1024,
- "step": 8
- },
- "steps": {
- "min": 1,
- "max": 150,
- "default": 20,
- "step": 1
- },
- "cfg_scale": {
- "min": 1.0,
- "max": 30.0,
- "default": 7.0,
- "step": 0.1
- },
- "batch_count": {
- "min": 1,
- "max": 50,
- "default": 1,
- "step": 1
- }
- }
- }
- </div>
- <h4>POST /api/validate</h4>
- <p>Validate generation parameters.</p>
-
- <div class="endpoint">
- <span class="method post">POST</span> /api/validate
- </div>
- <div class="info">
- <strong>Authentication Required:</strong> No
- </div>
- <h4>POST /api/estimate</h4>
- <p>Estimate generation time and resource usage.</p>
-
- <div class="endpoint">
- <span class="method post">POST</span> /api/estimate
- </div>
- <div class="info">
- <strong>Authentication Required:</strong> Yes
- </div>
- </div>
- </section>
- <section id="error-responses" class="section">
- <div class="section-header">
- <h2>Error Responses</h2>
- </div>
- <div class="section-content">
- <p>All endpoints may return error responses in the following format:</p>
-
- <div class="json error-example">
- {
- "error": {
- "message": "Error description",
- "code": "ERROR_CODE",
- "status_code": 400,
- "request_id": "string",
- "timestamp": 1234567890
- }
- }
- </div>
- <h4>Common Error Codes</h4>
- <ul>
- <li><code>AUTH_REQUIRED</code> - Authentication is required for this endpoint</li>
- <li><code>INVALID_CREDENTIALS</code> - Invalid username or password</li>
- <li><code>INSUFFICIENT_PERMISSIONS</code> - User lacks required permissions</li>
- <li><code>MODEL_NOT_FOUND</code> - Model not found</li>
- <li><code>MODEL_NOT_LOADED</code> - Model not loaded into memory</li>
- <li><code>JOB_NOT_FOUND</code> - Job not found</li>
- <li><code>INVALID_PARAMETERS</code> - Invalid request parameters</li>
- <li><code>VALIDATION_ERROR</code> - Parameter validation failed</li>
- <li><code>INTERNAL_ERROR</code> - Internal server error</li>
- </ul>
- </div>
- </section>
- <section id="authentication-and-authorization" class="section">
- <div class="section-header">
- <h2>Authentication and Authorization</h2>
- </div>
- <div class="section-content">
- <h3>Authentication Headers</h3>
- <p>For endpoints requiring authentication, include one of the following:</p>
-
- <h4>JWT Token:</h4>
- <div class="code-block">
- Authorization: Bearer <jwt_token>
- </div>
- <h4>API Key:</h4>
- <div class="code-block">
- X-API-Key: <api_key>
- </div>
- <h4>Unix User:</h4>
- <div class="code-block">
- X-Unix-User: <username>
- </div>
- <h3>Permission Levels</h3>
- <ul>
- <li><strong>Guest</strong>: No authentication required (public endpoints)</li>
- <li><strong>User</strong>: Can generate images and manage own jobs</li>
- <li><strong>Admin</strong>: Can manage models, users, and system settings</li>
- </ul>
- <h3>Public Endpoints</h3>
- <p>The following endpoints do not require authentication:</p>
- <ul>
- <li><code>GET /api/health</code></li>
- <li><code>GET /api/status</code></li>
- <li><code>GET /api/version</code></li>
- <li><code>GET /api/queue/job/{jobId}/output/{filename}</code></li>
- <li><code>GET /api/v1/jobs/{jobId}/output/{filename}</code></li>
- <li><code>GET /api/image/download</code></li>
- <li><code>POST /api/validate</code></li>
- </ul>
- </div>
- </section>
- <section id="rate-limiting-and-usage" class="section">
- <div class="section-header">
- <h2>Rate Limiting and Usage</h2>
- </div>
- <div class="section-content">
- <h3>Concurrent Generation Limits</h3>
- <p>The server limits concurrent generations based on configuration:</p>
- <ul>
- <li>Default: 1 concurrent generation</li>
- <li>Configurable via server settings</li>
- </ul>
- <h3>Queue Management</h3>
- <ul>
- <li>Jobs are processed in FIFO order</li>
- <li>Queue status can be monitored via <code>/api/queue/status</code></li>
- <li>Jobs can be cancelled before processing starts</li>
- </ul>
- <h3>File Storage</h3>
- <ul>
- <li>Generated images are stored in configured output directory</li>
- <li>Files are organized by job ID: <code>{output_dir}/{job_id}/{filename}</code></li>
- <li>Output files can be downloaded via public endpoints</li>
- </ul>
- </div>
- </section>
- <section id="websocket-support" class="section">
- <div class="section-header">
- <h2>WebSocket Support</h2>
- </div>
- <div class="section-content">
- <p>The API supports WebSocket connections for real-time updates:</p>
- <h3>Connection Endpoint</h3>
- <div class="code-block">
- ws://localhost:8080/ws
- </div>
- <h3>Message Types</h3>
- <ul>
- <li><code>job_update</code>: Real-time job progress updates</li>
- <li><code>queue_update</code>: Queue status changes</li>
- <li><code>system_update</code>: System status changes</li>
- </ul>
- <h3>WebSocket Message Format</h3>
- <div class="json">
- {
- "type": "job_update",
- "data": {
- "job_id": "string",
- "progress": 0.5,
- "current_step": 10,
- "total_steps": 20,
- "time_elapsed": 5000,
- "time_remaining": 5000
- }
- }
- </div>
- </div>
- </section>
- <section id="examples" class="section">
- <div class="section-header">
- <h2>Examples</h2>
- </div>
- <div class="section-content">
- <h3>Basic Text-to-Image Generation</h3>
- <div class="code-block">
- # Login
- curl -X POST http://localhost:8080/api/auth/login \
- -H "Content-Type: application/json" \
- -d '{"username": "user", "password": "pass"}'
- # Generate image
- curl -X POST http://localhost:8080/api/generate/text2img \
- -H "Content-Type: application/json" \
- -H "Authorization: Bearer <token>" \
- -d '{
- "model_name": "sd_xl_base_1.0.safetensors",
- "prompt": "A beautiful landscape",
- "width": 1024,
- "height": 1024,
- "steps": 20,
- "cfg_scale": 7.0
- }'
- # Check job status
- curl -X GET http://localhost:8080/api/queue/job/{job_id} \
- -H "Authorization: Bearer <token>"'
- # Download result
- curl -X GET http://localhost:8080/api/queue/job/{job_id}/output/image_0.png \
- --output generated_image.png
- </div>
- <h3>Model Management</h3>
- <div class="code-block">
- # List models
- curl -X GET http://localhost:8080/api/models \
- -H "Authorization: Bearer <token>"'
- # Load a model
- curl -X POST http://localhost:8080/api/models/model_hash/load \
- -H "Authorization: Bearer <token>"'
- # Get model info
- curl -X GET http://localhost:8080/api/models/model_hash \
- -H "Authorization: Bearer <token>"'
- </div>
- </div>
- </section>
- <section id="configuration" class="section">
- <div class="section-header">
- <h2>Configuration</h2>
- </div>
- <div class="section-content">
- <h3>Environment Variables</h3>
- <ul>
- <li><code>STABLE_DIFFUSION_PORT</code>: Server port (default: 8080)</li>
- <li><code>STABLE_DIFFUSION_HOST</code>: Server host (default: 0.0.0.0)</li>
- <li><code>STABLE_DIFFUSION_MODELS_DIR</code>: Models directory path</li>
- <li><code>STABLE_DIFFUSION_OUTPUT_DIR</code>: Output directory path</li>
- </ul>
- <h3>Server Configuration</h3>
- <p>The server can be configured via:</p>
- <ul>
- <li>Command line arguments</li>
- <li>Configuration file</li>
- <li>Environment variables</li>
- </ul>
- <p>Refer to the server documentation for detailed configuration options.</p>
- </div>
- </section>
- <section id="troubleshooting" class="section">
- <div class="section-header">
- <h2>Troubleshooting</h2>
- </div>
- <div class="section-content">
- <h3>Common Issues</h3>
- <ol>
- <li><strong>Model not loaded</strong>: Ensure the model is loaded before generation</li>
- <li><strong>Authentication failed</strong>: Check credentials and auth method</li>
- <li><strong>Generation timeout</strong>: Increase timeout or reduce image size</li>
- <li><strong>Memory errors</strong>: Reduce batch size or image dimensions</li>
- </ol>
- <h3>Debug Mode</h3>
- <p>Enable debug logging by setting:</p>
- <ul>
- <li><code>verbose=true</code> in server configuration</li>
- <li><code>RUST_LOG=debug</code> environment variable</li>
- </ul>
- <h3>Health Checks</h3>
- <p>Monitor server health:</p>
- <div class="code-block">
- curl -X GET http://localhost:8080/api/health
- curl -X GET http://localhost:8080/api/status
- </div>
- </div>
- </section>
- </div>
- <a href="#top" class="back-to-top">↑ Back to Top</a>
- <script>
- // Smooth scrolling for anchor links
- document.querySelectorAll('a[href^="#"]').forEach(anchor => {
- anchor.addEventListener('click', function (e) {
- e.preventDefault();
- const target = document.querySelector(this.getAttribute('href'));
- if (target) {
- target.scrollIntoView({
- behavior: 'smooth',
- block: 'start'
- });
- }
- });
- });
- // Show/hide back to top button based on scroll position
- const backToTop = document.querySelector('.back-to-top');
- window.addEventListener('scroll', () => {
- if (window.pageYOffset > 300) {
- backToTop.style.display = 'block';
- } else {
- backToTop.style.display = 'none';
- }
- });
- // Hide back to top button initially
- backToTop.style.display = 'none';
- </script>
- </body>
- </html>
|