https://github.com/dillonstreator/dalle
openai dalle http client
https://github.com/dillonstreator/dalle
dalle dalle2 openai
Last synced: 4 months ago
JSON representation
openai dalle http client
- Host: GitHub
- URL: https://github.com/dillonstreator/dalle
- Owner: dillonstreator
- Created: 2022-08-25T14:18:40.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-03T02:04:53.000Z (almost 3 years ago)
- Last Synced: 2025-05-22T02:11:41.165Z (5 months ago)
- Topics: dalle, dalle2, openai
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Dalle
go client for [DALL*E](https://openai.com/dall-e-2/)
## Usage
This tool requires access to DALL*E. If you don't currently have access, sign up for the [DALL*E wait list](https://labs.openai.com/waitlist).
Find the Bearer Token
- Go to https://labs.openai.com/
- Open Network Tab in Developer Tools
- Type a prompt and press "Generate"
- Look for the xhr request to https://labs.openai.com/api/labs/tasks
- In the request header, look for `Authorization` then get the Bearer Token which will act as the api key> Note: Do not include "Bearer " in the api key
### Using the api key
```go
// create the client with the bearer token api key
dalleClient, err := dalle.NewHTTPClient("your-api-key-here")
// handle err// generate a task to create an image with a prompt
task, err := dalleClient.Generate(ctx, "neon sports car driving into sunset, synthwave, cyberpunk")
// handle err// poll the task.ID until status is succeeded
var t *dalle.Task
for {
time.Sleep(time.Second * 3)t, err = dalleClient.GetTask(ctx, task.ID)
// handle errif t.Status == dalle.StatusSucceeded {
fmt.Println("task succeeded")
break
} else if t.Status == dalle.StatusRejected {
log.Fatal("rejected: ", t.ID)
}fmt.Println("task still pending")
}// download the first generated image
reader, err := dalleClient.Download(ctx, t.Generations.Data[0].ID)
// handle err and close readCloser
```## Examples
- [Generating, polling, and downloading a single image](./cmd/example/main.go)
- [Downloading all generated images from first 50 tasks](./cmd/downloadall/main.go)