How Sim Studio Integrates with LLM Providers Like OpenAI and Anthropic

Sim Studio unifies OpenAI, Anthropic, and other providers through a three-layer architecture that treats every LLM as a first-class resource with centralized metadata, runtime resolution utilities, and OpenAI-compatible streaming abstractions.

Sim Studio (simstudioai/sim) abstracts API differences between AI providers by routing all requests through a provider-agnostic pipeline defined in apps/sim/providers/. This architecture enables automatic key rotation in hosted environments, consistent tool calling across models, and unified cost tracking while supporting both direct API access and OpenAI-compatible endpoints including Azure-hosted Anthropic models.

The Three-Layer Provider Architecture

The integration is built on three tightly coupled layers that separate metadata definition from runtime execution.

Provider Catalog: Centralized Metadata in models.ts

The PROVIDER_DEFINITIONS constant in apps/sim/providers/models.ts serves as the single source of truth for every LLM provider. Each entry—including OpenAI and Anthropic—declares available models, pricing per token, temperature ranges, and capability flags like toolUsageControl.

According to the simstudioai/sim source code, this catalog uses regex patterns to identify models. For example, Anthropic models accessed via Azure match the pattern /^azure-anthropic\//, allowing the system to resolve azure-anthropic/claude-opus-4-6 to the correct endpoint configuration while retaining the same metadata structure as direct Anthropic access.

Runtime Utilities: Resolution and Secrets in utils.ts

The apps/sim/providers/utils.ts file contains the core runtime logic for provider resolution and authentication. Key functions include:

  • getProviderFromModel(model): Resolves any model string (e.g., "gpt-4o") to its provider ID ("openai") using the catalog patterns.
  • getApiKey(providerId, model, userProvidedKey): Retrieves API keys, automatically invoking getRotatingApiKey for hosted OpenAI and Anthropic environments while returning user-provided keys or placeholders ('empty') for self-hosted models like vLLM.
  • isProviderBlacklisted and isModelBlacklisted: Gate checks that validate provider availability before request execution.

OpenAI-Compatible Client Wrappers

For providers exposing OpenAI-compatible HTTP APIs—including OpenAI itself, Anthropic-via-Azure, OpenRouter, and Groq—the system reuses generic helper functions rather than provider-specific SDKs. The createOpenAICompatibleStream function converts the async iterable from any OpenAI-compatible SDK into a uniform ReadableStream<Uint8Array> for the UI, while checkForForcedToolUsageOpenAI tracks tool execution state across streaming responses.

Request Routing Pipeline

When processing a chat completion request, Sim Studio executes a deterministic six-step pipeline:

  1. Model Resolution: getProviderFromModel identifies the provider ID and retrieves metadata from PROVIDER_DEFINITIONS.
  2. Authentication: getApiKey sources the appropriate credential, rotating server-side keys automatically for managed OpenAI and Anthropic access.
  3. Client Instantiation: The official SDK (e.g., import OpenAI from 'openai') is instantiated with the resolved endpoint and key. For Azure-hosted Anthropic models, the base URL points to the Azure OpenAI endpoint.
  4. Payload Construction: Tools are prepared via prepareToolsWithUsageControl, injecting tool_choice objects for models supporting function calling.
  5. Streaming: createOpenAICompatibleStream normalizes the SDK's async iterable into a standard web stream, abstracting differences between OpenAI, Anthropic, and other providers.
  6. Cost Reporting: calculateCost and formatCost convert token usage (prompt and completion) to USD, then dollarsToCredits transforms this into platform-specific credits.

Anthropic-Specific Integration Details

While Anthropic maintains its own SDK (@ai-sdk/anthropic), Sim Studio primarily accesses Claude models through OpenAI-compatible endpoints to maximize code reuse.

When using direct Anthropic integration, the anthropic provider ID maps to models declaring temperature: { min: 0, max: 1 } and toolUsageControl: true. For enterprise deployments, the azure-anthropic provider pattern resolves to Azure OpenAI endpoints while preserving identical streaming and tool-handling logic. This dual-path approach ensures that features like forced tool usage—tracked via checkForForcedToolUsageOpenAI—function identically whether the underlying model is GPT-4o or Claude Opus.

Implementation Code Examples

Making a Chat Request to OpenAI

import OpenAI from 'openai';
import { getProviderFromModel, getApiKey, createOpenAICompatibleStream } from '@/providers/utils';

// Resolve provider and acquire API key
const model = 'gpt-4o';
const providerId = getProviderFromModel(model);  // Returns "openai"
const apiKey = getApiKey(providerId, model);     // Rotates automatically in hosted env

// Initialize OpenAI-compatible client
const openai = new OpenAI({ apiKey, baseURL: 'https://api.openai.com/v1' });

// Execute streaming request
const response = await openai.chat.completions.create({
  model,
  messages: [{ role: 'user', content: 'Explain the difference between GPT‑4 and GPT‑4o' }],
  stream: true,
});

// Convert to standard ReadableStream for UI consumption
const readable = createOpenAICompatibleStream(response, 'OpenAI');

Accessing Anthropic via Azure

import OpenAI from 'openai';
import { getProviderFromModel, getApiKey, createOpenAICompatibleStream } from '@/providers/utils';

const model = 'azure-anthropic/claude-opus-4-6';
const providerId = getProviderFromModel(model);  // Resolves using /^azure-anthropic\// pattern
const apiKey = getApiKey(providerId, model);

const azureEndpoint = 'https://YOUR_RESOURCE.openai.azure.com/v1';
const openai = new OpenAI({ apiKey, baseURL: azureEndpoint });

const response = await openai.chat.completions.create({
  model,
  messages: [{ role: 'user', content: 'Summarize the latest AI research.' }],
  stream: true,
});

const readable = createOpenAICompatibleStream(response, 'Azure‑Anthropic');

Summary

  • Sim Studio integrates OpenAI and Anthropic through a three-layer architecture: metadata catalog (models.ts), runtime utilities (utils.ts), and OpenAI-compatible wrappers.
  • The getProviderFromModel function resolves any model string to its provider using regex patterns defined in PROVIDER_DEFINITIONS.
  • API key handling supports automatic rotation for hosted environments via getRotatingApiKey while accommodating user-provided keys for self-hosted models.
  • Streaming abstraction via createOpenAICompatibleStream unifies OpenAI, Anthropic-via-Azure, and other providers into a single ReadableStream interface.
  • Tool usage control and cost calculation are provider-agnostic, leveraging checkForForcedToolUsageOpenAI and calculateCost across all supported models.

Frequently Asked Questions

How does Sim Studio determine which provider to use for a given model?

Sim Studio uses the getProviderFromModel function in apps/sim/providers/utils.ts to match the model string against regex patterns stored in the PROVIDER_DEFINITIONS constant. For example, gpt-4o matches the OpenAI provider pattern, while azure-anthropic/claude-opus-4-6 matches the Azure Anthropic pattern, automatically routing the request to the appropriate endpoint.

Can Sim Studio integrate with self-hosted LLM providers like vLLM?

Yes. The getApiKey function returns a placeholder value ('empty') for self-hosted models when no API key is required, and the createOpenAICompatibleStream helper works with any provider exposing an OpenAI-compatible HTTP interface. You simply add the provider to PROVIDER_DEFINITIONS with the appropriate model regex pattern.

How does the integration handle tool calling across different providers?

The system uses prepareToolsWithUsageControl to inject tool_choice parameters into requests and checkForForcedToolUsageOpenAI to monitor streaming responses. These utilities are provider-agnostic and work identically for OpenAI, Anthropic, and other models that support function calling, automatically managing the transition between forced tool use and standard completion.

What is the difference between using Anthropic directly versus through Azure?

Direct Anthropic access uses the anthropic provider ID with the official Anthropic SDK, while Azure access uses the azure-anthropic provider ID that resolves to an Azure OpenAI endpoint. Both paths utilize the same createOpenAICompatibleStream abstraction and cost calculation logic, but Azure integration leverages server-side key rotation and organizational Azure credentials rather than direct Anthropic API keys.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →