github.com/instill-ai/component@v0.16.0-beta/pkg/connector/stabilityai/v0/config/stabilityai.json (about) 1 { 2 "components": { 3 "headers": { 4 "Content-Length": { 5 "required": true, 6 "schema": { 7 "type": "integer" 8 } 9 }, 10 "Content-Type": { 11 "required": true, 12 "schema": { 13 "enum": [ 14 "application/json", 15 "image/png" 16 ], 17 "type": "string" 18 } 19 }, 20 "Finish-Reason": { 21 "schema": { 22 "$ref": "#/components/schemas/FinishReason" 23 } 24 }, 25 "Seed": { 26 "description": "The seed used to generate the image. This header is only present when the `Accept` is set to `image/png`. Otherwise it is returned in the response body.", 27 "example": 3817857576, 28 "schema": { 29 "example": 787078103, 30 "type": "integer" 31 } 32 } 33 }, 34 "parameters": { 35 "accept": { 36 "allowEmptyValue": false, 37 "description": "The format of the response. Leave blank for JSON, or set to 'image/png' for a PNG image.", 38 "in": "header", 39 "name": "Accept", 40 "schema": { 41 "default": "application/json", 42 "enum": [ 43 "application/json", 44 "image/png" 45 ], 46 "type": "string" 47 } 48 }, 49 "engineID": { 50 "example": "stable-diffusion-v1-6", 51 "in": "path", 52 "name": "engine_id", 53 "required": true, 54 "schema": { 55 "example": "stable-diffusion-v1-6", 56 "type": "string" 57 } 58 }, 59 "organization": { 60 "allowEmptyValue": false, 61 "description": "Allows for requests to be scoped to an organization other than the user's default. If not provided, the user's default organization will be used.", 62 "example": "org-123456", 63 "in": "header", 64 "name": "Organization", 65 "schema": { 66 "type": "string" 67 }, 68 "x-go-name": "OrganizationID" 69 }, 70 "stabilityClientID": { 71 "allowEmptyValue": false, 72 "description": "Used to identify the source of requests, such as the client application or sub-organization. Optional, but recommended for organizational clarity.", 73 "example": "my-great-plugin", 74 "in": "header", 75 "name": "Stability-Client-ID", 76 "schema": { 77 "type": "string" 78 } 79 }, 80 "stabilityClientVersion": { 81 "allowEmptyValue": false, 82 "description": "Used to identify the version of the application or service making the requests. Optional, but recommended for organizational clarity.", 83 "example": "1.2.1", 84 "in": "header", 85 "name": "Stability-Client-Version", 86 "schema": { 87 "type": "string" 88 } 89 }, 90 "upscaleEngineID": { 91 "examples": { 92 "ESRGAN_X2_PLUS": { 93 "description": "ESRGAN x2 Upscaler", 94 "value": "esrgan-v1-x2plus" 95 }, 96 "LATENT_UPSCALER_X4": { 97 "description": "Stable Diffusion x4 Latent Upscaler", 98 "value": "stable-diffusion-x4-latent-upscaler" 99 } 100 }, 101 "in": "path", 102 "name": "engine_id", 103 "required": true, 104 "schema": { 105 "type": "string" 106 } 107 } 108 }, 109 "responses": { 110 "400FromGeneration": { 111 "content": { 112 "application/json": { 113 "example": { 114 "id": "296a972f-666a-44a1-a3df-c9c28a1f56c0", 115 "message": "init_image: is required", 116 "name": "bad_request" 117 }, 118 "schema": { 119 "$ref": "#/components/schemas/Error" 120 } 121 } 122 }, 123 "description": "General error for invalid parameters, see below for specific errors.\n - bad_request: one or more provided parameters are invalid (see error description for details)\n - invalid_samples: Sample count may only be greater than 1 when the accept header is set to `application/json`\n - invalid_height_or_width: Height and width must be specified in increments of 64\n - invalid_file_size: The file size of one or more of the provided files is invalid\n - invalid_mime_type: The mime type of one or more of the provided files is invalid\n - invalid_image_dimensions: The dimensions of the provided `init_image` and `mask_image` do not match\n - invalid_mask_image: The parameter `mask_source` was set to `MASK_IMAGE_WHITE` or `MASK_IMAGE_BLACK` but no `mask_image` was provided\n - invalid_prompts: One or more of the prompts contains filtered words\n - invalid_pixel_count: Incorrect number of pixels specified.\n - invalid_sdxl_v222_dimensions: Incorrect dimensions specified for SDXL v2-2-2 engine. Requirements:\n - Neither `height` nor `width` may be below 128\n - Only one of `height` or `width` may be above 512 (e.g. 512x768 is valid but 578x768 is not)\n - Maximum dimensions supported are 512x896 or 896x512 \n - invalid_sdxl_v1_dimensions: Incorrect dimensions specified for SDXL v0.9 or v1.0 engine. Valid dimensions:\n - 1024x1024, 1152x896, 1216x832, 1344x768, 1536x640, 640x1536, 768x1344, 832x1216, or 896x1152" 124 }, 125 "400FromUpscale": { 126 "content": { 127 "application/json": { 128 "example": { 129 "id": "296a972f-666a-44a1-a3df-c9c28a1f56c0", 130 "message": "image: is required", 131 "name": "bad_request" 132 }, 133 "schema": { 134 "$ref": "#/components/schemas/Error" 135 } 136 } 137 }, 138 "description": "General error for invalid parameters, see below for specific errors.\n\n - bad_request: one or more provided parameters are invalid (see error description for details)\n - invalid_file_size: The file size of one or more of the provided files is invalid\n - invalid_mime_type: The mime type of one or more of the provided files is invalid\n - invalid_pixel_count: The requested image would exceed the maximum pixel count of 4,194,304" 139 }, 140 "401": { 141 "content": { 142 "application/json": { 143 "example": { 144 "id": "9160aa70-222f-4a36-9eb7-475e2668362a", 145 "message": "missing authorization header", 146 "name": "unauthorized" 147 }, 148 "schema": { 149 "$ref": "#/components/schemas/Error" 150 } 151 } 152 }, 153 "description": "unauthorized: API key missing or invalid" 154 }, 155 "403": { 156 "content": { 157 "application/json": { 158 "example": { 159 "id": "5cf19777-d17f-49fe-9bd9-39ff0ec6bb50", 160 "message": "You do not have permission to access this resource", 161 "name": "permission_denied" 162 }, 163 "schema": { 164 "$ref": "#/components/schemas/Error" 165 } 166 } 167 }, 168 "description": "permission_denied: You lack the necessary permissions to perform this action" 169 }, 170 "404": { 171 "content": { 172 "application/json": { 173 "example": { 174 "id": "92b19e7f-22a2-4e71-a821-90edda229293", 175 "message": "The specified engine (ID some-fake-engine) was not found.", 176 "name": "not_found" 177 }, 178 "schema": { 179 "$ref": "#/components/schemas/Error" 180 } 181 } 182 }, 183 "description": "not_found: The requested resource was not found (e.g. specifing a model that does not exist)" 184 }, 185 "500": { 186 "content": { 187 "application/json": { 188 "example": { 189 "id": "f81964d6-619b-453e-97bc-9fd7ac3f04e7", 190 "message": "An unexpected server error occurred, please try again.", 191 "name": "server_error" 192 }, 193 "schema": { 194 "$ref": "#/components/schemas/Error" 195 } 196 } 197 }, 198 "description": "server_error: Some unexpected server error occurred" 199 }, 200 "GenerationResponse": { 201 "content": { 202 "application/json": { 203 "schema": { 204 "description": "An array of results from the generation request, where each image is a base64 encoded PNG.", 205 "properties": { 206 "artifacts": { 207 "items": { 208 "$ref": "#/components/schemas/Image" 209 }, 210 "type": "array", 211 "x-go-type-skip-optional-pointer": true 212 } 213 }, 214 "type": "object" 215 } 216 }, 217 "image/png": { 218 "example": "The bytes of the generated image, what did you expect?", 219 "schema": { 220 "description": "The bytes of the generated PNG image", 221 "format": "binary", 222 "type": "string" 223 } 224 } 225 }, 226 "description": "One or more images were successfully generated.", 227 "headers": { 228 "Content-Length": { 229 "$ref": "#/components/headers/Content-Length" 230 }, 231 "Content-Type": { 232 "$ref": "#/components/headers/Content-Type" 233 }, 234 "Finish-Reason": { 235 "$ref": "#/components/headers/Finish-Reason" 236 }, 237 "Seed": { 238 "$ref": "#/components/headers/Seed" 239 } 240 } 241 } 242 }, 243 "schemas": { 244 "AccountResponseBody": { 245 "properties": { 246 "email": { 247 "description": "The user's email", 248 "example": "example@stability.ai", 249 "format": "email", 250 "type": "string" 251 }, 252 "id": { 253 "description": "The user's ID", 254 "example": "user-1234", 255 "type": "string", 256 "x-go-name": "ID" 257 }, 258 "organizations": { 259 "description": "The user's organizations", 260 "example": [ 261 { 262 "id": "org-5678", 263 "is_default": true, 264 "name": "Another Organization", 265 "role": "MEMBER" 266 }, 267 { 268 "id": "org-1234", 269 "is_default": false, 270 "name": "My Organization", 271 "role": "MEMBER" 272 } 273 ], 274 "items": { 275 "$ref": "#/components/schemas/OrganizationMembership" 276 }, 277 "type": "array" 278 }, 279 "profile_picture": { 280 "description": "The user's profile picture", 281 "example": "https://api.stability.ai/example.png", 282 "format": "uri", 283 "type": "string" 284 } 285 }, 286 "required": [ 287 "id", 288 "email", 289 "organizations" 290 ], 291 "type": "object" 292 }, 293 "BalanceResponseBody": { 294 "example": { 295 "credits": 0.07903292496944721 296 }, 297 "properties": { 298 "credits": { 299 "description": "The balance of the account/organization associated with the API key", 300 "example": 0.41122252265928866, 301 "format": "double", 302 "type": "number" 303 } 304 }, 305 "required": [ 306 "credits" 307 ], 308 "type": "object" 309 }, 310 "CfgScale": { 311 "default": 7, 312 "description": "How strictly the diffusion process adheres to the prompt text (higher values keep your image closer to your prompt)", 313 "example": 7, 314 "maximum": 35, 315 "minimum": 0, 316 "type": "number" 317 }, 318 "ClipGuidancePreset": { 319 "default": "NONE", 320 "enum": [ 321 "FAST_BLUE", 322 "FAST_GREEN", 323 "NONE", 324 "SIMPLE", 325 "SLOW", 326 "SLOWER", 327 "SLOWEST" 328 ], 329 "example": "FAST_BLUE", 330 "type": "string" 331 }, 332 "DiffuseImageHeight": { 333 "default": 512, 334 "description": "Height of the image to generate, in pixels, in an increment divible by 64.\n\nEngine-specific dimension validation:\n- SDXL Beta: must be between 128x128 and 512x896 (or 896x512); only one dimension can be greater than 512. \n- SDXL v0.9: must be one of 1024x1024, 1152x896, 1216x832, 1344x768, 1536x640, 640x1536, 768x1344, 832x1216, or 896x1152\n- SDXL v1.0: same as SDXL v0.9\n- SD v1.6: must be between 320x320 and 1536x1536", 335 "example": 512, 336 "minimum": 128, 337 "multipleOf": 64, 338 "type": "integer", 339 "x-go-type": "uint64" 340 }, 341 "DiffuseImageWidth": { 342 "default": 512, 343 "description": "Width of the image to generate, in pixels, in an increment divible by 64.\n\nEngine-specific dimension validation:\n- SDXL Beta: must be between 128x128 and 512x896 (or 896x512); only one dimension can be greater than 512. \n- SDXL v0.9: must be one of 1024x1024, 1152x896, 1216x832, 1344x768, 1536x640, 640x1536, 768x1344, 832x1216, or 896x1152\n- SDXL v1.0: same as SDXL v0.9\n- SD v1.6: must be between 320x320 and 1536x1536", 344 "example": 512, 345 "minimum": 128, 346 "multipleOf": 64, 347 "type": "integer", 348 "x-go-type": "uint64" 349 }, 350 "Engine": { 351 "properties": { 352 "description": { 353 "type": "string" 354 }, 355 "id": { 356 "description": "Unique identifier for the engine", 357 "example": "stable-diffusion-v1-6", 358 "type": "string", 359 "x-go-name": "ID" 360 }, 361 "name": { 362 "description": "Name of the engine", 363 "example": "Stable Diffusion XL v1.0", 364 "type": "string" 365 }, 366 "type": { 367 "description": "The type of content this engine produces", 368 "enum": [ 369 "AUDIO", 370 "CLASSIFICATION", 371 "PICTURE", 372 "STORAGE", 373 "TEXT", 374 "VIDEO" 375 ], 376 "example": "PICTURE", 377 "type": "string" 378 } 379 }, 380 "required": [ 381 "id", 382 "name", 383 "description", 384 "type" 385 ], 386 "type": "object" 387 }, 388 "Error": { 389 "properties": { 390 "id": { 391 "description": "A unique identifier for this particular occurrence of the problem.", 392 "example": "296a972f-666a-44a1-a3df-c9c28a1f56c0", 393 "type": "string", 394 "x-go-name": "ID" 395 }, 396 "message": { 397 "description": "A human-readable explanation specific to this occurrence of the problem.", 398 "example": "Header parameter Authorization is required, but not found", 399 "type": "string" 400 }, 401 "name": { 402 "description": "The short-name of this class of errors e.g. `bad_request`.", 403 "example": "bad_request", 404 "type": "string" 405 } 406 }, 407 "required": [ 408 "name", 409 "id", 410 "message", 411 "status" 412 ], 413 "type": "object", 414 "x-go-name": "RESTError" 415 }, 416 "Extras": { 417 "description": "Extra parameters passed to the engine.\nThese parameters are used for in-development or experimental features and may change\nwithout warning, so please use with caution.", 418 "type": "object" 419 }, 420 "FinishReason": { 421 "description": "The result of the generation process.\n- `SUCCESS` indicates success\n- `ERROR` indicates an error\n- `CONTENT_FILTERED` indicates the result affected by the content filter and may be blurred.\n\nThis header is only present when the `Accept` is set to `image/png`. Otherwise it is returned in the response body.", 422 "enum": [ 423 "SUCCESS", 424 "ERROR", 425 "CONTENT_FILTERED" 426 ], 427 "type": "string" 428 }, 429 "GenerationRequestOptionalParams": { 430 "description": "Represents the optional parameters that can be passed to any generation request.", 431 "properties": { 432 "cfg_scale": { 433 "$ref": "#/components/schemas/CfgScale" 434 }, 435 "clip_guidance_preset": { 436 "$ref": "#/components/schemas/ClipGuidancePreset" 437 }, 438 "extras": { 439 "$ref": "#/components/schemas/Extras" 440 }, 441 "sampler": { 442 "$ref": "#/components/schemas/Sampler" 443 }, 444 "samples": { 445 "$ref": "#/components/schemas/Samples" 446 }, 447 "seed": { 448 "$ref": "#/components/schemas/Seed" 449 }, 450 "steps": { 451 "$ref": "#/components/schemas/Steps" 452 }, 453 "style_preset": { 454 "$ref": "#/components/schemas/StylePreset" 455 } 456 }, 457 "type": "object" 458 }, 459 "Image": { 460 "example": [ 461 { 462 "base64": "...very long string...", 463 "finishReason": "SUCCESS", 464 "seed": 1050625087 465 }, 466 { 467 "base64": "...very long string...", 468 "finishReason": "CONTENT_FILTERED", 469 "seed": 1229191277 470 } 471 ], 472 "properties": { 473 "base64": { 474 "description": "Image encoded in base64", 475 "type": "string", 476 "x-go-type-skip-optional-pointer": true 477 }, 478 "finishReason": { 479 "enum": [ 480 "SUCCESS", 481 "ERROR", 482 "CONTENT_FILTERED" 483 ], 484 "example": "CONTENT_FILTERED", 485 "type": "string", 486 "x-go-type-skip-optional-pointer": true 487 }, 488 "seed": { 489 "description": "The seed associated with this image", 490 "example": 1229191277, 491 "type": "number", 492 "x-go-type-skip-optional-pointer": true 493 } 494 }, 495 "type": "object" 496 }, 497 "ImageToImageRequestBody": { 498 "discriminator": { 499 "mapping": { 500 "IMAGE_STRENGTH": "#/components/schemas/ImageToImageUsingImageStrengthRequestBody", 501 "STEP_SCHEDULE": "#/components/schemas/ImageToImageUsingStepScheduleRequestBody" 502 }, 503 "propertyName": "init_image_mode" 504 }, 505 "properties": { 506 "cfg_scale": { 507 "$ref": "#/components/schemas/CfgScale" 508 }, 509 "clip_guidance_preset": { 510 "$ref": "#/components/schemas/ClipGuidancePreset" 511 }, 512 "extras": { 513 "$ref": "#/components/schemas/Extras" 514 }, 515 "image_strength": { 516 "$ref": "#/components/schemas/InitImageStrength" 517 }, 518 "init_image": { 519 "$ref": "#/components/schemas/InitImage" 520 }, 521 "init_image_mode": { 522 "$ref": "#/components/schemas/InitImageMode" 523 }, 524 "sampler": { 525 "$ref": "#/components/schemas/Sampler" 526 }, 527 "samples": { 528 "$ref": "#/components/schemas/Samples" 529 }, 530 "seed": { 531 "$ref": "#/components/schemas/Seed" 532 }, 533 "step_schedule_end": { 534 "$ref": "#/components/schemas/StepScheduleEnd" 535 }, 536 "step_schedule_start": { 537 "$ref": "#/components/schemas/StepScheduleStart" 538 }, 539 "steps": { 540 "$ref": "#/components/schemas/Steps" 541 }, 542 "style_preset": { 543 "$ref": "#/components/schemas/StylePreset" 544 }, 545 "text_prompts": { 546 "$ref": "#/components/schemas/TextPrompts" 547 } 548 }, 549 "required": [ 550 "text_prompts", 551 "init_image" 552 ], 553 "type": "object" 554 }, 555 "ImageToImageUsingImageStrengthRequestBody": { 556 "allOf": [ 557 { 558 "properties": { 559 "image_strength": { 560 "$ref": "#/components/schemas/InitImageStrength" 561 }, 562 "init_image": { 563 "$ref": "#/components/schemas/InitImage" 564 }, 565 "init_image_mode": { 566 "$ref": "#/components/schemas/InitImageMode" 567 }, 568 "text_prompts": { 569 "$ref": "#/components/schemas/TextPrompts" 570 } 571 }, 572 "required": [ 573 "text_prompts", 574 "init_image" 575 ], 576 "type": "object" 577 }, 578 { 579 "$ref": "#/components/schemas/GenerationRequestOptionalParams" 580 } 581 ] 582 }, 583 "ImageToImageUsingStepScheduleRequestBody": { 584 "allOf": [ 585 { 586 "properties": { 587 "init_image": { 588 "$ref": "#/components/schemas/InitImage" 589 }, 590 "init_image_mode": { 591 "$ref": "#/components/schemas/InitImageMode" 592 }, 593 "step_schedule_end": { 594 "$ref": "#/components/schemas/StepScheduleEnd" 595 }, 596 "step_schedule_start": { 597 "$ref": "#/components/schemas/StepScheduleStart" 598 }, 599 "text_prompts": { 600 "$ref": "#/components/schemas/TextPrompts" 601 } 602 }, 603 "required": [ 604 "text_prompts", 605 "init_image" 606 ], 607 "type": "object" 608 }, 609 { 610 "$ref": "#/components/schemas/GenerationRequestOptionalParams" 611 } 612 ] 613 }, 614 "InitImage": { 615 "description": "Image used to initialize the diffusion process, in lieu of random noise.", 616 "example": "<image binary>", 617 "format": "binary", 618 "type": "string", 619 "x-go-type": "[]byte" 620 }, 621 "InitImageMode": { 622 "default": "IMAGE_STRENGTH", 623 "description": "Whether to use `image_strength` or `step_schedule_*` to control how much influence the `init_image` has on the result.", 624 "enum": [ 625 "IMAGE_STRENGTH", 626 "STEP_SCHEDULE" 627 ], 628 "type": "string" 629 }, 630 "InitImageStrength": { 631 "default": 0.35, 632 "description": "How much influence the `init_image` has on the diffusion process. Values close to `1` will yield images very similar to the `init_image` while values close to `0` will yield images wildly different than the `init_image`. The behavior of this is meant to mirror DreamStudio's \"Image Strength\" slider. <br/> <br/> This parameter is just an alternate way to set `step_schedule_start`, which is done via the calculation `1 - image_strength`. For example, passing in an Image Strength of 35% (`0.35`) would result in a `step_schedule_start` of `0.65`.\n", 633 "example": 0.4, 634 "format": "float", 635 "maximum": 1, 636 "minimum": 0, 637 "type": "number" 638 }, 639 "InputImage": { 640 "example": "<image binary>", 641 "format": "binary", 642 "type": "string", 643 "x-go-type": "[]byte" 644 }, 645 "LatentUpscalerUpscaleRequestBody": { 646 "properties": { 647 "cfg_scale": { 648 "$ref": "#/components/schemas/CfgScale" 649 }, 650 "height": { 651 "$ref": "#/components/schemas/UpscaleImageHeight" 652 }, 653 "image": { 654 "$ref": "#/components/schemas/InputImage" 655 }, 656 "seed": { 657 "$ref": "#/components/schemas/Seed" 658 }, 659 "steps": { 660 "$ref": "#/components/schemas/Steps" 661 }, 662 "text_prompts": { 663 "$ref": "#/components/schemas/TextPrompts" 664 }, 665 "width": { 666 "$ref": "#/components/schemas/UpscaleImageWidth" 667 } 668 }, 669 "required": [ 670 "image" 671 ], 672 "type": "object" 673 }, 674 "ListEnginesResponseBody": { 675 "description": "The engines available to your user/organization", 676 "example": [ 677 { 678 "description": "Stability-AI Stable Diffusion v1.6", 679 "id": "stable-diffusion-v1-6", 680 "name": "Stable Diffusion v1.6", 681 "type": "PICTURE" 682 }, 683 { 684 "description": "Stability-AI Stable Diffusion XL v1.0", 685 "id": "stable-diffusion-xl-1024-v1-0", 686 "name": "Stable Diffusion XL v1.0", 687 "type": "PICTURE" 688 } 689 ], 690 "items": { 691 "$ref": "#/components/schemas/Engine" 692 }, 693 "type": "array" 694 }, 695 "MaskImage": { 696 "description": "Optional grayscale mask that allows for influence over which pixels are eligible for diffusion and at what strength. Must be the same dimensions as the `init_image`. Use the `mask_source` option to specify whether the white or black pixels should be inpainted.", 697 "example": "<image binary>", 698 "format": "binary", 699 "type": "string", 700 "x-go-type": "[]byte" 701 }, 702 "MaskSource": { 703 "description": "For any given pixel, the mask determines the strength of generation on a linear scale. This parameter determines where to source the mask from:\n- `MASK_IMAGE_WHITE` will use the white pixels of the mask_image as the mask, where white pixels are completely replaced and black pixels are unchanged\n- `MASK_IMAGE_BLACK` will use the black pixels of the mask_image as the mask, where black pixels are completely replaced and white pixels are unchanged\n- `INIT_IMAGE_ALPHA` will use the alpha channel of the init_image as the mask, where fully transparent pixels are completely replaced and fully opaque pixels are unchanged", 704 "type": "string" 705 }, 706 "MaskingRequestBody": { 707 "discriminator": { 708 "mapping": { 709 "INIT_IMAGE_ALPHA": "#/components/schemas/MaskingUsingInitImageAlphaRequestBody", 710 "MASK_IMAGE_BLACK": "#/components/schemas/MaskingUsingMaskImageRequestBody", 711 "MASK_IMAGE_WHITE": "#/components/schemas/MaskingUsingMaskImageRequestBody" 712 }, 713 "propertyName": "mask_source" 714 }, 715 "properties": { 716 "cfg_scale": { 717 "$ref": "#/components/schemas/CfgScale" 718 }, 719 "clip_guidance_preset": { 720 "$ref": "#/components/schemas/ClipGuidancePreset" 721 }, 722 "extras": { 723 "$ref": "#/components/schemas/Extras" 724 }, 725 "init_image": { 726 "$ref": "#/components/schemas/InitImage" 727 }, 728 "mask_image": { 729 "$ref": "#/components/schemas/MaskImage" 730 }, 731 "mask_source": { 732 "$ref": "#/components/schemas/MaskSource" 733 }, 734 "sampler": { 735 "$ref": "#/components/schemas/Sampler" 736 }, 737 "samples": { 738 "$ref": "#/components/schemas/Samples" 739 }, 740 "seed": { 741 "$ref": "#/components/schemas/Seed" 742 }, 743 "steps": { 744 "$ref": "#/components/schemas/Steps" 745 }, 746 "style_preset": { 747 "$ref": "#/components/schemas/StylePreset" 748 }, 749 "text_prompts": { 750 "$ref": "#/components/schemas/TextPrompts" 751 } 752 }, 753 "required": [ 754 "text_prompts", 755 "init_image", 756 "mask_source" 757 ], 758 "type": "object" 759 }, 760 "MaskingUsingInitImageAlphaRequestBody": { 761 "allOf": [ 762 { 763 "properties": { 764 "init_image": { 765 "$ref": "#/components/schemas/InitImage" 766 }, 767 "mask_source": { 768 "$ref": "#/components/schemas/MaskSource" 769 }, 770 "text_prompts": { 771 "$ref": "#/components/schemas/TextPrompts" 772 } 773 }, 774 "required": [ 775 "init_image", 776 "text_prompts", 777 "mask_source" 778 ], 779 "type": "object" 780 }, 781 { 782 "$ref": "#/components/schemas/GenerationRequestOptionalParams" 783 } 784 ] 785 }, 786 "MaskingUsingMaskImageRequestBody": { 787 "allOf": [ 788 { 789 "properties": { 790 "init_image": { 791 "$ref": "#/components/schemas/InitImage" 792 }, 793 "mask_image": { 794 "$ref": "#/components/schemas/MaskImage" 795 }, 796 "mask_source": { 797 "$ref": "#/components/schemas/MaskSource" 798 }, 799 "text_prompts": { 800 "$ref": "#/components/schemas/TextPrompts" 801 } 802 }, 803 "required": [ 804 "init_image", 805 "mask_image", 806 "text_prompts", 807 "mask_source" 808 ], 809 "type": "object" 810 }, 811 { 812 "$ref": "#/components/schemas/GenerationRequestOptionalParams" 813 } 814 ] 815 }, 816 "OrganizationMembership": { 817 "properties": { 818 "id": { 819 "example": "org-123456", 820 "type": "string", 821 "x-go-name": "ID" 822 }, 823 "is_default": { 824 "example": false, 825 "type": "boolean" 826 }, 827 "name": { 828 "example": "My Organization", 829 "type": "string" 830 }, 831 "role": { 832 "example": "MEMBER", 833 "type": "string" 834 } 835 }, 836 "required": [ 837 "id", 838 "name", 839 "role", 840 "is_default" 841 ], 842 "type": "object" 843 }, 844 "RealESRGANUpscaleRequestBody": { 845 "properties": { 846 "height": { 847 "$ref": "#/components/schemas/UpscaleImageHeight" 848 }, 849 "image": { 850 "$ref": "#/components/schemas/InputImage" 851 }, 852 "width": { 853 "$ref": "#/components/schemas/UpscaleImageWidth" 854 } 855 }, 856 "required": [ 857 "image" 858 ], 859 "type": "object" 860 }, 861 "Sampler": { 862 "description": "Which sampler to use for the diffusion process. If this value is omitted we'll automatically select an appropriate sampler for you.", 863 "enum": [ 864 "DDIM", 865 "DDPM", 866 "K_DPMPP_2M", 867 "K_DPMPP_2S_ANCESTRAL", 868 "K_DPM_2", 869 "K_DPM_2_ANCESTRAL", 870 "K_EULER", 871 "K_EULER_ANCESTRAL", 872 "K_HEUN", 873 "K_LMS" 874 ], 875 "example": "K_DPM_2_ANCESTRAL", 876 "type": "string" 877 }, 878 "Samples": { 879 "default": 1, 880 "description": "Number of images to generate", 881 "example": 1, 882 "maximum": 10, 883 "minimum": 1, 884 "type": "integer", 885 "x-go-type": "uint64" 886 }, 887 "Seed": { 888 "default": 0, 889 "description": "Random noise seed (omit this option or use `0` for a random seed)", 890 "example": 0, 891 "maximum": 4294967295, 892 "minimum": 0, 893 "type": "integer", 894 "x-go-type": "uint32" 895 }, 896 "StepScheduleEnd": { 897 "description": "Skips a proportion of the end of the diffusion steps, allowing the init_image to influence the final generated image. Lower values will result in more influence from the init_image, while higher values will result in more influence from the diffusion steps.", 898 "example": 0.01, 899 "maximum": 1, 900 "minimum": 0, 901 "type": "number" 902 }, 903 "StepScheduleStart": { 904 "default": 0.65, 905 "description": "Skips a proportion of the start of the diffusion steps, allowing the init_image to influence the final generated image. Lower values will result in more influence from the init_image, while higher values will result in more influence from the diffusion steps. (e.g. a value of `0` would simply return you the init_image, where a value of `1` would return you a completely different image.)", 906 "example": 0.4, 907 "maximum": 1, 908 "minimum": 0, 909 "type": "number" 910 }, 911 "Steps": { 912 "default": 30, 913 "description": "Number of diffusion steps to run.", 914 "example": 50, 915 "maximum": 50, 916 "minimum": 10, 917 "type": "integer", 918 "x-go-type": "uint64" 919 }, 920 "StylePreset": { 921 "description": "Pass in a style preset to guide the image model towards a particular style.\nThis list of style presets is subject to change.", 922 "enum": [ 923 "enhance", 924 "anime", 925 "photographic", 926 "digital-art", 927 "comic-book", 928 "fantasy-art", 929 "line-art", 930 "analog-film", 931 "neon-punk", 932 "isometric", 933 "low-poly", 934 "origami", 935 "modeling-compound", 936 "cinematic", 937 "3d-model", 938 "pixel-art", 939 "tile-texture" 940 ], 941 "type": "string" 942 }, 943 "TextPrompt": { 944 "description": "Text prompt for image generation", 945 "properties": { 946 "text": { 947 "description": "The prompt itself", 948 "example": "A lighthouse on a cliff", 949 "maxLength": 2000, 950 "type": "string" 951 }, 952 "weight": { 953 "description": "Weight of the prompt (use negative numbers for negative prompts)", 954 "example": 0.8167237, 955 "format": "float", 956 "type": "number" 957 } 958 }, 959 "required": [ 960 "text" 961 ], 962 "type": "object" 963 }, 964 "TextPrompts": { 965 "description": "An array of text prompts to use for generation.\n\nDue to how arrays are represented in `multipart/form-data` requests, prompts must adhere to the format `text_prompts[index][text|weight]`,\nwhere `index` is some integer used to tie the text and weight together. While `index` does not have to be sequential, duplicate entries \nwill override previous entries, so it is recommended to use sequential indices.\n\nGiven a text prompt with the text `A lighthouse on a cliff` and a weight of `0.5`, it would be represented as:\n```\ntext_prompts[0][text]: \"A lighthouse on a cliff\"\ntext_prompts[0][weight]: 0.5\n```\n\nTo add another prompt to that request simply provide the values under a new `index`:\n\n```\ntext_prompts[0][text]: \"A lighthouse on a cliff\"\ntext_prompts[0][weight]: 0.5\ntext_prompts[1][text]: \"land, ground, dirt, grass\"\ntext_prompts[1][weight]: -0.9\n```", 966 "items": { 967 "$ref": "#/components/schemas/TextPrompt" 968 }, 969 "minItems": 1, 970 "type": "array" 971 }, 972 "TextPromptsForTextToImage": { 973 "description": "An array of text prompts to use for generation.\n\nGiven a text prompt with the text `A lighthouse on a cliff` and a weight of `0.5`, it would be represented as:\n\n```\n\"text_prompts\": [\n {\n \"text\": \"A lighthouse on a cliff\",\n \"weight\": 0.5\n }\n]\n```", 974 "items": { 975 "$ref": "#/components/schemas/TextPrompt" 976 }, 977 "minItems": 1, 978 "title": "TextPrompts", 979 "type": "array" 980 }, 981 "TextToImageRequestBody": { 982 "allOf": [ 983 { 984 "properties": { 985 "height": { 986 "$ref": "#/components/schemas/DiffuseImageHeight" 987 }, 988 "text_prompts": { 989 "$ref": "#/components/schemas/TextPromptsForTextToImage" 990 }, 991 "width": { 992 "$ref": "#/components/schemas/DiffuseImageWidth" 993 } 994 }, 995 "required": [ 996 "text_prompts" 997 ], 998 "type": "object" 999 }, 1000 { 1001 "$ref": "#/components/schemas/GenerationRequestOptionalParams" 1002 } 1003 ], 1004 "example": { 1005 "cfg_scale": 7, 1006 "clip_guidance_preset": "FAST_BLUE", 1007 "height": 512, 1008 "sampler": "K_DPM_2_ANCESTRAL", 1009 "samples": 1, 1010 "seed": 0, 1011 "steps": 30, 1012 "text_prompts": [ 1013 { 1014 "text": "A lighthouse on a cliff", 1015 "weight": 1 1016 } 1017 ], 1018 "width": 512 1019 }, 1020 "required": [ 1021 "text_prompts" 1022 ], 1023 "type": "object" 1024 }, 1025 "UpscaleImageHeight": { 1026 "description": "Desired height of the output image. Only one of `width` or `height` may be specified.", 1027 "minimum": 512, 1028 "type": "integer", 1029 "x-go-type": "uint64" 1030 }, 1031 "UpscaleImageWidth": { 1032 "description": "Desired width of the output image. Only one of `width` or `height` may be specified.", 1033 "minimum": 512, 1034 "type": "integer", 1035 "x-go-type": "uint64" 1036 } 1037 }, 1038 "securitySchemes": { 1039 "STABILITY_API_KEY": { 1040 "in": "header", 1041 "name": "Authorization", 1042 "type": "apiKey" 1043 } 1044 } 1045 }, 1046 "info": { 1047 "description": "Welcome to the official Stability AI REST API!\n\n#### Authentication\n\nYou will need your [Stability API key](https://platform.stability.ai/account/keys) in order to make requests to this API.\nMake sure you never share your API key with anyone, and you never commit it to a public repository. Include this key in \nthe `Authorization` header of your requests.\n\n#### Rate limiting\n\nThis API is rate-limited to 150 requests every 10 seconds. If you exceed this limit, you will receive a `429` response.\nIf you find this limit too restrictive, please reach out to us via email at [platform@stability.ai](mailto:platform@stability.ai).\n\n#### Support\n\nCheck our [Status Page](https://stabilityai.instatus.com/) to view the current health of our REST/gRPC APIs.\n\nIf you run into issues, please reach out to us:\n - [Support Form](https://platform.stability.ai/support)\n - [platform@stability.ai](mailto:platform@stability.ai) \n - [Discord](https://discord.com/channels/1002292111942635562/1042896447311454361)\n", 1048 "termsOfService": "https://platform.stability.ai/docs/terms-of-service", 1049 "title": "Stability.ai REST API", 1050 "version": "v1", 1051 "x-logo": { 1052 "altText": "Stability.ai REST API", 1053 "url": "/docs/StabilityLogo.png" 1054 } 1055 }, 1056 "openapi": "3.0.3", 1057 "paths": { 1058 "/v1/engines/list": { 1059 "get": { 1060 "description": "List all engines available to your organization/user", 1061 "operationId": "listEngines", 1062 "parameters": [ 1063 { 1064 "$ref": "#/components/parameters/organization" 1065 }, 1066 { 1067 "$ref": "#/components/parameters/stabilityClientID" 1068 }, 1069 { 1070 "$ref": "#/components/parameters/stabilityClientVersion" 1071 } 1072 ], 1073 "responses": { 1074 "200": { 1075 "content": { 1076 "application/json": { 1077 "schema": { 1078 "$ref": "#/components/schemas/ListEnginesResponseBody" 1079 } 1080 } 1081 }, 1082 "description": "OK response." 1083 }, 1084 "401": { 1085 "$ref": "#/components/responses/401" 1086 }, 1087 "500": { 1088 "$ref": "#/components/responses/500" 1089 } 1090 }, 1091 "security": [ 1092 { 1093 "STABILITY_API_KEY": [] 1094 } 1095 ], 1096 "summary": "list", 1097 "tags": [ 1098 "v1/engines" 1099 ], 1100 "x-codeSamples": [ 1101 { 1102 "lang": "Python", 1103 "source": "import os\nimport requests\n\napi_host = os.getenv('API_HOST', 'https://api.stability.ai')\nurl = f\"{api_host}/v1/engines/list\"\n\napi_key = os.getenv(\"STABILITY_API_KEY\")\nif api_key is None:\n raise Exception(\"Missing Stability API key.\")\n\nresponse = requests.get(url, headers={\n \"Authorization\": f\"Bearer {api_key}\"\n})\n\nif response.status_code != 200:\n raise Exception(\"Non-200 response: \" + str(response.text))\n\n# Do something with the payload...\npayload = response.json()\n\n" 1104 }, 1105 { 1106 "label": "TypeScript", 1107 "lang": "Javascript", 1108 "source": "import fetch from 'node-fetch'\n\nconst apiHost = process.env.API_HOST ?? 'https://api.stability.ai'\nconst url = `${apiHost}/v1/engines/list`\n\nconst apiKey = process.env.STABILITY_API_KEY\nif (!apiKey) throw new Error('Missing Stability API key.')\n\nconst response = await fetch(url, {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${apiKey}`,\n },\n})\n\nif (!response.ok) {\n throw new Error(`Non-200 response: ${await response.text()}`)\n}\n\ninterface Payload {\n engines: Array<{\n id: string\n name: string\n description: string\n type: string\n }>\n}\n\n// Do something with the payload...\nconst payload = (await response.json()) as Payload\n" 1109 }, 1110 { 1111 "lang": "Go", 1112 "source": "package main\n\nimport (\n\t\"io\"\n\t\"net/http\"\n\t\"os\"\n)\n\nfunc main() {\n\t// Build REST endpoint URL\n\tapiHost, hasApiHost := os.LookupEnv(\"API_HOST\")\n\tif !hasApiHost {\n\t\tapiHost = \"https://api.stability.ai\"\n\t}\n\treqUrl := apiHost + \"/v1/engines/list\"\n\n\t// Acquire an API key from the environment\n\tapiKey, hasAPIKey := os.LookupEnv(\"STABILITY_API_KEY\")\n\tif !hasAPIKey {\n\t\tpanic(\"Missing STABILITY_API_KEY environment variable\")\n\t}\n\n\t// Execute the request & read all the bytes of the response\n\treq, _ := http.NewRequest(\"GET\", reqUrl, nil)\n\treq.Header.Add(\"Authorization\", \"Bearer \"+apiKey)\n\tres, _ := http.DefaultClient.Do(req)\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tif res.StatusCode != 200 {\n\t\tpanic(\"Non-200 response: \" + string(body))\n\t}\n\n\t// Do something with the payload...\n\t// payload := string(body)\n}\n" 1113 }, 1114 { 1115 "lang": "cURL", 1116 "source": "if [ -z \"$STABILITY_API_KEY\" ]; then\n echo \"STABILITY_API_KEY environment variable is not set\"\n exit 1\nfi\n\nBASE_URL=${API_HOST:-https://api.stability.ai}\nURL=\"$BASE_URL/v1/engines/list\"\n\ncurl -f -sS \"$URL\" \\\n -H 'Accept: application/json' \\\n -H \"Authorization: Bearer $STABILITY_API_KEY\"\n" 1117 } 1118 ] 1119 } 1120 }, 1121 "/v1/generation/{engine_id}/image-to-image": { 1122 "post": { 1123 "description": "Modify an image based on a text prompt", 1124 "operationId": "imageToImage", 1125 "parameters": [ 1126 { 1127 "$ref": "#/components/parameters/engineID" 1128 }, 1129 { 1130 "$ref": "#/components/parameters/accept" 1131 }, 1132 { 1133 "$ref": "#/components/parameters/organization" 1134 }, 1135 { 1136 "$ref": "#/components/parameters/stabilityClientID" 1137 }, 1138 { 1139 "$ref": "#/components/parameters/stabilityClientVersion" 1140 } 1141 ], 1142 "requestBody": { 1143 "content": { 1144 "multipart/form-data": { 1145 "examples": { 1146 "IMAGE_STRENGTH": { 1147 "description": "Request using 35% image_strength", 1148 "summary": "Using IMAGE_STRENGTH", 1149 "value": { 1150 "cfg_scale": 7, 1151 "clip_guidance_preset": "FAST_BLUE", 1152 "image_strength": 0.35, 1153 "init_image": "<image binary>", 1154 "init_image_mode": "IMAGE_STRENGTH", 1155 "sampler": "K_DPM_2_ANCESTRAL", 1156 "samples": 3, 1157 "steps": 30, 1158 "text_prompts[0][text]": "A dog space commander", 1159 "text_prompts[0][weight]": 1 1160 } 1161 }, 1162 "STEP_SCHEDULE": { 1163 "description": "Equivalent request using step_schedule_start", 1164 "summary": "Using STEP_SCHEDULE", 1165 "value": { 1166 "cfg_scale": 7, 1167 "clip_guidance_preset": "FAST_BLUE", 1168 "init_image": "<image binary>", 1169 "init_image_mode": "STEP_SCHEDULE", 1170 "sampler": "K_DPM_2_ANCESTRAL", 1171 "samples": 3, 1172 "step_schedule_start": 0.65, 1173 "steps": 30, 1174 "text_prompts[0][text]": "A dog space commander", 1175 "text_prompts[0][weight]": 1 1176 } 1177 } 1178 }, 1179 "schema": { 1180 "$ref": "#/components/schemas/ImageToImageRequestBody" 1181 } 1182 } 1183 }, 1184 "required": true 1185 }, 1186 "responses": { 1187 "200": { 1188 "$ref": "#/components/responses/GenerationResponse" 1189 }, 1190 "400": { 1191 "$ref": "#/components/responses/400FromGeneration" 1192 }, 1193 "401": { 1194 "$ref": "#/components/responses/401" 1195 }, 1196 "403": { 1197 "$ref": "#/components/responses/403" 1198 }, 1199 "404": { 1200 "$ref": "#/components/responses/404" 1201 }, 1202 "500": { 1203 "$ref": "#/components/responses/500" 1204 } 1205 }, 1206 "security": [ 1207 { 1208 "STABILITY_API_KEY": [] 1209 } 1210 ], 1211 "summary": "image-to-image", 1212 "tags": [ 1213 "v1/generation" 1214 ], 1215 "x-codeSamples": [ 1216 { 1217 "lang": "Python", 1218 "source": "import base64\nimport os\nimport requests\n\nengine_id = \"stable-diffusion-xl-1024-v1-0\"\napi_host = os.getenv(\"API_HOST\", \"https://api.stability.ai\")\napi_key = os.getenv(\"STABILITY_API_KEY\")\n\nif api_key is None:\n raise Exception(\"Missing Stability API key.\")\n\nresponse = requests.post(\n f\"{api_host}/v1/generation/{engine_id}/image-to-image\",\n headers={\n \"Accept\": \"application/json\",\n \"Authorization\": f\"Bearer {api_key}\"\n },\n files={\n \"init_image\": open(\"../init_image_1024.png\", \"rb\")\n },\n data={\n \"image_strength\": 0.35,\n \"init_image_mode\": \"IMAGE_STRENGTH\",\n \"text_prompts[0][text]\": \"Galactic dog with a cape\",\n \"cfg_scale\": 7,\n \"samples\": 1,\n \"steps\": 30,\n }\n)\n\nif response.status_code != 200:\n raise Exception(\"Non-200 response: \" + str(response.text))\n\ndata = response.json()\n\nfor i, image in enumerate(data[\"artifacts\"]):\n with open(f\"./out/v1_img2img_{i}.png\", \"wb\") as f:\n f.write(base64.b64decode(image[\"base64\"]))\n" 1219 }, 1220 { 1221 "label": "TypeScript", 1222 "lang": "Javascript", 1223 "source": "import fetch from 'node-fetch'\nimport FormData from 'form-data'\nimport fs from 'node:fs'\n\nconst engineId = 'stable-diffusion-xl-1024-v1-0'\nconst apiHost = process.env.API_HOST ?? 'https://api.stability.ai'\nconst apiKey = process.env.STABILITY_API_KEY\n\nif (!apiKey) throw new Error('Missing Stability API key.')\n\n// NOTE: This example is using a NodeJS FormData library.\n// Browsers should use their native FormData class.\n// React Native apps should also use their native FormData class.\nconst formData = new FormData()\nformData.append('init_image', fs.readFileSync('../init_image_1024.png'))\nformData.append('init_image_mode', 'IMAGE_STRENGTH')\nformData.append('image_strength', 0.35)\nformData.append('text_prompts[0][text]', 'Galactic dog wearing a cape')\nformData.append('cfg_scale', 7)\nformData.append('samples', 1)\nformData.append('steps', 30)\n\nconst response = await fetch(\n `${apiHost}/v1/generation/${engineId}/image-to-image`,\n {\n method: 'POST',\n headers: {\n ...formData.getHeaders(),\n Accept: 'application/json',\n Authorization: `Bearer ${apiKey}`,\n },\n body: formData,\n }\n)\n\nif (!response.ok) {\n throw new Error(`Non-200 response: ${await response.text()}`)\n}\n\ninterface GenerationResponse {\n artifacts: Array<{\n base64: string\n seed: number\n finishReason: string\n }>\n}\n\nconst responseJSON = (await response.json()) as GenerationResponse\n\nresponseJSON.artifacts.forEach((image, index) => {\n fs.writeFileSync(\n `out/v1_img2img_${index}.png`,\n Buffer.from(image.base64, 'base64')\n )\n})\n" 1224 }, 1225 { 1226 "lang": "Go", 1227 "source": "package main\n\nimport (\n\t\"bytes\"\n\t\"encoding/base64\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"io\"\n\t\"mime/multipart\"\n\t\"net/http\"\n\t\"os\"\n)\n\ntype ImageToImageImage struct {\n\tBase64 string `json:\"base64\"`\n\tSeed uint32 `json:\"seed\"`\n\tFinishReason string `json:\"finishReason\"`\n}\n\ntype ImageToImageResponse struct {\n\tImages []ImageToImageImage `json:\"artifacts\"`\n}\n\nfunc main() {\n\tengineId := \"stable-diffusion-xl-1024-v1-0\"\n\n\t// Build REST endpoint URL\n\tapiHost, hasApiHost := os.LookupEnv(\"API_HOST\")\n\tif !hasApiHost {\n\t\tapiHost = \"https://api.stability.ai\"\n\t}\n\treqUrl := apiHost + \"/v1/generation/\" + engineId + \"/image-to-image\"\n\n\t// Acquire an API key from the environment\n\tapiKey, hasAPIKey := os.LookupEnv(\"STABILITY_API_KEY\")\n\tif !hasAPIKey {\n\t\tpanic(\"Missing STABILITY_API_KEY environment variable\")\n\t}\n\n\tdata := &bytes.Buffer{}\n\twriter := multipart.NewWriter(data)\n\n\t// Write the init image to the request\n\tinitImageWriter, _ := writer.CreateFormField(\"init_image\")\n\tinitImageFile, initImageErr := os.Open(\"../init_image_1024.png\")\n\tif initImageErr != nil {\n\t\tpanic(\"Could not open init_image.png\")\n\t}\n\t_, _ = io.Copy(initImageWriter, initImageFile)\n\n\t// Write the options to the request\n\t_ = writer.WriteField(\"init_image_mode\", \"IMAGE_STRENGTH\")\n\t_ = writer.WriteField(\"image_strength\", \"0.35\")\n\t_ = writer.WriteField(\"text_prompts[0][text]\", \"Galactic dog with a cape\")\n\t_ = writer.WriteField(\"cfg_scale\", \"7\")\n\t_ = writer.WriteField(\"samples\", \"1\")\n\t_ = writer.WriteField(\"steps\", \"30\")\n\twriter.Close()\n\n\t// Execute the request\n\tpayload := bytes.NewReader(data.Bytes())\n\treq, _ := http.NewRequest(\"POST\", reqUrl, payload)\n\treq.Header.Add(\"Content-Type\", writer.FormDataContentType())\n\treq.Header.Add(\"Accept\", \"application/json\")\n\treq.Header.Add(\"Authorization\", \"Bearer \"+apiKey)\n\tres, _ := http.DefaultClient.Do(req)\n\tdefer res.Body.Close()\n\n\tif res.StatusCode != 200 {\n\t\tvar body map[string]interface{}\n\t\tif err := json.NewDecoder(res.Body).Decode(&body); err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\tpanic(fmt.Sprintf(\"Non-200 response: %s\", body))\n\t}\n\n\t// Decode the JSON body\n\tvar body ImageToImageResponse\n\tif err := json.NewDecoder(res.Body).Decode(&body); err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Write the images to disk\n\tfor i, image := range body.Images {\n\t\toutFile := fmt.Sprintf(\"./out/v1_img2img_%d.png\", i)\n\t\tfile, err := os.Create(outFile)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\n\t\timageBytes, err := base64.StdEncoding.DecodeString(image.Base64)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\n\t\tif _, err := file.Write(imageBytes); err != nil {\n\t\t\tpanic(err)\n\t\t}\n\n\t\tif err := file.Close(); err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t}\n}\n" 1228 }, 1229 { 1230 "lang": "cURL", 1231 "source": "if [ -z \"$STABILITY_API_KEY\" ]; then\n echo \"STABILITY_API_KEY environment variable is not set\"\n exit 1\nfi\n\nOUTPUT_FILE=./out/v1_img2img.png\nBASE_URL=${API_HOST:-https://api.stability.ai}\nURL=\"$BASE_URL/v1/generation/stable-diffusion-xl-1024-v1-0/image-to-image\"\n\ncurl -f -sS -X POST \"$URL\" \\\n -H 'Content-Type: multipart/form-data' \\\n -H 'Accept: image/png' \\\n -H \"Authorization: Bearer $STABILITY_API_KEY\" \\\n -F 'init_image=@\"../init_image_1024.png\"' \\\n -F 'init_image_mode=IMAGE_STRENGTH' \\\n -F 'image_strength=0.35' \\\n -F 'text_prompts[0][text]=A galactic dog in space' \\\n -F 'cfg_scale=7' \\\n -F 'samples=1' \\\n -F 'steps=30' \\\n -o \"$OUTPUT_FILE\"\n" 1232 } 1233 ] 1234 } 1235 }, 1236 "/v1/generation/{engine_id}/image-to-image/masking": { 1237 "post": { 1238 "description": "Selectively modify portions of an image using a mask", 1239 "operationId": "masking", 1240 "parameters": [ 1241 { 1242 "example": "stable-diffusion-xl-1024-v1-0", 1243 "in": "path", 1244 "name": "engine_id", 1245 "required": true, 1246 "schema": { 1247 "type": "string" 1248 } 1249 }, 1250 { 1251 "$ref": "#/components/parameters/accept" 1252 }, 1253 { 1254 "$ref": "#/components/parameters/organization" 1255 }, 1256 { 1257 "$ref": "#/components/parameters/stabilityClientID" 1258 }, 1259 { 1260 "$ref": "#/components/parameters/stabilityClientVersion" 1261 } 1262 ], 1263 "requestBody": { 1264 "content": { 1265 "multipart/form-data": { 1266 "examples": { 1267 "INIT_IMAGE_ALPHA": { 1268 "value": { 1269 "cfg_scale": 7, 1270 "clip_guidance_preset": "FAST_BLUE", 1271 "init_image": "<image binary>", 1272 "mask_source": "INIT_IMAGE_ALPHA", 1273 "sampler": "K_DPM_2_ANCESTRAL", 1274 "samples": 3, 1275 "steps": 30, 1276 "text_prompts[0][text]": "A dog space commander", 1277 "text_prompts[0][weight]": 1 1278 } 1279 }, 1280 "MASK_IMAGE_BLACK": { 1281 "value": { 1282 "cfg_scale": 7, 1283 "clip_guidance_preset": "FAST_BLUE", 1284 "init_image": "<image binary>", 1285 "mask_image": "<image binary>", 1286 "mask_source": "MASK_IMAGE_BLACK", 1287 "sampler": "K_DPM_2_ANCESTRAL", 1288 "samples": 3, 1289 "steps": 30, 1290 "text_prompts[0][text]": "A dog space commander", 1291 "text_prompts[0][weight]": 1 1292 } 1293 }, 1294 "MASK_IMAGE_WHITE": { 1295 "value": { 1296 "cfg_scale": 7, 1297 "clip_guidance_preset": "FAST_BLUE", 1298 "init_image": "<image binary>", 1299 "mask_image": "<image binary>", 1300 "mask_source": "MASK_IMAGE_WHITE", 1301 "sampler": "K_DPM_2_ANCESTRAL", 1302 "samples": 3, 1303 "steps": 30, 1304 "text_prompts[0][text]": "A dog space commander", 1305 "text_prompts[0][weight]": 1 1306 } 1307 } 1308 }, 1309 "schema": { 1310 "$ref": "#/components/schemas/MaskingRequestBody" 1311 } 1312 } 1313 }, 1314 "required": true 1315 }, 1316 "responses": { 1317 "200": { 1318 "$ref": "#/components/responses/GenerationResponse" 1319 }, 1320 "400": { 1321 "$ref": "#/components/responses/400FromGeneration" 1322 }, 1323 "401": { 1324 "$ref": "#/components/responses/401" 1325 }, 1326 "403": { 1327 "$ref": "#/components/responses/403" 1328 }, 1329 "404": { 1330 "$ref": "#/components/responses/404" 1331 }, 1332 "500": { 1333 "$ref": "#/components/responses/500" 1334 } 1335 }, 1336 "security": [ 1337 { 1338 "STABILITY_API_KEY": [] 1339 } 1340 ], 1341 "summary": "image-to-image/masking", 1342 "tags": [ 1343 "v1/generation" 1344 ], 1345 "x-codeSamples": [ 1346 { 1347 "lang": "Python", 1348 "source": "import base64\nimport os\nimport requests\n\nengine_id = \"stable-diffusion-xl-1024-v1-0\"\napi_host = os.getenv('API_HOST', 'https://api.stability.ai')\napi_key = os.getenv(\"STABILITY_API_KEY\")\n\nif api_key is None:\n raise Exception(\"Missing Stability API key.\")\n\nresponse = requests.post(\n f\"{api_host}/v1/generation/{engine_id}/image-to-image/masking\",\n headers={\n \"Accept\": 'application/json',\n \"Authorization\": f\"Bearer {api_key}\"\n },\n files={\n 'init_image': open(\"../init_image_1024.png\", 'rb'),\n 'mask_image': open(\"../mask_image_black_1024.png\", 'rb'),\n },\n data={\n \"mask_source\": \"MASK_IMAGE_BLACK\",\n \"text_prompts[0][text]\": \"A large spiral galaxy with a bright central bulge and a ring of stars around it\",\n \"cfg_scale\": 7,\n \"clip_guidance_preset\": \"FAST_BLUE\",\n \"samples\": 1,\n \"steps\": 30,\n }\n)\n\nif response.status_code != 200:\n raise Exception(\"Non-200 response: \" + str(response.text))\n\ndata = response.json()\n\nfor i, image in enumerate(data[\"artifacts\"]):\n with open(f\"./out/v1_img2img_masking_{i}.png\", \"wb\") as f:\n f.write(base64.b64decode(image[\"base64\"]))\n" 1349 }, 1350 { 1351 "label": "TypeScript", 1352 "lang": "Javascript", 1353 "source": "import fetch from 'node-fetch'\nimport FormData from 'form-data'\nimport fs from 'node:fs'\n\nconst engineId = 'stable-diffusion-xl-1024-v1-0'\nconst apiHost = process.env.API_HOST ?? 'https://api.stability.ai'\nconst apiKey = process.env.STABILITY_API_KEY\n\nif (!apiKey) throw new Error('Missing Stability API key.')\n\n// NOTE: This example is using a NodeJS FormData library. Browser\n// implementations should use their native FormData class. React Native\n// implementations should also use their native FormData class.\nconst formData = new FormData()\nformData.append('init_image', fs.readFileSync('../init_image_1024.png'))\nformData.append('mask_image', fs.readFileSync('../mask_image_black_1024.png'))\nformData.append('mask_source', 'MASK_IMAGE_BLACK')\nformData.append(\n 'text_prompts[0][text]',\n 'A large spiral galaxy with a bright central bulge and a ring of stars around it'\n)\nformData.append('cfg_scale', '7')\nformData.append('clip_guidance_preset', 'FAST_BLUE')\nformData.append('samples', 1)\nformData.append('steps', 30)\n\nconst response = await fetch(\n `${apiHost}/v1/generation/${engineId}/image-to-image/masking`,\n {\n method: 'POST',\n headers: {\n ...formData.getHeaders(),\n Accept: 'application/json',\n Authorization: `Bearer ${apiKey}`,\n },\n body: formData,\n }\n)\n\nif (!response.ok) {\n throw new Error(`Non-200 response: ${await response.text()}`)\n}\n\ninterface GenerationResponse {\n artifacts: Array<{\n base64: string\n seed: number\n finishReason: string\n }>\n}\n\nconst responseJSON = (await response.json()) as GenerationResponse\n\nresponseJSON.artifacts.forEach((image, index) => {\n fs.writeFileSync(\n `out/v1_img2img_masking_${index}.png`,\n Buffer.from(image.base64, 'base64')\n )\n})\n" 1354 }, 1355 { 1356 "lang": "Go", 1357 "source": "package main\n\nimport (\n\t\"bytes\"\n\t\"encoding/base64\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"io\"\n\t\"mime/multipart\"\n\t\"net/http\"\n\t\"os\"\n)\n\ntype MaskingImage struct {\n\tBase64 string `json:\"base64\"`\n\tSeed uint32 `json:\"seed\"`\n\tFinishReason string `json:\"finishReason\"`\n}\n\ntype MaskingResponse struct {\n\tImages []MaskingImage `json:\"artifacts\"`\n}\n\nfunc main() {\n\tengineId := \"stable-diffusion-xl-1024-v1-0\"\n\n\t// Build REST endpoint URL\n\tapiHost, hasApiHost := os.LookupEnv(\"API_HOST\")\n\tif !hasApiHost {\n\t\tapiHost = \"https://api.stability.ai\"\n\t}\n\treqUrl := apiHost + \"/v1/generation/\" + engineId + \"/image-to-image/masking\"\n\n\t// Acquire an API key from the environment\n\tapiKey, hasAPIKey := os.LookupEnv(\"STABILITY_API_KEY\")\n\tif !hasAPIKey {\n\t\tpanic(\"Missing STABILITY_API_KEY environment variable\")\n\t}\n\n\tdata := &bytes.Buffer{}\n\twriter := multipart.NewWriter(data)\n\n\t// Write the init image to the request\n\tinitImageWriter, _ := writer.CreateFormField(\"init_image\")\n\tinitImageFile, initImageErr := os.Open(\"../init_image_1024.png\")\n\tif initImageErr != nil {\n\t\tpanic(\"Could not open init_image.png\")\n\t}\n\t_, _ = io.Copy(initImageWriter, initImageFile)\n\n\t// Write the mask image to the request\n\tmaskImageWriter, _ := writer.CreateFormField(\"mask_image\")\n\tmaskImageFile, maskImageErr := os.Open(\"../mask_image_black_1024.png\")\n\tif maskImageErr != nil {\n\t\tpanic(\"Could not open mask_image_white.png\")\n\t}\n\t_, _ = io.Copy(maskImageWriter, maskImageFile)\n\n\t// Write the options to the request\n\t_ = writer.WriteField(\"mask_source\", \"MASK_IMAGE_BLACK\")\n\t_ = writer.WriteField(\"text_prompts[0][text]\", \"A large spiral galaxy with a bright central bulge and a ring of stars around it\")\n\t_ = writer.WriteField(\"cfg_scale\", \"7\")\n\t_ = writer.WriteField(\"clip_guidance_preset\", \"FAST_BLUE\")\n\t_ = writer.WriteField(\"samples\", \"1\")\n\t_ = writer.WriteField(\"steps\", \"30\")\n\twriter.Close()\n\n\t// Execute the request & read all the bytes of the response\n\tpayload := bytes.NewReader(data.Bytes())\n\treq, _ := http.NewRequest(\"POST\", reqUrl, payload)\n\treq.Header.Add(\"Content-Type\", writer.FormDataContentType())\n\treq.Header.Add(\"Accept\", \"application/json\")\n\treq.Header.Add(\"Authorization\", \"Bearer \"+apiKey)\n\tres, _ := http.DefaultClient.Do(req)\n\tdefer res.Body.Close()\n\n\tif res.StatusCode != 200 {\n\t\tvar body map[string]interface{}\n\t\tif err := json.NewDecoder(res.Body).Decode(&body); err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\tpanic(fmt.Sprintf(\"Non-200 response: %s\", body))\n\t}\n\n\t// Decode the JSON body\n\tvar body MaskingResponse\n\tif err := json.NewDecoder(res.Body).Decode(&body); err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Write the images to disk\n\tfor i, image := range body.Images {\n\t\toutFile := fmt.Sprintf(\"./out/v1_img2img_masking_%d.png\", i)\n\t\tfile, err := os.Create(outFile)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\n\t\timageBytes, err := base64.StdEncoding.DecodeString(image.Base64)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\n\t\tif _, err := file.Write(imageBytes); err != nil {\n\t\t\tpanic(err)\n\t\t}\n\n\t\tif err := file.Close(); err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t}\n}\n" 1358 }, 1359 { 1360 "lang": "cURL", 1361 "source": "#!/bin/sh\n\nset -e\n\nif [ -z \"$STABILITY_API_KEY\" ]; then\n echo \"STABILITY_API_KEY environment variable is not set\"\n exit 1\nfi\n\nOUTPUT_FILE=./out/v1_img2img_masking.png\nBASE_URL=${API_HOST:-https://api.stability.ai}\nURL=\"$BASE_URL/v1/generation/stable-diffusion-xl-1024-v1-0/image-to-image/masking\"\n\ncurl -f -sS -X POST \"$URL\" \\\n -H 'Content-Type: multipart/form-data' \\\n -H 'Accept: image/png' \\\n -H \"Authorization: Bearer $STABILITY_API_KEY\" \\\n -F 'init_image=@\"../init_image_1024.png\"' \\\n -F 'mask_image=@\"../mask_image_black_1024.png\"' \\\n -F 'mask_source=MASK_IMAGE_BLACK' \\\n -F 'text_prompts[0][text]=A large spiral galaxy with a bright central bulge and a ring of stars around it' \\\n -F 'cfg_scale=7' \\\n -F 'clip_guidance_preset=FAST_BLUE' \\\n -F 'samples=1' \\\n -F 'steps=30' \\\n -o \"$OUTPUT_FILE\"\n" 1362 } 1363 ] 1364 } 1365 }, 1366 "/v1/generation/{engine_id}/image-to-image/upscale": { 1367 "post": { 1368 "description": "Create a higher resolution version of an input image.\n\nThis operation outputs an image with a maximum pixel count of **4,194,304**. This is equivalent to dimensions such as `2048x2048` and `4096x1024`.\n\nBy default, the input image will be upscaled by a factor of 2. For additional control over the output dimensions, a `width` or `height` parameter may be specified.\n\nFor upscaler engines that are ESRGAN-based, refer to the `RealESRGANUpscaleRequestBody` body option below. For upscaler engines that are Stable Diffusion Latent Upscaler-based, refer to the `LatentUpscalerUpscaleRequestBody` body option below.\n\nFor more details on the upscaler engines, refer to the [documentation on the Platform site.](https://platform.stability.ai/docs/features/image-upscaling?tab=python)\n", 1369 "operationId": "upscaleImage", 1370 "parameters": [ 1371 { 1372 "$ref": "#/components/parameters/upscaleEngineID" 1373 }, 1374 { 1375 "$ref": "#/components/parameters/accept" 1376 }, 1377 { 1378 "$ref": "#/components/parameters/organization" 1379 }, 1380 { 1381 "$ref": "#/components/parameters/stabilityClientID" 1382 }, 1383 { 1384 "$ref": "#/components/parameters/stabilityClientVersion" 1385 } 1386 ], 1387 "requestBody": { 1388 "content": { 1389 "multipart/form-data": { 1390 "examples": { 1391 "DESIRED_HEIGHT": { 1392 "description": "Upscale input image to desired height with ESRGAN or the Latent Upscaler.", 1393 "value": { 1394 "height": 1024, 1395 "image": "<image binary>" 1396 } 1397 }, 1398 "DESIRED_WIDTH": { 1399 "description": "Upscale input image to desired width with ESRGAN or the Latent Upscaler.", 1400 "value": { 1401 "image": "<image binary>", 1402 "width": 1024 1403 } 1404 }, 1405 "ESRGAN": { 1406 "description": "Upscale input image by 2x using ESRGAN.", 1407 "value": { 1408 "image": "<image binary>" 1409 } 1410 }, 1411 "LATENT_UPSCALER": { 1412 "description": "Request using the Latent Upscaler. Refer to the LatentUpscalerUpscaleRequestBody for reference.", 1413 "value": { 1414 "cfg_scale": 7, 1415 "image": "<image binary>", 1416 "seed": 5555, 1417 "steps": 30, 1418 "text_prompts[0][text]": "A dog space commander", 1419 "text_prompts[0][weight]": 1 1420 } 1421 } 1422 }, 1423 "schema": { 1424 "oneOf": [ 1425 { 1426 "$ref": "#/components/schemas/RealESRGANUpscaleRequestBody" 1427 }, 1428 { 1429 "$ref": "#/components/schemas/LatentUpscalerUpscaleRequestBody" 1430 } 1431 ] 1432 } 1433 } 1434 }, 1435 "required": true 1436 }, 1437 "responses": { 1438 "200": { 1439 "$ref": "#/components/responses/GenerationResponse" 1440 }, 1441 "400": { 1442 "$ref": "#/components/responses/400FromUpscale" 1443 }, 1444 "401": { 1445 "$ref": "#/components/responses/401" 1446 }, 1447 "403": { 1448 "$ref": "#/components/responses/403" 1449 }, 1450 "404": { 1451 "$ref": "#/components/responses/404" 1452 }, 1453 "500": { 1454 "$ref": "#/components/responses/500" 1455 } 1456 }, 1457 "security": [ 1458 { 1459 "STABILITY_API_KEY": [] 1460 } 1461 ], 1462 "summary": "image-to-image/upscale", 1463 "tags": [ 1464 "v1/generation" 1465 ], 1466 "x-codeSamples": [ 1467 { 1468 "lang": "Python", 1469 "source": "import os\nimport requests\n\nengine_id = \"esrgan-v1-x2plus\"\napi_host = os.getenv(\"API_HOST\", \"https://api.stability.ai\")\napi_key = os.getenv(\"STABILITY_API_KEY\")\n\nif api_key is None:\n raise Exception(\"Missing Stability API key.\")\n\nresponse = requests.post(\n f\"{api_host}/v1/generation/{engine_id}/image-to-image/upscale\",\n headers={\n \"Accept\": \"image/png\",\n \"Authorization\": f\"Bearer {api_key}\"\n },\n files={\n \"image\": open(\"../init_image.png\", \"rb\")\n },\n data={\n \"width\": 1024,\n }\n)\n\nif response.status_code != 200:\n raise Exception(\"Non-200 response: \" + str(response.text))\n\nwith open(f\"./out/v1_upscaled_image.png\", \"wb\") as f:\n f.write(response.content)\n" 1470 }, 1471 { 1472 "label": "TypeScript", 1473 "lang": "Javascript", 1474 "source": "import fetch from 'node-fetch'\nimport FormData from 'form-data'\nimport fs from 'node:fs'\n\nconst engineId = 'esrgan-v1-x2plus'\nconst apiHost = process.env.API_HOST ?? 'https://api.stability.ai'\nconst apiKey = process.env.STABILITY_API_KEY\n\nif (!apiKey) throw new Error('Missing Stability API key.')\n\n// NOTE: This example is using a NodeJS FormData library.\n// Browsers should use their native FormData class.\n// React Native apps should also use their native FormData class.\nconst formData = new FormData()\nformData.append('image', fs.readFileSync('../init_image.png'))\nformData.append('width', 1024)\n\nconst response = await fetch(\n `${apiHost}/v1/generation/${engineId}/image-to-image/upscale`,\n {\n method: 'POST',\n headers: {\n ...formData.getHeaders(),\n Accept: 'image/png',\n Authorization: `Bearer ${apiKey}`,\n },\n body: formData,\n }\n)\n\nif (!response.ok) {\n throw new Error(`Non-200 response: ${await response.text()}`)\n}\n\nconst image = await response.arrayBuffer()\nfs.writeFileSync('./out/v1_upscaled_image.png', Buffer.from(image))\n" 1475 }, 1476 { 1477 "lang": "Go", 1478 "source": "package main\n\nimport (\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"io\"\n\t\"mime/multipart\"\n\t\"net/http\"\n\t\"os\"\n)\n\nfunc main() {\n\tengineId := \"esrgan-v1-x2plus\"\n\n\t// Build REST endpoint URL\n\tapiHost, hasApiHost := os.LookupEnv(\"API_HOST\")\n\tif !hasApiHost {\n\t\tapiHost = \"https://api.stability.ai\"\n\t}\n\treqUrl := apiHost + \"/v1/generation/\" + engineId + \"/image-to-image/upscale\"\n\n\t// Acquire an API key from the environment\n\tapiKey, hasAPIKey := os.LookupEnv(\"STABILITY_API_KEY\")\n\tif !hasAPIKey {\n\t\tpanic(\"Missing STABILITY_API_KEY environment variable\")\n\t}\n\n\tdata := &bytes.Buffer{}\n\twriter := multipart.NewWriter(data)\n\n\t// Write the init image to the request\n\tinitImageWriter, _ := writer.CreateFormField(\"image\")\n\tinitImageFile, initImageErr := os.Open(\"../init_image.png\")\n\tif initImageErr != nil {\n\t\tpanic(\"Could not open init_image.png\")\n\t}\n\t_, _ = io.Copy(initImageWriter, initImageFile)\n\n\t// Write the options to the request\n\t_ = writer.WriteField(\"width\", \"1024\")\n\twriter.Close()\n\n\t// Execute the request\n\tpayload := bytes.NewReader(data.Bytes())\n\treq, _ := http.NewRequest(\"POST\", reqUrl, payload)\n\treq.Header.Add(\"Content-Type\", writer.FormDataContentType())\n\treq.Header.Add(\"Accept\", \"image/png\")\n\treq.Header.Add(\"Authorization\", \"Bearer \"+apiKey)\n\tres, _ := http.DefaultClient.Do(req)\n\tdefer res.Body.Close()\n\n\tif res.StatusCode != 200 {\n\t\tvar body map[string]interface{}\n\t\tif err := json.NewDecoder(res.Body).Decode(&body); err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\tpanic(fmt.Sprintf(\"Non-200 response: %s\", body))\n\t}\n\n\t// Write the response to a file\n\tout, err := os.Create(\"./out/v1_upscaled_image.png\")\n\tdefer out.Close()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t_, err = io.Copy(out, res.Body)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n" 1479 }, 1480 { 1481 "lang": "cURL", 1482 "source": "if [ -z \"$STABILITY_API_KEY\" ]; then\n echo \"STABILITY_API_KEY environment variable is not set\"\n exit 1\nfi\n\nOUTPUT_FILE=./out/v1_upscaled_image.png\nBASE_URL=${API_HOST:-https://api.stability.ai}\nURL=\"$BASE_URL/v1/generation/esrgan-v1-x2plus/image-to-image/upscale\"\n\ncurl -f -sS -X POST \"$URL\" \\\n -H 'Content-Type: multipart/form-data' \\\n -H 'Accept: image/png' \\\n -H \"Authorization: Bearer $STABILITY_API_KEY\" \\\n -F 'image=@\"../init_image.png\"' \\\n -F 'width=1024' \\\n -o \"$OUTPUT_FILE\"\n" 1483 } 1484 ] 1485 } 1486 }, 1487 "/v1/generation/{engine_id}/text-to-image": { 1488 "post": { 1489 "description": "Generate a new image from a text prompt", 1490 "operationId": "textToImage", 1491 "parameters": [ 1492 { 1493 "$ref": "#/components/parameters/engineID" 1494 }, 1495 { 1496 "$ref": "#/components/parameters/accept" 1497 }, 1498 { 1499 "$ref": "#/components/parameters/organization" 1500 }, 1501 { 1502 "$ref": "#/components/parameters/stabilityClientID" 1503 }, 1504 { 1505 "$ref": "#/components/parameters/stabilityClientVersion" 1506 } 1507 ], 1508 "requestBody": { 1509 "content": { 1510 "application/json": { 1511 "example": { 1512 "cfg_scale": 7, 1513 "clip_guidance_preset": "FAST_BLUE", 1514 "height": 512, 1515 "sampler": "K_DPM_2_ANCESTRAL", 1516 "samples": 1, 1517 "steps": 30, 1518 "text_prompts": [ 1519 { 1520 "text": "A lighthouse on a cliff", 1521 "weight": 1 1522 } 1523 ], 1524 "width": 512 1525 }, 1526 "schema": { 1527 "$ref": "#/components/schemas/TextToImageRequestBody" 1528 } 1529 } 1530 }, 1531 "required": true 1532 }, 1533 "responses": { 1534 "200": { 1535 "$ref": "#/components/responses/GenerationResponse" 1536 }, 1537 "400": { 1538 "$ref": "#/components/responses/400FromGeneration" 1539 }, 1540 "401": { 1541 "$ref": "#/components/responses/401" 1542 }, 1543 "403": { 1544 "$ref": "#/components/responses/403" 1545 }, 1546 "404": { 1547 "$ref": "#/components/responses/404" 1548 }, 1549 "500": { 1550 "$ref": "#/components/responses/500" 1551 } 1552 }, 1553 "security": [ 1554 { 1555 "STABILITY_API_KEY": [] 1556 } 1557 ], 1558 "summary": "text-to-image", 1559 "tags": [ 1560 "v1/generation" 1561 ], 1562 "x-codeSamples": [ 1563 { 1564 "lang": "Python", 1565 "source": "import base64\nimport os\nimport requests\n\nengine_id = \"stable-diffusion-v1-6\"\napi_host = os.getenv('API_HOST', 'https://api.stability.ai')\napi_key = os.getenv(\"STABILITY_API_KEY\")\n\nif api_key is None:\n raise Exception(\"Missing Stability API key.\")\n\nresponse = requests.post(\n f\"{api_host}/v1/generation/{engine_id}/text-to-image\",\n headers={\n \"Content-Type\": \"application/json\",\n \"Accept\": \"application/json\",\n \"Authorization\": f\"Bearer {api_key}\"\n },\n json={\n \"text_prompts\": [\n {\n \"text\": \"A lighthouse on a cliff\"\n }\n ],\n \"cfg_scale\": 7,\n \"height\": 1024,\n \"width\": 1024,\n \"samples\": 1,\n \"steps\": 30,\n },\n)\n\nif response.status_code != 200:\n raise Exception(\"Non-200 response: \" + str(response.text))\n\ndata = response.json()\n\nfor i, image in enumerate(data[\"artifacts\"]):\n with open(f\"./out/v1_txt2img_{i}.png\", \"wb\") as f:\n f.write(base64.b64decode(image[\"base64\"]))\n" 1566 }, 1567 { 1568 "label": "TypeScript", 1569 "lang": "Javascript", 1570 "source": "import fetch from 'node-fetch'\nimport fs from 'node:fs'\n\nconst engineId = 'stable-diffusion-v1-6'\nconst apiHost = process.env.API_HOST ?? 'https://api.stability.ai'\nconst apiKey = process.env.STABILITY_API_KEY\n\nif (!apiKey) throw new Error('Missing Stability API key.')\n\nconst response = await fetch(\n `${apiHost}/v1/generation/${engineId}/text-to-image`,\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n Authorization: `Bearer ${apiKey}`,\n },\n body: JSON.stringify({\n text_prompts: [\n {\n text: 'A lighthouse on a cliff',\n },\n ],\n cfg_scale: 7,\n height: 1024,\n width: 1024,\n steps: 30,\n samples: 1,\n }),\n }\n)\n\nif (!response.ok) {\n throw new Error(`Non-200 response: ${await response.text()}`)\n}\n\ninterface GenerationResponse {\n artifacts: Array<{\n base64: string\n seed: number\n finishReason: string\n }>\n}\n\nconst responseJSON = (await response.json()) as GenerationResponse\n\nresponseJSON.artifacts.forEach((image, index) => {\n fs.writeFileSync(\n `./out/v1_txt2img_${index}.png`,\n Buffer.from(image.base64, 'base64')\n )\n})\n" 1571 }, 1572 { 1573 "lang": "Go", 1574 "source": "package main\n\nimport (\n\t\"bytes\"\n\t\"encoding/base64\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"net/http\"\n\t\"os\"\n)\n\ntype TextToImageImage struct {\n\tBase64 string `json:\"base64\"`\n\tSeed uint32 `json:\"seed\"`\n\tFinishReason string `json:\"finishReason\"`\n}\n\ntype TextToImageResponse struct {\n\tImages []TextToImageImage `json:\"artifacts\"`\n}\n\nfunc main() {\n\t// Build REST endpoint URL w/ specified engine\n\tengineId := \"stable-diffusion-v1-6\"\n\tapiHost, hasApiHost := os.LookupEnv(\"API_HOST\")\n\tif !hasApiHost {\n\t\tapiHost = \"https://api.stability.ai\"\n\t}\n\treqUrl := apiHost + \"/v1/generation/\" + engineId + \"/text-to-image\"\n\n\t// Acquire an API key from the environment\n\tapiKey, hasAPIKey := os.LookupEnv(\"STABILITY_API_KEY\")\n\tif !hasAPIKey {\n\t\tpanic(\"Missing STABILITY_API_KEY environment variable\")\n\t}\n\n\tvar data = []byte(`{\n\t\t\"text_prompts\": [\n\t\t {\n\t\t\t\"text\": \"A lighthouse on a cliff\"\n\t\t }\n\t\t],\n\t\t\"cfg_scale\": 7,\n\t\t\"height\": 1024,\n\t\t\"width\": 1024,\n\t\t\"samples\": 1,\n\t\t\"steps\": 30\n \t}`)\n\n\treq, _ := http.NewRequest(\"POST\", reqUrl, bytes.NewBuffer(data))\n\treq.Header.Add(\"Content-Type\", \"application/json\")\n\treq.Header.Add(\"Accept\", \"application/json\")\n\treq.Header.Add(\"Authorization\", \"Bearer \"+apiKey)\n\n\t// Execute the request & read all the bytes of the body\n\tres, _ := http.DefaultClient.Do(req)\n\tdefer res.Body.Close()\n\n\tif res.StatusCode != 200 {\n\t\tvar body map[string]interface{}\n\t\tif err := json.NewDecoder(res.Body).Decode(&body); err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\tpanic(fmt.Sprintf(\"Non-200 response: %s\", body))\n\t}\n\n\t// Decode the JSON body\n\tvar body TextToImageResponse\n\tif err := json.NewDecoder(res.Body).Decode(&body); err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Write the images to disk\n\tfor i, image := range body.Images {\n\t\toutFile := fmt.Sprintf(\"./out/v1_txt2img_%d.png\", i)\n\t\tfile, err := os.Create(outFile)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\n\t\timageBytes, err := base64.StdEncoding.DecodeString(image.Base64)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\n\t\tif _, err := file.Write(imageBytes); err != nil {\n\t\t\tpanic(err)\n\t\t}\n\n\t\tif err := file.Close(); err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t}\n}\n" 1575 }, 1576 { 1577 "lang": "cURL", 1578 "source": "if [ -z \"$STABILITY_API_KEY\" ]; then\n echo \"STABILITY_API_KEY environment variable is not set\"\n exit 1\nfi\n\nOUTPUT_FILE=./out/v1_txt2img.png\nBASE_URL=${API_HOST:-https://api.stability.ai}\nURL=\"$BASE_URL/v1/generation/stable-diffusion-v1-6/text-to-image\"\n\ncurl -f -sS -X POST \"$URL\" \\\n -H 'Content-Type: application/json' \\\n -H 'Accept: image/png' \\\n -H \"Authorization: Bearer $STABILITY_API_KEY\" \\\n --data-raw '{\n \"text_prompts\": [\n {\n \"text\": \"A lighthouse on a cliff\"\n }\n ],\n \"cfg_scale\": 7,\n \"height\": 1024,\n \"width\": 1024,\n \"samples\": 1,\n \"steps\": 30\n }' \\\n -o \"$OUTPUT_FILE\"\n" 1579 } 1580 ] 1581 } 1582 }, 1583 "/v1/user/account": { 1584 "get": { 1585 "description": "Get information about the account associated with the provided API key", 1586 "operationId": "userAccount", 1587 "responses": { 1588 "200": { 1589 "content": { 1590 "application/json": { 1591 "schema": { 1592 "$ref": "#/components/schemas/AccountResponseBody" 1593 } 1594 } 1595 }, 1596 "description": "OK response." 1597 }, 1598 "401": { 1599 "$ref": "#/components/responses/401" 1600 }, 1601 "500": { 1602 "$ref": "#/components/responses/500" 1603 } 1604 }, 1605 "security": [ 1606 { 1607 "STABILITY_API_KEY": [] 1608 } 1609 ], 1610 "summary": "account", 1611 "tags": [ 1612 "v1/user" 1613 ], 1614 "x-codeSamples": [ 1615 { 1616 "lang": "Python", 1617 "source": "import os\nimport requests\n\napi_host = os.getenv('API_HOST', 'https://api.stability.ai')\nurl = f\"{api_host}/v1/user/account\"\n\napi_key = os.getenv(\"STABILITY_API_KEY\")\nif api_key is None:\n raise Exception(\"Missing Stability API key.\")\n\nresponse = requests.get(url, headers={\n \"Authorization\": f\"Bearer {api_key}\"\n})\n\nif response.status_code != 200:\n raise Exception(\"Non-200 response: \" + str(response.text))\n\n# Do something with the payload...\npayload = response.json()\n\n" 1618 }, 1619 { 1620 "label": "TypeScript", 1621 "lang": "Javascript", 1622 "source": "import fetch from 'node-fetch'\n\nconst apiHost = process.env.API_HOST ?? 'https://api.stability.ai'\nconst url = `${apiHost}/v1/user/account`\n\nconst apiKey = process.env.STABILITY_API_KEY\nif (!apiKey) throw new Error('Missing Stability API key.')\n\nconst response = await fetch(url, {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${apiKey}`,\n },\n})\n\nif (!response.ok) {\n throw new Error(`Non-200 response: ${await response.text()}`)\n}\n\ninterface User {\n id: string\n profile_picture: string\n email: string\n organizations?: Array<{\n id: string\n name: string\n role: string\n is_default: boolean\n }>\n}\n\n// Do something with the user...\nconst user = (await response.json()) as User\n" 1623 }, 1624 { 1625 "lang": "Go", 1626 "source": "package main\n\nimport (\n\t\"io\"\n\t\"net/http\"\n\t\"os\"\n)\n\nfunc main() {\n\t// Build REST endpoint URL\n\tapiHost, hasApiHost := os.LookupEnv(\"API_HOST\")\n\tif !hasApiHost {\n\t\tapiHost = \"https://api.stability.ai\"\n\t}\n\treqUrl := apiHost + \"/v1/user/account\"\n\n\t// Acquire an API key from the environment\n\tapiKey, hasAPIKey := os.LookupEnv(\"STABILITY_API_KEY\")\n\tif !hasAPIKey {\n\t\tpanic(\"Missing STABILITY_API_KEY environment variable\")\n\t}\n\n\t// Build the request\n\treq, _ := http.NewRequest(\"GET\", reqUrl, nil)\n\treq.Header.Add(\"Authorization\", \"Bearer \"+apiKey)\n\n\t// Execute the request\n\tres, _ := http.DefaultClient.Do(req)\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tif res.StatusCode != 200 {\n\t\tpanic(\"Non-200 response: \" + string(body))\n\t}\n\n\t// Do something with the payload...\n\t// payload := string(body)\n}\n" 1627 }, 1628 { 1629 "lang": "cURL", 1630 "source": "if [ -z \"$STABILITY_API_KEY\" ]; then\n echo \"STABILITY_API_KEY environment variable is not set\"\n exit 1\nfi\n\n# Determine the URL to use for the request\nBASE_URL=${API_HOST:-https://api.stability.ai}\nURL=\"$BASE_URL/v1/user/account\"\n\ncurl -f -sS \"$URL\" \\\n -H 'Accept: application/json' \\\n -H \"Authorization: Bearer $STABILITY_API_KEY\"\n" 1631 } 1632 ] 1633 } 1634 }, 1635 "/v1/user/balance": { 1636 "get": { 1637 "description": "Get the credit balance of the account/organization associated with the API key", 1638 "operationId": "userBalance", 1639 "parameters": [ 1640 { 1641 "$ref": "#/components/parameters/organization" 1642 }, 1643 { 1644 "$ref": "#/components/parameters/stabilityClientID" 1645 }, 1646 { 1647 "$ref": "#/components/parameters/stabilityClientVersion" 1648 } 1649 ], 1650 "responses": { 1651 "200": { 1652 "content": { 1653 "application/json": { 1654 "example": { 1655 "credits": 0.6336833840314097 1656 }, 1657 "schema": { 1658 "$ref": "#/components/schemas/BalanceResponseBody" 1659 } 1660 } 1661 }, 1662 "description": "OK response." 1663 }, 1664 "401": { 1665 "$ref": "#/components/responses/401" 1666 }, 1667 "500": { 1668 "$ref": "#/components/responses/500" 1669 } 1670 }, 1671 "security": [ 1672 { 1673 "STABILITY_API_KEY": [] 1674 } 1675 ], 1676 "summary": "balance", 1677 "tags": [ 1678 "v1/user" 1679 ], 1680 "x-codeSamples": [ 1681 { 1682 "lang": "Python", 1683 "source": "import os\nimport requests\n\napi_host = os.getenv('API_HOST', 'https://api.stability.ai')\nurl = f\"{api_host}/v1/user/balance\"\n\napi_key = os.getenv(\"STABILITY_API_KEY\")\nif api_key is None:\n raise Exception(\"Missing Stability API key.\")\n\nresponse = requests.get(url, headers={\n \"Authorization\": f\"Bearer {api_key}\"\n})\n\nif response.status_code != 200:\n raise Exception(\"Non-200 response: \" + str(response.text))\n\n# Do something with the payload...\npayload = response.json()\n\n" 1684 }, 1685 { 1686 "label": "TypeScript", 1687 "lang": "Javascript", 1688 "source": "import fetch from 'node-fetch'\n\nconst apiHost = process.env.API_HOST ?? 'https://api.stability.ai'\nconst url = `${apiHost}/v1/user/balance`\n\nconst apiKey = process.env.STABILITY_API_KEY\nif (!apiKey) throw new Error('Missing Stability API key.')\n\nconst response = await fetch(url, {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${apiKey}`,\n },\n})\n\nif (!response.ok) {\n throw new Error(`Non-200 response: ${await response.text()}`)\n}\n\ninterface Balance {\n credits: number\n}\n\n// Do something with the balance...\nconst balance = (await response.json()) as Balance\n" 1689 }, 1690 { 1691 "lang": "Go", 1692 "source": "package main\n\nimport (\n\t\"io\"\n\t\"net/http\"\n\t\"os\"\n)\n\nfunc main() {\n\t// Build REST endpoint URL\n\tapiHost, hasApiHost := os.LookupEnv(\"API_HOST\")\n\tif !hasApiHost {\n\t\tapiHost = \"https://api.stability.ai\"\n\t}\n\treqUrl := apiHost + \"/v1/user/balance\"\n\n\t// Acquire an API key from the environment\n\tapiKey, hasAPIKey := os.LookupEnv(\"STABILITY_API_KEY\")\n\tif !hasAPIKey {\n\t\tpanic(\"Missing STABILITY_API_KEY environment variable\")\n\t}\n\n\t// Build the request\n\treq, _ := http.NewRequest(\"GET\", reqUrl, nil)\n\treq.Header.Add(\"Authorization\", \"Bearer \"+apiKey)\n\n\t// Execute the request\n\tres, _ := http.DefaultClient.Do(req)\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tif res.StatusCode != 200 {\n\t\tpanic(\"Non-200 response: \" + string(body))\n\t}\n\n\t// Do something with the payload...\n\t// payload := string(body)\n}\n" 1693 }, 1694 { 1695 "lang": "cURL", 1696 "source": "if [ -z \"$STABILITY_API_KEY\" ]; then\n echo \"STABILITY_API_KEY environment variable is not set\"\n exit 1\nfi\n\n# Determine the URL to use for the request\nBASE_URL=${API_HOST:-https://api.stability.ai}\nURL=\"$BASE_URL/v1/user/balance\"\n\ncurl -f -sS \"$URL\" \\\n -H 'Content-Type: application/json' \\\n -H \"Authorization: Bearer $STABILITY_API_KEY\"\n" 1697 } 1698 ] 1699 } 1700 } 1701 }, 1702 "servers": [ 1703 { 1704 "url": "https://api.stability.ai" 1705 } 1706 ], 1707 "tags": [ 1708 { 1709 "description": "Manage your Stability.ai account, and view account/organization balances", 1710 "name": "v1/user" 1711 }, 1712 { 1713 "description": "Enumerate available engines", 1714 "name": "v1/engines" 1715 }, 1716 { 1717 "description": "Generate images from text, existing images, or both", 1718 "name": "v1/generation" 1719 } 1720 ] 1721 }