ReqLLM.Providers.Zai (ReqLLM v1.0.0)

View Source

Z.AI provider – OpenAI-compatible Chat Completions API (Standard Endpoint).

Implementation

Uses built-in OpenAI-style encoding/decoding defaults. No custom request/response handling needed – leverages the standard OpenAI wire format.

This provider uses the Z.AI standard endpoint (/api/paas/v4) for general-purpose chat and reasoning tasks. For code generation optimized responses, use the zai_coder provider.

Supported Models

  • glm-4.5 - Advanced reasoning model with 131K context
  • glm-4.5-air - Lighter variant with same capabilities
  • glm-4.5-flash - Free tier model with fast inference
  • glm-4.5v - Vision model supporting text, image, and video inputs
  • glm-4.6 - Latest model with 204K context and improved reasoning

Configuration

# Add to .env file (automatically loaded)
ZAI_API_KEY=your-api-key

Summary

Functions

Default implementation of attach/3.

Default implementation of attach_stream/4.

Default implementation of decode_response/1.

Default implementation of decode_stream_event/2.

Default implementation of encode_body/1.

Default implementation of extract_usage/2.

Default implementation of prepare_request/4.

Default implementation of translate_options/3.

Functions

attach(request, model_input, user_opts)

Default implementation of attach/3.

Sets up Bearer token authentication and standard pipeline steps.

attach_stream(model, context, opts, finch_name)

Default implementation of attach_stream/4.

Builds complete streaming requests using OpenAI-compatible format.

decode_response(request_response)

Default implementation of decode_response/1.

Handles success/error responses with standard ReqLLM.Response creation.

decode_stream_event(event, model)

Default implementation of decode_stream_event/2.

Decodes SSE events using OpenAI-compatible format.

default_base_url()

default_env_key()

Callback implementation for ReqLLM.Provider.default_env_key/0.

default_provider_opts()

encode_body(request)

Default implementation of encode_body/1.

Encodes request body using OpenAI-compatible format for chat and embedding operations.

extract_usage(body, model)

Default implementation of extract_usage/2.

Extracts usage data from standard usage field in response body.

metadata()

prepare_request(operation, model_spec, input, opts)

Default implementation of prepare_request/4.

Handles :chat, :object, and :embedding operations using OpenAI-compatible patterns.

provider_extended_generation_schema()

provider_id()

provider_schema()

supported_provider_options()

translate_options(operation, model, opts)

Default implementation of translate_options/3.

Pass-through implementation that returns options unchanged.