BLACKFUEL
Cookbooks

LangSmith

Trace Blackfuel API calls in LangSmith using the OpenAI Agents SDK integration

LangSmith gives you full observability into your agent runs — LLM calls, tool invocations, latency, and token usage. This cookbook shows how to connect Blackfuel as the inference backend using the OpenAI Agents SDK and stream traces to LangSmith.

Prerequisites

Install dependencies

pip install openai-agents langsmith

Set up credentials

Replace the placeholders with your actual keys:

export BLACKFUEL_API_KEY="bf_mykey_xxxxxx"
export LANGSMITH_API_KEY="your-langsmith-api-key"
export LANGSMITH_TRACING=true

Configure the Blackfuel client

The three blocks in this section build up one script — each continues the previous one, and the imports are shown once here.

The OpenAI Agents SDK routes requests to providers based on the model name prefix. Register Blackfuel as a named provider:

import asyncio
import os

from agents import Agent, Runner, set_trace_processors
from agents.models.multi_provider import MultiProvider, MultiProviderMap
from agents.models.openai_provider import OpenAIProvider
from agents.run_config import RunConfig
from langsmith.integrations.openai_agents_sdk import OpenAIAgentsTracingProcessor
from openai import AsyncOpenAI

client = AsyncOpenAI(
    api_key=os.environ["BLACKFUEL_API_KEY"],
    base_url="https://api.blackfuel.ai/v1",
)

# use_responses=False sends requests to the chat completions API
blackfuel_provider = OpenAIProvider(openai_client=client, use_responses=False)

provider_map = MultiProviderMap()
provider_map.add_provider("blackfuel", blackfuel_provider)  # "blackfuel" becomes the model prefix
custom_provider = MultiProvider(provider_map=provider_map)

Any model prefixed with blackfuel/ is routed to Blackfuel's API.

Add LangSmith tracing

Call set_trace_processors once at startup, before any agents run:

set_trace_processors([OpenAIAgentsTracingProcessor()])

This captures every agent run, LLM call, and tool invocation as a trace in your LangSmith dashboard.

Run your agent

Create an agent using the blackfuel/ prefix to route to Blackfuel, and pass the custom provider via RunConfig:

model_name = "moonshotai/Kimi-K3"  # Change model here


async def main():
    agent = Agent(
        name="Assistant",
        instructions="You are a helpful assistant.",
        model=f"blackfuel/{model_name}",
    )

    run_config = RunConfig(model_provider=custom_provider)
    result = await Runner.run(agent, "What is the capital of France?", run_config=run_config)
    print(result.final_output)


asyncio.run(main())

The model_provider in RunConfig tells the SDK to use your provider map for resolution — without it, the SDK would fall back to OpenAI directly.

Full example

Putting it all together:

import os
import asyncio
from agents import Agent, Runner, set_trace_processors
from agents.models.multi_provider import MultiProvider, MultiProviderMap
from agents.models.openai_provider import OpenAIProvider
from agents.run_config import RunConfig
from langsmith.integrations.openai_agents_sdk import OpenAIAgentsTracingProcessor
from openai import AsyncOpenAI

client = AsyncOpenAI(
    api_key=os.environ["BLACKFUEL_API_KEY"],
    base_url="https://api.blackfuel.ai/v1",
)

blackfuel_provider = OpenAIProvider(openai_client=client, use_responses=False)
provider_map = MultiProviderMap()
provider_map.add_provider("blackfuel", blackfuel_provider)
custom_provider = MultiProvider(provider_map=provider_map)


async def main():
    model_name = "moonshotai/Kimi-K3"  # Change model here

    agent = Agent(
        name="Assistant",
        instructions="You are a helpful assistant.",
        model=f"blackfuel/{model_name}",
    )

    run_config = RunConfig(model_provider=custom_provider)
    result = await Runner.run(agent, "What is the capital of France?", run_config=run_config)
    print(result.final_output)


if __name__ == "__main__":
    set_trace_processors([OpenAIAgentsTracingProcessor()])
    asyncio.run(main())

Traces appear in your LangSmith dashboard showing each agent run, LLM call, latency, and token usage. Browse available models to find the right model for your use case.

Wrap Runner.run in the retry handling your workload needs — the SDK raises openai.RateLimitError on a 429. See the Error Handling guide for status codes and backoff.

On this page