Skip to main content

launchdarkly-ai-openai-messages

OpenAI handler for launchdarkly-ai-server using the OpenAI Responses API (openai). Runs a manual function-call loop directly against the Responses API.

provides_for: ['OpenAI', 'messages'] — matches flag variations where provider.name is "OpenAI" and meta.mode is "messages".

Installation

pip install launchdarkly-ai-server launchdarkly-ai-openai-messages

Set OPENAI_API_KEY in your environment (the OpenAI SDK reads it automatically).

Usage

With config()

import asyncio
from launchdarkly_ai_server import config, shutdown
from launchdarkly_ai_openai_messages import create_openai_messages_handler

async def main():
    result = await config(
        key="my-ai-config-flag",
        handler=create_openai_messages_handler(),
        tool_handlers={"search": lambda q: "..."},
    ).invoke("What is feature flagging?", {"kind": "user", "key": "user-123"})

    print(result.response)
    await shutdown()

asyncio.run(main())

Convenience wrapper

import asyncio
from launchdarkly_ai_openai_messages import openai_messages

async def main():
    user_input = "What is feature flagging?"
    result = await openai_messages(
        "my-ai-config-flag",
        user_input,
        {"kind": "user", "key": "user-123"},
    )
    print(result.response)

asyncio.run(main())

How It Works

  • Uses the system prompt defined in your LaunchDarkly flag config.
  • Template placeholders ({{variable}}) in the prompt are substituted using variables before the call.
  • If tools are defined in the flag config, executes them as the model requests and feeds results back until the model produces a final response.
  • Emits an OTel span and LaunchDarkly telemetry for every call.

Environment Variables

Variable Description
OPENAI_API_KEY OpenAI API key (read automatically by the OpenAI SDK)
LD_SDK_KEY LaunchDarkly server-side SDK key
LD_SERVICE_NAME OTel service.name resource attribute (default: python-sdk)
LD_ENVIRONMENT deployment.environment attribute attached to telemetry
OTEL_EXPORTER_OTLP_ENDPOINT OTLP endpoint override (default: LaunchDarkly Observability backend)

Download files

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

Source Distribution

launchdarkly_ai_openai_messages-0.1.4.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file launchdarkly_ai_openai_messages-0.1.4.tar.gz.

File metadata

File hashes

Hashes for launchdarkly_ai_openai_messages-0.1.4.tar.gz
Algorithm Hash digest
SHA256 cae162d54f758f28525488005c25e83189088160935ef990a765dc46614ed241
MD5 a085f06730c2ba5e4db804e5c63b9d5c
BLAKE2b-256 c1ba2cc507e3875b90e827f3050bb0f6523739a6523b5244570c11f3df028ffa

See more details on using hashes here.

File details

Details for the file launchdarkly_ai_openai_messages-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for launchdarkly_ai_openai_messages-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cd830bf92a4623394399525e87ded1aedce3668b7a25cb333484efc2b42ef9b5
MD5 8c9510c9c90efc33a663b9aa438c8023
BLAKE2b-256 b24b474ffe9c0f877fc8ec64bdbc06e2bc5253df1020a78f58d833b7cc2e13ad

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