Dashboard
Welcome back
Cost - This Period
Input Tokens - This Period
Output Tokens - This Period
Anomalys found - This Period
Usage Statistics
Graphs the number of calls in this period
Welcome back
**SaaSpec is currently compatible with only OpenAI models
SaaSpec is a powerful API analytics and monitoring tool designed to help developers manage and optimize their usage of pay-as-you-go APIs. By integrating SaaSpec into your application, you can track key metrics, detect anomalies, and implement dynamic billing models based on actual usage. SaaSpec is currently able to be utilized with the OpenAI models only.
Watch the following video to learn how to use the dashboard:
import requests
api_url = 'https://us-central1-saaspect-424004.cloudfunctions.net/api_call/call'
# Define the payload with 5 variables
payload = {
"Who": "*insert UID here",
"api_token": "your SaaSpec project API token here",
"input": "question",
"output": "response from model here",
"what_api": "gpt-4..etc",
}
# Send the POST request to the API
response = requests.post(api_url, json=payload)
**SaaSpec is currently compatible with only OpenAI models
import requests
from openai import OpenAI
# Define SaaSpec API endpoint
api_url = 'https://us-central1-saaspect-424004.cloudfunctions.net/api_call/call'
client = OpenAI(api_key="your-openai-api-key")
question = "Rephrase this text..."
completion = client.chat.completions.create(
model="gpt-4",
messages=[
{"role": "system", "content": "You are a school teacher, skilled in explaining concepts and editing school work."},
{"role": "user", "content": question}
]
)
# Define the payload with 5 variables
payload = {
"Who": "*insert UID here",
"api_token": "your SaaSpec project API token here",
"input": question,
"output": completion.choices[0].message.content,
"what_api": completion.model,
}
# Send the POST request to the API
response = requests.post(api_url, json=payload)
# Check the response
if response.status_code == 200:
print("Success:", response.json())
else:
print("Failed:", response.status_code, response.text)
import csv
import stripe
# Stripe secret key
stripe.api_key = 'your_secret_key_here'
def read_csv(file_path):
users = []
with open(file_path, mode='r', newline='') as file:
csv_reader = csv.DictReader(file)
for row in csv_reader:
users.append({
'user': row['USER'],
'token_cost': float(row['TOKEN COST'].replace('$', '').strip()),
'input_count': int(row['INPUT COUNT']),
'output_count': int(row['OUTPUT COUNT']),
'anomaly': row['ANOMALY']
})
return users
def create_invoice(user, token_cost):
# Find or create a customer
customers = stripe.Customer.list(email=user)
if customers['data']:
customer_id = customers['data'][0]['id']
else:
customer = stripe.Customer.create(email=user)
customer_id = customer.id
# Create an invoice item
stripe.InvoiceItem.create(
customer=customer_id,
amount=int(token_cost * 100), # Stripe amount is in cents
currency='usd',
description=f'Token usage for {user}'
)
# Create and send the invoice
invoice = stripe.Invoice.create(
customer=customer_id,
auto_advance=True # Auto-finalize this draft after ~1 hour
)
invoice.send_invoice()
# Read CSV and create invoices
csv_file_path = '/mnt/data/users_data.csv' # replace with your actual CSV file path
users_data = read_csv(csv_file_path)
for user_data in users_data:
create_invoice(user_data['user'], user_data['token_cost'])
stoplookingatmycode@gmail.com
Here you can change the password to your account.
If you would like to cancel your subscription please email saaspecapi@gmail.com
Success! Your changes have been saved.