Skip to content

AI Provider types, registry, and configuration #19

@anurag629

Description

@anurag629

Phase 1 — Foundation (1/4)

Define the core type system and provider registry for the multi-provider AI integration.

Scope

src/lib/ai/types.ts

  • AIProvider enum: openai, anthropic, google, groq, openrouter
  • AIModel interface: { id, name, provider, maxTokens, description }
  • AIProviderConfig interface: { id, name, baseUrl, models[], headerBuilder(apiKey), validateEndpoint }
  • AIGenerateRequest interface: { provider, apiKey, model, prompt, maxTokens?, temperature? }
  • AIGenerateResponse interface: { content, model, usage? }
  • AIValidationResult interface: { valid, error?, provider }

src/lib/ai/providers.ts

  • Provider registry map with config for each provider:
    • OpenAI: base URL, auth header format, available models (gpt-4o, gpt-4o-mini)
    • Anthropic: base URL, x-api-key + anthropic-version headers, models (claude-sonnet-4-6, claude-haiku-4-5)
    • Google: generativelanguage.googleapis.com, key-as-param, models (gemini-2.0-flash, gemini-2.5-pro)
    • Groq: OpenAI-compatible base URL, models (llama-3.3-70b, mixtral-8x7b)
    • OpenRouter: base URL, models (flexible — let users pick any)
  • Helper functions: getProvider(id), getModelsForProvider(id), getDefaultModel(providerId)
  • Each provider config includes the request body formatter (OpenAI-style vs Anthropic-style vs Google-style)

Acceptance Criteria

  • All 5 providers defined with at least 2 models each
  • Type exports are clean and well-documented
  • Provider configs include correct API base URLs, header builders, and body formatters
  • No runtime dependencies added — pure TypeScript definitions

Technical Notes

  • OpenAI, Groq, and OpenRouter all use the OpenAI-compatible chat completions format
  • Anthropic uses its own messages format (/v1/messages)
  • Google uses the Gemini format (/v1beta/models/{model}:generateContent)
  • Keep the registry extensible — adding a new provider should be one object addition

Metadata

Metadata

Assignees

No one assigned

    Labels

    aiAI-powered featuresfeatureNew feature requestphase-1Foundation / infrastructure

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions