Search by

seletech / sele

seletech-ai

PHP client for SeleID sign-in (PKCE), SeleStorage, SeleBase, events and SeleAI.

0.1.0 2026-11-13 15:02 UTC

This package is auto-updated.

Last update: 2026-11-13 15:24:38 UTC


README

Licensed under Apache-2.0. See release notes.

PHP 8.1+ client for Continue with SeleID (OIDC + PKCE), SeleStorage, SeleBase, events (webhooks, mail, push) and SeleAI. No dependencies beyond the standard extensions.

Install

Requires PHP 8.1 or newer.

composer require seletech/sele

Sign in with SeleID (PKCE)

use SeleTech\{Pkce, SeleIdAuth};

$auth = new SeleIdAuth('YOUR_CLIENT_ID'); // public client: no secret
$pkce = Pkce::create();
$a = Pkce::authorizeUrl('YOUR_CLIENT_ID', 'https://app.example.com/callback', $pkce['codeChallenge']);
// store $pkce['codeVerifier'], $a['state'], $a['nonce'] in the session, then header('Location: ' . $a['url']);

// on the callback, after checking state:
$tokens = $auth->exchangeCode($_GET['code'], 'https://app.example.com/callback', $verifier);
$user = $auth->userInfo($tokens['access_token']);

Storage, SQL, events, AI

use SeleTech\{SeleStorage, SeleDb, SeleEvents, SeleAi, SeleError};

$storage = new SeleStorage(getenv('SELESTORAGE_KEY'));
$storage->put('reports/q3.txt', 'hello', 'text/plain');
echo $storage->get('reports/q3.txt');

$db = new SeleDb(getenv('SELEBASE_KEY'));
$db->createDatabase('app');
$db->query('app', 'INSERT INTO notes (title) VALUES (?)', ['Hello']); // always use params

$events = new SeleEvents(getenv('SELE_KEY'));
$endpoint = $events->createWebhookEndpoint('https://app.example.com/hooks/sele', ['order.created']); // secret shown once
$ok = SeleEvents::verifyWebhook($endpoint['secret'], file_get_contents('php://input'), $_SERVER['HTTP_SELEID_SIGNATURE'] ?? null);

try {
    $r = (new SeleAi(getenv('SELEAI_KEY')))->chat('MODEL_ID', [['role' => 'user', 'content' => 'Say hello']], 64);
    echo $r['message']['content'];
} catch (SeleError $e) {
    if ($e->errorCode === 'spend_cap_reached') { echo 'Cap reached'; }
}

Every non-2xx response throws SeleError (status, errorCode, getMessage(), requestId).

API reference: https://seleid.dev/docs/api