API Reference

Models and adapters

Root model contracts and the public provider translator entry point.

ModelAdapter

Access: @nylorun/harnessModelAdapter, ModelCall, ModelAdapterContext, ModelCandidate

An adapter converts one canonical Harness model call into a provider request and returns the provider result as a candidate, string, or deferred outcome.

ParameterTypeRequiredDescription
callModelCallYesProvider-facing projection with model directive, prompt, tools, and session id.
contextModelAdapterContextYesFull request, invocation id, and cancellation signal. Forward signal to the provider client.
ReturnsPromise<ModelCandidate or string or DeferredOutcome>Candidate data, direct text output, or deferred work marker.

ModelCall and adapter context

Access: @nylorun/harnessModelCall, ModelAdapterContext, ModelRequest

NameTypeRequiredDescription
ModelCall.modelModelDirectiveNoRequested model id, controls, and host-defined JSON config.
ModelCall.promptreadonly PromptItem[]YesProvider-neutral instructions, messages, tool results, and context.
ModelCall.toolsreadonly ModelCallTool[]YesModel-visible tool names, descriptions, and input schemas.
ModelCall.sessionIdstringYesOwning session id.
ModelAdapterContext.requestModelRequestYesImmutable configuration, runtime context, transcript, arrivals, tool results, and bound tools.
ModelAdapterContext.invocationIdstringYesUnique model invocation id.
ModelAdapterContext.signalAbortSignalYesCancellation signal.

Candidate, configuration, and prompt types

Access: @nylorun/harnessModelCandidate, ModelOutputBlock, ModelDirective, ModelControls, ModelUsage, ModelEvidence, ModelConfigurationSnapshot, ContextSnapshot

TypeFieldsDescription
ModelCandidateoutput, optional finishReason, usage, evidenceCanonical provider result.
ModelOutputBlocktext, reasoning, or tool-call variantA text/reasoning block or a tool call with id, name, JSON args, and optional raw arguments.
ModelDirectiveoptional id, controls, configMiddleware-selected provider model and host-defined provider configuration.
ModelControlsoptional temperature, maxOutputTokensProvider-neutral controls forwarded by the built-in translators.
ModelUsageoptional token counts and costUsdProvider usage normalized when available.
ModelEvidenceoptional request id, model, warnings, extrasProvider evidence retained with the candidate.
ModelConfigurationSnapshotmodel, instructions, tools, contracts, contributors, digestsImmutable, attributed model configuration for one step.
ContextSnapshotitems, contributors, digestRuntime context kept separate from configuration policy.

PromptItem, PromptContentPart, ModelCallTool, ModelConfigurationContributor, ModelConfigurationInstruction, ModelConfigurationTool, ContextContributor, and the mutation option types are also exported from the package root for adapters and middleware that need the complete canonical shape.

Chat Completions translators

Access: @nylorun/harness/model/adapterstoChatCompletions, fromChatCompletions, chatCompletionsAdapter

APIParametersReturnsDescription
toChatCompletionscall: ModelCallChatCompletionsRequestProjects the canonical call into Chat Completions messages, function tools, and controls.
fromChatCompletionsvalue: unknownModelCandidateValidates and normalizes one Chat Completions response.
chatCompletionsAdaptersend: AdapterSend<ChatCompletionsRequest>ModelAdapterCombines request translation, application-owned transport, and response normalization.
Request fieldTypeRequiredDescription
messagesreadonly ChatCompletionsMessage[]YesSystem, user, assistant, and tool messages.
toolsFunction-tool arrayNoModel-visible function definitions.
temperaturenumberNoForwarded model temperature.
max_completion_tokensnumberNoForwarded model output-token limit.

OpenAI Responses translators

Access: @nylorun/harness/model/adapterstoResponses, fromResponses, responsesAdapter

APIParametersReturnsDescription
toResponsescall: ModelCallResponsesRequestProjects instructions, messages, function calls, tool results, tools, and controls.
fromResponsesvalue: unknownModelCandidateValidates and normalizes a Responses API result.
responsesAdaptersend: AdapterSend<ResponsesRequest>ModelAdapterCreates an adapter backed by an application-owned Responses transport.
Request fieldTypeRequiredDescription
instructionsstringNoJoined canonical instructions.
inputreadonly ResponsesInputItem[]YesUser/assistant messages and function call or output items.
toolsFunction-tool arrayNoModel-visible function definitions.
temperaturenumberNoForwarded model temperature.
max_output_tokensnumberNoForwarded model output-token limit.

Anthropic Messages translators

Access: @nylorun/harness/model/adapterstoMessages, fromMessages, anthropicAdapter

APIParametersReturnsDescription
toMessagescall: ModelCall, defaultMaxOutputTokens: numberMessagesRequestProjects a canonical call into the Messages request format.
fromMessagesvalue: unknownModelCandidateValidates and normalizes a Messages API result.
anthropicAdapteroptions: AnthropicAdapterOptionsModelAdapterCreates an adapter backed by an application-owned Messages transport.
Option or request fieldTypeRequiredDescription
AnthropicAdapterOptions.defaultMaxOutputTokensnumberYesPositive fallback for max_tokens when the model directive has no output limit.
AnthropicAdapterOptions.sendAdapterSend<MessagesRequest>YesApplication-owned provider call.
MessagesRequest.systemstringNoJoined canonical instructions.
MessagesRequest.messagesreadonly MessagesMessage[]YesUser content, tool results, and assistant text/tool-use parts.
MessagesRequest.toolsTool-definition arrayNoModel-visible Messages tools.
MessagesRequest.temperaturenumberNoForwarded model temperature.
MessagesRequest.max_tokensnumberYesPer-step output limit or adapter fallback.

Shared adapter types

Access: @nylorun/harness/model/adaptersAdapterSend, ChatCompletionsMessage, ChatCompletionsToolCall, ResponsesInputItem, MessagesMessage, MessagesAssistantPart, MessagesToolResult

TypeDescription
AdapterSend<Request>Application transport callback receiving translated request, canonical call, and adapter context.
Chat Completions typesJSON messages and function tool-call structures emitted or parsed by its translator.
Responses typesJSON message, function-call, and function-call-output structures emitted or parsed by its translator.
Messages typesJSON user, assistant, tool-use, and tool-result structures emitted or parsed by its translator.

The translators cover text and JSON-object tool loops. Provider-native streaming, image input, continuation state, cache controls, and other extensions remain part of a custom host integration.

On this page