> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fireworks.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# API Reference

## BaseCompletion Objects

```python theme={null}
class BaseCompletion()
```

Base class for handling completions. This class provides shared logic for creating completions,\
both synchronously and asynchronously, and both streaming and non-streaming.

**Attributes**:

* `endpoint` *str* - API endpoint for the completion request.
* `response_class` *Type* - Class used for parsing the non-streaming response.
* `stream_response_class` *Type* - Class used for parsing the streaming response.

<a id="base_completion.BaseCompletion.create" />

#### create

```python theme={null}
@classmethod
def create(cls,
           model,
           prompt_or_messages=None,
           request_timeout=600,
           stream=False,
           **kwargs)
```

Create a completion or chat completion.

**Arguments**:

* `model` *str* - Model name to use for the completion.
* `prompt_or_messages` *Union\[str, List\[ChatMessage]]* - The prompt for Completion or a list of chat messages for ChatCompletion. If not specified, must specify either `prompt` or `messages` in kwargs.
* `request_timeout` *int, optional* - Request timeout in seconds. Defaults to 600.
* `stream` *bool, optional* - Whether to use streaming or not. Defaults to False.
* `**kwargs` - Additional keyword arguments.

**Returns**:

`Union[CompletionResponse, Generator[CompletionStreamResponse, None, None]]`:\
Depending on the `stream` argument, either returns a CompletionResponse\
or a generator yielding CompletionStreamResponse.

<a id="base_completion.BaseCompletion.acreate" />

#### acreate

```python theme={null}
@classmethod
def acreate(cls, model, *args, request_timeout=600, stream=False, **kwargs)
```

Asynchronously create a completion.

**Arguments**:

* `model` *str* - Model name to use for the completion.
* `request_timeout` *int, optional* - Request timeout in seconds. Defaults to 600.
* `stream` *bool, optional* - Whether to use streaming or not. Defaults to False.
* `**kwargs` - Additional keyword arguments.

**Returns**:

`Union[CompletionResponse, AsyncGenerator[CompletionStreamResponse, None]]`:\
Depending on the `stream` argument, either returns a CompletionResponse or an async generator yielding CompletionStreamResponse.

# completion

## Completion Objects

```python theme={null}
class Completion(BaseCompletion)
```

Class for handling text completions.

<a id="chat_completion" />

# chat\_completion

<a id="chat_completion.ChatCompletion" />

## ChatCompletion Objects

```python theme={null}
class ChatCompletion(BaseCompletion)
```

Class for handling chat completions.

<a id="api" />

# api

<a id="api.Choice" />

## Choice Objects

```python theme={null}
class Choice(BaseModel)
```

A completion choice.

**Attributes**:

* `index` *int* - The index of the completion choice.
* `text` *str* - The completion response.
* `logprobs` *float, optional* - The log probabilities of the most likely tokens.
* `finish_reason` *str* - The reason the model stopped generating tokens. This will be "stop" if the model hit a natural stop point or a provided stop sequence, or "length" if the maximum number of tokens specified in the request was reached.

<a id="api.CompletionResponse" />

## CompletionResponse Objects

```python theme={null}
class CompletionResponse(BaseModel)
```

The response message from a /v1/completions call.

**Attributes**:

* `id` *str* - A unique identifier of the response.
* `object` *str* - The object type, which is always "text\_completion".
* `created` *int* - The Unix time in seconds when the response was generated.
* `choices` *List\[Choice]* - The list of generated completion choices.

<a id="api.CompletionResponseStreamChoice" />

## CompletionResponseStreamChoice Objects

```python theme={null}
class CompletionResponseStreamChoice(BaseModel)
```

A streamed completion choice.

**Attributes**:

* `index` *int* - The index of the completion choice.
* `text` *str* - The completion response.
* `logprobs` *float, optional* - The log probabilities of the most likely tokens.
* `finish_reason` *str* - The reason the model stopped generating tokens. This will be "stop" if the model hit a natural stop point or a provided stop sequence, or "length" if the maximum number of tokens specified in the request was reached.

<a id="api.CompletionStreamResponse" />

## CompletionStreamResponse Objects

```python theme={null}
class CompletionStreamResponse(BaseModel)
```

The streamed response message from a /v1/completions call.

**Attributes**:

* `id` *str* - A unique identifier of the response.
* `object` *str* - The object type, which is always "text\_completion".
* `created` *int* - The Unix time in seconds when the response was generated.
* `model` *str* - The model used for the chat completion.\
  choices (List\[CompletionResponseStreamChoice]):\
  The list of streamed completion choices.

<a id="api.Model" />

## Model Objects

```python theme={null}
class Model(BaseModel)
```

A model deployed to the Fireworks platform.

**Attributes**:

* `id` *str* - The model name.
* `object` *str* - The object type, which is always "model".
* `created` *int* - The Unix time in seconds when the model was generated.

<a id="api.ListModelsResponse" />

## ListModelsResponse Objects

```python theme={null}
class ListModelsResponse(BaseModel)
```

The response message from a /v1/models call.

**Attributes**:

* `object` *str* - The object type, which is always "list".
* `data` *List\[Model]* - The list of models.

<a id="api.ChatMessage" />

## ChatMessage Objects

```python theme={null}
class ChatMessage(BaseModel)
```

A chat completion message.

**Attributes**:

* `role` *str* - The role of the author of this message.
* `content` *str* - The contents of the message.

<a id="api.ChatCompletionResponseChoice" />

## ChatCompletionResponseChoice Objects

```python theme={null}
class ChatCompletionResponseChoice(BaseModel)
```

A chat completion choice generated by a chat model.

**Attributes**:

* `index` *int* - The index of the chat completion choice.
* `message` *ChatMessage* - The chat completion message.
* `finish_reason` *Optional\[str]* - The reason the model stopped generating tokens. This will be "stop" if the model hit a natural stop point or a provided stop sequence, or "length" if the maximum number of tokens specified in the request was reached.

<a id="api.UsageInfo" />

## UsageInfo Objects

```python theme={null}
class UsageInfo(BaseModel)
```

Usage statistics.

**Attributes**:

* `prompt_tokens` *int* - The number of tokens in the prompt.
* `total_tokens` *int* - The total number of tokens used in the request (prompt + completion).
* `completion_tokens` *Optional\[int]* - The number of tokens in the generated completion.

<a id="api.ChatCompletionResponse" />

## ChatCompletionResponse Objects

```python theme={null}
class ChatCompletionResponse(BaseModel)
```

The response message from a /v1/chat/completions call.

**Attributes**:

* `id` *str* - A unique identifier of the response.
* `object` *str* - The object type, which is always "chat.completion".
* `created` *int* - The Unix time in seconds when the response was generated.
* `model` *str* - The model used for the chat completion.
* `choices` *List\[ChatCompletionResponseChoice]* - The list of chat completion choices.
* `usage` *UsageInfo* - Usage statistics for the chat completion.

<a id="api.DeltaMessage" />

## DeltaMessage Objects

```python theme={null}
class DeltaMessage(BaseModel)
```

A message delta.

**Attributes**:

* `role` *str* - The role of the author of this message.
* `content` *str* - The contents of the chunk message.

<a id="api.ChatCompletionResponseStreamChoice" />

## ChatCompletionResponseStreamChoice Objects

```python theme={null}
class ChatCompletionResponseStreamChoice(BaseModel)
```

A streamed chat completion choice.

**Attributes**:

* `index` *int* - The index of the chat completion choice.
* `delta` *DeltaMessage* - The message delta.
* `finish_reason` *str* - The reason the model stopped generating tokens. This will be "stop" if the model hit a natural stop point or a provided stop sequence, or "length" if the maximum number of tokens specified in the request was reached.

<a id="api.ChatCompletionStreamResponse" />

## ChatCompletionStreamResponse Objects

```python theme={null}
class ChatCompletionStreamResponse(BaseModel)
```

The streamed response message from a /v1/chat/completions call.

**Attributes**:

* `id` *str* - A unique identifier of the response.
* `object` *str* - The object type, which is always "chat.completion".
* `created` *int* - The Unix time in seconds when the response was generated.
* `model` *str* - The model used for the chat completion.\
  choices (List\[ChatCompletionResponseStreamChoice]):\
  The list of streamed chat completion choices.

<a id="model" />

# model

<a id="model.Model" />

## Model Objects

```python theme={null}
class Model()
```

<a id="model.Model.list" />

#### list

```python theme={null}
@classmethod
def list(cls, request_timeout=60)
```

Returns a list of available models.

**Arguments**:

* `request_timeout` *int, optional* - The request timeout in seconds. Default is 60.

**Returns**:

* `ListModelsResponse` - A list of available models.

<a id="log" />

# log

<a id="log.set_console_log_level" />

#### set\_console\_log\_level

```python theme={null}
def set_console_log_level(level: str) -> None
```

Controls console logging.

**Arguments**:

* `level` - the minimum level that prints out to console.\
  Supported values: \[CRITICAL, FATAL, ERROR, WARN,\
  WARNING, INFO, DEBUG]

<a id="error" />

# error

<a id="error.PermissionError" />

## PermissionError Objects

```python theme={null}
class PermissionError(FireworksError)
```

A permission denied error.

<a id="error.InvalidRequestError" />

## InvalidRequestError Objects

```python theme={null}
class InvalidRequestError(FireworksError)
```

A invalid request error.

<a id="error.AuthenticationError" />

## AuthenticationError Objects

```python theme={null}
class AuthenticationError(FireworksError)
```

A authentication error.

<a id="error.RateLimitError" />

## RateLimitError Objects

```python theme={null}
class RateLimitError(FireworksError)
```

A rate limit error.

<a id="error.InternalServerError" />

## InternalServerError Objects

```python theme={null}
class InternalServerError(FireworksError)
```

An internal server error.

<a id="error.ServiceUnavailableError" />

## ServiceUnavailableError Objects

```python theme={null}
class ServiceUnavailableError(FireworksError)
```

A service unavailable error.
