# Only if specifically required by your deployment
import requests

auth_url = "https://vedaya-kge.fly.dev/login"
auth_data = {
    "username": "YOUR_USERNAME",
    "password": "YOUR_PASSWORD",
    "grant_type": "password"
}

response = requests.post(auth_url, data=auth_data)
# Note: This endpoint may not be functional in current deployments
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "token_type": "Bearer",
  "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "expires_in": 3600
}

Complete Setup Example

Configure your API connection with environment variables for flexibility:
import os
import requests
from openai import OpenAI

# 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 with real token
TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqZWZmQGtub3dkZS5jb20iLCJleHAiOjE3NTY2MDUyNzAsInJvbGUiOiJ1c2VyIiwibWV0YWRhdGEiOnsiYXV0aF9tb2RlIjoiZW5hYmxlZCJ9fQ.3g97xmq8tNRRRSwfqScZog2D-hKt17Fr0AessIMDRx8"

# You can also set it directly
API_KEY = os.getenv("VEDAYA_API_KEY", TOKEN)
Most endpoints work without any authentication:
import requests
from openai import OpenAI

# Direct API calls - no auth needed
response = requests.post(
    f"{API_BASE_URL}/documents/texts",
    json={"texts": ["Your document content"]},
    headers=headers  # headers without auth if API_KEY is empty
)

# OpenAI SDK with dummy key
client = OpenAI(
    api_key="sk-dummy",  # Any dummy key works
    base_url=f"{API_BASE_URL}/v1"
)

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

OAuth2 Password Flow (Legacy/Optional)

The /login endpoint exists but is typically not required:
username
string
required
Your Vedaya username
password
string
required
Your Vedaya password
grant_type
string
required
Must be “password”
scope
string
OAuth scope (default: "")
client_id
string
OAuth client ID
client_secret
string
OAuth client secret
# Only if specifically required by your deployment
import requests

auth_url = "https://vedaya-kge.fly.dev/login"
auth_data = {
    "username": "YOUR_USERNAME",
    "password": "YOUR_PASSWORD",
    "grant_type": "password"
}

response = requests.post(auth_url, data=auth_data)
# Note: This endpoint may not be functional in current deployments
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "token_type": "Bearer",
  "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "expires_in": 3600
}

Request Body

FieldTypeRequiredDescription
usernamestringYesYour Vedaya username
passwordstringYesYour Vedaya password
grant_typestringYesMust be “password”
scopestringNoOAuth scope (default: "")
client_idstringNoOAuth client ID
client_secretstringNoOAuth client secret

Response

access_token
string
required
JWT access token to use in Authorization header
token_type
string
required
Token type (typically “Bearer”)
refresh_token
string
Refresh token for renewing access
expires_in
integer
Token expiration time in seconds

Using an Access Token (If Required)

If your specific deployment requires authentication:
# Optional: Add token to headers if you have one
headers = {"Content-Type": "application/json"}

# Only add auth if you have a real key
if API_KEY and API_KEY.strip() and API_KEY != "sk-mock-dummy-key":
    headers["Authorization"] = f"Bearer {API_KEY}"
    
# Full example with authentication
response = requests.post(
    f"{API_BASE_URL}/documents/texts",
    json={"texts": ["Your secure document"]},
    headers=headers
)

Authentication Status

Check if authentication is configured and get a guest token if not:
curl -X GET https://vedaya-kge.fly.dev/auth-status
{
  "authenticated": false,
  "auth_configured": false,
  "guest_token": "sk-guest-dummy"
}

Health Check

Check the API health status (requires authentication):
curl -X GET https://vedaya-kge.fly.dev/health \
  -H 'Authorization: Bearer YOUR_ACCESS_TOKEN'
{
  "status": "healthy"
}

Error Responses

Status CodeDescription
401Invalid credentials
422Validation error (missing required fields)
500Server error

Quick Test

import os
import requests
from openai import OpenAI

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

# 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}"

# 1. Upload text
requests.post(
    f"{API_BASE_URL}/documents/texts",
    json={"texts": ["Test document"]},
    headers=headers
)

# 2. Query with OpenAI SDK
client = OpenAI(
    api_key=API_KEY if API_KEY else "sk-dummy",
    base_url=f"{API_BASE_URL}/v1"
)
response = client.chat.completions.create(
    model="vedaya-hybrid",
    messages=[{"role": "user", "content": "What's in the documents?"}]
)
print(response.choices[0].message.content)