mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-11 17:26:45 +02:00
Merge pull request #109 from R0m1k3/claude/openrouter-api-404-h97d7e
fix(openrouter): resolve AI generation 401/404 errors
This commit is contained in:
2 files changed
+11
-3
No files matched your search
@@ -12,6 +12,7 @@ interface GeneratedText {
|
|||||||
characterCount: number;
|
characterCount: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import crypto from 'crypto';
|
||||||
import { storage } from '../storage';
|
import { storage } from '../storage';
|
||||||
|
|
||||||
export class OpenRouterService {
|
export class OpenRouterService {
|
||||||
@@ -26,16 +27,23 @@ export class OpenRouterService {
|
|||||||
throw new Error('Configuration OpenRouter non trouvée. Veuillez demander à un administrateur de configurer OpenRouter dans les Paramètres.');
|
throw new Error('Configuration OpenRouter non trouvée. Veuillez demander à un administrateur de configurer OpenRouter dans les Paramètres.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!config.apiKey || !config.apiKey.trim()) {
|
||||||
|
throw new Error('Clé API OpenRouter manquante ou vide en base de données. Veuillez la ressaisir dans les Paramètres.');
|
||||||
|
}
|
||||||
|
|
||||||
const prompt = this.buildPrompt(productInfo, config.systemPrompt);
|
const prompt = this.buildPrompt(productInfo, config.systemPrompt);
|
||||||
|
|
||||||
// Use provided model or fall back to config model
|
// Use provided model or fall back to config model
|
||||||
const modelToUse = modelOverride || config.model;
|
const modelToUse = modelOverride || config.model;
|
||||||
|
|
||||||
|
const keyFingerprint = crypto.createHash('sha256').update(config.apiKey).digest('hex').slice(0, 8);
|
||||||
|
console.log(`[OpenRouter] Generating with model="${modelToUse}" keyFingerprint=${keyFingerprint} keyLength=${config.apiKey.length} configUserId=${config.userId}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(this.baseUrl, {
|
const response = await fetch(this.baseUrl, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Authorization": `Bearer ${config.apiKey}`,
|
"Authorization": `Bearer ${config.apiKey.trim()}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"HTTP-Referer": process.env.APP_URL || "http://localhost:5555",
|
"HTTP-Referer": process.env.APP_URL || "http://localhost:5555",
|
||||||
"X-Title": "Social Flow"
|
"X-Title": "Social Flow"
|
||||||
|
|||||||
+1
-1
@@ -394,7 +394,7 @@ export const insertOpenrouterConfigSchema = createInsertSchema(openrouterConfig)
|
|||||||
createdAt: true,
|
createdAt: true,
|
||||||
updatedAt: true,
|
updatedAt: true,
|
||||||
}).extend({
|
}).extend({
|
||||||
apiKey: z.string().min(1, "La clé API ne peut pas être vide"),
|
apiKey: z.string().trim().min(1, "La clé API ne peut pas être vide"),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const updateOpenrouterConfigSchema = insertOpenrouterConfigSchema.partial({
|
export const updateOpenrouterConfigSchema = insertOpenrouterConfigSchema.partial({
|
||||||
|
|||||||
Reference in new issue
Block a user