{"id":22677801,"url":"https://github.com/jaschahuisman/sd-api","last_synced_at":"2025-08-20T06:32:29.803Z","repository":{"id":149897319,"uuid":"622299210","full_name":"jaschahuisman/sd-api","owner":"jaschahuisman","description":"A Typescript API client for AUTOMATIC111/stable-diffusion-webui","archived":false,"fork":false,"pushed_at":"2023-11-17T08:31:53.000Z","size":1488,"stargazers_count":97,"open_issues_count":4,"forks_count":18,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-12-11T07:38:41.441Z","etag":null,"topics":["api","automatic1111","client","javascript","stable-diffusion","stable-diffusion-webui","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/stable-diffusion-api","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jaschahuisman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-01T17:43:03.000Z","updated_at":"2024-06-04T13:03:26.000Z","dependencies_parsed_at":"2024-10-06T15:42:22.082Z","dependency_job_id":"4a818729-64f3-4dc5-86c4-e9531baa3a67","html_url":"https://github.com/jaschahuisman/sd-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaschahuisman%2Fsd-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaschahuisman%2Fsd-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaschahuisman%2Fsd-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaschahuisman%2Fsd-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaschahuisman","download_url":"https://codeload.github.com/jaschahuisman/sd-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230400615,"owners_count":18219831,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","automatic1111","client","javascript","stable-diffusion","stable-diffusion-webui","typescript"],"created_at":"2024-12-09T18:01:55.802Z","updated_at":"2024-12-19T08:08:04.519Z","avatar_url":"https://github.com/jaschahuisman.png","language":"TypeScript","readme":"# Stable Diffusion Api\n\n![npm](https://img.shields.io/npm/v/stable-diffusion-api)\n![npm](https://img.shields.io/npm/dw/stable-diffusion-api)\n![GitHub](https://img.shields.io/github/license/jaschahuisman/sd-api)\n\n[![npm](https://img.shields.io/badge/npm-CB3837?logo=npm\u0026logoColor=white)](https://www.npmjs.com/package/stable-diffusion-api)\n[![GitHub](https://img.shields.io/badge/GitHub-181717?logo=github\u0026logoColor=white)](https://www.github.com/jaschahuisman/sd-api)\n\nA Typescript API client for [AUTOMATIC111/stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui) API that is unremarkably inspired by the Python library [webuiapi](https://github.com/mix1009/sdwebuiapi).\n\n- [Stable Diffusion Api](#stable-diffusion-api)\n  - [Requisites](#requisites)\n  - [Installation](#installation)\n  - [Usage](#usage)\n    - [Instantiation](#instantiation)\n    - [Authentication](#authentication)\n    - [txt2img](#txt2img)\n    - [img2img](#img2img)\n  - [ControlNet Extension API usage](#controlnet-extension-api-usage)\n    - [Get models and modules](#get-models-and-modules)\n    - [ControlNetUnit](#controlnetunit)\n    - [detect](#detect)\n\n## Requisites\n\n- To use this API client, you have to run `stable-diffusion-webui` with the `--api` command line argument.\n- Optionally you can add `--nowebui` to disable the web interface.\n\n## Installation\n\n```bash\nnpm install stable-diffusion-api\n```\n\n```bash\nyarn add stable-diffusion-api\n```\n\n## Usage\n\n### Instantiation\n\n```typescript\nimport StableDiffusionApi from \"stable-diffusion-api\";\n\nconst api = new StableDiffusionApi();\n\nconst api = new StableDiffusionApi({\n  host: \"localhost\",\n  port: 7860,\n  protocol: \"http\",\n  defaultSampler: \"Euler a\",\n  defaultStepCount: 20,\n});\n\nconst api = new StableDiffusionApi({\n  baseUrl: \"http://localhost:7860\",\n});\n```\n\n### Authentication\n\nUse the `--api-auth` command line argument with \"username:password\" on the server to enable API authentication.\n\n```typescript\napi.setAuth(\"username\", \"password\");\n```\n\n### txt2img\n\n```typescript\nconst result = await api.txt2img({\n    prompt: \"An AI-powered robot that accidentally starts doing everyone's job, causing chaos in the workplace.\"\n    ...\n})\n\nresult.image.toFile('result.png')\n```\n\n| Result\n|:-------------------------:\n| ![](assets/img/robot_workplace.png)\n\n### img2img\n\n```typescript\nconst image = sharp('image.png')\n\nconst result = await api.img2img({\n    init_images: [image],\n    prompt: \"Man, scared of AGI, running away on a burning lava floor.\"\n    ...\n})\n\nresult.image.toFile('result.png')\n```\n\n|               Input               |             Result             |\n| :-------------------------------: | :----------------------------: |\n| ![](assets/img/running_track.png) | ![](assets/img/lava_floor.png) |\n\n---\n\n## ControlNet Extension API usage\n\n- To use the ControlNet API, you must have installed the [ControlNet extension](https://github.com/Mikubill/sd-webui-controlnet) into your `stable-diffusion-webui` instance.\n- It's also necessary to have the desired ControlNet models installed into the extension's models directory.\n\n### Get models and modules\n\nTo get a list of all installed ControlNet models and modules, you can use the `api.ControlNet.getModels()` and `api.ControlNet.getModules()` methods.\n\n```typescript\nconst models = await api.ControlNet.getModels();\nconst modules = await api.ControlNet.getModules();\n```\n\n### ControlNetUnit\n\nTo make use of the ControlNet API, you must first instantiate a `ControlNetUnit` object in wich you can specify the ControlNet model and preprocessor to use. Next, to use the unit, you must pass it as an array in the `controlnet_units` argument in the `txt2img` or `img2img` methods.\n\nIt's also possible to use multiple ControlNet units in the same request. To get some good results, it's recommended to use lower weights for each unit by setting the `weight` argument to a lower value.\n\nTo get a list of all installed ControlNet models, you can use the `api.ControlNet.getModels()` method.\n\n```typescript\nconst image = sharp(\"image.png\");\n\nconst controlNetUnit = new ControlNetUnit({\n  model: \"control_sd15_depth [fef5e48e]\",\n  module: \"depth\",\n  input_images: [image],\n  processor_res: 512,\n  threshold_a: 64,\n  threshold_b: 64,\n});\n\nconst result = await api.txt2img({\n  prompt:\n    \"Young lad laughing at all artists putting hard work and effort into their work.\",\n  controlnet_units: [controlNetUnit],\n});\n\nresult.image.toFile(\"result.png\");\n\n// To access the preprocessing result, you can use the following:\n\nconst depth = result.images[1];\ndepth.toFile(\"depth.png\");\n```\n\n|                Input                 |                 Result                 |                   Depth                   |\n| :----------------------------------: | :------------------------------------: | :---------------------------------------: |\n| ![](assets/img/grandpa_laughing.png) | ![](assets/img/young_lad_laughing.png) | ![](assets/img/grandpa_lauging_depth.png) |\n\n### detect\n\nUses the selected ControlNet proprocessor module to predict a detection on the input image. To make use of the detection result, you must use the model of choise in the `txt2img` or `img2img` without a preprocessor enabled (use `\"none\"` as the preprocessor module).\n\nThis comes in handy when you just want a detection result without generating a whole new image.\n\n```typescript\nconst image = sharp(\"image.png\");\n\nconst result = await api.ControlNet.detect({\n  controlnet_module: \"depth\",\n  controlnet_input_images: [image],\n  controlnet_processor_res: 512,\n  controlnet_threshold_a: 64,\n  controlnet_threshold_b: 64,\n});\n\nresult.image.toFile(\"result.png\");\n```\n\n|            Input             |               Result               |\n| :--------------------------: | :--------------------------------: |\n| ![](assets/img/food_man.png) | ![](assets/img/food_man_depth.png) |\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaschahuisman%2Fsd-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaschahuisman%2Fsd-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaschahuisman%2Fsd-api/lists"}