#20530: feat: add Astrai as implicit provider (intelligent inference router)
docs
agents
size: S
Cluster:
Voice Transcription Enhancements
## Summary
- Adds **[Astrai](https://github.com/beee003/astrai-landing)** as an auto-detected implicit provider in OpenClaw's model catalog
- When `ASTRAI_API_KEY` is set (or an auth profile exists), Astrai appears as a provider with `astrai/auto`, `astrai/gpt-4o`, and `astrai/claude-sonnet-4` models
- Astrai is an AI inference router that auto-selects the optimal model/provider per request based on **cost, latency, and task complexity**
- Uses `openai-completions` API (OpenAI-compatible `/v1/chat/completions`)
### Why Astrai in OpenClaw
OpenClaw already supports 15+ providers, but each requires its own API key and manual model selection. Astrai adds **intelligent routing** — one API key covers all major providers (OpenAI, Anthropic, Google, Groq, DeepInfra, etc.), and `astrai/auto` automatically picks the best model per request:
- Simple chat → cheap models (Groq Llama, DeepInfra)
- Code generation → Claude or Codex
- Complex reasoning → frontier models (GPT-4o, Claude Opus)
Three routing strategies: `balanced` (default), `cheapest`, `fastest`.
### Changes
| File | Change |
|------|--------|
| `src/agents/models-config.providers.ts` | Add `ASTRAI_*` constants, `buildAstraiProvider()`, wire into `resolveImplicitProviders()` |
| `docs/providers/astrai.md` | Full provider documentation (setup, models, config examples) |
| `docs/providers/index.md` | Add Astrai to provider list |
### Usage
```bash
# Set API key
export ASTRAI_API_KEY="sk-astrai-xxxxxxxxxxxx"
# Use automatic model selection
openclaw chat --model astrai/auto "Hello!"
# Route to specific model via cheapest provider
openclaw chat --model astrai/gpt-4o "Write a function..."
```
### How it integrates
Follows the exact same pattern as other implicit providers (venice, together, nvidia, etc.):
- `resolveEnvApiKeyVarName("astrai")` checks for `ASTRAI_API_KEY` env var
- `resolveApiKeyFromProfiles()` checks auth profile store
- `buildAstraiProvider()` returns a `ProviderConfig` with `api: "openai-completions"`
## Test plan
- [ ] Verify `ASTRAI_API_KEY` env var triggers auto-detection
- [ ] Verify `openclaw models list | grep astrai` shows `astrai/auto`, `astrai/gpt-4o`, `astrai/claude-sonnet-4`
- [ ] Verify `openclaw chat --model astrai/auto` works with a valid key
- [ ] Verify existing providers are unaffected when `ASTRAI_API_KEY` is not set
- [ ] Verify docs render correctly in the provider index
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds Astrai as an implicit provider for intelligent inference routing across multiple AI providers. The implementation follows existing patterns (similar to NVIDIA, Venice, etc.) with auto-detection via `ASTRAI_API_KEY` env var and auth profiles.
**Critical issue found:** The `ASTRAI_API_KEY` environment variable won't be detected because the required entry is missing from the `envMap` in `src/agents/model-auth.ts`. This means the provider won't auto-enable even when the env var is set.
The documentation is comprehensive and follows existing provider docs patterns. Code structure matches other OpenAI-compatible providers (uses `openai-completions` API, proper cost/context configuration).
<h3>Confidence Score: 1/5</h3>
- This PR cannot be merged safely due to a critical bug that prevents the core functionality from working
- Score of 1 reflects a blocking logical error: the `ASTRAI_API_KEY` env var won't be recognized because it's not registered in the `envMap` in `model-auth.ts`. Without this registration, users cannot use the provider even if they set the env var correctly. The PR description's test plan explicitly requires verifying env var detection, which will fail. All other aspects (code structure, documentation, patterns) are correct.
- `src/agents/model-auth.ts` requires modification (not included in PR) to add `astrai: "ASTRAI_API_KEY"` to the envMap around line 318
<sub>Last reviewed commit: da18bc8</sub>
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#16258: feat(models): add Mistral AI provider support
by joeVenner · 2026-02-14
76.6%
#20587: feat: add Tetrate Agent Router Service provider
by RicHincapie · 2026-02-19
76.5%
#15742: feat: add Edgee AI Gateway as provider
by manthis · 2026-02-13
76.3%
#12059: feat(agents): Add Azure AI Foundry credential support
by lisanyambere · 2026-02-08
76.1%
#15991: feat: add Novita AI provider support with dynamic model discovery
by Alex-wuhu · 2026-02-14
74.8%
#12020: feat: add AIsa provider, production-grade Chinese AI models
by renning22 · 2026-02-08
74.8%
#20476: Providers: add DigitalOcean Gradient AI inference endpoint
by adugan-do · 2026-02-19
74.2%
#15327: feat:(models): discover ZAI models dynamically for GLM-5 support [A...
by vincentkoc · 2026-02-13
73.6%
#13079: feat: Add OpenAI-compatible API option to CLI for self-hosted models
by MikeWang0316tw · 2026-02-10
73.3%
#10424: feat: Add OVHcloud AI Endpoints as a provider
by eliasto · 2026-02-06
73.1%