Skip to content

@codesoul-co/hypha-models / providers

Using this module

Use the Providers module for binding external or local providers to Hypha ports. It exports 3 classes, 3 functions, 3 interfaces.

Import from the package entrypoint

ts
import {
  FetchModelTransport,
  OpenAICompatibleModelProvider,
  OpenAIModelProvider,
  createDeepSeekProvider,
  normalizeOpenAIChatResponse,
  providerSpecFromConfig,
} from '@codesoul-co/hypha-models';

import type {
  ModelTransport,
  OpenAIChatCompletionResponse,
  OpenAICompatibleProviderConfig,
} from '@codesoul-co/hypha-models';

Usage patterns

  • Use the 3 type/interface exports as static contracts in application code, adapters, or tests. Import them with import type; they do not exist at runtime.
  • The module exposes 3 classes as constructable runtime implementations. Each symbol entry lists its constructor and public methods.
  • The module exposes 3 functions as direct operation entrypoints. Every overload, required/optional parameter, and return type is documented below.

Public exports

SymbolKindSignatureDescription
FetchModelTransportclassnew FetchModelTransport(): FetchModelTransportFetch Model Transport class with 3 public constructor or member entries; its exact declarations are listed below.
OpenAICompatibleModelProviderclassnew OpenAICompatibleModelProvider(config: OpenAICompatibleProviderConfig): OpenAICompatibleModelProviderOpen AI Compatible Model Provider class with 5 public constructor or member entries; its exact declarations are listed below.
OpenAIModelProviderclassnew OpenAIModelProvider(config: Omit<OpenAICompatibleProviderConfig, "type" | "baseUrl"> & { baseUrl?: string; }): OpenAIModelProviderOpen AI Model Provider class with 5 public constructor or member entries; its exact declarations are listed below.
createDeepSeekProviderfunctioncreateDeepSeekProvider(config: Omit<OpenAICompatibleProviderConfig, "type" | "baseUrl"> & { baseUrl?: string; }): OpenAICompatibleModelProviderCreate Deep Seek Provider function with 1 public call signature; parameters and return types are listed below.
normalizeOpenAIChatResponsefunctionnormalizeOpenAIChatResponse(response: OpenAIChatCompletionResponse, context?: OpenAIChatCompletionNormalizationContext): ModelResponseNormalize Open AI Chat Response function with 1 public call signature; parameters and return types are listed below.
providerSpecFromConfigfunctionproviderSpecFromConfig(config: OpenAICompatibleProviderConfig): ModelProviderSpecProvider Spec From Config function with 1 public call signature; parameters and return types are listed below.
ModelTransportinterfaceinterface ModelTransportModel Transport interface with 2 public fields or methods.
OpenAIChatCompletionResponseinterfaceinterface OpenAIChatCompletionResponseOpen AI Chat Completion Response interface with 4 public fields or methods.
OpenAICompatibleProviderConfiginterfaceinterface OpenAICompatibleProviderConfigOpen AI Compatible Provider Config interface with 9 public fields or methods.

FetchModelTransport

Fetch Model Transport class with 3 public constructor or member entries; its exact declarations are listed below.

  • Kind: class
  • Import: import { FetchModelTransport } from '@codesoul-co/hypha-models';
  • Source module: providers

Declaration

text
export declare class FetchModelTransport implements ModelTransport {
    postJson<TResponse>(url: string, body: unknown, headers: Record<string, string>, timeoutMs?: number): Promise<TResponse>;
    streamSse(url: string, body: unknown, headers: Record<string, string>, timeoutMs?: number): AsyncIterable<string>;
}

Public members

MemberKindSignatureDescription
constructorconstructor(): FetchModelTransportCreates an instance of this class.
postJsonmethodpostJson<TResponse>(url: string, body: unknown, headers: Record<string, string>, timeoutMs?: number): Promise<TResponse>Public method; parameters and return type are shown in the signature.
streamSsemethodstreamSse(url: string, body: unknown, headers: Record<string, string>, timeoutMs?: number): AsyncIterable<string>Public method; parameters and return type are shown in the signature.

OpenAICompatibleModelProvider

Open AI Compatible Model Provider class with 5 public constructor or member entries; its exact declarations are listed below.

  • Kind: class
  • Import: import { OpenAICompatibleModelProvider } from '@codesoul-co/hypha-models';
  • Source module: providers

Declaration

text
export declare class OpenAICompatibleModelProvider implements ModelProvider<ModelRequest, ModelResponse> {
    readonly id: string;
    constructor(config: OpenAICompatibleProviderConfig);
    capabilities(): ModelCapabilities;
    generate(request: ModelRequest): Promise<ModelResponse>;
    stream(request: ModelRequest): AsyncIterable<ModelStreamEvent>;
}

Public members

MemberKindSignatureDescription
capabilitiesmethodcapabilities(): ModelCapabilitiesPublic method; parameters and return type are shown in the signature.
constructorconstructor(config: OpenAICompatibleProviderConfig): OpenAICompatibleModelProviderCreates an instance of this class.
generatemethodgenerate(request: ModelRequest): Promise<ModelResponse>Public method; parameters and return type are shown in the signature.
idpropertyreadonly id: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
streammethodstream(request: ModelRequest): AsyncIterable<ModelStreamEvent>Public method; parameters and return type are shown in the signature.

OpenAIModelProvider

Open AI Model Provider class with 5 public constructor or member entries; its exact declarations are listed below.

  • Kind: class
  • Import: import { OpenAIModelProvider } from '@codesoul-co/hypha-models';
  • Source module: providers

Declaration

text
export declare class OpenAIModelProvider extends OpenAICompatibleModelProvider {
    constructor(config: Omit<OpenAICompatibleProviderConfig, 'type' | 'baseUrl'> & {
            baseUrl?: string;
        });
}

Public members

MemberKindSignatureDescription
capabilitiesmethodcapabilities(): ModelCapabilitiesPublic method; parameters and return type are shown in the signature.
constructorconstructor(config: Omit<OpenAICompatibleProviderConfig, "type" | "baseUrl"> & { baseUrl?: string; }): OpenAIModelProviderCreates an instance of this class.
generatemethodgenerate(request: ModelRequest): Promise<ModelResponse>Public method; parameters and return type are shown in the signature.
idpropertyreadonly id: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
streammethodstream(request: ModelRequest): AsyncIterable<ModelStreamEvent>Public method; parameters and return type are shown in the signature.

createDeepSeekProvider

Create Deep Seek Provider function with 1 public call signature; parameters and return types are listed below.

  • Kind: function
  • Import: import { createDeepSeekProvider } from '@codesoul-co/hypha-models';
  • Source module: providers

Declaration

text
export declare function createDeepSeekProvider(config: Omit<OpenAICompatibleProviderConfig, 'type' | 'baseUrl'> & {
    baseUrl?: string;
}): OpenAICompatibleModelProvider;

Call signature

text
createDeepSeekProvider(config: Omit<OpenAICompatibleProviderConfig, "type" | "baseUrl"> & { baseUrl?: string; }): OpenAICompatibleModelProvider

Parameters

ParameterTypeRequiredDescription
configOmit<OpenAICompatibleProviderConfig, "type" | "baseUrl"> & { baseUrl?: string; }YesRequired parameter; accepted values are defined by the type column.

Returns

  • Type: OpenAICompatibleModelProvider
  • Description: The return contract is defined by the type shown above.

normalizeOpenAIChatResponse

Normalize Open AI Chat Response function with 1 public call signature; parameters and return types are listed below.

  • Kind: function
  • Import: import { normalizeOpenAIChatResponse } from '@codesoul-co/hypha-models';
  • Source module: providers

Declaration

text
export declare function normalizeOpenAIChatResponse(response: OpenAIChatCompletionResponse, context?: OpenAIChatCompletionNormalizationContext): ModelResponse;

Call signature

text
normalizeOpenAIChatResponse(response: OpenAIChatCompletionResponse, context?: OpenAIChatCompletionNormalizationContext): ModelResponse

Parameters

ParameterTypeRequiredDescription
responseOpenAIChatCompletionResponseYesRequired parameter; accepted values are defined by the type column.
contextOpenAIChatCompletionNormalizationContextNoOptional parameter; accepted values are defined by the type column.

Returns

  • Type: ModelResponse<string>
  • Description: The return contract is defined by the type shown above.

providerSpecFromConfig

Provider Spec From Config function with 1 public call signature; parameters and return types are listed below.

  • Kind: function
  • Import: import { providerSpecFromConfig } from '@codesoul-co/hypha-models';
  • Source module: providers

Declaration

text
export declare function providerSpecFromConfig(config: OpenAICompatibleProviderConfig): ModelProviderSpec;

Call signature

text
providerSpecFromConfig(config: OpenAICompatibleProviderConfig): ModelProviderSpec

Parameters

ParameterTypeRequiredDescription
configOpenAICompatibleProviderConfigYesRequired parameter; accepted values are defined by the type column.

Returns

  • Type: ModelProviderSpec
  • Description: The return contract is defined by the type shown above.

ModelTransport

Model Transport interface with 2 public fields or methods.

  • Kind: interface
  • Import: import type { ModelTransport } from '@codesoul-co/hypha-models';
  • Source module: providers

Declaration

text
export interface ModelTransport {
    postJson<TResponse>(url: string, body: unknown, headers: Record<string, string>, timeoutMs?: number): Promise<TResponse>;
    streamSse?(url: string, body: unknown, headers: Record<string, string>, timeoutMs?: number): AsyncIterable<string>;
}

Contract members

MemberKindSignatureDescription
postJsonmethodpostJson<TResponse>(url: string, body: unknown, headers: Record<string, string>, timeoutMs?: number): Promise<TResponse>Public method; parameters and return type are shown in the signature.
streamSsemethodstreamSse?(url: string, body: unknown, headers: Record<string, string>, timeoutMs?: number): AsyncIterable<string>Public method; parameters and return type are shown in the signature.

OpenAIChatCompletionResponse

Open AI Chat Completion Response interface with 4 public fields or methods.

  • Kind: interface
  • Import: import type { OpenAIChatCompletionResponse } from '@codesoul-co/hypha-models';
  • Source module: providers

Declaration

text
export interface OpenAIChatCompletionResponse {
    id: string;
    choices: Array<{
        message?: {
            content?: string | null;
            tool_calls?: Array<{
                id: string;
                function?: {
                    name: string;
                    arguments: string;
                };
            }>;
        };
        finish_reason?: string | null;
    }>;
    usage?: {
        prompt_tokens?: number;
        completion_tokens?: number;
        total_tokens?: number;
        prompt_cache_hit_tokens?: number;
        prompt_cache_miss_tokens?: number;
        prompt_tokens_details?: {
            cached_tokens?: number;
        };
    };
    model?: string;
}

Contract members

MemberKindSignatureDescription
choicespropertychoices: { message?: { content?: string | null; tool_calls?: Array<{ id: string; function?: { name: string; arguments: string; }; }>; }; finish_reason?: string | null; }[]Public property; its type, readonly modifier and optionality are shown in the signature.
idpropertyid: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
modelpropertymodel?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
usagepropertyusage?: { prompt_tokens?: number; completion_tokens?: number; total_tokens?: number; prompt_cache_hit_tokens?: number; prompt_cache_miss_tokens?: number; prompt_tokens_details?: { cached_tokens?: number; }; }Public property; its type, readonly modifier and optionality are shown in the signature.

OpenAICompatibleProviderConfig

Open AI Compatible Provider Config interface with 9 public fields or methods.

  • Kind: interface
  • Import: import type { OpenAICompatibleProviderConfig } from '@codesoul-co/hypha-models';
  • Source module: providers

Declaration

text
export interface OpenAICompatibleProviderConfig {
    id: string;
    type: 'openai' | 'openai-compatible';
    baseUrl: string;
    apiKey?: string;
    apiKeyEnv?: string;
    providerModelByAlias: Record<string, string>;
    capabilities?: ModelCapabilities;
    timeoutMs?: number;
    transport?: ModelTransport;
}

Contract members

MemberKindSignatureDescription
apiKeypropertyapiKey?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
apiKeyEnvpropertyapiKeyEnv?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
baseUrlpropertybaseUrl: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
capabilitiespropertycapabilities?: ModelCapabilitiesPublic property; its type, readonly modifier and optionality are shown in the signature.
idpropertyid: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
providerModelByAliaspropertyproviderModelByAlias: Record<string, string>Public property; its type, readonly modifier and optionality are shown in the signature.
timeoutMspropertytimeoutMs?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
transportpropertytransport?: ModelTransportPublic property; its type, readonly modifier and optionality are shown in the signature.
typepropertytype: "openai" | "openai-compatible"Public property; its type, readonly modifier and optionality are shown in the signature.