R
RunPod4mo ago
maya007

Is it possible to restart the pod using manage Pod GraphQL API?

Is it possible to restart the pod using manage Pod GraphQL API?
4 Replies
ashleyk
ashleyk4mo ago
Yes, you can stop it and then start it. Here are some examples: https://github.com/ashleykleynhans/runpod-api
GitHub
GitHub - ashleykleynhans/runpod-api: A collection of Python scripts...
A collection of Python scripts for calling the RunPod GraphQL API - ashleykleynhans/runpod-api
πxel
πxel3mo ago
but this will introduce a risc of loosing the pod during the time between stop and start right when you restart from the webui i will just restart the docker container without stopping the whole thing however i am wondering how to do this as a api user, since the api https://hapi.runpod.net/v1/pod/${id}/restart seems to not work with the api key auth
ashleyk
ashleyk3mo ago
Those APIs have different credentials than your normal API key You have to inspect the console to see how to get it
πxel
πxel3mo ago
yes, i was able to fake a restart by doing a edit/update call without changing details, which in return will cause a restart nodejs example:
/** */
restartPod: async function({ id }: { id: string }) {
const response = await fetch(
`https://api.runpod.io/graphql?api_key=${}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
operationName: "editPodJob",
variables: {
input: {
podId: id,
imageName: "runpod/pytorch:2.1.0-py3.10-cuda11.8.0-devel-ubuntu22.04",
containerDiskInGb: 20,
volumeInGb: 20,
},
},
query: `
mutation editPodJob($input: PodEditJobInput!) {
podEditJob(input: $input) {
id
}
}`,
}),
},
)
const res = await response.json()
return res
},
/** */
restartPod: async function({ id }: { id: string }) {
const response = await fetch(
`https://api.runpod.io/graphql?api_key=${}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
operationName: "editPodJob",
variables: {
input: {
podId: id,
imageName: "runpod/pytorch:2.1.0-py3.10-cuda11.8.0-devel-ubuntu22.04",
containerDiskInGb: 20,
volumeInGb: 20,
},
},
query: `
mutation editPodJob($input: PodEditJobInput!) {
podEditJob(input: $input) {
id
}
}`,
}),
},
)
const res = await response.json()
return res
},