Use DALL·E 2 with Nodejs

Overview

Get Access

labs.openai.com/waitlist

Usage

npm install dalle-node
import { Dalle } from "dalle-node";

const dalle = new Dalle("sess-xxxxxxxxxxxxxxxxxxxxxxxxx"); // Bearer Token 

const generations = await dalle.generate("a cat driving a car");

console.log(generations)
[
  {
    id: 'generation-sCnERSYDPP0Zu14fsdXEcKmL',
    object: 'generation',
    created: 1553332711,
    generation_type: 'ImageGeneration',
    generation: {
      image_path: 'https://openailabsprodscus.blob.core.windows.net/private/user-hadpVzldsfs28CwvEZYMUT/generations/generation...'
    },
    task_id: 'task-nERkiKsdjVCSZ50yD69qewID',
    prompt_id: 'prompt-2CtaLQsgUbJHHDoJQy9Lul3T',
    is_public: false
  },
  {
    id: 'generation-hZWt2Nasrx8R0tJjbaROfKVy',
    object: 'generation',
    created: 1553332711,
    generation_type: 'ImageGeneration',
    generation: {
      image_path: 'https://openailabsprodscus.blob.core.windows.net/private/user-hadpVzldsfs28CwvEZYMUT/generations/generation...'
    },
    task_id: 'task-nERkiKhjasdSZ50yD69qewID',
    prompt_id: 'prompt-2CtaLasdUbJHHfoJQy9Lul3T',
    is_public: false
  },
  // 8 more ... 
]

Example Nextjs Application

Comments
  • using in browser environment

    using in browser environment

    import { Dalle } from "dalle-node"
    

    It works when imported in NextJS API Route, but when above import statement moved to component file, it fails with following error:

    image

    opened by 7flash 2
  • Add support for rejected responses

    Add support for rejected responses

    Currently rejected responses will hang as the promise never resolves. This PR adds support for rejected responses. There may be other statuses that should be handled also but currently only accounting for succeeded and rejected.

    opened by chambaz 2
  • :sparkles: Add getCredits() API

    :sparkles: Add getCredits() API

    Added a function to get the credits available. Remembered to update the README docs this time. Slightly adjusted this.url since this function does not use /tasks, it uses /billing instead.

    The call looks like:

    const creditsSummary = await dalle.getCredits();
    

    Returned object looks like:

    {
      "aggregate_credits": 180,
      "next_grant_ts": 123456789,
      "breakdown": {
        "free": 0,
        "grant_beta_tester": 65,
        "paid_dalle_15_115": 115
      },
      "object": "credit_summary"
    }
    

    In most cases, just the total credits left would be wanted:

    const totalCreditsLeft = (await dalle.getCredits()).aggregate_credits;
    

    To get the date + time that the free credits will refresh:

    const credits = await dalle.getCredits()
    console.log('Free credits refresh on:', new Date(credits.next_grant_ts * 1000).toLocaleString());
    
    opened by Christopher-Hayes 1
  • Add getTask() function

    Add getTask() function

    Added a function to get an individual task. The generate function already does this, just creating an endpoint for anyone to use it. Updated generate() to use this function as well.

    Arguments

    taskId The ID of the task, this gets returned by generate().

    Sample Usage

    import { Dalle } from "./dalle-node.js";
    const dalle = new Dalle('bearer-token');
    
    dalle.getTask('task-id-here').then(task => {
      console.log(task);
    }).catch(error => {
      console.log('error', error);
    })
    
    opened by Christopher-Hayes 1
  • Add function to list previous runs

    Add function to list previous runs

    This adds a function to list prevous runs.

    Options

    limit: A limit argument is optional, by default gets the last 50 runs, which is what the Dalle UI uses.

    fromTs: Get runs from a specific timestamp (ts). Uses time in milliseconds.

    Example usage

    import { Dalle } from "dalle-node";
    
    const dalle = new Dalle('bearer-token');
    
    const last50Runs = dalle.list()
    
    const last3Runs = dalle.list({ limit: 3 })
    
    const getRunsAfterTimestamp = dalle.list({ fromTs: 12345679 })
    

    Returns an array of these objects

      {
        object: 'task',
        id: '<task-id>',
        created: 123456789,
        task_type: 'text2im',
        status: 'succeeded',
        status_information: {},
        prompt_id: '<prompt-id>',
        generations: [Object],
        prompt: [Object]
      }
    
    opened by Christopher-Hayes 1
  • Support for lower nodeJS version

    Support for lower nodeJS version

    I use the require function to load the other npm module, e.g., const fs = require('fs'). However, It will be conflicted if I used import function to import your npm module. Do you have plan to support the require function rather than import / ES

    opened by akunerio 0
  • Convert

    Convert "request" library usage to "got"

    The "request" library was deprecated. Converted usage to use the newer "got" library. Added async/await where applicable.

    closes #8

    opened by Christopher-Hayes 0
  • Any idea how OpenAI deems a base64 image as invalid?

    Any idea how OpenAI deems a base64 image as invalid?

    It seems that when you submit a variation request it uses the following JSON body: { task_type: "variations", prompt: { batch_size: 3, image: "BASE64IMAGESTRING_HERE" } }

    However, this yields a response that the image was invalid... Plugging the base64 data scraped from the official website into a base64 image decoder does yield the image, but plugging my own base64 in there yields an error... Any ideas as to why? Are they tagging the data somewhere in the base64?

    question 
    opened by AndrewCPU 1
  • Add support to add image to favorites

    Add support to add image to favorites

    The DALL·E UI allows you to mark an image as a "favorite", which just saves a reference to a collection. It would be nice to do this programatically.

    enhancement help wanted good first issue 
    opened by ezzcodeezzlife 0
Releases(release108)
  • release108(Oct 6, 2022)

    What's Changed

    • Add function to list previous runs by @Christopher-Hayes in https://github.com/ezzcodeezzlife/dalle-node/pull/7
    • Add getTask() function by @Christopher-Hayes in https://github.com/ezzcodeezzlife/dalle-node/pull/9
    • Convert "request" library usage to "got" by @Christopher-Hayes in https://github.com/ezzcodeezzlife/dalle-node/pull/10
    • Update README to document function usage by @Christopher-Hayes in https://github.com/ezzcodeezzlife/dalle-node/pull/11
    • :sparkles: Add getCredits() API by @Christopher-Hayes in https://github.com/ezzcodeezzlife/dalle-node/pull/12
    • Error handling + custom error class by @nickbclifford in https://github.com/ezzcodeezzlife/dalle-node/pull/18

    New Contributors

    • @Christopher-Hayes made their first contribution in https://github.com/ezzcodeezzlife/dalle-node/pull/7
    • @nickbclifford made their first contribution in https://github.com/ezzcodeezzlife/dalle-node/pull/18

    Full Changelog: https://github.com/ezzcodeezzlife/dalle-node/compare/release...release108

    Source code(tar.gz)
    Source code(zip)
  • release(Jul 12, 2022)

Owner
fabi.s
happy to contribute. pixel perfect code mode.
fabi.s
DALL-E 2 prompt helper browser extension

DALL-E prompt helper chrome extension Have you got access to the amazing DALL-E interface but struggling creating high quality renders? Looking for a

altryne 25 Sep 18, 2022
DALL-E 2 prompt helper browser extension

DALL-E prompt helper chrome extension Have you got access to the amazing DALL-E interface but struggling creating high quality renders? Looking for a

altryne 25 Sep 18, 2022
CLI Progress Bar implemented in NodeJS to track Time, ETA and Steps for any long running jobs in any loops in JS, NodeJS code

NodeJS-ProgressBar CLI Progress Bar for NodeJS and JavaScript to track Time, ETA and Steps for any long running jobs in any loops in JS, NodeJS code D

Atanu Sarkar 5 Nov 14, 2022
A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and configure Typescript on it.

CTSP- Create TS Project A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and conf

Jean Rodríguez 7 Sep 13, 2022
A quick and easy to use security reconnaissance webapp tool, does OSINT, analysis and red-teaming in both passive and active mode. Written in nodeJS and Electron.

ᵔᴥᵔ RedJoust A quick and easy to use security reconnaissance webapp tool, does OSINT, analysis and red-teaming in both passive and active mode. Writte

Dave 17 Oct 31, 2022
A NodeJS Replit API package wrapped around GraphQL, returning JSON data for easy use.

repl-api.js A NodeJS Replit API package wrapped around GraphQL, returning JSON data for easy use. Contents: About Quickstart Pre-installation Installa

kokonut 5 May 20, 2022
A devtool improve your pakage manager use experience no more care about what package manager is this repo use; one line, try all.

pi A devtool improve your pakage manager use experience no more care about what package manager is this repo use; one line, try all. Stargazers over t

tick 11 Nov 1, 2022
A NestJS module that allows you use Prisma, set up multiple Prisma services, and use multi-tenancy in each Prisma service.

NestJS Prisma Module Installation To use this package, first install it: npm i @sabinthedev/nestjs-prisma Basic Usage In order to use this package, yo

Sabin Adams 39 Dec 2, 2022
An users NodeJS API without packages libs or frameworks!

NodeJS Users API - Without Frameworks And Packages ?? Table of Contents About Getting Started Usage Built Using Authors ?? About Purpose of this proje

Nathan Cotrim Lemos 31 Feb 7, 2022
O objetivo dessa aplicação era criar um frontend feito totalmente em Javascript, sem nenhum arquivo HTML ou CSS pré-criado. Além disso, esse projeto também é o frontend da minha API 100% NodeJS.

Projeto HTML 100% Javascript Front-end feito "sem HTML" Conteúdos ➜ Sobre o projeto ➜ O que aprendi ➜ Como usar ?? Sobre o projeto Voltar ao topo O ob

João Victor Negreiros 19 Aug 3, 2021
A NodeJS Console Logger with superpowers

LogFlake LogFlake is a NodeJS console logger with superpowers. It has the same API as the usual Console but with beautified output, a message header w

Felippe Regazio 57 Oct 9, 2022
Role based authentication for NodeJS and ExpressJS

Role based authentication Authentication service made for ExpressJS and MongoDB using JWT. We tried to make it as clean and structured as possible. We

null 4 Oct 3, 2021
NodeJs, tron transaction checker

Tron node-Explorer Recommended requirements Node v14.17.5. npm 6.14.14 https://nodejs.org Development Install dependencies npm install Running applica

null 3 Aug 21, 2022
This is a full-stack exercise tracker web application built using the MERN (MongoDB, ExpressJS, ReactJS, NodeJS) stack. You can easily track your exercises with this Full-Stack Web Application.

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

WMouton 2 Dec 25, 2021
Este repositório contem o desafio do curso da rocketseat Ignite Conceitos do Nodejs

Projeto API TODO Nessa aplicação foi feita uma API, que é uma gerador de tarefas TODOS, onde o usúario pode cadastrar um name e um username, e a aplic

Macmiller Duarte de Andrade 1 May 12, 2022
This is a simple script to upload Multiple files into google drive using google drive API and Nodejs.

Welcome to gDrive Multiple File Upload ?? This is a simple script to upload Multiple files into google drive using google drive API and Nodejs Install

Jayamal Sanuka Hettiarachchi 1 Dec 29, 2021
RESTful API using Hapi NodeJs Framework. This app is project from Dicoding Couses, Belajar Membuat Aplikasi Back-end untuk Pemula

RESTful API using Hapi NodeJs Framework. This app is project from Dicoding Couses, Belajar Membuat Aplikasi Back-end untuk Pemula

Muhammad Ferdian Iqbal 1 Jan 3, 2022
🛠 Nodejs configuration the easy way.

@elite-libs/auto-config Intro A Unified Config & Arguments Library for Node.js! Featuring support for environment variables, command line arguments, a

null 4 May 17, 2022
NodeJS Implementation of Decision Tree using ID3 Algorithm

Decision Tree for Node.js This Node.js module implements a Decision Tree using the ID3 Algorithm Installation npm install decision-tree Usage Import

Ankit Kuwadekar 204 Dec 12, 2022