Model providers for AStack. Each provider is a component: call it directly, use it in a pipeline, or pass it to an agent.
Website · Docs · Examples · GitHub
npm install @astack-tech/integrations @astack-tech/coreimport { ModelProvider } from '@astack-tech/integrations';
// OpenAI, or any API that speaks the OpenAI chat completions protocol
const model = new ModelProvider.OpenAICompatible({
apiKey: process.env['OPENAI_API_KEY'] ?? '',
model: 'gpt-4o-mini',
});
const text = await model.run('What is flow-based programming?');
const reply = await model.chatCompletion([{ role: 'user', content: 'Hello' }]);OpenAICompatible and Deepseek are also available from the subpath: import { OpenAICompatible, Deepseek } from '@astack-tech/integrations/model-provider'.
| Model | Provider |
|---|---|
| OpenAI | new ModelProvider.OpenAICompatible({ apiKey, model: 'gpt-4o-mini' }) |
| DeepSeek | new ModelProvider.Deepseek({ apiKey }) |
| Qwen, Moonshot and other OpenAI-compatible APIs | new ModelProvider.OpenAICompatible({ apiKey, baseURL, model }) |
| Local models through Ollama or vLLM | new ModelProvider.OpenAICompatible({ apiKey: 'ollama', baseURL: 'http://localhost:11434/v1', model: 'llama3.1' }) |
| Any other API | Implement the ModelProvider interface of @astack-tech/components (chatCompletion(messages)) |
Every provider satisfies the ModelProvider interface of @astack-tech/components, so it can drive Agent and StreamingAgent directly.
Calls any API that speaks the OpenAI chat completions protocol through the official openai client: OpenAI and the compatible endpoints of DeepSeek, Qwen, Moonshot, Ollama, vLLM and others. Tool calling and streaming depend on what the endpoint supports.
| Option | Default | Description |
|---|---|---|
apiKey |
— | API key of the provider |
model |
— | Model name (required) |
baseURL |
https://api.openai.com/v1 |
API base URL |
name |
The model API |
Provider name in errors and logs |
temperature |
0.7 |
Sampling temperature |
maxTokens, topP |
not sent | Optional sampling limits |
systemPrompt |
none | Added before every request |
rawTools / tools |
none | Tools as { name, description, parameters } or in the OpenAI format |
verbose |
false |
Log API errors to the console |
| Method | Returns |
|---|---|
run(prompt) |
Text |
run(messages), chatCompletion(messages, { temporaryTools }) |
Assistant message with content, tool_calls and usage |
streamChatCompletion(messages, options) |
Async generator of text, tool-call and usage chunks |
generateCompletion(prompt) |
Text, or the JSON assistant message when the model calls tools |
Messages are checked before the request: the role must be system, user, assistant or tool, and a tool message needs tool_call_id. Otherwise the call fails without reaching the API.
| Pipeline input port | Output port |
|---|---|
prompt |
completion |
messages |
message |
A value of the wrong type on an input port rejects the pipeline run with a TypeError before the API is called.
OpenAICompatible with DeepSeek's defaults. Methods, ports and the other options are the same.
const model = new ModelProvider.Deepseek({ apiKey: process.env['DEEPSEEK_API_KEY'] ?? '' });| Option | Default | Description |
|---|---|---|
apiKey |
— | DeepSeek API key |
model |
deepseek-chat |
Model name |
baseURL |
https://api.deepseek.com/v1 |
API base URL |
- API reference: every export, generated from the source
- Model providers, including how to write your own
- Examples: chat, custom model
| Package | Purpose |
|---|---|
@astack-tech/core |
Component, Pipeline and ports |
@astack-tech/components |
Agents, text splitting and tool invocation |
@astack-tech/tools |
Tool definitions for agents |
@astack-tech/integrations |
Model providers |
MIT. AStack is in public beta: APIs can change between beta releases. See CHANGELOG.md.
