Skip to main content
Softlimes Home
Softlimes
← Back to all articles•AI Automation•7 min read

How We Connect OpenAI and Claude APIs to Laravel Portals Without Leaking Customer Data

Ivan

Ivan

Lead Engineer & Strategist at Softlimes

How We Connect OpenAI and Claude APIs to Laravel Portals Without Leaking Customer Data

Why Direct Controller Calls Put Customer Records at Risk

Many engineering teams add language model features by calling the OpenAI or Anthropic HTTP endpoint directly inside a Laravel controller. That shortcut creates two immediate operational problems in a production web portal. First, the user request hangs for four to ten seconds while the external API generates tokens, which ties up PHP-FPM workers under concurrent load.

Second, developers often serialize entire Eloquent models into the prompt context. A standard customer or order model includes email addresses, phone numbers, billing street names, and internal database keys. Sending raw model attributes to a third-party model endpoint violates most enterprise data processing agreements and exposes sensitive fields in external request logs.

Building a PII Redaction Middleware Before Prompt Assembly

At Softlimes, we place a dedicated sanitization service between the Laravel database layer and the outbound API client. Before any text leaves our server, the sanitizer replaces identifiable strings with deterministic local placeholders such as [CUSTOMER_NAME_1] or [INVOICE_REF_42]. We store the mapping in Redis with a ten-minute time-to-live scoped to the current job ID.

Once the OpenAI or Claude endpoint returns its structured JSON output, our response handler swaps those placeholders back with the real values from Redis. The external model processes the grammatical structure and business intent of the ticket or document, but it never sees a real customer email, tax number, or street address.

  • Strip all Eloquent model metadata and pass only explicitly whitelisted text fields to the prompt builder.
  • Run regex and named-entity redaction for emails, phone numbers, IBANs, and postal addresses before outbound serialization.
  • Use commercial API accounts with zero-data-retention agreements enabled at the organization level.
  • Log only token counts, latency metrics, and prompt template versions in your local database.

Queue Isolation and Schema Validation With Laravel Horizon

All external model requests run inside dedicated Laravel Horizon queues separated from core transactional jobs like password resets or order receipts. If an upstream API experiences a rate limit spike or temporary outage, our main application queues continue processing customer actions without delay. We configure exponential backoff intervals of ten, thirty, and ninety seconds on failed model jobs.

We also enforce strict JSON schema outputs on every API call. When a prompt asks Claude or GPT-4o to classify a support request or extract line items, we validate the returned payload against a Laravel Data object before writing anything to PostgreSQL. If a field fails type validation, the job routes the record to a human review queue instead of saving broken data.

Monitoring Token Spend and Tenant Quotas in Production

Unbounded API calls can wreck monthly infrastructure budgets when a single client uploads thousands of documents at once. We track input and output token usage per tenant in a dedicated ledger table updated after every job completion. Each client account has a daily and monthly token ceiling enforced by Laravel rate limiters.

When a tenant reaches eighty percent of their monthly allowance, the portal sends an automated alert to their account administrator. This architecture lets businesses run high-volume document classification and ticket drafting every day while keeping both customer privacy and monthly API bills under strict control.

Related Softlimes Service

AI Automation Services

See how our engineering team scopes, builds, and supports this workflow in production.

Explore Service →

Related articles by Ivan

Work With Us

Need engineering or marketing help on your next release

Talk directly with Ivan and the Softlimes engineering team to scope your web application, online store, AI workflow, or search campaign.