For the complete documentation index, see llms.txt. This page is also available as Markdown.

How to using api integration guide

Connect to your vLLM endpoint from code. The vLLM API is OpenAI-compatible, so any OpenAI SDK works. Examples in curl, Python, and JavaScript.

Prerequisite: A running vLLM endpoint (see the vLLM Docker Deployment Guide).

1. Endpoint Basics

Item
Value

Base URL

http://<server-ip>:8000/v1 or https://api.yourdomain.com/v1

Auth

Authorization: Bearer <your-api-key>

Format

OpenAI-compatible

Main endpoints

/v1/chat/completions, /v1/completions, /v1/models, /v1/embeddings

List Available Models

curl http://<server-ip>:8000/v1/models \
  -H "Authorization: Bearer sk-your-key"

The id field in the response is the model name to use in requests.

2. curl

Basic Chat Completion

curl http://<server-ip>:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-your-key" \
  -d '{
    "model": "Qwen/Qwen2.5-7B-Instruct-AWQ",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Explain Docker in one sentence."}
    ],
    "temperature": 0.7,
    "max_tokens": 256
  }'

Extract Just the Answer (with jq)

Install the OpenAI SDK

3. Python

Basic Chat

Multi-Turn Conversation

Using requests (no SDK)

4. JavaScript / Node.js

Basic Chat

Using fetch (no SDK)

5. Streaming Responses

Streaming returns tokens as they're generated (like ChatGPT typing). Set stream: true.

Python (streaming)

JavaScript (streaming)

curl (streaming)

6. Embeddings API

If you run an embedding server (see AnythingLLM/RAG guide), call it the same way.

Python

curl

7. Common Parameters

Parameter
Type
Description

model

string

Model name (from /v1/models)

messages

array

Conversation history (chat endpoint)

temperature

float

Randomness 0.0-2.0 (lower = focused, higher = creative)

max_tokens

int

Max tokens to generate

top_p

float

Nucleus sampling (0.0-1.0)

stream

bool

Stream tokens as generated

stop

array

Stop sequences

frequency_penalty

float

Reduce repetition (-2.0 to 2.0)

presence_penalty

float

Encourage new topics (-2.0 to 2.0)

Use Case
temperature
Notes

Factual Q&A

0.1-0.3

Consistent, focused

Coding

0.0-0.2

Deterministic

Creative writing

0.7-1.0

More varied

Structured/JSON output

0.0-0.1

Predictable format

JSON Output

Instruct the model and (optionally) use guided decoding:

guided_json is a vLLM extension via extra_body — enforces valid JSON matching your schema.

8. Error Handling

Python

Common Errors

Error
Cause
Fix

Connection refused

vLLM not running / wrong URL

Check docker compose ps, verify URL

401 Unauthorized

Wrong/missing API key

Match --api-key value

404 model not found

Wrong model name

Use exact name from /v1/models

400 context length exceeded

Input too long

Reduce input or raise --max-model-len

Timeout

Long generation

Increase client timeout, reduce max_tokens

Set Client Timeout

Quick Reference

Language
SDK Install
Import

Python

pip install openai

from openai import OpenAI

Node.js

npm install openai

import OpenAI from "openai"

Any

Direct HTTP to /v1/chat/completions

Was this helpful?