Skip to main content

Drop-in instrumented wrappers for AI clients with zero-overhead telemetry

Project description

Weflayr SDK

Drop-in instrumented wrappers for AI clients. Add telemetry to your LLM calls in one line - no changes to your existing code structure required.

How it works

Weflayr wraps the official provider SDKs and automatically fires telemetry events to your Weflayr intake API before, after, and on error for every LLM call. Your application code stays identical.

your code  →  weflayr.sdk.openai.OpenAI  →  openai.OpenAI  →  OpenAI API
                       ↓
              Weflayr Intake API
              (before / after / error events)

Installation

pip install weflayr

Quickstart

Configuration

Set the following environment variables:

Variable Description Default
WEFLAYR_INTAKE_URL Your Weflayr intake API base URL https://api.weflayr.com
WEFLAYR_CLIENT_ID Your client identifier unknown_client
WEFLAYR_CLIENT_SECRET Your bearer token (empty)
export WEFLAYR_INTAKE_URL="https://api.weflayr.com"
export WEFLAYR_CLIENT_ID="my-app"
export WEFLAYR_CLIENT_SECRET="your-secret-token"

OpenAI

Drop-in replacement for openai.OpenAI and openai.AsyncOpenAI.

Sync

from weflayr.sdk.openai.client import OpenAI

client = OpenAI(api_key="sk-...")

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello!"}],
)

print(response.choices[0].message.content)

Async

import asyncio
from weflayr.sdk.openai.client import AsyncOpenAI

client = AsyncOpenAI(api_key="sk-...")

async def main():
    response = await client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": "Hello!"}],
    )
    print(response.choices[0].message.content)

asyncio.run(main())

Tagging calls

Pass a tags dict to attach arbitrary metadata to your telemetry events:

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Summarize this."}],
    tags={"feature": "summarization", "user_id": "u_123"},
)

Mistral AI

Drop-in replacement for mistralai.client.Mistral.

Sync

from weflayr.sdk.mistralai.client import Mistral

client = Mistral(api_key="sk-...")

response = client.chat.complete(
    model="mistral-small-latest",
    messages=[{"role": "user", "content": "Hello!"}],
)

print(response.choices[0].message.content)

Async

import asyncio
from weflayr.sdk.mistralai.client import Mistral

client = Mistral(api_key="sk-...")

async def main():
    response = await client.chat.complete_async(
        model="mistral-small-latest",
        messages=[{"role": "user", "content": "Hello!"}],
    )
    print(response.choices[0].message.content)

asyncio.run(main())

Tagging calls

response = client.chat.complete(
    model="mistral-small-latest",
    messages=[{"role": "user", "content": "Translate this."}],
    tags={"feature": "translation", "env": "production"},
)

Telemetry events

For every LLM call, Weflayr sends up to three events to your intake API:

Event When Payload includes
<call>.before Before the provider call model, message_count, tags
<call>.after On success model, elapsed_ms, prompt_tokens, completion_tokens
<call>.error On failure model, elapsed_ms, error_type, error_message, status_code

Events are sent fire-and-forget in background threads — they never block your application or raise exceptions.


Advanced: per-client configuration

Override the intake URL, client ID, and bearer token directly on the client instead of using environment variables:

from weflayr.sdk.openai.client import OpenAI

client = OpenAI(
    api_key="sk-...",
    intake_url="https://api.weflayr.com",
    client_id="my-service",
    bearer_token="my-secret",
)

License

Elastic License 2.0 — free to use, modifications and redistribution not permitted.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

weflayr-0.8.0.tar.gz (54.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

weflayr-0.8.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file weflayr-0.8.0.tar.gz.

File metadata

  • Download URL: weflayr-0.8.0.tar.gz
  • Upload date:
  • Size: 54.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for weflayr-0.8.0.tar.gz
Algorithm Hash digest
SHA256 85d57ddcd706f0a312c7027def64cdab92ea00d9cb9fac9f8b5dcfe791b45a98
MD5 81b168cb145dede4b8622a6b62ea833e
BLAKE2b-256 8fab0f465f274374b78fbe1bb176aea3b30f55836427acafd2faabe1f1f6f475

See more details on using hashes here.

File details

Details for the file weflayr-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: weflayr-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for weflayr-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9f5f32ea9fd0fd41562226cd77bcda36fc3c51aab1d7b619ecabc9aec380c59
MD5 35a47627b4e07dccaeaeefa0cb682ef4
BLAKE2b-256 b7d54d9da25adb44a42595a37a742fd583860760f5a246d580ffce32debec1e5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page