Add User-Agent header for Anthropic API calls (#5174)
* Add User-Agent header for Anthropic API calls
Passes User-Agent: AnythingLLM/{version} to the Anthropic SDK
so Anthropic can identify traffic from AnythingLLM.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* remove test, simplify header default
* unset change to spread
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Timothy Carambat <rambat1010@gmail.com>
This commit is contained in:
parent
192ca411f2
commit
9d242bc053
@ -9,6 +9,7 @@ const { MODEL_MAP } = require("../modelMap");
|
||||
const {
|
||||
LLMPerformanceMonitor,
|
||||
} = require("../../helpers/chat/LLMPerformanceMonitor");
|
||||
const { getAnythingLLMUserAgent } = require("../../../endpoints/utils");
|
||||
|
||||
class AnthropicLLM {
|
||||
constructor(embedder = null, modelPreference = null) {
|
||||
@ -20,6 +21,9 @@ class AnthropicLLM {
|
||||
const AnthropicAI = require("@anthropic-ai/sdk");
|
||||
const anthropic = new AnthropicAI({
|
||||
apiKey: process.env.ANTHROPIC_API_KEY,
|
||||
defaultHeaders: {
|
||||
"User-Agent": getAnythingLLMUserAgent(),
|
||||
},
|
||||
});
|
||||
this.anthropic = anthropic;
|
||||
this.model =
|
||||
|
||||
@ -3,6 +3,7 @@ const { RetryError } = require("../error.js");
|
||||
const Provider = require("./ai-provider.js");
|
||||
const { v4 } = require("uuid");
|
||||
const { safeJsonParse } = require("../../../http");
|
||||
const { getAnythingLLMUserAgent } = require("../../../../endpoints/utils");
|
||||
|
||||
/**
|
||||
* The agent provider for the Anthropic API.
|
||||
@ -16,6 +17,9 @@ class AnthropicProvider extends Provider {
|
||||
options = {
|
||||
apiKey: process.env.ANTHROPIC_API_KEY,
|
||||
maxRetries: 3,
|
||||
defaultHeaders: {
|
||||
"User-Agent": getAnythingLLMUserAgent(),
|
||||
},
|
||||
},
|
||||
model = "claude-3-5-sonnet-20240620",
|
||||
} = config;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user