Quickstart
Let's make your first API call to access AI functionalities using the service from PiAPI!
Generate an API key
:::highlight yellow 💡
What is API key?
An API key is a secure credential that allows your code to interact with our API. Never share your API key with anyone, as it can be exploited without your knowledge.
:::
- Create an account : Go to PiAPI workspace and log in with your github account.
- Create an API key: After logged in, navigate to the API key in workspace and generate one.
Set Base URL
This is the URL to be used for all of our API calls:
:::highlight blue
https://api.piapi.ai
:::Make your first API call
Let's take Flux API for an example. - Set URL endpoint: With our Unified API Schema, users could interact with all models and services through just two endpoints:
create task
andget task
.
Here we want to create a Fluxtext-to-image
task, so the endpoint should be:
:::highlight yellow
https://api.piapi.ai/api/v1/task
::: - Set the header: In most cases, you will need an API key for authorization. Remember to replace the
YOUR_API_KEY
with your own API key. The headers look like this:headers = { 'x-api-key': 'YOUR_API_KEY', }
- Set the request Body: APIs of Unified API schema share the same request and response format. you will need to specify three main components:
model
: The specific model you wish to interact with. Here we set toQubico/flux1-schnell
.task_type
: The type of task. Here we set totxt2img
.input
: The inputs specific to the task and model.prompt
is required, Let's set to "a bear" for example.
:::tip{ "model": "flux1-schnell", "task_type": "txt2img", "input": { "prompt": "a bear", } }
For the introduction of params needed in request body, refer to the documentation of specific endpoint you want to interact with.
You can check Flux Text to Image endpoint doc about the params above.
:::
Send the request:
import requests import json url = "https://api.piapi.ai/ api/v1/task" payload = json.dumps({ "model": "Qubico/flux1-dev", "task_type": "txt2img", "input": { "prompt": "a bear", } }) headers = { 'X-API-Key': 'Your API key', 'Content-Type': 'application/json' } response = requests.request("POST", url, headers=headers, data=payload) print(response.text)
And you will get a response in unified response schema. Now you have made your first API call. Happy intergrating!
What's next
As you can see in the example, our APIs of unified schema are really easy to understand and use. Now you can explore more models using PiAPI.
:::highlight orange 🚀
About Webhook:
For simplicity, we did't use the webhook service in the example above , which ensures timely updates and notifications. It is really useful and welcome to check the documentation about webhook here.
:::