ai4j
一款JavaSDK用于快速接入AI大模型应用,整合多平台大模型,如OpenAi、智谱Zhipu(ChatGLM)、深度求索DeepSeek、月之暗面Moonshot(Kimi)、腾讯混元Hunyuan、零一万物(01)等等,提供统一的输入输出(对齐OpenAi)消除差异化,优化函数调用(Tool Call),优化RAG调用、支持向量数据库(Pinecone)、内置联网增强,并且支持JDK1.8,为用户提供快速整合AI的能力。
claude mcp add --transport stdio lnyo-cly-ai4j java -jar path/to/ai4j-server.jar \ --env JAVA_HOME="Path to JDK 8+" \ --env AI4J_CONFIG="Optional path or string-based config for ai4j server"
How to use
ai4j is a Java SDK that unifies access to multiple large language model platforms (OpenAI, Zhipu, Ollama, DeepSeek, Moonshot, Hunyuan, Lingyi, Baichuan, etc.) through a consistent input/output interface and operational features such as function calling and RAG with vector stores. It supports MCP (Model Context Protocol) via STDIO, SSE, and Streamable HTTP, enabling you to run this server alongside MCP clients and gateways. The server can be embedded in Spring Boot or plain Java applications, and it provides a single set of services (chat, embedding, audio, realtime) across multiple providers, making integration easier and more maintainable. You can leverage built-in support for tool calls, streaming outputs, and dynamic MCP data sources, along with an internal gateway for MCP communications.
How to install
Prerequisites:
- JDK 8 or newer (ai4j explicitly supports Java 8 compatibility)
- Maven or Gradle for building Java projects
- Optional: a running PostgreSQL/MySQL or a vector store like Pinecone if you plan to use RAG features
- Install the library in your project
- Maven:
<dependency>
<groupId>io.github.lnyo-cly</groupId>
<artifactId>ai4j</artifactId>
<version>${project.version}</version>
</dependency>
- Maven (Spring boot starter):
<dependency>
<groupId>io.github.lnyo-cly</groupId>
<artifactId>ai4j-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>
- Gradle:
implementation 'io.github.lnyo-cly:ai4j:${project.version}'
- Gradle (Spring boot starter):
implementation 'io.github.lnyo-cly:ai4j-spring-boot-starter:${project.version}'
- Configure application (example for Spring Boot)
- application.yml:
ai:
openai:
api-key: "YOUR_OPENAI_API_KEY"
zhipu:
api-key: "YOUR_ZHIPU_API_KEY"
okhttp:
proxy-port: 10809
proxy-url: "127.0.0.1"
- Run the server
- If using a standalone Java app:
java -jar path/to/ai4j-server.jar
- If embedding in Spring Boot:
mvn spring-boot:run
- Interact with MCP clients
- Use MCP-compliant clients to connect via STDIO, SSE, or Streamable HTTP to the running server and access the unified AI services (Chat, Embedding, Audio, Realtime).
- Ensure environment variables for API keys and any gateway or proxy settings are configured as needed.
Additional notes
- ai4j supports multiple backends (OpenAI, Zhipu, Ollama, DeepSeek, Moonshot, Hunyuan, Lingyi, Baichuan, etc.).
- Ensure you provide appropriate API keys or access tokens for each provider you enable.
- If you enable vector stores for RAG (e.g., Pinecone), configure the endpoint and credentials via environment variables or application properties.
- The MCP gateway and dynamic MCP data sources are built-in; you can customize dispatchers and connect pools via SPI.
- For streaming outputs, enable and handle SseListener or equivalent streaming callbacks provided by the client.
- Java 8 compatibility is supported, but some platforms in the ecosystem may have newer requirements; consider using a compatible JDK for production.
- Common issues: network/proxy misconfigurations, API key scope, and mismatched model names across platforms. Check logs for streaming token usage when using stream_options.
Related MCP Servers
anything-llm
The all-in-one Desktop & Docker AI application with built-in RAG, AI agents, No-code agent builder, MCP compatibility, and more.
chatgpt-on-wechat
CowAgent是基于大模型的超级AI助理,能主动思考和任务规划、访问操作系统和外部资源、创造和执行Skills、拥有长期记忆并不断成长。同时支持飞书、钉钉、企业微信应用、微信公众号、网页等接入,可选择OpenAI/Claude/Gemini/DeepSeek/ Qwen/GLM/Kimi/LinkAI,能处理文本、语音、图片和文件,可快速搭建个人AI助手和企业数字员工。
UltraRAG
A Low-Code MCP Framework for Building Complex and Innovative RAG Pipelines
archestra
Secure cloud-native MCP registry, gateway & orchestrator
rikkahub
RikkaHub is an Android APP that supports for multiple LLM providers.
MCP-SuperAssistant
Brings MCP to ChatGPT, DeepSeek, Perplexity, Grok, Gemini, Google AI Studio, OpenRouter, DeepSeek, T3 Chat and more...