Skip to content

Instantly share code, notes, and snippets.

@PetkevichPavel
Created July 19, 2025 19:09
Show Gist options
  • Save PetkevichPavel/92acfdcf2f41d9ec283cf7b1a6f4e6fb to your computer and use it in GitHub Desktop.
Save PetkevichPavel/92acfdcf2f41d9ec283cf7b1a6f4e6fb to your computer and use it in GitHub Desktop.
Claude API Wrapper
import * as functions from 'firebase-functions';
import fetch from 'node-fetch';
const CLAUDE_API_KEY = process.env.CLAUDE_API_KEY;
const CLAUDE_API_URL = 'https://api.anthropic.com/v1/messages';
export const claudeReview = functions.https.onRequest(async (req, res) => {
if (req.method !== 'POST') {
return res.status(405).send('Method Not Allowed');
}
const { diff, prompt } = req.body;
if (!diff || !prompt) {
return res.status(400).json({ error: 'Missing diff or prompt in request body.' });
}
try {
const fullPrompt = `${prompt}\n\n---\n\n${diff}`;
const claudeRes = await fetch(CLAUDE_API_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': CLAUDE_API_KEY || '',
'anthropic-version': '2023-06-01'
},
body: JSON.stringify({
model: 'claude-3-opus-20240229',
max_tokens: 1000,
temperature: 0.3,
messages: [
{
role: 'user',
content: fullPrompt
}
]
})
});
const result = await claudeRes.json();
const message = result?.content?.[0]?.text || 'No content returned.';
return res.status(200).json({ review: message });
} catch (error) {
console.error('Claude API error:', error);
return res.status(500).json({ error: 'Internal error while querying Claude.' });
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment