1. Get your API key
Create one from the API Keys section of the console and copy it. You will not see it again. Then set it as an environment variable:export LIGHTON_API_KEY=your_api_key_here
2. Upload a document
from lighton import File, LightOn, Workspace
workspace_id = 42 # replace with your workspace ID
with LightOn() as client: # reads LIGHTON_API_KEY from the environment
workspace = Workspace.get(client, workspace_id)
doc = workspace.ingest(File(path="handbook.pdf"))
print(doc.id, doc.status)
import { File, LightOn, Workspace } from "@lighton-ai/sdk"
const workspaceId = 42 // replace with your workspace ID
const client = new LightOn() // reads LIGHTON_API_KEY from the environment
const workspace = await Workspace.get(client, workspaceId)
const doc = await workspace.ingest(new File({ path: "handbook.pdf" }))
console.log(doc.id, doc.status)
import os
import requests
workspace_id = 42 # replace with your workspace ID
headers = {"Authorization": f"Bearer {os.environ['LIGHTON_API_KEY']}"}
with open("handbook.pdf", "rb") as f:
response = requests.post(
"https://api.lighton.ai/api/v3/files",
headers=headers,
data={"workspace_id": workspace_id},
files={"file": f},
)
print(response.json())
id and a status of pending:
{"id": 12345, "status": "pending", "workspace_id": 42}
status is embedded:
from lighton import File, LightOn
file_id = 1234 # the ID returned by the upload above
with LightOn() as client:
doc = File.get(client, file_id)
doc.wait() # polls until ingestion reaches a terminal status
print(doc.status)
import { File, LightOn } from "@lighton-ai/sdk"
const fileId = 1234 // the ID returned by the upload above
const client = new LightOn()
const doc = await File.get(client, fileId)
await doc.wait() // polls until ingestion reaches a terminal status
console.log(doc.status)
import os
import time
import requests
file_id = 1234 # the ID returned by the upload above
headers = {"Authorization": f"Bearer {os.environ['LIGHTON_API_KEY']}"}
for _ in range(60): # give up after ~2 minutes
response = requests.get(
f"https://api.lighton.ai/api/v3/files/{file_id}",
headers=headers,
)
status = response.json()["status"]
if status == "embedded":
break
time.sleep(2)
print(status)
3. Search it
from lighton import LightOn
workspace_id = 42 # replace with your workspace ID
with LightOn() as client:
response = client.search(
"What is the vacation policy at LightOn?",
workspaces=[workspace_id],
max_results=3,
)
for result in response.results:
source = result.source
print(f"[p.{source.page_start}–{source.page_end}, score={result.score:.2f}]")
print(result.content[:120])
print()
import { LightOn } from "@lighton-ai/sdk"
const workspaceId = 42 // replace with your workspace ID
const client = new LightOn()
const response = await client.search("What is the vacation policy at LightOn?", {
workspaces: [workspaceId],
maxResults: 3,
})
for (const result of response.results) {
const source = result.source
console.log(`[p.${source.pageStart}–${source.pageEnd}, score=${result.score.toFixed(2)}]`)
console.log((result.content ?? "").slice(0, 120))
console.log()
}
import os
import requests
workspace_id = 42 # replace with your workspace ID
headers = {"Authorization": f"Bearer {os.environ['LIGHTON_API_KEY']}"}
response = requests.post(
"https://api.lighton.ai/api/v3/search",
headers=headers,
json={
"query": "What is the vacation policy at LightOn?",
"workspace_id": [workspace_id],
"max_results": 3,
},
)
for result in response.json()["results"]:
print(f"[p.{result['source']['page_start']}–{result['source']['page_end']}, score={result['score']:.2f}]")
print(result["content"][:120])
print()
[p.4–4, score=0.94]
Employees are entitled to 25 days of paid leave per year...
[p.4–4, score=0.87]
Unused vacation days carry over up to a maximum of 10 days...
[p.7–7, score=0.71]
Public holidays are in addition to the annual leave entitlement...
Next: Authentication
Learn how API keys work and how to handle auth errors.