Providers
Auto-instrumentation for LLM providers.
Risicare automatically instruments popular LLM providers. In Python, add import risicare to your entrypoint and set RISICARE_API_KEY and RISICARE_TRACING=true, or call risicare.init(). In JavaScript, call init() and a patchX() function. You do not change your agent logic.
Streams
In Python, a traced stream=True call returns a proxy of the provider's stream object for OpenAI, Anthropic, Groq, Cerebras and Together, and a proxy of the response object for Google. It works as the provider's own object does: for, async for, with and async with, .response, the OpenAI stream() helper, and LangChain stream() / astream(). Ollama and Hugging Face return a plain generator, as they do without the SDK. Mistral streaming calls are not traced.
The span is sent when the stream is read to its end. A stream that you stop reading and drop, or never read, still sends a span, with status ok and no token counts.
The Anthropic messages.stream() helper is traced too. The span of a streamed OpenAI or Anthropic call records the tool calls of the answer, as the span of a call that is not a stream does. See OpenAI and Anthropic.
In JavaScript, a streaming call through patchOpenAI or patchAnthropic makes a span. The SDK reads the tool calls of a stream that you read with the iterator. patchOpenAI also traces the stream helpers of openai (responses.stream(), chat.completions.stream()); traceStreamHelpers: false turns that off. See OpenAI (JS). Since npm 0.19.1, with content capture on, a streamed OpenAI chat call and a streamed Anthropic call also record the answer text in gen_ai.completion.content. The other JavaScript provider patches (patchGoogleAI, patchMistral, patchGroq, patchCohere, patchTogether, patchOllama, patchHuggingFace, patchCerebras, patchBedrock and patchVercelAI) capture no prompt text and no completion text, for a stream and for a whole answer. This is a known limit.
Supported Providers
Python SDK
The Python SDK patches the provider libraries itself: there are no explicit patchX() calls (that is the JS SDK's model). The order of your imports does not matter. risicare.init() (or import risicare with RISICARE_TRACING=true) traces a supported library that your program imported already, and one that it imports later with an import statement. One exception: a name that you bind with from ollama import chat before init() keeps the function that is not traced. See Ollama.
OpenAI
GPT-4o, GPT-4, embeddings
Anthropic
Claude 3.5, Claude 3
Gemini Pro, PaLM
Cohere
Command, embeddings
Mistral
Chat completions
Groq
Hosts open models
Together AI
Open-source models
Ollama
Local inference
Amazon Bedrock
AWS multi-model
Vertex AI
Google Cloud AI
Cerebras
Hardware-accelerated
HuggingFace
Inference API
OpenAI-Compatible
8+ providers via base_url
JavaScript SDK
The JS SDK supports 12 native providers through explicit patchX() calls — Python's list with Vercel AI in place of Vertex AI, which the JS SDK does not support — plus 8 host-detected providers through patchOpenAI():
OpenAI (JS)
Node.js OpenAI client
Anthropic (JS)
Node.js Anthropic client
Vercel AI (JS)
Vercel AI SDK
Additional JS providers (Google, Mistral, Groq, Cohere, Together, Ollama, HuggingFace, Cerebras, Bedrock) follow the same pattern — import from risicare/<provider> and call patchX(client). See the JS SDK reference for the full list.
How It Works
When you call risicare.init(), the SDK patches the supported provider libraries that your program imported already. It patches the ones that your program imports later too:
import risicare
from openai import OpenAI
risicare.init()
client = OpenAI()
# This call is automatically traced
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)Captured Data
For each LLM call, the SDK captures:
| Field | Description |
|---|---|
model | Model name (gpt-4o, claude-sonnet-5-5, etc.) |
provider | Provider name (openai, anthropic, etc.) |
prompt_tokens | Input token count |
completion_tokens | Output token count |
total_tokens | Total token count |
latency_ms | Request duration |
temperature | Sampling temperature |
max_tokens | Maximum output tokens |
prompt | Input prompt (when trace_content is on; it is on by default) |
completion | Output completion (when trace_content is on; it is on by default) |
Prompt and completion text leaves your process by default (Python 0.7.0 and npm 0.10.0 and later). To keep it in your process, set trace_content=False (npm: traceContent: false) or RISICARE_TRACE_CONTENT=false.
With content capture on, the OpenAI and Anthropic patches send the whole request: your tool definitions, the Anthropic system prompt and your whole message list. They send gen_ai.request.top_p, gen_ai.request.tool_choice, gen_ai.request.stop_sequences and gen_ai.request.seed (OpenAI only) when you set them, with capture on or off. See OpenAI and Anthropic.
The OpenAI and Anthropic patches also send the tool calls of the answer, for a streamed answer too: the number of calls, the names and the finish or stop reason of the first 5 calls, and their arguments. The arguments are content: the SDK sends them only with content capture on. The number, the names and the finish or stop reason are sent with capture on or off, and no option turns them off.
With content capture off, the SDK also withholds the text of an error (the status message, the exception messages, error.message and error.stack). The option error_text (npm: errorText) changes this. See Production & Failure Modes.
When the response gives them, the OpenAI and Anthropic patches (and LiteLLM in Python) also send the cached and reasoning token counts: gen_ai.usage.cache_read.input_tokens, gen_ai.usage.cache_write.input_tokens and gen_ai.usage.reasoning.output_tokens. The other providers do not send them yet.
The Python SDK does not compute cost. The JavaScript SDK sends a cost from its own table. The server calculates cost from the token counts and its price table, and its cost wins for each model that the table knows. See Cost Tracking.
Manual Instrumentation
If auto-instrumentation doesn't meet your needs:
from risicare import trace, SpanKind
@trace(name="custom-llm-call", kind=SpanKind.LLM_CALL)
def call_custom_llm(prompt: str) -> str:
# Your custom LLM call
return responseYou can also set provider and model attributes manually:
from risicare import get_tracer, SpanKind
tracer = get_tracer()
with tracer.start_span("custom-llm", kind=SpanKind.LLM_CALL) as span:
span.set_attribute("llm.provider", "custom")
span.set_attribute("llm.model", "my-model")
response = call_llm(prompt)Next Steps
Select a provider to see detailed integration guides: