本页还没有译文
本页 15 段还没译成简体中文,下面显示的是英文原文。NEAR AI Cloud
还没翻译译自英文(ai-sdk.dev)本页 15 段都还没译
NEAR AI Cloud provides TEE-backed inference through an OpenAI-compatible API. You can use it with the AI SDK through the @ai-sdk/openai-compatible module.
Setup
The NEAR AI Cloud provider is available via the @ai-sdk/openai-compatible module as it is compatible with the OpenAI API. You can install it with:
pnpm add @ai-sdk/openai-compatiblenpm install @ai-sdk/openai-compatibleyarn add @ai-sdk/openai-compatiblebun add @ai-sdk/openai-compatibleProvider Instance
To use NEAR AI Cloud, you can create a custom provider instance with the createOpenAICompatible function from @ai-sdk/openai-compatible:
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
const nearai = createOpenAICompatible({
name: 'nearai',
baseURL: 'https://cloud-api.near.ai/v1',
apiKey: process.env.NEARAI_API_KEY,
transformRequestBody: body => {
const { reasoning_effort, ...rest } = body;
return rest;
},
});Note
You can create an API key in NEAR AI Cloud. Make sure
to set the NEARAI_API_KEY environment variable with your API key.
Language Models
You can create NEAR AI Cloud models using a provider instance. The first argument is the model ID from the public model catalog, e.g. zai-org/GLM-5.1-FP8.
const model = nearai('zai-org/GLM-5.1-FP8');Example
You can use NEAR AI Cloud language models to generate text with the generateText function:
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { generateText } from 'ai';
const nearai = createOpenAICompatible({
name: 'nearai',
baseURL: 'https://cloud-api.near.ai/v1',
apiKey: process.env.NEARAI_API_KEY,
transformRequestBody: body => {
const { reasoning_effort, ...rest } = body;
return rest;
},
});
const { text } = await generateText({
model: nearai('zai-org/GLM-5.1-FP8'),
prompt: 'Tell me about yourself in one sentence.',
});
console.log(text);NEAR AI Cloud language models can also generate text in a streaming fashion with the streamText function:
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { streamText } from 'ai';
const nearai = createOpenAICompatible({
name: 'nearai',
baseURL: 'https://cloud-api.near.ai/v1',
apiKey: process.env.NEARAI_API_KEY,
transformRequestBody: body => {
const { reasoning_effort, ...rest } = body;
return rest;
},
});
const result = streamText({
model: nearai('zai-org/GLM-5.1-FP8'),
prompt: 'Write a short haiku about private inference.',
});
for await (const message of result.textStream) {
console.log(message);
}You can use any supported modelId from the NEAR AI Cloud model catalog. Model metadata includes context length, modalities, and whether TEE attestation is supported for that model.