Pika button command
Table of contents
Use this endpoint to submit the Pika button command to your Discord Pika channel. Results obtained as a callback via optional parameter replyUrl
or by querying pika/jobs/?jobid=jobid
endpoint.
Currently only the retry
button is supported. The API does not support the remix
button. Since both buttons simply offer a convenient way of rerunning a job without the need to re-upload content, this limitation does not result in any loss of functionality.
It is important not to use the Pika account setup for API access for any purposes other than its intended use, such as executing /button
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/button
Request Headers
Authorization: Bearer {API token}
Content-Type: multipart/form-data
API token
is required, see Setup useapi.net for details.
Request Body
{
"jobid": "jobid",
"button": "button",
"discord": "Discord token",
"maxJobs": 10,
"replyUrl": "Place your call back URL here",
"replyRef": "Place your reference id here"
}
-
jobid
is required,jobid
of successfully completed (status
set to completed pika/create, pika/animate, pika/encrypt_text, pika/encrypt_image or pika/button job. -
button
is required, button from buttons array of job referenced viajobid
above, see button. -
discord
is optional, if provided will overridediscord
value of referenced abovejobid
, see Setup Pika for details. If thechannel
corresponding to thejobid
mentioned above has an account configured under pika/account, the current account’sdiscord
value will be used if it is not explicitly provided. This ensures that even jobs executed some time ago can still be successfully executed by this endpoint, even after possible changes to the account’sdiscord
value. -
maxJobs
is optional, if provided will overridemaxJobs
value of referenced abovejobid
, 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-button", "status": "started", "created": "2023-09-09T02:04:49.667Z", "updated": "2023-09-09T02:04:53.490Z", "button": "retry", "parentJobId": "<jobid>", "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": "jobid or button value is missing" "button <button> not supported" "replyRef or replyUrl is too long" "code": 400 }
-
{ "error": "Unauthorized", "code": 401 }
-
{ "error": "Account has no subscription or subscription expired", "code": 402 }
-
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/button 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/button 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-button',
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
button: 'retry',
parentJobId: 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/button \ -F "discord=<Discord token>" \ -F "jobid=<Completed pika/… jobid>" \ -F "button=<Button from buttons array of above jobid>"
-
const main = async () => { const apiUrl = "https://api.useapi.net/v1/pika/button"; const token = "API token"; const jobid = "Completed pika/… jobid"; const button = "Button from buttons array of above jobid"; const discord = "Discord token"; const data = { method: 'POST', headers: { 'Authorization': `Bearer ${token}` } }; const formData = new FormData(); formData.append("jobid", jobid); formData.append("button", button); formData.append("discord", discord); 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/button" token = "API token" jobid = "Completed pika/… jobid" button = "Button from buttons array of above jobid" discord = "Discord token" channel = "Discord channel" headers = { 'Authorization': f'Bearer {token}' } files = { 'jobid': (None, jobid), 'button': (None, button), 'discord': (None, discord) } response = requests.post(api_url, headers=headers, files=files) print(response, response.json())