Skip to main content
Connect your application to llm.sg by preparing an API key, choosing a model ID, and sending a text request.
These examples use the OpenAI Chat Completions format. The model endpoint’s authentication requirement is verified. Authenticated discovery, chat, SDK compatibility, and streaming still require validation before publication.

1. Configure your API key

Follow account and API keys and set LLM_SG_API_KEY in the terminal or application environment where you will run the examples.

2. Choose a model

Request the available models:
Select a model suitable for text chat. If the endpoint uses the compatible list format, copy an entry’s id from the data array. Confirm the actual response format and preserve the complete model ID. On macOS or Linux:
On Windows PowerShell:
Replace YOUR_MODEL_ID with an ID provided by llm.sg. Model aliases from another service may not work here.

3. Send a request

Choose one of the following approaches. All examples read LLM_SG_API_KEY; the SDK examples also read LLM_SG_MODEL.
Run this command in Bash or Zsh. Replace YOUR_MODEL_ID in the JSON body with the model you selected.

Read the result

For a compatible text response, read the answer from choices[0].message.content. If the response includes usage, use it to inspect token consumption. Token counts are separate from the final billed amount. If a request fails, record the HTTP status, error message, and request ID, then follow troubleshooting.

Configure a third-party application

For clients that support a custom OpenAI-compatible endpoint, start with these settings and validate the integration: If the client asks for a full chat endpoint, use https://api.llm.sg/v1/chat/completions. Some clients append /v1 themselves. Check the resulting request URL if you encounter path errors.