Appearance
Llama 3.1 8B ​
End of Life
Llama 3.1 8B reached end of life on 12 October 2026 and is no longer available. See the models overview for currently available models.
The documentation below is retained for historical reference.
Overview ​
Llama-3.1-8B is a compact yet capable large language model (LLM) developed by Meta, part of the Llama 3 family. With 8 billion parameters, it strikes a balance between performance and efficiency, making it ideal for resource-constrained environments and real-time inference scenarios. The model supports a context length of up to 128K tokens.
Use Cases ​
Well-suited for lightweight chatbots, virtual assistants, and AI applications where latency or cost-efficiency is critical. Despite its smaller size, it demonstrates strong performance on instruction-following tasks, basic reasoning, summarization, and coding support such as code suggestions and completions.
Model Card: Llama 3.1 8B
Endpoints ​
1. Create Chat Completion ​
POST /v1/chat/completions
Description ​
Generates a conversational response based on the input messages.
Request Body ​
json
{
"model": "meta/llama-3.1-8b-instruct",
"messages": [
{
"role": "user",
"content": "What is the capital of Switzerland?"
}
],
"temperature": 0.7,
"max_completion_tokens": 100,
"stream" : "false"
}| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | ID of the model to use. Only meta/llama-3.1-8b-instruct is available. |
messages | array | Yes | List of messages in the conversation. Each message must include a role and content. |
temperature | number | No | Sampling temperature (0-2). Higher values make output more random. Default: 1. |
max_completion_tokens | integer | No | Maximum number of tokens to generate for the completion. |
stream | boolean | No | If true, the response will be streamed in chunks. Default: false. |
Response (When stream is false) ​
json
{
"id": "chat-abcdefg1234567",
"object": "chat.completion",
"created": 1743765837,
"model": "meta/llama-3.1-8b-instruct",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The capital of Switzerland is Bern."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 17,
"completion_tokens": 7,
"total_tokens": 24
}
}| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for the chat completion. |
object | string | Always "chat.completion". |
created | integer | Unix timestamp of when the chat completion was created. |
model | string | The model used to generate the completion. |
choices | array | List of generated responses. Each choice includes the message and finish_reason. |
usage | object | Token usage details, including prompt_tokens, completion_tokens, and total_tokens. |
Response (When stream is true) ​
The response is streamed in chunks. Each chunk contains a part of the generated message.
First Chunk ​
json
{
"id": "chat-abcdefg1234567",
"object": "chat.completion.chunk",
"created": 1743765837,
"model": "meta/llama-3.1-8b-instruct",
"choices": [
{
"index": 0,
"delta": {
"role": "assistant",
"content": "The capital of"
},
"finish_reason": null
}
]
}Subsequent Chunk ​
json
{
"id": "chat-abcdefg1234567",
"object": "chat.completion.chunk",
"created": 1743765838,
"model": "meta/llama-3.1-8b-instruct",
"choices": [
{
"index": 0,
"delta": {
"content": " Switzerland is Bern."
},
"finish_reason": null
}
]
}Final Chunk ​
json
{
"id": "chat-abcdefg1234567",
"object": "chat.completion.chunk",
"created": 1743765839,
"model": "meta/llama-3.1-8b-instruct",
"choices": [
{
"index": 0,
"delta": {},
"finish_reason": "stop"
}
]
}| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for the chat completion. |
object | string | Always "chat.completion.chunk" for streaming responses. |
created | integer | Unix timestamp of when the chunk was created. |
model | string | The model used to generate the completion. |
choices | array | List of incremental responses. Each choice includes the delta and finish_reason. |
delta | object | Contains the incremental part of the response. |
finish_reason | string/null | Indicates why the response generation stopped. |
2. List Models ​
GET /v1/models
Description ​
Lists all available models and their metadata.
Response ​
json
{
"object": "list",
"data": [
{
"id": "meta/llama-3.1-8b-instruct",
"object": "model",
"created": 1672531200,
"owned_by": "SwissAI"
}
]
}| Field | Type | Description |
|---|---|---|
id | string | Model identifier. |
object | string | Always "model". |
created | integer | Unix timestamp of model creation. |
owned_by | string | Organization owning the model. |
Example Code Snippets ​
Note:
The production URL for this API is available in the corresponding plan for this model in the Digital Marketplace. To retrieve the URL:
- Navigate to the Digital Marketplace.
- Go to the Documentation section.
- Select the plan associated with the
Llama 3.1 8bmodel.- Locate the production URL provided in the plan details.
- Set up the environment variable
API_URLto the production URL retrieved.
1. Using curl ​
Create Chat Completion ​
bash
curl -X POST $API_URL/v1/chat/completions \
-H "Authorization: Bearer $YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "meta/llama-3.1-8b-instruct",
"messages": [
{
"role": "user",
"content": "What is the capital of Switzerland?"
}
],
"temperature": 0.7,
"max_completion_tokens": 100
}'List Models ​
bash
curl -X GET $API_URL/v1/models \
-H "Authorization: Bearer YOUR_API_KEY"2. Using Python (OpenAI Client) ​
Create Chat Completion ​
python
import os
import openai
client = openai.OpenAI(
api_key=os.getenv("YOUR_API_KEY"),
base_url=os.getenv("API_URL") + "/v1",
)
response = client.chat.completions.create(
model="meta/llama-3.1-8b-instruct",
messages=[
{"role": "user", "content": "What is the capital of Switzerland?"}
],
temperature=0.7,
max_completion_tokens=100,
stream = True
)
for chunk in response:
print(chunk)
print(chunk.choices[0].delta)
print("****************")List Models ​
python
import os
import openai
client = openai.OpenAI(
api_key=os.getenv("YOUR_API_KEY"),
base_url=os.getenv("API_URL") + "/v1",
)
response = client.models.list()
print(response)Replace YOUR_API_KEY with your actual API key to authenticate the requests. You can follow the procedure in Inference Endpoints Overview

