To use OpenAI API completion, you can use the instance of OpenAIService.
use App\Services\OpenAIService;$openai = app(OpenAIService::class);$response = $openai->completion('Write recipe based on the given ingredients: 1 cup of flour, 2 eggs, 1 cup of sugar');// You can also pass the model name$response = $openai->completion('Write recipe based on the given ingredients: 1 cup of flour, 2 eggs, 1 cup of sugar', 'davinci');// See the list of pre-defined model names in config/services.php -> openai.models// To get the responseecho $response['choices'][0]['message']['content'];
To create images using OpenAI API, you can use:
use App\Services\OpenAIService;$openai = app(OpenAIService::class);$response = $openai->image('A beautiful sunset over the mountains');
You can adjust the number of generating images and the size in the OpenAIService@image method.To create an audio from text using OpenAI API, you can use:
use App\Services\OpenAIService;$openai = app(OpenAIService::class);$response = $openai->textToSpeech('Hello, how are you?');
The text-to-speech will return the audio content instead of the URL as for the image. You can save the audio content to a file or return it as a response.
For more information, you can check the OpenAI API documentation to add new features to your service or adjust existing ones.
{"docsConfig":{"$schema":"https://mintlify.com/docs.json","theme":"mint","name":"Larafast","colors":{"primary":"#0D9373","light":"#07C983","dark":"#0D9373"},"favicon":"/logo/favicon.svg","logo":{"light":"https://mintcdn.com/larafast/p7p6xbnL6MINm0mR/logo/larafast-small.png?fit=max\u0026auto=format\u0026n=p7p6xbnL6MINm0mR\u0026q=85\u0026s=e282ae2d477406a3992013a47d0c30c9","dark":"https://mintcdn.com/larafast/p7p6xbnL6MINm0mR/logo/larafast-small-white.png?fit=max\u0026auto=format\u0026n=p7p6xbnL6MINm0mR\u0026q=85\u0026s=79a7301c8c7bd102082ffa9f428e8f0c"},"navbar":{"links":[{"label":"Support","href":"mailto:[email protected]"}],"primary":{"type":"button","label":"Website","href":"https://larafast.com"}},"footer":{"socials":{"twitter":"https://twitter.com/larafastphp","github":"https://github.com/karakhanyans-tools/larafast.git"}},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"larafast","hasAudioNarration":false,"actualSubdomain":"larafast","customDomains":["docs.larafast.com"],"gitSource":{"type":"github","owner":"karakhanyans","repo":"docs","deployBranch":"main","contentDirectory":"","isPrivate":false,"mountPath":"","label":""},"entitlements":{},"buildId":"6ae91eff1deeea3b72fa104a:success","clientVersion":"0.0.4102","searchFilterCounts":[{"language":"default","tag":"VILT Components","count":38},{"language":"default","tag":"Features","count":35},{"language":"default","tag":"TALL Components","count":34},{"language":"default","tag":"Documentation","count":32},{"language":"default","tag":"Multi-Tenancy","count":29},{"language":"default","tag":"Fast Projects: API","count":14},{"language":"default","tag":"Fast Projects: Directories","count":7},{"language":"default","tag":"Tutorials","count":7},{"language":"default","tag":"Get Started","count":6},{"language":"default","tag":"Auth","count":5}]},"assistantConfig":{},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"features/openai","slug":"/features/openai","pageMetadata":{"title":"OpenAI API","description":"OpenAI API integration for Laravel","icon":"robot","href":"/features/openai"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"OpenAI API integration for Laravel\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,ol:`ol`,p:`p`,pre:`pre`,span:`span`,..._provideComponents(),...props.components},{CodeBlock,Heading,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsx(_components.p,{children:`Larafast provides a simple way to integrate OpenAI API with Laravel.`}),`\n`,_jsx(Heading,{level:`2`,id:`installation`,children:`Installation`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsxs(_components.li,{children:[`Create an account on `,_jsx(_components.a,{href:`https://platform.openai.com/signup`,children:`OpenAI`})]}),`\n`,_jsxs(_components.li,{children:[`Create your API key from the dashboard from `,_jsx(_components.a,{href:`https://platform.openai.com/api-keys`,children:`API Keys`})]}),`\n`,_jsxs(_components.li,{children:[`Add your API key to your `,_jsx(_components.code,{children:`.env`}),` file as `,_jsx(_components.code,{children:`OPENAI_KEY=your-api-key`})]}),`\n`]}),`\n`,_jsx(_components.p,{children:`That’s it, your project is ready to use OpenAI API.`}),`\n`,_jsx(Heading,{level:`2`,id:`usage`,children:`Usage`}),`\n`,_jsxs(_components.p,{children:[`To use OpenAI API completion, you can use the instance of `,_jsx(_components.code,{children:`OpenAIService`}),`.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`12`,language:`php`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`php`,children:_jsxs(_components.code,{language:`php`,numberOfLines:`12`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`use`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` App\\\\Services\\\\`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`OpenAIService`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$openai`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` app`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`OpenAIService`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`::`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`class`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` $openai`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`->`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`completion`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Write recipe based on the given ingredients: 1 cup of flour, 2 eggs, 1 cup of sugar'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// You can also pass the model name`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` $openai`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`->`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`completion`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Write recipe based on the given ingredients: 1 cup of flour, 2 eggs, 1 cup of sugar'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'davinci'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// See the list of pre-defined model names in config/services.php -> openai.models`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// To get the response`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`echo`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` $response`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'choices'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`][`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`][`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'message'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`][`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'content'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`];`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`To create images using OpenAI API, you can use:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,language:`php`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`php`,children:_jsxs(_components.code,{language:`php`,numberOfLines:`4`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`use`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` App\\\\Services\\\\`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`OpenAIService`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$openai`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` app`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`OpenAIService`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`::`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`class`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` $openai`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`->`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`image`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'A beautiful sunset over the mountains'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`You can adjust the number of generating images and the size in the OpenAIService@image method.`}),`\n`,_jsx(_components.p,{children:`To create an audio from text using OpenAI API, you can use:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,language:`php`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`php`,children:_jsxs(_components.code,{language:`php`,numberOfLines:`4`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`use`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` App\\\\Services\\\\`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`OpenAIService`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$openai`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` app`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`OpenAIService`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`::`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`class`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` $openai`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`->`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`textToSpeech`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Hello, how are you?'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`]})})}),`\n`,_jsx(Warning,{children:_jsx(_components.p,{children:`The text-to-speech will return the audio content instead of the URL as for the image. You can save the audio content to a file or return it as a response.`})}),`\n`,_jsxs(_components.p,{children:[`For more information, you can check the `,_jsx(_components.a,{href:`https://platform.openai.com/docs/overview`,children:`OpenAI API documentation`}),` to add new features to your service or adjust existing ones.`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"OpenAI API","description":"OpenAI API integration for Laravel","icon":"robot","href":"/features/openai"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Installation","slug":"installation","depth":2,"children":[]},{"title":"Usage","slug":"usage","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"larafast","siteName":"Larafast","title":"OpenAI API - Larafast","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2025-10-27T11:35:26.419Z","originalFileLocation":"features/openai.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"OpenAI API integration for Laravel\">\u003cmeta data-mint-head name=\"application-name\" content=\"Larafast\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/larafast/qg37bNa7kqUkjnFx/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/larafast/qg37bNa7kqUkjnFx/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/larafast/qg37bNa7kqUkjnFx/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/larafast/qg37bNa7kqUkjnFx/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/larafast/qg37bNa7kqUkjnFx/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/larafast/qg37bNa7kqUkjnFx/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/larafast/qg37bNa7kqUkjnFx/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/larafast/qg37bNa7kqUkjnFx/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/larafast/qg37bNa7kqUkjnFx/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"OpenAI API - Larafast\">\u003cmeta data-mint-head property=\"og:description\" content=\"OpenAI API integration for Laravel\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Larafast\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.larafast.com/features/openai\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://larafast.mintlify.site/_mintlify/api/og/v2?division=Features\u0026amp;title=OpenAI+API\u0026amp;description=OpenAI+API+integration+for+Laravel\u0026amp;theme=9371b70b45db6ce8fc4b435b\u0026amp;signature=c0ac8e69446291821155175d9f500d822e31e757f76d381fed3cef55713a7d86\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"OpenAI API - Larafast\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"OpenAI API integration for Laravel\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://larafast.mintlify.site/_mintlify/api/og/v2?division=Features\u0026amp;title=OpenAI+API\u0026amp;description=OpenAI+API+integration+for+Laravel\u0026amp;theme=9371b70b45db6ce8fc4b435b\u0026amp;signature=c0ac8e69446291821155175d9f500d822e31e757f76d381fed3cef55713a7d86\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/larafast/qg37bNa7kqUkjnFx/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Larafast\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#0D9373\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.larafast.com/features/openai\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/features/openai.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.larafast.com/#organization\",\"name\":\"Larafast\",\"url\":\"https://docs.larafast.com\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/larafast/p7p6xbnL6MINm0mR/logo/larafast-small.png?fit=max\u0026auto=format\u0026n=p7p6xbnL6MINm0mR\u0026q=85\u0026s=e282ae2d477406a3992013a47d0c30c9\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.larafast.com#website\",\"name\":\"Larafast\",\"url\":\"https://docs.larafast.com\",\"publisher\":{\"@id\":\"https://docs.larafast.com/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.larafast.com/features/openai#webpage\",\"url\":\"https://docs.larafast.com/features/openai\",\"name\":\"OpenAI API\",\"description\":\"OpenAI API integration for Laravel\",\"dateModified\":\"2025-10-27T11:35:26.419Z\",\"isPartOf\":{\"@id\":\"https://docs.larafast.com#website\"},\"breadcrumb\":{\"@id\":\"https://docs.larafast.com/features/openai#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.larafast.com/features/openai#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Features\",\"item\":\"https://docs.larafast.com/features/payments/lemonsqueezy\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"OpenAI API\",\"item\":\"https://docs.larafast.com/features/openai\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.larafast.com/features/openai#article\",\"headline\":\"OpenAI API\",\"name\":\"OpenAI API\",\"description\":\"OpenAI API integration for Laravel\",\"url\":\"https://docs.larafast.com/features/openai\",\"mainEntityOfPage\":{\"@id\":\"https://docs.larafast.com/features/openai#webpage\"},\"dateModified\":\"2025-10-27T11:35:26.419Z\",\"publisher\":{\"@id\":\"https://docs.larafast.com/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.larafast.com#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Larafast\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"Larafast\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/features/openai.md","siteName":"Larafast","nav":{"global":null,"tabs":[{"tab":"Documentation","groups":[{"group":"Get Started","pages":[{"title":"Larafast Installer","icon":"arrow-right","href":"/larafast-installer"},{"title":"Start Here for VILT Stack","icon":"arrow-right","href":"/intro-vilt"},{"title":"Start Here for TALL Stack","icon":"arrow-right","href":"/intro-tall"}]},{"group":"Tutorials","pages":[{"title":"Keeping your fork up to date","icon":"clock","href":"/tutorials/keeping-fork-up-to-date"},{"title":"LemonSqueezy for Non-Auth Users in Laravel","sidebarTitle":"LemonSqueezy for Non-Auth Users","icon":"lemon","href":"/tutorials/lemonsqueezy-for-non-auth-users"},{"title":"LemonSqueezy Webhooks for Non-Auth Users in Laravel","sidebarTitle":"LemonSqueezy Webhooks for Non-Auth Users","icon":"lemon","href":"/tutorials/lemonsqueezy-webhooks-for-non-auth-users"},{"title":"Track Unique User Visits and Match with Purchases","icon":"shuffle","href":"/tutorials/track-unique-user-visits-and-match-with-purchase"},{"title":"Stripe Payments Integration","icon":"stripe","href":"/tutorials/stripe-in-5-minutes"},{"icon":"clock","title":null,"href":"/tutorials/up-and-running-in-3-minutes"},{"title":"Zero Downtime Deployment with Laravel Forge","icon":"rocket","href":"/tutorials/zero-downtime-deployment-with-laravel-forge"}]},{"group":"Features","pages":[{"group":"Payments","icon":"money-check-dollar","pages":[{"title":"LemonSqueezy","icon":"lemon","href":"/features/payments/lemonsqueezy"},{"title":"Stripe [updated]","icon":"stripe","href":"/features/payments/stripe"},{"title":"Paddle","icon":"money-check-dollar","href":"/features/payments/paddle"}]},{"icon":"user-tie","title":null,"href":"/features/admin"},{"group":"SEO","icon":"magnifying-glass","pages":[{"title":"SEO","sidebarTitle":"SEO","icon":"magnifying-glass","href":"/features/seo/introduction"},{"title":"Dynamic OG Images","sidebarTitle":"Dynamic OG Images","icon":"image","href":"/features/seo/og-images"},{"title":"Sitemap","icon":"map","href":"/features/seo/sitemap"},{"title":"SchemaOrg","icon":"signs-post","href":"/features/seo/schemaorg"}]},{"title":"Blog","icon":"cube","href":"/features/blog"},{"title":"Changelog","icon":"list","href":"/features/changelog"},{"title":"Users","icon":"users","href":"/features/users"},{"title":"Emails","icon":"envelope","href":"/features/emails"},{"title":"Teams","icon":"users-line","href":"/features/teams"},{"title":"Roles \u0026 Permissions","icon":"lock","href":"/features/roles-and-permissions"},{"title":"Social Auth","icon":"users","href":"/features/social-auth"},{"title":"Magic Links","icon":"users","href":"/features/magic-links"},{"title":"Database","description":"Database in Larafast","icon":"database","href":"/features/database"},{"title":"OpenAI API","icon":"robot","href":"/features/openai"},{"title":"xAI API (Twitter)","description":"xAI API (Twitter) Docs","icon":"x","href":"/features/xai"}]},{"group":"Deployment","pages":[{"title":"Deploy to Prod","icon":"rocket","href":"/deploy/deploy-to-prod"},{"title":"Deploy with Forge","icon":"rocket","href":"/deploy/deploy-with-forge"},{"title":"Deployment with Laravel Envoy","sidebarTitle":"Deploy with Envoy","icon":"rocket","href":"/deploy/deploy-with-envoy"}]}]},{"tab":"Multi-Tenancy","pages":[{"title":"Multi-Tenancy","href":"/multi-tenancy/intro"}]},{"tab":"VILT Components","pages":[{"title":"VILT Components","href":"/vilt/components/themes-and-ui"}]},{"tab":"TALL Components","pages":[{"title":"TALL Components","href":"/tall/components/themes-and-ui"}]},{"tab":"Fast Projects: Directories","pages":[{"title":"Fast Projects: Directories","href":"/fast-projects/directories/intro"}]},{"tab":"Fast Projects: API","pages":[{"title":"Fast Projects: API","href":"/fast-projects/api/intro"}]}]},"basePath":"","title":"OpenAI API - Larafast","buildId":"dpl_596ePT575z4qnAFksq1biRW97aLY","deploymentId":"dpl_596ePT575z4qnAFksq1biRW97aLY","dynamics":[],"chunks":[]}