Integrations & Consulting

AI Integration & Consulting

Guidance for adding AI and language models to existing software while managing privacy, cost, and operational limits.

AI integration means adding a model or AI service to a workflow that already exists. The model may classify records, extract information from documents, answer questions about internal data, or help a user complete a task. The surrounding application still needs to handle permissions, failures, cost, and review of the result.

Our role is to help teams make those boundaries clear before they commit sensitive data or business decisions to a model.

Core AI Integration Scenarios

This page covers three common areas:

Generative AI & Large Language Models (LLMs)

Adding services such as OpenAI GPT, Google Gemini, Anthropic Claude, or open-weight models such as Llama 3 and Mistral to support search, document work, customer support, or controlled content generation.

Machine Learning & Predictive Analytics

Connecting models built with tools such as scikit-learn, TensorFlow, or PyTorch to financial and communication systems. Possible uses include scoring, churn analysis, fraud review, and routing decisions.

Cognitive & Computer Vision APIs

Using OCR, translation, speech, or vision services to extract information from identity documents and receipts, support onboarding, or make existing applications easier to use.

Resilient Architecture for AI Systems

Model calls can be slower and less predictable than a database query. They may also be priced by tokens and restricted by provider limits. A useful design makes those constraints visible:

1. Multi-Layered Caching Strategy

Cache only when the result is safe to reuse and the invalidation rules are understood. Two common approaches are:

  • Exact-match caching: Store a response against the complete input, including the prompt, system instructions, temperature, and model version.
  • Semantic caching: Match similar inputs using an embedding or vector index. A threshold must be tested against real examples; a high similarity score does not guarantee that two requests have the same business meaning.

2. Retrieval-Augmented Generation (RAG)

For domain-specific answers, a retrieval layer can select relevant material before the model is called. One possible implementation uses PostgreSQL with pgvector; documents are split into useful sections, embedded, indexed, and combined with keyword search where that improves recall.

3. Token-Aware Rate Limiting & Concurrency Control

Track both request counts and token usage when the provider exposes those limits. A bounded queue or a documented fallback can help, but non-idempotent work should not be duplicated just because a model call was slow or rejected.

4. Streaming Responses via Server-Sent Events (SSE)

Streaming can improve the experience when a response takes time to generate. Choose Server-Sent Events or WebSockets according to the rest of the application, and make sure disconnects, partial output, and moderation requirements are handled.

Enterprise Data Security & Privacy

Before sending company or customer information to an external model, decide what may leave your system, what must be removed, and how the request and response will be logged.

The Gateway Pattern for PII Protection

An AI gateway or middleware layer can apply those rules in one place. It can inspect the request, enforce provider and tenant policies, and keep credentials out of application clients.

  • PII filtering: Use rules for structured values such as phone numbers, API keys, and bank details. Entity recognition can help with names and organizations, but it needs testing and should not be treated as perfect.
  • Masking: Replace sensitive values with controlled placeholders such as [MASKED_EMAIL_1] only when the application can safely restore them and prevent the model from changing their meaning.
  • Retention: Confirm the provider's current retention and training terms for the account and endpoint you are using. Do not describe a zero-retention arrangement unless the contract actually provides it.
  • Private deployment: For stricter environments, evaluate self-hosted or private-cloud models such as Llama 3, Mistral, or Gemma against the operational and security burden they introduce.

Sample Integration: Streaming LLM Response

The example below shows the shape of a streaming request. In a real application, keep the provider call behind your server and expose only the application-specific endpoint that the browser is allowed to use.

Proxy Streaming Completion
curl -X POST https://api.openai.com/v1/chat/completions \
  -H "Authorization: Bearer $AI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Analyze transaction logs for fraud patterns."}],
    "stream": true
  }'
$apiKey = config('services.ai.key');

$response = Http::withHeaders([
    'Authorization' => 'Bearer ' . $apiKey,
])->post('https://api.openai.com/v1/chat/completions', [
    'model' => 'gpt-4o',
    'messages' => [
        ['role' => 'user', 'content' => 'Analyze transaction logs for fraud patterns.']
    ],
    'stream' => true,
]);

// Stream the response directly to the browser
$body = $response->getBody();
while (!$body->eof()) {
    echo $body->read(1024);
    ob_flush();
    flush();
}
const response = await fetch('https://api.openai.com/v1/chat/completions', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.AI_API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    model: 'gpt-4o',
    messages: [{ role: 'user', content: 'Analyze transaction logs for fraud patterns.' }],
    stream: true
  })
});

const reader = response.body.getReader();
const decoder = new TextDecoder('utf-8');

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  const chunk = decoder.decode(value);
  console.log(chunk); // Process stream token chunk
}

Our AI Consulting & Delivery Process

A sensible engagement starts with the use case and the data, then moves toward a small, testable implementation:

Step 01

Feasibility & Model Selection

Define the task, inputs, users, failure impact, budget, and evaluation criteria before choosing a model or provider.

Step 02

Prompt Engineering & RAG

Design the instructions and retrieval path, then test answers against representative private data rather than relying on a few demonstrations.

Step 03

Resiliency & Monitoring

Measure latency, token use, cost, failures, and answer quality. Add limits and fallbacks only where the measured workload needs them.

Start with a defined problem

If you are assessing an AI feature, a predictive workflow, or the security of a planned architecture in Kenya, contact the Statum team with the workflow and constraints you are working with.