Quickstart
Get started with the Optropic Trust API in under 5 minutes. This guide walks you through installation, authentication, and your first asset creation and verification.
Installationโ
- TypeScript
- Python
npm install optropic
pip install optropic
Initialize the Clientโ
- TypeScript
- Python
import { OptropicClient } from 'optropic';
const client = new OptropicClient({
apiKey: 'optr_live_your_api_key_here',
});
from optropic import Optropic
client = Optropic(api_key="optr_live_your_api_key_here")
Sandbox Mode
Use optr_test_* keys for sandbox mode โ they auto-detect and route to the test environment. No configuration needed.
Create Your First Assetโ
- TypeScript
- Python
const asset = await client.assets.create({
externalId: 'product-001',
vertical: 'pharmaceuticals',
securityLevel: 'signed',
metadata: {
product: 'Aspirin 500mg',
batch: 'B2026-0329',
},
});
console.log(`Asset created: ${asset.id}`);
console.log(`Serial: ${asset.serial}`);
asset = client.assets.create(
external_id="product-001",
vertical="pharmaceuticals",
security_level="signed",
metadata={
"product": "Aspirin 500mg",
"batch": "B2026-0329",
},
)
print(f"Asset created: {asset['id']}")
print(f"Serial: {asset['serial']}")
Verify an Assetโ
- TypeScript
- Python
const result = await client.assets.verify(asset.serial);
if (result.valid) {
console.log('โ Authentic product');
console.log(`Signed by keyset: ${result.keysetId}`);
} else {
console.log('โ Verification failed:', result.reason);
}
result = client.assets.verify(asset["serial"])
if result["valid"]:
print("โ Authentic product")
print(f"Signed by keyset: {result['keyset_id']}")
else:
print(f"โ Verification failed: {result['reason']}")
Track Provenanceโ
Record the product's journey through the supply chain:
- TypeScript
- Python
// Record manufacturing event
await client.provenance.record({
assetId: asset.id,
eventType: 'manufactured',
actor: 'factory-line-7',
location: { country: 'DE', facility: 'Munich Plant' },
});
// Ship the product
await client.provenance.record({
assetId: asset.id,
eventType: 'shipped',
actor: 'logistics-team',
location: { country: 'DE', facility: 'Munich Warehouse' },
});
// Get the full provenance chain
const chain = await client.provenance.getChain(asset.id);
console.log(`${chain.eventCount} events in chain`);
console.log(`Chain valid: ${chain.chainValid}`);
# Record manufacturing event
client.provenance.record(RecordProvenanceParams(
asset_id=asset["id"],
event_type="manufactured",
actor="factory-line-7",
location={"country": "DE", "facility": "Munich Plant"},
))
# Ship the product
client.provenance.record(RecordProvenanceParams(
asset_id=asset["id"],
event_type="shipped",
actor="logistics-team",
location={"country": "DE", "facility": "Munich Warehouse"},
))
# Get the full provenance chain
chain = client.provenance.get_chain(asset["id"])
print(f"{chain['event_count']} events in chain")
print(f"Chain valid: {chain['chain_valid']}")
What's Next?โ
- Authentication โ API key management, permissions, and scoping
- Digital Product Passport โ EU DPP compliance for battery, textile, and electronics products
- Offline Verification โ Verify assets without network access
- EPCIS 2.0 Integration โ Interoperability with SAP, Oracle, and GS1 systems