Skip to content

SDKs Overview

TruthVouch SDKs are drop-in LLM provider replacements. Replace your import statement and all your AI calls are automatically governed — no code changes needed.

Core Concept

Traditional setup:

from openai import AsyncOpenAI
client = AsyncOpenAI() # Direct provider
response = await client.chat.completions.create(...)

With TruthVouch:

from truthvouch import TruthVouchClient
client = TruthVouchClient(api_key="tv_live_...") # Governed
response = await client.openai.chat.completions.create(...) # Same API

All calls flow through TruthVouch Firewall for:

  • Hallucination detection (fact-checking)
  • PII masking and detection
  • Prompt injection defense
  • Policy enforcement
  • Audit logging

SDK Status & Installation

SDKPackageRegistryStatusInstall
PythontruthvouchPyPIGeneral Availabilitypip install truthvouch
TypeScript@truthvouch/sdknpmGeneral Availabilitynpm install @truthvouch/sdk
.NETTruthVouch.SdkNuGetGeneral Availabilitydotnet add package TruthVouch.Sdk
Gogithub.com/truthvouch/truthvouch-goGo modulesComing Soongo get github.com/truthvouch/truthvouch-go
Javacom.truthvouch:truthvouch-sdkMavenComing SoonVia Maven Central

Feature Matrix

All SDKs support the core features below:

FeaturePythonTypeScript.NETGoJava
Drop-in OpenAI replacement
Drop-in Anthropic replacement
Drop-in Google AI replacement
Streaming support
Manual scan API
Batch scanning
Circuit breaker
Async/await
Error handling
Retry logic
Webhook verification
Trust API client
OpenTelemetry support

Framework Integrations

Pre-built integrations with popular AI frameworks:

FrameworkLanguageStatusLink
LangChainPythonAvailableLangChain Integration →
LlamaIndexPythonAvailableLlamaIndex Integration →
Semantic Kernel.NETAvailableSemantic Kernel Integration →
Spring AIJavaComing SoonSpring AI Integration →
Vercel AI SDKTypeScriptComing SoonVercel AI Integration →

Quick Start by Language

Python

Terminal window
pip install truthvouch
from truthvouch import TruthVouchClient
async with TruthVouchClient(
gateway_url="https://gateway.truthvouch.com",
api_key="tv_live_..."
) as client:
response = await client.openai.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "What is TruthVouch?"}]
)
print(response.content)

Full Python Quick Start →

TypeScript/Node.js

Terminal window
npm install @truthvouch/sdk
import TruthVouch from '@truthvouch/sdk';
const tv = new TruthVouch({ apiKey: 'tv_live_...' });
const openai = tv.openai();
const completion = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'What is TruthVouch?' }],
});
console.log(completion.choices[0].message.content);

Full TypeScript Quick Start →

.NET

Terminal window
dotnet add package TruthVouch.Sdk
builder.Services.AddTruthVouch(options =>
{
options.GatewayUrl = "https://gateway.truthvouch.com";
options.ApiKey = "tv_live_...";
});
public class MyService(ITruthVouchClient client)
{
public async Task<string> GetAnswerAsync(string question, CancellationToken ct)
{
var response = await client.Chat.CreateAsync(new ChatRequest
{
Model = "gpt-4o",
Messages = [new("user", question)]
}, ct);
return response.Content;
}
}

Full .NET Quick Start →

Go (Coming Soon)

Terminal window
go get github.com/truthvouch/truthvouch-go
client := truthvouch.New(truthvouch.WithAPIKey("tv_live_..."))
openai := client.OpenAI()
resp, err := openai.Chat.Create(context.Background(), truthvouch.ChatRequest{
Model: "gpt-4o",
Messages: []truthvouch.Message{{Role: "user", Content: "What is TruthVouch?"}},
})

Full Go Quick Start →

Java (Coming Soon)

<dependency>
<groupId>com.truthvouch</groupId>
<artifactId>truthvouch-sdk</artifactId>
<version>1.0.0</version>
</dependency>
var tv = TruthVouch.builder()
.apiKey("tv_live_...")
.build();
var openai = tv.openai();
var response = openai.chat().create(ChatRequest.builder()
.model("gpt-4o")
.addMessage("user", "What is TruthVouch?")
.build());
System.out.println(response.content());

Full Java Quick Start →


Common Patterns

Authentication

All SDKs check for API key in this order:

  1. Constructor parameter
  2. TRUTHVOUCH_API_KEY environment variable
  3. .truthvouch.json config file (lowest priority)
# Method 1: Constructor
client = TruthVouchClient(api_key="tv_live_...")
# Method 2: Environment variable (recommended)
import os
client = TruthVouchClient(api_key=os.environ["TRUTHVOUCH_API_KEY"])
# Method 3: Config file
# .truthvouch.json: { "apiKey": "tv_live_..." }
client = TruthVouchClient()

Error Handling

All SDKs include typed exception classes:

from truthvouch import (
PolicyBlockedError,
GatewayUnreachableError,
AuthenticationError,
RateLimitError,
)
try:
response = await client.openai.chat.completions.create(...)
except PolicyBlockedError as e:
# Request blocked by governance policy
print(f"Policy violation: {e.governance_report.policy_id}")
except RateLimitError as e:
# Rate limit exceeded
print(f"Retry after: {e.retry_after} seconds")
except GatewayUnreachableError:
# Gateway unreachable (check fail_mode setting)
except AuthenticationError:
# Invalid or expired API key

Circuit Breaker

All SDKs include a built-in circuit breaker:

client = TruthVouchClient(
api_key="tv_live_...",
fail_mode="open", # Bypass on failure (default)
circuit_breaker_threshold=5, # Open after 5 failures
circuit_breaker_recovery_seconds=60 # Recover after 60s
)
SettingValueBehavior
fail_mode"open"On circuit open, bypass gateway and call provider directly (degraded)
fail_mode"closed"On circuit open, raise CircuitOpenError (safe)

Streaming

All SDKs support streaming:

async for chunk in await client.openai.chat.completions.create(
model="gpt-4o",
messages=[...],
stream=True
):
if chunk.content:
print(chunk.content, end="", flush=True)

Batch Scanning

For offline document scanning:

job = await client.batch.submit(
source_url="s3://my-bucket/documents.jsonl",
format="jsonl",
scan_mode="deep"
)
status = await client.batch.get_status(job.id)
print(f"Progress: {status.progress_percent}%")

Configuration

Environment Variables

VariableDefaultUsed By
TRUTHVOUCH_API_KEY(required)All SDKs
TRUTHVOUCH_GATEWAY_URLhttps://gateway.truthvouch.comAll SDKs
TRUTHVOUCH_TIMEOUT_MS30000All SDKs
TRUTHVOUCH_FAIL_MODE"open"All SDKs
TRUTHVOUCH_MAX_RETRIES3All SDKs

.truthvouch.json Config File

Create a .truthvouch.json in your project root:

{
"apiKey": "tv_live_...",
"gatewayUrl": "https://gateway.truthvouch.com",
"timeoutMs": 30000,
"failMode": "open",
"maxRetries": 3
}

Next Steps