# Interface IModelAdapter

Unified interface for all model adapters.

interface IModelAdapter {
providerId: string;
modelId: string;
capabilities: readonly ModelCapability[];
complete(
request: CompletionRequest,
): Promise<Result<CompletionResponse, ModelError>>;
stream(request: CompletionRequest): AsyncIterable<StreamChunk>;
countTokens(text: string): Promise<number>;
validateConfig(): Result<void, ConfigError>;
listModels?(): Promise<readonly ModelMetadata[]>;
}

#### Hierarchy (View Summary)

- IModelAdapter
  - ResilientLike

#### Implemented by

- BaseAdapter

- Defined in packages/nexus-agents/src/core/types/model.ts:139

##### Index

### Properties

providerId
modelId
capabilities

### Methods

complete
stream
countTokens
validateConfig
listModels?

## Properties

### `Readonly` providerId

providerId: string

Provider identifier (e.g., 'anthropic', 'openai')

- Defined in packages/nexus-agents/src/core/types/model.ts:141

### `Readonly` modelId

modelId: string

Model identifier (e.g., 'claude-sonnet-4', 'gpt-4o')

- Defined in packages/nexus-agents/src/core/types/model.ts:144

### `Readonly` capabilities

capabilities: readonly ModelCapability[]

Capabilities this model supports

- Defined in packages/nexus-agents/src/core/types/model.ts:147

## Methods

### complete

- complete(
  request: CompletionRequest,
  ): Promise<Result<CompletionResponse, ModelError>>

  Send a completion request.

  #### Parameters

  - request: CompletionRequest

    The completion request

  #### Returns Promise<Result<CompletionResponse, ModelError>>

  Result with response or ModelError

  - Defined in packages/nexus-agents/src/core/types/model.ts:154

### stream

- stream(request: CompletionRequest): AsyncIterable<StreamChunk>

  Stream a completion request.

  #### Parameters

  - request: CompletionRequest

    The completion request

  #### Returns AsyncIterable<StreamChunk>

  #### Yields

  StreamChunk objects as they arrive

  - Defined in packages/nexus-agents/src/core/types/model.ts:161

### countTokens

- countTokens(text: string): Promise<number>

  Count tokens in text.

  #### Parameters

  - text: string

    Text to count tokens for

  #### Returns Promise<number>

  Approximate token count

  - Defined in packages/nexus-agents/src/core/types/model.ts:168

### validateConfig

- validateConfig(): Result<void, ConfigError>

  Validate adapter configuration.

  #### Returns Result<void, ConfigError>

  Ok if valid, ConfigError if invalid

  - Defined in packages/nexus-agents/src/core/types/model.ts:174

### `Optional` listModels

- listModels?(): Promise<readonly ModelMetadata[]>

  (Optional, #2529) List models served by this adapter's endpoint.

  Implemented by adapters facing OpenAI-compatible endpoints (the upstream OpenAI API, OpenRouter, vLLM, custom gateways, etc.) — usually wraps `GET /v1/models`. Result is the harness-side identity resolver's most-trusted signal for "what model is actually being served behind this adapter."

  Subprocess-CLI adapters (claude / codex / gemini / opencode) leave this undefined; identity for those falls back to `modelId` parse.

  Implementations should cache the result for ~5 minutes — operators shouldn't pay round-trip latency on every resolve. Failures (network error, endpoint unsupported, auth missing) should throw so the caller can fall back; do NOT silently return an empty list.

  #### Returns Promise<readonly ModelMetadata[]>

  - Defined in packages/nexus-agents/src/core/types/model.ts:193