Skip to main content

E-03 Tokenization Service

Brick E: Data, RAG, context, memory. French version: E-03-tokenization-service

1. Role and responsibilities​

Reversible pseudonymization: replaces a sensitive value with a stable token, reversible only by an authorized principal.

  • Tokenize (deterministic per tenant)
  • Detokenize under policy and audit
  • Vault encryption key in OpenBao

2. Position in the architecture and interactions​

  • Callers: DLP Gateway, business applications.
  • Execution path: Synchronous.
  • Every interaction goes through the Control Plane API v1 (/v1) behind the API Gateway (D-14).

3. Open source component and developed part​

  • Open source: OpenBao (transit)
  • Developed: Token vault, detokenization policy.
  • External integration through an adapter eai/integrations/<system>.py with an in-process fallback when the URL is not configured.

4. Data model​

Tables (schema eai, tenant_id RLS):

  • eai.token_vault

Common columns: id uuid, tenant_id uuid NOT NULL, created_at, updated_at; RLS policy current_setting('app.tenant_id', true)::uuid.

5. Contract​

  • Applied contract: policy-contract
  • JSON Schema: contracts/v1/policy-contract.schema.json
  • Key fields: action=detokenize, purpose
  • Validation: POST /v1/contracts/{name}/validate; manifest apply: POST /v1/manifests/apply.

6. API endpoints​

  • POST /v1/tokenization/tokenize
  • POST /v1/tokenization/detokenize

Request POST /v1/tokenization/tokenize:

{
"values": [
"FR7630006000011234567890189"
],
"type": "IBAN"
}

Response:

{
"tokens": [
"tok_iban_8f3a1c"
]
}

7. SDK examples​

Python:

from enterprise_ai import EnterpriseAI

client = EnterpriseAI(base_url="<control-plane-url>", api_key="eai_xxx_secret")
t = client.tokenization.tokenize(values=[{"type": "IBAN", "value": "FR76..."}])
v = client.tokenization.detokenize(tokens=t.tokens, purpose="remboursement")

TypeScript:

import { EnterpriseAI } from "@enterprise-ai/sdk";

const client = new EnterpriseAI({ baseUrl: "<control-plane-url>", apiKey: process.env.EAI_API_KEY });
const t = await client.tokenization.tokenize({ values: ["FR76..."] });

Java:

EnterpriseAIClient client = EnterpriseAIClient.builder()
.baseUrl("<control-plane-url>")
.apiKey(System.getenv("EAI_API_KEY"))
.build();
Tokens t = client.tokenization().tokenize(List.of("FR76..."), "IBAN");

Go:

c, _ := eai.NewClient(eai.WithBaseURL("<control-plane-url>"), eai.WithAPIKey(os.Getenv("EAI_API_KEY")))
t, _ := c.Tokenization.Tokenize(ctx, []string{"FR76..."}, "IBAN")

8. Configuration​

  • Environment variables: EAI_OPENBAO_URL, EAI_OPENBAO_TRANSIT_MOUNT, EAI_DATABASE_URL
  • Helm values keys: global.openbao

9. Security controls​

  • Detokenization: role + purpose + OPA policy, never for the agent role by default
  • Every request carries the tenant resolved from the credential; PostgreSQL RLS
  • Every mutation and policy decision writes a hash-chained audit event

10. Observability​

  • Prometheus metrics: eai_tokenize_total, eai_detokenize_total{decision}
  • Traces: OpenTelemetry spans with GenAI semantic conventions (gen_ai.operation.name, gen_ai.agent.id, gen_ai.tool.name), attributes eai.tenant_id, eai.run_id, traceparent propagation.
  • Audit actions: tokenization.tokenize, tokenization.detokenize

11. FinOps units​

  • Tokenization operations.
  • Emitted as Usage Event (POST /v1/finops/usage) with tenant, project, agent and run.

12. Failure modes and resilience​

  • Deterministic token: retry without duplicate
  • Normalized errors (error envelope, message_i18n en/fr)

13. Standalone adoption (client of a client)​

  • enterprise_ai.dlp + OpenBao.
  • SDK: enterprise_ai.privacy / dlp / knowledge_bases / memory / retention / lineage
  • Minimal deployment: Helm chart with controlPlane.enabled=true and PostgreSQL; disabled external components use their in-process fallback.

14. Acceptance tests​

  1. Same value -> same token
  2. Detokenization by agent -> 403
  3. Cross-tenant access refused
  4. Error returned in fr with Accept-Language: fr

Governed RAG (kit L4)​

The RAG sensitive cache never holds a clear value: every entry is Tink encrypted and bound to its tenant key.