|
| 1 | +.. _ocs-text2image-api: |
| 2 | + |
| 3 | +====================== |
| 4 | +OCS Text-To-Image API |
| 5 | +====================== |
| 6 | + |
| 7 | +.. versionadded:: 28 |
| 8 | + |
| 9 | +The OCS Text-To-Image API allows you to run image generation tasks implemented by apps using :ref:`the backend Text-To-Image API<text2image>`. |
| 10 | + |
| 11 | +The base URL for all calls to this API is: *<nextcloud_base_url>/ocs/v2.php/text2image/* |
| 12 | + |
| 13 | +All calls to OCS endpoints require the ``OCS-APIRequest`` header to be set to ``true``. |
| 14 | + |
| 15 | + |
| 16 | +Check availability |
| 17 | +------------------ |
| 18 | + |
| 19 | +.. versionadded:: 28 |
| 20 | + |
| 21 | +* Method: ``GET`` |
| 22 | +* Endpoint: ``/is_available`` |
| 23 | +* Response: |
| 24 | + - Status code: |
| 25 | + + ``200 OK`` |
| 26 | + - Data: |
| 27 | + |
| 28 | ++----------------------+--------+---------------------------------------------------------------------------------------------------------------+ |
| 29 | +| field | type | Description | |
| 30 | ++----------------------+--------+---------------------------------------------------------------------------------------------------------------+ |
| 31 | +|``isAvailable`` | bool | Boolean indicating whether any Text-To-Image providers are installed | |
| 32 | ++----------------------+--------+---------------------------------------------------------------------------------------------------------------+ |
| 33 | + |
| 34 | +Schedule a task |
| 35 | +--------------- |
| 36 | + |
| 37 | +.. versionadded:: 28 |
| 38 | + |
| 39 | +.. note:: The endpoint is rate limited as it can be quite resource intensive. Users can make 20 requests in 2 minutes, guests only 5 |
| 40 | + |
| 41 | +* Method: ``POST`` |
| 42 | +* Endpoint: ``/schedule`` |
| 43 | +* Data: |
| 44 | + |
| 45 | ++-------------------+-------------+--------------------------------------------------------------------------------+ |
| 46 | +| field | type | Description | |
| 47 | ++-------------------+-------------+--------------------------------------------------------------------------------+ |
| 48 | +|``input`` | string | The input text for the task | |
| 49 | ++-------------------+-------------+--------------------------------------------------------------------------------+ |
| 50 | +|``numberOfImages`` | int | The number of images to generate (optional; default: 8) | |
| 51 | ++-------------------+-------------+--------------------------------------------------------------------------------+ |
| 52 | +|``appId`` | string | The id of the requesting app | |
| 53 | ++-------------------+-------------+--------------------------------------------------------------------------------+ |
| 54 | +|``identifier`` | string | An app-defined identifier for the task (optional) | |
| 55 | ++-------------------+-------------+--------------------------------------------------------------------------------+ |
| 56 | + |
| 57 | +If possible the task will be executed while the request is processed on the server, otherwise it is scheduled as a background job. |
| 58 | + |
| 59 | +* Response: |
| 60 | + - Status code: |
| 61 | + + ``200 OK`` |
| 62 | + + ``412 Precondition Failed`` - When the task type is not available currently |
| 63 | + + ``429 Too Many Requests`` - When the rate limiting was exceeded |
| 64 | + |
| 65 | + - Data: |
| 66 | + + ``id`` - Only provided in case of ``200 OK``, the assigned task id, int |
| 67 | + + ``input`` - Only provided in case of ``200 OK``, the task input, string |
| 68 | + + ``status`` - Only provided in case of ``200 OK``, the current task status, int, see :ref:`the backend Text-To-Image API<text2image_statuses>` |
| 69 | + + ``userId`` - Only provided in case of ``200 OK``, the originating userId of the task, string |
| 70 | + + ``appId`` - Only provided in case of ``200 OK``, the originating appId of the task, string |
| 71 | + + ``identifier`` - Only provided in case of ``200 OK``, the originating appId of the task, string |
| 72 | + + ``numberOfImages`` - Only provided in case of ``200 OK``, the number of generated images, int |
| 73 | + + ``completionExpectedAt`` - Only provided in case of ``200 OK``, the date and time when the result is expected to be completed as a UNIX timestamp, int |
| 74 | + + ``message`` - Only provided when not ``200 OK``, an error message in the user's language, ready to be displayed |
| 75 | + |
| 76 | +Fetch a task by ID |
| 77 | +------------------ |
| 78 | + |
| 79 | +.. versionadded:: 28 |
| 80 | + |
| 81 | +.. note:: The endpoint is rate limited as it can be quite resource intensive. Users can make 20 requests in 2 minutes, guests only 5 |
| 82 | + |
| 83 | +* Method: ``POST`` |
| 84 | +* Endpoint: ``/task/{id}`` |
| 85 | + |
| 86 | +* Response: |
| 87 | + - Status code: |
| 88 | + + ``200 OK`` |
| 89 | + + ``404 Not Found`` - When the task could not be found |
| 90 | + |
| 91 | + - Data: |
| 92 | + + ``id`` - Only provided in case of ``200 OK``, the assigned task id, int |
| 93 | + + ``input`` - Only provided in case of ``200 OK``, the task input, string |
| 94 | + + ``status`` - Only provided in case of ``200 OK``, the current task status, int, see :ref:`the backend Text-To-Image API<text2image_statuses>` |
| 95 | + + ``userId`` - Only provided in case of ``200 OK``, the originating userId of the task, string |
| 96 | + + ``appId`` - Only provided in case of ``200 OK``, the originating appId of the task, string |
| 97 | + + ``identifier`` - Only provided in case of ``200 OK``, the originating appId of the task, string |
| 98 | + + ``numberOfImages`` - Only provided in case of ``200 OK``, the number of generated images, int |
| 99 | + + ``completionExpectedAt`` - Only provided in case of ``200 OK``, the date and time when the result is expected to be completed as a UNIX timestamp, int |
| 100 | + + ``message`` - Only provided when not ``200 OK``, an error message in the user's language, ready to be displayed |
| 101 | + |
| 102 | +Fetch a result image |
| 103 | +-------------------- |
| 104 | + |
| 105 | +.. versionadded:: 28 |
| 106 | + |
| 107 | +* Method: ``POST`` |
| 108 | +* Endpoint: ``/task/{id}/image/{index}`` |
| 109 | + * ``index``: The index of the image, starting at 0 |
| 110 | + |
| 111 | +* Response: |
| 112 | + - Status code: |
| 113 | + + ``200 OK`` |
| 114 | + + ``404 Not Found`` - When the task could not be found, isn't successful, isn't completed yet, or the index is out of bounds |
| 115 | + |
| 116 | + - Data: The raw image data |
| 117 | + |
| 118 | +Delete a task |
| 119 | +------------- |
| 120 | + |
| 121 | +.. versionadded:: 28 |
| 122 | + |
| 123 | +* Method: ``DELETE`` |
| 124 | +* Endpoint: ``/task/{id}`` |
| 125 | + |
| 126 | +* Response: |
| 127 | + - Status code: |
| 128 | + + ``200 OK`` |
| 129 | + + ``404 Not Found`` - When the task could not be found |
| 130 | + |
| 131 | + - Data: |
| 132 | + + ``id`` - Only provided in case of ``200 OK``, the assigned task id, int |
| 133 | + + ``input`` - Only provided in case of ``200 OK``, the task input, string |
| 134 | + + ``status`` - Only provided in case of ``200 OK``, the current task status, int, see :ref:`the backend Text-To-Image API<text2image_statuses>` |
| 135 | + + ``userId`` - Only provided in case of ``200 OK``, the originating userId of the task, string |
| 136 | + + ``appId`` - Only provided in case of ``200 OK``, the originating appId of the task, string |
| 137 | + + ``identifier`` - Only provided in case of ``200 OK``, the originating appId of the task, string |
| 138 | + + ``numberOfImages`` - Only provided in case of ``200 OK``, the number of generated images, int |
| 139 | + + ``completionExpectedAt`` - Only provided in case of ``200 OK``, the date and time when the result is expected to be completed as a UNIX timestamp, int |
| 140 | + + ``message`` - Only provided when not ``200 OK``, an error message in the user's language, ready to be displayed |
| 141 | + |
| 142 | +List tasks by App |
| 143 | +------------------ |
| 144 | + |
| 145 | +.. versionadded:: 28 |
| 146 | + |
| 147 | +.. note:: The endpoint is rate limited as it can be quite resource intensive. Guests can only do 5 requests within 2 minutes |
| 148 | + |
| 149 | +* Method: ``DELETE`` |
| 150 | +* Endpoint: ``/tasks/app/{appId}`` |
| 151 | +* Data: |
| 152 | + |
| 153 | ++-------------------+-------------+--------------------------------------------------------------------------------+ |
| 154 | +| field | type | Description | |
| 155 | ++-------------------+-------------+--------------------------------------------------------------------------------+ |
| 156 | +|``appId`` | string | The id of the requesting app | |
| 157 | ++-------------------+-------------+--------------------------------------------------------------------------------+ |
| 158 | +|``identifier`` | string | An app-defined identifier for the task (optional) | |
| 159 | ++-------------------+-------------+--------------------------------------------------------------------------------+ |
| 160 | + |
| 161 | +* Response: |
| 162 | + - Status code: |
| 163 | + + ``200 OK`` |
| 164 | + + ``404 Not Found`` - When the task could not be found |
| 165 | + |
| 166 | + - Data: |
| 167 | + + Only provided in case of ``200 OK``, an array of objects: |
| 168 | + + ``id`` - the assigned task id, int |
| 169 | + + ``input`` - the task input, string |
| 170 | + + ``status`` - the current task status, int, see :ref:`the backend Text-To-Image API<text2image_statuses>` |
| 171 | + + ``userId`` - the originating userId of the task, string |
| 172 | + + ``appId`` - the originating appId of the task, string |
| 173 | + + ``identifier`` - the originating appId of the task, string |
| 174 | + + ``numberOfImages`` - the number of generated images, int |
| 175 | + + ``completionExpectedAt`` - the date and time when the result is expected to be completed as a UNIX timestamp, int |
| 176 | + + ``message`` - Only provided when not ``200 OK``, an error message in the user's language, ready to be displayed |
0 commit comments