Skip to content
Robotadocs

@robota-sdk/agent-provider/openai-compatible

OpenAI-compatible providers for the Robota SDK: DeepSeekProvider (@robota-sdk/agent-provider/deepseek), QwenProvider (@robota-sdk/agent-provider/qwen) and GemmaProvider (@robota-sdk/agent-provider/gemma). Each one speaks the OpenAI-compatible protocol through the openai SDK and implements the @robota-sdk/agent-core provider contract, so it can be passed to a ConversationAgent agent like any other provider. The shared OpenAI-compatible protocol code (message and tool conversion, request building, response parsing, stream assembly) is the @robota-sdk/agent-provider/openai-compatible subpath; these providers and @robota-sdk/agent-provider/openai are built on it.

Installation

npm install @robota-sdk/agent-provider @robota-sdk/agent-core openai

openai is an optional peer dependency of the package (^6.0.0).

Usage

import { ConversationAgent } from '@robota-sdk/agent-core';
import { DeepSeekProvider } from '@robota-sdk/agent-provider/deepseek';
 
const provider = new DeepSeekProvider({ apiKey: process.env.DEEPSEEK_API_KEY });
 
const agent = new ConversationAgent({
  name: 'MyAgent',
  aiProviders: [provider],
  defaultModel: { provider: 'deepseek', model: 'deepseek-v4-flash' },
});
 
const response = await agent.run('Hello!');
console.log(response);

The other providers are constructed the same way:

import { GemmaProvider } from '@robota-sdk/agent-provider/gemma';
import { QwenProvider } from '@robota-sdk/agent-provider/qwen';
 
const qwen = new QwenProvider({ apiKey: process.env.DASHSCOPE_API_KEY });
 
// A local OpenAI-compatible server, e.g. LM Studio
const gemma = new GemmaProvider({ apiKey: 'lm-studio', baseURL: 'http://localhost:1234/v1' });

Providers

ProviderImport pathdefaultModel.providerDefault endpoint
DeepSeekProvider@robota-sdk/agent-provider/deepseek'deepseek'https://api.deepseek.com
QwenProvider@robota-sdk/agent-provider/qwen'qwen'DashScope OpenAI-compatible endpoint (Singapore region)
GemmaProvider@robota-sdk/agent-provider/gemma'gemma'None: set baseURL to the server hosting the model

Each provider adds a few options and behaviors of its own:

  • DeepSeek: thinking ('enabled' | 'disabled') and reasoningEffort are sent as DeepSeek's thinking and reasoning_effort request fields.
  • Qwen: turning on builtInWebTools.webSearch or builtInWebTools.webFetch switches requests to DashScope's Responses endpoint with its server-side web search and web extractor tools; builtInWebTools.enableThinking is sent as enable_thinking on those requests. responsesBaseURL overrides the Responses endpoint. QWEN_PROVIDER_BASE_URLS and QWEN_PROVIDER_RESPONSES_BASE_URLS hold the DashScope endpoints per region (singapore, usVirginia, beijing, and hongKong for Chat Completions only); the default is singapore.
  • Gemma: removes Gemma's reasoning-channel text from visible output and turns tool calls the model writes as text into structured tool calls. The gemma provider definition (used by @robota-sdk/agent-provider/builtin) defaults to a local server at http://localhost:1234/v1.

Common options

All three providers accept these options. One of apiKey, client or executor is required; the constructor throws otherwise.

OptionTypeDescription
apiKeystringAPI key used to create the openai client.
baseURLstringEndpoint base URL. Any OpenAI-compatible server works; model ids are passed through verbatim.
timeoutnumberRequest timeout in milliseconds.
defaultModelstringModel used when a call does not name one.
clientOpenAIA pre-built openai client, used instead of apiKey.
executorIExecutorDelegates chat calls to an executor instead of calling the API directly.
loggerILoggerLogger for internal provider messages (silent by default).

Errors

A failed API call throws a typed error from @robota-sdk/agent-core: RateLimitError (with retryAfter from the retry-after header), AuthenticationError, ModelNotAvailableError or NetworkError when the failure is one of those, otherwise a ProviderError that carries the HTTP status and the error type the endpoint reported and keeps the SDK error as originalError. Streaming calls map failures the same way. An aborted call rethrows the abort unchanged. See Provider failures.

Exports

  • @robota-sdk/agent-provider/deepseek: DeepSeekProvider, its option types, createDeepSeekProviderDefinition() and the default constants (for example DEFAULT_DEEPSEEK_PROVIDER_MODEL, DEFAULT_DEEPSEEK_PROVIDER_BASE_URL).
  • @robota-sdk/agent-provider/qwen: QwenProvider, its option types, createQwenProviderDefinition() and the default constants, including the regional endpoint tables.
  • @robota-sdk/agent-provider/gemma: GemmaProvider, its option types, createGemmaProviderDefinition() and the reasoning and tool-call text projectors.
  • @robota-sdk/agent-provider/openai-compatible: the shared protocol layer, including convertToOpenAICompatibleMessages, convertToOpenAICompatibleTools, buildOpenAICompatibleRequestParams, OpenAICompatibleResponseParser, assembleOpenAICompatibleStream and probeOpenAICompatibleProfile.

The definitions are the ones Robota's built-in provider registry uses; their API-key references are $ENV:DEEPSEEK_API_KEY and $ENV:DASHSCOPE_API_KEY. The Gemma definition has no API-key default and requires none.

See SPEC.md for the package contract.

License

This package is dual-licensed under the GNU AGPL-3.0 or a commercial license. See LICENSING.md.