Inference Providers documentation

Text Generation

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Text Generation

Generate text based on a prompt.

If you are interested in a Chat Completion task, which generates a response based on a list of messages, check out the chat-completion task.

For more details about the text-generation task, check out its dedicated page! You will find examples and related materials.

Recommended models

Explore all available models and find the one that suits you best here.

Using the API

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://router.huggingface.co/featherless-ai/v1/completions",
    api_key=os.environ["HF_TOKEN"],
)

completion = client.chat.completions.create(
    model="zai-org/GLM-5.2",
    messages="\"Can you please let us know more details about your \"",
)

print(completion.choices[0].message)

API specification

Request

Headers
authorizationstringAuthentication header in the form 'Bearer: hf_****' when hf_**** is a personal user access token with “Inference Providers” permission. You can generate one from your settings page.
Payload
inputs*string
parametersobject
        adapter_idstringLora adapter id
        best_ofintegerGenerate best_of sequences and return the one if the highest token logprobs.
        decoder_input_detailsbooleanWhether to return decoder input token logprobs and ids.
        detailsbooleanWhether to return generation details.
        do_samplebooleanActivate logits sampling.
        frequency_penaltynumberThe parameter for frequency penalty. 1.0 means no penalty Penalize new tokens based on their existing frequency in the text so far, decreasing the model’s likelihood to repeat the same line verbatim.
        grammarunknownOne of the following:
                 (#1)object
                        type*enumPossible values: json.
                        value*unknownA string that represents a JSON Schema. JSON Schema is a declarative language that allows to annotate JSON documents with types and descriptions.
                 (#2)object
                        type*enumPossible values: regex.
                        value*string
                 (#3)object
                        type*enumPossible values: json_schema.
                        value*object
                                namestringOptional name identifier for the schema
                                schema*unknownThe actual JSON schema definition
        max_new_tokensintegerMaximum number of tokens to generate.
        repetition_penaltynumberThe parameter for repetition penalty. 1.0 means no penalty. See this paper for more details.
        return_full_textbooleanWhether to prepend the prompt to the generated text
        seedintegerRandom sampling seed.
        stopstring[]Stop generating tokens if a member of stop is generated.
        temperaturenumberThe value used to module the logits distribution.
        top_kintegerThe number of highest probability vocabulary tokens to keep for top-k-filtering.
        top_n_tokensintegerThe number of highest probability vocabulary tokens to keep for top-n-filtering.
        top_pnumberTop-p value for nucleus sampling.
        truncateintegerTruncate inputs tokens to the given size.
        typical_pnumberTypical Decoding mass See Typical Decoding for Natural Language Generation for more information.
        watermarkbooleanWatermarking with A Watermark for Large Language Models.
streamboolean

Response

Output type depends on the stream input parameter. If stream is false (default), the response will be a JSON object with the following fields:

Body
detailsobject
        best_of_sequencesobject[]
                finish_reasonenumPossible values: length, eos_token, stop_sequence.
                generated_textstring
                generated_tokensinteger
                prefillobject[]
                        idinteger
                        logprobnumber
                        textstring
                seedinteger
                tokensobject[]
                        idinteger
                        logprobnumber
                        specialboolean
                        textstring
                top_tokensarray[]
                        idinteger
                        logprobnumber
                        specialboolean
                        textstring
        finish_reasonenumPossible values: length, eos_token, stop_sequence.
        generated_tokensinteger
        prefillobject[]
                idinteger
                logprobnumber
                textstring
        seedinteger
        tokensobject[]
                idinteger
                logprobnumber
                specialboolean
                textstring
        top_tokensarray[]
                idinteger
                logprobnumber
                specialboolean
                textstring
generated_textstring

If stream is true, generated tokens are returned as a stream, using Server-Sent Events (SSE). For more information about streaming, check out this guide.

Body
detailsobject
        finish_reasonenumPossible values: length, eos_token, stop_sequence.
        generated_tokensinteger
        input_lengthinteger
        seedinteger
generated_textstring
indexinteger
tokenobject
        idinteger
        logprobnumber
        specialboolean
        textstring
top_tokensobject[]
        idinteger
        logprobnumber
        specialboolean
        textstring
Update on GitHub