@2ndopinion/sdk
v0.3.1
Published
Official JavaScript/TypeScript SDK for 2ndOpinion — AI-to-AI code review where Claude, Codex, and Gemini review your code together
Downloads
95
Maintainers
Readme
@2ndopinion/sdk
Official JavaScript/TypeScript SDK for 2ndOpinion — the AI-to-AI code review platform where Claude, Codex, and Gemini review your code together.
Installation
npm install @2ndopinion/sdkQuick Start
import { SecondOpinion } from '@2ndopinion/sdk';
const client = new SecondOpinion('sk_2op_your_key_here');
// Get a code review
const result = await client.opinion({
diff: `--- a/auth.js\n+++ b/auth.js\n@@ -1,3 +1,3 @@\n-const token = req.headers.authorization;\n+const token = req.query.token;`,
llm: 'codex',
});
console.log(result.analysis.summary);
console.log(result.analysis.recommendation); // 'accept' | 'review' | 'reject'Methods
| Method | Description | Credits |
|--------|-------------|---------|
| opinion(diff, llm?, context?) | Single-model code review with risk analysis | 1 |
| review(diff, llm?, context?) | Alias for opinion | 1 |
| ask(question, llm?, code?, context?) | Ask an AI model a question about code | 1 |
| batch(files[], llm?) | Analyze up to 20 files concurrently | 1 each |
| status() | Check account credits, tier, and usage | 0 |
| stream(diff, llm?, context?) | SSE streaming analysis | 1 |
Examples
Ask a Question
const answer = await client.ask({
question: 'Is this SQL query vulnerable to injection?',
code: `db.query("SELECT * FROM users WHERE id = " + userId)`,
llm: 'claude',
});
console.log(answer.response);Check Usage
const usage = await client.status();
console.log(`${usage.totalAvailable} credits remaining (${usage.tier} plan)`);Streaming
for await (const chunk of client.stream({ diff: myDiff, llm: 'gemini' })) {
process.stdout.write(chunk);
}Batch Review
const results = await client.batch({
files: [
{ path: 'auth.js', diff: authDiff },
{ path: 'db.js', diff: dbDiff },
],
});
results.forEach(r => console.log(`${r.file}: ${r.analysis.recommendation}`));Error Handling
import { SecondOpinion, SecondOpinionError } from '@2ndopinion/sdk';
try {
const result = await client.opinion({ diff: myDiff });
} catch (err) {
if (err instanceof SecondOpinionError) {
switch (err.code) {
case 'RATE_LIMIT': // Wait and retry
case 'INSUFFICIENT_CREDITS': // Upgrade plan
case 'UNAUTHORIZED': // Check API key
}
}
}CI/CD Usage
Use the SDK in Node.js scripts for automated pipelines:
import { SecondOpinion } from '@2ndopinion/sdk';
import { execSync } from 'child_process';
const client = new SecondOpinion(process.env.SECONDOPINION_API_KEY!);
const diff = execSync('git diff HEAD~1').toString();
const result = await client.opinion({ diff, llm: 'codex' });
if (result.analysis.recommendation === 'reject') {
console.error('Code review failed:', result.analysis.summary);
process.exit(1);
}Or use the CLI directly with --ci for JSON output:
npx 2ndopinion analyze --ci | jq '.verdict'Get an API Key
- Sign up at get2ndopinion.dev/signup
- Go to Dashboard > API Keys
- Create a key and use it in the constructor
Pricing
Free tier includes 5 credits/month. See all plans.
Links
- Documentation
- API Reference
- Playground — try without signing up
- Pricing
- Support
