### Traditional Multi-Provider Setup Source: https://developer.puter.com/tutorials/access-any-model-using-langchain Shows the standard approach of installing separate packages for each LLM provider. ```bash # The traditional way — one package per provider pip install langchain-openai # for GPT models pip install langchain-anthropic # for Claude models pip install langchain-google-genai # for Gemini models ``` -------------------------------- ### Implement Peer-to-Peer Chat with Puter.js Source: https://developer.puter.com/blog/puter-peer A complete HTML/JavaScript example demonstrating how to start a peer server and connect to it using invite codes. ```html

Peer Chat

Open this page in two tabs. Start a server in one tab, then connect from the other.



    


```

--------------------------------

### Navigate and Install Dependencies

Source: https://developer.puter.com/tutorials/puter-js-react

Change directory into the new project and install its dependencies.

```bash
cd puter-react
npm install
```

--------------------------------

### Handle HTTP Methods and Headers with puter.net.fetch()

Source: https://developer.puter.com/tutorials/cors-free-fetch-api

This example shows how to perform GET, POST, PUT, and DELETE requests using puter.net.fetch(). The syntax mirrors the native fetch API. Ensure the puter.js library is included.

```html


    
``` -------------------------------- ### Initialize Project and Install Dependencies Source: https://developer.puter.com/tutorials/access-any-model-using-langchain Set up a new Python project and install the required langchain-openai package using uv. ```bash uv init puter-langchain cd puter-langchain uv add langchain-openai ``` -------------------------------- ### Basic Chat Completion Example Source: https://developer.puter.com/tutorials/use-litellm-with-puter A simple example to get a single chat completion response from the model and print its content. The response format mirrors OpenAI's. ```python from litellm import completion response = completion( model="openai/gpt-5-nano", api_base="https://api.puter.com/puterai/openai/v1/", api_key="YOUR_PUTER_AUTH_TOKEN", messages=[ {"role": "user", "content": "What is the capital of France?"}, ], ) print(response.choices[0].message.content) ``` -------------------------------- ### Deploy Simple 'Hello World' Website with Puter.js Source: https://developer.puter.com/tutorials/free-unlimited-hosting-api Use `puter.fs.write()` to create an HTML file and `puter.hosting.create()` to deploy it. This example demonstrates creating a directory, writing an index.html file, and deploying the site with a random subdomain. ```javascript // Create a directory to write the HTML file await puter.fs.mkdir('my-website'); // Write an index.html file await puter.fs.write('my-website/index.html', '

Hello World!

'); // Deploy the website const site = await puter.hosting.create('hello-world', 'my-website'); console.log(`Website deployed at: https://${site.subdomain}.puter.site`); ``` ```html ``` -------------------------------- ### Generate Image with FLUX.1 [schnell] (npm) Source: https://developer.puter.com/ai/black-forest-labs/flux-schnell Use the Puter.js library in your Node.js or frontend project to generate an image. Ensure you have installed the library using `npm install @heyputer/puter.js`. This example appends the generated image to the document body. ```javascript // npm install @heyputer/puter.js import { puter } from '@heyputer/puter.js'; puter.ai.txt2img("A serene mountain landscape at sunset", { model: "black-forest-labs/flux-schnell" }).then(image => { document.body.appendChild(image); }); ``` -------------------------------- ### Retrieve website information using puter.hosting.get Source: https://developer.puter.com/tutorials/free-unlimited-hosting-api Demonstrates creating a website and subsequently fetching its metadata including subdomain, URL, and root directory path. ```html ``` -------------------------------- ### Start Development Server Source: https://developer.puter.com/tutorials/puter-js-next-js Command to launch the local development server. ```bash npm run dev ``` -------------------------------- ### Generate Image with Grok 2 (Node.js) Source: https://developer.puter.com/ai/x-ai/grok-2-image Use the Puter.js AI API to generate an image from a text prompt using the Grok 2 Image model. No API keys or setup are required. Install the library using `npm install @heyputer/puter.js`. ```javascript // npm install @heyputer/puter.js import { puter } from '@heyputer/puter.js'; puter.ai.txt2img("A serene mountain landscape at sunset", { model: "x-ai/grok-2-image" }).then(image => { document.body.appendChild(image); }); ``` -------------------------------- ### Create a POST Endpoint Source: https://developer.puter.com/tutorials/serverless-functions-on-puter Use the router API to create a POST endpoint that returns a JSON response. This is a basic example for starting with serverless functions. ```javascript router.post("/api/hello", async ({ request, user, params }) => { return { message: "Hello, World!" }; }); ``` -------------------------------- ### Full Example: ElevenLabs Text-to-Speech with Format Selection Source: https://developer.puter.com/tutorials/free-unlimited-elevenlabs-api This HTML example integrates the Puter SDK to allow users to input text, select an audio output format from a dropdown, and generate speech using the ElevenLabs provider. ```html
``` -------------------------------- ### Manage TCP Socket Events and Data Source: https://developer.puter.com/networking Handle the 'open' event for a TCP socket to send data. This example demonstrates sending an HTTP GET request. ```javascript // Open a TCP socket connection const socket = new puter.net.Socket("example.com", 80); // Open a secure TLS socket connection const tlsSocket = new puter.net.tls.TLSSocket("example.com", 443); // Send data when connected socket.on("open", () => { socket.write("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"); }); // Fetch without CORS restrictions const response = await puter.net.fetch("https://api.example.com"); ``` -------------------------------- ### Generate Image with GPT Image 2 (Node.js) Source: https://developer.puter.com/ai/openai/gpt-image-2 Use the Puter.js AI API to generate an image from a text prompt. This example requires the `@heyputer/puter.js` package to be installed. ```javascript // npm install @heyputer/puter.js import { puter } from '@heyputer/puter.js'; puter.ai.txt2img("A serene mountain landscape at sunset", { model: "openai/gpt-image-2" }).then(image => { document.body.appendChild(image); }); ``` -------------------------------- ### Installation Methods Source: https://developer.puter.com/blog/aion-2-in-puter-js Provides options for integrating Puter.js via npm or a direct script tag. ```javascript // npm install @heyputer/puter.js import { puter } from '@heyputer/puter.js'; ``` ```html ``` -------------------------------- ### Chat with Z.AI using Puter.js (npm) Source: https://developer.puter.com/ai/z-ai Use this snippet to interact with Z.AI models via npm. Ensure you have installed the Puter.js library. This example uses the 'z-ai/glm-5' model. ```javascript // npm install @heyputer/puter.js import { puter } from '@heyputer/puter.js'; puter.ai.chat("Explain AI like I'm five!", { model: "z-ai/glm-5" }).then(response => { console.log(response); }); ``` -------------------------------- ### Tool/Function Calling Setup Source: https://developer.puter.com/tutorials/use-litellm-with-puter Prepare for tool/function calling by importing necessary libraries like `json` and `litellm`. ```python import json from litellm import completion ``` -------------------------------- ### Initialize Node.js Project Source: https://developer.puter.com/tutorials/puter-js-node-js Create a new directory, initialize a Node.js project, and enable ES modules. ```bash mkdir puter-node cd puter-node npm init -y ``` ```json { "name": "puter-node", "type": "module" } ``` ```bash npm i @heyputer/puter.js ``` -------------------------------- ### Chat with Qwen using Puter.js (Node.js) Source: https://developer.puter.com/ai/qwen Install the Puter.js library via npm and use the `puter.ai.chat` method to interact with Qwen models. This example uses the `qwen/qwen3.5-flash-02-23` model. ```javascript // npm install @heyputer/puter.js import { puter } from '@heyputer/puter.js'; puter.ai.chat("Explain AI like I'm five!", { model: "qwen/qwen3.5-flash-02-23" }).then(response => { console.log(response); }); ``` -------------------------------- ### Deploy a multi-page website using Puter SDK Source: https://developer.puter.com/tutorials/free-unlimited-hosting-api Creates a directory, populates it with site assets, and deploys the content to a unique subdomain. ```html ``` -------------------------------- ### Chat with Moonshot v1 Auto using Python (OpenAI client) Source: https://developer.puter.com/ai/moonshotai/moonshot-v1-auto Interact with Moonshot v1 Auto using the OpenAI Python client. Ensure you have installed the library with `pip install openai`. Configure the `base_url` to `https://api.puter.com/puterai/openai/v1/` and use your PUTER_AUTH_TOKEN for authentication. This example prints the content of the first message choice. ```python # pip install openai from openai import OpenAI client = OpenAI( base_url="https://api.puter.com/puterai/openai/v1/", api_key="YOUR_PUTER_AUTH_TOKEN", ) response = client.chat.completions.create( model="moonshotai/moonshot-v1-auto", messages=[ {"role": "user", "content": "Explain quantum computing in simple terms"} ], ) print(response.choices[0].message.content) ``` -------------------------------- ### Chat with Perceptron Mk1 using Puter.js (npm) Source: https://developer.puter.com/ai/perceptron Install Puter.js via npm and use the `puter.ai.chat` method to interact with the Perceptron Mk1 model. This example is suitable for Node.js environments. ```javascript // npm install @heyputer/puter.js import { puter } from '@heyputer/puter.js'; puter.ai.chat("Explain AI like I'm five!", { model: "perceptron/perceptron-mk1" }).then(response => { console.log(response); }); ``` -------------------------------- ### Create Directory, Write, and List Contents Source: https://developer.puter.com/tutorials/free-unlimited-cloud-storage-api Shows how to create a new directory, write a file into it, and then list the contents of that directory. This is useful for organizing files. ```html ``` -------------------------------- ### Basic Text Generation with DeepSeek v4 Flash Source: https://developer.puter.com/tutorials/free-unlimited-deepseek-api Use DeepSeek v4 Flash for everyday text generation tasks. This example shows how to get a simple explanation of quantum entanglement. ```html ``` -------------------------------- ### Initialize Next.js Project Source: https://developer.puter.com/tutorials/puter-js-next-js Commands to create a new Next.js project and navigate into the directory. ```bash npx create-next-app@latest puter-nextjs ``` ```bash cd puter-nextjs ``` -------------------------------- ### Full HTML Example for HiDream I1 Full Source: https://developer.puter.com/tutorials/free-unlimited-hidream-api A complete HTML file demonstrating how to integrate HiDream I1 Full image generation using Puter.js. ```html

HiDream I1 Full Image Generation

``` -------------------------------- ### Get File Information with Puter.js Source: https://developer.puter.com/tutorials/free-unlimited-cloud-storage-api Retrieve detailed information about files and directories, including name, size, path, creation, and modification times. This example first writes a file to ensure it exists. ```html ``` -------------------------------- ### Generate Image from Text (npm) Source: https://developer.puter.com/ai/stabilityai Use the Puter.js library to generate an image from a text prompt. Ensure you have installed the library using npm. This example appends the generated image element to the document body. ```javascript // npm install @heyputer/puter.js import { puter } from '@heyputer/puter.js'; puter.ai.txt2img("A beautiful sunset", { model: "stabilityai/stable-diffusion-3-medium" }).then(imageElement => { document.body.appendChild(imageElement); }); ``` -------------------------------- ### Python (OpenAI SDK) Source: https://developer.puter.com/ai/qwen/qwen3-14b Example of how to use Qwen3 14B with the OpenAI Python client library, configured for the Puter.com API. ```APIDOC ## Chat with Qwen3 14B using Python and OpenAI SDK ### Description This snippet demonstrates using the `openai` Python library to interact with the Qwen3 14B model via the Puter.com API endpoint. ### Method `client.chat.completions.create(model, messages)` ### Parameters - **model** (string) - Required - The identifier for the AI model, e.g., "qwen/qwen3-14b". - **messages** (array) - Required - A list of message objects, each with a `role` and `content`. - **role** (string) - The role of the message sender (e.g., "user", "system", "assistant"). - **content** (string) - The text of the message. ### Request Example ```python # pip install openai from openai import OpenAI client = OpenAI( base_url="https://api.puter.com/puterai/openai/v1/", api_key="YOUR_PUTER_AUTH_TOKEN", ) response = client.chat.completions.create( model="qwen/qwen3-14b", messages=[ {"role": "user", "content": "Explain quantum computing in simple terms"} ], ) print(response.choices[0].message.content) ``` ``` -------------------------------- ### Full HTML Example for Code Generation Source: https://developer.puter.com/tutorials/free-unlimited-poolside-ai-api A complete HTML file demonstrating code generation using Laguna M.1 via Puter.js. ```html ``` -------------------------------- ### Chat with Moonshot v1 32K Vision using Python Source: https://developer.puter.com/ai/moonshotai/moonshot-v1-32k-vision-preview This Python example uses the OpenAI client library to communicate with the model. Ensure you have the 'openai' library installed and replace 'YOUR_PUTER_AUTH_TOKEN' with your actual token. ```python # pip install openai from openai import OpenAI client = OpenAI( base_url="https://api.puter.com/puterai/openai/v1/", api_key="YOUR_PUTER_AUTH_TOKEN", ) response = client.chat.completions.create( model="moonshotai/moonshot-v1-32k-vision-preview", messages=[ {"role": "user", "content": "Explain quantum computing in simple terms"} ], ) print(response.choices[0].message.content) ``` -------------------------------- ### Chat with Morph AI using Puter.js (npm) Source: https://developer.puter.com/ai/morph Use this snippet to initiate a chat with a Morph AI model via npm. Ensure you have installed the @heyputer/puter.js package. This example uses the 'morph/morph-v3-fast' model. ```javascript // npm install @heyputer/puter.js import { puter } from '@heyputer/puter.js'; puter.ai.chat("Explain AI like I'm five!", { model: "morph/morph-v3-fast" }).then(response => { console.log(response); }); ``` -------------------------------- ### Traditional LLM API Key Setup Source: https://developer.puter.com/tutorials/litellm-with-openai-claude-gemini-grok Demonstrates the traditional method of setting environment variables for different LLM providers. This highlights the complexity LiteLLM with Puter aims to simplify. ```bash # The traditional way — one API key per provider export OPENAI_API_KEY="sk-..." # for GPT models export ANTHROPIC_API_KEY="sk-ant-..." # for Claude models export GEMINI_API_KEY="AIza..." # for Gemini models ``` -------------------------------- ### Chat with Meituan AI using Puter.js (npm) Source: https://developer.puter.com/ai/meituan Use this snippet to interact with Meituan AI models via npm. Ensure you have installed the @heyputer/puter.js package. This example demonstrates a basic chat request. ```javascript // npm install @heyputer/puter.js import { puter } from '@heyputer/puter.js'; puter.ai.chat("Explain AI like I'm five!", { model: "meituan/longcat-flash-chat" }).then(response => { console.log(response); }); ``` -------------------------------- ### Full Text-to-Video Generation Example Source: https://developer.puter.com/tutorials/free-unlimited-wan-ai-api A complete HTML example demonstrating WAN 2.2 Text-to-Video generation. It includes a status indicator to show loading progress and finalization time. Error handling is also included. ```html

Wan 2.2 Text-to-Video Generation

``` -------------------------------- ### Chat with Gryphe AI using Puter.js (npm) Source: https://developer.puter.com/ai/gryphe Use this snippet to interact with Gryphe AI models via npm. Ensure you have installed the Puter.js library. This example uses the MythoMax 13B model. ```javascript // npm install @heyputer/puter.js import { puter } from '@heyputer/puter.js'; puter.ai.chat("Explain AI like I'm five!", { model: "gryphe/mythomax-l2-13b" }).then(response => { console.log(response); }); ``` -------------------------------- ### JavaScript (npm) Source: https://developer.puter.com/ai/openai/gpt-audio-mini Example of using GPT Audio Mini with Puter.js in a Node.js environment. ```APIDOC ## JavaScript (npm) ### Description Use the Puter.js library to interact with GPT Audio Mini in a Node.js application. ### Method `puter.ai.chat(prompt, options)` ### Parameters - **prompt** (string) - Required - The text prompt for the AI. - **options** (object) - Required - Configuration options for the AI call. - **model** (string) - Required - Specifies the model to use, e.g., "openai/gpt-audio-mini". ### Request Example ```javascript // npm install @heyputer/puter.js import { puter } from '@heyputer/puter.js'; puter.ai.chat("Explain quantum computing in simple terms", { model: "openai/gpt-audio-mini" }).then(response => { console.log(response.message.content); }); ``` ### Response #### Success Response - **message.content** (string) - The AI's response content. ``` -------------------------------- ### Complete Example: Cohere Text Generation Source: https://developer.puter.com/tutorials/free-unlimited-cohere-api A full HTML example demonstrating how to include the Puter.js library and use it to generate text with the Cohere Command model. ```html ``` -------------------------------- ### Chat with Essential AI using Puter.js (npm) Source: https://developer.puter.com/ai/essentialai Use this snippet to interact with Essential AI models via npm. Ensure you have installed the Puter.js library. This example demonstrates a basic chat interaction. ```javascript // npm install @heyputer/puter.js import { puter } from '@heyputer/puter.js'; puter.ai.chat("Explain AI like I'm five!", { model: "essentialai/rnj-1-instruct" }).then(response => { console.log(response); }); ``` -------------------------------- ### Make a Text-to-Speech API Call with ElevenLabs Source: https://developer.puter.com/tutorials/how-to-get-elevenlabs-api-key Use the ElevenLabs SDK to convert text to speech. This example shows how to get the raw response, including headers like character count and request ID. ```javascript import { ElevenLabsClient } from '@elevenlabs/elevenlabs-js'; const client = new ElevenLabsClient({ apiKey: 'your_api_key' }); // Get raw response with headers const { data, rawResponse } = await client.textToSpeech .convert('voice_id', { text: 'Hello, world!', modelId: 'eleven_multilingual_v2', }) .withRawResponse(); // Access character cost from headers const charCost = rawResponse.headers.get('x-character-count'); const requestId = rawResponse.headers.get('request-id'); const audioData = data; ``` -------------------------------- ### JavaScript (npm) Source: https://developer.puter.com/ai/qwen/qwen3-14b Example of how to use Qwen3 14B with Puter.js in a Node.js environment. ```APIDOC ## Chat with Qwen3 14B using Puter.js ### Description This snippet demonstrates how to send a chat message to the Qwen3 14B model using the Puter.js library. ### Method `puter.ai.chat(prompt, options)` ### Parameters - **prompt** (string) - Required - The user's message or question. - **options** (object) - Required - Configuration options for the AI call. - **model** (string) - Required - The identifier for the AI model to use, e.g., "qwen/qwen3-14b". ### Response - **response.message.content** (string) - The content of the AI's response. ### Request Example ```javascript // npm install @heyputer/puter.js import { puter } from '@heyputer/puter.js'; puter.ai.chat("Explain quantum computing in simple terms", { model: "qwen/qwen3-14b" }).then(response => { document.body.innerHTML = response.message.content; }); ``` ```