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.6.2.tar.gz (52.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.6.2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: weflayr-0.6.2.tar.gz
  • Upload date:
  • Size: 52.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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.6.2.tar.gz
Algorithm Hash digest
SHA256 f7ccc8db563236e6be1c035037c4147a7d2663aeed37506b501799a708df1ac4
MD5 862c310f445eec452e37748d33250e1a
BLAKE2b-256 be15ff6002cd5b1e535d6525f385b7a3a20877b5df489fdad04caf0f7331b3aa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: weflayr-0.6.2-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3834fc6ec7349a6a02b296079c45c9b4cf1619a0ba8bffa3be88accad6fa94b5
MD5 6c751a182aa8b011000d1bf9833af758
BLAKE2b-256 f96701f870ce88a975d7506d2afb9e8e05cc1ea55d499306eb2fd6e1d067ae21

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