Skip to main content

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
See Authentication for more on key management.

2. Upload a document

import requests, time

headers = {"Authorization": "Bearer $LIGHTON_API_KEY"}

response = requests.post(
    "https://api.lighton.ai/api/v3/files",
    headers=headers,
    data={"workspace_id": 42},
    files={"file": open("handbook.pdf", "rb")},
)
file = response.json()
print(f"Uploaded: {file['id']}, status: {file['status']}")
# → Uploaded: 12345, status: pending
Indexing takes a few seconds. Poll until status is embedded:
file_id = file["id"]
while True:
    r = requests.get(f"https://api.lighton.ai/api/v3/files/{file_id}", headers=headers)
    if r.json()["status"] == "embedded":
        break
    time.sleep(2)

3. Search it

response = requests.post(
    "https://api.lighton.ai/api/v3/search",
    headers=headers,
    json={
        "query": "What is the vacation policy at LightOn?",
        "workspace_id": [42],
        "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...
Three API calls: upload, wait, search. That’s the full pipeline.

Next: Authentication

Learn how API keys work and how to handle auth errors.