Integration Examples
Real-world examples and complete integration patterns
Legal Use Cases
Explore practical examples for common legal research and analysis workflows
Contract Analysis
Analyze contracts for risks, key terms, and compliance issues
contract
analysis
compliance
typescript
import { createBriefcaseLegal } from '@briefcase/ai-sdk-legal'import { generateText } from 'ai' const briefcase = createBriefcaseLegal({ apiKey: process.env.LEGAL_API_KEY, baseURL: 'https://briefcasebrain.ai/api/v1'}) export async function analyzeContract(contractText: string) { const { text, toolResults } = await generateText({ model: briefcase('contract-reviewer'), prompt: `Please analyze this contract for potential risks, key terms, and compliance issues: ${contractText}`, tools: { contractAnalysis: briefcase.tools.contractAnalysis, regulatoryCompliance: briefcase.tools.regulatoryCompliance }, toolChoice: 'auto', maxTokens: 4000 }) return { analysis: text, detailedResults: toolResults }} // Usage exampleconst contract = `[CONTRACT TEXT HERE]`const result = await analyzeContract(contract) console.log('Contract Analysis:', result.analysis)result.detailedResults.forEach(tool => { console.log(`${tool.toolName}:, tool.result)})Case Law Research
Research relevant cases, precedents, and legal citations
research
cases
precedents
typescript
import { createBriefcaseLegal } from '@briefcase/ai-sdk-legal'import { generateText } from 'ai' const briefcase = createBriefcaseLegal({ apiKey: process.env.LEGAL_API_KEY, baseURL: 'https://briefcasebrain.ai/api/v1'}) export async function researchCaseLaw(query: string, jurisdiction?: string) { const { text, toolResults } = await generateText({ model: briefcase('case-law-analyzer'), prompt: `Research case law related to: ${query}` + (jurisdiction ? ` in ${jurisdiction} jurisdiction` : ''), tools: { caseLawSearch: briefcase.tools.caseLawSearch, precedentAnalysis: briefcase.tools.precedentAnalysis, legalCitation: briefcase.tools.legalCitation }, toolChoice: 'auto', temperature: 0.3 // Lower temperature for more precise legal research }) return { summary: text, cases: toolResults.find(r => r.toolName === 'caseLawSearch')?.result, precedents: toolResults.find(r => r.toolName === 'precedentAnalysis')?.result, citations: toolResults.find(r => r.toolName === 'legalCitation')?.result }} // Research employment law casesconst research = await researchCaseLaw( 'workplace discrimination based on remote work policies', 'California') console.log('Research Summary:', research.summary)console.log('Relevant Cases:', research.cases)console.log('Legal Precedents:', research.precedents)Compliance Checker
Check documents against regulations and standards
compliance
regulations
audit
typescript
import { createBriefcaseLegal } from '@briefcase/ai-sdk-legal'import { generateText } from 'ai' const briefcase = createBriefcaseLegal({ apiKey: process.env.LEGAL_API_KEY, baseURL: 'https://briefcasebrain.ai/api/v1'}) interface ComplianceCheck { document: string regulations: string[] jurisdiction: string} export async function checkCompliance({ document, regulations, jurisdiction}: ComplianceCheck) { const regulationsList = regulations.join(', ') const { text, toolResults } = await generateText({ model: briefcase('legal-research-pro'), prompt: `Review this document for compliance with ${regulationsList} in ${jurisdiction}: Document:${document} Please identify:1. Compliance gaps2. Required modifications3. Risk assessment4. Recommendations`, tools: { regulatoryCompliance: briefcase.tools.regulatoryCompliance, jurisdictionComparison: briefcase.tools.jurisdictionComparison, statuteAnalysis: briefcase.tools.statuteAnalysis }, toolChoice: 'auto' }) return { complianceReport: text, detailedAnalysis: toolResults }} // Example: GDPR compliance checkconst result = await checkCompliance({ document: 'Privacy Policy text...', regulations: ['GDPR', 'CCPA'], jurisdiction: 'European Union'})Litigation Support
Generate legal briefs and litigation documents
litigation
briefs
streaming
typescript
import { createBriefcaseLegal } from '@briefcase/ai-sdk-legal'import { streamText } from 'ai' const briefcase = createBriefcaseLegal({ apiKey: process.env.LEGAL_API_KEY, baseURL: 'https://briefcasebrain.ai/api/v1'}) export async function generateLegalBrief( caseDetails: string, arguments: string[], onChunk?: (chunk: string) => void) { const argumentsList = arguments.map((arg, i) => `${i + 1}. ${arg}`).join('\n') const { textStream } = await streamText({ model: briefcase('litigation-assistant'), prompt: `Draft a legal brief for the following case with these key arguments: Case Details:${caseDetails} Key Arguments:${argumentsList} Please structure the brief with:1. Statement of Facts2. Legal Issues3. Argument Analysis4. Conclusion5. Supporting Case Citations`, tools: { caseLawSearch: briefcase.tools.caseLawSearch, precedentAnalysis: briefcase.tools.precedentAnalysis, legalCitation: briefcase.tools.legalCitation }, toolChoice: 'auto', temperature: 0.4 }) let fullText = '' for await (const chunk of textStream) { fullText += chunk onChunk?.(chunk) } return fullText} // Usage with streamingconst brief = await generateLegalBrief( 'Contract dispute over remote work policies...', [ 'Breach of employment contract terms', 'Violation of state labor laws', 'Discriminatory enforcement of policies' ], (chunk) => { // Stream chunks to UI in real-time console.log('New chunk:', chunk) })Framework Integration
Complete examples for popular frameworks and platforms
Next.js API Route
Server-side legal analysis endpoint
Next.js
typescript
// pages/api/legal-analysis.tsimport { NextApiRequest, NextApiResponse } from 'next'import { createBriefcaseLegal } from '@briefcase/ai-sdk-legal'import { generateText } from 'ai' const briefcase = createBriefcaseLegal({ apiKey: process.env.LEGAL_API_KEY!, baseURL: 'https://briefcasebrain.ai/api/v1'}) export default async function handler( req: NextApiRequest, res: NextApiResponse) { if (req.method !== 'POST') { return res.status(405).json({ error: 'Method not allowed' }) } const { query, type = 'general' } = req.body if (!query) { return res.status(400).json({ error: 'Query is required' }) } try { const modelMap = { contract: 'contract-reviewer', case: 'case-law-analyzer', litigation: 'litigation-assistant', general: 'legal-research-pro' } const { text, toolResults } = await generateText({ model: briefcase(modelMap[type] || 'legal-research-pro'), prompt: query, tools: briefcase.tools, toolChoice: 'auto', maxTokens: 2000 }) res.status(200).json({ analysis: text, tools_used: toolResults.map(r => r.toolName), results: toolResults }) } catch (error) { console.error('Legal analysis error:', error) res.status(500).json({ error: 'Failed to analyze legal query', details: error.message }) }}Quick Start Templates
Ready-to-use templates to jumpstart your legal AI application
Legal Chat App
Complete chat interface with legal models
Next.js
React
Vercel AI SDK
Contract Analyzer
Upload and analyze contract documents
Next.js
PDF processing
File uploads
Research Dashboard
Legal research and case law analysis dashboard
React
Charts
Export features
Need custom integration help? Our team can provide consultation and custom integration support. Contact us for enterprise solutions.
Best Practices
Guidelines for building robust AI agent applications
API Key Security
- Store API keys in environment variables
- Never expose keys in client-side code
- Rotate keys regularly
- Use different keys for different environments
Error Handling
- Always handle rate limit errors gracefully
- Implement retry logic with exponential backoff
- Provide meaningful error messages to users
- Log errors for monitoring and debugging
Performance Optimization
- Use streaming for long responses
- Implement caching for repeated queries
- Optimize token usage with precise prompts
- Consider parallel requests for multiple tasks
Legal Accuracy
- Always include disclaimers about AI-generated content
- Encourage legal professional review
- Validate important results manually
- Stay updated with model capabilities and limitations
Ready to Build?
Start building AI agent applications with our comprehensive API and SDK