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 AsyncOpenAIclient = AsyncOpenAI() # Direct providerresponse = await client.chat.completions.create(...)With TruthVouch:
from truthvouch import TruthVouchClientclient = TruthVouchClient(api_key="tv_live_...") # Governedresponse = await client.openai.chat.completions.create(...) # Same APIAll calls flow through TruthVouch Firewall for:
- Hallucination detection (fact-checking)
- PII masking and detection
- Prompt injection defense
- Policy enforcement
- Audit logging
SDK Status & Installation
| SDK | Package | Registry | Status | Install |
|---|---|---|---|---|
| Python | truthvouch | PyPI | General Availability | pip install truthvouch |
| TypeScript | @truthvouch/sdk | npm | General Availability | npm install @truthvouch/sdk |
| .NET | TruthVouch.Sdk | NuGet | General Availability | dotnet add package TruthVouch.Sdk |
| Go | github.com/truthvouch/truthvouch-go | Go modules | Coming Soon | go get github.com/truthvouch/truthvouch-go |
| Java | com.truthvouch:truthvouch-sdk | Maven | Coming Soon | Via Maven Central |
Feature Matrix
All SDKs support the core features below:
| Feature | Python | TypeScript | .NET | Go | Java |
|---|---|---|---|---|---|
| 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:
| Framework | Language | Status | Link |
|---|---|---|---|
| LangChain | Python | Available | LangChain Integration → |
| LlamaIndex | Python | Available | LlamaIndex Integration → |
| Semantic Kernel | .NET | Available | Semantic Kernel Integration → |
| Spring AI | Java | Coming Soon | Spring AI Integration → |
| Vercel AI SDK | TypeScript | Coming Soon | Vercel AI Integration → |
Quick Start by Language
Python
pip install truthvouchfrom 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)TypeScript/Node.js
npm install @truthvouch/sdkimport 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);.NET
dotnet add package TruthVouch.Sdkbuilder.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; }}Go (Coming Soon)
go get github.com/truthvouch/truthvouch-goclient := 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?"}},})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());Common Patterns
Authentication
All SDKs check for API key in this order:
- Constructor parameter
TRUTHVOUCH_API_KEYenvironment variable.truthvouch.jsonconfig file (lowest priority)
# Method 1: Constructorclient = TruthVouchClient(api_key="tv_live_...")
# Method 2: Environment variable (recommended)import osclient = 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 keyCircuit 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)| Setting | Value | Behavior |
|---|---|---|
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
| Variable | Default | Used By |
|---|---|---|
TRUTHVOUCH_API_KEY | (required) | All SDKs |
TRUTHVOUCH_GATEWAY_URL | https://gateway.truthvouch.com | All SDKs |
TRUTHVOUCH_TIMEOUT_MS | 30000 | All SDKs |
TRUTHVOUCH_FAIL_MODE | "open" | All SDKs |
TRUTHVOUCH_MAX_RETRIES | 3 | All 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}