canonical: https://jentic.com/apis/ai21.com/ai21

# AI21 Labs API

Jentic publishes the only available OpenAPI specification for AI21 Labs API, keeping it validated and agent-ready. The AI21 Labs API runs large language model chat completions and text embeddings, tokenizes and detokenizes text, and manages a document library for retrieval. It gives agents direct access to AI21's language models for generation and semantic search.

## For AI agents

Run chat completions against AI21's language models, generate text embeddings, tokenize and detokenize text, and manage documents in the retrieval library.

## Scope

Does not fine-tune models, host inference endpoints, or manage billing. Use for AI21 text generation, embeddings, and retrieval only.

## Capabilities

- Run chat completions against AI21's language models
- Generate text embeddings for semantic search and retrieval
- Tokenize and detokenize text to manage context length
- Upload and manage documents in the retrieval library
- Retrieve a previous chat completion by its request identifier

## Use cases

### Agent Language Generation

An AI agent can call the chat completion operation to summarize, rewrite, or answer from a prompt using AI21's language models. Because the request and response formats are structured, the agent can chain generation into a larger workflow without bespoke parsing. Through Jentic the agent discovers the completion operation by intent and runs it with the token injected at call time.

Example prompt: Generate a summary of this support ticket using a chat completion

### Semantic Search Over Documents

An agent can embed a set of documents, store them in the retrieval library, and later embed a query to find the most relevant passages. This gives retrieval-augmented answers without standing up a separate vector database. The agent works only with the files it uploads.

Example prompt: Embed these 20 FAQ entries and store them for retrieval

### Context-Length Management

Before sending a long prompt, an agent can tokenize the text to measure its length and trim it to fit the model's context window, then detokenize when it needs to inspect tokens. This avoids failed requests from oversized inputs. The check runs as a lightweight preflight step.

Example prompt: Tokenize this document and tell me if it fits the model's context window

## Key endpoints

| Method | Path | Description |
| --- | --- | --- |
| POST | `/chat/completions` | Run a chat completion |
| POST | `/embed` | Generate text embeddings |
| POST | `/tokenize` | Tokenize text |
| POST | `/detokenize` | Convert tokens back to text |
| GET | `/library/files` | List documents in the retrieval library |
| POST | `/library/files` | Upload a document to the retrieval library |

## Key resources

- **Chat completions** — Language model generation with a structured request and response
- **Embeddings** — Vector representations of text for semantic search
- **Tokenizer** — Tokenize and detokenize text to manage context length
- **Document library** — Uploaded files stored for retrieval

## Why Jentic

- **Setup:** Wiring the AI21 Labs API by hand means obtaining a bearer token, setting the Authorization header on every request, and handling the completion, embedding, and library request formats yourself. Through Jentic you install once, import AI21 from the API Directory, store the token once, and your agent calls it.
- **Permission scoping:** AI21 carries each request's input in the body rather than the URL path, so rules bound which operations the agent may call. You can allow completions and embeddings while keeping the agent out of the document library, or restrict it to read-only library access.
- **Credential handling:** Your AI21 bearer token is stored once, encrypted, by your own Jentic One instance and injected at execution time. It never enters the agent's prompt, logs, or context.
- **Discovery method:** Agents search Jentic by intent such as 'generate a chat completion' or 'create text embeddings', and Jentic returns the matching AI21 Labs operation with its input schema so the agent calls the right endpoint without reading the reference docs.

## Related APIs

- **OpenAI** — OpenAI offers chat completions and embeddings from its own model family.
- **Anthropic** — Anthropic's Messages API runs Claude models for chat-style generation.
- **Cohere** — Cohere provides generation and embeddings with a strong retrieval focus.

## FAQ

### Why is there no official OpenAPI spec for AI21 Labs API?

AI21 Labs does not publish an OpenAPI specification. Jentic generates and maintains this spec so that AI agents and developers can call the AI21 Labs API via structured tooling. It is validated against the live API and kept up to date. To run it on your own infrastructure, install Jentic One from its GitHub repo.

### Is there an AI21 Labs MCP server?

You don't need an MCP server to give your agent the AI21 Labs API. Jentic connects it directly from the API Directory: import it, store your bearer token once, and your agent runs completions and embeddings. No extra server sits in the agent's context.

### Can I limit what my agent is allowed to do with the AI21 Labs API?

Yes. You choose which operations the agent may call, so it can be allowed to run completions and embeddings while being kept out of the document library, or restricted to read-only library access. Requests carry their input in the body rather than the URL path, so rules bound which operations the agent may use. Every call is logged.

### What authentication does the AI21 Labs API use?

The AI21 Labs API authenticates with a bearer token in the Authorization header, per its OpenAPI spec. Through Jentic the token is stored encrypted by your own Jentic One instance and injected when the agent makes a call, so it never appears in the agent's prompt or logs.

### Can my agent do semantic search with the AI21 Labs API?

Yes. The embeddings operation turns text into vectors, and the document library stores files for retrieval, so an agent can embed a query and find the most relevant passages without a separate vector service.

### What are the rate limits for the AI21 Labs API?

The OpenAPI spec does not specify rate limits; AI21 applies per-plan quotas. Check the AI21 Labs documentation for the current limits before scaling an agent's usage.

### How does my agent run a completion with the AI21 Labs API through Jentic?

Search Jentic for 'generate a chat completion' and it returns the AI21 Labs completion operation with its input schema. Store your bearer token once, then the agent sends a prompt and reads back the generated text.
