> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getbluejay.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Observe Your Agent

> Send production transcripts, traces, and recordings to Bluejay.

Enable tracing at process startup, then use the integration for your agent. The SDK groups telemetry by session so the transcript and trace are available on the same conversation in [Logs](https://docs.getbluejay.ai/monitor/logs).

```python Python icon="https://mintcdn.com/bluejay/73RDPPJpgHtl6PiO/logo/python.svg?fit=max&auto=format&n=73RDPPJpgHtl6PiO&q=85&s=ce56f186813559443f877804e7aef209" theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from bluejay import BluejayClient

client = BluejayClient(tracing=True)
```

```typescript TypeScript icon="https://mintcdn.com/bluejay/73RDPPJpgHtl6PiO/logo/typescript.svg?fit=max&auto=format&n=73RDPPJpgHtl6PiO&q=85&s=d4b45d3e44d76cf40cfb09b3d24831f5" theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { BluejayClient } from "@getbluejay/sdk";

const client = new BluejayClient({ tracing: true });
```

| Agent | What to add |
| - | - |
| LiveKit | Attach Bluejay before the agent session starts. The integration captures turns, spans, and audio. [LiveKit setup](https://docs.getbluejay.ai/sdk/livekit.md) |
| Pipecat | Add the tap to the pipeline and enable Pipecat tracing. The integration captures turns, spans, and audio. [Pipecat setup](https://docs.getbluejay.ai/sdk/pipecat.md) |
| Chat or SMS | Reuse the conversation ID and call `client.turn()` for each message. |
| Custom voice | Record finalized speech with `client.turn()` and add spans for custom steps. |

## Trace chat or SMS

Use `@client.session(...)` in Python or a `client.session(...)` callback in Node.js. Choose a stable conversation ID from the handler's arguments. Use the same ID for every message in the conversation.

```python Python icon="https://mintcdn.com/bluejay/73RDPPJpgHtl6PiO/logo/python.svg?fit=max&auto=format&n=73RDPPJpgHtl6PiO&q=85&s=ce56f186813559443f877804e7aef209" theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
@client.session(lambda chat_id, message: chat_id, external_agent_id="support-chat")
def answer_message(chat_id, message):
    client.turn("USER", message)
    reply = generate_reply(message)
    client.turn("AGENT", reply)
    return reply
```

```typescript TypeScript icon="https://mintcdn.com/bluejay/73RDPPJpgHtl6PiO/logo/typescript.svg?fit=max&auto=format&n=73RDPPJpgHtl6PiO&q=85&s=d4b45d3e44d76cf40cfb09b3d24831f5" theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
async function answerMessage(chatId, message) {
  return client.session({ sessionId: chatId, externalAgentId: "support-chat" }, async () => {
    client.turn("USER", message);
    const reply = await generateReply(message);
    client.turn("AGENT", reply);
    return reply;
  });
}
```

For SMS, use the conversation ID across messages and record the agent turn after your send succeeds:

```python Python icon="https://mintcdn.com/bluejay/73RDPPJpgHtl6PiO/logo/python.svg?fit=max&auto=format&n=73RDPPJpgHtl6PiO&q=85&s=ce56f186813559443f877804e7aef209" theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
@client.session(lambda thread_id, sender, message: thread_id, external_agent_id="support-sms")
async def respond_to_sms(thread_id, sender, message):
    client.turn("USER", message)
    reply = await generate_sms_reply(message)
    await send_sms(sender, reply)
    client.turn("AGENT", reply)
```

```typescript TypeScript icon="https://mintcdn.com/bluejay/73RDPPJpgHtl6PiO/logo/typescript.svg?fit=max&auto=format&n=73RDPPJpgHtl6PiO&q=85&s=d4b45d3e44d76cf40cfb09b3d24831f5" theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
async function respondToSms(threadId, sender, message) {
  return client.session({ sessionId: threadId, externalAgentId: "support-sms" }, async () => {
    client.turn("USER", message);
    const reply = await generateSmsReply(message);
    await sendSms(sender, reply);
    client.turn("AGENT", reply);
  });
}
```

Use the external ID configured on your Bluejay agent. To build the conversation when your app knows it has ended, call `client.end_session()` in Python or `await client.endSession()` in Node.js. Pass the conversation ID and the same agent ID. Bluejay also builds idle sessions automatically.

## Trace custom voice

Keep one ID for the call. Record the caller's finalized transcript and the portion of the reply that played. Pass timezone-aware `datetime` values for speech timing.

```python Python icon="https://mintcdn.com/bluejay/73RDPPJpgHtl6PiO/logo/python.svg?fit=max&auto=format&n=73RDPPJpgHtl6PiO&q=85&s=ce56f186813559443f877804e7aef209" theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
with client.session(call_id, external_agent_id="support-voice") as conversation:
    conversation.turn("USER", caller_text, start_time=heard_at, end_time=heard_until)
    conversation.turn(
        "AGENT", played_text,
        start_time=played_at,
        end_time=played_until,
        interrupted=caller_barged_in,
    )

conversation.end()
```

```typescript TypeScript icon="https://mintcdn.com/bluejay/73RDPPJpgHtl6PiO/logo/typescript.svg?fit=max&auto=format&n=73RDPPJpgHtl6PiO&q=85&s=d4b45d3e44d76cf40cfb09b3d24831f5" theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
const conversation = client.createSession({ sessionId: callId, externalAgentId: "support-voice" });
conversation.turn("USER", callerText, { startTime: heardAt, endTime: heardUntil });
conversation.turn("AGENT", playedText, {
  startTime: playedAt,
  endTime: playedUntil,
  interrupted: callerBargedIn,
});
await conversation.end();
```

For callbacks, reopen the same session ID as each callback runs. A custom stack supplies its own audio. If you already have a recording and a transcript, you can submit the finished call through [Evaluate](https://docs.getbluejay.ai/api-reference/endpoint/evaluate.md) as an alternative ingest path. Use one ingest path per conversation.

## Add model and tool details

`turn()` writes a transcript line. Supported provider calls are traced automatically inside the active session. Node.js has built-in OpenAI tracing. For other providers, use existing OpenTelemetry instrumentation or a manual model span. See [OpenAI](https://docs.getbluejay.ai/sdk/openai.md), [Anthropic](https://docs.getbluejay.ai/sdk/anthropic.md), [Gemini](https://docs.getbluejay.ai/sdk/gemini.md), or [Bedrock](https://docs.getbluejay.ai/sdk/bedrock.md).

Wrap a custom function with `observe()` to record its arguments, result, and errors. Use a decorator in Python or wrap the function in Node.js.

```python Python icon="https://mintcdn.com/bluejay/73RDPPJpgHtl6PiO/logo/python.svg?fit=max&auto=format&n=73RDPPJpgHtl6PiO&q=85&s=ce56f186813559443f877804e7aef209" theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
@client.observe(kind="tool")
def lookup_order(order_id):
    return orders.get(order_id)
```

```typescript TypeScript icon="https://mintcdn.com/bluejay/73RDPPJpgHtl6PiO/logo/typescript.svg?fit=max&auto=format&n=73RDPPJpgHtl6PiO&q=85&s=d4b45d3e44d76cf40cfb09b3d24831f5" theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
const lookupOrder = client.observe(
  "lookup order",
  async (orderId) => orders.get(orderId),
  { kind: "tool" },
);
```

For a model request that has no provider or framework span, use a manual span and set its output and token counts.

```python Python icon="https://mintcdn.com/bluejay/73RDPPJpgHtl6PiO/logo/python.svg?fit=max&auto=format&n=73RDPPJpgHtl6PiO&q=85&s=ce56f186813559443f877804e7aef209" theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
with client.span("generate reply", kind="llm", model=model_name, input=messages) as span:
    result = model_client.generate(messages)
    span.set_output(result.text, input_tokens=result.input_tokens, output_tokens=result.output_tokens)
```

```typescript TypeScript icon="https://mintcdn.com/bluejay/73RDPPJpgHtl6PiO/logo/typescript.svg?fit=max&auto=format&n=73RDPPJpgHtl6PiO&q=85&s=d4b45d3e44d76cf40cfb09b3d24831f5" theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
const result = await client.span("generate reply", async (span) => {
  const reply = await modelClient.generate(messages);
  span.setAttribute("gen_ai.usage.input_tokens", reply.inputTokens);
  span.setAttribute("gen_ai.usage.output_tokens", reply.outputTokens);
  return reply.text;
}, { kind: "llm", model: modelName, input: messages });
```

## Configure data capture

Configure trace redaction when initializing the client at startup:

```python Python icon="https://mintcdn.com/bluejay/73RDPPJpgHtl6PiO/logo/python.svg?fit=max&auto=format&n=73RDPPJpgHtl6PiO&q=85&s=ce56f186813559443f877804e7aef209" theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
client = BluejayClient()
client.init_tracing(redact_pii=True)
```

```typescript TypeScript icon="https://mintcdn.com/bluejay/73RDPPJpgHtl6PiO/logo/typescript.svg?fit=max&auto=format&n=73RDPPJpgHtl6PiO&q=85&s=d4b45d3e44d76cf40cfb09b3d24831f5" theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
const client = new BluejayClient({ tracing: { redactPii: true } });
```

`redact_pii=True` in Python and `redactPii: true` in Node.js strip supported content attributes such as transcript lines, prompts, and tool payloads from spans sent to Bluejay. For custom span attributes, provide a `mask` function. The voice integrations have separate audio upload settings.

## Verify the integration

Send a message or place a call, then open the conversation in [Logs](https://docs.getbluejay.ai/monitor/logs) and inspect its [trace](https://docs.getbluejay.ai/monitor/traces.md). For a short-lived trace-only script, flush spans before exit with `client.flush()` in Python or `await client.flush()` in Node.js.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.