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.7.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.7.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: weflayr-0.7.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.7.0.tar.gz
Algorithm Hash digest
SHA256 018315ab3b821b023a9ddcac649449c48ada0390971c5f2b07c7f27dacb81a7e
MD5 1ec1d3f9297aac2cfa5e48e693ad0a3a
BLAKE2b-256 7b908fb93c42c3793148ef16392ce1a78ab1b4745b3949b7a1328e3ba9dc9cff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: weflayr-0.7.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.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 461f2a26a470fd60677f24f9d83c32ccd0174688cc977efe7875737ba9e32649
MD5 167d2d855e5a475f00760452573a7835
BLAKE2b-256 92d24f79b1672211968cbd1800c961b33e47e0a488627f91effeeae532b7fa23

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