API.html 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Stable Diffusion REST API Documentation</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. box-sizing: border-box;
  12. }
  13. body {
  14. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  15. line-height: 1.6;
  16. color: #e9ecef;
  17. background-color: #1a1a1a;
  18. }
  19. .container {
  20. max-width: 1200px;
  21. margin: 0 auto;
  22. padding: 20px;
  23. display: flex;
  24. gap: 2rem;
  25. }
  26. .sidebar {
  27. width: 280px;
  28. flex-shrink: 0;
  29. position: sticky;
  30. top: 20px;
  31. height: fit-content;
  32. max-height: calc(100vh - 40px);
  33. overflow-y: auto;
  34. }
  35. .main-content {
  36. flex: 1;
  37. min-width: 0;
  38. }
  39. header {
  40. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  41. color: white;
  42. padding: 2rem;
  43. margin-bottom: 2rem;
  44. border-radius: 8px;
  45. box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  46. }
  47. .header-content {
  48. text-align: center;
  49. }
  50. h1 {
  51. font-size: 2.5rem;
  52. margin-bottom: 0.5rem;
  53. font-weight: 700;
  54. color: #000000;
  55. }
  56. .subtitle {
  57. font-size: 1.2rem;
  58. opacity: 0.9;
  59. }
  60. .toc {
  61. background: #2d3748;
  62. padding: 1.5rem;
  63. border-radius: 8px;
  64. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  65. margin-bottom: 2rem;
  66. border: 1px solid #4a5568;
  67. }
  68. .toc h2 {
  69. color: #667eea;
  70. margin-bottom: 1rem;
  71. font-size: 1.5rem;
  72. }
  73. .toc ul {
  74. list-style: none;
  75. }
  76. .toc-level-1 {
  77. margin-bottom: 1rem;
  78. }
  79. .toc-level-1 > li {
  80. margin-bottom: 0.5rem;
  81. font-weight: 600;
  82. }
  83. .toc-level-2 {
  84. margin-left: 1rem;
  85. margin-top: 0.5rem;
  86. }
  87. .toc-level-2 li {
  88. margin-bottom: 0.25rem;
  89. font-weight: 400;
  90. }
  91. .toc a {
  92. color: #a0aec0;
  93. text-decoration: none;
  94. transition: color 0.3s ease;
  95. display: block;
  96. padding: 0.25rem 0;
  97. border-radius: 4px;
  98. }
  99. .toc a:hover {
  100. color: #667eea;
  101. background: #4a5568;
  102. text-decoration: none;
  103. }
  104. .toc a.active {
  105. color: #667eea;
  106. background: #4a5568;
  107. }
  108. .section {
  109. background: #2d3748;
  110. margin-bottom: 2rem;
  111. border-radius: 8px;
  112. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  113. overflow: hidden;
  114. border: 1px solid #4a5568;
  115. }
  116. .section-header {
  117. background: #667eea;
  118. color: white;
  119. padding: 1.5rem;
  120. border-left: 4px solid #764ba2;
  121. }
  122. .section-content {
  123. padding: 1.5rem;
  124. }
  125. h2 {
  126. color: #000000;
  127. margin-bottom: 1rem;
  128. font-size: 1.8rem;
  129. font-weight: 600;
  130. }
  131. h3 {
  132. color: #000000;
  133. margin: 1.5rem 0 1rem 0;
  134. font-size: 1.4rem;
  135. font-weight: 600;
  136. border-bottom: 2px solid #4a5568;
  137. padding-bottom: 0.5rem;
  138. }
  139. h4 {
  140. color: #000000;
  141. margin: 1rem 0 0.5rem 0;
  142. font-size: 1.2rem;
  143. font-weight: 600;
  144. }
  145. .endpoint {
  146. background: #1a202c;
  147. border: 1px solid #4a5568;
  148. border-radius: 6px;
  149. padding: 1rem;
  150. margin: 1rem 0;
  151. font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  152. }
  153. .method {
  154. display: inline-block;
  155. padding: 0.25rem 0.5rem;
  156. border-radius: 4px;
  157. font-weight: bold;
  158. font-size: 0.9rem;
  159. margin-right: 0.5rem;
  160. }
  161. .get { background: #28a745; color: white; }
  162. .post { background: #007bff; color: white; }
  163. .put { background: #ffc107; color: #212529; }
  164. .delete { background: #dc3545; color: white; }
  165. .code-block {
  166. background: #1a202c;
  167. border: 1px solid #4a5568;
  168. border-radius: 6px;
  169. padding: 1rem;
  170. margin: 1rem 0;
  171. overflow-x: auto;
  172. font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  173. font-size: 0.9rem;
  174. color: #e2e8f0;
  175. }
  176. .json {
  177. background: #1a202c;
  178. color: #68d391;
  179. border-radius: 6px;
  180. padding: 1rem;
  181. margin: 1rem 0;
  182. overflow-x: auto;
  183. font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  184. font-size: 0.9rem;
  185. border: 1px solid #4a5568;
  186. }
  187. .parameter-table {
  188. width: 100%;
  189. border-collapse: collapse;
  190. margin: 1rem 0;
  191. background: #2d3748;
  192. border-radius: 6px;
  193. overflow: hidden;
  194. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  195. border: 1px solid #4a5568;
  196. }
  197. .parameter-table th {
  198. background: #667eea;
  199. color: white;
  200. padding: 0.75rem;
  201. text-align: left;
  202. font-weight: 600;
  203. }
  204. .parameter-table td {
  205. padding: 0.75rem;
  206. border-bottom: 1px solid #4a5568;
  207. color: #e2e8f0;
  208. }
  209. .parameter-table tr:nth-child(even) {
  210. background: #1a202c;
  211. }
  212. .required {
  213. color: #fc8181;
  214. font-weight: bold;
  215. }
  216. .optional {
  217. color: #68d391;
  218. font-weight: bold;
  219. }
  220. .note {
  221. background: #2d3748;
  222. border: 1px solid #f6e05e;
  223. border-radius: 6px;
  224. padding: 1rem;
  225. margin: 1rem 0;
  226. border-left: 4px solid #f6e05e;
  227. color: #e2e8f0;
  228. }
  229. .warning {
  230. background: #2d3748;
  231. border: 1px solid #fc8181;
  232. border-radius: 6px;
  233. padding: 1rem;
  234. margin: 1rem 0;
  235. border-left: 4px solid #fc8181;
  236. color: #e2e8f0;
  237. }
  238. .info {
  239. background: #2d3748;
  240. border: 1px solid #63b3ed;
  241. border-radius: 6px;
  242. padding: 1rem;
  243. margin: 1rem 0;
  244. border-left: 4px solid #63b3ed;
  245. color: #e2e8f0;
  246. }
  247. .response-example {
  248. background: #2d3748;
  249. border: 1px solid #68d391;
  250. border-radius: 6px;
  251. padding: 1rem;
  252. margin: 1rem 0;
  253. color: #e2e8f0;
  254. }
  255. .error-example {
  256. background: #2d3748;
  257. border: 1px solid #fc8181;
  258. border-radius: 6px;
  259. padding: 1rem;
  260. margin: 1rem 0;
  261. color: #e2e8f0;
  262. }
  263. .back-to-top {
  264. position: fixed;
  265. bottom: 20px;
  266. right: 20px;
  267. background: #667eea;
  268. color: white;
  269. padding: 0.5rem 1rem;
  270. border-radius: 6px;
  271. text-decoration: none;
  272. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  273. transition: all 0.3s ease;
  274. border: 1px solid #764ba2;
  275. }
  276. .back-to-top:hover {
  277. background: #764ba2;
  278. transform: translateY(-2px);
  279. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
  280. }
  281. @media (max-width: 1024px) {
  282. .container {
  283. flex-direction: column;
  284. }
  285. .sidebar {
  286. width: 100%;
  287. position: static;
  288. height: auto;
  289. max-height: none;
  290. margin-bottom: 2rem;
  291. }
  292. .main-content {
  293. width: 100%;
  294. }
  295. }
  296. @media (max-width: 768px) {
  297. .container {
  298. padding: 10px;
  299. }
  300. h1 {
  301. font-size: 2rem;
  302. }
  303. .toc-level-2 {
  304. margin-left: 0.5rem;
  305. }
  306. .parameter-table {
  307. font-size: 0.8rem;
  308. }
  309. .json {
  310. font-size: 0.8rem;
  311. }
  312. .section-content {
  313. padding: 1rem;
  314. }
  315. .toc {
  316. padding: 1rem;
  317. }
  318. }
  319. </style>
  320. </head>
  321. <body>
  322. <div class="container">
  323. <aside class="sidebar">
  324. <nav class="toc">
  325. <h2>Table of Contents</h2>
  326. <ul class="toc-level-1">
  327. <li><a href="#authentication">Authentication</a>
  328. <ul class="toc-level-2">
  329. <li><a href="#authentication-methods">Authentication Methods</a></li>
  330. <li><a href="#authentication-endpoints">Authentication Endpoints</a></li>
  331. </ul>
  332. </li>
  333. <li><a href="#system-information">System Information</a></li>
  334. <li><a href="#model-management">Model Management</a></li>
  335. <li><a href="#image-generation">Image Generation</a></li>
  336. <li><a href="#queue-management">Queue Management</a></li>
  337. <li><a href="#file-management">File Management</a></li>
  338. <li><a href="#utilities">Utilities</a></li>
  339. <li><a href="#error-responses">Error Responses</a></li>
  340. <li><a href="#authentication-and-authorization">Authentication and Authorization</a></li>
  341. <li><a href="#rate-limiting-and-usage">Rate Limiting and Usage</a></li>
  342. <li><a href="#websocket-support">WebSocket Support</a></li>
  343. <li><a href="#examples">Examples</a></li>
  344. <li><a href="#configuration">Configuration</a></li>
  345. <li><a href="#troubleshooting">Troubleshooting</a></li>
  346. </ul>
  347. </nav>
  348. </aside>
  349. <main class="main-content">
  350. <header>
  351. <div class="header-content">
  352. <h1>Stable Diffusion REST API Documentation</h1>
  353. <p class="subtitle">Comprehensive API reference for stable-diffusion.cpp-rest server</p>
  354. </div>
  355. </header>
  356. <section id="authentication" class="section">
  357. <div class="section-header">
  358. <h2>Authentication</h2>
  359. </div>
  360. <div class="section-content">
  361. <h3 id="authentication-methods">Authentication Methods</h3>
  362. <p>The API supports multiple authentication methods:</p>
  363. <ul>
  364. <li><strong>None</strong>: No authentication required</li>
  365. <li><strong>JWT</strong>: JSON Web Token authentication</li>
  366. <li><strong>API Key</strong>: API key authentication</li>
  367. <li><strong>Unix</strong>: Unix user authentication</li>
  368. <li><strong>PAM</strong>: Pluggable Authentication Modules</li>
  369. </ul>
  370. <h3 id="authentication-endpoints">Authentication Endpoints</h3>
  371. <h4>POST /api/auth/login</h4>
  372. <p>Authenticate with the server and receive an access token.</p>
  373. <div class="endpoint">
  374. <span class="method post">POST</span> /api/auth/login
  375. </div>
  376. <h5>Request Body:</h5>
  377. <div class="json">
  378. {
  379. "username": "string",
  380. "password": "string" // Optional for Unix auth without PAM
  381. }
  382. </div>
  383. <h5>Response:</h5>
  384. <div class="json response-example">
  385. {
  386. "token": "string",
  387. "user": {
  388. "id": "string",
  389. "username": "string",
  390. "role": "string",
  391. "permissions": ["string"]
  392. },
  393. "message": "string"
  394. }
  395. </div>
  396. <h4>POST /api/auth/logout</h4>
  397. <p>Log out and invalidate the current session.</p>
  398. <div class="endpoint">
  399. <span class="method post">POST</span> /api/auth/logout
  400. </div>
  401. <h5>Response:</h5>
  402. <div class="json response-example">
  403. {
  404. "message": "Logout successful"
  405. }
  406. </div>
  407. <h4>GET /api/auth/validate</h4>
  408. <p>Validate the current authentication token.</p>
  409. <div class="endpoint">
  410. <span class="method get">GET</span> /api/auth/validate
  411. </div>
  412. <h5>Headers:</h5>
  413. <div class="code-block">
  414. Authorization: Bearer &lt;token&gt;
  415. </div>
  416. <h5>Response:</h5>
  417. <div class="json response-example">
  418. {
  419. "user": {
  420. "id": "string",
  421. "username": "string",
  422. "role": "string",
  423. "permissions": ["string"]
  424. },
  425. "valid": true
  426. }
  427. </div>
  428. <h4>POST /api/auth/refresh</h4>
  429. <p>Refresh the current authentication token.</p>
  430. <div class="endpoint">
  431. <span class="method post">POST</span> /api/auth/refresh
  432. </div>
  433. <h5>Response:</h5>
  434. <div class="json response-example">
  435. {
  436. "token": "string",
  437. "message": "Token refreshed successfully"
  438. }
  439. </div>
  440. <h4>GET /api/auth/me</h4>
  441. <p>Get information about the currently authenticated user.</p>
  442. <div class="endpoint">
  443. <span class="method get">GET</span> /api/auth/me
  444. </div>
  445. <h5>Headers:</h5>
  446. <div class="code-block">
  447. Authorization: Bearer &lt;token&gt;
  448. </div>
  449. <h5>Response:</h5>
  450. <div class="json response-example">
  451. {
  452. "user": {
  453. "id": "string",
  454. "username": "string",
  455. "role": "string",
  456. "permissions": ["string"]
  457. }
  458. }
  459. </div>
  460. </div>
  461. </section>
  462. <section id="system-information" class="section">
  463. <div class="section-header">
  464. <h2>System Information</h2>
  465. </div>
  466. <div class="section-content">
  467. <h4>GET /api/health</h4>
  468. <p>Check if the server is running and healthy.</p>
  469. <div class="endpoint">
  470. <span class="method get">GET</span> /api/health
  471. </div>
  472. <h5>Response:</h5>
  473. <div class="json response-example">
  474. {
  475. "status": "healthy",
  476. "timestamp": 1234567890,
  477. "version": "1.0.0"
  478. }
  479. </div>
  480. <h4>GET /api/status</h4>
  481. <p>Get detailed server and system status.</p>
  482. <div class="endpoint">
  483. <span class="method get">GET</span> /api/status
  484. </div>
  485. <h5>Response:</h5>
  486. <div class="json response-example">
  487. {
  488. "server": {
  489. "running": true,
  490. "host": "localhost",
  491. "port": 8080
  492. },
  493. "generation_queue": {
  494. "running": true,
  495. "queue_size": 5,
  496. "active_generations": 1
  497. },
  498. "models": {
  499. "loaded_count": 2,
  500. "available_count": 10
  501. }
  502. }
  503. </div>
  504. <h4>GET /api/version</h4>
  505. <p>Get version information about the server.</p>
  506. <div class="endpoint">
  507. <span class="method get">GET</span> /api/version
  508. </div>
  509. <h5>Response:</h5>
  510. <div class="json response-example">
  511. {
  512. "version": "1.0.0",
  513. "type": "release",
  514. "commit": {
  515. "short": "abc1234",
  516. "full": "abc1234567890abcdef"
  517. },
  518. "branch": "main",
  519. "clean": true,
  520. "build_time": "2024-01-01T12:00:00Z"
  521. }
  522. </div>
  523. <h4>GET /api/config</h4>
  524. <p>Get server configuration (requires authentication).</p>
  525. <div class="endpoint">
  526. <span class="method get">GET</span> /api/config
  527. </div>
  528. <h5>Response:</h5>
  529. <div class="json response-example">
  530. {
  531. "config": {
  532. // Server configuration details
  533. }
  534. }
  535. </div>
  536. <h4>GET /api/system</h4>
  537. <p>Get system information (requires authentication).</p>
  538. <div class="endpoint">
  539. <span class="method get">GET</span> /api/system
  540. </div>
  541. <h5>Response:</h5>
  542. <div class="json response-example">
  543. {
  544. "system": {
  545. // System information details
  546. }
  547. }
  548. </div>
  549. <h4>POST /api/system/restart</h4>
  550. <p>Restart the server (requires admin authentication).</p>
  551. <div class="endpoint">
  552. <span class="method post">POST</span> /api/system/restart
  553. </div>
  554. <h5>Response:</h5>
  555. <div class="json response-example">
  556. {
  557. "message": "Server restart initiated"
  558. }
  559. </div>
  560. </div>
  561. </section>
  562. <section id="model-management" class="section">
  563. <div class="section-header">
  564. <h2>Model Management</h2>
  565. </div>
  566. <div class="section-content">
  567. <h4>GET /api/models</h4>
  568. <p>List all available models with filtering and pagination support.</p>
  569. <div class="endpoint">
  570. <span class="method get">GET</span> /api/models
  571. </div>
  572. <h5>Query Parameters:</h5>
  573. <table class="parameter-table">
  574. <thead>
  575. <tr>
  576. <th>Parameter</th>
  577. <th>Type</th>
  578. <th>Required</th>
  579. <th>Description</th>
  580. </tr>
  581. </thead>
  582. <tbody>
  583. <tr>
  584. <td>type</td>
  585. <td>string</td>
  586. <td class="optional">No</td>
  587. <td>Filter by model type (checkpoint, vae, lora, etc.)</td>
  588. </tr>
  589. <tr>
  590. <td>search</td>
  591. <td>string</td>
  592. <td class="optional">No</td>
  593. <td>Search in model names and descriptions</td>
  594. </tr>
  595. <tr>
  596. <td>sort_by</td>
  597. <td>string</td>
  598. <td class="optional">No</td>
  599. <td>Sort field (name, size, date, type, loaded)</td>
  600. </tr>
  601. <tr>
  602. <td>sort_order</td>
  603. <td>string</td>
  604. <td class="optional">No</td>
  605. <td>Sort order (asc, desc)</td>
  606. </tr>
  607. <tr>
  608. <td>limit</td>
  609. <td>integer</td>
  610. <td class="optional">No</td>
  611. <td>Pagination limit (default: 50, 0 = no limit)</td>
  612. </tr>
  613. <tr>
  614. <td>page</td>
  615. <td>integer</td>
  616. <td class="optional">No</td>
  617. <td>Page number (default: 1)</td>
  618. </tr>
  619. </tbody>
  620. </table>
  621. <div class="note">
  622. <strong>Note:</strong> This endpoint supports advanced filtering by model type, date ranges, size categories, and loaded status.
  623. </div>
  624. <h4>POST /api/models/{modelId}/load</h4>
  625. <p>Load a specific model into memory.</p>
  626. <div class="endpoint">
  627. <span class="method post">POST</span> /api/models/{modelId}/load
  628. </div>
  629. <h5>Response:</h5>
  630. <div class="json response-example">
  631. {
  632. "message": "Model loaded successfully",
  633. "model": "string"
  634. }
  635. </div>
  636. <h4>POST /api/models/{modelId}/unload</h4>
  637. <p>Unload a specific model from memory.</p>
  638. <div class="endpoint">
  639. <span class="method post">POST</span> /api/models/{modelId}/unload
  640. </div>
  641. <h5>Response:</h5>
  642. <div class="json response-example">
  643. {
  644. "message": "Model unloaded successfully",
  645. "model": "string"
  646. }
  647. </div>
  648. <h4>GET /api/models/types</h4>
  649. <p>Get available model types.</p>
  650. <div class="endpoint">
  651. <span class="method get">GET</span> /api/models/types
  652. </div>
  653. <h5>Response:</h5>
  654. <div class="json response-example">
  655. {
  656. "types": [
  657. "checkpoint",
  658. "vae",
  659. "lora",
  660. "controlnet",
  661. "embedding",
  662. "esrgan",
  663. "taesd"
  664. ]
  665. }
  666. </div>
  667. <h4>POST /api/models/refresh</h4>
  668. <p>Rescan model directories for new models.</p>
  669. <div class="endpoint">
  670. <span class="method post">POST</span> /api/models/refresh
  671. </div>
  672. <h5>Response:</h5>
  673. <div class="json response-example">
  674. {
  675. "message": "Model refresh completed",
  676. "models_found": 5,
  677. "models_updated": 2
  678. }
  679. </div>
  680. </div>
  681. </section>
  682. <section id="image-generation" class="section">
  683. <div class="section-header">
  684. <h2>Image Generation</h2>
  685. </div>
  686. <div class="section-content">
  687. <h4>POST /api/generate/text2img</h4>
  688. <p>Generate images from text prompts.</p>
  689. <div class="endpoint">
  690. <span class="method post">POST</span> /api/generate/text2img
  691. </div>
  692. <div class="info">
  693. <strong>Authentication Required:</strong> Yes
  694. </div>
  695. <h5>Request Body:</h5>
  696. <div class="json">
  697. {
  698. "model_name": "string",
  699. "prompt": "string",
  700. "negative_prompt": "string",
  701. "width": 1024,
  702. "height": 1024,
  703. "steps": 20,
  704. "cfg_scale": 7.0,
  705. "sampling_method": "euler",
  706. "scheduler": "karras",
  707. "seed": "random",
  708. "batch_count": 1,
  709. "clip_skip": 1,
  710. "n_threads": 4,
  711. "offload_params_to_cpu": false,
  712. "clip_on_cpu": false,
  713. "vae_on_cpu": false,
  714. "diffusion_flash_attn": false,
  715. "diffusion_conv_direct": false,
  716. "vae_conv_direct": false,
  717. "vae_path": "string",
  718. "clip_l_path": "string",
  719. "clip_g_path": "string",
  720. "taesd_path": "string",
  721. "embedding_dir": "string",
  722. "lora_model_dir": "string"
  723. }
  724. </div>
  725. <h5>Response:</h5>
  726. <div class="json response-example">
  727. {
  728. "request_id": "string",
  729. "status": "queued",
  730. "message": "Generation request queued successfully"
  731. }
  732. </div>
  733. <h4>POST /api/generate/img2img</h4>
  734. <p>Generate images from text prompts and input images.</p>
  735. <div class="endpoint">
  736. <span class="method post">POST</span> /api/generate/img2img
  737. </div>
  738. <div class="info">
  739. <strong>Authentication Required:</strong> Yes
  740. </div>
  741. <h4>POST /api/generate/controlnet</h4>
  742. <p>Generate images using ControlNet.</p>
  743. <div class="endpoint">
  744. <span class="method post">POST</span> /api/generate/controlnet
  745. </div>
  746. <div class="info">
  747. <strong>Authentication Required:</strong> Yes
  748. </div>
  749. <h4>POST /api/generate/upscale</h4>
  750. <p>Upscale images using ESRGAN models.</p>
  751. <div class="endpoint">
  752. <span class="method post">POST</span> /api/generate/upscale
  753. </div>
  754. <div class="info">
  755. <strong>Authentication Required:</strong> Yes
  756. </div>
  757. <h4>POST /api/generate/inpainting</h4>
  758. <p>Generate images with inpainting.</p>
  759. <div class="endpoint">
  760. <span class="method post">POST</span> /api/generate/inpainting
  761. </div>
  762. <div class="info">
  763. <strong>Authentication Required:</strong> Yes
  764. </div>
  765. </div>
  766. </section>
  767. <section id="queue-management" class="section">
  768. <div class="section-header">
  769. <h2>Queue Management</h2>
  770. </div>
  771. <div class="section-content">
  772. <h4>GET /api/queue/status</h4>
  773. <p>Get current queue status and all jobs.</p>
  774. <div class="endpoint">
  775. <span class="method get">GET</span> /api/queue/status
  776. </div>
  777. <div class="info">
  778. <strong>Authentication Required:</strong> Yes
  779. </div>
  780. <h5>Response:</h5>
  781. <div class="json response-example">
  782. {
  783. "queue": {
  784. "size": 5,
  785. "active_generations": 1,
  786. "running": true,
  787. "jobs": [
  788. {
  789. "id": "string",
  790. "status": "queued|processing|completed|failed",
  791. "prompt": "string",
  792. "queued_time": 1234567890,
  793. "start_time": 1234567890,
  794. "end_time": 1234567890,
  795. "position": 1,
  796. "progress": 0.5,
  797. "current_step": 10,
  798. "total_steps": 20,
  799. "time_elapsed": 5000,
  800. "time_remaining": 5000,
  801. "speed": 2.0
  802. }
  803. ]
  804. }
  805. }
  806. </div>
  807. <h4>GET /api/queue/job/{jobId}</h4>
  808. <p>Get detailed information about a specific job.</p>
  809. <div class="endpoint">
  810. <span class="method get">GET</span> /api/queue/job/{jobId}
  811. </div>
  812. <div class="info">
  813. <strong>Authentication Required:</strong> Yes
  814. </div>
  815. <h4>POST /api/queue/cancel</h4>
  816. <p>Cancel a specific job.</p>
  817. <div class="endpoint">
  818. <span class="method post">POST</span> /api/queue/cancel
  819. </div>
  820. <div class="info">
  821. <strong>Authentication Required:</strong> Yes
  822. </div>
  823. <h5>Request Body:</h5>
  824. <div class="json">
  825. {
  826. "job_id": "string"
  827. }
  828. </div>
  829. <h5>Response:</h5>
  830. <div class="json response-example">
  831. {
  832. "status": "success",
  833. "message": "Job cancelled successfully",
  834. "job_id": "string"
  835. }
  836. </div>
  837. <h4>POST /api/queue/clear</h4>
  838. <p>Clear all queued jobs.</p>
  839. <div class="endpoint">
  840. <span class="method post">POST</span> /api/queue/clear
  841. </div>
  842. <div class="info">
  843. <strong>Authentication Required:</strong> Yes
  844. </div>
  845. <h5>Response:</h5>
  846. <div class="json response-example">
  847. {
  848. "status": "success",
  849. "message": "Queue cleared successfully"
  850. }
  851. </div>
  852. </div>
  853. </section>
  854. <section id="file-management" class="section">
  855. <div class="section-header">
  856. <h2>File Management</h2>
  857. </div>
  858. <div class="section-content">
  859. <h4>GET /api/queue/job/{jobId}/output/{filename}</h4>
  860. <p>Download a specific output file from a completed job.</p>
  861. <div class="endpoint">
  862. <span class="method get">GET</span> /api/queue/job/{jobId}/output/{filename}
  863. </div>
  864. <div class="info">
  865. <strong>Authentication Required:</strong> No (public for frontend access)
  866. </div>
  867. <p><strong>Response:</strong> Binary file data with appropriate Content-Type header</p>
  868. <h4>GET /api/v1/jobs/{jobId}/output/{filename}</h4>
  869. <p>Alternative endpoint for downloading job output files.</p>
  870. <div class="endpoint">
  871. <span class="method get">GET</span> /api/v1/jobs/{jobId}/output/{filename}
  872. </div>
  873. <div class="info">
  874. <strong>Authentication Required:</strong> No
  875. </div>
  876. <h5>Query Parameters:</h5>
  877. <table class="parameter-table">
  878. <thead>
  879. <tr>
  880. <th>Parameter</th>
  881. <th>Type</th>
  882. <th>Required</th>
  883. <th>Description</th>
  884. </tr>
  885. </thead>
  886. <tbody>
  887. <tr>
  888. <td>thumb</td>
  889. <td>boolean</td>
  890. <td class="optional">No</td>
  891. <td>Generate thumbnail</td>
  892. </tr>
  893. <tr>
  894. <td>size</td>
  895. <td>integer</td>
  896. <td class="optional">No</td>
  897. <td>Thumbnail size (50-500px)</td>
  898. </tr>
  899. </tbody>
  900. </table>
  901. <p><strong>Response:</strong> Image file or thumbnail</p>
  902. <h4>GET /api/image/download</h4>
  903. <p>Download an image from a URL (CORS-free handling).</p>
  904. <div class="endpoint">
  905. <span class="method get">GET</span> /api/image/download
  906. </div>
  907. <div class="info">
  908. <strong>Authentication Required:</strong> No
  909. </div>
  910. <p><strong>Response:</strong> Binary image data</p>
  911. </div>
  912. </section>
  913. <section id="utilities" class="section">
  914. <div class="section-header">
  915. <h2>Utilities</h2>
  916. </div>
  917. <div class="section-content">
  918. <h4>GET /api/samplers</h4>
  919. <p>Get available sampling methods.</p>
  920. <div class="endpoint">
  921. <span class="method get">GET</span> /api/samplers
  922. </div>
  923. <div class="info">
  924. <strong>Authentication Required:</strong> Yes
  925. </div>
  926. <h5>Response:</h5>
  927. <div class="json response-example">
  928. {
  929. "samplers": [
  930. "euler",
  931. "euler_a",
  932. "heun",
  933. "dpm2",
  934. "dpmpp2s_a",
  935. "dpmpp2m",
  936. "dpmpp2mv2",
  937. "ipndm",
  938. "ipndm_v",
  939. "lcm",
  940. "ddim_trailing",
  941. "tcd"
  942. ]
  943. }
  944. </div>
  945. <h4>GET /api/schedulers</h4>
  946. <p>Get available schedulers.</p>
  947. <div class="endpoint">
  948. <span class="method get">GET</span> /api/schedulers
  949. </div>
  950. <div class="info">
  951. <strong>Authentication Required:</strong> Yes
  952. </div>
  953. <h5>Response:</h5>
  954. <div class="json response-example">
  955. {
  956. "schedulers": [
  957. "discrete",
  958. "karras",
  959. "exponential",
  960. "ays",
  961. "gits",
  962. "smoothstep",
  963. "sgm_uniform",
  964. "simple"
  965. ]
  966. }
  967. </div>
  968. <h4>GET /api/parameters</h4>
  969. <p>Get available generation parameters and their defaults.</p>
  970. <div class="endpoint">
  971. <span class="method get">GET</span> /api/parameters
  972. </div>
  973. <div class="info">
  974. <strong>Authentication Required:</strong> Yes
  975. </div>
  976. <h5>Response:</h5>
  977. <div class="json response-example">
  978. {
  979. "parameters": {
  980. "width": {
  981. "min": 64,
  982. "max": 4096,
  983. "default": 1024,
  984. "step": 8
  985. },
  986. "height": {
  987. "min": 64,
  988. "max": 4096,
  989. "default": 1024,
  990. "step": 8
  991. },
  992. "steps": {
  993. "min": 1,
  994. "max": 150,
  995. "default": 20,
  996. "step": 1
  997. },
  998. "cfg_scale": {
  999. "min": 1.0,
  1000. "max": 30.0,
  1001. "default": 7.0,
  1002. "step": 0.1
  1003. },
  1004. "batch_count": {
  1005. "min": 1,
  1006. "max": 50,
  1007. "default": 1,
  1008. "step": 1
  1009. }
  1010. }
  1011. }
  1012. </div>
  1013. <h4>POST /api/validate</h4>
  1014. <p>Validate generation parameters.</p>
  1015. <div class="endpoint">
  1016. <span class="method post">POST</span> /api/validate
  1017. </div>
  1018. <div class="info">
  1019. <strong>Authentication Required:</strong> No
  1020. </div>
  1021. <h4>POST /api/estimate</h4>
  1022. <p>Estimate generation time and resource usage.</p>
  1023. <div class="endpoint">
  1024. <span class="method post">POST</span> /api/estimate
  1025. </div>
  1026. <div class="info">
  1027. <strong>Authentication Required:</strong> Yes
  1028. </div>
  1029. </div>
  1030. </section>
  1031. <section id="error-responses" class="section">
  1032. <div class="section-header">
  1033. <h2>Error Responses</h2>
  1034. </div>
  1035. <div class="section-content">
  1036. <p>All endpoints may return error responses in the following format:</p>
  1037. <div class="json error-example">
  1038. {
  1039. "error": {
  1040. "message": "Error description",
  1041. "code": "ERROR_CODE",
  1042. "status_code": 400,
  1043. "request_id": "string",
  1044. "timestamp": 1234567890
  1045. }
  1046. }
  1047. </div>
  1048. <h4>Common Error Codes</h4>
  1049. <ul>
  1050. <li><code>AUTH_REQUIRED</code> - Authentication is required for this endpoint</li>
  1051. <li><code>INVALID_CREDENTIALS</code> - Invalid username or password</li>
  1052. <li><code>INSUFFICIENT_PERMISSIONS</code> - User lacks required permissions</li>
  1053. <li><code>MODEL_NOT_FOUND</code> - Model not found</li>
  1054. <li><code>MODEL_NOT_LOADED</code> - Model not loaded into memory</li>
  1055. <li><code>JOB_NOT_FOUND</code> - Job not found</li>
  1056. <li><code>INVALID_PARAMETERS</code> - Invalid request parameters</li>
  1057. <li><code>VALIDATION_ERROR</code> - Parameter validation failed</li>
  1058. <li><code>INTERNAL_ERROR</code> - Internal server error</li>
  1059. </ul>
  1060. </div>
  1061. </section>
  1062. <section id="authentication-and-authorization" class="section">
  1063. <div class="section-header">
  1064. <h2>Authentication and Authorization</h2>
  1065. </div>
  1066. <div class="section-content">
  1067. <h3>Authentication Headers</h3>
  1068. <p>For endpoints requiring authentication, include one of the following:</p>
  1069. <h4>JWT Token:</h4>
  1070. <div class="code-block">
  1071. Authorization: Bearer &lt;jwt_token&gt;
  1072. </div>
  1073. <h4>API Key:</h4>
  1074. <div class="code-block">
  1075. X-API-Key: &lt;api_key&gt;
  1076. </div>
  1077. <h4>Unix User:</h4>
  1078. <div class="code-block">
  1079. X-Unix-User: &lt;username&gt;
  1080. </div>
  1081. <h3>Permission Levels</h3>
  1082. <ul>
  1083. <li><strong>Guest</strong>: No authentication required (public endpoints)</li>
  1084. <li><strong>User</strong>: Can generate images and manage own jobs</li>
  1085. <li><strong>Admin</strong>: Can manage models, users, and system settings</li>
  1086. </ul>
  1087. <h3>Public Endpoints</h3>
  1088. <p>The following endpoints do not require authentication:</p>
  1089. <ul>
  1090. <li><code>GET /api/health</code></li>
  1091. <li><code>GET /api/status</code></li>
  1092. <li><code>GET /api/version</code></li>
  1093. <li><code>GET /api/queue/job/{jobId}/output/{filename}</code></li>
  1094. <li><code>GET /api/v1/jobs/{jobId}/output/{filename}</code></li>
  1095. <li><code>GET /api/image/download</code></li>
  1096. <li><code>POST /api/validate</code></li>
  1097. </ul>
  1098. </div>
  1099. </section>
  1100. <section id="rate-limiting-and-usage" class="section">
  1101. <div class="section-header">
  1102. <h2>Rate Limiting and Usage</h2>
  1103. </div>
  1104. <div class="section-content">
  1105. <h3>Concurrent Generation Limits</h3>
  1106. <p>The server limits concurrent generations based on configuration:</p>
  1107. <ul>
  1108. <li>Default: 1 concurrent generation</li>
  1109. <li>Configurable via server settings</li>
  1110. </ul>
  1111. <h3>Queue Management</h3>
  1112. <ul>
  1113. <li>Jobs are processed in FIFO order</li>
  1114. <li>Queue status can be monitored via <code>/api/queue/status</code></li>
  1115. <li>Jobs can be cancelled before processing starts</li>
  1116. </ul>
  1117. <h3>File Storage</h3>
  1118. <ul>
  1119. <li>Generated images are stored in configured output directory</li>
  1120. <li>Files are organized by job ID: <code>{output_dir}/{job_id}/{filename}</code></li>
  1121. <li>Output files can be downloaded via public endpoints</li>
  1122. </ul>
  1123. </div>
  1124. </section>
  1125. <section id="websocket-support" class="section">
  1126. <div class="section-header">
  1127. <h2>WebSocket Support</h2>
  1128. </div>
  1129. <div class="section-content">
  1130. <p>The API supports WebSocket connections for real-time updates:</p>
  1131. <h3>Connection Endpoint</h3>
  1132. <div class="code-block">
  1133. ws://localhost:8080/ws
  1134. </div>
  1135. <h3>Message Types</h3>
  1136. <ul>
  1137. <li><code>job_update</code>: Real-time job progress updates</li>
  1138. <li><code>queue_update</code>: Queue status changes</li>
  1139. <li><code>system_update</code>: System status changes</li>
  1140. </ul>
  1141. <h3>WebSocket Message Format</h3>
  1142. <div class="json">
  1143. {
  1144. "type": "job_update",
  1145. "data": {
  1146. "job_id": "string",
  1147. "progress": 0.5,
  1148. "current_step": 10,
  1149. "total_steps": 20,
  1150. "time_elapsed": 5000,
  1151. "time_remaining": 5000
  1152. }
  1153. }
  1154. </div>
  1155. </div>
  1156. </section>
  1157. <section id="examples" class="section">
  1158. <div class="section-header">
  1159. <h2>Examples</h2>
  1160. </div>
  1161. <div class="section-content">
  1162. <h3>Basic Text-to-Image Generation</h3>
  1163. <div class="code-block">
  1164. # Login
  1165. curl -X POST http://localhost:8080/api/auth/login \
  1166. -H "Content-Type: application/json" \
  1167. -d '{"username": "user", "password": "pass"}'
  1168. # Generate image
  1169. curl -X POST http://localhost:8080/api/generate/text2img \
  1170. -H "Content-Type: application/json" \
  1171. -H "Authorization: Bearer &lt;token&gt;" \
  1172. -d '{
  1173. "model_name": "sd_xl_base_1.0.safetensors",
  1174. "prompt": "A beautiful landscape",
  1175. "width": 1024,
  1176. "height": 1024,
  1177. "steps": 20,
  1178. "cfg_scale": 7.0
  1179. }'
  1180. # Check job status
  1181. curl -X GET http://localhost:8080/api/queue/job/{job_id} \
  1182. -H "Authorization: Bearer &lt;token&gt;"'
  1183. # Download result
  1184. curl -X GET http://localhost:8080/api/queue/job/{job_id}/output/image_0.png \
  1185. --output generated_image.png
  1186. </div>
  1187. <h3>Model Management</h3>
  1188. <div class="code-block">
  1189. # List models
  1190. curl -X GET http://localhost:8080/api/models \
  1191. -H "Authorization: Bearer &lt;token&gt;"'
  1192. # Load a model
  1193. curl -X POST http://localhost:8080/api/models/model_hash/load \
  1194. -H "Authorization: Bearer &lt;token&gt;"'
  1195. # Get model info
  1196. curl -X GET http://localhost:8080/api/models/model_hash \
  1197. -H "Authorization: Bearer &lt;token&gt;"'
  1198. </div>
  1199. </div>
  1200. </section>
  1201. <section id="configuration" class="section">
  1202. <div class="section-header">
  1203. <h2>Configuration</h2>
  1204. </div>
  1205. <div class="section-content">
  1206. <h3>Environment Variables</h3>
  1207. <ul>
  1208. <li><code>STABLE_DIFFUSION_PORT</code>: Server port (default: 8080)</li>
  1209. <li><code>STABLE_DIFFUSION_HOST</code>: Server host (default: 0.0.0.0)</li>
  1210. <li><code>STABLE_DIFFUSION_MODELS_DIR</code>: Models directory path</li>
  1211. <li><code>STABLE_DIFFUSION_OUTPUT_DIR</code>: Output directory path</li>
  1212. </ul>
  1213. <h3>Server Configuration</h3>
  1214. <p>The server can be configured via:</p>
  1215. <ul>
  1216. <li>Command line arguments</li>
  1217. <li>Configuration file</li>
  1218. <li>Environment variables</li>
  1219. </ul>
  1220. <p>Refer to the server documentation for detailed configuration options.</p>
  1221. </div>
  1222. </section>
  1223. <section id="troubleshooting" class="section">
  1224. <div class="section-header">
  1225. <h2>Troubleshooting</h2>
  1226. </div>
  1227. <div class="section-content">
  1228. <h3>Common Issues</h3>
  1229. <ol>
  1230. <li><strong>Model not loaded</strong>: Ensure the model is loaded before generation</li>
  1231. <li><strong>Authentication failed</strong>: Check credentials and auth method</li>
  1232. <li><strong>Generation timeout</strong>: Increase timeout or reduce image size</li>
  1233. <li><strong>Memory errors</strong>: Reduce batch size or image dimensions</li>
  1234. </ol>
  1235. <h3>Debug Mode</h3>
  1236. <p>Enable debug logging by setting:</p>
  1237. <ul>
  1238. <li><code>verbose=true</code> in server configuration</li>
  1239. <li><code>RUST_LOG=debug</code> environment variable</li>
  1240. </ul>
  1241. <h3>Health Checks</h3>
  1242. <p>Monitor server health:</p>
  1243. <div class="code-block">
  1244. curl -X GET http://localhost:8080/api/health
  1245. curl -X GET http://localhost:8080/api/status
  1246. </div>
  1247. </div>
  1248. </section>
  1249. </div>
  1250. <a href="#top" class="back-to-top">↑ Back to Top</a>
  1251. <script>
  1252. // Smooth scrolling for anchor links
  1253. document.querySelectorAll('a[href^="#"]').forEach(anchor => {
  1254. anchor.addEventListener('click', function (e) {
  1255. e.preventDefault();
  1256. const target = document.querySelector(this.getAttribute('href'));
  1257. if (target) {
  1258. target.scrollIntoView({
  1259. behavior: 'smooth',
  1260. block: 'start'
  1261. });
  1262. }
  1263. });
  1264. });
  1265. // Show/hide back to top button based on scroll position
  1266. const backToTop = document.querySelector('.back-to-top');
  1267. window.addEventListener('scroll', () => {
  1268. if (window.pageYOffset > 300) {
  1269. backToTop.style.display = 'block';
  1270. } else {
  1271. backToTop.style.display = 'none';
  1272. }
  1273. });
  1274. // Hide back to top button initially
  1275. backToTop.style.display = 'none';
  1276. </script>
  1277. </body>
  1278. </html>