Skip to content

Example Code

Sign Up

Sign Up

This example shows how the signup API is used to register with Pavillion.
Integrate this with your sign up flow or page.

import os

import requests
import json

CLIENT_ID = os.environ['PAVILLION_CLIENT_ID']

payload = json.dumps({
    "email": "user@example.com",
    "password": "ABCabc#$#$%123",
    "clientId": CLIENT_ID,
})
res = requests.post(
    url="https://www.pavillion.ai/api/signup",
    data=payload
)
if (res.status_code != 201) {
    # implement error handling logic
}
const clientId = process.env.PAVILLION_CLIENT_ID

const payload = JSON.stringify({
    email: "user@example.com",
    password: "ABCabc#$#$%123",
    clientId,
});
const res = await fetch("https://www.pavillion.ai/api/signup", {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: payload
})
if (res.status !== 201) {
    // implement error handling logic
}
Login

Login

This example shows how to log user in with Pavillion API.
Integrate this in your login flow or page.

import os

import requests
import json

CLIENT_ID = os.environ['PAVILLION_CLIENT_ID']

payload = json.dumps({
    "email": "user@example.com",
    "password": "ABCabc#$#$%123",
    "clientId": CLIENT_ID,
})
res = requests.post(
    url="https://www.pavillion.ai/api/login",
    data=payload
)
if (res.status_code != 200) {
    # implement error handling logic
}
user_info = res.json()
# token, id and email fields are available from the response
# use the token to send subsequent requests
jwt_token = user_info['token']
user_id = user_info['id']
user_email = user_info['email']
const clientId = process.env.PAVILLION_CLIENT_ID

const payload = JSON.stringify({
    email: "user@example.com",
    password: "ABCabc#$#$%123",
    clientId,
});
const res = await fetch("https://www.pavillion.ai/api/login", {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: payload
})
if (res.status !== 200) {
    // implement error handling logic
}
// token, id and email fields are available from the response
// use the token to send subsequent requests
const { id, token, email } = await res.json()
Charge

Charge

This example shows how to charge user's wallet using the Pavillion API.
Integrate this to where you serve the user's request or query.

import os

import requests
import json

CLIENT_ID = os.environ['PAVILLION_CLIENT_ID']

payload = json.dumps({
    "message": {"input": "Hello!", "output": "Hi, how can I help you today?"},
    "clientId": CLIENT_ID,
    "chargeCents": 100,
})
res = requests.post(
    url=f"https://www.pavillion.ai/api/{CLIENT_ID}/charge",
    data=payload,
    headers={"Authorization": f"Bearer {JWT_TOKEN_FROM_LOGIN}"}
)
if (res.status_code != 200) {
    # implement error handling logic
}
const clientId = process.env.PAVILLION_CLIENT_ID

const payload = JSON.stringify({
    message: {"input": "Hello!", "output": "Hi, how can I help you today?"},
    clientId,
    chargeCents: 100,
});
const res = await fetch(`https://www.pavillion.ai/api/${clientId}/charge`, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        Authorization: `Bearer ${JWT_TOKEN_FROM_LOGIN}`
    },
    body: payload
})
if (res.status !== 200) {
    // implement error handling logic
}