runpod-client
Version:
This unofficial runpod.io client provides functionality to interact with the Runpod.io API.
171 lines (170 loc) • 5.89 kB
JavaScript
var r = /* @__PURE__ */ ((e) => (e.create = "create", e.list = "list", e.start = "start", e.stop = "stop", e.get = "get", e.getGPUTypes = "getGPUTypes", e.getGPU = "getGPU", e))(r || {});
const a = async (e) => (await (await fetch(e, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
query: `
query
Pods {
myself {
pods {
id
name
runtime {
uptimeInSeconds
ports {
ip
isIpPublic
privatePort
publicPort
type
}
gpus {
id
gpuUtilPercent
memoryUtilPercent
} container {
cpuPercent
memoryPercent
}
}
}
}
}
`
})
})).json()).data.myself.pods, p = async (e) => (await (await fetch(e, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
query: `
query GpuTypes {
gpuTypes {
id
displayName
memoryInGb
}
}
`
})
})).json()).data.gpuTypes, i = async (e, s, t = 1) => (await (await fetch(e, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
query: `
mutation {
podResume(
input: {
podId: "${s}",
gpuCount: ${t}
} )
{
id
desiredStatus
imageName
env
machineId
machine {
podHostId
}
}
}`
})
})).json()).data, c = async (e, s) => (await (await fetch(e, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
query: `
mutation {
podStop(
input:
{podId: "${s}"
})
{
id
desiredStatus
}
}`
})
})).json()).data, u = async (e, s) => (await (await fetch(e, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
query: `
query
Pod {
pod(
input: {
podId: "${s}"
}
)
{
id
name
runtime {
uptimeInSeconds
ports {
ip
isIpPublic
privatePort
publicPort
type
}
gpus {
id
gpuUtilPercent
memoryUtilPercent
} container {
cpuPercent
memoryPercent
}
}
}
}`
})
})).json()).data, d = async (e, s, t) => {
const n = await (await fetch(e, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
query: `
query GpuTypes {
gpuTypes(input: {id: "${s}"}) {
id
displayName
memoryInGb
secureCloud
communityCloud
lowestPrice(input: {gpuCount: ${t || 1}}) {
minimumBidPrice
uninterruptablePrice
}
}
}
`
})
})).json();
if (n.errors)
console.log(n.errors[0].message);
else
return n.data.gpuTypes;
}, y = (e) => ({ action: s, id: t, count: o }) => {
const n = "https://api.runpod.io/graphql?api_key=" + e;
switch (s) {
case r.list:
return a(n);
case r.start:
return t ? i(n, t, o) : "Please provide a pod id";
case r.stop:
return t ? c(n, t) : "Please provide a pod id";
case r.get:
return t ? u(n, t) : "Please provide a pod id";
case r.getGPU:
return t ? d(n, t, o) : "Please provide a gpu id";
case r.getGPUTypes:
return p(n);
}
};
export {
y as default
};