Add optional ANTHROPIC_API_BASE_URL
This commit is contained in:
@@ -2,6 +2,9 @@
|
|||||||
ANTHROPIC_API_KEY=your_anthropic_api_key_here # Format: sk-ant-api03-...
|
ANTHROPIC_API_KEY=your_anthropic_api_key_here # Format: sk-ant-api03-...
|
||||||
PERPLEXITY_API_KEY=your_perplexity_api_key_here # Format: pplx-...
|
PERPLEXITY_API_KEY=your_perplexity_api_key_here # Format: pplx-...
|
||||||
|
|
||||||
|
# API Base URLs (Optional)
|
||||||
|
ANTHROPIC_API_BASE_URL=optional_base_url_here # Optional custom base URL for Anthropic API
|
||||||
|
|
||||||
# Model Configuration
|
# Model Configuration
|
||||||
MODEL=claude-3-7-sonnet-20250219 # Recommended models: claude-3-7-sonnet-20250219, claude-3-opus-20240229
|
MODEL=claude-3-7-sonnet-20250219 # Recommended models: claude-3-7-sonnet-20250219, claude-3-opus-20240229
|
||||||
PERPLEXITY_MODEL=sonar-pro # Perplexity model for research-backed subtasks
|
PERPLEXITY_MODEL=sonar-pro # Perplexity model for research-backed subtasks
|
||||||
|
|||||||
@@ -3784,6 +3784,7 @@ In this tutorial, you'll learn how to build a LLM-powered chatbot client that co
|
|||||||
if (!ANTHROPIC_API_KEY) {
|
if (!ANTHROPIC_API_KEY) {
|
||||||
throw new Error("ANTHROPIC_API_KEY is not set");
|
throw new Error("ANTHROPIC_API_KEY is not set");
|
||||||
}
|
}
|
||||||
|
const ANTHROPIC_API_BASE_URL = process.env.ANTHROPIC_API_BASE_URL;
|
||||||
|
|
||||||
class MCPClient {
|
class MCPClient {
|
||||||
private mcp: Client;
|
private mcp: Client;
|
||||||
@@ -3794,6 +3795,7 @@ In this tutorial, you'll learn how to build a LLM-powered chatbot client that co
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.anthropic = new Anthropic({
|
this.anthropic = new Anthropic({
|
||||||
apiKey: ANTHROPIC_API_KEY,
|
apiKey: ANTHROPIC_API_KEY,
|
||||||
|
baseUrl: ANTHROPIC_API_BASE_URL,
|
||||||
});
|
});
|
||||||
this.mcp = new Client({ name: "mcp-client-cli", version: "1.0.0" });
|
this.mcp = new Client({ name: "mcp-client-cli", version: "1.0.0" });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,9 +35,13 @@ export function getAnthropicClientForMCP(session, log = console) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const baseURL =
|
||||||
|
session?.env?.ANTHROPIC_API_BASE_URL || process.env.ANTHROPIC_API_BASE_URL;
|
||||||
|
|
||||||
// Initialize and return a new Anthropic client
|
// Initialize and return a new Anthropic client
|
||||||
return new Anthropic({
|
return new Anthropic({
|
||||||
apiKey,
|
apiKey,
|
||||||
|
baseURL: baseURL, // Will be undefined if not set, defaulting to Anthropic's standard URL
|
||||||
defaultHeaders: {
|
defaultHeaders: {
|
||||||
'anthropic-beta': 'output-128k-2025-02-19' // Include header for increased token limit
|
'anthropic-beta': 'output-128k-2025-02-19' // Include header for increased token limit
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ dotenv.config();
|
|||||||
// Configure Anthropic client
|
// Configure Anthropic client
|
||||||
const anthropic = new Anthropic({
|
const anthropic = new Anthropic({
|
||||||
apiKey: process.env.ANTHROPIC_API_KEY,
|
apiKey: process.env.ANTHROPIC_API_KEY,
|
||||||
|
baseURL: process.env.ANTHROPIC_API_BASE_URL,
|
||||||
// Add beta header for 128k token output
|
// Add beta header for 128k token output
|
||||||
defaultHeaders: {
|
defaultHeaders: {
|
||||||
'anthropic-beta': 'output-128k-2025-02-19'
|
'anthropic-beta': 'output-128k-2025-02-19'
|
||||||
@@ -1297,8 +1298,11 @@ function getAnthropicClient(session) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const baseUrl = session?.env?.ANTHROPIC_API_BASE_URL || process.env.ANTHROPIC_API_BASE_URL;
|
||||||
|
|
||||||
return new Anthropic({
|
return new Anthropic({
|
||||||
apiKey: apiKey,
|
apiKey: apiKey,
|
||||||
|
baseURL: baseUrl,
|
||||||
// Add beta header for 128k token output
|
// Add beta header for 128k token output
|
||||||
defaultHeaders: {
|
defaultHeaders: {
|
||||||
'anthropic-beta': 'output-128k-2025-02-19'
|
'anthropic-beta': 'output-128k-2025-02-19'
|
||||||
@@ -1465,6 +1469,11 @@ function getConfiguredAnthropicClient(session = null, customEnv = null) {
|
|||||||
process.env.ANTHROPIC_API_KEY ||
|
process.env.ANTHROPIC_API_KEY ||
|
||||||
customEnv?.ANTHROPIC_API_KEY;
|
customEnv?.ANTHROPIC_API_KEY;
|
||||||
|
|
||||||
|
const baseUrl =
|
||||||
|
session?.ANTHROPIC_API_BASE_URL ||
|
||||||
|
process?.env?.ANTHROPIC_API_BASE_URL ||
|
||||||
|
customEnv.env.ANTHROPIC_API_BASE_URL;
|
||||||
|
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'ANTHROPIC_API_KEY environment variable is missing. Set it to use AI features.'
|
'ANTHROPIC_API_KEY environment variable is missing. Set it to use AI features.'
|
||||||
@@ -1473,6 +1482,7 @@ function getConfiguredAnthropicClient(session = null, customEnv = null) {
|
|||||||
|
|
||||||
return new Anthropic({
|
return new Anthropic({
|
||||||
apiKey: apiKey,
|
apiKey: apiKey,
|
||||||
|
baseURL: baseUrl,
|
||||||
// Add beta header for 128k token output
|
// Add beta header for 128k token output
|
||||||
defaultHeaders: {
|
defaultHeaders: {
|
||||||
'anthropic-beta': 'output-128k-2025-02-19'
|
'anthropic-beta': 'output-128k-2025-02-19'
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ import { generateTaskFiles } from './task-manager.js';
|
|||||||
|
|
||||||
// Initialize Anthropic client
|
// Initialize Anthropic client
|
||||||
const anthropic = new Anthropic({
|
const anthropic = new Anthropic({
|
||||||
apiKey: process.env.ANTHROPIC_API_KEY
|
apiKey: process.env.ANTHROPIC_API_KEY,
|
||||||
|
baseURL: process.env.ANTHROPIC_API_BASE_URL
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ import {
|
|||||||
|
|
||||||
// Initialize Anthropic client
|
// Initialize Anthropic client
|
||||||
const anthropic = new Anthropic({
|
const anthropic = new Anthropic({
|
||||||
apiKey: process.env.ANTHROPIC_API_KEY
|
apiKey: process.env.ANTHROPIC_API_KEY,
|
||||||
|
baseURL: process.env.ANTHROPIC_API_BASE_URL
|
||||||
});
|
});
|
||||||
|
|
||||||
// Import perplexity if available
|
// Import perplexity if available
|
||||||
|
|||||||
Reference in New Issue
Block a user