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.10.3.tar.gz (56.5 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.10.3-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: weflayr-0.10.3.tar.gz
  • Upload date:
  • Size: 56.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","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.10.3.tar.gz
Algorithm Hash digest
SHA256 247459661a98165f5645d777b366181e4133478fcb9b5eb89f5164fbdb5cba06
MD5 1efe40e0f8bd99c30511e4cf470609eb
BLAKE2b-256 ff7db0629082f4a8c41fb487b9d59d05fc9507f09dfa21f8016eeb59ba576d4b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: weflayr-0.10.3-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","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.10.3-py3-none-any.whl
Algorithm Hash digest
SHA256 10c4e92e297b0847edb8059553e6a8e34a288681b752cb23e91307df2d8a2ef0
MD5 fb2e88d1ce5387f4747ac66b1b9c6b7d
BLAKE2b-256 1f8d546f3c0fc6f895afbab93048b84f8c374ec0dcd6531fff90ad6a61ea8289

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