Skip to content

Quickstart

Get up and running with the PixAI API

The PixAI API are most easily accessed via the GraphQL endpoint. You can use any GraphQL client to interact with the API. Or even use it as a simple HTTP endpoint.

But the most easily way to get started is to use our SDK.

We provide SDKs for the following languages:

You can follow the instructions in the respective repositories to get started.

Most SDKs provide relatively complete encapsulation for calling our main interfaces.

Setting up the client

Here is an example using the JavaScript language:

You just need to pass your API key to the client. And this all you need to get started.

import PixAIClient from 'pixai-client-js'
const client = new PixAIClient({
apiKey: 'YOUR_API_KEY',
})

Start to generate images

After setting up the client, you can start to generate images. Here is an example of generating an image with text-to-image.

const task = await client.generateImage(
{
prompts: '1girl',
modelId: '1648918127446573124',
width: 512,
height: 512,
},
)
console.log('Task completed: ', task)

Get the result

In the task object, there will be a lot of information. If you just want to get the generated image, you can refer to the following code.

const media = await client.getMediaFromTask(task)

Download the image

In the JavaScript SDK. The obtained media may contain one or more images, depending on the batch in the parameters. If you only generated one image. You can assert that there is only one media.

Afterwards, you can use the built-in method to directly download the image without concerning about the content of the media object.

assert(media && !Array.isArray(media))
const buffer = await client.downloadMedia(media)
await fs.writeFile('output.png', Buffer.from(buffer))

Next steps

The above is the fastest way to start using the API. If you want to know more information or more usage, you can refer to the documentation of our SDK and other documents on this site.