# Text Generation

AI Text Generation

## Generating text for an object description

> Generates a text based on a prompt. \
> 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 \`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":"Text Generation","description":"AI Text Generation"}],"servers":[{"url":"https://api.emporix.io"}],"security":[{"OAuth2":["ai.text_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"}}}}}}},"TextGenerationRequest":{"title":"TextGenerationRequest","type":"object","description":"Represents a request body for a text generation operation.","required":["prompt"],"properties":{"id":{"type":"string","description":"Identifier of the request. The value is not mandatory - if provided, the ID is returned in the text generation response."},"prompt":{"type":"string","description":"A prompt to AI engine. A desired text content is generated based on the prompt."},"maxTokens":{"type":"integer","description":"Maximum number of tokens that should be used during text generation. If not provided, then 4097 is used."}}}},"requestBodies":{"TextGeneration":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TextGenerationRequest"}}}}}},"paths":{"/ai-service/{tenant}/texts":{"post":{"summary":"Generating text for an object description","operationId":"POST-ai-generate-description","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 text based on a prompt. \nCurrently, the supported AI engine for the text generation is https://platform.openai.com/.\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 `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.\nIf 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/TextGeneration"},"tags":["Text Generation"]}}}}
```
