Skip to main content
Use LiteLLM with NEAR AI Cloud by routing LiteLLM’s OpenAI-compatible provider to the NEAR AI Cloud gateway.

Prerequisites

  • LiteLLM Python SDK or LiteLLM Proxy.
  • A NEAR AI Cloud API key from the NEAR AI Cloud Dashboard.
  • NEARAI_API_KEY exported in the shell or injected into the proxy container.
Keep the NEAR AI Cloud API key in an environment variable. Do not paste a real key into checked-in Python files or config.yaml.

Base URL

Use the NEAR AI Cloud gateway base URL:
Do not append /chat/completions to api_base. LiteLLM and the OpenAI client add the request path when they make chat completion calls.

Model ID

Use LiteLLM’s OpenAI-compatible prefix for the upstream model:
The openai/ prefix tells LiteLLM to send the request through OpenAI-compatible chat completions. The NEAR AI Cloud model ID after the prefix is z-ai/glm-5.2. Check Model Discovery and Refresh when you need the freshest NEAR AI Cloud model list.

Configure

Python SDK

Call NEAR AI Cloud directly from the LiteLLM Python SDK:

Proxy config.yaml

Expose NEAR AI Cloud through LiteLLM Proxy with a local model alias:
Start the proxy with the config:
Clients that call your proxy use the proxy alias:

Optional: report capabilities and limits

LiteLLM passes tool calls and reasoning through the openai/ path regardless of metadata, so the config above is enough to use GLM 5.2. If you want LiteLLM’s introspection endpoints (/v1/models, /v1/model/info, /model_group/info) to report GLM 5.2’s real capabilities — instead of defaulting to false/null because z-ai/glm-5.2 is not in LiteLLM’s built-in model map — add a sibling model_info block:
The values match the live /v1/models record for z-ai/glm-5.2 (tools and reasoning supported, text-only, context 500000, output 131072). This block is reporting metadata only; it does not change request behavior.

Refresh models

LiteLLM Proxy uses the entries in model_list; it does not automatically add every NEAR AI Cloud model to your config. When NEAR AI Cloud releases a new model:
  1. Run curl https://cloud-api.near.ai/v1/models.
  2. Copy the new model’s id.
  3. Add or update a model_list entry.
  4. Set litellm_params.model to openai/<model-id>.
  5. Restart or reload LiteLLM Proxy so the new alias appears.
You can generate starter entries from /v1/models and then review them before using the config:
Review generated aliases for readability and remove models you do not want to expose through your proxy.

Quick test

Before debugging LiteLLM, verify the same key, base URL, and NEAR AI Cloud model with curl:
If curl fails, fix the NEAR AI Cloud key, model ID, or network path before changing LiteLLM settings.

Troubleshooting

Sources Checked

Sources checked on 2026-06-23: