home / skills / lookatitude / beluga-ai / provider-implementation
This skill helps you implement providers for Beluga AI v2 registries across LLM, embedding, vectorstore, voice, and more.
npx playbooks add skill lookatitude/beluga-ai --skill provider-implementationReview the files below or copy the command above to add this skill to your agents.
---
name: provider-implementation
description: Implementing providers for Beluga AI v2 registries. Use when creating LLM, embedding, vectorstore, voice, or any other provider.
---
# Provider Implementation
## Checklist
1. Implement the full interface (ChatModel, Embedder, VectorStore, STT, TTS, etc.).
2. Register via `init()` with parent package's `Register()`.
3. Map provider errors to `core.Error` with correct ErrorCode.
4. Support context cancellation.
5. Include token/usage metrics where applicable.
6. Compile-time check: `var _ Interface = (*Impl)(nil)`.
7. Unit tests with mocked HTTP responses (httptest).
## File Structure
```
llm/providers/openai/
├── openai.go # Implementation + New() + init()
├── stream.go # Streaming
├── errors.go # Error mapping
├── openai_test.go # Tests
└── testdata/ # Recorded HTTP responses
```
## Template
```go
var _ llm.ChatModel = (*Model)(nil)
func init() {
llm.Register("openai", func(cfg llm.ProviderConfig) (llm.ChatModel, error) { return New(cfg) })
}
func New(cfg llm.ProviderConfig) (*Model, error) {
if cfg.APIKey == "" { return nil, &core.Error{Op: "openai.new", Code: core.ErrAuth, Message: "API key required"} }
return &Model{client: newClient(cfg.APIKey, cfg.BaseURL), model: cfg.Model}, nil
}
func (m *Model) Stream(ctx context.Context, msgs []schema.Message, opts ...llm.GenerateOption) iter.Seq2[schema.StreamChunk, error] {
return func(yield func(schema.StreamChunk, error) bool) { /* stream implementation */ }
}
```
## Error Mapping
```go
switch apiErr.StatusCode {
case 401: code = core.ErrAuth
case 429: code = core.ErrRateLimit
case 408, 504: code = core.ErrTimeout
case 400: code = core.ErrInvalidInput
}
```
See `docs/providers.md` for provider categories and priorities.
This skill guides implementing providers for Beluga AI v2 registries. It explains required interfaces, registration, error mapping, tests, and practical file layout so new providers integrate reliably with the runtime. The guidance is concise and focused on outcomes: correctness, observability, and graceful cancellation.
The skill inspects the provider implementation checklist and a minimal Go template to ensure each provider implements the full interface (ChatModel, Embedder, VectorStore, STT, TTS, etc.). It enforces registration via init(), maps external API errors to core.Error with proper ErrorCode, supports context cancellation, and recommends usage metrics and compile-time interface checks. It also outlines test strategy using httptest and recorded responses.
What compile-time checks should I add?
Include a var _ Interface = (*Impl)(nil) assertion for every interface your provider implements to catch mismatches at compile time.
How do I map external HTTP errors to core.Error codes?
Translate status codes to core.ErrAuth for 401, core.ErrRateLimit for 429, core.ErrTimeout for 408/504, and core.ErrInvalidInput for 400; include the original op and message for debugging.