Use LangChain with Datagram

Build chains, agents and RAG with LangChain on open models hosted on our own Apple Silicon, in Python or JavaScript.

Works with Datagram AI

All guides · API quickstart · Last checked: Settings from the app's official documentation, November 2026; requests use our standard OpenAI-compatible API

  1. 1. Create an accountSign up in a minute and get $5 of free credit. Already a customer? Sign in.
  2. 2. Make an API keyIn your account, open AI API and press Create key. Keys start with dgk_. Keep yours secret.
  3. 3. Follow the steps belowCopy each block, paste your key where it says dgk_your_key_here.

Python

pip install -U langchain-openai
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="gemma4:26b-nvfp4",
    base_url="https://api.datagram.net/v1",
    api_key="dgk_your_key_here",
)
print(llm.invoke("Say hello in five words.").text)

Or set OPENAI_BASE_URL / OPENAI_API_KEY in the environment and leave them out of the code.

JavaScript / TypeScript

npm install @langchain/openai @langchain/core
import { ChatOpenAI } from "@langchain/openai";

// export OPENAI_API_KEY=dgk_your_key_here
const llm = new ChatOpenAI({
  model: "gemma4:26b-nvfp4",
  configuration: { baseURL: "https://api.datagram.net/v1" },
});
console.log((await llm.invoke("Say hello in five words.")).content);

Embeddings (for search and RAG)

from langchain_openai import OpenAIEmbeddings

emb = OpenAIEmbeddings(model="qwen3-embedding:8b", base_url="https://api.datagram.net/v1", api_key="dgk_your_key_here")
vectors = emb.embed_documents(["first text", "second text"])

Use an embedding model from GET https://api.datagram.net/v1/models; the quickstart lists them.

Which model?

gemma4:26b-nvfp4 for general chains, qwen3-coder:30b-64k for agents with tools or long inputs, gpt-oss:120b for harder reasoning.

If something goes wrong

401 "Missing API key" or "Invalid or revoked API key"

Check the key is pasted in full (it starts with dgk_) and hasn't been revoked in your account under AI API.

402 "credit has run out"

Add credit in your account under AI API. Credit never expires.

Usage numbers missing when streaming

Some OpenAI-compatible servers don't send usage while streaming. Ours does; if a proxy in between doesn't, the JS client accepts streamUsage: false.

Questions

Which model should I use?

gemma4:26b-nvfp4 for everyday chat (quick, can see images); gpt-oss:120b for harder questions; qwen3-coder:30b-64k for very long inputs.

Is it private?

Yes. Requests run on our own Macs in our datacenter, and we never store prompts or answers, only counts for billing.

Create an account Get an API key More guides →