Skip to main content

launchdarkly-ai-claude-messages

Anthropic Claude handler for launchdarkly-ai-server using the Anthropic Messages API (anthropic). Runs a manual tool-use loop without the Claude Agent SDK layer.

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

Installation

pip install launchdarkly-ai-server launchdarkly-ai-claude-messages

Set ANTHROPIC_API_KEY in your environment (the Anthropic SDK reads it automatically).

Usage

With config()

import asyncio
from launchdarkly_ai_server import config, shutdown
from launchdarkly_ai_claude_messages import create_claude_messages_handler

async def main():
    result = await config(
        key="my-ai-config-flag",
        handler=create_claude_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_claude_messages import claude_messages

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

asyncio.run(main())

How It Works

  • Uses the system prompt and conversation history 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.

Choosing Between claude-agents and claude-messages

claude-agents claude-messages
Underlying SDK claude-agent-sdk anthropic
Tool loop Managed by the Claude Agent SDK Executed and fed back manually
Complexity Lower (SDK manages loop) More explicit control

Environment Variables

Variable Description
ANTHROPIC_API_KEY Anthropic API key (read automatically by the Anthropic 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_claude_messages-0.1.4.tar.gz (14.9 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_claude_messages-0.1.4.tar.gz.

File metadata

File hashes

Hashes for launchdarkly_ai_claude_messages-0.1.4.tar.gz
Algorithm Hash digest
SHA256 cec5eed5933d58c992407e87af2d071fedeedcae3736de42fc9c9a1725a7a052
MD5 0f88e5d0759dc00fecff5d017f522f3d
BLAKE2b-256 166d8946bca5318706230e208dece4515f625fd7176f5b8b7010acd86e4d7d76

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for launchdarkly_ai_claude_messages-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 12fc7888171b54fd7a25fa7f7ee1cd94051a9d46659e17c8d50fe322bf02308e
MD5 66d09f154a3a1c7bcd802045c6ce4acc
BLAKE2b-256 02cb7b494ea60561f417f1ee09402251231e70c5ad5f6e7460a1b7d4bbd28218

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 Sentry Error logging StatusPage Status page