@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
148 lines (147 loc) • 5.98 kB
TypeScript
import { type LanguageModel } from "ai";
import { type AIProviderName } from "../constants/enums.js";
import { BaseProvider } from "../core/baseProvider.js";
import type { AnthropicProviderConfig, StreamOptions, StreamResult, ValidationSchema, EnhancedGenerateResult, TextGenerationOptions, AnthropicAuthMethod, AnthropicResponseMetadata, ClaudeSubscriptionTier, ClaudeUsageInfo } from "../types/index.js";
/**
* Beta headers for Claude Code integration.
* These enable experimental features:
* - claude-code-20250219: Claude Code specific features
* - fine-grained-tool-streaming-2025-05-14: Fine-grained tool streaming
*
* Note: interleaved-thinking-2025-05-14 was removed — it was claude-3-7-sonnet
* specific and causes invalid_request_error (HTTP 400) on claude-4 models
* (claude-opus-4-6, claude-sonnet-4-6) which handle thinking via the
* `thinking` request body parameter instead.
*/
declare const ANTHROPIC_BETA_HEADERS: {
"anthropic-beta": string;
};
/**
* Anthropic Provider v2 - BaseProvider Implementation
* Enhanced with OAuth support, subscription tiers, and beta headers for Claude Code integration.
*/
export declare class AnthropicProvider extends BaseProvider {
private model;
private readonly authMethod;
private readonly subscriptionTier;
private readonly enableBetaFeatures;
private oauthToken;
private lastResponseMetadata;
private usageInfo;
private refreshPromise?;
/**
* Create a new Anthropic provider instance.
*
* @param modelName - Optional model name to use (defaults to CLAUDE_3_5_SONNET)
* @param sdk - Optional NeuroLink SDK instance
* @param config - Optional configuration options for auth, subscription tier, and beta features
*/
constructor(modelName?: string, sdk?: unknown, config?: AnthropicProviderConfig, credentials?: {
apiKey?: string;
oauthToken?: string;
});
/**
* Get authentication headers based on current auth method and configuration.
*
* @returns Headers object containing auth and beta feature headers
*/
getAuthHeaders(): Record<string, string>;
/**
* Validate if a model is accessible with the current subscription tier.
*
* @param model - The model ID to validate
* @returns true if the model is accessible, false otherwise
*
* @example
* ```typescript
* const provider = new AnthropicProvider();
* if (provider.validateModelAccess("claude-opus-4-5-20251101")) {
* // Use the model
* } else {
* // Fall back to a different model or show upgrade prompt
* }
* ```
*/
validateModelAccess(model: string): boolean;
/**
* Get current usage information.
*
* Returns usage tracking data including messages sent, tokens consumed,
* and remaining quotas. This information is updated after each API request.
*
* @returns Current usage info or null if no requests have been made
*
* @example
* ```typescript
* const usage = provider.getUsageInfo();
* if (usage && usage.tokenQuotaPercent > 80) {
* console.warn("Approaching token quota limit");
* }
* ```
*/
getUsageInfo(): ClaudeUsageInfo | null;
/**
* Check if beta features are enabled for this provider instance.
*
* @returns true if beta features are enabled
*/
areBetaFeaturesEnabled(): boolean;
/**
* Get model capabilities for the current model.
*
* @returns The model capabilities or undefined if not found
*/
getModelCapabilities(): import("../index.js").AnthropicModelMetadata | undefined;
/**
* Get the current subscription tier.
* @returns The detected or configured subscription tier
*/
getSubscriptionTier(): ClaudeSubscriptionTier;
/**
* Get the authentication method being used.
* @returns The current authentication method
*/
getAuthMethod(): AnthropicAuthMethod;
/**
* Refresh OAuth token if needed and possible.
* This method checks if the token is expired or about to expire,
* and attempts to refresh it using the refresh token if available.
*
* @returns Promise that resolves when refresh is complete (or not needed)
* @throws Error if refresh is needed but fails
*/
refreshAuthIfNeeded(): Promise<void>;
/**
* Get the last response metadata including rate limit information.
* @returns The last response metadata or null if no request has been made
*/
getLastResponseMetadata(): AnthropicResponseMetadata | null;
/**
* Update response metadata from API response headers.
* This should be called after each API request to track rate limits.
* @param headers - Response headers from the API
* @param requestId - Optional request ID
*/
protected updateResponseMetadata(headers: Headers | Record<string, string>, requestId?: string, usageUpdate?: {
inputTokens?: number;
outputTokens?: number;
}): void;
getProviderName(): AIProviderName;
getDefaultModel(): string;
/**
* Returns the Vercel AI SDK model instance for Anthropic
*/
getAISDKModel(): LanguageModel;
protected formatProviderError(error: unknown): Error;
/**
* Override generate to refresh the OAuth token before delegating to
* BaseProvider so that expired tokens are renewed automatically.
*/
generate(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ValidationSchema): Promise<EnhancedGenerateResult | null>;
protected executeStream(options: StreamOptions, _analysisSchema?: ValidationSchema): Promise<StreamResult>;
isAvailable(): Promise<boolean>;
getModel(): LanguageModel;
}
export { getModelCapabilities, getRecommendedModelForTier, isModelAvailableForTier, ModelAccessError, } from "../models/anthropicModels.js";
export { ANTHROPIC_BETA_HEADERS };
export default AnthropicProvider;