dmlab / module-typesafe-core
TypeSafe (Jev) AI client for Magento 2: shared connection with your own encrypted API key, response cache, monthly token budget, retries and rate limiting.
Package info
github.com/dmlab-work/module-typesafe-core
Type:magento2-module
pkg:composer/dmlab/module-typesafe-core
Requires
- php: ~8.3.0||~8.4.0||~8.5.0
- ext-curl: *
- magento/framework: ^103.0.9
- magento/module-backend: ^102.0.9
- magento/module-config: ^101.2.9
- psr/log: ^2.0||^3.0
- symfony/console: ^6.4||^7.0
Requires (Dev)
- phpunit/phpunit: ^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
TypeSafe (Jev) AI client for Magento 2 — one connection, cache and token budget shared by every DMLab AI module.
TypeSafe answers structured questions about text — yes/no, pick one of N options, score on a scale — with calibrated probabilities instead of free-form output, at $0.042 per 1M input tokens. This module connects Magento to it. You usually get it as a dependency of a module that uses it, such as Catalog Enrich (fills empty product attributes from descriptions); on its own it adds no storefront or catalog behaviour.
What you get
- Your own key — register at console.typesafe.ai and pay TypeSafe directly. The key is stored encrypted in Magento; we never see it.
- Settings in one place — enable, API key, pinned model version (
jev-1.13.0), Test Connection. - Spend control — a monthly token budget with this month's usage and cost shown under the field; a response cache so the same question is never paid for twice.
- Resilience — parallel requests, retries with backoff, rate-limit pauses and a circuit breaker, so an API hiccup never floods the API or your logs.
Install
composer require dmlab/module-typesafe-core bin/magento setup:upgrade
Magento 2.4.9+, PHP 8.3–8.5 with ext-curl. Then Stores → Configuration → DMLab → TypeSafe: enable, paste the
key, Test Connection.
bin/magento dmlab:typesafe:ping # check the connection bin/magento dmlab:typesafe:usage [--month=YYYY-MM] # requests, cache hits, tokens and cost per module
For developers
$response = $client->evaluate(new Request( // DmLab\TypeSafeCore\Api\ClientInterface ['title' => 'Merino wool crew sweater', 'description' => '…'], [ 'is_apparel' => new NoulQuestion('Is this product clothing?'), 'material' => new ChoiceQuestion('Main material', ['wool' => null, 'cotton' => null, 'synthetic' => null]), ], 'my_module' // usage is accounted per consumer )); $response->getAnswer('is_apparel')->getProbability(); // 0..1 $response->getAnswer('material')->getChoice(); // 'wool', with getConfidence()
evaluateMany() sends a batch in parallel and returns a Response or a TypeSafeException per key; it never
throws. Use Api\ConfigInterface::isConfigured() / getModel() instead of your own settings, and
Api\UsageInterface for the remaining budget.
Data and privacy
Only the text a consuming module puts into a request is sent to TypeSafe (US-hosted API). Request and response content is never logged. Zero data retention is available on TypeSafe's enterprise plan.
