Quick Setup

The Vedaya API supports optional authentication. You can use the API without authentication for testing, or add authentication for production use.

Complete Setup Example

import os
import requests
import json

# Configure API (prefer environment variables)
API_BASE_URL = os.getenv("VEDAYA_API_BASE_URL", "https://vedaya-kge.fly.dev")  # no trailing slash
API_KEY = os.getenv("VEDAYA_API_KEY", "")  # leave empty if no auth

# Build headers
headers = {"Content-Type": "application/json"}
if API_KEY and API_KEY.strip() and API_KEY != "sk-mock-dummy-key":
    headers["Authorization"] = f"Bearer {API_KEY}"

print(f"Connecting to: {API_BASE_URL}")
print(f"Auth header set: {'Authorization' in headers}")

# Example: Upload documents
response = requests.post(
    f"{API_BASE_URL}/documents/texts",
    headers=headers,
    json={"texts": ["Your document content"]}
)

Authentication Methods

1. No Authentication (Simplest)

Works for testing and development:
import requests

# Works without any authentication
response = requests.post(
    "https://vedaya-kge.fly.dev/documents/texts",
    headers={"Content-Type": "application/json"},
    json={"texts": ["Your document content"]}
)

2. Bearer Token Authentication

For production deployments with authentication enabled:
import os
import requests

# Set your token as an environment variable
TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."  # Your actual token

# Configure with environment variables
API_BASE_URL = os.getenv("VEDAYA_API_BASE_URL", "https://vedaya-kge.fly.dev")
API_KEY = os.getenv("VEDAYA_API_KEY", TOKEN)

# Build headers with authentication
headers = {"Content-Type": "application/json"}
if API_KEY and API_KEY.strip():
    headers["Authorization"] = f"Bearer {API_KEY}"

# Make authenticated requests
response = requests.post(
    f"{API_BASE_URL}/documents/texts",
    headers=headers,
    json={"texts": ["Your content"]}
)

3. OpenAI SDK Compatibility

When using the OpenAI SDK, you can use dummy keys:
from openai import OpenAI

# Use any dummy key for OpenAI SDK compatibility
client = OpenAI(
    api_key="sk-dummy",  # Any dummy key works
    base_url="https://vedaya-kge.fly.dev/v1"
)

response = client.chat.completions.create(
    model="vedaya-hybrid",
    messages=[{"role": "user", "content": "Your question"}]
)

Working Example Without Auth

import requests
from openai import OpenAI
import time

# 1. Upload documents (no auth needed)
response = requests.post(
    "https://vedaya-kge.fly.dev/documents/texts",
    json={"texts": ["Test document about AI"]}
)
print("Upload status:", response.status_code)

# 2. Wait for processing
time.sleep(5)

# 3. Query with OpenAI SDK (dummy key)
client = OpenAI(
    api_key="sk-dummy",
    base_url="https://vedaya-kge.fly.dev/v1"
)

response = client.chat.completions.create(
    model="vedaya-hybrid",
    messages=[{"role": "user", "content": "What's in the documents?"}]
)
print(response.choices[0].message.content)

OAuth2 Login (Legacy/Optional)

The /login endpoint exists but is not required:
# Only if specifically required by your deployment
url = "https://vedaya-kge.fly.dev/login"
data = {
    "username": "your_username",
    "password": "your_password",
    "grant_type": "password"
}
response = requests.post(url, data=data)
# This endpoint may not be functional in current deployments

Fly.io Deployment Authentication Setup

Since the API has no signup endpoint, you need to seed a user via Fly secrets and restart the app. This sets up authentication for protected endpoints.

1. Set Secrets for User

Pick a strong password (watch out for ! in zsh; single-quote it).
EMAIL='your_username'
PASSWORD='your_password'

# Set both common variants so you're covered
fly secrets set \
  AUTH_USERNAME="$EMAIL" AUTH_PASSWORD="$PASSWORD" \
  VEDAYA_ADMIN_EMAIL="$EMAIL" VEDAYA_ADMIN_PASSWORD="$PASSWORD" \
  -a vedaya-kg
If your shell yells about !, either escape it (SuperStrong\!Pass123) or keep the single quotes as shown.

2. (Optional) Set an API Key

Handy for service-to-service calls. The OpenAPI shows an api_key_header_value query param on most endpoints.
fly secrets set VEDAYA_API_KEY='vedaya_live_$(uuidgen | tr -d -)' -a vedaya-kg

3. Restart the App

Apply the secrets by restarting:
fly apps restart vedaya-kg

4. Log In to Get a Token

# Safest: url-encode fields
curl -s 'https://vedaya-kge.fly.dev/login' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'grant_type=password' \
  --data-urlencode "username=$EMAIL" \
  --data-urlencode "password=$PASSWORD"
You should get JSON like:
{"access_token":"<TOKEN>","token_type":"bearer"}

5. Use the Token on Protected Endpoints

TOKEN='<paste token here>'
curl -s 'https://vedaya-kge.fly.dev/documents' -H "Authorization: Bearer $TOKEN"

Quick Checks if Authentication Doesn’t Work

  • Print auth status:
    curl -s https://vedaya-kge.fly.dev/auth-status | python - <<'PY'
    import sys, json; print(json.dumps(json.load(sys.stdin), indent=2))
    PY
    
  • Watch logs during login:
    fly logs -a vedaya-kg | egrep -i 'auth|login|user'
    

Best Practices

  • For testing: Use no authentication or dummy keys
  • For production: Check with your deployment admin if auth is required
  • For OpenAI SDK: Always use dummy keys like “sk-dummy”
  • For direct HTTP: Omit Authorization header unless you have a real key