Quickstart
Create an API key, configure the SDK and send your first model request.
Create an API key
Sign in to the dashboard, open Keys, choose Create key and give it a name, for example "report script". The full key is shown only once, so store it somewhere safe right away. Keys start with hvd_.
Keep it in the HOVEYDAI_API_KEY environment variable. If a key leaks, delete it in the dashboard and create a new one.
Install the library
No separate library is needed. The official OpenAI library works.
pip install openaiSend your first request
Only two things differ from the usual code: the base URL and the key. The rest is what you already know.
import osfrom openai import OpenAI client = OpenAI( base_url="https://<HOVEYDAI_BASE_URL>/v1", api_key=os.environ["HOVEYDAI_API_KEY"],) resp = client.chat.completions.create( model="MODEL_ID", messages=[{"role": "user", "content": "Hello! Introduce yourself in one sentence."}],)print(resp.choices[0].message.content)
Replace MODEL_ID with the id of one of the models; the list is in Models and on models and prices. If you see an answer in the output, everything works.
In these samples <HOVEYDAI_BASE_URL> is a placeholder and is replaced with the real address.
Stream the answer
To show the answer as it is generated, add stream=True and read the chunks one by one.
stream = client.chat.completions.create( model="MODEL_ID", messages=[{"role": "user", "content": "Write a two-line poem."}], stream=True,)for chunk in stream: print(chunk.choices[0].delta.content or "", end="")
If you get an error
Three common errors on the very first call:
| Status | Means | Next step |
|---|---|---|
401 | The key is wrong or was not sent. | Compare api_key with the key in the dashboard. |
404 | We do not know that model id. | Copy the id from the model list. |
429 | Too many requests in a short time. | Look at Retry-After, wait and send again. |
The full list of errors is on the Errors page.
Next
- Authentication: keeping the key safe and one key per app.
- Streaming: reading chunks in the browser and on the server.
- Endpoint reference: every parameter and response.
Did this page not help? Tell us.