BennyKok / comfyui-deploy

An open source `vercel` like deployment platform for Comfy UI
https://comfydeploy.ing
GNU Affero General Public License v3.0
963 stars 124 forks source link

I can't open this webpage 'https://www.comfydeploy.com/api/run' - it's showing 'Invalid or expired token'." #5

Closed smilebear2010 closed 7 months ago

smilebear2010 commented 9 months ago

I can't open this webpage 'https://www.comfydeploy.com/api/run' - it's showing 'Invalid or expired token'."

BennyKok commented 9 months ago

You will need to call the endpoint to queue for the API, docs is coming on the way!

but here's a js client i have made for server side previously

Comfy Deploy Client

create a file called comfy-deploy.ts [expand to see the code]

```ts import { z } from "zod"; const runTypes = z.object({ run_id: z.string(), }); const runOutputTypes = z.object({ id: z.string(), status: z.string(), outputs: z.array( z.object({ data: z.any(), }) ), }); export class ComfyDeployClient { apiBase: string = "https://www.comfydeploy.com/api"; apiToken: string; constructor({ apiBase, apiToken }: { apiBase?: string; apiToken: string }) { if (apiBase) this.apiBase = `${apiBase}/api`; this.apiToken = apiToken; } async run({ deployment_id, inputs, }: { deployment_id: string; inputs?: Record; }) { return fetch(`${this.apiBase}/run`, { method: "POST", headers: { "Content-Type": "application/json", authorization: `Bearer ${this.apiToken}`, }, body: JSON.stringify({ deployment_id: deployment_id, inputs: inputs, }), }) .then((response) => response.json()) .then((json) => runTypes.parse(json)) .catch((err) => { console.error(err); return null; }); } async getRun(run_id: string) { return await fetch(`${this.apiBase}/run?run_id=${run_id}`, { method: "GET", headers: { "Content-Type": "application/json", authorization: `Bearer ${this.apiToken}`, }, }) .then((response) => response.json()) .then((json) => runOutputTypes.parse(json)) .catch((err) => { console.error(err); return null; }); } async runSync(props: { deployment_id: string; inputs?: Record; }) { const runResult = await this.run(props); if (!runResult) return null; // 5 minutes const timeout = 60 * 5; const interval = 1000; let run: Awaited> = null; for (let i = 0; i < timeout; i++) { run = await this.getRun(runResult.run_id); if (run && run.status == "succuss") { break; } await new Promise((resolve) => setTimeout(resolve, interval)); } if (!run) { return { id: runResult.run_id, }; } return run; } } ```

Calling run API

const result = await client.run({
  deployment_id: "<deployment_id>",
  inputs: {
      input_text: "some input if have",
    },
});

Example run response object

{
  "run_id": "acb550a9-5b4f-4758-a484-50d5245d394f"
}

Checking the API Outputs

const outputs = await client.getRun(result.run_id);

Example run outputs object

{
  "id": "acb550a9-5b4f-4758-a484-50d5245d394f",
  "workflow_version_id": "6307f76b-bb76-4583-9b3c-d7979adb2828",
  "workflow_inputs": {
    "input_text": "(a beautiful alien relaxing by the sea:1.2) (final professional masterpiece highly overflowing detailed:1.1), (room bokeh, warm soft lighting:1.1)"
  },
  "workflow_id": "31e4e07c-5478-487a-b507-82ea630dcbb0",
  "machine_id": "04f199fe-51ec-43c7-81da-ecb1d16db3fe",
  "origin": "api",
  "status": "success",
  "ended_at": "2023-12-30T16:00:54.356Z",
  "created_at": "2023-12-30T15:59:15.993Z",
  "outputs": [
    {
      "data": {
        "images": [
          {
            "type": "temp",
            "filename": "ComfyUI_temp_fnzzp_00001_.png",
            "subfolder": "",
            "url": "https://storage.comfydeploy.com/outputs/runs/acb550a9-5b4f-4758-a484-50d5245d394f/ComfyUI_temp_fnzzp_00001_.png"
          }
        ]
      }
    }
  ]
}

.env.local

COMFY_DEPLOY_AUTH=<YOUR_API_KEY>