Skip to content
中文

ModelProviderErrorCode ​

SUPPORT · type · Type contract

Stable failure classification reported by the compatible provider adapter.

Import ​

ts
import type { ModelProviderErrorCode } from '@jangts/agent-core/support';
js
/** @typedef {import('@jangts/agent-core/support').ModelProviderErrorCode} ModelProviderErrorCode */

Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/support, @jangts/agent-core/support/model.

Definition ​

ts
type ModelProviderErrorCode = | 'MODEL_NOT_CONFIGURED'
  /** Upstream rejected the credentials (HTTP 401/403). */
  | 'MODEL_AUTH'
  /** Upstream reported exhausted balance or quota (HTTP 402). */
  | 'MODEL_BALANCE'
  /** Upstream is rate limiting or overloaded (HTTP 429). */
  | 'MODEL_BUSY'
  /** The request itself is invalid (HTTP 400/404 or configuration validation). */
  | 'MODEL_CONFIG'
  /** Unclassified upstream failure. */
  | 'MODEL_UPSTREAM'
  /** Response body could not be parsed as the expected wire format. */
  | 'MODEL_FORMAT'
  /** The stream violated the protocol, for example data after the finish marker. */
  | 'MODEL_PROTOCOL'
  /** The provider stopped because the output token limit was reached. */
  | 'MODEL_OUTPUT_LIMIT'
  /** The stream ended without a usable payload. */
  | 'MODEL_INCOMPLETE';

Index structure ​

FieldTypeRequiredDescription
[key: number]stringRequiredRead-only. Index entry.

Union branch structure ​

Examples ​

Connect a common protocol with real server-side configuration ​

Beginner · Node.js

Running this example requires connection configuration for an available model service.

ts
import { ModelRunner, Support } from '@jangts/agent-core';
const provider = new Support.CompatibleModelProvider({ config: {
  baseUrl: process.env.MODEL_BASE_URL!, apiKey: process.env.MODEL_API_KEY!, model: process.env.MODEL_NAME!,
} });
const runner = new ModelRunner({ provider });
console.log((await runner.invoke('你好')).value);
js
import { ModelRunner, Support } from '@jangts/agent-core';
const provider = new Support.CompatibleModelProvider({ config: {
        baseUrl: process.env.MODEL_BASE_URL, apiKey: process.env.MODEL_API_KEY, model: process.env.MODEL_NAME,
    } });
const runner = new ModelRunner({ provider });
console.log((await runner.invoke('你好')).value);

Declared fields and wire mapping for a direct tool thread ​

Configuration · Node.js

This only demonstrates message conversion, with no network request or tool execution. Raw tool_calls, tool_call_id, and host-attached data are not forwarded.

ts
import { Support } from '@jangts/agent-core';
const messages: Support.ProviderMessage[] = [
  { role: 'user', content: '查询资料' },
  { role: 'assistant', content: '', toolCalls: [
    { id: 'call-1', name: 'lookup', arguments: '{"query":"资料"}' },
  ] },
  { role: 'tool', content: '{"found":true}', toolCallId: 'call-1' },
];
console.log(Support.chatCompletionMessages(messages));
js
import { Support } from '@jangts/agent-core';
const messages = [
    { role: 'user', content: '查询资料' },
    { role: 'assistant', content: '', toolCalls: [
            { id: 'call-1', name: 'lookup', arguments: '{"query":"资料"}' },
        ] },
    { role: 'tool', content: '{"found":true}', toolCallId: 'call-1' },
];
console.log(Support.chatCompletionMessages(messages));

API reference, usage examples and developer guides.