# Getting started

Welcome to the Oxygen Documentation. Let's get started !

At Oxygen, we are steadfast in our belief that access to cutting-edge artificial intelligence should be as universal and vital as the air we breathe. Our mission is to democratize AI by providing a single platform where all AI models are available for free. We open the doors to the future of technology, ensuring that every curious mind, aspiring innovator, and dedicated developer has the tools they need to create, experiment, and thrive.\
\
**Oxyen Teams.**\
\
You can start with the introduction !


# Introduction

Let's get you started with Oxygen API

You can interact with the API through HTTP requests from any language, via OpenAI official Python bindings, OpenAI official Node.js library, or an OpenAI community-maintained library.

To install the official OpenAI Python bindings, run the following command :

```python
pip install openai
```

To install the official Node.js library, run the following command in your Node.js project directory:

```javascript
npm install openai@^4.0.0
```

***

### OpenAI/Oxygen community libraries

The libraries below are built and maintained by the broader developer community. You can also [watch the OpenAPI specification](https://github.com/openai/openai-openapi) repository on GitHub to get timely updates on when we make changes to our API.

Please note that Oxygen does not verify the correctness or security of these projects. **Use them at your own risk!**

#### **C# / .NET**

* [Betalgo.OpenAI](https://github.com/betalgo/openai) by [Betalgo](https://github.com/betalgo)
* [OpenAI-API-dotnet](https://github.com/OkGoDoIt/OpenAI-API-dotnet) by [OkGoDoIt](https://github.com/OkGoDoIt)
* [OpenAI-DotNet](https://github.com/RageAgainstThePixel/OpenAI-DotNet) by [RageAgainstThePixel](https://github.com/RageAgainstThePixel)

#### **C++**

* [liboai](https://github.com/D7EAD/liboai) by [D7EAD](https://github.com/D7EAD)

#### **Clojure**

* [openai-clojure](https://github.com/wkok/openai-clojure) by [wkok](https://github.com/wkok)

#### **Crystal**

* [openai-crystal](https://github.com/sferik/openai-crystal) by [sferik](https://github.com/sferik)

#### **Dart/Flutter**

* [openai](https://github.com/anasfik/openai) by [anasfik](https://github.com/anasfik)

#### **Delphi**

* [DelphiOpenAI](https://github.com/HemulGM/DelphiOpenAI) by [HemulGM](https://github.com/HemulGM)

#### **Elixir**

* [openai.ex](https://github.com/mgallo/openai.ex) by [mgallo](https://github.com/mgallo)

#### **Go**

* [go-gpt3](https://github.com/sashabaranov/go-gpt3) by [sashabaranov](https://github.com/sashabaranov)

#### **Java**

* [openai-java](https://github.com/TheoKanning/openai-java) by [Theo Kanning](https://github.com/TheoKanning)

#### **Julia**

* [OpenAI.jl](https://github.com/rory-linehan/OpenAI.jl) by [rory-linehan](https://github.com/rory-linehan)

#### **Kotlin**

* [openai-kotlin](https://github.com/Aallam/openai-kotlin) by [Mouaad Aallam](https://github.com/Aallam)

#### **Node.js**

* [openai-api](https://www.npmjs.com/package/openai-api) by [Njerschow](https://github.com/Njerschow)
* [openai-api-node](https://www.npmjs.com/package/openai-api-node) by [erlapso](https://github.com/erlapso)
* [gpt-x](https://www.npmjs.com/package/gpt-x) by [ceifa](https://github.com/ceifa)
* [gpt3](https://www.npmjs.com/package/gpt3) by [poteat](https://github.com/poteat)
* [gpts](https://www.npmjs.com/package/gpts) by [thencc](https://github.com/thencc)
* [@dalenguyen/openai](https://www.npmjs.com/package/@dalenguyen/openai) by [dalenguyen](https://github.com/dalenguyen)
* [tectalic/openai](https://github.com/tectalichq/public-openai-client-js) by [tectalic](https://tectalic.com/)

#### **PHP**

* [orhanerday/open-ai](https://packagist.org/packages/orhanerday/open-ai) by [orhanerday](https://github.com/orhanerday)
* [tectalic/openai](https://github.com/tectalichq/public-openai-client-php) by [tectalic](https://tectalic.com/)
* [openai-php client](https://github.com/openai-php/client) by [openai-php](https://github.com/openai-php)

#### **Python**

* [chronology](https://github.com/OthersideAI/chronology) by [OthersideAI](https://www.othersideai.com/)

#### **R**

* [rgpt3](https://github.com/ben-aaron188/rgpt3) by [ben-aaron188](https://github.com/ben-aaron188)

#### **Ruby**

* [openai](https://github.com/nileshtrivedi/openai/) by [nileshtrivedi](https://github.com/nileshtrivedi)
* [ruby-openai](https://github.com/alexrudall/ruby-openai) by [alexrudall](https://github.com/alexrudall)

#### **Rust**

* [async-openai](https://github.com/64bit/async-openai) by [64bit](https://github.com/64bit)
* [fieri](https://github.com/lbkolev/fieri) by [lbkolev](https://github.com/lbkolev)

#### **Scala**

* [openai-scala-client](https://github.com/cequence-io/openai-scala-client) by [cequence-io](https://github.com/cequence-io)

#### **Swift**

* [OpenAIKit](https://github.com/dylanshine/openai-kit) by [dylanshine](https://github.com/dylanshine)
* [OpenAI](https://github.com/MacPaw/OpenAI/) by [MacPaw](https://github.com/MacPaw)

#### **Unity**

* [OpenAi-Api-Unity](https://github.com/hexthedev/OpenAi-Api-Unity) by [hexthedev](https://github.com/hexthedev)
* [com.openai.unity](https://github.com/RageAgainstThePixel/com.openai.unity) by [RageAgainstThePixel](https://github.com/RageAgainstThePixel)

#### **Unreal Engine**

* [OpenAI-Api-Unreal](https://github.com/KellanM/OpenAI-Api-Unreal) by [KellanM](https://github.com/KellanM)


# Authentication

Let's get you started with Oxygen API Authentication

Oxygen uses API keys for authentication. Visit our [**discord server**](https://oxyapi.uk/discord) to retrieve the API key you'll use in your requests.

**Remember that your API key is a secret !** Do not share it with others or expose it in any client-side code (browsers, apps). Production requests must be routed through your own backend server where your API key can be securely loaded from an environment variable or key management service.

All API requests should include your API key in an `Authorization` HTTP header as follows :

```url
Authorization: Bearer OXYGEN_API_KEY
```


# Making requests

You can paste the command below into your terminal to run your first API request. Make sure to replace `$OXYGEN_API_KEY` with your secret API key.

```bash
curl https://app.oxyapi.uk/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OXYGEN_API_KEY" \
  -d '{
     "model": "gpt-3.5-turbo",
     "messages": [{"role": "user", "content": "Say this is a test!"}],
     "temperature": 0.7
   }'

```

This request queries the `gpt-3.5-turbo` model (which under the hood points to the **latest** `gpt-3.5-turbo` **model variant**) to complete the text starting with a prompt of "*Say this is a test*". You should get a response back that resembles the following:

```json
{
    "id": "chatcmpl-abc123",
    "object": "chat.completion",
    "created": 1677858242,
    "model": "gpt-3.5-turbo-1106",
    "usage": {
        "prompt_tokens": 13,
        "completion_tokens": 7,
        "total_tokens": 20
    },
    "choices": [
        {
            "message": {
                "role": "assistant",
                "content": "\n\nThis is a test!"
            },
            "logprobs": null,
            "finish_reason": "stop",
            "index": 0
        }
    ]
}
```

Now that you've generated your first chat completion, let's break down the response object. We can see the `finish_reason` is `stop` which means the API returned the full chat completion generated by the model without running into any limits. In the choices list, we only generated a single message but you can set the `n` parameter to generate multiple messages choices.


# Streaming

The Oxygen API provides the ability to stream responses back to a client in order to allow partial results for certain requests. To achieve this, we follow the [**Server-sent events**](https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events) standard.

OpenAI official [**Node**](https://github.com/openai/openai-node) and [**Python**](https://github.com/openai/openai-python) libraries handle Server-sent events for you. In Python, a streaming request looks like :

```python
from openai import OpenAI

client = OpenAI(api_key="OXYGEN_API_KEY",base_url="https://app.oxyapi.uk/v1")

stream = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[{"role": "user", "content": "Say this is a test"}],
    stream=True,
)
for chunk in stream:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="")
```

#### Parsing Server-sent events

Parsing Server-sent events is non-trivial and should be done with caution. Simple strategies like splitting by a new line may result in parsing errors. We recommend using existing client libraries when possible.


# Chat

<mark style="color:blue;">**`ENDPOINT : https://app.oxyapi.uk/v1/chat/completions`**</mark>

`messages  [array]`` `<mark style="color:red;">**`REQUIRED`**</mark>

* A list of messages comprising the conversation so far. [Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models).

`model  [string]`` `<mark style="color:red;">**`REQUIRED`**</mark>

* ID of the model to use. See the [model endpoint compatibility](https://app.oxyapi.uk/v1/models) table for details on which models work with the Chat API.

`frequency_penalty [number or null] Optional Defaults to 0`

* Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.

`logit_biasmap Optional Defaults to null`

* Modify the likelihood of specified tokens appearing in the completion.
* Accepts a JSON object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.

`logprobs [boolean or null] Optional Defaults to false`

* Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the `content` of `message`. This option is currently not available on the `gpt-4-vision-preview` model.

`top_logprobs [integer] or null Optional`

* An integer between 0 and 5 specifying the number of most likely tokens to return at each token position, each with an associated log probability. `logprobs` must be set to `true` if this parameter is used.

`max_tokens [integer] or null Optional`

* The maximum number of [tokens](https://platform.openai.com/tokenizer) that can be generated in the chat completion.
* The total length of input tokens and generated tokens is limited by the model's context length. [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting tokens.

`n [integer] or nullOptionalDefaults to 1`

* How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep `n` as `1` to minimize costs. `n`max = 2

`presence_penalty [number] or null Optional Defaults to 0`

* Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
* [See more information about frequency and presence penalties.](https://platform.openai.com/docs/guides/text-generation/parameter-details)

`response_format object Optional`

* An object specifying the format that the model must output. Compatible with `gpt-4-1106-preview` and `gpt-3.5-turbo-1106`.
* Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates is valid JSON.
* **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length.

`seed [integer or null] Optional`

* This feature is in Beta. If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result. Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.

`stop [string / array / null] Optional Defaults to null`

* Up to 4 sequences where the API will stop generating further tokens.

`stream [boolean or null] Optional Defaults to false`

* If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) as they become available, with the stream terminated by a `data: [DONE]` message. [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).

`temperature [number or null] Optional Defaults to 1`

* What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
* We generally recommend altering this or `top_p` but not both.

`top_p [number or null] Optional Defaults to 1`

* An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top\_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.
* We generally recommend altering this or `temperature` but not both.

`tools [array] Optional`

* A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for.

`tool_choice [string or object] Optional`

* Controls which (if any) function is called by the model. `none` means the model will not call a function and instead generates a message. `auto` means the model can pick between generating a message or calling a function. Specifying a particular function via `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that function.
* `none` is the default when no functions are present. `auto` is the default if functions are present.

`user [string] Optional`

* A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids).

`function_call Deprecated [string or object] Optional`

* Deprecated in favor of `tool_choice`.
* Controls which (if any) function is called by the model. `none` means the model will not call a function and instead generates a message. `auto` means the model can pick between generating a message or calling a function. Specifying a particular function via `{"name": "my_function"}` forces the model to call that function.
* `none` is the default when no functions are present. `auto` is the default if functions are present.

`functions Deprecated [array] Optional`

* Deprecated in favor of `tools`.
* A list of functions the model may generate JSON inputs for.

## Returns

Returns a chat completion object, or a streamed sequence of chat completion chunk objects if the request is streamed.

## The chat completion object

Represents a chat completion response returned by model, based on the provided input.

`id [string]`

* A unique identifier for the chat completion.

`choices [array]`

* A list of chat completion choices. Can be more than one if `n` is greater than 1.

`created [integer]`

* The Unix timestamp (in seconds) of when the chat completion was created.

`model [[string]`

* The model used for the chat completion.

`system_fingerprint [string]`

* This fingerprint represents the backend configuration that the model runs with.
* Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism.

`object [string]`

* The object type, which is always `chat.completion`.

## The chat completion chunk object

Represents a streamed chunk of a chat completion response returned by model, based on the provided input.

`id [string]`

* A unique identifier for the chat completion.

`choices [array]`

* A list of chat completion choices. Can be more than one if `n` is greater than 1.

`created [integer]`

* The Unix timestamp (in seconds) of when the chat completion was created.

`model [[string]`

* The model used for the chat completion.

`system_fingerprint [string]`

* This fingerprint represents the backend configuration that the model runs with.
* Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism.

`object [string]`

* The object type, which is always `chat.completion.chunk`.


# Image

<mark style="color:blue;">**`ENDPOINT : https://app.oxyapi.uk/v1/images/generations`**</mark>

## MidJourney&#x20;

`prompt  [string]`` `<mark style="color:red;">**`REQUIRED`**</mark>

* Prompt to use for the generation.

`model  [string]`` `<mark style="color:red;">**`REQUIRED`**</mark>

* ID of the model to use. See the [model endpoint compatibility](https://app.oxyapi.uk/v1/models).

`stream [boolean or null] Optional Defaults to false`

* If set, partial images with progression deltas will be sent.

## Stable Diffusion Models

`prompt  [string]`` `<mark style="color:red;">**`REQUIRED`**</mark>

* Prompt to use for the generation.

`negative_prompt  [string] Default to null Optional`&#x20;

* Generation negative prompt.

`model  [string]`` `<mark style="color:red;">**`REQUIRED`**</mark>

* ID of the model to use. See the [model endpoint compatibility](https://app.oxyapi.uk/v1/models) table for details on which models work with the Chat API..

`steps  [integer] Default to 25 Optional`&#x20;

* Generation denoising steps , must be in range 1 / 50

`sampler [string] Default to DPM++ 2M Karras Optional`&#x20;

* Generation sampler must be in the list :

  ```javascript
  ["Euler", "Euler a", "Heun", "DPM++ 2M Karras", "DPM++ SDE Karras", "DDIM"]
  ```

`n  [integer] Default to 1 Optional`&#x20;

* Generation images number , must be in range 1 / 4, when stream is true n must be 1.

`seed  [integer] Default to random Optional`&#x20;

* Generation seed.


# Audio

<mark style="color:blue;">**`ENDPOINT : https://app.oxyapi.uk/v1/audio/speech`**</mark>

`input [string]`` `<mark style="color:red;">**`REQUIRED`**</mark>

* Input text to use for the generation.

`model  [string]`` `<mark style="color:red;">**`REQUIRED`**</mark>

* ID of the model to use. See the [model endpoint compatibility](https://app.oxyapi.uk/v1/models) table for details on which models work with the Chat API..


# Embeddings

<mark style="color:blue;">**`ENDPOINT : https://app.oxyapi.uk/v1/embeddings`**</mark>

`input [string]`` `<mark style="color:red;">**`REQUIRED`**</mark>

* Input text to embed, encoded as a string or array of tokens. To embed multiple inputs in a single request, pass an array of strings or array of token arrays. The input must not exceed the max input tokens for the model (8192 tokens for `text-embedding-ada-002`), cannot be an empty string, and any array must be 2048 dimensions or less. [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting tokens.

`model  [string]`` `<mark style="color:red;">**`REQUIRED`**</mark>

* ID of the model to use. See the [model endpoint compatibility](https://app.oxyapi.uk/v1/models) table for details on which models work with the Embedding API..

`encoding_format [string] Optional Defaults to float`

* The format to return the embeddings in. Can be either `float` or [`base64`](https://pypi.org/project/pybase64/).

`dimensions [integer] Optional`

* The number of dimensions the resulting output embeddings should have. Only supported in `text-embedding-3` and later models.

`user [string] Optional`

* A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids).


