Pika /encrypt_image command
Table of contents
Use this endpoint to submit the Pika /encrypt_image command to your Discord Pika channel. Results obtained as a callback via optional parameter replyUrl
or by querying pika/jobs/?jobid=jobid
endpoint.
It is important not to use the Pika account setup for API access for any purposes other than its intended use, such as executing /encrypt_image
or any other Pika commands manually or in conjunction with any other automation tools. The useapi.net API internally tracks the usage of the Pika account, including the number of currently active executions. Using it for other activities may cause API to function incorrectly.
https://api.useapi.net/v1/pika/encrypt_image
Request Headers
Authorization: Bearer {API token}
Content-Type: multipart/form-data
API token
is required, see Setup useapi.net for details.
Request Body
{
"message": "Message image to be encrypted, must be File or Blob",
"prompt": "Pika prompt",
"image": "Reference image, must be File or Blob",
"discord": "Discord token",
"channel": "Discord channel id",
"maxJobs": 10,
"replyUrl": "Place your call back URL here",
"replyRef": "Place your reference id here"
}
-
message
is required, image to be encrypted. Must be either a File or Blob object when included in this FormData POST request. -
prompt
is required, must contain Pika /encrypt_image prompt.
Maximum length 1500 characters. -
image
is optional, use it as a reference image. Must be either a File or Blob object when included in this FormData POST request. -
discord
,channel
are optional, if not provided randomly selected available account from pika/account will be used. See Setup Pika for details.
Note You may specify thechannel
value alone (omittingdiscord
) when you wish to use a specific account from the configured list at pika/account. -
maxJobs
is optional, if not provided value forchannel
account selected above will be used, if not provided defaulted to 10. -
replyUrl
is optional, if not provided value from account will be used.
Place here your callback URL. API will call the providedreplyUrl
once job completed or failed.
Maximum length 1024 characters.
We recommend using sites like webhook.site to test callback URL functionality. -
replyRef
is optional, place here your reference id which will be stored and returned along with this job response / result.
Maximum length 1024 characters.
Responses
-
Use returned
jobid
to retrieve Pika job status and results.content
contains message generated by Pika reflecting current generation parameters and progress.{ "jobid": "<jobid>", "verb": "pika-encrypt_image", "status": "started", "created": "2023-09-09T02:04:49.667Z", "updated": "2023-09-09T02:04:53.490Z", "message": { "size": 92729, "type": "image/jpeg" }, "prompt": "waves crashing over the sandy beach, overhead shot -w 2 -size 100", "image": { "size": 23558, "type": "image/webp" }, "discord": "<ABC…secured…xyz>", "channel": "<Discord channel id>", "maxJobs": 10, "replyUrl": "https://webhook.site/abc", "replyRef": "<your optional reference id>", "messageId": "<Discord message id>", "content": "<@Discord user id> Creation job queued. (Prompt: waves crashing over the sandy beach, overhead shot -w 2 -size 100 Message: 1 Attachment Image: 1 Attachment Author: <@Discord user id>)", "timestamp": "2023-09-09T02:04:51.926000+00:00", "code": 200 }
-
{ "error": "message, prompt, discord or channel value is missing" "prompt, replyRef or replyUrl is too long" "message is not File or Blob" "image is not File or Blob" "code": 400 }
-
{ "error": "Unauthorized", "code": 401 }
-
{ "error": "Account has no subscription or subscription expired", "code": 402 }
-
Moderated message or invalid prompt params.
{ "error": "Sorry, your input may be inconsistent with server rules.", "jobid": "<jobid>", "status": "moderated", "code": 422 }
{ "error": "Invalid parameter", "errorDetails": "Unrecognized parameter(s): `size`", "jobid": "<jobid>", "status": "moderated", "code": 422 }
-
Wait in a loop for at least 10..30 seconds and retry again.
There are two possible cases for API response 429.
- API query is full and can not accept new pika/encrypt_image requests. Size of query defined by
maxJobs
optional parameter. Wait in a loop for at least 10..30 seconds and retry again.{ "error": "Maximum of <maxJobs> jobs executing in parallel supported", "executingJobs": [ "<jobid>", "<jobid>", "<jobid>" ], "code": 429 }
- The API received an HTTP status 429 from the Discord API when it attempted to POST to the
/interactions
endpoint. Under normal circumstances, this should be a rare occurrence because the API is designed to strictly adhere to Discord rate limits. However, in certain scenarios, Discord may still issue a 429 response.{ "error": "Discord /interactions failed with HTTP status 429", "errorDetails": "{\"global\":true,\"message\":\"You are being rate limited.\",\"retry_after\":10}", "code": 429 }
- API query is full and can not accept new pika/encrypt_image requests. Size of query defined by
Model
{ // TypeScript, all fields are optional
jobid: string, // Use returned jobid value to retrieve job status and results
verb: 'pika-encrypt_image',
status: 'started' | 'moderated' | 'failed',
created: string, // YYYY-MM-DDTHH:mm:ss.sssZ, IS0 8601, UTC
updated: string, // YYYY-MM-DDTHH:mm:ss.sssZ, IS0 8601, UTC
message: { size: number, type: string },
prompt: string,
image: { size: number, type: string },
discord: string, // Provided for debugging purposes only, contains the first 3 and the last 3 characters of the original value
channel: string,
maxJobs: number,
replyUrl: string,
replyRef: string,
messageId: string,
content: string, // Contains message generated by Pika reflecting current generation parameters and progress
timestamp: string,
error: string,
errorDetails: string,
executingJobs: string[],
code: number
}
Examples
-
curl -H "Accept: application/json" \ -H "Authorization: Bearer …" \ -X POST https://api.useapi.net/v1/pika/encrypt_image \ -F "discord=<Discord token>" \ -F "channel=<Discord channel id>" \ -F 'message=@"<Path to the message image>"' \ -F "prompt=<Pika prompt>" \ -F 'image=@"<Path to the reference image>"'
-
const main = async () => { const apiUrl = "https://api.useapi.net/v1/pika/encrypt_image"; const token = "API token"; const prompt = "Pika prompt"; const discord = "Discord token"; const channel = "Discord channel"; const data = { method: 'POST', headers: { 'Authorization': `Bearer ${token}` } }; const formData = new FormData(); formData.append("prompt", prompt); formData.append("discord", discord); formData.append("channel", channel); /* // Example 1: Fetch image from URL const imageUrl = "https://upload.wikimedia.org/wikipedia/commons/7/7d/Mona_Lisa_color_restoration.jpg"; const responseImage = await fetch(imageUrl); formData.append("message", await responseImage.blob()); */ /* // Example 2: Load image from local file (Blob) const fsp = require('fs').promises; const imageFileName = "./pika.webp"; const blob = new Blob([await fsp.readFile(imageFileName)]); formData.append("message", blob); */ /* // Example 3: Load from input file html element // <input id="pika-encrypt_image-image-url" type="file"> const imageFile = document.getElementById(`pika-encrypt_image-image-file`); if (imageFile.files[0]) formData.append("message", imageFile.files[0]); */ data.body = formData; const response = await fetch(apiUrl, data); const result = await response.json(); console.log("response", { response, result }); }; main()
-
import requests api_url = "https://api.useapi.net/v1/pika/encrypt_image" token = "API token" prompt = "Pika prompt" discord = "Discord token" channel = "Discord channel" headers = { 'Authorization': f'Bearer {token}' } files = { 'prompt': (None, prompt), 'discord': (None, discord), 'channel': (None, channel) } # # Example 1: Fetch image from URL # image_url = "https://upload.wikimedia.org/wikipedia/commons/7/7d/Mona_Lisa_color_restoration.jpg" # response_image = requests.get(image_url) # image_content = response_image.content # files['message'] = ('image.jpg', image_content, 'image/jpeg') # # Example 2: Load image from local file # image_file_path = "./pika.webp" # with open(image_file_path, 'rb') as image_file: # files['message'] = ('pika.webp', image_file.read(), 'image/webp') response = requests.post(api_url, headers=headers, files=files) print(response, response.json())