---
title: "From OpenAI to Open LLMs with Messages API on Hugging Face"
description: "Text Generation Inference 1.4.0 adds a Messages API compatible with OpenAI's Chat Completion API, so open LLMs on Inference Endpoints can be called from existing OpenAI client code by changing the base URL and token."
url: "https://swe.quest/articles/from-openai-to-open-llms-with-messages-api-on-hugging-face-98058f09a7d2acc1"
canonical: "https://huggingface.co/blog/tgi-messages-api"
source: "Hugging Face"
published: "2024-02-08"
difficulty: "medium"
kind: "How-to"
reading_minutes: 7
tags: ["inference","llms","api-design","rag"]
---

# From OpenAI to Open LLMs with Messages API on Hugging Face

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2024-02-08, 7 min read, How-to. Original: [https://huggingface.co/blog/tgi-messages-api](https://huggingface.co/blog/tgi-messages-api)

## Summary

Text Generation Inference 1.4.0 adds a Messages API compatible with OpenAI's Chat Completion API, so open LLMs on Inference Endpoints can be called from existing OpenAI client code by changing the base URL and token. The guide deploys Nous-Hermes-2-Mixtral-8x7B-DPO via huggingface\_hub with TGI token-limit settings and then calls it from the OpenAI Python and JavaScript clients. It also plugs the endpoint into LangChain (ChatOpenAI) and LlamaIndex (OpenAILike) RAG pipelines. Limitations: no function calling, only models with a chat\_template, and a subset of parameters (stream, max\_tokens, temperature, top\_p, seed, logprobs, frequency\_penalty).

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [API design](https://swe.quest/tags/api-design.md) (Backend & APIs)
- [RAG & retrieval](https://swe.quest/tags/rag.md) (AI & ML)

## Prerequisites

- OpenAI Chat Completion API
- Python ([easy posts on Python](https://swe.quest/tags/python.md?difficulty=easy))
- RAG basics ([easy posts on RAG & retrieval](https://swe.quest/tags/rag.md?difficulty=easy))

## Keywords

Text Generation Inference, Messages API, Inference Endpoints, OpenAI API, LangChain, LlamaIndex, Mixtral 8x7B, huggingface\_hub

## Related posts

- [Inference for PROs](https://swe.quest/articles/inference-for-pros-8849074774f039ec.md): Hugging Face · 2023-09-22 · Medium · 10 min read · Inference & serving, LLMs, API design, Python
  Hugging Face PRO subscribers get curated, rate-limit-boosted HTTP inference endpoints served by text-generation-inference for models such as Llama 3, Mixtral 8x7B, Zephyr, Code Llama, Stable Diffusion XL and Bark, intended for prototyping rather than heavy production (Inference Endpoints is recommended for that).
- [Hugging Face x LangChain : A new partner package](https://swe.quest/articles/hugging-face-x-langchain-a-new-partner-package-4a05b92542fbd2d8.md): Hugging Face · 2024-05-14 · Medium · 4 min read · LLMs, Python, Inference & serving, RAG & retrieval
  langchain-huggingface is a new Python partner package jointly maintained by Hugging Face and LangChain, replacing community-written integrations that had drifted out of date.
- [Deploy LLMs with Hugging Face Inference Endpoints](https://swe.quest/articles/deploy-llms-with-hugging-face-inference-endpoints-3facefc244b0efa0.md): Hugging Face · 2023-07-04 · Medium · 6 min read · Inference & serving, LLMs, Python, JavaScript
  Falcon 40B Instruct can be deployed to Hugging Face Inference Endpoints through the web UI by choosing a repository, cloud, region and instance.
- [Tool Use, Unified](https://swe.quest/articles/tool-use-unified-117f148d6f2c2374.md): Hugging Face · 2024-08-12 · Medium · 11 min read · LLMs, AI agents, Python, API design
  Hugging Face Transformers extends Jinja chat templates to cover tool use, giving a single portable API for passing tools to Mistral, Cohere, NousResearch and Llama models.
- [Local LLM Messenger: Chat with GenAI on Your iPhone](https://swe.quest/articles/local-llm-messenger-chat-with-genai-on-your-iphone-7541b86ddf4d704e.md): Docker · 2024-07-23 · Medium · 13 min read · LLMs, Python, Containers
  Local LLM Messenger (LoLLMM), an honorable-mention project from Docker's AI/ML Hackathon by Justin Garrison, lets you send iMessages to LLMs running on your own machine.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
