Token API
GET https://llmfoundry.straive.com/token
returns the LLMFoundry token for the user. This can be used to authenticate with the API. For example:
const token = await fetch("https://llmfoundry.straive.com/token", { credentials: "include" }).then((r) => r.json());
If the user is not logged in as a valid user, this returns an empty object. Otherwise, it returns:
{
"email": "user.name@straive.com",
"token": "..."
}
To redirect the user to the login page, use https://llmfoundry.straive.com/login?next=https://your-site.com/
Token Expiry
You can set token expiry in two ways:
expires_at
: Set an absolute expiry timestamp
const token = await fetch("https://llmfoundry.straive.com/token?expires_at=2024-12-31", { credentials: "include" }).then((r) => r.json());
expires_in
: Set a relative expiry in seconds from now
const token = await fetch("https://llmfoundry.straive.com/token?expires_in=3600", { credentials: "include" }).then((r) => r.json());
Token with app name
You can also set an app name to track usage. This is useful to track usage of temporary tokens.
const token = await fetch("https://llmfoundry.straive.com/token?expires_in=3600&app=my-app", { credentials: "include" }).then((r) => r.json());
When you visit the usage page, you can see usage by app.
Python requests
import os
import requests
response = requests.get(
"https://llmfoundry.straive.com/token?expires_in=3600&app=my-app",
headers={"Authorization": f"Bearer {os.environ['LLMFOUNDRY_TOKEN']}"},
)
token = response.json()
Tutorial
See the Single Page LLM Apps Workshop for a step-by-step tutorial.