{"id":18486121,"url":"https://github.com/mathsgod/openai-client","last_synced_at":"2026-03-06T06:32:08.046Z","repository":{"id":174870233,"uuid":"637696983","full_name":"mathsgod/openai-client","owner":"mathsgod","description":null,"archived":false,"fork":false,"pushed_at":"2025-08-07T05:07:10.000Z","size":168,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-16T09:35:44.003Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mathsgod.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-05-08T08:12:59.000Z","updated_at":"2025-08-07T05:04:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"b420d18d-19a7-4ddd-a52d-f089a79d2a42","html_url":"https://github.com/mathsgod/openai-client","commit_stats":null,"previous_names":["mathsgod/openai-client"],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/mathsgod/openai-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Fopenai-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Fopenai-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Fopenai-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Fopenai-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mathsgod","download_url":"https://codeload.github.com/mathsgod/openai-client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Fopenai-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30164594,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T04:43:31.446Z","status":"ssl_error","status_checked_at":"2026-03-06T04:40:30.133Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T12:47:54.207Z","updated_at":"2026-03-06T06:32:08.011Z","avatar_url":"https://github.com/mathsgod.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# openai-client\n\nA very simple client for the OpenAI API.\n\n## Installation\n\n```bash\ncomposer require mathsgod/openai-client\n```\n\n## Usage\nCreate a client instance with your API key.\n```php\nuse OpenAI\\Client;\n$client=new Client(\"OPEN_API_KEY\");\n```\n\n\n### Responses\n\n```php\n$tools = [\n    [\n        \"type\" =\u003e \"function\",\n        \"name\" =\u003e \"get_iphone_price\",\n        \"description\" =\u003e \"Get the current price of an iPhone model.\",\n        \"parameters\" =\u003e [\n            \"type\" =\u003e \"object\",\n            \"properties\" =\u003e [\n                \"model\" =\u003e [\n                    \"type\" =\u003e \"string\",\n                    \"description\" =\u003e \"The iPhone model, e.g. iPhone 14 Pro Max\"\n                ]\n            ],\n            \"required\" =\u003e [\"model\"],\n            \"additional_properties\" =\u003e false\n        ]\n    ],\n    [\n        \"type\" =\u003e \"function\",\n        \"name\" =\u003e \"get_iphone_release_date\",\n        \"description\" =\u003e \"Get the release date of an iPhone model.\",\n        \"parameters\" =\u003e [\n            \"type\" =\u003e \"object\",\n            \"properties\" =\u003e [\n                \"model\" =\u003e [\n                    \"type\" =\u003e \"string\",\n                    \"description\" =\u003e \"The iPhone model, e.g. iPhone 14 Pro Max\"\n                ]\n            ],\n            \"required\" =\u003e [\"model\"],\n            \"additional_properties\" =\u003e false\n        ]\n    ]\n];\n\n$data = $client-\u003eresponses()-\u003ecreate([\n    \"model\" =\u003e \"gpt-4o-mini\",\n    \"input\" =\u003e \"What is the price and release date of iPhone 14 Pro Max?\",\n    \"tools\" =\u003e $tools,\n]);\n\n$input = [];\n\nforeach ($data[\"output\"] as $output) {\n    if ($output[\"name\"] == \"get_iphone_price\") {\n        $input[] = [\n            \"type\" =\u003e \"function_call_output\",\n            \"call_id\" =\u003e $output[\"call_id\"],\n            \"output\" =\u003e json_encode([\n                \"model\" =\u003e \"iPhone 14 Pro Max\",\n                \"price\" =\u003e \"$1099\"\n            ]),\n        ];\n    }\n\n    if ($output[\"name\"] == \"get_iphone_release_date\") {\n        $input[] = [\n            \"type\" =\u003e \"function_call_output\",\n            \"call_id\" =\u003e $output[\"call_id\"],\n            \"output\" =\u003e json_encode([\n                \"model\" =\u003e \"iPhone 14 Pro Max\",\n                \"release_date\" =\u003e \"September 16, 2022\"\n            ]),\n        ];\n    }\n}\n\n$data = $client-\u003eresponses()-\u003ecreate([\n    \"model\" =\u003e \"gpt-4o-mini\",\n    \"input\" =\u003e $input,\n    \"tools\" =\u003e $tools,\n    \"previous_response_id\" =\u003e $data[\"id\"],\n]);\n\nprint_r($data);\n\n```\n\n### Responses Streaming\n\n```php\n$tool = [\n    \"type\" =\u003e \"function\",\n    \"name\" =\u003e \"get_weather\",\n    \"description\" =\u003e \"Get current temperature for a given location.\",\n    \"parameters\" =\u003e [\n        \"type\" =\u003e \"object\",\n        \"properties\" =\u003e [\n            \"location\" =\u003e [\n                \"type\" =\u003e \"string\",\n                \"description\" =\u003e \"The city and state, e.g. San Francisco, CA\"\n            ]\n        ],\n        \"required\" =\u003e [\"location\"],\n        \"additional_properties\" =\u003e false\n    ]\n];\n\n\n$stream = $client-\u003eresponses()-\u003ecreateStream([\n    \"model\" =\u003e \"gpt-4o-mini\",\n    \"input\" =\u003e \"What is the weather like in Paris today?\",\n    \"tools\" =\u003e [$tool],\n]);\n\n$stream-\u003eonCompleted(function ($data) use ($client, $tool) {\n    $input = [];\n    $input[] = [\n        \"type\" =\u003e \"function_call_output\",\n        \"call_id\" =\u003e $data[\"response\"][\"output\"][0][\"call_id\"],\n        \"output\" =\u003e json_encode(\"Paris is currently 20 degrees Celsius with clear skies.\"),\n    ];\n\n    $s2 = $client-\u003eresponses()-\u003ecreateStream([\n        \"model\" =\u003e \"gpt-4o-mini\",\n        \"input\" =\u003e $input,\n        \"tools\" =\u003e [$tool],\n        \"previous_response_id\" =\u003e $data[\"response\"][\"id\"],\n    ]);\n\n    $s2-\u003eonOutputTextDelta(function ($data) {\n        echo \"output_text.delta: \" . $data[\"delta\"] . \"\\n\";\n    });\n\n    $s2-\u003eonCompleted(function ($data) {\n        echo \"completed\\n\";\n        print_r($data);\n    });\n   \n});\n\n```\n\n\n### Chat completion\n\n```php\n\n$data = $client-\u003echatCompletions()-\u003ecreate([\n    \"model\" =\u003e \"gpt-4o-mini\",\n    \"messages\" =\u003e [\n        [\"role\" =\u003e \"user\", \"content\" =\u003e \"Hi\"]\n    ]\n]);\n\nprint_r($data);\n```\n\n```\nArray\n(\n    [id] =\u003e chatcmpl-1234\n    [object] =\u003e chat.completion\n    [created] =\u003e 1722324090\n    [model] =\u003e gpt-4o-mini-2024-07-18\n    [choices] =\u003e Array\n        (\n            [0] =\u003e Array\n                (\n                    [index] =\u003e 0\n                    [message] =\u003e Array\n                        (\n                            [role] =\u003e assistant\n                            [content] =\u003e Hello! How can I assist you today?\n                        )\n\n                    [logprobs] =\u003e\n                    [finish_reason] =\u003e stop\n                )\n\n        )\n\n    [usage] =\u003e Array\n        (\n            [prompt_tokens] =\u003e 8\n            [completion_tokens] =\u003e 9\n            [total_tokens] =\u003e 17\n        )\n\n    [system_fingerprint] =\u003e fp_1234\n)\n```\n\n#### Function call\n\n```php\n$data=$client-\u003echatCompletions()-\u003ecreate([\n   \"model\" =\u003e \"gpt-4o-mini\",\n    \"messages\" =\u003e [\n      [\"role\" =\u003e \"user\", \"content\" =\u003e \"What is the price of iphone14?\"]\n    ],\n    \"functions\" =\u003e[\n        [\n            \"name\" =\u003e \"get_iphone_price\",\n            \"description\" =\u003e \"Get the price of iphone\",\n            \"parameters\" =\u003e [\n                \"type\" =\u003e \"object\",\n                \"properties\" =\u003e [\n                    \"model\" =\u003e [\n                        \"type\" =\u003e \"string\",\n                        \"description\" =\u003e \"The model of the iphone\"\n                    ]\n                ],\n                \"required\" =\u003e [\"model\"]\n            ],\n        ]\n    ]\n]);\n\nprint_r($data);\n```\n\n```\nArray\n(\n    [id] =\u003e chatcmpl-1234\n    [object] =\u003e chat.completion\n    [created] =\u003e 1722324296\n    [model] =\u003e gpt-4o-mini-2024-07-18\n    [choices] =\u003e Array\n        (\n            [0] =\u003e Array\n                (\n                    [index] =\u003e 0\n                    [message] =\u003e Array\n                        (\n                            [role] =\u003e assistant\n                            [content] =\u003e\n                            [function_call] =\u003e Array\n                                (\n                                    [name] =\u003e get_iphone_price\n                                    [arguments] =\u003e {\"model\":\"iPhone 14\"}\n                                )\n\n                        )\n\n                    [logprobs] =\u003e\n                    [finish_reason] =\u003e function_call\n                )\n\n        )\n\n    [usage] =\u003e Array\n        (\n            [prompt_tokens] =\u003e 60\n            [completion_tokens] =\u003e 19\n            [total_tokens] =\u003e 79\n        )\n\n    [system_fingerprint] =\u003e fp_1234\n)\n```\n### Images\n\n#### Create image\n   \n```php \nprint_r($client-\u003eimages()-\u003egenerations([\n    \"model\" =\u003e \"dall-e-3\",\n    \"prompt\" =\u003e \"a white siamese cat\",\n    \"n\" =\u003e 1,\n    \"size\" =\u003e \"1024x1024\"\n]));\n```\n\n### Embeddings\n\n```php\nprint_r($client-\u003eembeddings()-\u003ecreate([\n    \"model\" =\u003e \"text-embedding-3-small\",\n    \"input\"=\u003e\"I feel great\",\n]));\n```\n\n\n### Audio\n\n#### Speech\n```php\nprint_r($client-\u003eaudio()-\u003espeech([\n    \"model\"=\u003e\"tts-1\",\n    \"input\"=\u003e\"Hello, how are you?\",\n    \"voice\"=\u003e\"alloy\"\n]));\n```\n\n#### Transcriptions\n```php\nprint_r($client-\u003eaudio()-\u003etranscriptions([\n    \"model\"=\u003e\"whisper-1\",\n    \"file\"=\u003efopen('/path/to/audio.mp3', 'r')\n]));\n```\n\n#### Translation\n```php\nprint_r($client-\u003eaudio()-\u003etranslation([\n    \"model\"=\u003e\"whisper-1\",\n    \"file\"=\u003efopen('/path/to/audio.mp3', 'r')\n]));\n```\n\n## Assistants\n\n### Create\n\n```php\n$client-\u003eassistants()-\u003ecreate([\n    \"model\" =\u003e \"gpt-4o-mini\",\n]);\n```    \n\n### List\n```php\n$client-\u003eassistants()-\u003elist();\n```\n\n### Retrieve\n```php\n$client-\u003eassistants()-\u003eretrieve(\"asst_1234\");\n```\n\n### Delete\n```php\n$client-\u003eassistant(\"asst_1234\")-\u003edelete();\n```\n\n## Threads\n\n### Create\n\n```php\n$client-\u003ethreads()-\u003ecreate(); //return Thread object\n```\n\n\n## Messages\n\n### Create\n\n```php\n$client-\u003ethread(\"thread_1234\")-\u003emessages()-\u003ecreate([\n    \"role\" =\u003e \"user\",\n    \"content\" =\u003e \"Hello\"\n]);\n```\n\n#### Create with stream\n\n```php\n$stream = $thread-\u003eruns()-\u003ecreateStream([\n    \"assistant_id\" =\u003e \"asst_1234\",\n]);\n\n$stream-\u003eon(\"thread.message.delta\", function ($data) {\n    echo $data;\n    echo \"\\n\";\n});\n\n$stream-\u003eon(\"thread.message.completed\", function ($data) {\n    echo $data;\n    echo \"\\n\";\n});\n\n$stream-\u003eon(\"done\", function () use (\u0026$thread) {\n    echo \"End\\n\";\n});\n\n```\n\n\n\n## Example\n\n```php\n$thread = $client-\u003ethreads()-\u003ecreate([\n    \"messages\" =\u003e [\n        [\n            \"role\" =\u003e \"user\",\n            \"content\" =\u003e \"Hi\"\n        ]\n    ]\n]);\n\n$data=$thread-\u003eruns()-\u003ecreate([\n    \"assistant_id\" =\u003e \"asst_1234\", //assistant_id\n]);\n\nprint_r($data); \n\n```\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathsgod%2Fopenai-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmathsgod%2Fopenai-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathsgod%2Fopenai-client/lists"}