# AI Completions

AI Completions

## Generating AI Completions

> Generates a completion based on chat history. \
> Currently, the supported AI engine for the text generation is <https://platform.openai.com/.\\>
> \
> \
> \*\*\*\
> Prerequisite: Using the AI service requires an API token, you have to either configure your own OpenAI account, or use the Emporix one. To configure your own OpenAI token, use the configuration service by storing the token under the \`openAiApiToken\` key. \
> \
> If you don't provide your own OpenAI token, the Emporix one is used with the following limits: 3 mln input tokens and 1 mln output tokens. When you reach the limit, the next requests are rejected and you have to provide your own OpenAI token. \
> Emporix uses the gpt-4o-mini model by default. If you want to use your own OpenAI account with a different AI model, please contact our \[Emporix Support Team]\(mailto:<support@emporix.com>) to negotiate the model and usage.

```json
{"openapi":"3.0.0","info":{"title":"AI Service","version":"0.0.1"},"tags":[{"name":"AI Completions","description":"AI Completions"}],"servers":[{"url":"https://api.emporix.io"}],"security":[{"OAuth2":["ai.completion_manage"]}],"components":{"securitySchemes":{"OAuth2":{"type":"oauth2","flows":{"clientCredentials":{"scopes":{"ai.text_manage":"Needed to execute actions related to the text generation.","ai.completion_manage":"Needed to execute actions related to the AI completions.","ai.agent_read":"Needed to read AI agents.","ai.agent_manage":"Needed to manage AI agents."},"tokenUrl":"https://api.emporix.io/oauth/token"}}}},"responses":{"200_resp_GET_text_generation":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/GenerationResponse"}}}},"400_resp_common":{"description":"The request was syntactically incorrect.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}},"401_resp_common":{"description":"The authorization token is invalid or has expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessageFault"}}}},"403_resp_common":{"description":"Authorization scopes of the access token are not sufficient and do not match the scopes required by the endpoint.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}},"500_resp_common":{"description":"A server-side error occurred.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}}},"schemas":{"GenerationResponse":{"title":"GenerationResponse","type":"object","description":"Object represents the text generation response.","properties":{"id":{"type":"string","description":"Identifier of the text generation request. The value is populated only if the ID was provided in the request. "},"result":{"type":"string","description":"Text generation result."}}},"ErrorMessage":{"type":"object","properties":{"code":{"type":"integer"},"type":{"type":"string"},"message":{"type":"string"},"moreInfo":{"type":"string"},"details":{"type":"array","items":{"type":"object","properties":{"field":{"type":"string"},"type":{"type":"string"},"message":{"type":"string"},"moreInfo":{"type":"string"}}}}},"description":""},"ErrorMessageFault":{"type":"object","properties":{"fault":{"type":"object","properties":{"faultstring":{"type":"string"},"detail":{"type":"object","properties":{"errorcode":{"type":"string"}}}}}}},"CompletionRequest":{"title":"CompletionRequest","type":"object","required":["messages"],"properties":{"id":{"type":"string","description":"Identifier of the request. The value is not mandatory - if provided, then the ID is returned in the text generation response."},"messages":{"type":"array","items":{"type":"object","required":["role","content"],"properties":{"role":{"type":"string","enum":["USER","SYSTEM","ASSISTANT"],"description":"Specifies the role of the message. `SYSTEM` - Provides instructions or context to the AI about the conversation. `USER` - Represents a message sent by the user. `ASSISTANT` - Represents a message generated by the AI."},"content":{"type":"string","description":"Content of the message. Depending on the role parameter, it can be a background instruction, user instruction, or AI response."}}}}}}},"requestBodies":{"Completion":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CompletionRequest"}}}}}},"paths":{"/ai-service/{tenant}/completions":{"post":{"summary":"Generating AI Completions","operationId":"POST-ai-completions","responses":{"200":{"$ref":"#/components/responses/200_resp_GET_text_generation"},"400":{"$ref":"#/components/responses/400_resp_common"},"401":{"$ref":"#/components/responses/401_resp_common"},"403":{"$ref":"#/components/responses/403_resp_common"},"500":{"$ref":"#/components/responses/500_resp_common"}},"description":"Generates a completion based on chat history. \nCurrently, the supported AI engine for the text generation is https://platform.openai.com/.\n\n\n***\nPrerequisite: Using the AI service requires an API token, you have to either configure your own OpenAI account, or use the Emporix one. To configure your own OpenAI token, use the configuration service by storing the token under the `openAiApiToken` key. \n\nIf you don't provide your own OpenAI token, the Emporix one is used with the following limits: 3 mln input tokens and 1 mln output tokens. When you reach the limit, the next requests are rejected and you have to provide your own OpenAI token. \nEmporix uses the gpt-4o-mini model by default. If you want to use your own OpenAI account with a different AI model, please contact our [Emporix Support Team](mailto:support@emporix.com) to negotiate the model and usage.","requestBody":{"$ref":"#/components/requestBodies/Completion"},"tags":["AI Completions"]}}}}
```
