Kong / Kong/developer.konghq.com

AI Gateway – Add documentation for integrating with Langfuse

Open
#3,353 0 comments 0 reactions 1 assignee Claimed by @tomek-labuk View on GitHub
internal priority: medium product:ai-gateway release-docs
Dominant language
Ruby
Stars
28
Forks
121
Avg merge
1d 4h
Merged PRs (30d)
313

Description

Add a how-to for integrating with Langfuse via AI Proxy (similar to LangChain and LiteLLM)

Both, AI Proxy and the script must use the same model:

```python
from langchain_openai import ChatOpenAI
from langfuse import Langfuse
from langfuse.callback import CallbackHandler

# --- Kong Gateway config ---
kong_url = "http://127.0.0.1:8000"
kong_route = "anything"

# --- Langfuse config ---
langfuse = Langfuse(
public_key="LF_PUBLIC_KEY",
secret_key="LF_SECRET_KEY",
host="https://cloud.langfuse.com" # or your self-host URL
)
handler = CallbackHandler(langfuse)

# LLM routed through Kong AI Gateway
llm = ChatOpenAI(
base_url=f"{kong_url}/{kong_route}",
model="gpt-4.1",
api_key="my-api-key",
callbacks=[handler]
)

def say_hello():
trace = langfuse.trace(name="say_hello")
span = trace.span(name="llm-call")

response = llm.invoke(
"Are you using Langfuse with Kong??",
callbacks=[handler] # optional but ensures span binding
)

print(f"$ ChainAnswer:> {response.content}")

span.end()
trace.end()
langfuse.flush()

say_hello()

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.