backstage icon indicating copy to clipboard operation
backstage copied to clipboard

RFC: AI Provider Abstraction Layer for Backstage

Open pguppy opened this issue 7 months ago • 9 comments

📜 Issue Labels

  • [x] Please familiarize yourself with the issue labels used in this project: LABELS.md

🔎 Search Terms

ai provider, llm provider, backstage ai plugin, ai service, openai backstage,
llm abstraction, ai backend plugin, generative ai backstage, ai extension point

🗃️ Project Area

Core Framework

🔖 Need

This need was articulated clearly in a comment on the 2026 roadmap discussion:


AI Service Abstraction for Backstage

One area I'd love to see on the 2026 roadmap is a first-class AI service abstraction in Backstage. A unified way for plugins to consume AI capabilities like text generation, structured output, embeddings, etc. without implementing provider-specific logic.

The Problem

Today, if you want to build a Backstage plugin that uses AI (say, to summarize entities, generate documentation, or assist with scaffolding), you have to:

  1. Pick a specific AI provider (OpenAI, Anthropic, Google, etc.)
  2. Implement the API integration yourself (auth, streaming, error handling, retries)
  3. Manage configuration (API keys, model selection, endpoints)

This means every AI-powered plugin ends up reinventing the wheel, and adopters get locked into whatever provider the plugin author chose.

The Proposal

Introduce an AI backend service (either as a new core service or as a plugin exposing an extension point) that:

  • Exposes a unified API: generateText, streamText, generateObject, embed, etc.
  • Defines an extension point where AI providers register themselves as modules, following the same pattern as auth, search, and catalog providers
  • Lets plugin authors consume AI without caring about the provider

Prior Art

  • Drupal AI module: A core ai module exposes a provider-agnostic service with 48+ providers today.
  • Laravel AI SDK: First-party package using Laravel's driver pattern. Providers are swappable via configuration.
  • Vercel AI SDK: TypeScript/Node.js, same stack as Backstage. Providers are separate npm packages (@ai-sdk/openai, @ai-sdk/anthropic) with unified functions like generateText, streamText, generateObject, embed.

Originally posted by @zeshanziya in #32083


This RFC is a concrete proposal to build exactly what was described above. Teams building AI-powered features inside Backstage, catalog enrichment, scaffolder assistance, search, documentation generation, each need access to an LLM provider. The current state creates several compounding problems:

Fragmented credentials. API keys for OpenAI, Anthropic, and Azure are scattered across plugin configurations with no standard location. Operators have no single place to manage them.

Repeated implementation. Every plugin reinvents provider selection, model resolution, error handling, and health checking. There is no shared surface that other plugins can depend on.

Switching cost. Replacing an LLM provider today requires coordinated changes across multiple plugins. There is no abstraction that makes providers interchangeable.

Framework lock-in at the wrong layer. Several organizations want to use agentic AI frameworks (Mastra, LangGraph.js, OpenAI Agents SDK) inside Backstage but face no standard way to wire LLM providers into those frameworks consistently.

Related discussions: #30047 (Gen AI Agents), #32062 (MCP modeling), #33575 (AIContext kind).

📝 Proposal

Provider protocol: Vercel AI SDK

This proposal builds on the Vercel AI SDK as the provider protocol interface. Specifically, @ai-sdk/provider, the open-source, TypeScript-first language model specification at the core of the AI SDK, defines the contract between the Backstage AI service and any LLM provider. Every provider at ai-sdk.dev/providers/ai-sdk-providers implements this interface.

Why the Vercel AI SDK?

  • TypeScript/Node.js native, same runtime stack as Backstage
  • Open-source provider specification (LanguageModelV3, EmbeddingModelV3) is a stable, versioned contract independent of Vercel's product offering
  • 30+ first-party provider packages (@ai-sdk/openai, @ai-sdk/anthropic, etc.) plus a growing community ecosystem, all interchangeable at the interface level
  • @ai-sdk/openai-compatible covers any OpenAI-compatible endpoint, meaning the interface is future proof as the OpenAI API format becomes an industry standard
  • Already adopted widely in the TypeScript AI ecosystem, familiar to the Backstage contributor base

The @ai-sdk/provider package is a runtime dependency of ai-node. All other @ai-sdk/* packages (the concrete provider implementations) are dependencies of the individual provider modules, keeping ai-backend itself provider-agnostic.


Introduce a set of packages following the established Backstage backend plugin pattern:

@backstage/plugin-ai-common                        (common-library)
@backstage/plugin-ai-node                          (node-library)
@backstage/plugin-ai-backend                       (backend-plugin)

# Dedicated modules — providers with non-OpenAI-compatible protocols
@backstage/plugin-ai-backend-module-openai          @ai-sdk/openai
@backstage/plugin-ai-backend-module-anthropic       @ai-sdk/anthropic
@backstage/plugin-ai-backend-module-google          @ai-sdk/google + @ai-sdk/google-vertex
@backstage/plugin-ai-backend-module-bedrock         @ai-sdk/amazon-bedrock (SigV4 auth)

# Config-driven — covers ALL OpenAI-compatible providers via app-config.yaml
# One module package, N providers from config — no new package per provider.
# Covers: xAI (Grok), Groq, Mistral, Together AI, Fireworks, DeepInfra,
#   Perplexity, Cerebras, DeepSeek, Azure OpenAI, NVIDIA NIM, Hugging Face,
#   Ollama, LM Studio, Alibaba DashScope (Qwen), IBM watsonx.ai, Replicate,
#   AI21 Labs, and any future OpenAI-compatible provider — automatically.
@backstage/plugin-ai-backend-module-openai-compatible  @ai-sdk/openai-compatible

# Optional gateway — 200+ models via a single OpenRouter API key
@backstage/plugin-ai-backend-module-openrouter      @openrouter/ai-sdk-provider

Core abstraction

ai-node exports an AIProvider interface and an aiProvidersExtensionPoint that backend modules use to register providers during Backstage's init phase.

// ai-node — imports the open-source @ai-sdk/provider specification
import type {
  LanguageModelV3,
  EmbeddingModelV3,
  ImageModelV3,
  SpeechModelV3,
  TranscriptionModelV3,
  Experimental_VideoModelV3,
} from '@ai-sdk/provider';

export interface AIProvider {
  readonly metadata: AIProviderMetadata;
  initialize(config: unknown): Promise<void>;
  supports(capability: AICapabilityType): boolean;
  getLanguageModelFactory(): (modelId: string) => LanguageModelV3;
  getEmbeddingModelFactory?(): (modelId: string) => EmbeddingModelV3;
  getImageModelFactory?(): (modelId: string) => ImageModelV3;
  getSpeechModelFactory?(): (modelId: string) => SpeechModelV3;
  getTranscriptionModelFactory?(): (modelId: string) => TranscriptionModelV3;
  getVideoModelFactory?(): (modelId: string) => Experimental_VideoModelV3;  // experimental
  healthCheck(): Promise<{ healthy: boolean; message?: string; latency?: number }>;
  dispose?(): Promise<void>;
}

export enum AICapabilityType {
  TEXT_GENERATION   = 'text-generation',
  STRUCTURED_OUTPUT = 'structured-output',
  EMBEDDINGS        = 'embeddings',
  IMAGE_GENERATION  = 'image-generation',
  VIDEO_GENERATION  = 'video-generation',   // experimental
  SPEECH_TO_TEXT    = 'speech-to-text',
  TEXT_TO_SPEECH    = 'text-to-speech',
}

Provider modules follow the standard backend module pattern

// @backstage/plugin-ai-backend-module-openai
export const aiModuleOpenAI = createBackendModule({
  pluginId: 'ai',
  moduleId: 'openai',
  register(env) {
    env.registerInit({
      deps: {
        config: coreServices.rootConfig,
        logger: coreServices.logger,
        providers: aiProvidersExtensionPoint,
      },
      async init({ config, logger, providers }) {
        const openaiConfig = config.getOptionalConfig('ai.providers.openai');
        if (!openaiConfig) {
          logger.info('OpenAI provider not configured, skipping');
          return;
        }
        const provider = new OpenAIProvider();
        await provider.initialize({
          apiKey: openaiConfig.getString('apiKey'),
          defaultModels: openaiConfig.getOptional('defaultModels'),
        });
        providers.registerProvider(provider, { isDefault: true, priority: 100 });
      },
    });
  },
});

Capability gates — explicit configuration required, no silent defaults

A capability (text generation, embeddings) is disabled unless its model ID is explicitly configured. There are no hardcoded fallback models. This prevents unexpected cost and unintended capability exposure.

# app-config.yaml
ai:
  defaultProvider: openai
  providers:
    openai:
      apiKey: ${OPENAI_API_KEY}
      defaultModels:
        text-generation: gpt-4o
        embeddings: text-embedding-3-large

If defaultModels.text-generation is absent, all text generation calls throw an actionable error pointing to the config key to set.

REST API + typed client

ai-backend exposes an OpenAPI-first REST API at /api/ai/v1/. The schema generates both a server router and a typed client into ai-common, to be used for a frontend clint as well as a backend service.

Key endpoints:

Endpoint Capability
POST /v1/generate Text generation — mirrors generateText()
POST /v1/embed Embeddings — mirrors embed()
POST /v1/generate/image Image generation — mirrors generateImage()
POST /v1/generate/speech Text-to-speech — mirrors generateSpeech()
POST /v1/transcribe Speech-to-text — mirrors transcribe()
POST /v1/generate/video Video generation (experimental) — mirrors experimental_generateVideo()
GET /v1/providers List registered providers and their capabilities
GET /v1/providers/{id}/health Per-provider health check
GET /v1/ready Readiness probe with provider count

The REST API field names deliberately mirror the Vercel AI SDK function signatures for each capability (prompt, messages, system, maxOutputTokens, topP, topK, stopSequences, seed, providerOptions, finishReason, warnings, value for embeddings, voice/outputFormat/speed for speech, aspectRatio/resolution/duration/fps for video). Developers familiar with the AI SDK recognise all fields instantly, there is no translation layer between the HTTP interface and the underlying SDK calls.

Framework freedom

The AI service provides LLM primitives, not an agentic runtime. Teams choose their own framework (Mastra, LangGraph.js, OpenAI Agents SDK) and wire it to the provider via the HTTP client. This avoids the Backstage extension point scope constraint, extension points are plugin-scoped and cannot be consumed by arbitrary other plugins at runtime.

Provider module contribution policy

Publishing this RFC will likely trigger a wave of contribution PRs from developers wanting to add a dedicated module for the provider they use. The following policy governs what is accepted into backstage:

The primary filter: "Can this provider be configured today via ai-backend-module-openai-compatible?" If yes, the PR is declined. The provider is already self-serve via app-config.yaml with no code changes required.

A dedicated module qualifies for core only if all of the following are true:

  • Protocol incompatibility, cannot use @ai-sdk/openai-compatible at all
  • Dedicated first-party @ai-sdk/* package (not a community workaround)
  • Auth complexity beyond API key (e.g., AWS SigV4, GCP service accounts)
  • Demonstrable enterprise Backstage adoption

Current core modules that pass this bar: OpenAI (reference), Anthropic (unique streaming protocol), Google AI/Vertex (proprietary schema + GCP auth), AWS Bedrock (SigV4 auth). All other providers are OpenAI-compatible and are self-serve.

Community path: Providers with a unique protocol but lower adoption should go to backstage/community-plugins, not backstage/backstage.

🔄 Alternatives

Per-plugin SDK management (current state)

Each plugin installs and configures its own @ai-sdk/openai or openai package directly. Simple for a single plugin; does not scale across an organization. No shared credentials, no consistent health checking, no switching cost reduction.

Expose providers as a core BackendService

Model the AI provider as a coreServices.ai alongside DatabaseService and HttpRouterService. This would make a single provider available to all backend plugins via DI. However, organizations need multiple providers (e.g., OpenAI for generation, Ollama for embeddings), and the provider choice itself should be operator-configurable, not hardcoded in the framework. The backend plugin + extension point model handles this more flexibly.

Have you read the Code of Conduct?

Are you willing to submit a PR?

Yes, and I have enough information to get started

pguppy avatar Apr 13 '26 11:04 pguppy

I do already have a PR ready as I already have this implemented in my own backstage instance. Though just looking for some guidance before we get to that, if this is the right direction we want to be heading and ofc make the big decision of if we want to be useing the ai-sdk in backstage at all offically, which I think sets us up well for using a harness like langchain/graph and or mastra. Or if we are wanting to go down the route in backstage of having everything independant and make our own harness.

pguppy avatar Apr 13 '26 11:04 pguppy

Hey :wave: I think that this could be a good topic for the Framework SIG tomorrow? Would you be able to attend and present this? :pray:

benjdlambert avatar Apr 13 '26 14:04 benjdlambert

Hey 👋 I think that this could be a good topic for the Framework SIG tomorrow? Would you be able to attend and present this? 🙏

would love to @benjdlambert thankyou for the offer, didn't even know these were a thing. Happy to start the convo with the community on what our next step forward is in this pace

pguppy avatar Apr 13 '26 15:04 pguppy

I'd also suggest moving this to a Backstage Enhancement Proposal (BEP) as we've learned RFC that are large like this are really hard to comment on and follow up for both the author and the community.

awanlin avatar Apr 13 '26 18:04 awanlin

As requested BEP is up https://github.com/backstage/backstage/pull/33890

pguppy avatar Apr 14 '26 11:04 pguppy

As per discussions from SIG I will re-raise this a service and NOT a plugin

pguppy avatar Apr 14 '26 15:04 pguppy

@pguppy Thanks for picking this up! It's great to see it moving forward. Please let me know if there's anything I can help with — I'd love to collaborate on this.

zeshanziya avatar May 01 '26 01:05 zeshanziya

BEP is ready for review https://github.com/backstage/backstage/pull/33906

pguppy avatar May 05 '26 05:05 pguppy

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jul 05 '26 21:07 github-actions[bot]