LiteLLM

LiteLLM provides a unified Python interface for calling 100+ LLM providers using the OpenAI format. Respan gives you full observability over every LiteLLM completion across providers — and gateway routing through the OpenAI-compatible Respan endpoint.

Create an account at platform.respan.ai and grab an API key. For gateway, also add credits or a provider key.

Run npx @respan/cli setup to set up with your coding agent.

Setup

1

Install packages

$pip install respan-ai respan-exporter-litellm litellm
2

Set environment variables

$export OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"

OPENAI_API_KEY (or any provider key) is used for LLM requests. RESPAN_API_KEY is used to export traces to Respan.

3

Initialize and run

Register the Respan callback to log all completions automatically. Requests go directly to providers; the logs are sent to Respan.

1import litellm
2from respan_exporter_litellm import RespanLiteLLMCallback
3
4litellm.callbacks = [RespanLiteLLMCallback()]
5
6response = litellm.completion(
7 model="gpt-4.1-nano",
8 messages=[{"role": "user", "content": "Say hello in three languages."}],
9)
10print(response.choices[0].message.content)
4

View your trace

Open the Traces page to see your LiteLLM completions across providers as auto-traced spans.

Configuration

ParameterTypeDefaultDescription
api_keystrRESPAN_API_KEY env varRespan API key.
base_urlstr | NoneNoneAPI base URL.

See the LiteLLM Exporter SDK reference for the full API.

Attributes

Pass Respan parameters inside metadata.respan_params on each call.

1response = litellm.completion(
2 model="gpt-4.1-nano",
3 messages=[{"role": "user", "content": "Hello!"}],
4 metadata={
5 "respan_params": {
6 "workflow_name": "simple_logging",
7 "span_name": "single_log",
8 "customer_identifier": "user-123",
9 "thread_identifier": "conv_abc_123",
10 "metadata": {"plan": "pro"},
11 }
12 },
13)
AttributeDescription
customer_identifierIdentifies the end user in Respan analytics.
thread_identifierGroups related messages into a conversation.
metadataCustom key-value pairs attached to the span.
workflow_nameLogical workflow grouping the call belongs to.
span_nameCustom name for the resulting span.

Async usage

The callback supports async completions automatically.

1import litellm
2from respan_exporter_litellm import RespanLiteLLMCallback
3
4litellm.callbacks = [RespanLiteLLMCallback()]
5
6response = await litellm.acompletion(
7 model="gpt-4.1-nano",
8 messages=[{"role": "user", "content": "Tell me a joke"}],
9)

Multiple providers

LiteLLM’s unified interface means all providers are logged with the same callback.

1import litellm
2from respan_exporter_litellm import RespanLiteLLMCallback
3
4litellm.callbacks = [RespanLiteLLMCallback()]
5
6litellm.completion(model="gpt-4.1-nano", messages=[...])
7litellm.completion(model="claude-sonnet-4-5-20250929", messages=[...])
8litellm.completion(model="together_ai/meta-llama/Llama-3-70b", messages=[...])