> For the complete documentation index, see [llms.txt](https://whoman.gitbook.io/openlib-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whoman.gitbook.io/openlib-documentation/initialize-the-library.md).

# Initialize the library

## But first.. what even is OpenLib?

OpenLib is a library that lets you use the chatgpt api for free (almost)\
With this library you can do Text Completion and Chat Completion, it is open source and can be found in [this](https://github.com/altacountbabi/OpenLib) github repository, please leave a star if you like this project\
\
And keep in mind, this is for roblox executors not roblox games however i might port it to work as a server script that you can add, if we get 5 stars on the [github repo](https://github.com/altacountbabi/OpenLib) i will do it.

## Get an api key.

Sadly we need an api key for this too but thankfully its free, however there is a credit system but lets ignore that for now.

You can get an api key from [this](https://discord.gg/pawan-krd-1055397662976905229) server, to get it you have to go to the "Bot" channel and use the /key slash command and the bot should give you your api key.

## Initializing the library

Alright now lets initialize the library, to do this we will add this piece of code:

{% code lineNumbers="true" fullWidth="false" %}

```lua
local OpenLib = loadstring(game:HttpGet('https://raw.githubusercontent.com/altacountbabi/OpenLib/main/src.lua'))()

local client = OpenLib.init({
    api_key = 'pk-Nx*********************************************id'
})
```

{% endcode %}

<details>

<summary>All Arguments/Options</summary>

api\_key (string) (required)

api\_base (string) (optional) (default: "<https://api.pawan.krd/v1>") changes the api endpoint so you can actually just use the official openai api if you want to

reset\_ip (bool) (optional) (default: true) this only works when the api\_base is "<https://api.pawan.krd/v1>" or default i recommend that you leave this on as it will attempt to link your api key to the user's ip

</details>

Alright, now we have the client loaded we can use [text completion](/openlib-documentation/text-completion.md) or [chat completion](/openlib-documentation/chat-completion.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://whoman.gitbook.io/openlib-documentation/initialize-the-library.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
