cocoon-ai-provider
v0.1.0
Published
AI SDK v6 provider for Cocoon models
Readme
cocoon-ai-provider
AI SDK v6 provider for Cocoon.
Install
pnpm add cocoon-ai-provider aiQuick Start
import { cocoon } from 'cocoon-ai-provider';
import { generateText } from 'ai';
const result = await generateText({
model: cocoon('Qwen/Qwen3-32B'),
prompt: 'Write a one-line welcome message.',
});
console.log(result.text);
await cocoon.close();Streaming
import { cocoon } from 'cocoon-ai-provider';
import { streamText } from 'ai';
const result = streamText({
model: cocoon('Qwen/Qwen3-32B'),
prompt: 'Write a short product tagline.',
});
for await (const textPart of result.textStream) {
process.stdout.write(textPart);
}
await cocoon.close();Runnable Example
This repository includes a runnable end-to-end example at examples/basic.mjs.
COCOON_WALLET="your 24-word mnemonic" pnpm example:basicOptional:
COCOON_MODEL_IDto override the model (default:Qwen/Qwen3-32B)- Any other Cocoon env vars described below
Custom Provider Instance
You can pass an existing Cocoon client or let the provider build one from clientOptions.
import { createCocoon } from 'cocoon-ai-provider';
const provider = createCocoon({
clientOptions: {
wallet: process.env.MNEMONIC!,
secretString: process.env.SECRET,
proxyUrl: process.env.PROXY_URL,
},
defaults: {
maxCoefficient: 1.2,
timeout: 30_000,
},
});Provider Options
Use call-level Cocoon options with providerOptions.cocoon:
import { generateText } from 'ai';
import { cocoon } from 'cocoon-ai-provider';
const result = await generateText({
model: cocoon('Qwen/Qwen3-32B'),
prompt: 'Summarize this in one sentence.',
providerOptions: {
cocoon: {
maxCoefficient: 1.1,
timeout: 20_000,
},
},
});Call-level providerOptions.cocoon override provider-level defaults.
Environment Variables
When createCocoon() is called without client and without clientOptions, the provider builds a Cocoon client from env values.
wallet:COCOON_WALLETorMNEMONIC(required)secretString:COCOON_SECRET_STRINGorSECRETproxyUrl:COCOON_PROXY_URLorPROXY_URLtonEndpoint:COCOON_TON_ENDPOINTorTON_ENDPOINTtonV4Endpoint:COCOON_TON_V4_ENDPOINTorTON_V4_ENDPOINTnetwork:COCOON_NETWORK(mainnetortestnet)timeout:COCOON_TIMEOUT(positive number)useTls:COCOON_USE_TLS(true/falseor1/0)autoRegisterOnLongAuth:COCOON_AUTO_REGISTER_ON_LONG_AUTH(true/falseor1/0, defaultfalse)longAuthRegisterAmountTon:COCOON_LONG_AUTH_REGISTER_AMOUNT_TON- TLS credential values:
COCOON_TLS_CERT+COCOON_TLS_KEY - TLS credential files:
COCOON_TLS_CERT_PATH+COCOON_TLS_KEY_PATH
Runtime and Limitations
- Node.js
>=18only. - v1 supports language-model generation and streaming only.
- Tool calling is not supported.
- Multimodal file input is not supported.
- Embedding and image model methods intentionally throw
NoSuchModelError. - Abort behavior is best-effort. Cocoon cancellation is limited by the underlying SDK.
Testing
pnpm testOptional real-network integration tests:
pnpm test:integration